Fix compilation with LLVM16 (#4176)

This commit is contained in:
Nicholas Wilson 2022-09-16 11:09:41 +08:00 committed by GitHub
parent f4bbcdd07b
commit a3eae7a815
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View file

@ -35,8 +35,10 @@
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/IR/Module.h"
#ifdef LDC_LLVM_SUPPORTED_TARGET_SPIRV
#if LDC_LLVM_VER < 1600
#include "LLVMSPIRVLib/LLVMSPIRVLib.h"
#endif
#endif
#include <cstddef>
#include <fstream>
@ -65,10 +67,12 @@ void codegenModule(llvm::TargetMachine &Target, llvm::Module &m,
if (cb == ComputeBackend::SPIRV) {
#ifdef LDC_LLVM_SUPPORTED_TARGET_SPIRV
#if LDC_LLVM_VER < 1600
IF_LOG Logger::println("running createSPIRVWriterPass()");
std::ofstream out(filename, std::ofstream::binary);
llvm::createSPIRVWriterPass(out)->runOnModule(m);
IF_LOG Logger::println("Success.");
#endif
#else
error(Loc(), "Trying to target SPIRV, but LDC is not built to do so!");
#endif

View file

@ -458,19 +458,29 @@ static void addAddressSanitizerPasses(ModulePassManager &mpm,
aso.UseAfterScope = true;
aso.UseAfterReturn = AsanDetectStackUseAfterReturnMode::Runtime;
#if LDC_LLVM_VER >= 1600
mpm.addPass(AddressSanitizerPass(aso));
#else
mpm.addPass(ModuleAddressSanitizerPass(aso));
#endif
if (verifyEach) {
mpm.addPass(VerifierPass());
}
}
static void addMemorySanitizerPass(FunctionPassManager &fpm,
static void addMemorySanitizerPass(ModulePassManager &mpm,
FunctionPassManager &fpm,
OptimizationLevel level ) {
int trackOrigins = fSanitizeMemoryTrackOrigins;
bool recover = false;
bool kernel = false;
#if LDC_LLVM_VER >= 1600
mpm.addPass(MemorySanitizerPass(
MemorySanitizerOptions{trackOrigins, recover, kernel}));
#else
fpm.addPass(MemorySanitizerPass(
MemorySanitizerOptions{trackOrigins, recover, kernel}));
#endif
// MemorySanitizer inserts complex instrumentation that mostly follows
// the logic of the original code, but operates on "shadow" values.
@ -494,8 +504,13 @@ static void addThreadSanitizerPass(ModulePassManager &mpm,
static void addSanitizerCoveragePass(ModulePassManager &mpm,
OptimizationLevel level ) {
#if LDC_LLVM_VER >= 1600
mpm.addPass(SanitizerCoveragePass(
opts::getSanitizerCoverageOptions()));
#else
mpm.addPass(ModuleSanitizerCoveragePass(
opts::getSanitizerCoverageOptions()));
#endif
}
// Adds PGO instrumentation generation and use passes.
static void addPGOPasses(ModulePassManager &mpm,
@ -665,7 +680,7 @@ void runOptimizationPasses(llvm::Module *M) {
pb.registerOptimizerLastEPCallback([&](ModulePassManager &mpm,
OptimizationLevel level) {
FunctionPassManager fpm;
addMemorySanitizerPass(fpm,level);
addMemorySanitizerPass(mpm, fpm,level);
mpm.addPass(createModuleToFunctionPassAdaptor(std::move(fpm)));
});
}