@@ -37,12 +37,26 @@ pub fn inline(sess: &Session, module: &mut Module) -> super::Result<()> {
37
37
. iter ( )
38
38
. find ( |inst| inst. class . opcode == Op :: TypeVoid )
39
39
. map_or ( 0 , |inst| inst. result_id . unwrap ( ) ) ;
40
+ let ptr_map: FxHashMap < _ , _ > = module
41
+ . types_global_values
42
+ . iter ( )
43
+ . filter_map ( |inst| {
44
+ if inst. class . opcode == Op :: TypePointer
45
+ && inst. operands [ 0 ] . unwrap_storage_class ( ) == StorageClass :: Function
46
+ {
47
+ Some ( ( inst. operands [ 1 ] . unwrap_id_ref ( ) , inst. result_id . unwrap ( ) ) )
48
+ } else {
49
+ None
50
+ }
51
+ } )
52
+ . collect ( ) ;
40
53
// Drop all the functions we'll be inlining. (This also means we won't waste time processing
41
54
// inlines in functions that will get inlined)
42
55
let mut inliner = Inliner {
43
56
header : module. header . as_mut ( ) . unwrap ( ) ,
44
57
types_global_values : & mut module. types_global_values ,
45
58
void,
59
+ ptr_map,
46
60
functions : & functions,
47
61
disallowed_argument_types : & disallowed_argument_types,
48
62
disallowed_return_types : & disallowed_return_types,
@@ -281,6 +295,7 @@ struct Inliner<'m, 'map> {
281
295
header : & ' m mut ModuleHeader ,
282
296
types_global_values : & ' m mut Vec < Instruction > ,
283
297
void : Word ,
298
+ ptr_map : FxHashMap < Word , Word > ,
284
299
functions : & ' map FunctionMap ,
285
300
disallowed_argument_types : & ' map FxHashSet < Word > ,
286
301
disallowed_return_types : & ' map FxHashSet < Word > ,
@@ -295,14 +310,9 @@ impl Inliner<'_, '_> {
295
310
}
296
311
297
312
fn ptr_ty ( & mut self , pointee : Word ) -> Word {
298
- // TODO: This is horribly slow, fix this
299
- let existing = self . types_global_values . iter ( ) . find ( |inst| {
300
- inst. class . opcode == Op :: TypePointer
301
- && inst. operands [ 0 ] . unwrap_storage_class ( ) == StorageClass :: Function
302
- && inst. operands [ 1 ] . unwrap_id_ref ( ) == pointee
303
- } ) ;
313
+ let existing = self . ptr_map . get ( & pointee) ;
304
314
if let Some ( existing) = existing {
305
- return existing. result_id . unwrap ( ) ;
315
+ return * existing;
306
316
}
307
317
let inst_id = self . id ( ) ;
308
318
self . types_global_values . push ( Instruction :: new (
@@ -314,6 +324,7 @@ impl Inliner<'_, '_> {
314
324
Operand :: IdRef ( pointee) ,
315
325
] ,
316
326
) ) ;
327
+ self . ptr_map . insert ( pointee, inst_id) ;
317
328
inst_id
318
329
}
319
330
0 commit comments