- // Try to replace the Use of the instruction with something simpler.
- Value *resolve(SetCondInst *SCI, const PropertySet &);
- Value *resolve(BinaryOperator *BO, const PropertySet &);
- Value *resolve(SelectInst *SI, const PropertySet &);
- Value *resolve(Value *V, const PropertySet &);
+ /// Backwards - Try to replace the Use of the instruction with
+ /// something simpler. This resolves a value by walking backwards
+ /// through its definition and the operands of that definition to
+ /// see if any values can now be solved for with the properties
+ /// that are in effect now, but weren't at definition time.
+ class Backwards : public InstVisitor<Backwards, Value &> {
+ friend class InstVisitor<Backwards, Value &>;
+ const PropertySet &KP;
+
+ Value &visitSetCondInst(SetCondInst &SCI);
+ Value &visitBinaryOperator(BinaryOperator &BO);
+ Value &visitSelectInst(SelectInst &SI);
+ Value &visitInstruction(Instruction &I);
+
+ public:
+ explicit Backwards(const PropertySet &KP) : KP(KP) {}
+
+ Value *resolve(Value *V);
+ };
+
+ /// Forwards - Adds new properties into PropertySet and uses them to
+ /// simplify instructions. Because new properties sometimes apply to
+ /// a transition from one BasicBlock to another, this will use the
+ /// PredicateSimplifier::proceedToSuccessor(s) interface to enter the
+ /// basic block with the new PropertySet.
+ class Forwards : public InstVisitor<Forwards> {
+ friend class InstVisitor<Forwards>;
+ PredicateSimplifier *PS;
+ public:
+ PropertySet &KP;
+
+ Forwards(PredicateSimplifier *PS, PropertySet &KP) : PS(PS), KP(KP) {}
+
+ // Tries to simplify each Instruction and add new properties to
+ // the PropertySet. Returns true if it erase the instruction.
+ //void visitInstruction(Instruction *I);
+
+ void visitTerminatorInst(TerminatorInst &TI);
+ void visitBranchInst(BranchInst &BI);
+ void visitSwitchInst(SwitchInst &SI);
+
+ void visitLoadInst(LoadInst &LI);
+ void visitStoreInst(StoreInst &SI);
+ void visitBinaryOperator(BinaryOperator &BO);
+ };