llir-opt
0.0.1
Low-Level Post-Link Optimiser for OCaml and C
|
10 #include <llvm/ADT/ilist_node.h>
11 #include <llvm/ADT/ilist.h>
13 #include "core/annot.h"
14 #include "core/constant.h"
15 #include "core/cond.h"
16 #include "core/expr.h"
17 #include "core/type.h"
18 #include "core/register.h"
19 #include "core/value.h"
20 #include "core/calling_conv.h"
33 template <>
struct llvm::ilist_traits<
Inst> {
35 using instr_iterator = simple_ilist<Inst>::iterator;
38 void deleteNode(
Inst *inst);
39 void addNodeToList(
Inst *inst);
40 void removeNodeFromList(
Inst *inst);
41 void transferNodesFromList(
54 :
public llvm::ilist_node_with_parent<Inst, Block>
65 enum class Kind : uint8_t {
66 #define GET_INST(kind, type, name, sort) kind,
67 #include "instructions.def"
90 virtual Type
GetType(
unsigned i)
const { llvm_unreachable(
"missing type"); }
96 virtual bool IsReturn()
const {
return false; }
117 template<
typename T,
typename... Args>
120 return annot_.
Set<T, Args...>(std::forward<Args>(args)...);
132 llvm::iterator_range<AnnotSet::const_iterator>
annots()
const
134 return llvm::make_range(annot_.
begin(), annot_.
end());
148 template <
typename T>
149 typename std::enable_if<std::is_base_of<Inst, T>::value>::type
152 std::vector<Ref<Inst>> values;
153 for (
Ref<T> inst : insts) {
154 values.push_back(inst);
160 void dump(llvm::raw_ostream &os = llvm::errs())
const;
169 friend struct llvm::ilist_traits<
Inst>;
187 llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
Inst::Kind kind);
190 inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
const Inst &inst)
196 #define GET_BASE_INTF
197 #include "instructions.def"
bool SetAnnot(Args &&... args)
Sets an annotation.
Definition: inst.h:118
static constexpr Value::Kind kValueKind
Kind of the instruction.
Definition: inst.h:59
virtual bool IsReturn() const
Checks if the instruction returns from the function.
Definition: inst.h:96
unsigned order_
Unique number for stable ordering.
Definition: inst.h:183
virtual bool HasSideEffects() const
Checks if the instruction has side effects.
Definition: inst.h:102
ConstRef< Inst > GetSubValue(unsigned i) const
Returns the ith sub-value.
Definition: inst.h:140
std::enable_if< std::is_base_of< Inst, T >::value >::type replaceAllUsesWith(llvm::ArrayRef< Ref< T >> insts)
Replaces all uses of a multi-type value.
Definition: inst.h:150
bool Has() const
Definition: annot.h:94
Kind
Definition: inst.h:65
virtual bool IsTerminator() const
Checks if the instruction is a terminator.
Definition: inst.h:100
bool AddAnnot(const Annot &annot)
Adds an annotation.
Definition: inst.h:124
const AnnotSet & GetAnnots() const
Returns the instruction's annotation.
Definition: inst.h:126
virtual Type GetType(unsigned i) const
Returns the type of the ith return value.
Definition: inst.h:90
bool empty() const
Checks if there are any annotations set.
Definition: annot.h:183
void removeFromParent()
Removes an instruction from the parent.
Definition: inst.cpp:46
unsigned GetOrder() const
Returns a unique, stable identifier for the instruction.
Definition: inst.h:74
Kind GetKind() const
Returns the instruction kind.
Definition: inst.h:82
Ref< Inst > GetSubValue(unsigned i)
Returns the ith sub-value.
Definition: inst.h:138
bool Add(const Annot &annot)
Definition: annot.cpp:66
size_t size() const
Returns the number of set annotations.
Definition: annot.h:181
bool ClearAnnot()
Removes an annotation.
Definition: inst.h:110
size_t annot_size() const
Returns the number of annotations.
Definition: inst.h:128
void replaceAllUsesWith(Value *v) override
Replaces all uses of this value.
Definition: inst.cpp:58
bool Is(Kind kind) const
Checks if the instruction is of a specific kind.
Definition: inst.h:84
virtual ~Inst()
Destroys an instruction.
Definition: inst.cpp:41
bool IsVoid() const
Checks if the instruction is void.
Definition: inst.h:93
void dump(llvm::raw_ostream &os=llvm::errs()) const
Dumps the textual representation of the instruction.
Definition: inst.cpp:81
Kind
Enumeration of value types.
Definition: value.h:133
bool Clear()
Definition: annot.h:126
iterator end()
Iterator past the last annotation.
Definition: annot.h:187
llvm::iterator_range< AnnotSet::const_iterator > annots() const
Iterator over annotations.
Definition: inst.h:132
void eraseFromParent()
Removes an instruction from the parent and deletes it.
Definition: inst.cpp:52
Block * parent_
Parent node.
Definition: inst.h:181
Inst(Kind kind, unsigned numOps, AnnotSet &&annot)
Constructs an instruction of a given type.
Definition: inst.cpp:21
Block * getParent() const
Returns the parent node.
Definition: inst.h:86
virtual bool IsConstant() const
Checks if the instruction is constant.
Definition: inst.h:98
bool annot_empty() const
Checks if any flags are set.
Definition: inst.h:130
bool Set(Args &&... args)
Definition: annot.h:110
virtual unsigned GetNumRets() const
Returns the number of returned values.
Definition: inst.h:88
iterator begin()
Iterator to the first annotation.
Definition: annot.h:185
bool HasAnnot() const
Checks if a flag is set.
Definition: inst.h:106
const T * GetAnnot() const
Returns an annotation.
Definition: inst.h:114
const T * Get() const
Definition: annot.h:142