Rename target_pointer_width to pointer_width and turn it into an u32
Rename target_pointer_width to pointer_width because it is already member of the Target struct. The compiler supports only three valid values for target_pointer_width: 16, 32, 64. Thus it can safely be turned into an int. This means less allocations and clones as well as easier handling of the type.
This commit is contained in:
parent
64ba25d0f2
commit
0d1aa1e034
|
@ -16,10 +16,10 @@ pub(crate) unsafe fn codegen(
|
|||
) {
|
||||
let llcx = &*mods.llcx;
|
||||
let llmod = mods.llmod();
|
||||
let usize = match &tcx.sess.target.target.target_pointer_width[..] {
|
||||
"16" => llvm::LLVMInt16TypeInContext(llcx),
|
||||
"32" => llvm::LLVMInt32TypeInContext(llcx),
|
||||
"64" => llvm::LLVMInt64TypeInContext(llcx),
|
||||
let usize = match tcx.sess.target.target.pointer_width {
|
||||
16 => llvm::LLVMInt16TypeInContext(llcx),
|
||||
32 => llvm::LLVMInt32TypeInContext(llcx),
|
||||
64 => llvm::LLVMInt64TypeInContext(llcx),
|
||||
tws => bug!("Unsupported target word size for int: {}", tws),
|
||||
};
|
||||
let i8 = llvm::LLVMInt8TypeInContext(llcx);
|
||||
|
|
|
@ -307,7 +307,7 @@ pub struct CodegenContext<B: WriteBackendMethods> {
|
|||
pub allocator_module_config: Arc<ModuleConfig>,
|
||||
pub tm_factory: TargetMachineFactory<B>,
|
||||
pub msvc_imps_needed: bool,
|
||||
pub target_pointer_width: String,
|
||||
pub target_pointer_width: u32,
|
||||
pub target_arch: String,
|
||||
pub debuginfo: config::DebugInfo,
|
||||
|
||||
|
@ -1022,7 +1022,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
|
|||
tm_factory: TargetMachineFactory(backend.target_machine_factory(tcx.sess, ol)),
|
||||
total_cgus,
|
||||
msvc_imps_needed: msvc_imps_needed(tcx),
|
||||
target_pointer_width: tcx.sess.target.target.target_pointer_width.clone(),
|
||||
target_pointer_width: tcx.sess.target.target.pointer_width,
|
||||
target_arch: tcx.sess.target.target.arch.clone(),
|
||||
debuginfo: tcx.sess.opts.debuginfo,
|
||||
};
|
||||
|
|
|
@ -742,7 +742,7 @@ pub const fn default_lib_output() -> CrateType {
|
|||
pub fn default_configuration(sess: &Session) -> CrateConfig {
|
||||
let end = &sess.target.target.target_endian;
|
||||
let arch = &sess.target.target.arch;
|
||||
let wordsz = &sess.target.target.target_pointer_width;
|
||||
let wordsz = sess.target.target.pointer_width.to_string();
|
||||
let os = &sess.target.target.target_os;
|
||||
let env = &sess.target.target.target_env;
|
||||
let vendor = &sess.target.target.target_vendor;
|
||||
|
@ -767,7 +767,7 @@ pub fn default_configuration(sess: &Session) -> CrateConfig {
|
|||
}
|
||||
ret.insert((sym::target_arch, Some(Symbol::intern(arch))));
|
||||
ret.insert((sym::target_endian, Some(Symbol::intern(end))));
|
||||
ret.insert((sym::target_pointer_width, Some(Symbol::intern(wordsz))));
|
||||
ret.insert((sym::target_pointer_width, Some(Symbol::intern(&wordsz))));
|
||||
ret.insert((sym::target_env, Some(Symbol::intern(env))));
|
||||
ret.insert((sym::target_vendor, Some(Symbol::intern(vendor))));
|
||||
if sess.target.target.options.has_elf_tls {
|
||||
|
@ -792,7 +792,7 @@ pub fn default_configuration(sess: &Session) -> CrateConfig {
|
|||
};
|
||||
let s = i.to_string();
|
||||
insert_atomic(&s, align);
|
||||
if &s == wordsz {
|
||||
if s == wordsz {
|
||||
insert_atomic("ptr", layout.pointer_align.abi);
|
||||
}
|
||||
}
|
||||
|
@ -844,19 +844,18 @@ pub fn build_target_config(opts: &Options, target_override: Option<Target>) -> C
|
|||
)
|
||||
});
|
||||
|
||||
let ptr_width = match &target.target_pointer_width[..] {
|
||||
"16" => 16,
|
||||
"32" => 32,
|
||||
"64" => 64,
|
||||
w => early_error(
|
||||
if !matches!(target.pointer_width, 16 | 32 | 64) {
|
||||
early_error(
|
||||
opts.error_format,
|
||||
&format!(
|
||||
"target specification was invalid: \
|
||||
unrecognized target-pointer-width {}",
|
||||
w
|
||||
target.pointer_width
|
||||
),
|
||||
),
|
||||
};
|
||||
)
|
||||
}
|
||||
|
||||
let ptr_width = target.pointer_width;
|
||||
|
||||
Config { target, ptr_width }
|
||||
}
|
||||
|
|
|
@ -164,12 +164,12 @@ impl TargetDataLayout {
|
|||
));
|
||||
}
|
||||
|
||||
if dl.pointer_size.bits().to_string() != target.target_pointer_width {
|
||||
if dl.pointer_size.bits() != target.pointer_width.into() {
|
||||
return Err(format!(
|
||||
"inconsistent target specification: \"data-layout\" claims \
|
||||
pointers are {}-bit, while \"target-pointer-width\" is `{}`",
|
||||
dl.pointer_size.bits(),
|
||||
target.target_pointer_width
|
||||
target.pointer_width
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -665,8 +665,8 @@ pub struct Target {
|
|||
pub llvm_target: String,
|
||||
/// String to use as the `target_endian` `cfg` variable.
|
||||
pub target_endian: String,
|
||||
/// String to use as the `target_pointer_width` `cfg` variable.
|
||||
pub target_pointer_width: String,
|
||||
/// Number of bits in a pointer. Influences the `target_pointer_width` `cfg` variable.
|
||||
pub pointer_width: u32,
|
||||
/// Width of c_int type
|
||||
pub target_c_int_width: String,
|
||||
/// OS name to use for conditional compilation.
|
||||
|
@ -1111,7 +1111,7 @@ impl Target {
|
|||
/// Maximum integer size in bits that this target can perform atomic
|
||||
/// operations on.
|
||||
pub fn max_atomic_width(&self) -> u64 {
|
||||
self.options.max_atomic_width.unwrap_or_else(|| self.target_pointer_width.parse().unwrap())
|
||||
self.options.max_atomic_width.unwrap_or_else(|| self.pointer_width.into())
|
||||
}
|
||||
|
||||
pub fn is_abi_supported(&self, abi: Abi) -> bool {
|
||||
|
@ -1144,7 +1144,9 @@ impl Target {
|
|||
let mut base = Target {
|
||||
llvm_target: get_req_field("llvm-target")?,
|
||||
target_endian: get_req_field("target-endian")?,
|
||||
target_pointer_width: get_req_field("target-pointer-width")?,
|
||||
pointer_width: get_req_field("target-pointer-width")?
|
||||
.parse::<u32>()
|
||||
.map_err(|_| "target-pointer-width must be an integer".to_string())?,
|
||||
target_c_int_width: get_req_field("target-c-int-width")?,
|
||||
data_layout: get_req_field("data-layout")?,
|
||||
arch: get_req_field("arch")?,
|
||||
|
@ -1617,7 +1619,10 @@ impl ToJson for Target {
|
|||
|
||||
target_val!(llvm_target);
|
||||
target_val!(target_endian);
|
||||
target_val!(target_pointer_width);
|
||||
d.insert(
|
||||
"target-pointer-width".to_string(),
|
||||
self.pointer_width.to_string().to_json(),
|
||||
);
|
||||
target_val!(target_c_int_width);
|
||||
target_val!(arch);
|
||||
target_val!(target_os, "os");
|
||||
|
|
Loading…
Reference in New Issue