class AllocaInst;
class DominanceFrontier;
+class TargetData;
#include <vector>
/// isAllocaPromotable - Return true if this alloca is legal for promotion.
/// This is true if there are only loads and stores to the alloca...
///
-bool isAllocaPromotable(const AllocaInst *AI);
+bool isAllocaPromotable(const AllocaInst *AI, const TargetData &TD);
/// PromoteMemToReg - Promote the specified list of alloca instructions into
/// scalar registers, inserting PHI nodes as appropriate. This function makes
/// of the function at all. All allocas must be from the same function.
///
void PromoteMemToReg(const std::vector<AllocaInst*> &Allocas,
- DominanceFrontier &DF);
-
+ DominanceFrontier &DF, const TargetData &TD);
#endif
#include "llvm/Analysis/Dominators.h"
#include "llvm/Instructions.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/Target/TargetData.h"
#include "llvm/Support/InstVisitor.h"
#include "llvm/Support/CFG.h"
#include "Support/Statistic.h"
PromotedAllocas.reserve(PromotedValues.size());
for (unsigned i = 0, e = PromotedValues.size(); i != e; ++i)
PromotedAllocas.push_back(PromotedValues[i].first);
- PromoteMemToReg(PromotedAllocas, getAnalysis<DominanceFrontier>());
+ PromoteMemToReg(PromotedAllocas, getAnalysis<DominanceFrontier>(),
+ AA->getTargetData());
}
/// findPromotableValuesInLoop - Check the current loop for stores to definate
#include "llvm/Analysis/Dominators.h"
#include "llvm/iMemory.h"
#include "llvm/Function.h"
+#include "llvm/Target/TargetData.h"
#include "Support/Statistic.h"
namespace {
//
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<DominanceFrontier>();
+ AU.addRequired<TargetData>();
AU.setPreservesCFG();
}
};
bool PromotePass::runOnFunction(Function &F) {
std::vector<AllocaInst*> Allocas;
+ const TargetData &TD = getAnalysis<TargetData>();
BasicBlock &BB = F.getEntryNode(); // Get the entry node for the function
// 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, TD))
Allocas.push_back(AI);
if (!Allocas.empty()) {
- PromoteMemToReg(Allocas, getAnalysis<DominanceFrontier>());
+ PromoteMemToReg(Allocas, getAnalysis<DominanceFrontier>(), TD);
NumPromoted += Allocas.size();
return true;
}
/// isAllocaPromotable - Return true if this alloca is legal for promotion.
/// This is true if there are only loads and stores to the alloca...
///
-bool isAllocaPromotable(const AllocaInst *AI) {
+bool isAllocaPromotable(const AllocaInst *AI, const TargetData &TD) {
+ // FIXME: If the memory unit is of pointer or integer type, we can permit
+ // assignments to subsections of the memory unit.
+
// Only allow direct loads and stores...
for (Value::use_const_iterator UI = AI->use_begin(), UE = AI->use_end();
UI != UE; ++UI) // Loop over all of the uses of the alloca
struct PromoteMem2Reg {
const std::vector<AllocaInst*> &Allocas; // the alloca instructions..
DominanceFrontier &DF;
+ const TargetData &TD;
std::map<Instruction*, unsigned> AllocaLookup; // reverse mapping of above
std::vector<PHINode*> > NewPhiNodes; // the PhiNodes we're adding
public:
- PromoteMem2Reg(const std::vector<AllocaInst*> &A, DominanceFrontier &df)
- :Allocas(A), DF(df) {}
+ PromoteMem2Reg(const std::vector<AllocaInst*> &A, DominanceFrontier &df,
+ const TargetData &td)
+ : Allocas(A), DF(df), TD(td) {}
void run();
Function &F = *DF.getRoot()->getParent();
for (unsigned i = 0, e = Allocas.size(); i != e; ++i) {
- assert(isAllocaPromotable(Allocas[i]) &&
+ assert(isAllocaPromotable(Allocas[i], TD) &&
"Cannot promote non-promotable alloca!");
assert(Allocas[i]->getParent()->getParent() == &F &&
"All allocas should be in the same function, which is same as DF!");
/// of the function at all. All allocas must be from the same function.
///
void PromoteMemToReg(const std::vector<AllocaInst*> &Allocas,
- DominanceFrontier &DF) {
- PromoteMem2Reg(Allocas, DF).run();
+ DominanceFrontier &DF, const TargetData &TD) {
+ PromoteMem2Reg(Allocas, DF, TD).run();
}