namespace llvm {
class AllocaInst;
+class DataLayout;
class DominatorTree;
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.
/// 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
if (DT && !ForceSSAUpdater) {
DEBUG(dbgs() << "Promoting allocas with mem2reg...\n");
- PromoteMemToReg(PromotableAllocas, *DT);
+ PromoteMemToReg(PromotableAllocas, *DT, DL);
PromotableAllocas.clear();
return true;
}
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) {
#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"
namespace {
struct PromotePass : public FunctionPass {
static char ID; // Pass identification, replacement for typeid
+
PromotePass() : FunctionPass(ID) {
initializePromotePassPass(*PassRegistry::getPassRegistry());
}
bool Changed = false;
DominatorTree &DT = getAnalysis<DominatorTree>();
+ const DataLayout *DL = getAnalysisIfAvailable<DataLayout>();
while (1) {
Allocas.clear();
// 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;
}
namespace {
struct AllocaInfo : private InstVisitor<AllocaInfo, bool> {
+ const DataLayout *DL;
+
SmallVector<BasicBlock *, 32> DefiningBlocks;
SmallVector<BasicBlock *, 32> UsingBlocks;
SmallVector<Instruction *, 8> DeadInsts;
Value *AllocaPointerVal;
DbgDeclareInst *DbgDeclare;
+ AllocaInfo(const DataLayout *DL) : DL(DL) {}
+
void clear() {
DefiningBlocks.clear();
UsingBlocks.clear();
std::vector<AllocaInst *> Allocas;
DominatorTree &DT;
DIBuilder DIB;
+ const DataLayout *DL;
/// An AliasSetTracker object to update. If null, don't update it.
AliasSetTracker *AST;
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();
PointerAllocaValues.resize(Allocas.size());
AllocaDbgDeclares.resize(Allocas.size());
- AllocaInfo Info;
+ AllocaInfo Info(DL);
LargeBlockInfo LBI;
for (unsigned AllocaNum = 0; AllocaNum != Allocas.size(); ++AllocaNum) {
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();
}