Thread DataLayout through the callers and into mem2reg. This will be
authorChandler Carruth <chandlerc@gmail.com>
Sun, 28 Jul 2013 06:43:11 +0000 (06:43 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sun, 28 Jul 2013 06:43:11 +0000 (06:43 +0000)
useful in a subsequent patch, but causes an unfortunate amount of noise,
so I pulled it out into a separate patch.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187322 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Transforms/Utils/PromoteMemToReg.h
lib/Transforms/Scalar/SROA.cpp
lib/Transforms/Scalar/ScalarReplAggregates.cpp
lib/Transforms/Utils/Mem2Reg.cpp
lib/Transforms/Utils/PromoteMemoryToRegister.cpp

index 22f46e5fc963c55b822a77ec5040272f9820fb26..2f28f3333f9c5bc77b9cbd782b6ffc5e1061d863 100644 (file)
@@ -20,6 +20,7 @@
 namespace llvm {
 
 class AllocaInst;
+class DataLayout;
 class DominatorTree;
 class AliasSetTracker;
 
@@ -29,7 +30,7 @@ class AliasSetTracker;
 /// (transitively) using this alloca. This also enforces that there is only
 /// ever one layer of bitcasts or GEPs between the alloca and the lifetime
 /// markers.
-bool isAllocaPromotable(const AllocaInst *AI);
+bool isAllocaPromotable(const AllocaInst *AI, const DataLayout *DL);
 
 /// \brief Promote the specified list of alloca instructions into scalar
 /// registers, inserting PHI nodes as appropriate.
@@ -41,7 +42,7 @@ bool isAllocaPromotable(const AllocaInst *AI);
 /// If AST is specified, the specified tracker is updated to reflect changes
 /// made to the IR.
 void PromoteMemToReg(ArrayRef<AllocaInst *> Allocas, DominatorTree &DT,
-                     AliasSetTracker *AST = 0);
+                     const DataLayout *DL, AliasSetTracker *AST = 0);
 
 } // End llvm namespace
 
