Skip to content

Commit 0079487

Browse files
kvpanchTheDan64
andauthored
Initial support to LLVM 21 (#617)
Co-authored-by: Dan Kolsoi <ThaDan64@gmail.com>
1 parent 9a84825 commit 0079487

22 files changed

Lines changed: 126 additions & 56 deletions

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ llvm17-0 = ["llvm-sys-170"]
2929
llvm18-1 = ["llvm-sys-181"]
3030
llvm19-1 = ["llvm-sys-191"]
3131
llvm20-1 = ["llvm-sys-201"]
32+
llvm21-1 = ["llvm-sys-211"]
3233

3334
# Don't link against LLVM libraries. This is useful if another dependency is
3435
# installing LLVM. See llvm-sys for more details. We can't enable a single
@@ -48,6 +49,7 @@ llvm17-0-no-llvm-linking = ["llvm17-0", "llvm-sys-170/no-llvm-linking"]
4849
llvm18-1-no-llvm-linking = ["llvm18-1", "llvm-sys-181/no-llvm-linking"]
4950
llvm19-1-no-llvm-linking = ["llvm19-1", "llvm-sys-191/no-llvm-linking"]
5051
llvm20-1-no-llvm-linking = ["llvm20-1", "llvm-sys-201/no-llvm-linking"]
52+
llvm21-1-no-llvm-linking = ["llvm21-1", "llvm-sys-211/no-llvm-linking"]
5153

5254
# Linking preference.
5355
# If none of these are enabled, it defaults to force static linking.
@@ -62,6 +64,7 @@ llvm17-0-force-dynamic = ["llvm17-0", "llvm-sys-170/force-dynamic"]
6264
llvm18-1-force-dynamic = ["llvm18-1", "llvm-sys-181/force-dynamic"]
6365
llvm19-1-force-dynamic = ["llvm19-1", "llvm-sys-191/force-dynamic"]
6466
llvm20-1-force-dynamic = ["llvm20-1", "llvm-sys-201/force-dynamic"]
67+
llvm21-1-force-dynamic = ["llvm21-1", "llvm-sys-211/force-dynamic"]
6568

6669
# Prefer dynamic linking against LLVM libraries. See llvm-sys for more details
6770
llvm12-0-prefer-dynamic = ["llvm12-0", "llvm-sys-120/prefer-dynamic"]
@@ -73,6 +76,7 @@ llvm17-0-prefer-dynamic = ["llvm17-0", "llvm-sys-170/prefer-dynamic"]
7376
llvm18-1-prefer-dynamic = ["llvm18-1", "llvm-sys-181/prefer-dynamic"]
7477
llvm19-1-prefer-dynamic = ["llvm19-1", "llvm-sys-191/prefer-dynamic"]
7578
llvm20-1-prefer-dynamic = ["llvm20-1", "llvm-sys-201/prefer-dynamic"]
79+
llvm21-1-prefer-dynamic = ["llvm21-1", "llvm-sys-211/prefer-dynamic"]
7680

7781
# Force static linking against LLVM libraries. See llvm-sys for more details
7882
llvm12-0-force-static = ["llvm12-0", "llvm-sys-120/force-static"]
@@ -84,6 +88,7 @@ llvm17-0-force-static = ["llvm17-0", "llvm-sys-170/force-static"]
8488
llvm18-1-force-static = ["llvm18-1", "llvm-sys-181/force-static"]
8589
llvm19-1-force-static = ["llvm19-1", "llvm-sys-191/force-static"]
8690
llvm20-1-force-static = ["llvm20-1", "llvm-sys-201/force-static"]
91+
llvm21-1-force-static = ["llvm21-1", "llvm-sys-211/force-static"]
8792

8893
# Prefer static linking against LLVM libraries. See llvm-sys for more details
8994
llvm12-0-prefer-static = ["llvm12-0", "llvm-sys-120/prefer-static"]
@@ -95,6 +100,7 @@ llvm17-0-prefer-static = ["llvm17-0", "llvm-sys-170/prefer-static"]
95100
llvm18-1-prefer-static = ["llvm18-1", "llvm-sys-181/prefer-static"]
96101
llvm19-1-prefer-static = ["llvm19-1", "llvm-sys-191/prefer-static"]
97102
llvm20-1-prefer-static = ["llvm20-1", "llvm-sys-201/prefer-static"]
103+
llvm21-1-prefer-static = ["llvm21-1", "llvm-sys-211/prefer-static"]
98104

99105
# Don't force linking to libffi on non-windows platforms. Without this feature
100106
# inkwell always links to libffi on non-windows platforms.
@@ -155,6 +161,7 @@ llvm-sys-170 = { package = "llvm-sys", version = "170.2.0", optional = true }
155161
llvm-sys-181 = { package = "llvm-sys", version = "181.2.0", optional = true }
156162
llvm-sys-191 = { package = "llvm-sys", version = "191.0.0", optional = true }
157163
llvm-sys-201 = { package = "llvm-sys", version = "201.0.0", optional = true }
164+
llvm-sys-211 = { package = "llvm-sys", version = "211.0.0", optional = true }
158165

159166
libc = "0.2"
160167
once_cell = "1.16"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Inkwell aims to help you pen your own programming languages by safely wrapping l
1414
## Requirements
1515

1616
* Rust 1.56+ (Stable, Beta, or Nightly)
17-
* One of LLVM 8-18 (WIP: 19 and 20 are barely supported without extensive tests)
17+
* One of LLVM 8-18 (WIP: 19, 20, and 21 are barely supported without extensive tests)
1818

1919
## Usage
2020

internal_macros/src/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use syn::{Lit, RangeLimits};
1010
// This array should match the LLVM features in the top level Cargo manifest
1111
const FEATURE_VERSIONS: &[&str] = &[
1212
"llvm8-0", "llvm9-0", "llvm10-0", "llvm11-0", "llvm12-0", "llvm13-0", "llvm14-0", "llvm15-0", "llvm16-0",
13-
"llvm17-0", "llvm18-1", "llvm19-1", "llvm20-1"
13+
"llvm17-0", "llvm18-1", "llvm19-1", "llvm20-1", "llvm21-1",
1414
];
1515

1616
pub struct VersionRange {

src/builder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3493,6 +3493,9 @@ impl<'ctx> Builder<'ctx> {
34933493
/// let i32_ptr_param = fn_value.get_first_param().unwrap().into_pointer_value();
34943494
/// let builder = context.create_builder();
34953495
/// builder.position_at_end(entry);
3496+
/// #[cfg(feature = "llvm21-1")]
3497+
/// builder.build_atomicrmw(AtomicRMWBinOp::Add, i32_ptr_param, i32_seven, AtomicOrdering::Monotonic).unwrap();
3498+
/// #[cfg(not(feature = "llvm21-1"))]
34963499
/// builder.build_atomicrmw(AtomicRMWBinOp::Add, i32_ptr_param, i32_seven, AtomicOrdering::Unordered).unwrap();
34973500
/// builder.build_return(None).unwrap();
34983501
/// ```

src/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ impl Context {
594594
/// builder.build_call(callable_value, params, "exit").unwrap();
595595
/// }
596596
///
597-
/// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1", feature = "llvm19-1", feature = "llvm20-1"))]
597+
/// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1", feature = "llvm19-1", feature = "llvm20-1", feature = "llvm21-1"))]
598598
/// builder.build_indirect_call(asm_fn, asm, params, "exit").unwrap();
599599
///
600600
/// builder.build_return(None).unwrap();
@@ -1456,7 +1456,7 @@ impl<'ctx> ContextRef<'ctx> {
14561456
/// builder.build_call(callable_value, params, "exit").unwrap();
14571457
/// }
14581458
///
1459-
/// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1", feature = "llvm19-1", feature = "llvm20-1"))]
1459+
/// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1", feature = "llvm19-1", feature = "llvm20-1", feature = "llvm21-1"))]
14601460
/// builder.build_indirect_call(asm_fn, asm, params, "exit").unwrap();
14611461
///
14621462
/// builder.build_return(None).unwrap();

src/debug_info.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
211211
feature = "llvm17-0",
212212
feature = "llvm18-1",
213213
feature = "llvm19-1",
214-
feature = "llvm20-1"
214+
feature = "llvm20-1",
215+
feature = "llvm21-1"
215216
))]
216217
sysroot: &str,
217218
#[cfg(any(
@@ -224,7 +225,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
224225
feature = "llvm17-0",
225226
feature = "llvm18-1",
226227
feature = "llvm19-1",
227-
feature = "llvm20-1"
228+
feature = "llvm20-1",
229+
feature = "llvm21-1"
228230
))]
229231
sdk: &str,
230232
) -> (Self, DICompileUnit<'ctx>) {
@@ -265,7 +267,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
265267
feature = "llvm17-0",
266268
feature = "llvm18-1",
267269
feature = "llvm19-1",
268-
feature = "llvm20-1"
270+
feature = "llvm20-1",
271+
feature = "llvm21-1",
269272
))]
270273
sysroot,
271274
#[cfg(any(
@@ -278,7 +281,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
278281
feature = "llvm17-0",
279282
feature = "llvm18-1",
280283
feature = "llvm19-1",
281-
feature = "llvm20-1"
284+
feature = "llvm20-1",
285+
feature = "llvm21-1",
282286
))]
283287
sdk,
284288
);
@@ -327,7 +331,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
327331
feature = "llvm17-0",
328332
feature = "llvm18-1",
329333
feature = "llvm19-1",
330-
feature = "llvm20-1"
334+
feature = "llvm20-1",
335+
feature = "llvm21-1",
331336
))]
332337
sysroot: &str,
333338
#[cfg(any(
@@ -340,7 +345,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
340345
feature = "llvm17-0",
341346
feature = "llvm18-1",
342347
feature = "llvm19-1",
343-
feature = "llvm20-1"
348+
feature = "llvm20-1",
349+
feature = "llvm21-1",
344350
))]
345351
sdk: &str,
346352
) -> DICompileUnit<'ctx> {
@@ -376,7 +382,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
376382
feature = "llvm17-0",
377383
feature = "llvm18-1",
378384
feature = "llvm19-1",
379-
feature = "llvm20-1"
385+
feature = "llvm20-1",
386+
feature = "llvm21-1",
380387
))]
381388
{
382389
LLVMDIBuilderCreateCompileUnit(
@@ -955,15 +962,15 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
955962
)
956963
};
957964

