stage1: add tsan LLVM passes when appropriate

This commit is contained in:
Andrew Kelley
2020-12-22 22:00:58 -07:00
parent a4b134746f
commit 4d8c5dd4be
3 changed files with 14 additions and 4 deletions

View File

@@ -8436,7 +8436,7 @@ static void zig_llvm_emit_output(CodeGen *g) {
// pipeline multiple times if this is requested.
if (asm_filename != nullptr && bin_filename != nullptr) {
if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, &err_msg, g->build_mode == BuildModeDebug,
is_small, g->enable_time_report, nullptr, bin_filename, llvm_ir_filename))
is_small, g->enable_time_report, g->tsan_enabled, nullptr, bin_filename, llvm_ir_filename))
{
fprintf(stderr, "LLVM failed to emit file: %s\n", err_msg);
exit(1);
@@ -8446,7 +8446,7 @@ static void zig_llvm_emit_output(CodeGen *g) {
}
if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, &err_msg, g->build_mode == BuildModeDebug,
is_small, g->enable_time_report, asm_filename, bin_filename, llvm_ir_filename))
is_small, g->enable_time_report, g->tsan_enabled, asm_filename, bin_filename, llvm_ir_filename))
{
fprintf(stderr, "LLVM failed to emit file: %s\n", err_msg);
exit(1);

View File

@@ -50,6 +50,7 @@
#include <llvm/Transforms/IPO.h>
#include <llvm/Transforms/IPO/AlwaysInliner.h>
#include <llvm/Transforms/IPO/PassManagerBuilder.h>
#include <llvm/Transforms/Instrumentation/ThreadSanitizer.h>
#include <llvm/Transforms/Scalar.h>
#include <llvm/Transforms/Utils.h>
@@ -93,6 +94,10 @@ static void addDiscriminatorsPass(const PassManagerBuilder &Builder, legacy::Pas
PM.add(createAddDiscriminatorsPass());
}
static void addThreadSanitizerPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) {
PM.add(createThreadSanitizerLegacyPassPass());
}
#ifndef NDEBUG
static const bool assertions_on = true;
#else
@@ -179,7 +184,7 @@ unsigned ZigLLVMDataLayoutGetProgramAddressSpace(LLVMTargetDataRef TD) {
bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,
char **error_message, bool is_debug,
bool is_small, bool time_report,
bool is_small, bool time_report, bool tsan,
const char *asm_filename, const char *bin_filename, const char *llvm_ir_filename)
{
TimePassesIsEnabled = time_report;
@@ -245,6 +250,11 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
PMBuilder->Inliner = createFunctionInliningPass(PMBuilder->OptLevel, PMBuilder->SizeLevel, false);
}
if (tsan) {
PMBuilder->addExtension(PassManagerBuilder::EP_OptimizerLast, addThreadSanitizerPass);
PMBuilder->addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0, addThreadSanitizerPass);
}
// Set up the per-function pass manager.
legacy::FunctionPassManager FPM = legacy::FunctionPassManager(module);
auto tliwp = new(std::nothrow) TargetLibraryInfoWrapperPass(tlii);

View File

@@ -48,7 +48,7 @@ ZIG_EXTERN_C char *ZigLLVMGetNativeFeatures(void);
ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,
char **error_message, bool is_debug,
bool is_small, bool time_report,
bool is_small, bool time_report, bool tsan,
const char *asm_filename, const char *bin_filename, const char *llvm_ir_filename);