blob: 5176359e5d0e54d0ee55c6c3f6f2389af59e7e28 [file] [log] [blame]
Nick Kledzik6d886992008-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 Kledzik79d0a052008-02-27 22:25:36 +000015#include "LTOModule.h"
16#include "LTOCodeGenerator.h"
17
18
Nick Kledzik6d886992008-02-26 20:26:43 +000019#include "llvm/Constants.h"
20#include "llvm/DerivedTypes.h"
Nick Lewycky3d1feeb2009-06-17 06:52:10 +000021#include "llvm/Linker.h"
Owen Anderson353dadb2009-07-02 00:31:14 +000022#include "llvm/LLVMContext.h"
Nick Lewycky3d1feeb2009-06-17 06:52:10 +000023#include "llvm/Module.h"
Nick Kledzik6d886992008-02-26 20:26:43 +000024#include "llvm/ModuleProvider.h"
Nick Lewycky3d1feeb2009-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 Kledzik6d886992008-02-26 20:26:43 +000030#include "llvm/Bitcode/ReaderWriter.h"
Nick Lewycky3d1feeb2009-06-17 06:52:10 +000031#include "llvm/CodeGen/FileWriters.h"
Nick Kledzik4059fb12008-07-08 21:14:10 +000032#include "llvm/Support/CommandLine.h"
David Greene302008d2009-07-14 20:18:05 +000033#include "llvm/Support/FormattedStream.h"
Nick Kledzik6d886992008-02-26 20:26:43 +000034#include "llvm/Support/Mangler.h"
35#include "llvm/Support/MemoryBuffer.h"
Daniel Dunbar9068de52009-06-03 21:06:14 +000036#include "llvm/Support/StandardPasses.h"
37#include "llvm/Support/SystemUtils.h"
Nick Kledzik6d886992008-02-26 20:26:43 +000038#include "llvm/System/Signals.h"
Bill Wendling568e37c2008-06-18 06:35:30 +000039#include "llvm/Target/SubtargetFeature.h"
Nick Kledzik6d886992008-02-26 20:26:43 +000040#include "llvm/Target/TargetOptions.h"
Chris Lattner41788082009-06-17 16:42:19 +000041#include "llvm/Target/TargetAsmInfo.h"
Nick Kledzik6d886992008-02-26 20:26:43 +000042#include "llvm/Target/TargetData.h"
43#include "llvm/Target/TargetMachine.h"
44#include "llvm/Target/TargetMachineRegistry.h"
Chris Lattner41788082009-06-17 16:42:19 +000045#include "llvm/Target/TargetSelect.h"
Nick Kledzik6d886992008-02-26 20:26:43 +000046#include "llvm/Transforms/IPO.h"
47#include "llvm/Transforms/Scalar.h"
Nick Kledzik6d886992008-02-26 20:26:43 +000048#include "llvm/Config/config.h"
49
Nick Kledzik6d886992008-02-26 20:26:43 +000050
Nick Lewycky3d1feeb2009-06-17 06:52:10 +000051#include <cstdlib>
Nick Kledzik6d886992008-02-26 20:26:43 +000052#include <fstream>
53#include <unistd.h>
Nick Kledzik6d886992008-02-26 20:26:43 +000054#include <fcntl.h>
55
56
57using namespace llvm;
58
Nick Kledzik4059fb12008-07-08 21:14:10 +000059static cl::opt<bool> DisableInline("disable-inlining",
60 cl::desc("Do not run the inliner pass"));
Nick Kledzik6d886992008-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 Anderson353dadb2009-07-02 00:31:14 +000073LTOCodeGenerator::LTOCodeGenerator()
74 : _context(getGlobalContext()),
Owen Anderson25209b42009-07-01 16:58:40 +000075 _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL),
Nick Kledzik6d886992008-02-26 20:26:43 +000076 _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false),
Nick Kledzik79d0a052008-02-27 22:25:36 +000077 _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC),
Nick Kledzik39d9b412009-06-04 00:28:45 +000078 _nativeObjectFile(NULL), _gccPath(NULL), _assemblerPath(NULL)
Nick Kledzik6d886992008-02-26 20:26:43 +000079{
Chris Lattner41788082009-06-17 16:42:19 +000080 InitializeAllTargets();
81 InitializeAllAsmPrinters();
Nick Kledzik6d886992008-02-26 20:26:43 +000082
83}
84
85LTOCodeGenerator::~LTOCodeGenerator()
86{
Nick Kledzik79d0a052008-02-27 22:25:36 +000087 delete _target;
88 delete _nativeObjectFile;
Nick Kledzik6d886992008-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 Cheng521500b2009-06-26 06:57:16 +0000116 std::string& errMsg)
Nick Kledzik6d886992008-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 Lewyckyef973202009-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 Kledzik39d9b412009-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 Kledzik6d886992008-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 Kledzik79d0a052008-02-27 22:25:36 +0000177const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg)
Nick Kledzik6d886992008-02-26 20:26:43 +0000178{
Nick Kledzik79d0a052008-02-27 22:25:36 +0000179 // make unique temp .s file to put generated assembly code
Nick Kledzik6d886992008-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 Anderson847b99b2008-08-21 00:14:44 +0000186 bool genResult = false;
187 {
David Greene302008d2009-07-14 20:18:05 +0000188 raw_fd_ostream asmFD(raw_fd_ostream(uniqueAsmPath.c_str(),
Dan Gohmandd7ca8e2009-07-15 17:29:42 +0000189 /*Binary=*/false, /*Force=*/true,
190 errMsg));
David Greene302008d2009-07-14 20:18:05 +0000191 formatted_raw_ostream asmFile(asmFD);
Dan Gohmande20df82008-08-21 15:33:45 +0000192 if (!errMsg.empty())
193 return NULL;
Owen Anderson847b99b2008-08-21 00:14:44 +0000194 genResult = this->generateAssemblyCode(asmFile, errMsg);
195 }
Nick Kledzik6d886992008-02-26 20:26:43 +0000196 if ( genResult ) {
197 if ( uniqueAsmPath.exists() )
198 uniqueAsmPath.eraseFromDisk();
199 return NULL;
200 }
201
Nick Kledzik79d0a052008-02-27 22:25:36 +0000202 // make unique temp .o file to put generated object file
Nick Kledzik6d886992008-02-26 20:26:43 +0000203 sys::PathWithStatus uniqueObjPath("lto-llvm.o");
204 if ( uniqueObjPath.createTemporaryFileOnDisk(true, &errMsg) ) {
205 if ( uniqueAsmPath.exists() )
206 uniqueAsmPath.eraseFromDisk();
207 return NULL;
208 }
209 sys::RemoveFileOnSignal(uniqueObjPath);
210
211 // assemble the assembly code
Nick Kledzik79d0a052008-02-27 22:25:36 +0000212 const std::string& uniqueObjStr = uniqueObjPath.toString();
Nick Kledzik6d886992008-02-26 20:26:43 +0000213 bool asmResult = this->assemble(uniqueAsmPath.toString(),
Nick Kledzik79d0a052008-02-27 22:25:36 +0000214 uniqueObjStr, errMsg);
Nick Kledzik6d886992008-02-26 20:26:43 +0000215 if ( !asmResult ) {
Nick Kledzik79d0a052008-02-27 22:25:36 +0000216 // remove old buffer if compile() called twice
217 delete _nativeObjectFile;
218
Nick Kledzik6d886992008-02-26 20:26:43 +0000219 // read .o file into memory buffer
Chris Lattnerfc003612008-04-01 18:04:03 +0000220 _nativeObjectFile = MemoryBuffer::getFile(uniqueObjStr.c_str(),&errMsg);
Nick Kledzik6d886992008-02-26 20:26:43 +0000221 }
Nick Kledzik79d0a052008-02-27 22:25:36 +0000222
223 // remove temp files
Nick Kledzik6d886992008-02-26 20:26:43 +0000224 uniqueAsmPath.eraseFromDisk();
225 uniqueObjPath.eraseFromDisk();
Nick Kledzik79d0a052008-02-27 22:25:36 +0000226
227 // return buffer, unless error
228 if ( _nativeObjectFile == NULL )
229 return NULL;
230 *length = _nativeObjectFile->getBufferSize();
231 return _nativeObjectFile->getBufferStart();
Nick Kledzik6d886992008-02-26 20:26:43 +0000232}
233
234
235bool LTOCodeGenerator::assemble(const std::string& asmPath,
236 const std::string& objPath, std::string& errMsg)
237{
Nick Kledzik39d9b412009-06-04 00:28:45 +0000238 sys::Path tool;
239 bool needsCompilerOptions = true;
240 if ( _assemblerPath ) {
241 tool = *_assemblerPath;
242 needsCompilerOptions = false;
243 }
244 else if ( _gccPath ) {
245 tool = *_gccPath;
Nick Lewyckyef973202009-04-30 15:24:09 +0000246 } else {
247 // find compiler driver
Nick Kledzik39d9b412009-06-04 00:28:45 +0000248 tool = sys::Program::FindProgramByName("gcc");
249 if ( tool.isEmpty() ) {
Nick Lewyckyef973202009-04-30 15:24:09 +0000250 errMsg = "can't locate gcc";
251 return true;
252 }
Nick Kledzik6d886992008-02-26 20:26:43 +0000253 }
254
255 // build argument list
256 std::vector<const char*> args;
257 std::string targetTriple = _linker.getModule()->getTargetTriple();
Nick Kledzik39d9b412009-06-04 00:28:45 +0000258 args.push_back(tool.c_str());
Rafael Espindola6c279402009-06-09 21:14:25 +0000259 if ( targetTriple.find("darwin") != std::string::npos ) {
Nick Kledzikfe15a722009-06-04 19:14:08 +0000260 // darwin specific command line options
Devang Patelaa6cd1f2008-11-04 23:13:50 +0000261 if (strncmp(targetTriple.c_str(), "i386-apple-", 11) == 0) {
Nick Kledzik6d886992008-02-26 20:26:43 +0000262 args.push_back("-arch");
263 args.push_back("i386");
264 }
265 else if (strncmp(targetTriple.c_str(), "x86_64-apple-", 13) == 0) {
266 args.push_back("-arch");
267 args.push_back("x86_64");
268 }
269 else if (strncmp(targetTriple.c_str(), "powerpc-apple-", 14) == 0) {
270 args.push_back("-arch");
271 args.push_back("ppc");
272 }
273 else if (strncmp(targetTriple.c_str(), "powerpc64-apple-", 16) == 0) {
274 args.push_back("-arch");
275 args.push_back("ppc64");
276 }
Evan Chengdc5b6d62009-04-01 18:54:56 +0000277 else if (strncmp(targetTriple.c_str(), "arm-apple-", 10) == 0) {
278 args.push_back("-arch");
279 args.push_back("arm");
280 }
281 else if ((strncmp(targetTriple.c_str(), "armv4t-apple-", 13) == 0) ||
282 (strncmp(targetTriple.c_str(), "thumbv4t-apple-", 15) == 0)) {
283 args.push_back("-arch");
284 args.push_back("armv4t");
285 }
286 else if ((strncmp(targetTriple.c_str(), "armv5-apple-", 12) == 0) ||
287 (strncmp(targetTriple.c_str(), "armv5e-apple-", 13) == 0) ||
288 (strncmp(targetTriple.c_str(), "thumbv5-apple-", 14) == 0) ||
289 (strncmp(targetTriple.c_str(), "thumbv5e-apple-", 15) == 0)) {
290 args.push_back("-arch");
291 args.push_back("armv5");
292 }
293 else if ((strncmp(targetTriple.c_str(), "armv6-apple-", 12) == 0) ||
294 (strncmp(targetTriple.c_str(), "thumbv6-apple-", 14) == 0)) {
295 args.push_back("-arch");
296 args.push_back("armv6");
297 }
Bob Wilson5b50a242009-06-22 18:01:28 +0000298 else if ((strncmp(targetTriple.c_str(), "armv7-apple-", 12) == 0) ||
299 (strncmp(targetTriple.c_str(), "thumbv7-apple-", 14) == 0)) {
300 args.push_back("-arch");
301 args.push_back("armv7");
302 }
Nick Kledzikfe15a722009-06-04 19:14:08 +0000303 // add -static to assembler command line when code model requires
304 if ( (_assemblerPath != NULL) && (_codeModel == LTO_CODEGEN_PIC_MODEL_STATIC) )
305 args.push_back("-static");
Nick Kledzik6d886992008-02-26 20:26:43 +0000306 }
Nick Kledzik39d9b412009-06-04 00:28:45 +0000307 if ( needsCompilerOptions ) {
308 args.push_back("-c");
309 args.push_back("-x");
310 args.push_back("assembler");
311 }
Nick Kledzik6d886992008-02-26 20:26:43 +0000312 args.push_back("-o");
313 args.push_back(objPath.c_str());
314 args.push_back(asmPath.c_str());
315 args.push_back(0);
316
317 // invoke assembler
Nick Kledzik39d9b412009-06-04 00:28:45 +0000318 if ( sys::Program::ExecuteAndWait(tool, &args[0], 0, 0, 0, 0, &errMsg) ) {
Nick Kledzik6d886992008-02-26 20:26:43 +0000319 errMsg = "error in assembly";
320 return true;
321 }
322 return false; // success
323}
324
325
326
327bool LTOCodeGenerator::determineTarget(std::string& errMsg)
328{
329 if ( _target == NULL ) {
330 // create target machine from info for merged modules
331 Module* mergedModule = _linker.getModule();
Daniel Dunbarfe5939f2009-07-15 20:24:03 +0000332 const Target *march =
333 TargetRegistry::getClosestStaticTargetForModule(*mergedModule,
334 errMsg);
Nick Kledzik6d886992008-02-26 20:26:43 +0000335 if ( march == NULL )
336 return true;
Bill Wendling568e37c2008-06-18 06:35:30 +0000337
Nick Kledzik3e843222009-06-03 22:52:12 +0000338 // The relocation model is actually a static member of TargetMachine
339 // and needs to be set before the TargetMachine is instantiated.
340 switch( _codeModel ) {
341 case LTO_CODEGEN_PIC_MODEL_STATIC:
342 TargetMachine::setRelocationModel(Reloc::Static);
343 break;
344 case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
345 TargetMachine::setRelocationModel(Reloc::PIC_);
346 break;
347 case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
348 TargetMachine::setRelocationModel(Reloc::DynamicNoPIC);
349 break;
350 }
351
Bill Wendling568e37c2008-06-18 06:35:30 +0000352 // construct LTModule, hand over ownership of module and target
Bill Wendling0478d1a2008-06-18 21:39:02 +0000353 std::string FeatureStr =
354 getFeatureString(_linker.getModule()->getTargetTriple().c_str());
Daniel Dunbarfe5939f2009-07-15 20:24:03 +0000355 _target = march->createTargetMachine(*mergedModule, FeatureStr.c_str());
Nick Kledzik6d886992008-02-26 20:26:43 +0000356 }
357 return false;
358}
359
360void LTOCodeGenerator::applyScopeRestrictions()
361{
362 if ( !_scopeRestrictionsDone ) {
363 Module* mergedModule = _linker.getModule();
364
365 // Start off with a verification pass.
366 PassManager passes;
367 passes.add(createVerifierPass());
368
369 // mark which symbols can not be internalized
370 if ( !_mustPreserveSymbols.empty() ) {
371 Mangler mangler(*mergedModule,
372 _target->getTargetAsmInfo()->getGlobalPrefix());
373 std::vector<const char*> mustPreserveList;
374 for (Module::iterator f = mergedModule->begin(),
375 e = mergedModule->end(); f != e; ++f) {
376 if ( !f->isDeclaration()
Chris Lattnerb3cdde62009-07-14 18:17:16 +0000377 && _mustPreserveSymbols.count(mangler.getMangledName(f)) )
Nick Kledzik6d886992008-02-26 20:26:43 +0000378 mustPreserveList.push_back(::strdup(f->getName().c_str()));
379 }
380 for (Module::global_iterator v = mergedModule->global_begin(),
381 e = mergedModule->global_end(); v != e; ++v) {
382 if ( !v->isDeclaration()
Chris Lattnerb3cdde62009-07-14 18:17:16 +0000383 && _mustPreserveSymbols.count(mangler.getMangledName(v)) )
Nick Kledzik6d886992008-02-26 20:26:43 +0000384 mustPreserveList.push_back(::strdup(v->getName().c_str()));
385 }
386 passes.add(createInternalizePass(mustPreserveList));
387 }
388 // apply scope restrictions
389 passes.run(*mergedModule);
390
391 _scopeRestrictionsDone = true;
392 }
393}
394
Nick Kledzik6d886992008-02-26 20:26:43 +0000395/// Optimize merged modules using various IPO passes
David Greene302008d2009-07-14 20:18:05 +0000396bool LTOCodeGenerator::generateAssemblyCode(formatted_raw_ostream& out,
Owen Anderson847b99b2008-08-21 00:14:44 +0000397 std::string& errMsg)
Nick Kledzik6d886992008-02-26 20:26:43 +0000398{
399 if ( this->determineTarget(errMsg) )
400 return true;
401
402 // mark which symbols can not be internalized
403 this->applyScopeRestrictions();
404
405 Module* mergedModule = _linker.getModule();
406
407 // If target supports exception handling then enable it now.
408 if ( _target->getTargetAsmInfo()->doesSupportExceptionHandling() )
409 llvm::ExceptionHandling = true;
410
Nick Kledzik4059fb12008-07-08 21:14:10 +0000411 // if options were requested, set them
412 if ( !_codegenOptions.empty() )
413 cl::ParseCommandLineOptions(_codegenOptions.size(),
414 (char**)&_codegenOptions[0]);
Devang Patel6fb60262008-07-03 22:53:14 +0000415
Nick Kledzik6d886992008-02-26 20:26:43 +0000416 // Instantiate the pass manager to organize the passes.
417 PassManager passes;
418
419 // Start off with a verification pass.
420 passes.add(createVerifierPass());
421
422 // Add an appropriate TargetData instance for this module...
423 passes.add(new TargetData(*_target->getTargetData()));
424
Daniel Dunbar9068de52009-06-03 21:06:14 +0000425 createStandardLTOPasses(&passes, /*Internalize=*/ false, !DisableInline,
Daniel Dunbar9068de52009-06-03 21:06:14 +0000426 /*VerifyEach=*/ false);
Nick Kledzik6d886992008-02-26 20:26:43 +0000427
428 // Make sure everything is still good.
429 passes.add(createVerifierPass());
430
431 FunctionPassManager* codeGenPasses =
432 new FunctionPassManager(new ExistingModuleProvider(mergedModule));
433
434 codeGenPasses->add(new TargetData(*_target->getTargetData()));
435
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000436 ObjectCodeEmitter* oce = NULL;
Nick Kledzik6d886992008-02-26 20:26:43 +0000437
438 switch (_target->addPassesToEmitFile(*codeGenPasses, out,
Bill Wendling5ed22ac2009-04-29 23:29:43 +0000439 TargetMachine::AssemblyFile,
Bill Wendling2d1c1162009-04-29 23:40:42 +0000440 CodeGenOpt::Aggressive)) {
Nick Kledzik6d886992008-02-26 20:26:43 +0000441 case FileModel::MachOFile:
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000442 oce = AddMachOWriter(*codeGenPasses, out, *_target);
Nick Kledzik6d886992008-02-26 20:26:43 +0000443 break;
444 case FileModel::ElfFile:
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000445 oce = AddELFWriter(*codeGenPasses, out, *_target);
Nick Kledzik6d886992008-02-26 20:26:43 +0000446 break;
447 case FileModel::AsmFile:
448 break;
449 case FileModel::Error:
450 case FileModel::None:
451 errMsg = "target file type not supported";
452 return true;
453 }
454
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000455 if (_target->addPassesToEmitFileFinish(*codeGenPasses, oce,
Bill Wendling2d1c1162009-04-29 23:40:42 +0000456 CodeGenOpt::Aggressive)) {
Nick Kledzik6d886992008-02-26 20:26:43 +0000457 errMsg = "target does not support generation of this file type";
458 return true;
459 }
460
461 // Run our queue of passes all at once now, efficiently.
462 passes.run(*mergedModule);
463
464 // Run the code generator, and write assembly file
465 codeGenPasses->doInitialization();
Nick Kledzik6d886992008-02-26 20:26:43 +0000466
Bill Wendling568e37c2008-06-18 06:35:30 +0000467 for (Module::iterator
468 it = mergedModule->begin(), e = mergedModule->end(); it != e; ++it)
469 if (!it->isDeclaration())
470 codeGenPasses->run(*it);
471
472 codeGenPasses->doFinalization();
Nick Kledzik6d886992008-02-26 20:26:43 +0000473 return false; // success
474}
475
476
Nick Kledzik4059fb12008-07-08 21:14:10 +0000477/// Optimize merged modules using various IPO passes
478void LTOCodeGenerator::setCodeGenDebugOptions(const char* options)
479{
480 std::string ops(options);
481 for (std::string o = getToken(ops); !o.empty(); o = getToken(ops)) {
482 // ParseCommandLineOptions() expects argv[0] to be program name.
483 // Lazily add that.
484 if ( _codegenOptions.empty() )
485 _codegenOptions.push_back("libLTO");
486 _codegenOptions.push_back(strdup(o.c_str()));
487 }
488}