958-
#[cfg(any(feature = "llvm19-1", feature = "llvm20-1"))]
965+
#[cfg(any(feature = "llvm19-1", feature = "llvm20-1", feature = "llvm21-1"))]
959966
{
960967
// In LLVM 19+, the insert... functions return a DbgRecord, not a Value.
961968
// We need to cast it to a ValueRef to create an InstructionValue.
962969
// This is unsafe, but it's the only way to do it.
963970
unsafe { InstructionValue::new(value_ref as LLVMValueRef) }
964971
}
965972

966-
#[cfg(not(any(feature = "llvm19-1", feature = "llvm20-1")))]
973+
#[cfg(not(any(feature = "llvm19-1", feature = "llvm20-1", feature = "llvm21-1")))]
967974
{
968975
unsafe { InstructionValue::new(value_ref) }
969976
}
@@ -989,15 +996,15 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
989996
)
990997
};
991998

992-
#[cfg(any(feature = "llvm19-1", feature = "llvm20-1"))]
999+
#[cfg(any(feature = "llvm19-1", feature = "llvm20-1", feature = "llvm21-1"))]
9931000
{
9941001
// In LLVM 19+, the insert... functions return a DbgRecord, not a Value.
9951002
// We need to cast it to a ValueRef to create an InstructionValue.
9961003
// This is unsafe, but it's the only way to do it.
9971004
unsafe { InstructionValue::new(value_ref as LLVMValueRef) }
9981005
}
9991006

