1
0
mirror of https://github.com/exaloop/codon.git synced 2025-06-03 15:03:52 +08:00

Upgrade to LLVM 17 (#531)

* Support LLVM 16

* Update for LLVM 17

* Add climits include

* Use LLVM 17 branch

* Disable tests in clang build

* Fix regex GC issue

* Use new "codon" branch of exaloop/llvm
This commit is contained in:
A. R. Shajii 2024-01-23 17:12:58 -05:00 committed by GitHub
parent c8bc944a50
commit 725003c64f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 28 additions and 28 deletions

View File

@ -80,22 +80,21 @@ LLVMVisitor::LLVMVisitor()
auto &registry = *llvm::PassRegistry::getPassRegistry();
llvm::initializeCore(registry);
llvm::initializeScalarOpts(registry);
llvm::initializeObjCARCOpts(registry);
llvm::initializeVectorization(registry);
llvm::initializeIPO(registry);
llvm::initializeAnalysis(registry);
llvm::initializeTransformUtils(registry);
llvm::initializeInstCombine(registry);
llvm::initializeAggressiveInstCombine(registry);
llvm::initializeInstrumentation(registry);
llvm::initializeTarget(registry);
llvm::initializeExpandLargeDivRemLegacyPassPass(registry);
llvm::initializeExpandLargeFpConvertLegacyPassPass(registry);
llvm::initializeExpandMemCmpPassPass(registry);
llvm::initializeScalarizeMaskedMemIntrinLegacyPassPass(registry);
llvm::initializeSelectOptimizePass(registry);
llvm::initializeCallBrPreparePass(registry);
llvm::initializeCodeGenPreparePass(registry);
llvm::initializeAtomicExpandPass(registry);
llvm::initializeRewriteSymbolsLegacyPassPass(registry);
llvm::initializeWinEHPreparePass(registry);
llvm::initializeDwarfEHPrepareLegacyPassPass(registry);
llvm::initializeSafeStackLegacyPassPass(registry);
@ -110,8 +109,6 @@ LLVMVisitor::LLVMVisitor()
llvm::initializeExpandVectorPredicationPass(registry);
llvm::initializeWasmEHPreparePass(registry);
llvm::initializeWriteBitcodePassPass(registry);
llvm::initializeHardwareLoopsPass(registry);
llvm::initializeTypePromotionPass(registry);
llvm::initializeReplaceWithVeclibLegacyPass(registry);
llvm::initializeJMCInstrumenterPass(registry);
}
@ -1855,7 +1852,7 @@ void LLVMVisitor::visit(const LLVMFunc *x) {
// set up debug info
// for now we just set all to func's source location
auto *srcInfo = getSrcInfo(x);
for (auto &block : func->getBasicBlockList()) {
for (auto &block : *func) {
for (auto &inst : block) {
if (!inst.getDebugLoc()) {
inst.setDebugLoc(llvm::DebugLoc(llvm::DILocation::get(

View File

@ -6,7 +6,6 @@
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Analysis/CallGraphSCCPass.h"
#include "llvm/Analysis/CaptureTracking.h"
@ -26,7 +25,6 @@
#include "llvm/ExecutionEngine/JITLink/JITLink.h"
#include "llvm/ExecutionEngine/JITLink/JITLinkDylib.h"
#include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
#include "llvm/ExecutionEngine/JITLink/MemoryFlags.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/MCJIT.h"
#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
@ -81,7 +79,6 @@
#include "llvm/LinkAllIR.h"
#include "llvm/LinkAllPasses.h"
#include "llvm/Linker/Linker.h"
#include "llvm/MC/SubtargetFeature.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Support/Allocator.h"
@ -92,7 +89,6 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/Memory.h"
#include "llvm/Support/Process.h"
@ -105,11 +101,11 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/TargetParser/Host.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/IPO/AlwaysInliner.h"
#include "llvm/Transforms/IPO/GlobalDCE.h"
#include "llvm/Transforms/IPO/Internalize.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
#include "llvm/Transforms/IPO/StripSymbols.h"
#include "llvm/Transforms/IPO/WholeProgramDevirt.h"

View File

@ -63,7 +63,7 @@ void applyDebugTransformations(llvm::Module *module, bool debug, bool jit) {
f.addFnAttr("no-frame-pointer-elim-non-leaf");
f.addFnAttr("no-jump-tables", "false");
for (auto &block : f.getBasicBlockList()) {
for (auto &block : f) {
for (auto &inst : block) {
if (auto *call = llvm::dyn_cast<llvm::CallInst>(&inst)) {
call->setTailCall(false);

View File

@ -127,13 +127,15 @@ llvm::Error DebugPlugin::notifyFailed(llvm::orc::MaterializationResponsibility &
return llvm::Error::success();
}
llvm::Error DebugPlugin::notifyRemovingResources(llvm::orc::ResourceKey key) {
llvm::Error DebugPlugin::notifyRemovingResources(llvm::orc::JITDylib &jd,
llvm::orc::ResourceKey key) {
std::lock_guard<std::mutex> lock(pluginMutex);
registeredObjs.erase(key);
return llvm::Error::success();
}
void DebugPlugin::notifyTransferringResources(llvm::orc::ResourceKey dstKey,
void DebugPlugin::notifyTransferringResources(llvm::orc::JITDylib &jd,
llvm::orc::ResourceKey dstKey,
llvm::orc::ResourceKey srcKey) {
std::lock_guard<std::mutex> lock(pluginMutex);
auto it = registeredObjs.find(srcKey);

View File

@ -73,8 +73,10 @@ public:
llvm::MemoryBufferRef inputObject) override;
llvm::Error notifyEmitted(llvm::orc::MaterializationResponsibility &mr) override;
llvm::Error notifyFailed(llvm::orc::MaterializationResponsibility &mr) override;
llvm::Error notifyRemovingResources(llvm::orc::ResourceKey key) override;
void notifyTransferringResources(llvm::orc::ResourceKey dstKey,
llvm::Error notifyRemovingResources(llvm::orc::JITDylib &jd,
llvm::orc::ResourceKey key) override;
void notifyTransferringResources(llvm::orc::JITDylib &jd,
llvm::orc::ResourceKey dstKey,
llvm::orc::ResourceKey srcKey) override;
void modifyPassConfig(llvm::orc::MaterializationResponsibility &mr,
llvm::jitlink::LinkGraph &,

View File

@ -57,13 +57,12 @@ llvm::Expected<std::unique_ptr<Engine>> Engine::create() {
auto sess = std::make_unique<llvm::orc::ExecutionSession>(std::move(*epc));
auto epciu =
llvm::orc::EPCIndirectionUtils::Create(sess->getExecutorProcessControl());
auto epciu = llvm::orc::EPCIndirectionUtils::Create(*sess);
if (!epciu)
return epciu.takeError();
(*epciu)->createLazyCallThroughManager(
*sess, llvm::pointerToJITTargetAddress(&handleLazyCallThroughError));
*sess, llvm::orc::ExecutorAddr::fromPtr(&handleLazyCallThroughError));
if (auto err = llvm::orc::setUpInProcessLCTMReentryViaEPCIU(**epciu))
return std::move(err);
@ -87,7 +86,7 @@ llvm::Error Engine::addModule(llvm::orc::ThreadSafeModule module,
return optimizeLayer.add(rt, std::move(module));
}
llvm::Expected<llvm::JITEvaluatedSymbol> Engine::lookup(llvm::StringRef name) {
llvm::Expected<llvm::orc::ExecutorSymbolDef> Engine::lookup(llvm::StringRef name) {
return sess->lookup({&mainJD}, mangle(name.str()));
}

View File

@ -52,7 +52,7 @@ public:
llvm::Error addModule(llvm::orc::ThreadSafeModule module,
llvm::orc::ResourceTrackerSP rt = nullptr);
llvm::Expected<llvm::JITEvaluatedSymbol> lookup(llvm::StringRef name);
llvm::Expected<llvm::orc::ExecutorSymbolDef> lookup(llvm::StringRef name);
};
} // namespace jit

View File

@ -60,7 +60,7 @@ llvm::Error JIT::init() {
if (auto err = func.takeError())
return err;
auto *main = (MainFunc *)func->getAddress();
auto *main = func->getAddress().toPtr<MainFunc>();
(*main)(0, nullptr);
return llvm::Error::success();
}
@ -174,7 +174,7 @@ llvm::Expected<void *> JIT::address(const ir::Func *input) {
if (auto err = func.takeError())
return std::move(err);
return (void *)func->getAddress();
return (void *)func->getAddress().getValue();
}
llvm::Expected<std::string> JIT::run(const ir::Func *input) {
@ -292,7 +292,7 @@ JITResult JIT::executePython(const std::string &name,
auto *wrapper = it->second;
const std::string name = ir::LLVMVisitor::getNameForFunction(wrapper);
auto func = llvm::cantFail(engine->lookup(name));
wrap = (PyWrapperFunc *)func.getAddress();
wrap = func.getAddress().toPtr<PyWrapperFunc>();
} else {
static int idx = 0;
auto wrapname = "__codon_wrapped__" + name + "_" + std::to_string(idx++);

View File

@ -179,7 +179,7 @@ void BoehmGCJITLinkMemoryManager::allocate(const llvm::jitlink::JITLinkDylib *JD
auto &Seg = KV.second;
auto &SegAddr =
(AG.getMemDeallocPolicy() == llvm::jitlink::MemDeallocPolicy::Standard)
(AG.getMemLifetimePolicy() == llvm::orc::MemLifetimePolicy::Standard)
? NextStandardSegAddr
: NextFinalizeSegAddr;
@ -189,7 +189,7 @@ void BoehmGCJITLinkMemoryManager::allocate(const llvm::jitlink::JITLinkDylib *JD
SegAddr += llvm::alignTo(Seg.ContentSize + Seg.ZeroFillSize, PageSize);
if (static_cast<int>(AG.getMemProt()) &
static_cast<int>(llvm::jitlink::MemProt::Write)) {
static_cast<int>(llvm::orc::MemProt::Write)) {
seq_gc_add_roots((void *)Seg.Addr.getValue(), (void *)SegAddr.getValue());
}
}

View File

@ -3,6 +3,7 @@
#include "common.h"
#include <cinttypes>
#include <climits>
#include <string>
#include <vector>

View File

@ -56,6 +56,8 @@ SEQ_FUNC void seq_assert_failed(seq_str_t file, seq_int_t line);
SEQ_FUNC void *seq_alloc(size_t n);
SEQ_FUNC void *seq_alloc_atomic(size_t n);
SEQ_FUNC void *seq_alloc_uncollectable(size_t n);
SEQ_FUNC void *seq_alloc_atomic_uncollectable(size_t n);
SEQ_FUNC void *seq_calloc(size_t m, size_t n);
SEQ_FUNC void *seq_calloc_atomic(size_t m, size_t n);
SEQ_FUNC void *seq_realloc(void *p, size_t newsize, size_t oldsize);

View File

@ -75,7 +75,7 @@ template <typename KV> struct GCMapAllocator : public std::allocator<KV> {
template <typename KV1> GCMapAllocator(const GCMapAllocator<KV1> &) noexcept {}
KV *allocate(std::size_t n) { return (KV *)seq_alloc(n * sizeof(KV)); }
KV *allocate(std::size_t n) { return (KV *)seq_alloc_uncollectable(n * sizeof(KV)); }
void deallocate(KV *p, std::size_t n) { seq_free(p); }

View File

@ -33,6 +33,7 @@ if [ ! -f "${INSTALLDIR}/bin/llvm-config" ]; then
cd "${SRCDIR}/clang/build"
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_INCLUDE_TESTS=OFF \
-DCMAKE_INSTALL_PREFIX="${INSTALLDIR}"
make -j "${JOBS}"
make install