mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-19 04:32:19 +00:00
add support for bugpointing the integrated assembler. Something like this
works for me: bugpoint Output/bisort.llvm.bc -run-llc-ia -safe-run-llc This uses llc with the integrated assembler as the test compiler and llc without it as the safe compiler. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98618 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4d82068167
commit
50010429a7
@ -28,7 +28,7 @@ namespace {
|
|||||||
// for miscompilation.
|
// for miscompilation.
|
||||||
//
|
//
|
||||||
enum OutputType {
|
enum OutputType {
|
||||||
AutoPick, RunLLI, RunJIT, RunLLC, RunCBE, CBE_bug, LLC_Safe, Custom
|
AutoPick, RunLLI, RunJIT, RunLLC, RunLLCIA, RunCBE, CBE_bug, LLC_Safe,Custom
|
||||||
};
|
};
|
||||||
|
|
||||||
cl::opt<double>
|
cl::opt<double>
|
||||||
@ -45,6 +45,8 @@ namespace {
|
|||||||
"Execute with the interpreter"),
|
"Execute with the interpreter"),
|
||||||
clEnumValN(RunJIT, "run-jit", "Execute with JIT"),
|
clEnumValN(RunJIT, "run-jit", "Execute with JIT"),
|
||||||
clEnumValN(RunLLC, "run-llc", "Compile with LLC"),
|
clEnumValN(RunLLC, "run-llc", "Compile with LLC"),
|
||||||
|
clEnumValN(RunLLCIA, "run-llc-ia",
|
||||||
|
"Compile with LLC with integrated assembler"),
|
||||||
clEnumValN(RunCBE, "run-cbe", "Compile with CBE"),
|
clEnumValN(RunCBE, "run-cbe", "Compile with CBE"),
|
||||||
clEnumValN(CBE_bug,"cbe-bug", "Find CBE bugs"),
|
clEnumValN(CBE_bug,"cbe-bug", "Find CBE bugs"),
|
||||||
clEnumValN(LLC_Safe, "llc-safe", "Use LLC for all"),
|
clEnumValN(LLC_Safe, "llc-safe", "Use LLC for all"),
|
||||||
@ -168,9 +170,11 @@ bool BugDriver::initializeExecutionEnvironment() {
|
|||||||
&ToolArgv);
|
&ToolArgv);
|
||||||
break;
|
break;
|
||||||
case RunLLC:
|
case RunLLC:
|
||||||
|
case RunLLCIA:
|
||||||
case LLC_Safe:
|
case LLC_Safe:
|
||||||
Interpreter = AbstractInterpreter::createLLC(getToolName(), Message,
|
Interpreter = AbstractInterpreter::createLLC(getToolName(), Message,
|
||||||
&ToolArgv, &GCCToolArgv);
|
&ToolArgv, &GCCToolArgv,
|
||||||
|
InterpreterSel == RunLLCIA);
|
||||||
break;
|
break;
|
||||||
case RunJIT:
|
case RunJIT:
|
||||||
Interpreter = AbstractInterpreter::createJIT(getToolName(), Message,
|
Interpreter = AbstractInterpreter::createJIT(getToolName(), Message,
|
||||||
@ -244,10 +248,12 @@ bool BugDriver::initializeExecutionEnvironment() {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RunLLC:
|
case RunLLC:
|
||||||
|
case RunLLCIA:
|
||||||
SafeToolArgs.push_back("--relocation-model=pic");
|
SafeToolArgs.push_back("--relocation-model=pic");
|
||||||
SafeInterpreter = AbstractInterpreter::createLLC(Path.c_str(), Message,
|
SafeInterpreter = AbstractInterpreter::createLLC(Path.c_str(), Message,
|
||||||
&SafeToolArgs,
|
&SafeToolArgs,
|
||||||
&GCCToolArgv);
|
&GCCToolArgv,
|
||||||
|
SafeInterpreterSel == RunLLCIA);
|
||||||
break;
|
break;
|
||||||
case RunCBE:
|
case RunCBE:
|
||||||
SafeInterpreter = AbstractInterpreter::createCBE(Path.c_str(), Message,
|
SafeInterpreter = AbstractInterpreter::createCBE(Path.c_str(), Message,
|
||||||
|
@ -352,7 +352,8 @@ AbstractInterpreter *AbstractInterpreter::createCustom(
|
|||||||
//
|
//
|
||||||
GCC::FileType LLC::OutputCode(const std::string &Bitcode,
|
GCC::FileType LLC::OutputCode(const std::string &Bitcode,
|
||||||
sys::Path &OutputAsmFile) {
|
sys::Path &OutputAsmFile) {
|
||||||
sys::Path uniqueFile(Bitcode+".llc.s");
|
const char *Suffix = (UseIntegratedAssembler ? ".llc.o" : ".llc.s");
|
||||||
|
sys::Path uniqueFile(Bitcode + Suffix);
|
||||||
std::string ErrMsg;
|
std::string ErrMsg;
|
||||||
if (uniqueFile.makeUnique(true, &ErrMsg)) {
|
if (uniqueFile.makeUnique(true, &ErrMsg)) {
|
||||||
errs() << "Error making unique filename: " << ErrMsg << "\n";
|
errs() << "Error making unique filename: " << ErrMsg << "\n";
|
||||||
@ -360,18 +361,23 @@ GCC::FileType LLC::OutputCode(const std::string &Bitcode,
|
|||||||
}
|
}
|
||||||
OutputAsmFile = uniqueFile;
|
OutputAsmFile = uniqueFile;
|
||||||
std::vector<const char *> LLCArgs;
|
std::vector<const char *> LLCArgs;
|
||||||
LLCArgs.push_back (LLCPath.c_str());
|
LLCArgs.push_back(LLCPath.c_str());
|
||||||
|
|
||||||
// Add any extra LLC args.
|
// Add any extra LLC args.
|
||||||
for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
|
for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
|
||||||
LLCArgs.push_back(ToolArgs[i].c_str());
|
LLCArgs.push_back(ToolArgs[i].c_str());
|
||||||
|
|
||||||
LLCArgs.push_back ("-o");
|
LLCArgs.push_back("-o");
|
||||||
LLCArgs.push_back (OutputAsmFile.c_str()); // Output to the Asm file
|
LLCArgs.push_back(OutputAsmFile.c_str()); // Output to the Asm file
|
||||||
LLCArgs.push_back (Bitcode.c_str()); // This is the input bitcode
|
LLCArgs.push_back(Bitcode.c_str()); // This is the input bitcode
|
||||||
|
|
||||||
|
if (UseIntegratedAssembler)
|
||||||
|
LLCArgs.push_back("-filetype=obj");
|
||||||
|
|
||||||
LLCArgs.push_back (0);
|
LLCArgs.push_back (0);
|
||||||
|
|
||||||
outs() << "<llc>"; outs().flush();
|
outs() << (UseIntegratedAssembler ? "<llc-ia>" : "<llc>");
|
||||||
|
outs().flush();
|
||||||
DEBUG(errs() << "\nAbout to run:\t";
|
DEBUG(errs() << "\nAbout to run:\t";
|
||||||
for (unsigned i=0, e = LLCArgs.size()-1; i != e; ++i)
|
for (unsigned i=0, e = LLCArgs.size()-1; i != e; ++i)
|
||||||
errs() << " " << LLCArgs[i];
|
errs() << " " << LLCArgs[i];
|
||||||
@ -381,7 +387,7 @@ GCC::FileType LLC::OutputCode(const std::string &Bitcode,
|
|||||||
sys::Path(), sys::Path(), sys::Path()))
|
sys::Path(), sys::Path(), sys::Path()))
|
||||||
ProcessFailure(sys::Path(LLCPath), &LLCArgs[0]);
|
ProcessFailure(sys::Path(LLCPath), &LLCArgs[0]);
|
||||||
|
|
||||||
return GCC::AsmFile;
|
return UseIntegratedAssembler ? GCC::ObjectFile : GCC::AsmFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LLC::compileProgram(const std::string &Bitcode) {
|
void LLC::compileProgram(const std::string &Bitcode) {
|
||||||
@ -400,7 +406,7 @@ int LLC::ExecuteProgram(const std::string &Bitcode,
|
|||||||
unsigned MemoryLimit) {
|
unsigned MemoryLimit) {
|
||||||
|
|
||||||
sys::Path OutputAsmFile;
|
sys::Path OutputAsmFile;
|
||||||
OutputCode(Bitcode, OutputAsmFile);
|
GCC::FileType FileKind = OutputCode(Bitcode, OutputAsmFile);
|
||||||
FileRemover OutFileRemover(OutputAsmFile, !SaveTemps);
|
FileRemover OutFileRemover(OutputAsmFile, !SaveTemps);
|
||||||
|
|
||||||
std::vector<std::string> GCCArgs(ArgsForGCC);
|
std::vector<std::string> GCCArgs(ArgsForGCC);
|
||||||
@ -408,7 +414,7 @@ int LLC::ExecuteProgram(const std::string &Bitcode,
|
|||||||
GCCArgs.insert(GCCArgs.end(), gccArgs.begin(), gccArgs.end());
|
GCCArgs.insert(GCCArgs.end(), gccArgs.begin(), gccArgs.end());
|
||||||
|
|
||||||
// Assuming LLC worked, compile the result with GCC and run it.
|
// Assuming LLC worked, compile the result with GCC and run it.
|
||||||
return gcc->ExecuteProgram(OutputAsmFile.str(), Args, GCC::AsmFile,
|
return gcc->ExecuteProgram(OutputAsmFile.str(), Args, FileKind,
|
||||||
InputFile, OutputFile, GCCArgs,
|
InputFile, OutputFile, GCCArgs,
|
||||||
Timeout, MemoryLimit);
|
Timeout, MemoryLimit);
|
||||||
}
|
}
|
||||||
@ -418,7 +424,8 @@ int LLC::ExecuteProgram(const std::string &Bitcode,
|
|||||||
LLC *AbstractInterpreter::createLLC(const char *Argv0,
|
LLC *AbstractInterpreter::createLLC(const char *Argv0,
|
||||||
std::string &Message,
|
std::string &Message,
|
||||||
const std::vector<std::string> *Args,
|
const std::vector<std::string> *Args,
|
||||||
const std::vector<std::string> *GCCArgs) {
|
const std::vector<std::string> *GCCArgs,
|
||||||
|
bool UseIntegratedAssembler) {
|
||||||
std::string LLCPath =
|
std::string LLCPath =
|
||||||
FindExecutable("llc", Argv0, (void *)(intptr_t)&createLLC).str();
|
FindExecutable("llc", Argv0, (void *)(intptr_t)&createLLC).str();
|
||||||
if (LLCPath.empty()) {
|
if (LLCPath.empty()) {
|
||||||
@ -432,7 +439,7 @@ LLC *AbstractInterpreter::createLLC(const char *Argv0,
|
|||||||
errs() << Message << "\n";
|
errs() << Message << "\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
return new LLC(LLCPath, gcc, Args, GCCArgs);
|
return new LLC(LLCPath, gcc, Args, GCCArgs, UseIntegratedAssembler);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===---------------------------------------------------------------------===//
|
//===---------------------------------------------------------------------===//
|
||||||
@ -605,17 +612,14 @@ CBE *AbstractInterpreter::createCBE(const char *Argv0,
|
|||||||
// GCC abstraction
|
// GCC abstraction
|
||||||
//
|
//
|
||||||
|
|
||||||
static bool
|
static bool IsARMArchitecture(std::vector<std::string> Args) {
|
||||||
IsARMArchitecture(std::vector<std::string> Args)
|
|
||||||
{
|
|
||||||
for (std::vector<std::string>::const_iterator
|
for (std::vector<std::string>::const_iterator
|
||||||
I = Args.begin(), E = Args.end(); I != E; ++I) {
|
I = Args.begin(), E = Args.end(); I != E; ++I) {
|
||||||
StringRef S(*I);
|
StringRef S(*I);
|
||||||
if (!S.equals_lower("-arch")) {
|
if (!S.equals_lower("-arch")) {
|
||||||
++I;
|
++I;
|
||||||
if (I != E && !S.substr(0, strlen("arm")).equals_lower("arm")) {
|
if (I != E && !S.substr(0, strlen("arm")).equals_lower("arm"))
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -634,26 +638,33 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
|
|||||||
|
|
||||||
GCCArgs.push_back(GCCPath.c_str());
|
GCCArgs.push_back(GCCPath.c_str());
|
||||||
|
|
||||||
|
if (TargetTriple.getArch() == Triple::x86)
|
||||||
|
GCCArgs.push_back("-m32");
|
||||||
|
|
||||||
for (std::vector<std::string>::const_iterator
|
for (std::vector<std::string>::const_iterator
|
||||||
I = gccArgs.begin(), E = gccArgs.end(); I != E; ++I)
|
I = gccArgs.begin(), E = gccArgs.end(); I != E; ++I)
|
||||||
GCCArgs.push_back(I->c_str());
|
GCCArgs.push_back(I->c_str());
|
||||||
|
|
||||||
// Specify -x explicitly in case the extension is wonky
|
// Specify -x explicitly in case the extension is wonky
|
||||||
GCCArgs.push_back("-x");
|
if (fileType != ObjectFile) {
|
||||||
if (fileType == CFile) {
|
GCCArgs.push_back("-x");
|
||||||
GCCArgs.push_back("c");
|
if (fileType == CFile) {
|
||||||
GCCArgs.push_back("-fno-strict-aliasing");
|
GCCArgs.push_back("c");
|
||||||
} else {
|
GCCArgs.push_back("-fno-strict-aliasing");
|
||||||
GCCArgs.push_back("assembler");
|
} else {
|
||||||
|
GCCArgs.push_back("assembler");
|
||||||
|
|
||||||
// For ARM architectures we don't want this flag. bugpoint isn't
|
// For ARM architectures we don't want this flag. bugpoint isn't
|
||||||
// explicitly told what architecture it is working on, so we get
|
// explicitly told what architecture it is working on, so we get
|
||||||
// it from gcc flags
|
// it from gcc flags
|
||||||
if ((TargetTriple.getOS() == Triple::Darwin) &&
|
if ((TargetTriple.getOS() == Triple::Darwin) &&
|
||||||
!IsARMArchitecture(ArgsForGCC))
|
!IsARMArchitecture(ArgsForGCC))
|
||||||
GCCArgs.push_back("-force_cpusubtype_ALL");
|
GCCArgs.push_back("-force_cpusubtype_ALL");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
GCCArgs.push_back(ProgramFile.c_str()); // Specify the input filename...
|
|
||||||
|
GCCArgs.push_back(ProgramFile.c_str()); // Specify the input filename.
|
||||||
|
|
||||||
GCCArgs.push_back("-x");
|
GCCArgs.push_back("-x");
|
||||||
GCCArgs.push_back("none");
|
GCCArgs.push_back("none");
|
||||||
GCCArgs.push_back("-o");
|
GCCArgs.push_back("-o");
|
||||||
@ -765,13 +776,18 @@ int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
|
|||||||
|
|
||||||
GCCArgs.push_back(GCCPath.c_str());
|
GCCArgs.push_back(GCCPath.c_str());
|
||||||
|
|
||||||
|
if (TargetTriple.getArch() == Triple::x86)
|
||||||
|
GCCArgs.push_back("-m32");
|
||||||
|
|
||||||
for (std::vector<std::string>::const_iterator
|
for (std::vector<std::string>::const_iterator
|
||||||
I = gccArgs.begin(), E = gccArgs.end(); I != E; ++I)
|
I = gccArgs.begin(), E = gccArgs.end(); I != E; ++I)
|
||||||
GCCArgs.push_back(I->c_str());
|
GCCArgs.push_back(I->c_str());
|
||||||
|
|
||||||
// Compile the C/asm file into a shared object
|
// Compile the C/asm file into a shared object
|
||||||
GCCArgs.push_back("-x");
|
if (fileType != ObjectFile) {
|
||||||
GCCArgs.push_back(fileType == AsmFile ? "assembler" : "c");
|
GCCArgs.push_back("-x");
|
||||||
|
GCCArgs.push_back(fileType == AsmFile ? "assembler" : "c");
|
||||||
|
}
|
||||||
GCCArgs.push_back("-fno-strict-aliasing");
|
GCCArgs.push_back("-fno-strict-aliasing");
|
||||||
GCCArgs.push_back(InputFile.c_str()); // Specify the input filename.
|
GCCArgs.push_back(InputFile.c_str()); // Specify the input filename.
|
||||||
GCCArgs.push_back("-x");
|
GCCArgs.push_back("-x");
|
||||||
|
@ -58,7 +58,7 @@ class GCC {
|
|||||||
if (GCCArgs) gccArgs = *GCCArgs;
|
if (GCCArgs) gccArgs = *GCCArgs;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
enum FileType { AsmFile, CFile };
|
enum FileType { AsmFile, ObjectFile, CFile };
|
||||||
|
|
||||||
static GCC *create(std::string &Message,
|
static GCC *create(std::string &Message,
|
||||||
const std::vector<std::string> *Args);
|
const std::vector<std::string> *Args);
|
||||||
@ -101,7 +101,8 @@ public:
|
|||||||
const std::vector<std::string> *GCCArgs = 0);
|
const std::vector<std::string> *GCCArgs = 0);
|
||||||
static LLC *createLLC(const char *Argv0, std::string &Message,
|
static LLC *createLLC(const char *Argv0, std::string &Message,
|
||||||
const std::vector<std::string> *Args = 0,
|
const std::vector<std::string> *Args = 0,
|
||||||
const std::vector<std::string> *GCCArgs = 0);
|
const std::vector<std::string> *GCCArgs = 0,
|
||||||
|
bool UseIntegratedAssembler = false);
|
||||||
|
|
||||||
static AbstractInterpreter* createLLI(const char *Argv0, std::string &Message,
|
static AbstractInterpreter* createLLI(const char *Argv0, std::string &Message,
|
||||||
const std::vector<std::string> *Args=0);
|
const std::vector<std::string> *Args=0);
|
||||||
@ -195,11 +196,14 @@ class LLC : public AbstractInterpreter {
|
|||||||
std::vector<std::string> ToolArgs; // Extra args to pass to LLC.
|
std::vector<std::string> ToolArgs; // Extra args to pass to LLC.
|
||||||
std::vector<std::string> gccArgs; // Extra args to pass to GCC.
|
std::vector<std::string> gccArgs; // Extra args to pass to GCC.
|
||||||
GCC *gcc;
|
GCC *gcc;
|
||||||
|
bool UseIntegratedAssembler;
|
||||||
public:
|
public:
|
||||||
LLC(const std::string &llcPath, GCC *Gcc,
|
LLC(const std::string &llcPath, GCC *Gcc,
|
||||||
const std::vector<std::string> *Args,
|
const std::vector<std::string> *Args,
|
||||||
const std::vector<std::string> *GCCArgs)
|
const std::vector<std::string> *GCCArgs,
|
||||||
: LLCPath(llcPath), gcc(Gcc) {
|
bool useIntegratedAssembler)
|
||||||
|
: LLCPath(llcPath), gcc(Gcc),
|
||||||
|
UseIntegratedAssembler(useIntegratedAssembler) {
|
||||||
ToolArgs.clear();
|
ToolArgs.clear();
|
||||||
if (Args) ToolArgs = *Args;
|
if (Args) ToolArgs = *Args;
|
||||||
if (GCCArgs) gccArgs = *GCCArgs;
|
if (GCCArgs) gccArgs = *GCCArgs;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user