7 #include <unordered_set>
9 #include "core/adt/id.h"
10 #include "core/adt/bitset.h"
11 #include "core/adt/union_find.h"
12 #include "core/target.h"
13 #include "core/inst_visitor.h"
14 #include "passes/tags/tagged_type.h"
15 #include "passes/tags/constraint_type.h"
21 class RegisterAnalysis;
39 void BuildConstraints();
40 void CollapseEquivalences();
41 void SolveConstraints();
45 void VisitArgInst(ArgInst &i)
override;
46 void VisitCallSite(CallSite &i)
override;
47 void VisitLandingPadInst(LandingPadInst &i)
override;
49 void VisitSubInst(SubInst &i)
override;
50 void VisitAddInst(AddInst &i)
override;
51 void VisitAndInst(AndInst &i)
override;
52 void VisitOrInst(OrInst &i)
override;
53 void VisitXorInst(XorInst &i)
override;
54 void VisitCmpInst(CmpInst &i)
override;
55 void VisitSelectInst(SelectInst &i)
override;
56 void VisitPhiInst(
PhiInst &i)
override;
58 void VisitMovInst(
MovInst &i)
override;
59 void VisitExtensionInst(ExtensionInst &i)
override;
60 void VisitTruncInst(TruncInst &i)
override;
61 void VisitMemoryStoreInst(MemoryStoreInst &store)
override;
62 void VisitMemoryLoadInst(MemoryLoadInst &load)
override;
63 void VisitMemoryExchangeInst(MemoryExchangeInst &i)
override;
64 void VisitMemoryCompareExchangeInst(MemoryCompareExchangeInst &i)
override;
66 void VisitFrameInst(FrameInst &i)
override { ExactlyPointer(i); }
67 void VisitUndefInst(UndefInst &i)
override;
68 void VisitAllocaInst(AllocaInst &i)
override { ExactlyPointer(i); }
69 void VisitFloatInst(FloatInst &i)
override { ExactlyInt(i); }
70 void VisitShiftRightInst(ShiftRightInst &i)
override { ExactlyInt(i); }
71 void VisitSllInst(SllInst &i)
override { ExactlyInt(i); }
72 void VisitRotateInst(RotateInst &i)
override { ExactlyInt(i); }
73 void VisitCopySignInst(CopySignInst &i)
override { ExactlyInt(i); }
74 void VisitGetInst(GetInst &i)
override;
75 void VisitX86_RdTscInst(X86_RdTscInst &i)
override { ExactlyInt(i); }
76 void VisitMultiplyInst(MultiplyInst &i)
override { ExactlyInt(i); }
77 void VisitDivisionRemainderInst(DivisionRemainderInst &i)
override { ExactlyInt(i); }
78 void VisitByteSwapInst(ByteSwapInst &i)
override { ExactlyInt(i); }
79 void VisitBitCountInst(BitCountInst &i)
override { ExactlyInt(i); }
80 void VisitBitCastInst(BitCastInst &i)
override { Infer(i); }
81 void VisitVaStartInst(VaStartInst &i)
override { ExactlyPointer(i.GetVAList()); }
82 void VisitX86_FPUControlInst(X86_FPUControlInst &i)
override { AnyPointer(i.GetAddr()); }
83 void VisitSyscallInst(SyscallInst &i)
override;
84 void VisitCloneInst(CloneInst &i)
override { ExactlyInt(i); }
85 void VisitTerminatorInst(TerminatorInst &i)
override {}
86 void VisitSetInst(SetInst &i)
override {}
87 void VisitX86_OutInst(X86_OutInst &i)
override {}
88 void VisitX86_WrMsrInst(X86_WrMsrInst &i)
override {}
89 void VisitX86_LidtInst(X86_LidtInst &i)
override {}
90 void VisitX86_LgdtInst(X86_LgdtInst &i)
override {}
91 void VisitX86_LtrInst(X86_LtrInst &i)
override {}
92 void VisitX86_HltInst(X86_HltInst &i)
override {}
93 void VisitX86_PauseInst(X86_PauseInst &i)
override {}
94 void VisitX86_YieldInst(X86_YieldInst &i)
override {}
95 void VisitX86_BarrierInst(X86_BarrierInst &i)
override {}
96 void VisitX86_FnClExInst(X86_FnClExInst &i)
override {}
98 void VisitInst(
Inst &i)
override;
110 std::unordered_set<Ref<Inst>> Defs;
114 , Min(ConstraintType::BOT)
115 , Max(ConstraintType::PTR_INT)
120 void Union(Constraint &that);
122 void dump(llvm::raw_ostream &os = llvm::errs());
130 using Lit = std::tuple<ID<Constraint>, bool,
bool>;
132 static Lit IsInt(
ID<Constraint> id) {
return { id,
false,
true }; }
133 static Lit IsPtr(
ID<Constraint> id) {
return { id,
true,
true }; }
134 static Lit NotInt(
ID<Constraint> id) {
return { id,
false,
false }; }
135 static Lit NotPtr(
ID<Constraint> id) {
return { id,
true,
false }; }
137 static Lit Conj(
const Lit &l)
139 return { std::get<0>(l), std::get<1>(l), !std::get<2>(l) };
145 llvm::SmallVector<Lit, 2> Conj;
149 void Alternatives(
Ref<Inst> i, llvm::ArrayRef<Alternative> alternatives);
153 void AtMost(
Ref<Inst> a, ConstraintType type);
154 void AtLeast(
Ref<Inst> a, ConstraintType type);
156 void AtMostPointer(
Ref<Inst> arg) { AtMost(arg, ConstraintType::PTR); }
157 void ExactlyPointer(
Ref<Inst> arg) { Exactly(arg, ConstraintType::PTR); }
158 void ExactlyYoung(
Ref<Inst> arg) { Exactly(arg, ConstraintType::YOUNG); }
159 void ExactlyHeap(
Ref<Inst> arg) { Exactly(arg, ConstraintType::HEAP); }
160 void ExactlyInt(
Ref<Inst> arg) { Exactly(arg, ConstraintType::INT); }
161 void ExactlyFunc(
Ref<Inst> arg) { Exactly(arg, ConstraintType::FUNC); }
165 AtLeast(a, ConstraintType::PTR_BOT);
166 AtMost(a, ConstraintType::PTR);
169 void Exactly(
Ref<Inst> a,
const ConstraintType &type)
181 ConstraintType LowerBound(Type ty,
TaggedType type);
182 ConstraintType UpperBound(Type ty,
TaggedType type);
186 return AtLeast(arg, LowerBound(arg.GetType(), type));
191 return AtMost(arg, UpperBound(arg.GetType(), type));
197 bool IsExtern(
const Func &f);
205 bool banPolymorphism_;
214 std::unordered_map<const Func *, bool> externs_;
216 std::vector<llvm::SmallVector<Lit, 3>> conj_;