diff options
author | Zhigang Gong <zhigang.gong@intel.com> | 2014-09-29 19:01:51 +0800 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@intel.com> | 2014-09-29 19:05:16 +0800 |
commit | 7287f9eb96e4644db05357d557246a5d318f7046 (patch) | |
tree | 8a3a6a301f2ce08074576e9a3a304578405b5fe6 | |
parent | b2b19e901668bb26551ae4972378b44d2557629d (diff) |
draftloop_unroll
need to disable unrolling for those loops have too large travel count.
and all its parent loop.
Signed-off-by: Zhigang Gong <zhigang.gong@intel.com>
-rw-r--r-- | backend/src/llvm/llvm_unroll.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/backend/src/llvm/llvm_unroll.cpp b/backend/src/llvm/llvm_unroll.cpp index de0bd5e7..6f10fd83 100644 --- a/backend/src/llvm/llvm_unroll.cpp +++ b/backend/src/llvm/llvm_unroll.cpp @@ -41,6 +41,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/PassManager.h" #include "llvm/Transforms/Scalar.h" +#include "llvm/Analysis/ScalarEvolution.h" #include "llvm/Analysis/LoopPass.h" #include "llvm/llvm_gen_backend.hpp" #include "sys/map.hpp" @@ -63,6 +64,8 @@ namespace gbe { AU.addPreservedID(LoopSimplifyID); AU.addRequiredID(LCSSAID); AU.addPreservedID(LCSSAID); + AU.addRequired<ScalarEvolution>(); + AU.addPreserved<ScalarEvolution>(); } // Returns the value associated with the given metadata node name (for @@ -95,7 +98,7 @@ namespace gbe { static void setForceUnrollID(Loop *L) { LLVMContext &Context = L->getHeader()->getContext(); - SmallVector<Value *, 2> forceUnroll, unrollCount; + SmallVector<Value *, 2> forceUnroll; forceUnroll.push_back(MDString::get(Context, "llvm.loop.unroll.enable")); forceUnroll.push_back(ConstantInt::get(Type::getInt1Ty(Context), 1)); MDNode *forceUnrollNode = MDNode::get(Context, forceUnroll); @@ -118,6 +121,18 @@ namespace gbe { const ConstantInt *Count = GetUnrollMetadataValue(L, "llvm.loop.unroll.count"); if (Count) return false; + ScalarEvolution *SE = &getAnalysis<ScalarEvolution>(); + BasicBlock *LatchBlock = L->getLoopLatch(); + unsigned TripCount = SE->getSmallConstantTripCount(L, LatchBlock); + if (TripCount > 32) { + // 32 is too large to unroll, let's disable the unrolling on it and all its parent loop. + Loop *parentL = L->getParentLoop(); + while(parentL) { + setDisableUnrollID(parentL); + parentL = parentL->getParentLoop(); + } + } + const std::vector<Loop*> subLoops = L->getSubLoops(); std::set<BasicBlock*> subBlocks, blocks; for(auto l : subLoops) |