Skip to content

Commit

Permalink
Utilize new inlining utility to potentially inline any call (#684)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Jun 21, 2019
1 parent 070d67f commit 2d31692
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 275 deletions.
30 changes: 26 additions & 4 deletions src/compiler.ts
Expand Up @@ -6675,10 +6675,32 @@ export class Compiler extends DiagnosticEmitter {
skipAutorelease: bool = false
): ExpressionRef {
if (instance.hasDecorator(DecoratorFlags.INLINE)) {
this.warning(
DiagnosticCode.TODO_Cannot_inline_inferred_calls_and_specific_internals_yet,
reportNode.range, instance.internalName
);
assert(!instance.is(CommonFlags.TRAMPOLINE)); // doesn't make sense
if (this.currentInlineFunctions.includes(instance)) {
this.warning(
DiagnosticCode.Function_0_cannot_be_inlined_into_itself,
reportNode.range, instance.internalName
);
} else {
this.currentInlineFunctions.push(instance);
let expr: ExpressionRef;
if (instance.is(CommonFlags.INSTANCE)) {
let theOperands = assert(operands);
assert(theOperands.length);
expr = this.makeCallInline(instance, theOperands.slice(1), theOperands[0], immediatelyDropped);
} else {
expr = this.makeCallInline(instance, operands, 0, immediatelyDropped);
}
if (this.currentType.isManaged) {
if (!skipAutorelease) {
expr = this.makeAutorelease(expr, this.currentFlow);
} else {
this.skippedAutoreleases.add(expr);
}
}
this.currentInlineFunctions.pop();
return expr;
}
}
var numOperands = operands ? operands.length : 0;
var numArguments = numOperands;
Expand Down
182 changes: 83 additions & 99 deletions tests/compiler/std/operator-overloading.untouched.wat
Expand Up @@ -2004,54 +2004,7 @@
i32.store offset=4
local.get $0
)
(func $std/operator-overloading/TesterInlineStatic.postInc (; 34 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
(local $1 i32)
local.get $0
call $~lib/rt/stub/__retain
drop
i32.const 0
local.get $0
i32.load
i32.const 1
i32.add
local.get $0
i32.load offset=4
i32.const 1
i32.add
call $std/operator-overloading/TesterInlineStatic#constructor
local.set $1
local.get $0
call $~lib/rt/stub/__release
local.get $1
)
(func $std/operator-overloading/TesterInlineStatic.add (; 35 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
local.get $0
call $~lib/rt/stub/__retain
drop
local.get $1
call $~lib/rt/stub/__retain
drop
i32.const 0
local.get $0
i32.load
local.get $1
i32.load
i32.add
local.get $0
i32.load offset=4
local.get $1
i32.load offset=4
i32.add
call $std/operator-overloading/TesterInlineStatic#constructor
local.set $2
local.get $0
call $~lib/rt/stub/__release
local.get $1
call $~lib/rt/stub/__release
local.get $2
)
(func $std/operator-overloading/TesterInlineInstance#constructor (; 36 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func $std/operator-overloading/TesterInlineInstance#constructor (; 34 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
local.get $0
i32.eqz
if
Expand All @@ -2069,41 +2022,7 @@
i32.store offset=4
local.get $0
)
(func $std/operator-overloading/TesterInlineInstance#postInc (; 37 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
i32.const 0
local.get $0
i32.load
i32.const 1
i32.add
local.get $0
i32.load offset=4
i32.const 1
i32.add
call $std/operator-overloading/TesterInlineInstance#constructor
)
(func $std/operator-overloading/TesterInlineInstance#add (; 38 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
local.get $1
call $~lib/rt/stub/__retain
drop
i32.const 0
local.get $0
i32.load
local.get $1
i32.load
i32.add
local.get $0
i32.load offset=4
local.get $1
i32.load offset=4
i32.add
call $std/operator-overloading/TesterInlineInstance#constructor
local.set $2
local.get $1
call $~lib/rt/stub/__release
local.get $2
)
(func $start:std/operator-overloading (; 39 ;) (type $FUNCSIG$v)
(func $start:std/operator-overloading (; 35 ;) (type $FUNCSIG$v)
(local $0 i32)
(local $1 i32)
(local $2 i32)
Expand All @@ -2128,6 +2047,7 @@
(local $21 i32)
(local $22 i32)
(local $23 i32)
(local $24 i32)
global.get $~lib/heap/__heap_base
i32.const 15
i32.add
Expand Down Expand Up @@ -3143,30 +3063,66 @@
call $std/operator-overloading/TesterInlineStatic#constructor
global.set $std/operator-overloading/ais1
global.get $std/operator-overloading/ais1
call $std/operator-overloading/TesterInlineStatic.postInc
local.tee $21
call $~lib/rt/stub/__retain
local.set $20
i32.const 0
local.get $20
i32.load
i32.const 1
i32.add
local.get $20
i32.load offset=4
i32.const 1
i32.add
call $std/operator-overloading/TesterInlineStatic#constructor
local.set $21
local.get $20
call $~lib/rt/stub/__release
local.get $21
local.tee $20
global.get $std/operator-overloading/ais1
local.tee $18
global.get $std/operator-overloading/ais1
local.tee $21
i32.ne
if
local.get $20
local.get $18
call $~lib/rt/stub/__retain
drop
local.get $18
local.get $21
call $~lib/rt/stub/__release
end
local.get $20
local.get $18
global.set $std/operator-overloading/ais1
i32.const 0
i32.const 2
i32.const 3
call $std/operator-overloading/TesterInlineStatic#constructor
global.set $std/operator-overloading/ais2
global.get $std/operator-overloading/ais1
call $~lib/rt/stub/__retain
local.set $18
global.get $std/operator-overloading/ais2
call $std/operator-overloading/TesterInlineStatic.add
local.tee $20
call $~lib/rt/stub/__retain
local.set $21
i32.const 0
local.get $18
i32.load
local.get $21
i32.load
i32.add
local.get $18
i32.load offset=4
local.get $21
i32.load offset=4
i32.add
call $std/operator-overloading/TesterInlineStatic#constructor
local.set $22
local.get $21
call $~lib/rt/stub/__release
local.get $18
call $~lib/rt/stub/__release
local.get $22
local.tee $18
call $~lib/rt/stub/__retain
global.set $std/operator-overloading/ais
global.get $std/operator-overloading/ais
Expand Down Expand Up @@ -3196,30 +3152,58 @@
call $std/operator-overloading/TesterInlineInstance#constructor
global.set $std/operator-overloading/aii1
global.get $std/operator-overloading/aii1
call $std/operator-overloading/TesterInlineInstance#postInc
local.tee $18
local.set $22
i32.const 0
local.get $22
i32.load
i32.const 1
i32.add
local.get $22
i32.load offset=4
i32.const 1
i32.add
call $std/operator-overloading/TesterInlineInstance#constructor
local.tee $22
local.tee $21
global.get $std/operator-overloading/aii1
local.tee $23
i32.ne
if
local.get $22
local.get $21
call $~lib/rt/stub/__retain
drop
local.get $23
call $~lib/rt/stub/__release
end
local.get $22
local.get $21
global.set $std/operator-overloading/aii1
i32.const 0
i32.const 2
i32.const 3
call $std/operator-overloading/TesterInlineInstance#constructor
global.set $std/operator-overloading/aii2
global.get $std/operator-overloading/aii1
local.set $21
global.get $std/operator-overloading/aii2
call $std/operator-overloading/TesterInlineInstance#add
local.tee $22
call $~lib/rt/stub/__retain
local.set $23
i32.const 0
local.get $21
i32.load
local.get $23
i32.load
i32.add
local.get $21
i32.load offset=4
local.get $23
i32.load offset=4
i32.add
call $std/operator-overloading/TesterInlineInstance#constructor
local.set $24
local.get $23
call $~lib/rt/stub/__release
local.get $24
local.tee $21
call $~lib/rt/stub/__retain
global.set $std/operator-overloading/aii
global.get $std/operator-overloading/aii
Expand Down Expand Up @@ -3290,9 +3274,9 @@
local.get $22
call $~lib/rt/stub/__release
)
(func $start (; 40 ;) (type $FUNCSIG$v)
(func $start (; 36 ;) (type $FUNCSIG$v)
call $start:std/operator-overloading
)
(func $null (; 41 ;) (type $FUNCSIG$v)
(func $null (; 37 ;) (type $FUNCSIG$v)
)
)

0 comments on commit 2d31692

Please sign in to comment.