Skip to content

Commit 88d874d

Browse files
committed
rustc_codegen_llvm: avoid converting between DILocation and Value.
1 parent fa2b381 commit 88d874d

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> {
192192
let dbg_loc = self.cx().create_debug_loc(scope, span);
193193

194194
unsafe {
195-
llvm::LLVMSetCurrentDebugLocation(self.llbuilder, dbg_loc);
195+
let dbg_loc_as_llval = llvm::LLVMRustMetadataAsValue(self.cx().llcx, dbg_loc);
196+
llvm::LLVMSetCurrentDebugLocation(self.llbuilder, dbg_loc_as_llval);
196197
}
197198
}
198199
fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) {

compiler/rustc_codegen_llvm/src/debuginfo/source_loc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use super::metadata::{UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER};
22
use super::utils::debug_context;
33

44
use crate::common::CodegenCx;
5-
use crate::llvm::debuginfo::DIScope;
6-
use crate::llvm::{self, Value};
5+
use crate::llvm;
6+
use crate::llvm::debuginfo::{DILocation, DIScope};
77
use rustc_codegen_ssa::traits::*;
88

99
use rustc_data_structures::sync::Lrc;
@@ -45,7 +45,7 @@ impl CodegenCx<'ll, '_> {
4545
}
4646
}
4747

48-
pub fn create_debug_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll Value {
48+
pub fn create_debug_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll DILocation {
4949
let DebugLoc { line, col, .. } = self.lookup_debug_loc(span.lo());
5050

5151
unsafe {

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ use rustc_codegen_ssa::coverageinfo::map as coverage_map;
55

66
use super::debuginfo::{
77
DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator,
8-
DIFile, DIFlags, DIGlobalVariableExpression, DILexicalBlock, DINameSpace, DISPFlags, DIScope,
9-
DISubprogram, DISubrange, DITemplateTypeParameter, DIType, DIVariable, DebugEmissionKind,
8+
DIFile, DIFlags, DIGlobalVariableExpression, DILexicalBlock, DILocation, DINameSpace,
9+
DISPFlags, DIScope, DISubprogram, DISubrange, DITemplateTypeParameter, DIType, DIVariable,
10+
DebugEmissionKind,
1011
};
1112

1213
use libc::{c_char, c_int, c_uint, size_t};
@@ -794,6 +795,7 @@ pub mod debuginfo {
794795
pub struct DIBuilder<'a>(InvariantOpaque<'a>);
795796

796797
pub type DIDescriptor = Metadata;
798+
pub type DILocation = Metadata;
797799
pub type DIScope = DIDescriptor;
798800
pub type DIFile = DIScope;
799801
pub type DILexicalBlock = DIScope;
@@ -2005,7 +2007,7 @@ extern "C" {
20052007
VarInfo: &'a DIVariable,
20062008
AddrOps: *const i64,
20072009
AddrOpsCount: c_uint,
2008-
DL: &'a Value,
2010+
DL: &'a DILocation,
20092011
InsertAtEnd: &'a BasicBlock,
20102012
) -> &'a Value;
20112013

@@ -2093,8 +2095,8 @@ extern "C" {
20932095
Line: c_uint,
20942096
Column: c_uint,
20952097
Scope: &'a DIScope,
2096-
InlinedAt: Option<&'a Metadata>,
2097-
) -> &'a Value;
2098+
InlinedAt: Option<&'a DILocation>,
2099+
) -> &'a DILocation;
20982100
pub fn LLVMRustDIBuilderCreateOpDeref() -> i64;
20992101
pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> i64;
21002102

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -931,12 +931,12 @@ LLVMRustDIBuilderGetOrCreateArray(LLVMRustDIBuilderRef Builder,
931931

932932
extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd(
933933
LLVMRustDIBuilderRef Builder, LLVMValueRef V, LLVMMetadataRef VarInfo,
934-
int64_t *AddrOps, unsigned AddrOpsCount, LLVMValueRef DL,
934+
int64_t *AddrOps, unsigned AddrOpsCount, LLVMMetadataRef DL,
935935
LLVMBasicBlockRef InsertAtEnd) {
936936
return wrap(Builder->insertDeclare(
937937
unwrap(V), unwrap<DILocalVariable>(VarInfo),
938938
Builder->createExpression(llvm::ArrayRef<int64_t>(AddrOps, AddrOpsCount)),
939-
DebugLoc(cast<MDNode>(unwrap<MetadataAsValue>(DL)->getMetadata())),
939+
DebugLoc(cast<MDNode>(DL)),
940940
unwrap(InsertAtEnd)));
941941
}
942942

@@ -1003,7 +1003,7 @@ LLVMRustDICompositeTypeReplaceArrays(LLVMRustDIBuilderRef Builder,
10031003
DINodeArray(unwrap<MDTuple>(Params)));
10041004
}
10051005

1006-
extern "C" LLVMValueRef
1006+
extern "C" LLVMMetadataRef
10071007
LLVMRustDIBuilderCreateDebugLocation(LLVMContextRef ContextRef, unsigned Line,
10081008
unsigned Column, LLVMMetadataRef Scope,
10091009
LLVMMetadataRef InlinedAt) {
@@ -1012,7 +1012,7 @@ LLVMRustDIBuilderCreateDebugLocation(LLVMContextRef ContextRef, unsigned Line,
10121012
DebugLoc debug_loc = DebugLoc::get(Line, Column, unwrapDIPtr<MDNode>(Scope),
10131013
unwrapDIPtr<MDNode>(InlinedAt));
10141014

1015-
return wrap(MetadataAsValue::get(Context, debug_loc.getAsMDNode()));
1015+
return wrap(debug_loc.getAsMDNode());
10161016
}
10171017

10181018
extern "C" int64_t LLVMRustDIBuilderCreateOpDeref() {

0 commit comments

Comments
 (0)