-
-
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.
Summary:
With this diff, we add a function inliner as an HIR pass. The structure of the
inliner pass is as follows: for each `VectorCall` instruction, if it can be
inlined, inline it. There is no interesting policy yet.
Inlining is similar to HIR building, except that inlined functions do not get
their own `Function`s and are constructed inside their caller's CFG. In
addition, `LoadArg` gets translated to `Assign` and `Return` to
`Assign`+`Branch`. For example, the following HIR:
```
# Final HIR (without inlining)
fun __main__:callee {
bb 0 {
v3:Object = LoadArg<0; "x">
v5:MortalLongExact[1] = LoadConst<MortalLongExact[1]>
v6:Object = BinaryOp<Add> v3 v5
Return v6
}
}
fun __main__:caller {
bb 0 {
v3:OptObject = LoadGlobalCached<0; "callee">
v4:MortalFunc[function:0x7f379b5584b0] = GuardIs<0x7f379b5584b0> v3
v5:MortalLongExact[3] = LoadConst<MortalLongExact[3]>
v6:Object = VectorCall<1> v4 v5
Return v6
}
}
```
gets inlined to:
```
# Final HIR
fun __main__:caller {
bb 0 {
v3:OptObject = LoadGlobalCached<0; "callee">
v4:MortalFunc[function:0x7f62660574b0] = GuardIs<0x7f62660574b0> v3
v5:MortalLongExact[3] = LoadConst<MortalLongExact[3]>
BeginInlinedFunction<__main__:callee>
v13:MortalLongExact[1] = LoadConst<MortalLongExact[1]>
v14:Object = BinaryOp<Add> v5 v13
EndInlinedFunction
Return v14
}
}
```
The inliner does not inline functions that:
* Are not preloaded, if running in in a multithreaded context
* Cannot be compiled by the JIT (`exec`, `locals`, etc)
* Have mismatched argument/parameter counts
* Have varargs
* Have varkeywords
* Have cellvars
* Have freevars
* Are generators or coroutines
* Have default arguments
* Have `*args`
* Have `**kwargs`
The inliner is currently disabled by default. This diff adds `-X
jit-enable-hir-inliner` and `PYTHONJITENABLEHIRINLINER` to enable it.
Reviewed By: mpage
Differential Revision: D30819582
fbshipit-source-id: 238980b- Loading branch information
1 parent
6586370
commit f3c50b3
Showing
23 changed files
with
1,018 additions
and
31 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
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
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
Oops, something went wrong.