[llvm-commits] [llvm] r126426 - in /llvm/trunk/tools/lto: LTOCodeGenerator.cpp LTOCodeGenerator.h lto.cpp

Owen Anderson resistor at mac.com
Fri Feb 25 10:35:42 PST 2011


Should this apply to all targets, or only the same ones for which -integrated-as is the default?

--Owen

On Feb 24, 2011, at 1:04 PM, Rafael Espindola wrote:

> Author: rafael
> Date: Thu Feb 24 15:04:06 2011
> New Revision: 126426
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=126426&view=rev
> Log:
> Switch LTO to use MC. This takes the linking of libxul.so from about 7m to
> 6m30.
> 
> Modified:
>    llvm/trunk/tools/lto/LTOCodeGenerator.cpp
>    llvm/trunk/tools/lto/LTOCodeGenerator.h
>    llvm/trunk/tools/lto/lto.cpp
> 
> Modified: llvm/trunk/tools/lto/LTOCodeGenerator.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.cpp?rev=126426&r1=126425&r2=126426&view=diff
> ==============================================================================
> --- llvm/trunk/tools/lto/LTOCodeGenerator.cpp (original)
> +++ llvm/trunk/tools/lto/LTOCodeGenerator.cpp Thu Feb 24 15:04:06 2011
> @@ -71,10 +71,11 @@
>       _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL),
>       _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false),
>       _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC),
> -      _nativeObjectFile(NULL), _assemblerPath(NULL)
> +      _nativeObjectFile(NULL)
> {
>     InitializeAllTargets();
>     InitializeAllAsmPrinters();
> +    InitializeAllAsmParsers();
> }
> 
> LTOCodeGenerator::~LTOCodeGenerator()
> @@ -126,21 +127,6 @@
>   _mCpu = mCpu;
> }
> 
> -void LTOCodeGenerator::setAssemblerPath(const char* path)
> -{
> -    if ( _assemblerPath )
> -        delete _assemblerPath;
> -    _assemblerPath = new sys::Path(path);
> -}
> -
> -void LTOCodeGenerator::setAssemblerArgs(const char** args, int nargs)
> -{
> -  for (int i = 0; i < nargs; ++i) {
> -    const char *arg = args[i];
> -    _assemblerArgs.push_back(arg);
> -  }
> -}
> -
> void LTOCodeGenerator::addMustPreserveSymbol(const char* sym)
> {
>     _mustPreserveSymbols[sym] = 1;
> @@ -183,55 +169,42 @@
> 
> const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg)
> {
> -    // make unique temp .s file to put generated assembly code
> -    sys::Path uniqueAsmPath("lto-llvm.s");
> -    if ( uniqueAsmPath.createTemporaryFileOnDisk(false, &errMsg) )
> -        return NULL;
> -    sys::RemoveFileOnSignal(uniqueAsmPath);
> -       
> -    // generate assembly code
> -    bool genResult = false;
> -    {
> -      tool_output_file asmFile(uniqueAsmPath.c_str(), errMsg);
> -      if (!errMsg.empty())
> -        return NULL;
> -      genResult = this->generateAssemblyCode(asmFile.os(), errMsg);
> -      asmFile.os().close();
> -      if (asmFile.os().has_error()) {
> -        asmFile.os().clear_error();
> -        return NULL;
> -      }
> -      asmFile.keep();
> -    }
> -    if ( genResult ) {
> -        uniqueAsmPath.eraseFromDisk();
> -        return NULL;
> -    }
> -    
>     // make unique temp .o file to put generated object file
>     sys::PathWithStatus uniqueObjPath("lto-llvm.o");
>     if ( uniqueObjPath.createTemporaryFileOnDisk(false, &errMsg) ) {
> -        uniqueAsmPath.eraseFromDisk();
> +        uniqueObjPath.eraseFromDisk();
>         return NULL;
>     }
>     sys::RemoveFileOnSignal(uniqueObjPath);
> 
> -    // assemble the assembly code
> -    const std::string& uniqueObjStr = uniqueObjPath.str();
> -    bool asmResult = this->assemble(uniqueAsmPath.str(), uniqueObjStr, errMsg);
> -    if ( !asmResult ) {
> -        // remove old buffer if compile() called twice
> -        delete _nativeObjectFile;
> -
> -        // read .o file into memory buffer
> -        OwningPtr<MemoryBuffer> BuffPtr;
> -        if (error_code ec = MemoryBuffer::getFile(uniqueObjStr.c_str(),BuffPtr))
> -          errMsg = ec.message();
> -        _nativeObjectFile = BuffPtr.take();
> +    // generate object file
> +    bool genResult = false;
> +    tool_output_file objFile(uniqueObjPath.c_str(), errMsg);
> +    if (!errMsg.empty())
> +      return NULL;
> +    genResult = this->generateObjectFile(objFile.os(), errMsg);
> +    objFile.os().close();
> +    if (objFile.os().has_error()) {
> +      objFile.os().clear_error();
> +      return NULL;
> +    }
> +    objFile.keep();
> +    if ( genResult ) {
> +      uniqueObjPath.eraseFromDisk();
> +      return NULL;
>     }
> 
> +    const std::string& uniqueObjStr = uniqueObjPath.str();
> +    // remove old buffer if compile() called twice
> +    delete _nativeObjectFile;
> +
> +    // read .o file into memory buffer
> +    OwningPtr<MemoryBuffer> BuffPtr;
> +    if (error_code ec = MemoryBuffer::getFile(uniqueObjStr.c_str(),BuffPtr))
> +      errMsg = ec.message();
> +    _nativeObjectFile = BuffPtr.take();
> +
>     // remove temp files
> -    uniqueAsmPath.eraseFromDisk();
>     uniqueObjPath.eraseFromDisk();
> 
>     // return buffer, unless error
> @@ -241,67 +214,6 @@
>     return _nativeObjectFile->getBufferStart();
> }
> 
> -
> -bool LTOCodeGenerator::assemble(const std::string& asmPath, 
> -                                const std::string& objPath, std::string& errMsg)
> -{
> -    sys::Path tool;
> -    bool needsCompilerOptions = true;
> -    if ( _assemblerPath ) {
> -        tool = *_assemblerPath;
> -        needsCompilerOptions = false;
> -    } else {
> -        // find compiler driver
> -        tool = sys::Program::FindProgramByName("gcc");
> -        if ( tool.isEmpty() ) {
> -            errMsg = "can't locate gcc";
> -            return true;
> -        }
> -    }
> -
> -    // build argument list
> -    std::vector<const char*> args;
> -    llvm::Triple targetTriple(_linker.getModule()->getTargetTriple());
> -    const char *arch = targetTriple.getArchNameForAssembler();
> -
> -    args.push_back(tool.c_str());
> -
> -    if (targetTriple.getOS() == Triple::Darwin) {
> -        // darwin specific command line options
> -        if (arch != NULL) {
> -            args.push_back("-arch");
> -            args.push_back(arch);
> -        }
> -        // 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");
> -    } else {
> -        for (std::vector<std::string>::iterator I = _assemblerArgs.begin(),
> -               E = _assemblerArgs.end(); I != E; ++I) {
> -            args.push_back(I->c_str());
> -        }
> -    }
> -    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(tool, &args[0], 0, 0, 0, 0, &errMsg) ) {
> -        errMsg = "error in assembly";    
> -        return true;
> -    }
> -    return false; // success
> -}
> -
> -
> -
> bool LTOCodeGenerator::determineTarget(std::string& errMsg)
> {
>     if ( _target == NULL ) {
> @@ -385,8 +297,8 @@
> }
> 
> /// Optimize merged modules using various IPO passes
> -bool LTOCodeGenerator::generateAssemblyCode(raw_ostream& out,
> -                                            std::string& errMsg)
> +bool LTOCodeGenerator::generateObjectFile(raw_ostream& out,
> +                                          std::string& errMsg)
> {
>     if ( this->determineTarget(errMsg) ) 
>         return true;
> @@ -423,7 +335,7 @@
>     formatted_raw_ostream Out(out);
> 
>     if (_target->addPassesToEmitFile(*codeGenPasses, Out,
> -                                     TargetMachine::CGFT_AssemblyFile,
> +                                     TargetMachine::CGFT_ObjectFile,
>                                      CodeGenOpt::Aggressive)) {
>       errMsg = "target file type not supported";
>       return true;
> 
> Modified: llvm/trunk/tools/lto/LTOCodeGenerator.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.h?rev=126426&r1=126425&r2=126426&view=diff
> ==============================================================================
> --- llvm/trunk/tools/lto/LTOCodeGenerator.h (original)
> +++ llvm/trunk/tools/lto/LTOCodeGenerator.h Thu Feb 24 15:04:06 2011
> @@ -37,18 +37,14 @@
>     bool                setDebugInfo(lto_debug_model, std::string& errMsg);
>     bool                setCodePICModel(lto_codegen_model, std::string& errMsg);
>     void                setCpu(const char *cpu);
> -    void                setAssemblerPath(const char* path);
> -    void                setAssemblerArgs(const char** args, int nargs);
>     void                addMustPreserveSymbol(const char* sym);
>     bool                writeMergedModules(const char* path, 
>                                                            std::string& errMsg);
>     const void*         compile(size_t* length, std::string& errMsg);
>     void                setCodeGenDebugOptions(const char *opts); 
> private:
> -    bool                generateAssemblyCode(llvm::raw_ostream& out, 
> -                                             std::string& errMsg);
> -    bool                assemble(const std::string& asmPath, 
> -                            const std::string& objPath, std::string& errMsg);
> +    bool                generateObjectFile(llvm::raw_ostream& out, 
> +                                           std::string& errMsg);
>     void                applyScopeRestrictions();
>     bool                determineTarget(std::string& errMsg);
> 
> @@ -63,9 +59,7 @@
>     StringSet                   _mustPreserveSymbols;
>     llvm::MemoryBuffer*         _nativeObjectFile;
>     std::vector<const char*>    _codegenOptions;
> -    llvm::sys::Path*            _assemblerPath;
>     std::string                 _mCpu;
> -    std::vector<std::string>    _assemblerArgs;
> };
> 
> #endif // LTO_CODE_GENERATOR_H
> 
> Modified: llvm/trunk/tools/lto/lto.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/lto.cpp?rev=126426&r1=126425&r2=126426&view=diff
> ==============================================================================
> --- llvm/trunk/tools/lto/lto.cpp (original)
> +++ llvm/trunk/tools/lto/lto.cpp Thu Feb 24 15:04:06 2011
> @@ -231,7 +231,7 @@
> //
> void lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path)
> {
> -    cg->setAssemblerPath(path);
> +  // In here only for backwards compatibility. We use MC now.
> }
> 
> 
> @@ -241,7 +241,7 @@
> void lto_codegen_set_assembler_args(lto_code_gen_t cg, const char** args,
>                                     int nargs)
> {
> -  cg->setAssemblerArgs(args, nargs);
> +  // In here only for backwards compatibility. We use MC now.
> }
> 
> //
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list