1 #ifndef MEMOIR_KEYWORDS_H
2 #define MEMOIR_KEYWORDS_H
7 #include "llvm/IR/Constants.h"
8 #include "llvm/IR/GlobalVariable.h"
9 #include "llvm/IR/User.h"
11 #include "memoir/support/Assert.hpp"
13 namespace llvm::memoir {
17 using iterator = llvm::User::value_op_iterator;
18 using operand_iterator = llvm::User::op_iterator;
19 using const_iterator = llvm::User::const_value_op_iterator;
20 using const_operand_iterator = llvm::User::const_op_iterator;
33 std::enable_if_t<std::is_base_of_v<Keyword, KeywordTy>,
bool> =
true>
34 static llvm::ConstantDataArray &
get_llvm(llvm::LLVMContext &C) {
36 std::string(Keyword::PREFIX) + std::string(KeywordTy::NAME);
38 auto *data = llvm::ConstantDataArray::getString(C, name);
40 return MEMOIR_SANITIZE(dyn_cast_or_null<llvm::ConstantDataArray>(data),
41 "Failed to create keyword as LLVM constant.");
49 llvm::iterator_range<iterator> values();
53 llvm::iterator_range<operand_iterator> operands();
54 operand_iterator op_begin();
55 operand_iterator op_end();
57 llvm::iterator_range<const_iterator> values()
const;
58 const_iterator begin()
const;
59 const_iterator end()
const;
61 llvm::iterator_range<const_operand_iterator> operands()
const;
62 const_operand_iterator op_begin()
const;
63 const_operand_iterator op_end()
const;
65 Keyword(llvm::Use &use) : use(&use) {}
67 static const char *PREFIX;
85 return lhs.op == rhs.op;
88 llvm::Use *asUse()
const {
96 #define CLASSOF_IMPL() \
97 static bool classof(const Keyword &kw) { \
98 auto *value = kw.getAsUse().get(); \
99 auto *data = dyn_cast<llvm::ConstantDataSequential>(value); \
100 if (auto *global = dyn_cast<llvm::GlobalVariable>(value)) { \
101 auto *init = global->getInitializer(); \
102 data = dyn_cast<llvm::ConstantDataSequential>(init); \
107 auto str = data->getAsCString(); \
108 return str.ends_with(NAME); \
113 llvm::iterator_range<Keyword::iterator> args();
114 Keyword::iterator args_begin();
115 Keyword::iterator args_end();
117 llvm::iterator_range<Keyword::operand_iterator> arg_operands();
118 Keyword::operand_iterator arg_ops_begin();
119 Keyword::operand_iterator arg_ops_end();
126 static const char *NAME;
133 llvm::Value &getInput()
const;
134 llvm::Use &getInputAsUse()
const;
136 llvm::iterator_range<Keyword::iterator> indices();
137 Keyword::iterator indices_begin();
138 Keyword::iterator indices_end();
140 llvm::iterator_range<Keyword::operand_iterator> index_operands();
141 Keyword::operand_iterator index_ops_begin();
142 Keyword::operand_iterator index_ops_end();
149 static const char *NAME;
156 llvm::Value &getBegin()
const;
157 llvm::Use &getBeginAsUse()
const;
159 llvm::Value &getEnd()
const;
160 llvm::Use &getEndAsUse()
const;
167 static const char *NAME;
174 llvm::Value &getValue()
const;
175 llvm::Use &getValueAsUse()
const;
182 static const char *NAME;
189 std::string getSelection()
const;
190 llvm::Value &getSelectionOperand()
const;
191 llvm::Use &getSelectionOperandAsUse()
const;
198 static const char *NAME;
210 static const char *NAME;
217 llvm::iterator_range<Keyword::iterator> indices();
218 Keyword::iterator indices_begin();
219 Keyword::iterator indices_end();
221 llvm::iterator_range<Keyword::operand_iterator> index_operands();
222 Keyword::operand_iterator index_ops_begin();
223 Keyword::operand_iterator index_ops_end();
230 static const char *NAME;
Definition: Keywords.hpp:215
Definition: Keywords.hpp:111
Definition: Keywords.hpp:15
static bool is_keyword(llvm::Value &V)
Definition: Keywords.cpp:18
llvm::Use & getAsUse() const
Definition: Keywords.cpp:59
static llvm::ConstantDataArray & get_llvm(llvm::LLVMContext &C)
Definition: Keywords.hpp:34
Definition: Keywords.hpp:154
Definition: Keywords.hpp:203
Definition: Keywords.hpp:187
Definition: Keywords.hpp:172
Definition: Keywords.hpp:73