1000-
#[cfg(not(any(feature = "llvm19-1", feature = "llvm20-1")))]
1007+
#[cfg(not(any(feature = "llvm19-1", feature = "llvm20-1", feature = "llvm21-1")))]
10011008
{
10021009
unsafe { InstructionValue::new(value_ref) }
10031010
}
@@ -1038,15 +1045,15 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
10381045
)
10391046
};
10401047

1041-
#[cfg(any(feature = "llvm19-1", feature = "llvm20-1"))]
1048+
#[cfg(any(feature = "llvm19-1", feature = "llvm20-1", feature = "llvm21-1"))]
10421049
{
10431050
// In LLVM 19+, the insert... functions return a DbgRecord, not a Value.
10441051
// We need to cast it to a ValueRef to create an InstructionValue.
10451052
// This is unsafe, but it's the only way to do it.
10461053
unsafe { InstructionValue::new(value_ref as LLVMValueRef) }
10471054
}
10481055

1049-
#[cfg(not(any(feature = "llvm19-1", feature = "llvm20-1")))]
1056+
#[cfg(not(any(feature = "llvm19-1", feature = "llvm20-1", feature = "llvm21-1")))]
10501057
{
10511058
unsafe { InstructionValue::new(value_ref) }
10521059
}

src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ pub extern crate llvm_sys_181 as llvm_sys;
6565
pub extern crate llvm_sys_191 as llvm_sys;
6666
#[cfg(feature = "llvm20-1")]
6767
pub extern crate llvm_sys_201 as llvm_sys;
68+
#[cfg(feature = "llvm21-1")]
69+
pub extern crate llvm_sys_211 as llvm_sys;
6870
#[cfg(feature = "llvm8-0")]
6971
pub extern crate llvm_sys_80 as llvm_sys;
7072
#[cfg(feature = "llvm9-0")]
@@ -125,7 +127,8 @@ assert_unique_used_features! {
125127
"llvm17-0",
126128
"llvm18-1",
127129
"llvm19-1",
128-
"llvm20-1"
130+
"llvm20-1",
131+
"llvm21-1"
129132
}
130133

