Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ccfbf78
Move llvmlite to llvm19
yashssh Mar 26, 2025
04a1f68
Support building with LLVM20, add back codegen time passes APIs
yashssh May 29, 2025
47e299f
Remove LLVMLITE_ALIGN macro and unused value in LLVMPY_LLJIT_Link
yashssh May 29, 2025
30de275
Fix X86 failing tests with LLVM20
yashssh Jul 24, 2025
61d5d4e
Skip broken test_global_ctors_dtors on Darwin
yashssh Jul 24, 2025
3d81f0c
Reformat LLVM version check
yashssh Aug 20, 2025
9822d62
Merge branch 'main' into yashwants/llvm19
yashssh Aug 20, 2025
095858d
Comment out deperecated GDBJITDebugInfoRegistrationPlugin code causin…
yashssh Aug 20, 2025
b8843db
update conda channel for llvm-20 on wheel builder workflows
swap357 Aug 21, 2025
dce9f50
update conda channel for llvm-20 on conda builder workflow
swap357 Aug 21, 2025
d82bd05
update azure ci config and conda setup scripts to support llvmdev-20
swap357 Aug 21, 2025
0c6819a
update conda channel for llvm-20 on manylinux build script
swap357 Aug 21, 2025
c2a7629
update llvmdev version to 20.* on llvmlite conda recipe
swap357 Aug 21, 2025
30d21ef
update test_binding.py to assert llvm_assertions_state as "on" for al…
swap357 Aug 21, 2025
e6ff790
update llvm version on environment.yml and docs to 20.1.0
swap357 Aug 21, 2025
c17ba17
add ntdll.dll to expected imports on validate_win-64_wheel.py
swap357 Aug 21, 2025
990845a
add ntdll to expected imports on TestBuild for windows
swap357 Aug 21, 2025
c6b40c4
add ntdll to win wheel expected imports on TestBuild
swap357 Aug 21, 2025
23f78c8
add zstd to expected imports for windows conda on TestBuild
swap357 Aug 21, 2025
5f3e5bc
add corefoundation to expected imports for osx-64 conda and wheel on …
swap357 Aug 21, 2025
a67b9e9
add variables parameter to azure pipelines CI configs
swap357 Aug 21, 2025
de71d45
resolve flake8 issue on test_binding.py
swap357 Aug 21, 2025
d30d7c6
update llvmlite conda builder workflow to use py 3.12 on base
swap357 Aug 21, 2025
9cf580a
update llvmlite conda builder workflow to activate 'base' environment
swap357 Aug 21, 2025
03b6bb1
update llvmlite conda builder workflow to activate 'cibuild' environment
swap357 Aug 21, 2025
6f13d29
Run clang-format20 on ffi/*.cpp files
yashssh Aug 22, 2025
cda85cc
simplify llvmdev installation on setup scripts, remove support for ll…
swap357 Aug 22, 2025
390db9f
Apply suggestions from code review, use llvmdev=20
swap357 Aug 25, 2025
ed00df8
Apply suggestions from code review, remove py3.12 pin from miniconda …
swap357 Aug 25, 2025
299b412
add OrcDebugging
swap357 Aug 25, 2025
7d4fe41
Change initialize() to hard error out with useful information
sklam Aug 25, 2025
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
1 change: 0 additions & 1 deletion docs/source/user-guide/examples/ll_fpadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


# All these initializations are required for code generation!
llvm.initialize()
llvm.initialize_native_target()
llvm.initialize_native_asmprinter() # yes, even this one

Expand Down
1 change: 0 additions & 1 deletion docs/source/user-guide/examples/parseasm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from llvmlite import binding as llvm
from llvmlite import ir as lc

llvm.initialize()
llvm.initialize_native_target()
llvm.initialize_native_asmprinter()

Expand Down
1 change: 0 additions & 1 deletion docs/source/user-guide/examples/sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import llvmlite.binding as llvm


llvm.initialize()
llvm.initialize_native_target()
llvm.initialize_native_asmprinter()

Expand Down
1 change: 0 additions & 1 deletion examples/ll_fpadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


# All these initializations are required for code generation!
llvm.initialize()
llvm.initialize_native_target()
llvm.initialize_native_asmprinter() # yes, even this one

Expand Down
1 change: 0 additions & 1 deletion examples/lljit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import llvmlite.binding as llvm
import numpy as np

llvm.initialize()
llvm.initialize_native_target()
llvm.initialize_native_asmprinter() # yes, even this one

Expand Down
1 change: 0 additions & 1 deletion examples/npm_passes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
faulthandler.enable()

# All are required to initialize LLVM
llvm.initialize()
llvm.initialize_native_target()
llvm.initialize_native_asmprinter()

Expand Down
1 change: 0 additions & 1 deletion examples/npm_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
faulthandler.enable()

# All are required to initialize LLVM
llvm.initialize()
llvm.initialize_native_target()
llvm.initialize_native_asmprinter()

Expand Down
1 change: 0 additions & 1 deletion examples/opaque_pointers/sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import llvmlite.binding as llvm


llvm.initialize()
llvm.initialize_native_target()
llvm.initialize_native_asmprinter()

Expand Down
1 change: 0 additions & 1 deletion examples/parseasm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from llvmlite import binding as llvm
from llvmlite import ir as lc

llvm.initialize()
llvm.initialize_native_target()
llvm.initialize_native_asmprinter()

Expand Down
1 change: 0 additions & 1 deletion examples/sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import llvmlite.binding as llvm


llvm.initialize()
llvm.initialize_native_target()
llvm.initialize_native_asmprinter()

Expand Down
4 changes: 2 additions & 2 deletions ffi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ endif()

# Define our shared library
add_library(llvmlite SHARED assembly.cpp bitcode.cpp core.cpp initfini.cpp
module.cpp value.cpp executionengine.cpp transforms.cpp type.cpp
passmanagers.cpp targets.cpp dylib.cpp linker.cpp object_file.cpp
module.cpp value.cpp executionengine.cpp type.cpp
targets.cpp dylib.cpp linker.cpp object_file.cpp
custom_passes.cpp orcjit.cpp memorymanager.cpp newpassmanagers.cpp)

# Find the libraries that correspond to the LLVM components
Expand Down
2 changes: 1 addition & 1 deletion ffi/Makefile.freebsd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LDFLAGS := $(LDFLAGS) $(LLVM_LDFLAGS) $(LD_FLTO_FLAGS)
LIBS = $(LLVM_LIBS)
INCLUDE = core.h
SRC = assembly.cpp bitcode.cpp core.cpp initfini.cpp module.cpp value.cpp \
executionengine.cpp transforms.cpp passmanagers.cpp type.cpp targets.cpp \
executionengine.cpp type.cpp targets.cpp \
dylib.cpp linker.cpp object_file.cpp orcjit.cpp custom_passes.cpp \
memorymanager.cpp newpassmanagers.cpp
OUTPUT = libllvmlite.so
Expand Down
2 changes: 1 addition & 1 deletion ffi/Makefile.linux
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ LDFLAGS := $(LDFLAGS) $(LLVM_LDFLAGS) $(LD_FLTO_FLAGS)
LIBS = $(LLVM_LIBS)
INCLUDE = core.h
OBJ = assembly.o bitcode.o core.o initfini.o module.o value.o \
executionengine.o transforms.o passmanagers.o targets.o type.o dylib.o \
executionengine.o targets.o type.o dylib.o \
linker.o object_file.o custom_passes.o orcjit.o memorymanager.o newpassmanagers.o
OUTPUT = libllvmlite.so

Expand Down
2 changes: 1 addition & 1 deletion ffi/Makefile.osx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LDFLAGS := $(LDFLAGS) $(EXPORT) $(LLVM_LDFLAGS)
LIBS = $(LLVM_LIBS)
INCLUDE = core.h
SRC = assembly.cpp bitcode.cpp core.cpp initfini.cpp module.cpp value.cpp \
executionengine.cpp transforms.cpp passmanagers.cpp targets.cpp type.cpp \
executionengine.cpp targets.cpp type.cpp \
dylib.cpp linker.cpp object_file.cpp custom_passes.cpp orcjit.cpp \
memorymanager.cpp newpassmanagers.cpp
OUTPUT = libllvmlite.dylib
Expand Down
1 change: 0 additions & 1 deletion ffi/PASSREGISTRY.def
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ MODULE_PASS("sample-profile", SampleProfileLoaderPass())
MODULE_PASS("scc-oz-module-inliner",buildInlinerPipeline(OptimizationLevel::Oz, ThinOrFullLTOPhase::None))
MODULE_PASS("pseudo-probe", SampleProfileProbePass(TM))
MODULE_PASS("strip-nonlinetable-debuginfo", StripNonLineTableDebugInfoPass())
MODULE_PASS("synthetic-counts-propagation", SyntheticCountsPropagation())
MODULE_PASS("trigger-crash", TriggerCrashPass())
MODULE_PASS("verify", VerifierPass())
MODULE_PASS("view-callgraph", CallGraphViewerPass())
Expand Down
20 changes: 12 additions & 8 deletions ffi/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,21 @@ def main_posix(kind, library_ext):
else:
(version, _) = out.split('.', 1)
version = int(version)
if version == 16:
msg = ("Building with LLVM 16; note that LLVM 16 support is "
"presently experimental")
if version == 20:
pass
elif version > 20:
msg = ("WARNING: Building llvmlite with LLVM version > 20 ({!r}) "
"is untested and may result in problems. Be sure to set "
"LLVM_CONFIG to the right executable path.\nRead the "
"documentation at http://llvmlite.pydata.org/ for more "
"information about building llvmlite.\n".format(version))
show_warning(msg)
elif version != 15:

msg = ("Building llvmlite requires LLVM 15, got "
"{!r}. Be sure to set LLVM_CONFIG to the right executable "
else:
msg = (f"Building llvmlite requires LLVM 20, got {version!r}. "
"Be sure to set LLVM_CONFIG to the right executable "
"path.\nRead the documentation at "
"http://llvmlite.pydata.org/ for more information about "
"building llvmlite.\n".format(out.strip()))
"building llvmlite.\n")
raise RuntimeError(msg)

# Get LLVM information for building
Expand Down
4 changes: 0 additions & 4 deletions ffi/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ LLVMPY_DisposeString(const char *msg) { free(const_cast<char *>(msg)); }
API_EXPORT(LLVMContextRef)
LLVMPY_GetGlobalContext() {
auto context = LLVMGetGlobalContext();
// FIXME: Remove with LLVM >= 17.
LLVMContextSetOpaquePointers(context, true);
return context;
}

API_EXPORT(LLVMContextRef)
LLVMPY_ContextCreate() {
LLVMContextRef context = LLVMContextCreate();
// FIXME: Remove with LLVM >= 17.
LLVMContextSetOpaquePointers(context, true);
return context;
}

Expand Down
78 changes: 4 additions & 74 deletions ffi/custom_passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include "llvm/Analysis/PostDominators.h"
#include "llvm/Support/raw_ostream.h"

#include "llvm/IR/LegacyPassManager.h"

#include "llvm/InitializePasses.h"
#include "llvm/LinkAllPasses.h"

Expand All @@ -25,11 +23,6 @@

using namespace llvm;

namespace llvm {
void initializeRefNormalizeLegacyPassPass(PassRegistry &Registry);
void initializeRefPruneLegacyPassPass(PassRegistry &Registry);
} // namespace llvm

namespace llvm {
struct OpaqueModulePassManager;
typedef OpaqueModulePassManager *LLVMModulePassManagerRef;
Expand Down Expand Up @@ -960,7 +953,7 @@ struct RefPrune {
auto name = dyn_cast<StoreInst>(&instruction)
->getPointerOperand()
->getName();
if (name.equals("excinfo") &&
if (name.compare("excinfo") == 0 &&
instruction.hasMetadata("numba_exception_output")) {
return true;
}
Expand Down Expand Up @@ -1192,84 +1185,21 @@ class RefNormalizePass : public PassInfoMixin<RefNormalizePass> {
RefNormalizePass() = default;

PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) {
RefNormalize().runOnFunction(F);
if (RefNormalize().runOnFunction(F)) {
return PreservedAnalyses::none();
}

return PreservedAnalyses::all();
}
};

class RefNormalizeLegacyPass : public FunctionPass {
public:
static char ID;
RefNormalizeLegacyPass() : FunctionPass(ID) {
initializeRefNormalizeLegacyPassPass(*PassRegistry::getPassRegistry());
}

bool runOnFunction(Function &F) override {
return RefNormalize().runOnFunction(F);
};
};

class RefPruneLegacyPass : public FunctionPass {

public:
static char ID; // Pass identification, replacement for typeid
// The maximum number of nodes that the fanout pruners will look at.
size_t subgraph_limit;
Subpasses flags;
RefPruneLegacyPass(Subpasses flags = Subpasses::All,
size_t subgraph_limit = -1)
: FunctionPass(ID), flags(flags), subgraph_limit(subgraph_limit) {
initializeRefPruneLegacyPassPass(*PassRegistry::getPassRegistry());
}

bool runOnFunction(Function &F) override {
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();

auto &PDT =
getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree();

return RefPrune(DT, PDT, flags, subgraph_limit).runOnFunction(F);
};

/**
* getAnalysisUsage() LLVM plumbing for the pass
*/
void getAnalysisUsage(AnalysisUsage &Info) const override {
Info.addRequired<DominatorTreeWrapperPass>();
Info.addRequired<PostDominatorTreeWrapperPass>();
}
};

