|
11 | 11 | #include <clang/Frontend/CompilerInstance.h> |
12 | 12 | #include <clang/Basic/DiagnosticOptions.h> |
13 | 13 | #include <clang/Frontend/TextDiagnosticPrinter.h> |
| 14 | +#if LLVM_VERSION_MAJOR >= 18 |
| 15 | +#include <llvm/Frontend/Debug/Options.h> |
| 16 | +#else |
| 17 | +#include <llvm/Support/CodeGen.h> |
| 18 | +#endif |
14 | 19 | #include <clang/CodeGen/CodeGenAction.h> |
15 | 20 | #include <clang/Basic/TargetInfo.h> |
16 | 21 | #include <clang/Lex/PreprocessorOptions.h> |
|
21 | 26 | #include <llvm/ExecutionEngine/GenericValue.h> |
22 | 27 | #include <llvm/Target/TargetMachine.h> |
23 | 28 | #include <llvm/MC/TargetRegistry.h> |
24 | | -#include <llvm/Support/Host.h> |
25 | 29 | #include <llvm/PassRegistry.h> |
26 | 30 | #include <llvm/InitializePasses.h> |
27 | 31 | #include <llvm/IR/LegacyPassManager.h> |
@@ -114,7 +118,11 @@ static std::unique_ptr<llvm::Module> cpp_to_llvm(const std::string& input_file, |
114 | 118 |
|
115 | 119 | if(debug) |
116 | 120 | { |
| 121 | + #if LLVM_VERSION_MAJOR >= 18 |
| 122 | + compiler_invocation.getCodeGenOpts().setDebugInfo(llvm::codegenoptions::FullDebugInfo); |
| 123 | + #else |
117 | 124 | compiler_invocation.getCodeGenOpts().setDebugInfo(clang::codegenoptions::FullDebugInfo); |
| 125 | + #endif |
118 | 126 | } |
119 | 127 |
|
120 | 128 | // Map code to a MemoryBuffer |
@@ -174,7 +182,11 @@ static std::unique_ptr<llvm::Module> cuda_to_llvm(const std::string& input_file, |
174 | 182 |
|
175 | 183 | if(debug) |
176 | 184 | { |
| 185 | + #if LLVM_VERSION_MAJOR >= 18 |
| 186 | + compiler_invocation.getCodeGenOpts().setDebugInfo(llvm::codegenoptions::FullDebugInfo); |
| 187 | + #else |
177 | 188 | compiler_invocation.getCodeGenOpts().setDebugInfo(clang::codegenoptions::FullDebugInfo); |
| 189 | + #endif |
178 | 190 | } |
179 | 191 |
|
180 | 192 | // Map code to a MemoryBuffer |
@@ -234,7 +246,11 @@ WP_API int compile_cpp(const char* cpp_src, const char *input_file, const char* |
234 | 246 | llvm::raw_fd_ostream output(output_file, error_code, llvm::sys::fs::OF_None); |
235 | 247 |
|
236 | 248 | llvm::legacy::PassManager pass_manager; |
| 249 | + #if LLVM_VERSION_MAJOR >= 18 |
| 250 | + llvm::CodeGenFileType file_type = llvm::CodeGenFileType::ObjectFile; |
| 251 | + #else |
237 | 252 | llvm::CodeGenFileType file_type = llvm::CGFT_ObjectFile; |
| 253 | + #endif |
238 | 254 | target_machine->addPassesToEmitFile(pass_manager, output, nullptr, file_type); |
239 | 255 |
|
240 | 256 | pass_manager.run(*module); |
@@ -287,7 +303,11 @@ WP_API int compile_cuda(const char* cpp_src, const char *input_file, const char* |
287 | 303 | llvm::raw_fd_ostream output(output_file, error_code, llvm::sys::fs::OF_None); |
288 | 304 |
|
289 | 305 | llvm::legacy::PassManager pass_manager; |
| 306 | + #if LLVM_VERSION_MAJOR >= 18 |
| 307 | + llvm::CodeGenFileType file_type = llvm::CodeGenFileType::AssemblyFile; |
| 308 | + #else |
290 | 309 | llvm::CodeGenFileType file_type = llvm::CGFT_AssemblyFile; |
| 310 | + #endif |
291 | 311 | target_machine->addPassesToEmitFile(pass_manager, output, nullptr, file_type); |
292 | 312 |
|
293 | 313 | pass_manager.run(*module); |
@@ -352,10 +372,17 @@ WP_API int load_obj(const char* object_file, const char* module_name) |
352 | 372 | #endif |
353 | 373 |
|
354 | 374 | const auto flags = llvm::JITSymbolFlags::Exported | llvm::JITSymbolFlags::Absolute; |
| 375 | + #if LLVM_VERSION_MAJOR >= 18 |
| 376 | + #define SYMBOL(sym) { jit->getExecutionSession().intern(MANGLING_PREFIX #sym), { llvm::orc::ExecutorAddr::fromPtr(&::sym), flags} } |
| 377 | + #define SYMBOL_T(sym, T) { jit->getExecutionSession().intern(MANGLING_PREFIX #sym), { llvm::orc::ExecutorAddr::fromPtr(static_cast<T>(&::sym)), flags} } |
| 378 | + |
| 379 | + auto error = dll->define(llvm::orc::absoluteSymbols(llvm::orc::SymbolMap({ |
| 380 | + #else |
355 | 381 | #define SYMBOL(sym) { jit->getExecutionSession().intern(MANGLING_PREFIX #sym), { llvm::pointerToJITTargetAddress(&::sym), flags} } |
356 | 382 | #define SYMBOL_T(sym, T) { jit->getExecutionSession().intern(MANGLING_PREFIX #sym), { llvm::pointerToJITTargetAddress(static_cast<T>(&::sym)), flags} } |
357 | 383 |
|
358 | 384 | auto error = dll->define(llvm::orc::absoluteSymbols({ |
| 385 | + #endif |
359 | 386 | SYMBOL(printf), SYMBOL(puts), SYMBOL(putchar), |
360 | 387 | SYMBOL_T(abs, int(*)(int)), SYMBOL(llabs), |
361 | 388 | SYMBOL(fmodf), SYMBOL_T(fmod, double(*)(double, double)), |
@@ -397,7 +424,11 @@ WP_API int load_obj(const char* object_file, const char* module_name) |
397 | 424 | #else |
398 | 425 | SYMBOL(sincosf), SYMBOL_T(sincos, void(*)(double,double*,double*)), |
399 | 426 | #endif |
| 427 | + #if LLVM_VERSION_MAJOR >= 18 |
| 428 | + }))); |
| 429 | + #else |
400 | 430 | })); |
| 431 | + #endif |
401 | 432 |
|
402 | 433 | if(error) |
403 | 434 | { |
|
0 commit comments