Reviewed By: skcho Differential Revision: D22090818 fbshipit-source-id: 86c4bdaf9master
parent
219cc64cb6
commit
0c365136b1
@ -0,0 +1,3 @@
|
||||
This checker detects opportunities to hoist function calls that are invariant to outside of loop bodies. The hoisting analysis relies on [purity](/docs/next/checker-purity) analysis to determine whather a function is pure or not.
|
||||
|
||||
It has an additional mode that reports [loop-invariant functions that are expensive](/docs/next/all-issue-types#expensive_loop_invariant_call) (i.e. at least linear). This is enabled by the flag `--hoisting-report-only-expensive`.
|
@ -0,0 +1,22 @@
|
||||
We report this issue type when a function is [loop-invariant](/docs/next/all-issue-types#invariant_call) and also expensive (i.e. at least has linear complexity as determined by the [cost](/docs/next/checker-cost) analysis).
|
||||
|
||||
```java
|
||||
int incr(int x) {
|
||||
return x + 1;
|
||||
}
|
||||
|
||||
// incr will not be hoisted since it is cheap(constant time)
|
||||
void foo_linear(int size) {
|
||||
int x = 10;
|
||||
for (int i = 0; i < size; i++) {
|
||||
incr(x); // constant call, don't hoist
|
||||
}
|
||||
}
|
||||
|
||||
// call to foo_linear will be hoisted since it is expensive(linear in size).
|
||||
void symbolic_expensive_hoist(int size) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
foo_linear(size); // hoist
|
||||
}
|
||||
}
|
||||
```
|
@ -0,0 +1,19 @@
|
||||
We report this issue type when a function call is loop-invariant and hoistable, i.e.
|
||||
- the function has no side side effects (pure)
|
||||
- has invariant arguments and result (i.e. have the same value in all loop iterations)
|
||||
- it is guaranteed to execute, i.e. it dominates all loop sources
|
||||
|
||||
```java
|
||||
int foo(int x, int y) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
|
||||
void invariant_hoist(int size) {
|
||||
int x = 10;
|
||||
int y = 5;
|
||||
for (int i = 0; i < size; i++) {
|
||||
foo(x, y); // hoistable
|
||||
}
|
||||
}
|
||||
```
|
Loading…
Reference in new issue