index 5afd83008a08fec07be6a6d7004d1994fac61a43..1525caa868b801bc2ccf95814fa4aadca475e014 100644 (file)
@@ -3376,7 +3376,7 @@ bool SROA::promoteAllocas(Function &F) {
 
   if (DT && !ForceSSAUpdater) {
     DEBUG(dbgs() << "Promoting allocas with mem2reg...\n");
-    PromoteMemToReg(PromotableAllocas, *DT);
+    PromoteMemToReg(PromotableAllocas, *DT, DL);
     PromotableAllocas.clear();
     return true;
   }
index 33bbe1516306d9719ae977efa5db24b98d4093b2..73b2edfac2c9db76b695bde7ed2fce0a9b991113 100644 (file)
@@ -1426,7 +1426,7 @@ bool SROA::performPromotion(Function &F) {
     if (Allocas.empty()) break;
 
     if (HasDomTree)
-      PromoteMemToReg(Allocas, *DT);
+      PromoteMemToReg(Allocas, *DT, TD);
     else {
       SSAUpdater SSA;
       for (unsigned i = 0, e = Allocas.size(); i != e; ++i) {
index 61b3965d8f119f4b5d1efc0242b19b0501515b90..ebd7db6210caecea445d143cd86c353acd2a1b77 100644 (file)
@@ -16,6 +16,7 @@
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/Dominators.h"
+#include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/Transforms/Utils/PromoteMemToReg.h"
@@ -27,6 +28,7 @@ STATISTIC(NumPromoted, "Number of alloca's promoted");
 namespace {
   struct PromotePass : public FunctionPass {
     static char ID; // Pass identification, replacement for typeid
+
     PromotePass() : FunctionPass(ID) {
       initializePromotePassPass(*PassRegistry::getPassRegistry());
     }
@@ -62,6 +64,7 @@ bool PromotePass::runOnFunction(Function &F) {
   bool Changed  = false;
 
   DominatorTree &DT = getAnalysis<DominatorTree>();
+  const DataLayout *DL = getAnalysisIfAvailable<DataLayout>();
 
   while (1) {
     Allocas.clear();
@@ -70,12 +73,12 @@ bool PromotePass::runOnFunction(Function &F) {
     // the entry node
     for (BasicBlock::iterator I = BB.begin(), E = --BB.end(); I != E; ++I)
       if (AllocaInst *AI = dyn_cast<AllocaInst>(I))       // Is it an alloca?
-        if (isAllocaPromotable(AI))
+        if (isAllocaPromotable(AI, DL))
           Allocas.push_back(AI);
 
     if (Allocas.empty()) break;
 
-    PromoteMemToReg(Allocas, DT);
+    PromoteMemToReg(Allocas, DT, DL);
     NumPromoted += Allocas.size();
     Changed = true;
   }
index b3eaa1319afbf307e104eb92c4a64218d1b5052e..691018099706c147ebcbebbea9dcf41a8ff4ed2f 100644 (file)
@@ -61,6 +61,8 @@ STATISTIC(NumPHIInsert,     "Number of PHI nodes inserted");
 namespace {
 
 struct AllocaInfo : private InstVisitor<AllocaInfo, bool> {
+  const DataLayout *DL;
+
   SmallVector<BasicBlock *, 32> DefiningBlocks;
   SmallVector<BasicBlock *, 32> UsingBlocks;
   SmallVector<Instruction *, 8> DeadInsts;
@@ -73,6 +75,8 @@ struct AllocaInfo : private InstVisitor<AllocaInfo, bool> {
   Value *AllocaPointerVal;
   DbgDeclareInst *DbgDeclare;
 
+  AllocaInfo(const DataLayout *DL) : DL(DL) {}
+
   void clear() {
     DefiningBlocks.clear();
     UsingBlocks.clear();
@@ -274,6 +278,7 @@ struct PromoteMem2Reg {
   std::vector<AllocaInst *> Allocas;
   DominatorTree &DT;
   DIBuilder DIB;
+  const DataLayout *DL;
 
   /// An AliasSetTracker object to update.  If null, don't update it.
   AliasSetTracker *AST;
@@ -319,9 +324,9 @@ struct PromoteMem2Reg {
 
 public:
   PromoteMem2Reg(ArrayRef<AllocaInst *> Allocas, DominatorTree &DT,
-                 AliasSetTracker *AST)
+                 const DataLayout *DL, AliasSetTracker *AST)
       : Allocas(Allocas.begin(), Allocas.end()), DT(DT),
-        DIB(*DT.getRoot()->getParent()->getParent()), AST(AST) {}
+        DIB(*DT.getRoot()->getParent()->getParent()), DL(DL), AST(AST) {}
 
   void run();
 
@@ -585,7 +590,7 @@ void PromoteMem2Reg::run() {
     PointerAllocaValues.resize(Allocas.size());
   AllocaDbgDeclares.resize(Allocas.size());
 
-  AllocaInfo Info;
+  AllocaInfo Info(DL);
   LargeBlockInfo LBI;
 
   for (unsigned AllocaNum = 0; AllocaNum != Allocas.size(); ++AllocaNum) {
@@ -1140,19 +1145,19 @@ NextIteration:
   goto NextIteration;
 }
 
-bool llvm::isAllocaPromotable(const AllocaInst *AI) {
+bool llvm::isAllocaPromotable(const AllocaInst *AI, const DataLayout *DL) {
   // We cast away constness because we re-use the non-const analysis that the
   // actual promotion routine uses. While it is non-const, it doesn't actually
   // mutate anything at this phase, and we discard the non-const results that
   // promotion uses to mutate the alloca.
-  return AllocaInfo().analyzeAlloca(*const_cast<AllocaInst *>(AI));
+  return AllocaInfo(DL).analyzeAlloca(*const_cast<AllocaInst *>(AI));
 }
 
-void llvm::PromoteMemToReg(ArrayRef<AllocaInst *> Allocas,
-                           DominatorTree &DT, AliasSetTracker *AST) {
+void llvm::PromoteMemToReg(ArrayRef<AllocaInst *> Allocas, DominatorTree &DT,
+                           const DataLayout *DL, AliasSetTracker *AST) {
   // If there is nothing to do, bail out...
   if (Allocas.empty())
     return;
 
-  PromoteMem2Reg(Allocas, DT, AST).run();
+  PromoteMem2Reg(Allocas, DT, DL, AST).run();
 }