refactor some code, no functionality change. On the path to PR1639

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41929 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2007-09-13 17:29:05 +00:00
parent c451f9c167
commit 330245e90b

View File

@@ -891,26 +891,20 @@ static bool GlobalLoadUsesSimpleEnoughForHeapSRA(GlobalVariable *GV) {
return true; return true;
} }
/// RewriteUsesOfLoadForHeapSRoA - We are performing Heap SRoA on a global. Ptr /// RewriteHeapSROALoadUser - Given a load instruction and a value derived from
/// is a value loaded from the global. Eliminate all uses of Ptr, making them /// the load, rewrite the derived value to use the HeapSRoA'd load.
/// use FieldGlobals instead. All uses of loaded values satisfy static void RewriteHeapSROALoadUser(LoadInst *Load, Instruction *LoadUser,
/// GlobalLoadUsesSimpleEnoughForHeapSRA. const std::vector<GlobalVariable*> &FieldGlobals,
static void RewriteUsesOfLoadForHeapSRoA(LoadInst *Ptr, std::vector<Value *> &InsertedLoadsForPtr) {
const std::vector<GlobalVariable*> &FieldGlobals) {
std::vector<Value *> InsertedLoadsForPtr;
//InsertedLoadsForPtr.resize(FieldGlobals.size());
while (!Ptr->use_empty()) {
Instruction *User = Ptr->use_back();
// If this is a comparison against null, handle it. // If this is a comparison against null, handle it.
if (ICmpInst *SCI = dyn_cast<ICmpInst>(User)) { if (ICmpInst *SCI = dyn_cast<ICmpInst>(LoadUser)) {
assert(isa<ConstantPointerNull>(SCI->getOperand(1))); assert(isa<ConstantPointerNull>(SCI->getOperand(1)));
// If we have a setcc of the loaded pointer, we can use a setcc of any // If we have a setcc of the loaded pointer, we can use a setcc of any
// field. // field.
Value *NPtr; Value *NPtr;
if (InsertedLoadsForPtr.empty()) { if (InsertedLoadsForPtr.empty()) {
NPtr = new LoadInst(FieldGlobals[0], Ptr->getName()+".f0", Ptr); NPtr = new LoadInst(FieldGlobals[0], Load->getName()+".f0", Load);
InsertedLoadsForPtr.push_back(Ptr); InsertedLoadsForPtr.push_back(Load);
} else { } else {
NPtr = InsertedLoadsForPtr.back(); NPtr = InsertedLoadsForPtr.back();
} }
@@ -920,11 +914,11 @@ static void RewriteUsesOfLoadForHeapSRoA(LoadInst *Ptr,
SCI->getName(), SCI); SCI->getName(), SCI);
SCI->replaceAllUsesWith(New); SCI->replaceAllUsesWith(New);
SCI->eraseFromParent(); SCI->eraseFromParent();
continue; return;
} }
// Otherwise, this should be: 'getelementptr Ptr, Idx, uint FieldNo ...' // Otherwise, this should be: 'getelementptr Ptr, Idx, uint FieldNo ...'
GetElementPtrInst *GEPI = cast<GetElementPtrInst>(User); GetElementPtrInst *GEPI = cast<GetElementPtrInst>(LoadUser);
assert(GEPI->getNumOperands() >= 3 && isa<ConstantInt>(GEPI->getOperand(2)) assert(GEPI->getNumOperands() >= 3 && isa<ConstantInt>(GEPI->getOperand(2))
&& "Unexpected GEPI!"); && "Unexpected GEPI!");
@@ -934,8 +928,8 @@ static void RewriteUsesOfLoadForHeapSRoA(LoadInst *Ptr,
InsertedLoadsForPtr.resize(FieldNo+1); InsertedLoadsForPtr.resize(FieldNo+1);
if (InsertedLoadsForPtr[FieldNo] == 0) if (InsertedLoadsForPtr[FieldNo] == 0)
InsertedLoadsForPtr[FieldNo] = new LoadInst(FieldGlobals[FieldNo], InsertedLoadsForPtr[FieldNo] = new LoadInst(FieldGlobals[FieldNo],
Ptr->getName()+".f" + Load->getName()+".f" +
utostr(FieldNo), Ptr); utostr(FieldNo), Load);
Value *NewPtr = InsertedLoadsForPtr[FieldNo]; Value *NewPtr = InsertedLoadsForPtr[FieldNo];
// Create the new GEP idx vector. // Create the new GEP idx vector.
@@ -947,7 +941,19 @@ static void RewriteUsesOfLoadForHeapSRoA(LoadInst *Ptr,
GEPI->getName(), GEPI); GEPI->getName(), GEPI);
GEPI->replaceAllUsesWith(NGEPI); GEPI->replaceAllUsesWith(NGEPI);
GEPI->eraseFromParent(); GEPI->eraseFromParent();
} }
/// RewriteUsesOfLoadForHeapSRoA - We are performing Heap SRoA on a global. Ptr
/// is a value loaded from the global. Eliminate all uses of Ptr, making them
/// use FieldGlobals instead. All uses of loaded values satisfy
/// GlobalLoadUsesSimpleEnoughForHeapSRA.
static void RewriteUsesOfLoadForHeapSRoA(LoadInst *Load,
const std::vector<GlobalVariable*> &FieldGlobals) {
std::vector<Value *> InsertedLoadsForPtr;
//InsertedLoadsForPtr.resize(FieldGlobals.size());
while (!Load->use_empty())
RewriteHeapSROALoadUser(Load, Load->use_back(),
FieldGlobals, InsertedLoadsForPtr);
} }
/// PerformHeapAllocSRoA - MI is an allocation of an array of structures. Break /// PerformHeapAllocSRoA - MI is an allocation of an array of structures. Break