[llvm-commits] [llvm-gcc-4.2] r47080 - in /llvm-gcc-4.2/trunk/gcc: common.opt llvm-backend.cpp
Devang Patel
dpatel at apple.com
Wed Feb 13 11:12:17 PST 2008
Author: dpatel
Date: Wed Feb 13 13:12:16 2008
New Revision: 47080
URL: http://llvm.org/viewvc/llvm-project?rev=47080&view=rev
Log:
Add hook to dump .bc file before module level optimizer is run. This helps investigate optimizer and code generator bugs which are not easily reproducible using standalone 'opt' and 'llc' tools.
Modified:
llvm-gcc-4.2/trunk/gcc/common.opt
llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
Modified: llvm-gcc-4.2/trunk/gcc/common.opt
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/common.opt?rev=47080&r1=47079&r2=47080&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/common.opt (original)
+++ llvm-gcc-4.2/trunk/gcc/common.opt Wed Feb 13 13:12:16 2008
@@ -233,6 +233,10 @@
fdebug-pass-arguments
Common Report Var(flag_debug_pass_arguments)
Print pass manager arguments
+
+fdebug-llvm-module-opt
+Common Report Var(flag_debug_llvm_module_opt)
+Help debug llvm module-level optimizer
; LLVM LOCAL end
; The version of the C++ ABI in use. The following values are allowed:
Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp?rev=47080&r1=47079&r2=47080&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Wed Feb 13 13:12:16 2008
@@ -79,6 +79,7 @@
TargetMachine *TheTarget = 0;
TypeConverter *TheTypeConverter = 0;
llvm::OStream *AsmOutFile = 0;
+llvm::OStream *AsmIntermediateOutFile = 0;
/// DisableLLVMOptimizations - Allow the user to specify:
/// "-mllvm -disable-llvm-optzns" on the llvm-gcc command line to force llvm
@@ -210,6 +211,7 @@
}
oFILEstream *AsmOutStream = 0;
+oFILEstream *AsmIntermediateOutStream = 0;
/// Read bytecode from PCH file. Initialize TheModule and setup
/// LTypes vector.
@@ -556,7 +558,31 @@
// Finish off the per-function pass.
if (PerFunctionPasses)
PerFunctionPasses->doFinalization();
+
+ // Emit intermediate .bc file before module level optimization passes are run.
+ if (emit_llvm_bc && flag_debug_llvm_module_opt) {
+ static PassManager *IntermediatePM = new PassManager();
+ IntermediatePM->add(new TargetData(*TheTarget->getTargetData()));
+
+ // Emit an LLVM .bc file to the output. This is used when passed
+ // -emit-llvm -c to the GCC driver.
+
+ char asm_intermediate_out_filename[MAXPATHLEN];
+ strcpy(&asm_intermediate_out_filename[0], asm_file_name);
+ strcat(&asm_intermediate_out_filename[0],".0");
+ FILE *asm_intermediate_out_file = fopen(asm_intermediate_out_filename, "w+b");
+ AsmIntermediateOutStream = new oFILEstream(asm_intermediate_out_file);
+ AsmIntermediateOutFile = new OStream(*AsmIntermediateOutStream);
+ IntermediatePM->add(CreateBitcodeWriterPass(*AsmIntermediateOutStream));
+ IntermediatePM->run(*TheModule);
+ AsmIntermediateOutStream->flush();
+ fflush(asm_intermediate_out_file);
+ delete AsmIntermediateOutStream;
+ AsmIntermediateOutStream = 0;
+ delete AsmIntermediateOutFile;
+ AsmIntermediateOutFile = 0;
+ }
// Run module-level optimizers, if any are present.
if (PerModulePasses)
PerModulePasses->run(*TheModule);
More information about the llvm-commits
mailing list