mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-10 21:06:33 +03:00
Fix compilation with LLVM16 (#4176)
This commit is contained in:
parent
f4bbcdd07b
commit
a3eae7a815
2 changed files with 22 additions and 3 deletions
|
@ -35,8 +35,10 @@
|
||||||
#include "llvm/Transforms/Utils/Cloning.h"
|
#include "llvm/Transforms/Utils/Cloning.h"
|
||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
#ifdef LDC_LLVM_SUPPORTED_TARGET_SPIRV
|
#ifdef LDC_LLVM_SUPPORTED_TARGET_SPIRV
|
||||||
|
#if LDC_LLVM_VER < 1600
|
||||||
#include "LLVMSPIRVLib/LLVMSPIRVLib.h"
|
#include "LLVMSPIRVLib/LLVMSPIRVLib.h"
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
@ -65,10 +67,12 @@ void codegenModule(llvm::TargetMachine &Target, llvm::Module &m,
|
||||||
|
|
||||||
if (cb == ComputeBackend::SPIRV) {
|
if (cb == ComputeBackend::SPIRV) {
|
||||||
#ifdef LDC_LLVM_SUPPORTED_TARGET_SPIRV
|
#ifdef LDC_LLVM_SUPPORTED_TARGET_SPIRV
|
||||||
|
#if LDC_LLVM_VER < 1600
|
||||||
IF_LOG Logger::println("running createSPIRVWriterPass()");
|
IF_LOG Logger::println("running createSPIRVWriterPass()");
|
||||||
std::ofstream out(filename, std::ofstream::binary);
|
std::ofstream out(filename, std::ofstream::binary);
|
||||||
llvm::createSPIRVWriterPass(out)->runOnModule(m);
|
llvm::createSPIRVWriterPass(out)->runOnModule(m);
|
||||||
IF_LOG Logger::println("Success.");
|
IF_LOG Logger::println("Success.");
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
error(Loc(), "Trying to target SPIRV, but LDC is not built to do so!");
|
error(Loc(), "Trying to target SPIRV, but LDC is not built to do so!");
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -458,19 +458,29 @@ static void addAddressSanitizerPasses(ModulePassManager &mpm,
|
||||||
aso.UseAfterScope = true;
|
aso.UseAfterScope = true;
|
||||||
aso.UseAfterReturn = AsanDetectStackUseAfterReturnMode::Runtime;
|
aso.UseAfterReturn = AsanDetectStackUseAfterReturnMode::Runtime;
|
||||||
|
|
||||||
|
#if LDC_LLVM_VER >= 1600
|
||||||
|
mpm.addPass(AddressSanitizerPass(aso));
|
||||||
|
#else
|
||||||
mpm.addPass(ModuleAddressSanitizerPass(aso));
|
mpm.addPass(ModuleAddressSanitizerPass(aso));
|
||||||
|
#endif
|
||||||
if (verifyEach) {
|
if (verifyEach) {
|
||||||
mpm.addPass(VerifierPass());
|
mpm.addPass(VerifierPass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addMemorySanitizerPass(FunctionPassManager &fpm,
|
static void addMemorySanitizerPass(ModulePassManager &mpm,
|
||||||
|
FunctionPassManager &fpm,
|
||||||
OptimizationLevel level ) {
|
OptimizationLevel level ) {
|
||||||
int trackOrigins = fSanitizeMemoryTrackOrigins;
|
int trackOrigins = fSanitizeMemoryTrackOrigins;
|
||||||
bool recover = false;
|
bool recover = false;
|
||||||
bool kernel = false;
|
bool kernel = false;
|
||||||
|
#if LDC_LLVM_VER >= 1600
|
||||||
|
mpm.addPass(MemorySanitizerPass(
|
||||||
|
MemorySanitizerOptions{trackOrigins, recover, kernel}));
|
||||||
|
#else
|
||||||
fpm.addPass(MemorySanitizerPass(
|
fpm.addPass(MemorySanitizerPass(
|
||||||
MemorySanitizerOptions{trackOrigins, recover, kernel}));
|
MemorySanitizerOptions{trackOrigins, recover, kernel}));
|
||||||
|
#endif
|
||||||
|
|
||||||
// MemorySanitizer inserts complex instrumentation that mostly follows
|
// MemorySanitizer inserts complex instrumentation that mostly follows
|
||||||
// the logic of the original code, but operates on "shadow" values.
|
// 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,
|
static void addSanitizerCoveragePass(ModulePassManager &mpm,
|
||||||
OptimizationLevel level ) {
|
OptimizationLevel level ) {
|
||||||
|
#if LDC_LLVM_VER >= 1600
|
||||||
|
mpm.addPass(SanitizerCoveragePass(
|
||||||
|
opts::getSanitizerCoverageOptions()));
|
||||||
|
#else
|
||||||
mpm.addPass(ModuleSanitizerCoveragePass(
|
mpm.addPass(ModuleSanitizerCoveragePass(
|
||||||
opts::getSanitizerCoverageOptions()));
|
opts::getSanitizerCoverageOptions()));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
// Adds PGO instrumentation generation and use passes.
|
// Adds PGO instrumentation generation and use passes.
|
||||||
static void addPGOPasses(ModulePassManager &mpm,
|
static void addPGOPasses(ModulePassManager &mpm,
|
||||||
|
@ -665,7 +680,7 @@ void runOptimizationPasses(llvm::Module *M) {
|
||||||
pb.registerOptimizerLastEPCallback([&](ModulePassManager &mpm,
|
pb.registerOptimizerLastEPCallback([&](ModulePassManager &mpm,
|
||||||
OptimizationLevel level) {
|
OptimizationLevel level) {
|
||||||
FunctionPassManager fpm;
|
FunctionPassManager fpm;
|
||||||
addMemorySanitizerPass(fpm,level);
|
addMemorySanitizerPass(mpm, fpm,level);
|
||||||
mpm.addPass(createModuleToFunctionPassAdaptor(std::move(fpm)));
|
mpm.addPass(createModuleToFunctionPassAdaptor(std::move(fpm)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue