llvm.org GIT mirror llvm / c13c9e5
Move command line options to the users of libLTO. Fixes --enable-shared build. Patch by Richard Sandiford. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191680 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 7 years ago
6 changed file(s) with 185 addition(s) and 176 deletion(s). Raw diff Collapse all Expand all
3838 #include "llvm/ADT/SmallPtrSet.h"
3939 #include "llvm/ADT/StringMap.h"
4040 #include "llvm/Linker.h"
41 #include "llvm/Target/TargetOptions.h"
4142 #include
4243 #include
4344
6364 // Merge given module, return true on success.
6465 bool addModule(struct LTOModule*, std::string &errMsg);
6566
67 void setTargetOptions(llvm::TargetOptions options);
6668 void setDebugInfo(lto_debug_model);
6769 void setCodePICModel(lto_codegen_model);
6870
8991 // Do not try to remove the object file in LTOCodeGenerator's destructor
9092 // as we don't who (LTOCodeGenerator or the obj file) will last longer.
9193 //
92 bool compile_to_file(const char **name, std::string &errMsg);
94 bool compile_to_file(const char **name,
95 bool disableOpt,
96 bool disableInline,
97 bool disableGVNLoadPRE,
98 std::string &errMsg);
9399
94100 // As with compile_to_file(), this function compiles the merged module into
95101 // single object file. Instead of returning the object-file-path to the caller
97103 // caller. This function should delete intermediate object file once its content
98104 // is brought to memory. Return NULL if the compilation was not successful.
99105 //
100 const void *compile(size_t *length, std::string &errMsg);
106 const void *compile(size_t *length,
107 bool disableOpt,
108 bool disableInline,
109 bool disableGVNLoadPRE,
110 std::string &errMsg);
101111
102112 private:
103113 void initializeLTOPasses();
104114
105 bool generateObjectFile(llvm::raw_ostream &out, std::string &errMsg);
115 bool generateObjectFile(llvm::raw_ostream &out,
116 bool disableOpt,
117 bool disableInline,
118 bool disableGVNLoadPRE,
119 std::string &errMsg);
106120 void applyScopeRestrictions();
107121 void applyRestriction(llvm::GlobalValue &GV,
108122 std::vector &MustPreserveList,
124138 std::vector CodegenOptions;
125139 std::string MCpu;
126140 std::string NativeObjectPath;
141 llvm::TargetOptions Options;
127142 };
128143
129144 #endif // LTO_CODE_GENERATOR_H
8383 /// InitializeAllAsmPrinters();
8484 /// InitializeAllAsmParsers();
8585 static LTOModule *makeLTOModule(const char* path,
86 llvm::TargetOptions options,
8687 std::string &errMsg);
8788 static LTOModule *makeLTOModule(int fd, const char *path,
88 size_t size, std::string &errMsg);
89 size_t size, llvm::TargetOptions options,
90 std::string &errMsg);
8991 static LTOModule *makeLTOModule(int fd, const char *path,
9092 size_t map_size,
91 off_t offset,
93 off_t offset, llvm::TargetOptions options,
9294 std::string& errMsg);
9395 static LTOModule *makeLTOModule(const void *mem, size_t length,
96 llvm::TargetOptions options,
9497 std::string &errMsg);
9598
9699 /// getTargetTriple - Return the Module's target triple.
130133 const std::vector &getAsmUndefinedRefs() {
131134 return _asm_undefines;
132135 }
133
134 /// getTargetOptions - Fill the TargetOptions object with the options
135 /// specified on the command line.
136 static void getTargetOptions(llvm::TargetOptions &Options);
137136
138137 private:
139138 /// parseSymbols - Parse the symbols from the module and model-level ASM and
186185 /// makeLTOModule - Create an LTOModule (private version). N.B. This
187186 /// method takes ownership of the buffer.
188187 static LTOModule *makeLTOModule(llvm::MemoryBuffer *buffer,
188 llvm::TargetOptions options,
189189 std::string &errMsg);
190190
191191 /// makeBuffer - Create a MemoryBuffer from a memory range.
3939 #include "llvm/Support/TargetSelect.h"
4040 #include "llvm/Support/ToolOutputFile.h"
4141 #include "llvm/Support/system_error.h"
42 #include "llvm/Target/TargetOptions.h"
4243 #include "llvm/Target/TargetRegisterInfo.h"
4344 #include "llvm/Target/Mangler.h"
4445 #include "llvm/Transforms/IPO.h"
4546 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
4647 #include "llvm/Transforms/ObjCARC.h"
4748 using namespace llvm;
48
49 static cl::opt
50 DisableOpt("disable-opt", cl::init(false),
51 cl::desc("Do not run any optimization passes"));
52
53 static cl::opt
54 DisableInline("disable-inlining", cl::init(false),
55 cl::desc("Do not run the inliner pass"));
56
57 static cl::opt
58 DisableGVNLoadPRE("disable-gvn-loadpre", cl::init(false),
59 cl::desc("Do not run the GVN load PRE pass"));
6049
6150 const char* LTOCodeGenerator::getVersionString() {
6251 #ifdef LLVM_VERSION_INFO
124113 return !ret;
125114 }
126115
116 void LTOCodeGenerator::setTargetOptions(TargetOptions options) {
117 Options.LessPreciseFPMADOption = options.LessPreciseFPMADOption;
118 Options.NoFramePointerElim = options.NoFramePointerElim;
119 Options.AllowFPOpFusion = options.AllowFPOpFusion;
120 Options.UnsafeFPMath = options.UnsafeFPMath;
121 Options.NoInfsFPMath = options.NoInfsFPMath;
122 Options.NoNaNsFPMath = options.NoNaNsFPMath;
123 Options.HonorSignDependentRoundingFPMathOption =
124 options.HonorSignDependentRoundingFPMathOption;
125 Options.UseSoftFloat = options.UseSoftFloat;
126 Options.FloatABIType = options.FloatABIType;
127 Options.NoZerosInBSS = options.NoZerosInBSS;
128 Options.GuaranteedTailCallOpt = options.GuaranteedTailCallOpt;
129 Options.DisableTailCalls = options.DisableTailCalls;
130 Options.StackAlignmentOverride = options.StackAlignmentOverride;
131 Options.TrapFuncName = options.TrapFuncName;
132 Options.PositionIndependentExecutable = options.PositionIndependentExecutable;
133 Options.EnableSegmentedStacks = options.EnableSegmentedStacks;
134 Options.UseInitArray = options.UseInitArray;
135 }
136
127137 void LTOCodeGenerator::setDebugInfo(lto_debug_model debug) {
128138 switch (debug) {
129139 case LTO_DEBUG_MODEL_NONE:
180190 return true;
181191 }
182192
183 bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg) {
193 bool LTOCodeGenerator::compile_to_file(const char** name,
194 bool disableOpt,
195 bool disableInline,
196 bool disableGVNLoadPRE,
197 std::string& errMsg) {
184198 // make unique temp .o file to put generated object file
185199 SmallString<128> Filename;
186200 int FD;
193207 // generate object file
194208 tool_output_file objFile(Filename.c_str(), FD);
195209
196 bool genResult = generateObjectFile(objFile.os(), errMsg);
210 bool genResult = generateObjectFile(objFile.os(), disableOpt, disableInline,
211 disableGVNLoadPRE, errMsg);
197212 objFile.os().close();
198213 if (objFile.os().has_error()) {
199214 objFile.os().clear_error();
212227 return true;
213228 }
214229
215 const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg) {
230 const void* LTOCodeGenerator::compile(size_t* length,
231 bool disableOpt,
232 bool disableInline,
233 bool disableGVNLoadPRE,
234 std::string& errMsg) {
216235 const char *name;
217 if (!compile_to_file(&name, errMsg))
236 if (!compile_to_file(&name, disableOpt, disableInline, disableGVNLoadPRE,
237 errMsg))
218238 return NULL;
219239
220240 // remove old buffer if compile() called twice
284304 else if (Triple.getArch() == llvm::Triple::x86)
285305 MCpu = "yonah";
286306 }
287 TargetOptions Options;
288 LTOModule::getTargetOptions(Options);
307
289308 TargetMach = march->createTargetMachine(TripleStr, MCpu, FeatureStr, Options,
290309 RelocModel, CodeModel::Default,
291310 CodeGenOpt::Aggressive);
381400
382401 /// Optimize merged modules using various IPO passes
383402 bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,
403 bool DisableOpt,
404 bool DisableInline,
405 bool DisableGVNLoadPRE,
384406 std::string &errMsg) {
385407 if (!this->determineTarget(errMsg))
386408 return false;
3939 #include "llvm/Target/TargetRegisterInfo.h"
4040 using namespace llvm;
4141
42 static cl::opt
43 EnableFPMAD("enable-fp-mad",
44 cl::desc("Enable less precise MAD instructions to be generated"),
45 cl::init(false));
46
47 static cl::opt
48 DisableFPElim("disable-fp-elim",
49 cl::desc("Disable frame pointer elimination optimization"),
50 cl::init(false));
51
52 static cl::opt
53 EnableUnsafeFPMath("enable-unsafe-fp-math",
54 cl::desc("Enable optimizations that may decrease FP precision"),
55 cl::init(false));
56
57 static cl::opt
58 EnableNoInfsFPMath("enable-no-infs-fp-math",
59 cl::desc("Enable FP math optimizations that assume no +-Infs"),
60 cl::init(false));
61
62 static cl::opt
63 EnableNoNaNsFPMath("enable-no-nans-fp-math",
64 cl::desc("Enable FP math optimizations that assume no NaNs"),
65 cl::init(false));
66
67 static cl::opt
68 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
69 cl::Hidden,
70 cl::desc("Force codegen to assume rounding mode can change dynamically"),
71 cl::init(false));
72
73 static cl::opt
74 GenerateSoftFloatCalls("soft-float",
75 cl::desc("Generate software floating point library calls"),
76 cl::init(false));
77
78 static cl::opt
79 FloatABIForCalls("float-abi",
80 cl::desc("Choose float ABI type"),
81 cl::init(FloatABI::Default),
82 cl::values(
83 clEnumValN(FloatABI::Default, "default",
84 "Target default float ABI type"),
85 clEnumValN(FloatABI::Soft, "soft",
86 "Soft float ABI (implied by -soft-float)"),
87 clEnumValN(FloatABI::Hard, "hard",
88 "Hard float ABI (uses FP registers)"),
89 clEnumValEnd));
90
91 static cl::opt
92 FuseFPOps("fp-contract",
93 cl::desc("Enable aggresive formation of fused FP ops"),
94 cl::init(FPOpFusion::Standard),
95 cl::values(
96 clEnumValN(FPOpFusion::Fast, "fast",
97 "Fuse FP ops whenever profitable"),
98 clEnumValN(FPOpFusion::Standard, "on",
99 "Only fuse 'blessed' FP ops."),
100 clEnumValN(FPOpFusion::Strict, "off",
101 "Only fuse FP ops when the result won't be effected."),
102 clEnumValEnd));
103
104 static cl::opt
105 DontPlaceZerosInBSS("nozero-initialized-in-bss",
106 cl::desc("Don't place zero-initialized symbols into bss section"),
107 cl::init(false));
108
109 static cl::opt
110 EnableGuaranteedTailCallOpt("tailcallopt",
111 cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
112 cl::init(false));
113
114 static cl::opt
115 DisableTailCalls("disable-tail-calls",
116 cl::desc("Never emit tail calls"),
117 cl::init(false));
118
119 static cl::opt
120 OverrideStackAlignment("stack-alignment",
121 cl::desc("Override default stack alignment"),
122 cl::init(0));
123
124 static cl::opt
125 TrapFuncName("trap-func", cl::Hidden,
126 cl::desc("Emit a call to trap function rather than a trap instruction"),
127 cl::init(""));
128
129 static cl::opt
130 EnablePIE("enable-pie",
131 cl::desc("Assume the creation of a position independent executable."),
132 cl::init(false));
133
134 static cl::opt
135 SegmentedStacks("segmented-stacks",
136 cl::desc("Use segmented stacks if possible."),
137 cl::init(false));
138
139 static cl::opt
140 UseInitArray("use-init-array",
141 cl::desc("Use .init_array instead of .ctors."),
142 cl::init(false));
143
14442 LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t)
14543 : _module(m), _target(t),
14644 _context(_target->getMCAsmInfo(), _target->getRegisterInfo(), NULL),
18886
18987 /// makeLTOModule - Create an LTOModule. N.B. These methods take ownership of
19088 /// the buffer.
191 LTOModule *LTOModule::makeLTOModule(const char *path, std::string &errMsg) {
89 LTOModule *LTOModule::makeLTOModule(const char *path, TargetOptions options,
90 std::string &errMsg) {
19291 OwningPtr buffer;
19392 if (error_code ec = MemoryBuffer::getFile(path, buffer)) {
19493 errMsg = ec.message();
19594 return NULL;
19695 }
197 return makeLTOModule(buffer.take(), errMsg);
96 return makeLTOModule(buffer.take(), options, errMsg);
19897 }
19998
20099 LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
201 size_t size, std::string &errMsg) {
202 return makeLTOModule(fd, path, size, 0, errMsg);
100 size_t size, TargetOptions options,
101 std::string &errMsg) {
102 return makeLTOModule(fd, path, size, 0, options, errMsg);
203103 }
204104
205105 LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
206106 size_t map_size,
207107 off_t offset,
108 TargetOptions options,
208109 std::string &errMsg) {
209110 OwningPtr buffer;
210111 if (error_code ec =
212113 errMsg = ec.message();
213114 return NULL;
214115 }
215 return makeLTOModule(buffer.take(), errMsg);
116 return makeLTOModule(buffer.take(), options, errMsg);
216117 }
217118
218119 LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length,
120 TargetOptions options,
219121 std::string &errMsg) {
220122 OwningPtr buffer(makeBuffer(mem, length));
221123 if (!buffer)
222124 return NULL;
223 return makeLTOModule(buffer.take(), errMsg);
224 }
225
226 void LTOModule::getTargetOptions(TargetOptions &Options) {
227 Options.LessPreciseFPMADOption = EnableFPMAD;
228 Options.NoFramePointerElim = DisableFPElim;
229 Options.AllowFPOpFusion = FuseFPOps;
230 Options.UnsafeFPMath = EnableUnsafeFPMath;
231 Options.NoInfsFPMath = EnableNoInfsFPMath;
232 Options.NoNaNsFPMath = EnableNoNaNsFPMath;
233 Options.HonorSignDependentRoundingFPMathOption =
234 EnableHonorSignDependentRoundingFPMath;
235 Options.UseSoftFloat = GenerateSoftFloatCalls;
236 if (FloatABIForCalls != FloatABI::Default)
237 Options.FloatABIType = FloatABIForCalls;
238 Options.NoZerosInBSS = DontPlaceZerosInBSS;
239 Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
240 Options.DisableTailCalls = DisableTailCalls;
241 Options.StackAlignmentOverride = OverrideStackAlignment;
242 Options.TrapFuncName = TrapFuncName;
243 Options.PositionIndependentExecutable = EnablePIE;
244 Options.EnableSegmentedStacks = SegmentedStacks;
245 Options.UseInitArray = UseInitArray;
125 return makeLTOModule(buffer.take(), options, errMsg);
246126 }
247127
248128 LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
129 TargetOptions options,
249130 std::string &errMsg) {
250131 // parse bitcode buffer
251132 OwningPtr m(getLazyBitcodeModule(buffer, getGlobalContext(),
277158 else if (Triple.getArch() == llvm::Triple::x86)
278159 CPU = "yonah";
279160 }
280 TargetOptions Options;
281 getTargetOptions(Options);
161
282162 TargetMachine *target = march->createTargetMachine(TripleStr, CPU, FeatureStr,
283 Options);
163 options);
284164 LTOModule *Ret = new LTOModule(m.take(), target);
285165 if (Ret->parseSymbols(errMsg)) {
286166 delete Ret;
1111 //
1212 //===----------------------------------------------------------------------===//
1313
14 #include "llvm/CodeGen/CommandFlags.h"
1415 #include "llvm/LTO/LTOCodeGenerator.h"
1516 #include "llvm/LTO/LTOModule.h"
1617 #include "llvm/Support/CommandLine.h"
2223
2324 using namespace llvm;
2425
25 static cl::list InputFilenames(cl::Positional, cl::OneOrMore,
26 cl::desc(""));
26 static cl::opt
27 DisableOpt("disable-opt", cl::init(false),
28 cl::desc("Do not run any optimization passes"));
2729
28 static cl::opt OutputFilename("o",
29 cl::desc("Override output filename"),
30 cl::init(""),
31 cl::value_desc("filename"));
30 static cl::opt
31 DisableInline("disable-inlining", cl::init(false),
32 cl::desc("Do not run the inliner pass"));
33
34 static cl::opt
35 DisableGVNLoadPRE("disable-gvn-loadpre", cl::init(false),
36 cl::desc("Do not run the GVN load PRE pass"));
37
38 static cl::list
39 InputFilenames(cl::Positional, cl::OneOrMore,
40 cl::desc(""));
41
42 static cl::opt
43 OutputFilename("o", cl::init(""),
44 cl::desc("Override output filename"),
45 cl::value_desc("filename"));
3246
3347 int main(int argc, char **argv) {
3448 // Print a stack trace if we signal out.
4458 InitializeAllAsmPrinters();
4559 InitializeAllAsmParsers();
4660
61 // set up the TargetOptions for the machine
62 TargetOptions Options;
63 Options.LessPreciseFPMADOption = EnableFPMAD;
64 Options.NoFramePointerElim = DisableFPElim;
65 Options.AllowFPOpFusion = FuseFPOps;
66 Options.UnsafeFPMath = EnableUnsafeFPMath;
67 Options.NoInfsFPMath = EnableNoInfsFPMath;
68 Options.NoNaNsFPMath = EnableNoNaNsFPMath;
69 Options.HonorSignDependentRoundingFPMathOption =
70 EnableHonorSignDependentRoundingFPMath;
71 Options.UseSoftFloat = GenerateSoftFloatCalls;
72 if (FloatABIForCalls != FloatABI::Default)
73 Options.FloatABIType = FloatABIForCalls;
74 Options.NoZerosInBSS = DontPlaceZerosInBSS;
75 Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
76 Options.DisableTailCalls = DisableTailCalls;
77 Options.StackAlignmentOverride = OverrideStackAlignment;
78 Options.TrapFuncName = TrapFuncName;
79 Options.PositionIndependentExecutable = EnablePIE;
80 Options.EnableSegmentedStacks = SegmentedStacks;
81 Options.UseInitArray = UseInitArray;
82
4783 unsigned BaseArg = 0;
4884 std::string ErrorMessage;
4985
5187
5288 CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC);
5389 CodeGen.setDebugInfo(LTO_DEBUG_MODEL_DWARF);
90 CodeGen.setTargetOptions(Options);
5491
5592 for (unsigned i = BaseArg; i < InputFilenames.size(); ++i) {
5693 std::string error;
5794 OwningPtr Module(LTOModule::makeLTOModule(InputFilenames[i].c_str(),
58 error));
95 Options, error));
5996 if (!error.empty()) {
6097 errs() << argv[0] << ": error loading file '" << InputFilenames[i]
6198 << "': " << error << "\n";
73110 if (!OutputFilename.empty()) {
74111 size_t len = 0;
75112 std::string ErrorInfo;
76 const void *Code = CodeGen.compile(&len, ErrorInfo);
113 const void *Code = CodeGen.compile(&len, DisableOpt, DisableInline,
114 DisableGVNLoadPRE, ErrorInfo);
77115 if (Code == NULL) {
78116 errs() << argv[0]
79117 << ": error compiling the code: " << ErrorInfo << "\n";
91129 } else {
92130 std::string ErrorInfo;
93131 const char *OutputName = NULL;
94 if (!CodeGen.compile_to_file(&OutputName, ErrorInfo)) {
132 if (!CodeGen.compile_to_file(&OutputName, DisableOpt, DisableInline,
133 DisableGVNLoadPRE, ErrorInfo)) {
95134 errs() << argv[0]
96135 << ": error compiling the code: " << ErrorInfo
97136 << "\n";
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "llvm-c/lto.h"
15 #include "llvm/CodeGen/CommandFlags.h"
1516 #include "llvm/LTO/LTOCodeGenerator.h"
1617 #include "llvm/LTO/LTOModule.h"
1718 #include "llvm-c/Core.h"
1819 #include "llvm-c/Target.h"
1920
21 // extra command-line flags needed for LTOCodeGenerator
22 static cl::opt
23 DisableOpt("disable-opt", cl::init(false),
24 cl::desc("Do not run any optimization passes"));
25
26 static cl::opt
27 DisableInline("disable-inlining", cl::init(false),
28 cl::desc("Do not run the inliner pass"));
29
30 static cl::opt
31 DisableGVNLoadPRE("disable-gvn-loadpre", cl::init(false),
32 cl::desc("Do not run the GVN load PRE pass"));
2033
2134 // Holds most recent error string.
2235 // *** Not thread safe ***
3952 }
4053 }
4154
55 static void lto_set_target_options(llvm::TargetOptions &Options) {
56 Options.LessPreciseFPMADOption = EnableFPMAD;
57 Options.NoFramePointerElim = DisableFPElim;
58 Options.AllowFPOpFusion = FuseFPOps;
59 Options.UnsafeFPMath = EnableUnsafeFPMath;
60 Options.NoInfsFPMath = EnableNoInfsFPMath;
61 Options.NoNaNsFPMath = EnableNoNaNsFPMath;
62 Options.HonorSignDependentRoundingFPMathOption =
63 EnableHonorSignDependentRoundingFPMath;
64 Options.UseSoftFloat = GenerateSoftFloatCalls;
65 if (FloatABIForCalls != llvm::FloatABI::Default)
66 Options.FloatABIType = FloatABIForCalls;
67 Options.NoZerosInBSS = DontPlaceZerosInBSS;
68 Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
69 Options.DisableTailCalls = DisableTailCalls;
70 Options.StackAlignmentOverride = OverrideStackAlignment;
71 Options.TrapFuncName = TrapFuncName;
72 Options.PositionIndependentExecutable = EnablePIE;
73 Options.EnableSegmentedStacks = SegmentedStacks;
74 Options.UseInitArray = UseInitArray;
75 }
76
4277 /// lto_get_version - Returns a printable string.
4378 extern const char* lto_get_version() {
4479 return LTOCodeGenerator::getVersionString();
81116 /// (check lto_get_error_message() for details).
82117 lto_module_t lto_module_create(const char* path) {
83118 lto_initialize();
84 return LTOModule::makeLTOModule(path, sLastErrorString);
119 llvm::TargetOptions Options;
120 lto_set_target_options(Options);
121 return LTOModule::makeLTOModule(path, Options, sLastErrorString);
85122 }
86123
87124 /// lto_module_create_from_fd - Loads an object file from disk. Returns NULL on
88125 /// error (check lto_get_error_message() for details).
89126 lto_module_t lto_module_create_from_fd(int fd, const char *path, size_t size) {
90127 lto_initialize();
91 return LTOModule::makeLTOModule(fd, path, size, sLastErrorString);
128 llvm::TargetOptions Options;
129 lto_set_target_options(Options);
130 return LTOModule::makeLTOModule(fd, path, size, Options, sLastErrorString);
92131 }
93132
94133 /// lto_module_create_from_fd_at_offset - Loads an object file from disk.
98137 size_t map_size,
99138 off_t offset) {
100139 lto_initialize();
101 return LTOModule::makeLTOModule(fd, path, map_size, offset, sLastErrorString);
140 llvm::TargetOptions Options;
141 lto_set_target_options(Options);
142 return LTOModule::makeLTOModule(fd, path, map_size, offset, Options,
143 sLastErrorString);
102144 }
103145
104146 /// lto_module_create_from_memory - Loads an object file from memory. Returns
105147 /// NULL on error (check lto_get_error_message() for details).
106148 lto_module_t lto_module_create_from_memory(const void* mem, size_t length) {
107149 lto_initialize();
108 return LTOModule::makeLTOModule(mem, length, sLastErrorString);
150 llvm::TargetOptions Options;
151 lto_set_target_options(Options);
152 return LTOModule::makeLTOModule(mem, length, Options, sLastErrorString);
109153 }
110154
111155 /// lto_module_dispose - Frees all memory for a module. Upon return the
149193 /// is an error.
150194 lto_code_gen_t lto_codegen_create(void) {
151195 lto_initialize();
152 return new LTOCodeGenerator();
196
197 TargetOptions Options;
198 lto_set_target_options(Options);
199
200 LTOCodeGenerator *CodeGen = new LTOCodeGenerator();
201 if (CodeGen)
202 CodeGen->setTargetOptions(Options);
203 return CodeGen;
153204 }
154205
155206 /// lto_codegen_dispose - Frees all memory for a code generator. Upon return the
219270 /// lto_codegen_compile() is called again. On failure, returns NULL (check
220271 /// lto_get_error_message() for details).
221272 const void *lto_codegen_compile(lto_code_gen_t cg, size_t *length) {
222 return cg->compile(length, sLastErrorString);
273 return cg->compile(length, DisableOpt, DisableInline, DisableGVNLoadPRE,
274 sLastErrorString);
223275 }
224276
225277 /// lto_codegen_compile_to_file - Generates code for all added modules into one
226278 /// native object file. The name of the file is written to name. Returns true on
227279 /// error.
228280 bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) {
229 return !cg->compile_to_file(name, sLastErrorString);
281 return !cg->compile_to_file(name, DisableOpt, DisableInline, DisableGVNLoadPRE,
282 sLastErrorString);
230283 }
231284
232285 /// lto_codegen_debug_options - Used to pass extra options to the code