| 89 | |
| 90 | impl<'tcx> CodegenCx<'tcx> { |
| 91 | pub fn new(tcx: TyCtxt<'tcx>, codegen_unit: &'tcx CodegenUnit<'tcx>) -> Self { |
| 92 | let sym = Symbols::get(); |
| 93 | |
| 94 | let mut feature_names = tcx |
| 95 | .sess |
| 96 | .target_features |
| 97 | .iter() |
| 98 | .map(|s| s.as_str()) |
| 99 | .collect::<Vec<_>>(); |
| 100 | |
| 101 | // target_features is a HashSet, not a Vec, so we need to sort to have deterministic |
| 102 | // compilation - otherwise, the order of capabilities in binaries depends on the iteration |
| 103 | // order of the hashset. Sort by the string, since that's easy. |
| 104 | feature_names.sort_unstable(); |
| 105 | |
| 106 | let features = feature_names |
| 107 | .into_iter() |
| 108 | .map(|s| s.parse()) |
| 109 | .collect::<Result<_, String>>() |
| 110 | .unwrap_or_else(|error| { |
| 111 | tcx.sess.err(error); |
| 112 | Vec::new() |
| 113 | }); |
| 114 | |
| 115 | let codegen_args = CodegenArgs::from_session(tcx.sess); |
| 116 | let target = tcx.sess.target.llvm_target.parse().unwrap(); |
| 117 | |
| 118 | Self { |
| 119 | tcx, |
| 120 | codegen_unit, |
| 121 | builder: BuilderSpirv::new(tcx, &sym, &target, &features), |
| 122 | instances: Default::default(), |
| 123 | function_parameter_values: Default::default(), |
| 124 | type_cache: Default::default(), |
| 125 | vtables: Default::default(), |
| 126 | ext_inst: Default::default(), |
| 127 | zombie_decorations: Default::default(), |
| 128 | target, |
| 129 | sym, |
| 130 | instruction_table: InstructionTable::new(), |
| 131 | libm_intrinsics: Default::default(), |
| 132 | panic_entry_point_ids: Default::default(), |
| 133 | fmt_args_new_fn_ids: Default::default(), |
| 134 | fmt_rt_arg_new_fn_ids_to_ty_and_spec: Default::default(), |
| 135 | buffer_load_intrinsic_fn_id: Default::default(), |
| 136 | buffer_store_intrinsic_fn_id: Default::default(), |
| 137 | i8_i16_atomics_allowed: false, |
| 138 | codegen_args, |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | /// See comment on `BuilderCursor` |
| 143 | pub fn emit_global(&self) -> std::cell::RefMut<'_, rspirv::dr::Builder> { |