Skip to content

Commit

Permalink
Add support for LLVM 19 (#55650)
Browse files Browse the repository at this point in the history
Co-authored-by: Zentrik <[email protected]>
  • Loading branch information
Zentrik and Zentrik authored Oct 13, 2024
1 parent 7241673 commit 35bf824
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 39 deletions.
2 changes: 2 additions & 0 deletions deps/llvm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ $$(LLVM_BUILDDIR_withtype)/build-compiled: $$(SRCCACHE)/$$(LLVM_SRC_DIR)/$1.patc
LLVM_PATCH_PREV := $$(SRCCACHE)/$$(LLVM_SRC_DIR)/$1.patch-applied
endef

ifeq ($(shell test $(LLVM_VER_MAJ) -lt 19 && echo true),true)
$(eval $(call LLVM_PATCH,llvm-ittapi-cmake))
endif

ifeq ($(USE_SYSTEM_ZLIB), 0)
$(LLVM_BUILDDIR_withtype)/build-configured: | $(build_prefix)/manifest/zlib
Expand Down
6 changes: 3 additions & 3 deletions src/clangsa/GCChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ bool GCChecker::isGCTracked(const Expr *E) {

bool GCChecker::isGloballyRootedType(QualType QT) const {
return isJuliaType(
[](StringRef Name) { return Name.endswith("jl_sym_t"); }, QT);
[](StringRef Name) { return Name.ends_with("jl_sym_t"); }, QT);
}

bool GCChecker::isSafepoint(const CallEvent &Call, CheckerContext &C) const {
Expand Down Expand Up @@ -1166,10 +1166,10 @@ void GCChecker::checkDerivingExpr(const Expr *Result, const Expr *Parent,
// TODO: We may want to refine this. This is to track pointers through the
// array list in jl_module_t.
bool ParentIsModule = isJuliaType(
[](StringRef Name) { return Name.endswith("jl_module_t"); },
[](StringRef Name) { return Name.ends_with("jl_module_t"); },
Parent->getType());
bool ResultIsArrayList = isJuliaType(
[](StringRef Name) { return Name.endswith("arraylist_t"); },
[](StringRef Name) { return Name.ends_with("arraylist_t"); },
Result->getType());
if (!(ParentIsModule && ResultIsArrayList) && isGCTracked(Parent)) {
ResultTracked = false;
Expand Down
6 changes: 3 additions & 3 deletions src/debuginfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void JITDebugInfoRegistry::registerJITObject(const object::ObjectFile &Object,
uint8_t *catchjmp = NULL;
for (const object::SymbolRef &sym_iter : Object.symbols()) {
StringRef sName = cantFail(sym_iter.getName());
if (sName.equals("__UnwindData") || sName.equals("__catchjmp")) {
if (sName == "__UnwindData" || sName == "__catchjmp") {
uint64_t Addr = cantFail(sym_iter.getAddress()); // offset into object (including section offset)
auto Section = cantFail(sym_iter.getSection());
assert(Section != EndSection && Section->isText());
Expand All @@ -310,10 +310,10 @@ void JITDebugInfoRegistry::registerJITObject(const object::ObjectFile &Object,
SectionAddrCheck = SectionAddr;
SectionLoadCheck = SectionLoadAddr;
Addr += SectionLoadAddr - SectionAddr;
if (sName.equals("__UnwindData")) {
if (sName == "__UnwindData") {
UnwindData = (uint8_t*)Addr;
}
else if (sName.equals("__catchjmp")) {
else if (sName == "__catchjmp") {
catchjmp = (uint8_t*)Addr;
}
}
Expand Down
51 changes: 41 additions & 10 deletions src/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
// for outputting assembly
#include <llvm/CodeGen/AsmPrinter.h>
#include <llvm/CodeGen/AsmPrinterHandler.h>
#include <llvm/CodeGen/DebugHandlerBase.h>
#include <llvm/CodeGen/MachineModuleInfo.h>
#include <llvm/CodeGen/Passes.h>
#include <llvm/CodeGen/TargetPassConfig.h>
Expand Down Expand Up @@ -920,11 +921,17 @@ static void jl_dump_asm_internal(
// LLVM will destroy the formatted stream, and we keep the raw stream.
std::unique_ptr<formatted_raw_ostream> ustream(new formatted_raw_ostream(rstream));
std::unique_ptr<MCStreamer> Streamer(
TheTarget->createAsmStreamer(Ctx, std::move(ustream), /*asmverbose*/true,
/*useDwarfDirectory*/ true,
IP.release(),
std::move(CE), std::move(MAB),
/*ShowInst*/ false));
#if JL_LLVM_VERSION >= 190000
TheTarget->createAsmStreamer(Ctx, std::move(ustream),

IP.release(), std::move(CE), std::move(MAB))
#else
TheTarget->createAsmStreamer(Ctx, std::move(ustream), /*asmverbose*/ true,
/*useDwarfDirectory*/ true, IP.release(),
std::move(CE), std::move(MAB),
/*ShowInst*/ false)
#endif
);
Streamer->initSections(true, *STI);

// Make the MemoryObject wrapper
Expand Down Expand Up @@ -1148,7 +1155,11 @@ addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM) {
return &MMIWP->getMMI().getContext();
}

#if JL_LLVM_VERSION >= 190000
class LineNumberPrinterHandler : public DebugHandlerBase {
#else
class LineNumberPrinterHandler : public AsmPrinterHandler {
#endif
MCStreamer &S;
LineNumberAnnotatedWriter LinePrinter;
std::string Buffer;
Expand All @@ -1157,7 +1168,11 @@ class LineNumberPrinterHandler : public AsmPrinterHandler {

public:
LineNumberPrinterHandler(AsmPrinter &Printer, const char *debuginfo)
: S(*Printer.OutStreamer),
:
#if JL_LLVM_VERSION >= 190000
DebugHandlerBase(&Printer),
#endif
S(*Printer.OutStreamer),
LinePrinter("; ", true, debuginfo),
RawStream(Buffer),
Stream(RawStream) {}
Expand All @@ -1176,12 +1191,20 @@ class LineNumberPrinterHandler : public AsmPrinterHandler {
//virtual void beginModule(Module *M) override {}
virtual void endModule() override {}
/// note that some AsmPrinter implementations may not call beginFunction at all
#if JL_LLVM_VERSION >= 190000
virtual void beginFunctionImpl(const MachineFunction *MF) override {
#else
virtual void beginFunction(const MachineFunction *MF) override {
#endif
LinePrinter.emitFunctionAnnot(&MF->getFunction(), Stream);
emitAndReset();
}
//virtual void markFunctionEnd() override {}
#if JL_LLVM_VERSION >= 190000
virtual void endFunctionImpl(const MachineFunction *MF) override {
#else
virtual void endFunction(const MachineFunction *MF) override {
#endif
LinePrinter.emitEnd(Stream);
emitAndReset();
}
Expand Down Expand Up @@ -1257,15 +1280,23 @@ jl_value_t *jl_dump_function_asm_impl(jl_llvmf_dump_t* dump, char emit_mc, const
}
auto FOut = std::make_unique<formatted_raw_ostream>(asmfile);
std::unique_ptr<MCStreamer> S(TM->getTarget().createAsmStreamer(
*Context, std::move(FOut), true,
true, InstPrinter,
std::move(MCE), std::move(MAB),
false));
#if JL_LLVM_VERSION >= 190000
*Context, std::move(FOut), InstPrinter, std::move(MCE), std::move(MAB)
#else
*Context, std::move(FOut), true, true, InstPrinter, std::move(MCE),
std::move(MAB), false
#endif
));
std::unique_ptr<AsmPrinter> Printer(
TM->getTarget().createAsmPrinter(*TM, std::move(S)));
#if JL_LLVM_VERSION >= 190000
Printer->addDebugHandler(
std::make_unique<LineNumberPrinterHandler>(*Printer, debuginfo));
#else
Printer->addAsmPrinterHandler(AsmPrinter::HandlerInfo(
std::unique_ptr<AsmPrinterHandler>(new LineNumberPrinterHandler(*Printer, debuginfo)),
"emit", "Debug Info Emission", "Julia", "Julia::LineNumberPrinterHandler Markup"));
#endif
if (!Printer)
return jl_an_empty_string;
PM.add(Printer.release());
Expand Down
6 changes: 3 additions & 3 deletions src/features_x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ JL_FEATURE_DEF(avx512ifma, 32 * 2 + 21, 0)
// JL_FEATURE_DEF(pcommit, 32 * 2 + 22, 0) // Deprecated
JL_FEATURE_DEF(clflushopt, 32 * 2 + 23, 0)
JL_FEATURE_DEF(clwb, 32 * 2 + 24, 0)
JL_FEATURE_DEF(avx512pf, 32 * 2 + 26, 0)
JL_FEATURE_DEF(avx512er, 32 * 2 + 27, 0)
// JL_FEATURE_DEF(avx512pf, 32 * 2 + 26, 0) // Deprecated in LLVM 19
// JL_FEATURE_DEF(avx512er, 32 * 2 + 27, 0) // Deprecated in LLVM 19
JL_FEATURE_DEF(avx512cd, 32 * 2 + 28, 0)
JL_FEATURE_DEF(sha, 32 * 2 + 29, 0)
JL_FEATURE_DEF(avx512bw, 32 * 2 + 30, 0)
JL_FEATURE_DEF(avx512vl, 32 * 2 + 31, 0)

// EAX=7,ECX=0: ECX
JL_FEATURE_DEF(prefetchwt1, 32 * 3 + 0, 0)
// JL_FEATURE_DEF(prefetchwt1, 32 * 3 + 0, 0) // Deprecated in LLVM 19
JL_FEATURE_DEF(avx512vbmi, 32 * 3 + 1, 0)
JL_FEATURE_DEF(pku, 32 * 3 + 4, 0) // ospke
JL_FEATURE_DEF(waitpkg, 32 * 3 + 5, 0)
Expand Down
2 changes: 1 addition & 1 deletion src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1968,7 +1968,7 @@ void JuliaOJIT::enableJITDebuggingSupport()
void JuliaOJIT::enableIntelJITEventListener()
{
#if JL_LLVM_VERSION >= 190000
if (TT.isOSBinFormatELF()) {
if (TM->getTargetTriple().isOSBinFormatELF()) {
orc::SymbolMap VTuneFunctions;
auto RegisterImplAddr = addAbsoluteToMap(VTuneFunctions,llvm_orc_registerVTuneImpl);
auto UnregisterImplAddr = addAbsoluteToMap(VTuneFunctions,llvm_orc_unregisterVTuneImpl);
Expand Down
1 change: 1 addition & 0 deletions src/llvm-multiversioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <llvm-c/Types.h>

#include <llvm/Pass.h>
#include <llvm/ADT/SmallString.h>
#include <llvm/ADT/BitVector.h>
#include <llvm/ADT/Statistic.h>
#if JL_LLVM_VERSION >= 170000
Expand Down
4 changes: 2 additions & 2 deletions src/llvm-simdloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ static bool processLoop(Loop &L, OptimizationRemarkEmitter &ORE, ScalarEvolution
if (S) {
LLVM_DEBUG(dbgs() << "LSL: found " << S->getString() << "\n");
if (S->getString().starts_with("julia")) {
if (S->getString().equals("julia.simdloop"))
if (S->getString() == "julia.simdloop")
simd = true;
if (S->getString().equals("julia.ivdep"))
if (S->getString() == "julia.ivdep")
ivdep = true;
continue;
}
Expand Down
1 change: 1 addition & 0 deletions src/llvmcalltest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "llvm/Config/llvm-config.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Module.h"
#include <llvm/Support/raw_ostream.h>

#include "julia.h"
Expand Down
4 changes: 4 additions & 0 deletions src/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,8 +978,12 @@ static std::string jl_get_cpu_name_llvm(void)

static std::string jl_get_cpu_features_llvm(void)
{
#if JL_LLVM_VERSION >= 190000
auto HostFeatures = llvm::sys::getHostCPUFeatures();
#else
llvm::StringMap<bool> HostFeatures;
llvm::sys::getHostCPUFeatures(HostFeatures);
#endif
std::string attr;
for (auto &ele: HostFeatures) {
if (ele.getValue()) {
Expand Down
8 changes: 2 additions & 6 deletions src/processor_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ static constexpr FeatureDep deps[] = {
{avx512f, avx2},
{avx512dq, avx512f},
{avx512ifma, avx512f},
{avx512pf, avx512f},
{avx512er, avx512f},
{avx512cd, avx512f},
{avx512bw, avx512f},
{avx512bf16, avx512bw},
Expand Down Expand Up @@ -183,7 +181,7 @@ constexpr auto tremont = goldmont_plus | get_feature_masks(clwb, gfni);
constexpr auto knl = get_feature_masks(sse3, ssse3, sse41, sse42, cx16, sahf, popcnt,
aes, pclmul, avx, xsave, xsaveopt, rdrnd, f16c, fsgsbase,
avx2, bmi, bmi2, fma, lzcnt, movbe, adx, rdseed, prfchw,
avx512f, avx512er, avx512cd, avx512pf, prefetchwt1);
avx512f, avx512cd);
constexpr auto knm = knl | get_feature_masks(avx512vpopcntdq);
constexpr auto yonah = get_feature_masks(sse3);
constexpr auto prescott = yonah;
Expand Down Expand Up @@ -584,7 +582,7 @@ template<typename T>
static inline void features_disable_avx512(T &features)
{
using namespace Feature;
unset_bits(features, avx512f, avx512dq, avx512ifma, avx512pf, avx512er, avx512cd,
unset_bits(features, avx512f, avx512dq, avx512ifma, avx512cd,
avx512bw, avx512vl, avx512vbmi, avx512vpopcntdq, avx512vbmi2, avx512vnni,
avx512bitalg, avx512vp2intersect, avx512bf16);
}
Expand Down Expand Up @@ -948,7 +946,6 @@ static void ensure_jit_target(bool imaging)
Feature::vaes, Feature::vpclmulqdq,
Feature::sse4a, Feature::avx512f,
Feature::avx512dq, Feature::avx512ifma,
Feature::avx512pf, Feature::avx512er,
Feature::avx512cd, Feature::avx512bw,
Feature::avx512vl, Feature::avx512vbmi,
Feature::avx512vpopcntdq, Feature::avxvnni,
Expand Down Expand Up @@ -1142,7 +1139,6 @@ llvm::SmallVector<jl_target_spec_t, 0> jl_get_llvm_clone_targets(void)
Feature::vaes, Feature::vpclmulqdq,
Feature::sse4a, Feature::avx512f,
Feature::avx512dq, Feature::avx512ifma,
Feature::avx512pf, Feature::avx512er,
Feature::avx512cd, Feature::avx512bw,
Feature::avx512vl, Feature::avx512vbmi,
Feature::avx512vpopcntdq, Feature::avxvnni,
Expand Down
Loading

0 comments on commit 35bf824

Please sign in to comment.