]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_codegen_llvm/src/context.rs
New upstream version 1.51.0+dfsg1
[rustc.git] / compiler / rustc_codegen_llvm / src / context.rs
1 use crate::attributes;
2 use crate::callee::get_fn;
3 use crate::coverageinfo;
4 use crate::debuginfo;
5 use crate::llvm;
6 use crate::llvm_util;
7 use crate::type_::Type;
8 use crate::value::Value;
9
10 use rustc_codegen_ssa::base::wants_msvc_seh;
11 use rustc_codegen_ssa::traits::*;
12 use rustc_data_structures::base_n;
13 use rustc_data_structures::const_cstr;
14 use rustc_data_structures::fx::FxHashMap;
15 use rustc_data_structures::small_c_str::SmallCStr;
16 use rustc_middle::bug;
17 use rustc_middle::mir::mono::CodegenUnit;
18 use rustc_middle::ty::layout::{HasParamEnv, LayoutError, TyAndLayout};
19 use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
20 use rustc_session::config::{CFGuard, CrateType, DebugInfo};
21 use rustc_session::Session;
22 use rustc_span::source_map::{Span, DUMMY_SP};
23 use rustc_span::symbol::Symbol;
24 use rustc_target::abi::{HasDataLayout, LayoutOf, PointeeInfo, Size, TargetDataLayout, VariantIdx};
25 use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel};
26
27 use std::cell::{Cell, RefCell};
28 use std::ffi::CStr;
29 use std::str;
30
31 /// There is one `CodegenCx` per compilation unit. Each one has its own LLVM
32 /// `llvm::Context` so that several compilation units may be optimized in parallel.
33 /// All other LLVM data structures in the `CodegenCx` are tied to that `llvm::Context`.
34 pub struct CodegenCx<'ll, 'tcx> {
35 pub tcx: TyCtxt<'tcx>,
36 pub check_overflow: bool,
37 pub use_dll_storage_attrs: bool,
38 pub tls_model: llvm::ThreadLocalMode,
39
40 pub llmod: &'ll llvm::Module,
41 pub llcx: &'ll llvm::Context,
42 pub codegen_unit: &'tcx CodegenUnit<'tcx>,
43
44 /// Cache instances of monomorphic and polymorphic items
45 pub instances: RefCell<FxHashMap<Instance<'tcx>, &'ll Value>>,
46 /// Cache generated vtables
47 pub vtables:
48 RefCell<FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), &'ll Value>>,
49 /// Cache of constant strings,
50 pub const_cstr_cache: RefCell<FxHashMap<Symbol, &'ll Value>>,
51
52 /// Reverse-direction for const ptrs cast from globals.
53 ///
54 /// Key is a Value holding a `*T`,
55 /// Val is a Value holding a `*[T]`.
56 ///
57 /// Needed because LLVM loses pointer->pointee association
58 /// when we ptrcast, and we have to ptrcast during codegen
59 /// of a `[T]` const because we form a slice, a `(*T,usize)` pair, not
60 /// a pointer to an LLVM array type. Similar for trait objects.
61 pub const_unsized: RefCell<FxHashMap<&'ll Value, &'ll Value>>,
62
63 /// Cache of emitted const globals (value -> global)
64 pub const_globals: RefCell<FxHashMap<&'ll Value, &'ll Value>>,
65
66 /// List of globals for static variables which need to be passed to the
67 /// LLVM function ReplaceAllUsesWith (RAUW) when codegen is complete.
68 /// (We have to make sure we don't invalidate any Values referring
69 /// to constants.)
70 pub statics_to_rauw: RefCell<Vec<(&'ll Value, &'ll Value)>>,
71
72 /// Statics that will be placed in the llvm.used variable
73 /// See <http://llvm.org/docs/LangRef.html#the-llvm-used-global-variable> for details
74 pub used_statics: RefCell<Vec<&'ll Value>>,
75
76 pub lltypes: RefCell<FxHashMap<(Ty<'tcx>, Option<VariantIdx>), &'ll Type>>,
77 pub scalar_lltypes: RefCell<FxHashMap<Ty<'tcx>, &'ll Type>>,
78 pub pointee_infos: RefCell<FxHashMap<(Ty<'tcx>, Size), Option<PointeeInfo>>>,
79 pub isize_ty: &'ll Type,
80
81 pub coverage_cx: Option<coverageinfo::CrateCoverageContext<'tcx>>,
82 pub dbg_cx: Option<debuginfo::CrateDebugContext<'ll, 'tcx>>,
83
84 eh_personality: Cell<Option<&'ll Value>>,
85 eh_catch_typeinfo: Cell<Option<&'ll Value>>,
86 pub rust_try_fn: Cell<Option<&'ll Value>>,
87
88 intrinsics: RefCell<FxHashMap<&'static str, &'ll Value>>,
89
90 /// A counter that is used for generating local symbol names
91 local_gen_sym_counter: Cell<usize>,
92 }
93
94 fn to_llvm_tls_model(tls_model: TlsModel) -> llvm::ThreadLocalMode {
95 match tls_model {
96 TlsModel::GeneralDynamic => llvm::ThreadLocalMode::GeneralDynamic,
97 TlsModel::LocalDynamic => llvm::ThreadLocalMode::LocalDynamic,
98 TlsModel::InitialExec => llvm::ThreadLocalMode::InitialExec,
99 TlsModel::LocalExec => llvm::ThreadLocalMode::LocalExec,
100 }
101 }
102
103 fn strip_x86_address_spaces(data_layout: String) -> String {
104 data_layout.replace("-p270:32:32-p271:32:32-p272:64:64-", "-")
105 }
106
107 pub unsafe fn create_module(
108 tcx: TyCtxt<'_>,
109 llcx: &'ll llvm::Context,
110 mod_name: &str,
111 ) -> &'ll llvm::Module {
112 let sess = tcx.sess;
113 let mod_name = SmallCStr::new(mod_name);
114 let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx);
115
116 let mut target_data_layout = sess.target.data_layout.clone();
117 if llvm_util::get_version() < (10, 0, 0)
118 && (sess.target.arch == "x86" || sess.target.arch == "x86_64")
119 {
120 target_data_layout = strip_x86_address_spaces(target_data_layout);
121 }
122
123 // Ensure the data-layout values hardcoded remain the defaults.
124 if sess.target.is_builtin {
125 let tm = crate::back::write::create_informational_target_machine(tcx.sess);
126 llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, tm);
127 llvm::LLVMRustDisposeTargetMachine(tm);
128
129 let llvm_data_layout = llvm::LLVMGetDataLayoutStr(llmod);
130 let llvm_data_layout = str::from_utf8(CStr::from_ptr(llvm_data_layout).to_bytes())
131 .expect("got a non-UTF8 data-layout from LLVM");
132
133 // Unfortunately LLVM target specs change over time, and right now we
134 // don't have proper support to work with any more than one
135 // `data_layout` than the one that is in the rust-lang/rust repo. If
136 // this compiler is configured against a custom LLVM, we may have a
137 // differing data layout, even though we should update our own to use
138 // that one.
139 //
140 // As an interim hack, if CFG_LLVM_ROOT is not an empty string then we
141 // disable this check entirely as we may be configured with something
142 // that has a different target layout.
143 //
144 // Unsure if this will actually cause breakage when rustc is configured
145 // as such.
146 //
147 // FIXME(#34960)
148 let cfg_llvm_root = option_env!("CFG_LLVM_ROOT").unwrap_or("");
149 let custom_llvm_used = cfg_llvm_root.trim() != "";
150
151 if !custom_llvm_used && target_data_layout != llvm_data_layout {
152 bug!(
153 "data-layout for builtin `{}` target, `{}`, \
154 differs from LLVM default, `{}`",
155 sess.target.llvm_target,
156 target_data_layout,
157 llvm_data_layout
158 );
159 }
160 }
161
162 let data_layout = SmallCStr::new(&target_data_layout);
163 llvm::LLVMSetDataLayout(llmod, data_layout.as_ptr());
164
165 let llvm_target = SmallCStr::new(&sess.target.llvm_target);
166 llvm::LLVMRustSetNormalizedTarget(llmod, llvm_target.as_ptr());
167
168 if sess.relocation_model() == RelocModel::Pic {
169 llvm::LLVMRustSetModulePICLevel(llmod);
170 // PIE is potentially more effective than PIC, but can only be used in executables.
171 // If all our outputs are executables, then we can relax PIC to PIE.
172 if sess.crate_types().iter().all(|ty| *ty == CrateType::Executable) {
173 llvm::LLVMRustSetModulePIELevel(llmod);
174 }
175 }
176
177 // If skipping the PLT is enabled, we need to add some module metadata
178 // to ensure intrinsic calls don't use it.
179 if !sess.needs_plt() {
180 let avoid_plt = "RtLibUseGOT\0".as_ptr().cast();
181 llvm::LLVMRustAddModuleFlag(llmod, avoid_plt, 1);
182 }
183
184 // Control Flow Guard is currently only supported by the MSVC linker on Windows.
185 if sess.target.is_like_msvc {
186 match sess.opts.cg.control_flow_guard {
187 CFGuard::Disabled => {}
188 CFGuard::NoChecks => {
189 // Set `cfguard=1` module flag to emit metadata only.
190 llvm::LLVMRustAddModuleFlag(llmod, "cfguard\0".as_ptr() as *const _, 1)
191 }
192 CFGuard::Checks => {
193 // Set `cfguard=2` module flag to emit metadata and checks.
194 llvm::LLVMRustAddModuleFlag(llmod, "cfguard\0".as_ptr() as *const _, 2)
195 }
196 }
197 }
198
199 llmod
200 }
201
202 impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
203 crate fn new(
204 tcx: TyCtxt<'tcx>,
205 codegen_unit: &'tcx CodegenUnit<'tcx>,
206 llvm_module: &'ll crate::ModuleLlvm,
207 ) -> Self {
208 // An interesting part of Windows which MSVC forces our hand on (and
209 // apparently MinGW didn't) is the usage of `dllimport` and `dllexport`
210 // attributes in LLVM IR as well as native dependencies (in C these
211 // correspond to `__declspec(dllimport)`).
212 //
213 // LD (BFD) in MinGW mode can often correctly guess `dllexport` but
214 // relying on that can result in issues like #50176.
215 // LLD won't support that and expects symbols with proper attributes.
216 // Because of that we make MinGW target emit dllexport just like MSVC.
217 // When it comes to dllimport we use it for constants but for functions
218 // rely on the linker to do the right thing. Opposed to dllexport this
219 // task is easy for them (both LD and LLD) and allows us to easily use
220 // symbols from static libraries in shared libraries.
221 //
222 // Whenever a dynamic library is built on Windows it must have its public
223 // interface specified by functions tagged with `dllexport` or otherwise
224 // they're not available to be linked against. This poses a few problems
225 // for the compiler, some of which are somewhat fundamental, but we use
226 // the `use_dll_storage_attrs` variable below to attach the `dllexport`
227 // attribute to all LLVM functions that are exported e.g., they're
228 // already tagged with external linkage). This is suboptimal for a few
229 // reasons:
230 //
231 // * If an object file will never be included in a dynamic library,
232 // there's no need to attach the dllexport attribute. Most object
233 // files in Rust are not destined to become part of a dll as binaries
234 // are statically linked by default.
235 // * If the compiler is emitting both an rlib and a dylib, the same
236 // source object file is currently used but with MSVC this may be less
237 // feasible. The compiler may be able to get around this, but it may
238 // involve some invasive changes to deal with this.
239 //
240 // The flipside of this situation is that whenever you link to a dll and
241 // you import a function from it, the import should be tagged with
242 // `dllimport`. At this time, however, the compiler does not emit
243 // `dllimport` for any declarations other than constants (where it is
244 // required), which is again suboptimal for even more reasons!
245 //
246 // * Calling a function imported from another dll without using
247 // `dllimport` causes the linker/compiler to have extra overhead (one
248 // `jmp` instruction on x86) when calling the function.
249 // * The same object file may be used in different circumstances, so a
250 // function may be imported from a dll if the object is linked into a
251 // dll, but it may be just linked against if linked into an rlib.
252 // * The compiler has no knowledge about whether native functions should
253 // be tagged dllimport or not.
254 //
255 // For now the compiler takes the perf hit (I do not have any numbers to
256 // this effect) by marking very little as `dllimport` and praying the
257 // linker will take care of everything. Fixing this problem will likely
258 // require adding a few attributes to Rust itself (feature gated at the
259 // start) and then strongly recommending static linkage on Windows!
260 let use_dll_storage_attrs = tcx.sess.target.is_like_windows;
261
262 let check_overflow = tcx.sess.overflow_checks();
263
264 let tls_model = to_llvm_tls_model(tcx.sess.tls_model());
265
266 let (llcx, llmod) = (&*llvm_module.llcx, llvm_module.llmod());
267
268 let coverage_cx = if tcx.sess.opts.debugging_opts.instrument_coverage {
269 let covctx = coverageinfo::CrateCoverageContext::new();
270 Some(covctx)
271 } else {
272 None
273 };
274
275 let dbg_cx = if tcx.sess.opts.debuginfo != DebugInfo::None {
276 let dctx = debuginfo::CrateDebugContext::new(llmod);
277 debuginfo::metadata::compile_unit_metadata(tcx, &codegen_unit.name().as_str(), &dctx);
278 Some(dctx)
279 } else {
280 None
281 };
282
283 let isize_ty = Type::ix_llcx(llcx, tcx.data_layout.pointer_size.bits());
284
285 CodegenCx {
286 tcx,
287 check_overflow,
288 use_dll_storage_attrs,
289 tls_model,
290 llmod,
291 llcx,
292 codegen_unit,
293 instances: Default::default(),
294 vtables: Default::default(),
295 const_cstr_cache: Default::default(),
296 const_unsized: Default::default(),
297 const_globals: Default::default(),
298 statics_to_rauw: RefCell::new(Vec::new()),
299 used_statics: RefCell::new(Vec::new()),
300 lltypes: Default::default(),
301 scalar_lltypes: Default::default(),
302 pointee_infos: Default::default(),
303 isize_ty,
304 coverage_cx,
305 dbg_cx,
306 eh_personality: Cell::new(None),
307 eh_catch_typeinfo: Cell::new(None),
308 rust_try_fn: Cell::new(None),
309 intrinsics: Default::default(),
310 local_gen_sym_counter: Cell::new(0),
311 }
312 }
313
314 crate fn statics_to_rauw(&self) -> &RefCell<Vec<(&'ll Value, &'ll Value)>> {
315 &self.statics_to_rauw
316 }
317
318 #[inline]
319 pub fn coverage_context(&'a self) -> Option<&'a coverageinfo::CrateCoverageContext<'tcx>> {
320 self.coverage_cx.as_ref()
321 }
322 }
323
324 impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
325 fn vtables(
326 &self,
327 ) -> &RefCell<FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), &'ll Value>>
328 {
329 &self.vtables
330 }
331
332 fn get_fn(&self, instance: Instance<'tcx>) -> &'ll Value {
333 get_fn(self, instance)
334 }
335
336 fn get_fn_addr(&self, instance: Instance<'tcx>) -> &'ll Value {
337 get_fn(self, instance)
338 }
339
340 fn eh_personality(&self) -> &'ll Value {
341 // The exception handling personality function.
342 //
343 // If our compilation unit has the `eh_personality` lang item somewhere
344 // within it, then we just need to codegen that. Otherwise, we're
345 // building an rlib which will depend on some upstream implementation of
346 // this function, so we just codegen a generic reference to it. We don't
347 // specify any of the types for the function, we just make it a symbol
348 // that LLVM can later use.
349 //
350 // Note that MSVC is a little special here in that we don't use the
351 // `eh_personality` lang item at all. Currently LLVM has support for
352 // both Dwarf and SEH unwind mechanisms for MSVC targets and uses the
353 // *name of the personality function* to decide what kind of unwind side
354 // tables/landing pads to emit. It looks like Dwarf is used by default,
355 // injecting a dependency on the `_Unwind_Resume` symbol for resuming
356 // an "exception", but for MSVC we want to force SEH. This means that we
357 // can't actually have the personality function be our standard
358 // `rust_eh_personality` function, but rather we wired it up to the
359 // CRT's custom personality function, which forces LLVM to consider
360 // landing pads as "landing pads for SEH".
361 if let Some(llpersonality) = self.eh_personality.get() {
362 return llpersonality;
363 }
364 let tcx = self.tcx;
365 let llfn = match tcx.lang_items().eh_personality() {
366 Some(def_id) if !wants_msvc_seh(self.sess()) => self.get_fn_addr(
367 ty::Instance::resolve(
368 tcx,
369 ty::ParamEnv::reveal_all(),
370 def_id,
371 tcx.intern_substs(&[]),
372 )
373 .unwrap()
374 .unwrap(),
375 ),
376 _ => {
377 let name = if wants_msvc_seh(self.sess()) {
378 "__CxxFrameHandler3"
379 } else {
380 "rust_eh_personality"
381 };
382 let fty = self.type_variadic_func(&[], self.type_i32());
383 self.declare_cfn(name, fty)
384 }
385 };
386 attributes::apply_target_cpu_attr(self, llfn);
387 self.eh_personality.set(Some(llfn));
388 llfn
389 }
390
391 fn sess(&self) -> &Session {
392 &self.tcx.sess
393 }
394
395 fn check_overflow(&self) -> bool {
396 self.check_overflow
397 }
398
399 fn codegen_unit(&self) -> &'tcx CodegenUnit<'tcx> {
400 self.codegen_unit
401 }
402
403 fn used_statics(&self) -> &RefCell<Vec<&'ll Value>> {
404 &self.used_statics
405 }
406
407 fn set_frame_pointer_elimination(&self, llfn: &'ll Value) {
408 attributes::set_frame_pointer_elimination(self, llfn)
409 }
410
411 fn apply_target_cpu_attr(&self, llfn: &'ll Value) {
412 attributes::apply_target_cpu_attr(self, llfn);
413 attributes::apply_tune_cpu_attr(self, llfn);
414 }
415
416 fn create_used_variable(&self) {
417 let name = const_cstr!("llvm.used");
418 let section = const_cstr!("llvm.metadata");
419 let array =
420 self.const_array(&self.type_ptr_to(self.type_i8()), &*self.used_statics.borrow());
421
422 unsafe {
423 let g = llvm::LLVMAddGlobal(self.llmod, self.val_ty(array), name.as_ptr());
424 llvm::LLVMSetInitializer(g, array);
425 llvm::LLVMRustSetLinkage(g, llvm::Linkage::AppendingLinkage);
426 llvm::LLVMSetSection(g, section.as_ptr());
427 }
428 }
429
430 fn declare_c_main(&self, fn_type: Self::Type) -> Option<Self::Function> {
431 if self.get_declared_value("main").is_none() {
432 Some(self.declare_cfn("main", fn_type))
433 } else {
434 // If the symbol already exists, it is an error: for example, the user wrote
435 // #[no_mangle] extern "C" fn main(..) {..}
436 // instead of #[start]
437 None
438 }
439 }
440 }
441
442 impl CodegenCx<'b, 'tcx> {
443 crate fn get_intrinsic(&self, key: &str) -> &'b Value {
444 if let Some(v) = self.intrinsics.borrow().get(key).cloned() {
445 return v;
446 }
447
448 self.declare_intrinsic(key).unwrap_or_else(|| bug!("unknown intrinsic '{}'", key))
449 }
450
451 fn insert_intrinsic(
452 &self,
453 name: &'static str,
454 args: Option<&[&'b llvm::Type]>,
455 ret: &'b llvm::Type,
456 ) -> &'b llvm::Value {
457 let fn_ty = if let Some(args) = args {
458 self.type_func(args, ret)
459 } else {
460 self.type_variadic_func(&[], ret)
461 };
462 let f = self.declare_cfn(name, fn_ty);
463 llvm::SetUnnamedAddress(f, llvm::UnnamedAddr::No);
464 self.intrinsics.borrow_mut().insert(name, f);
465 f
466 }
467
468 fn declare_intrinsic(&self, key: &str) -> Option<&'b Value> {
469 macro_rules! ifn {
470 ($name:expr, fn() -> $ret:expr) => (
471 if key == $name {
472 return Some(self.insert_intrinsic($name, Some(&[]), $ret));
473 }
474 );
475 ($name:expr, fn(...) -> $ret:expr) => (
476 if key == $name {
477 return Some(self.insert_intrinsic($name, None, $ret));
478 }
479 );
480 ($name:expr, fn($($arg:expr),*) -> $ret:expr) => (
481 if key == $name {
482 return Some(self.insert_intrinsic($name, Some(&[$($arg),*]), $ret));
483 }
484 );
485 }
486 macro_rules! mk_struct {
487 ($($field_ty:expr),*) => (self.type_struct( &[$($field_ty),*], false))
488 }
489
490 let i8p = self.type_i8p();
491 let void = self.type_void();
492 let i1 = self.type_i1();
493 let t_i8 = self.type_i8();
494 let t_i16 = self.type_i16();
495 let t_i32 = self.type_i32();
496 let t_i64 = self.type_i64();
497 let t_i128 = self.type_i128();
498 let t_f32 = self.type_f32();
499 let t_f64 = self.type_f64();
500
501 macro_rules! vector_types {
502 ($id_out:ident: $elem_ty:ident, $len:expr) => {
503 let $id_out = self.type_vector($elem_ty, $len);
504 };
505 ($($id_out:ident: $elem_ty:ident, $len:expr;)*) => {
506 $(vector_types!($id_out: $elem_ty, $len);)*
507 }
508 }
509 vector_types! {
510 t_v2f32: t_f32, 2;
511 t_v4f32: t_f32, 4;
512 t_v8f32: t_f32, 8;
513 t_v16f32: t_f32, 16;
514
515 t_v2f64: t_f64, 2;
516 t_v4f64: t_f64, 4;
517 t_v8f64: t_f64, 8;
518 }
519
520 ifn!("llvm.wasm.trunc.saturate.unsigned.i32.f32", fn(t_f32) -> t_i32);
521 ifn!("llvm.wasm.trunc.saturate.unsigned.i32.f64", fn(t_f64) -> t_i32);
522 ifn!("llvm.wasm.trunc.saturate.unsigned.i64.f32", fn(t_f32) -> t_i64);
523 ifn!("llvm.wasm.trunc.saturate.unsigned.i64.f64", fn(t_f64) -> t_i64);
524 ifn!("llvm.wasm.trunc.saturate.signed.i32.f32", fn(t_f32) -> t_i32);
525 ifn!("llvm.wasm.trunc.saturate.signed.i32.f64", fn(t_f64) -> t_i32);
526 ifn!("llvm.wasm.trunc.saturate.signed.i64.f32", fn(t_f32) -> t_i64);
527 ifn!("llvm.wasm.trunc.saturate.signed.i64.f64", fn(t_f64) -> t_i64);
528 ifn!("llvm.wasm.trunc.unsigned.i32.f32", fn(t_f32) -> t_i32);
529 ifn!("llvm.wasm.trunc.unsigned.i32.f64", fn(t_f64) -> t_i32);
530 ifn!("llvm.wasm.trunc.unsigned.i64.f32", fn(t_f32) -> t_i64);
531 ifn!("llvm.wasm.trunc.unsigned.i64.f64", fn(t_f64) -> t_i64);
532 ifn!("llvm.wasm.trunc.signed.i32.f32", fn(t_f32) -> t_i32);
533 ifn!("llvm.wasm.trunc.signed.i32.f64", fn(t_f64) -> t_i32);
534 ifn!("llvm.wasm.trunc.signed.i64.f32", fn(t_f32) -> t_i64);
535 ifn!("llvm.wasm.trunc.signed.i64.f64", fn(t_f64) -> t_i64);
536
537 ifn!("llvm.trap", fn() -> void);
538 ifn!("llvm.debugtrap", fn() -> void);
539 ifn!("llvm.frameaddress", fn(t_i32) -> i8p);
540 ifn!("llvm.sideeffect", fn() -> void);
541
542 ifn!("llvm.powi.f32", fn(t_f32, t_i32) -> t_f32);
543 ifn!("llvm.powi.v2f32", fn(t_v2f32, t_i32) -> t_v2f32);
544 ifn!("llvm.powi.v4f32", fn(t_v4f32, t_i32) -> t_v4f32);
545 ifn!("llvm.powi.v8f32", fn(t_v8f32, t_i32) -> t_v8f32);
546 ifn!("llvm.powi.v16f32", fn(t_v16f32, t_i32) -> t_v16f32);
547 ifn!("llvm.powi.f64", fn(t_f64, t_i32) -> t_f64);
548 ifn!("llvm.powi.v2f64", fn(t_v2f64, t_i32) -> t_v2f64);
549 ifn!("llvm.powi.v4f64", fn(t_v4f64, t_i32) -> t_v4f64);
550 ifn!("llvm.powi.v8f64", fn(t_v8f64, t_i32) -> t_v8f64);
551
552 ifn!("llvm.pow.f32", fn(t_f32, t_f32) -> t_f32);
553 ifn!("llvm.pow.v2f32", fn(t_v2f32, t_v2f32) -> t_v2f32);
554 ifn!("llvm.pow.v4f32", fn(t_v4f32, t_v4f32) -> t_v4f32);
555 ifn!("llvm.pow.v8f32", fn(t_v8f32, t_v8f32) -> t_v8f32);
556 ifn!("llvm.pow.v16f32", fn(t_v16f32, t_v16f32) -> t_v16f32);
557 ifn!("llvm.pow.f64", fn(t_f64, t_f64) -> t_f64);
558 ifn!("llvm.pow.v2f64", fn(t_v2f64, t_v2f64) -> t_v2f64);
559 ifn!("llvm.pow.v4f64", fn(t_v4f64, t_v4f64) -> t_v4f64);
560 ifn!("llvm.pow.v8f64", fn(t_v8f64, t_v8f64) -> t_v8f64);
561
562 ifn!("llvm.sqrt.f32", fn(t_f32) -> t_f32);
563 ifn!("llvm.sqrt.v2f32", fn(t_v2f32) -> t_v2f32);
564 ifn!("llvm.sqrt.v4f32", fn(t_v4f32) -> t_v4f32);
565 ifn!("llvm.sqrt.v8f32", fn(t_v8f32) -> t_v8f32);
566 ifn!("llvm.sqrt.v16f32", fn(t_v16f32) -> t_v16f32);
567 ifn!("llvm.sqrt.f64", fn(t_f64) -> t_f64);
568 ifn!("llvm.sqrt.v2f64", fn(t_v2f64) -> t_v2f64);
569 ifn!("llvm.sqrt.v4f64", fn(t_v4f64) -> t_v4f64);
570 ifn!("llvm.sqrt.v8f64", fn(t_v8f64) -> t_v8f64);
571
572 ifn!("llvm.sin.f32", fn(t_f32) -> t_f32);
573 ifn!("llvm.sin.v2f32", fn(t_v2f32) -> t_v2f32);
574 ifn!("llvm.sin.v4f32", fn(t_v4f32) -> t_v4f32);
575 ifn!("llvm.sin.v8f32", fn(t_v8f32) -> t_v8f32);
576 ifn!("llvm.sin.v16f32", fn(t_v16f32) -> t_v16f32);
577 ifn!("llvm.sin.f64", fn(t_f64) -> t_f64);
578 ifn!("llvm.sin.v2f64", fn(t_v2f64) -> t_v2f64);
579 ifn!("llvm.sin.v4f64", fn(t_v4f64) -> t_v4f64);
580 ifn!("llvm.sin.v8f64", fn(t_v8f64) -> t_v8f64);
581
582 ifn!("llvm.cos.f32", fn(t_f32) -> t_f32);
583 ifn!("llvm.cos.v2f32", fn(t_v2f32) -> t_v2f32);
584 ifn!("llvm.cos.v4f32", fn(t_v4f32) -> t_v4f32);
585 ifn!("llvm.cos.v8f32", fn(t_v8f32) -> t_v8f32);
586 ifn!("llvm.cos.v16f32", fn(t_v16f32) -> t_v16f32);
587 ifn!("llvm.cos.f64", fn(t_f64) -> t_f64);
588 ifn!("llvm.cos.v2f64", fn(t_v2f64) -> t_v2f64);
589 ifn!("llvm.cos.v4f64", fn(t_v4f64) -> t_v4f64);
590 ifn!("llvm.cos.v8f64", fn(t_v8f64) -> t_v8f64);
591
592 ifn!("llvm.exp.f32", fn(t_f32) -> t_f32);
593 ifn!("llvm.exp.v2f32", fn(t_v2f32) -> t_v2f32);
594 ifn!("llvm.exp.v4f32", fn(t_v4f32) -> t_v4f32);
595 ifn!("llvm.exp.v8f32", fn(t_v8f32) -> t_v8f32);
596 ifn!("llvm.exp.v16f32", fn(t_v16f32) -> t_v16f32);
597 ifn!("llvm.exp.f64", fn(t_f64) -> t_f64);
598 ifn!("llvm.exp.v2f64", fn(t_v2f64) -> t_v2f64);
599 ifn!("llvm.exp.v4f64", fn(t_v4f64) -> t_v4f64);
600 ifn!("llvm.exp.v8f64", fn(t_v8f64) -> t_v8f64);
601
602 ifn!("llvm.exp2.f32", fn(t_f32) -> t_f32);
603 ifn!("llvm.exp2.v2f32", fn(t_v2f32) -> t_v2f32);
604 ifn!("llvm.exp2.v4f32", fn(t_v4f32) -> t_v4f32);
605 ifn!("llvm.exp2.v8f32", fn(t_v8f32) -> t_v8f32);
606 ifn!("llvm.exp2.v16f32", fn(t_v16f32) -> t_v16f32);
607 ifn!("llvm.exp2.f64", fn(t_f64) -> t_f64);
608 ifn!("llvm.exp2.v2f64", fn(t_v2f64) -> t_v2f64);
609 ifn!("llvm.exp2.v4f64", fn(t_v4f64) -> t_v4f64);
610 ifn!("llvm.exp2.v8f64", fn(t_v8f64) -> t_v8f64);
611
612 ifn!("llvm.log.f32", fn(t_f32) -> t_f32);
613 ifn!("llvm.log.v2f32", fn(t_v2f32) -> t_v2f32);
614 ifn!("llvm.log.v4f32", fn(t_v4f32) -> t_v4f32);
615 ifn!("llvm.log.v8f32", fn(t_v8f32) -> t_v8f32);
616 ifn!("llvm.log.v16f32", fn(t_v16f32) -> t_v16f32);
617 ifn!("llvm.log.f64", fn(t_f64) -> t_f64);
618 ifn!("llvm.log.v2f64", fn(t_v2f64) -> t_v2f64);
619 ifn!("llvm.log.v4f64", fn(t_v4f64) -> t_v4f64);
620 ifn!("llvm.log.v8f64", fn(t_v8f64) -> t_v8f64);
621
622 ifn!("llvm.log10.f32", fn(t_f32) -> t_f32);
623 ifn!("llvm.log10.v2f32", fn(t_v2f32) -> t_v2f32);
624 ifn!("llvm.log10.v4f32", fn(t_v4f32) -> t_v4f32);
625 ifn!("llvm.log10.v8f32", fn(t_v8f32) -> t_v8f32);
626 ifn!("llvm.log10.v16f32", fn(t_v16f32) -> t_v16f32);
627 ifn!("llvm.log10.f64", fn(t_f64) -> t_f64);
628 ifn!("llvm.log10.v2f64", fn(t_v2f64) -> t_v2f64);
629 ifn!("llvm.log10.v4f64", fn(t_v4f64) -> t_v4f64);
630 ifn!("llvm.log10.v8f64", fn(t_v8f64) -> t_v8f64);
631
632 ifn!("llvm.log2.f32", fn(t_f32) -> t_f32);
633 ifn!("llvm.log2.v2f32", fn(t_v2f32) -> t_v2f32);
634 ifn!("llvm.log2.v4f32", fn(t_v4f32) -> t_v4f32);
635 ifn!("llvm.log2.v8f32", fn(t_v8f32) -> t_v8f32);
636 ifn!("llvm.log2.v16f32", fn(t_v16f32) -> t_v16f32);
637 ifn!("llvm.log2.f64", fn(t_f64) -> t_f64);
638 ifn!("llvm.log2.v2f64", fn(t_v2f64) -> t_v2f64);
639 ifn!("llvm.log2.v4f64", fn(t_v4f64) -> t_v4f64);
640 ifn!("llvm.log2.v8f64", fn(t_v8f64) -> t_v8f64);
641
642 ifn!("llvm.fma.f32", fn(t_f32, t_f32, t_f32) -> t_f32);
643 ifn!("llvm.fma.v2f32", fn(t_v2f32, t_v2f32, t_v2f32) -> t_v2f32);
644 ifn!("llvm.fma.v4f32", fn(t_v4f32, t_v4f32, t_v4f32) -> t_v4f32);
645 ifn!("llvm.fma.v8f32", fn(t_v8f32, t_v8f32, t_v8f32) -> t_v8f32);
646 ifn!("llvm.fma.v16f32", fn(t_v16f32, t_v16f32, t_v16f32) -> t_v16f32);
647 ifn!("llvm.fma.f64", fn(t_f64, t_f64, t_f64) -> t_f64);
648 ifn!("llvm.fma.v2f64", fn(t_v2f64, t_v2f64, t_v2f64) -> t_v2f64);
649 ifn!("llvm.fma.v4f64", fn(t_v4f64, t_v4f64, t_v4f64) -> t_v4f64);
650 ifn!("llvm.fma.v8f64", fn(t_v8f64, t_v8f64, t_v8f64) -> t_v8f64);
651
652 ifn!("llvm.fabs.f32", fn(t_f32) -> t_f32);
653 ifn!("llvm.fabs.v2f32", fn(t_v2f32) -> t_v2f32);
654 ifn!("llvm.fabs.v4f32", fn(t_v4f32) -> t_v4f32);
655 ifn!("llvm.fabs.v8f32", fn(t_v8f32) -> t_v8f32);
656 ifn!("llvm.fabs.v16f32", fn(t_v16f32) -> t_v16f32);
657 ifn!("llvm.fabs.f64", fn(t_f64) -> t_f64);
658 ifn!("llvm.fabs.v2f64", fn(t_v2f64) -> t_v2f64);
659 ifn!("llvm.fabs.v4f64", fn(t_v4f64) -> t_v4f64);
660 ifn!("llvm.fabs.v8f64", fn(t_v8f64) -> t_v8f64);
661
662 ifn!("llvm.minnum.f32", fn(t_f32, t_f32) -> t_f32);
663 ifn!("llvm.minnum.f64", fn(t_f64, t_f64) -> t_f64);
664 ifn!("llvm.maxnum.f32", fn(t_f32, t_f32) -> t_f32);
665 ifn!("llvm.maxnum.f64", fn(t_f64, t_f64) -> t_f64);
666
667 ifn!("llvm.floor.f32", fn(t_f32) -> t_f32);
668 ifn!("llvm.floor.v2f32", fn(t_v2f32) -> t_v2f32);
669 ifn!("llvm.floor.v4f32", fn(t_v4f32) -> t_v4f32);
670 ifn!("llvm.floor.v8f32", fn(t_v8f32) -> t_v8f32);
671 ifn!("llvm.floor.v16f32", fn(t_v16f32) -> t_v16f32);
672 ifn!("llvm.floor.f64", fn(t_f64) -> t_f64);
673 ifn!("llvm.floor.v2f64", fn(t_v2f64) -> t_v2f64);
674 ifn!("llvm.floor.v4f64", fn(t_v4f64) -> t_v4f64);
675 ifn!("llvm.floor.v8f64", fn(t_v8f64) -> t_v8f64);
676
677 ifn!("llvm.ceil.f32", fn(t_f32) -> t_f32);
678 ifn!("llvm.ceil.v2f32", fn(t_v2f32) -> t_v2f32);
679 ifn!("llvm.ceil.v4f32", fn(t_v4f32) -> t_v4f32);
680 ifn!("llvm.ceil.v8f32", fn(t_v8f32) -> t_v8f32);
681 ifn!("llvm.ceil.v16f32", fn(t_v16f32) -> t_v16f32);
682 ifn!("llvm.ceil.f64", fn(t_f64) -> t_f64);
683 ifn!("llvm.ceil.v2f64", fn(t_v2f64) -> t_v2f64);
684 ifn!("llvm.ceil.v4f64", fn(t_v4f64) -> t_v4f64);
685 ifn!("llvm.ceil.v8f64", fn(t_v8f64) -> t_v8f64);
686
687 ifn!("llvm.trunc.f32", fn(t_f32) -> t_f32);
688 ifn!("llvm.trunc.f64", fn(t_f64) -> t_f64);
689
690 ifn!("llvm.copysign.f32", fn(t_f32, t_f32) -> t_f32);
691 ifn!("llvm.copysign.f64", fn(t_f64, t_f64) -> t_f64);
692 ifn!("llvm.round.f32", fn(t_f32) -> t_f32);
693 ifn!("llvm.round.f64", fn(t_f64) -> t_f64);
694
695 ifn!("llvm.rint.f32", fn(t_f32) -> t_f32);
696 ifn!("llvm.rint.f64", fn(t_f64) -> t_f64);
697 ifn!("llvm.nearbyint.f32", fn(t_f32) -> t_f32);
698 ifn!("llvm.nearbyint.f64", fn(t_f64) -> t_f64);
699
700 ifn!("llvm.ctpop.i8", fn(t_i8) -> t_i8);
701 ifn!("llvm.ctpop.i16", fn(t_i16) -> t_i16);
702 ifn!("llvm.ctpop.i32", fn(t_i32) -> t_i32);
703 ifn!("llvm.ctpop.i64", fn(t_i64) -> t_i64);
704 ifn!("llvm.ctpop.i128", fn(t_i128) -> t_i128);
705
706 ifn!("llvm.ctlz.i8", fn(t_i8, i1) -> t_i8);
707 ifn!("llvm.ctlz.i16", fn(t_i16, i1) -> t_i16);
708 ifn!("llvm.ctlz.i32", fn(t_i32, i1) -> t_i32);
709 ifn!("llvm.ctlz.i64", fn(t_i64, i1) -> t_i64);
710 ifn!("llvm.ctlz.i128", fn(t_i128, i1) -> t_i128);
711
712 ifn!("llvm.cttz.i8", fn(t_i8, i1) -> t_i8);
713 ifn!("llvm.cttz.i16", fn(t_i16, i1) -> t_i16);
714 ifn!("llvm.cttz.i32", fn(t_i32, i1) -> t_i32);
715 ifn!("llvm.cttz.i64", fn(t_i64, i1) -> t_i64);
716 ifn!("llvm.cttz.i128", fn(t_i128, i1) -> t_i128);
717
718 ifn!("llvm.bswap.i16", fn(t_i16) -> t_i16);
719 ifn!("llvm.bswap.i32", fn(t_i32) -> t_i32);
720 ifn!("llvm.bswap.i64", fn(t_i64) -> t_i64);
721 ifn!("llvm.bswap.i128", fn(t_i128) -> t_i128);
722
723 ifn!("llvm.bitreverse.i8", fn(t_i8) -> t_i8);
724 ifn!("llvm.bitreverse.i16", fn(t_i16) -> t_i16);
725 ifn!("llvm.bitreverse.i32", fn(t_i32) -> t_i32);
726 ifn!("llvm.bitreverse.i64", fn(t_i64) -> t_i64);
727 ifn!("llvm.bitreverse.i128", fn(t_i128) -> t_i128);
728
729 ifn!("llvm.fshl.i8", fn(t_i8, t_i8, t_i8) -> t_i8);
730 ifn!("llvm.fshl.i16", fn(t_i16, t_i16, t_i16) -> t_i16);
731 ifn!("llvm.fshl.i32", fn(t_i32, t_i32, t_i32) -> t_i32);
732 ifn!("llvm.fshl.i64", fn(t_i64, t_i64, t_i64) -> t_i64);
733 ifn!("llvm.fshl.i128", fn(t_i128, t_i128, t_i128) -> t_i128);
734
735 ifn!("llvm.fshr.i8", fn(t_i8, t_i8, t_i8) -> t_i8);
736 ifn!("llvm.fshr.i16", fn(t_i16, t_i16, t_i16) -> t_i16);
737 ifn!("llvm.fshr.i32", fn(t_i32, t_i32, t_i32) -> t_i32);
738 ifn!("llvm.fshr.i64", fn(t_i64, t_i64, t_i64) -> t_i64);
739 ifn!("llvm.fshr.i128", fn(t_i128, t_i128, t_i128) -> t_i128);
740
741 ifn!("llvm.sadd.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct! {t_i8, i1});
742 ifn!("llvm.sadd.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct! {t_i16, i1});
743 ifn!("llvm.sadd.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct! {t_i32, i1});
744 ifn!("llvm.sadd.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct! {t_i64, i1});
745 ifn!("llvm.sadd.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct! {t_i128, i1});
746
747 ifn!("llvm.uadd.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct! {t_i8, i1});
748 ifn!("llvm.uadd.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct! {t_i16, i1});
749 ifn!("llvm.uadd.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct! {t_i32, i1});
750 ifn!("llvm.uadd.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct! {t_i64, i1});
751 ifn!("llvm.uadd.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct! {t_i128, i1});
752
753 ifn!("llvm.ssub.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct! {t_i8, i1});
754 ifn!("llvm.ssub.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct! {t_i16, i1});
755 ifn!("llvm.ssub.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct! {t_i32, i1});
756 ifn!("llvm.ssub.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct! {t_i64, i1});
757 ifn!("llvm.ssub.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct! {t_i128, i1});
758
759 ifn!("llvm.usub.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct! {t_i8, i1});
760 ifn!("llvm.usub.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct! {t_i16, i1});
761 ifn!("llvm.usub.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct! {t_i32, i1});
762 ifn!("llvm.usub.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct! {t_i64, i1});
763 ifn!("llvm.usub.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct! {t_i128, i1});
764
765 ifn!("llvm.smul.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct! {t_i8, i1});
766 ifn!("llvm.smul.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct! {t_i16, i1});
767 ifn!("llvm.smul.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct! {t_i32, i1});
768 ifn!("llvm.smul.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct! {t_i64, i1});
769 ifn!("llvm.smul.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct! {t_i128, i1});
770
771 ifn!("llvm.umul.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct! {t_i8, i1});
772 ifn!("llvm.umul.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct! {t_i16, i1});
773 ifn!("llvm.umul.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct! {t_i32, i1});
774 ifn!("llvm.umul.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct! {t_i64, i1});
775 ifn!("llvm.umul.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct! {t_i128, i1});
776
777 ifn!("llvm.sadd.sat.i8", fn(t_i8, t_i8) -> t_i8);
778 ifn!("llvm.sadd.sat.i16", fn(t_i16, t_i16) -> t_i16);
779 ifn!("llvm.sadd.sat.i32", fn(t_i32, t_i32) -> t_i32);
780 ifn!("llvm.sadd.sat.i64", fn(t_i64, t_i64) -> t_i64);
781 ifn!("llvm.sadd.sat.i128", fn(t_i128, t_i128) -> t_i128);
782
783 ifn!("llvm.uadd.sat.i8", fn(t_i8, t_i8) -> t_i8);
784 ifn!("llvm.uadd.sat.i16", fn(t_i16, t_i16) -> t_i16);
785 ifn!("llvm.uadd.sat.i32", fn(t_i32, t_i32) -> t_i32);
786 ifn!("llvm.uadd.sat.i64", fn(t_i64, t_i64) -> t_i64);
787 ifn!("llvm.uadd.sat.i128", fn(t_i128, t_i128) -> t_i128);
788
789 ifn!("llvm.ssub.sat.i8", fn(t_i8, t_i8) -> t_i8);
790 ifn!("llvm.ssub.sat.i16", fn(t_i16, t_i16) -> t_i16);
791 ifn!("llvm.ssub.sat.i32", fn(t_i32, t_i32) -> t_i32);
792 ifn!("llvm.ssub.sat.i64", fn(t_i64, t_i64) -> t_i64);
793 ifn!("llvm.ssub.sat.i128", fn(t_i128, t_i128) -> t_i128);
794
795 ifn!("llvm.usub.sat.i8", fn(t_i8, t_i8) -> t_i8);
796 ifn!("llvm.usub.sat.i16", fn(t_i16, t_i16) -> t_i16);
797 ifn!("llvm.usub.sat.i32", fn(t_i32, t_i32) -> t_i32);
798 ifn!("llvm.usub.sat.i64", fn(t_i64, t_i64) -> t_i64);
799 ifn!("llvm.usub.sat.i128", fn(t_i128, t_i128) -> t_i128);
800
801 ifn!("llvm.lifetime.start.p0i8", fn(t_i64, i8p) -> void);
802 ifn!("llvm.lifetime.end.p0i8", fn(t_i64, i8p) -> void);
803
804 ifn!("llvm.expect.i1", fn(i1, i1) -> i1);
805 ifn!("llvm.eh.typeid.for", fn(i8p) -> t_i32);
806 ifn!("llvm.localescape", fn(...) -> void);
807 ifn!("llvm.localrecover", fn(i8p, i8p, t_i32) -> i8p);
808 ifn!("llvm.x86.seh.recoverfp", fn(i8p, i8p) -> i8p);
809
810 ifn!("llvm.assume", fn(i1) -> void);
811 ifn!("llvm.prefetch", fn(i8p, t_i32, t_i32, t_i32) -> void);
812
813 // variadic intrinsics
814 ifn!("llvm.va_start", fn(i8p) -> void);
815 ifn!("llvm.va_end", fn(i8p) -> void);
816 ifn!("llvm.va_copy", fn(i8p, i8p) -> void);
817
818 if self.sess().opts.debugging_opts.instrument_coverage {
819 ifn!("llvm.instrprof.increment", fn(i8p, t_i64, t_i32, t_i32) -> void);
820 }
821
822 if self.sess().opts.debuginfo != DebugInfo::None {
823 ifn!("llvm.dbg.declare", fn(self.type_metadata(), self.type_metadata()) -> void);
824 ifn!("llvm.dbg.value", fn(self.type_metadata(), t_i64, self.type_metadata()) -> void);
825 }
826 None
827 }
828
829 crate fn eh_catch_typeinfo(&self) -> &'b Value {
830 if let Some(eh_catch_typeinfo) = self.eh_catch_typeinfo.get() {
831 return eh_catch_typeinfo;
832 }
833 let tcx = self.tcx;
834 assert!(self.sess().target.is_like_emscripten);
835 let eh_catch_typeinfo = match tcx.lang_items().eh_catch_typeinfo() {
836 Some(def_id) => self.get_static(def_id),
837 _ => {
838 let ty = self
839 .type_struct(&[self.type_ptr_to(self.type_isize()), self.type_i8p()], false);
840 self.declare_global("rust_eh_catch_typeinfo", ty)
841 }
842 };
843 let eh_catch_typeinfo = self.const_bitcast(eh_catch_typeinfo, self.type_i8p());
844 self.eh_catch_typeinfo.set(Some(eh_catch_typeinfo));
845 eh_catch_typeinfo
846 }
847 }
848
849 impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
850 /// Generates a new symbol name with the given prefix. This symbol name must
851 /// only be used for definitions with `internal` or `private` linkage.
852 pub fn generate_local_symbol_name(&self, prefix: &str) -> String {
853 let idx = self.local_gen_sym_counter.get();
854 self.local_gen_sym_counter.set(idx + 1);
855 // Include a '.' character, so there can be no accidental conflicts with
856 // user defined names
857 let mut name = String::with_capacity(prefix.len() + 6);
858 name.push_str(prefix);
859 name.push('.');
860 base_n::push_str(idx as u128, base_n::ALPHANUMERIC_ONLY, &mut name);
861 name
862 }
863 }
864
865 impl HasDataLayout for CodegenCx<'ll, 'tcx> {
866 fn data_layout(&self) -> &TargetDataLayout {
867 &self.tcx.data_layout
868 }
869 }
870
871 impl HasTargetSpec for CodegenCx<'ll, 'tcx> {
872 fn target_spec(&self) -> &Target {
873 &self.tcx.sess.target
874 }
875 }
876
877 impl ty::layout::HasTyCtxt<'tcx> for CodegenCx<'ll, 'tcx> {
878 fn tcx(&self) -> TyCtxt<'tcx> {
879 self.tcx
880 }
881 }
882
883 impl LayoutOf for CodegenCx<'ll, 'tcx> {
884 type Ty = Ty<'tcx>;
885 type TyAndLayout = TyAndLayout<'tcx>;
886
887 fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout {
888 self.spanned_layout_of(ty, DUMMY_SP)
889 }
890
891 fn spanned_layout_of(&self, ty: Ty<'tcx>, span: Span) -> Self::TyAndLayout {
892 self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)).unwrap_or_else(|e| {
893 if let LayoutError::SizeOverflow(_) = e {
894 self.sess().span_fatal(span, &e.to_string())
895 } else {
896 bug!("failed to get layout for `{}`: {}", ty, e)
897 }
898 })
899 }
900 }
901
902 impl<'tcx, 'll> HasParamEnv<'tcx> for CodegenCx<'ll, 'tcx> {
903 fn param_env(&self) -> ty::ParamEnv<'tcx> {
904 ty::ParamEnv::reveal_all()
905 }
906 }