- if (!parsedOptions) {
- unwrap(cg)->parseCodeGenDebugOptions();
- lto_add_attrs(cg);
- parsedOptions = true;
- }
- return unwrap(cg)->compile(length, DisableOpt, DisableInline,
- DisableGVNLoadPRE, DisableLTOVectorization,
- sLastErrorString);
+ maybeParseOptions(cg);
+ LibLTOCodeGenerator *CG = unwrap(cg);
+ CG->NativeObjectFile = CG->compile(DisableInline, DisableGVNLoadPRE,
+ DisableLTOVectorization, sLastErrorString);
+ if (!CG->NativeObjectFile)
+ return nullptr;
+ *length = CG->NativeObjectFile->getBufferSize();
+ return CG->NativeObjectFile->getBufferStart();
+}
+
+bool lto_codegen_optimize(lto_code_gen_t cg) {
+ maybeParseOptions(cg);
+ return !unwrap(cg)->optimize(DisableInline,
+ DisableGVNLoadPRE, DisableLTOVectorization,
+ sLastErrorString);
+}
+
+const void *lto_codegen_compile_optimized(lto_code_gen_t cg, size_t *length) {
+ maybeParseOptions(cg);
+ LibLTOCodeGenerator *CG = unwrap(cg);
+ CG->NativeObjectFile = CG->compileOptimized(sLastErrorString);
+ if (!CG->NativeObjectFile)
+ return nullptr;
+ *length = CG->NativeObjectFile->getBufferSize();
+ return CG->NativeObjectFile->getBufferStart();