blob: b4c4e7767b983880c9e4df3e8adf910ad5a8797d [file] [log] [blame]
Nick Kledzik77595fc2008-02-26 20:26:43 +00001//===-LTOCodeGenerator.cpp - LLVM Link Time Optimizer ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Link Time Optimization library. This library is
11// intended to be used by linker to optimize code at link time.
12//
13//===----------------------------------------------------------------------===//
14
Nick Kledzikef194ed2008-02-27 22:25:36 +000015#include "LTOModule.h"
16#include "LTOCodeGenerator.h"
17
18
Nick Kledzik77595fc2008-02-26 20:26:43 +000019#include "llvm/Constants.h"
20#include "llvm/DerivedTypes.h"
Nick Lewycky8189d402009-06-17 06:52:10 +000021#include "llvm/Linker.h"
Owen Anderson0e7a5462009-07-02 00:31:14 +000022#include "llvm/LLVMContext.h"
Nick Lewycky8189d402009-06-17 06:52:10 +000023#include "llvm/Module.h"
Nick Kledzik77595fc2008-02-26 20:26:43 +000024#include "llvm/ModuleProvider.h"
Nick Lewycky8189d402009-06-17 06:52:10 +000025#include "llvm/PassManager.h"
26#include "llvm/ADT/StringExtras.h"
27#include "llvm/Analysis/Passes.h"
28#include "llvm/Analysis/LoopPass.h"
29#include "llvm/Analysis/Verifier.h"
Nick Kledzik77595fc2008-02-26 20:26:43 +000030#include "llvm/Bitcode/ReaderWriter.h"
Nick Lewycky8189d402009-06-17 06:52:10 +000031#include "llvm/CodeGen/FileWriters.h"
Nick Kledzik920ae982008-07-08 21:14:10 +000032#include "llvm/Support/CommandLine.h"
David Greene71847812009-07-14 20:18:05 +000033#include "llvm/Support/FormattedStream.h"
Nick Kledzik77595fc2008-02-26 20:26:43 +000034#include "llvm/Support/Mangler.h"
35#include "llvm/Support/MemoryBuffer.h"
Daniel Dunbar006a0342009-06-03 21:06:14 +000036#include "llvm/Support/StandardPasses.h"
37#include "llvm/Support/SystemUtils.h"
Nick Kledzik77595fc2008-02-26 20:26:43 +000038#include "llvm/System/Signals.h"
Bill Wendling604a8182008-06-18 06:35:30 +000039#include "llvm/Target/SubtargetFeature.h"
Nick Kledzik77595fc2008-02-26 20:26:43 +000040#include "llvm/Target/TargetOptions.h"
Chris Lattner2deb58f2009-06-17 16:42:19 +000041#include "llvm/Target/TargetAsmInfo.h"
Nick Kledzik77595fc2008-02-26 20:26:43 +000042#include "llvm/Target/TargetData.h"
43#include "llvm/Target/TargetMachine.h"
44#include "llvm/Target/TargetMachineRegistry.h"
Chris Lattner2deb58f2009-06-17 16:42:19 +000045#include "llvm/Target/TargetSelect.h"
Nick Kledzik77595fc2008-02-26 20:26:43 +000046#include "llvm/Transforms/IPO.h"
47#include "llvm/Transforms/Scalar.h"
Nick Kledzik77595fc2008-02-26 20:26:43 +000048#include "llvm/Config/config.h"
49
Nick Kledzik77595fc2008-02-26 20:26:43 +000050
Nick Lewycky8189d402009-06-17 06:52:10 +000051#include <cstdlib>
Nick Kledzik77595fc2008-02-26 20:26:43 +000052#include <fstream>
53#include <unistd.h>
Nick Kledzik77595fc2008-02-26 20:26:43 +000054#include <fcntl.h>
55
56
57using namespace llvm;
58
Nick Kledzik920ae982008-07-08 21:14:10 +000059static cl::opt<bool> DisableInline("disable-inlining",
60 cl::desc("Do not run the inliner pass"));
Nick Kledzik77595fc2008-02-26 20:26:43 +000061
62
63const char* LTOCodeGenerator::getVersionString()
64{
65#ifdef LLVM_VERSION_INFO
66 return PACKAGE_NAME " version " PACKAGE_VERSION ", " LLVM_VERSION_INFO;
67#else
68 return PACKAGE_NAME " version " PACKAGE_VERSION;
69#endif
70}
71
72
Owen Anderson0e7a5462009-07-02 00:31:14 +000073LTOCodeGenerator::LTOCodeGenerator()
74 : _context(getGlobalContext()),
Owen Anderson8b477ed2009-07-01 16:58:40 +000075 _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL),
Nick Kledzik77595fc2008-02-26 20:26:43 +000076 _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false),
Nick Kledzikef194ed2008-02-27 22:25:36 +000077 _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC),
Nick Kledzikcbad5862009-06-04 00:28:45 +000078 _nativeObjectFile(NULL), _gccPath(NULL), _assemblerPath(NULL)
Nick Kledzik77595fc2008-02-26 20:26:43 +000079{
Chris Lattner2deb58f2009-06-17 16:42:19 +000080 InitializeAllTargets();
81 InitializeAllAsmPrinters();
Nick Kledzik77595fc2008-02-26 20:26:43 +000082
83}
84
85LTOCodeGenerator::~LTOCodeGenerator()
86{
Nick Kledzikef194ed2008-02-27 22:25:36 +000087 delete _target;
88 delete _nativeObjectFile;
Nick Kledzik77595fc2008-02-26 20:26:43 +000089}
90
91
92
93bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg)
94{
95 return _linker.LinkInModule(mod->getLLVVMModule(), &errMsg);
96}
97
98
99bool LTOCodeGenerator::setDebugInfo(lto_debug_model debug, std::string& errMsg)
100{
101 switch (debug) {
102 case LTO_DEBUG_MODEL_NONE:
103 _emitDwarfDebugInfo = false;
104 return false;
105
106 case LTO_DEBUG_MODEL_DWARF:
107 _emitDwarfDebugInfo = true;
108 return false;
109 }
110 errMsg = "unknown debug format";
111 return true;
112}
113
114
115bool LTOCodeGenerator::setCodePICModel(lto_codegen_model model,
Evan Cheng855a1682009-06-26 06:57:16 +0000116 std::string& errMsg)
Nick Kledzik77595fc2008-02-26 20:26:43 +0000117{
118 switch (model) {
119 case LTO_CODEGEN_PIC_MODEL_STATIC:
120 case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
121 case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
122 _codeModel = model;
123 return false;
124 }
125 errMsg = "unknown pic model";
126 return true;
127}
128
Nick Lewycky195bea32009-04-30 15:24:09 +0000129void LTOCodeGenerator::setGccPath(const char* path)
130{
131 if ( _gccPath )
132 delete _gccPath;
133 _gccPath = new sys::Path(path);
134}
135
Nick Kledzikcbad5862009-06-04 00:28:45 +0000136void LTOCodeGenerator::setAssemblerPath(const char* path)
137{
138 if ( _assemblerPath )
139 delete _assemblerPath;
140 _assemblerPath = new sys::Path(path);
141}
142
Nick Kledzik77595fc2008-02-26 20:26:43 +0000143void LTOCodeGenerator::addMustPreserveSymbol(const char* sym)
144{
145 _mustPreserveSymbols[sym] = 1;
146}
147
148
149bool LTOCodeGenerator::writeMergedModules(const char* path, std::string& errMsg)
150{
151 if ( this->determineTarget(errMsg) )
152 return true;
153
154 // mark which symbols can not be internalized
155 this->applyScopeRestrictions();
156
157 // create output file
158 std::ofstream out(path, std::ios_base::out|std::ios::trunc|std::ios::binary);
159 if ( out.fail() ) {
160 errMsg = "could not open bitcode file for writing: ";
161 errMsg += path;
162 return true;
163 }
164
165 // write bitcode to it
166 WriteBitcodeToFile(_linker.getModule(), out);
167 if ( out.fail() ) {
168 errMsg = "could not write bitcode file: ";
169 errMsg += path;
170 return true;
171 }
172
173 return false;
174}
175
176
Nick Kledzikef194ed2008-02-27 22:25:36 +0000177const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg)
Nick Kledzik77595fc2008-02-26 20:26:43 +0000178{
Nick Kledzikef194ed2008-02-27 22:25:36 +0000179 // make unique temp .s file to put generated assembly code
Nick Kledzik77595fc2008-02-26 20:26:43 +0000180 sys::Path uniqueAsmPath("lto-llvm.s");
181 if ( uniqueAsmPath.createTemporaryFileOnDisk(true, &errMsg) )
182 return NULL;
183 sys::RemoveFileOnSignal(uniqueAsmPath);
184
185 // generate assembly code
Owen Andersoncb371882008-08-21 00:14:44 +0000186 bool genResult = false;
187 {
David Greene71847812009-07-14 20:18:05 +0000188 raw_fd_ostream asmFD(raw_fd_ostream(uniqueAsmPath.c_str(),
189 false, errMsg));
190 formatted_raw_ostream asmFile(asmFD);
Dan Gohmaned3e8b42008-08-21 15:33:45 +0000191 if (!errMsg.empty())
192 return NULL;
Owen Andersoncb371882008-08-21 00:14:44 +0000193 genResult = this->generateAssemblyCode(asmFile, errMsg);
194 }
Nick Kledzik77595fc2008-02-26 20:26:43 +0000195 if ( genResult ) {
196 if ( uniqueAsmPath.exists() )
197 uniqueAsmPath.eraseFromDisk();
198 return NULL;
199 }
200
Nick Kledzikef194ed2008-02-27 22:25:36 +0000201 // make unique temp .o file to put generated object file
Nick Kledzik77595fc2008-02-26 20:26:43 +0000202 sys::PathWithStatus uniqueObjPath("lto-llvm.o");
203 if ( uniqueObjPath.createTemporaryFileOnDisk(true, &errMsg) ) {
204 if ( uniqueAsmPath.exists() )
205 uniqueAsmPath.eraseFromDisk();
206 return NULL;
207 }
208 sys::RemoveFileOnSignal(uniqueObjPath);
209
210 // assemble the assembly code
Nick Kledzikef194ed2008-02-27 22:25:36 +0000211 const std::string& uniqueObjStr = uniqueObjPath.toString();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000212 bool asmResult = this->assemble(uniqueAsmPath.toString(),
Nick Kledzikef194ed2008-02-27 22:25:36 +0000213 uniqueObjStr, errMsg);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000214 if ( !asmResult ) {
Nick Kledzikef194ed2008-02-27 22:25:36 +0000215 // remove old buffer if compile() called twice
216 delete _nativeObjectFile;
217
Nick Kledzik77595fc2008-02-26 20:26:43 +0000218 // read .o file into memory buffer
Chris Lattner038112a2008-04-01 18:04:03 +0000219 _nativeObjectFile = MemoryBuffer::getFile(uniqueObjStr.c_str(),&errMsg);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000220 }
Nick Kledzikef194ed2008-02-27 22:25:36 +0000221
222 // remove temp files
Nick Kledzik77595fc2008-02-26 20:26:43 +0000223 uniqueAsmPath.eraseFromDisk();
224 uniqueObjPath.eraseFromDisk();
Nick Kledzikef194ed2008-02-27 22:25:36 +0000225
226 // return buffer, unless error
227 if ( _nativeObjectFile == NULL )
228 return NULL;
229 *length = _nativeObjectFile->getBufferSize();
230 return _nativeObjectFile->getBufferStart();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000231}
232
233
234bool LTOCodeGenerator::assemble(const std::string& asmPath,
235 const std::string& objPath, std::string& errMsg)
236{
Nick Kledzikcbad5862009-06-04 00:28:45 +0000237 sys::Path tool;
238 bool needsCompilerOptions = true;
239 if ( _assemblerPath ) {
240 tool = *_assemblerPath;
241 needsCompilerOptions = false;
242 }
243 else if ( _gccPath ) {
244 tool = *_gccPath;
Nick Lewycky195bea32009-04-30 15:24:09 +0000245 } else {
246 // find compiler driver
Nick Kledzikcbad5862009-06-04 00:28:45 +0000247 tool = sys::Program::FindProgramByName("gcc");
248 if ( tool.isEmpty() ) {
Nick Lewycky195bea32009-04-30 15:24:09 +0000249 errMsg = "can't locate gcc";
250 return true;
251 }
Nick Kledzik77595fc2008-02-26 20:26:43 +0000252 }
253
254 // build argument list
255 std::vector<const char*> args;
256 std::string targetTriple = _linker.getModule()->getTargetTriple();
Nick Kledzikcbad5862009-06-04 00:28:45 +0000257 args.push_back(tool.c_str());
Rafael Espindolaf403cd72009-06-09 21:14:25 +0000258 if ( targetTriple.find("darwin") != std::string::npos ) {
Nick Kledzikd8b47112009-06-04 19:14:08 +0000259 // darwin specific command line options
Devang Patelf75e7892008-11-04 23:13:50 +0000260 if (strncmp(targetTriple.c_str(), "i386-apple-", 11) == 0) {
Nick Kledzik77595fc2008-02-26 20:26:43 +0000261 args.push_back("-arch");
262 args.push_back("i386");
263 }
264 else if (strncmp(targetTriple.c_str(), "x86_64-apple-", 13) == 0) {
265 args.push_back("-arch");
266 args.push_back("x86_64");
267 }
268 else if (strncmp(targetTriple.c_str(), "powerpc-apple-", 14) == 0) {
269 args.push_back("-arch");
270 args.push_back("ppc");
271 }
272 else if (strncmp(targetTriple.c_str(), "powerpc64-apple-", 16) == 0) {
273 args.push_back("-arch");
274 args.push_back("ppc64");
275 }
Evan Cheng9f777c62009-04-01 18:54:56 +0000276 else if (strncmp(targetTriple.c_str(), "arm-apple-", 10) == 0) {
277 args.push_back("-arch");
278 args.push_back("arm");
279 }
280 else if ((strncmp(targetTriple.c_str(), "armv4t-apple-", 13) == 0) ||
281 (strncmp(targetTriple.c_str(), "thumbv4t-apple-", 15) == 0)) {
282 args.push_back("-arch");
283 args.push_back("armv4t");
284 }
285 else if ((strncmp(targetTriple.c_str(), "armv5-apple-", 12) == 0) ||
286 (strncmp(targetTriple.c_str(), "armv5e-apple-", 13) == 0) ||
287 (strncmp(targetTriple.c_str(), "thumbv5-apple-", 14) == 0) ||
288 (strncmp(targetTriple.c_str(), "thumbv5e-apple-", 15) == 0)) {
289 args.push_back("-arch");
290 args.push_back("armv5");
291 }
292 else if ((strncmp(targetTriple.c_str(), "armv6-apple-", 12) == 0) ||
293 (strncmp(targetTriple.c_str(), "thumbv6-apple-", 14) == 0)) {
294 args.push_back("-arch");
295 args.push_back("armv6");
296 }
Bob Wilson75d6ffd2009-06-22 18:01:28 +0000297 else if ((strncmp(targetTriple.c_str(), "armv7-apple-", 12) == 0) ||
298 (strncmp(targetTriple.c_str(), "thumbv7-apple-", 14) == 0)) {
299 args.push_back("-arch");
300 args.push_back("armv7");
301 }
Nick Kledzikd8b47112009-06-04 19:14:08 +0000302 // add -static to assembler command line when code model requires
303 if ( (_assemblerPath != NULL) && (_codeModel == LTO_CODEGEN_PIC_MODEL_STATIC) )
304 args.push_back("-static");
Nick Kledzik77595fc2008-02-26 20:26:43 +0000305 }
Nick Kledzikcbad5862009-06-04 00:28:45 +0000306 if ( needsCompilerOptions ) {
307 args.push_back("-c");
308 args.push_back("-x");
309 args.push_back("assembler");
310 }
Nick Kledzik77595fc2008-02-26 20:26:43 +0000311 args.push_back("-o");
312 args.push_back(objPath.c_str());
313 args.push_back(asmPath.c_str());
314 args.push_back(0);
315
316 // invoke assembler
Nick Kledzikcbad5862009-06-04 00:28:45 +0000317 if ( sys::Program::ExecuteAndWait(tool, &args[0], 0, 0, 0, 0, &errMsg) ) {
Nick Kledzik77595fc2008-02-26 20:26:43 +0000318 errMsg = "error in assembly";
319 return true;
320 }
321 return false; // success
322}
323
324
325
326bool LTOCodeGenerator::determineTarget(std::string& errMsg)
327{
328 if ( _target == NULL ) {
329 // create target machine from info for merged modules
330 Module* mergedModule = _linker.getModule();
Stuart Hastings2286f8d2009-07-15 17:27:11 +0000331 const TargetMachineRegistry::entry* march =
332 TargetMachineRegistry::getClosestStaticTargetForModule(
333 *mergedModule, errMsg);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000334 if ( march == NULL )
335 return true;
Bill Wendling604a8182008-06-18 06:35:30 +0000336
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000337 // The relocation model is actually a static member of TargetMachine
338 // and needs to be set before the TargetMachine is instantiated.
339 switch( _codeModel ) {
340 case LTO_CODEGEN_PIC_MODEL_STATIC:
341 TargetMachine::setRelocationModel(Reloc::Static);
342 break;
343 case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
344 TargetMachine::setRelocationModel(Reloc::PIC_);
345 break;
346 case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
347 TargetMachine::setRelocationModel(Reloc::DynamicNoPIC);
348 break;
349 }
350
Bill Wendling604a8182008-06-18 06:35:30 +0000351 // construct LTModule, hand over ownership of module and target
Bill Wendlinge4242542008-06-18 21:39:02 +0000352 std::string FeatureStr =
353 getFeatureString(_linker.getModule()->getTargetTriple().c_str());
Stuart Hastings2286f8d2009-07-15 17:27:11 +0000354 _target = march->CtorFn(*mergedModule, FeatureStr.c_str());
Nick Kledzik77595fc2008-02-26 20:26:43 +0000355 }
356 return false;
357}
358
359void LTOCodeGenerator::applyScopeRestrictions()
360{
361 if ( !_scopeRestrictionsDone ) {
362 Module* mergedModule = _linker.getModule();
363
364 // Start off with a verification pass.
365 PassManager passes;
366 passes.add(createVerifierPass());
367
368 // mark which symbols can not be internalized
369 if ( !_mustPreserveSymbols.empty() ) {
370 Mangler mangler(*mergedModule,
371 _target->getTargetAsmInfo()->getGlobalPrefix());
372 std::vector<const char*> mustPreserveList;
373 for (Module::iterator f = mergedModule->begin(),
374 e = mergedModule->end(); f != e; ++f) {
375 if ( !f->isDeclaration()
Chris Lattnerb8158ac2009-07-14 18:17:16 +0000376 && _mustPreserveSymbols.count(mangler.getMangledName(f)) )
Nick Kledzik77595fc2008-02-26 20:26:43 +0000377 mustPreserveList.push_back(::strdup(f->getName().c_str()));
378 }
379 for (Module::global_iterator v = mergedModule->global_begin(),
380 e = mergedModule->global_end(); v != e; ++v) {
381 if ( !v->isDeclaration()
Chris Lattnerb8158ac2009-07-14 18:17:16 +0000382 && _mustPreserveSymbols.count(mangler.getMangledName(v)) )
Nick Kledzik77595fc2008-02-26 20:26:43 +0000383 mustPreserveList.push_back(::strdup(v->getName().c_str()));
384 }
385 passes.add(createInternalizePass(mustPreserveList));
386 }
387 // apply scope restrictions
388 passes.run(*mergedModule);
389
390 _scopeRestrictionsDone = true;
391 }
392}
393
Nick Kledzik77595fc2008-02-26 20:26:43 +0000394/// Optimize merged modules using various IPO passes
David Greene71847812009-07-14 20:18:05 +0000395bool LTOCodeGenerator::generateAssemblyCode(formatted_raw_ostream& out,
Owen Andersoncb371882008-08-21 00:14:44 +0000396 std::string& errMsg)
Nick Kledzik77595fc2008-02-26 20:26:43 +0000397{
398 if ( this->determineTarget(errMsg) )
399 return true;
400
401 // mark which symbols can not be internalized
402 this->applyScopeRestrictions();
403
404 Module* mergedModule = _linker.getModule();
405
406 // If target supports exception handling then enable it now.
407 if ( _target->getTargetAsmInfo()->doesSupportExceptionHandling() )
408 llvm::ExceptionHandling = true;
409
Nick Kledzik920ae982008-07-08 21:14:10 +0000410 // if options were requested, set them
411 if ( !_codegenOptions.empty() )
412 cl::ParseCommandLineOptions(_codegenOptions.size(),
413 (char**)&_codegenOptions[0]);
Devang Patela93ae712008-07-03 22:53:14 +0000414
Nick Kledzik77595fc2008-02-26 20:26:43 +0000415 // Instantiate the pass manager to organize the passes.
416 PassManager passes;
417
418 // Start off with a verification pass.
419 passes.add(createVerifierPass());
420
421 // Add an appropriate TargetData instance for this module...
422 passes.add(new TargetData(*_target->getTargetData()));
423
Daniel Dunbar006a0342009-06-03 21:06:14 +0000424 createStandardLTOPasses(&passes, /*Internalize=*/ false, !DisableInline,
Daniel Dunbar006a0342009-06-03 21:06:14 +0000425 /*VerifyEach=*/ false);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000426
427 // Make sure everything is still good.
428 passes.add(createVerifierPass());
429
430 FunctionPassManager* codeGenPasses =
431 new FunctionPassManager(new ExistingModuleProvider(mergedModule));
432
433 codeGenPasses->add(new TargetData(*_target->getTargetData()));
434
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000435 ObjectCodeEmitter* oce = NULL;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000436
437 switch (_target->addPassesToEmitFile(*codeGenPasses, out,
Bill Wendling98a366d2009-04-29 23:29:43 +0000438 TargetMachine::AssemblyFile,
Bill Wendlingb8cb0bb2009-04-29 23:40:42 +0000439 CodeGenOpt::Aggressive)) {
Nick Kledzik77595fc2008-02-26 20:26:43 +0000440 case FileModel::MachOFile:
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000441 oce = AddMachOWriter(*codeGenPasses, out, *_target);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000442 break;
443 case FileModel::ElfFile:
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000444 oce = AddELFWriter(*codeGenPasses, out, *_target);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000445 break;
446 case FileModel::AsmFile:
447 break;
448 case FileModel::Error:
449 case FileModel::None:
450 errMsg = "target file type not supported";
451 return true;
452 }
453
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000454 if (_target->addPassesToEmitFileFinish(*codeGenPasses, oce,
Bill Wendlingb8cb0bb2009-04-29 23:40:42 +0000455 CodeGenOpt::Aggressive)) {
Nick Kledzik77595fc2008-02-26 20:26:43 +0000456 errMsg = "target does not support generation of this file type";
457 return true;
458 }
459
460 // Run our queue of passes all at once now, efficiently.
461 passes.run(*mergedModule);
462
463 // Run the code generator, and write assembly file
464 codeGenPasses->doInitialization();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000465
Bill Wendling604a8182008-06-18 06:35:30 +0000466 for (Module::iterator
467 it = mergedModule->begin(), e = mergedModule->end(); it != e; ++it)
468 if (!it->isDeclaration())
469 codeGenPasses->run(*it);
470
471 codeGenPasses->doFinalization();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000472 return false; // success
473}
474
475
Nick Kledzik920ae982008-07-08 21:14:10 +0000476/// Optimize merged modules using various IPO passes
477void LTOCodeGenerator::setCodeGenDebugOptions(const char* options)
478{
479 std::string ops(options);
480 for (std::string o = getToken(ops); !o.empty(); o = getToken(ops)) {
481 // ParseCommandLineOptions() expects argv[0] to be program name.
482 // Lazily add that.
483 if ( _codegenOptions.empty() )
484 _codegenOptions.push_back("libLTO");
485 _codegenOptions.push_back(strdup(o.c_str()));
486 }
487}