Skip to content

Commit 35bf824

Browse files
authored
Add support for LLVM 19 (#55650)
Co-authored-by: Zentrik <[email protected]>
1 parent 7241673 commit 35bf824

File tree

12 files changed

+74
-39
lines changed

12 files changed

+74
-39
lines changed

deps/llvm.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,9 @@ $$(LLVM_BUILDDIR_withtype)/build-compiled: $$(SRCCACHE)/$$(LLVM_SRC_DIR)/$1.patc
234234
LLVM_PATCH_PREV := $$(SRCCACHE)/$$(LLVM_SRC_DIR)/$1.patch-applied
235235
endef
236236

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

239241
ifeq ($(USE_SYSTEM_ZLIB), 0)
240242
$(LLVM_BUILDDIR_withtype)/build-configured: | $(build_prefix)/manifest/zlib

src/clangsa/GCChecker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ bool GCChecker::isGCTracked(const Expr *E) {
865865

866866
bool GCChecker::isGloballyRootedType(QualType QT) const {
867867
return isJuliaType(
868-
[](StringRef Name) { return Name.endswith("jl_sym_t"); }, QT);
868+
[](StringRef Name) { return Name.ends_with("jl_sym_t"); }, QT);
869869
}
870870

871871
bool GCChecker::isSafepoint(const CallEvent &Call, CheckerContext &C) const {
@@ -1166,10 +1166,10 @@ void GCChecker::checkDerivingExpr(const Expr *Result, const Expr *Parent,
11661166
// TODO: We may want to refine this. This is to track pointers through the
11671167
// array list in jl_module_t.
11681168
bool ParentIsModule = isJuliaType(
1169-
[](StringRef Name) { return Name.endswith("jl_module_t"); },
1169+
[](StringRef Name) { return Name.ends_with("jl_module_t"); },
11701170
Parent->getType());
11711171
bool ResultIsArrayList = isJuliaType(
1172-
[](StringRef Name) { return Name.endswith("arraylist_t"); },
1172+
[](StringRef Name) { return Name.ends_with("arraylist_t"); },
11731173
Result->getType());
11741174
if (!(ParentIsModule && ResultIsArrayList) && isGCTracked(Parent)) {
11751175
ResultTracked = false;

src/debuginfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ void JITDebugInfoRegistry::registerJITObject(const object::ObjectFile &Object,
296296
uint8_t *catchjmp = NULL;
297297
for (const object::SymbolRef &sym_iter : Object.symbols()) {
298298
StringRef sName = cantFail(sym_iter.getName());
299-
if (sName.equals("__UnwindData") || sName.equals("__catchjmp")) {
299+
if (sName == "__UnwindData" || sName == "__catchjmp") {
300300
uint64_t Addr = cantFail(sym_iter.getAddress()); // offset into object (including section offset)
301301
auto Section = cantFail(sym_iter.getSection());
302302
assert(Section != EndSection && Section->isText());
@@ -310,10 +310,10 @@ void JITDebugInfoRegistry::registerJITObject(const object::ObjectFile &Object,
310310
SectionAddrCheck = SectionAddr;
311311
SectionLoadCheck = SectionLoadAddr;
312312
Addr += SectionLoadAddr - SectionAddr;
313-
if (sName.equals("__UnwindData")) {
313+
if (sName == "__UnwindData") {
314314
UnwindData = (uint8_t*)Addr;
315315
}
316-
else if (sName.equals("__catchjmp")) {
316+
else if (sName == "__catchjmp") {
317317
catchjmp = (uint8_t*)Addr;
318318
}
319319
}

src/disasm.cpp

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
// for outputting assembly
104104
#include <llvm/CodeGen/AsmPrinter.h>
105105
#include <llvm/CodeGen/AsmPrinterHandler.h>
106+
#include <llvm/CodeGen/DebugHandlerBase.h>
106107
#include <llvm/CodeGen/MachineModuleInfo.h>
107108
#include <llvm/CodeGen/Passes.h>
108109
#include <llvm/CodeGen/TargetPassConfig.h>
@@ -920,11 +921,17 @@ static void jl_dump_asm_internal(
920921
// LLVM will destroy the formatted stream, and we keep the raw stream.
921922
std::unique_ptr<formatted_raw_ostream> ustream(new formatted_raw_ostream(rstream));
922923
std::unique_ptr<MCStreamer> Streamer(
923-
TheTarget->createAsmStreamer(Ctx, std::move(ustream), /*asmverbose*/true,
924-
/*useDwarfDirectory*/ true,
925-
IP.release(),
926-
std::move(CE), std::move(MAB),
927-
/*ShowInst*/ false));
924+
#if JL_LLVM_VERSION >= 190000
925+
TheTarget->createAsmStreamer(Ctx, std::move(ustream),
926+
927+
IP.release(), std::move(CE), std::move(MAB))
928+
#else
929+
TheTarget->createAsmStreamer(Ctx, std::move(ustream), /*asmverbose*/ true,
930+
/*useDwarfDirectory*/ true, IP.release(),
931+
std::move(CE), std::move(MAB),
932+
/*ShowInst*/ false)
933+
#endif
934+
);
928935
Streamer->initSections(true, *STI);
929936

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

1158+
#if JL_LLVM_VERSION >= 190000
1159+
class LineNumberPrinterHandler : public DebugHandlerBase {
1160+
#else
11511161
class LineNumberPrinterHandler : public AsmPrinterHandler {
1162+
#endif
11521163
MCStreamer &S;
11531164
LineNumberAnnotatedWriter LinePrinter;
11541165
std::string Buffer;
@@ -1157,7 +1168,11 @@ class LineNumberPrinterHandler : public AsmPrinterHandler {
11571168

11581169
public:
11591170
LineNumberPrinterHandler(AsmPrinter &Printer, const char *debuginfo)
1160-
: S(*Printer.OutStreamer),
1171+
:
1172+
#if JL_LLVM_VERSION >= 190000
1173+
DebugHandlerBase(&Printer),
1174+
#endif
1175+
S(*Printer.OutStreamer),
11611176
LinePrinter("; ", true, debuginfo),
11621177
RawStream(Buffer),
11631178
Stream(RawStream) {}
@@ -1176,12 +1191,20 @@ class LineNumberPrinterHandler : public AsmPrinterHandler {
11761191
//virtual void beginModule(Module *M) override {}
11771192
virtual void endModule() override {}
11781193
/// note that some AsmPrinter implementations may not call beginFunction at all
1194+
#if JL_LLVM_VERSION >= 190000
1195+
virtual void beginFunctionImpl(const MachineFunction *MF) override {
1196+
#else
11791197
virtual void beginFunction(const MachineFunction *MF) override {
1198+
#endif
11801199
LinePrinter.emitFunctionAnnot(&MF->getFunction(), Stream);
11811200
emitAndReset();
11821201
}
11831202
//virtual void markFunctionEnd() override {}
1203+
#if JL_LLVM_VERSION >= 190000
1204+
virtual void endFunctionImpl(const MachineFunction *MF) override {
1205+
#else
11841206
virtual void endFunction(const MachineFunction *MF) override {
1207+
#endif
11851208
LinePrinter.emitEnd(Stream);
11861209
emitAndReset();
11871210
}
@@ -1257,15 +1280,23 @@ jl_value_t *jl_dump_function_asm_impl(jl_llvmf_dump_t* dump, char emit_mc, const
12571280
}
12581281
auto FOut = std::make_unique<formatted_raw_ostream>(asmfile);
12591282
std::unique_ptr<MCStreamer> S(TM->getTarget().createAsmStreamer(
1260-
*Context, std::move(FOut), true,
1261-
true, InstPrinter,
1262-
std::move(MCE), std::move(MAB),
1263-
false));
1283+
#if JL_LLVM_VERSION >= 190000
1284+
*Context, std::move(FOut), InstPrinter, std::move(MCE), std::move(MAB)
1285+
#else
1286+
*Context, std::move(FOut), true, true, InstPrinter, std::move(MCE),
1287+
std::move(MAB), false
1288+
#endif
1289+
));
12641290
std::unique_ptr<AsmPrinter> Printer(
12651291
TM->getTarget().createAsmPrinter(*TM, std::move(S)));
1292+
#if JL_LLVM_VERSION >= 190000
1293+
Printer->addDebugHandler(
1294+
std::make_unique<LineNumberPrinterHandler>(*Printer, debuginfo));
1295+
#else
12661296
Printer->addAsmPrinterHandler(AsmPrinter::HandlerInfo(
12671297
std::unique_ptr<AsmPrinterHandler>(new LineNumberPrinterHandler(*Printer, debuginfo)),
12681298
"emit", "Debug Info Emission", "Julia", "Julia::LineNumberPrinterHandler Markup"));
1299+
#endif
12691300
if (!Printer)
12701301
return jl_an_empty_string;
12711302
PM.add(Printer.release());

src/features_x86.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ JL_FEATURE_DEF(avx512ifma, 32 * 2 + 21, 0)
4545
// JL_FEATURE_DEF(pcommit, 32 * 2 + 22, 0) // Deprecated
4646
JL_FEATURE_DEF(clflushopt, 32 * 2 + 23, 0)
4747
JL_FEATURE_DEF(clwb, 32 * 2 + 24, 0)
48-
JL_FEATURE_DEF(avx512pf, 32 * 2 + 26, 0)
49-
JL_FEATURE_DEF(avx512er, 32 * 2 + 27, 0)
48+
// JL_FEATURE_DEF(avx512pf, 32 * 2 + 26, 0) // Deprecated in LLVM 19
49+
// JL_FEATURE_DEF(avx512er, 32 * 2 + 27, 0) // Deprecated in LLVM 19
5050
JL_FEATURE_DEF(avx512cd, 32 * 2 + 28, 0)
5151
JL_FEATURE_DEF(sha, 32 * 2 + 29, 0)
5252
JL_FEATURE_DEF(avx512bw, 32 * 2 + 30, 0)
5353
JL_FEATURE_DEF(avx512vl, 32 * 2 + 31, 0)
5454

5555
// EAX=7,ECX=0: ECX
56-
JL_FEATURE_DEF(prefetchwt1, 32 * 3 + 0, 0)
56+
// JL_FEATURE_DEF(prefetchwt1, 32 * 3 + 0, 0) // Deprecated in LLVM 19
5757
JL_FEATURE_DEF(avx512vbmi, 32 * 3 + 1, 0)
5858
JL_FEATURE_DEF(pku, 32 * 3 + 4, 0) // ospke
5959
JL_FEATURE_DEF(waitpkg, 32 * 3 + 5, 0)

src/jitlayers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1968,7 +1968,7 @@ void JuliaOJIT::enableJITDebuggingSupport()
19681968
void JuliaOJIT::enableIntelJITEventListener()
19691969
{
19701970
#if JL_LLVM_VERSION >= 190000
1971-
if (TT.isOSBinFormatELF()) {
1971+
if (TM->getTargetTriple().isOSBinFormatELF()) {
19721972
orc::SymbolMap VTuneFunctions;
19731973
auto RegisterImplAddr = addAbsoluteToMap(VTuneFunctions,llvm_orc_registerVTuneImpl);
19741974
auto UnregisterImplAddr = addAbsoluteToMap(VTuneFunctions,llvm_orc_unregisterVTuneImpl);

src/llvm-multiversioning.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <llvm-c/Types.h>
1313

1414
#include <llvm/Pass.h>
15+
#include <llvm/ADT/SmallString.h>
1516
#include <llvm/ADT/BitVector.h>
1617
#include <llvm/ADT/Statistic.h>
1718
#if JL_LLVM_VERSION >= 170000

src/llvm-simdloop.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ static bool processLoop(Loop &L, OptimizationRemarkEmitter &ORE, ScalarEvolution
178178
if (S) {
179179
LLVM_DEBUG(dbgs() << "LSL: found " << S->getString() << "\n");
180180
if (S->getString().starts_with("julia")) {
181-
if (S->getString().equals("julia.simdloop"))
181+
if (S->getString() == "julia.simdloop")
182182
simd = true;
183-
if (S->getString().equals("julia.ivdep"))
183+
if (S->getString() == "julia.ivdep")
184184
ivdep = true;
185185
continue;
186186
}

src/llvmcalltest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "llvm/Config/llvm-config.h"
88
#include "llvm/IR/IRBuilder.h"
9+
#include "llvm/IR/Module.h"
910
#include <llvm/Support/raw_ostream.h>
1011

1112
#include "julia.h"

src/processor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,8 +978,12 @@ static std::string jl_get_cpu_name_llvm(void)
978978

979979
static std::string jl_get_cpu_features_llvm(void)
980980
{
981+
#if JL_LLVM_VERSION >= 190000
982+
auto HostFeatures = llvm::sys::getHostCPUFeatures();
983+
#else
981984
llvm::StringMap<bool> HostFeatures;
982985
llvm::sys::getHostCPUFeatures(HostFeatures);
986+
#endif
983987
std::string attr;
984988
for (auto &ele: HostFeatures) {
985989
if (ele.getValue()) {

0 commit comments

Comments
 (0)