llir-opt  0.0.1
Low-Level Post-Link Optimiser for OCaml and C
type.h
1 // This file if part of the llir-opt project.
2 // Licensing information can be found in the LICENSE file.
3 // (C) 2018 Nandor Licker. All rights reserved.
4 
5 #pragma once
6 
7 #include <llvm/Support/raw_ostream.h>
8 #include <llvm/Support/MachineValueType.h>
9 #include <llvm/Support/Alignment.h>
10 
11 
12 
16 enum class Type {
17  I8,
18  I16,
19  I32,
20  I64,
21  V64,
22  I128,
23  F32,
24  F64,
25  F80,
26  F128
27 };
28 
32 class TypeFlag {
33 public:
34  enum class Kind : uint8_t {
35  NONE,
36  BYVAL,
37  SEXT,
38  ZEXT,
39  };
40 
41 public:
42  static TypeFlag GetNone();
43  static TypeFlag GetSExt();
44  static TypeFlag GetZExt();
45  static TypeFlag GetByVal(unsigned size, llvm::Align align);
46 
47  bool IsByVal() const { return GetKind() == Kind::BYVAL; }
48 
49  Kind GetKind() const { return static_cast<Kind>(kind_); }
50 
51  bool operator==(const TypeFlag &that) const
52  {
53  return true;
54  }
55 
56  unsigned GetByValSize() const;
57  llvm::Align GetByValAlign() const;
58 
59 private:
61  TypeFlag() { }
62 
63 private:
64  union {
65  uint64_t data_;
66  struct {
67  unsigned size_ : 16;
68  unsigned align_ : 16;
69  unsigned kind_ : 8;
70  };
71  };
72 };
73 
77 class FlaggedType {
78 public:
79  FlaggedType(Type type) : type_(type), flag_(TypeFlag::GetNone()) {}
80  FlaggedType(Type type, TypeFlag flag) : type_(type), flag_(flag) {}
81 
82  Type GetType() const { return type_; }
83  TypeFlag GetFlag() const { return flag_; }
84 
85  bool operator==(const FlaggedType &that) const
86  {
87  return type_ == that.type_ && flag_ == that.flag_;
88  }
89 
90 private:
92  Type type_;
94  TypeFlag flag_;
95 };
96 
100 llvm::raw_ostream &operator<<(llvm::raw_ostream &os, Type type);
101 
105 llvm::raw_ostream &operator<<(llvm::raw_ostream &os, TypeFlag flag);
106 
110 llvm::raw_ostream &operator<<(llvm::raw_ostream &os, FlaggedType type);
111 
115 bool IsIntegerType(Type type);
116 
120 bool IsFloatType(Type type);
121 
125 unsigned GetSize(Type type);
126 
130 unsigned GetBitWidth(Type type);
131 
135 llvm::Align GetAlignment(Type type);
136 
140 llvm::MVT GetVT(Type type);
FlaggedType
Definition: type.h:77
TypeFlag
Definition: type.h:32