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) {
84368436 // pipeline multiple times if this is requested.
84378437 if (asm_filename != nullptr && bin_filename != nullptr) {
84388438 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))
84408440 {
84418441 fprintf(stderr, "LLVM failed to emit file: %s\n", err_msg);
84428442 exit(1);
......@@ -8446,7 +8446,7 @@ static void zig_llvm_emit_output(CodeGen *g) {
84468446 }
84478447
84488448 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))
84508450 {
84518451 fprintf(stderr, "LLVM failed to emit file: %s\n", err_msg);
84528452 exit(1);
src/zig_llvm.cpp+11-1
......@@ -50,6 +50,7 @@
5050#include <llvm/Transforms/IPO.h>
5151#include <llvm/Transforms/IPO/AlwaysInliner.h>
5252#include <llvm/Transforms/IPO/PassManagerBuilder.h>
53#include <llvm/Transforms/Instrumentation/ThreadSanitizer.h>
5354#include <llvm/Transforms/Scalar.h>
5455#include <llvm/Transforms/Utils.h>
5556
......@@ -93,6 +94,10 @@ static void addDiscriminatorsPass(const PassManagerBuilder &Builder, legacy::Pas
9394 PM.add(createAddDiscriminatorsPass());
9495}
9596
97static void addThreadSanitizerPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) {
98 PM.add(createThreadSanitizerLegacyPassPass());
99}
100
96101#ifndef NDEBUG
97102static const bool assertions_on = true;
98103#else
......@@ -179,7 +184,7 @@ unsigned ZigLLVMDataLayoutGetProgramAddressSpace(LLVMTargetDataRef TD) {
179184
180185bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,
181186 char **error_message, bool is_debug,
182 bool is_small, bool time_report,
187 bool is_small, bool time_report, bool tsan,
183188 const char *asm_filename, const char *bin_filename, const char *llvm_ir_filename)
184189{
185190 TimePassesIsEnabled = time_report;
......@@ -245,6 +250,11 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
245250 PMBuilder->Inliner = createFunctionInliningPass(PMBuilder->OptLevel, PMBuilder->SizeLevel, false);
246251 }
247252
253 if (tsan) {
254 PMBuilder->addExtension(PassManagerBuilder::EP_OptimizerLast, addThreadSanitizerPass);
255 PMBuilder->addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0, addThreadSanitizerPass);
256 }
257
248258 // Set up the per-function pass manager.
249259 legacy::FunctionPassManager FPM = legacy::FunctionPassManager(module);
250260 auto tliwp = new(std::nothrow) TargetLibraryInfoWrapperPass(tlii);
src/zig_llvm.h+1-1
......@@ -48,7 +48,7 @@ ZIG_EXTERN_C char *ZigLLVMGetNativeFeatures(void);
4848
4949ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,
5050 char **error_message, bool is_debug,
51 bool is_small, bool time_report,
51 bool is_small, bool time_report, bool tsan,
5252 const char *asm_filename, const char *bin_filename, const char *llvm_ir_filename);
5353
5454