Make this code not depend on LinkModules leaving the second argument unmolested.
llvm-svn: 17874
This commit is contained in:
parent
09e9f2a37b
commit
d308797cae
|
@ -143,9 +143,18 @@ Module *BugDriver::ExtractLoop(Module *M) {
|
||||||
|
|
||||||
// Check to see if we created any new functions. If not, no loops were
|
// Check to see if we created any new functions. If not, no loops were
|
||||||
// extracted and we should return null.
|
// extracted and we should return null.
|
||||||
if (M->size() == NewM->size()) {
|
static unsigned NumExtracted = 15;
|
||||||
|
|
||||||
|
if (M->size() == NewM->size() || --NumExtracted == 0) {
|
||||||
delete NewM;
|
delete NewM;
|
||||||
return 0;
|
return 0;
|
||||||
|
} else {
|
||||||
|
assert(M->size() < NewM->size() && "Loop extract removed functions?");
|
||||||
|
Module::iterator MI = NewM->begin();
|
||||||
|
for (unsigned i = 0, e = M->size(); i != e; ++i)
|
||||||
|
++MI;
|
||||||
|
for (; MI != NewM->end(); ++MI)
|
||||||
|
std::cerr << "NEW FUNCTION: " << *MI;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewM;
|
return NewM;
|
||||||
|
|
|
@ -90,7 +90,7 @@ struct ListReducer {
|
||||||
// could. If there is more two elements in the list, try deleting interior
|
// could. If there is more two elements in the list, try deleting interior
|
||||||
// elements and testing that.
|
// elements and testing that.
|
||||||
//
|
//
|
||||||
if (TheList.size() > 2) {
|
if (0 && TheList.size() > 2) {
|
||||||
bool Changed = true;
|
bool Changed = true;
|
||||||
std::vector<ElTy> EmptyList;
|
std::vector<ElTy> EmptyList;
|
||||||
while (Changed) {
|
while (Changed) {
|
||||||
|
|
|
@ -171,13 +171,16 @@ static bool TestMergedProgram(BugDriver &BD, Module *M1, Module *M2,
|
||||||
bool DeleteInputs) {
|
bool DeleteInputs) {
|
||||||
// Link the two portions of the program back to together.
|
// Link the two portions of the program back to together.
|
||||||
std::string ErrorMsg;
|
std::string ErrorMsg;
|
||||||
if (!DeleteInputs) M1 = CloneModule(M1);
|
if (!DeleteInputs) {
|
||||||
|
M1 = CloneModule(M1);
|
||||||
|
M2 = CloneModule(M2);
|
||||||
|
}
|
||||||
if (LinkModules(M1, M2, &ErrorMsg)) {
|
if (LinkModules(M1, M2, &ErrorMsg)) {
|
||||||
std::cerr << BD.getToolName() << ": Error linking modules together:"
|
std::cerr << BD.getToolName() << ": Error linking modules together:"
|
||||||
<< ErrorMsg << '\n';
|
<< ErrorMsg << '\n';
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (DeleteInputs) delete M2; // We are done with this module...
|
delete M2; // We are done with this module.
|
||||||
|
|
||||||
Module *OldProgram = BD.swapProgramIn(M1);
|
Module *OldProgram = BD.swapProgramIn(M1);
|
||||||
|
|
||||||
|
@ -289,6 +292,12 @@ static bool ExtractLoops(BugDriver &BD,
|
||||||
|
|
||||||
std::cout << "*** Loop extraction successful!\n";
|
std::cout << "*** Loop extraction successful!\n";
|
||||||
|
|
||||||
|
std::vector<std::pair<std::string, const FunctionType*> > MisCompFunctions;
|
||||||
|
for (Module::iterator I = ToOptimizeLoopExtracted->begin(),
|
||||||
|
E = ToOptimizeLoopExtracted->end(); I != E; ++I)
|
||||||
|
MisCompFunctions.push_back(std::make_pair(I->getName(),
|
||||||
|
I->getFunctionType()));
|
||||||
|
|
||||||
// Okay, great! Now we know that we extracted a loop and that loop
|
// Okay, great! Now we know that we extracted a loop and that loop
|
||||||
// extraction both didn't break the program, and didn't mask the problem.
|
// extraction both didn't break the program, and didn't mask the problem.
|
||||||
// Replace the current program with the loop extracted version, and try to
|
// Replace the current program with the loop extracted version, and try to
|
||||||
|
@ -299,21 +308,18 @@ static bool ExtractLoops(BugDriver &BD,
|
||||||
<< ErrorMsg << '\n';
|
<< ErrorMsg << '\n';
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
delete ToOptimizeLoopExtracted;
|
||||||
|
|
||||||
// All of the Function*'s in the MiscompiledFunctions list are in the old
|
// All of the Function*'s in the MiscompiledFunctions list are in the old
|
||||||
// module. Update this list to include all of the functions in the
|
// module. Update this list to include all of the functions in the
|
||||||
// optimized and loop extracted module.
|
// optimized and loop extracted module.
|
||||||
MiscompiledFunctions.clear();
|
MiscompiledFunctions.clear();
|
||||||
for (Module::iterator I = ToOptimizeLoopExtracted->begin(),
|
for (unsigned i = 0, e = MisCompFunctions.size(); i != e; ++i) {
|
||||||
E = ToOptimizeLoopExtracted->end(); I != E; ++I) {
|
Function *NewF = ToNotOptimize->getFunction(MisCompFunctions[i].first,
|
||||||
if (!I->isExternal()) {
|
MisCompFunctions[i].second);
|
||||||
Function *NewF = ToNotOptimize->getFunction(I->getName(),
|
assert(NewF && "Function not found??");
|
||||||
I->getFunctionType());
|
MiscompiledFunctions.push_back(NewF);
|
||||||
assert(NewF && "Function not found??");
|
|
||||||
MiscompiledFunctions.push_back(NewF);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
delete ToOptimizeLoopExtracted;
|
|
||||||
|
|
||||||
BD.setNewProgram(ToNotOptimize);
|
BD.setNewProgram(ToNotOptimize);
|
||||||
MadeChange = true;
|
MadeChange = true;
|
||||||
|
@ -423,12 +429,19 @@ static bool ExtractBlocks(BugDriver &BD,
|
||||||
// together.
|
// together.
|
||||||
delete ToExtract;
|
delete ToExtract;
|
||||||
|
|
||||||
|
std::vector<std::pair<std::string, const FunctionType*> > MisCompFunctions;
|
||||||
|
for (Module::iterator I = Extracted->begin(), E = Extracted->end();
|
||||||
|
I != E; ++I)
|
||||||
|
MisCompFunctions.push_back(std::make_pair(I->getName(),
|
||||||
|
I->getFunctionType()));
|
||||||
|
|
||||||
std::string ErrorMsg;
|
std::string ErrorMsg;
|
||||||
if (LinkModules(ProgClone, Extracted, &ErrorMsg)) {
|
if (LinkModules(ProgClone, Extracted, &ErrorMsg)) {
|
||||||
std::cerr << BD.getToolName() << ": Error linking modules together:"
|
std::cerr << BD.getToolName() << ": Error linking modules together:"
|
||||||
<< ErrorMsg << '\n';
|
<< ErrorMsg << '\n';
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
delete Extracted;
|
||||||
|
|
||||||
// Set the new program and delete the old one.
|
// Set the new program and delete the old one.
|
||||||
BD.setNewProgram(ProgClone);
|
BD.setNewProgram(ProgClone);
|
||||||
|
@ -436,15 +449,12 @@ static bool ExtractBlocks(BugDriver &BD,
|
||||||
// Update the list of miscompiled functions.
|
// Update the list of miscompiled functions.
|
||||||
MiscompiledFunctions.clear();
|
MiscompiledFunctions.clear();
|
||||||
|
|
||||||
for (Module::iterator I = Extracted->begin(), E = Extracted->end(); I != E;
|
for (unsigned i = 0, e = MisCompFunctions.size(); i != e; ++i) {
|
||||||
++I)
|
Function *NewF = ProgClone->getFunction(MisCompFunctions[i].first,
|
||||||
if (!I->isExternal()) {
|
MisCompFunctions[i].second);
|
||||||
Function *NF = ProgClone->getFunction(I->getName(), I->getFunctionType());
|
assert(NewF && "Function not found??");
|
||||||
assert(NF && "Mapped function not found!");
|
MiscompiledFunctions.push_back(NewF);
|
||||||
MiscompiledFunctions.push_back(NF);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
delete Extracted;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue