diff options
| author | Timon Kruiper <timonkruiper@gmail.com> | 2019-07-01 15:22:57 +0200 |
|---|---|---|
| committer | Timon Kruiper <timonkruiper@gmail.com> | 2019-07-02 19:54:29 +0200 |
| commit | bbc0d440b86a1783c1fddc5e594f9b4067016489 (patch) | |
| tree | 6669783a72d03a9818e581a1896bd455ef3251d6 /src/zig_llvm.cpp | |
| parent | 7586f613d58db8f210649c890c467edce11643b9 (diff) | |
| download | zig-bbc0d440b86a1783c1fddc5e594f9b4067016489.tar.gz zig-bbc0d440b86a1783c1fddc5e594f9b4067016489.zip | |
Added ZigLLVMCreateTargetMachine and pass function-sections flag
Also added extra cache line
Added the ZigLVVMCreateTargetMachine to self hosted zig code
Diffstat (limited to 'src/zig_llvm.cpp')
| -rw-r--r-- | src/zig_llvm.cpp | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp index bd118d936b..f8d2ccce7e 100644 --- a/src/zig_llvm.cpp +++ b/src/zig_llvm.cpp @@ -39,7 +39,9 @@ #include <llvm/Support/TargetParser.h> #include <llvm/Support/Timer.h> #include <llvm/Support/raw_ostream.h> +#include <llvm/Support/TargetRegistry.h> #include <llvm/Target/TargetMachine.h> +#include <llvm/Target/CodeGenCWrappers.h> #include <llvm/Transforms/Coroutines.h> #include <llvm/Transforms/IPO.h> #include <llvm/Transforms/IPO/AlwaysInliner.h> @@ -93,9 +95,63 @@ static const bool assertions_on = true; static const bool assertions_on = false; #endif +LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple, + const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, + LLVMCodeModel CodeModel, bool function_sections) +{ + Optional<Reloc::Model> RM; + switch (Reloc){ + case LLVMRelocStatic: + RM = Reloc::Static; + break; + case LLVMRelocPIC: + RM = Reloc::PIC_; + break; + case LLVMRelocDynamicNoPic: + RM = Reloc::DynamicNoPIC; + break; + case LLVMRelocROPI: + RM = Reloc::ROPI; + break; + case LLVMRelocRWPI: + RM = Reloc::RWPI; + break; + case LLVMRelocROPI_RWPI: + RM = Reloc::ROPI_RWPI; + break; + default: + break; + } + + bool JIT; + Optional<CodeModel::Model> CM = unwrap(CodeModel, JIT); + + CodeGenOpt::Level OL; + switch (Level) { + case LLVMCodeGenLevelNone: + OL = CodeGenOpt::None; + break; + case LLVMCodeGenLevelLess: + OL = CodeGenOpt::Less; + break; + case LLVMCodeGenLevelAggressive: + OL = CodeGenOpt::Aggressive; + break; + default: + OL = CodeGenOpt::Default; + break; + } + + TargetOptions opt; + opt.FunctionSections = function_sections; + + return reinterpret_cast<LLVMTargetMachineRef>(const_cast<TargetMachine *>( + reinterpret_cast<Target*>(T)->createTargetMachine(Triple, CPU, Features, opt, RM, CM, OL, JIT))); +} + bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref, const char *filename, ZigLLVM_EmitOutputType output_type, char **error_message, bool is_debug, - bool is_small, bool time_report, bool function_sections) + bool is_small, bool time_report) { TimePassesIsEnabled = time_report; @@ -108,8 +164,6 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM TargetMachine* target_machine = reinterpret_cast<TargetMachine*>(targ_machine_ref); target_machine->setO0WantsFastISel(true); - target_machine->Options.FunctionSections = function_sections; - Module* module = unwrap(module_ref); PassManagerBuilder *PMBuilder = new(std::nothrow) PassManagerBuilder(); |
