llir-opt
0.0.1
Low-Level Post-Link Optimiser for OCaml and C
|
7 #include <llvm/ADT/APFloat.h>
8 #include <llvm/ADT/APInt.h>
9 #include <llvm/Support/raw_ostream.h>
12 #include "passes/pre_eval/symbolic_pointer.h"
16 using APInt = llvm::APInt;
17 using APFloat = llvm::APFloat;
63 const std::optional<Origin> &orig = std::nullopt
67 const std::optional<Origin> &orig = std::nullopt
72 const std::optional<Origin> &orig = std::nullopt
77 const std::optional<Origin> &orig = std::nullopt
82 const std::optional<Origin> &orig = std::nullopt
88 const std::optional<Origin> &orig = std::nullopt
92 const SymbolicPointer::Ref &pointer,
93 const std::optional<Origin> &orig = std::nullopt
97 const SymbolicPointer::Ref &pointer,
98 const std::optional<Origin> &orig = std::nullopt
102 const SymbolicPointer::Ref &pointer,
103 const std::optional<Origin> &orig = std::nullopt
106 Kind GetKind()
const {
return kind_; }
108 bool IsInteger()
const {
return GetKind() ==
Kind::INTEGER; }
109 bool IsScalar()
const {
return GetKind() ==
Kind::SCALAR; }
112 bool IsFloat()
const {
return GetKind() ==
Kind::FLOAT; }
113 bool IsPointer()
const {
return GetKind() ==
Kind::POINTER; }
114 bool IsValue()
const {
return GetKind() ==
Kind::VALUE; }
117 bool IsPointerLike()
const {
return IsPointer() || IsValue() || IsNullable(); }
118 bool IsIntegerLike()
const {
return IsInteger() || IsLowerBoundedInteger(); }
120 APInt GetInteger()
const { assert(IsIntegerLike());
return intVal_; }
122 APInt GetMaskKnown()
const { assert(IsMaskedInteger());
return maskVal_.Known; }
123 APInt GetMaskValue()
const { assert(IsMaskedInteger());
return maskVal_.Value; }
125 APFloat GetFloat()
const { assert(IsFloat());
return floatVal_; }
127 const SymbolicPointer::Ref &GetPointer()
const
129 assert(IsPointerLike());
135 if (IsPointerLike()) {
136 return &*GetPointer();
142 std::optional<APInt> AsInt()
const
145 return std::optional<APInt>(GetInteger());
160 std::optional<Origin>
GetOrigin()
const {
return origin_; }
177 bool operator!=(
const SymbolicValue &that)
const {
return !(*
this == that); }
180 void dump(llvm::raw_ostream &os)
const;
197 std::optional<Origin> origin_;
217 inline llvm::raw_ostream &operator<<(
218 llvm::raw_ostream &os,
Definition: symbolic_pointer.h:270
Definition: symbolic_value.h:24
struct SymbolicValue::@8::@10 maskVal_
Value is kind is mask.
std::pair< ID< SymbolicFrame >, Ref< Inst > > Origin
Instruction which originated the value.
Definition: symbolic_value.h:49
~SymbolicValue()
Cleanup.
Definition: symbolic_value.cpp:44
@ UNDEFINED
A undefined value.
bool operator==(const SymbolicValue &that) const
Compares two values for equality.
Definition: symbolic_value.cpp:617
SymbolicValue Cast(Type type) const
Cast the value to a specific type.
Definition: symbolic_value.cpp:237
SymbolicValue Pin(Ref< Inst > ref, ID< SymbolicFrame > frame) const
Pin the value to a different instruction.
Definition: symbolic_value.cpp:169
std::optional< Origin > GetOrigin() const
Return the origin, if there is one.
Definition: symbolic_value.h:160
APInt Known
1's for bits whose values are known.
Definition: symbolic_value.h:207
Kind
Enumeration of value kinds.
Definition: symbolic_value.h:27
@ POINTER
A pointer or a range of pointers.
APFloat floatVal_
Value if kind is float.
Definition: symbolic_value.h:203
SymbolicValue LUB(const SymbolicValue &that) const
Computes the least-upper-bound.
Definition: symbolic_value.h:168
@ FLOAT
Floating-point value.
@ LOWER_BOUNDED_INTEGER
An unknown integer with a lower bound.
@ NULLABLE
A pointer or null.
bool IsTrue() const
Checks whether the value evaluates to true.
Definition: symbolic_value.cpp:177
APInt Value
Values of the known bits.
Definition: symbolic_value.h:209
@ INTEGER
A specific integer.
Definition: symbolic_frame.h:29
void Merge(const SymbolicValue &that)
Merges a value into this one.
Definition: symbolic_value.cpp:323
APInt intVal_
Value if kind is integer.
Definition: symbolic_value.h:201
void dump(llvm::raw_ostream &os) const
Dump the textual representation to a stream.
Definition: symbolic_value.cpp:660
SymbolicValue & operator=(const SymbolicValue &that)
Copy assignment operator.
Definition: symbolic_value.cpp:50
@ SCALAR
A integer of an unknown value.
@ MASKED_INTEGER
An integer with some known bits.
SymbolicValue()
Undefined constructor.
Definition: symbolic_value.h:53
std::shared_ptr< SymbolicPointer > ptrVal_
Value if kind is pointer.
Definition: symbolic_value.h:212
bool IsFalse() const
Checks whether the value evaluates to false.
Definition: symbolic_value.cpp:208
@ VALUE
Value - unknown integer or pointer.