operands,
options: _,
destination,
+ line_spans: _,
} => {
match template {
&[] => {
let place = trans_place(fx, *place);
place.write_place_ref(fx, lval);
}
+ Rvalue::ThreadLocalRef(def_id) => {
+ let val = crate::constant::codegen_tls_ref(fx, *def_id, lval.layout());
+ lval.write_cvalue(fx, val);
+ }
Rvalue::BinaryOp(bin_op, lhs, rhs) => {
let lhs = trans_operand(fx, lhs);
let rhs = trans_operand(fx, rhs);
let mut cplace = fx.get_local_place(place.local);
for elem in place.projection {
- match *elem {
+ match elem {
PlaceElem::Deref => {
cplace = cplace.place_deref(fx);
}
use rustc_target::abi::Align;
use rustc_data_structures::fx::FxHashSet;
-use cranelift_codegen::ir::GlobalValue;
+use cranelift_codegen::ir::GlobalValueData;
use cranelift_module::*;
use crate::prelude::*;
constants_cx.todo.push(TodoItem::Static(def_id));
}
+pub(crate) fn codegen_tls_ref<'tcx>(
+ fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
+ def_id: DefId,
+ layout: TyAndLayout<'tcx>,
+) -> CValue<'tcx> {
+ let linkage = crate::linkage::get_static_ref_linkage(fx.tcx, def_id);
+ let data_id = data_id_for_static(fx.tcx, fx.module, def_id, linkage);
+ let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
+ #[cfg(debug_assertions)]
+ fx.add_comment(local_data_id, format!("tls {:?}", def_id));
+ let tls_ptr = fx.bcx.ins().tls_value(fx.pointer_type, local_data_id);
+ CValue::by_val(tls_ptr, layout)
+}
+
fn codegen_static_ref<'tcx>(
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
def_id: DefId,
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
#[cfg(debug_assertions)]
fx.add_comment(local_data_id, format!("{:?}", def_id));
- cplace_for_dataid(fx, layout, local_data_id)
+ let global_ptr = fx.bcx.ins().global_value(fx.pointer_type, local_data_id);
+ assert!(!layout.is_unsized(), "unsized statics aren't supported");
+ assert!(matches!(fx.bcx.func.global_values[local_data_id], GlobalValueData::Symbol { tls: false, ..}), "tls static referenced without Rvalue::ThreadLocalRef");
+ CPlace::for_ptr(crate::pointer::Pointer::new(global_ptr), layout)
}
pub(crate) fn trans_constant<'tcx>(
data_id
}
-fn cplace_for_dataid<'tcx>(
- fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
- layout: TyAndLayout<'tcx>,
- local_data_id: GlobalValue,
-) -> CPlace<'tcx> {
- let global_ptr = fx.bcx.ins().global_value(fx.pointer_type, local_data_id);
- assert!(!layout.is_unsized(), "unsized statics aren't supported");
- CPlace::for_ptr(crate::pointer::Pointer::new(global_ptr), layout)
-}
-
fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut Module<impl Backend>, cx: &mut ConstantCx) {
while let Some(todo_item) = cx.todo.pop() {
let (data_id, alloc) = match todo_item {
use crate::prelude::*;
-use rustc_span::FileName;
-
use cranelift_codegen::ir::{StackSlots, ValueLabel, ValueLoc};
use cranelift_codegen::isa::TargetIsa;
use cranelift_codegen::ValueLocRange;
let (name, file_info) = match tcx.sess.local_crate_source_file.clone() {
Some(path) => {
let name = path.to_string_lossy().into_owned();
- let info = tcx.sess
- .source_map()
- .get_source_file(&FileName::Real(path))
- .map(|f| f.src_hash)
- .and_then(line_info::make_file_info);
- (name, info)
+ (name, None)
},
None => (tcx.crate_name(LOCAL_CRATE).to_string(), None),
};