llir-opt
0.0.1
Low-Level Post-Link Optimiser for OCaml and C
|
7 #include "passes/pre_eval/symbolic_value.h"
8 #include "passes/pre_eval/symbolic_context.h"
38 struct Mask {
const APInt &Known;
const APInt &
Value; };
40 struct Value {
const SymbolicPointer::Ref &Ptr; };
42 struct Pointer {
const SymbolicPointer::Ref &Ptr; };
44 struct Nullable {
const SymbolicPointer::Ref &Ptr; };
46 #define VISITOR(lhs, rhs) \
47 virtual bool Visit(lhs, rhs) \
48 { llvm_unreachable(("not implemented: " #lhs " and " #rhs)); }
50 #define VISITOR_GROUP(lhs) \
51 VISITOR(lhs, Scalar) \
52 VISITOR(lhs, LowerBoundedInteger) \
54 VISITOR(lhs, const APInt &) \
55 VISITOR(lhs, const APFloat &) \
56 VISITOR(lhs, Pointer) \
57 VISITOR(lhs, Undefined) \
59 VISITOR(lhs, Nullable)
64 VISITOR_GROUP(
const APInt &);
65 VISITOR_GROUP(
const APFloat &);
106 template <
typename T>
109 #define DISPATCH(value) \
110 switch (rhs_.GetKind()) { \
111 case SymbolicValue::Kind::SCALAR: \
112 return Visit(value, Scalar{}); \
113 case SymbolicValue::Kind::LOWER_BOUNDED_INTEGER: \
114 return Visit(value, LowerBoundedInteger{rhs_.GetInteger()}); \
115 case SymbolicValue::Kind::MASKED_INTEGER: \
116 return Visit(value, Mask{rhs_.GetMaskKnown(), rhs_.GetMaskValue()}); \
117 case SymbolicValue::Kind::UNDEFINED: \
118 return Visit(value, Undefined{}); \
119 case SymbolicValue::Kind::INTEGER: \
120 return Visit(value, rhs_.GetInteger()); \
121 case SymbolicValue::Kind::FLOAT: \
122 return Visit(value, rhs_.GetFloat()); \
123 case SymbolicValue::Kind::POINTER: \
124 return Visit(value, Pointer{rhs_.GetPointer()}); \
125 case SymbolicValue::Kind::NULLABLE: \
126 return Visit(value, Nullable{rhs_.GetPointer()}); \
127 case SymbolicValue::Kind::VALUE: \
128 return Visit(value, Value{rhs_.GetPointer()}); \
130 llvm_unreachable("invalid rhs kind");
132 switch (lhs_.GetKind()) {
138 DISPATCH((
Mask{lhs_.GetMaskKnown(), lhs_.GetMaskValue()}));
140 DISPATCH((lhs_.GetInteger()));
142 DISPATCH((lhs_.GetFloat()));
144 DISPATCH((
Pointer{lhs_.GetPointer()}));
146 DISPATCH((
Value{lhs_.GetPointer()}));
148 DISPATCH((
Nullable{lhs_.GetPointer()}));
152 llvm_unreachable(
"invalid lhs kind");
Definition: symbolic_context.h:28
Definition: symbolic_value.h:24
bool SetUndefined()
Helper to return a scalar.
Definition: symbolic_eval.h:45
bool SetNullable(const SymbolicPointer::Ref &p)
Forward to evaluator, return a nullable.
Definition: symbolic_visitor.h:86
bool SetScalar()
Helper to return a scalar.
Definition: symbolic_eval.h:51
bool SetScalar()
Forward to evaluator, return a scalar.
Definition: symbolic_visitor.h:82
Definition: symbolic_eval.h:19
T & inst_
Instruction to be evaluated.
Definition: symbolic_visitor.h:98
bool SetInteger(const APInt &i)
Helper to return an integer.
Definition: symbolic_eval.h:57
bool SetValue(const SymbolicPointer::Ref &p)
Forward to evaluator, return a pointer.
Definition: symbolic_visitor.h:88
@ UNDEFINED
A undefined value.
SymbolicContext & ctx_
Reference to the context.
Definition: symbolic_visitor.h:96
Token for pointers.
Definition: symbolic_visitor.h:42
bool SetLowerBounded(const APInt &i)
Forward to evaluator, return a lower bounded integer.
Definition: symbolic_visitor.h:78
Token for lower bounded integers.
Definition: symbolic_visitor.h:36
@ POINTER
A pointer or a range of pointers.
bool SetPointer(const SymbolicPointer::Ref &p)
Forward to evaluator, return a valu.
Definition: symbolic_visitor.h:84
@ FLOAT
Floating-point value.
bool SetNullable(const SymbolicPointer::Ref &ptr)
Helper to forward a pointer (nullptr).
Definition: symbolic_eval.h:93
bool SetPointer(const SymbolicPointer::Ref &ptr)
Helper to forward a pointer (pointer).
Definition: symbolic_eval.h:87
@ LOWER_BOUNDED_INTEGER
An unknown integer with a lower bound.
@ NULLABLE
A pointer or null.
Token for masked integers.
Definition: symbolic_visitor.h:38
bool SetMask(const APInt &k, const APInt &v)
Forward to evaluator, return a pointer.
Definition: symbolic_visitor.h:90
bool SetInteger(const APInt &i)
Forward to evaluator, return an integer.
Definition: symbolic_visitor.h:76
Definition: symbolic_visitor.h:15
bool SetMask(const APInt &k, const APInt &v)
Forward to frameuator, return a pointer.
Definition: symbolic_eval.h:75
bool SetUndefined()
Forward to evaluator, return a undefined value.
Definition: symbolic_visitor.h:80
Token for pointer or null values.
Definition: symbolic_visitor.h:44
Token for values.
Definition: symbolic_visitor.h:40
bool SetLowerBounded(const APInt &i)
Helper to return a lower bounded integer.
Definition: symbolic_eval.h:69
@ INTEGER
A specific integer.
const SymbolicValue & rhs_
Right-hand operand.
Definition: symbolic_visitor.h:102
Token for an undefined value.
Definition: symbolic_visitor.h:32
bool Evaluate()
Dispatch to the correct case.
Definition: symbolic_visitor.h:107
SymbolicEval & eval_
Reference to the evaluator.
Definition: symbolic_visitor.h:94
const SymbolicValue & lhs_
Left-hand operand.
Definition: symbolic_visitor.h:100
@ SCALAR
A integer of an unknown value.
@ MASKED_INTEGER
An integer with some known bits.
Token for unknown integer values.
Definition: symbolic_visitor.h:34
BinaryVisitor(SymbolicEval &eval, T &i)
Looks up the values and dispatches them to the correct case.
Definition: symbolic_visitor.h:18
bool SetValue(const SymbolicPointer::Ref &ptr)
Helper to forward a pointer (value).
Definition: symbolic_eval.h:81
@ VALUE
Value - unknown integer or pointer.