Trace code should always be exported just before code generation;

this is not a debugging option.  But we can export it as assembly
instead of bytecode if -debugtrace is specified.

llvm-svn: 889
This commit is contained in:
Vikram S. Adve 2001-10-18 13:51:20 +00:00
parent 7ac553aa12
commit b2ac1e76b4
2 changed files with 29 additions and 26 deletions

View File

@ -1,6 +1,6 @@
LEVEL = ../.. LEVEL = ../..
TOOLNAME = llc TOOLNAME = llc
USEDLIBS = sparc regalloc sched select sparc regalloc sched select target opt instrument livevar bcreader vmcore asmwriter analysis support transforms USEDLIBS = sparc regalloc sched select sparc regalloc sched select target opt instrument livevar bcreader bcwriter vmcore asmwriter analysis support transforms
include $(LEVEL)/Makefile.common include $(LEVEL)/Makefile.common

View File

@ -27,9 +27,8 @@ cl::Flag DoNotEmitAssembly("noasm", "Do not emit assembly code", cl::Hidden);
cl::Flag TraceBBValues ("trace", cl::Flag TraceBBValues ("trace",
"Trace values at basic block and method exits"); "Trace values at basic block and method exits");
cl::Flag TraceMethodValues("tracem", "Trace values only at method exits"); cl::Flag TraceMethodValues("tracem", "Trace values only at method exits");
cl::Flag DebugTrace ("dumptrace", cl::Flag DebugTrace ("debugtrace",
"output trace code to a <fn>.trace.ll file", "output trace code as assembly instead of bytecode");
cl::Hidden);
// GetFileNameRoot - Helper function to get the basename of a filename... // GetFileNameRoot - Helper function to get the basename of a filename...
@ -104,6 +103,7 @@ public:
//===---------------------------------------------------------------------===// //===---------------------------------------------------------------------===//
int main(int argc, char **argv) { int main(int argc, char **argv) {
int retCode = 0;
cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n"); cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
// Allocate a target... in the future this will be controllable on the // Allocate a target... in the future this will be controllable on the
@ -130,30 +130,33 @@ int main(int argc, char **argv) {
Passes.push_back(new HoistPHIConstants()); Passes.push_back(new HoistPHIConstants());
if (TraceBBValues || TraceMethodValues) // If tracing enabled... if (TraceBBValues || TraceMethodValues) // If tracing enabled...
// Insert trace code in all methods in the module {
Passes.push_back(new InsertTraceCode(TraceBBValues, // Insert trace code in all methods in the module
TraceBBValues || TraceMethodValues)); Passes.push_back(new InsertTraceCode(TraceBBValues,
TraceBBValues ||TraceMethodValues));
if (DebugTrace) { // If Trace Debugging is enabled... // Then write out the module with tracing code before code generation
// Then write the module with tracing code out in assembly form assert(InputFilename != "-" &&
assert(InputFilename != "-" && "files on stdin not supported with tracing"); "files on stdin not supported with tracing");
string traceFileName = GetFileNameRoot(InputFilename) + ".trace.ll"; string traceFileName = GetFileNameRoot(InputFilename)
+ (DebugTrace? ".trace.ll" : ".trace.bc");
ostream *os = new ofstream(traceFileName.c_str(), ostream *os = new ofstream(traceFileName.c_str(),
(Force ? 0 : ios::noreplace)|ios::out); (Force ? 0 : ios::noreplace)|ios::out);
if (!os->good()) { if (!os->good()) {
cerr << "Error opening " << traceFileName << "!\n"; cerr << "Error opening " << traceFileName
delete os; << "! SKIPPING OUTPUT OF TRACE CODE\n";
return 1; delete os;
retCode = 1;
}
Passes.push_back(new PrintModulePass("", os,
/*deleteStream*/ true,
/*printAsBytecode*/ ! DebugTrace));
} }
Passes.push_back(new PrintModulePass("", os, true));
}
// If LLVM dumping after transformations is requested, add it to the pipeline // If LLVM dumping after transformations is requested, add it to the pipeline
if (DumpAsm) if (DumpAsm)
Passes.push_back(new PrintModulePass("Method after xformations: \n",&cerr)); Passes.push_back(new PrintModulePass("Code after xformations: \n",&cerr));
// Generate Target code... // Generate Target code...
Passes.push_back(new GenerateCodeForTarget(Target)); Passes.push_back(new GenerateCodeForTarget(Target));
@ -189,7 +192,7 @@ int main(int argc, char **argv) {
// runAllPasses frees the Pass objects after runAllPasses completes. // runAllPasses frees the Pass objects after runAllPasses completes.
Pass::runAllPassesAndFree(M.get(), Passes); Pass::runAllPassesAndFree(M.get(), Passes);
return 0; return retCode;
} }