llir-opt
0.0.1
Low-Level Post-Link Optimiser for OCaml and C
|
8 #include <llvm/ADT/APFloat.h>
9 #include <llvm/ADT/APInt.h>
10 #include <llvm/Support/raw_ostream.h>
12 using APInt = llvm::APInt;
13 using APFloat = llvm::APFloat;
54 Kind GetKind()
const {
return kind_; }
58 bool IsInt()
const {
return GetKind() ==
Kind::INT; }
59 bool IsMask()
const {
return GetKind() ==
Kind::MASK; }
60 bool IsFloat()
const {
return GetKind() ==
Kind::FLOAT; }
62 bool IsGlobal()
const {
return GetKind() ==
Kind::GLOBAL; }
63 bool IsFrame()
const {
return GetKind() ==
Kind::FRAME; }
65 bool IsRange()
const {
return GetKind() ==
Kind::RANGE; }
67 bool IsPointerLike()
const {
return IsPointer() || IsFrame() || IsGlobal(); }
69 APInt GetInt()
const { assert(IsInt());
return intVal_; }
70 APInt GetKnown()
const { assert(IsMask());
return maskVal_.Known; }
71 APInt GetValue()
const { assert(IsMask());
return maskVal_.Value; }
72 APFloat GetFloat()
const { assert(IsFloat());
return floatVal_; }
73 unsigned GetFrameObject()
const { assert(IsFrame());
return frameVal_.Obj; }
74 int64_t GetFrameOffset()
const { assert(IsFrame());
return frameVal_.Off; }
75 Global *GetGlobalSymbol()
const { assert(IsGlobal());
return globalVal_.Sym; }
76 int64_t GetGlobalOffset()
const { assert(IsGlobal());
return globalVal_.Off; }
83 std::optional<APInt>
AsInt()
const
85 return IsInt() ? std::optional<APInt>(
intVal_) : std::nullopt;
91 return IsFloat() ? std::optional<APFloat>(
floatVal_) : std::nullopt;
170 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
const Lattice &l);
bool operator!=(const Lattice &that) const
Checks if two values are not identical.
Definition: lattice.h:95
struct Lattice::@11::@13 maskVal_
Bit mask value.
APInt intVal_
Integer value.
Definition: lattice.h:143
APFloat floatVal_
Double value.
Definition: lattice.h:145
Kind
Enumeration of lattice value kinds.
Definition: lattice.h:25
static Lattice CreateRange(Global *g)
Creates a global value.
Definition: lattice.cpp:369
static Lattice Undefined()
Creates an undefined value.
Definition: lattice.cpp:339
@ FRAME
Offset into the frame.
static Lattice CreateFrame(unsigned obj, int64_t off)
Creates a frame value.
Definition: lattice.cpp:351
std::optional< APInt > AsInt() const
Returns some integer, if the value is one.
Definition: lattice.h:83
@ UNDEFINED
Constant, undefined.
Lattice LUB(const Lattice &that) const
Least upper bound operator.
Definition: lattice.cpp:252
struct Lattice::@11::@15 globalVal_
Global value.
static Lattice Pointer()
Creates a unknown pointer value.
Definition: lattice.cpp:345
static Lattice CreateInteger(int64_t i)
Creates an integral value from an integer.
Definition: lattice.cpp:377
APInt Known
Mask indicating the bits which have known values.
Definition: lattice.h:149
Lattice & operator=(const Lattice &that)
Assigns a value to a lattice.
Definition: lattice.cpp:185
@ GLOBAL
Constant symbol with a potential offset.
static Lattice CreateFloat(double f)
Creates a floating value from a double.
Definition: lattice.cpp:400
bool operator==(const Lattice &that) const
Checks if two values are identical.
Definition: lattice.cpp:145
@ UNKNOWN
Top - value not encountered yet.
@ OVERDEFINED
Bot - value is not constant.
int64_t Off
Relative offset.
Definition: lattice.h:158
static Lattice CreateFloatZero()
Creates a float-point zero.
Definition: lattice.cpp:414
APInt Value
Mask indicating the values of those bits.
Definition: lattice.h:151
@ FLOAT_ZERO
Positive or negative float zero.
static Lattice CreateGlobal(Global *g, int64_t Off=0)
Creates a global value.
Definition: lattice.cpp:360
static Lattice Unknown()
Creates an unknown value.
Definition: lattice.cpp:327
static Lattice Overdefined()
Creates an overdefined value.
Definition: lattice.cpp:333
@ RANGE
Any offset into a pointer.
struct Lattice::@11::@14 frameVal_
Frame value.
static Lattice CreateMask(const APInt &known, const APInt &values)
Creates a mask value;.
Definition: lattice.cpp:391
unsigned Obj
Object identifier.
Definition: lattice.h:156
std::optional< APFloat > AsFloat() const
Returns some float, if the value is one.
Definition: lattice.h:89
@ FLOAT
Constant floating-point.
@ POINTER
Pointer which is not null.
Global * Sym
Base pointer.
Definition: lattice.h:163