Move get_static from CodegenCx to Builder
This commit is contained in:
parent
ceb29e2ac4
commit
d108a913c7
7 changed files with 44 additions and 33 deletions
|
@ -20,6 +20,7 @@ use value::Value;
|
|||
use libc::{c_uint, c_char};
|
||||
use rustc::ty::{self, Ty, TyCtxt};
|
||||
use rustc::ty::layout::{self, Align, Size, TyLayout};
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::session::config;
|
||||
use rustc_data_structures::small_c_str::SmallCStr;
|
||||
use rustc_codegen_ssa::traits::*;
|
||||
|
@ -1486,6 +1487,12 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl StaticBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
|
||||
fn get_static(&self, def_id: DefId) -> &'ll Value {
|
||||
self.cx().get_static(def_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl Builder<'a, 'll, 'tcx> {
|
||||
fn call_lifetime_intrinsic(&mut self, intrinsic: &str, ptr: &'ll Value, size: Size) {
|
||||
if self.cx.sess().opts.optimize == config::OptLevel::No {
|
||||
|
|
|
@ -203,35 +203,8 @@ impl CodegenCx<'ll, 'tcx> {
|
|||
gv
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StaticMethods for CodegenCx<'ll, 'tcx> {
|
||||
fn static_addr_of(
|
||||
&self,
|
||||
cv: &'ll Value,
|
||||
align: Align,
|
||||
kind: Option<&str>,
|
||||
) -> &'ll Value {
|
||||
if let Some(&gv) = self.const_globals.borrow().get(&cv) {
|
||||
unsafe {
|
||||
// Upgrade the alignment in cases where the same constant is used with different
|
||||
// alignment requirements
|
||||
let llalign = align.bytes() as u32;
|
||||
if llalign > llvm::LLVMGetAlignment(gv) {
|
||||
llvm::LLVMSetAlignment(gv, llalign);
|
||||
}
|
||||
}
|
||||
return gv;
|
||||
}
|
||||
let gv = self.static_addr_of_mut(cv, align, kind);
|
||||
unsafe {
|
||||
llvm::LLVMSetGlobalConstant(gv, True);
|
||||
}
|
||||
self.const_globals.borrow_mut().insert(cv, gv);
|
||||
gv
|
||||
}
|
||||
|
||||
fn get_static(&self, def_id: DefId) -> &'ll Value {
|
||||
crate fn get_static(&self, def_id: DefId) -> &'ll Value {
|
||||
let instance = Instance::mono(self.tcx, def_id);
|
||||
if let Some(&g) = self.instances.borrow().get(&instance) {
|
||||
return g;
|
||||
|
@ -351,6 +324,33 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
|
|||
self.instances.borrow_mut().insert(instance, g);
|
||||
g
|
||||
}
|
||||
}
|
||||
|
||||
impl StaticMethods for CodegenCx<'ll, 'tcx> {
|
||||
fn static_addr_of(
|
||||
&self,
|
||||
cv: &'ll Value,
|
||||
align: Align,
|
||||
kind: Option<&str>,
|
||||
) -> &'ll Value {
|
||||
if let Some(&gv) = self.const_globals.borrow().get(&cv) {
|
||||
unsafe {
|
||||
// Upgrade the alignment in cases where the same constant is used with different
|
||||
// alignment requirements
|
||||
let llalign = align.bytes() as u32;
|
||||
if llalign > llvm::LLVMGetAlignment(gv) {
|
||||
llvm::LLVMSetAlignment(gv, llalign);
|
||||
}
|
||||
}
|
||||
return gv;
|
||||
}
|
||||
let gv = self.static_addr_of_mut(cv, align, kind);
|
||||
unsafe {
|
||||
llvm::LLVMSetGlobalConstant(gv, True);
|
||||
}
|
||||
self.const_globals.borrow_mut().insert(cv, gv);
|
||||
gv
|
||||
}
|
||||
|
||||
fn codegen_static(
|
||||
&self,
|
||||
|
|
|
@ -915,7 +915,7 @@ fn codegen_msvc_try(
|
|||
catchswitch.add_handler(cs, catchpad.llbb());
|
||||
|
||||
let tydesc = match bx.tcx().lang_items().msvc_try_filter() {
|
||||
Some(did) => bx.cx().get_static(did),
|
||||
Some(did) => bx.get_static(did),
|
||||
None => bug!("msvc_try_filter not defined"),
|
||||
};
|
||||
let funclet = catchpad.catch_pad(cs, &[tydesc, bx.const_i32(0), slot]);
|
||||
|
|
|
@ -423,7 +423,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
}
|
||||
mir::Place::Static(box mir::Static { def_id, ty }) => {
|
||||
let layout = cx.layout_of(self.monomorphize(&ty));
|
||||
PlaceRef::new_sized(cx.get_static(def_id), layout, layout.align.abi)
|
||||
PlaceRef::new_sized(bx.get_static(def_id), layout, layout.align.abi)
|
||||
},
|
||||
mir::Place::Projection(box mir::Projection {
|
||||
ref base,
|
||||
|
|
|
@ -13,7 +13,7 @@ use super::asm::AsmBuilderMethods;
|
|||
use super::debuginfo::DebugInfoBuilderMethods;
|
||||
use super::intrinsic::IntrinsicCallMethods;
|
||||
use super::type_::ArgTypeMethods;
|
||||
use super::HasCodegen;
|
||||
use super::{HasCodegen, StaticBuilderMethods};
|
||||
use common::{AtomicOrdering, AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope};
|
||||
use mir::operand::OperandRef;
|
||||
use mir::place::PlaceRef;
|
||||
|
@ -40,6 +40,7 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
|
|||
+ AbiBuilderMethods<'tcx>
|
||||
+ IntrinsicCallMethods<'tcx>
|
||||
+ AsmBuilderMethods<'tcx>
|
||||
+ StaticBuilderMethods<'tcx>
|
||||
{
|
||||
fn new_block<'b>(cx: &'a Self::CodegenCx, llfn: Self::Value, name: &'b str) -> Self;
|
||||
fn with_cx(cx: &'a Self::CodegenCx) -> Self;
|
||||
|
|
|
@ -46,7 +46,7 @@ pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoMethods};
|
|||
pub use self::declare::{DeclareMethods, PreDefineMethods};
|
||||
pub use self::intrinsic::IntrinsicCallMethods;
|
||||
pub use self::misc::MiscMethods;
|
||||
pub use self::statics::StaticMethods;
|
||||
pub use self::statics::{StaticMethods, StaticBuilderMethods};
|
||||
pub use self::type_::{
|
||||
ArgTypeMethods, BaseTypeMethods, DerivedTypeMethods, LayoutTypeMethods, TypeMethods,
|
||||
};
|
||||
|
|
|
@ -14,6 +14,9 @@ use rustc::ty::layout::Align;
|
|||
|
||||
pub trait StaticMethods: BackendTypes {
|
||||
fn static_addr_of(&self, cv: Self::Value, align: Align, kind: Option<&str>) -> Self::Value;
|
||||
fn get_static(&self, def_id: DefId) -> Self::Value;
|
||||
fn codegen_static(&self, def_id: DefId, is_mutable: bool);
|
||||
}
|
||||
|
||||
pub trait StaticBuilderMethods<'tcx>: BackendTypes {
|
||||
fn get_static(&self, def_id: DefId) -> Self::Value;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue