Skip to content

Commit 0986d64

Browse files
committed
Auto merge of #32236 - alexcrichton:better-compile-intrinsics, r=arielb1
rustc: Improve compile time of platform intrinsics This commit improves the compile time of `rustc_platform_intrinsics` from 23s to 3.6s if compiling with `-O` and from 77s to 17s if compiling with `-O -g`. The compiled rlib size also drops from 3.1M to 1.2M. The wins here were gained by removing the destructors associated with `Type` by removing the internal `Box` and `Vec` indirections. These destructors meant that a lot of landing pads and extra code were generated to manage the runtime representations. Instead everything can basically be statically computed and shoved into rodata, so all we need is a giant string compare to lookup what's what. Closes #28273
2 parents c66d238 + 87ede2d commit 0986d64

File tree

6 files changed

+2802
-2741
lines changed

6 files changed

+2802
-2741
lines changed

Diff for: src/etc/platform-intrinsics/generator.py

+48-23
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ def __init__(self):
117117
Type.__init__(self, 0)
118118

119119
def compiler_ctor(self):
120-
return 'void()'
120+
return '::VOID'
121+
122+
def compiler_ctor_ref(self):
123+
return '&' + self.compiler_ctor()
121124

122125
def rust_name(self):
123126
return '()'
@@ -163,10 +166,12 @@ def __init__(self, bitwidth, llvm_bitwidth = None):
163166

164167
def compiler_ctor(self):
165168
if self._llvm_bitwidth is None:
166-
return 'i({})'.format(self.bitwidth())
169+
return '::I{}'.format(self.bitwidth())
167170
else:
168-
return 'i_({}, {})'.format(self.bitwidth(),
169-
self._llvm_bitwidth)
171+
return '::I{}_{}'.format(self.bitwidth(), self._llvm_bitwidth)
172+
173+
def compiler_ctor_ref(self):
174+
return '&' + self.compiler_ctor()
170175

171176
def llvm_name(self):
172177
bw = self._llvm_bitwidth or self.bitwidth()
@@ -182,10 +187,12 @@ def __init__(self, bitwidth, llvm_bitwidth = None):
182187

183188
def compiler_ctor(self):
184189
if self._llvm_bitwidth is None:
185-
return 'u({})'.format(self.bitwidth())
190+
return '::U{}'.format(self.bitwidth())
186191
else:
187-
return 'u_({}, {})'.format(self.bitwidth(),
188-
self._llvm_bitwidth)
192+
return '::U{}_{}'.format(self.bitwidth(), self._llvm_bitwidth)
193+
194+
def compiler_ctor_ref(self):
195+
return '&' + self.compiler_ctor()
189196

190197
def llvm_name(self):
191198
bw = self._llvm_bitwidth or self.bitwidth()
@@ -200,7 +207,10 @@ def __init__(self, bitwidth):
200207
Number.__init__(self, bitwidth)
201208

202209
def compiler_ctor(self):
203-
return 'f({})'.format(self.bitwidth())
210+
return '::F{}'.format(self.bitwidth())
211+
212+
def compiler_ctor_ref(self):
213+
return '&' + self.compiler_ctor()
204214

205215
def llvm_name(self):
206216
return 'f{}'.format(self.bitwidth())
@@ -244,12 +254,16 @@ def modify(self, spec, width, previous):
244254

245255
def compiler_ctor(self):
246256
if self._bitcast is None:
247-
return 'v({}, {})'.format(self._elem.compiler_ctor(),
248-
self._length)
257+
return '{}x{}'.format(self._elem.compiler_ctor(),
258+
self._length)
249259
else:
250-
return 'v_({}, {}, {})'.format(self._elem.compiler_ctor(),
251-
self._bitcast.compiler_ctor(),
252-
self._length)
260+
return '{}x{}_{}'.format(self._elem.compiler_ctor(),
261+
self._length,
262+
self._bitcast.compiler_ctor()
263+
.replace('::', ''))
264+
265+
def compiler_ctor_ref(self):
266+
return '&' + self.compiler_ctor()
253267

254268
def rust_name(self):
255269
return '{}x{}'.format(self._elem.rust_name(), self._length)
@@ -284,10 +298,14 @@ def compiler_ctor(self):
284298
if self._llvm_elem is None:
285299
llvm_elem = 'None'
286300
else:
287-
llvm_elem = 'Some({})'.format(self._llvm_elem.compiler_ctor())
288-
return 'p({}, {}, {})'.format('true' if self._const else 'false',
289-
self._elem.compiler_ctor(),
290-
llvm_elem)
301+
llvm_elem = 'Some({})'.format(self._llvm_elem.compiler_ctor_ref())
302+
return 'Type::Pointer({}, {}, {})'.format(self._elem.compiler_ctor_ref(),
303+
llvm_elem,
304+
'true' if self._const else 'false')
305+
306+
def compiler_ctor_ref(self):
307+
return "{{ static PTR: Type = {}; &PTR }}".format(self.compiler_ctor())
308+
291309

292310
def rust_name(self):
293311
return '*{} {}'.format('const' if self._const else 'mut',
@@ -322,8 +340,14 @@ def modify(self, spec, width, previous):
322340
raise NotImplementedError()
323341

324342
def compiler_ctor(self):
325-
return 'agg({}, vec![{}])'.format('true' if self._flatten else 'false',
326-
', '.join(elem.compiler_ctor() for elem in self._elems))
343+
parts = "{{ static PARTS: [&'static Type; {}] = [{}]; &PARTS }}"
344+
elems = ', '.join(elem.compiler_ctor_ref() for elem in self._elems)
345+
parts = parts.format(len(self._elems), elems)
346+
return 'Type::Aggregate({}, {})'.format('true' if self._flatten else 'false',
347+
parts)
348+
349+
def compiler_ctor_ref(self):
350+
return "{{ static AGG: Type = {}; &AGG }}".format(self.compiler_ctor())
327351

328352
def rust_name(self):
329353
return '({})'.format(', '.join(elem.rust_name() for elem in self._elems))
@@ -518,10 +542,10 @@ def intrinsic_name(self):
518542
return self._platform.platform().intrinsic_prefix() + self.intrinsic_suffix()
519543

520544
def compiler_args(self):
521-
return ', '.join(arg.compiler_ctor() for arg in self._args_raw)
545+
return ', '.join(arg.compiler_ctor_ref() for arg in self._args_raw)
522546

523547
def compiler_ret(self):
524-
return self._ret_raw.compiler_ctor()
548+
return self._ret_raw.compiler_ctor_ref()
525549

526550
def compiler_signature(self):
527551
return '({}) -> {}'.format(self.compiler_args(), self.compiler_ret())
@@ -733,7 +757,7 @@ def open(self, platform):
733757
734758
#![allow(unused_imports)]
735759
736-
use {{Intrinsic, i, i_, u, u_, f, v, v_, agg, p, void}};
760+
use {{Intrinsic, Type}};
737761
use IntrinsicDef::Named;
738762
use rustc::middle::ty::TyCtxt;
739763
@@ -747,10 +771,11 @@ def open(self, platform):
747771
def render(self, mono):
748772
return '''\
749773
"{}" => Intrinsic {{
750-
inputs: vec![{}],
774+
inputs: {{ static INPUTS: [&'static Type; {}] = [{}]; &INPUTS }},
751775
output: {},
752776
definition: Named("{}")
753777
}},'''.format(mono.intrinsic_suffix(),
778+
len(mono._args_raw),
754779
mono.compiler_args(),
755780
mono.compiler_ret(),
756781
mono.llvm_name())

0 commit comments

Comments
 (0)