Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump LLVM to v18 #54848

Merged
merged 21 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
216 changes: 108 additions & 108 deletions deps/checksums/clang

Large diffs are not rendered by default.

216 changes: 108 additions & 108 deletions deps/checksums/lld

Large diffs are not rendered by default.

436 changes: 218 additions & 218 deletions deps/checksums/llvm

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deps/clang.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
## jll artifact
# Clang (paired with LLVM, only here as a JLL download)
CLANG_JLL_NAME := Clang
CLANG_JLL_VER := 17.0.6+4
CLANG_JLL_VER := 18.1.7+2
2 changes: 1 addition & 1 deletion deps/lld.version
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

## jll artifact
LLD_JLL_NAME := LLD
LLD_JLL_VER := 17.0.6+4
LLD_JLL_VER := 18.1.7+2
4 changes: 2 additions & 2 deletions deps/llvm-tools.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
## jll artifact
# LLVM_tools (downloads LLVM_jll to get things like `lit` and `opt`)
LLVM_TOOLS_JLL_NAME := LLVM
LLVM_TOOLS_JLL_VER := 17.0.6+4
LLVM_TOOLS_ASSERT_JLL_VER := 17.0.6+4
LLVM_TOOLS_JLL_VER := 18.1.7+2
LLVM_TOOLS_ASSERT_JLL_VER := 18.1.7+2
12 changes: 6 additions & 6 deletions deps/llvm.version
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

## jll artifact
LLVM_JLL_NAME := libLLVM
LLVM_ASSERT_JLL_VER := 17.0.6+4
LLVM_ASSERT_JLL_VER := 18.1.7+2
## source build
# Version number of LLVM
LLVM_VER := 17.0.6
LLVM_VER := 18.1.7
# Git branch name in `LLVM_GIT_URL` repository
LLVM_BRANCH=julia-17.0.6-4
LLVM_BRANCH=julia-18.1.7-2
# Git ref in `LLVM_GIT_URL` repository
LLVM_SHA1=julia-17.0.6-4
LLVM_SHA1=julia-18.1.7-2

## Following options are used to automatically fetch patchset from Julia's fork. This is
## useful if you want to build an external LLVM while still applying Julia's patches.
Expand All @@ -18,6 +18,6 @@ LLVM_APPLY_JULIA_PATCHES := 0
# GitHub repository to use for fetching the Julia patches to apply to LLVM source code.
LLVM_JULIA_DIFF_GITHUB_REPO := https://github.com/llvm/llvm-project
# Base GitHub ref for generating the diff.
LLVM_BASE_REF := llvm:llvmorg-17.0.6
LLVM_BASE_REF := llvm:llvmorg-18.1.7
# Julia fork's GitHub ref for generating the diff.
LLVM_JULIA_REF := JuliaLang:julia-17.0.6-4
LLVM_JULIA_REF := JuliaLang:julia-18.1.7-2
70 changes: 36 additions & 34 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,9 @@

