llir-opt
0.0.1
Low-Level Post-Link Optimiser for OCaml and C
|
7 #include <llvm/ADT/ilist_node.h>
8 #include <llvm/ADT/ilist.h>
9 #include <llvm/ADT/iterator_range.h>
15 class Annot :
public llvm::ilist_node<Annot> {
25 Annot(Kind kind) : kind_(kind) {}
28 bool Is(Kind kind)
const {
return GetKind() == kind; }
45 static constexpr Annot::Kind kAnnotKind = Kind::PROBABILITY;
72 using AnnotListType = llvm::ilist<Annot>;
77 using const_iterator = AnnotListType::const_iterator;
96 for (
auto &annot : annots_) {
97 if (annot.Is(T::kAnnotKind)) {
109 template<
typename T,
typename... Args>
112 for (
auto &annot : annots_) {
113 if (annot.Is(T::kAnnotKind)) {
118 annots_.push_back(
new T(std::move(args)...));
128 for (
auto it = annots_.begin(); it != annots_.end(); ) {
130 if (jt->Is(T::kAnnotKind)) {
144 for (
auto it = annots_.begin(); it != annots_.end(); ++it) {
145 if (it->Is(T::kAnnotKind)) {
146 return static_cast<const T *
>(&*it);
159 for (
auto &annot : annots_) {
160 if (!annot.Is(T::kAnnotKind)) {
181 size_t size()
const {
return annots_.size(); }
183 bool empty()
const {
return annots_.empty(); }
189 const_iterator
begin()
const {
return annots_.begin(); }
191 const_iterator
end()
const {
return annots_.end(); }
195 AnnotListType annots_;
203 static constexpr Annot::Kind kAnnotKind = Kind::CAML_FRAME;
243 std::vector<size_t> &&
allocs,
250 llvm::iterator_range<const_alloc_iterator>
allocs()
const
252 return { allocs_.begin(), allocs_.end() };
258 llvm::iterator_range<const_debug_infos_iterator>
debug_infos()
const
260 return { debug_infos_.begin(), debug_infos_.end() };
268 std::vector<size_t> allocs_;
270 std::vector<DebugInfos> debug_infos_;
278 static constexpr Annot::Kind kAnnotKind = Kind::CXX_LSDA;
287 std::vector<std::string> &&
catches,
288 std::vector<std::string> &&
filters)
289 :
Annot(Kind::CXX_LSDA)
291 , catchAll_(catchAll)
305 llvm::iterator_range<const_type_iterator>
catches()
const
307 return { catches_.begin(), catches_.end() };
313 llvm::iterator_range<const_type_iterator>
filters()
const
315 return { filters_.begin(), filters_.end() };
324 std::vector<std::string> catches_;
326 std::vector<std::string> filters_;
llvm::iterator_range< const_debug_infos_iterator > debug_infos() const
Iterator over debug information bundles.
Definition: annot.h:258
llvm::iterator_range< const_type_iterator > catches() const
Iterator over catches.
Definition: annot.h:305
bool operator==(const Probability &that) const
Checks if two annotations are equal.
Definition: annot.cpp:140
AnnotSet()
Creats a new, empty annotation set.
Definition: annot.cpp:32
bool operator==(const AnnotSet &that) const
Compares two annotations sets for equality.
Definition: annot.cpp:80
bool operator!=(const AnnotSet &that) const
Compares two annotations sets for inequality.
Definition: annot.h:175
std::vector< DebugInfo > DebugInfos
Debug information bundle.
Definition: annot.h:231
bool Has() const
Definition: annot.h:94
Debug information.
Definition: annot.h:207
size_t filter_size() const
Returns the number of filters.
Definition: annot.h:311
bool empty() const
Checks if there are any annotations set.
Definition: annot.h:183
Probability(uint32_t n, uint32_t d)
Constructs an annotation carrying a probability.
Definition: annot.cpp:133
bool operator==(const DebugInfo &that) const
Compares two debug info objects.
Definition: annot.h:216
int64_t Location
Packed location information.
Definition: annot.h:209
bool IsCatchAll() const
Checks whether the frame is a catch-all frame.
Definition: annot.h:300
llvm::iterator_range< const_type_iterator > filters() const
Iterator over filters.
Definition: annot.h:313
llvm::iterator_range< const_alloc_iterator > allocs() const
Iterator over allocations.
Definition: annot.h:250
bool Add(const Annot &annot)
Definition: annot.cpp:66
size_t size() const
Returns the number of set annotations.
Definition: annot.h:181
bool IsCleanup() const
Checks whether the frame is a cleanup frame.
Definition: annot.h:298
bool operator==(const Annot &annot) const
Checks if two annotations are equal.
Definition: annot.cpp:12
std::vector< DebugInfos >::const_iterator const_debug_infos_iterator
Iterator over debug infos.
Definition: annot.h:236
~AnnotSet()
Destroys the annotation set.
Definition: annot.cpp:61
bool Clear()
Definition: annot.h:126
iterator end()
Iterator past the last annotation.
Definition: annot.h:187
AnnotSet & operator=(AnnotSet &&that)
Assigns annotation from a different set.
Definition: annot.cpp:110
const_iterator end() const
Constant iterator past the last annotation.
Definition: annot.h:191
size_t catch_size() const
Returns the number of catches.
Definition: annot.h:303
bool Is(Kind kind) const
Checks if the annotation is of a given kind.
Definition: annot.h:28
const_iterator begin() const
Constant iterator to the first annotation.
Definition: annot.h:189
Kind GetKind() const
Returns the annotation kind.
Definition: annot.h:30
bool Set(Args &&... args)
Definition: annot.h:110
size_t alloc_size() const
Returns the number of allocations.
Definition: annot.h:248
uint32_t GetNumerator() const
Returns the numerator.
Definition: annot.h:52
AnnotSet Without() const
Definition: annot.h:156
uint32_t GetDenumerator() const
Returns the denominator.
Definition: annot.h:54
size_t debug_info_size() const
Returns the number of debug infos.
Definition: annot.h:256
std::string Definition
Name of the definition.
Definition: annot.h:213
std::string File
Name of the originating file.
Definition: annot.h:211
std::vector< std::string >::const_iterator const_type_iterator
Iterator over type IDs.
Definition: annot.h:281
CamlFrame()
Constructs an annotation without debug info.
Definition: annot.h:240
bool operator==(const CamlFrame &annot) const
Checks if two annotations are equal.
Definition: annot.cpp:127
iterator begin()
Iterator to the first annotation.
Definition: annot.h:185
AnnotListType::iterator iterator
Iterator over the annotations.
Definition: annot.h:76
Annot(Kind kind)
Creates a new annotation.
Definition: annot.h:25
std::vector< size_t >::const_iterator const_alloc_iterator
Iterator over allocations.
Definition: annot.h:234
const T * Get() const
Definition: annot.h:142