diff options
author | Justin Bogner <mail@justinbogner.com> | 2016-08-04 23:41:01 +0000 |
---|---|---|
committer | Justin Bogner <mail@justinbogner.com> | 2016-08-04 23:41:01 +0000 |
commit | 19dd0da153304f7947220141efd517f86406c9b3 (patch) | |
tree | 50853177c541c09176e5ed2df5b6acf37a320947 /llvm/lib | |
parent | 68de2e98a64ffa4e26af6e51dd7517ef18426887 (diff) | |
download | bcm5719-llvm-19dd0da153304f7947220141efd517f86406c9b3.tar.gz bcm5719-llvm-19dd0da153304f7947220141efd517f86406c9b3.zip |
IR: Provide an IRBuilder Inserter that calls a callback after insertion
Add a generalized IRBuilderCallbackInserter, which is just given a
callback to execute after insertion. This can be used to get rid of
the custom inserter in InstCombine, which will in turn allow me to add
target specific InstCombineCalls API for intrinsics without horrible
layering violations.
llvm-svn: 277784
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineInternal.h | 24 | ||||
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 11 |
2 files changed, 10 insertions, 25 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index 0763a0a8bfa..72fde594306 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -135,28 +135,6 @@ IntrinsicIDToOverflowCheckFlavor(unsigned ID) { } } -/// \brief An IRBuilder inserter that adds new instructions to the instcombine -/// worklist. -class LLVM_LIBRARY_VISIBILITY InstCombineIRInserter - : public IRBuilderDefaultInserter { - InstCombineWorklist &Worklist; - AssumptionCache *AC; - -public: - InstCombineIRInserter(InstCombineWorklist &WL, AssumptionCache *AC) - : Worklist(WL), AC(AC) {} - - void InsertHelper(Instruction *I, const Twine &Name, BasicBlock *BB, - BasicBlock::iterator InsertPt) const { - IRBuilderDefaultInserter::InsertHelper(I, Name, BB, InsertPt); - Worklist.Add(I); - - using namespace llvm::PatternMatch; - if (match(I, m_Intrinsic<Intrinsic::assume>())) - AC->registerAssumption(cast<CallInst>(I)); - } -}; - /// \brief The core instruction combiner logic. /// /// This class provides both the logic to recursively visit instructions and @@ -171,7 +149,7 @@ public: /// \brief An IRBuilder that automatically inserts new instructions into the /// worklist. - typedef IRBuilder<TargetFolder, InstCombineIRInserter> BuilderTy; + typedef IRBuilder<TargetFolder, IRBuilderCallbackInserter> BuilderTy; BuilderTy *Builder; private: diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 6e4c823901a..312683588eb 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -3120,8 +3120,15 @@ combineInstructionsOverFunction(Function &F, InstCombineWorklist &Worklist, /// Builder - This is an IRBuilder that automatically inserts new /// instructions into the worklist when they are created. - IRBuilder<TargetFolder, InstCombineIRInserter> Builder( - F.getContext(), TargetFolder(DL), InstCombineIRInserter(Worklist, &AC)); + IRBuilder<TargetFolder, IRBuilderCallbackInserter> Builder( + F.getContext(), TargetFolder(DL), + IRBuilderCallbackInserter([&Worklist, &AC](Instruction *I) { + Worklist.Add(I); + + using namespace llvm::PatternMatch; + if (match(I, m_Intrinsic<Intrinsic::assume>())) + AC.registerAssumption(cast<CallInst>(I)); + })); // Lower dbg.declare intrinsics otherwise their value may be clobbered // by instcombiner. |