Skip to content

Commit 0b633c8

Browse files
committed
rustc_codegen_ssa: split declare_local into create_dbg_var and dbg_var_addr.
1 parent 0d34a87 commit 0b633c8

File tree

8 files changed

+79
-43
lines changed

8 files changed

+79
-43
lines changed

Diff for: src/librustc_codegen_llvm/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ impl BackendTypes for Builder<'_, 'll, 'tcx> {
5757
type Funclet = <CodegenCx<'ll, 'tcx> as BackendTypes>::Funclet;
5858

5959
type DIScope = <CodegenCx<'ll, 'tcx> as BackendTypes>::DIScope;
60+
type DIVariable = <CodegenCx<'ll, 'tcx> as BackendTypes>::DIVariable;
6061
}
6162

6263
impl ty::layout::HasDataLayout for Builder<'_, '_, '_> {

Diff for: src/librustc_codegen_llvm/common.rs

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ impl BackendTypes for CodegenCx<'ll, 'tcx> {
9191
type Funclet = Funclet<'ll>;
9292

9393
type DIScope = &'ll llvm::debuginfo::DIScope;
94+
type DIVariable = &'ll llvm::debuginfo::DIVariable;
9495
}
9596

9697
impl CodegenCx<'ll, 'tcx> {

Diff for: src/librustc_codegen_llvm/debuginfo/mod.rs

+51-33
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use self::utils::{create_DIArray, is_node_local_to_unit, span_start, DIB};
1111

1212
use crate::llvm;
1313
use crate::llvm::debuginfo::{
14-
DIArray, DIBuilder, DIFile, DIFlags, DILexicalBlock, DISPFlags, DIScope, DIType,
14+
DIArray, DIBuilder, DIFile, DIFlags, DILexicalBlock, DISPFlags, DIScope, DIType, DIVariable,
1515
};
1616
use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1717
use rustc::ty::subst::{GenericArgKind, SubstsRef};
@@ -143,33 +143,23 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
143143
};
144144
}
145145