char RefNormalizeLegacyPass::ID = 0;
char RefPruneLegacyPass::ID = 0;

size_t RefPrune::stats_per_bb = 0;
size_t RefPrune::stats_diamond = 0;
size_t RefPrune::stats_fanout = 0;
size_t RefPrune::stats_fanout_raise = 0;

INITIALIZE_PASS(RefNormalizeLegacyPass, "nrtRefNormalize",
"Normalize NRT refops", false, false)

INITIALIZE_PASS_BEGIN(RefPruneLegacyPass, "nrtRefPruneLegacyPass",
"Prune NRT refops", false, false)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass)

INITIALIZE_PASS_END(RefPruneLegacyPass, "RefPruneLegacyPass",
"Prune NRT refops", false, false)

extern "C" {

API_EXPORT(void)
LLVMPY_AddLegacyRefPrunePass(LLVMPassManagerRef PM, int subpasses,
size_t subgraph_limit) {
unwrap(PM)->add(new RefNormalizeLegacyPass());
unwrap(PM)->add(
new RefPruneLegacyPass((Subpasses)subpasses, subgraph_limit));
}

API_EXPORT(void)
LLVMPY_AddRefPrunePass_module(LLVMModulePassManagerRef MPM, int subpasses,
size_t subgraph_limit) {
Expand Down
24 changes: 2 additions & 22 deletions ffi/initfini.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
#include "llvm-c/Core.h"
#include "llvm-c/Initialization.h"
#include "llvm-c/Target.h"

#include "core.h"
#include "llvm/Config/llvm-config.h"

extern "C" {

#define INIT(F) \
API_EXPORT(void) LLVMPY_Initialize##F() { \
LLVMInitialize##F(LLVMGetGlobalPassRegistry()); \
}

INIT(Core)
INIT(TransformUtils)
INIT(ScalarOpts)
#if LLVM_VERSION_MAJOR < 16
INIT(ObjCARCOpts)
#endif
INIT(Vectorization)
INIT(InstCombine)
INIT(IPO)
// INIT(Instrumentation)
INIT(Analysis)
INIT(IPA)
INIT(CodeGen)
INIT(Target)

#undef INIT
// Pass registry and initialization APIs support dropped
// https://reviews.llvm.org/D145043

API_EXPORT(void)
LLVMPY_Shutdown() { LLVMShutdown(); }
Expand Down
33 changes: 12 additions & 21 deletions ffi/memorymanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,20 @@ bool LlvmliteMemoryManager::hasSpace(const MemoryGroup &MemGroup,
return false;
}

void LlvmliteMemoryManager::reserveAllocationSpace(uintptr_t CodeSize,
LLVMLITE_ALIGN CodeAlign,
uintptr_t RODataSize,
LLVMLITE_ALIGN RODataAlign,
uintptr_t RWDataSize,
LLVMLITE_ALIGN RWDataAlign) {
void LlvmliteMemoryManager::reserveAllocationSpace(
uintptr_t CodeSize, Align CodeAlign, uintptr_t RODataSize,
Align RODataAlign, uintptr_t RWDataSize, Align RWDataAlign) {
LLVM_DEBUG(
dbgs()
<< "\nLlvmliteMemoryManager::reserveAllocationSpace() request:\n\n");
LLVM_DEBUG(dbgs() << "Code size / align: " << format_hex(CodeSize, 2, true)
<< " / " << GET_ALIGN_VALUE(CodeAlign) << "\n");
<< " / " << CodeAlign.value() << "\n");
LLVM_DEBUG(dbgs() << "ROData size / align: "
<< format_hex(RODataSize, 2, true) << " / "
<< GET_ALIGN_VALUE(RODataAlign) << "\n");
<< RODataAlign.value() << "\n");
LLVM_DEBUG(dbgs() << "RWData size / align: "
<< format_hex(RWDataSize, 2, true) << " / "
<< GET_ALIGN_VALUE(RWDataAlign) << "\n");
<< RWDataAlign.value() << "\n");

if (CodeSize == 0 && RODataSize == 0 && RWDataSize == 0) {
LLVM_DEBUG(dbgs() << "No memory requested - returning early.\n");
Expand All @@ -155,31 +152,25 @@ void LlvmliteMemoryManager::reserveAllocationSpace(uintptr_t CodeSize,
// Code alignment needs to be at least the stub alignment - however, we
// don't have an easy way to get that here so as a workaround, we assume
// it's 8, which is the largest value I observed across all platforms.
#if LLVM_VERSION_MAJOR < 16
constexpr uint32_t StubAlign = 8;
#else
constexpr uint64_t StubAlign = 8;
#endif

CodeAlign = LLVMLITE_ALIGN(std::max(GET_ALIGN_VALUE(CodeAlign), StubAlign));
CodeAlign = Align(std::max(CodeAlign.value(), StubAlign));

// ROData and RWData may not need to be aligned to the StubAlign, but the
// stub alignment seems like a reasonable (if slightly arbitrary) minimum
// alignment for them that should not cause any issues on all (i.e. 64-bit)
// platforms.
RODataAlign =
LLVMLITE_ALIGN(std::max(GET_ALIGN_VALUE(RODataAlign), StubAlign));
RWDataAlign =
LLVMLITE_ALIGN(std::max(GET_ALIGN_VALUE(RWDataAlign), StubAlign));
RODataAlign = Align(std::max(RODataAlign.value(), StubAlign));
RWDataAlign = Align(std::max(RWDataAlign.value(), StubAlign));

// Get space required for each section. Use the same calculation as
// allocateSection because we need to be able to satisfy it.
uintptr_t RequiredCodeSize =
alignTo(CodeSize, CodeAlign) + GET_ALIGN_VALUE(CodeAlign);
alignTo(CodeSize, CodeAlign) + CodeAlign.value();
uintptr_t RequiredRODataSize =
alignTo(RODataSize, RODataAlign) + GET_ALIGN_VALUE(RODataAlign);
alignTo(RODataSize, RODataAlign) + RODataAlign.value();
uintptr_t RequiredRWDataSize =
alignTo(RWDataSize, RWDataAlign) + GET_ALIGN_VALUE(RWDataAlign);
alignTo(RWDataSize, RWDataAlign) + RWDataAlign.value();
uint64_t TotalSize =
RequiredCodeSize + RequiredRODataSize + RequiredRWDataSize;

Expand Down
Loading
Loading