Skip to content

Commit

Permalink
aot compiler: Some updates for LLVM 18 (bytecodealliance#2981)
Browse files Browse the repository at this point in the history
Note: This commit includes copy-and-paste from LLVM and thus adds
the LLVM copyright notice.

cf. llvm/llvm-project@0a1aa6c
cf. llvm/llvm-project@a1e9777
cf. llvm/llvm-project@56c72c7
  • Loading branch information
yamt authored Jan 8, 2024
1 parent 9c9ccea commit ec82956
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/iwasm/compilation/aot_llvm_extra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,10 @@ aot_compress_aot_func_names(AOTCompContext *comp_ctx, uint32 *p_size)
NameStrs.push_back(str);
}

if (collectPGOFuncNameStrings(NameStrs, true, Result)) {
#if LLVM_VERSION_MAJOR < 18
#define collectGlobalObjectNameStrings collectPGOFuncNameStrings
#endif
if (collectGlobalObjectNameStrings(NameStrs, true, Result)) {
aot_set_last_error("collect pgo func name strings failed");
return NULL;
}
Expand Down
19 changes: 19 additions & 0 deletions core/iwasm/compilation/aot_llvm_extra2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ convert(LLVMRelocMode reloc_mode)
#endif
}

#if LLVM_VERSION_MAJOR < 18
static llvm::CodeGenOpt::Level
convert(LLVMCodeGenOptLevel opt_level)
{
Expand All @@ -74,6 +75,24 @@ convert(LLVMCodeGenOptLevel opt_level)
bh_assert(0);
return llvm::CodeGenOpt::None;
}
#else
static llvm::CodeGenOptLevel
convert(LLVMCodeGenOptLevel opt_level)
{
switch (opt_level) {
case LLVMCodeGenLevelNone:
return llvm::CodeGenOptLevel::None;
case LLVMCodeGenLevelLess:
return llvm::CodeGenOptLevel::Less;
case LLVMCodeGenLevelDefault:
return llvm::CodeGenOptLevel::Default;
case LLVMCodeGenLevelAggressive:
return llvm::CodeGenOptLevel::Aggressive;
}
bh_assert(0);
return llvm::CodeGenOptLevel::None;
}
#endif

static llvm::Optional<llvm::CodeModel::Model>
convert(LLVMCodeModel code_model, bool *jit)
Expand Down
27 changes: 27 additions & 0 deletions core/iwasm/compilation/aot_orc_extra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "llvm-c/LLJIT.h"
#include "llvm-c/Orc.h"
#include "llvm-c/OrcEE.h"
Expand Down Expand Up @@ -44,6 +48,7 @@ class InProgressLookupState;
class OrcV2CAPIHelper
{
public:
#if LLVM_VERSION_MAJOR < 18
using PoolEntry = SymbolStringPtr::PoolEntry;
using PoolEntryPtr = SymbolStringPtr::PoolEntryPtr;

Expand Down Expand Up @@ -86,6 +91,7 @@ class OrcV2CAPIHelper
S.S = P;
}

#endif
static InProgressLookupState *extractLookupState(LookupState &LS)
{
return LS.IPLS.release();
Expand All @@ -101,15 +107,31 @@ class OrcV2CAPIHelper
} // namespace llvm

// ORC.h
#if LLVM_VERSION_MAJOR >= 18
inline LLVMOrcSymbolStringPoolEntryRef
wrap(SymbolStringPoolEntryUnsafe E)
{
return reinterpret_cast<LLVMOrcSymbolStringPoolEntryRef>(E.rawPtr());
}

inline SymbolStringPoolEntryUnsafe
unwrap(LLVMOrcSymbolStringPoolEntryRef E)
{
return reinterpret_cast<SymbolStringPoolEntryUnsafe::PoolEntry *>(E);
}
#endif

DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ExecutionSession, LLVMOrcExecutionSessionRef)
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRTransformLayer, LLVMOrcIRTransformLayerRef)
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(JITDylib, LLVMOrcJITDylibRef)
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(JITTargetMachineBuilder,
LLVMOrcJITTargetMachineBuilderRef)
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ObjectTransformLayer,
LLVMOrcObjectTransformLayerRef)
#if LLVM_VERSION_MAJOR < 18
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(OrcV2CAPIHelper::PoolEntry,
LLVMOrcSymbolStringPoolEntryRef)
#endif
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ObjectLayer, LLVMOrcObjectLayerRef)
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(SymbolStringPool, LLVMOrcSymbolStringPoolRef)
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ThreadSafeModule, LLVMOrcThreadSafeModuleRef)
Expand Down Expand Up @@ -292,8 +314,13 @@ LLVMOrcSymbolStringPoolEntryRef
LLVMOrcLLLazyJITMangleAndIntern(LLVMOrcLLLazyJITRef J,
const char *UnmangledName)
{
#if LLVM_VERSION_MAJOR < 18
return wrap(OrcV2CAPIHelper::moveFromSymbolStringPtr(
unwrap(J)->mangleAndIntern(UnmangledName)));
#else
return wrap(SymbolStringPoolEntryUnsafe::take(
unwrap(J)->mangleAndIntern(UnmangledName)));
#endif
}

LLVMOrcJITDylibRef
Expand Down

0 comments on commit ec82956

Please sign in to comment.