Revert "Reapply "LTO: add API to set strategy for -internalize""
[oota-llvm.git] / tools / lto / lto.cpp
index a28257f6ab04f5189cc153f0d84890d79021926b..cc8318a8ba2e0735043c11f521194316e568b0a7 100644 (file)
@@ -56,28 +56,6 @@ static void lto_initialize() {
   }
 }
 
-static void lto_set_target_options(llvm::TargetOptions &Options) {
-  Options.LessPreciseFPMADOption = EnableFPMAD;
-  Options.NoFramePointerElim = DisableFPElim;
-  Options.AllowFPOpFusion = FuseFPOps;
-  Options.UnsafeFPMath = EnableUnsafeFPMath;
-  Options.NoInfsFPMath = EnableNoInfsFPMath;
-  Options.NoNaNsFPMath = EnableNoNaNsFPMath;
-  Options.HonorSignDependentRoundingFPMathOption =
-    EnableHonorSignDependentRoundingFPMath;
-  Options.UseSoftFloat = GenerateSoftFloatCalls;
-  if (FloatABIForCalls != llvm::FloatABI::Default)
-    Options.FloatABIType = FloatABIForCalls;
-  Options.NoZerosInBSS = DontPlaceZerosInBSS;
-  Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
-  Options.DisableTailCalls = DisableTailCalls;
-  Options.StackAlignmentOverride = OverrideStackAlignment;
-  Options.TrapFuncName = TrapFuncName;
-  Options.PositionIndependentExecutable = EnablePIE;
-  Options.EnableSegmentedStacks = SegmentedStacks;
-  Options.UseInitArray = UseInitArray;
-}
-
 /// lto_get_version - Returns a printable string.
 extern const char* lto_get_version() {
   return LTOCodeGenerator::getVersionString();
@@ -120,8 +98,7 @@ lto_module_is_object_file_in_memory_for_target(const void* mem,
 /// (check lto_get_error_message() for details).
 lto_module_t lto_module_create(const char* path) {
   lto_initialize();
-  llvm::TargetOptions Options;
-  lto_set_target_options(Options);
+  llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
   return LTOModule::makeLTOModule(path, Options, sLastErrorString);
 }
 
@@ -129,8 +106,7 @@ lto_module_t lto_module_create(const char* path) {
 /// error (check lto_get_error_message() for details).
 lto_module_t lto_module_create_from_fd(int fd, const char *path, size_t size) {
   lto_initialize();
-  llvm::TargetOptions Options;
-  lto_set_target_options(Options);
+  llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
   return LTOModule::makeLTOModule(fd, path, size, Options, sLastErrorString);
 }
 
@@ -141,8 +117,7 @@ lto_module_t lto_module_create_from_fd_at_offset(int fd, const char *path,
                                                  size_t map_size,
                                                  off_t offset) {
   lto_initialize();
-  llvm::TargetOptions Options;
-  lto_set_target_options(Options);
+  llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
   return LTOModule::makeLTOModule(fd, path, map_size, offset, Options,
                                   sLastErrorString);
 }
@@ -151,11 +126,20 @@ lto_module_t lto_module_create_from_fd_at_offset(int fd, const char *path,
 /// NULL on error (check lto_get_error_message() for details).
 lto_module_t lto_module_create_from_memory(const void* mem, size_t length) {
   lto_initialize();
-  llvm::TargetOptions Options;
-  lto_set_target_options(Options);
+  llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
   return LTOModule::makeLTOModule(mem, length, Options, sLastErrorString);
 }
 
+/// Loads an object file from memory with an extra path argument.
+/// Returns NULL on error (check lto_get_error_message() for details).
+lto_module_t lto_module_create_from_memory_with_path(const void* mem,
+                                                     size_t length,
+                                                     const char *path) {
+  lto_initialize();
+  llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
+  return LTOModule::makeLTOModule(mem, length, Options, sLastErrorString, path);
+}
+
 /// lto_module_dispose - Frees all memory for a module. Upon return the
 /// lto_module_t is no longer valid.
 void lto_module_dispose(lto_module_t mod) {
@@ -193,13 +177,41 @@ lto_symbol_attributes lto_module_get_symbol_attribute(lto_module_t mod,
   return mod->getSymbolAttributes(index);
 }
 
+/// lto_module_get_num_deplibs - Returns the number of dependent libraries in
+/// the object module.
+unsigned int lto_module_get_num_deplibs(lto_module_t mod) {
+  return mod->getDependentLibraryCount();
+}
+
+/// lto_module_get_deplib - Returns the ith dependent library in the module.
+const char* lto_module_get_deplib(lto_module_t mod, unsigned int index) {
+  return mod->getDependentLibrary(index);
+}
+
+/// lto_module_get_num_linkeropts - Returns the number of linker options in the
+/// object module.
+unsigned int lto_module_get_num_linkeropts(lto_module_t mod) {
+  return mod->getLinkerOptCount();
+}
+
+/// lto_module_get_linkeropt - Returns the ith linker option in the module.
+const char* lto_module_get_linkeropt(lto_module_t mod, unsigned int index) {
+  return mod->getLinkerOpt(index);
+}
+
+/// Set a diagnostic handler.
+void lto_codegen_set_diagnostic_handler(lto_code_gen_t cg,
+                                        lto_diagnostic_handler_t diag_handler,
+                                        void *ctxt) {
+  cg->setDiagnosticHandler(diag_handler, ctxt);
+}
+
 /// lto_codegen_create - Instantiates a code generator. Returns NULL if there
 /// is an error.
 lto_code_gen_t lto_codegen_create(void) {
   lto_initialize();
 
-  TargetOptions Options;
-  lto_set_target_options(Options);
+  TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
 
   LTOCodeGenerator *CodeGen = new LTOCodeGenerator();
   if (CodeGen)
@@ -252,13 +264,6 @@ void lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args,
   // In here only for backwards compatibility. We use MC now.
 }
 
-/// lto_codegen_set_internalize_strategy - Sets the strategy to use during
-/// internalize.
-void lto_codegen_set_internalize_strategy(lto_code_gen_t cg,
-                                          lto_internalize_strategy strategy) {
-  cg->setInternalizeStrategy(strategy);
-}
-
 /// lto_codegen_add_must_preserve_symbol - Adds to a list of all global symbols
 /// that must exist in the final generated code. If a function is not listed
 /// there, it might be inlined into every usage and optimized away.