From: Chris Lattner Date: Fri, 14 Jan 2011 08:13:00 +0000 (+0000) Subject: split SROA into two passes: one that uses DomFrontiers (-scalarrepl) X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=b352d6eb49927a7c707cbd9046cfc525b0c3f2d7;p=oota-llvm.git split SROA into two passes: one that uses DomFrontiers (-scalarrepl) and one that uses SSAUpdater (-scalarrepl-ssa) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123436 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/InitializePasses.h b/include/llvm/InitializePasses.h index 07812809764..d86b19992ec 100644 --- a/include/llvm/InitializePasses.h +++ b/include/llvm/InitializePasses.h @@ -193,7 +193,8 @@ void initializeRegisterCoalescerAnalysisGroup(PassRegistry&); void initializeRenderMachineFunctionPass(PassRegistry&); void initializeSCCPPass(PassRegistry&); void initializeSRETPromotionPass(PassRegistry&); -void initializeSROAPass(PassRegistry&); +void initializeSROA_DFPass(PassRegistry&); +void initializeSROA_SSAUpPass(PassRegistry&); void initializeScalarEvolutionAliasAnalysisPass(PassRegistry&); void initializeScalarEvolutionPass(PassRegistry&); void initializeSimpleInlinerPass(PassRegistry&); diff --git a/include/llvm/Transforms/Scalar.h b/include/llvm/Transforms/Scalar.h index 039e4a2f408..9a87eab3fee 100644 --- a/include/llvm/Transforms/Scalar.h +++ b/include/llvm/Transforms/Scalar.h @@ -73,7 +73,8 @@ FunctionPass *createAggressiveDCEPass(); // ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas // if possible. // -FunctionPass *createScalarReplAggregatesPass(signed Threshold = -1); +FunctionPass *createScalarReplAggregatesPass(signed Threshold = -1, + bool UseDomFrontier = true); //===----------------------------------------------------------------------===// // diff --git a/lib/Transforms/Scalar/Scalar.cpp b/lib/Transforms/Scalar/Scalar.cpp index 2b13bcacc19..1d0ca7d071e 100644 --- a/lib/Transforms/Scalar/Scalar.cpp +++ b/lib/Transforms/Scalar/Scalar.cpp @@ -53,7 +53,8 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) { initializeRegToMemPass(Registry); initializeSCCPPass(Registry); initializeIPSCCPPass(Registry); - initializeSROAPass(Registry); + initializeSROA_DFPass(Registry); + initializeSROA_SSAUpPass(Registry); initializeCFGSimplifyPassPass(Registry); initializeSimplifyHalfPowrLibCallsPass(Registry); initializeSimplifyLibCallsPass(Registry); diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp index e644ccf1383..f66a7193312 100644 --- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp +++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp @@ -52,15 +52,10 @@ STATISTIC(NumPromoted, "Number of allocas promoted"); STATISTIC(NumConverted, "Number of aggregates converted to scalar"); STATISTIC(NumGlobals, "Number of allocas copied from constant global"); -enum { - UsePromoteMemToReg = 1 -}; - namespace { struct SROA : public FunctionPass { - static char ID; // Pass identification, replacement for typeid - explicit SROA(signed T = -1) : FunctionPass(ID) { - initializeSROAPass(*PassRegistry::getPassRegistry()); + SROA(int T, bool hasDF, char &ID) + : FunctionPass(ID), HasDomFrontiers(hasDF) { if (T == -1) SRThreshold = 128; else @@ -72,17 +67,8 @@ namespace { bool performScalarRepl(Function &F); bool performPromotion(Function &F); - // getAnalysisUsage - This pass does not require any passes, but we know it - // will not alter the CFG, so say so. - virtual void getAnalysisUsage(AnalysisUsage &AU) const { - if (UsePromoteMemToReg) { - AU.addRequired(); - AU.addRequired(); - } - AU.setPreservesCFG(); - } - private: + bool HasDomFrontiers; TargetData *TD; /// DeadInsts - Keep track of instructions we have made dead, so that @@ -142,19 +128,62 @@ namespace { static MemTransferInst *isOnlyCopiedFromConstantGlobal(AllocaInst *AI); }; + + // SROA_DF - SROA that uses DominanceFrontier. + struct SROA_DF : public SROA { + static char ID; + public: + SROA_DF(int T = -1) : SROA(T, true, ID) { + initializeSROA_DFPass(*PassRegistry::getPassRegistry()); + } + + // getAnalysisUsage - This pass does not require any passes, but we know it + // will not alter the CFG, so say so. + virtual void getAnalysisUsage(AnalysisUsage &AU) const { + AU.addRequired(); + AU.addRequired(); + AU.setPreservesCFG(); + } + }; + + // SROA_SSAUp - SROA that uses SSAUpdater. + struct SROA_SSAUp : public SROA { + static char ID; + public: + SROA_SSAUp(int T = -1) : SROA(T, false, ID) { + initializeSROA_SSAUpPass(*PassRegistry::getPassRegistry()); + } + + // getAnalysisUsage - This pass does not require any passes, but we know it + // will not alter the CFG, so say so. + virtual void getAnalysisUsage(AnalysisUsage &AU) const { + AU.setPreservesCFG(); + } + }; + } -char SROA::ID = 0; -INITIALIZE_PASS_BEGIN(SROA, "scalarrepl", - "Scalar Replacement of Aggregates", false, false) +char SROA_DF::ID = 0; +char SROA_SSAUp::ID = 0; + +INITIALIZE_PASS_BEGIN(SROA_DF, "scalarrepl", + "Scalar Replacement of Aggregates (DF)", false, false) INITIALIZE_PASS_DEPENDENCY(DominatorTree) INITIALIZE_PASS_DEPENDENCY(DominanceFrontier) -INITIALIZE_PASS_END(SROA, "scalarrepl", - "Scalar Replacement of Aggregates", false, false) +INITIALIZE_PASS_END(SROA_DF, "scalarrepl", + "Scalar Replacement of Aggregates (DF)", false, false) + +INITIALIZE_PASS_BEGIN(SROA_SSAUp, "scalarrepl-ssa", + "Scalar Replacement of Aggregates (SSAUp)", false, false) +INITIALIZE_PASS_END(SROA_SSAUp, "scalarrepl-ssa", + "Scalar Replacement of Aggregates (SSAUp)", false, false) // Public interface to the ScalarReplAggregates pass -FunctionPass *llvm::createScalarReplAggregatesPass(signed int Threshold) { - return new SROA(Threshold); +FunctionPass *llvm::createScalarReplAggregatesPass(int Threshold, + bool UseDomFrontier) { + if (UseDomFrontier) + return new SROA_DF(Threshold); + return new SROA_SSAUp(Threshold); } @@ -954,7 +983,7 @@ bool SROA::performPromotion(Function &F) { std::vector Allocas; DominatorTree *DT = 0; DominanceFrontier *DF = 0; - if (UsePromoteMemToReg) { + if (HasDomFrontiers) { DT = &getAnalysis(); DF = &getAnalysis(); } @@ -975,7 +1004,7 @@ bool SROA::performPromotion(Function &F) { if (Allocas.empty()) break; - if (UsePromoteMemToReg) + if (HasDomFrontiers) PromoteMemToReg(Allocas, *DT, *DF); else { SSAUpdater SSA;