mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-06 06:33:24 +00:00
Use CloneModule's ValueMap in more places, instead of looking
up functions by name. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@69805 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e370c80d31
commit
d50330cd02
@ -16,11 +16,13 @@
|
|||||||
#ifndef BUGDRIVER_H
|
#ifndef BUGDRIVER_H
|
||||||
#define BUGDRIVER_H
|
#define BUGDRIVER_H
|
||||||
|
|
||||||
|
#include "llvm/ADT/DenseMap.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
|
class Value;
|
||||||
class PassInfo;
|
class PassInfo;
|
||||||
class Module;
|
class Module;
|
||||||
class GlobalVariable;
|
class GlobalVariable;
|
||||||
@ -312,7 +314,8 @@ void DeleteFunctionBody(Function *F);
|
|||||||
/// SplitFunctionsOutOfModule - Given a module and a list of functions in the
|
/// SplitFunctionsOutOfModule - Given a module and a list of functions in the
|
||||||
/// module, split the functions OUT of the specified module, and place them in
|
/// module, split the functions OUT of the specified module, and place them in
|
||||||
/// the new module.
|
/// the new module.
|
||||||
Module *SplitFunctionsOutOfModule(Module *M, const std::vector<Function*> &F);
|
Module *SplitFunctionsOutOfModule(Module *M, const std::vector<Function*> &F,
|
||||||
|
DenseMap<const Value*, Value*> &ValueMap);
|
||||||
|
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
|
||||||
|
@ -197,7 +197,8 @@ static Constant *GetTorInit(std::vector<std::pair<Function*, int> > &TorList) {
|
|||||||
/// M1 has all of the global variables. If M2 contains any functions that are
|
/// M1 has all of the global variables. If M2 contains any functions that are
|
||||||
/// static ctors/dtors, we need to add an llvm.global_[cd]tors global to M2, and
|
/// static ctors/dtors, we need to add an llvm.global_[cd]tors global to M2, and
|
||||||
/// prune appropriate entries out of M1s list.
|
/// prune appropriate entries out of M1s list.
|
||||||
static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2){
|
static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2,
|
||||||
|
DenseMap<const Value*, Value*> ValueMap) {
|
||||||
GlobalVariable *GV = M1->getNamedGlobal(GlobalName);
|
GlobalVariable *GV = M1->getNamedGlobal(GlobalName);
|
||||||
if (!GV || GV->isDeclaration() || GV->hasLocalLinkage() ||
|
if (!GV || GV->isDeclaration() || GV->hasLocalLinkage() ||
|
||||||
!GV->use_empty()) return;
|
!GV->use_empty()) return;
|
||||||
@ -225,7 +226,7 @@ static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2){
|
|||||||
M1Tors.push_back(std::make_pair(F, Priority));
|
M1Tors.push_back(std::make_pair(F, Priority));
|
||||||
else {
|
else {
|
||||||
// Map to M2's version of the function.
|
// Map to M2's version of the function.
|
||||||
F = M2->getFunction(F->getName());
|
F = cast<Function>(ValueMap[F]);
|
||||||
M2Tors.push_back(std::make_pair(F, Priority));
|
M2Tors.push_back(std::make_pair(F, Priority));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -255,8 +256,10 @@ static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2){
|
|||||||
/// SplitFunctionsOutOfModule - Given a module and a list of functions in the
|
/// SplitFunctionsOutOfModule - Given a module and a list of functions in the
|
||||||
/// module, split the functions OUT of the specified module, and place them in
|
/// module, split the functions OUT of the specified module, and place them in
|
||||||
/// the new module.
|
/// the new module.
|
||||||
Module *llvm::SplitFunctionsOutOfModule(Module *M,
|
Module *
|
||||||
const std::vector<Function*> &F) {
|
llvm::SplitFunctionsOutOfModule(Module *M,
|
||||||
|
const std::vector<Function*> &F,
|
||||||
|
DenseMap<const Value*, Value*> &ValueMap) {
|
||||||
// Make sure functions & globals are all external so that linkage
|
// Make sure functions & globals are all external so that linkage
|
||||||
// between the two modules will work.
|
// between the two modules will work.
|
||||||
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
|
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
|
||||||
@ -268,7 +271,8 @@ Module *llvm::SplitFunctionsOutOfModule(Module *M,
|
|||||||
I->setLinkage(GlobalValue::ExternalLinkage);
|
I->setLinkage(GlobalValue::ExternalLinkage);
|
||||||
}
|
}
|
||||||
|
|
||||||
Module *New = CloneModule(M);
|
DenseMap<const Value*, Value*> NewValueMap;
|
||||||
|
Module *New = CloneModule(M, NewValueMap);
|
||||||
|
|
||||||
// Make sure global initializers exist only in the safe module (CBE->.so)
|
// Make sure global initializers exist only in the safe module (CBE->.so)
|
||||||
for (Module::global_iterator I = New->global_begin(), E = New->global_end();
|
for (Module::global_iterator I = New->global_begin(), E = New->global_end();
|
||||||
@ -276,27 +280,27 @@ Module *llvm::SplitFunctionsOutOfModule(Module *M,
|
|||||||
I->setInitializer(0); // Delete the initializer to make it external
|
I->setInitializer(0); // Delete the initializer to make it external
|
||||||
|
|
||||||
// Remove the Test functions from the Safe module
|
// Remove the Test functions from the Safe module
|
||||||
std::set<std::pair<std::string, const PointerType*> > TestFunctions;
|
std::set<Function *> TestFunctions;
|
||||||
for (unsigned i = 0, e = F.size(); i != e; ++i) {
|
for (unsigned i = 0, e = F.size(); i != e; ++i) {
|
||||||
TestFunctions.insert(std::make_pair(F[i]->getName(), F[i]->getType()));
|
Function *TNOF = cast<Function>(ValueMap[F[i]]);
|
||||||
Function *TNOF = M->getFunction(F[i]->getName());
|
DEBUG(std::cerr << "Removing function ");
|
||||||
assert(TNOF && "Function doesn't exist in module!");
|
DEBUG(WriteAsOperand(std::cerr, TNOF, false));
|
||||||
assert(TNOF->getFunctionType() == F[i]->getFunctionType() && "wrong type?");
|
DEBUG(std::cerr << "\n");
|
||||||
DEBUG(std::cerr << "Removing function " << F[i]->getName() << "\n");
|
TestFunctions.insert(cast<Function>(NewValueMap[TNOF]));
|
||||||
DeleteFunctionBody(TNOF); // Function is now external in this module!
|
DeleteFunctionBody(TNOF); // Function is now external in this module!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Remove the Safe functions from the Test module
|
// Remove the Safe functions from the Test module
|
||||||
for (Module::iterator I = New->begin(), E = New->end(); I != E; ++I)
|
for (Module::iterator I = New->begin(), E = New->end(); I != E; ++I)
|
||||||
if (!TestFunctions.count(std::make_pair(I->getName(), I->getType())))
|
if (!TestFunctions.count(I))
|
||||||
DeleteFunctionBody(I);
|
DeleteFunctionBody(I);
|
||||||
|
|
||||||
|
|
||||||
// Make sure that there is a global ctor/dtor array in both halves of the
|
// Make sure that there is a global ctor/dtor array in both halves of the
|
||||||
// module if they both have static ctor/dtor functions.
|
// module if they both have static ctor/dtor functions.
|
||||||
SplitStaticCtorDtor("llvm.global_ctors", M, New);
|
SplitStaticCtorDtor("llvm.global_ctors", M, New, NewValueMap);
|
||||||
SplitStaticCtorDtor("llvm.global_dtors", M, New);
|
SplitStaticCtorDtor("llvm.global_dtors", M, New, NewValueMap);
|
||||||
|
|
||||||
return New;
|
return New;
|
||||||
}
|
}
|
||||||
|
@ -220,8 +220,10 @@ bool ReduceMiscompilingFunctions::TestFuncs(const std::vector<Function*>&Funcs){
|
|||||||
std::cout << '\n';
|
std::cout << '\n';
|
||||||
|
|
||||||
// Split the module into the two halves of the program we want.
|
// Split the module into the two halves of the program we want.
|
||||||
Module *ToNotOptimize = CloneModule(BD.getProgram());
|
DenseMap<const Value*, Value*> ValueMap;
|
||||||
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, Funcs);
|
Module *ToNotOptimize = CloneModule(BD.getProgram(), ValueMap);
|
||||||
|
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, Funcs,
|
||||||
|
ValueMap);
|
||||||
|
|
||||||
// Run the predicate, note that the predicate will delete both input modules.
|
// Run the predicate, note that the predicate will delete both input modules.
|
||||||
return TestFn(BD, ToOptimize, ToNotOptimize);
|
return TestFn(BD, ToOptimize, ToNotOptimize);
|
||||||
@ -258,9 +260,11 @@ static bool ExtractLoops(BugDriver &BD,
|
|||||||
while (1) {
|
while (1) {
|
||||||
if (BugpointIsInterrupted) return MadeChange;
|
if (BugpointIsInterrupted) return MadeChange;
|
||||||
|
|
||||||
Module *ToNotOptimize = CloneModule(BD.getProgram());
|
DenseMap<const Value*, Value*> ValueMap;
|
||||||
|
Module *ToNotOptimize = CloneModule(BD.getProgram(), ValueMap);
|
||||||
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
|
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
|
||||||
MiscompiledFunctions);
|
MiscompiledFunctions,
|
||||||
|
ValueMap);
|
||||||
Module *ToOptimizeLoopExtracted = BD.ExtractLoop(ToOptimize);
|
Module *ToOptimizeLoopExtracted = BD.ExtractLoop(ToOptimize);
|
||||||
if (!ToOptimizeLoopExtracted) {
|
if (!ToOptimizeLoopExtracted) {
|
||||||
// If the loop extractor crashed or if there were no extractible loops,
|
// If the loop extractor crashed or if there were no extractible loops,
|
||||||
@ -396,9 +400,11 @@ bool ReduceMiscompiledBlocks::TestFuncs(const std::vector<BasicBlock*> &BBs) {
|
|||||||
std::cout << '\n';
|
std::cout << '\n';
|
||||||
|
|
||||||
// Split the module into the two halves of the program we want.
|
// Split the module into the two halves of the program we want.
|
||||||
Module *ToNotOptimize = CloneModule(BD.getProgram());
|
DenseMap<const Value*, Value*> ValueMap;
|
||||||
|
Module *ToNotOptimize = CloneModule(BD.getProgram(), ValueMap);
|
||||||
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
|
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
|
||||||
FunctionsBeingTested);
|
FunctionsBeingTested,
|
||||||
|
ValueMap);
|
||||||
|
|
||||||
// Try the extraction. If it doesn't work, then the block extractor crashed
|
// Try the extraction. If it doesn't work, then the block extractor crashed
|
||||||
// or something, in which case bugpoint can't chase down this possibility.
|
// or something, in which case bugpoint can't chase down this possibility.
|
||||||
@ -443,9 +449,11 @@ static bool ExtractBlocks(BugDriver &BD,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Module *ProgClone = CloneModule(BD.getProgram());
|
DenseMap<const Value*, Value*> ValueMap;
|
||||||
|
Module *ProgClone = CloneModule(BD.getProgram(), ValueMap);
|
||||||
Module *ToExtract = SplitFunctionsOutOfModule(ProgClone,
|
Module *ToExtract = SplitFunctionsOutOfModule(ProgClone,
|
||||||
MiscompiledFunctions);
|
MiscompiledFunctions,
|
||||||
|
ValueMap);
|
||||||
Module *Extracted = BD.ExtractMappedBlocksFromModule(Blocks, ToExtract);
|
Module *Extracted = BD.ExtractMappedBlocksFromModule(Blocks, ToExtract);
|
||||||
if (Extracted == 0) {
|
if (Extracted == 0) {
|
||||||
// Weird, extraction should have worked.
|
// Weird, extraction should have worked.
|
||||||
@ -608,9 +616,11 @@ bool BugDriver::debugMiscompilation() {
|
|||||||
|
|
||||||
// Output a bunch of bitcode files for the user...
|
// Output a bunch of bitcode files for the user...
|
||||||
std::cout << "Outputting reduced bitcode files which expose the problem:\n";
|
std::cout << "Outputting reduced bitcode files which expose the problem:\n";
|
||||||
Module *ToNotOptimize = CloneModule(getProgram());
|
DenseMap<const Value*, Value*> ValueMap;
|
||||||
|
Module *ToNotOptimize = CloneModule(getProgram(), ValueMap);
|
||||||
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
|
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
|
||||||
MiscompiledFunctions);
|
MiscompiledFunctions,
|
||||||
|
ValueMap);
|
||||||
|
|
||||||
std::cout << " Non-optimized portion: ";
|
std::cout << " Non-optimized portion: ";
|
||||||
ToNotOptimize = swapProgramIn(ToNotOptimize);
|
ToNotOptimize = swapProgramIn(ToNotOptimize);
|
||||||
@ -856,8 +866,9 @@ bool BugDriver::debugCodeGenerator() {
|
|||||||
std::vector<Function*> Funcs = DebugAMiscompilation(*this, TestCodeGenerator);
|
std::vector<Function*> Funcs = DebugAMiscompilation(*this, TestCodeGenerator);
|
||||||
|
|
||||||
// Split the module into the two halves of the program we want.
|
// Split the module into the two halves of the program we want.
|
||||||
Module *ToNotCodeGen = CloneModule(getProgram());
|
DenseMap<const Value*, Value*> ValueMap;
|
||||||
Module *ToCodeGen = SplitFunctionsOutOfModule(ToNotCodeGen, Funcs);
|
Module *ToNotCodeGen = CloneModule(getProgram(), ValueMap);
|
||||||
|
Module *ToCodeGen = SplitFunctionsOutOfModule(ToNotCodeGen, Funcs, ValueMap);
|
||||||
|
|
||||||
// Condition the modules
|
// Condition the modules
|
||||||
CleanupAndPrepareModules(*this, ToCodeGen, ToNotCodeGen);
|
CleanupAndPrepareModules(*this, ToCodeGen, ToNotCodeGen);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user