From d1c0936e47960a4ade0cd729d2565c20d483e94e Mon Sep 17 00:00:00 2001 From: Dan Kolsoi Date: Sat, 27 Jul 2024 10:22:04 -0400 Subject: [PATCH 01/13] Marked const_float_from_string as unsafe. Fixes #513 (#519) --- src/types/float_type.rs | 24 ++++++++++++------------ tests/all/test_values.rs | 18 ++++++++---------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/types/float_type.rs b/src/types/float_type.rs index b7abe8974b0..6d028387890 100644 --- a/src/types/float_type.rs +++ b/src/types/float_type.rs @@ -98,8 +98,10 @@ impl<'ctx> FloatType<'ctx> { unsafe { FloatValue::new(LLVMConstReal(self.float_type.ty, value)) } } - /// Create a `FloatValue` from a string. LLVM provides no error handling here, - /// so this may produce unexpected results and should not be relied upon for validation. + // We could make this safe again by doing the validation for users. + /// Create a `FloatValue` from a string. This function is marked unsafe because LLVM + /// provides no error handling here, so this may produce undefined behavior if an invalid + /// string is used. /// /// # Example /// @@ -109,28 +111,26 @@ impl<'ctx> FloatType<'ctx> { /// /// let context = Context::create(); /// let f64_type = context.f64_type(); - /// let f64_val = f64_type.const_float_from_string("3.6"); + /// let f64_val = unsafe { f64_type.const_float_from_string("3.6") }; /// /// assert_eq!(f64_val.print_to_string().to_string(), "double 3.600000e+00"); /// - /// let f64_val = f64_type.const_float_from_string("3."); + /// let f64_val = unsafe { f64_type.const_float_from_string("3.") }; /// /// assert_eq!(f64_val.print_to_string().to_string(), "double 3.000000e+00"); /// - /// let f64_val = f64_type.const_float_from_string("3"); + /// let f64_val = unsafe { f64_type.const_float_from_string("3") }; /// /// assert_eq!(f64_val.print_to_string().to_string(), "double 3.000000e+00"); /// - /// let f64_val = f64_type.const_float_from_string(""); - /// - /// assert_eq!(f64_val.print_to_string().to_string(), "double 0.000000e+00"); - /// - /// let f64_val = f64_type.const_float_from_string("3.asd"); + /// let f64_val = unsafe { f64_type.const_float_from_string("3.asd") }; /// /// assert_eq!(f64_val.print_to_string().to_string(), "double 0x7FF0000000000000"); /// ``` - pub fn const_float_from_string(self, slice: &str) -> FloatValue<'ctx> { - unsafe { + pub unsafe fn const_float_from_string(self, slice: &str) -> FloatValue<'ctx> { + assert!(!slice.is_empty()); + + unsafe { FloatValue::new(LLVMConstRealOfStringAndSize( self.as_type_ref(), slice.as_ptr() as *const ::libc::c_char, diff --git a/tests/all/test_values.rs b/tests/all/test_values.rs index bba39fab60d..ccf723676e6 100644 --- a/tests/all/test_values.rs +++ b/tests/all/test_values.rs @@ -871,26 +871,24 @@ fn test_value_from_string() { // Floats let f64_type = context.f64_type(); - let f64_val = f64_type.const_float_from_string("3.6"); + let f64_val = unsafe { f64_type.const_float_from_string("3.6") }; assert_eq!(f64_val.print_to_string().to_string(), "double 3.600000e+00"); - let f64_val = f64_type.const_float_from_string("3."); + let f64_val = unsafe { f64_type.const_float_from_string("3.") }; assert_eq!(f64_val.print_to_string().to_string(), "double 3.000000e+00"); - let f64_val = f64_type.const_float_from_string("3"); + let f64_val = unsafe { f64_type.const_float_from_string("3") }; assert_eq!(f64_val.print_to_string().to_string(), "double 3.000000e+00"); - let f64_val = f64_type.const_float_from_string(""); - - assert_eq!(f64_val.print_to_string().to_string(), "double 0.000000e+00"); - - // TODO: We should return a Result that returns Err here. - //let f64_val = f64_type.const_float_from_string("3.asd"); + // TODO: We should return a Result that returns Err here. This would require + // us to implement manual validation of the input to assert it matched LLVM's + // expected format. + // let f64_val = f64_type.const_float_from_string("3.asd"); // - //assert_eq!(f64_val.print_to_string().to_string(), "double 0x7FF0000000000000"); + // assert_eq!(f64_val.print_to_string().to_string(), "double 0x7FF0000000000000"); } #[test] From c3f6e0536b9959ddb6a712ec13f2453a9587eaac Mon Sep 17 00:00:00 2001 From: Anton Baliasnikov Date: Sat, 27 Jul 2024 15:30:40 +0100 Subject: [PATCH 02/13] Fix memory leak caused by LLVMVerifyModule function call (#507) Co-authored-by: Dan Kolsoi --- src/module.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/module.rs b/src/module.rs index 94e9f80053a..5a137e97e6a 100644 --- a/src/module.rs +++ b/src/module.rs @@ -12,7 +12,7 @@ use llvm_sys::core::{ LLVMDisposeModule, LLVMDumpModule, LLVMGetFirstFunction, LLVMGetFirstGlobal, LLVMGetLastFunction, LLVMGetLastGlobal, LLVMGetModuleContext, LLVMGetModuleIdentifier, LLVMGetNamedFunction, LLVMGetNamedGlobal, LLVMGetNamedMetadataNumOperands, LLVMGetNamedMetadataOperands, LLVMGetTarget, LLVMPrintModuleToFile, - LLVMPrintModuleToString, LLVMSetDataLayout, LLVMSetModuleIdentifier, LLVMSetTarget, + LLVMPrintModuleToString, LLVMSetDataLayout, LLVMSetModuleIdentifier, LLVMSetTarget, LLVMDisposeMessage }; #[llvm_versions(7..)] use llvm_sys::core::{LLVMAddModuleFlag, LLVMGetModuleFlag}; @@ -740,6 +740,8 @@ impl<'ctx> Module<'ctx> { return unsafe { Err(LLVMString::new(err_str)) }; } + unsafe { LLVMDisposeMessage(err_str) }; + Ok(()) } From 89e06af9dd70dc5d6bc5ae42a2a03f680a367d37 Mon Sep 17 00:00:00 2001 From: Gavrilikhin Daniil Date: Sat, 27 Jul 2024 22:37:14 +0800 Subject: [PATCH 03/13] expose functions for working with LLVMContextRef for interoperability with other libraries (#518) * expose raw functions * Remove unsafe --------- Co-authored-by: Dan Kolsoi --- src/context.rs | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/context.rs b/src/context.rs index 041a4aee760..3e70327d2ae 100644 --- a/src/context.rs +++ b/src/context.rs @@ -417,7 +417,22 @@ pub struct Context { unsafe impl Send for Context {} impl Context { - pub(crate) unsafe fn new(context: LLVMContextRef) -> Self { + /// Get raw [`LLVMContextRef`]. + /// + /// This function is exposed only for interoperability with other LLVM IR libraries. + /// It's not intended to be used by most users. + pub fn raw(&self) -> LLVMContextRef { + self.context.0 + } + + /// Creates a new `Context` from [`LLVMContextRef`]. + /// + /// # Safety + /// + /// This function is exposed only for interoperability with other LLVM IR libraries. + /// It's not intended to be used by most users, hence marked as unsafe. + /// Use [`Context::create`] instead. + pub unsafe fn new(context: LLVMContextRef) -> Self { Context { context: ContextImpl::new(context), } @@ -1321,7 +1336,21 @@ pub struct ContextRef<'ctx> { } impl<'ctx> ContextRef<'ctx> { - pub(crate) unsafe fn new(context: LLVMContextRef) -> Self { + /// Get raw [`LLVMContextRef`]. + /// + /// This function is exposed only for interoperability with other LLVM IR libraries. + /// It's not intended to be used by most users. + pub fn raw(&self) -> LLVMContextRef { + self.context.0 + } + + /// Creates a new `ContextRef` from [`LLVMContextRef`]. + /// + /// # Safety + /// + /// This function is exposed only for interoperability with other LLVM IR libraries. + /// It's not intended to be used by most users, hence marked as unsafe. + pub unsafe fn new(context: LLVMContextRef) -> Self { ContextRef { context: ContextImpl::new(context), _marker: PhantomData, From a8361b1e47a7a4b3431b483044d195ce50cc0a67 Mon Sep 17 00:00:00 2001 From: Vaivaswatha N Date: Sun, 4 Aug 2024 08:58:12 +0530 Subject: [PATCH 04/13] Provide get_gep_source_element_type and InstructionValue -> CallSiteValue (#506) * Provide get_gep_source_element_type and InstructionValue -> CallSiteValue * restrict new api to llvm 14+ * restrict test to llvm versions * add llvm14 also for test * temporarily remove callsite test * Revert "temporarily remove callsite test" This reverts commit baaa9822b9f9e13a60134a32351f1cade2793ba1. * Similar to other value types, provide `is_const` method for StructValue * build_gep is only available in LLVM 15+ --------- Co-authored-by: Dan Kolsoi --- src/values/call_site_value.rs | 14 +++++++++++++- src/values/instruction_value.rs | 19 +++++++++++++++++-- src/values/struct_value.rs | 18 ++++++++++++++++++ tests/all/test_instruction_values.rs | 24 ++++++++++++++++++++++-- 4 files changed, 70 insertions(+), 5 deletions(-) diff --git a/src/values/call_site_value.rs b/src/values/call_site_value.rs index 833866ce01a..07602f8d369 100644 --- a/src/values/call_site_value.rs +++ b/src/values/call_site_value.rs @@ -13,7 +13,7 @@ use llvm_sys::LLVMTypeKind; use crate::attributes::{Attribute, AttributeLoc}; use crate::values::{AsValueRef, BasicValueEnum, FunctionValue, InstructionValue, Value}; -use super::AnyValue; +use super::{AnyValue, InstructionOpcode}; /// A value resulting from a function call. It may have function attributes applied to it. /// @@ -605,3 +605,15 @@ impl Display for CallSiteValue<'_> { write!(f, "{}", self.print_to_string()) } } + +impl<'ctx> TryFrom> for CallSiteValue<'ctx> { + type Error = (); + + fn try_from(value: InstructionValue<'ctx>) -> Result { + if value.get_opcode() == InstructionOpcode::Call { + unsafe { Ok(CallSiteValue::new(value.as_value_ref())) } + } else { + Err(()) + } + } +} diff --git a/src/values/instruction_value.rs b/src/values/instruction_value.rs index 3a654261fb7..1de4cc206ea 100644 --- a/src/values/instruction_value.rs +++ b/src/values/instruction_value.rs @@ -2,13 +2,15 @@ use either::{ Either, Either::{Left, Right}, }; +#[llvm_versions(14..)] +use llvm_sys::core::LLVMGetGEPSourceElementType; use llvm_sys::core::{ LLVMGetAlignment, LLVMGetAllocatedType, LLVMGetFCmpPredicate, LLVMGetICmpPredicate, LLVMGetInstructionOpcode, LLVMGetInstructionParent, LLVMGetMetadata, LLVMGetNextInstruction, LLVMGetNumOperands, LLVMGetOperand, LLVMGetOperandUse, LLVMGetPreviousInstruction, LLVMGetVolatile, LLVMHasMetadata, LLVMInstructionClone, LLVMInstructionEraseFromParent, LLVMInstructionRemoveFromParent, LLVMIsAAllocaInst, LLVMIsABasicBlock, - LLVMIsALoadInst, LLVMIsAStoreInst, LLVMIsATerminatorInst, LLVMIsConditional, LLVMIsTailCall, LLVMSetAlignment, - LLVMSetMetadata, LLVMSetOperand, LLVMSetVolatile, LLVMValueAsBasicBlock, + LLVMIsAGetElementPtrInst, LLVMIsALoadInst, LLVMIsAStoreInst, LLVMIsATerminatorInst, LLVMIsConditional, + LLVMIsTailCall, LLVMSetAlignment, LLVMSetMetadata, LLVMSetOperand, LLVMSetVolatile, LLVMValueAsBasicBlock, }; use llvm_sys::core::{LLVMGetOrdering, LLVMSetOrdering}; #[llvm_versions(10..)] @@ -121,6 +123,9 @@ impl<'ctx> InstructionValue<'ctx> { fn is_a_alloca_inst(self) -> bool { !unsafe { LLVMIsAAllocaInst(self.as_value_ref()) }.is_null() } + fn is_a_getelementptr_inst(self) -> bool { + !unsafe { LLVMIsAGetElementPtrInst(self.as_value_ref()) }.is_null() + } #[llvm_versions(10..)] fn is_a_atomicrmw_inst(self) -> bool { !unsafe { LLVMIsAAtomicRMWInst(self.as_value_ref()) }.is_null() @@ -398,6 +403,16 @@ impl<'ctx> InstructionValue<'ctx> { Ok(unsafe { BasicTypeEnum::new(LLVMGetAllocatedType(self.as_value_ref())) }) } + // SubTypes: Only apply to GetElementPtr instruction + /// Returns the source element type of the given GEP. + #[llvm_versions(14..)] + pub fn get_gep_source_element_type(self) -> Result, &'static str> { + if !self.is_a_getelementptr_inst() { + return Err("Value is not a GEP."); + } + Ok(unsafe { BasicTypeEnum::new(LLVMGetGEPSourceElementType(self.as_value_ref())) }) + } + // SubTypes: Only apply to memory access and alloca instructions /// Returns alignment on a memory access instruction or alloca. pub fn get_alignment(self) -> Result { diff --git a/src/values/struct_value.rs b/src/values/struct_value.rs index 57892b2673a..74a81ebe568 100644 --- a/src/values/struct_value.rs +++ b/src/values/struct_value.rs @@ -145,6 +145,24 @@ impl<'ctx> StructValue<'ctx> { pub fn replace_all_uses_with(self, other: StructValue<'ctx>) { self.struct_value.replace_all_uses_with(other.as_value_ref()) } + + /// Determines whether or not a `StructValue` is a constant. + /// + /// # Example + /// + /// ```no_run + /// use inkwell::{context::Context, values::BasicValue}; + /// + /// let context = Context::create(); + /// let i64_type = context.i64_type(); + /// let i64_val = i64_type.const_int(23, false).as_basic_value_enum(); + /// let struct_val = context.const_struct(&[i64_val, i64_val], false); + /// + /// assert!(struct_val.is_const()); + /// ``` + pub fn is_const(self) -> bool { + self.struct_value.is_const() + } } unsafe impl AsValueRef for StructValue<'_> { diff --git a/tests/all/test_instruction_values.rs b/tests/all/test_instruction_values.rs index 539bbc1396d..c68c2d79c05 100644 --- a/tests/all/test_instruction_values.rs +++ b/tests/all/test_instruction_values.rs @@ -1,6 +1,6 @@ use inkwell::context::Context; -use inkwell::types::{AnyTypeEnum, BasicType}; -use inkwell::values::{BasicValue, InstructionOpcode::*}; +use inkwell::types::{AnyType, AnyTypeEnum, BasicType}; +use inkwell::values::{BasicValue, CallSiteValue, InstructionOpcode::*}; use inkwell::{AddressSpace, AtomicOrdering, AtomicRMWBinOp, FloatPredicate, IntPredicate}; #[test] @@ -311,6 +311,24 @@ fn test_instructions() { .build_conditional_branch(i64_type.const_zero(), basic_block, basic_block) .unwrap(); + #[cfg(any( + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + { + let gep_instr = unsafe { builder.build_gep(i64_type, alloca_val, &vec![], "gep").unwrap() }; + assert_eq!( + gep_instr + .as_instruction_value() + .unwrap() + .get_gep_source_element_type() + .unwrap() + .as_any_type_enum(), + i64_type.as_any_type_enum() + ); + } assert_eq!( alloca_val.as_instruction().unwrap().get_allocated_type(), Ok(i64_type.as_basic_type_enum()) @@ -321,6 +339,8 @@ fn test_instructions() { assert!(!store_instruction.is_conditional()); assert!(!return_instruction.is_conditional()); assert!(cond_br_instruction.is_conditional()); + assert!(TryInto::::try_into(free_instruction).is_ok()); + assert!(TryInto::::try_into(return_instruction).is_err()); assert_eq!(store_instruction.get_opcode(), Store); assert_eq!(ptr_val.as_instruction().unwrap().get_opcode(), PtrToInt); assert_eq!(ptr.as_instruction().unwrap().get_opcode(), IntToPtr); From 393a1b82bd5899c4ca67a8244810ed9075c4b5d6 Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Sat, 27 Jul 2024 10:45:36 -0400 Subject: [PATCH 05/13] Prepare for inkwell 0.5.0 --- CHANGELOG.md | 23 ----------------------- Cargo.toml | 4 ++-- README.md | 2 +- internal_macros/Cargo.toml | 2 +- 4 files changed, 4 insertions(+), 27 deletions(-) delete mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 8a49d4eb6d2..00000000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,23 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). - -## [Unreleased] -### TODO -- TODO - -## [0.2.0] - 2023-05-04 -- Added LLVM 16 support -- Updated internal_macros syn dep to v2 -- Added Module::get_globals iterator - -## [0.1.1] - 2023-02-11 -- Fixed set_section method on macOS - -## [0.1.0] - 2023-01-21 -- Initial release - -## [0.0.0] - 2017-06-29 -- This is a placeholder version for crates.io diff --git a/Cargo.toml b/Cargo.toml index 59a906dc9b9..05a55916d73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "inkwell" -version = "0.4.0" +version = "0.5.0" authors = ["Daniel Kolsoi "] description = "Inkwell aims to help you pen your own programming languages by safely wrapping llvm-sys." documentation = "https://thedan64.github.io/inkwell/" @@ -135,7 +135,7 @@ experimental = ["static-alloc"] nightly = ["inkwell_internals/nightly"] [dependencies] -inkwell_internals = { path = "./internal_macros", version = "0.9.0" } +inkwell_internals = { path = "./internal_macros", version = "0.10.0" } llvm-sys-40 = { package = "llvm-sys", version = "40.4", optional = true } llvm-sys-50 = { package = "llvm-sys", version = "50.4", optional = true } diff --git a/README.md b/README.md index 66ab2a2d5d9..90ba58adb2c 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ You'll need to point your Cargo.toml to use a single LLVM version feature flag c ```toml [dependencies] -inkwell = { version = "0.4.0", features = ["llvm18-0"] } +inkwell = { version = "0.5.0", features = ["llvm18-0"] } ``` Supported versions: diff --git a/internal_macros/Cargo.toml b/internal_macros/Cargo.toml index e1fb6c45b36..c49467c5227 100644 --- a/internal_macros/Cargo.toml +++ b/internal_macros/Cargo.toml @@ -6,7 +6,7 @@ license = "Apache-2.0" name = "inkwell_internals" readme = "README.md" repository = "https://github.com/TheDan64/inkwell" -version = "0.9.0" +version = "0.10.0" [dependencies] proc-macro2 = "1.0" From a4e37ac5a86048be3d390f967b44964f6a3d5f38 Mon Sep 17 00:00:00 2001 From: Etienne Wodey <44871469+airwoodix@users.noreply.github.com> Date: Thu, 22 Aug 2024 17:34:51 +0200 Subject: [PATCH 06/13] workflows: test against LLVM 18.1 (#525) * workflows: test against LLVM 18.1 * workflows: remove testing on LLVM < 7.1. * workflows: use ubuntu-20.04 for llvm 18 * workflows: use install-llvm-action@v1 for llvm <= 7 * workflows: build docs against LLVM 18 --- .github/workflows/test.yml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4a07879d3e0..f5178379728 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,8 +4,8 @@ on: [push, pull_request] env: CARGO_TERM_COLOR: always - DOC_LLVM_FEATURE: llvm17-0 - DOC_LLVM_VERSION: "17.0" + DOC_LLVM_FEATURE: llvm18-0 + DOC_LLVM_VERSION: "18.1" DOC_PATH: target/doc jobs: @@ -29,6 +29,7 @@ jobs: - ["5.0", "5-0"] - ["6.0", "6-0"] - ["7.0", "7-0"] + - ["7.1", "7-0"] - ["8.0", "8-0"] - ["9.0", "9-0"] - ["10.0", "10-0"] @@ -39,9 +40,10 @@ jobs: - ["15.0", "15-0"] - ["16.0", "16-0"] - ["17.0", "17-0"] + - ["18.1", "18-0"] include: - os: ubuntu-20.04 - # only use ubuntu-22.04 for llvm 16 and higher + # only use ubuntu-22.04 for llvm 16 and llvm 17 - os: ubuntu-22.04 llvm-version: ["16.0", "16-0"] - os: ubuntu-22.04 @@ -49,8 +51,14 @@ jobs: steps: - name: Checkout Repo uses: actions/checkout@v4 - - name: Install LLVM and Clang + - name: Install LLVM and Clang (LLVM >= 7.1) + uses: KyleMayes/install-llvm-action@v2 + if: ${{ matrix.llvm-version[0] > 7 }} + with: + version: ${{ matrix.llvm-version[0] }} + - name: Install LLVM and Clang (LLVM <= 7) uses: KyleMayes/install-llvm-action@v1 + if: ${{ matrix.llvm-version[0] <= 7 }} with: version: ${{ matrix.llvm-version[0] }} - name: llvm-config @@ -65,12 +73,12 @@ jobs: run: cargo build --example kaleidoscope --features llvm${{ matrix.llvm-version[1] }} --verbose doc: name: Documentation - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 needs: [typos, tests] if: github.event_name == 'push' && github.ref == 'refs/heads/master' steps: - uses: actions/checkout@v4 - - uses: KyleMayes/install-llvm-action@v1 + - uses: KyleMayes/install-llvm-action@v2 with: version: ${{ env.DOC_LLVM_VERSION }} - name: Install Rust Nightly From 4028abc9d147e5b0a16acedc7047545fc2213c3f Mon Sep 17 00:00:00 2001 From: Etienne Wodey <44871469+airwoodix@users.noreply.github.com> Date: Thu, 22 Aug 2024 18:51:56 +0200 Subject: [PATCH 07/13] module: make write_bitcode_to_path accept more general path representations (#528) Co-authored-by: Dan Kolsoi --- src/module.rs | 19 +++++++++++-------- tests/all/test_module.rs | 9 ++------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/module.rs b/src/module.rs index 5a137e97e6a..14c79a5cffe 100644 --- a/src/module.rs +++ b/src/module.rs @@ -648,27 +648,30 @@ impl<'ctx> Module<'ctx> { unsafe { GlobalValue::new(value) } } - /// Writes a `Module` to a `Path`. + /// Writes a `Module` to a file. + /// + /// # Arguments + /// + /// * `path` - path to write the module's bitcode to. Must be valid Unicode. /// /// # Example /// /// ```no_run /// use inkwell::context::Context; /// - /// use std::path::Path; - /// - /// let mut path = Path::new("module.bc"); - /// /// let context = Context::create(); /// let module = context.create_module("my_module"); /// let void_type = context.void_type(); /// let fn_type = void_type.fn_type(&[], false); /// /// module.add_function("my_fn", fn_type, None); - /// module.write_bitcode_to_path(&path); + /// module.write_bitcode_to_path("module.bc"); /// ``` - pub fn write_bitcode_to_path(&self, path: &Path) -> bool { - let path_str = path.to_str().expect("Did not find a valid Unicode path string"); + pub fn write_bitcode_to_path(&self, path: impl AsRef) -> bool { + let path_str = path + .as_ref() + .to_str() + .expect("Did not find a valid Unicode path string"); let c_string = to_c_str(path_str); unsafe { LLVMWriteBitcodeToFile(self.module.get(), c_string.as_ptr()) == 0 } diff --git a/tests/all/test_module.rs b/tests/all/test_module.rs index 668dc6e6992..aa88002d47c 100644 --- a/tests/all/test_module.rs +++ b/tests/all/test_module.rs @@ -6,8 +6,7 @@ use inkwell::values::AnyValue; use inkwell::OptimizationLevel; use std::env::temp_dir; -use std::fs::{remove_file, File}; -use std::io::Read; +use std::fs::{self, remove_file}; use std::path::Path; #[test] @@ -24,11 +23,7 @@ fn test_write_bitcode_to_path() { module.add_function("my_fn", fn_type, None); module.write_bitcode_to_path(&path); - let mut contents = Vec::new(); - let mut file = File::open(&path).expect("Could not open temp file"); - - file.read_to_end(&mut contents).expect("Unable to verify written file"); - + let contents = fs::read(&path).expect("Could not read back written file."); assert!(!contents.is_empty()); remove_file(&path).unwrap(); From 885c5f7a332ab75ea16b489e14d5e2d40e641ddb Mon Sep 17 00:00:00 2001 From: Andrzej Janik Date: Mon, 16 Sep 2024 16:25:36 +0200 Subject: [PATCH 08/13] Fix null-terminated strings in LLVMSetValueName2 and LLVMMDStringInContext (#534) --- src/basic_block.rs | 2 +- src/context.rs | 2 +- src/values/mod.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/basic_block.rs b/src/basic_block.rs index a1390a993d9..6d039a67bde 100644 --- a/src/basic_block.rs +++ b/src/basic_block.rs @@ -481,7 +481,7 @@ impl<'ctx> BasicBlock<'ctx> { { use llvm_sys::core::LLVMSetValueName2; - unsafe { LLVMSetValueName2(LLVMBasicBlockAsValue(self.basic_block), c_string.as_ptr(), name.len()) }; + unsafe { LLVMSetValueName2(LLVMBasicBlockAsValue(self.basic_block), c_string.as_ptr(), c_string.to_bytes().len()) }; } } diff --git a/src/context.rs b/src/context.rs index 3e70327d2ae..82cb783bea1 100644 --- a/src/context.rs +++ b/src/context.rs @@ -345,7 +345,7 @@ impl ContextImpl { fn metadata_string<'ctx>(&self, string: &str) -> MetadataValue<'ctx> { let c_string = to_c_str(string); - unsafe { MetadataValue::new(LLVMMDStringInContext(self.0, c_string.as_ptr(), string.len() as u32)) } + unsafe { MetadataValue::new(LLVMMDStringInContext(self.0, c_string.as_ptr(), c_string.to_bytes().len() as u32)) } } fn get_kind_id(&self, key: &str) -> u32 { diff --git a/src/values/mod.rs b/src/values/mod.rs index 408ecca74f6..953b4449c37 100644 --- a/src/values/mod.rs +++ b/src/values/mod.rs @@ -132,7 +132,7 @@ impl<'ctx> Value<'ctx> { { use llvm_sys::core::LLVMSetValueName2; - unsafe { LLVMSetValueName2(self.value, c_string.as_ptr(), name.len()) } + unsafe { LLVMSetValueName2(self.value, c_string.as_ptr(), c_string.to_bytes().len()) } } } From 22c04776a3f85d1cfe1e0c380012e0527a1103dd Mon Sep 17 00:00:00 2001 From: Etienne Wodey <44871469+airwoodix@users.noreply.github.com> Date: Thu, 19 Sep 2024 04:17:29 +0200 Subject: [PATCH 09/13] Implement safe API for operand bundles. (#524) Co-authored-by: Dan Kolsoi --- src/builder.rs | 120 +++++++++++++++++++++ src/values/call_site_value.rs | 43 ++++++++ src/values/mod.rs | 6 ++ src/values/operand_bundle.rs | 197 ++++++++++++++++++++++++++++++++++ tests/all/test_values.rs | 49 +++++++++ 5 files changed, 415 insertions(+) create mode 100644 src/values/operand_bundle.rs diff --git a/src/builder.rs b/src/builder.rs index 084a3d03e25..accb513fe0e 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1,5 +1,7 @@ //! A `Builder` enables you to build instructions. +#[llvm_versions(18..)] +use llvm_sys::core::LLVMBuildCallWithOperandBundles; use llvm_sys::core::{ LLVMAddCase, LLVMAddClause, LLVMAddDestination, LLVMBuildAShr, LLVMBuildAdd, LLVMBuildAddrSpaceCast, LLVMBuildAggregateRet, LLVMBuildAlloca, LLVMBuildAnd, LLVMBuildArrayAlloca, LLVMBuildArrayMalloc, @@ -42,6 +44,8 @@ use crate::context::AsContextRef; use crate::debug_info::DILocation; use crate::support::to_c_str; use crate::types::{AsTypeRef, BasicType, FloatMathType, FunctionType, IntMathType, PointerMathType, PointerType}; +#[llvm_versions(18..)] +use crate::values::operand_bundle::OperandBundle; #[llvm_versions(..=14)] use crate::values::CallableValue; use crate::values::{ @@ -308,6 +312,57 @@ impl<'ctx> Builder<'ctx> { self.build_call_help(function.get_type(), function.as_value_ref(), args, name) } + /// Build a function call instruction, with attached operand bundles. + /// + /// # Example + /// + /// ``` + /// use inkwell::context::Context; + /// use inkwell::values::OperandBundle; + /// + /// let context = Context::create(); + /// let module = context.create_module("call_with_op_bundles"); + /// let builder = context.create_builder(); + /// let i32_type = context.i32_type(); + /// + /// // declare i32 @func(i32) + /// let fn_type = i32_type.fn_type(&[i32_type.into()], false); + /// let fn_value = module.add_function("func", fn_type, None); + /// + /// let basic_block = context.append_basic_block(fn_value, "entry"); + /// builder.position_at_end(basic_block); + /// + /// // %func_ret = call i32 @func(i32 0) [ "tag"(i32 0) ] + /// let ret_val = builder.build_direct_call_with_operand_bundles( + /// fn_value, + /// &[i32_type.const_zero().into()], + /// &[OperandBundle::create("tag", &[i32_type.const_zero().into()])], + /// "func_ret" + /// ) + /// .unwrap() + /// .try_as_basic_value() + /// .unwrap_left(); + /// builder.build_return(Some(&ret_val)).unwrap(); + /// + /// # module.verify().unwrap(); + /// ``` + #[llvm_versions(18..)] + pub fn build_direct_call_with_operand_bundles( + &self, + function: FunctionValue<'ctx>, + args: &[BasicMetadataValueEnum<'ctx>], + operand_bundles: &[OperandBundle<'ctx>], + name: &str, + ) -> Result, BuilderError> { + self.build_call_with_operand_bundles_help( + function.get_type(), + function.as_value_ref(), + args, + operand_bundles, + name, + ) + } + /// Call a function pointer. Because a pointer does not carry a type, the type of the function /// must be specified explicitly. /// @@ -352,6 +407,28 @@ impl<'ctx> Builder<'ctx> { self.build_call_help(function_type, function_pointer.as_value_ref(), args, name) } + /// Build a call instruction to a function pointer, with attached operand bundles. + /// + /// See [Builder::build_direct_call_with_operand_bundles] for a usage example + /// with operand bundles. + #[llvm_versions(18..)] + pub fn build_indirect_call_with_operand_bundles( + &self, + function_type: FunctionType<'ctx>, + function_pointer: PointerValue<'ctx>, + args: &[BasicMetadataValueEnum<'ctx>], + operand_bundles: &[OperandBundle<'ctx>], + name: &str, + ) -> Result, BuilderError> { + self.build_call_with_operand_bundles_help( + function_type, + function_pointer.as_value_ref(), + args, + operand_bundles, + name, + ) + } + #[llvm_versions(15..)] fn build_call_help( &self, @@ -388,6 +465,49 @@ impl<'ctx> Builder<'ctx> { unsafe { Ok(CallSiteValue::new(value)) } } + #[llvm_versions(18..)] + fn build_call_with_operand_bundles_help( + &self, + function_type: FunctionType<'ctx>, + fn_val_ref: LLVMValueRef, + args: &[BasicMetadataValueEnum<'ctx>], + operand_bundles: &[OperandBundle<'ctx>], + name: &str, + ) -> Result, BuilderError> { + use llvm_sys::prelude::LLVMOperandBundleRef; + + if self.positioned.get() != PositionState::Set { + return Err(BuilderError::UnsetPosition); + } + // LLVM gets upset when void return calls are named because they don't return anything + let name = match function_type.get_return_type() { + None => "", + Some(_) => name, + }; + + let fn_ty_ref = function_type.as_type_ref(); + + let c_string = to_c_str(name); + let mut args: Vec = args.iter().map(|val| val.as_value_ref()).collect(); + let mut operand_bundles: Vec = + operand_bundles.iter().map(|val| val.as_mut_ptr()).collect(); + + let value = unsafe { + LLVMBuildCallWithOperandBundles( + self.builder, + fn_ty_ref, + fn_val_ref, + args.as_mut_ptr(), + args.len() as u32, + operand_bundles.as_mut_ptr(), + operand_bundles.len() as u32, + c_string.as_ptr(), + ) + }; + + unsafe { Ok(CallSiteValue::new(value)) } + } + /// An invoke is similar to a normal function call, but used to /// call functions that may throw an exception, and then respond to the exception. /// diff --git a/src/values/call_site_value.rs b/src/values/call_site_value.rs index 07602f8d369..7d307ef34ed 100644 --- a/src/values/call_site_value.rs +++ b/src/values/call_site_value.rs @@ -11,6 +11,8 @@ use llvm_sys::prelude::LLVMValueRef; use llvm_sys::LLVMTypeKind; use crate::attributes::{Attribute, AttributeLoc}; +#[llvm_versions(18..)] +use crate::values::operand_bundle::OperandBundleIter; use crate::values::{AsValueRef, BasicValueEnum, FunctionValue, InstructionValue, Value}; use super::{AnyValue, InstructionOpcode}; @@ -592,6 +594,47 @@ impl<'ctx> CallSiteValue<'ctx> { unsafe { LLVMSetInstrParamAlignment(self.as_value_ref(), loc.get_index(), alignment) } } + + /// Iterate over operand bundles. + /// + /// # Example + /// + /// ``` + /// use inkwell::context::Context; + /// use inkwell::values::OperandBundle; + /// + /// let context = Context::create(); + /// let module = context.create_module("op_bundles"); + /// let builder = context.create_builder(); + /// + /// let void_type = context.void_type(); + /// let i32_type = context.i32_type(); + /// let fn_type = void_type.fn_type(&[], false); + /// let fn_value = module.add_function("func", fn_type, None); + /// + /// let basic_block = context.append_basic_block(fn_value, "entry"); + /// builder.position_at_end(basic_block); + /// + /// // Recursive call + /// let callinst = builder.build_direct_call_with_operand_bundles( + /// fn_value, + /// &[], + /// &[OperandBundle::create("tag0", &[i32_type.const_zero().into()]), OperandBundle::create("tag1", &[])], + /// "call" + /// ).unwrap(); + /// + /// builder.build_return(None).unwrap(); + /// # module.verify().unwrap(); + /// + /// let mut op_bundles_iter = callinst.get_operand_bundles(); + /// assert_eq!(op_bundles_iter.len(), 2); + /// let tags: Vec = op_bundles_iter.map(|ob| ob.get_tag().unwrap().into()).collect(); + /// assert_eq!(tags, vec!["tag0", "tag1"]); + /// ``` + #[llvm_versions(18..)] + pub fn get_operand_bundles(&self) -> OperandBundleIter<'_, 'ctx> { + OperandBundleIter::new(self) + } } unsafe impl AsValueRef for CallSiteValue<'_> { diff --git a/src/values/mod.rs b/src/values/mod.rs index 953b4449c37..7a90c205c32 100644 --- a/src/values/mod.rs +++ b/src/values/mod.rs @@ -20,6 +20,9 @@ mod struct_value; mod traits; mod vec_value; +#[cfg(feature = "llvm18-0")] +pub(crate) mod operand_bundle; + #[cfg(not(any( feature = "llvm15-0", feature = "llvm16-0", @@ -36,6 +39,9 @@ mod callable_value; )))] pub use crate::values::callable_value::CallableValue; +#[llvm_versions(18..)] +pub use crate::values::operand_bundle::OperandBundle; + use crate::support::{to_c_str, LLVMString}; pub use crate::values::array_value::ArrayValue; pub use crate::values::basic_value_use::BasicValueUse; diff --git a/src/values/operand_bundle.rs b/src/values/operand_bundle.rs new file mode 100644 index 00000000000..d573b744c22 --- /dev/null +++ b/src/values/operand_bundle.rs @@ -0,0 +1,197 @@ +use crate::context::Context; +use crate::support::to_c_str; +use crate::values::{AnyValueEnum, AsValueRef, BasicValueEnum, CallSiteValue}; +use llvm_sys::core::{ + LLVMCreateOperandBundle, LLVMDisposeOperandBundle, LLVMGetNumOperandBundleArgs, LLVMGetNumOperandBundles, + LLVMGetOperandBundleArgAtIndex, LLVMGetOperandBundleAtIndex, LLVMGetOperandBundleTag, +}; +use llvm_sys::prelude::{LLVMOperandBundleRef, LLVMValueRef}; +use std::cell::Cell; +use std::ffi::CStr; +use std::marker::PhantomData; + +/// One of an instruction's operand bundles. +#[derive(Debug)] +pub struct OperandBundle<'ctx> { + bundle: Cell, + _marker: PhantomData<&'ctx Context>, +} + +/// Iterator over an instruction's operand bundles. +#[derive(Debug)] +pub struct OperandBundleIter<'a, 'ctx> { + instruction: &'a CallSiteValue<'ctx>, + current: u32, + size: u32, +} + +/// Iterator over an operand bundle's arguments. +#[derive(Debug)] +pub struct OperandBundleArgsIter<'a, 'ctx> { + bundle: &'a OperandBundle<'ctx>, + current: u32, + size: u32, +} + +impl<'ctx> OperandBundle<'ctx> { + /// Get an operand bundle from a [LLVMOperandBundleRef]. + /// + /// # Safety + /// + /// The ref must be valid and represent an operand bundle. + pub unsafe fn new(bundle: LLVMOperandBundleRef) -> Self { + Self { + bundle: Cell::new(bundle), + _marker: PhantomData, + } + } + + /// Create a new operand bundle. + /// + /// # Example + /// + /// ``` + /// use inkwell::context::Context; + /// use inkwell::values::OperandBundle; + /// + /// let context = Context::create(); + /// let i32_type = context.i32_type(); + /// + /// let op_bundle = OperandBundle::create("tag", &[i32_type.const_zero().into()]); + /// + /// assert_eq!(op_bundle.get_tag().unwrap(), "tag"); + /// let arg = op_bundle.get_args().nth(0).unwrap().into_int_value(); + /// assert!(arg.is_const()); + /// assert_eq!(arg.get_zero_extended_constant().unwrap(), 0); + /// ``` + pub fn create(tag: &str, args: &[AnyValueEnum<'ctx>]) -> Self { + let c_tag = to_c_str(tag); + let mut args: Vec = args.iter().map(|value| value.as_value_ref()).collect(); + + unsafe { + let bundle = LLVMCreateOperandBundle(c_tag.as_ptr(), tag.len(), args.as_mut_ptr(), args.len() as u32); + Self::new(bundle) + } + } + + /// Acquire the underlying raw pointer belonging to this `OperandBundle` type. + pub fn as_mut_ptr(&self) -> LLVMOperandBundleRef { + self.bundle.get() + } + + /// Get this operand bundle's tag. + /// + /// # Example + /// + /// ``` + /// use inkwell::values::OperandBundle; + /// + /// let op_bundle = OperandBundle::create("tag", &[]); + /// assert_eq!(op_bundle.get_tag().unwrap(), "tag"); + /// ``` + pub fn get_tag(&self) -> Result<&str, std::str::Utf8Error> { + unsafe { + let mut size = 0usize; + let tag = LLVMGetOperandBundleTag(self.bundle.get(), &mut size as *mut usize); + CStr::from_ptr(tag).to_str() + } + } + + /// Iterate over this operand bundle's arguments. + /// + /// # Example + /// + /// ``` + /// use inkwell::context::Context; + /// use inkwell::values::OperandBundle; + /// + /// let context = Context::create(); + /// let i32_type = context.i32_type(); + /// let f32_type = context.f32_type(); + /// + /// let op_bundle = OperandBundle::create("tag", &[i32_type.const_zero().into(), f32_type.const_float(1.23).into()]); + /// assert_eq!(op_bundle.get_args().count(), 2); + /// assert_eq!(op_bundle.get_args().len(), 2); + /// ``` + pub fn get_args(&self) -> OperandBundleArgsIter<'_, 'ctx> { + OperandBundleArgsIter::new(self) + } +} + +impl Drop for OperandBundle<'_> { + fn drop(&mut self) { + unsafe { LLVMDisposeOperandBundle(self.as_mut_ptr()) } + } +} + +impl<'a, 'ctx> OperandBundleIter<'a, 'ctx> { + pub(crate) fn new(instruction: &'a CallSiteValue<'ctx>) -> Self { + let size = unsafe { LLVMGetNumOperandBundles(instruction.as_value_ref()) }; + + Self { + instruction, + current: 0, + size, + } + } +} + +impl<'ctx> Iterator for OperandBundleIter<'_, 'ctx> { + type Item = OperandBundle<'ctx>; + + fn next(&mut self) -> Option { + if self.current < self.size { + let bundle = unsafe { + OperandBundle::new(LLVMGetOperandBundleAtIndex( + self.instruction.as_value_ref(), + self.current, + )) + }; + self.current += 1; + Some(bundle) + } else { + None + } + } + + fn size_hint(&self) -> (usize, Option) { + let remaining = (self.size - self.current) as usize; + (remaining, Some(remaining)) + } +} + +impl ExactSizeIterator for OperandBundleIter<'_, '_> {} + +impl<'a, 'ctx> OperandBundleArgsIter<'a, 'ctx> { + fn new(bundle: &'a OperandBundle<'ctx>) -> Self { + let size = unsafe { LLVMGetNumOperandBundleArgs(bundle.as_mut_ptr()) }; + Self { + bundle, + current: 0, + size, + } + } +} + +impl<'ctx> Iterator for OperandBundleArgsIter<'_, 'ctx> { + type Item = BasicValueEnum<'ctx>; + + fn next(&mut self) -> Option { + if self.current < self.size { + unsafe { + let arg = LLVMGetOperandBundleArgAtIndex(self.bundle.as_mut_ptr(), self.current); + self.current += 1; + Some(BasicValueEnum::new(arg)) + } + } else { + None + } + } + + fn size_hint(&self) -> (usize, Option) { + let remaining = (self.size - self.current) as usize; + (remaining, Some(remaining)) + } +} + +impl ExactSizeIterator for OperandBundleArgsIter<'_, '_> {} diff --git a/tests/all/test_values.rs b/tests/all/test_values.rs index ccf723676e6..3910360e630 100644 --- a/tests/all/test_values.rs +++ b/tests/all/test_values.rs @@ -4,6 +4,8 @@ use inkwell::comdat::ComdatSelectionKind; use inkwell::context::Context; use inkwell::module::Linkage::*; use inkwell::types::{AnyTypeEnum, StringRadix, VectorType}; +#[llvm_versions(18..)] +use inkwell::values::OperandBundle; use inkwell::values::{AnyValue, InstructionOpcode::*, FIRST_CUSTOM_METADATA_KIND_ID}; use inkwell::{AddressSpace, DLLStorageClass, GlobalVisibility, ThreadLocalMode}; @@ -98,6 +100,53 @@ fn test_call_site_tail_call_attributes() { assert!(call_site.is_tail_call()); } +#[llvm_versions(18..)] +#[test] +fn test_call_site_operand_bundles() { + let context = Context::create(); + let module = context.create_module("my_mod"); + let builder = context.create_builder(); + + let void_type = context.void_type(); + let i32_type = context.i32_type(); + let fn_type = void_type.fn_type(&[], false); + let fn_value = module.add_function("my_fn", fn_type, None); + let entry_bb = context.append_basic_block(fn_value, "entry"); + + builder.position_at_end(entry_bb); + let call_site = builder + .build_direct_call_with_operand_bundles( + fn_value, + &[], + &[ + OperandBundle::create("tag0", &[i32_type.const_zero().into(), i32_type.const_zero().into()]), + OperandBundle::create("tag1", &[]), + ], + "call", + ) + .unwrap(); + builder.build_return(None).unwrap(); + + assert!(module.verify().is_ok()); + + let mut op_bundle_iter = call_site.get_operand_bundles(); + assert_eq!(op_bundle_iter.len(), 2); + + let op_bundle0 = op_bundle_iter.next().unwrap(); + let op_bundle1 = op_bundle_iter.next().unwrap(); + assert!(op_bundle_iter.next().is_none()); + + assert_eq!(op_bundle0.get_tag().unwrap(), "tag0"); + assert_eq!(op_bundle1.get_tag().unwrap(), "tag1"); + + assert_eq!(op_bundle1.get_args().len(), 0); + assert!(op_bundle1.get_args().next().is_none()); + + let args_iter = op_bundle0.get_args(); + assert_eq!(args_iter.len(), 2); + args_iter.for_each(|arg| assert!(arg.into_int_value().is_const())); +} + #[test] fn test_set_get_name() { let context = Context::create(); From 2458297765b99e4ccb9c9c84b2027424e8de84b1 Mon Sep 17 00:00:00 2001 From: naci Date: Thu, 10 Oct 2024 08:01:42 +0300 Subject: [PATCH 10/13] wrapper for LLVMBuildBinOp (#539) * LLVMBuildBinOp * fix lifetime --- src/builder.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/builder.rs b/src/builder.rs index accb513fe0e..6b7b079f887 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -5,7 +5,7 @@ use llvm_sys::core::LLVMBuildCallWithOperandBundles; use llvm_sys::core::{ LLVMAddCase, LLVMAddClause, LLVMAddDestination, LLVMBuildAShr, LLVMBuildAdd, LLVMBuildAddrSpaceCast, LLVMBuildAggregateRet, LLVMBuildAlloca, LLVMBuildAnd, LLVMBuildArrayAlloca, LLVMBuildArrayMalloc, - LLVMBuildAtomicCmpXchg, LLVMBuildAtomicRMW, LLVMBuildBitCast, LLVMBuildBr, LLVMBuildCast, LLVMBuildCondBr, + LLVMBuildAtomicCmpXchg, LLVMBuildAtomicRMW, LLVMBuildBinOp, LLVMBuildBitCast, LLVMBuildBr, LLVMBuildCast, LLVMBuildCondBr, LLVMBuildExactSDiv, LLVMBuildExtractElement, LLVMBuildExtractValue, LLVMBuildFAdd, LLVMBuildFCmp, LLVMBuildFDiv, LLVMBuildFMul, LLVMBuildFNeg, LLVMBuildFPCast, LLVMBuildFPExt, LLVMBuildFPToSI, LLVMBuildFPToUI, LLVMBuildFPTrunc, LLVMBuildFRem, LLVMBuildFSub, LLVMBuildFence, LLVMBuildFree, LLVMBuildGlobalString, LLVMBuildGlobalStringPtr, @@ -2622,6 +2622,16 @@ impl<'ctx> Builder<'ctx> { unsafe { Ok(T::new(value)) } } + pub fn build_binop>(&self, op: InstructionOpcode, lhs: T, rhs: T, name: &str) -> Result, BuilderError> { + if self.positioned.get() != PositionState::Set { + return Err(BuilderError::UnsetPosition); + } + let c_string = to_c_str(name); + let value = unsafe { LLVMBuildBinOp(self.builder, op.into(), lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; + + unsafe { Ok(BasicValueEnum::new(value)) } + } + pub fn build_cast, V: BasicValue<'ctx>>( &self, op: InstructionOpcode, From 7b410298b6a93450adaa90b1841d5805a3038f12 Mon Sep 17 00:00:00 2001 From: Cyrill Leutwiler Date: Fri, 25 Oct 2024 17:16:26 +0200 Subject: [PATCH 11/13] bump llvm-sys (#549) Signed-off-by: Cyrill Leutwiler --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 05a55916d73..3333ab9df93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -150,8 +150,8 @@ llvm-sys-130 = { package = "llvm-sys", version = "130.0.4", optional = true } llvm-sys-140 = { package = "llvm-sys", version = "140.0.2", optional = true } llvm-sys-150 = { package = "llvm-sys", version = "150.0.3", optional = true } llvm-sys-160 = { package = "llvm-sys", version = "160.1.0", optional = true } -llvm-sys-170 = { package = "llvm-sys", version = "170.0.1", optional = true } -llvm-sys-180 = { package = "llvm-sys", version = "180.0.0", optional = true } +llvm-sys-170 = { package = "llvm-sys", version = "170.2.0", optional = true } +llvm-sys-180 = { package = "llvm-sys", version = "181.2.0", optional = true } either = "1.5" libc = "0.2" From 8bd9f087c7fedd3897016568184aa8516d6a0abf Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Mon, 28 Oct 2024 02:20:20 +0000 Subject: [PATCH 12/13] Add scalable vector (#542) * feat: add scalable vector support * test: add some scalable vector * feat: add separate scalable vector type and value Introduce `VectorBaseValue` trait for both fixed and scalable vector values. Add type, value and builder tests for scalable vector. Revise min. LLVM version from 11 to 12 due to llvm_sys. * fix: various bugs fix: remove always false functions style: cargo fmt fix: rename doc comments fix: remove leftover test fix: add conditional llvm versions to type kind variant fix: change to doctest to ignore fix: remove llvm 11 from scalable vector type test --------- Co-authored-by: Dan Kolsoi --- src/builder.rs | 26 +-- src/types/enums.rs | 56 +++++- src/types/float_type.rs | 33 ++- src/types/int_type.rs | 21 +- src/types/mod.rs | 14 ++ src/types/ptr_type.rs | 26 ++- src/types/scalable_vec_type.rs | 289 ++++++++++++++++++++++++++ src/types/traits.rs | 30 ++- src/values/enums.rs | 88 +++++++- src/values/mod.rs | 6 +- src/values/scalable_vec_value.rs | 149 ++++++++++++++ src/values/traits.rs | 37 +++- tests/all/test_builder.rs | 290 +++++++++++++++++++++++++++ tests/all/test_instruction_values.rs | 2 +- tests/all/test_types.rs | 123 ++++++++++++ tests/all/test_values.rs | 241 +++++++++++++++++++++- 16 files changed, 1388 insertions(+), 43 deletions(-) create mode 100644 src/types/scalable_vec_type.rs create mode 100644 src/values/scalable_vec_value.rs diff --git a/src/builder.rs b/src/builder.rs index 6b7b079f887..ccdb811428d 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -51,7 +51,7 @@ use crate::values::CallableValue; use crate::values::{ AggregateValue, AggregateValueEnum, AsValueRef, BasicMetadataValueEnum, BasicValue, BasicValueEnum, CallSiteValue, FloatMathValue, FunctionValue, GlobalValue, InstructionOpcode, InstructionValue, IntMathValue, IntValue, PhiValue, - PointerMathValue, PointerValue, StructValue, VectorValue, + PointerMathValue, PointerValue, StructValue, VectorBaseValue, }; use crate::{AtomicOrdering, AtomicRMWBinOp, FloatPredicate, IntPredicate}; @@ -3064,9 +3064,9 @@ impl<'ctx> Builder<'ctx> { /// /// builder.build_return(Some(&extracted)).unwrap(); /// ``` - pub fn build_extract_element( + pub fn build_extract_element>( &self, - vector: VectorValue<'ctx>, + vector: V, index: IntValue<'ctx>, name: &str, ) -> Result, BuilderError> { @@ -3112,13 +3112,13 @@ impl<'ctx> Builder<'ctx> { /// builder.build_insert_element(vector_param, i32_seven, i32_zero, "insert").unwrap(); /// builder.build_return(None).unwrap(); /// ``` - pub fn build_insert_element>( + pub fn build_insert_element, W: VectorBaseValue<'ctx>>( &self, - vector: VectorValue<'ctx>, + vector: W, element: V, index: IntValue<'ctx>, name: &str, - ) -> Result, BuilderError> { + ) -> Result { if self.positioned.get() != PositionState::Set { return Err(BuilderError::UnsetPosition); } @@ -3134,7 +3134,7 @@ impl<'ctx> Builder<'ctx> { ) }; - unsafe { Ok(VectorValue::new(value)) } + unsafe { Ok(W::new(value)) } } pub fn build_unreachable(&self) -> Result, BuilderError> { @@ -3329,13 +3329,13 @@ impl<'ctx> Builder<'ctx> { } // REVIEW: Do we need to constrain types here? subtypes? - pub fn build_shuffle_vector( + pub fn build_shuffle_vector>( &self, - left: VectorValue<'ctx>, - right: VectorValue<'ctx>, - mask: VectorValue<'ctx>, + left: V, + right: V, + mask: V, name: &str, - ) -> Result, BuilderError> { + ) -> Result { if self.positioned.get() != PositionState::Set { return Err(BuilderError::UnsetPosition); } @@ -3350,7 +3350,7 @@ impl<'ctx> Builder<'ctx> { ) }; - unsafe { Ok(VectorValue::new(value)) } + unsafe { Ok(V::new(value)) } } // REVIEW: Is return type correct? diff --git a/src/types/enums.rs b/src/types/enums.rs index 39460e8c994..d17394698d4 100644 --- a/src/types/enums.rs +++ b/src/types/enums.rs @@ -5,7 +5,9 @@ use llvm_sys::LLVMTypeKind; use crate::support::LLVMString; use crate::types::traits::AsTypeRef; use crate::types::MetadataType; -use crate::types::{ArrayType, FloatType, FunctionType, IntType, PointerType, StructType, VectorType, VoidType}; +use crate::types::{ + ArrayType, FloatType, FunctionType, IntType, PointerType, ScalableVectorType, StructType, VectorType, VoidType, +}; use crate::values::{BasicValue, BasicValueEnum, IntValue}; use std::convert::TryFrom; @@ -70,6 +72,8 @@ enum_type_set! { StructType, /// A contiguous homogeneous "SIMD" container type. VectorType, + /// A contiguous homogenous scalable "SIMD" container type. + ScalableVectorType, /// A valueless type. VoidType, } @@ -89,6 +93,8 @@ enum_type_set! { StructType, /// A contiguous homogeneous "SIMD" container type. VectorType, + /// A contiguous homogenous scalable "SIMD" container type. + ScalableVectorType, } } enum_type_set! { @@ -99,6 +105,7 @@ enum_type_set! { PointerType, StructType, VectorType, + ScalableVectorType, MetadataType, } } @@ -152,6 +159,14 @@ impl<'ctx> BasicMetadataTypeEnum<'ctx> { } } + pub fn into_scalable_vector_type(self) -> ScalableVectorType<'ctx> { + if let BasicMetadataTypeEnum::ScalableVectorType(t) = self { + t + } else { + panic!("Found {:?} but expected another variant", self); + } + } + pub fn into_metadata_type(self) -> MetadataType<'ctx> { if let BasicMetadataTypeEnum::MetadataType(t) = self { t @@ -188,6 +203,10 @@ impl<'ctx> BasicMetadataTypeEnum<'ctx> { matches!(self, BasicMetadataTypeEnum::VectorType(_)) } + pub fn is_scalable_vector_type(self) -> bool { + matches!(self, BasicMetadataTypeEnum::ScalableVectorType(_)) + } + /// Print the definition of a `BasicMetadataTypeEnum` to `LLVMString`. pub fn print_to_string(self) -> LLVMString { match self { @@ -197,6 +216,7 @@ impl<'ctx> BasicMetadataTypeEnum<'ctx> { BasicMetadataTypeEnum::PointerType(t) => t.print_to_string(), BasicMetadataTypeEnum::StructType(t) => t.print_to_string(), BasicMetadataTypeEnum::VectorType(t) => t.print_to_string(), + BasicMetadataTypeEnum::ScalableVectorType(t) => t.print_to_string(), BasicMetadataTypeEnum::MetadataType(t) => t.print_to_string(), } } @@ -244,7 +264,7 @@ impl<'ctx> AnyTypeEnum<'ctx> { feature = "llvm17-0", feature = "llvm18-0" ))] - LLVMTypeKind::LLVMScalableVectorTypeKind => AnyTypeEnum::VectorType(VectorType::new(type_)), + LLVMTypeKind::LLVMScalableVectorTypeKind => AnyTypeEnum::ScalableVectorType(ScalableVectorType::new(type_)), // FIXME: should inkwell support metadata as AnyType? LLVMTypeKind::LLVMMetadataTypeKind => panic!("Metadata type is not supported as AnyType."), LLVMTypeKind::LLVMX86_MMXTypeKind => panic!("FIXME: Unsupported type: MMX"), @@ -325,6 +345,14 @@ impl<'ctx> AnyTypeEnum<'ctx> { } } + pub fn into_scalable_vector_type(self) -> ScalableVectorType<'ctx> { + if let AnyTypeEnum::ScalableVectorType(t) = self { + t + } else { + panic!("Found {:?} but expected the ScalableVectorType variant", self); + } + } + pub fn into_void_type(self) -> VoidType<'ctx> { if let AnyTypeEnum::VoidType(t) = self { t @@ -373,6 +401,7 @@ impl<'ctx> AnyTypeEnum<'ctx> { AnyTypeEnum::PointerType(t) => Some(t.size_of()), AnyTypeEnum::StructType(t) => t.size_of(), AnyTypeEnum::VectorType(t) => t.size_of(), + AnyTypeEnum::ScalableVectorType(t) => t.size_of(), AnyTypeEnum::VoidType(_) => None, AnyTypeEnum::FunctionType(_) => None, } @@ -387,6 +416,7 @@ impl<'ctx> AnyTypeEnum<'ctx> { AnyTypeEnum::PointerType(t) => t.print_to_string(), AnyTypeEnum::StructType(t) => t.print_to_string(), AnyTypeEnum::VectorType(t) => t.print_to_string(), + AnyTypeEnum::ScalableVectorType(t) => t.print_to_string(), AnyTypeEnum::VoidType(t) => t.print_to_string(), AnyTypeEnum::FunctionType(t) => t.print_to_string(), } @@ -432,7 +462,9 @@ impl<'ctx> BasicTypeEnum<'ctx> { feature = "llvm17-0", feature = "llvm18-0" ))] - LLVMTypeKind::LLVMScalableVectorTypeKind => BasicTypeEnum::VectorType(VectorType::new(type_)), + LLVMTypeKind::LLVMScalableVectorTypeKind => { + BasicTypeEnum::ScalableVectorType(ScalableVectorType::new(type_)) + }, LLVMTypeKind::LLVMMetadataTypeKind => panic!("Unsupported basic type: Metadata"), // see https://llvm.org/docs/LangRef.html#x86-mmx-type LLVMTypeKind::LLVMX86_MMXTypeKind => panic!("Unsupported basic type: MMX"), @@ -504,6 +536,14 @@ impl<'ctx> BasicTypeEnum<'ctx> { } } + pub fn into_scalable_vector_type(self) -> ScalableVectorType<'ctx> { + if let BasicTypeEnum::ScalableVectorType(t) = self { + t + } else { + panic!("Found {:?} but expected the ScalableVectorType variant", self); + } + } + pub fn is_array_type(self) -> bool { matches!(self, BasicTypeEnum::ArrayType(_)) } @@ -528,6 +568,10 @@ impl<'ctx> BasicTypeEnum<'ctx> { matches!(self, BasicTypeEnum::VectorType(_)) } + pub fn is_scalable_vector_type(self) -> bool { + matches!(self, BasicTypeEnum::ScalableVectorType(_)) + } + /// Creates a constant `BasicValueZero`. /// /// # Example @@ -547,6 +591,7 @@ impl<'ctx> BasicTypeEnum<'ctx> { BasicTypeEnum::PointerType(ty) => ty.const_zero().as_basic_value_enum(), BasicTypeEnum::StructType(ty) => ty.const_zero().as_basic_value_enum(), BasicTypeEnum::VectorType(ty) => ty.const_zero().as_basic_value_enum(), + BasicTypeEnum::ScalableVectorType(ty) => ty.const_zero().as_basic_value_enum(), } } @@ -559,6 +604,7 @@ impl<'ctx> BasicTypeEnum<'ctx> { BasicTypeEnum::PointerType(t) => t.print_to_string(), BasicTypeEnum::StructType(t) => t.print_to_string(), BasicTypeEnum::VectorType(t) => t.print_to_string(), + BasicTypeEnum::ScalableVectorType(t) => t.print_to_string(), } } } @@ -575,6 +621,7 @@ impl<'ctx> TryFrom> for BasicTypeEnum<'ctx> { PointerType(pt) => pt.into(), StructType(st) => st.into(), VectorType(vt) => vt.into(), + ScalableVectorType(vt) => vt.into(), VoidType(_) | FunctionType(_) => return Err(()), }) } @@ -592,6 +639,7 @@ impl<'ctx> TryFrom> for BasicMetadataTypeEnum<'ctx> { PointerType(pt) => pt.into(), StructType(st) => st.into(), VectorType(vt) => vt.into(), + ScalableVectorType(vt) => vt.into(), VoidType(_) | FunctionType(_) => return Err(()), }) } @@ -609,6 +657,7 @@ impl<'ctx> TryFrom> for BasicTypeEnum<'ctx> { PointerType(pt) => pt.into(), StructType(st) => st.into(), VectorType(vt) => vt.into(), + ScalableVectorType(vt) => vt.into(), MetadataType(_) => return Err(()), }) } @@ -624,6 +673,7 @@ impl<'ctx> From> for BasicMetadataTypeEnum<'ctx> { PointerType(pt) => pt.into(), StructType(st) => st.into(), VectorType(vt) => vt.into(), + ScalableVectorType(vt) => vt.into(), } } } diff --git a/src/types/float_type.rs b/src/types/float_type.rs index 6d028387890..3de4f2d11ce 100644 --- a/src/types/float_type.rs +++ b/src/types/float_type.rs @@ -6,7 +6,7 @@ use crate::context::ContextRef; use crate::support::LLVMString; use crate::types::enums::BasicMetadataTypeEnum; use crate::types::traits::AsTypeRef; -use crate::types::{ArrayType, FunctionType, PointerType, Type, VectorType}; +use crate::types::{ArrayType, FunctionType, PointerType, ScalableVectorType, Type, VectorType}; use crate::values::{ArrayValue, FloatValue, GenericValue, IntValue}; use crate::AddressSpace; @@ -64,7 +64,7 @@ impl<'ctx> FloatType<'ctx> { self.float_type.array_type(size) } - /// Creates a `VectorType` with this `FloatType` for its element type. + /// Creates a `ScalableVectorType` with this `FloatType` for its element type. /// /// # Example /// @@ -73,15 +73,34 @@ impl<'ctx> FloatType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); - /// let f32_vector_type = f32_type.vec_type(3); + /// let f32_scalable_vector_type = f32_type.vec_type(3); /// - /// assert_eq!(f32_vector_type.get_size(), 3); - /// assert_eq!(f32_vector_type.get_element_type().into_float_type(), f32_type); + /// assert_eq!(f32_scalable_vector_type.get_size(), 3); + /// assert_eq!(f32_scalable_vector_type.get_element_type().into_float_type(), f32_type); /// ``` pub fn vec_type(self, size: u32) -> VectorType<'ctx> { self.float_type.vec_type(size) } + /// Creates a scalable `VectorType` with this `FloatType` for its element type. + /// + /// # Example + /// + /// ```no_run + /// use inkwell::context::Context; + /// + /// let context = Context::create(); + /// let f32_type = context.f32_type(); + /// let f32_vector_type = f32_type.scalable_vec_type(3); + /// + /// assert_eq!(f32_vector_type.get_size(), 3); + /// assert_eq!(f32_vector_type.get_element_type().into_float_type(), f32_type); + /// ``` + #[llvm_versions(12..)] + pub fn scalable_vec_type(self, size: u32) -> ScalableVectorType<'ctx> { + self.float_type.scalable_vec_type(size) + } + /// Creates a `FloatValue` representing a constant value of this `FloatType`. /// It will be automatically assigned this `FloatType`'s `Context`. /// @@ -128,9 +147,9 @@ impl<'ctx> FloatType<'ctx> { /// assert_eq!(f64_val.print_to_string().to_string(), "double 0x7FF0000000000000"); /// ``` pub unsafe fn const_float_from_string(self, slice: &str) -> FloatValue<'ctx> { - assert!(!slice.is_empty()); + assert!(!slice.is_empty()); - unsafe { + unsafe { FloatValue::new(LLVMConstRealOfStringAndSize( self.as_type_ref(), slice.as_ptr() as *const ::libc::c_char, diff --git a/src/types/int_type.rs b/src/types/int_type.rs index c5867ce0090..95f43a670b2 100644 --- a/src/types/int_type.rs +++ b/src/types/int_type.rs @@ -7,7 +7,7 @@ use llvm_sys::prelude::LLVMTypeRef; use crate::context::ContextRef; use crate::support::LLVMString; use crate::types::traits::AsTypeRef; -use crate::types::{ArrayType, FunctionType, PointerType, Type, VectorType}; +use crate::types::{ArrayType, FunctionType, PointerType, ScalableVectorType, Type, VectorType}; use crate::values::{ArrayValue, GenericValue, IntValue}; use crate::AddressSpace; @@ -244,6 +244,25 @@ impl<'ctx> IntType<'ctx> { self.int_type.vec_type(size) } + /// Creates a `ScalableVectorType` with this `IntType` for its element type. + /// + /// # Example + /// + /// ```no_run + /// use inkwell::context::Context; + /// + /// let context = Context::create(); + /// let i8_type = context.i8_type(); + /// let i8_scalable_vector_type = i8_type.scalable_vec_type(3); + /// + /// assert_eq!(i8_scalable_vector_type.get_size(), 3); + /// assert_eq!(i8_scalable_vector_type.get_element_type().into_int_type(), i8_type); + /// ``` + #[llvm_versions(12..)] + pub fn scalable_vec_type(self, size: u32) -> ScalableVectorType<'ctx> { + self.int_type.scalable_vec_type(size) + } + /// Gets a reference to the `Context` this `IntType` was created in. /// /// # Example diff --git a/src/types/mod.rs b/src/types/mod.rs index cb588986b25..6d9c1c780fc 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -14,6 +14,8 @@ mod metadata_type; #[deny(missing_docs)] mod ptr_type; #[deny(missing_docs)] +mod scalable_vec_type; +#[deny(missing_docs)] mod struct_type; #[deny(missing_docs)] mod traits; @@ -29,12 +31,16 @@ pub use crate::types::fn_type::FunctionType; pub use crate::types::int_type::{IntType, StringRadix}; pub use crate::types::metadata_type::MetadataType; pub use crate::types::ptr_type::PointerType; +pub use crate::types::scalable_vec_type::ScalableVectorType; pub use crate::types::struct_type::FieldTypesIter; pub use crate::types::struct_type::StructType; pub use crate::types::traits::{AnyType, AsTypeRef, BasicType, FloatMathType, IntMathType, PointerMathType}; pub use crate::types::vec_type::VectorType; pub use crate::types::void_type::VoidType; +#[llvm_versions(12..)] +use llvm_sys::core::LLVMScalableVectorType; + #[llvm_versions(12..)] use llvm_sys::core::LLVMGetPoison; @@ -95,6 +101,14 @@ impl<'ctx> Type<'ctx> { unsafe { VectorType::new(LLVMVectorType(self.ty, size)) } } + #[llvm_versions(12..)] + fn scalable_vec_type(self, size: u32) -> ScalableVectorType<'ctx> { + assert!(size != 0, "Vectors of size zero are not allowed."); + // -- https://llvm.org/docs/LangRef.html#vector-type + + unsafe { ScalableVectorType::new(LLVMScalableVectorType(self.ty, size)) } + } + #[cfg(not(feature = "experimental"))] fn fn_type(self, param_types: &[BasicMetadataTypeEnum<'ctx>], is_var_args: bool) -> FunctionType<'ctx> { let mut param_types: Vec = param_types.iter().map(|val| val.as_type_ref()).collect(); diff --git a/src/types/ptr_type.rs b/src/types/ptr_type.rs index 1ab7dedd76d..575aeae5bd0 100644 --- a/src/types/ptr_type.rs +++ b/src/types/ptr_type.rs @@ -8,7 +8,7 @@ use crate::support::LLVMString; use crate::types::traits::AsTypeRef; #[llvm_versions(..=14)] use crate::types::AnyTypeEnum; -use crate::types::{ArrayType, FunctionType, Type, VectorType}; +use crate::types::{ArrayType, FunctionType, ScalableVectorType, Type, VectorType}; use crate::values::{ArrayValue, IntValue, PointerValue}; use crate::AddressSpace; @@ -326,6 +326,30 @@ impl<'ctx> PointerType<'ctx> { self.ptr_type.vec_type(size) } + /// Creates a `ScalableVectorType` with this `PointerType` for its element type. + /// + /// # Example + /// + /// ```no_run + /// use inkwell::context::Context; + /// use inkwell::AddressSpace; + /// + /// let context = Context::create(); + /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] + /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); + /// let f32_ptr_scalable_vec_type = f32_ptr_type.scalable_vec_type(3); + /// + /// assert_eq!(f32_ptr_scalable_vec_type.get_size(), 3); + /// assert_eq!(f32_ptr_scalable_vec_type.get_element_type().into_pointer_type(), f32_ptr_type); + /// ``` + #[llvm_versions(12..)] + pub fn scalable_vec_type(self, size: u32) -> ScalableVectorType<'ctx> { + self.ptr_type.scalable_vec_type(size) + } + // SubType: PointerrType -> BT? /// Gets the element type of this `PointerType`. /// diff --git a/src/types/scalable_vec_type.rs b/src/types/scalable_vec_type.rs new file mode 100644 index 00000000000..b4890768158 --- /dev/null +++ b/src/types/scalable_vec_type.rs @@ -0,0 +1,289 @@ +use llvm_sys::core::LLVMGetVectorSize; +use llvm_sys::prelude::LLVMTypeRef; + +use crate::context::ContextRef; +use crate::support::LLVMString; +use crate::types::enums::BasicMetadataTypeEnum; +use crate::types::{traits::AsTypeRef, ArrayType, BasicTypeEnum, FunctionType, PointerType, Type}; +use crate::values::{ArrayValue, IntValue, ScalableVectorValue}; +use crate::AddressSpace; + +use std::fmt::{self, Display}; + +/// A `ScalableVectorType` is the type of a scalable multiple value SIMD constant or variable. +#[derive(Debug, PartialEq, Eq, Clone, Copy)] +pub struct ScalableVectorType<'ctx> { + scalable_vec_type: Type<'ctx>, +} + +impl<'ctx> ScalableVectorType<'ctx> { + /// Create `ScalableVectorType` from [`LLVMTypeRef`] + /// + /// # Safety + /// Undefined behavior, if referenced type isn't scalable vector type + pub unsafe fn new(scalable_vector_type: LLVMTypeRef) -> Self { + assert!(!scalable_vector_type.is_null()); + + ScalableVectorType { + scalable_vec_type: Type::new(scalable_vector_type), + } + } + + // TODO: impl only for ScalableVectorType> + // REVIEW: What about Opaque struct hiding in deeper levels + // like ScalableVectorType>>? + /// Gets the size of this `ScalableVectorType`. Value may vary depending on the target architecture. + /// + /// # Example + /// + /// ```ignore + /// use inkwell::context::Context; + /// + /// let context = Context::create(); + /// let f32_type = context.f32_type(); + /// let f32_scalable_vec_type = f32_type.scalable_vec_type(3); + /// let f32_scalable_vec_type_size = f32_scalable_vec_type.size_of(); + /// ``` + pub fn size_of(self) -> Option> { + self.scalable_vec_type.size_of() + } + + /// Gets the alignment of this `ScalableVectorType`. Value may vary depending on the target architecture. + /// + /// # Example + /// + /// ```ignore + /// use inkwell::context::Context; + /// + /// let context = Context::create(); + /// let f32_type = context.f32_type(); + /// let f32_scalable_vec_type = f32_type.scalable_vec_type(7); + /// let f32_type_alignment = f32_scalable_vec_type.get_alignment(); + /// ``` + pub fn get_alignment(self) -> IntValue<'ctx> { + self.scalable_vec_type.get_alignment() + } + + /// Gets the size of this `ScalableVectorType`. + /// + /// # Example + /// + /// ```ignore + /// use inkwell::context::Context; + /// + /// let context = Context::create(); + /// let f32_type = context.f32_type(); + /// let f32_scalable_vector_type = f32_type.scalable_vec_type(3); + /// + /// assert_eq!(f32_scalable_vector_type.get_size(), 3); + /// assert_eq!(f32_scalable_vector_type.get_element_type().into_float_type(), f32_type); + /// ``` + pub fn get_size(self) -> u32 { + unsafe { LLVMGetVectorSize(self.as_type_ref()) } + } + + /// Creates a constant zero value of this `ScalableVectorType`. + /// + /// # Example + /// + /// ```ignore + /// use inkwell::context::Context; + /// + /// let context = Context::create(); + /// let f32_type = context.f32_type(); + /// let f32_scalable_vec_type = f32_type.scalable_vec_type(7); + /// let f32_scalable_vec_zero = f32_scalable_vec_type.const_zero(); + /// ``` + pub fn const_zero(self) -> ScalableVectorValue<'ctx> { + unsafe { ScalableVectorValue::new(self.scalable_vec_type.const_zero()) } + } + + /// Print the definition of a `ScalableVectorType` to `LLVMString`. + pub fn print_to_string(self) -> LLVMString { + self.scalable_vec_type.print_to_string() + } + + /// Creates an undefined instance of a `ScalableVectorType`. + /// + /// # Example + /// ```ignore + /// use inkwell::context::Context; + /// use inkwell::AddressSpace; + /// + /// let context = Context::create(); + /// let f32_type = context.f32_type(); + /// let f32_scalable_vec_type = f32_type.scalable_vec_type(3); + /// let f32_scalable_vec_undef = f32_scalable_vec_type.get_undef(); + /// + /// assert!(f32_scalable_vec_undef.is_undef()); + /// ``` + pub fn get_undef(self) -> ScalableVectorValue<'ctx> { + unsafe { ScalableVectorValue::new(self.scalable_vec_type.get_undef()) } + } + + /// Creates a poison instance of a `ScalableVectorType`. + /// + /// # Example + /// ```ignore + /// use inkwell::context::Context; + /// use inkwell::AddressSpace; + /// + /// let context = Context::create(); + /// let f32_type = context.f32_type(); + /// let f32_scalable_vec_type = f32_type.scalable_vec_type(3); + /// let f32_scalable_vec_poison = f32_scalable_vec_type.get_undef(); + /// + /// assert!(f32_scalable_vec_poison.is_undef()); + /// ``` + #[llvm_versions(12..)] + pub fn get_poison(self) -> ScalableVectorValue<'ctx> { + unsafe { ScalableVectorValue::new(self.scalable_vec_type.get_poison()) } + } + + // SubType: ScalableVectorType -> BT? + /// Gets the element type of this `ScalableVectorType`. + /// + /// # Example + /// + /// ```ignore + /// use inkwell::context::Context; + /// + /// let context = Context::create(); + /// let f32_type = context.f32_type(); + /// let f32_scalable_vector_type = f32_type.scalable_vec_type(3); + /// + /// assert_eq!(f32_scalable_vector_type.get_size(), 3); + /// assert_eq!(f32_scalable_vector_type.get_element_type().into_float_type(), f32_type); + /// ``` + pub fn get_element_type(self) -> BasicTypeEnum<'ctx> { + self.scalable_vec_type.get_element_type().as_basic_type_enum() + } + + /// Creates a `PointerType` with this `ScalableVectorType` for its element type. + /// + /// # Example + /// + /// ```ignore + /// use inkwell::context::Context; + /// use inkwell::AddressSpace; + /// + /// let context = Context::create(); + /// let f32_type = context.f32_type(); + /// let f32_scalable_vec_type = f32_type.scalable_vec_type(3); + /// let f32_scalable_vec_ptr_type = f32_scalable_vec_type.ptr_type(AddressSpace::default()); + /// + /// #[cfg(any( + /// feature = "llvm4-0", + /// feature = "llvm5-0", + /// feature = "llvm6-0", + /// feature = "llvm7-0", + /// feature = "llvm8-0", + /// feature = "llvm9-0", + /// feature = "llvm10-0", + /// feature = "llvm11-0", + /// feature = "llvm12-0", + /// feature = "llvm13-0", + /// feature = "llvm14-0" + /// ))] + /// assert_eq!(f32_scalable_vec_ptr_type.get_element_type().into_scalable_vector_type(), f32_scalable_vec_type); + /// ``` + #[cfg_attr( + any( + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ), + deprecated( + note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead." + ) + )] + pub fn ptr_type(self, address_space: AddressSpace) -> PointerType<'ctx> { + self.scalable_vec_type.ptr_type(address_space) + } + + /// Creates a `FunctionType` with this `ScalableVectorType` for its return type. + /// + /// # Example + /// + /// ```ignore + /// use inkwell::context::Context; + /// + /// let context = Context::create(); + /// let f32_type = context.f32_type(); + /// let f32_scalable_vec_type = f32_type.scalable_vec_type(3); + /// let fn_type = f32_scalable_vec_type.fn_type(&[], false); + /// ``` + pub fn fn_type(self, param_types: &[BasicMetadataTypeEnum<'ctx>], is_var_args: bool) -> FunctionType<'ctx> { + self.scalable_vec_type.fn_type(param_types, is_var_args) + } + + /// Creates an `ArrayType` with this `ScalableVectorType` for its element type. + /// + /// # Example + /// + /// ```ignore + /// use inkwell::context::Context; + /// + /// let context = Context::create(); + /// let f32_type = context.f32_type(); + /// let f32_scalable_vec_type = f32_type.scalable_vec_type(3); + /// let f32_scalable_vec_array_type = f32_scalable_vec_type.array_type(3); + /// + /// assert_eq!(f32_scalable_vec_array_type.len(), 3); + /// assert_eq!(f32_scalable_vec_array_type.get_element_type().into_scalable_vector_type(), f32_scalable_vec_type); + /// ``` + pub fn array_type(self, size: u32) -> ArrayType<'ctx> { + self.scalable_vec_type.array_type(size) + } + + /// Creates a constant `ArrayValue`. + /// + /// # Example + /// ```ignore + /// use inkwell::context::Context; + /// use inkwell::types::ScalableVectorType; + /// + /// let context = Context::create(); + /// let f32_type = context.f32_type(); + /// let f32_val = f32_type.const_float(0.); + /// let f32_val2 = f32_type.const_float(2.); + /// let f32_scalable_vec_type = f32_type.scalable_vec_type(2); + /// let f32_scalable_vec_val = f32_scalable_vec_type.const_zero(); + /// let f32_array = f32_scalable_vec_type.const_array(&[f32_scalable_vec_val, f32_scalable_vec_val]); + /// + /// assert!(f32_array.is_const()); + /// ``` + pub fn const_array(self, values: &[ScalableVectorValue<'ctx>]) -> ArrayValue<'ctx> { + unsafe { ArrayValue::new_const_array(&self, values) } + } + + /// Gets a reference to the `Context` this `ScalableVectorType` was created in. + /// + /// # Example + /// + /// ```ignore + /// use inkwell::context::Context; + /// + /// let context = Context::create(); + /// let f32_type = context.f32_type(); + /// let f32_scalable_vec_type = f32_type.scalable_vec_type(7); + /// + /// assert_eq!(f32_scalable_vec_type.get_context(), context); + /// ``` + pub fn get_context(self) -> ContextRef<'ctx> { + self.scalable_vec_type.get_context() + } +} + +unsafe impl AsTypeRef for ScalableVectorType<'_> { + fn as_type_ref(&self) -> LLVMTypeRef { + self.scalable_vec_type.ty + } +} + +impl Display for ScalableVectorType<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.print_to_string()) + } +} diff --git a/src/types/traits.rs b/src/types/traits.rs index 0637df266b6..368b4d68e0d 100644 --- a/src/types/traits.rs +++ b/src/types/traits.rs @@ -4,8 +4,14 @@ use std::fmt::Debug; use crate::support::LLVMString; use crate::types::enums::{AnyTypeEnum, BasicMetadataTypeEnum, BasicTypeEnum}; -use crate::types::{ArrayType, FloatType, FunctionType, IntType, PointerType, StructType, Type, VectorType, VoidType}; -use crate::values::{FloatMathValue, FloatValue, IntMathValue, IntValue, PointerMathValue, PointerValue, VectorValue}; +use crate::types::{ + ArrayType, FloatType, FunctionType, IntType, PointerType, ScalableVectorType, StructType, Type, VectorType, + VoidType, +}; +use crate::values::{ + FloatMathValue, FloatValue, IntMathValue, IntValue, PointerMathValue, PointerValue, ScalableVectorValue, + VectorValue, +}; use crate::AddressSpace; /// Accessor to the inner LLVM type reference @@ -168,8 +174,8 @@ pub unsafe trait PointerMathType<'ctx>: BasicType<'ctx> { type PtrConvType: IntMathType<'ctx>; } -trait_type_set! {AnyType: AnyTypeEnum, BasicTypeEnum, IntType, FunctionType, FloatType, PointerType, StructType, ArrayType, VoidType, VectorType} -trait_type_set! {BasicType: BasicTypeEnum, IntType, FloatType, PointerType, StructType, ArrayType, VectorType} +trait_type_set! {AnyType: AnyTypeEnum, BasicTypeEnum, IntType, FunctionType, FloatType, PointerType, StructType, ArrayType, VoidType, VectorType, ScalableVectorType} +trait_type_set! {BasicType: BasicTypeEnum, IntType, FloatType, PointerType, StructType, ArrayType, VectorType, ScalableVectorType} unsafe impl<'ctx> IntMathType<'ctx> for IntType<'ctx> { type ValueType = IntValue<'ctx>; @@ -183,6 +189,12 @@ unsafe impl<'ctx> IntMathType<'ctx> for VectorType<'ctx> { type PtrConvType = VectorType<'ctx>; } +unsafe impl<'ctx> IntMathType<'ctx> for ScalableVectorType<'ctx> { + type ValueType = ScalableVectorValue<'ctx>; + type MathConvType = ScalableVectorType<'ctx>; + type PtrConvType = ScalableVectorType<'ctx>; +} + unsafe impl<'ctx> FloatMathType<'ctx> for FloatType<'ctx> { type ValueType = FloatValue<'ctx>; type MathConvType = IntType<'ctx>; @@ -193,6 +205,11 @@ unsafe impl<'ctx> FloatMathType<'ctx> for VectorType<'ctx> { type MathConvType = VectorType<'ctx>; } +unsafe impl<'ctx> FloatMathType<'ctx> for ScalableVectorType<'ctx> { + type ValueType = ScalableVectorValue<'ctx>; + type MathConvType = ScalableVectorType<'ctx>; +} + unsafe impl<'ctx> PointerMathType<'ctx> for PointerType<'ctx> { type ValueType = PointerValue<'ctx>; type PtrConvType = IntType<'ctx>; @@ -202,3 +219,8 @@ unsafe impl<'ctx> PointerMathType<'ctx> for VectorType<'ctx> { type ValueType = VectorValue<'ctx>; type PtrConvType = VectorType<'ctx>; } + +unsafe impl<'ctx> PointerMathType<'ctx> for ScalableVectorType<'ctx> { + type ValueType = ScalableVectorValue<'ctx>; + type PtrConvType = ScalableVectorType<'ctx>; +} diff --git a/src/values/enums.rs b/src/values/enums.rs index 3def22ca143..b0a29933c3a 100644 --- a/src/values/enums.rs +++ b/src/values/enums.rs @@ -6,7 +6,7 @@ use crate::types::{AnyTypeEnum, BasicTypeEnum}; use crate::values::traits::AsValueRef; use crate::values::{ ArrayValue, FloatValue, FunctionValue, InstructionValue, IntValue, MetadataValue, PhiValue, PointerValue, - StructValue, VectorValue, + ScalableVectorValue, StructValue, VectorValue, }; use std::convert::TryFrom; @@ -68,9 +68,9 @@ macro_rules! enum_value_set { } enum_value_set! {AggregateValueEnum: ArrayValue, StructValue} -enum_value_set! {AnyValueEnum: ArrayValue, IntValue, FloatValue, PhiValue, FunctionValue, PointerValue, StructValue, VectorValue, InstructionValue, MetadataValue} -enum_value_set! {BasicValueEnum: ArrayValue, IntValue, FloatValue, PointerValue, StructValue, VectorValue} -enum_value_set! {BasicMetadataValueEnum: ArrayValue, IntValue, FloatValue, PointerValue, StructValue, VectorValue, MetadataValue} +enum_value_set! {AnyValueEnum: ArrayValue, IntValue, FloatValue, PhiValue, FunctionValue, PointerValue, StructValue, VectorValue, ScalableVectorValue, InstructionValue, MetadataValue} +enum_value_set! {BasicValueEnum: ArrayValue, IntValue, FloatValue, PointerValue, StructValue, VectorValue, ScalableVectorValue} +enum_value_set! {BasicMetadataValueEnum: ArrayValue, IntValue, FloatValue, PointerValue, StructValue, VectorValue, ScalableVectorValue, MetadataValue} impl<'ctx> AnyValueEnum<'ctx> { /// Get a value from an [LLVMValueRef]. @@ -94,6 +94,19 @@ impl<'ctx> AnyValueEnum<'ctx> { }, LLVMTypeKind::LLVMArrayTypeKind => AnyValueEnum::ArrayValue(ArrayValue::new(value)), LLVMTypeKind::LLVMVectorTypeKind => AnyValueEnum::VectorValue(VectorValue::new(value)), + #[cfg(any( + feature = "llvm11-0", + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + LLVMTypeKind::LLVMScalableVectorTypeKind => { + AnyValueEnum::ScalableVectorValue(ScalableVectorValue::new(value)) + }, LLVMTypeKind::LLVMFunctionTypeKind => AnyValueEnum::FunctionValue(FunctionValue::new(value).unwrap()), LLVMTypeKind::LLVMVoidTypeKind => { if LLVMIsAInstruction(value).is_null() { @@ -142,6 +155,10 @@ impl<'ctx> AnyValueEnum<'ctx> { matches!(self, AnyValueEnum::VectorValue(_)) } + pub fn is_scalable_vector_value(self) -> bool { + matches!(self, AnyValueEnum::ScalableVectorValue(_)) + } + pub fn is_instruction_value(self) -> bool { matches!(self, AnyValueEnum::InstructionValue(_)) } @@ -210,6 +227,14 @@ impl<'ctx> AnyValueEnum<'ctx> { } } + pub fn into_scalable_vector_value(self) -> ScalableVectorValue<'ctx> { + if let AnyValueEnum::ScalableVectorValue(v) = self { + v + } else { + panic!("Found {:?} but expected the ScalableVectorValue variant", self) + } + } + pub fn into_instruction_value(self) -> InstructionValue<'ctx> { if let AnyValueEnum::InstructionValue(v) = self { v @@ -238,6 +263,19 @@ impl<'ctx> BasicValueEnum<'ctx> { LLVMTypeKind::LLVMPointerTypeKind => BasicValueEnum::PointerValue(PointerValue::new(value)), LLVMTypeKind::LLVMArrayTypeKind => BasicValueEnum::ArrayValue(ArrayValue::new(value)), LLVMTypeKind::LLVMVectorTypeKind => BasicValueEnum::VectorValue(VectorValue::new(value)), + #[cfg(any( + feature = "llvm11-0", + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + LLVMTypeKind::LLVMScalableVectorTypeKind => { + BasicValueEnum::ScalableVectorValue(ScalableVectorValue::new(value)) + }, _ => unreachable!("The given type is not a basic type."), } } @@ -251,6 +289,7 @@ impl<'ctx> BasicValueEnum<'ctx> { BasicValueEnum::PointerValue(v) => v.get_name(), BasicValueEnum::StructValue(v) => v.get_name(), BasicValueEnum::VectorValue(v) => v.get_name(), + BasicValueEnum::ScalableVectorValue(v) => v.get_name(), } } @@ -263,6 +302,7 @@ impl<'ctx> BasicValueEnum<'ctx> { BasicValueEnum::PointerValue(v) => v.set_name(name), BasicValueEnum::StructValue(v) => v.set_name(name), BasicValueEnum::VectorValue(v) => v.set_name(name), + BasicValueEnum::ScalableVectorValue(v) => v.set_name(name), } } @@ -294,6 +334,10 @@ impl<'ctx> BasicValueEnum<'ctx> { matches!(self, BasicValueEnum::VectorValue(_)) } + pub fn is_scalable_vector_value(self) -> bool { + matches!(self, BasicValueEnum::ScalableVectorValue(_)) + } + pub fn into_array_value(self) -> ArrayValue<'ctx> { if let BasicValueEnum::ArrayValue(v) = self { v @@ -341,6 +385,14 @@ impl<'ctx> BasicValueEnum<'ctx> { panic!("Found {:?} but expected the VectorValue variant", self) } } + + pub fn into_scalable_vector_value(self) -> ScalableVectorValue<'ctx> { + if let BasicValueEnum::ScalableVectorValue(v) = self { + v + } else { + panic!("Found {:?} but expected the ScalableVectorValue variant", self) + } + } } impl<'ctx> AggregateValueEnum<'ctx> { @@ -396,6 +448,19 @@ impl<'ctx> BasicMetadataValueEnum<'ctx> { LLVMTypeKind::LLVMPointerTypeKind => BasicMetadataValueEnum::PointerValue(PointerValue::new(value)), LLVMTypeKind::LLVMArrayTypeKind => BasicMetadataValueEnum::ArrayValue(ArrayValue::new(value)), LLVMTypeKind::LLVMVectorTypeKind => BasicMetadataValueEnum::VectorValue(VectorValue::new(value)), + #[cfg(any( + feature = "llvm11-0", + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + LLVMTypeKind::LLVMScalableVectorTypeKind => { + BasicMetadataValueEnum::ScalableVectorValue(ScalableVectorValue::new(value)) + }, LLVMTypeKind::LLVMMetadataTypeKind => BasicMetadataValueEnum::MetadataValue(MetadataValue::new(value)), _ => unreachable!("Unsupported type"), } @@ -425,6 +490,10 @@ impl<'ctx> BasicMetadataValueEnum<'ctx> { matches!(self, BasicMetadataValueEnum::VectorValue(_)) } + pub fn is_scalable_vector_value(self) -> bool { + matches!(self, BasicMetadataValueEnum::ScalableVectorValue(_)) + } + pub fn is_metadata_value(self) -> bool { matches!(self, BasicMetadataValueEnum::MetadataValue(_)) } @@ -477,6 +546,14 @@ impl<'ctx> BasicMetadataValueEnum<'ctx> { } } + pub fn into_scalable_vector_value(self) -> ScalableVectorValue<'ctx> { + if let BasicMetadataValueEnum::ScalableVectorValue(v) = self { + v + } else { + panic!("Found {:?} but expected the ScalableVectorValue variant", self) + } + } + pub fn into_metadata_value(self) -> MetadataValue<'ctx> { if let BasicMetadataValueEnum::MetadataValue(v) = self { v @@ -510,6 +587,7 @@ impl<'ctx> TryFrom> for BasicValueEnum<'ctx> { PointerValue(pv) => pv.into(), StructValue(sv) => sv.into(), VectorValue(vv) => vv.into(), + ScalableVectorValue(vv) => vv.into(), MetadataValue(_) | PhiValue(_) | FunctionValue(_) | InstructionValue(_) => return Err(()), }) } @@ -527,6 +605,7 @@ impl<'ctx> TryFrom> for BasicMetadataValueEnum<'ctx> { PointerValue(pv) => pv.into(), StructValue(sv) => sv.into(), VectorValue(vv) => vv.into(), + ScalableVectorValue(vv) => vv.into(), MetadataValue(mv) => mv.into(), PhiValue(_) | FunctionValue(_) | InstructionValue(_) => return Err(()), }) @@ -545,6 +624,7 @@ impl<'ctx> TryFrom> for BasicValueEnum<'ctx> { PointerValue(pv) => pv.into(), StructValue(sv) => sv.into(), VectorValue(vv) => vv.into(), + ScalableVectorValue(vv) => vv.into(), MetadataValue(_) => return Err(()), }) } diff --git a/src/values/mod.rs b/src/values/mod.rs index 7a90c205c32..04d3ac54a6c 100644 --- a/src/values/mod.rs +++ b/src/values/mod.rs @@ -16,6 +16,7 @@ mod int_value; mod metadata_value; mod phi_value; mod ptr_value; +mod scalable_vec_value; mod struct_value; mod traits; mod vec_value; @@ -59,10 +60,13 @@ pub use crate::values::metadata_value::{MetadataValue, FIRST_CUSTOM_METADATA_KIN pub use crate::values::phi_value::IncomingIter; pub use crate::values::phi_value::PhiValue; pub use crate::values::ptr_value::PointerValue; +pub use crate::values::scalable_vec_value::ScalableVectorValue; pub use crate::values::struct_value::FieldValueIter; pub use crate::values::struct_value::StructValue; pub use crate::values::traits::AsValueRef; -pub use crate::values::traits::{AggregateValue, AnyValue, BasicValue, FloatMathValue, IntMathValue, PointerMathValue}; +pub use crate::values::traits::{ + AggregateValue, AnyValue, BasicValue, FloatMathValue, IntMathValue, PointerMathValue, VectorBaseValue, +}; pub use crate::values::vec_value::VectorValue; #[llvm_versions(18..)] diff --git a/src/values/scalable_vec_value.rs b/src/values/scalable_vec_value.rs new file mode 100644 index 00000000000..3fe11e76ba1 --- /dev/null +++ b/src/values/scalable_vec_value.rs @@ -0,0 +1,149 @@ +#[llvm_versions(..=16)] +use llvm_sys::core::LLVMConstSelect; +#[allow(deprecated)] +use llvm_sys::core::LLVMGetElementAsConstant; +use llvm_sys::core::{LLVMConstExtractElement, LLVMConstInsertElement, LLVMConstShuffleVector}; +use llvm_sys::prelude::LLVMValueRef; + +use std::ffi::CStr; +use std::fmt::{self, Display}; + +use crate::types::ScalableVectorType; +use crate::values::traits::AsValueRef; +use crate::values::{BasicValue, BasicValueEnum, InstructionValue, IntValue, Value}; + +use super::AnyValue; + +#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] +pub struct ScalableVectorValue<'ctx> { + scalable_vec_value: Value<'ctx>, +} + +impl<'ctx> ScalableVectorValue<'ctx> { + /// Get a value from an [LLVMValueRef]. + /// + /// # Safety + /// + /// The ref must be valid and of type scalable vector. + pub unsafe fn new(scalable_vector_value: LLVMValueRef) -> Self { + assert!(!scalable_vector_value.is_null()); + + ScalableVectorValue { + scalable_vec_value: Value::new(scalable_vector_value), + } + } + + /// Determines whether or not a `ScalableVectorValue` is a constant. + /// + /// # Example + /// + /// ```ignore + /// use inkwell::context::Context; + /// + /// let context = Context::create(); + /// let i8_type = context.i8_type(); + /// let i8_scalable_vec_type = i8_type.scalable_vec_type(3); + /// let i8_scalable_vec_zero = i8_scalable_vec_type.const_zero(); + /// + /// assert!(i8_scalable_vec_zero.is_const()); + /// ``` + pub fn is_const(self) -> bool { + self.scalable_vec_value.is_const() + } + + pub fn print_to_stderr(self) { + self.scalable_vec_value.print_to_stderr() + } + + /// Gets the name of a `ScalableVectorValue`. If the value is a constant, this will + /// return an empty string. + pub fn get_name(&self) -> &CStr { + self.scalable_vec_value.get_name() + } + + /// Set name of the `ScalableVectorValue`. + pub fn set_name(&self, name: &str) { + self.scalable_vec_value.set_name(name) + } + + pub fn get_type(self) -> ScalableVectorType<'ctx> { + unsafe { ScalableVectorType::new(self.scalable_vec_value.get_type()) } + } + + pub fn is_null(self) -> bool { + self.scalable_vec_value.is_null() + } + + pub fn is_undef(self) -> bool { + self.scalable_vec_value.is_undef() + } + + pub fn as_instruction(self) -> Option> { + self.scalable_vec_value.as_instruction() + } + + pub fn const_extract_element(self, index: IntValue<'ctx>) -> BasicValueEnum<'ctx> { + unsafe { BasicValueEnum::new(LLVMConstExtractElement(self.as_value_ref(), index.as_value_ref())) } + } + + // SubTypes: value should really be T in self: ScalableVectorValue I think + pub fn const_insert_element>(self, index: IntValue<'ctx>, value: BV) -> BasicValueEnum<'ctx> { + unsafe { + BasicValueEnum::new(LLVMConstInsertElement( + self.as_value_ref(), + value.as_value_ref(), + index.as_value_ref(), + )) + } + } + + pub fn replace_all_uses_with(self, other: ScalableVectorValue<'ctx>) { + self.scalable_vec_value.replace_all_uses_with(other.as_value_ref()) + } + + // TODOC: Value seems to be zero initialized if index out of bounds + // SubType: ScalableVectorValue -> BV + #[allow(deprecated)] + pub fn get_element_as_constant(self, index: u32) -> BasicValueEnum<'ctx> { + unsafe { BasicValueEnum::new(LLVMGetElementAsConstant(self.as_value_ref(), index)) } + } + + // SubTypes: self can only be ScalableVectoValue> + #[llvm_versions(..=16)] + pub fn const_select>(self, then: BV, else_: BV) -> BasicValueEnum<'ctx> { + unsafe { + BasicValueEnum::new(LLVMConstSelect( + self.as_value_ref(), + then.as_value_ref(), + else_.as_value_ref(), + )) + } + } + + // SubTypes: > self: V, right: V, mask: V -> V + pub fn const_shuffle_vector( + self, + right: ScalableVectorValue<'ctx>, + mask: ScalableVectorValue<'ctx>, + ) -> ScalableVectorValue<'ctx> { + unsafe { + ScalableVectorValue::new(LLVMConstShuffleVector( + self.as_value_ref(), + right.as_value_ref(), + mask.as_value_ref(), + )) + } + } +} + +unsafe impl AsValueRef for ScalableVectorValue<'_> { + fn as_value_ref(&self) -> LLVMValueRef { + self.scalable_vec_value.value + } +} + +impl Display for ScalableVectorValue<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.print_to_string()) + } +} diff --git a/src/values/traits.rs b/src/values/traits.rs index bd76778471c..760a30cbf71 100644 --- a/src/values/traits.rs +++ b/src/values/traits.rs @@ -6,10 +6,13 @@ use llvm_sys::core::LLVMIsPoison; use std::fmt::Debug; use crate::support::LLVMString; -use crate::types::{FloatMathType, FloatType, IntMathType, IntType, PointerMathType, PointerType, VectorType}; +use crate::types::{ + FloatMathType, FloatType, IntMathType, IntType, PointerMathType, PointerType, ScalableVectorType, VectorType, +}; use crate::values::{ AggregateValueEnum, AnyValueEnum, ArrayValue, BasicValueEnum, BasicValueUse, CallSiteValue, FloatValue, - FunctionValue, GlobalValue, InstructionValue, IntValue, PhiValue, PointerValue, StructValue, Value, VectorValue, + FunctionValue, GlobalValue, InstructionValue, IntValue, PhiValue, PointerValue, ScalableVectorValue, StructValue, + Value, VectorValue, }; use super::{BasicMetadataValueEnum, MetadataValue}; @@ -47,6 +50,20 @@ macro_rules! math_trait_value_set { ) } +macro_rules! base_trait_value_set { + ($trait_name:ident: $($value_type:ident),*) => ( + $( + unsafe impl<'ctx> $trait_name<'ctx> for $value_type<'ctx> { + unsafe fn new(value: LLVMValueRef) -> $value_type<'ctx> { + unsafe { + $value_type::new(value) + } + } + } + )* + ) +} + /// Represents an aggregate value, built on top of other values. pub unsafe trait AggregateValue<'ctx>: BasicValue<'ctx> { /// Returns an enum containing a typed version of the `AggregateValue`. @@ -135,6 +152,11 @@ pub unsafe trait PointerMathValue<'ctx>: BasicValue<'ctx> { unsafe fn new(value: LLVMValueRef) -> Self; } +/// Represents a value which is permitted in vector operations, either fixed or scalable +pub unsafe trait VectorBaseValue<'ctx>: BasicValue<'ctx> { + unsafe fn new(value: LLVMValueRef) -> Self; +} + // REVIEW: print_to_string might be a good candidate to live here? /// Defines any struct wrapping an LLVM value. pub unsafe trait AnyValue<'ctx>: AsValueRef + Debug { @@ -156,8 +178,9 @@ pub unsafe trait AnyValue<'ctx>: AsValueRef + Debug { } trait_value_set! {AggregateValue: ArrayValue, AggregateValueEnum, StructValue} -trait_value_set! {AnyValue: AnyValueEnum, BasicValueEnum, BasicMetadataValueEnum, AggregateValueEnum, ArrayValue, IntValue, FloatValue, GlobalValue, PhiValue, PointerValue, FunctionValue, StructValue, VectorValue, InstructionValue, CallSiteValue, MetadataValue} -trait_value_set! {BasicValue: ArrayValue, BasicValueEnum, AggregateValueEnum, IntValue, FloatValue, GlobalValue, StructValue, PointerValue, VectorValue} -math_trait_value_set! {IntMathValue: (IntValue => IntType), (VectorValue => VectorType), (PointerValue => IntType)} -math_trait_value_set! {FloatMathValue: (FloatValue => FloatType), (VectorValue => VectorType)} -math_trait_value_set! {PointerMathValue: (PointerValue => PointerType), (VectorValue => VectorType)} +trait_value_set! {AnyValue: AnyValueEnum, BasicValueEnum, BasicMetadataValueEnum, AggregateValueEnum, ArrayValue, IntValue, FloatValue, GlobalValue, PhiValue, PointerValue, FunctionValue, StructValue, VectorValue, ScalableVectorValue, InstructionValue, CallSiteValue, MetadataValue} +trait_value_set! {BasicValue: ArrayValue, BasicValueEnum, AggregateValueEnum, IntValue, FloatValue, GlobalValue, StructValue, PointerValue, VectorValue, ScalableVectorValue} +math_trait_value_set! {IntMathValue: (IntValue => IntType), (VectorValue => VectorType), (ScalableVectorValue => ScalableVectorType), (PointerValue => IntType)} +math_trait_value_set! {FloatMathValue: (FloatValue => FloatType), (VectorValue => VectorType), (ScalableVectorValue => ScalableVectorType)} +math_trait_value_set! {PointerMathValue: (PointerValue => PointerType), (VectorValue => VectorType), (ScalableVectorValue => ScalableVectorType)} +base_trait_value_set! {VectorBaseValue: VectorValue, ScalableVectorValue} diff --git a/tests/all/test_builder.rs b/tests/all/test_builder.rs index 8d22573684a..d25f2a27581 100644 --- a/tests/all/test_builder.rs +++ b/tests/all/test_builder.rs @@ -916,6 +916,62 @@ fn test_vector_convert_ops() { assert!(fn_value.verify(true)); } +#[llvm_versions(12..)] +#[test] +fn test_scalable_vector_convert_ops() { + let context = Context::create(); + let module = context.create_module("test"); + let int8_vec_type = context.i8_type().scalable_vec_type(3); + let int32_vec_type = context.i32_type().scalable_vec_type(3); + let float32_vec_type = context.f32_type().scalable_vec_type(3); + let float16_vec_type = context.f16_type().scalable_vec_type(3); + + // Here we're building a function that takes in a and returns it casted to + // and from a + // Casting to and from means we can ensure the cast build functions return a vector when one is provided. + let fn_type = int32_vec_type.fn_type(&[int8_vec_type.into()], false); + let fn_value = module.add_function("test_int_vec_cast", fn_type, None); + let entry = context.append_basic_block(fn_value, "entry"); + let builder = context.create_builder(); + + builder.position_at_end(entry); + let in_vec = fn_value.get_first_param().unwrap().into_scalable_vector_value(); + let casted_vec = builder.build_int_cast(in_vec, int32_vec_type, "casted_vec").unwrap(); + let _uncasted_vec = builder.build_int_cast(casted_vec, int8_vec_type, "uncasted_vec"); + builder.build_return(Some(&casted_vec)).unwrap(); + assert!(fn_value.verify(true)); + + // Here we're building a function that takes in a and returns it casted to and from a + let fn_type = float16_vec_type.fn_type(&[float32_vec_type.into()], false); + let fn_value = module.add_function("test_float_vec_cast", fn_type, None); + let entry = context.append_basic_block(fn_value, "entry"); + let builder = context.create_builder(); + + builder.position_at_end(entry); + let in_vec = fn_value.get_first_param().unwrap().into_scalable_vector_value(); + let casted_vec = builder + .build_float_cast(in_vec, float16_vec_type, "casted_vec") + .unwrap(); + let _uncasted_vec = builder.build_float_cast(casted_vec, float32_vec_type, "uncasted_vec"); + builder.build_return(Some(&casted_vec)).unwrap(); + assert!(fn_value.verify(true)); + + // Here we're building a function that takes in a and returns it casted to and from a + let fn_type = int32_vec_type.fn_type(&[float32_vec_type.into()], false); + let fn_value = module.add_function("test_float_to_int_vec_cast", fn_type, None); + let entry = context.append_basic_block(fn_value, "entry"); + let builder = context.create_builder(); + + builder.position_at_end(entry); + let in_vec = fn_value.get_first_param().unwrap().into_scalable_vector_value(); + let casted_vec = builder + .build_float_to_signed_int(in_vec, int32_vec_type, "casted_vec") + .unwrap(); + let _uncasted_vec = builder.build_signed_int_to_float(casted_vec, float32_vec_type, "uncasted_vec"); + builder.build_return(Some(&casted_vec)).unwrap(); + assert!(fn_value.verify(true)); +} + #[llvm_versions(8..)] #[test] fn test_vector_convert_ops_respect_target_signedness() { @@ -940,6 +996,31 @@ fn test_vector_convert_ops_respect_target_signedness() { assert!(fn_value.verify(true)); } +#[llvm_versions(12..)] +#[test] +fn test_scalable_vector_convert_ops_respect_target_signedness() { + let context = Context::create(); + let module = context.create_module("test"); + let int8_vec_type = context.i8_type().scalable_vec_type(3); + + // Here we're building a function that takes in a (signed) and returns it + // casted to and from a (unsigned) + let fn_type = int8_vec_type.fn_type(&[int8_vec_type.into()], false); + let fn_value = module.add_function("test_int_vec_cast", fn_type, None); + let entry = context.append_basic_block(fn_value, "entry"); + let builder = context.create_builder(); + + builder.position_at_end(entry); + let in_vec = fn_value.get_first_param().unwrap().into_scalable_vector_value(); + let casted_vec = builder + .build_int_cast_sign_flag(in_vec, int8_vec_type, true, "casted_vec") + .unwrap(); + let _uncasted_vec = builder.build_int_cast_sign_flag(casted_vec, int8_vec_type, true, "uncasted_vec"); + builder.build_return(Some(&casted_vec)).unwrap(); + + assert!(fn_value.verify(true)); +} + #[test] fn test_vector_binary_ops() { let context = Context::create(); @@ -1011,6 +1092,79 @@ fn test_vector_binary_ops() { assert!(fn_value.verify(true)); } +#[llvm_versions(12..)] +#[test] +fn test_scalable_vector_binary_ops() { + let context = Context::create(); + let module = context.create_module("test"); + let int32_vec_type = context.i32_type().scalable_vec_type(2); + let float32_vec_type = context.f32_type().scalable_vec_type(2); + let bool_vec_type = context.bool_type().scalable_vec_type(2); + + // Here we're building a function that takes in three s and returns them + // added together as a + let fn_type = int32_vec_type.fn_type( + &[int32_vec_type.into(), int32_vec_type.into(), int32_vec_type.into()], + false, + ); + let fn_value = module.add_function("test_int_vec_add", fn_type, None); + let entry = context.append_basic_block(fn_value, "entry"); + let builder = context.create_builder(); + + builder.position_at_end(entry); + let p1_vec = fn_value.get_first_param().unwrap().into_scalable_vector_value(); + let p2_vec = fn_value.get_nth_param(1).unwrap().into_scalable_vector_value(); + let p3_vec = fn_value.get_nth_param(2).unwrap().into_scalable_vector_value(); + let added_vec = builder.build_int_add(p1_vec, p2_vec, "added_vec").unwrap(); + let added_vec = builder.build_int_add(added_vec, p3_vec, "added_vec").unwrap(); + builder.build_return(Some(&added_vec)).unwrap(); + assert!(fn_value.verify(true)); + + // Here we're building a function that takes in three s and returns x * y / z as an + // + let fn_type = float32_vec_type.fn_type( + &[ + float32_vec_type.into(), + float32_vec_type.into(), + float32_vec_type.into(), + ], + false, + ); + let fn_value = module.add_function("test_float_vec_mul", fn_type, None); + let entry = context.append_basic_block(fn_value, "entry"); + let builder = context.create_builder(); + + builder.position_at_end(entry); + let p1_vec = fn_value.get_first_param().unwrap().into_scalable_vector_value(); + let p2_vec = fn_value.get_nth_param(1).unwrap().into_scalable_vector_value(); + let p3_vec = fn_value.get_nth_param(2).unwrap().into_scalable_vector_value(); + let multiplied_vec = builder.build_float_mul(p1_vec, p2_vec, "multiplied_vec").unwrap(); + let divided_vec = builder.build_float_div(multiplied_vec, p3_vec, "divided_vec").unwrap(); + builder.build_return(Some(÷d_vec)).unwrap(); + assert!(fn_value.verify(true)); + + // Here we're building a function that takes two s and a and returns (x < y) * z + // as a + let fn_type = bool_vec_type.fn_type( + &[float32_vec_type.into(), float32_vec_type.into(), bool_vec_type.into()], + false, + ); + let fn_value = module.add_function("test_float_vec_compare", fn_type, None); + let entry = context.append_basic_block(fn_value, "entry"); + let builder = context.create_builder(); + + builder.position_at_end(entry); + let p1_vec = fn_value.get_first_param().unwrap().into_scalable_vector_value(); + let p2_vec = fn_value.get_nth_param(1).unwrap().into_scalable_vector_value(); + let p3_vec = fn_value.get_nth_param(2).unwrap().into_scalable_vector_value(); + let compared_vec = builder + .build_float_compare(inkwell::FloatPredicate::OLT, p1_vec, p2_vec, "compared_vec") + .unwrap(); + let multiplied_vec = builder.build_int_mul(compared_vec, p3_vec, "multiplied_vec").unwrap(); + builder.build_return(Some(&multiplied_vec)).unwrap(); + assert!(fn_value.verify(true)); +} + #[test] fn test_vector_pointer_ops() { let context = Context::create(); @@ -1047,6 +1201,43 @@ fn test_vector_pointer_ops() { assert!(fn_value.verify(true)); } +#[llvm_versions(12..)] +#[test] +fn test_scalable_vector_pointer_ops() { + let context = Context::create(); + let module = context.create_module("test"); + let int32_vec_type = context.i32_type().scalable_vec_type(4); + #[cfg(not(any( + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + )))] + let i8_ptr_vec_type = context.i8_type().ptr_type(AddressSpace::default()).scalable_vec_type(4); + #[cfg(any( + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + let i8_ptr_vec_type = context.ptr_type(AddressSpace::default()).scalable_vec_type(4); + let bool_vec_type = context.bool_type().scalable_vec_type(4); + + // Here we're building a function that takes a , converts it to a and returns a + // if the pointer is null + let fn_type = bool_vec_type.fn_type(&[int32_vec_type.into()], false); + let fn_value = module.add_function("test_ptr_null", fn_type, None); + let entry = context.append_basic_block(fn_value, "entry"); + let builder = context.create_builder(); + + builder.position_at_end(entry); + let in_vec = fn_value.get_first_param().unwrap().into_scalable_vector_value(); + let ptr_vec = builder.build_int_to_ptr(in_vec, i8_ptr_vec_type, "ptr_vec").unwrap(); + let is_null_vec = builder.build_is_null(ptr_vec, "is_null_vec").unwrap(); + builder.build_return(Some(&is_null_vec)).unwrap(); + assert!(fn_value.verify(true)); +} + #[test] fn test_insert_value() { let context = Context::create(); @@ -1232,6 +1423,48 @@ fn test_insert_element() { assert!(module.verify().is_ok()); } +#[llvm_versions(12..)] +#[test] +fn test_insert_element_scalable() { + use inkwell::types::IntType; + use inkwell::values::ScalableVectorValue; + + let context = Context::create(); + let module = context.create_module("vec"); + + let fn_type = context.void_type().fn_type(&[], false); + let fn_value = module.add_function("vec_fn", fn_type, None); + let builder = context.create_builder(); + let entry = context.append_basic_block(fn_value, "entry"); + + builder.position_at_end(entry); + + fn get_empty_vector_of(ty: IntType<'_>) -> ScalableVectorValue<'_> { + ty.scalable_vec_type(4).get_poison() + } + + let i8_ty = context.i8_type(); + let i32_ty = context.i32_type(); + let mut v = get_empty_vector_of(i8_ty); + v = builder + .build_insert_element(v, i8_ty.const_int(0, false), i32_ty.const_int(0, false), "v0") + .unwrap(); + v = builder + .build_insert_element(v, i8_ty.const_int(1, false), i32_ty.const_int(1, false), "v1") + .unwrap(); + v = builder + .build_insert_element(v, i8_ty.const_int(2, false), i32_ty.const_int(2, false), "v2") + .unwrap(); + v = builder + .build_insert_element(v, i8_ty.const_int(3, false), i32_ty.const_int(3, false), "v3") + .unwrap(); + let _ = v; + + builder.build_return(None).unwrap(); + + assert!(module.verify().is_ok()); +} + fn is_alignment_ok(align: u32) -> bool { // This replicates the assertions LLVM runs. // @@ -1683,12 +1916,32 @@ fn test_bit_cast() { ))] let i64_ptr_type = context.ptr_type(AddressSpace::default()); let i32_vec_type = i32_type.vec_type(2); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + let i32_scalable_vec_type = i32_type.scalable_vec_type(2); let arg_types = [ i32_type.into(), f32_type.into(), i32_vec_type.into(), i32_ptr_type.into(), f64_type.into(), + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + i32_scalable_vec_type.into(), ]; let fn_type = void_type.fn_type(&arg_types, false); let fn_value = module.add_function("bc", fn_type, None); @@ -1699,6 +1952,16 @@ fn test_bit_cast() { let i32_vec_arg = fn_value.get_nth_param(2).unwrap(); let i32_ptr_arg = fn_value.get_nth_param(3).unwrap(); let f64_arg = fn_value.get_nth_param(4).unwrap(); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + let i32_scalable_vec_arg = fn_value.get_nth_param(5).unwrap(); builder.position_at_end(entry); @@ -1706,6 +1969,33 @@ fn test_bit_cast() { builder.build_bit_cast(f32_arg, f32_type, "f32tof32").unwrap(); builder.build_bit_cast(i32_vec_arg, i64_type, "2xi32toi64").unwrap(); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + { + let i64_scalable_vec_type = i64_type.scalable_vec_type(1); + let f32_scalable_vec_type = f32_type.scalable_vec_type(2); + builder + .build_bit_cast( + i32_scalable_vec_arg, + i64_scalable_vec_type, + "vscalex2xi32tovscalex1xi64", + ) + .unwrap(); + builder + .build_bit_cast( + i32_scalable_vec_arg, + f32_scalable_vec_type, + "vscalex2xi32tovscalex2xf32", + ) + .unwrap(); + } builder.build_bit_cast(i32_ptr_arg, i64_ptr_type, "i32*toi64*").unwrap(); builder.build_return(None).unwrap(); diff --git a/tests/all/test_instruction_values.rs b/tests/all/test_instruction_values.rs index c68c2d79c05..04d9a1c6440 100644 --- a/tests/all/test_instruction_values.rs +++ b/tests/all/test_instruction_values.rs @@ -527,7 +527,7 @@ fn test_mem_instructions() { assert!(fadd_instruction.set_alignment(16).is_err()); } -#[llvm_versions(11..)] +#[llvm_versions(12..)] #[test] fn test_mem_instructions() { let context = Context::create(); diff --git a/tests/all/test_types.rs b/tests/all/test_types.rs index d1e782652fa..1037984f9ff 100644 --- a/tests/all/test_types.rs +++ b/tests/all/test_types.rs @@ -276,6 +276,37 @@ fn sized_types(global_ctx: &Context) { ))] assert!(ptr_type.vec_type(42).is_sized()); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + { + assert!(bool_type.scalable_vec_type(42).is_sized()); + assert!(i8_type.scalable_vec_type(42).is_sized()); + assert!(i16_type.scalable_vec_type(42).is_sized()); + assert!(i32_type.scalable_vec_type(42).is_sized()); + assert!(i64_type.scalable_vec_type(42).is_sized()); + assert!(i128_type.scalable_vec_type(42).is_sized()); + assert!(f16_type.scalable_vec_type(42).is_sized()); + assert!(f32_type.scalable_vec_type(42).is_sized()); + assert!(f64_type.scalable_vec_type(42).is_sized()); + assert!(f80_type.scalable_vec_type(42).is_sized()); + assert!(f128_type.scalable_vec_type(42).is_sized()); + assert!(ppc_f128_type.scalable_vec_type(42).is_sized()); + #[cfg(any( + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + assert!(ptr_type.scalable_vec_type(42).is_sized()); + } + let opaque_struct_type = global_ctx.opaque_struct_type("opaque"); assert!(!opaque_struct_type.is_sized()); @@ -324,6 +355,16 @@ fn test_const_zero() { ))] let ptr_type = context.ptr_type(AddressSpace::default()); let vec_type = f64_type.vec_type(42); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + let scalable_vec_type = f64_type.scalable_vec_type(42); let array_type = f64_type.array_type(42); bool_type.size_of(); @@ -331,6 +372,16 @@ fn test_const_zero() { struct_type.size_of(); ptr_type.size_of(); vec_type.size_of(); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + scalable_vec_type.size_of(); array_type.size_of(); bool_type.get_alignment(); @@ -338,6 +389,16 @@ fn test_const_zero() { struct_type.get_alignment(); ptr_type.get_alignment(); vec_type.get_alignment(); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + scalable_vec_type.get_alignment(); array_type.get_alignment(); let bool_zero = bool_type.const_zero(); @@ -355,6 +416,16 @@ fn test_const_zero() { let struct_zero = struct_type.const_zero(); let ptr_zero = ptr_type.const_zero(); let vec_zero = vec_type.const_zero(); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + let scalable_vec_zero = scalable_vec_type.const_zero(); let array_zero = array_type.const_zero(); assert!(bool_zero.is_null()); @@ -372,6 +443,16 @@ fn test_const_zero() { assert!(struct_zero.is_null()); assert!(ptr_zero.is_null()); assert!(vec_zero.is_null()); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + assert!(scalable_vec_zero.is_null()); assert!(array_zero.is_null()); assert_eq!(bool_zero.print_to_string().to_str(), Ok("i1 false")); @@ -415,6 +496,19 @@ fn test_const_zero() { assert_eq!(ptr_zero.print_to_string().to_str(), Ok(ptr_type)); assert_eq!(vec_zero.print_to_string().to_str(), Ok("<42 x double> zeroinitializer")); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + assert_eq!( + scalable_vec_zero.print_to_string().to_str(), + Ok(" zeroinitializer") + ); assert_eq!( array_zero.print_to_string().to_str(), Ok("[42 x double] zeroinitializer") @@ -430,6 +524,16 @@ fn test_vec_type() { assert_eq!(vec_type.get_size(), 42); } +#[llvm_versions(12..)] +#[test] +fn test_scalable_vec_type() { + let context = Context::create(); + let int = context.i8_type(); + let vec_type = int.scalable_vec_type(42); + + assert_eq!(vec_type.get_size(), 42); +} + #[test] fn test_type_copies() { let context = Context::create(); @@ -527,6 +631,16 @@ fn test_basic_type_enum() { &context.ptr_type(addr), &context.struct_type(&[int.as_basic_type_enum()], false), &int.vec_type(1), + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + &int.scalable_vec_type(1), ]; for basic_type in types { #[cfg(not(any( @@ -552,6 +666,15 @@ fn test_no_vector_zero() { int.vec_type(0); } +#[llvm_versions(12..)] +#[test] +#[should_panic] +fn test_no_scalable_vector_zero() { + let context = Context::create(); + let int = context.i32_type(); + int.scalable_vec_type(0); +} + #[test] fn test_ptr_address_space() { let context = Context::create(); diff --git a/tests/all/test_values.rs b/tests/all/test_values.rs index 3910360e630..72fa704b5d6 100644 --- a/tests/all/test_values.rs +++ b/tests/all/test_values.rs @@ -197,6 +197,16 @@ fn test_set_get_name() { let array_val = f64_type.const_array(&[f64_val]); let struct_val = context.const_struct(&[i8_val.into(), f128_val.into()], false); let vec_val = VectorType::const_vector(&[i8_val]); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + let scalable_vec_val = f64_type.scalable_vec_type(42).const_zero(); let ppc_f128_val = ppc_f128_type.const_float(0.0); assert_eq!(bool_val.get_name().to_str(), Ok("")); @@ -213,6 +223,16 @@ fn test_set_get_name() { assert_eq!(array_val.get_name().to_str(), Ok("")); assert_eq!(struct_val.get_name().to_str(), Ok("")); assert_eq!(vec_val.get_name().to_str(), Ok("")); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + assert_eq!(scalable_vec_val.get_name().to_str(), Ok("")); assert_eq!(ppc_f128_val.get_name().to_str(), Ok("")); // LLVM Gem: You can't set names on constant values, so this doesn't do anything: @@ -230,7 +250,17 @@ fn test_set_get_name() { array_val.set_name("my_val12"); struct_val.set_name("my_val13"); vec_val.set_name("my_val14"); - ppc_f128_val.set_name("my_val14"); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + scalable_vec_val.set_name("my_val15"); + ppc_f128_val.set_name("my_val16"); assert_eq!(bool_val.get_name().to_str(), Ok("")); assert_eq!(i8_val.get_name().to_str(), Ok("")); @@ -246,6 +276,16 @@ fn test_set_get_name() { assert_eq!(array_val.get_name().to_str(), Ok("")); assert_eq!(struct_val.get_name().to_str(), Ok("")); assert_eq!(vec_val.get_name().to_str(), Ok("")); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + assert_eq!(scalable_vec_val.get_name().to_str(), Ok("")); assert_eq!(ppc_f128_val.get_name().to_str(), Ok("")); let void_type = context.void_type(); @@ -265,6 +305,16 @@ fn test_set_get_name() { let ptr_type = context.ptr_type(AddressSpace::default()); let struct_type = context.struct_type(&[bool_type.into()], false); let vec_type = bool_type.vec_type(1); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + let scalable_vec_type = bool_type.scalable_vec_type(1); let module = context.create_module("types"); let builder = context.create_builder(); @@ -277,6 +327,16 @@ fn test_set_get_name() { array_type.into(), ptr_type.into(), vec_type.into(), + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + scalable_vec_type.into(), ]; let fn_type = void_type.fn_type(&fn_type_params, false); @@ -291,6 +351,16 @@ fn test_set_get_name() { let array_param = function.get_nth_param(3).unwrap().into_array_value(); let ptr_param = function.get_nth_param(4).unwrap().into_pointer_value(); let vec_param = function.get_nth_param(5).unwrap().into_vector_value(); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + let scalable_vec_param = function.get_nth_param(6).unwrap().into_scalable_vector_value(); let phi_val = builder.build_phi(bool_type, "phi_node").unwrap(); assert_eq!(int_param.get_name().to_str(), Ok("")); @@ -299,6 +369,16 @@ fn test_set_get_name() { assert_eq!(array_param.get_name().to_str(), Ok("")); assert_eq!(ptr_param.get_name().to_str(), Ok("")); assert_eq!(vec_param.get_name().to_str(), Ok("")); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + assert_eq!(scalable_vec_param.get_name().to_str(), Ok("")); assert_eq!(phi_val.get_name().to_str(), Ok("phi_node")); int_param.set_name("my_val"); @@ -307,6 +387,16 @@ fn test_set_get_name() { array_param.set_name("my_val4"); struct_param.set_name("my_val5"); vec_param.set_name("my_val6"); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + scalable_vec_param.set_name("my_val7"); phi_val.set_name("phi"); assert_eq!(int_param.get_name().to_str(), Ok("my_val")); @@ -315,6 +405,16 @@ fn test_set_get_name() { assert_eq!(array_param.get_name().to_str(), Ok("my_val4")); assert_eq!(struct_param.get_name().to_str(), Ok("my_val5")); assert_eq!(vec_param.get_name().to_str(), Ok("my_val6")); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + assert_eq!(scalable_vec_param.get_name().to_str(), Ok("my_val7")); assert_eq!(phi_val.get_name().to_str(), Ok("phi")); // TODO: Test globals, supposedly constant globals work? @@ -372,6 +472,16 @@ fn test_undef() { let array_val = f64_type.const_array(&[f64_val]); let struct_val = context.const_struct(&[i8_val.into(), f128_val.into()], false); let vec_val = VectorType::const_vector(&[i8_val]); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + let scalable_vec_val = f64_type.scalable_vec_type(42).const_zero(); let ppc_f128_val = ppc_f128_type.const_float(0.0); assert!(!bool_val.is_undef()); @@ -388,6 +498,16 @@ fn test_undef() { assert!(!array_val.is_undef()); assert!(!struct_val.is_undef()); assert!(!vec_val.is_undef()); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + assert!(!scalable_vec_val.is_undef()); assert!(!ppc_f128_val.is_undef()); let bool_undef = bool_type.get_undef(); @@ -417,6 +537,16 @@ fn test_undef() { let array_undef = array_type.get_undef(); let struct_undef = context.struct_type(&[bool_type.into()], false).get_undef(); let vec_undef = bool_type.vec_type(1).get_undef(); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + let scalable_vec_undef = bool_type.scalable_vec_type(1).get_undef(); let ppc_f128_undef = ppc_f128_type.get_undef(); assert!(bool_undef.is_undef()); @@ -433,6 +563,16 @@ fn test_undef() { assert!(array_undef.is_undef()); assert!(struct_undef.is_undef()); assert!(vec_undef.is_undef()); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + assert!(scalable_vec_undef.is_undef()); assert!(ppc_f128_undef.is_undef()); } @@ -458,6 +598,16 @@ fn test_poison() { ))] let ptr_type = context.ptr_type(AddressSpace::default()); let array_type = f64_type.array_type(42); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + let scalable_vec_type = f64_type.scalable_vec_type(42); let ppc_f128_type = context.ppc_f128_type(); assert_eq!(array_type.get_element_type().into_float_type(), f64_type); @@ -489,6 +639,16 @@ fn test_poison() { let array_val = f64_type.const_array(&[f64_val]); let struct_val = context.const_struct(&[i8_val.into(), f128_val.into()], false); let vec_val = VectorType::const_vector(&[i8_val]); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + let scalable_vec_val = scalable_vec_type.const_zero(); let ppc_f128_val = ppc_f128_type.const_float(0.0); assert!(!bool_val.is_poison()); @@ -505,6 +665,16 @@ fn test_poison() { assert!(!array_val.is_poison()); assert!(!struct_val.is_poison()); assert!(!vec_val.is_poison()); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + assert!(!scalable_vec_val.is_poison()); assert!(!ppc_f128_val.is_poison()); let bool_poison = bool_type.get_poison(); @@ -534,6 +704,16 @@ fn test_poison() { let array_poison = array_type.get_poison(); let struct_poison = context.struct_type(&[bool_type.into()], false).get_poison(); let vec_poison = bool_type.vec_type(1).get_poison(); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + let scalable_vec_poison = scalable_vec_type.get_poison(); let ppc_f128_poison = ppc_f128_type.get_poison(); assert!(bool_poison.is_poison()); @@ -550,6 +730,16 @@ fn test_poison() { assert!(array_poison.is_poison()); assert!(struct_poison.is_poison()); assert!(vec_poison.is_poison()); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + assert!(scalable_vec_poison.is_poison()); assert!(ppc_f128_poison.is_poison()); } @@ -1343,6 +1533,16 @@ fn test_consts() { let f128_val = f128_type.const_float(7.8); let ppc_f128_val = ppc_f128_type.const_float(9.0); let vec_val = VectorType::const_vector(&[i8_val]); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + let scalable_vec_val = f64_type.scalable_vec_type(42).const_zero(); let array_val = i8_type.const_array(&[i8_val]); let arbitrary_precision_int = i64_type.const_int_arbitrary_precision(&[1, 2]); @@ -1358,6 +1558,16 @@ fn test_consts() { assert!(f128_val.is_const()); assert!(ppc_f128_val.is_const()); assert!(vec_val.is_const()); + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-0" + ))] + assert!(scalable_vec_val.is_const()); assert!(array_val.is_const()); assert!(arbitrary_precision_int.is_const()); @@ -1561,6 +1771,35 @@ fn test_vectors() { assert!(module.verify().is_ok()); } +#[llvm_versions(12..)] +#[test] +fn test_scalable_vectors() { + let context = Context::create(); + let builder = context.create_builder(); + let module = context.create_module("my_mod"); + let i32_type = context.i32_type(); + let i32_zero = i32_type.const_int(0, false); + let i32_seven = i32_type.const_int(7, false); + let scalable_vec_type = i32_type.scalable_vec_type(2); + let fn_type = i32_type.fn_type(&[scalable_vec_type.into()], false); + let fn_value = module.add_function("my_func", fn_type, None); + let bb = context.append_basic_block(fn_value, "entry"); + let scalable_vector_param = fn_value.get_first_param().unwrap().into_scalable_vector_value(); + + builder.position_at_end(bb); + builder + .build_insert_element(scalable_vector_param, i32_seven, i32_zero, "insert") + .unwrap(); + + let extracted = builder + .build_extract_element(scalable_vector_param, i32_zero, "extract") + .unwrap(); + + builder.build_return(Some(&extracted)).unwrap(); + + assert!(module.verify().is_ok()); +} + #[test] fn test_aggregate_returns() { let context = Context::create(); From b64c336ad6412f62e9e112e2acf2bd48f56d3c53 Mon Sep 17 00:00:00 2001 From: Alexander Fedotov Date: Fri, 20 Dec 2024 20:24:54 +0000 Subject: [PATCH 13/13] Revert "Add support for LLVM 18.1" This reverts commit 80473af6af5b5aa320fc21a1db6fba2a24b855f8. --- Cargo.toml | 14 ++-- README.md | 2 +- internal_macros/src/cfg.rs | 2 +- src/basic_block.rs | 4 +- src/builder.rs | 68 ++++++++--------- src/context.rs | 4 +- src/debug_info.rs | 14 ++-- src/lib.rs | 6 +- src/module.rs | 8 +- src/targets.rs | 10 +-- src/types/array_type.rs | 2 +- src/types/enums.rs | 16 ++-- src/types/float_type.rs | 2 +- src/types/fn_type.rs | 2 +- src/types/int_type.rs | 2 +- src/types/ptr_type.rs | 58 +++++++------- src/types/struct_type.rs | 2 +- src/types/traits.rs | 2 +- src/types/vec_type.rs | 2 +- src/values/basic_value_use.rs | 12 +-- src/values/call_site_value.rs | 6 +- src/values/instruction_value.rs | 36 ++++----- src/values/metadata_value.rs | 2 +- src/values/mod.rs | 6 +- tests/all/main.rs | 2 +- tests/all/test_builder.rs | 96 ++++++++++++------------ tests/all/test_context.rs | 4 +- tests/all/test_debug_info.rs | 36 ++++----- tests/all/test_execution_engine.rs | 4 +- tests/all/test_instruction_conversion.rs | 4 +- tests/all/test_instruction_values.rs | 42 +++++------ tests/all/test_targets.rs | 4 +- tests/all/test_types.rs | 32 ++++---- tests/all/test_values.rs | 62 +++++++-------- 34 files changed, 284 insertions(+), 284 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 215741a6e20..59a906dc9b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ llvm14-0 = ["llvm-sys-140"] llvm15-0 = ["llvm-sys-150"] llvm16-0 = ["llvm-sys-160"] llvm17-0 = ["llvm-sys-170"] -llvm18-1 = ["llvm-sys-181"] +llvm18-0 = ["llvm-sys-180"] # Don't link against LLVM libraries. This is useful if another dependency is # installing LLVM. See llvm-sys for more details. We can't enable a single @@ -50,7 +50,7 @@ llvm14-0-no-llvm-linking = ["llvm14-0", "llvm-sys-140/no-llvm-linking"] llvm15-0-no-llvm-linking = ["llvm15-0", "llvm-sys-150/no-llvm-linking"] llvm16-0-no-llvm-linking = ["llvm16-0", "llvm-sys-160/no-llvm-linking"] llvm17-0-no-llvm-linking = ["llvm17-0", "llvm-sys-170/no-llvm-linking"] -llvm18-1-no-llvm-linking = ["llvm18-1", "llvm-sys-181/no-llvm-linking"] +llvm18-0-no-llvm-linking = ["llvm18-0", "llvm-sys-180/no-llvm-linking"] # Linking preference. # If none of these are enabled, it defaults to force static linking. @@ -62,7 +62,7 @@ llvm14-0-force-dynamic = ["llvm14-0", "llvm-sys-140/force-dynamic"] llvm15-0-force-dynamic = ["llvm15-0", "llvm-sys-150/force-dynamic"] llvm16-0-force-dynamic = ["llvm16-0", "llvm-sys-160/force-dynamic"] llvm17-0-force-dynamic = ["llvm17-0", "llvm-sys-170/force-dynamic"] -llvm18-1-force-dynamic = ["llvm18-1", "llvm-sys-181/force-dynamic"] +llvm18-0-force-dynamic = ["llvm18-0", "llvm-sys-180/force-dynamic"] # Prefer dynamic linking against LLVM libraries. See llvm-sys for more details llvm12-0-prefer-dynamic = ["llvm12-0", "llvm-sys-120/prefer-dynamic"] @@ -71,7 +71,7 @@ llvm14-0-prefer-dynamic = ["llvm14-0", "llvm-sys-140/prefer-dynamic"] llvm15-0-prefer-dynamic = ["llvm15-0", "llvm-sys-150/prefer-dynamic"] llvm16-0-prefer-dynamic = ["llvm16-0", "llvm-sys-160/prefer-dynamic"] llvm17-0-prefer-dynamic = ["llvm17-0", "llvm-sys-170/prefer-dynamic"] -llvm18-1-prefer-dynamic = ["llvm18-1", "llvm-sys-181/prefer-dynamic"] +llvm18-0-prefer-dynamic = ["llvm18-0", "llvm-sys-180/prefer-dynamic"] # Force static linking against LLVM libraries. See llvm-sys for more details llvm12-0-force-static = ["llvm12-0", "llvm-sys-120/force-static"] @@ -80,7 +80,7 @@ llvm14-0-force-static = ["llvm14-0", "llvm-sys-140/force-static"] llvm15-0-force-static = ["llvm15-0", "llvm-sys-150/force-static"] llvm16-0-force-static = ["llvm16-0", "llvm-sys-160/force-static"] llvm17-0-force-static = ["llvm17-0", "llvm-sys-170/force-static"] -llvm18-1-force-static = ["llvm18-1", "llvm-sys-181/force-static"] +llvm18-0-force-static = ["llvm18-0", "llvm-sys-180/force-static"] # Prefer static linking against LLVM libraries. See llvm-sys for more details llvm12-0-prefer-static = ["llvm12-0", "llvm-sys-120/prefer-static"] @@ -89,7 +89,7 @@ llvm14-0-prefer-static = ["llvm14-0", "llvm-sys-140/prefer-static"] llvm15-0-prefer-static = ["llvm15-0", "llvm-sys-150/prefer-static"] llvm16-0-prefer-static = ["llvm16-0", "llvm-sys-160/prefer-static"] llvm17-0-prefer-static = ["llvm17-0", "llvm-sys-170/prefer-static"] -llvm18-1-prefer-static = ["llvm18-1", "llvm-sys-181/prefer-static"] +llvm18-0-prefer-static = ["llvm18-0", "llvm-sys-180/prefer-static"] # Don't force linking to libffi on non-windows platforms. Without this feature # inkwell always links to libffi on non-windows platforms. @@ -151,7 +151,7 @@ llvm-sys-140 = { package = "llvm-sys", version = "140.0.2", optional = true } llvm-sys-150 = { package = "llvm-sys", version = "150.0.3", optional = true } llvm-sys-160 = { package = "llvm-sys", version = "160.1.0", optional = true } llvm-sys-170 = { package = "llvm-sys", version = "170.0.1", optional = true } -llvm-sys-181 = { package = "llvm-sys", version = "181.1.0", optional = true } +llvm-sys-180 = { package = "llvm-sys", version = "180.0.0", optional = true } either = "1.5" libc = "0.2" diff --git a/README.md b/README.md index 1b82b974c17..66ab2a2d5d9 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ You'll need to point your Cargo.toml to use a single LLVM version feature flag c ```toml [dependencies] -inkwell = { version = "0.4.0", features = ["llvm18-1"] } +inkwell = { version = "0.4.0", features = ["llvm18-0"] } ``` Supported versions: diff --git a/internal_macros/src/cfg.rs b/internal_macros/src/cfg.rs index b06a02aac43..73e1f1e425a 100644 --- a/internal_macros/src/cfg.rs +++ b/internal_macros/src/cfg.rs @@ -10,7 +10,7 @@ use syn::{Lit, RangeLimits}; // This array should match the LLVM features in the top level Cargo manifest const FEATURE_VERSIONS: &[&str] = &[ "llvm4-0", "llvm5-0", "llvm6-0", "llvm7-0", "llvm8-0", "llvm9-0", "llvm10-0", "llvm11-0", "llvm12-0", "llvm13-0", - "llvm14-0", "llvm15-0", "llvm16-0", "llvm17-0", "llvm18-1", + "llvm14-0", "llvm15-0", "llvm16-0", "llvm17-0", "llvm18-0", ]; pub struct VersionRange { diff --git a/src/basic_block.rs b/src/basic_block.rs index 7e8bbfa29ab..a1390a993d9 100644 --- a/src/basic_block.rs +++ b/src/basic_block.rs @@ -288,9 +288,9 @@ impl<'ctx> BasicBlock<'ctx> { /// /// let void_type = context.void_type(); /// let i32_type = context.i32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let i32_ptr_type = context.ptr_type(AddressSpace::default()); /// /// let fn_type = void_type.fn_type(&[i32_ptr_type.into()], false); diff --git a/src/builder.rs b/src/builder.rs index 08f3e08e7c2..084a3d03e25 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -456,9 +456,9 @@ impl<'ctx> Builder<'ctx> { /// }; /// /// // type of an exception in C++ - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let i8_ptr_type = context.i32_type().ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let i32_ptr_ty = context.ptr_type(AddressSpace::default()); /// let i32_type = context.i32_type(); /// let exception_type = context.struct_type(&[i8_ptr_type.into(), i32_type.into()], false); @@ -708,9 +708,9 @@ impl<'ctx> Builder<'ctx> { /// let builder = context.create_builder(); /// /// // type of an exception in C++ - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let i8_ptr_type = context.i8_type().ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let i8_ptr_type = context.ptr_type(AddressSpace::default()); /// let i32_type = context.i32_type(); /// let exception_type = context.struct_type(&[i8_ptr_type.into(), i32_type.into()], false); @@ -740,9 +740,9 @@ impl<'ctx> Builder<'ctx> { /// let builder = context.create_builder(); /// /// // type of an exception in C++ - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let i8_ptr_type = context.i8_type().ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let i8_ptr_type = context.ptr_type(AddressSpace::default()); /// let i32_type = context.i32_type(); /// let exception_type = context.struct_type(&[i8_ptr_type.into(), i32_type.into()], false); @@ -775,9 +775,9 @@ impl<'ctx> Builder<'ctx> { /// let builder = context.create_builder(); /// /// // type of an exception in C++ - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let i8_ptr_type = context.i8_type().ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let i8_ptr_type = context.ptr_type(AddressSpace::default()); /// let i32_type = context.i32_type(); /// let exception_type = context.struct_type(&[i8_ptr_type.into(), i32_type.into()], false); @@ -813,9 +813,9 @@ impl<'ctx> Builder<'ctx> { /// let builder = context.create_builder(); /// /// // type of an exception in C++ - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let i8_ptr_type = context.i8_type().ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let i8_ptr_type = context.ptr_type(AddressSpace::default()); /// let i32_type = context.i32_type(); /// let exception_type = context.struct_type(&[i8_ptr_type.into(), i32_type.into()], false); @@ -935,9 +935,9 @@ impl<'ctx> Builder<'ctx> { /// }; /// /// // type of an exception in C++ - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let i8_ptr_type = context.i8_type().ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let i8_ptr_type = context.ptr_type(AddressSpace::default()); /// let i32_type = context.i32_type(); /// let exception_type = context.struct_type(&[i8_ptr_type.into(), i32_type.into()], false); @@ -1087,9 +1087,9 @@ impl<'ctx> Builder<'ctx> { /// let module = context.create_module("struct_gep"); /// let void_type = context.void_type(); /// let i32_ty = context.i32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let i32_ptr_ty = i32_ty.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let i32_ptr_ty = context.ptr_type(AddressSpace::default()); /// let field_types = &[i32_ty.into(), i32_ty.into()]; /// let struct_ty = context.struct_type(field_types, false); @@ -1153,9 +1153,9 @@ impl<'ctx> Builder<'ctx> { /// let module = context.create_module("struct_gep"); /// let void_type = context.void_type(); /// let i32_ty = context.i32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let i32_ptr_ty = i32_ty.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let i32_ptr_ty = context.ptr_type(AddressSpace::default()); /// let field_types = &[i32_ty.into(), i32_ty.into()]; /// let struct_ty = context.struct_type(field_types, false); @@ -1227,9 +1227,9 @@ impl<'ctx> Builder<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let i32_type = context.i32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let i32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[i32_ptr_type.into(), i32_ptr_type.into()], false); /// let fn_value = module.add_function("ret", fn_type, None); @@ -1278,9 +1278,9 @@ impl<'ctx> Builder<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let i32_type = context.i32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let i32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[i32_ptr_type.into(), i32_ptr_type.into()], false); /// let fn_value = module.add_function("ret", fn_type, None); @@ -1347,9 +1347,9 @@ impl<'ctx> Builder<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let i32_type = context.i32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let i32_ptr_type = context.ptr_type(AddressSpace::default()); /// let i32_seven = i32_type.const_int(7, false); /// let fn_type = void_type.fn_type(&[i32_ptr_type.into()], false); @@ -1387,9 +1387,9 @@ impl<'ctx> Builder<'ctx> { /// let module = context.create_module("ret"); /// let builder = context.create_builder(); /// let i32_type = context.i32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let i32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = i32_type.fn_type(&[i32_ptr_type.into()], false); /// let fn_value = module.add_function("ret", fn_type, None); @@ -1427,9 +1427,9 @@ impl<'ctx> Builder<'ctx> { /// let module = context.create_module("ret"); /// let builder = context.create_builder(); /// let i32_type = context.i32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let i32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = i32_type.fn_type(&[i32_ptr_type.into()], false); /// let fn_value = module.add_function("ret", fn_type, None); @@ -2777,7 +2777,7 @@ impl<'ctx> Builder<'ctx> { /// feature = "llvm14-0" /// ))] /// let array = builder.build_load(array_alloca, "array_load").unwrap().into_array_value(); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let array = builder.build_load(i32_type, array_alloca, "array_load").unwrap().into_array_value(); /// /// let const_int1 = i32_type.const_int(2, false); @@ -2860,7 +2860,7 @@ impl<'ctx> Builder<'ctx> { /// feature = "llvm14-0" /// ))] /// let array = builder.build_load(array_alloca, "array_load").unwrap().into_array_value(); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let array = builder.build_load(i32_type, array_alloca, "array_load").unwrap().into_array_value(); /// /// let const_int1 = i32_type.const_int(2, false); @@ -3265,9 +3265,9 @@ impl<'ctx> Builder<'ctx> { /// let void_type = context.void_type(); /// let i32_type = context.i32_type(); /// let i32_seven = i32_type.const_int(7, false); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let i32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[i32_ptr_type.into()], false); /// let fn_value = module.add_function("rmw", fn_type, None); @@ -3302,7 +3302,7 @@ impl<'ctx> Builder<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] if ptr.get_type().get_element_type() != value.get_type().into() { return Err(BuilderError::PointeeTypeMismatch( @@ -3344,9 +3344,9 @@ impl<'ctx> Builder<'ctx> { /// let module = context.create_module("cmpxchg"); /// let void_type = context.void_type(); /// let i32_type = context.i32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let i32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[i32_ptr_type.into()], false); /// let fn_value = module.add_function("", fn_type, None); @@ -3388,7 +3388,7 @@ impl<'ctx> Builder<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] if ptr.get_type().get_element_type().as_basic_type_enum() != cmp.get_type() { return Err(BuilderError::PointeeTypeMismatch( diff --git a/src/context.rs b/src/context.rs index fab4eba9b63..041a4aee760 100644 --- a/src/context.rs +++ b/src/context.rs @@ -579,7 +579,7 @@ impl Context { /// builder.build_call(callable_value, params, "exit").unwrap(); /// } /// - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// builder.build_indirect_call(asm_fn, asm, params, "exit").unwrap(); /// /// builder.build_return(None).unwrap(); @@ -1447,7 +1447,7 @@ impl<'ctx> ContextRef<'ctx> { /// builder.build_call(callable_value, params, "exit").unwrap(); /// } /// - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// builder.build_indirect_call(asm_fn, asm, params, "exit").unwrap(); /// /// builder.build_return(None).unwrap(); diff --git a/src/debug_info.rs b/src/debug_info.rs index dbb5279353f..678db68060e 100644 --- a/src/debug_info.rs +++ b/src/debug_info.rs @@ -195,7 +195,7 @@ impl<'ctx> DebugInfoBuilder<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] sysroot: &str, #[cfg(any( @@ -206,7 +206,7 @@ impl<'ctx> DebugInfoBuilder<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] sdk: &str, ) -> (Self, DICompileUnit<'ctx>) { @@ -245,7 +245,7 @@ impl<'ctx> DebugInfoBuilder<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] sysroot, #[cfg(any( @@ -256,7 +256,7 @@ impl<'ctx> DebugInfoBuilder<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] sdk, ); @@ -303,7 +303,7 @@ impl<'ctx> DebugInfoBuilder<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] sysroot: &str, #[cfg(any( @@ -314,7 +314,7 @@ impl<'ctx> DebugInfoBuilder<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] sdk: &str, ) -> DICompileUnit<'ctx> { @@ -356,7 +356,7 @@ impl<'ctx> DebugInfoBuilder<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] { LLVMDIBuilderCreateCompileUnit( diff --git a/src/lib.rs b/src/lib.rs index 31a09041306..9917f35920e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,8 +58,8 @@ pub extern crate llvm_sys_150 as llvm_sys; pub extern crate llvm_sys_160 as llvm_sys; #[cfg(feature = "llvm17-0")] pub extern crate llvm_sys_170 as llvm_sys; -#[cfg(feature = "llvm18-1")] -pub extern crate llvm_sys_181 as llvm_sys; +#[cfg(feature = "llvm18-0")] +pub extern crate llvm_sys_180 as llvm_sys; #[cfg(feature = "llvm4-0")] pub extern crate llvm_sys_40 as llvm_sys; #[cfg(feature = "llvm5-0")] @@ -130,7 +130,7 @@ assert_unique_used_features! { "llvm15-0", "llvm16-0", "llvm17-0", - "llvm18-1" + "llvm18-0" } /// Defines the address space in which a global will be inserted. diff --git a/src/module.rs b/src/module.rs index 65c912de9bb..94e9f80053a 100644 --- a/src/module.rs +++ b/src/module.rs @@ -1433,7 +1433,7 @@ impl<'ctx> Module<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] sysroot: &str, #[cfg(any( @@ -1444,7 +1444,7 @@ impl<'ctx> Module<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] sdk: &str, ) -> (DebugInfoBuilder<'ctx>, DICompileUnit<'ctx>) { @@ -1471,7 +1471,7 @@ impl<'ctx> Module<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] sysroot, #[cfg(any( @@ -1482,7 +1482,7 @@ impl<'ctx> Module<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] sdk, ) diff --git a/src/targets.rs b/src/targets.rs index dd84fac07d4..5edc005632a 100644 --- a/src/targets.rs +++ b/src/targets.rs @@ -14,7 +14,7 @@ use llvm_sys::target_machine::{ LLVMTargetHasAsmBackend, LLVMTargetHasJIT, LLVMTargetHasTargetMachine, LLVMTargetMachineEmitToFile, LLVMTargetMachineEmitToMemoryBuffer, LLVMTargetMachineRef, LLVMTargetRef, }; -#[llvm_versions(18.1..)] +#[llvm_versions(18..)] use llvm_sys::target_machine::{ LLVMCreateTargetMachineOptions, LLVMCreateTargetMachineWithOptions, LLVMDisposeTargetMachineOptions, LLVMTargetMachineOptionsRef, LLVMTargetMachineOptionsSetABI, LLVMTargetMachineOptionsSetCPU, @@ -960,7 +960,7 @@ impl Target { /// assert_eq!(target_machine.get_cpu().to_str(), Ok("x86-64")); /// assert_eq!(target_machine.get_feature_string().to_str(), Ok("+avx2")); /// ``` - #[llvm_versions(18.1..)] + #[llvm_versions(18..)] pub fn create_target_machine_from_options( &self, triple: &TargetTriple, @@ -1422,11 +1422,11 @@ impl Drop for TargetData { /// /// The option structure exposes an additional setting (i.e., the target ABI) /// and provides default values for unspecified settings. -#[llvm_versions(18.1..)] +#[llvm_versions(18..)] #[derive(Default, Debug)] pub struct TargetMachineOptions(Option); -#[llvm_versions(18.1..)] +#[llvm_versions(18..)] impl TargetMachineOptions { pub fn new() -> Self { Default::default() @@ -1491,7 +1491,7 @@ impl TargetMachineOptions { } } -#[llvm_versions(18.1..)] +#[llvm_versions(18..)] impl Drop for TargetMachineOptions { fn drop(&mut self) { if let Some(inner) = self.0 { diff --git a/src/types/array_type.rs b/src/types/array_type.rs index 40014d6e7cb..85568f3009c 100644 --- a/src/types/array_type.rs +++ b/src/types/array_type.rs @@ -97,7 +97,7 @@ impl<'ctx> ArrayType<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ), deprecated( note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead." diff --git a/src/types/enums.rs b/src/types/enums.rs index e6b75b6c79b..39460e8c994 100644 --- a/src/types/enums.rs +++ b/src/types/enums.rs @@ -224,7 +224,7 @@ impl<'ctx> AnyTypeEnum<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] LLVMTypeKind::LLVMBFloatTypeKind => AnyTypeEnum::FloatType(FloatType::new(type_)), LLVMTypeKind::LLVMLabelTypeKind => panic!("FIXME: Unsupported type: Label"), @@ -242,7 +242,7 @@ impl<'ctx> AnyTypeEnum<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] LLVMTypeKind::LLVMScalableVectorTypeKind => AnyTypeEnum::VectorType(VectorType::new(type_)), // FIXME: should inkwell support metadata as AnyType? @@ -255,11 +255,11 @@ impl<'ctx> AnyTypeEnum<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] LLVMTypeKind::LLVMX86_AMXTypeKind => panic!("FIXME: Unsupported type: AMX"), LLVMTypeKind::LLVMTokenTypeKind => panic!("FIXME: Unsupported type: Token"), - #[cfg(any(feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + #[cfg(any(feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] LLVMTypeKind::LLVMTargetExtTypeKind => panic!("FIXME: Unsupported type: TargetExt"), } } @@ -414,7 +414,7 @@ impl<'ctx> BasicTypeEnum<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] LLVMTypeKind::LLVMBFloatTypeKind => BasicTypeEnum::FloatType(FloatType::new(type_)), LLVMTypeKind::LLVMIntegerTypeKind => BasicTypeEnum::IntType(IntType::new(type_)), @@ -430,7 +430,7 @@ impl<'ctx> BasicTypeEnum<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] LLVMTypeKind::LLVMScalableVectorTypeKind => BasicTypeEnum::VectorType(VectorType::new(type_)), LLVMTypeKind::LLVMMetadataTypeKind => panic!("Unsupported basic type: Metadata"), @@ -444,14 +444,14 @@ impl<'ctx> BasicTypeEnum<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] LLVMTypeKind::LLVMX86_AMXTypeKind => unreachable!("Unsupported basic type: AMX"), LLVMTypeKind::LLVMLabelTypeKind => unreachable!("Unsupported basic type: Label"), LLVMTypeKind::LLVMVoidTypeKind => unreachable!("Unsupported basic type: VoidType"), LLVMTypeKind::LLVMFunctionTypeKind => unreachable!("Unsupported basic type: FunctionType"), LLVMTypeKind::LLVMTokenTypeKind => unreachable!("Unsupported basic type: Token"), - #[cfg(any(feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + #[cfg(any(feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] LLVMTypeKind::LLVMTargetExtTypeKind => unreachable!("Unsupported basic type: TargetExt"), } } diff --git a/src/types/float_type.rs b/src/types/float_type.rs index 7a405e428d5..b7abe8974b0 100644 --- a/src/types/float_type.rs +++ b/src/types/float_type.rs @@ -235,7 +235,7 @@ impl<'ctx> FloatType<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ), deprecated( note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead." diff --git a/src/types/fn_type.rs b/src/types/fn_type.rs index 131dfe3549e..25f3e8c92f3 100644 --- a/src/types/fn_type.rs +++ b/src/types/fn_type.rs @@ -65,7 +65,7 @@ impl<'ctx> FunctionType<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ), deprecated( note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead." diff --git a/src/types/int_type.rs b/src/types/int_type.rs index b3a2687ca62..c5867ce0090 100644 --- a/src/types/int_type.rs +++ b/src/types/int_type.rs @@ -322,7 +322,7 @@ impl<'ctx> IntType<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ), deprecated( note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead." diff --git a/src/types/ptr_type.rs b/src/types/ptr_type.rs index b313430e9b3..1ab7dedd76d 100644 --- a/src/types/ptr_type.rs +++ b/src/types/ptr_type.rs @@ -44,9 +44,9 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_type_size = f32_ptr_type.size_of(); /// ``` @@ -64,9 +64,9 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_type_alignment = f32_ptr_type.get_alignment(); /// ``` @@ -84,9 +84,9 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_ptr_type = f32_ptr_type.ptr_type(AddressSpace::default()); /// @@ -110,7 +110,7 @@ impl<'ctx> PointerType<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ), deprecated( note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead." @@ -130,9 +130,9 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// /// assert_eq!(f32_ptr_type.get_context(), context); @@ -152,9 +152,9 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = f32_ptr_type.fn_type(&[], false); /// ``` @@ -172,9 +172,9 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_array_type = f32_ptr_type.array_type(3); /// @@ -195,9 +195,9 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// /// assert_eq!(f32_ptr_type.get_address_space(), AddressSpace::default()); @@ -224,9 +224,9 @@ impl<'ctx> PointerType<'ctx> { /// // Local Context /// let context = Context::create(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_null = f32_ptr_type.const_null(); /// @@ -249,9 +249,9 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_zero = f32_ptr_type.const_zero(); /// ``` @@ -268,9 +268,9 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_undef = f32_ptr_type.get_undef(); /// @@ -290,9 +290,9 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_undef = f32_ptr_type.get_poison(); /// @@ -313,9 +313,9 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_vec_type = f32_ptr_type.vec_type(3); /// @@ -337,9 +337,9 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// /// assert_eq!(f32_ptr_type.get_element_type().into_float_type(), f32_type); @@ -358,9 +358,9 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_val = f32_ptr_type.const_null(); /// let f32_ptr_array = f32_ptr_type.const_array(&[f32_ptr_val, f32_ptr_val]); diff --git a/src/types/struct_type.rs b/src/types/struct_type.rs index c552aec6f7a..56e24251569 100644 --- a/src/types/struct_type.rs +++ b/src/types/struct_type.rs @@ -221,7 +221,7 @@ impl<'ctx> StructType<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ), deprecated( note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead." diff --git a/src/types/traits.rs b/src/types/traits.rs index cac47f88b78..0637df266b6 100644 --- a/src/types/traits.rs +++ b/src/types/traits.rs @@ -131,7 +131,7 @@ pub unsafe trait BasicType<'ctx>: AnyType<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ), deprecated( note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead." diff --git a/src/types/vec_type.rs b/src/types/vec_type.rs index 0c977a905dc..28ccd1f4b70 100644 --- a/src/types/vec_type.rs +++ b/src/types/vec_type.rs @@ -220,7 +220,7 @@ impl<'ctx> VectorType<'ctx> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ), deprecated( note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead." diff --git a/src/values/basic_value_use.rs b/src/values/basic_value_use.rs index 84824a995a0..32591293770 100644 --- a/src/values/basic_value_use.rs +++ b/src/values/basic_value_use.rs @@ -40,9 +40,9 @@ impl<'ctx> BasicValueUse<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false); /// @@ -104,9 +104,9 @@ impl<'ctx> BasicValueUse<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false); /// @@ -143,9 +143,9 @@ impl<'ctx> BasicValueUse<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false); /// diff --git a/src/values/call_site_value.rs b/src/values/call_site_value.rs index 1dd0fe45971..833866ce01a 100644 --- a/src/values/call_site_value.rs +++ b/src/values/call_site_value.rs @@ -5,7 +5,7 @@ use llvm_sys::core::{ LLVMGetInstructionCallConv, LLVMGetTypeKind, LLVMIsTailCall, LLVMSetInstrParamAlignment, LLVMSetInstructionCallConv, LLVMSetTailCall, LLVMTypeOf, }; -#[llvm_versions(18.1..)] +#[llvm_versions(18..)] use llvm_sys::core::{LLVMGetTailCallKind, LLVMSetTailCallKind}; use llvm_sys::prelude::LLVMValueRef; use llvm_sys::LLVMTypeKind; @@ -104,7 +104,7 @@ impl<'ctx> CallSiteValue<'ctx> { /// /// assert_eq!(call_site.get_tail_call_kind(), LLVMTailCallKindNone); /// ``` - #[llvm_versions(18.1..)] + #[llvm_versions(18..)] pub fn get_tail_call_kind(self) -> super::LLVMTailCallKind { unsafe { LLVMGetTailCallKind(self.as_value_ref()) } } @@ -131,7 +131,7 @@ impl<'ctx> CallSiteValue<'ctx> { /// call_site.set_tail_call_kind(LLVMTailCallKindTail); /// assert_eq!(call_site.get_tail_call_kind(), LLVMTailCallKindTail); /// ``` - #[llvm_versions(18.1..)] + #[llvm_versions(18..)] pub fn set_tail_call_kind(self, kind: super::LLVMTailCallKind) { unsafe { LLVMSetTailCallKind(self.as_value_ref(), kind) }; } diff --git a/src/values/instruction_value.rs b/src/values/instruction_value.rs index 6bb143d6dbc..3a654261fb7 100644 --- a/src/values/instruction_value.rs +++ b/src/values/instruction_value.rs @@ -260,7 +260,7 @@ impl<'ctx> InstructionValue<'ctx> { /// Returns the tail call kind on call instructions. /// /// Other instructions return `None`. - #[llvm_versions(18.1..)] + #[llvm_versions(18..)] pub fn get_tail_call_kind(self) -> Option { if self.get_opcode() == InstructionOpcode::Call { unsafe { llvm_sys::core::LLVMGetTailCallKind(self.as_value_ref()) }.into() @@ -272,7 +272,7 @@ impl<'ctx> InstructionValue<'ctx> { /// Check whether this instructions supports [fast math flags][0]. /// /// [0]: https://llvm.org/docs/LangRef.html#fast-math-flags - #[llvm_versions(18.1..)] + #[llvm_versions(18..)] pub fn can_use_fast_math_flags(self) -> bool { unsafe { llvm_sys::core::LLVMCanValueUseFastMathFlags(self.as_value_ref()) == 1 } } @@ -282,7 +282,7 @@ impl<'ctx> InstructionValue<'ctx> { /// Calling this on unsupported instructions is safe and returns `None`. /// /// [0]: https://llvm.org/docs/LangRef.html#fast-math-flags - #[llvm_versions(18.1..)] + #[llvm_versions(18..)] pub fn get_fast_math_flags(self) -> Option { self.can_use_fast_math_flags() .then(|| unsafe { llvm_sys::core::LLVMGetFastMathFlags(self.as_value_ref()) } as u32) @@ -293,7 +293,7 @@ impl<'ctx> InstructionValue<'ctx> { /// Calling this on unsupported instructions is safe and results in a no-op. /// /// [0]: https://llvm.org/docs/LangRef.html#fast-math-flags - #[llvm_versions(18.1..)] + #[llvm_versions(18..)] pub fn set_fast_math_flags(self, flags: u32) { if self.can_use_fast_math_flags() { unsafe { llvm_sys::core::LLVMSetFastMathFlags(self.as_value_ref(), flags) }; @@ -303,7 +303,7 @@ impl<'ctx> InstructionValue<'ctx> { /// Check if a `zext` instruction has the non-negative flag set. /// /// Calling this function on other instructions is safe and returns `None`. - #[llvm_versions(18.1..)] + #[llvm_versions(18..)] pub fn get_non_negative_flag(self) -> Option { (self.get_opcode() == InstructionOpcode::ZExt) .then(|| unsafe { llvm_sys::core::LLVMGetNNeg(self.as_value_ref()) == 1 }) @@ -312,7 +312,7 @@ impl<'ctx> InstructionValue<'ctx> { /// Set the non-negative flag on `zext` instructions. /// /// Calling this function on other instructions is safe and results in a no-op. - #[llvm_versions(18.1..)] + #[llvm_versions(18..)] pub fn set_non_negative_flag(self, flag: bool) { if self.get_opcode() == InstructionOpcode::ZExt { unsafe { llvm_sys::core::LLVMSetNNeg(self.as_value_ref(), flag as i32) }; @@ -322,7 +322,7 @@ impl<'ctx> InstructionValue<'ctx> { /// Checks if an `or` instruction has the `disjoint` flag set. /// /// Calling this function on other instructions is safe and returns `None`. - #[llvm_versions(18.1..)] + #[llvm_versions(18..)] pub fn get_disjoint_flag(self) -> Option { (self.get_opcode() == InstructionOpcode::Or) .then(|| unsafe { llvm_sys::core::LLVMGetIsDisjoint(self.as_value_ref()) == 1 }) @@ -331,7 +331,7 @@ impl<'ctx> InstructionValue<'ctx> { /// Set the `disjoint` flag on `or` instructions. /// /// Calling this function on other instructions is safe and results in a no-op. - #[llvm_versions(18.1..)] + #[llvm_versions(18..)] pub fn set_disjoint_flag(self, flag: bool) { if self.get_opcode() == InstructionOpcode::Or { unsafe { llvm_sys::core::LLVMSetIsDisjoint(self.as_value_ref(), flag as i32) }; @@ -475,9 +475,9 @@ impl<'ctx> InstructionValue<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false); /// @@ -538,9 +538,9 @@ impl<'ctx> InstructionValue<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false); /// @@ -642,9 +642,9 @@ impl<'ctx> InstructionValue<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false); /// @@ -688,9 +688,9 @@ impl<'ctx> InstructionValue<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false); /// @@ -755,9 +755,9 @@ impl<'ctx> InstructionValue<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let f32_type = context.f32_type(); - /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); - /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false); /// diff --git a/src/values/metadata_value.rs b/src/values/metadata_value.rs index c340bdffa6d..4a56c36c3f9 100644 --- a/src/values/metadata_value.rs +++ b/src/values/metadata_value.rs @@ -38,7 +38,7 @@ pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = if cfg!(feature = "llvm4-0") { 36 } else if cfg!(any(feature = "llvm16-0", feature = "llvm17-0")) { 39 -} else if cfg!(feature = "llvm18-1") { +} else if cfg!(feature = "llvm18-0") { 40 } else { panic!("Unhandled LLVM version") diff --git a/src/values/mod.rs b/src/values/mod.rs index 508d9f34f2e..40248cca477 100644 --- a/src/values/mod.rs +++ b/src/values/mod.rs @@ -24,7 +24,7 @@ mod vec_value; feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] mod callable_value; @@ -32,7 +32,7 @@ mod callable_value; feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] pub use crate::values::callable_value::CallableValue; @@ -59,7 +59,7 @@ pub use crate::values::traits::AsValueRef; pub use crate::values::traits::{AggregateValue, AnyValue, BasicValue, FloatMathValue, IntMathValue, PointerMathValue}; pub use crate::values::vec_value::VectorValue; -#[llvm_versions(18.1..)] +#[llvm_versions(18..)] pub use llvm_sys::LLVMTailCallKind; use llvm_sys::core::{ diff --git a/tests/all/main.rs b/tests/all/main.rs index 2eb14b2855b..2f57a23914c 100644 --- a/tests/all/main.rs +++ b/tests/all/main.rs @@ -15,7 +15,7 @@ mod test_instruction_values; mod test_intrinsics; mod test_module; mod test_object_file; -#[cfg(not(any(feature = "llvm17-0", feature = "llvm18-1")))] +#[cfg(not(any(feature = "llvm17-0", feature = "llvm18-0")))] mod test_passes; mod test_targets; mod test_tari_example; diff --git a/tests/all/test_builder.rs b/tests/all/test_builder.rs index 5e02bab1868..8d22573684a 100644 --- a/tests/all/test_builder.rs +++ b/tests/all/test_builder.rs @@ -51,14 +51,14 @@ fn test_build_call() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let fn_ptr_type = fn_ptr.get_type(); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let fn_ptr_type = context.ptr_type(AddressSpace::default()); @@ -86,7 +86,7 @@ fn test_build_call() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let load = builder .build_load(fn_ptr_type, alloca, "load") @@ -115,7 +115,7 @@ fn test_build_call() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] builder.build_indirect_call(fn_type2, load, &[], "call").unwrap(); builder.build_return(None).unwrap(); @@ -183,14 +183,14 @@ fn test_build_invoke_cleanup_resume() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let i8_ptr_type = context.i32_type().ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let i8_ptr_type = context.ptr_type(AddressSpace::default()); let i32_type = context.i32_type(); @@ -267,14 +267,14 @@ fn test_build_invoke_catch_all() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let i8_ptr_type = context.i32_type().ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let i8_ptr_type = context.ptr_type(AddressSpace::default()); let i32_type = context.i32_type(); @@ -355,14 +355,14 @@ fn landing_pad_filter() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let i8_ptr_type = context.i32_type().ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let i8_ptr_type = context.ptr_type(AddressSpace::default()); let i32_type = context.i32_type(); @@ -413,14 +413,14 @@ fn test_null_checked_ptr_ops() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let i8_ptr_type = context.i32_type().ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let i8_ptr_type = context.ptr_type(AddressSpace::default()); let i64_type = context.i64_type(); @@ -472,7 +472,7 @@ fn test_null_checked_ptr_ops() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let index1 = builder.build_load(i8_ptr_type, new_ptr, "deref").unwrap(); @@ -531,7 +531,7 @@ fn test_null_checked_ptr_ops() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let index1 = builder.build_load(i8_ptr_type, new_ptr, "deref").unwrap(); @@ -1020,14 +1020,14 @@ fn test_vector_pointer_ops() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let i8_ptr_vec_type = context.i8_type().ptr_type(AddressSpace::default()).vec_type(4); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let i8_ptr_vec_type = context.ptr_type(AddressSpace::default()).vec_type(4); let bool_vec_type = context.bool_type().vec_type(4); @@ -1085,7 +1085,7 @@ fn test_insert_value() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let array = builder .build_load(array_type, array_alloca, "array_load") @@ -1144,7 +1144,7 @@ fn test_insert_value() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let struct_value = builder .build_load(struct_type, struct_alloca, "struct_load") @@ -1290,14 +1290,14 @@ fn run_memcpy_on<'ctx>( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let fn_type = i32_type.ptr_type(AddressSpace::default()).fn_type(&[], false); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let fn_type = context.ptr_type(AddressSpace::default()).fn_type(&[], false); let fn_value = module.add_function("test_fn", fn_type, None); @@ -1331,7 +1331,7 @@ fn run_memcpy_on<'ctx>( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let elem_ptr = unsafe { builder @@ -1366,7 +1366,7 @@ fn run_memcpy_on<'ctx>( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let dest_ptr = unsafe { builder @@ -1422,14 +1422,14 @@ fn run_memmove_on<'ctx>( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let fn_type = i32_type.ptr_type(AddressSpace::default()).fn_type(&[], false); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let fn_type = context.ptr_type(AddressSpace::default()).fn_type(&[], false); let fn_value = module.add_function("test_fn", fn_type, None); @@ -1463,7 +1463,7 @@ fn run_memmove_on<'ctx>( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let elem_ptr = unsafe { builder @@ -1498,7 +1498,7 @@ fn run_memmove_on<'ctx>( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let dest_ptr = unsafe { builder @@ -1555,14 +1555,14 @@ fn run_memset_on<'ctx>( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let fn_type = i32_type.ptr_type(AddressSpace::default()).fn_type(&[], false); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let fn_type = context.ptr_type(AddressSpace::default()).fn_type(&[], false); let fn_value = module.add_function("test_fn", fn_type, None); @@ -1602,7 +1602,7 @@ fn run_memset_on<'ctx>( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let part_2 = unsafe { builder @@ -1658,28 +1658,28 @@ fn test_bit_cast() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let i32_ptr_type = context.ptr_type(AddressSpace::default()); #[cfg(not(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let i64_ptr_type = i64_type.ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let i64_ptr_type = context.ptr_type(AddressSpace::default()); let i32_vec_type = i32_type.vec_type(2); @@ -1740,14 +1740,14 @@ fn test_atomicrmw() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let ptr_value = i32_type.ptr_type(AddressSpace::default()).get_undef(); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let ptr_value = context.ptr_type(AddressSpace::default()).get_undef(); let zero_value = i32_type.const_zero(); @@ -1779,14 +1779,14 @@ fn test_atomicrmw() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let ptr_value = i31_type.ptr_type(AddressSpace::default()).get_undef(); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let ptr_value = context.ptr_type(AddressSpace::default()).get_undef(); let zero_value = i31_type.const_zero(); @@ -1797,14 +1797,14 @@ fn test_atomicrmw() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let ptr_value = i4_type.ptr_type(AddressSpace::default()).get_undef(); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let ptr_value = context.ptr_type(AddressSpace::default()).get_undef(); let zero_value = i4_type.const_zero(); @@ -1830,28 +1830,28 @@ fn test_cmpxchg() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let i32_ptr_type = context.ptr_type(AddressSpace::default()); #[cfg(not(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let i32_ptr_ptr_type = i32_ptr_type.ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let i32_ptr_ptr_type = context.ptr_type(AddressSpace::default()); @@ -2029,14 +2029,14 @@ fn test_safe_struct_gep() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let i32_ptr_ty = i32_ty.ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let i32_ptr_ty = context.ptr_type(AddressSpace::default()); let field_types = &[i32_ty.into(), i32_ty.into()]; @@ -2045,14 +2045,14 @@ fn test_safe_struct_gep() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let struct_ptr_ty = struct_ty.ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let struct_ptr_ty = context.ptr_type(AddressSpace::default()); let fn_type = void_type.fn_type(&[i32_ptr_ty.into(), struct_ptr_ty.into()], false); @@ -2088,7 +2088,7 @@ fn test_safe_struct_gep() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] { assert!(builder.build_struct_gep(i32_ty, i32_ptr, 0, "struct_gep").is_err()); diff --git a/tests/all/test_context.rs b/tests/all/test_context.rs index f7241caabca..003eedf1439 100644 --- a/tests/all/test_context.rs +++ b/tests/all/test_context.rs @@ -57,14 +57,14 @@ fn test_values_get_context() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let f32_ptr_type = context.ptr_type(AddressSpace::default()); let f32_array_type = f32_type.array_type(2); diff --git a/tests/all/test_debug_info.rs b/tests/all/test_debug_info.rs index 17ce1d70d32..31408f0ef92 100644 --- a/tests/all/test_debug_info.rs +++ b/tests/all/test_debug_info.rs @@ -33,7 +33,7 @@ fn test_smoke() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] "", #[cfg(any( @@ -44,7 +44,7 @@ fn test_smoke() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] "", ); @@ -123,7 +123,7 @@ fn test_struct_with_placeholders() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] "", #[cfg(any( @@ -134,7 +134,7 @@ fn test_struct_with_placeholders() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] "", ); @@ -255,7 +255,7 @@ fn test_no_explicit_finalize() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] "", #[cfg(any( @@ -266,7 +266,7 @@ fn test_no_explicit_finalize() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] "", ); @@ -304,7 +304,7 @@ fn test_replacing_placeholder_with_placeholder() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] "", #[cfg(any( @@ -315,7 +315,7 @@ fn test_replacing_placeholder_with_placeholder() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] "", ); @@ -367,7 +367,7 @@ fn test_anonymous_basic_type() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] "", #[cfg(any( @@ -378,7 +378,7 @@ fn test_anonymous_basic_type() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] "", ); @@ -423,7 +423,7 @@ fn test_global_expressions() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] "", #[cfg(any( @@ -434,7 +434,7 @@ fn test_global_expressions() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] "", ); @@ -497,7 +497,7 @@ fn test_pointer_types() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] "", #[cfg(any( @@ -508,7 +508,7 @@ fn test_pointer_types() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] "", ); @@ -555,7 +555,7 @@ fn test_reference_types() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] "", #[cfg(any( @@ -566,7 +566,7 @@ fn test_reference_types() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] "", ); @@ -614,7 +614,7 @@ fn test_array_type() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] "", #[cfg(any( @@ -625,7 +625,7 @@ fn test_array_type() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] "", ); diff --git a/tests/all/test_execution_engine.rs b/tests/all/test_execution_engine.rs index c0b0c778483..bd056f00003 100644 --- a/tests/all/test_execution_engine.rs +++ b/tests/all/test_execution_engine.rs @@ -58,7 +58,7 @@ fn test_jit_execution_engine() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let i8_ptr_ptr_type = context .i8_type() @@ -68,7 +68,7 @@ fn test_jit_execution_engine() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let i8_ptr_ptr_type = context.ptr_type(AddressSpace::default()); let one_i32 = i32_type.const_int(1, false); diff --git a/tests/all/test_instruction_conversion.rs b/tests/all/test_instruction_conversion.rs index 1053d03adfe..e129e711af9 100644 --- a/tests/all/test_instruction_conversion.rs +++ b/tests/all/test_instruction_conversion.rs @@ -114,14 +114,14 @@ fn test_conversion_to_pointer_value() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let i64_ptr_type = context.i64_type().ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let i64_ptr_type = context.ptr_type(AddressSpace::default()); let alloca_instr = builder diff --git a/tests/all/test_instruction_values.rs b/tests/all/test_instruction_values.rs index 6c5cc78d688..539bbc1396d 100644 --- a/tests/all/test_instruction_values.rs +++ b/tests/all/test_instruction_values.rs @@ -15,14 +15,14 @@ fn test_operands() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let f32_ptr_type = context.ptr_type(AddressSpace::default()); let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false); @@ -271,14 +271,14 @@ fn test_instructions() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let f32_ptr_type = context.ptr_type(AddressSpace::default()); let fn_type = void_type.fn_type(&[f32_ptr_type.into(), f32_type.into()], false); @@ -375,14 +375,14 @@ fn test_volatile_atomicrmw_cmpxchg() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let i32_ptr_type = context.ptr_type(AddressSpace::default()); let fn_type = void_type.fn_type(&[i32_ptr_type.into(), i32_type.into()], false); @@ -442,14 +442,14 @@ fn test_mem_instructions() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let f32_ptr_type = context.ptr_type(AddressSpace::default()); let fn_type = void_type.fn_type(&[f32_ptr_type.into(), f32_type.into()], false); @@ -520,14 +520,14 @@ fn test_mem_instructions() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let f32_ptr_type = context.ptr_type(AddressSpace::default()); let fn_type = void_type.fn_type(&[f32_ptr_type.into(), f32_type.into()], false); @@ -564,7 +564,7 @@ fn test_mem_instructions() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let load = builder.build_load(f32_type, arg1, "").unwrap(); let load_instruction = load.as_instruction_value().unwrap(); @@ -617,14 +617,14 @@ fn test_atomic_ordering_mem_instructions() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let f32_ptr_type = context.ptr_type(AddressSpace::default()); let fn_type = void_type.fn_type(&[f32_ptr_type.into(), f32_type.into()], false); @@ -661,7 +661,7 @@ fn test_atomic_ordering_mem_instructions() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let load = builder.build_load(f32_type, arg1, "").unwrap(); let load_instruction = load.as_instruction_value().unwrap(); @@ -710,14 +710,14 @@ fn test_metadata_kinds() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let ptr_type = i8_type.ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let ptr_type = context.ptr_type(AddressSpace::default()); let struct_type = context.struct_type(&[i8_type.into(), f32_type.into()], false); @@ -757,14 +757,14 @@ fn test_find_instruction_with_name() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let i32_ptr_type = context.ptr_type(AddressSpace::default()); @@ -784,7 +784,7 @@ fn test_find_instruction_with_name() { assert_eq!(some_number.unwrap().get_name().unwrap().to_str(), Ok("some_number")) } -#[llvm_versions(18.1..)] +#[llvm_versions(18..)] #[test] fn test_fast_math_flags() { let context = Context::create(); @@ -828,7 +828,7 @@ fn test_fast_math_flags() { assert_eq!(f32_addition.get_fast_math_flags(), Some(1)); } -#[llvm_versions(18.1..)] +#[llvm_versions(18..)] #[test] fn test_zext_non_negative_flag() { let context = Context::create(); @@ -870,7 +870,7 @@ fn test_zext_non_negative_flag() { assert_eq!(i32_sext.get_non_negative_flag(), None); } -#[llvm_versions(18.1..)] +#[llvm_versions(18..)] #[test] fn test_or_disjoint_flag() { let context = Context::create(); diff --git a/tests/all/test_targets.rs b/tests/all/test_targets.rs index f45008f81f5..dad038bdf73 100644 --- a/tests/all/test_targets.rs +++ b/tests/all/test_targets.rs @@ -428,7 +428,7 @@ fn test_write_target_machine_to_memory_buffer() { write_target_machine_to_memory_buffer(target_machine); } -#[llvm_versions(18.1..)] +#[llvm_versions(18..)] #[test] fn test_create_target_machine_from_default_options() { Target::initialize_x86(&InitializationConfig::default()); @@ -445,7 +445,7 @@ fn test_create_target_machine_from_default_options() { write_target_machine_to_memory_buffer(target_machine); } -#[llvm_versions(18.1..)] +#[llvm_versions(18..)] #[test] fn test_create_target_machine_from_options() { Target::initialize_x86(&InitializationConfig::default()); diff --git a/tests/all/test_types.rs b/tests/all/test_types.rs index 6e812679769..d1e782652fa 100644 --- a/tests/all/test_types.rs +++ b/tests/all/test_types.rs @@ -164,7 +164,7 @@ fn sized_types(global_ctx: &Context) { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let ptr_type = global_ctx.ptr_type(AddressSpace::default()); let struct_type = global_ctx.struct_type(&[i8_type.into(), f128_type.into()], false); @@ -195,7 +195,7 @@ fn sized_types(global_ctx: &Context) { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] assert!(ptr_type.is_sized()); assert!(struct_type.is_sized()); @@ -211,7 +211,7 @@ fn sized_types(global_ctx: &Context) { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] { assert!(bool_type.ptr_type(AddressSpace::default()).is_sized()); @@ -248,7 +248,7 @@ fn sized_types(global_ctx: &Context) { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] assert!(ptr_type.array_type(42).is_sized()); assert!(struct_type.array_type(0).is_sized()); @@ -272,7 +272,7 @@ fn sized_types(global_ctx: &Context) { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] assert!(ptr_type.vec_type(42).is_sized()); @@ -285,7 +285,7 @@ fn sized_types(global_ctx: &Context) { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] { let opaque_struct_ptr_type = opaque_struct_type.ptr_type(AddressSpace::default()); @@ -313,14 +313,14 @@ fn test_const_zero() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let ptr_type = f64_type.ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let ptr_type = context.ptr_type(AddressSpace::default()); let vec_type = f64_type.vec_type(42); @@ -405,7 +405,7 @@ fn test_const_zero() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )) { "ptr null" } else { @@ -446,14 +446,14 @@ fn test_ptr_type() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let ptr_type = context.i8_type().ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let ptr_type = context.ptr_type(AddressSpace::default()); @@ -515,14 +515,14 @@ fn test_basic_type_enum() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] &int.ptr_type(addr), #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] &context.ptr_type(addr), &context.struct_type(&[int.as_basic_type_enum()], false), @@ -533,7 +533,7 @@ fn test_basic_type_enum() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] assert_eq!( basic_type.as_basic_type_enum().ptr_type(addr), @@ -565,14 +565,14 @@ fn test_ptr_address_space() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let ptr = context.i32_type().ptr_type(address_space); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let ptr = context.ptr_type(address_space); assert_eq!(ptr.get_address_space(), address_space); diff --git a/tests/all/test_values.rs b/tests/all/test_values.rs index 546c31b6a33..bba39fab60d 100644 --- a/tests/all/test_values.rs +++ b/tests/all/test_values.rs @@ -7,10 +7,10 @@ use inkwell::types::{AnyTypeEnum, StringRadix, VectorType}; use inkwell::values::{AnyValue, InstructionOpcode::*, FIRST_CUSTOM_METADATA_KIND_ID}; use inkwell::{AddressSpace, DLLStorageClass, GlobalVisibility, ThreadLocalMode}; -#[llvm_versions(18.1..)] +#[llvm_versions(18..)] pub use llvm_sys::LLVMTailCallKind::*; -#[cfg(feature = "llvm18-1")] -use llvm_sys_181 as llvm_sys; +#[cfg(feature = "llvm18-0")] +use llvm_sys_180 as llvm_sys; use std::convert::TryFrom; @@ -70,7 +70,7 @@ fn test_call_site() { } #[test] -#[cfg(feature = "llvm18-1")] +#[cfg(feature = "llvm18-0")] fn test_call_site_tail_call_attributes() { let context = Context::create(); let builder = context.create_builder(); @@ -115,7 +115,7 @@ fn test_set_get_name() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let ptr_type = context.ptr_type(AddressSpace::default()); let array_type = f64_type.array_type(42); @@ -135,14 +135,14 @@ fn test_set_get_name() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let ptr_val = bool_type.ptr_type(AddressSpace::default()).const_null(); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let ptr_val = ptr_type.const_null(); let array_val = f64_type.const_array(&[f64_val]); @@ -204,14 +204,14 @@ fn test_set_get_name() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let ptr_type = bool_type.ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let ptr_type = context.ptr_type(AddressSpace::default()); let struct_type = context.struct_type(&[bool_type.into()], false); @@ -288,7 +288,7 @@ fn test_undef() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let ptr_type = context.ptr_type(AddressSpace::default()); let array_type = f64_type.array_type(42); @@ -310,14 +310,14 @@ fn test_undef() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let ptr_val = bool_type.ptr_type(AddressSpace::default()).const_null(); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let ptr_val = ptr_type.const_null(); let array_val = f64_type.const_array(&[f64_val]); @@ -355,14 +355,14 @@ fn test_undef() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let ptr_undef = bool_type.ptr_type(AddressSpace::default()).get_undef(); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let ptr_undef = ptr_type.get_undef(); let array_undef = array_type.get_undef(); @@ -405,7 +405,7 @@ fn test_poison() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let ptr_type = context.ptr_type(AddressSpace::default()); let array_type = f64_type.array_type(42); @@ -427,14 +427,14 @@ fn test_poison() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let ptr_val = bool_type.ptr_type(AddressSpace::default()).const_null(); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let ptr_val = ptr_type.const_null(); let array_val = f64_type.const_array(&[f64_val]); @@ -472,14 +472,14 @@ fn test_poison() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let ptr_poison = bool_type.ptr_type(AddressSpace::default()).get_poison(); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let ptr_poison = ptr_type.get_poison(); let array_poison = array_type.get_poison(); @@ -624,7 +624,7 @@ fn test_metadata() { let f32_type = context.f32_type(); // let f64_type = context.f64_type(); // let f128_type = context.f128_type(); - // #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + // #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] // let ptr_type = context.ptr_type(AddressSpace::default()); // let array_type = f64_type.array_type(42); // let ppc_f128_type = context.ppc_f128_type(); @@ -641,9 +641,9 @@ fn test_metadata() { // let f64_val = f64_type.const_float(0.0); // let f128_val = f128_type.const_float(0.0); // let ppc_f128_val = ppc_f128_type.const_float(0.0); - // #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + // #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] // let ptr_val = bool_type.ptr_type(AddressSpace::default()).const_null(); - // #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1"))] + // #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0"))] // let ptr_val = ptr_type.const_null(); // let array_val = f64_type.const_array(&[f64_val]); // let struct_val = context.const_struct(&[i8_val.into(), f128_val.into()], false); @@ -747,7 +747,7 @@ fn test_metadata() { #[test] fn test_floats() { - #[cfg(not(any(feature = "llvm15-0", feature = "llvm18-1")))] + #[cfg(not(any(feature = "llvm15-0", feature = "llvm18-0")))] { use inkwell::FloatPredicate; @@ -782,7 +782,7 @@ fn test_floats() { let f64_one = f64_type.const_float(1.); let f64_two = f64_type.const_float(2.); - #[cfg(not(any(feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1")))] + #[cfg(not(any(feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-0")))] { let neg_two = f64_two.const_neg(); @@ -1167,7 +1167,7 @@ fn test_allocations() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )) { "ptr" } else { @@ -1438,14 +1438,14 @@ fn test_non_fn_ptr_called() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let i8_ptr_type = i8_type.ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let i8_ptr_type = context.ptr_type(AddressSpace::default()); let fn_type = i8_type.fn_type(&[i8_ptr_type.into()], false); @@ -1476,7 +1476,7 @@ fn test_non_fn_ptr_called() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] builder .build_indirect_call(i8_ptr_type.fn_type(&[], false), i8_ptr_param, &[], "call") @@ -1524,14 +1524,14 @@ fn test_aggregate_returns() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" )))] let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); #[cfg(any( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] let i32_ptr_type = context.ptr_type(AddressSpace::default()); let i32_three = i32_type.const_int(3, false); @@ -1562,7 +1562,7 @@ fn test_aggregate_returns() { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-1" + feature = "llvm18-0" ))] builder .build_ptr_diff(i32_ptr_type, ptr_param1, ptr_param2, "diff")