Skip to content

Commit

Permalink
Support LLVM 16
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Mar 12, 2023
1 parent 81a6769 commit 42af62e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/llvm/ext/llvm_ext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <llvm/IR/Metadata.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/Support/FileSystem.h>
#include <llvm/ADT/Triple.h>
#include <llvm-c/TargetMachine.h>
#include <llvm/Target/TargetMachine.h>
#include <llvm-c/ExecutionEngine.h>
Expand All @@ -26,11 +25,22 @@ using namespace llvm;
#define LLVM_VERSION_LE(major, minor) \
(LLVM_VERSION_MAJOR < (major) || LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))

// TODO: remove after #13177
#if LLVM_VERSION_GE(16, 0)
#include <llvm/TargetParser/Triple.h>
#else
#include <llvm/ADT/Triple.h>
#endif

#include <llvm/Target/CodeGenCWrappers.h>
#include <llvm-c/DebugInfo.h>
#include <llvm/Bitcode/BitcodeWriter.h>
#include <llvm/Analysis/ModuleSummaryAnalysis.h>

#if LLVM_VERSION_GE(16, 0)
#define makeArrayRef ArrayRef
#endif

typedef DIBuilder *DIBuilderRef;
#define DIArray DINodeArray
template <typename T> T *unwrapDIptr(LLVMMetadataRef v) {
Expand Down Expand Up @@ -238,7 +248,11 @@ LLVMMetadataRef LLVMExtDIBuilderCreatePointerType(
uint64_t SizeInBits, uint64_t AlignInBits, const char *Name) {
DIDerivedType *T = Dref->createPointerType(unwrapDI<DIType>(PointeeType),
SizeInBits, AlignInBits,
#if LLVM_VERSION_GE(16, 0)
std::nullopt,
#else
None,
#endif
Name);
return wrap(T);
}
Expand Down Expand Up @@ -457,7 +471,7 @@ LLVMBool LLVMExtCreateMCJITCompilerForModule(
.setOptLevel((CodeGenOpt::Level)options.OptLevel)
.setTargetOptions(targetOptions);
bool JIT;
if (Optional<CodeModel::Model> CM = unwrap(options.CodeModel, JIT))
if (auto CM = unwrap(options.CodeModel, JIT))
builder.setCodeModel(*CM);
if (options.MCJMM)
builder.setMCJITMemoryManager(
Expand Down

0 comments on commit 42af62e

Please sign in to comment.