From 2361a5c2bfbaef476824e51fa72712e334219c7b Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 6 Jun 2009 08:20:29 +0000 Subject: Import LLVM, at r72995. We should now have support for #pragma weak. --- tools/CMakeLists.txt | 6 ++-- tools/llc/llc.cpp | 17 ++++++++++- tools/llvm-ld/Optimize.cpp | 2 +- tools/lto/LTOCodeGenerator.cpp | 68 ++++++++++++++++++++++++++---------------- tools/lto/LTOCodeGenerator.h | 2 ++ tools/lto/lto.cpp | 8 +++++ tools/lto/lto.exports | 1 + 7 files changed, 74 insertions(+), 30 deletions(-) (limited to 'tools') diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 113d987..5c1ee35 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -2,9 +2,9 @@ # large and three small executables. This is done to minimize memory load # in parallel builds. Please retain this ordering. -if( NOT MSVC ) - add_subdirectory(llvm-config) -endif( NOT MSVC ) +if (NOT USE_EXPLICIT_DEPENDENCIES) + add_subdirectory(llvm-config) +endif() add_subdirectory(opt) add_subdirectory(llvm-as) diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index 4808f0e..c630331 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -100,6 +100,16 @@ cl::opt NoVerify("disable-verify", cl::Hidden, cl::desc("Do not verify input module")); +static cl::opt +DisableRedZone("disable-red-zone", + cl::desc("Do not emit code that uses the red zone."), + cl::init(false)); + +static cl::opt +NoImplicitFloats("no-implicit-float", + cl::desc("Don't generate implicit floating point instructions (x86-only)"), + cl::init(false)); + // GetFileNameRoot - Helper function to get the basename of a filename. static inline std::string GetFileNameRoot(const std::string &InputFilename) { @@ -336,8 +346,13 @@ int main(int argc, char **argv) { // Run our queue of passes all at once now, efficiently. // TODO: this could lazily stream functions out of the module. for (Module::iterator I = mod.begin(), E = mod.end(); I != E; ++I) - if (!I->isDeclaration()) + if (!I->isDeclaration()) { + if (DisableRedZone) + I->addFnAttr(Attribute::NoRedZone); + if (NoImplicitFloats) + I->addFnAttr(Attribute::NoImplicitFloat); Passes.run(*I); + } Passes.doFinalization(); } diff --git a/tools/llvm-ld/Optimize.cpp b/tools/llvm-ld/Optimize.cpp index a4ca951..e466895 100644 --- a/tools/llvm-ld/Optimize.cpp +++ b/tools/llvm-ld/Optimize.cpp @@ -94,7 +94,7 @@ void Optimize(Module* M) { if (!DisableOptimizations) createStandardLTOPasses(&Passes, !DisableInternalize, !DisableInline, - /*RunSecondGlobalOpt=*/true, VerifyEach); + VerifyEach); // If the -s or -S command line options were specified, strip the symbols out // of the resulting program to make it smaller. -s and -S are GNU ld options diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 03a11b6..0bd2abe 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -72,7 +72,7 @@ LTOCodeGenerator::LTOCodeGenerator() : _linker("LinkTimeOptimizer", "ld-temp.o"), _target(NULL), _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false), _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC), - _nativeObjectFile(NULL), _gccPath(NULL) + _nativeObjectFile(NULL), _gccPath(NULL), _assemblerPath(NULL) { } @@ -128,6 +128,13 @@ void LTOCodeGenerator::setGccPath(const char* path) _gccPath = new sys::Path(path); } +void LTOCodeGenerator::setAssemblerPath(const char* path) +{ + if ( _assemblerPath ) + delete _assemblerPath; + _assemblerPath = new sys::Path(path); +} + void LTOCodeGenerator::addMustPreserveSymbol(const char* sym) { _mustPreserveSymbols[sym] = 1; @@ -220,13 +227,18 @@ const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg) bool LTOCodeGenerator::assemble(const std::string& asmPath, const std::string& objPath, std::string& errMsg) { - sys::Path gcc; - if ( _gccPath ) { - gcc = *_gccPath; + sys::Path tool; + bool needsCompilerOptions = true; + if ( _assemblerPath ) { + tool = *_assemblerPath; + needsCompilerOptions = false; + } + else if ( _gccPath ) { + tool = *_gccPath; } else { // find compiler driver - gcc = sys::Program::FindProgramByName("gcc"); - if ( gcc.isEmpty() ) { + tool = sys::Program::FindProgramByName("gcc"); + if ( tool.isEmpty() ) { errMsg = "can't locate gcc"; return true; } @@ -235,8 +247,9 @@ bool LTOCodeGenerator::assemble(const std::string& asmPath, // build argument list std::vector args; std::string targetTriple = _linker.getModule()->getTargetTriple(); - args.push_back(gcc.c_str()); + args.push_back(tool.c_str()); if ( targetTriple.find("darwin") != targetTriple.size() ) { + // darwin specific command line options if (strncmp(targetTriple.c_str(), "i386-apple-", 11) == 0) { args.push_back("-arch"); args.push_back("i386"); @@ -274,17 +287,22 @@ bool LTOCodeGenerator::assemble(const std::string& asmPath, args.push_back("-arch"); args.push_back("armv6"); } + // add -static to assembler command line when code model requires + if ( (_assemblerPath != NULL) && (_codeModel == LTO_CODEGEN_PIC_MODEL_STATIC) ) + args.push_back("-static"); + } + if ( needsCompilerOptions ) { + args.push_back("-c"); + args.push_back("-x"); + args.push_back("assembler"); } - args.push_back("-c"); - args.push_back("-x"); - args.push_back("assembler"); args.push_back("-o"); args.push_back(objPath.c_str()); args.push_back(asmPath.c_str()); args.push_back(0); // invoke assembler - if ( sys::Program::ExecuteAndWait(gcc, &args[0], 0, 0, 0, 0, &errMsg) ) { + if ( sys::Program::ExecuteAndWait(tool, &args[0], 0, 0, 0, 0, &errMsg) ) { errMsg = "error in assembly"; return true; } @@ -304,6 +322,20 @@ bool LTOCodeGenerator::determineTarget(std::string& errMsg) if ( march == NULL ) return true; + // The relocation model is actually a static member of TargetMachine + // and needs to be set before the TargetMachine is instantiated. + switch( _codeModel ) { + case LTO_CODEGEN_PIC_MODEL_STATIC: + TargetMachine::setRelocationModel(Reloc::Static); + break; + case LTO_CODEGEN_PIC_MODEL_DYNAMIC: + TargetMachine::setRelocationModel(Reloc::PIC_); + break; + case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC: + TargetMachine::setRelocationModel(Reloc::DynamicNoPIC); + break; + } + // construct LTModule, hand over ownership of module and target std::string FeatureStr = getFeatureString(_linker.getModule()->getTargetTriple().c_str()); @@ -363,19 +395,6 @@ bool LTOCodeGenerator::generateAssemblyCode(raw_ostream& out, if ( _target->getTargetAsmInfo()->doesSupportExceptionHandling() ) llvm::ExceptionHandling = true; - // set codegen model - switch( _codeModel ) { - case LTO_CODEGEN_PIC_MODEL_STATIC: - _target->setRelocationModel(Reloc::Static); - break; - case LTO_CODEGEN_PIC_MODEL_DYNAMIC: - _target->setRelocationModel(Reloc::PIC_); - break; - case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC: - _target->setRelocationModel(Reloc::DynamicNoPIC); - break; - } - // if options were requested, set them if ( !_codegenOptions.empty() ) cl::ParseCommandLineOptions(_codegenOptions.size(), @@ -391,7 +410,6 @@ bool LTOCodeGenerator::generateAssemblyCode(raw_ostream& out, passes.add(new TargetData(*_target->getTargetData())); createStandardLTOPasses(&passes, /*Internalize=*/ false, !DisableInline, - /*RunSecondGlobalOpt=*/ false, /*VerifyEach=*/ false); // Make sure everything is still good. diff --git a/tools/lto/LTOCodeGenerator.h b/tools/lto/LTOCodeGenerator.h index 57398b0..e02a7ab 100644 --- a/tools/lto/LTOCodeGenerator.h +++ b/tools/lto/LTOCodeGenerator.h @@ -37,6 +37,7 @@ public: bool setDebugInfo(lto_debug_model, std::string& errMsg); bool setCodePICModel(lto_codegen_model, std::string& errMsg); void setGccPath(const char* path); + void setAssemblerPath(const char* path); void addMustPreserveSymbol(const char* sym); bool writeMergedModules(const char* path, std::string& errMsg); @@ -61,6 +62,7 @@ private: llvm::MemoryBuffer* _nativeObjectFile; std::vector _codegenOptions; llvm::sys::Path* _gccPath; + llvm::sys::Path* _assemblerPath; }; #endif // LTO_CODE_GENERATOR_H diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp index 5c3f90a..7eb39ef 100644 --- a/tools/lto/lto.cpp +++ b/tools/lto/lto.cpp @@ -210,6 +210,14 @@ void lto_codegen_set_gcc_path(lto_code_gen_t cg, const char* path) } // +// sets the path to the assembler tool +// +void lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path) +{ + cg->setAssemblerPath(path); +} + +// // adds to a list of all global symbols that must exist in the final // generated code. If a function is not listed there, it might be // inlined into every usage and optimized away. diff --git a/tools/lto/lto.exports b/tools/lto/lto.exports index aff7559..01f43d1 100644 --- a/tools/lto/lto.exports +++ b/tools/lto/lto.exports @@ -20,4 +20,5 @@ _lto_codegen_set_debug_model _lto_codegen_set_pic_model _lto_codegen_write_merged_modules _lto_codegen_debug_options +_lto_codegen_set_assembler_path -- cgit v1.1