diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/gold/gold-plugin.cpp | 1 | ||||
-rw-r--r-- | tools/llc/llc.cpp | 2 | ||||
-rw-r--r-- | tools/lli/lli.cpp | 3 | ||||
-rw-r--r-- | tools/llvm-as/llvm-as.cpp | 66 | ||||
-rw-r--r-- | tools/llvm-ld/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tools/llvm-ld/Makefile | 1 | ||||
-rw-r--r-- | tools/llvm-ld/llvm-ld.cpp | 339 | ||||
-rw-r--r-- | tools/llvm-mc/AsmParser.cpp | 46 | ||||
-rw-r--r-- | tools/llvm-prof/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tools/llvm-prof/Makefile | 1 | ||||
-rw-r--r-- | tools/llvm-prof/llvm-prof.cpp | 65 | ||||
-rw-r--r-- | tools/llvmc/doc/LLVMC-Reference.rst | 5 | ||||
-rw-r--r-- | tools/llvmc/example/mcc16/driver/Main.cpp | 13 | ||||
-rw-r--r-- | tools/llvmc/example/mcc16/plugins/PIC16Base/PIC16Base.td | 141 | ||||
-rw-r--r-- | tools/llvmc/example/mcc16/plugins/PIC16Base/PluginMain.cpp | 8 | ||||
-rw-r--r-- | tools/llvmc/plugins/Base/Base.td.in | 32 | ||||
-rw-r--r-- | tools/opt/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tools/opt/Makefile | 1 | ||||
-rw-r--r-- | tools/opt/opt.cpp | 313 |
19 files changed, 586 insertions, 454 deletions
diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp index 6520617..b1562d1 100644 --- a/tools/gold/gold-plugin.cpp +++ b/tools/gold/gold-plugin.cpp @@ -12,6 +12,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Config/config.h" #include "plugin-api.h" #include "llvm-c/lto.h" diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index b94e5fb..84e6867 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -298,7 +298,7 @@ int main(int argc, char **argv) { return 1; case ' ': break; case '0': OLvl = CodeGenOpt::None; break; - case '1': + case '1': OLvl = CodeGenOpt::Less; break; case '2': OLvl = CodeGenOpt::Default; break; case '3': OLvl = CodeGenOpt::Aggressive; break; } diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp index e5c1070..4578c4e 100644 --- a/tools/lli/lli.cpp +++ b/tools/lli/lli.cpp @@ -148,7 +148,7 @@ int main(int argc, char **argv, char * const *envp) { return 1; case ' ': break; case '0': OLvl = CodeGenOpt::None; break; - case '1': + case '1': OLvl = CodeGenOpt::Less; break; case '2': OLvl = CodeGenOpt::Default; break; case '3': OLvl = CodeGenOpt::Aggressive; break; } @@ -163,7 +163,6 @@ int main(int argc, char **argv, char * const *envp) { exit(1); } - EE->RegisterJITEventListener(createMacOSJITEventListener()); EE->RegisterJITEventListener(createOProfileJITEventListener()); if (NoLazyCompilation) diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp index d510297..d39d6c8 100644 --- a/tools/llvm-as/llvm-as.cpp +++ b/tools/llvm-as/llvm-as.cpp @@ -50,34 +50,7 @@ static cl::opt<bool> DisableVerify("disable-verify", cl::Hidden, cl::desc("Do not run verifier on input LLVM (dangerous!)")); -int main(int argc, char **argv) { - // Print a stack trace if we signal out. - sys::PrintStackTraceOnErrorSignal(); - PrettyStackTraceProgram X(argc, argv); - LLVMContext &Context = getGlobalContext(); - llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. - cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n"); - - // Parse the file now... - SMDiagnostic Err; - std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename, Err, Context)); - if (M.get() == 0) { - Err.Print(argv[0], errs()); - return 1; - } - - if (!DisableVerify) { - std::string Err; - if (verifyModule(*M.get(), ReturnStatusAction, &Err)) { - errs() << argv[0] - << ": assembly parsed, but does not verify as correct!\n"; - errs() << Err; - return 1; - } - } - - if (DumpAsm) errs() << "Here's the assembly:\n" << *M.get(); - +static void WriteOutputFile(const Module *M) { // Infer the output filename if needed. if (OutputFilename.empty()) { if (InputFilename == "-") { @@ -106,12 +79,43 @@ int main(int argc, char **argv) { raw_fd_ostream::F_Binary)); if (!ErrorInfo.empty()) { errs() << ErrorInfo << '\n'; + exit(1); + } + + if (Force || !CheckBitcodeOutputToConsole(*Out, true)) + WriteBitcodeToFile(M, *Out); +} + +int main(int argc, char **argv) { + // Print a stack trace if we signal out. + sys::PrintStackTraceOnErrorSignal(); + PrettyStackTraceProgram X(argc, argv); + LLVMContext &Context = getGlobalContext(); + llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. + cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n"); + + // Parse the file now... + SMDiagnostic Err; + std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename, Err, Context)); + if (M.get() == 0) { + Err.Print(argv[0], errs()); return 1; } + if (!DisableVerify) { + std::string Err; + if (verifyModule(*M.get(), ReturnStatusAction, &Err)) { + errs() << argv[0] + << ": assembly parsed, but does not verify as correct!\n"; + errs() << Err; + return 1; + } + } + + if (DumpAsm) errs() << "Here's the assembly:\n" << *M.get(); + if (!DisableOutput) - if (Force || !CheckBitcodeOutputToConsole(*Out, true)) - WriteBitcodeToFile(M.get(), *Out); + WriteOutputFile(M.get()); + return 0; } - diff --git a/tools/llvm-ld/CMakeLists.txt b/tools/llvm-ld/CMakeLists.txt index 51f0dc1..2ae4a1d 100644 --- a/tools/llvm-ld/CMakeLists.txt +++ b/tools/llvm-ld/CMakeLists.txt @@ -1,5 +1,4 @@ set(LLVM_LINK_COMPONENTS ipo scalaropts linker archive bitwriter) -set(LLVM_REQUIRES_EH 1) add_llvm_tool(llvm-ld Optimize.cpp diff --git a/tools/llvm-ld/Makefile b/tools/llvm-ld/Makefile index 92cac2a..1ef9bf1 100644 --- a/tools/llvm-ld/Makefile +++ b/tools/llvm-ld/Makefile @@ -11,6 +11,5 @@ LEVEL = ../.. TOOLNAME = llvm-ld LINK_COMPONENTS = ipo scalaropts linker archive bitwriter -REQUIRES_EH := 1 include $(LEVEL)/Makefile.common diff --git a/tools/llvm-ld/llvm-ld.cpp b/tools/llvm-ld/llvm-ld.cpp index ef3c250..e71aefc 100644 --- a/tools/llvm-ld/llvm-ld.cpp +++ b/tools/llvm-ld/llvm-ld.cpp @@ -513,205 +513,200 @@ int main(int argc, char **argv, char **envp) { LLVMContext &Context = getGlobalContext(); llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. - try { - // Initial global variable above for convenience printing of program name. - progname = sys::Path(argv[0]).getBasename(); - - // Parse the command line options - cl::ParseCommandLineOptions(argc, argv, "llvm linker\n"); - - // Construct a Linker (now that Verbose is set) - Linker TheLinker(progname, OutputFilename, Context, Verbose); - - // Keep track of the native link items (versus the bitcode items) - Linker::ItemList NativeLinkItems; - - // Add library paths to the linker - TheLinker.addPaths(LibPaths); - TheLinker.addSystemPaths(); - - // Remove any consecutive duplicates of the same library... - Libraries.erase(std::unique(Libraries.begin(), Libraries.end()), - Libraries.end()); - - if (LinkAsLibrary) { - std::vector<sys::Path> Files; - for (unsigned i = 0; i < InputFilenames.size(); ++i ) - Files.push_back(sys::Path(InputFilenames[i])); - if (TheLinker.LinkInFiles(Files)) - return 1; // Error already printed - - // The libraries aren't linked in but are noted as "dependent" in the - // module. - for (cl::list<std::string>::const_iterator I = Libraries.begin(), - E = Libraries.end(); I != E ; ++I) { - TheLinker.getModule()->addLibrary(*I); - } - } else { - // Build a list of the items from our command line - Linker::ItemList Items; - BuildLinkItems(Items, InputFilenames, Libraries); - - // Link all the items together - if (TheLinker.LinkInItems(Items, NativeLinkItems) ) - return 1; // Error already printed + + // Initial global variable above for convenience printing of program name. + progname = sys::Path(argv[0]).getBasename(); + + // Parse the command line options + cl::ParseCommandLineOptions(argc, argv, "llvm linker\n"); + + // Construct a Linker (now that Verbose is set) + Linker TheLinker(progname, OutputFilename, Context, Verbose); + + // Keep track of the native link items (versus the bitcode items) + Linker::ItemList NativeLinkItems; + + // Add library paths to the linker + TheLinker.addPaths(LibPaths); + TheLinker.addSystemPaths(); + + // Remove any consecutive duplicates of the same library... + Libraries.erase(std::unique(Libraries.begin(), Libraries.end()), + Libraries.end()); + + if (LinkAsLibrary) { + std::vector<sys::Path> Files; + for (unsigned i = 0; i < InputFilenames.size(); ++i ) + Files.push_back(sys::Path(InputFilenames[i])); + if (TheLinker.LinkInFiles(Files)) + return 1; // Error already printed + + // The libraries aren't linked in but are noted as "dependent" in the + // module. + for (cl::list<std::string>::const_iterator I = Libraries.begin(), + E = Libraries.end(); I != E ; ++I) { + TheLinker.getModule()->addLibrary(*I); } + } else { + // Build a list of the items from our command line + Linker::ItemList Items; + BuildLinkItems(Items, InputFilenames, Libraries); + + // Link all the items together + if (TheLinker.LinkInItems(Items, NativeLinkItems) ) + return 1; // Error already printed + } - std::auto_ptr<Module> Composite(TheLinker.releaseModule()); + std::auto_ptr<Module> Composite(TheLinker.releaseModule()); - // Optimize the module - Optimize(Composite.get()); + // Optimize the module + Optimize(Composite.get()); #if defined(_WIN32) || defined(__CYGWIN__) - if (!LinkAsLibrary) { - // Default to "a.exe" instead of "a.out". - if (OutputFilename.getNumOccurrences() == 0) - OutputFilename = "a.exe"; - - // If there is no suffix add an "exe" one. - sys::Path ExeFile( OutputFilename ); - if (ExeFile.getSuffix() == "") { - ExeFile.appendSuffix("exe"); - OutputFilename = ExeFile.str(); - } + if (!LinkAsLibrary) { + // Default to "a.exe" instead of "a.out". + if (OutputFilename.getNumOccurrences() == 0) + OutputFilename = "a.exe"; + + // If there is no suffix add an "exe" one. + sys::Path ExeFile( OutputFilename ); + if (ExeFile.getSuffix() == "") { + ExeFile.appendSuffix("exe"); + OutputFilename = ExeFile.str(); } + } #endif - // Generate the bitcode for the optimized module. - // If -b wasn't specified, use the name specified - // with -o to construct BitcodeOutputFilename. - if (BitcodeOutputFilename.empty()) { - BitcodeOutputFilename = OutputFilename; - if (!LinkAsLibrary) BitcodeOutputFilename += ".bc"; - } + // Generate the bitcode for the optimized module. + // If -b wasn't specified, use the name specified + // with -o to construct BitcodeOutputFilename. + if (BitcodeOutputFilename.empty()) { + BitcodeOutputFilename = OutputFilename; + if (!LinkAsLibrary) BitcodeOutputFilename += ".bc"; + } - GenerateBitcode(Composite.get(), BitcodeOutputFilename); - - // If we are not linking a library, generate either a native executable - // or a JIT shell script, depending upon what the user wants. - if (!LinkAsLibrary) { - // If the user wants to run a post-link optimization, run it now. - if (!PostLinkOpts.empty()) { - std::vector<std::string> opts = PostLinkOpts; - for (std::vector<std::string>::iterator I = opts.begin(), - E = opts.end(); I != E; ++I) { - sys::Path prog(*I); - if (!prog.canExecute()) { - prog = sys::Program::FindProgramByName(*I); - if (prog.isEmpty()) - PrintAndExit(std::string("Optimization program '") + *I + - "' is not found or not executable."); - } - // Get the program arguments - sys::Path tmp_output("opt_result"); - std::string ErrMsg; - if (tmp_output.createTemporaryFileOnDisk(true, &ErrMsg)) - PrintAndExit(ErrMsg); - - const char* args[4]; - args[0] = I->c_str(); - args[1] = BitcodeOutputFilename.c_str(); - args[2] = tmp_output.c_str(); - args[3] = 0; - if (0 == sys::Program::ExecuteAndWait(prog, args, 0,0,0,0, &ErrMsg)) { - if (tmp_output.isBitcodeFile() || tmp_output.isBitcodeFile()) { - sys::Path target(BitcodeOutputFilename); - target.eraseFromDisk(); - if (tmp_output.renamePathOnDisk(target, &ErrMsg)) - PrintAndExit(ErrMsg, 2); - } else - PrintAndExit("Post-link optimization output is not bitcode"); - } else { - PrintAndExit(ErrMsg); - } + GenerateBitcode(Composite.get(), BitcodeOutputFilename); + + // If we are not linking a library, generate either a native executable + // or a JIT shell script, depending upon what the user wants. + if (!LinkAsLibrary) { + // If the user wants to run a post-link optimization, run it now. + if (!PostLinkOpts.empty()) { + std::vector<std::string> opts = PostLinkOpts; + for (std::vector<std::string>::iterator I = opts.begin(), + E = opts.end(); I != E; ++I) { + sys::Path prog(*I); + if (!prog.canExecute()) { + prog = sys::Program::FindProgramByName(*I); + if (prog.isEmpty()) + PrintAndExit(std::string("Optimization program '") + *I + + "' is not found or not executable."); } - } - - // If the user wants to generate a native executable, compile it from the - // bitcode file. - // - // Otherwise, create a script that will run the bitcode through the JIT. - if (Native) { - // Name of the Assembly Language output file - sys::Path AssemblyFile ( OutputFilename); - AssemblyFile.appendSuffix("s"); - - // Mark the output files for removal if we get an interrupt. - sys::RemoveFileOnSignal(AssemblyFile); - sys::RemoveFileOnSignal(sys::Path(OutputFilename)); - - // Determine the locations of the llc and gcc programs. - sys::Path llc = FindExecutable("llc", argv[0], - (void *)(intptr_t)&Optimize); - if (llc.isEmpty()) - PrintAndExit("Failed to find llc"); - - sys::Path gcc = sys::Program::FindProgramByName("gcc"); - if (gcc.isEmpty()) - PrintAndExit("Failed to find gcc"); - - // Generate an assembly language file for the bitcode. + // Get the program arguments + sys::Path tmp_output("opt_result"); std::string ErrMsg; - if (0 != GenerateAssembly(AssemblyFile.str(), BitcodeOutputFilename, - llc, ErrMsg)) + if (tmp_output.createTemporaryFileOnDisk(true, &ErrMsg)) PrintAndExit(ErrMsg); - if (0 != GenerateNative(OutputFilename, AssemblyFile.str(), - NativeLinkItems, gcc, envp, ErrMsg)) + const char* args[4]; + args[0] = I->c_str(); + args[1] = BitcodeOutputFilename.c_str(); + args[2] = tmp_output.c_str(); + args[3] = 0; + if (0 == sys::Program::ExecuteAndWait(prog, args, 0,0,0,0, &ErrMsg)) { + if (tmp_output.isBitcodeFile() || tmp_output.isBitcodeFile()) { + sys::Path target(BitcodeOutputFilename); + target.eraseFromDisk(); + if (tmp_output.renamePathOnDisk(target, &ErrMsg)) + PrintAndExit(ErrMsg, 2); + } else + PrintAndExit("Post-link optimization output is not bitcode"); + } else { PrintAndExit(ErrMsg); + } + } + } - // Remove the assembly language file. - AssemblyFile.eraseFromDisk(); - } else if (NativeCBE) { - sys::Path CFile (OutputFilename); - CFile.appendSuffix("cbe.c"); - - // Mark the output files for removal if we get an interrupt. - sys::RemoveFileOnSignal(CFile); - sys::RemoveFileOnSignal(sys::Path(OutputFilename)); - - // Determine the locations of the llc and gcc programs. - sys::Path llc = FindExecutable("llc", argv[0], - (void *)(intptr_t)&Optimize); - if (llc.isEmpty()) - PrintAndExit("Failed to find llc"); + // If the user wants to generate a native executable, compile it from the + // bitcode file. + // + // Otherwise, create a script that will run the bitcode through the JIT. + if (Native) { + // Name of the Assembly Language output file + sys::Path AssemblyFile ( OutputFilename); + AssemblyFile.appendSuffix("s"); + + // Mark the output files for removal if we get an interrupt. + sys::RemoveFileOnSignal(AssemblyFile); + sys::RemoveFileOnSignal(sys::Path(OutputFilename)); + + // Determine the locations of the llc and gcc programs. + sys::Path llc = FindExecutable("llc", argv[0], + (void *)(intptr_t)&Optimize); + if (llc.isEmpty()) + PrintAndExit("Failed to find llc"); + + sys::Path gcc = sys::Program::FindProgramByName("gcc"); + if (gcc.isEmpty()) + PrintAndExit("Failed to find gcc"); + + // Generate an assembly language file for the bitcode. + std::string ErrMsg; + if (0 != GenerateAssembly(AssemblyFile.str(), BitcodeOutputFilename, + llc, ErrMsg)) + PrintAndExit(ErrMsg); - sys::Path gcc = sys::Program::FindProgramByName("gcc"); - if (gcc.isEmpty()) - PrintAndExit("Failed to find gcc"); + if (0 != GenerateNative(OutputFilename, AssemblyFile.str(), + NativeLinkItems, gcc, envp, ErrMsg)) + PrintAndExit(ErrMsg); - // Generate an assembly language file for the bitcode. - std::string ErrMsg; - if (GenerateCFile(CFile.str(), BitcodeOutputFilename, llc, ErrMsg)) - PrintAndExit(ErrMsg); + // Remove the assembly language file. + AssemblyFile.eraseFromDisk(); + } else if (NativeCBE) { + sys::Path CFile (OutputFilename); + CFile.appendSuffix("cbe.c"); - if (GenerateNative(OutputFilename, CFile.str(), - NativeLinkItems, gcc, envp, ErrMsg)) - PrintAndExit(ErrMsg); + // Mark the output files for removal if we get an interrupt. + sys::RemoveFileOnSignal(CFile); + sys::RemoveFileOnSignal(sys::Path(OutputFilename)); - // Remove the assembly language file. - CFile.eraseFromDisk(); + // Determine the locations of the llc and gcc programs. + sys::Path llc = FindExecutable("llc", argv[0], + (void *)(intptr_t)&Optimize); + if (llc.isEmpty()) + PrintAndExit("Failed to find llc"); - } else { - EmitShellScript(argv); - } + sys::Path gcc = sys::Program::FindProgramByName("gcc"); + if (gcc.isEmpty()) + PrintAndExit("Failed to find gcc"); - // Make the script executable... + // Generate an assembly language file for the bitcode. std::string ErrMsg; - if (sys::Path(OutputFilename).makeExecutableOnDisk(&ErrMsg)) + if (GenerateCFile(CFile.str(), BitcodeOutputFilename, llc, ErrMsg)) PrintAndExit(ErrMsg); - // Make the bitcode file readable and directly executable in LLEE as well - if (sys::Path(BitcodeOutputFilename).makeExecutableOnDisk(&ErrMsg)) + if (GenerateNative(OutputFilename, CFile.str(), + NativeLinkItems, gcc, envp, ErrMsg)) PrintAndExit(ErrMsg); - if (sys::Path(BitcodeOutputFilename).makeReadableOnDisk(&ErrMsg)) - PrintAndExit(ErrMsg); + // Remove the assembly language file. + CFile.eraseFromDisk(); + + } else { + EmitShellScript(argv); } - } catch (const std::string& msg) { - PrintAndExit(msg,2); - } catch (...) { - PrintAndExit("Unexpected unknown exception occurred.", 2); + + // Make the script executable... + std::string ErrMsg; + if (sys::Path(OutputFilename).makeExecutableOnDisk(&ErrMsg)) + PrintAndExit(ErrMsg); + + // Make the bitcode file readable and directly executable in LLEE as well + if (sys::Path(BitcodeOutputFilename).makeExecutableOnDisk(&ErrMsg)) + PrintAndExit(ErrMsg); + + if (sys::Path(BitcodeOutputFilename).makeReadableOnDisk(&ErrMsg)) + PrintAndExit(ErrMsg); } // Graceful exit diff --git a/tools/llvm-mc/AsmParser.cpp b/tools/llvm-mc/AsmParser.cpp index aae27f5d..436f17d 100644 --- a/tools/llvm-mc/AsmParser.cpp +++ b/tools/llvm-mc/AsmParser.cpp @@ -21,6 +21,7 @@ #include "llvm/MC/MCSectionMachO.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCValue.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetAsmParser.h" @@ -220,12 +221,22 @@ bool AsmParser::ParsePrimaryExpr(const MCExpr *&Res) { Res = MCUnaryExpr::CreateLNot(Res, getContext()); return false; case AsmToken::String: - case AsmToken::Identifier: - // This is a label, this should be parsed as part of an expression, to - // handle things like LFOO+4. - Res = MCSymbolRefExpr::Create(Lexer.getTok().getIdentifier(), getContext()); + case AsmToken::Identifier: { + // This is a symbol reference. + MCSymbol *Sym = CreateSymbol(Lexer.getTok().getIdentifier()); Lexer.Lex(); // Eat identifier. + + // If this is an absolute variable reference, substitute it now to preserve + // semantics in the face of reassignment. + if (Sym->getValue() && isa<MCConstantExpr>(Sym->getValue())) { + Res = Sym->getValue(); + return false; + } + + // Otherwise create a symbol ref. + Res = MCSymbolRefExpr::Create(Sym, getContext()); return false; + } case AsmToken::Integer: Res = MCConstantExpr::Create(Lexer.getTok().getIntVal(), getContext()); Lexer.Lex(); // Eat token. @@ -281,7 +292,7 @@ bool AsmParser::ParseAbsoluteExpression(int64_t &Res) { if (ParseExpression(Expr)) return true; - if (!Expr->EvaluateAsAbsolute(Ctx, Res)) + if (!Expr->EvaluateAsAbsolute(Res)) return Error(StartLoc, "expected absolute expression"); return false; @@ -730,14 +741,25 @@ bool AsmParser::ParseAssignment(const StringRef &Name) { // Eat the end of statement marker. Lexer.Lex(); - // Diagnose assignment to a label. - // - // FIXME: Diagnostics. Note the location of the definition as a label. + // Validate that the LHS is allowed to be a variable (either it has not been + // used as a symbol, or it is an absolute symbol). + MCSymbol *Sym = getContext().LookupSymbol(Name); + if (Sym) { + // Diagnose assignment to a label. + // + // FIXME: Diagnostics. Note the location of the definition as a label. + // FIXME: Diagnose assignment to protected identifier (e.g., register name). + if (!Sym->isUndefined() && !Sym->isAbsolute()) + return Error(EqualLoc, "redefinition of '" + Name + "'"); + else if (!Sym->isVariable()) + return Error(EqualLoc, "invalid assignment to '" + Name + "'"); + else if (!isa<MCConstantExpr>(Sym->getValue())) + return Error(EqualLoc, "invalid reassignment of non-absolute variable '" + + Name + "'"); + } else + Sym = CreateSymbol(Name); + // FIXME: Handle '.'. - // FIXME: Diagnose assignment to protected identifier (e.g., register name). - MCSymbol *Sym = CreateSymbol(Name); - if (!Sym->isUndefined() && !Sym->isAbsolute()) - return Error(EqualLoc, "symbol has already been defined"); // Do the assignment. Out.EmitAssignment(Sym, Value); diff --git a/tools/llvm-prof/CMakeLists.txt b/tools/llvm-prof/CMakeLists.txt index 9a51150..442112b 100644 --- a/tools/llvm-prof/CMakeLists.txt +++ b/tools/llvm-prof/CMakeLists.txt @@ -1,5 +1,4 @@ set(LLVM_LINK_COMPONENTS bitreader analysis) -set(LLVM_REQUIRES_EH 1) add_llvm_tool(llvm-prof llvm-prof.cpp diff --git a/tools/llvm-prof/Makefile b/tools/llvm-prof/Makefile index 3c4948e..86eb54d 100644 --- a/tools/llvm-prof/Makefile +++ b/tools/llvm-prof/Makefile @@ -10,7 +10,6 @@ LEVEL = ../.. TOOLNAME = llvm-prof LINK_COMPONENTS = bitreader analysis -REQUIRES_EH := 1 # This tool has no plugins, optimize startup time. TOOL_NO_EXPORTS = 1 diff --git a/tools/llvm-prof/llvm-prof.cpp b/tools/llvm-prof/llvm-prof.cpp index cff139e..88adeb4 100644 --- a/tools/llvm-prof/llvm-prof.cpp +++ b/tools/llvm-prof/llvm-prof.cpp @@ -255,41 +255,34 @@ int main(int argc, char **argv) { LLVMContext &Context = getGlobalContext(); llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. - try { - cl::ParseCommandLineOptions(argc, argv, "llvm profile dump decoder\n"); - - // Read in the bitcode file... - std::string ErrorMessage; - Module *M = 0; - if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(BitcodeFile, - &ErrorMessage)) { - M = ParseBitcodeFile(Buffer, Context, &ErrorMessage); - delete Buffer; - } - if (M == 0) { - errs() << argv[0] << ": " << BitcodeFile << ": " - << ErrorMessage << "\n"; - return 1; - } - - // Read the profiling information. This is redundant since we load it again - // using the standard profile info provider pass, but for now this gives us - // access to additional information not exposed via the ProfileInfo - // interface. - ProfileInfoLoader PIL(argv[0], ProfileDataFile, *M); - - // Run the printer pass. - PassManager PassMgr; - PassMgr.add(createProfileLoaderPass(ProfileDataFile)); - PassMgr.add(new ProfileInfoPrinterPass(PIL)); - PassMgr.run(*M); - - return 0; - } catch (const std::string& msg) { - errs() << argv[0] << ": " << msg << "\n"; - } catch (...) { - errs() << argv[0] << ": Unexpected unknown exception occurred.\n"; - } - return 1; + cl::ParseCommandLineOptions(argc, argv, "llvm profile dump decoder\n"); + + // Read in the bitcode file... + std::string ErrorMessage; + Module *M = 0; + if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(BitcodeFile, + &ErrorMessage)) { + M = ParseBitcodeFile(Buffer, Context, &ErrorMessage); + delete Buffer; + } + if (M == 0) { + errs() << argv[0] << ": " << BitcodeFile << ": " + << ErrorMessage << "\n"; + return 1; + } + + // Read the profiling information. This is redundant since we load it again + // using the standard profile info provider pass, but for now this gives us + // access to additional information not exposed via the ProfileInfo + // interface. + ProfileInfoLoader PIL(argv[0], ProfileDataFile, *M); + + // Run the printer pass. + PassManager PassMgr; + PassMgr.add(createProfileLoaderPass(ProfileDataFile)); + PassMgr.add(new ProfileInfoPrinterPass(PIL)); + PassMgr.run(*M); + + return 0; } diff --git a/tools/llvmc/doc/LLVMC-Reference.rst b/tools/llvmc/doc/LLVMC-Reference.rst index fad2ccc..7041bd1 100644 --- a/tools/llvmc/doc/LLVMC-Reference.rst +++ b/tools/llvmc/doc/LLVMC-Reference.rst @@ -349,8 +349,9 @@ separate option groups syntactically. - ``multi_val n`` - this option takes *n* arguments (can be useful in some special cases). Usage example: ``(parameter_list_option "foo", (multi_val - 3))``. Only list options can have this attribute; you can, however, use - the ``one_or_more`` and ``zero_or_one`` properties. + 3))``; the command-line syntax is '-foo a b c'. Only list options can have + this attribute; you can, however, use the ``one_or_more``, ``zero_or_one`` + and ``required`` properties. - ``init`` - this option has a default value, either a string (if it is a parameter), or a boolean (if it is a switch; boolean constants are called diff --git a/tools/llvmc/example/mcc16/driver/Main.cpp b/tools/llvmc/example/mcc16/driver/Main.cpp index f42e17f..5d50f9d 100644 --- a/tools/llvmc/example/mcc16/driver/Main.cpp +++ b/tools/llvmc/example/mcc16/driver/Main.cpp @@ -13,18 +13,31 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Config/config.h" #include "llvm/CompilerDriver/BuiltinOptions.h" #include "llvm/CompilerDriver/ForceLinkage.h" #include "llvm/System/Path.h" +#include <iostream> namespace llvmc { int Main(int argc, char** argv); } +// Modify the PACKAGE_VERSION to use build number in top level configure file. +void PIC16VersionPrinter(void) { + std::cout << "MPLAB C16 1.0 " << PACKAGE_VERSION << "\n"; +} + int main(int argc, char** argv) { // HACK SaveTemps.setHiddenFlag(llvm::cl::Hidden); + TempDirname.setHiddenFlag(llvm::cl::Hidden); + Languages.setHiddenFlag(llvm::cl::Hidden); + DryRun.setHiddenFlag(llvm::cl::Hidden); + + llvm::cl::SetVersionPrinter(PIC16VersionPrinter); + TempDirname = "tmp-objs"; // Remove the temp dir if already exists. diff --git a/tools/llvmc/example/mcc16/plugins/PIC16Base/PIC16Base.td b/tools/llvmc/example/mcc16/plugins/PIC16Base/PIC16Base.td index 3d25ab6..df9b99e 100644 --- a/tools/llvmc/example/mcc16/plugins/PIC16Base/PIC16Base.td +++ b/tools/llvmc/example/mcc16/plugins/PIC16Base/PIC16Base.td @@ -11,85 +11,149 @@ include "llvm/CompilerDriver/Common.td" def OptionList : OptionList<[ (switch_option "g", (help "Enable Debugging")), + (switch_option "E", + (help "Stop after preprocessing, do not compile")), (switch_option "S", (help "Stop after compilation, do not assemble")), + (switch_option "bc", + (help "Stop after b-code generation, do not compile")), (switch_option "c", (help "Stop after assemble, do not link")), - (parameter_option "I", + (prefix_list_option "I", (help "Add a directory to include path")), - (parameter_option "pre-RA-sched", - (help "Example of an option that is passed to llc")), + (prefix_list_option "L", + (help "Add a directory to library path")), + (prefix_list_option "K", + (help "Add a directory to linker script search path")), + (parameter_option "l", + (help "Specify a library to link")), + (parameter_option "k", + (help "Specify a linker script")), + (parameter_option "m", + (help "Generate linker map file with the given name")), + (prefix_list_option "D", + (help "Define a macro")), + (switch_option "O0", + (help "Do not optimize")), +// (switch_option "O1", +// (help "Optimization level 1")), +// (switch_option "O2", +// (help "Optimization level 2. (Default)")), +// (parameter_option "pre-RA-sched", +// (help "Example of an option that is passed to llc")), (prefix_list_option "Wa,", (help "Pass options to native assembler")), (prefix_list_option "Wl,", - (help "Pass options to native linker")), - (prefix_list_option "Wllc,", - (help "Pass options to llc")), - (prefix_list_option "Wo,", - (help "Pass options to llvm-ld")) + (help "Pass options to native linker")) +// (prefix_list_option "Wllc,", +// (help "Pass options to llc")), +// (prefix_list_option "Wo,", +// (help "Pass options to llvm-ld")) ]>; // Tools - -def clang_cc : Tool<[ - (in_language "c"), +class clang_based<string language, string cmd, string ext_E> : Tool< +[(in_language language), (out_language "llvm-bitcode"), (output_suffix "bc"), - (cmd_line "$CALL(GetBinDir)clang-cc -I $CALL(GetStdHeadersDir) -triple=pic16- -emit-llvm-bc $INFILE -o $OUTFILE"), - (actions (case - (not_empty "I"), (forward "I"))), + (cmd_line (case + (switch_on "E"), + (case + (not_empty "o"), !strconcat(cmd, " -E $INFILE -o $OUTFILE"), + (default), !strconcat(cmd, " -E $INFILE")), + (default), !strconcat(cmd, " $INFILE -o $OUTFILE"))), + (actions (case + (and (multiple_input_files), (or (switch_on "S"), (switch_on "c"))), + (error "cannot specify -o with -c or -S with multiple files"), + (switch_on "E"), [(stop_compilation), (output_suffix ext_E)], + (switch_on "bc"),[(stop_compilation), (output_suffix "bc")], + (switch_on "g"), (append_cmd "-g"), + (not_empty "D"), (forward "D"), + (not_empty "I"), (forward "I"))), (sink) ]>; +def clang_cc : clang_based<"c", "$CALL(GetBinDir)clang-cc -I $CALL(GetStdHeadersDir) -triple=pic16- -emit-llvm-bc ", "i">; + +//def clang_cc : Tool<[ +// (in_language "c"), +// (out_language "llvm-bitcode"), +// (output_suffix "bc"), +// (cmd_line "$CALL(GetBinDir)clang-cc -I $CALL(GetStdHeadersDir) -triple=pic16- -emit-llvm-bc "), +// (cmd_line kkkkk +// (actions (case +// (switch_on "g"), (append_cmd "g"), +// (not_empty "I"), (forward "I"))), +// (sink) +//]>; + + +// pre-link-and-lto step. def llvm_ld : Tool<[ (in_language "llvm-bitcode"), (out_language "llvm-bitcode"), (output_suffix "bc"), - (cmd_line "$CALL(GetBinDir)llvm-ld -link-as-library $INFILE -o $OUTFILE"), + (cmd_line "$CALL(GetBinDir)llvm-ld -L $CALL(GetStdLibsDir) -disable-gvn -instcombine -disable-inlining $INFILE -b $OUTFILE -l std"), (actions (case - (switch_on "g"), (append_cmd "-disable-opt"), - (not_empty "Wo,"), (unpack_values "Wo,"))) + (switch_on "O0"), (append_cmd "-disable-opt"))), + (join) ]>; -def llvm_ld_lto : Tool<[ +// optimize single file +def llvm_ld_optimizer : Tool<[ (in_language "llvm-bitcode"), (out_language "llvm-bitcode"), (output_suffix "bc"), - (cmd_line "$CALL(GetBinDir)llvm-ld -L $CALL(GetStdLibsDir) -l std $INFILE -b $OUTFILE"), + (cmd_line "$CALL(GetBinDir)llvm-ld -disable-gvn -instcombine -disable-inlining $INFILE -b $OUTFILE"), (actions (case - (switch_on "g"), (append_cmd "-disable-opt"), - (not_empty "Wo,"), (unpack_values "Wo,"))), - (join) + (switch_on "O0"), (append_cmd "-disable-opt"))) +]>; + +// optimizer step. +def pic16passes : Tool<[ + (in_language "llvm-bitcode"), + (out_language "llvm-bitcode"), + (output_suffix "obc"), + (cmd_line "$CALL(GetBinDir)opt -pic16cg -pic16overlay $INFILE -f -o $OUTFILE"), + (actions (case + (switch_on "O0"), (append_cmd "-disable-opt"))) ]>; def llc : Tool<[ (in_language "llvm-bitcode"), (out_language "assembler"), (output_suffix "s"), - (cmd_line "$CALL(GetBinDir)llc -march=pic16 -disable-jump-tables -f $INFILE -o $OUTFILE"), + (cmd_line "$CALL(GetBinDir)llc -march=pic16 -disable-jump-tables -pre-RA-sched=list-burr -regalloc=pbqp -f $INFILE -o $OUTFILE"), (actions (case - (switch_on "S"), (stop_compilation), - (not_empty "Wllc,"), (unpack_values "Wllc,"), - (not_empty "pre-RA-sched"), (forward "pre-RA-sched"))) + (switch_on "S"), (stop_compilation))) +// (not_empty "Wllc,"), (unpack_values "Wllc,"), +// (not_empty "pre-RA-sched"), (forward "pre-RA-sched"))) ]>; def gpasm : Tool<[ (in_language "assembler"), (out_language "object-code"), (output_suffix "o"), - (cmd_line "$CALL(GetBinDir)gpasm -r decimal -p p16F1937 -I $CALL(GetStdAsmHeadersDir) -C -c $INFILE -o $OUTFILE"), + (cmd_line "$CALL(GetBinDir)gpasm -r decimal -p p16F1937 -I $CALL(GetStdAsmHeadersDir) -C -c -q $INFILE -o $OUTFILE"), (actions (case (switch_on "c"), (stop_compilation), + (switch_on "g"), (append_cmd "-g"), (not_empty "Wa,"), (unpack_values "Wa,"))) ]>; def mplink : Tool<[ (in_language "object-code"), (out_language "executable"), - (output_suffix "out"), - (cmd_line "$CALL(GetBinDir)mplink.exe -k $CALL(GetStdLinkerScriptsDir) -l $CALL(GetStdLibsDir) 16f1937_g.lkr intrinsics.lib devices.lib $INFILE -o $OUTFILE"), + (output_suffix "cof"), + (cmd_line "$CALL(GetBinDir)mplink.exe -k $CALL(GetStdLinkerScriptsDir) -l $CALL(GetStdLibsDir) -p 16f1937 intrinsics.lib devices.lib $INFILE -o $OUTFILE"), (actions (case - (not_empty "Wl,"), (unpack_values "Wl,"))), + (not_empty "Wl,"), (unpack_values "Wl,"), + (not_empty "L"), (forward_as "L", "-l"), + (not_empty "K"), (forward_as "K", "-k"), + (not_empty "m"), (forward "m"), +// (not_empty "l"), [(unpack_values "l"),(append_cmd ".lib")])), + (not_empty "k"), (unpack_values "k"), + (not_empty "l"), (unpack_values "l"))), (join) ]>; @@ -103,19 +167,26 @@ def LanguageMap : LanguageMap<[ LangToSuffixes<"llvm-assembler", ["ll"]>, LangToSuffixes<"llvm-bitcode", ["bc"]>, LangToSuffixes<"object-code", ["o"]>, - LangToSuffixes<"executable", ["out"]> + LangToSuffixes<"executable", ["cof"]> ]>; // Compilation graph def CompilationGraph : CompilationGraph<[ Edge<"root", "clang_cc">, - Edge<"clang_cc", "llvm_ld_lto">, - Edge<"llvm_ld_lto", "llc">, - OptionalEdge<"clang_cc", "llvm_ld", (case + Edge<"root", "llvm_ld">, + OptionalEdge<"root", "llvm_ld_optimizer", (case + (switch_on "S"), (inc_weight), + (switch_on "c"), (inc_weight))>, + Edge<"root", "gpasm">, + Edge<"root", "mplink">, + Edge<"clang_cc", "llvm_ld">, + OptionalEdge<"clang_cc", "llvm_ld_optimizer", (case (switch_on "S"), (inc_weight), (switch_on "c"), (inc_weight))>, - Edge<"llvm_ld", "llc">, + Edge<"llvm_ld", "pic16passes">, + Edge<"llvm_ld_optimizer", "pic16passes">, + Edge<"pic16passes", "llc">, Edge<"llc", "gpasm">, Edge<"gpasm", "mplink"> ]>; diff --git a/tools/llvmc/example/mcc16/plugins/PIC16Base/PluginMain.cpp b/tools/llvmc/example/mcc16/plugins/PIC16Base/PluginMain.cpp index f8492ed..a6d2ff6 100644 --- a/tools/llvmc/example/mcc16/plugins/PIC16Base/PluginMain.cpp +++ b/tools/llvmc/example/mcc16/plugins/PIC16Base/PluginMain.cpp @@ -10,11 +10,13 @@ namespace llvmc { } // Returns the platform specific directory separator via #ifdefs. +// FIXME: This currently work on linux and windows only. It does not +// work on other unices. static std::string GetDirSeparator() { -#ifdef _WIN32 - return "\\"; -#else +#if __linux__ || __APPLE__ return "/"; +#else + return "\\"; #endif } diff --git a/tools/llvmc/plugins/Base/Base.td.in b/tools/llvmc/plugins/Base/Base.td.in index be325a0..c26a567 100644 --- a/tools/llvmc/plugins/Base/Base.td.in +++ b/tools/llvmc/plugins/Base/Base.td.in @@ -24,6 +24,14 @@ def OptList : OptionList<[ (help "Stop after checking the input for syntax errors")), (switch_option "opt", (help "Enable opt")), + (switch_option "O0", + (help "Turn off optimization")), + (switch_option "O1", + (help "Optimization level 1")), + (switch_option "O2", + (help "Optimization level 2")), + (switch_option "O3", + (help "Optimization level 3")), (switch_option "S", (help "Stop after compilation, do not assemble")), (switch_option "c", @@ -57,6 +65,18 @@ def OptList : OptionList<[ (help "Pass options to opt")) ]>; +// Option preprocessor. + +def Preprocess : OptionPreprocessor< +(case (and (switch_on "O3"), (any_switch_on ["O0", "O1", "O2"])), + (unset_option ["O0", "O1", "O2"]), + (and (switch_on "O2"), (any_switch_on ["O0", "O1"])), + (unset_option ["O0", "O1"]), + (and (switch_on "O1"), (switch_on "O0")), + (unset_option "O0")) +>; + + // Tools class llvm_gcc_based <string cmd_prefix, string in_lang, string E_ext> : Tool< @@ -87,6 +107,9 @@ class llvm_gcc_based <string cmd_prefix, string in_lang, string E_ext> : Tool< (not_empty "include"), (forward "include"), (not_empty "I"), (forward "I"), (not_empty "D"), (forward "D"), + (switch_on "O1"), (forward "O1"), + (switch_on "O2"), (forward "O2"), + (switch_on "O3"), (forward "O3"), (not_empty "MF"), (forward "MF"), (not_empty "MT"), (forward "MT"))), (sink) @@ -103,7 +126,10 @@ def opt : Tool< [(in_language "llvm-bitcode"), (out_language "llvm-bitcode"), (output_suffix "bc"), - (actions (case (not_empty "Wo,"), (unpack_values "Wo,"))), + (actions (case (not_empty "Wo,"), (unpack_values "Wo,"), + (switch_on "O1"), (forward "O1"), + (switch_on "O2"), (forward "O2"), + (switch_on "O3"), (forward "O3"))), (cmd_line "opt -f $INFILE -o $OUTFILE") ]>; @@ -132,6 +158,10 @@ def llc : Tool< (cmd_line "llc -f $INFILE -o $OUTFILE"), (actions (case (switch_on "S"), (stop_compilation), + (switch_on "O0"), (forward "O0"), + (switch_on "O1"), (forward "O1"), + (switch_on "O2"), (forward "O2"), + (switch_on "O3"), (forward "O3"), (not_empty "Wllc,"), (unpack_values "Wllc,"))) ]>; diff --git a/tools/opt/CMakeLists.txt b/tools/opt/CMakeLists.txt index b75cda0..0570d0e 100644 --- a/tools/opt/CMakeLists.txt +++ b/tools/opt/CMakeLists.txt @@ -1,4 +1,3 @@ -set(LLVM_REQUIRES_EH 1) set(LLVM_LINK_COMPONENTS bitreader asmparser bitwriter instrumentation scalaropts ipo) add_llvm_tool(opt diff --git a/tools/opt/Makefile b/tools/opt/Makefile index b17be34..726cad8 100644 --- a/tools/opt/Makefile +++ b/tools/opt/Makefile @@ -8,7 +8,6 @@ ##===----------------------------------------------------------------------===## LEVEL = ../.. TOOLNAME = opt -REQUIRES_EH := 1 LINK_COMPONENTS := bitreader bitwriter asmparser instrumentation scalaropts ipo diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 5bf39e5..1950a73 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -127,6 +127,15 @@ QuietA("quiet", cl::desc("Alias for -q"), cl::aliasopt(Quiet)); static cl::opt<bool> AnalyzeOnly("analyze", cl::desc("Only perform analysis, no optimization")); +static cl::opt<std::string> +DefaultDataLayout("default-data-layout", + cl::desc("data layout string to use if not specified by module"), + cl::value_desc("layout-string"), cl::init("")); + +static cl::opt<bool> +NoDefaultDataLayout("no-default-data-layout", + cl::desc("no data layout assumptions unless module specifies data layout")); + // ---------- Define Printers for module and function passes ------------ namespace { @@ -337,189 +346,187 @@ void AddStandardLinkPasses(PassManager &PM) { int main(int argc, char **argv) { llvm_shutdown_obj X; // Call llvm_shutdown() on exit. LLVMContext &Context = getGlobalContext(); - try { - cl::ParseCommandLineOptions(argc, argv, - "llvm .bc -> .bc modular optimizer and analysis printer\n"); - sys::PrintStackTraceOnErrorSignal(); + + cl::ParseCommandLineOptions(argc, argv, + "llvm .bc -> .bc modular optimizer and analysis printer\n"); + sys::PrintStackTraceOnErrorSignal(); - // Allocate a full target machine description only if necessary. - // FIXME: The choice of target should be controllable on the command line. - std::auto_ptr<TargetMachine> target; + // Allocate a full target machine description only if necessary. + // FIXME: The choice of target should be controllable on the command line. + std::auto_ptr<TargetMachine> target; - SMDiagnostic Err; + SMDiagnostic Err; - // Load the input module... - std::auto_ptr<Module> M; - M.reset(ParseIRFile(InputFilename, Err, Context)); + // Load the input module... + std::auto_ptr<Module> M; + M.reset(ParseIRFile(InputFilename, Err, Context)); - if (M.get() == 0) { - Err.Print(argv[0], errs()); - return 1; - } - - // Figure out what stream we are supposed to write to... - // FIXME: outs() is not binary! - raw_ostream *Out = &outs(); // Default to printing to stdout... - if (OutputFilename != "-") { - // Make sure that the Output file gets unlinked from the disk if we get a - // SIGINT - sys::RemoveFileOnSignal(sys::Path(OutputFilename)); - - std::string ErrorInfo; - Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo, - raw_fd_ostream::F_Binary); - if (!ErrorInfo.empty()) { - errs() << ErrorInfo << '\n'; - delete Out; - return 1; - } - } + if (M.get() == 0) { + Err.Print(argv[0], errs()); + return 1; + } - // If the output is set to be emitted to standard out, and standard out is a - // console, print out a warning message and refuse to do it. We don't - // impress anyone by spewing tons of binary goo to a terminal. - if (!Force && !NoOutput && !OutputAssembly) - if (CheckBitcodeOutputToConsole(*Out, !Quiet)) - NoOutput = true; - - // Create a PassManager to hold and optimize the collection of passes we are - // about to build... - // - PassManager Passes; - - // Add an appropriate TargetData instance for this module... - Passes.add(new TargetData(M.get())); - - FunctionPassManager *FPasses = NULL; - if (OptLevelO1 || OptLevelO2 || OptLevelO3) { - FPasses = new FunctionPassManager(new ExistingModuleProvider(M.get())); - FPasses->add(new TargetData(M.get())); + // Figure out what stream we are supposed to write to... + // FIXME: outs() is not binary! + raw_ostream *Out = &outs(); // Default to printing to stdout... + if (OutputFilename != "-") { + // Make sure that the Output file gets unlinked from the disk if we get a + // SIGINT + sys::RemoveFileOnSignal(sys::Path(OutputFilename)); + + std::string ErrorInfo; + Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo, + raw_fd_ostream::F_Binary); + if (!ErrorInfo.empty()) { + errs() << ErrorInfo << '\n'; + delete Out; + return 1; } + } - // If the -strip-debug command line option was specified, add it. If - // -std-compile-opts was also specified, it will handle StripDebug. - if (StripDebug && !StandardCompileOpts) - addPass(Passes, createStripSymbolsPass(true)); - - // Create a new optimization pass for each one specified on the command line - for (unsigned i = 0; i < PassList.size(); ++i) { - // Check to see if -std-compile-opts was specified before this option. If - // so, handle it. - if (StandardCompileOpts && - StandardCompileOpts.getPosition() < PassList.getPosition(i)) { - AddStandardCompilePasses(Passes); - StandardCompileOpts = false; - } - - if (StandardLinkOpts && - StandardLinkOpts.getPosition() < PassList.getPosition(i)) { - AddStandardLinkPasses(Passes); - StandardLinkOpts = false; - } - - if (OptLevelO1 && OptLevelO1.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, 1); - OptLevelO1 = false; - } - - if (OptLevelO2 && OptLevelO2.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, 2); - OptLevelO2 = false; - } - - if (OptLevelO3 && OptLevelO3.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, 3); - OptLevelO3 = false; - } - - const PassInfo *PassInf = PassList[i]; - Pass *P = 0; - if (PassInf->getNormalCtor()) - P = PassInf->getNormalCtor()(); - else - errs() << argv[0] << ": cannot create pass: " - << PassInf->getPassName() << "\n"; - if (P) { - bool isBBPass = dynamic_cast<BasicBlockPass*>(P) != 0; - bool isLPass = !isBBPass && dynamic_cast<LoopPass*>(P) != 0; - bool isFPass = !isLPass && dynamic_cast<FunctionPass*>(P) != 0; - bool isCGSCCPass = !isFPass && dynamic_cast<CallGraphSCCPass*>(P) != 0; - - addPass(Passes, P); - - if (AnalyzeOnly) { - if (isBBPass) - Passes.add(new BasicBlockPassPrinter(PassInf)); - else if (isLPass) - Passes.add(new LoopPassPrinter(PassInf)); - else if (isFPass) - Passes.add(new FunctionPassPrinter(PassInf)); - else if (isCGSCCPass) - Passes.add(new CallGraphSCCPassPrinter(PassInf)); - else - Passes.add(new ModulePassPrinter(PassInf)); - } - } - - if (PrintEachXForm) - Passes.add(createPrintModulePass(&errs())); - } + // If the output is set to be emitted to standard out, and standard out is a + // console, print out a warning message and refuse to do it. We don't + // impress anyone by spewing tons of binary goo to a terminal. + if (!Force && !NoOutput && !OutputAssembly) + if (CheckBitcodeOutputToConsole(*Out, !Quiet)) + NoOutput = true; + + // Create a PassManager to hold and optimize the collection of passes we are + // about to build... + // + PassManager Passes; + + // Add an appropriate TargetData instance for this module... + TargetData *TD = 0; + const std::string &ModuleDataLayout = M.get()->getDataLayout(); + if (!ModuleDataLayout.empty()) + TD = new TargetData(ModuleDataLayout); + else if (!NoDefaultDataLayout) + TD = new TargetData(DefaultDataLayout); + + if (TD) + Passes.add(TD); + + FunctionPassManager *FPasses = NULL; + if (OptLevelO1 || OptLevelO2 || OptLevelO3) { + FPasses = new FunctionPassManager(new ExistingModuleProvider(M.get())); + if (TD) + FPasses->add(new TargetData(*TD)); + } - // If -std-compile-opts was specified at the end of the pass list, add them. - if (StandardCompileOpts) { + // If the -strip-debug command line option was specified, add it. If + // -std-compile-opts was also specified, it will handle StripDebug. + if (StripDebug && !StandardCompileOpts) + addPass(Passes, createStripSymbolsPass(true)); + + // Create a new optimization pass for each one specified on the command line + for (unsigned i = 0; i < PassList.size(); ++i) { + // Check to see if -std-compile-opts was specified before this option. If + // so, handle it. + if (StandardCompileOpts && + StandardCompileOpts.getPosition() < PassList.getPosition(i)) { AddStandardCompilePasses(Passes); StandardCompileOpts = false; } - if (StandardLinkOpts) { + if (StandardLinkOpts && + StandardLinkOpts.getPosition() < PassList.getPosition(i)) { AddStandardLinkPasses(Passes); StandardLinkOpts = false; } - if (OptLevelO1) { + if (OptLevelO1 && OptLevelO1.getPosition() < PassList.getPosition(i)) { AddOptimizationPasses(Passes, *FPasses, 1); + OptLevelO1 = false; } - if (OptLevelO2) { + if (OptLevelO2 && OptLevelO2.getPosition() < PassList.getPosition(i)) { AddOptimizationPasses(Passes, *FPasses, 2); + OptLevelO2 = false; } - if (OptLevelO3) { + if (OptLevelO3 && OptLevelO3.getPosition() < PassList.getPosition(i)) { AddOptimizationPasses(Passes, *FPasses, 3); + OptLevelO3 = false; } - if (OptLevelO1 || OptLevelO2 || OptLevelO3) { - FPasses->doInitialization(); - for (Module::iterator I = M.get()->begin(), E = M.get()->end(); - I != E; ++I) - FPasses->run(*I); + const PassInfo *PassInf = PassList[i]; + Pass *P = 0; + if (PassInf->getNormalCtor()) + P = PassInf->getNormalCtor()(); + else + errs() << argv[0] << ": cannot create pass: " + << PassInf->getPassName() << "\n"; + if (P) { + bool isBBPass = dynamic_cast<BasicBlockPass*>(P) != 0; + bool isLPass = !isBBPass && dynamic_cast<LoopPass*>(P) != 0; + bool isFPass = !isLPass && dynamic_cast<FunctionPass*>(P) != 0; + bool isCGSCCPass = !isFPass && dynamic_cast<CallGraphSCCPass*>(P) != 0; + + addPass(Passes, P); + + if (AnalyzeOnly) { + if (isBBPass) + Passes.add(new BasicBlockPassPrinter(PassInf)); + else if (isLPass) + Passes.add(new LoopPassPrinter(PassInf)); + else if (isFPass) + Passes.add(new FunctionPassPrinter(PassInf)); + else if (isCGSCCPass) + Passes.add(new CallGraphSCCPassPrinter(PassInf)); + else + Passes.add(new ModulePassPrinter(PassInf)); + } } - // Check that the module is well formed on completion of optimization - if (!NoVerify && !VerifyEach) - Passes.add(createVerifierPass()); + if (PrintEachXForm) + Passes.add(createPrintModulePass(&errs())); + } - // Write bitcode or assembly out to disk or outs() as the last step... - if (!NoOutput && !AnalyzeOnly) { - if (OutputAssembly) - Passes.add(createPrintModulePass(Out)); - else - Passes.add(createBitcodeWriterPass(*Out)); - } + // If -std-compile-opts was specified at the end of the pass list, add them. + if (StandardCompileOpts) { + AddStandardCompilePasses(Passes); + StandardCompileOpts = false; + } - // Now that we have all of the passes ready, run them. - Passes.run(*M.get()); + if (StandardLinkOpts) { + AddStandardLinkPasses(Passes); + StandardLinkOpts = false; + } - // Delete the raw_fd_ostream. - if (Out != &outs()) - delete Out; - return 0; + if (OptLevelO1) + AddOptimizationPasses(Passes, *FPasses, 1); + + if (OptLevelO2) + AddOptimizationPasses(Passes, *FPasses, 2); + + if (OptLevelO3) + AddOptimizationPasses(Passes, *FPasses, 3); - } catch (const std::string& msg) { - errs() << argv[0] << ": " << msg << "\n"; - } catch (...) { - errs() << argv[0] << ": Unexpected unknown exception occurred.\n"; + if (OptLevelO1 || OptLevelO2 || OptLevelO3) { + FPasses->doInitialization(); + for (Module::iterator I = M.get()->begin(), E = M.get()->end(); + I != E; ++I) + FPasses->run(*I); } - llvm_shutdown(); - return 1; + + // Check that the module is well formed on completion of optimization + if (!NoVerify && !VerifyEach) + Passes.add(createVerifierPass()); + + // Write bitcode or assembly out to disk or outs() as the last step... + if (!NoOutput && !AnalyzeOnly) { + if (OutputAssembly) + Passes.add(createPrintModulePass(Out)); + else + Passes.add(createBitcodeWriterPass(*Out)); + } + + // Now that we have all of the passes ready, run them. + Passes.run(*M.get()); + + // Delete the raw_fd_ostream. + if (Out != &outs()) + delete Out; + return 0; } |