131134
#[cfg(all(
@@ -404,6 +407,14 @@ pub enum AtomicRMWBinOp {
404407
#[llvm_versions(20..)]
405408
#[llvm_variant(LLVMAtomicRMWBinOpUSubSat)]
406409
USubSat,
410+
411+
#[llvm_versions(21..)]
412+
#[llvm_variant(LLVMAtomicRMWBinOpFMaximum)]
413+
FMaximum,
414+
415+
#[llvm_versions(21..)]
416+
#[llvm_variant(LLVMAtomicRMWBinOpFMinimum)]
417+
FMinimum,
407418
}
408419

409420
/// Defines the optimization level used to compile a [`Module`](crate::module::Module).

src/module.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,8 @@ impl<'ctx> Module<'ctx> {
15471547
feature = "llvm17-0",
15481548
feature = "llvm18-1",
15491549
feature = "llvm19-1",
1550-
feature = "llvm20-1"
1550+
feature = "llvm20-1",
1551+
feature = "llvm21-1",
15511552
))]
15521553
sysroot: &str,
15531554
#[cfg(any(
@@ -1560,7 +1561,8 @@ impl<'ctx> Module<'ctx> {
15601561
feature = "llvm17-0",
15611562
feature = "llvm18-1",
15621563
feature = "llvm19-1",
1563-
feature = "llvm20-1"
1564+
feature = "llvm20-1",
1565+
feature = "llvm21-1",
15641566
))]
15651567
sdk: &str,
15661568
) -> (DebugInfoBuilder<'ctx>, DICompileUnit<'ctx>) {
@@ -1589,7 +1591,8 @@ impl<'ctx> Module<'ctx> {
15891591
feature = "llvm17-0",
15901592
feature = "llvm18-1",
15911593
feature = "llvm19-1",
1592-
feature = "llvm20-1"
1594+
feature = "llvm20-1",
1595+
feature = "llvm21-1",
15931596
))]
15941597
sysroot,
15951598
#[cfg(any(
@@ -1602,7 +1605,8 @@ impl<'ctx> Module<'ctx> {
16021605
feature = "llvm17-0",
16031606
feature = "llvm18-1",
16041607
feature = "llvm19-1",
1605-
feature = "llvm20-1"
1608+
feature = "llvm20-1",
1609+
feature = "llvm21-1",
16061610
))]
16071611
sdk,
16081612
)

src/types/array_type.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ impl<'ctx> ArrayType<'ctx> {
8787
feature = "llvm17-0",
8888
feature = "llvm18-1",
8989
feature = "llvm19-1",
90-
feature = "llvm20-1"
90+
feature = "llvm20-1",
91+
feature = "llvm21-1",
9192
),
9293
deprecated(
9394
note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead."

0 commit comments

Comments
 (0)