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
5 changed files with 28 additions and 24 deletions
|
@ -16,10 +16,10 @@ pub(crate) unsafe fn codegen(
|
||||||
) {
|
) {
|
||||||
let llcx = &*mods.llcx;
|
let llcx = &*mods.llcx;
|
||||||
let llmod = mods.llmod();
|
let llmod = mods.llmod();
|
||||||
let usize = match &tcx.sess.target.target.target_pointer_width[..] {
|
let usize = match tcx.sess.target.target.pointer_width {
|
||||||
"16" => llvm::LLVMInt16TypeInContext(llcx),
|
16 => llvm::LLVMInt16TypeInContext(llcx),
|
||||||
"32" => llvm::LLVMInt32TypeInContext(llcx),
|
32 => llvm::LLVMInt32TypeInContext(llcx),
|
||||||
"64" => llvm::LLVMInt64TypeInContext(llcx),
|
64 => llvm::LLVMInt64TypeInContext(llcx),
|
||||||
tws => bug!("Unsupported target word size for int: {}", tws),
|
tws => bug!("Unsupported target word size for int: {}", tws),
|
||||||
};
|
};
|
||||||
let i8 = llvm::LLVMInt8TypeInContext(llcx);
|
let i8 = llvm::LLVMInt8TypeInContext(llcx);
|
||||||
|
|
|
@ -307,7 +307,7 @@ pub struct CodegenContext<B: WriteBackendMethods> {
|
||||||
pub allocator_module_config: Arc<ModuleConfig>,
|
pub allocator_module_config: Arc<ModuleConfig>,
|
||||||
pub tm_factory: TargetMachineFactory<B>,
|
pub tm_factory: TargetMachineFactory<B>,
|
||||||
pub msvc_imps_needed: bool,
|
pub msvc_imps_needed: bool,
|
||||||
pub target_pointer_width: String,
|
pub target_pointer_width: u32,
|
||||||
pub target_arch: String,
|
pub target_arch: String,
|
||||||
pub debuginfo: config::DebugInfo,
|
pub debuginfo: config::DebugInfo,
|
||||||
|
|
||||||
|
@ -1022,7 +1022,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
|
||||||
tm_factory: TargetMachineFactory(backend.target_machine_factory(tcx.sess, ol)),
|
tm_factory: TargetMachineFactory(backend.target_machine_factory(tcx.sess, ol)),
|
||||||
total_cgus,
|
total_cgus,
|
||||||
msvc_imps_needed: msvc_imps_needed(tcx),
|
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(),
|
target_arch: tcx.sess.target.target.arch.clone(),
|
||||||
debuginfo: tcx.sess.opts.debuginfo,
|
debuginfo: tcx.sess.opts.debuginfo,
|
||||||
};
|
};
|
||||||
|
|
|
@ -742,7 +742,7 @@ pub const fn default_lib_output() -> CrateType {
|
||||||
pub fn default_configuration(sess: &Session) -> CrateConfig {
|
pub fn default_configuration(sess: &Session) -> CrateConfig {
|
||||||
let end = &sess.target.target.target_endian;
|
let end = &sess.target.target.target_endian;
|
||||||
let arch = &sess.target.target.arch;
|
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 os = &sess.target.target.target_os;
|
||||||
let env = &sess.target.target.target_env;
|
let env = &sess.target.target.target_env;
|
||||||
let vendor = &sess.target.target.target_vendor;
|
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_arch, Some(Symbol::intern(arch))));
|
||||||
ret.insert((sym::target_endian, Some(Symbol::intern(end))));
|
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_env, Some(Symbol::intern(env))));
|
||||||
ret.insert((sym::target_vendor, Some(Symbol::intern(vendor))));
|
ret.insert((sym::target_vendor, Some(Symbol::intern(vendor))));
|
||||||
if sess.target.target.options.has_elf_tls {
|
if sess.target.target.options.has_elf_tls {
|
||||||
|
@ -792,7 +792,7 @@ pub fn default_configuration(sess: &Session) -> CrateConfig {
|
||||||
};
|
};
|
||||||
let s = i.to_string();
|
let s = i.to_string();
|
||||||
insert_atomic(&s, align);
|
insert_atomic(&s, align);
|
||||||
if &s == wordsz {
|
if s == wordsz {
|
||||||
insert_atomic("ptr", layout.pointer_align.abi);
|
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[..] {
|
if !matches!(target.pointer_width, 16 | 32 | 64) {
|
||||||
"16" => 16,
|
early_error(
|
||||||
"32" => 32,
|
|
||||||
"64" => 64,
|
|
||||||
w => early_error(
|
|
||||||
opts.error_format,
|
opts.error_format,
|
||||||
&format!(
|
&format!(
|
||||||
"target specification was invalid: \
|
"target specification was invalid: \
|
||||||
unrecognized target-pointer-width {}",
|
unrecognized target-pointer-width {}",
|
||||||
w
|
target.pointer_width
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
|
let ptr_width = target.pointer_width;
|
||||||
|
|
||||||
Config { target, ptr_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!(
|
return Err(format!(
|
||||||
"inconsistent target specification: \"data-layout\" claims \
|
"inconsistent target specification: \"data-layout\" claims \
|
||||||
pointers are {}-bit, while \"target-pointer-width\" is `{}`",
|
pointers are {}-bit, while \"target-pointer-width\" is `{}`",
|
||||||
dl.pointer_size.bits(),
|
dl.pointer_size.bits(),
|
||||||
target.target_pointer_width
|
target.pointer_width
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -665,8 +665,8 @@ pub struct Target {
|
||||||
pub llvm_target: String,
|
pub llvm_target: String,
|
||||||
/// String to use as the `target_endian` `cfg` variable.
|
/// String to use as the `target_endian` `cfg` variable.
|
||||||
pub target_endian: String,
|
pub target_endian: String,
|
||||||
/// String to use as the `target_pointer_width` `cfg` variable.
|
/// Number of bits in a pointer. Influences the `target_pointer_width` `cfg` variable.
|
||||||
pub target_pointer_width: String,
|
pub pointer_width: u32,
|
||||||
/// Width of c_int type
|
/// Width of c_int type
|
||||||
pub target_c_int_width: String,
|
pub target_c_int_width: String,
|
||||||
/// OS name to use for conditional compilation.
|
/// OS name to use for conditional compilation.
|
||||||
|
@ -1111,7 +1111,7 @@ impl Target {
|
||||||
/// Maximum integer size in bits that this target can perform atomic
|
/// Maximum integer size in bits that this target can perform atomic
|
||||||
/// operations on.
|
/// operations on.
|
||||||
pub fn max_atomic_width(&self) -> u64 {
|
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 {
|
pub fn is_abi_supported(&self, abi: Abi) -> bool {
|
||||||
|
@ -1144,7 +1144,9 @@ impl Target {
|
||||||
let mut base = Target {
|
let mut base = Target {
|
||||||
llvm_target: get_req_field("llvm-target")?,
|
llvm_target: get_req_field("llvm-target")?,
|
||||||
target_endian: get_req_field("target-endian")?,
|
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")?,
|
target_c_int_width: get_req_field("target-c-int-width")?,
|
||||||
data_layout: get_req_field("data-layout")?,
|
data_layout: get_req_field("data-layout")?,
|
||||||
arch: get_req_field("arch")?,
|
arch: get_req_field("arch")?,
|
||||||
|
@ -1617,7 +1619,10 @@ impl ToJson for Target {
|
||||||
|
|
||||||
target_val!(llvm_target);
|
target_val!(llvm_target);
|
||||||
target_val!(target_endian);
|
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!(target_c_int_width);
|
||||||
target_val!(arch);
|
target_val!(arch);
|
||||||
target_val!(target_os, "os");
|
target_val!(target_os, "os");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue