1
Fork 0

codegen_llvm/misc: improve common patterns

This commit is contained in:
ljedrz 2018-10-09 15:15:41 +02:00
parent e90e8aaeba
commit b07a2d02ca
4 changed files with 32 additions and 38 deletions

View file

@ -37,7 +37,7 @@ pub struct MirDebugScope<'ll> {
impl MirDebugScope<'ll> { impl MirDebugScope<'ll> {
pub fn is_valid(&self) -> bool { pub fn is_valid(&self) -> bool {
!self.scope_metadata.is_none() self.scope_metadata.is_some()
} }
} }

View file

@ -163,10 +163,10 @@ impl TypeMap<'ll, 'tcx> {
fn get_unique_type_id_of_type<'a>(&mut self, cx: &CodegenCx<'a, 'tcx>, fn get_unique_type_id_of_type<'a>(&mut self, cx: &CodegenCx<'a, 'tcx>,
type_: Ty<'tcx>) -> UniqueTypeId { type_: Ty<'tcx>) -> UniqueTypeId {
// Let's see if we already have something in the cache // Let's see if we already have something in the cache
match self.type_to_unique_id.get(&type_).cloned() { if let Some(unique_type_id) = self.type_to_unique_id.get(&type_).cloned() {
Some(unique_type_id) => return unique_type_id, return unique_type_id
None => { /* generate one */} }
}; // if not, generate one
// The hasher we are using to generate the UniqueTypeId. We want // The hasher we are using to generate the UniqueTypeId. We want
// something that provides more than the 64 bits of the DefaultHasher. // something that provides more than the 64 bits of the DefaultHasher.
@ -286,11 +286,11 @@ impl RecursiveTypeDescription<'ll, 'tcx> {
// unique id can be found in the type map // unique id can be found in the type map
macro_rules! return_if_metadata_created_in_meantime { macro_rules! return_if_metadata_created_in_meantime {
($cx: expr, $unique_type_id: expr) => ( ($cx: expr, $unique_type_id: expr) => (
match debug_context($cx).type_map if let Some(metadata) = debug_context($cx).type_map
.borrow() .borrow()
.find_metadata_for_unique_id($unique_type_id) { .find_metadata_for_unique_id($unique_type_id)
Some(metadata) => return MetadataCreationResult::new(metadata, true), {
None => { /* proceed normally */ } return MetadataCreationResult::new(metadata, true)
} }
) )
} }
@ -548,12 +548,12 @@ pub fn type_metadata(
_ => { _ => {
let pointee_metadata = type_metadata(cx, ty, usage_site_span); let pointee_metadata = type_metadata(cx, ty, usage_site_span);
match debug_context(cx).type_map if let Some(metadata) = debug_context(cx).type_map
.borrow() .borrow()
.find_metadata_for_unique_id(unique_type_id) { .find_metadata_for_unique_id(unique_type_id)
Some(metadata) => return Err(metadata), {
None => { /* proceed normally */ } return Err(metadata)
}; }
Ok(MetadataCreationResult::new(pointer_type_metadata(cx, t, pointee_metadata), Ok(MetadataCreationResult::new(pointer_type_metadata(cx, t, pointee_metadata),
false)) false))
@ -608,12 +608,12 @@ pub fn type_metadata(
unique_type_id, unique_type_id,
t.fn_sig(cx.tcx), t.fn_sig(cx.tcx),
usage_site_span).metadata; usage_site_span).metadata;
match debug_context(cx).type_map if let Some(metadata) = debug_context(cx).type_map
.borrow() .borrow()
.find_metadata_for_unique_id(unique_type_id) { .find_metadata_for_unique_id(unique_type_id)
Some(metadata) => return metadata, {
None => { /* proceed normally */ } return metadata
}; }
// This is actually a function pointer, so wrap it in pointer DI // This is actually a function pointer, so wrap it in pointer DI
MetadataCreationResult::new(pointer_type_metadata(cx, t, fn_metadata), false) MetadataCreationResult::new(pointer_type_metadata(cx, t, fn_metadata), false)
@ -1476,9 +1476,8 @@ fn prepare_enum_metadata(
} }
}; };
match (&layout.abi, discriminant_type_metadata) { if let (&layout::Abi::Scalar(_), Some(discr)) = (&layout.abi, discriminant_type_metadata) {
(&layout::Abi::Scalar(_), Some(discr)) => return FinalMetadata(discr), return FinalMetadata(discr)
_ => {}
} }
let (enum_type_size, enum_type_align) = layout.size_and_align(); let (enum_type_size, enum_type_align) = layout.size_and_align();

View file

@ -271,16 +271,14 @@ pub fn create_function_debug_context(
let mut flags = DIFlags::FlagPrototyped; let mut flags = DIFlags::FlagPrototyped;
let local_id = cx.tcx.hir.as_local_node_id(def_id); let local_id = cx.tcx.hir.as_local_node_id(def_id);
match *cx.sess().entry_fn.borrow() { if let Some((id, _, _)) = *cx.sess().entry_fn.borrow() {
Some((id, _, _)) => { if local_id == Some(id) {
if local_id == Some(id) { flags |= DIFlags::FlagMainSubprogram;
flags = flags | DIFlags::FlagMainSubprogram;
}
} }
None => {} }
};
if cx.layout_of(sig.output()).abi.is_uninhabited() { if cx.layout_of(sig.output()).abi.is_uninhabited() {
flags = flags | DIFlags::FlagNoReturn; flags |= DIFlags::FlagNoReturn;
} }
let fn_metadata = unsafe { let fn_metadata = unsafe {

View file

@ -56,11 +56,8 @@ pub fn set_source_location(
/// switches source location emitting on and must therefore be called before the /// switches source location emitting on and must therefore be called before the
/// first real statement/expression of the function is codegened. /// first real statement/expression of the function is codegened.
pub fn start_emitting_source_locations(dbg_context: &FunctionDebugContext<'ll>) { pub fn start_emitting_source_locations(dbg_context: &FunctionDebugContext<'ll>) {
match *dbg_context { if let FunctionDebugContext::RegularContext(ref data) = *dbg_context {
FunctionDebugContext::RegularContext(ref data) => { data.source_locations_enabled.set(true)
data.source_locations_enabled.set(true)
},
_ => { /* safe to ignore */ }
} }
} }