Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 31 additions & 21 deletions compiler/rustc_codegen_llvm/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ use crate::llvm::{self, Attribute, AttributePlace, Type, Value};
use crate::type_of::LayoutLlvmExt;

trait ArgAttributesExt {
fn apply_attrs_to_llfn(&self, idx: AttributePlace, cx: &CodegenCx<'_, '_>, llfn: &Value);
fn apply_attrs_to_callsite(
fn apply_attrs_to_llfn<'ll>(
&self,
idx: AttributePlace,
cx: &CodegenCx<'_, '_>,
callsite: &Value,
cx: &CodegenCx<'ll, '_>,
llfn: Value<'ll>,
);
fn apply_attrs_to_callsite<'ll>(
&self,
idx: AttributePlace,
cx: &CodegenCx<'ll, '_>,
callsite: Value<'ll>,
);
}

Expand Down Expand Up @@ -116,16 +121,21 @@ fn get_attrs<'ll>(this: &ArgAttributes, cx: &CodegenCx<'ll, '_>) -> SmallVec<[&'
}

impl ArgAttributesExt for ArgAttributes {
fn apply_attrs_to_llfn(&self, idx: AttributePlace, cx: &CodegenCx<'_, '_>, llfn: &Value) {
fn apply_attrs_to_llfn<'ll>(
&self,
idx: AttributePlace,
cx: &CodegenCx<'ll, '_>,
llfn: Value<'ll>,
) {
let attrs = get_attrs(self, cx);
attributes::apply_to_llfn(llfn, idx, &attrs);
}

fn apply_attrs_to_callsite(
fn apply_attrs_to_callsite<'ll>(
&self,
idx: AttributePlace,
cx: &CodegenCx<'_, '_>,
callsite: &Value,
cx: &CodegenCx<'ll, '_>,
callsite: Value<'ll>,
) {
let attrs = get_attrs(self, cx);
attributes::apply_to_callsite(callsite, idx, &attrs);
Expand Down Expand Up @@ -236,14 +246,14 @@ trait ArgAbiExt<'ll, 'tcx> {
fn store(
&self,
bx: &mut Builder<'_, 'll, 'tcx>,
val: &'ll Value,
dst: PlaceRef<'tcx, &'ll Value>,
val: Value<'ll>,
dst: PlaceRef<'tcx, Value<'ll>>,
);
fn store_fn_arg(
&self,
bx: &mut Builder<'_, 'll, 'tcx>,
idx: &mut usize,
dst: PlaceRef<'tcx, &'ll Value>,
dst: PlaceRef<'tcx, Value<'ll>>,
);
}

Expand All @@ -255,8 +265,8 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
fn store(
&self,
bx: &mut Builder<'_, 'll, 'tcx>,
val: &'ll Value,
dst: PlaceRef<'tcx, &'ll Value>,
val: Value<'ll>,
dst: PlaceRef<'tcx, Value<'ll>>,
) {
match &self.mode {
PassMode::Ignore => {}
Expand Down Expand Up @@ -310,7 +320,7 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
&self,
bx: &mut Builder<'_, 'll, 'tcx>,
idx: &mut usize,
dst: PlaceRef<'tcx, &'ll Value>,
dst: PlaceRef<'tcx, Value<'ll>>,
) {
let mut next = || {
let val = llvm::get_param(bx.llfn(), *idx as c_uint);
Expand Down Expand Up @@ -347,8 +357,8 @@ impl<'ll, 'tcx> ArgAbiBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
fn store_arg(
&mut self,
arg_abi: &ArgAbi<'tcx, Ty<'tcx>>,
val: &'ll Value,
dst: PlaceRef<'tcx, &'ll Value>,
val: Value<'ll>,
dst: PlaceRef<'tcx, Value<'ll>>,
) {
arg_abi.store(self, val, dst)
}
Expand All @@ -363,12 +373,12 @@ pub(crate) trait FnAbiLlvmExt<'ll, 'tcx> {
fn apply_attrs_llfn(
&self,
cx: &CodegenCx<'ll, 'tcx>,
llfn: &'ll Value,
llfn: Value<'ll>,
instance: Option<ty::Instance<'tcx>>,
);

/// Apply attributes to a function call.
fn apply_attrs_callsite(&self, bx: &mut Builder<'_, 'll, 'tcx>, callsite: &'ll Value);
fn apply_attrs_callsite(&self, bx: &mut Builder<'_, 'll, 'tcx>, callsite: Value<'ll>);
}

impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
Expand Down Expand Up @@ -470,7 +480,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
fn apply_attrs_llfn(
&self,
cx: &CodegenCx<'ll, 'tcx>,
llfn: &'ll Value,
llfn: Value<'ll>,
instance: Option<ty::Instance<'tcx>>,
) {
let mut func_attrs = SmallVec::<[_; 3]>::new();
Expand Down Expand Up @@ -648,7 +658,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
}
}

fn apply_attrs_callsite(&self, bx: &mut Builder<'_, 'll, 'tcx>, callsite: &'ll Value) {
fn apply_attrs_callsite(&self, bx: &mut Builder<'_, 'll, 'tcx>, callsite: Value<'ll>) {
let mut func_attrs = SmallVec::<[_; 2]>::new();
if self.ret.layout.is_uninhabited() {
func_attrs.push(llvm::AttributeKind::NoReturn.create_attr(bx.cx.llcx));
Expand All @@ -659,7 +669,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
attributes::apply_to_callsite(callsite, llvm::AttributePlace::Function, &{ func_attrs });

let mut i = 0;
let mut apply = |cx: &CodegenCx<'_, '_>, attrs: &ArgAttributes| {
let mut apply = |cx: &CodegenCx<'ll, '_>, attrs: &ArgAttributes| {
attrs.apply_attrs_to_callsite(llvm::AttributePlace::Argument(i), cx, callsite);
i += 1;
i - 1
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_codegen_llvm/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ pub(crate) fn inline_asm_call<'ll>(
bx: &mut Builder<'_, 'll, '_>,
asm: &str,
cons: &str,
inputs: &[&'ll Value],
inputs: &[Value<'ll>],
output: llvm::Type<'ll>,
labels: &[&'ll llvm::BasicBlock],
volatile: bool,
Expand All @@ -547,7 +547,7 @@ pub(crate) fn inline_asm_call<'ll>(
unwind: bool,
dest: Option<&'ll llvm::BasicBlock>,
catch_funclet: Option<(&'ll llvm::BasicBlock, Option<&Funclet<'ll>>)>,
) -> Option<&'ll Value> {
) -> Option<Value<'ll>> {
let argtys = inputs
.iter()
.map(|v| {
Expand Down Expand Up @@ -1170,11 +1170,11 @@ fn any_target_feature_enabled(
/// Fix up an input value to work around LLVM bugs.
fn llvm_fixup_input<'ll, 'tcx>(
bx: &mut Builder<'_, 'll, 'tcx>,
mut value: &'ll Value,
mut value: Value<'ll>,
reg: InlineAsmRegClass,
layout: &TyAndLayout<'tcx>,
instance: Instance<'_>,
) -> &'ll Value {
) -> Value<'ll> {
use InlineAsmRegClass::*;
let dl = &bx.tcx.data_layout;
match (reg, layout.backend_repr) {
Expand Down Expand Up @@ -1373,11 +1373,11 @@ fn llvm_fixup_input<'ll, 'tcx>(
/// Fix up an output value to work around LLVM bugs.
fn llvm_fixup_output<'ll, 'tcx>(
bx: &mut Builder<'_, 'll, 'tcx>,
mut value: &'ll Value,
mut value: Value<'ll>,
reg: InlineAsmRegClass,
layout: &TyAndLayout<'tcx>,
instance: Instance<'_>,
) -> &'ll Value {
) -> Value<'ll> {
use InlineAsmRegClass::*;
match (reg, layout.backend_repr) {
(AArch64(AArch64InlineAsmRegClass::vreg), BackendRepr::Scalar(s)) => {
Expand Down
14 changes: 9 additions & 5 deletions compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,27 @@ use crate::llvm::{
};
use crate::{attributes, llvm_util};

pub(crate) fn apply_to_llfn(llfn: &Value, idx: AttributePlace, attrs: &[&Attribute]) {
pub(crate) fn apply_to_llfn<'ll>(llfn: Value<'ll>, idx: AttributePlace, attrs: &[&'ll Attribute]) {
if !attrs.is_empty() {
llvm::AddFunctionAttributes(llfn, idx, attrs);
}
}

pub(crate) fn apply_to_callsite(callsite: &Value, idx: AttributePlace, attrs: &[&Attribute]) {
pub(crate) fn apply_to_callsite<'ll>(
callsite: Value<'ll>,
idx: AttributePlace,
attrs: &[&'ll Attribute],
) {
if !attrs.is_empty() {
llvm::AddCallSiteAttributes(callsite, idx, attrs);
}
}

pub(crate) fn has_string_attr(llfn: &Value, name: &str) -> bool {
pub(crate) fn has_string_attr<'ll>(llfn: Value<'ll>, name: &str) -> bool {
llvm::HasStringAttribute(llfn, name)
}

pub(crate) fn remove_string_attr_from_llfn(llfn: &Value, name: &str) {
pub(crate) fn remove_string_attr_from_llfn<'ll>(llfn: Value<'ll>, name: &str) {
llvm::RemoveStringAttrFromFn(llfn, name);
}

Expand Down Expand Up @@ -503,7 +507,7 @@ fn create_alloc_family_attr<'ll>(llcx: llvm::Context<'ll>) -> &'ll llvm::Attribu
pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
cx: &SimpleCx<'ll>,
tcx: TyCtxt<'tcx>,
llfn: &'ll Value,
llfn: Value<'ll>,
codegen_fn_attrs: &CodegenFnAttrs,
instance: Option<ty::Instance<'tcx>>,
sanitizer_ignorelist: Option<&SanitizerIgnoreList>,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,8 @@ pub(crate) unsafe fn llvm_optimize<'ll>(
// Returns the new function, or `None` if nothing was wrapped
fn handle_offload<'ll>(
cx: &SimpleCx<'ll>,
old_fn: &'ll llvm::Value,
) -> Option<&'ll llvm::Value> {
old_fn: llvm::Value<'ll>,
) -> Option<llvm::Value<'ll>> {
let old_fn_ty = cx.get_type_of_global(old_fn);
let old_param_types = cx.func_params_types(old_fn_ty);
let old_param_count = old_param_types.len();
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_codegen_llvm/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ use crate::llvm::{self, Value};
use crate::{ModuleLlvm, attributes};

pub(crate) struct ValueIter<'ll> {
cur: Option<&'ll Value>,
step: unsafe extern "C" fn(&'ll Value) -> Option<&'ll Value>,
cur: Option<Value<'ll>>,
step: unsafe extern "C" fn(Value<'ll>) -> Option<Value<'ll>>,
}

impl<'ll> Iterator for ValueIter<'ll> {
type Item = &'ll Value;
type Item = Value<'ll>;

fn next(&mut self) -> Option<&'ll Value> {
fn next(&mut self) -> Option<Value<'ll>> {
let old = self.cur;
if let Some(old) = old {
self.cur = unsafe { (self.step)(old) };
Expand Down Expand Up @@ -221,7 +221,7 @@ pub(crate) fn compile_codegen_unit(
(module, cost)
}

pub(crate) fn set_link_section(llval: &Value, attrs: &CodegenFnAttrs) {
pub(crate) fn set_link_section<'ll>(llval: Value<'ll>, attrs: &CodegenFnAttrs) {
let Some(sect) = attrs.link_section else { return };
let buf = SmallCStr::new(sect.as_str());
llvm::set_section(llval, &buf);
Expand All @@ -248,7 +248,7 @@ pub(crate) fn visibility_to_llvm(linkage: Visibility) -> llvm::Visibility {
}
}

pub(crate) fn set_variable_sanitizer_attrs(llval: &Value, attrs: &CodegenFnAttrs) {
pub(crate) fn set_variable_sanitizer_attrs<'ll>(llval: Value<'ll>, attrs: &CodegenFnAttrs) {
if attrs.sanitizers.disabled.contains(SanitizerSet::ADDRESS)
|| attrs.sanitizers.disabled.contains(SanitizerSet::KERNELADDRESS)
{
Expand Down
Loading
Loading