1 #ifndef MEMOIR_IR_TYPES_H 2 #define MEMOIR_IR_TYPES_H 7 #include "llvm/IR/Function.h" 8 #include "llvm/IR/Instruction.h" 9 #include "llvm/IR/Instructions.h" 10 #include "llvm/IR/Module.h" 11 #include "llvm/Support/raw_ostream.h" 13 #include "memoir/support/Assert.hpp" 14 #include "memoir/support/InternalDatatypes.hpp" 16 #include "memoir/utility/FunctionNames.hpp" 18 #include "memoir/ir/Instructions.hpp" 43 struct FieldArrayType;
44 struct StaticTensorType;
46 struct AssocArrayType;
49 struct DefineStructTypeInst;
70 vector<Type *> field_types);
71 static StructType &get_struct_type(std::string name);
73 unsigned field_index);
76 vector<size_t> dimension_lengths);
78 unsigned num_dimensions);
82 static bool is_primitive_type(
Type &type);
83 static bool is_reference_type(
Type &type);
84 static bool is_struct_type(
Type &type);
85 static bool is_collection_type(
Type &type);
86 static bool value_is_collection_type(llvm::Value &value);
87 static bool value_is_struct_type(llvm::Value &value);
89 TypeCode getCode()
const;
94 virtual std::string toString(std::string indent =
"")
const = 0;
95 virtual opt<std::string> get_code()
const;
97 friend std::ostream &operator<<(std::ostream &os,
const Type &T);
98 friend llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
const Type &T);
99 friend bool operator<(
const Type &L,
const Type &R);
101 virtual ~
Type() =
default;
108 friend class TypeAnalysis;
114 template <
unsigned BW,
bool S>
118 unsigned getBitWidth()
const;
119 bool isSigned()
const;
122 static bool classof(
const Type *T) {
123 return (T->getCode() == TypeCode::INTEGER);
127 std::string toString(std::string indent =
"")
const override;
128 opt<std::string> get_code()
const override;
136 friend class TypeAnalysis;
143 static bool classof(
const Type *T) {
144 return (T->getCode() == TypeCode::FLOAT);
147 std::string toString(std::string indent =
"")
const override;
148 opt<std::string> get_code()
const override;
153 friend class TypeAnalysis;
160 static bool classof(
const Type *T) {
161 return (T->getCode() == TypeCode::DOUBLE);
164 std::string toString(std::string indent =
"")
const override;
165 opt<std::string> get_code()
const override;
170 friend class TypeAnalysis;
177 static bool classof(
const Type *T) {
178 return (T->getCode() == TypeCode::POINTER);
181 std::string toString(std::string indent =
"")
const override;
182 opt<std::string> get_code()
const override;
187 friend class TypeAnalysis;
194 Type &getReferencedType()
const;
196 static bool classof(
const Type *T) {
197 return (T->getCode() == TypeCode::REFERENCE);
200 std::string toString(std::string indent =
"")
const override;
201 opt<std::string> get_code()
const override;
204 Type &referenced_type;
206 static map<Type *, ReferenceType *> *reference_types;
210 friend class TypeAnalysis;
218 vector<Type *> field_types);
223 std::string getName()
const;
224 unsigned getNumFields()
const;
225 Type &getFieldType(
unsigned field_index)
const;
228 static bool classof(
const Type *T) {
229 return (T->getCode() == TypeCode::STRUCT);
233 std::string toString(std::string indent =
"")
const override;
234 opt<std::string> get_code()
const override;
239 vector<Type *> field_types;
241 static map<std::string, StructType *> *defined_types;
245 vector<Type *> field_types);
247 friend class TypeAnalysis;
252 virtual Type &getElementType()
const = 0;
254 static bool classof(
const Type *T) {
255 switch (T->getCode()) {
258 case TypeCode::FIELD_ARRAY:
259 case TypeCode::STATIC_TENSOR:
260 case TypeCode::TENSOR:
261 case TypeCode::SEQUENCE:
262 case TypeCode::ASSOC_ARRAY:
267 opt<std::string> get_code()
const override;
272 friend class TypeAnalysis;
279 Type &getElementType()
const override;
282 unsigned getFieldIndex()
const;
284 static bool classof(
const Type *T) {
285 return (T->getCode() == TypeCode::FIELD_ARRAY);
288 std::string toString(std::string indent =
"")
const override;
292 unsigned field_index;
294 static map<StructType *, map<unsigned, FieldArrayType *>>
295 *struct_to_field_array;
303 vector<size_t> length_of_dimensions);
305 Type &getElementType()
const override;
306 unsigned getNumberOfDimensions()
const;
307 size_t getLengthOfDimension(
unsigned dimension_index)
const;
309 static bool classof(
const Type *T) {
310 return (T->getCode() == TypeCode::STATIC_TENSOR);
313 std::string toString(std::string indent =
"")
const override;
317 unsigned number_of_dimensions;
318 vector<size_t> length_of_dimensions;
321 unsigned number_of_dimensions,
322 vector<size_t> length_of_dimensions);
324 static ordered_multimap<Type *, StaticTensorType *> *static_tensor_types;
326 friend class TypeAnalysis;
331 static TensorType &
get(
Type &element_type,
unsigned num_dimensions);
333 Type &getElementType()
const override;
334 unsigned getNumberOfDimensions()
const;
336 static bool classof(
const Type *T) {
337 return (T->getCode() == TypeCode::TENSOR);
340 std::string toString(std::string indent =
"")
const override;
344 unsigned number_of_dimensions;
348 static map<Type *, map<unsigned, TensorType *>> *tensor_types;
350 friend class TypeAnalysis;
357 Type &getKeyType()
const;
358 Type &getValueType()
const;
359 Type &getElementType()
const override;
361 static bool classof(
const Type *T) {
362 return (T->getCode() == TypeCode::ASSOC_ARRAY);
365 std::string toString(std::string indent =
"")
const override;
371 static map<Type *, map<Type *, AssocArrayType *>> *assoc_array_types;
375 friend class TypeAnalysis;
382 Type &getElementType()
const override;
384 static bool classof(
const Type *T) {
385 return (T->getCode() == TypeCode::SEQUENCE);
388 std::string toString(std::string indent =
"")
const override;
393 static map<Type *, SequenceType *> *sequence_types;
397 friend class TypeAnalysis;
406 Type *type_of(llvm::Value &V);
Definition: Types.hpp:111
Definition: Types.hpp:139
Definition: Types.hpp:300
Definition: Types.hpp:213
Definition: Types.hpp:378
Definition: Types.hpp:275
Definition: Instructions.hpp:334
Definition: Types.hpp:353
Definition: Types.hpp:190
Definition: Liveness.hpp:17
Definition: Instructions.hpp:31
Definition: Types.hpp:250
Definition: Types.hpp:173
Definition: Types.hpp:156
Definition: Types.hpp:329