| author | |
| committer | |
| log | bbc0d440b86a1783c1fddc5e594f9b4067016489 |
| tree | 6669783a72d03a9818e581a1896bd455ef3251d6 |
| parent | 7586f613d58db8f210649c890c467edce11643b9 |
Also added extra cache line
Added the ZigLVVMCreateTargetMachine to self hosted zig code5 files changed, 73 insertions(+), 12 deletions(-)
src-self-hosted/compilation.zig+1| ... | ... | @@ -516,6 +516,7 @@ pub const Compilation = struct { |
| 516 | 516 | opt_level, |
| 517 | 517 | reloc_mode, |
| 518 | 518 | llvm.CodeModelDefault, |
| 519 | false // TODO: add -ffunction-sections option | |
| 519 | 520 | ) orelse return error.OutOfMemory; |
| 520 | 521 | defer llvm.DisposeTargetMachine(comp.target_machine); |
| 521 | 522 |
src-self-hosted/llvm.zig+3-3| ... | ... | @@ -163,8 +163,8 @@ extern fn LLVMCopyStringRepOfTargetData(TD: *TargetData) ?[*]u8; |
| 163 | 163 | pub const CreateTargetDataLayout = LLVMCreateTargetDataLayout; |
| 164 | 164 | extern fn LLVMCreateTargetDataLayout(T: *TargetMachine) ?*TargetData; |
| 165 | 165 | |
| 166 | pub const CreateTargetMachine = LLVMCreateTargetMachine; | |
| 167 | extern fn LLVMCreateTargetMachine( | |
| 166 | pub const CreateTargetMachine = ZigLLVMCreateTargetMachine; | |
| 167 | extern fn ZigLLVMCreateTargetMachine( | |
| 168 | 168 | T: *Target, |
| 169 | 169 | Triple: [*]const u8, |
| 170 | 170 | CPU: [*]const u8, |
| ... | ... | @@ -172,6 +172,7 @@ extern fn LLVMCreateTargetMachine( |
| 172 | 172 | Level: CodeGenOptLevel, |
| 173 | 173 | Reloc: RelocMode, |
| 174 | 174 | CodeModel: CodeModel, |
| 175 | function_sections: bool, | |
| 175 | 176 | ) ?*TargetMachine; |
| 176 | 177 | |
| 177 | 178 | pub const GetHostCPUName = LLVMGetHostCPUName; |
| ... | ... | @@ -283,7 +284,6 @@ extern fn ZigLLVMTargetMachineEmitToFile( |
| 283 | 284 | error_message: *[*]u8, |
| 284 | 285 | is_debug: bool, |
| 285 | 286 | is_small: bool, |
| 286 | function_sections: bool, | |
| 287 | 287 | ) bool; |
| 288 | 288 | |
| 289 | 289 | pub const BuildCall = ZigLLVMBuildCall; |
src/codegen.cpp+7-5| ... | ... | @@ -7042,7 +7042,7 @@ static void zig_llvm_emit_output(CodeGen *g) { |
| 7042 | 7042 | case EmitFileTypeBinary: |
| 7043 | 7043 | if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path), |
| 7044 | 7044 | ZigLLVM_EmitBinary, &err_msg, g->build_mode == BuildModeDebug, is_small, |
| 7045 | g->enable_time_report, g->function_sections)) | |
| 7045 | g->enable_time_report)) | |
| 7046 | 7046 | { |
| 7047 | 7047 | zig_panic("unable to write object file %s: %s", buf_ptr(output_path), err_msg); |
| 7048 | 7048 | } |
| ... | ... | @@ -7058,7 +7058,7 @@ static void zig_llvm_emit_output(CodeGen *g) { |
| 7058 | 7058 | case EmitFileTypeAssembly: |
| 7059 | 7059 | if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path), |
| 7060 | 7060 | ZigLLVM_EmitAssembly, &err_msg, g->build_mode == BuildModeDebug, is_small, |
| 7061 | g->enable_time_report, g->function_sections)) | |
| 7061 | g->enable_time_report)) | |
| 7062 | 7062 | { |
| 7063 | 7063 | zig_panic("unable to write assembly file %s: %s", buf_ptr(output_path), err_msg); |
| 7064 | 7064 | } |
| ... | ... | @@ -7068,7 +7068,7 @@ static void zig_llvm_emit_output(CodeGen *g) { |
| 7068 | 7068 | case EmitFileTypeLLVMIr: |
| 7069 | 7069 | if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path), |
| 7070 | 7070 | ZigLLVM_EmitLLVMIr, &err_msg, g->build_mode == BuildModeDebug, is_small, |
| 7071 | g->enable_time_report, g->function_sections)) | |
| 7071 | g->enable_time_report)) | |
| 7072 | 7072 | { |
| 7073 | 7073 | zig_panic("unable to write llvm-ir file %s: %s", buf_ptr(output_path), err_msg); |
| 7074 | 7074 | } |
| ... | ... | @@ -8130,8 +8130,9 @@ static void init(CodeGen *g) { |
| 8130 | 8130 | target_specific_features = ""; |
| 8131 | 8131 | } |
| 8132 | 8132 | |
| 8133 | g->target_machine = LLVMCreateTargetMachine(target_ref, buf_ptr(&g->triple_str), | |
| 8134 | target_specific_cpu_args, target_specific_features, opt_level, reloc_mode, LLVMCodeModelDefault); | |
| 8133 | g->target_machine = ZigLLVMCreateTargetMachine(target_ref, buf_ptr(&g->triple_str), | |
| 8134 | target_specific_cpu_args, target_specific_features, opt_level, reloc_mode, | |
| 8135 | LLVMCodeModelDefault, g->function_sections); | |
| 8135 | 8136 | |
| 8136 | 8137 | g->target_data_ref = LLVMCreateTargetDataLayout(g->target_machine); |
| 8137 | 8138 | |
| ... | ... | @@ -9448,6 +9449,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) { |
| 9448 | 9449 | cache_bool(ch, g->have_dynamic_link); |
| 9449 | 9450 | cache_bool(ch, g->have_stack_probing); |
| 9450 | 9451 | cache_bool(ch, g->is_dummy_so); |
| 9452 | cache_bool(ch, g->function_sections); | |
| 9451 | 9453 | cache_buf_opt(ch, g->mmacosx_version_min); |
| 9452 | 9454 | cache_buf_opt(ch, g->mios_version_min); |
| 9453 | 9455 | cache_usize(ch, g->version_major); |
src/zig_llvm.cpp+57-3| ... | ... | @@ -39,7 +39,9 @@ |
| 39 | 39 | #include <llvm/Support/TargetParser.h> |
| 40 | 40 | #include <llvm/Support/Timer.h> |
| 41 | 41 | #include <llvm/Support/raw_ostream.h> |
| 42 | #include <llvm/Support/TargetRegistry.h> | |
| 42 | 43 | #include <llvm/Target/TargetMachine.h> |
| 44 | #include <llvm/Target/CodeGenCWrappers.h> | |
| 43 | 45 | #include <llvm/Transforms/Coroutines.h> |
| 44 | 46 | #include <llvm/Transforms/IPO.h> |
| 45 | 47 | #include <llvm/Transforms/IPO/AlwaysInliner.h> |
| ... | ... | @@ -93,9 +95,63 @@ static const bool assertions_on = true; |
| 93 | 95 | static const bool assertions_on = false; |
| 94 | 96 | #endif |
| 95 | 97 | |
| 98 | LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple, | |
| 99 | const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, | |
| 100 | LLVMCodeModel CodeModel, bool function_sections) | |
| 101 | { | |
| 102 | Optional<Reloc::Model> RM; | |
| 103 | switch (Reloc){ | |
| 104 | case LLVMRelocStatic: | |
| 105 | RM = Reloc::Static; | |
| 106 | break; | |
| 107 | case LLVMRelocPIC: | |
| 108 | RM = Reloc::PIC_; | |
| 109 | break; | |
| 110 | case LLVMRelocDynamicNoPic: | |
| 111 | RM = Reloc::DynamicNoPIC; | |
| 112 | break; | |
| 113 | case LLVMRelocROPI: | |
| 114 | RM = Reloc::ROPI; | |
| 115 | break; | |
| 116 | case LLVMRelocRWPI: | |
| 117 | RM = Reloc::RWPI; | |
| 118 | break; | |
| 119 | case LLVMRelocROPI_RWPI: | |
| 120 | RM = Reloc::ROPI_RWPI; | |
| 121 | break; | |
| 122 | default: | |
| 123 | break; | |
| 124 | } | |
| 125 | ||
| 126 | bool JIT; | |
| 127 | Optional<CodeModel::Model> CM = unwrap(CodeModel, JIT); | |
| 128 | ||
| 129 | CodeGenOpt::Level OL; | |
| 130 | switch (Level) { | |
| 131 | case LLVMCodeGenLevelNone: | |
| 132 | OL = CodeGenOpt::None; | |
| 133 | break; | |
| 134 | case LLVMCodeGenLevelLess: | |
| 135 | OL = CodeGenOpt::Less; | |
| 136 | break; | |
| 137 | case LLVMCodeGenLevelAggressive: | |
| 138 | OL = CodeGenOpt::Aggressive; | |
| 139 | break; | |
| 140 | default: | |
| 141 | OL = CodeGenOpt::Default; | |
| 142 | break; | |
| 143 | } | |
| 144 | ||
| 145 | TargetOptions opt; | |
| 146 | opt.FunctionSections = function_sections; | |
| 147 | ||
| 148 | return reinterpret_cast<LLVMTargetMachineRef>(const_cast<TargetMachine *>( | |
| 149 | reinterpret_cast<Target*>(T)->createTargetMachine(Triple, CPU, Features, opt, RM, CM, OL, JIT))); | |
| 150 | } | |
| 151 | ||
| 96 | 152 | bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref, |
| 97 | 153 | const char *filename, ZigLLVM_EmitOutputType output_type, char **error_message, bool is_debug, |
| 98 | bool is_small, bool time_report, bool function_sections) | |
| 154 | bool is_small, bool time_report) | |
| 99 | 155 | { |
| 100 | 156 | TimePassesIsEnabled = time_report; |
| 101 | 157 | |
| ... | ... | @@ -108,8 +164,6 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM |
| 108 | 164 | TargetMachine* target_machine = reinterpret_cast<TargetMachine*>(targ_machine_ref); |
| 109 | 165 | target_machine->setO0WantsFastISel(true); |
| 110 | 166 | |
| 111 | target_machine->Options.FunctionSections = function_sections; | |
| 112 | ||
| 113 | 167 | Module* module = unwrap(module_ref); |
| 114 | 168 | |
| 115 | 169 | PassManagerBuilder *PMBuilder = new(std::nothrow) PassManagerBuilder(); |
src/zig_llvm.h+5-1| ... | ... | @@ -56,7 +56,11 @@ enum ZigLLVM_EmitOutputType { |
| 56 | 56 | |
| 57 | 57 | ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref, |
| 58 | 58 | const char *filename, enum ZigLLVM_EmitOutputType output_type, char **error_message, bool is_debug, |
| 59 | bool is_small, bool time_report, bool function_sections); | |
| 59 | bool is_small, bool time_report); | |
| 60 | ||
| 61 | ZIG_EXTERN_C LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple, | |
| 62 | const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, | |
| 63 | LLVMCodeModel CodeModel, bool function_sections); | |
| 60 | 64 | |
| 61 | 65 | ZIG_EXTERN_C LLVMTypeRef ZigLLVMTokenTypeInContext(LLVMContextRef context_ref); |
| 62 | 66 |