10 #include "core/inst_visitor.h"
11 #include "core/insts.h"
17 using Iterator = std::optional<std::pair<std::unique_ptr<Prog>, T *>>;
30 std::unique_ptr<Prog>
Reduce(
31 std::unique_ptr<Prog> &&prog,
36 virtual bool Verify(
const Prog &prog)
const = 0;
39 using It = Iterator<Inst>;
40 using Bt = Iterator<Block>;
41 using At = Iterator<Atom>;
42 using Ft = Iterator<Func>;
45 It ReduceInst(
Inst *i) {
return Dispatch(*i); }
47 Bt ReduceBlock(
Block *b);
49 At ReduceAtom(
Atom *a);
51 Ft ReduceFunc(
Func *f);
54 It VisitArg(ArgInst &i);
56 It VisitCall(CallInst &i);
58 It VisitInvoke(InvokeInst &i);
60 It VisitTailCall(TailCallInst &i);
62 It VisitSyscall(SyscallInst &i);
64 It VisitClone(CloneInst &i);
66 It VisitRaise(RaiseInst &i);
68 It VisitStore(StoreInst &i);
72 It VisitSwitch(SwitchInst &i);
74 It VisitJmp(JumpInst &i);
76 It VisitJcc(JumpCondInst &i);
78 It VisitReturn(ReturnInst &i);
82 It VisitUndef(UndefInst &i);
84 It VisitVAStart(VaStartInst &i);
86 It VisitSet(SetInst &i);
88 It VisitAlloca(AllocaInst &i) {
return ReduceOperator(i); }
90 It VisitFrame(FrameInst &i) {
return ReduceOperator(i); }
92 It VisitLoad(LoadInst &i) {
return ReduceOperator(i); }
94 It VisitUnary(UnaryInst &i) {
return ReduceOperator(i); }
96 It VisitBinary(BinaryInst &i) {
return ReduceOperator(i); }
98 It VisitSelect(SelectInst &i) {
return ReduceOperator(i); }
100 It VisitXchg(X86_XchgInst &i) {
return ReduceOperator(i); }
102 It VisitCmpXchg(X86_CmpXchgInst &i) {
return ReduceOperator(i); }
104 It VisitX86_Rdtsc(X86_RdTscInst &i) {
return ReduceOperator(i); }
106 It VisitX86_FPUControlInst(X86_FPUControlInst &i);
108 It VisitInst(
Inst &i);
111 It ReduceOperator(
Inst &i);
113 using Candidate = std::pair<std::unique_ptr<Prog>,
Inst *>;
114 using CandidateList = std::queue<Candidate>;
117 template <
typename T>
118 void RemoveArg(CandidateList &cand, T &i);
120 void ReduceToOp(CandidateList &cand,
Inst &i);
122 void ReduceToRet(CandidateList &cand,
Inst &i);
124 void ReduceToTrap(CandidateList &cand,
Inst &i);
126 void ReduceToUndef(CandidateList &cand,
Inst &i);
128 void ReduceZero(CandidateList &cand,
Inst &i);
130 void ReduceErase(CandidateList &cand,
Inst &i);
132 void ReduceToArg(CandidateList &cand,
Inst &i);
134 void ReduceOperator(CandidateList &cand,
Inst &i);
137 It Evaluate(CandidateList &&cand);