about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
diff options
context:
space:
mode:
authorDavid Wood <david@davidtw.co>2020-08-28 16:24:52 +0100
committerDavid Wood <david@davidtw.co>2020-08-31 11:20:52 +0100
commitfa01ce802f1b403a2140fd945b43af86ec3998a1 (patch)
tree4eb8a9a114cba2bf3fb838a624a01e810e0d006e /compiler/rustc_codegen_llvm/src
parent6c44bcc4ffeb0ee8059c2c167388c69dedf1ea44 (diff)
downloadrust-fa01ce802f1b403a2140fd945b43af86ec3998a1.tar.gz
rust-fa01ce802f1b403a2140fd945b43af86ec3998a1.zip
cg_llvm: `fewer_names` in `uncached_llvm_type`
This commit changes `uncached_llvm_type` so that a named struct type
(with an empty name) is always created when the `fewer_names` option
is enabled. By skipping the generation of names, we can improve perf.
Giving `LLVMStructCreateNamed` an empty name works because LLVM will
perform random renames to avoid collisions.

Signed-off-by: David Wood <david@davidtw.co>
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
-rw-r--r--compiler/rustc_codegen_llvm/src/type_of.rs24
1 files changed, 14 insertions, 10 deletions
diff --git a/compiler/rustc_codegen_llvm/src/type_of.rs b/compiler/rustc_codegen_llvm/src/type_of.rs
index 60a4e362600..a02601eb43e 100644
--- a/compiler/rustc_codegen_llvm/src/type_of.rs
+++ b/compiler/rustc_codegen_llvm/src/type_of.rs
@@ -51,30 +51,34 @@ fn uncached_llvm_type<'a, 'tcx>(
     }
 
     let name = match layout.ty.kind {
-        ty::Closure(..) |
-        ty::Generator(..) |
-        ty::Adt(..) |
         // FIXME(eddyb) producing readable type names for trait objects can result
         // in problematically distinct types due to HRTB and subtyping (see #47638).
         // ty::Dynamic(..) |
-        ty::Foreign(..) |
-        ty::Str => {
+        ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Generator(..) | ty::Str
+            if !cx.sess().fewer_names() =>
+        {
             let mut name = layout.ty.to_string();
-            if let (&ty::Adt(def, _), &Variants::Single { index })
-                 = (&layout.ty.kind, &layout.variants)
+            if let (&ty::Adt(def, _), &Variants::Single { index }) =
+                (&layout.ty.kind, &layout.variants)
             {
                 if def.is_enum() && !def.variants.is_empty() {
                     write!(&mut name, "::{}", def.variants[index].ident).unwrap();
                 }
             }
-            if let (&ty::Generator(_, _, _), &Variants::Single { index })
-                 = (&layout.ty.kind, &layout.variants)
+            if let (&ty::Generator(_, _, _), &Variants::Single { index }) =
+                (&layout.ty.kind, &layout.variants)
             {
                 write!(&mut name, "::{}", ty::GeneratorSubsts::variant_name(index)).unwrap();
             }
             Some(name)
         }
-        _ => None
+        ty::Adt(..) => {
+            // If `Some` is returned then a named struct is created in LLVM. Name collisions are
+            // avoided by LLVM (with increasing suffixes). If rustc doesn't generate names then that
+            // can improve perf.
+            Some(String::new())
+        }
+        _ => None,
     };
 
     match layout.fields {