summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_codegen_ssa/src/traits
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/traits')
-rw-r--r--compiler/rustc_codegen_ssa/src/traits/backend.rs4
-rw-r--r--compiler/rustc_codegen_ssa/src/traits/consts.rs13
-rw-r--r--compiler/rustc_codegen_ssa/src/traits/coverageinfo.rs58
-rw-r--r--compiler/rustc_codegen_ssa/src/traits/mod.rs4
-rw-r--r--compiler/rustc_codegen_ssa/src/traits/type_.rs22
5 files changed, 35 insertions, 66 deletions
diff --git a/compiler/rustc_codegen_ssa/src/traits/backend.rs b/compiler/rustc_codegen_ssa/src/traits/backend.rs
index d83bfc740..b3c9ecf8b 100644
--- a/compiler/rustc_codegen_ssa/src/traits/backend.rs
+++ b/compiler/rustc_codegen_ssa/src/traits/backend.rs
@@ -6,7 +6,7 @@ use crate::back::write::TargetMachineFactoryFn;
use crate::{CodegenResults, ModuleCodegen};
use rustc_ast::expand::allocator::AllocatorKind;
-use rustc_data_structures::fx::FxHashMap;
+use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sync::{DynSend, DynSync};
use rustc_errors::ErrorGuaranteed;
use rustc_metadata::EncodedMetadata;
@@ -101,7 +101,7 @@ pub trait CodegenBackend {
ongoing_codegen: Box<dyn Any>,
sess: &Session,
outputs: &OutputFilenames,
- ) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorGuaranteed>;
+ ) -> Result<(CodegenResults, FxIndexMap<WorkProductId, WorkProduct>), ErrorGuaranteed>;
/// This is called on the returned `Box<dyn Any>` from `join_codegen`
///
diff --git a/compiler/rustc_codegen_ssa/src/traits/consts.rs b/compiler/rustc_codegen_ssa/src/traits/consts.rs
index 619063027..d6e9bfce1 100644
--- a/compiler/rustc_codegen_ssa/src/traits/consts.rs
+++ b/compiler/rustc_codegen_ssa/src/traits/consts.rs
@@ -1,8 +1,6 @@
use super::BackendTypes;
-use crate::mir::place::PlaceRef;
use rustc_middle::mir::interpret::{ConstAllocation, Scalar};
-use rustc_middle::ty::layout::TyAndLayout;
-use rustc_target::abi::{self, Size};
+use rustc_target::abi;
pub trait ConstMethods<'tcx>: BackendTypes {
// Constant constructors
@@ -17,6 +15,7 @@ pub trait ConstMethods<'tcx>: BackendTypes {
fn const_i32(&self, i: i32) -> Self::Value;
fn const_u32(&self, i: u32) -> Self::Value;
fn const_u64(&self, i: u64) -> Self::Value;
+ fn const_u128(&self, i: u128) -> Self::Value;
fn const_usize(&self, i: u64) -> Self::Value;
fn const_u8(&self, i: u8) -> Self::Value;
fn const_real(&self, t: Self::Type, val: f64) -> Self::Value;
@@ -30,12 +29,8 @@ pub trait ConstMethods<'tcx>: BackendTypes {
fn const_data_from_alloc(&self, alloc: ConstAllocation<'tcx>) -> Self::Value;
fn scalar_to_backend(&self, cv: Scalar, layout: abi::Scalar, llty: Self::Type) -> Self::Value;
- fn from_const_alloc(
- &self,
- layout: TyAndLayout<'tcx>,
- alloc: ConstAllocation<'tcx>,
- offset: Size,
- ) -> PlaceRef<'tcx, Self::Value>;
fn const_ptrcast(&self, val: Self::Value, ty: Self::Type) -> Self::Value;
+ fn const_bitcast(&self, val: Self::Value, ty: Self::Type) -> Self::Value;
+ fn const_ptr_byte_offset(&self, val: Self::Value, offset: abi::Size) -> Self::Value;
}
diff --git a/compiler/rustc_codegen_ssa/src/traits/coverageinfo.rs b/compiler/rustc_codegen_ssa/src/traits/coverageinfo.rs
index e77201cf0..7e8de0ddc 100644
--- a/compiler/rustc_codegen_ssa/src/traits/coverageinfo.rs
+++ b/compiler/rustc_codegen_ssa/src/traits/coverageinfo.rs
@@ -1,57 +1,11 @@
use super::BackendTypes;
-use rustc_hir::def_id::DefId;
-use rustc_middle::mir::coverage::*;
+use rustc_middle::mir::Coverage;
use rustc_middle::ty::Instance;
-pub trait CoverageInfoMethods<'tcx>: BackendTypes {
- fn coverageinfo_finalize(&self);
-
- /// Codegen a small function that will never be called, with one counter
- /// that will never be incremented, that gives LLVM coverage tools a
- /// function definition it needs in order to resolve coverage map references
- /// to unused functions. This is necessary so unused functions will appear
- /// as uncovered (coverage execution count `0`) in LLVM coverage reports.
- fn define_unused_fn(&self, def_id: DefId);
-
- /// For LLVM codegen, returns a function-specific `Value` for a global
- /// string, to hold the function name passed to LLVM intrinsic
- /// `instrprof.increment()`. The `Value` is only created once per instance.
- /// Multiple invocations with the same instance return the same `Value`.
- fn get_pgo_func_name_var(&self, instance: Instance<'tcx>) -> Self::Value;
-}
-
pub trait CoverageInfoBuilderMethods<'tcx>: BackendTypes {
- /// Returns true if the function source hash was added to the coverage map (even if it had
- /// already been added, for this instance). Returns false *only* if `-C instrument-coverage` is
- /// not enabled (a coverage map is not being generated).
- fn set_function_source_hash(
- &mut self,
- instance: Instance<'tcx>,
- function_source_hash: u64,
- ) -> bool;
-
- /// Returns true if the counter was added to the coverage map; false if `-C instrument-coverage`
- /// is not enabled (a coverage map is not being generated).
- fn add_coverage_counter(
- &mut self,
- instance: Instance<'tcx>,
- index: CounterValueReference,
- region: CodeRegion,
- ) -> bool;
-
- /// Returns true if the expression was added to the coverage map; false if
- /// `-C instrument-coverage` is not enabled (a coverage map is not being generated).
- fn add_coverage_counter_expression(
- &mut self,
- instance: Instance<'tcx>,
- id: InjectedExpressionId,
- lhs: ExpressionOperandId,
- op: Op,
- rhs: ExpressionOperandId,
- region: Option<CodeRegion>,
- ) -> bool;
-
- /// Returns true if the region was added to the coverage map; false if `-C instrument-coverage`
- /// is not enabled (a coverage map is not being generated).
- fn add_coverage_unreachable(&mut self, instance: Instance<'tcx>, region: CodeRegion) -> bool;
+ /// Handle the MIR coverage info in a backend-specific way.
+ ///
+ /// This can potentially be a no-op in backends that don't support
+ /// coverage instrumentation.
+ fn add_coverage(&mut self, instance: Instance<'tcx>, coverage: &Coverage);
}
diff --git a/compiler/rustc_codegen_ssa/src/traits/mod.rs b/compiler/rustc_codegen_ssa/src/traits/mod.rs
index 782fdadbf..8cb58bd4c 100644
--- a/compiler/rustc_codegen_ssa/src/traits/mod.rs
+++ b/compiler/rustc_codegen_ssa/src/traits/mod.rs
@@ -33,7 +33,7 @@ pub use self::asm::{AsmBuilderMethods, AsmMethods, GlobalAsmOperandRef, InlineAs
pub use self::backend::{Backend, BackendTypes, CodegenBackend, ExtraBackendMethods};
pub use self::builder::{BuilderMethods, OverflowOp};
pub use self::consts::ConstMethods;
-pub use self::coverageinfo::{CoverageInfoBuilderMethods, CoverageInfoMethods};
+pub use self::coverageinfo::CoverageInfoBuilderMethods;
pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoMethods};
pub use self::declare::PreDefineMethods;
pub use self::intrinsic::IntrinsicCallMethods;
@@ -59,7 +59,6 @@ pub trait CodegenMethods<'tcx>:
+ MiscMethods<'tcx>
+ ConstMethods<'tcx>
+ StaticMethods
- + CoverageInfoMethods<'tcx>
+ DebugInfoMethods<'tcx>
+ AsmMethods<'tcx>
+ PreDefineMethods<'tcx>
@@ -75,7 +74,6 @@ impl<'tcx, T> CodegenMethods<'tcx> for T where
+ MiscMethods<'tcx>
+ ConstMethods<'tcx>
+ StaticMethods
- + CoverageInfoMethods<'tcx>
+ DebugInfoMethods<'tcx>
+ AsmMethods<'tcx>
+ PreDefineMethods<'tcx>
diff --git a/compiler/rustc_codegen_ssa/src/traits/type_.rs b/compiler/rustc_codegen_ssa/src/traits/type_.rs
index 36d986422..e64417e1a 100644
--- a/compiler/rustc_codegen_ssa/src/traits/type_.rs
+++ b/compiler/rustc_codegen_ssa/src/traits/type_.rs
@@ -126,6 +126,28 @@ pub trait LayoutTypeMethods<'tcx>: Backend<'tcx> {
index: usize,
immediate: bool,
) -> Self::Type;
+
+ /// A type that can be used in a [`super::BuilderMethods::load`] +
+ /// [`super::BuilderMethods::store`] pair to implement a *typed* copy,
+ /// such as a MIR `*_0 = *_1`.
+ ///
+ /// It's always legal to return `None` here, as the provided impl does,
+ /// in which case callers should use [`super::BuilderMethods::memcpy`]
+ /// instead of the `load`+`store` pair.
+ ///
+ /// This can be helpful for things like arrays, where the LLVM backend type
+ /// `[3 x i16]` optimizes to three separate loads and stores, but it can
+ /// instead be copied via an `i48` that stays as the single `load`+`store`.
+ /// (As of 2023-05 LLVM cannot necessarily optimize away a `memcpy` in these
+ /// cases, due to `poison` handling, but in codegen we have more information
+ /// about the type invariants, so can emit something better instead.)
+ ///
+ /// This *should* return `None` for particularly-large types, where leaving
+ /// the `memcpy` may well be important to avoid code size explosion.
+ fn scalar_copy_backend_type(&self, layout: TyAndLayout<'tcx>) -> Option<Self::Type> {
+ let _ = layout;
+ None
+ }
}
// For backends that support CFI using type membership (i.e., testing whether a given pointer is