Mercurial > hg > Members > tobaru > cbc > CbC_llvm
changeset 11:b7de57f78d3a
add FPM SROA pass for function which contains goto cs().
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 14 Jul 2013 17:42:20 +0900 |
parents | e3d004bb4de5 |
children | 449dd23ac5df |
files | include/llvm/Transforms/Scalar.h lib/Transforms/IPO/PassManagerBuilder.cpp lib/Transforms/Scalar/SROA.cpp lib/Transforms/Scalar/TailRecursionElimination.cpp |
diffstat | 4 files changed, 65 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/include/llvm/Transforms/Scalar.h Sat Jul 13 18:16:49 2013 +0900 +++ b/include/llvm/Transforms/Scalar.h Sun Jul 14 17:42:20 2013 +0900 @@ -72,8 +72,11 @@ // // SROA - Replace aggregates or pieces of aggregates with scalar SSA values. // +#ifndef noCbC + FunctionPass *createSROAPass(bool RequiresDomTree = true,bool isOnlyForCbC = false); +#else FunctionPass *createSROAPass(bool RequiresDomTree = true); - +#endif //===----------------------------------------------------------------------===// // // ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas
--- a/lib/Transforms/IPO/PassManagerBuilder.cpp Sat Jul 13 18:16:49 2013 +0900 +++ b/lib/Transforms/IPO/PassManagerBuilder.cpp Sun Jul 14 17:42:20 2013 +0900 @@ -106,15 +106,29 @@ // Add LibraryInfo if we have some. if (LibraryInfo) FPM.add(new TargetLibraryInfo(*LibraryInfo)); +#ifndef noCbC + if (UseNewSROA) + FPM.add(createSROAPass(true,true)); + else + FPM.add(createScalarReplAggregatesPass()); +#endif + if (OptLevel == 0) return; addInitialAliasAnalysisPasses(FPM); FPM.add(createCFGSimplificationPass()); +#ifndef noCbC + if (UseNewSROA) + FPM.add(createSROAPass(true,false)); + else + FPM.add(createScalarReplAggregatesPass()); +#else if (UseNewSROA) FPM.add(createSROAPass()); else FPM.add(createScalarReplAggregatesPass()); +#endif FPM.add(createEarlyCSEPass()); FPM.add(createLowerExpectIntrinsicPass()); } @@ -137,6 +151,7 @@ #ifndef noCbC MPM.add(createTailCallEliminationPass(true)); // Eliminate tail calls #endif + addExtensionsToPM(EP_EnabledOnOptLevel0, MPM); return; } @@ -172,10 +187,17 @@ // Start of function pass. // Break up aggregate allocas, using SSAUpdater. +#ifndef noCbC + if (UseNewSROA) + MPM.add(createSROAPass(/*RequiresDomTree*/ false,false)); + else + MPM.add(createScalarReplAggregatesPass(-1, false)); +#else if (UseNewSROA) MPM.add(createSROAPass(/*RequiresDomTree*/ false)); else MPM.add(createScalarReplAggregatesPass(-1, false)); +#endif MPM.add(createEarlyCSEPass()); // Catch trivial redundancies if (!DisableSimplifyLibCalls) MPM.add(createSimplifyLibCallsPass()); // Library Call Optimizations
--- a/lib/Transforms/Scalar/SROA.cpp Sat Jul 13 18:16:49 2013 +0900 +++ b/lib/Transforms/Scalar/SROA.cpp Sun Jul 14 17:42:20 2013 +0900 @@ -1391,11 +1391,20 @@ std::vector<AllocaInst *> PromotableAllocas; public: +#ifndef noCbC + SROA(bool RequiresDomTree = true,bool f = false) + : FunctionPass(ID), RequiresDomTree(RequiresDomTree), + C(0), TD(0), DT(0) { + initializeSROAPass(*PassRegistry::getPassRegistry()); + onlyForCbC = f; + } +#else SROA(bool RequiresDomTree = true) : FunctionPass(ID), RequiresDomTree(RequiresDomTree), C(0), TD(0), DT(0) { initializeSROAPass(*PassRegistry::getPassRegistry()); } +#endif bool runOnFunction(Function &F); void getAnalysisUsage(AnalysisUsage &AU) const; @@ -1414,15 +1423,25 @@ bool runOnAlloca(AllocaInst &AI); void deleteDeadInstructions(SmallPtrSet<AllocaInst *, 4> &DeletedAllocas); bool promoteAllocas(Function &F); +#ifndef noCbC + bool onlyForCbC; +public: + bool isOnlyForCbC(); +#endif }; } char SROA::ID = 0; +#ifndef noCbC +FunctionPass *llvm::createSROAPass(bool RequiresDomTree,bool isOnlyForCbC) { + return new SROA(RequiresDomTree,isOnlyForCbC); +} +#else FunctionPass *llvm::createSROAPass(bool RequiresDomTree) { return new SROA(RequiresDomTree); } - +#endif INITIALIZE_PASS_BEGIN(SROA, "sroa", "Scalar Replacement Of Aggregates", false, false) INITIALIZE_PASS_DEPENDENCY(DominatorTree) @@ -3719,6 +3738,19 @@ } DT = getAnalysisIfAvailable<DominatorTree>(); +#ifndef noCbC + if (isOnlyForCbC()) { //if only for CbC , we must check this function contains __code + bool contains__Code = false; + for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) + for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) + if (CallInst *CI = dyn_cast<CallInst>(I)) + if (CI->getCalledFunction()->getReturnType()->is__CodeTy()) + contains__Code = true; + if (!contains__Code) + return false; // if the function doesn't contains __code , we have not to touch it. + } +#endif + BasicBlock &EntryBB = F.getEntryBlock(); for (BasicBlock::iterator I = EntryBB.begin(), E = llvm::prior(EntryBB.end()); I != E; ++I) @@ -3762,3 +3794,9 @@ AU.addRequired<DominatorTree>(); AU.setPreservesCFG(); } + +#ifndef noCbC +bool SROA::isOnlyForCbC(){ + return onlyForCbC; +} +#endif
--- a/lib/Transforms/Scalar/TailRecursionElimination.cpp Sat Jul 13 18:16:49 2013 +0900 +++ b/lib/Transforms/Scalar/TailRecursionElimination.cpp Sun Jul 14 17:42:20 2013 +0900 @@ -121,7 +121,6 @@ #ifndef noCbC public: - void setCbCFlag(bool f); bool isOnlyForCbC(); #endif }; @@ -686,9 +685,6 @@ } #ifndef noCbC - void TailCallElim::setCbCFlag(bool f){ - onlyForCbC = f; -} bool TailCallElim::isOnlyForCbC(){ return onlyForCbC; }