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:
parent
c8bc944a50
commit
725003c64f
@ -80,22 +80,21 @@ LLVMVisitor::LLVMVisitor()
|
|||||||
auto ®istry = *llvm::PassRegistry::getPassRegistry();
|
auto ®istry = *llvm::PassRegistry::getPassRegistry();
|
||||||
llvm::initializeCore(registry);
|
llvm::initializeCore(registry);
|
||||||
llvm::initializeScalarOpts(registry);
|
llvm::initializeScalarOpts(registry);
|
||||||
llvm::initializeObjCARCOpts(registry);
|
|
||||||
llvm::initializeVectorization(registry);
|
llvm::initializeVectorization(registry);
|
||||||
llvm::initializeIPO(registry);
|
llvm::initializeIPO(registry);
|
||||||
llvm::initializeAnalysis(registry);
|
llvm::initializeAnalysis(registry);
|
||||||
llvm::initializeTransformUtils(registry);
|
llvm::initializeTransformUtils(registry);
|
||||||
llvm::initializeInstCombine(registry);
|
llvm::initializeInstCombine(registry);
|
||||||
llvm::initializeAggressiveInstCombine(registry);
|
|
||||||
llvm::initializeInstrumentation(registry);
|
|
||||||
llvm::initializeTarget(registry);
|
llvm::initializeTarget(registry);
|
||||||
|
|
||||||
|
llvm::initializeExpandLargeDivRemLegacyPassPass(registry);
|
||||||
|
llvm::initializeExpandLargeFpConvertLegacyPassPass(registry);
|
||||||
llvm::initializeExpandMemCmpPassPass(registry);
|
llvm::initializeExpandMemCmpPassPass(registry);
|
||||||
llvm::initializeScalarizeMaskedMemIntrinLegacyPassPass(registry);
|
llvm::initializeScalarizeMaskedMemIntrinLegacyPassPass(registry);
|
||||||
llvm::initializeSelectOptimizePass(registry);
|
llvm::initializeSelectOptimizePass(registry);
|
||||||
|
llvm::initializeCallBrPreparePass(registry);
|
||||||
llvm::initializeCodeGenPreparePass(registry);
|
llvm::initializeCodeGenPreparePass(registry);
|
||||||
llvm::initializeAtomicExpandPass(registry);
|
llvm::initializeAtomicExpandPass(registry);
|
||||||
llvm::initializeRewriteSymbolsLegacyPassPass(registry);
|
|
||||||
llvm::initializeWinEHPreparePass(registry);
|
llvm::initializeWinEHPreparePass(registry);
|
||||||
llvm::initializeDwarfEHPrepareLegacyPassPass(registry);
|
llvm::initializeDwarfEHPrepareLegacyPassPass(registry);
|
||||||
llvm::initializeSafeStackLegacyPassPass(registry);
|
llvm::initializeSafeStackLegacyPassPass(registry);
|
||||||
@ -110,8 +109,6 @@ LLVMVisitor::LLVMVisitor()
|
|||||||
llvm::initializeExpandVectorPredicationPass(registry);
|
llvm::initializeExpandVectorPredicationPass(registry);
|
||||||
llvm::initializeWasmEHPreparePass(registry);
|
llvm::initializeWasmEHPreparePass(registry);
|
||||||
llvm::initializeWriteBitcodePassPass(registry);
|
llvm::initializeWriteBitcodePassPass(registry);
|
||||||
llvm::initializeHardwareLoopsPass(registry);
|
|
||||||
llvm::initializeTypePromotionPass(registry);
|
|
||||||
llvm::initializeReplaceWithVeclibLegacyPass(registry);
|
llvm::initializeReplaceWithVeclibLegacyPass(registry);
|
||||||
llvm::initializeJMCInstrumenterPass(registry);
|
llvm::initializeJMCInstrumenterPass(registry);
|
||||||
}
|
}
|
||||||
@ -1855,7 +1852,7 @@ void LLVMVisitor::visit(const LLVMFunc *x) {
|
|||||||
// set up debug info
|
// set up debug info
|
||||||
// for now we just set all to func's source location
|
// for now we just set all to func's source location
|
||||||
auto *srcInfo = getSrcInfo(x);
|
auto *srcInfo = getSrcInfo(x);
|
||||||
for (auto &block : func->getBasicBlockList()) {
|
for (auto &block : *func) {
|
||||||
for (auto &inst : block) {
|
for (auto &inst : block) {
|
||||||
if (!inst.getDebugLoc()) {
|
if (!inst.getDebugLoc()) {
|
||||||
inst.setDebugLoc(llvm::DebugLoc(llvm::DILocation::get(
|
inst.setDebugLoc(llvm::DebugLoc(llvm::DILocation::get(
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include "llvm/ADT/SmallSet.h"
|
#include "llvm/ADT/SmallSet.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/ADT/StringRef.h"
|
#include "llvm/ADT/StringRef.h"
|
||||||
#include "llvm/ADT/Triple.h"
|
|
||||||
#include "llvm/Analysis/CallGraph.h"
|
#include "llvm/Analysis/CallGraph.h"
|
||||||
#include "llvm/Analysis/CallGraphSCCPass.h"
|
#include "llvm/Analysis/CallGraphSCCPass.h"
|
||||||
#include "llvm/Analysis/CaptureTracking.h"
|
#include "llvm/Analysis/CaptureTracking.h"
|
||||||
@ -26,7 +25,6 @@
|
|||||||
#include "llvm/ExecutionEngine/JITLink/JITLink.h"
|
#include "llvm/ExecutionEngine/JITLink/JITLink.h"
|
||||||
#include "llvm/ExecutionEngine/JITLink/JITLinkDylib.h"
|
#include "llvm/ExecutionEngine/JITLink/JITLinkDylib.h"
|
||||||
#include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
|
#include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
|
||||||
#include "llvm/ExecutionEngine/JITLink/MemoryFlags.h"
|
|
||||||
#include "llvm/ExecutionEngine/JITSymbol.h"
|
#include "llvm/ExecutionEngine/JITSymbol.h"
|
||||||
#include "llvm/ExecutionEngine/MCJIT.h"
|
#include "llvm/ExecutionEngine/MCJIT.h"
|
||||||
#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
|
#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
|
||||||
@ -81,7 +79,6 @@
|
|||||||
#include "llvm/LinkAllIR.h"
|
#include "llvm/LinkAllIR.h"
|
||||||
#include "llvm/LinkAllPasses.h"
|
#include "llvm/LinkAllPasses.h"
|
||||||
#include "llvm/Linker/Linker.h"
|
#include "llvm/Linker/Linker.h"
|
||||||
#include "llvm/MC/SubtargetFeature.h"
|
|
||||||
#include "llvm/MC/TargetRegistry.h"
|
#include "llvm/MC/TargetRegistry.h"
|
||||||
#include "llvm/Passes/PassBuilder.h"
|
#include "llvm/Passes/PassBuilder.h"
|
||||||
#include "llvm/Support/Allocator.h"
|
#include "llvm/Support/Allocator.h"
|
||||||
@ -92,7 +89,6 @@
|
|||||||
#include "llvm/Support/Error.h"
|
#include "llvm/Support/Error.h"
|
||||||
#include "llvm/Support/FileSystem.h"
|
#include "llvm/Support/FileSystem.h"
|
||||||
#include "llvm/Support/FormatVariadic.h"
|
#include "llvm/Support/FormatVariadic.h"
|
||||||
#include "llvm/Support/Host.h"
|
|
||||||
#include "llvm/Support/InitLLVM.h"
|
#include "llvm/Support/InitLLVM.h"
|
||||||
#include "llvm/Support/Memory.h"
|
#include "llvm/Support/Memory.h"
|
||||||
#include "llvm/Support/Process.h"
|
#include "llvm/Support/Process.h"
|
||||||
@ -105,11 +101,11 @@
|
|||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/Target/TargetLoweringObjectFile.h"
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetMachine.h"
|
||||||
|
#include "llvm/TargetParser/Host.h"
|
||||||
#include "llvm/Transforms/IPO.h"
|
#include "llvm/Transforms/IPO.h"
|
||||||
#include "llvm/Transforms/IPO/AlwaysInliner.h"
|
#include "llvm/Transforms/IPO/AlwaysInliner.h"
|
||||||
#include "llvm/Transforms/IPO/GlobalDCE.h"
|
#include "llvm/Transforms/IPO/GlobalDCE.h"
|
||||||
#include "llvm/Transforms/IPO/Internalize.h"
|
#include "llvm/Transforms/IPO/Internalize.h"
|
||||||
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
|
||||||
#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
|
#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
|
||||||
#include "llvm/Transforms/IPO/StripSymbols.h"
|
#include "llvm/Transforms/IPO/StripSymbols.h"
|
||||||
#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
|
#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
|
||||||
|
@ -63,7 +63,7 @@ void applyDebugTransformations(llvm::Module *module, bool debug, bool jit) {
|
|||||||
f.addFnAttr("no-frame-pointer-elim-non-leaf");
|
f.addFnAttr("no-frame-pointer-elim-non-leaf");
|
||||||
f.addFnAttr("no-jump-tables", "false");
|
f.addFnAttr("no-jump-tables", "false");
|
||||||
|
|
||||||
for (auto &block : f.getBasicBlockList()) {
|
for (auto &block : f) {
|
||||||
for (auto &inst : block) {
|
for (auto &inst : block) {
|
||||||
if (auto *call = llvm::dyn_cast<llvm::CallInst>(&inst)) {
|
if (auto *call = llvm::dyn_cast<llvm::CallInst>(&inst)) {
|
||||||
call->setTailCall(false);
|
call->setTailCall(false);
|
||||||
|
@ -127,13 +127,15 @@ llvm::Error DebugPlugin::notifyFailed(llvm::orc::MaterializationResponsibility &
|
|||||||
return llvm::Error::success();
|
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);
|
std::lock_guard<std::mutex> lock(pluginMutex);
|
||||||
registeredObjs.erase(key);
|
registeredObjs.erase(key);
|
||||||
return llvm::Error::success();
|
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) {
|
llvm::orc::ResourceKey srcKey) {
|
||||||
std::lock_guard<std::mutex> lock(pluginMutex);
|
std::lock_guard<std::mutex> lock(pluginMutex);
|
||||||
auto it = registeredObjs.find(srcKey);
|
auto it = registeredObjs.find(srcKey);
|
||||||
|
@ -73,8 +73,10 @@ public:
|
|||||||
llvm::MemoryBufferRef inputObject) override;
|
llvm::MemoryBufferRef inputObject) override;
|
||||||
llvm::Error notifyEmitted(llvm::orc::MaterializationResponsibility &mr) override;
|
llvm::Error notifyEmitted(llvm::orc::MaterializationResponsibility &mr) override;
|
||||||
llvm::Error notifyFailed(llvm::orc::MaterializationResponsibility &mr) override;
|
llvm::Error notifyFailed(llvm::orc::MaterializationResponsibility &mr) override;
|
||||||
llvm::Error notifyRemovingResources(llvm::orc::ResourceKey key) override;
|
llvm::Error notifyRemovingResources(llvm::orc::JITDylib &jd,
|
||||||
void notifyTransferringResources(llvm::orc::ResourceKey dstKey,
|
llvm::orc::ResourceKey key) override;
|
||||||
|
void notifyTransferringResources(llvm::orc::JITDylib &jd,
|
||||||
|
llvm::orc::ResourceKey dstKey,
|
||||||
llvm::orc::ResourceKey srcKey) override;
|
llvm::orc::ResourceKey srcKey) override;
|
||||||
void modifyPassConfig(llvm::orc::MaterializationResponsibility &mr,
|
void modifyPassConfig(llvm::orc::MaterializationResponsibility &mr,
|
||||||
llvm::jitlink::LinkGraph &,
|
llvm::jitlink::LinkGraph &,
|
||||||
|
@ -57,13 +57,12 @@ llvm::Expected<std::unique_ptr<Engine>> Engine::create() {
|
|||||||
|
|
||||||
auto sess = std::make_unique<llvm::orc::ExecutionSession>(std::move(*epc));
|
auto sess = std::make_unique<llvm::orc::ExecutionSession>(std::move(*epc));
|
||||||
|
|
||||||
auto epciu =
|
auto epciu = llvm::orc::EPCIndirectionUtils::Create(*sess);
|
||||||
llvm::orc::EPCIndirectionUtils::Create(sess->getExecutorProcessControl());
|
|
||||||
if (!epciu)
|
if (!epciu)
|
||||||
return epciu.takeError();
|
return epciu.takeError();
|
||||||
|
|
||||||
(*epciu)->createLazyCallThroughManager(
|
(*epciu)->createLazyCallThroughManager(
|
||||||
*sess, llvm::pointerToJITTargetAddress(&handleLazyCallThroughError));
|
*sess, llvm::orc::ExecutorAddr::fromPtr(&handleLazyCallThroughError));
|
||||||
|
|
||||||
if (auto err = llvm::orc::setUpInProcessLCTMReentryViaEPCIU(**epciu))
|
if (auto err = llvm::orc::setUpInProcessLCTMReentryViaEPCIU(**epciu))
|
||||||
return std::move(err);
|
return std::move(err);
|
||||||
@ -87,7 +86,7 @@ llvm::Error Engine::addModule(llvm::orc::ThreadSafeModule module,
|
|||||||
return optimizeLayer.add(rt, std::move(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()));
|
return sess->lookup({&mainJD}, mangle(name.str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ public:
|
|||||||
llvm::Error addModule(llvm::orc::ThreadSafeModule module,
|
llvm::Error addModule(llvm::orc::ThreadSafeModule module,
|
||||||
llvm::orc::ResourceTrackerSP rt = nullptr);
|
llvm::orc::ResourceTrackerSP rt = nullptr);
|
||||||
|
|
||||||
llvm::Expected<llvm::JITEvaluatedSymbol> lookup(llvm::StringRef name);
|
llvm::Expected<llvm::orc::ExecutorSymbolDef> lookup(llvm::StringRef name);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace jit
|
} // namespace jit
|
||||||
|
@ -60,7 +60,7 @@ llvm::Error JIT::init() {
|
|||||||
if (auto err = func.takeError())
|
if (auto err = func.takeError())
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
auto *main = (MainFunc *)func->getAddress();
|
auto *main = func->getAddress().toPtr<MainFunc>();
|
||||||
(*main)(0, nullptr);
|
(*main)(0, nullptr);
|
||||||
return llvm::Error::success();
|
return llvm::Error::success();
|
||||||
}
|
}
|
||||||
@ -174,7 +174,7 @@ llvm::Expected<void *> JIT::address(const ir::Func *input) {
|
|||||||
if (auto err = func.takeError())
|
if (auto err = func.takeError())
|
||||||
return std::move(err);
|
return std::move(err);
|
||||||
|
|
||||||
return (void *)func->getAddress();
|
return (void *)func->getAddress().getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::Expected<std::string> JIT::run(const ir::Func *input) {
|
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;
|
auto *wrapper = it->second;
|
||||||
const std::string name = ir::LLVMVisitor::getNameForFunction(wrapper);
|
const std::string name = ir::LLVMVisitor::getNameForFunction(wrapper);
|
||||||
auto func = llvm::cantFail(engine->lookup(name));
|
auto func = llvm::cantFail(engine->lookup(name));
|
||||||
wrap = (PyWrapperFunc *)func.getAddress();
|
wrap = func.getAddress().toPtr<PyWrapperFunc>();
|
||||||
} else {
|
} else {
|
||||||
static int idx = 0;
|
static int idx = 0;
|
||||||
auto wrapname = "__codon_wrapped__" + name + "_" + std::to_string(idx++);
|
auto wrapname = "__codon_wrapped__" + name + "_" + std::to_string(idx++);
|
||||||
|
@ -179,7 +179,7 @@ void BoehmGCJITLinkMemoryManager::allocate(const llvm::jitlink::JITLinkDylib *JD
|
|||||||
auto &Seg = KV.second;
|
auto &Seg = KV.second;
|
||||||
|
|
||||||
auto &SegAddr =
|
auto &SegAddr =
|
||||||
(AG.getMemDeallocPolicy() == llvm::jitlink::MemDeallocPolicy::Standard)
|
(AG.getMemLifetimePolicy() == llvm::orc::MemLifetimePolicy::Standard)
|
||||||
? NextStandardSegAddr
|
? NextStandardSegAddr
|
||||||
: NextFinalizeSegAddr;
|
: NextFinalizeSegAddr;
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ void BoehmGCJITLinkMemoryManager::allocate(const llvm::jitlink::JITLinkDylib *JD
|
|||||||
SegAddr += llvm::alignTo(Seg.ContentSize + Seg.ZeroFillSize, PageSize);
|
SegAddr += llvm::alignTo(Seg.ContentSize + Seg.ZeroFillSize, PageSize);
|
||||||
|
|
||||||
if (static_cast<int>(AG.getMemProt()) &
|
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());
|
seq_gc_add_roots((void *)Seg.Addr.getValue(), (void *)SegAddr.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
|
#include <climits>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -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(size_t n);
|
||||||
SEQ_FUNC void *seq_alloc_atomic(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(size_t m, size_t n);
|
||||||
SEQ_FUNC void *seq_calloc_atomic(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);
|
SEQ_FUNC void *seq_realloc(void *p, size_t newsize, size_t oldsize);
|
||||||
|
@ -75,7 +75,7 @@ template <typename KV> struct GCMapAllocator : public std::allocator<KV> {
|
|||||||
|
|
||||||
template <typename KV1> GCMapAllocator(const GCMapAllocator<KV1> &) noexcept {}
|
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); }
|
void deallocate(KV *p, std::size_t n) { seq_free(p); }
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ if [ ! -f "${INSTALLDIR}/bin/llvm-config" ]; then
|
|||||||
cd "${SRCDIR}/clang/build"
|
cd "${SRCDIR}/clang/build"
|
||||||
cmake .. \
|
cmake .. \
|
||||||
-DCMAKE_BUILD_TYPE=Release \
|
-DCMAKE_BUILD_TYPE=Release \
|
||||||
|
-DLLVM_INCLUDE_TESTS=OFF \
|
||||||
-DCMAKE_INSTALL_PREFIX="${INSTALLDIR}"
|
-DCMAKE_INSTALL_PREFIX="${INSTALLDIR}"
|
||||||
make -j "${JOBS}"
|
make -j "${JOBS}"
|
||||||
make install
|
make install
|
||||||
|
Loading…
x
Reference in New Issue
Block a user