aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-08-29 23:38:20 +0000
committerChris Lattner <sabre@nondot.org>2006-08-29 23:38:20 +0000
commit1bb6f0643dc4f5ecc2db295cf432b22def3a2b2f (patch)
treeb8537d3dac69d79bf46b291415b58d5548f06c55 /tools
parent6d8fbef015ff836bcb8f64f52c49805e43f8ea9f (diff)
downloadexternal_llvm-1bb6f0643dc4f5ecc2db295cf432b22def3a2b2f.zip
external_llvm-1bb6f0643dc4f5ecc2db295cf432b22def3a2b2f.tar.gz
external_llvm-1bb6f0643dc4f5ecc2db295cf432b22def3a2b2f.tar.bz2
Code cleanups, no functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29969 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/bugpoint/ExtractFunction.cpp66
1 files changed, 30 insertions, 36 deletions
diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp
index c172946..756ef8b 100644
--- a/tools/bugpoint/ExtractFunction.cpp
+++ b/tools/bugpoint/ExtractFunction.cpp
@@ -248,11 +248,11 @@ static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2){
}
}
-//// RewriteUsesInNewModule - takes a Module and a reference to a globalvalue
-//// (OrigVal) in that module and changes the reference to a different
-//// globalvalue (NewVal) in a seperate module.
+/// RewriteUsesInNewModule - Given a constant 'OrigVal' and a module 'OrigMod',
+/// find all uses of the constant. If they are not in the specified module,
+/// replace them with uses of another constant 'NewVal'.
static void RewriteUsesInNewModule(Constant *OrigVal, Constant *NewVal,
- Module *TargetMod) {
+ Module *OrigMod) {
assert(OrigVal->getType() == NewVal->getType() &&
"Can't replace something with a different type");
for (Value::use_iterator UI = OrigVal->use_begin(), E = OrigVal->use_end();
@@ -260,20 +260,17 @@ static void RewriteUsesInNewModule(Constant *OrigVal, Constant *NewVal,
Value::use_iterator TmpUI = UI++;
User *U = *TmpUI;
if (Instruction *Inst = dyn_cast<Instruction>(U)) {
- Module *InstM = Inst->getParent()->getParent()->getParent();
- if (InstM != TargetMod) {
- TmpUI.getUse() = NewVal;
- }
+ if (Inst->getParent()->getParent()->getParent() != OrigMod)
+ TmpUI.getUse() = NewVal;
} else if (GlobalVariable *GV = dyn_cast<GlobalVariable>(U)) {
- if (GV->getParent() != TargetMod) {
+ if (GV->getParent() != OrigMod)
TmpUI.getUse() = NewVal;
- }
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U)) {
// If nothing uses this, don't bother making a copy.
if (CE->use_empty()) continue;
Constant *NewCE = CE->getWithOperandReplaced(TmpUI.getOperandNo(),
NewVal);
- RewriteUsesInNewModule(CE, NewCE, TargetMod);
+ RewriteUsesInNewModule(CE, NewCE, OrigMod);
} else if (ConstantStruct *CS = dyn_cast<ConstantStruct>(U)) {
// If nothing uses this, don't bother making a copy.
if (CS->use_empty()) continue;
@@ -282,7 +279,7 @@ static void RewriteUsesInNewModule(Constant *OrigVal, Constant *NewVal,
for (unsigned i = 0, e = CS->getNumOperands(); i != e; ++i)
Ops.push_back(i == OpNo ? NewVal : CS->getOperand(i));
Constant *NewStruct = ConstantStruct::get(Ops);
- RewriteUsesInNewModule(CS, NewStruct, TargetMod);
+ RewriteUsesInNewModule(CS, NewStruct, OrigMod);
} else if (ConstantPacked *CP = dyn_cast<ConstantPacked>(U)) {
// If nothing uses this, don't bother making a copy.
if (CP->use_empty()) continue;
@@ -291,7 +288,7 @@ static void RewriteUsesInNewModule(Constant *OrigVal, Constant *NewVal,
for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
Ops.push_back(i == OpNo ? NewVal : CP->getOperand(i));
Constant *NewPacked = ConstantPacked::get(Ops);
- RewriteUsesInNewModule(CP, NewPacked, TargetMod);
+ RewriteUsesInNewModule(CP, NewPacked, OrigMod);
} else if (ConstantArray *CA = dyn_cast<ConstantArray>(U)) {
// If nothing uses this, don't bother making a copy.
if (CA->use_empty()) continue;
@@ -301,7 +298,7 @@ static void RewriteUsesInNewModule(Constant *OrigVal, Constant *NewVal,
Ops.push_back(i == OpNo ? NewVal : CA->getOperand(i));
}
Constant *NewArray = ConstantArray::get(CA->getType(), Ops);
- RewriteUsesInNewModule(CA, NewArray, TargetMod);
+ RewriteUsesInNewModule(CA, NewArray, OrigMod);
} else {
assert(0 && "Unexpected user");
}
@@ -345,42 +342,38 @@ Module *llvm::SplitFunctionsOutOfModule(Module *M,
// Adding specified functions to new module...
for (Module::iterator I = M->begin(), E = M->end(); I != E;) {
OrigGlobals.push_back(I);
- if(TestFunctions.count(std::make_pair(I->getName(), I->getType()))) {
+ if (TestFunctions.count(std::make_pair(I->getName(), I->getType()))) {
Module::iterator tempI = I;
I++;
- Function * func = new Function(tempI->getFunctionType(),
+ Function *Func = new Function(tempI->getFunctionType(),
GlobalValue::ExternalLinkage);
- M->getFunctionList().insert(tempI, func);
+ M->getFunctionList().insert(tempI, Func);
New->getFunctionList().splice(New->end(),
M->getFunctionList(),
tempI);
- func->setName(tempI->getName());
- func->setCallingConv(tempI->getCallingConv());
- GlobalToPrototypeMap[tempI] = func;
- // NEW TO OLD
+ Func->setName(tempI->getName());
+ Func->setCallingConv(tempI->getCallingConv());
+ GlobalToPrototypeMap[tempI] = Func;
} else {
- Function * func = new Function(I->getFunctionType(),
+ Function *Func = new Function(I->getFunctionType(),
GlobalValue::ExternalLinkage,
I->getName(),
New);
- func->setCallingConv(I->getCallingConv());
- GlobalToPrototypeMap[I] = func;
- // NEW TO OLD
+ Func->setCallingConv(I->getCallingConv());
+ GlobalToPrototypeMap[I] = Func;
I++;
}
}
- //copy over global list
- for (Module::global_iterator I = M->global_begin(),
- E = M->global_end(); I != E; ++I) {
+ // Copy over global variable list.
+ for (Module::global_iterator I = M->global_begin(), E = M->global_end();
+ I != E; ++I) {
OrigGlobals.push_back(I);
- GlobalVariable *glob = new GlobalVariable (I->getType()->getElementType(),
- I->isConstant(),
- GlobalValue::ExternalLinkage,
- 0,
- I->getName(),
- New);
- GlobalToPrototypeMap[I] = glob;
+ GlobalVariable *G = new GlobalVariable(I->getType()->getElementType(),
+ I->isConstant(),
+ GlobalValue::ExternalLinkage,
+ 0, I->getName(), New);
+ GlobalToPrototypeMap[I] = G;
}
// Copy all of the type symbol table entries over.
@@ -394,7 +387,8 @@ Module *llvm::SplitFunctionsOutOfModule(Module *M,
// the prototype.
for (unsigned i = 0, e = OrigGlobals.size(); i != e; ++i) {
assert(OrigGlobals[i]->getName() ==
- GlobalToPrototypeMap[OrigGlobals[i]]->getName());
+ GlobalToPrototypeMap[OrigGlobals[i]]->getName() &&
+ "Something got renamed?");
RewriteUsesInNewModule(OrigGlobals[i], GlobalToPrototypeMap[OrigGlobals[i]],
OrigGlobals[i]->getParent());
}