diff options
Diffstat (limited to 'tools/lto/LTOCodeGenerator.cpp')
-rw-r--r-- | tools/lto/LTOCodeGenerator.cpp | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 911fddfe1888..671348c8333b 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -119,6 +119,11 @@ bool LTOCodeGenerator::setCodePICModel(lto_codegen_model model, return true; } +void LTOCodeGenerator::setCpu(const char* mCpu) +{ + _mCpu = mCpu; +} + void LTOCodeGenerator::setAssemblerPath(const char* path) { if ( _assemblerPath ) @@ -126,6 +131,14 @@ void LTOCodeGenerator::setAssemblerPath(const char* path) _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; @@ -142,8 +155,8 @@ bool LTOCodeGenerator::writeMergedModules(const char *path, // create output file std::string ErrInfo; - raw_fd_ostream Out(path, ErrInfo, - raw_fd_ostream::F_Binary); + tool_output_file Out(path, ErrInfo, + raw_fd_ostream::F_Binary); if (!ErrInfo.empty()) { errMsg = "could not open bitcode file for writing: "; errMsg += path; @@ -151,16 +164,17 @@ bool LTOCodeGenerator::writeMergedModules(const char *path, } // write bitcode to it - WriteBitcodeToFile(_linker.getModule(), Out); - Out.close(); + WriteBitcodeToFile(_linker.getModule(), Out.os()); + Out.os().close(); - if (Out.has_error()) { + if (Out.os().has_error()) { errMsg = "could not write bitcode file: "; errMsg += path; - Out.clear_error(); + Out.os().clear_error(); return true; } + Out.keep(); return false; } @@ -176,11 +190,16 @@ const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg) // generate assembly code bool genResult = false; { - raw_fd_ostream asmFD(uniqueAsmPath.c_str(), errMsg); - formatted_raw_ostream asmFile(asmFD); + tool_output_file asmFile(uniqueAsmPath.c_str(), errMsg); if (!errMsg.empty()) return NULL; - genResult = this->generateAssemblyCode(asmFile, errMsg); + 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(); @@ -257,6 +276,11 @@ bool LTOCodeGenerator::assemble(const std::string& asmPath, 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()); @@ -301,7 +325,7 @@ bool LTOCodeGenerator::determineTarget(std::string& errMsg) // construct LTModule, hand over ownership of module and target SubtargetFeatures Features; - Features.getDefaultSubtargetFeatures("" /* cpu */, llvm::Triple(Triple)); + Features.getDefaultSubtargetFeatures(_mCpu, llvm::Triple(Triple)); std::string FeatureStr = Features.getString(); _target = march->createTargetMachine(Triple, FeatureStr); } @@ -343,7 +367,7 @@ void LTOCodeGenerator::applyScopeRestrictions() { } /// Optimize merged modules using various IPO passes -bool LTOCodeGenerator::generateAssemblyCode(formatted_raw_ostream& out, +bool LTOCodeGenerator::generateAssemblyCode(raw_ostream& out, std::string& errMsg) { if ( this->determineTarget(errMsg) ) @@ -378,7 +402,9 @@ bool LTOCodeGenerator::generateAssemblyCode(formatted_raw_ostream& out, codeGenPasses->add(new TargetData(*_target->getTargetData())); - if (_target->addPassesToEmitFile(*codeGenPasses, out, + formatted_raw_ostream Out(out); + + if (_target->addPassesToEmitFile(*codeGenPasses, Out, TargetMachine::CGFT_AssemblyFile, CodeGenOpt::Aggressive)) { errMsg = "target file type not supported"; |