Skip to content

llvm-wrapper cleanup #145092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
16 changes: 7 additions & 9 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::{iter, ptr};

use libc::{c_longlong, c_uint};
use libc::c_uint;
use rustc_abi::{Align, Size};
use rustc_codegen_ssa::debuginfo::type_names::{VTableNameKind, cpp_like_debuginfo};
use rustc_codegen_ssa::traits::*;
Expand Down Expand Up @@ -112,12 +112,10 @@ fn build_fixed_size_array_di_node<'ll, 'tcx>(

let (size, align) = cx.size_and_align_of(array_type);

let upper_bound = len
.try_to_target_usize(cx.tcx)
.expect("expected monomorphic const in codegen") as c_longlong;
let count =
len.try_to_target_usize(cx.tcx).expect("expected monomorphic const in codegen") as i64;

let subrange =
unsafe { Some(llvm::LLVMRustDIBuilderGetOrCreateSubrange(DIB(cx), 0, upper_bound)) };
let subrange = unsafe { Some(llvm::LLVMDIBuilderGetOrCreateSubrange(DIB(cx), 0, count)) };

let subscripts = create_DIArray(DIB(cx), &[subrange]);
let di_node = unsafe {
Expand Down Expand Up @@ -173,7 +171,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
);

let di_node = unsafe {
llvm::LLVMRustDIBuilderCreatePointerType(
llvm::LLVMDIBuilderCreatePointerType(
DIB(cx),
pointee_type_di_node,
pointer_size.bits(),
Expand Down Expand Up @@ -231,7 +229,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
// The data pointer type is a regular, thin pointer, regardless of whether this
// is a slice or a trait object.
let data_ptr_type_di_node = unsafe {
llvm::LLVMRustDIBuilderCreatePointerType(
llvm::LLVMDIBuilderCreatePointerType(
DIB(cx),
pointee_type_di_node,
addr_field.size.bits(),
Expand Down Expand Up @@ -327,7 +325,7 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(
_ => unreachable!(),
};
let di_node = unsafe {
llvm::LLVMRustDIBuilderCreatePointerType(
llvm::LLVMDIBuilderCreatePointerType(
DIB(cx),
fn_di_node,
size.bits(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,39 +567,37 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
None,
));

let build_assoc_const = |name: &str,
type_di_node_: &'ll DIType,
value: u64,
align: Align| unsafe {
// FIXME: Currently we force all DISCR_* values to be u64's as LLDB seems to have
// problems inspecting other value types. Since DISCR_* is typically only going to be
// directly inspected via the debugger visualizer - which compares it to the `tag` value
// (whose type is not modified at all) it shouldn't cause any real problems.
let (t_di, align) = if name == ASSOC_CONST_DISCR_NAME {
(type_di_node_, align.bits() as u32)
} else {
let ty_u64 = Ty::new_uint(cx.tcx, ty::UintTy::U64);
(type_di_node(cx, ty_u64), Align::EIGHT.bits() as u32)
let build_assoc_const =
|name: &str, type_di_node_: &'ll DIType, value: u64, align: Align| unsafe {
// FIXME: Currently we force all DISCR_* values to be u64's as LLDB seems to have
// problems inspecting other value types. Since DISCR_* is typically only going to be
// directly inspected via the debugger visualizer - which compares it to the `tag` value
// (whose type is not modified at all) it shouldn't cause any real problems.
let (t_di, align) = if name == ASSOC_CONST_DISCR_NAME {
(type_di_node_, align.bits() as u32)
} else {
let ty_u64 = Ty::new_uint(cx.tcx, ty::UintTy::U64);
(type_di_node(cx, ty_u64), Align::EIGHT.bits() as u32)
};

// must wrap type in a `const` modifier for LLDB to be able to inspect the value of the member
let field_type =
llvm::LLVMDIBuilderCreateQualifiedType(DIB(cx), DW_TAG_const_type, t_di);

llvm::LLVMRustDIBuilderCreateStaticMemberType(
DIB(cx),
wrapper_struct_type_di_node,
name.as_c_char_ptr(),
name.len(),
unknown_file_metadata(cx),
UNKNOWN_LINE_NUMBER,
field_type,
DIFlags::FlagZero,
Some(cx.const_u64(value)),
align,
)
};

// must wrap type in a `const` modifier for LLDB to be able to inspect the value of the member
let field_type =
llvm::LLVMRustDIBuilderCreateQualifiedType(DIB(cx), DW_TAG_const_type, t_di);

llvm::LLVMRustDIBuilderCreateStaticMemberType(
DIB(cx),
wrapper_struct_type_di_node,
name.as_c_char_ptr(),
name.len(),
unknown_file_metadata(cx),
UNKNOWN_LINE_NUMBER,
field_type,
DIFlags::FlagZero,
Some(cx.const_u64(value)),
align,
)
};

// We also always have an associated constant for the discriminant value
// of the variant.
fields.push(build_assoc_const(
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Utility Functions.

use libc::size_t;
use rustc_hir::def_id::DefId;
use rustc_middle::ty::layout::{HasTypingEnv, LayoutOf};
use rustc_middle::ty::{self, Ty};
Expand Down Expand Up @@ -28,7 +29,7 @@ pub(crate) fn create_DIArray<'ll>(
builder: &DIBuilder<'ll>,
arr: &[Option<&'ll DIDescriptor>],
) -> &'ll DIArray {
unsafe { llvm::LLVMRustDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32) }
unsafe { llvm::LLVMDIBuilderGetOrCreateTypeArray(builder, arr.as_ptr(), arr.len() as size_t) }
}

#[inline]
Expand Down
56 changes: 28 additions & 28 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,34 @@ unsafe extern "C" {
Scope: &'ll Metadata,
InlinedAt: Option<&'ll Metadata>,
) -> &'ll Metadata;

pub(crate) fn LLVMDIBuilderCreateQualifiedType<'ll>(
Builder: &DIBuilder<'ll>,
Tag: c_uint,
Type: &'ll DIType,
) -> &'ll DIDerivedType;

pub(crate) fn LLVMDIBuilderCreatePointerType<'ll>(
Builder: &DIBuilder<'ll>,
PointeeTy: &'ll DIType,
SizeInBits: u64,
AlignInBits: u32,
AddressSpace: c_uint,
Name: *const c_char,
NameLen: size_t,
) -> &'ll DIDerivedType;

pub(crate) fn LLVMDIBuilderGetOrCreateTypeArray<'ll>(
Builder: &DIBuilder<'ll>,
Data: *const Option<&'ll DIDescriptor>, //FIXME: is it really const?
Length: size_t,
) -> &'ll DIArray;

pub(crate) fn LLVMDIBuilderGetOrCreateSubrange<'ll>(
Builder: &DIBuilder<'ll>,
Lo: i64,
Count: i64,
) -> &'ll DISubrange;
}

#[link(name = "llvm-wrapper", kind = "static")]
Expand Down Expand Up @@ -2189,16 +2217,6 @@ unsafe extern "C" {
Scope: Option<&'a DIScope>,
) -> &'a DIDerivedType;

pub(crate) fn LLVMRustDIBuilderCreatePointerType<'a>(
Builder: &DIBuilder<'a>,
PointeeTy: &'a DIType,
SizeInBits: u64,
AlignInBits: u32,
AddressSpace: c_uint,
Name: *const c_char,
NameLen: size_t,
) -> &'a DIDerivedType;

pub(crate) fn LLVMRustDIBuilderCreateStructType<'a>(
Builder: &DIBuilder<'a>,
Scope: Option<&'a DIDescriptor>,
Expand Down Expand Up @@ -2259,12 +2277,6 @@ unsafe extern "C" {
AlignInBits: u32,
) -> &'a DIDerivedType;

pub(crate) fn LLVMRustDIBuilderCreateQualifiedType<'a>(
Builder: &DIBuilder<'a>,
Tag: c_uint,
Type: &'a DIType,
) -> &'a DIDerivedType;

pub(crate) fn LLVMRustDIBuilderCreateStaticVariable<'a>(
Builder: &DIBuilder<'a>,
Context: Option<&'a DIScope>,
Expand Down Expand Up @@ -2304,18 +2316,6 @@ unsafe extern "C" {
Subscripts: &'a DIArray,
) -> &'a DIType;

pub(crate) fn LLVMRustDIBuilderGetOrCreateSubrange<'a>(
Builder: &DIBuilder<'a>,
Lo: i64,
Count: i64,
) -> &'a DISubrange;

pub(crate) fn LLVMRustDIBuilderGetOrCreateArray<'a>(
Builder: &DIBuilder<'a>,
Ptr: *const Option<&'a DIDescriptor>,
Count: c_uint,
) -> &'a DIArray;

