aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-09-04 04:14:57 +0000
committerChris Lattner <sabre@nondot.org>2006-09-04 04:14:57 +0000
commit1911fd4f85aebcd4d7b8f27313c5a363eebf49cb (patch)
tree56477a21ba8925f2c2f1868f0e1ec2229349a50b /tools
parentdd842e12e1a054256314d36f3cab3d59da39fc68 (diff)
downloadexternal_llvm-1911fd4f85aebcd4d7b8f27313c5a363eebf49cb.zip
external_llvm-1911fd4f85aebcd4d7b8f27313c5a363eebf49cb.tar.gz
external_llvm-1911fd4f85aebcd4d7b8f27313c5a363eebf49cb.tar.bz2
Completely rearchitect the interface between targets and the pass manager.
This pass: 1. Splits TargetMachine into TargetMachine (generic targets, can be implemented any way, like the CBE) and LLVMTargetMachine (subclass of TM that is used by things using libcodegen and other support). 2. Instead of having each target fully populate the passmgr for file or JIT output, move all this to common code, and give targets hooks they can implement. 3. Commonalize the target population stuff between file emission and JIT emission. 4. All (native code) codegen stuff now happens in a FunctionPassManager, which paves the way for "fast -O0" stuff in the CFE later, and now LLC could lazily stream .bc files from disk to use less memory. 5. There are now many fewer #includes and the targets don't depend on the scalar xforms or libanalysis anymore (but codegen does). 6. Changing common code generator pass ordering stuff no longer requires touching all targets. 7. The JIT now has the option of "-fast" codegen or normal optimized codegen, which is now orthogonal to the fact that JIT'ing is being done. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30081 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/llc/llc.cpp189
1 files changed, 110 insertions, 79 deletions
diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp
index 917c826..cd04792 100644
--- a/tools/llc/llc.cpp
+++ b/tools/llc/llc.cpp
@@ -101,6 +101,69 @@ GetFileNameRoot(const std::string &InputFilename) {
return outputFilename;
}
+static std::ostream *GetOutputStream(const char *ProgName) {
+ if (OutputFilename != "") {
+ if (OutputFilename == "-")
+ return &std::cout;
+
+ // Specified an output filename?
+ if (!Force && std::ifstream(OutputFilename.c_str())) {
+ // If force is not specified, make sure not to overwrite a file!
+ std::cerr << ProgName << ": error opening '" << OutputFilename
+ << "': file exists!\n"
+ << "Use -f command line argument to force output\n";
+ return 0;
+ }
+ // Make sure that the Out file gets unlinked from the disk if we get a
+ // SIGINT
+ sys::RemoveFileOnSignal(sys::Path(OutputFilename));
+
+ return new std::ofstream(OutputFilename.c_str());
+ }
+
+ if (InputFilename == "-") {
+ OutputFilename = "-";
+ return &std::cout;
+ }
+
+ OutputFilename = GetFileNameRoot(InputFilename);
+
+ switch (FileType) {
+ case TargetMachine::AssemblyFile:
+ if (MArch->Name[0] != 'c' || MArch->Name[1] != 0) // not CBE
+ OutputFilename += ".s";
+ else
+ OutputFilename += ".cbe.c";
+ break;
+ case TargetMachine::ObjectFile:
+ OutputFilename += ".o";
+ break;
+ case TargetMachine::DynamicLibrary:
+ OutputFilename += LTDL_SHLIB_EXT;
+ break;
+ }
+
+ if (!Force && std::ifstream(OutputFilename.c_str())) {
+ // If force is not specified, make sure not to overwrite a file!
+ std::cerr << ProgName << ": error opening '" << OutputFilename
+ << "': file exists!\n"
+ << "Use -f command line argument to force output\n";
+ return 0;
+ }
+
+ // Make sure that the Out file gets unlinked from the disk if we get a
+ // SIGINT
+ sys::RemoveFileOnSignal(sys::Path(OutputFilename));
+
+ std::ostream *Out = new std::ofstream(OutputFilename.c_str());
+ if (!Out->good()) {
+ std::cerr << ProgName << ": error opening " << OutputFilename << "!\n";
+ delete Out;
+ return 0;
+ }
+
+ return Out;
+}
// main - Entry point for the llc compiler.
//
@@ -148,91 +211,59 @@ int main(int argc, char **argv) {
assert(target.get() && "Could not allocate target machine!");
TargetMachine &Target = *target.get();
- // Build up all of the passes that we want to do to the module...
- PassManager Passes;
- Passes.add(new TargetData(*Target.getTargetData()));
-
-#ifndef NDEBUG
- if(!NoVerify)
- Passes.add(createVerifierPass());
-#endif
-
// Figure out where we are going to send the output...
- std::ostream *Out = 0;
- if (OutputFilename != "") {
- if (OutputFilename != "-") {
- // Specified an output filename?
- if (!Force && std::ifstream(OutputFilename.c_str())) {
- // If force is not specified, make sure not to overwrite a file!
- std::cerr << argv[0] << ": error opening '" << OutputFilename
- << "': file exists!\n"
- << "Use -f command line argument to force output\n";
- return 1;
- }
- Out = new std::ofstream(OutputFilename.c_str());
-
- // Make sure that the Out file gets unlinked from the disk if we get a
- // SIGINT
- sys::RemoveFileOnSignal(sys::Path(OutputFilename));
- } else {
- Out = &std::cout;
+ std::ostream *Out = GetOutputStream(argv[0]);
+ if (Out == 0) return 1;
+
+ // If this target requires addPassesToEmitWholeFile, do it now. This is
+ // used by strange things like the C backend.
+ if (Target.WantsWholeFile()) {
+ PassManager PM;
+ PM.add(new TargetData(*Target.getTargetData()));
+ if (!NoVerify)
+ PM.add(createVerifierPass());
+
+ // Ask the target to add backend passes as necessary.
+ if (Target.addPassesToEmitWholeFile(PM, *Out, FileType, Fast)) {
+ std::cerr << argv[0] << ": target does not support generation of this"
+ << " file type!\n";
+ if (Out != &std::cout) delete Out;
+ // And the Out file is empty and useless, so remove it now.
+ sys::Path(OutputFilename).eraseFromDisk();
+ return 1;
}
+ PM.run(mod);
} else {
- if (InputFilename == "-") {
- OutputFilename = "-";
- Out = &std::cout;
- } else {
- OutputFilename = GetFileNameRoot(InputFilename);
-
- switch (FileType) {
- case TargetMachine::AssemblyFile:
- if (MArch->Name[0] != 'c' || MArch->Name[1] != 0) // not CBE
- OutputFilename += ".s";
- else
- OutputFilename += ".cbe.c";
- break;
- case TargetMachine::ObjectFile:
- OutputFilename += ".o";
- break;
- case TargetMachine::DynamicLibrary:
- OutputFilename += LTDL_SHLIB_EXT;
- break;
- }
-
- if (!Force && std::ifstream(OutputFilename.c_str())) {
- // If force is not specified, make sure not to overwrite a file!
- std::cerr << argv[0] << ": error opening '" << OutputFilename
- << "': file exists!\n"
- << "Use -f command line argument to force output\n";
- return 1;
- }
-
- Out = new std::ofstream(OutputFilename.c_str());
- if (!Out->good()) {
- std::cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
- delete Out;
- return 1;
- }
-
- // Make sure that the Out file gets unlinked from the disk if we get a
- // SIGINT
- sys::RemoveFileOnSignal(sys::Path(OutputFilename));
+ // Build up all of the passes that we want to do to the module.
+ FunctionPassManager Passes(new ExistingModuleProvider(M.get()));
+ Passes.add(new TargetData(*Target.getTargetData()));
+
+#ifndef NDEBUG
+ if (!NoVerify)
+ Passes.add(createVerifierPass());
+#endif
+
+ // Ask the target to add backend passes as necessary.
+ if (Target.addPassesToEmitFile(Passes, *Out, FileType, Fast)) {
+ std::cerr << argv[0] << ": target does not support generation of this"
+ << " file type!\n";
+ if (Out != &std::cout) delete Out;
+ // And the Out file is empty and useless, so remove it now.
+ sys::Path(OutputFilename).eraseFromDisk();
+ return 1;
}
- }
-
- // Ask the target to add backend passes as necessary.
- if (Target.addPassesToEmitFile(Passes, *Out, FileType, Fast)) {
- std::cerr << argv[0] << ": target does not support generation of this"
- << " file type!\n";
- if (Out != &std::cout) delete Out;
- // And the Out file is empty and useless, so remove it now.
- sys::Path(OutputFilename).eraseFromDisk();
- return 1;
- } else {
+
+ Passes.doInitialization();
+
// Run our queue of passes all at once now, efficiently.
- Passes.run(*M.get());
+ // TODO: this could lazily stream functions out of the module.
+ for (Module::iterator I = mod.begin(), E = mod.end(); I != E; ++I)
+ if (!I->isExternal())
+ Passes.run(*I);
+
+ Passes.doFinalization();
}
-
+
// Delete the ostream if it's not a stdout stream
if (Out != &std::cout) delete Out;