-
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove BeginInlinedFunction and EndInlinedFunction in trivial cases
Summary: When a function is just returning a constant, for example, we can get rid of the shadow frame bookkeeping. It is not needed for deopt or otherwise reifying frames. Such a function will likely not even show up in profiles, so don't bother keeping a shadow frame around for it. Reviewed By: swtaarrs Differential Revision: D35374703 fbshipit-source-id: 3806bab
- Loading branch information
1 parent
73a99f6
commit c4a1f41
Showing
7 changed files
with
282 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
RuntimeTests/hir_tests/inliner_elimination_static_test.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| InlinerEliminationStaticTest | ||
| --- | ||
| InlineFunctionCalls | ||
| Simplify | ||
| BeginInlinedFunctionElimination | ||
| --- | ||
| Simple | ||
| --- | ||
| def foo(): | ||
| # Chosen by fair dice roll. Guaranteed to be random. | ||
| return 4 | ||
|
|
||
| def test(): | ||
| return foo() | ||
| --- | ||
| fun jittestmodule:test { | ||
| bb 0 { | ||
| v5:MortalLongExact[4] = LoadConst<MortalLongExact[4]> | ||
| Return v5 | ||
| } | ||
| } | ||
| --- | ||
| InlineMultipleFunctions | ||
| --- | ||
| def foo(): | ||
| return 3 | ||
|
|
||
| def bar(): | ||
| return 4 | ||
|
|
||
| def test(): | ||
| return foo() + bar() | ||
| --- | ||
| fun jittestmodule:test { | ||
| bb 0 { | ||
| v10:MortalLongExact[3] = LoadConst<MortalLongExact[3]> | ||
| v14:MortalLongExact[4] = LoadConst<MortalLongExact[4]> | ||
| UseType<LongExact> v10 | ||
| UseType<LongExact> v14 | ||
| v16:LongExact = LongBinaryOp<Add> v10 v14 { | ||
| FrameState { | ||
| NextInstrOffset 12 | ||
| } | ||
| } | ||
| Return v16 | ||
| } | ||
| } | ||
| --- | ||
| BeginEndWithMemoryEffectsNotRemoved | ||
| --- | ||
| def add(x, y): | ||
| return x + y | ||
|
|
||
| def test(): | ||
| return add(3, 4) | ||
| --- | ||
| fun jittestmodule:test { | ||
| bb 0 { | ||
| v4:MortalLongExact[3] = LoadConst<MortalLongExact[3]> | ||
| v5:MortalLongExact[4] = LoadConst<MortalLongExact[4]> | ||
| BeginInlinedFunction<jittestmodule:add> { | ||
| NextInstrOffset 10 | ||
| } | ||
| UseType<LongExact> v4 | ||
| UseType<LongExact> v5 | ||
| v17:LongExact = LongBinaryOp<Add> v4 v5 { | ||
| FrameState { | ||
| NextInstrOffset 8 | ||
| Locals<2> v4 v5 | ||
| } | ||
| } | ||
| EndInlinedFunction | ||
| Return v17 | ||
| } | ||
| } | ||
| --- | ||
| InlinedStoreFieldLoadFieldIsEliminated | ||
| --- | ||
| from __static__ import int8 | ||
|
|
||
| class C: | ||
| def __init__(self): | ||
| self.foo: int8 = 4 | ||
|
|
||
| def getfoo(self) -> int8: | ||
| return self.foo | ||
|
|
||
| def test() -> int8: | ||
| return C().getfoo() | ||
| --- | ||
| fun jittestmodule:test { | ||
| bb 0 { | ||
| v5:ObjectUser[C:Exact] = TpAlloc<C> { | ||
| FrameState { | ||
| NextInstrOffset 4 | ||
| } | ||
| } | ||
| v15:CInt8[4] = LoadConst<CInt8[4]> | ||
| v17:Nullptr = LoadConst<Nullptr> | ||
| UseType<CInt8> v15 | ||
| StoreField<foo@16> v5 v15 v17 | ||
| v19:NoneType = LoadConst<NoneType> | ||
| v26:CInt8 = LoadField<foo@16, CInt8, borrowed> v5 | ||
| Return<CInt8> v26 | ||
| } | ||
| } | ||
| --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| InlinerEliminationTest | ||
| --- | ||
| InlineFunctionCalls | ||
| Simplify | ||
| BeginInlinedFunctionElimination | ||
| --- | ||
| Simple | ||
| --- | ||
| def foo(): | ||
| # Chosen by fair dice roll. Guaranteed to be random. | ||
| return 4 | ||
|
|
||
| def test(): | ||
| return foo() | ||
| --- | ||
| fun jittestmodule:test { | ||
| bb 0 { | ||
| v2:OptObject = LoadGlobalCached<0; "foo"> | ||
| v3:MortalFunc[function:0xdeadbeef] = GuardIs<0xdeadbeef> v2 { | ||
| Descr 'LOAD_GLOBAL: foo' | ||
| } | ||
| v9:Object = LoadField<func_code@16, Object, borrowed> v3 | ||
| v10:MortalCode["foo"] = GuardIs<0xdeadbeef> v9 { | ||
| } | ||
| v7:MortalLongExact[4] = LoadConst<MortalLongExact[4]> | ||
| Return v7 | ||
| } | ||
| } | ||
| --- | ||
| InlineMultipleFunctions | ||
| --- | ||
| def foo(): | ||
| return 3 | ||
|
|
||
| def bar(): | ||
| return 4 | ||
|
|
||
| def test(): | ||
| return foo() + bar() | ||
| --- | ||
| fun jittestmodule:test { | ||
| bb 0 { | ||
| v5:OptObject = LoadGlobalCached<0; "foo"> | ||
| v6:MortalFunc[function:0xdeadbeef] = GuardIs<0xdeadbeef> v5 { | ||
| Descr 'LOAD_GLOBAL: foo' | ||
| } | ||
| v16:Object = LoadField<func_code@16, Object, borrowed> v6 | ||
| v17:MortalCode["foo"] = GuardIs<0xdeadbeef> v16 { | ||
| } | ||
| v14:MortalLongExact[3] = LoadConst<MortalLongExact[3]> | ||
| v8:OptObject = LoadGlobalCached<1; "bar"> | ||
| v9:MortalFunc[function:0xdeadbeef] = GuardIs<0xdeadbeef> v8 { | ||
| Descr 'LOAD_GLOBAL: bar' | ||
| } | ||
| v22:Object = LoadField<func_code@16, Object, borrowed> v9 | ||
| v23:MortalCode["bar"] = GuardIs<0xdeadbeef> v22 { | ||
| } | ||
| v20:MortalLongExact[4] = LoadConst<MortalLongExact[4]> | ||
| UseType<LongExact> v14 | ||
| UseType<LongExact> v20 | ||
| v24:LongExact = LongBinaryOp<Add> v14 v20 { | ||
| FrameState { | ||
| NextInstrOffset 10 | ||
| } | ||
| } | ||
| Return v24 | ||
| } | ||
| } | ||
| --- | ||
| BeginEndWithMemoryEffectsNotRemoved | ||
| --- | ||
| def add(x, y): | ||
| return x + y | ||
|
|
||
| def test(): | ||
| return add(3, 4) | ||
| --- | ||
| fun jittestmodule:test { | ||
| bb 0 { | ||
| v4:OptObject = LoadGlobalCached<0; "add"> | ||
| v5:MortalFunc[function:0xdeadbeef] = GuardIs<0xdeadbeef> v4 { | ||
| Descr 'LOAD_GLOBAL: add' | ||
| } | ||
| v6:MortalLongExact[3] = LoadConst<MortalLongExact[3]> | ||
| v7:MortalLongExact[4] = LoadConst<MortalLongExact[4]> | ||
| v19:Object = LoadField<func_code@16, Object, borrowed> v5 | ||
| v20:MortalCode["add"] = GuardIs<0xdeadbeef> v19 { | ||
| } | ||
| BeginInlinedFunction<jittestmodule:add> { | ||
| NextInstrOffset 8 | ||
| } | ||
| UseType<LongExact> v6 | ||
| UseType<LongExact> v7 | ||
| v21:LongExact = LongBinaryOp<Add> v6 v7 { | ||
| FrameState { | ||
| NextInstrOffset 6 | ||
| Locals<2> v6 v7 | ||
| } | ||
| } | ||
| EndInlinedFunction | ||
| Return v21 | ||
| } | ||
| } | ||
| --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters