Skip to content

Commit a87be98

Browse files
authored
Rollup merge of rust-lang#94001 - durin42:llvm-15-uwtable, r=nikic
llvm: migrate to new parameter-bearing uwtable attr In https://reviews.llvm.org/D114543 the uwtable attribute gained a flag so that we can ask for sync uwtables instead of async, as the former are much cheaper. The default is async, so that's what I've done here, but I left a TODO that we might be able to do better. While in here I went ahead and dropped support for removing uwtable attributes in rustc: we never did it, so I didn't write the extra C++ bridge code to make it work. Maybe I should have done the same thing with the `sync|async` parameter but we'll see.
2 parents c6b27db + 0958c8f commit a87be98

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

compiler/rustc_codegen_llvm/src/allocator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub(crate) unsafe fn codegen(
6464
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
6565
}
6666
if tcx.sess.must_emit_unwind_tables() {
67-
attributes::emit_uwtable(llfn, true);
67+
attributes::emit_uwtable(llfn);
6868
}
6969

7070
let callee = kind.fn_name(method.name);
@@ -111,7 +111,7 @@ pub(crate) unsafe fn codegen(
111111
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
112112
}
113113
if tcx.sess.must_emit_unwind_tables() {
114-
attributes::emit_uwtable(llfn, true);
114+
attributes::emit_uwtable(llfn);
115115
}
116116

117117
let kind = if has_alloc_error_handler { AllocatorKind::Global } else { AllocatorKind::Default };

compiler/rustc_codegen_llvm/src/attributes.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ pub fn sanitize<'ll>(cx: &CodegenCx<'ll, '_>, no_sanitize: SanitizerSet, llfn: &
5959

6060
/// Tell LLVM to emit or not emit the information necessary to unwind the stack for the function.
6161
#[inline]
62-
pub fn emit_uwtable(val: &Value, emit: bool) {
63-
Attribute::UWTable.toggle_llfn(Function, val, emit);
62+
pub fn emit_uwtable(val: &Value) {
63+
// NOTE: We should determine if we even need async unwind tables, as they
64+
// take have more overhead and if we can use sync unwind tables we
65+
// probably should.
66+
llvm::EmitUWTableAttr(val, true);
6467
}
6568

6669
/// Tell LLVM if this function should be 'naked', i.e., skip the epilogue and prologue.
@@ -275,7 +278,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(
275278
// You can also find more info on why Windows always requires uwtables here:
276279
// https://bugzilla.mozilla.org/show_bug.cgi?id=1302078
277280
if cx.sess().must_emit_unwind_tables() {
278-
attributes::emit_uwtable(llfn, true);
281+
attributes::emit_uwtable(llfn);
279282
}
280283

281284
if cx.sess().opts.debugging_opts.profile_sample_use.is_some() {

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,7 @@ extern "C" {
11821182
pub fn LLVMRustAddByValAttr(Fn: &Value, index: c_uint, ty: &Type);
11831183
pub fn LLVMRustAddStructRetAttr(Fn: &Value, index: c_uint, ty: &Type);
11841184
pub fn LLVMRustAddFunctionAttribute(Fn: &Value, index: c_uint, attr: Attribute);
1185+
pub fn LLVMRustEmitUWTableAttr(Fn: &Value, async_: bool);
11851186
pub fn LLVMRustAddFunctionAttrStringValue(
11861187
Fn: &Value,
11871188
index: c_uint,

compiler/rustc_codegen_llvm/src/llvm/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ impl LLVMRustResult {
3131
}
3232
}
3333

34+
pub fn EmitUWTableAttr(llfn: &Value, async_: bool) {
35+
unsafe { LLVMRustEmitUWTableAttr(llfn, async_) }
36+
}
37+
3438
pub fn AddFunctionAttrStringValue(llfn: &Value, idx: AttributePlace, attr: &CStr, value: &CStr) {
3539
unsafe {
3640
LLVMRustAddFunctionAttrStringValue(llfn, idx.as_uint(), attr.as_ptr(), value.as_ptr())

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,17 @@ extern "C" void LLVMRustAddStructRetAttr(LLVMValueRef Fn, unsigned Index,
334334
AddAttribute(F, Index, Attr);
335335
}
336336

337+
extern "C" void LLVMRustEmitUWTableAttr(LLVMValueRef Fn, bool Async) {
338+
Function *F = unwrap<Function>(Fn);
339+
#if LLVM_VERSION_LT(15, 0)
340+
Attribute Attr = Attribute::get(F->getContext(), Attribute::UWTable);
341+
#else
342+
Attribute Attr = Attribute::getWithUWTableKind(
343+
F->getContext(), Async ? UWTableKind::Async : UWTableKind::Sync);
344+
#endif
345+
AddAttribute(F, AttributeList::AttrIndex::FunctionIndex, Attr);
346+
}
347+
337348
extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn,
338349
unsigned Index,
339350
const char *Name,

0 commit comments

Comments
 (0)