pub(crate) fn LLVMRustDIBuilderInsertDeclareAtEnd<'a>(
Builder: &DIBuilder<'a>,
Val: &'a Value,
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,6 @@ static FloatABI::ABIType fromRust(LLVMRustFloatABI RustFloatAbi) {
report_fatal_error("Bad FloatABI.");
}

/// getLongestEntryLength - Return the length of the longest entry in the table.
template <typename KV> static size_t getLongestEntryLength(ArrayRef<KV> Table) {
size_t MaxLen = 0;
for (auto &I : Table)
MaxLen = std::max(MaxLen, std::strlen(I.Key));
return MaxLen;
}

extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM,
RustStringRef OutStr) {
ArrayRef<SubtargetSubTypeKV> CPUTable =
Expand Down
31 changes: 0 additions & 31 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1076,15 +1076,6 @@ LLVMRustDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type,
LineNo, unwrapDIPtr<DIScope>(Scope)));
}

extern "C" LLVMMetadataRef LLVMRustDIBuilderCreatePointerType(
LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeTy, uint64_t SizeInBits,
uint32_t AlignInBits, unsigned AddressSpace, const char *Name,
size_t NameLen) {
return wrap(unwrap(Builder)->createPointerType(
unwrapDI<DIType>(PointeeTy), SizeInBits, AlignInBits, AddressSpace,
StringRef(Name, NameLen)));
}

extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStructType(
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
Expand Down Expand Up @@ -1149,13 +1140,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticMemberType(
unwrap<llvm::ConstantInt>(val), llvm::dwarf::DW_TAG_member, AlignInBits));
}

extern "C" LLVMMetadataRef
LLVMRustDIBuilderCreateQualifiedType(LLVMDIBuilderRef Builder, unsigned Tag,
LLVMMetadataRef Type) {
return wrap(
unwrap(Builder)->createQualifiedType(Tag, unwrapDI<DIType>(Type)));
}

extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticVariable(
LLVMDIBuilderRef Builder, LLVMMetadataRef Context, const char *Name,
size_t NameLen, const char *LinkageName, size_t LinkageNameLen,
Expand Down Expand Up @@ -1214,21 +1198,6 @@ LLVMRustDIBuilderCreateArrayType(LLVMDIBuilderRef Builder, uint64_t Size,
DINodeArray(unwrapDI<MDTuple>(Subscripts))));
}

extern "C" LLVMMetadataRef
LLVMRustDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Builder, int64_t Lo,
int64_t Count) {
return wrap(unwrap(Builder)->getOrCreateSubrange(Lo, Count));
}

extern "C" LLVMMetadataRef
LLVMRustDIBuilderGetOrCreateArray(LLVMDIBuilderRef Builder,
LLVMMetadataRef *Ptr, unsigned Count) {
Metadata **DataValue = unwrap(Ptr);
return wrap(unwrap(Builder)
->getOrCreateArray(ArrayRef<Metadata *>(DataValue, Count))
.get());
}

extern "C" void
LLVMRustDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Builder, LLVMValueRef V,
LLVMMetadataRef VarInfo, uint64_t *AddrOps,
Expand Down
Loading