Skip to content

Commit d108a91

Browse files
committed
Move get_static from CodegenCx to Builder
1 parent ceb29e2 commit d108a91

File tree

7 files changed

+44
-33
lines changed

7 files changed

+44
-33
lines changed

src/librustc_codegen_llvm/builder.rs

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use value::Value;
2020
use libc::{c_uint, c_char};
2121
use rustc::ty::{self, Ty, TyCtxt};
2222
use rustc::ty::layout::{self, Align, Size, TyLayout};
23+
use rustc::hir::def_id::DefId;
2324
use rustc::session::config;
2425
use rustc_data_structures::small_c_str::SmallCStr;
2526
use rustc_codegen_ssa::traits::*;
@@ -1486,6 +1487,12 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
14861487
}
14871488
}
14881489

1490+
impl StaticBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
1491+
fn get_static(&self, def_id: DefId) -> &'ll Value {
1492+
self.cx().get_static(def_id)
1493+
}
1494+
}
1495+
14891496
impl Builder<'a, 'll, 'tcx> {
14901497
fn call_lifetime_intrinsic(&mut self, intrinsic: &str, ptr: &'ll Value, size: Size) {
14911498
if self.cx.sess().opts.optimize == config::OptLevel::No {

src/librustc_codegen_llvm/consts.rs

+28-28
Original file line numberDiff line numberDiff line change
@@ -203,35 +203,8 @@ impl CodegenCx<'ll, 'tcx> {
203203
gv
204204
}
205205
}
206-
}
207-
208-
impl StaticMethods for CodegenCx<'ll, 'tcx> {
209-
fn static_addr_of(
210-
&self,
211-
cv: &'ll Value,
212-
align: Align,
213-
kind: Option<&str>,
214-
) -> &'ll Value {
215-
if let Some(&gv) = self.const_globals.borrow().get(&cv) {
216-
unsafe {
217-
// Upgrade the alignment in cases where the same constant is used with different
218-
// alignment requirements
219-
let llalign = align.bytes() as u32;
220-
if llalign > llvm::LLVMGetAlignment(gv) {
221-
llvm::LLVMSetAlignment(gv, llalign);
222-
}
223-
}
224-
return gv;
225-
}
226-
let gv = self.static_addr_of_mut(cv, align, kind);
227-
unsafe {
228-
llvm::LLVMSetGlobalConstant(gv, True);
229-
}
230-
self.const_globals.borrow_mut().insert(cv, gv);
231-
gv
232-
}
233206

234-
fn get_static(&self, def_id: DefId) -> &'ll Value {
207+
crate fn get_static(&self, def_id: DefId) -> &'ll Value {
235208
let instance = Instance::mono(self.tcx, def_id);
236209
if let Some(&g) = self.instances.borrow().get(&instance) {
237210
return g;
@@ -351,6 +324,33 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
351324
self.instances.borrow_mut().insert(instance, g);
352325
g
353326
}
327+
}
328+
329+
impl StaticMethods for CodegenCx<'ll, 'tcx> {
330+
fn static_addr_of(
331+
&self,
332+
cv: &'ll Value,
333+
align: Align,
334+
kind: Option<&str>,
335+
) -> &'ll Value {
336+
if let Some(&gv) = self.const_globals.borrow().get(&cv) {
337+
unsafe {
338+
// Upgrade the alignment in cases where the same constant is used with different
339+
// alignment requirements
340+
let llalign = align.bytes() as u32;
341+
if llalign > llvm::LLVMGetAlignment(gv) {
342+
llvm::LLVMSetAlignment(gv, llalign);
343+
}
344+
}
345+
return gv;
346+
}
347+
let gv = self.static_addr_of_mut(cv, align, kind);
348+
unsafe {
349+
llvm::LLVMSetGlobalConstant(gv, True);
350+
}
351+
self.const_globals.borrow_mut().insert(cv, gv);
352+
gv
353+
}
354354

355355
fn codegen_static(
356356
&self,

src/librustc_codegen_llvm/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ fn codegen_msvc_try(
915915
catchswitch.add_handler(cs, catchpad.llbb());
916916

917917
let tydesc = match bx.tcx().lang_items().msvc_try_filter() {
918-
Some(did) => bx.cx().get_static(did),
918+
Some(did) => bx.get_static(did),
919919
None => bug!("msvc_try_filter not defined"),
920920
};
921921
let funclet = catchpad.catch_pad(cs, &[tydesc, bx.const_i32(0), slot]);

src/librustc_codegen_ssa/mir/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
423423
}
424424
mir::Place::Static(box mir::Static { def_id, ty }) => {
425425
let layout = cx.layout_of(self.monomorphize(&ty));
426-
PlaceRef::new_sized(cx.get_static(def_id), layout, layout.align.abi)
426+
PlaceRef::new_sized(bx.get_static(def_id), layout, layout.align.abi)
427427
},
428428
mir::Place::Projection(box mir::Projection {
429429
ref base,

src/librustc_codegen_ssa/traits/builder.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use super::asm::AsmBuilderMethods;
1313
use super::debuginfo::DebugInfoBuilderMethods;
1414
use super::intrinsic::IntrinsicCallMethods;
1515
use super::type_::ArgTypeMethods;
16-
use super::HasCodegen;
16+
use super::{HasCodegen, StaticBuilderMethods};
1717
use common::{AtomicOrdering, AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope};
1818
use mir::operand::OperandRef;
1919
use mir::place::PlaceRef;
@@ -40,6 +40,7 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
4040
+ AbiBuilderMethods<'tcx>
4141
+ IntrinsicCallMethods<'tcx>
4242
+ AsmBuilderMethods<'tcx>
43+
+ StaticBuilderMethods<'tcx>
4344
{
4445
fn new_block<'b>(cx: &'a Self::CodegenCx, llfn: Self::Value, name: &'b str) -> Self;
4546
fn with_cx(cx: &'a Self::CodegenCx) -> Self;

src/librustc_codegen_ssa/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoMethods};
4646
pub use self::declare::{DeclareMethods, PreDefineMethods};
4747
pub use self::intrinsic::IntrinsicCallMethods;
4848
pub use self::misc::MiscMethods;
49-
pub use self::statics::StaticMethods;
49+
pub use self::statics::{StaticMethods, StaticBuilderMethods};
5050
pub use self::type_::{
5151
ArgTypeMethods, BaseTypeMethods, DerivedTypeMethods, LayoutTypeMethods, TypeMethods,
5252
};

src/librustc_codegen_ssa/traits/statics.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ use rustc::ty::layout::Align;
1414

1515
pub trait StaticMethods: BackendTypes {
1616
fn static_addr_of(&self, cv: Self::Value, align: Align, kind: Option<&str>) -> Self::Value;
17-
fn get_static(&self, def_id: DefId) -> Self::Value;
1817
fn codegen_static(&self, def_id: DefId, is_mutable: bool);
1918
}
19+
20+
pub trait StaticBuilderMethods<'tcx>: BackendTypes {
21+
fn get_static(&self, def_id: DefId) -> Self::Value;
22+
}

0 commit comments

Comments
 (0)