X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Flto%2Flto.cpp;h=ec0372ea56076e626f198f6c5162fde6b6a6cad2;hb=acc1d12b7cb7d697d9b4080a7ec7569fc3e8c615;hp=86e1e810e8d64dcf81e9c532d7a0663770926817;hpb=01ccb9c9b8544aaf8076672abde4984e6ea56036;p=oota-llvm.git diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp index 86e1e810e8d..ec0372ea560 100644 --- a/tools/lto/lto.cpp +++ b/tools/lto/lto.cpp @@ -13,11 +13,11 @@ //===----------------------------------------------------------------------===// #include "llvm-c/lto.h" -#include "llvm-c/Core.h" -#include "llvm-c/Target.h" #include "llvm/CodeGen/CommandFlags.h" +#include "llvm/IR/LLVMContext.h" #include "llvm/LTO/LTOCodeGenerator.h" #include "llvm/LTO/LTOModule.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/TargetSelect.h" // extra command-line flags needed for LTOCodeGenerator @@ -33,6 +33,10 @@ static cl::opt DisableGVNLoadPRE("disable-gvn-loadpre", cl::init(false), cl::desc("Do not run the GVN load PRE pass")); +static cl::opt +DisableLTOVectorization("disable-lto-vectorization", cl::init(false), + cl::desc("Do not run loop or slp vectorization during LTO")); + // Holds most recent error string. // *** Not thread safe *** static std::string sLastErrorString; @@ -89,7 +93,10 @@ bool lto_module_is_object_file(const char* path) { bool lto_module_is_object_file_for_target(const char* path, const char* target_triplet_prefix) { - return LTOModule::isBitcodeFileForTarget(path, target_triplet_prefix); + ErrorOr> Buffer = MemoryBuffer::getFile(path); + if (!Buffer) + return false; + return LTOModule::isBitcodeForTarget(Buffer->get(), target_triplet_prefix); } bool lto_module_is_object_file_in_memory(const void* mem, size_t length) { @@ -100,20 +107,23 @@ bool lto_module_is_object_file_in_memory_for_target(const void* mem, size_t length, const char* target_triplet_prefix) { - return LTOModule::isBitcodeFileForTarget(mem, length, target_triplet_prefix); + std::unique_ptr buffer(LTOModule::makeBuffer(mem, length)); + if (!buffer) + return false; + return LTOModule::isBitcodeForTarget(buffer.get(), target_triplet_prefix); } lto_module_t lto_module_create(const char* path) { lto_initialize(); llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); - return wrap(LTOModule::makeLTOModule(path, Options, sLastErrorString)); + return wrap(LTOModule::createFromFile(path, Options, sLastErrorString)); } lto_module_t lto_module_create_from_fd(int fd, const char *path, size_t size) { lto_initialize(); llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); return wrap( - LTOModule::makeLTOModule(fd, path, size, Options, sLastErrorString)); + LTOModule::createFromOpenFile(fd, path, size, Options, sLastErrorString)); } lto_module_t lto_module_create_from_fd_at_offset(int fd, const char *path, @@ -122,14 +132,14 @@ lto_module_t lto_module_create_from_fd_at_offset(int fd, const char *path, off_t offset) { lto_initialize(); llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); - return wrap(LTOModule::makeLTOModule(fd, path, map_size, offset, Options, - sLastErrorString)); + return wrap(LTOModule::createFromOpenFileSlice(fd, path, map_size, offset, + Options, sLastErrorString)); } lto_module_t lto_module_create_from_memory(const void* mem, size_t length) { lto_initialize(); llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); - return wrap(LTOModule::makeLTOModule(mem, length, Options, sLastErrorString)); + return wrap(LTOModule::createFromBuffer(mem, length, Options, sLastErrorString)); } lto_module_t lto_module_create_from_memory_with_path(const void* mem, @@ -138,13 +148,31 @@ lto_module_t lto_module_create_from_memory_with_path(const void* mem, lto_initialize(); llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); return wrap( - LTOModule::makeLTOModule(mem, length, Options, sLastErrorString, path)); + LTOModule::createFromBuffer(mem, length, Options, sLastErrorString, path)); +} + +lto_module_t lto_module_create_in_local_context(const void *mem, size_t length, + const char *path) { + lto_initialize(); + llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); + return wrap(LTOModule::createInLocalContext(mem, length, Options, + sLastErrorString, path)); +} + +lto_module_t lto_module_create_in_codegen_context(const void *mem, + size_t length, + const char *path, + lto_code_gen_t cg) { + lto_initialize(); + llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); + return wrap(LTOModule::createInContext(mem, length, Options, sLastErrorString, + path, &unwrap(cg)->getContext())); } void lto_module_dispose(lto_module_t mod) { delete unwrap(mod); } const char* lto_module_get_target_triple(lto_module_t mod) { - return unwrap(mod)->getTargetTriple(); + return unwrap(mod)->getTargetTriple().c_str(); } void lto_module_set_target_triple(lto_module_t mod, const char *triple) { @@ -186,21 +214,31 @@ void lto_codegen_set_diagnostic_handler(lto_code_gen_t cg, unwrap(cg)->setDiagnosticHandler(diag_handler, ctxt); } -lto_code_gen_t lto_codegen_create(void) { +static lto_code_gen_t createCodeGen(bool InLocalContext) { lto_initialize(); TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); - LTOCodeGenerator *CodeGen = new LTOCodeGenerator(); + LTOCodeGenerator *CodeGen = + InLocalContext ? new LTOCodeGenerator(make_unique()) + : new LTOCodeGenerator(); if (CodeGen) CodeGen->setTargetOptions(Options); return wrap(CodeGen); } +lto_code_gen_t lto_codegen_create(void) { + return createCodeGen(/* InLocalContext */ false); +} + +lto_code_gen_t lto_codegen_create_in_local_context(void) { + return createCodeGen(/* InLocalContext */ true); +} + void lto_codegen_dispose(lto_code_gen_t cg) { delete unwrap(cg); } bool lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod) { - return !unwrap(cg)->addModule(unwrap(mod), sLastErrorString); + return !unwrap(cg)->addModule(unwrap(mod)); } bool lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model debug) { @@ -217,10 +255,6 @@ void lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu) { return unwrap(cg)->setCpu(cpu); } -void lto_codegen_set_attr(lto_code_gen_t cg, const char *attr) { - return unwrap(cg)->setAttr(attr); -} - void lto_codegen_set_assembler_path(lto_code_gen_t cg, const char *path) { // In here only for backwards compatibility. We use MC now. } @@ -251,7 +285,8 @@ const void *lto_codegen_compile(lto_code_gen_t cg, size_t *length) { parsedOptions = true; } return unwrap(cg)->compile(length, DisableOpt, DisableInline, - DisableGVNLoadPRE, sLastErrorString); + DisableGVNLoadPRE, DisableLTOVectorization, + sLastErrorString); } bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) { @@ -260,8 +295,9 @@ bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) { lto_add_attrs(cg); parsedOptions = true; } - return !unwrap(cg)->compile_to_file(name, DisableOpt, DisableInline, - DisableGVNLoadPRE, sLastErrorString); + return !unwrap(cg)->compile_to_file( + name, DisableOpt, DisableInline, DisableGVNLoadPRE, + DisableLTOVectorization, sLastErrorString); } void lto_codegen_debug_options(lto_code_gen_t cg, const char *opt) {