32 #define DEBUG_TYPE "reg2mem"
34 STATISTIC(NumRegsDemoted,
"Number of registers demoted");
35 STATISTIC(NumPhisDemoted,
"Number of phi-nodes demoted");
53 if (UI->
getParent() != BB || isa<PHINode>(UI))
70 bool RegToMem::runOnFunction(
Function &
F) {
71 if (F.isDeclaration())
77 "Entry block to function must not have predecessors!");
83 while (isa<AllocaInst>(I)) ++
I;
88 "reg2mem alloca point", I);
92 std::list<Instruction*> WorkList;
97 if (!(isa<AllocaInst>(iib) && iib->getParent() == BBEntry) &&
99 WorkList.push_front(&*iib);
104 NumRegsDemoted += WorkList.size();
105 for (std::list<Instruction*>::iterator ilb = WorkList.begin(),
106 ile = WorkList.end(); ilb != ile; ++ilb)
116 if (isa<PHINode>(iib))
117 WorkList.push_front(&*iib);
120 NumPhisDemoted += WorkList.size();
121 for (std::list<Instruction*>::iterator ilb = WorkList.begin(),
122 ile = WorkList.end(); ilb != ile; ++ilb)
132 return new RegToMem();
ValuesClass< DataType > LLVM_END_WITH_NULL values(const char *Arg, DataType Val, const char *Desc,...)
AllocaInst * DemoteRegToStack(Instruction &X, bool VolatileLoads=false, Instruction *AllocaPoint=nullptr)
DemoteRegToStack - This function takes a virtual register computed by an Instruction and replaces it ...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
STATISTIC(NumFunctions,"Total number of functions")
char & DemoteRegisterToMemoryID
FunctionPass * createDemoteRegisterToMemoryPass()
static Constant * getNullValue(Type *Ty)
iterator begin()
Instruction iterator methods.
#define INITIALIZE_PASS_DEPENDENCY(depName)
This is the base class for all instructions that perform data casts.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
This class represents a no-op cast from one type to another.
AnalysisUsage & addPreservedID(const void *ID)
INITIALIZE_PASS_BEGIN(RegToMem,"reg2mem","Demote all values to stack slots", false, false) INITIALIZE_PASS_END(RegToMem
Demote all values to stack false
LLVM Basic Block Representation.
char & BreakCriticalEdgesID
Demote all values to stack slots
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
bool pred_empty(const BasicBlock *BB)
void initializeRegToMemPass(PassRegistry &)
AnalysisUsage & addRequiredID(const void *ID)
Module.h This file contains the declarations for the Module class.
iterator_range< user_iterator > users()
static IntegerType * getInt32Ty(LLVMContext &C)
AllocaInst * DemotePHIToStack(PHINode *P, Instruction *AllocaPoint=nullptr)
DemotePHIToStack - This function takes a virtual register computed by a phi node and replaces it with...
const BasicBlock * getParent() const