146-
impl DebugInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
147-
fn declare_local(
146+
impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> {
147+
// FIXME(eddyb) find a common convention for all of the debuginfo-related
148+
// names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
149+
fn dbg_var_addr(
148150
&mut self,
149151
dbg_context: &FunctionDebugContext<&'ll DIScope>,
150-
variable_name: ast::Name,
151-
variable_type: Ty<'tcx>,
152+
dbg_var: &'ll DIVariable,
152153
scope_metadata: &'ll DIScope,
153154
variable_alloca: Self::Value,
154155
direct_offset: Size,
155156
indirect_offsets: &[Size],
156-
variable_kind: VariableKind,
157157
span: Span,
158158
) {
159159
assert!(!dbg_context.source_locations_enabled);
160160
let cx = self.cx();
161161

162-
let file = span_start(cx, span).file;
163-
let file_metadata = file_metadata(cx, &file.name, dbg_context.defining_crate);
164-
165162
let loc = span_start(cx, span);
166-
let type_metadata = type_metadata(cx, variable_type, span);
167-
168-
let (argument_index, dwarf_tag) = match variable_kind {
169-
ArgumentVariable(index) => (index as c_uint, DW_TAG_arg_variable),
170-
LocalVariable => (0, DW_TAG_auto_variable),
171-
};
172-
let align = cx.align_of(variable_type);
173163

174164
// Convert the direct and indirect offsets to address ops.
175165
let op_deref = || unsafe { llvm::LLVMRustDIBuilderCreateOpDeref() };
@@ -188,32 +178,19 @@ impl DebugInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
188178
}
189179
}
190180

191-
let name = SmallCStr::new(&variable_name.as_str());
192-
let metadata = unsafe {
193-
llvm::LLVMRustDIBuilderCreateVariable(
194-
DIB(cx),
195-
dwarf_tag,
196-
scope_metadata,
197-
name.as_ptr(),
198-
file_metadata,
199-
loc.line as c_uint,
200-
type_metadata,
201-
cx.sess().opts.optimize != config::OptLevel::No,
202-
DIFlags::FlagZero,
203-
argument_index,
204-
align.bytes() as u32,
205-
)
206-
};
181+
// FIXME(eddyb) maybe this information could be extracted from `var`,
182+
// to avoid having to pass it down in both places?
207183
source_loc::set_debug_location(
208184
self,
209185
InternalDebugLocation::new(scope_metadata, loc.line, loc.col.to_usize()),
210186
);
211187
unsafe {
212188
let debug_loc = llvm::LLVMGetCurrentDebugLocation(self.llbuilder);
189+
// FIXME(eddyb) replace `llvm.dbg.declare` with `llvm.dbg.addr`.
213190
let instr = llvm::LLVMRustDIBuilderInsertDeclareAtEnd(
214191
DIB(cx),
215192
variable_alloca,
216-
metadata,
193+
dbg_var,
217194
addr_ops.as_ptr(),
218195
addr_ops.len() as c_uint,
219196
debug_loc,
@@ -558,4 +535,45 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
558535
fn debuginfo_finalize(&self) {
559536
finalize(self)
560537
}
538+
539+
// FIXME(eddyb) find a common convention for all of the debuginfo-related
540+
// names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
541+
fn create_dbg_var(
542+
&self,
543+
dbg_context: &FunctionDebugContext<&'ll DIScope>,
544+
variable_name: ast::Name,
545+
variable_type: Ty<'tcx>,
546+
scope_metadata: &'ll DIScope,
547+
variable_kind: VariableKind,
548+
span: Span,
549+
) -> &'ll DIVariable {
550+
let file = span_start(self, span).file;
551+
let file_metadata = file_metadata(self, &file.name, dbg_context.defining_crate);
552+
553+
let loc = span_start(self, span);
554+
let type_metadata = type_metadata(self, variable_type, span);
555+
556+
let (argument_index, dwarf_tag) = match variable_kind {
557+
ArgumentVariable(index) => (index as c_uint, DW_TAG_arg_variable),
558+
LocalVariable => (0, DW_TAG_auto_variable),
559+
};
560+
let align = self.align_of(variable_type);
561+
562+
let name = SmallCStr::new(&variable_name.as_str());
563+
unsafe {
564+
llvm::LLVMRustDIBuilderCreateVariable(
565+
DIB(self),
566+
dwarf_tag,
567+
scope_metadata,
568+
name.as_ptr(),
569+
file_metadata,
570+
loc.line as c_uint,
571+
type_metadata,
572+
self.sess().opts.optimize != config::OptLevel::No,
573+
DIFlags::FlagZero,
574+
argument_index,
575+
align.bytes() as u32,
576+
)
577+
}
578+
}
561579
}

Diff for: src/librustc_codegen_ssa/mir/debuginfo.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
226226

227227
let (scope, span) = self.debug_loc(var.source_info);
228228
if let Some(scope) = scope {
229-
bx.declare_local(
229+
let dbg_var =
230+
bx.create_dbg_var(debug_context, var.name, layout.ty, scope, kind, span);
231+
bx.dbg_var_addr(
230232
debug_context,
231-
var.name,
232-
layout.ty,
233+
dbg_var,
233234
scope,
234235
base.llval,
235236
direct_offset,
236237
&indirect_offsets,
237-
kind,
238238
span,
239239
);
240240
}

Diff for: src/librustc_codegen_ssa/traits/backend.rs

+3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ pub trait BackendTypes {
2121
type Type: CodegenObject;
2222
type Funclet;
2323

24+
// FIXME(eddyb) find a common convention for all of the debuginfo-related
25+
// names (choose between `Dbg`, `Debug`, `DebugInfo`, `DI` etc.).
2426
type DIScope: Copy;
27+
type DIVariable: Copy;
2528
}
2629

2730
pub trait Backend<'tcx>:

Diff for: src/librustc_codegen_ssa/traits/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub enum OverflowOp {
2828

2929
pub trait BuilderMethods<'a, 'tcx>:
3030
HasCodegen<'tcx>
31-
+ DebugInfoBuilderMethods<'tcx>
31+
+ DebugInfoBuilderMethods
3232
+ ArgAbiMethods<'tcx>
3333
+ AbiBuilderMethods<'tcx>
3434
+ IntrinsicCallMethods<'tcx>

Diff for: src/librustc_codegen_ssa/traits/debuginfo.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,32 @@ pub trait DebugInfoMethods<'tcx>: BackendTypes {
3030
defining_crate: CrateNum,
3131
) -> Self::DIScope;
3232
fn debuginfo_finalize(&self);
33-
}
3433

35-
pub trait DebugInfoBuilderMethods<'tcx>: BackendTypes {
36-
fn declare_local(
37-
&mut self,
34+
// FIXME(eddyb) find a common convention for all of the debuginfo-related
35+
// names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
36+
fn create_dbg_var(
37+
&self,
3838
dbg_context: &FunctionDebugContext<Self::DIScope>,
3939
variable_name: Name,
4040
variable_type: Ty<'tcx>,
4141
scope_metadata: Self::DIScope,
42+
variable_kind: VariableKind,
43+
span: Span,
44+
) -> Self::DIVariable;
45+
}
46+
47+
pub trait DebugInfoBuilderMethods: BackendTypes {
48+
// FIXME(eddyb) find a common convention for all of the debuginfo-related
49+
// names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
50+
fn dbg_var_addr(
51+
&mut self,
52+
dbg_context: &FunctionDebugContext<Self::DIScope>,
53+
dbg_var: Self::DIVariable,
54+
scope_metadata: Self::DIScope,
4255
variable_alloca: Self::Value,
4356
direct_offset: Size,
4457
// NB: each offset implies a deref (i.e. they're steps in a pointer chain).
4558
indirect_offsets: &[Size],
46-
variable_kind: VariableKind,
4759
span: Span,
4860
);
4961
fn set_source_location(

Diff for: src/librustc_codegen_ssa/traits/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,6 @@ pub trait HasCodegen<'tcx>:
9393
Type = Self::Type,
9494
Funclet = Self::Funclet,
9595
DIScope = Self::DIScope,
96+
DIVariable = Self::DIVariable,
9697
>;
9798
}

0 commit comments

Comments
 (0)