// analysis passes
#include <llvm/Analysis/Passes.h>
#include <llvm/Analysis/BasicAliasAnalysis.h>
#include <llvm/Analysis/TypeBasedAliasAnalysis.h>
#include <llvm/Analysis/ScopedNoAliasAA.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/PassManager.h>
#include <llvm/IR/Verifier.h>
#include <llvm/Transforms/IPO.h>
#include <llvm/Transforms/Scalar.h>
#include <llvm/Transforms/Vectorize.h>
#include <llvm/Transforms/Instrumentation/AddressSanitizer.h>
#include <llvm/Transforms/Instrumentation/MemorySanitizer.h>
#include <llvm/Transforms/Instrumentation/ThreadSanitizer.h>
#include <llvm/Transforms/Scalar/GVN.h>
#include <llvm/Transforms/IPO/AlwaysInliner.h>
#include <llvm/Transforms/InstCombine/InstCombine.h>
#include <llvm/Transforms/Scalar/InstSimplifyPass.h>
#include <llvm/Transforms/Scalar/SimpleLoopUnswitch.h>
#include <llvm/Transforms/Utils/SimplifyCFGOptions.h>
#include <llvm/Transforms/Utils/ModuleUtils.h>
#include <llvm/Passes/PassBuilder.h>
#include <llvm/Passes/PassPlugin.h>
Expand Down Expand Up @@ -1164,7 +1149,11 @@ static AOTOutputs add_output_impl(Module &M, TargetMachine &SourceTM, ShardTimer
raw_svector_ostream OS(out.obj);
legacy::PassManager emitter;
addTargetPasses(&emitter, TM->getTargetTriple(), TM->getTargetIRAnalysis());
#if JL_LLVM_VERSION >= 180000
if (TM->addPassesToEmitFile(emitter, OS, nullptr, CodeGenFileType::ObjectFile, false))
#else
if (TM->addPassesToEmitFile(emitter, OS, nullptr, CGFT_ObjectFile, false))
#endif
jl_safe_printf("ERROR: target does not support generation of object files\n");
emitter.run(M);
timers.obj.stopTimer();
Expand All @@ -1175,7 +1164,11 @@ static AOTOutputs add_output_impl(Module &M, TargetMachine &SourceTM, ShardTimer
raw_svector_ostream OS(out.asm_);
legacy::PassManager emitter;
addTargetPasses(&emitter, TM->getTargetTriple(), TM->getTargetIRAnalysis());
#if JL_LLVM_VERSION >= 180000
if (TM->addPassesToEmitFile(emitter, OS, nullptr, CodeGenFileType::AssemblyFile, false))
#else
if (TM->addPassesToEmitFile(emitter, OS, nullptr, CGFT_AssemblyFile, false))
#endif
jl_safe_printf("ERROR: target does not support generation of assembly files\n");
emitter.run(M);
timers.asm_.stopTimer();
Expand Down Expand Up @@ -1632,7 +1625,11 @@ void jl_dump_native_impl(void *native_code,
jl_ExecutionEngine->getTargetOptions(),
RelocModel,
CMModel,
#if JL_LLVM_VERSION >= 180000
CodeGenOptLevel::Aggressive // -O3 TODO: respect command -O0 flag?
#else
CodeGenOpt::Aggressive // -O3 TODO: respect command -O0 flag?
#endif
));
fixupTM(*SourceTM);
auto DL = jl_create_datalayout(*SourceTM);
Expand Down Expand Up @@ -1892,26 +1889,31 @@ void jl_dump_native_impl(void *native_code,
JL_TIMING(NATIVE_AOT, NATIVE_Write);

object::Archive::Kind Kind = getDefaultForHost(TheTriple);
#if JL_LLVM_VERSION >= 180000
#define WritingMode SymtabWritingMode::NormalSymtab
#else
#define WritingMode true
#endif
#define WRITE_ARCHIVE(fname, field, prefix, suffix) \
if (fname) {\
SmallVector<NewArchiveMember, 0> archive; \
SmallVector<std::string, 16> filenames; \
SmallVector<StringRef, 16> buffers; \
for (size_t i = 0; i < threads; i++) { \
filenames.push_back((StringRef("text") + prefix + "#" + Twine(i) + suffix).str()); \
buffers.push_back(StringRef(data_outputs[i].field.data(), data_outputs[i].field.size())); \
} \
filenames.push_back("metadata" prefix suffix); \
buffers.push_back(StringRef(metadata_outputs[0].field.data(), metadata_outputs[0].field.size())); \
if (z) { \
filenames.push_back("sysimg" prefix suffix); \
buffers.push_back(StringRef(sysimg_outputs[0].field.data(), sysimg_outputs[0].field.size())); \
} \
for (size_t i = 0; i < filenames.size(); i++) { \
archive.push_back(NewArchiveMember(MemoryBufferRef(buffers[i], filenames[i]))); \
} \
handleAllErrors(writeArchive(fname, archive, true, Kind, true, false), reportWriterError); \
}
if (fname) {\
SmallVector<NewArchiveMember, 0> archive; \
SmallVector<std::string, 16> filenames; \
SmallVector<StringRef, 16> buffers; \
for (size_t i = 0; i < threads; i++) { \
filenames.push_back((StringRef("text") + prefix + "#" + Twine(i) + suffix).str()); \
buffers.push_back(StringRef(data_outputs[i].field.data(), data_outputs[i].field.size())); \
} \
filenames.push_back("metadata" prefix suffix); \
buffers.push_back(StringRef(metadata_outputs[0].field.data(), metadata_outputs[0].field.size())); \
if (z) { \
filenames.push_back("sysimg" prefix suffix); \
buffers.push_back(StringRef(sysimg_outputs[0].field.data(), sysimg_outputs[0].field.size())); \
} \
for (size_t i = 0; i < filenames.size(); i++) { \
archive.push_back(NewArchiveMember(MemoryBufferRef(buffers[i], filenames[i]))); \
} \
handleAllErrors(writeArchive(fname, archive, WritingMode, Kind, true, false), reportWriterError); \
}

WRITE_ARCHIVE(unopt_bc_fname, unopt, "_unopt", ".bc");
WRITE_ARCHIVE(bc_fname, opt, "_opt", ".bc");
Expand Down
2 changes: 1 addition & 1 deletion src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2108,7 +2108,7 @@ jl_cgval_t function_sig_t::emit_a_ccall(
if (!isa<Function>(llvmf) || cast<Function>(llvmf)->isIntrinsic() || cast<Function>(llvmf)->getFunctionType() != functype)
llvmf = NULL;
}
else if (f_name.startswith("llvm.")) {
else if (f_name.starts_with("llvm.")) {
// compute and verify auto-mangling for intrinsic name
auto ID = Function::lookupIntrinsicID(f_name);
if (ID != Intrinsic::not_intrinsic) {
Expand Down
12 changes: 6 additions & 6 deletions src/clangsa/GCChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ bool GCChecker::isFDAnnotatedNotSafepoint(const clang::FunctionDecl *FD, const S
SourceLocation Loc = FD->getLocation();
StringRef Name = SM.getFilename(Loc);
Name = llvm::sys::path::filename(Name);
if (Name.startswith("llvm-"))
if (Name.starts_with("llvm-"))
return true;
return false;
}
Expand Down Expand Up @@ -911,9 +911,9 @@ bool GCChecker::isSafepoint(const CallEvent &Call, CheckerContext &C) const {
if (FD->getBuiltinID() != 0 || FD->isTrivial())
isCalleeSafepoint = false;
else if (FD->getDeclName().isIdentifier() &&
(FD->getName().startswith("uv_") ||
FD->getName().startswith("unw_") ||
FD->getName().startswith("_U")) &&
(FD->getName().starts_with("uv_") ||
FD->getName().starts_with("unw_") ||
FD->getName().starts_with("_U")) &&
FD->getName() != "uv_run")
isCalleeSafepoint = false;
else
Expand Down Expand Up @@ -1050,13 +1050,13 @@ bool GCChecker::processAllocationOfResult(const CallEvent &Call,
// global roots.
StringRef FDName =
FD->getDeclName().isIdentifier() ? FD->getName() : "";
if (FDName.startswith("jl_box_") || FDName.startswith("ijl_box_")) {
if (FDName.starts_with("jl_box_") || FDName.starts_with("ijl_box_")) {
SVal Arg = Call.getArgSVal(0);
if (auto CI = Arg.getAs<nonloc::ConcreteInt>()) {
const llvm::APSInt &Value = CI->getValue();
bool GloballyRooted = false;
const int64_t NBOX_C = 1024;
if (FDName.startswith("jl_box_u") || FDName.startswith("ijl_box_u")) {
if (FDName.starts_with("jl_box_u") || FDName.starts_with("ijl_box_u")) {
if (Value < NBOX_C) {
GloballyRooted = true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,7 @@ static GlobalVariable *get_pointer_to_constant(jl_codegen_params_t &emission_con
gv = get_gv(gvname);
}
}
assert(gv->getName().startswith(name.str()));
assert(gv->getName().starts_with(name.str()));
assert(val == gv->getInitializer());
return gv;
}
Expand Down Expand Up @@ -8846,7 +8846,7 @@ static jl_llvm_functions_t
!jl_is_submodule(mod, jl_core_module));
};
auto in_tracked_path = [] (StringRef file) { // falls within an explicitly set file or directory
return jl_options.tracked_path != NULL && file.startswith(jl_options.tracked_path);
return jl_options.tracked_path != NULL && file.starts_with(jl_options.tracked_path);
};
bool mod_is_user_mod = in_user_mod(ctx.module);
bool mod_is_tracked = in_tracked_path(ctx.file);
Expand Down Expand Up @@ -9638,7 +9638,7 @@ static jl_llvm_functions_t
// make sure that anything we attempt to call has some inlining info, just in case optimization messed up
// (except if we know that it is an intrinsic used in our prologue, which should never have its own debug subprogram)
Function *F = call->getCalledFunction();
if (!in_prologue || !F || !(F->isIntrinsic() || F->getName().startswith("julia.") || &I == restTuple)) {
if (!in_prologue || !F || !(F->isIntrinsic() || F->getName().starts_with("julia.") || &I == restTuple)) {
I.setDebugLoc(topdebugloc);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/coverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ extern "C" JL_DLLEXPORT void jl_write_coverage_data(const char *output)
{
if (output) {
StringRef output_pattern(output);
if (output_pattern.endswith(".info"))
if (output_pattern.ends_with(".info"))
write_lcov_data(coverageData, jl_format_filename(output_pattern.str().c_str()));
}
else {
Expand Down
4 changes: 4 additions & 0 deletions src/datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,10 @@ JL_DLLEXPORT jl_datatype_t *jl_new_primitivetype(jl_value_t *name, jl_module_t *
jl_emptysvec, jl_emptysvec, jl_emptysvec, 0, 0, 0);
uint32_t nbytes = (nbits + 7) / 8;
uint32_t alignm = next_power_of_two(nbytes);
# if defined(_CPU_X86_) && !defined(_OS_WINDOWS_)
if (alignm == 8)
gbaraldi marked this conversation as resolved.
Show resolved Hide resolved
alignm = 4;
# endif
if (alignm > MAX_ALIGN)
alignm = MAX_ALIGN;
// memoize isprimitivetype, since it is much easier than checking
Expand Down
4 changes: 4 additions & 0 deletions src/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,11 @@ jl_value_t *jl_dump_function_asm_impl(jl_llvmf_dump_t* dump, char emit_mc, const
addTargetPasses(&PM, TM->getTargetTriple(), TM->getTargetIRAnalysis());
if (emit_mc) {
raw_svector_ostream obj_OS(ObjBufferSV);
#if JL_LLVM_VERSION >= 180000
if (TM->addPassesToEmitFile(PM, obj_OS, nullptr, CodeGenFileType::ObjectFile, false, nullptr))
#else
if (TM->addPassesToEmitFile(PM, obj_OS, nullptr, CGFT_ObjectFile, false, nullptr))
#endif
return jl_an_empty_string;
TSM->withModuleDo([&](Module &m) { PM.run(m); });
}
Expand Down
45 changes: 36 additions & 9 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "llvm-version.h"
#include "platform.h"
#include <stdint.h>
#include <sstream>
#include <string>

#include "llvm/IR/Mangler.h"
#include <llvm/ADT/Statistic.h>
Expand Down Expand Up @@ -42,7 +42,11 @@ using namespace llvm;
#include "julia_assert.h"
#include "processor.h"

#if JL_LLVM_VERSION >= 180000
# include <llvm/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.h>
#else
# include <llvm/ExecutionEngine/Orc/DebuggerSupportPlugin.h>
#endif
# include <llvm/ExecutionEngine/JITLink/EHFrameSupport.h>
# include <llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h>
# include <llvm/ExecutionEngine/Orc/MapperJITLinkMemoryManager.h>
Expand Down Expand Up @@ -564,6 +568,19 @@ jl_value_t *jl_dump_method_asm_impl(jl_method_instance_t *mi, size_t world,
return jl_an_empty_string;
}

#if JL_LLVM_VERSION >= 180000
CodeGenOptLevel CodeGenOptLevelFor(int optlevel)
{
#ifdef DISABLE_OPT
return CodeGenOptLevel::None;
#else
return optlevel == 0 ? CodeGenOptLevel::None :
optlevel == 1 ? CodeGenOptLevel::Less :
optlevel == 2 ? CodeGenOptLevel::Default :
CodeGenOptLevel::Aggressive;
#endif
}
#else
CodeGenOpt::Level CodeGenOptLevelFor(int optlevel)
{
#ifdef DISABLE_OPT
Expand All @@ -575,6 +592,7 @@ CodeGenOpt::Level CodeGenOptLevelFor(int optlevel)
CodeGenOpt::Aggressive;
#endif
}
#endif

static auto countBasicBlocks(const Function &F) JL_NOTSAFEPOINT
{
Expand All @@ -589,7 +607,7 @@ static Expected<orc::ThreadSafeModule> validateExternRelocations(orc::ThreadSafe
auto F = dyn_cast<Function>(&GO);
if (!F)
return false;
return F->isIntrinsic() || F->getName().startswith("julia.");
return F->isIntrinsic() || F->getName().starts_with("julia.");
};
// validate the relocations for M (only for RuntimeDyld, JITLink performs its own symbol validation)
auto Err = TSM.withModuleDo([isIntrinsicFunction](Module &M) JL_NOTSAFEPOINT {
Expand Down Expand Up @@ -1157,7 +1175,7 @@ namespace {
{
if (*jl_ExecutionEngine->get_dump_llvm_opt_stream()) {
for (auto &F : M.functions()) {
if (F.isDeclaration() || F.getName().startswith("jfptr_")) {
if (F.isDeclaration() || F.getName().starts_with("jfptr_")) {
continue;
}
// Each function is printed as a YAML object with several attributes
Expand Down Expand Up @@ -1210,7 +1228,7 @@ namespace {
// Print LLVM function statistics _after_ optimization
ios_printf(stream, " after: \n");
for (auto &F : M.functions()) {
if (F.isDeclaration() || F.getName().startswith("jfptr_")) {
if (F.isDeclaration() || F.getName().starts_with("jfptr_")) {
continue;
}
Stat(F).dump(stream);
Expand Down Expand Up @@ -1397,7 +1415,7 @@ struct JuliaOJIT::DLSymOptimizer {
void operator()(Module &M) {
for (auto &GV : M.globals()) {
auto Name = GV.getName();
if (Name.startswith("jlplt") && Name.endswith("got")) {
if (Name.starts_with("jlplt") && Name.ends_with("got")) {
auto fname = GV.getAttribute("julia.fname").getValueAsString().str();
void *addr;
if (GV.hasAttribute("julia.libname")) {
Expand Down Expand Up @@ -1651,7 +1669,7 @@ JuliaOJIT::JuliaOJIT()
DL.getGlobalPrefix(),
[&](const orc::SymbolStringPtr &S) {
const char *const atomic_prefix = "__atomic_";
return (*S).startswith(atomic_prefix);
return (*S).starts_with(atomic_prefix);
})));
}
}
Expand Down Expand Up @@ -2208,8 +2226,15 @@ static void jl_decorate_module(Module &M) {
// Add special values used by debuginfo to build the UnwindData table registration for Win64
// This used to be GV, but with https://reviews.llvm.org/D100944 we no longer can emit GV into `.text`
// TODO: The data is set in debuginfo.cpp but it should be okay to actually emit it here.
M.appendModuleInlineAsm("\
.section .text \n\
std::string inline_asm = "\
.section ";
inline_asm +=
#if JL_LLVM_VERSION >= 180000
".ltext,\"ax\",@progbits";
#else
".text";
#endif
inline_asm += "\n\
.type __UnwindData,@object \n\
.p2align 2, 0x90 \n\
__UnwindData: \n\
Expand All @@ -2220,7 +2245,9 @@ static void jl_decorate_module(Module &M) {
.p2align 2, 0x90 \n\
__catchjmp: \n\
.zero 12 \n\
.size __catchjmp, 12");
.size __catchjmp, 12";

M.appendModuleInlineAsm(inline_asm);
}
}

Expand Down
Loading