authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-22 22:00:58-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-24 01:18:48-07:00
log4d8c5dd4be7a84c5f01f8910c44c5a1e23740b77
treef88b867af7671eb20b942a04cce928dc57352872
parenta4b134746f61a2f07ea5450c0504f51cba8f6be3

stage1: add tsan LLVM passes when appropriate


3 files changed, 14 insertions(+), 4 deletions(-)

src/stage1/codegen.cpp+2-2
...@@ -8436,7 +8436,7 @@ static void zig_llvm_emit_output(CodeGen *g) {...@@ -8436,7 +8436,7 @@ static void zig_llvm_emit_output(CodeGen *g) {
8436 // pipeline multiple times if this is requested.8436 // pipeline multiple times if this is requested.
8437 if (asm_filename != nullptr && bin_filename != nullptr) {8437 if (asm_filename != nullptr && bin_filename != nullptr) {
8438 if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, &err_msg, g->build_mode == BuildModeDebug,8438 if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, &err_msg, g->build_mode == BuildModeDebug,
8439 is_small, g->enable_time_report, nullptr, bin_filename, llvm_ir_filename))8439 is_small, g->enable_time_report, g->tsan_enabled, nullptr, bin_filename, llvm_ir_filename))
8440 {8440 {
8441 fprintf(stderr, "LLVM failed to emit file: %s\n", err_msg);8441 fprintf(stderr, "LLVM failed to emit file: %s\n", err_msg);
8442 exit(1);8442 exit(1);
...@@ -8446,7 +8446,7 @@ static void zig_llvm_emit_output(CodeGen *g) {...@@ -8446,7 +8446,7 @@ static void zig_llvm_emit_output(CodeGen *g) {
8446 }8446 }
84478447
8448 if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, &err_msg, g->build_mode == BuildModeDebug,8448 if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, &err_msg, g->build_mode == BuildModeDebug,
8449 is_small, g->enable_time_report, asm_filename, bin_filename, llvm_ir_filename))8449 is_small, g->enable_time_report, g->tsan_enabled, asm_filename, bin_filename, llvm_ir_filename))
8450 {8450 {
8451 fprintf(stderr, "LLVM failed to emit file: %s\n", err_msg);8451 fprintf(stderr, "LLVM failed to emit file: %s\n", err_msg);
8452 exit(1);8452 exit(1);
src/zig_llvm.cpp+11-1
...@@ -50,6 +50,7 @@...@@ -50,6 +50,7 @@
50#include <llvm/Transforms/IPO.h>50#include <llvm/Transforms/IPO.h>
51#include <llvm/Transforms/IPO/AlwaysInliner.h>51#include <llvm/Transforms/IPO/AlwaysInliner.h>
52#include <llvm/Transforms/IPO/PassManagerBuilder.h>52#include <llvm/Transforms/IPO/PassManagerBuilder.h>
53#include <llvm/Transforms/Instrumentation/ThreadSanitizer.h>
53#include <llvm/Transforms/Scalar.h>54#include <llvm/Transforms/Scalar.h>
54#include <llvm/Transforms/Utils.h>55#include <llvm/Transforms/Utils.h>
5556
...@@ -93,6 +94,10 @@ static void addDiscriminatorsPass(const PassManagerBuilder &Builder, legacy::Pas...@@ -93,6 +94,10 @@ static void addDiscriminatorsPass(const PassManagerBuilder &Builder, legacy::Pas
93 PM.add(createAddDiscriminatorsPass());94 PM.add(createAddDiscriminatorsPass());
94}95}
9596
97static void addThreadSanitizerPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) {
98 PM.add(createThreadSanitizerLegacyPassPass());
99}
100
96#ifndef NDEBUG101#ifndef NDEBUG
97static const bool assertions_on = true;102static const bool assertions_on = true;
98#else103#else
...@@ -179,7 +184,7 @@ unsigned ZigLLVMDataLayoutGetProgramAddressSpace(LLVMTargetDataRef TD) {...@@ -179,7 +184,7 @@ unsigned ZigLLVMDataLayoutGetProgramAddressSpace(LLVMTargetDataRef TD) {
179184
180bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,185bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,
181 char **error_message, bool is_debug,186 char **error_message, bool is_debug,
182 bool is_small, bool time_report,187 bool is_small, bool time_report, bool tsan,
183 const char *asm_filename, const char *bin_filename, const char *llvm_ir_filename)188 const char *asm_filename, const char *bin_filename, const char *llvm_ir_filename)
184{189{
185 TimePassesIsEnabled = time_report;190 TimePassesIsEnabled = time_report;
...@@ -245,6 +250,11 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM...@@ -245,6 +250,11 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
245 PMBuilder->Inliner = createFunctionInliningPass(PMBuilder->OptLevel, PMBuilder->SizeLevel, false);250 PMBuilder->Inliner = createFunctionInliningPass(PMBuilder->OptLevel, PMBuilder->SizeLevel, false);
246 }251 }
247252
253 if (tsan) {
254 PMBuilder->addExtension(PassManagerBuilder::EP_OptimizerLast, addThreadSanitizerPass);
255 PMBuilder->addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0, addThreadSanitizerPass);
256 }
257
248 // Set up the per-function pass manager.258 // Set up the per-function pass manager.
249 legacy::FunctionPassManager FPM = legacy::FunctionPassManager(module);259 legacy::FunctionPassManager FPM = legacy::FunctionPassManager(module);
250 auto tliwp = new(std::nothrow) TargetLibraryInfoWrapperPass(tlii);260 auto tliwp = new(std::nothrow) TargetLibraryInfoWrapperPass(tlii);
src/zig_llvm.h+1-1
...@@ -48,7 +48,7 @@ ZIG_EXTERN_C char *ZigLLVMGetNativeFeatures(void);...@@ -48,7 +48,7 @@ ZIG_EXTERN_C char *ZigLLVMGetNativeFeatures(void);
4848
49ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,49ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,
50 char **error_message, bool is_debug,50 char **error_message, bool is_debug,
51 bool is_small, bool time_report,51 bool is_small, bool time_report, bool tsan,
52 const char *asm_filename, const char *bin_filename, const char *llvm_ir_filename);52 const char *asm_filename, const char *bin_filename, const char *llvm_ir_filename);
5353
5454