From bfb0e32bc329fd35f6c5a529a1a6209936a147f8 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 5 Jun 2021 13:23:40 +0200 Subject: [PATCH 01/15] add feature flag --- Cargo.toml | 3 +++ internal_macros/src/lib.rs | 4 ++-- src/debug_info.rs | 14 +++++++------- src/lib.rs | 4 +++- src/module.rs | 8 ++++---- src/types/enums.rs | 8 ++++---- src/values/instruction_value.rs | 2 +- src/values/metadata_value.rs | 2 +- 8 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cf25a2c636645..ae2bcaef3be94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ llvm8-0 = ["llvm-sys-80"] llvm9-0 = ["llvm-sys-90"] llvm10-0 = ["llvm-sys-100"] llvm11-0 = ["llvm-sys-110"] +llvm12-0 = ["llvm-sys-120"] # Don't link aganist LLVM libraries. This is useful if another dependency is # installing LLVM. See llvm-sys for more details. We can't enable a single # `no-llvm-linking` feature across the board of llvm versions, as it'll cause @@ -43,6 +44,7 @@ llvm8-0-no-llvm-linking = ["llvm8-0", "llvm-sys-80/no-llvm-linking"] llvm9-0-no-llvm-linking = ["llvm9-0", "llvm-sys-90/no-llvm-linking"] llvm10-0-no-llvm-linking = ["llvm10-0", "llvm-sys-100/no-llvm-linking"] llvm11-0-no-llvm-linking = ["llvm11-0", "llvm-sys-110/no-llvm-linking"] +llvm12-0-no-llvm-linking = ["llvm12-0", "llvm-sys-120/no-llvm-linking"] # Don't force linking to libffi on non-windows platforms. Without this feature # inkwell always links to libffi on non-windows platforms. no-libffi-linking = [] @@ -99,6 +101,7 @@ llvm-sys-80 = { package = "llvm-sys", version = "80.3", optional = true } llvm-sys-90 = { package = "llvm-sys", version = "90.2", optional = true } llvm-sys-100 = { package = "llvm-sys", version = "100.2", optional = true } llvm-sys-110 = { package = "llvm-sys", version = "110.0", optional = true } +llvm-sys-120 = { package = "llvm-sys", version = "120.0", optional = true } once_cell = "1.4.1" parking_lot = "0.11" regex = "1" diff --git a/internal_macros/src/lib.rs b/internal_macros/src/lib.rs index 1e5487a6be6c1..1a176b4320275 100644 --- a/internal_macros/src/lib.rs +++ b/internal_macros/src/lib.rs @@ -19,8 +19,8 @@ use syn::spanned::Spanned; use syn::{Token, LitFloat, Ident, Item, Field, Variant, Attribute}; // This array should match the LLVM features in the top level Cargo manifest -const FEATURE_VERSIONS: [&str; 12] = - ["llvm3-6", "llvm3-7", "llvm3-8", "llvm3-9", "llvm4-0", "llvm5-0", "llvm6-0", "llvm7-0", "llvm8-0", "llvm9-0", "llvm10-0", "llvm11-0"]; +const FEATURE_VERSIONS: [&str; 13] = + ["llvm3-6", "llvm3-7", "llvm3-8", "llvm3-9", "llvm4-0", "llvm5-0", "llvm6-0", "llvm7-0", "llvm8-0", "llvm9-0", "llvm10-0", "llvm11-0", "llvm12-0"]; /// Gets the index of the feature version that represents `latest` fn get_latest_feature_index(features: &[&str]) -> usize { diff --git a/src/debug_info.rs b/src/debug_info.rs index c3a570addcd77..58a080308027f 100644 --- a/src/debug_info.rs +++ b/src/debug_info.rs @@ -177,9 +177,9 @@ impl<'ctx> DebugInfoBuilder<'ctx> { dwo_id: libc::c_uint, split_debug_inlining: bool, debug_info_for_profiling: bool, - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] sysroot: &str, - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] sdk: &str, ) -> (Self, DICompileUnit<'ctx>) { let builder = unsafe { @@ -209,9 +209,9 @@ impl<'ctx> DebugInfoBuilder<'ctx> { dwo_id, split_debug_inlining, debug_info_for_profiling, - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] sysroot, - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] sdk ); @@ -244,9 +244,9 @@ impl<'ctx> DebugInfoBuilder<'ctx> { dwo_id: libc::c_uint, split_debug_inlining: bool, debug_info_for_profiling: bool, - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] sysroot: &str, - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] sdk: &str, ) -> DICompileUnit<'ctx> { @@ -271,7 +271,7 @@ impl<'ctx> DebugInfoBuilder<'ctx> { debug_info_for_profiling as _, ) } - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] { LLVMDIBuilderCreateCompileUnit( self.builder, language.into(), diff --git a/src/lib.rs b/src/lib.rs index 668fe3f44dd9b..8fad5ae3e2c2b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,6 +65,8 @@ extern crate llvm_sys_90 as llvm_sys; extern crate llvm_sys_100 as llvm_sys; #[cfg(feature="llvm11-0")] extern crate llvm_sys_110 as llvm_sys; +#[cfg(feature="llvm12-0")] +extern crate llvm_sys_120 as llvm_sys; use llvm_sys::{LLVMIntPredicate, LLVMRealPredicate, LLVMVisibility, LLVMThreadLocalMode, LLVMDLLStorageClass, LLVMAtomicOrdering, LLVMAtomicRMWBinOp}; @@ -102,7 +104,7 @@ macro_rules! assert_unique_used_features { } } -assert_unique_used_features!{"llvm3-6", "llvm3-7", "llvm3-8", "llvm3-9", "llvm4-0", "llvm5-0", "llvm6-0", "llvm7-0", "llvm8-0", "llvm9-0", "llvm10-0", "llvm11-0"} +assert_unique_used_features!{"llvm3-6", "llvm3-7", "llvm3-8", "llvm3-9", "llvm4-0", "llvm5-0", "llvm6-0", "llvm7-0", "llvm8-0", "llvm9-0", "llvm10-0", "llvm11-0", "llvm12-0"} /// Defines the address space in which a global will be inserted. /// diff --git a/src/module.rs b/src/module.rs index 6caabfad3eb91..d6b387c3c39b5 100644 --- a/src/module.rs +++ b/src/module.rs @@ -1380,18 +1380,18 @@ impl<'ctx> Module<'ctx> { dwo_id: libc::c_uint, split_debug_inlining: bool, debug_info_for_profiling: bool, - #[cfg(feature="llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] sysroot: &str, - #[cfg(feature="llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] sdk: &str, ) -> (DebugInfoBuilder<'ctx>, DICompileUnit<'ctx>) { DebugInfoBuilder::new(self, allow_unresolved, language, filename, directory, producer, is_optimized, flags, runtime_ver, split_name, kind, dwo_id, split_debug_inlining, debug_info_for_profiling, - #[cfg(feature="llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] sysroot, - #[cfg(feature="llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] sdk ) } diff --git a/src/types/enums.rs b/src/types/enums.rs index 211801d9d8643..b7bc27ba019f9 100644 --- a/src/types/enums.rs +++ b/src/types/enums.rs @@ -99,7 +99,7 @@ impl<'ctx> AnyTypeEnum<'ctx> { LLVMTypeKind::LLVMX86_FP80TypeKind | LLVMTypeKind::LLVMFP128TypeKind | LLVMTypeKind::LLVMPPC_FP128TypeKind => AnyTypeEnum::FloatType(FloatType::new(type_)), - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] LLVMTypeKind::LLVMBFloatTypeKind => AnyTypeEnum::FloatType(FloatType::new(type_)), LLVMTypeKind::LLVMLabelTypeKind => panic!("FIXME: Unsupported type: Label"), LLVMTypeKind::LLVMIntegerTypeKind => AnyTypeEnum::IntType(IntType::new(type_)), @@ -108,7 +108,7 @@ impl<'ctx> AnyTypeEnum<'ctx> { LLVMTypeKind::LLVMArrayTypeKind => AnyTypeEnum::ArrayType(ArrayType::new(type_)), LLVMTypeKind::LLVMPointerTypeKind => AnyTypeEnum::PointerType(PointerType::new(type_)), LLVMTypeKind::LLVMVectorTypeKind => AnyTypeEnum::VectorType(VectorType::new(type_)), - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] LLVMTypeKind::LLVMScalableVectorTypeKind => AnyTypeEnum::VectorType(VectorType::new(type_)), LLVMTypeKind::LLVMMetadataTypeKind => panic!("FIXME: Unsupported type: Metadata"), LLVMTypeKind::LLVMX86_MMXTypeKind => panic!("FIXME: Unsupported type: MMX"), @@ -243,14 +243,14 @@ impl<'ctx> BasicTypeEnum<'ctx> { LLVMTypeKind::LLVMX86_FP80TypeKind | LLVMTypeKind::LLVMFP128TypeKind | LLVMTypeKind::LLVMPPC_FP128TypeKind => BasicTypeEnum::FloatType(FloatType::new(type_)), - #[cfg(feature= "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] LLVMTypeKind::LLVMBFloatTypeKind => BasicTypeEnum::FloatType(FloatType::new(type_)), LLVMTypeKind::LLVMIntegerTypeKind => BasicTypeEnum::IntType(IntType::new(type_)), LLVMTypeKind::LLVMStructTypeKind => BasicTypeEnum::StructType(StructType::new(type_)), LLVMTypeKind::LLVMPointerTypeKind => BasicTypeEnum::PointerType(PointerType::new(type_)), LLVMTypeKind::LLVMArrayTypeKind => BasicTypeEnum::ArrayType(ArrayType::new(type_)), LLVMTypeKind::LLVMVectorTypeKind => BasicTypeEnum::VectorType(VectorType::new(type_)), - #[cfg(feature= "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] LLVMTypeKind::LLVMScalableVectorTypeKind => BasicTypeEnum::VectorType(VectorType::new(type_)), LLVMTypeKind::LLVMMetadataTypeKind => unreachable!("Unsupported basic type: Metadata"), LLVMTypeKind::LLVMX86_MMXTypeKind => unreachable!("Unsupported basic type: MMX"), diff --git a/src/values/instruction_value.rs b/src/values/instruction_value.rs index ea6aa1ca7accf..86244d13c2bed 100644 --- a/src/values/instruction_value.rs +++ b/src/values/instruction_value.rs @@ -271,7 +271,7 @@ impl<'ctx> InstructionValue<'ctx> { // SubTypes: Only apply to memory access and alloca instructions /// Sets alignment on a memory access instruction or alloca. pub fn set_alignment(self, alignment: u32) -> Result<(), &'static str> { - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] { if alignment == 0 { return Err("Alignment cannot be 0"); diff --git a/src/values/metadata_value.rs b/src/values/metadata_value.rs index df2bdf8ed993e..caeebeea59c31 100644 --- a/src/values/metadata_value.rs +++ b/src/values/metadata_value.rs @@ -34,7 +34,7 @@ pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 25; pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 26; #[cfg(feature = "llvm9-0")] pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 28; -#[cfg(any(feature = "llvm10-0", feature = "llvm11-0"))] +#[cfg(any(feature = "llvm10-0", feature = "llvm11-0", feature = "llvm12-0"))] pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 30; #[derive(PartialEq, Eq, Clone, Copy, Hash)] From 3b87fe52be244f72f88f3254017efb08117e0248 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 5 Jun 2021 13:24:43 +0200 Subject: [PATCH 02/15] exclude ConstantPropagation in llvm12 this pass was removed in this release --- src/passes.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/passes.rs b/src/passes.rs index 13bb0984a2f62..cf640dca21a7d 100644 --- a/src/passes.rs +++ b/src/passes.rs @@ -1,13 +1,20 @@ use llvm_sys::core::{LLVMDisposePassManager, LLVMInitializeFunctionPassManager, LLVMFinalizeFunctionPassManager, LLVMRunFunctionPassManager, LLVMRunPassManager, LLVMCreatePassManager, LLVMCreateFunctionPassManagerForModule, LLVMGetGlobalPassRegistry}; use llvm_sys::initialization::{LLVMInitializeCore, LLVMInitializeTransformUtils, LLVMInitializeScalarOpts, LLVMInitializeObjCARCOpts, LLVMInitializeVectorization, LLVMInitializeInstCombine, LLVMInitializeIPO, LLVMInitializeInstrumentation, LLVMInitializeAnalysis, LLVMInitializeIPA, LLVMInitializeCodeGen, LLVMInitializeTarget}; use llvm_sys::prelude::{LLVMPassManagerRef, LLVMPassRegistryRef}; -use llvm_sys::transforms::ipo::{LLVMAddArgumentPromotionPass, LLVMAddConstantMergePass, LLVMAddDeadArgEliminationPass, LLVMAddFunctionAttrsPass, LLVMAddFunctionInliningPass, LLVMAddAlwaysInlinerPass, LLVMAddGlobalDCEPass, LLVMAddGlobalOptimizerPass, LLVMAddIPConstantPropagationPass, LLVMAddIPSCCPPass, LLVMAddInternalizePass, LLVMAddStripDeadPrototypesPass, LLVMAddPruneEHPass, LLVMAddStripSymbolsPass}; +use llvm_sys::transforms::ipo::{LLVMAddArgumentPromotionPass, LLVMAddConstantMergePass, LLVMAddDeadArgEliminationPass, LLVMAddFunctionAttrsPass, LLVMAddFunctionInliningPass, LLVMAddAlwaysInlinerPass, LLVMAddGlobalDCEPass, LLVMAddGlobalOptimizerPass, LLVMAddIPSCCPPass, LLVMAddInternalizePass, LLVMAddStripDeadPrototypesPass, LLVMAddPruneEHPass, LLVMAddStripSymbolsPass}; use llvm_sys::transforms::pass_manager_builder::{LLVMPassManagerBuilderRef, LLVMPassManagerBuilderCreate, LLVMPassManagerBuilderDispose, LLVMPassManagerBuilderSetOptLevel, LLVMPassManagerBuilderSetSizeLevel, LLVMPassManagerBuilderSetDisableUnitAtATime, LLVMPassManagerBuilderSetDisableUnrollLoops, LLVMPassManagerBuilderSetDisableSimplifyLibCalls, LLVMPassManagerBuilderUseInlinerWithThreshold, LLVMPassManagerBuilderPopulateFunctionPassManager, LLVMPassManagerBuilderPopulateModulePassManager, LLVMPassManagerBuilderPopulateLTOPassManager}; -use llvm_sys::transforms::scalar::{LLVMAddAggressiveDCEPass, LLVMAddMemCpyOptPass, LLVMAddAlignmentFromAssumptionsPass, LLVMAddCFGSimplificationPass, LLVMAddDeadStoreEliminationPass, LLVMAddScalarizerPass, LLVMAddMergedLoadStoreMotionPass, LLVMAddGVNPass, LLVMAddIndVarSimplifyPass, LLVMAddInstructionCombiningPass, LLVMAddJumpThreadingPass, LLVMAddLICMPass, LLVMAddLoopDeletionPass, LLVMAddLoopIdiomPass, LLVMAddLoopRotatePass, LLVMAddLoopRerollPass, LLVMAddLoopUnrollPass, LLVMAddLoopUnswitchPass, LLVMAddPartiallyInlineLibCallsPass, LLVMAddSCCPPass, LLVMAddScalarReplAggregatesPass, LLVMAddScalarReplAggregatesPassSSA, LLVMAddScalarReplAggregatesPassWithThreshold, LLVMAddSimplifyLibCallsPass, LLVMAddTailCallEliminationPass, LLVMAddConstantPropagationPass, LLVMAddDemoteMemoryToRegisterPass, LLVMAddVerifierPass, LLVMAddCorrelatedValuePropagationPass, LLVMAddEarlyCSEPass, LLVMAddLowerExpectIntrinsicPass, LLVMAddTypeBasedAliasAnalysisPass, LLVMAddScopedNoAliasAAPass, LLVMAddBasicAliasAnalysisPass, LLVMAddReassociatePass}; +use llvm_sys::transforms::scalar::{LLVMAddAggressiveDCEPass, LLVMAddMemCpyOptPass, LLVMAddAlignmentFromAssumptionsPass, LLVMAddCFGSimplificationPass, LLVMAddDeadStoreEliminationPass, LLVMAddScalarizerPass, LLVMAddMergedLoadStoreMotionPass, LLVMAddGVNPass, LLVMAddIndVarSimplifyPass, LLVMAddInstructionCombiningPass, LLVMAddJumpThreadingPass, LLVMAddLICMPass, LLVMAddLoopDeletionPass, LLVMAddLoopIdiomPass, LLVMAddLoopRotatePass, LLVMAddLoopRerollPass, LLVMAddLoopUnrollPass, LLVMAddLoopUnswitchPass, LLVMAddPartiallyInlineLibCallsPass, LLVMAddSCCPPass, LLVMAddScalarReplAggregatesPass, LLVMAddScalarReplAggregatesPassSSA, LLVMAddScalarReplAggregatesPassWithThreshold, LLVMAddSimplifyLibCallsPass, LLVMAddTailCallEliminationPass, LLVMAddDemoteMemoryToRegisterPass, LLVMAddVerifierPass, LLVMAddCorrelatedValuePropagationPass, LLVMAddEarlyCSEPass, LLVMAddLowerExpectIntrinsicPass, LLVMAddTypeBasedAliasAnalysisPass, LLVMAddScopedNoAliasAAPass, LLVMAddBasicAliasAnalysisPass, LLVMAddReassociatePass}; #[llvm_versions(3.7..=latest)] use llvm_sys::transforms::scalar::LLVMAddBitTrackingDCEPass; use llvm_sys::transforms::vectorize::{LLVMAddLoopVectorizePass, LLVMAddSLPVectorizePass}; +// LLVM12 removes the ConstantPropagation pass +// Users should use the InstSimplify pass instead. +#[llvm_versions(3.6..=11.0)] +use llvm_sys::transforms::ipo::LLVMAddIPConstantPropagationPass; +#[llvm_versions(3.6..=11.0)] +use llvm_sys::transforms::scalar::LLVMAddConstantPropagationPass; + use crate::OptimizationLevel; use crate::module::Module; #[llvm_versions(3.6..=3.8)] @@ -362,6 +369,7 @@ impl PassManager { /// makes arguments dead, but does not remove them. The existing /// dead argument elimination pass should be run after this to /// clean up the mess. + #[llvm_versions(3.6..=11.0)] pub fn add_ip_constant_propagation_pass(&self) { unsafe { LLVMAddIPConstantPropagationPass(self.pass_manager) @@ -920,6 +928,7 @@ impl PassManager { /// /// NOTE: this pass has a habit of making definitions be dead. It is a good idea to /// run a Dead Instruction Elimination pass sometime after running this pass. + #[llvm_versions(3.6..=11.0)] pub fn add_constant_propagation_pass(&self) { unsafe { LLVMAddConstantPropagationPass(self.pass_manager) From f53f40629163395afa9b41f22ba4c4028e12079a Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 5 Jun 2021 13:28:56 +0200 Subject: [PATCH 03/15] match on LLVMX86_AMXTypeKind; not supported, panics immediately --- src/types/enums.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/types/enums.rs b/src/types/enums.rs index b7bc27ba019f9..40a8b2abcf7fb 100644 --- a/src/types/enums.rs +++ b/src/types/enums.rs @@ -112,6 +112,8 @@ impl<'ctx> AnyTypeEnum<'ctx> { LLVMTypeKind::LLVMScalableVectorTypeKind => AnyTypeEnum::VectorType(VectorType::new(type_)), LLVMTypeKind::LLVMMetadataTypeKind => panic!("FIXME: Unsupported type: Metadata"), LLVMTypeKind::LLVMX86_MMXTypeKind => panic!("FIXME: Unsupported type: MMX"), + #[cfg(feature = "llvm12-0")] + LLVMTypeKind::LLVMX86_AMXTypeKind => panic!("FIXME: Unsupported type: AMX"), #[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))] LLVMTypeKind::LLVMTokenTypeKind => panic!("FIXME: Unsupported type: Token"), } @@ -254,6 +256,8 @@ impl<'ctx> BasicTypeEnum<'ctx> { LLVMTypeKind::LLVMScalableVectorTypeKind => BasicTypeEnum::VectorType(VectorType::new(type_)), LLVMTypeKind::LLVMMetadataTypeKind => unreachable!("Unsupported basic type: Metadata"), LLVMTypeKind::LLVMX86_MMXTypeKind => unreachable!("Unsupported basic type: MMX"), + #[cfg(feature = "llvm12-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"), From 811ed8fa3211f3c63e7842db81534c07df4bb8da Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 5 Jun 2021 13:35:04 +0200 Subject: [PATCH 04/15] disable test for constant_propagation_pass in llvm12 --- tests/all/test_passes.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/all/test_passes.rs b/tests/all/test_passes.rs index 15cc43bc17f0c..df4a7491e48d4 100644 --- a/tests/all/test_passes.rs +++ b/tests/all/test_passes.rs @@ -18,7 +18,6 @@ fn test_init_all_passes_for_module() { pass_manager.add_always_inliner_pass(); pass_manager.add_global_dce_pass(); pass_manager.add_global_optimizer_pass(); - pass_manager.add_ip_constant_propagation_pass(); pass_manager.add_prune_eh_pass(); pass_manager.add_ipsccp_pass(); pass_manager.add_internalize_pass(true); @@ -58,7 +57,6 @@ fn test_init_all_passes_for_module() { pass_manager.add_scalar_repl_aggregates_pass_with_threshold(1); pass_manager.add_simplify_lib_calls_pass(); pass_manager.add_tail_call_elimination_pass(); - pass_manager.add_constant_propagation_pass(); pass_manager.add_demote_memory_to_register_pass(); pass_manager.add_verifier_pass(); pass_manager.add_correlated_value_propagation_pass(); @@ -90,6 +88,12 @@ fn test_init_all_passes_for_module() { pass_manager.add_coroutine_cleanup_pass(); } + #[cfg(not(any(feature = "llvm12-0")))] + { + pass_manager.add_constant_propagation_pass(); + pass_manager.add_ip_constant_propagation_pass(); + } + pass_manager.run_on(&module); } From 549e4dd789289e20ba0b350a0d9d89c002bf615c Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 5 Jun 2021 13:42:50 +0200 Subject: [PATCH 05/15] llvm 12 compat in debug_info tests --- tests/all/test_debug_info.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/all/test_debug_info.rs b/tests/all/test_debug_info.rs index 116b6cc7eff72..042871eb2e573 100644 --- a/tests/all/test_debug_info.rs +++ b/tests/all/test_debug_info.rs @@ -30,9 +30,9 @@ fn test_smoke() { 0, false, false, - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] "", - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] "", ); @@ -108,9 +108,9 @@ fn test_struct_with_placeholders() { 0, false, false, - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] "", - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] "", ); @@ -225,9 +225,9 @@ fn test_no_explicit_finalize() { 0, false, false, - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] "", - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] "", ); @@ -256,9 +256,9 @@ fn test_replacing_placeholder_with_placeholder() { 0, false, false, - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] "", - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] "", ); @@ -303,9 +303,9 @@ fn test_anonymous_basic_type() { 0, false, false, - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] "", - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] "", ); @@ -341,9 +341,9 @@ fn test_global_expressions() { 0, false, false, - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] "", - #[cfg(feature = "llvm11-0")] + #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] "", ); From 5a8c4e584d0de4a2f63e7d42649e84e25eeafc01 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 5 Jun 2021 13:43:03 +0200 Subject: [PATCH 06/15] fix pass manager test --- tests/all/test_passes.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/all/test_passes.rs b/tests/all/test_passes.rs index df4a7491e48d4..f53674c25e822 100644 --- a/tests/all/test_passes.rs +++ b/tests/all/test_passes.rs @@ -18,6 +18,8 @@ fn test_init_all_passes_for_module() { pass_manager.add_always_inliner_pass(); pass_manager.add_global_dce_pass(); pass_manager.add_global_optimizer_pass(); + #[cfg(not(feature = "llvm12-0"))] + pass_manager.add_ip_constant_propagation_pass(); pass_manager.add_prune_eh_pass(); pass_manager.add_ipsccp_pass(); pass_manager.add_internalize_pass(true); @@ -57,6 +59,8 @@ fn test_init_all_passes_for_module() { pass_manager.add_scalar_repl_aggregates_pass_with_threshold(1); pass_manager.add_simplify_lib_calls_pass(); pass_manager.add_tail_call_elimination_pass(); + #[cfg(not(feature = "llvm12-0"))] + pass_manager.add_constant_propagation_pass(); pass_manager.add_demote_memory_to_register_pass(); pass_manager.add_verifier_pass(); pass_manager.add_correlated_value_propagation_pass(); @@ -88,12 +92,6 @@ fn test_init_all_passes_for_module() { pass_manager.add_coroutine_cleanup_pass(); } - #[cfg(not(any(feature = "llvm12-0")))] - { - pass_manager.add_constant_propagation_pass(); - pass_manager.add_ip_constant_propagation_pass(); - } - pass_manager.run_on(&module); } @@ -143,9 +141,9 @@ fn test_pass_manager_builder() { let module2 = module.clone(); // TODOC: In 3.6, 3.8, & 3.9 it returns false. Seems like a LLVM bug? - #[cfg(not(any(feature = "llvm3-7", feature = "llvm6-0", feature = "llvm7-0", feature = "llvm8-0", feature = "llvm9-0", feature = "llvm10-0", feature = "llvm11-0")))] + #[cfg(not(any(feature = "llvm3-7", feature = "llvm6-0", feature = "llvm7-0", feature = "llvm8-0", feature = "llvm9-0", feature = "llvm10-0", feature = "llvm11-0", feature = "llvm12-0")))] assert!(!module_pass_manager.run_on(&module)); - #[cfg(any(feature = "llvm3-7", feature = "llvm6-0", feature = "llvm7-0", feature = "llvm8-0", feature = "llvm9-0", feature = "llvm10-0", feature = "llvm11-0"))] + #[cfg(any(feature = "llvm3-7", feature = "llvm6-0", feature = "llvm7-0", feature = "llvm8-0", feature = "llvm9-0", feature = "llvm10-0", feature = "llvm11-0", feature = "llvm12-0"))] assert!(module_pass_manager.run_on(&module)); let lto_pass_manager = PassManager::create(()); From 29a1d72f1b806917d0b29242c006ad8ebb9a103a Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 5 Jun 2021 13:45:22 +0200 Subject: [PATCH 07/15] bump number of metadata items --- src/values/metadata_value.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/values/metadata_value.rs b/src/values/metadata_value.rs index caeebeea59c31..c9f25f08407dd 100644 --- a/src/values/metadata_value.rs +++ b/src/values/metadata_value.rs @@ -34,8 +34,10 @@ pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 25; pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 26; #[cfg(feature = "llvm9-0")] pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 28; -#[cfg(any(feature = "llvm10-0", feature = "llvm11-0", feature = "llvm12-0"))] +#[cfg(any(feature = "llvm10-0", feature = "llvm11-0"))] pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 30; +#[cfg(feature = "llvm12-0")] +pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 31; #[derive(PartialEq, Eq, Clone, Copy, Hash)] pub struct MetadataValue<'ctx> { From 7f5905f4b9a41ab47788a9c3b991cf84c6817935 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 5 Jun 2021 13:46:12 +0200 Subject: [PATCH 08/15] fix value tests by including llvm12 --- tests/all/test_values.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/all/test_values.rs b/tests/all/test_values.rs index 428ed1df5d6c5..6c9e68abbd2e3 100644 --- a/tests/all/test_values.rs +++ b/tests/all/test_values.rs @@ -320,10 +320,10 @@ fn test_verify_fn() { let function = module.add_function("fn", fn_type, None); - #[cfg(not(any(feature = "llvm3-9", feature = "llvm4-0", feature = "llvm5-0", feature = "llvm6-0", feature = "llvm7-0", feature = "llvm8-0", feature = "llvm9-0", feature = "llvm10-0", feature = "llvm11-0")))] + #[cfg(not(any(feature = "llvm3-9", 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")))] assert!(!function.verify(false)); // REVIEW: Why does 3.9 -> 8.0 return true here? LLVM bug? Bugfix? - #[cfg(any(feature = "llvm3-9", feature = "llvm4-0", feature = "llvm5-0", feature = "llvm6-0", feature = "llvm7-0", feature = "llvm8-0", feature = "llvm9-0", feature = "llvm10-0", feature = "llvm11-0"))] + #[cfg(any(feature = "llvm3-9", 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"))] assert!(function.verify(false)); let basic_block = context.append_basic_block(function, "entry"); @@ -730,7 +730,7 @@ fn test_globals() { assert!(!global.is_externally_initialized()); assert_eq!(global.get_name().to_str(), Ok("my_global")); // REVIEW: Segfaults in 4.0 -> 11.0 - #[cfg(not(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")))] + #[cfg(not(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")))] assert_eq!(global.get_section().to_str(), Ok("")); assert_eq!(global.get_dll_storage_class(), DLLStorageClass::default()); assert_eq!(global.get_visibility(), GlobalVisibility::default()); From 3843d8cac9aded8c1839d8d69624f4de612093a4 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 5 Jun 2021 13:56:12 +0200 Subject: [PATCH 09/15] expose new LLVMAddInstructionSimplifyPass --- src/passes.rs | 35 +++++++++++++++++++++++++++++++++++ tests/all/test_passes.rs | 2 ++ 2 files changed, 37 insertions(+) diff --git a/src/passes.rs b/src/passes.rs index cf640dca21a7d..127487b873ac8 100644 --- a/src/passes.rs +++ b/src/passes.rs @@ -15,6 +15,9 @@ use llvm_sys::transforms::ipo::LLVMAddIPConstantPropagationPass; #[llvm_versions(3.6..=11.0)] use llvm_sys::transforms::scalar::LLVMAddConstantPropagationPass; +#[llvm_versions(12.0..=latest)] +use llvm_sys::transforms::scalar::LLVMAddInstructionSimplifyPass; + use crate::OptimizationLevel; use crate::module::Module; #[llvm_versions(3.6..=3.8)] @@ -369,7 +372,11 @@ impl PassManager { /// makes arguments dead, but does not remove them. The existing /// dead argument elimination pass should be run after this to /// clean up the mess. + /// + /// In LLVM 12 and later, this instruction is replaced by the + /// [`add_instruction_simplify_pass`]. #[llvm_versions(3.6..=11.0)] + #[doc(alias = "add_instruction_simplify_pass")] pub fn add_ip_constant_propagation_pass(&self) { unsafe { LLVMAddIPConstantPropagationPass(self.pass_manager) @@ -928,13 +935,41 @@ impl PassManager { /// /// NOTE: this pass has a habit of making definitions be dead. It is a good idea to /// run a Dead Instruction Elimination pass sometime after running this pass. + /// + /// In LLVM 12 and later, this instruction is replaced by the + /// [`add_instruction_simplify_pass`]. #[llvm_versions(3.6..=11.0)] + #[doc(alias = "add_instruction_simplify_pass")] pub fn add_constant_propagation_pass(&self) { unsafe { LLVMAddConstantPropagationPass(self.pass_manager) } } + /// This pass implements constant propagation and merging. It looks for instructions + /// involving only constant operands and replaces them with a constant value instead + /// of an instruction. For example: + /// + /// ```ir + /// add i32 1, 2 + /// ``` + /// + /// becomes + /// + /// ```ir + /// i32 3 + /// ``` + /// + /// NOTE: this pass has a habit of making definitions be dead. It is a good idea to + /// run a Dead Instruction Elimination pass sometime after running this pass. + #[llvm_versions(12.0..=latest)] + #[doc(alias = "add_constant_propagation_pass")] + pub fn add_instruction_simplify_pass(&self) { + unsafe { + LLVMAddInstructionSimplifyPass(self.pass_manager) + } + } + /// This file promotes memory references to be register references. /// It promotes alloca instructions which only have loads and stores /// as uses. An alloca is transformed by using dominator frontiers to diff --git a/tests/all/test_passes.rs b/tests/all/test_passes.rs index f53674c25e822..771fd4aa2c8eb 100644 --- a/tests/all/test_passes.rs +++ b/tests/all/test_passes.rs @@ -61,6 +61,8 @@ fn test_init_all_passes_for_module() { pass_manager.add_tail_call_elimination_pass(); #[cfg(not(feature = "llvm12-0"))] pass_manager.add_constant_propagation_pass(); + #[cfg(feature = "llvm12-0")] + pass_manager.add_instruction_simplify_pass(); pass_manager.add_demote_memory_to_register_pass(); pass_manager.add_verifier_pass(); pass_manager.add_correlated_value_propagation_pass(); From e1a98f1d9b34d647b0eaeef38b5d123f9f12eecd Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 5 Jun 2021 19:24:46 +0200 Subject: [PATCH 10/15] remove doc alias --- src/passes.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/passes.rs b/src/passes.rs index 127487b873ac8..4f9dad3049852 100644 --- a/src/passes.rs +++ b/src/passes.rs @@ -376,7 +376,6 @@ impl PassManager { /// In LLVM 12 and later, this instruction is replaced by the /// [`add_instruction_simplify_pass`]. #[llvm_versions(3.6..=11.0)] - #[doc(alias = "add_instruction_simplify_pass")] pub fn add_ip_constant_propagation_pass(&self) { unsafe { LLVMAddIPConstantPropagationPass(self.pass_manager) @@ -939,7 +938,6 @@ impl PassManager { /// In LLVM 12 and later, this instruction is replaced by the /// [`add_instruction_simplify_pass`]. #[llvm_versions(3.6..=11.0)] - #[doc(alias = "add_instruction_simplify_pass")] pub fn add_constant_propagation_pass(&self) { unsafe { LLVMAddConstantPropagationPass(self.pass_manager) @@ -963,7 +961,6 @@ impl PassManager { /// NOTE: this pass has a habit of making definitions be dead. It is a good idea to /// run a Dead Instruction Elimination pass sometime after running this pass. #[llvm_versions(12.0..=latest)] - #[doc(alias = "add_constant_propagation_pass")] pub fn add_instruction_simplify_pass(&self) { unsafe { LLVMAddInstructionSimplifyPass(self.pass_manager) From 5d94b0d337037a0725d7bd0cf486a403cea8a04b Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 5 Jun 2021 19:25:53 +0200 Subject: [PATCH 11/15] add mmx/amx link --- src/types/enums.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/types/enums.rs b/src/types/enums.rs index 40a8b2abcf7fb..bb75365e08acb 100644 --- a/src/types/enums.rs +++ b/src/types/enums.rs @@ -255,7 +255,9 @@ impl<'ctx> BasicTypeEnum<'ctx> { #[cfg(any(feature = "llvm11-0", feature = "llvm12-0"))] LLVMTypeKind::LLVMScalableVectorTypeKind => BasicTypeEnum::VectorType(VectorType::new(type_)), LLVMTypeKind::LLVMMetadataTypeKind => unreachable!("Unsupported basic type: Metadata"), + // see https://llvm.org/docs/LangRef.html#x86-mmx-type LLVMTypeKind::LLVMX86_MMXTypeKind => unreachable!("Unsupported basic type: MMX"), + // see https://llvm.org/docs/LangRef.html#x86-amx-type #[cfg(feature = "llvm12-0")] LLVMTypeKind::LLVMX86_AMXTypeKind => unreachable!("Unsupported basic type: AMX"), LLVMTypeKind::LLVMLabelTypeKind => unreachable!("Unsupported basic type: Label"), From 9ef040e0f9365a25ee8351740fcc8d47985f002e Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 5 Jun 2021 19:29:41 +0200 Subject: [PATCH 12/15] update travis.ci to include llvm12 --- .travis.yml | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index a966f57314e2e..c519bab875063 100644 --- a/.travis.yml +++ b/.travis.yml @@ -197,6 +197,22 @@ matrix: - libclang-common-11-dev rust: 1.45.2 dist: bionic + - env: + - LLVM_VERSION="12.0" + <<: *BASE + addons: + apt: + sources: + - *BASE_SOURCES + - llvm-toolchain-bionic-12 + - sourceline: 'deb https://apt.llvm.org/bionic/ llvm-toolchain-bionic-12 main' + key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' + packages: + - *BASE_PACKAGES + - llvm-12-dev + - libclang-common-12-dev + rust: 1.45.2 + dist: bionic - deploy: # Documentation build; Only latest supported LLVM version for now provider: pages skip-cleanup: true @@ -206,10 +222,10 @@ matrix: on: branch: master before_install: - - export PATH=/usr/lib/llvm-11/bin/:$HOME/.local/bin:$PATH - - export LLVM_PATH=/usr/share/llvm-11/cmake/ + - export PATH=/usr/lib/llvm-12/bin/:$HOME/.local/bin:$PATH + - export LLVM_PATH=/usr/share/llvm-12/cmake/ script: - - cargo doc --no-default-features --features "target-all,llvm11-0,nightly" --color=always + - cargo doc --no-default-features --features "target-all,llvm12-0,nightly" --color=always - echo '' > target/doc/index.html rust: nightly name: "GitHub IO Documentation Deployment" @@ -228,8 +244,9 @@ matrix: # - llvm-toolchain-trusty-8 # - llvm-toolchain-bionic-9 # llvm-toolchain-bionic-10 - - llvm-toolchain-bionic-11 - - sourceline: 'deb https://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main' + # llvm-toolchain-bionic-11 + - llvm-toolchain-bionic-12 + - sourceline: 'deb https://apt.llvm.org/bionic/ llvm-toolchain-bionic-12 main' key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' packages: - *BASE_PACKAGES @@ -243,8 +260,9 @@ matrix: # - llvm-7-dev # - llvm-8-dev # - llvm-9-dev - # llvm-10-dev - - llvm-11-dev + # - llvm-10-dev + # - llvm-11-dev + - llvm-12-dev dist: bionic env: From c0845edaa8803f63d0387fafda9450ec20ffbf37 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 6 Jun 2021 00:15:51 +0200 Subject: [PATCH 13/15] try focal for doc building --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c519bab875063..b45ed7e0d0593 100644 --- a/.travis.yml +++ b/.travis.yml @@ -245,8 +245,8 @@ matrix: # - llvm-toolchain-bionic-9 # llvm-toolchain-bionic-10 # llvm-toolchain-bionic-11 - - llvm-toolchain-bionic-12 - - sourceline: 'deb https://apt.llvm.org/bionic/ llvm-toolchain-bionic-12 main' + - llvm-toolchain-focal-12 + - sourceline: 'deb https://apt.llvm.org/bionic/ llvm-toolchain-focal-12 main' key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' packages: - *BASE_PACKAGES @@ -263,7 +263,7 @@ matrix: # - llvm-10-dev # - llvm-11-dev - llvm-12-dev - dist: bionic + dist: focal env: global: From 16cf7673ed7d5923d4478b687b2df4eedf768e71 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 6 Jun 2021 00:55:53 +0200 Subject: [PATCH 14/15] make docs more like the llvm12 build --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index b45ed7e0d0593..ffab2e1cb23f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -245,8 +245,8 @@ matrix: # - llvm-toolchain-bionic-9 # llvm-toolchain-bionic-10 # llvm-toolchain-bionic-11 - - llvm-toolchain-focal-12 - - sourceline: 'deb https://apt.llvm.org/bionic/ llvm-toolchain-focal-12 main' + - llvm-toolchain-bionic-12 + - sourceline: 'deb https://apt.llvm.org/bionic/ llvm-toolchain-bionic-12 main' key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' packages: - *BASE_PACKAGES @@ -263,7 +263,8 @@ matrix: # - llvm-10-dev # - llvm-11-dev - llvm-12-dev - dist: focal + - libclang-common-12-dev + dist: bionic env: global: From 1f9ad7709e6e81d6cb7605e89bf1c61c9297326f Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 6 Jun 2021 10:01:36 +0200 Subject: [PATCH 15/15] update req and usage sections --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1776af6b9fbea..95d5e01e5f3b0 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Inkwell aims to help you pen your own programming languages by safely wrapping l * Rust 1.42+ * Rust Stable, Beta, or Nightly -* LLVM 3.6, 3.7, 3.8, 3.9, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, or 11.0 +* LLVM 3.6, 3.7, 3.8, 3.9, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0 or 12.0 ## Usage @@ -24,7 +24,7 @@ branch with a corresponding LLVM feature flag: ```toml [dependencies] -inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", features = ["llvm11-0"] } +inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", features = ["llvm12-0"] } ``` Supported versions: @@ -43,6 +43,7 @@ Supported versions: | 9.0.x | llvm9-0 | | 10.0.x | llvm10-0 | | 11.0.x | llvm11-0 | +| 12.0.x | llvm12-0 | Please be aware that we may make breaking changes on master from time to time since we are pre-v1.0.0, in compliance with semver. Please prefer a crates.io release whenever possible!