Commit 70e34f4
committed
opt: allow a bound function to opt out of constant folding
The folder evaluates a builtin call at compile time when the callee is pure,
returns a foldable type and every argument is constant. That is wrong when
the body is not really there: an AOT compiler build (DAS_AOT_COMPILER)
replaces C++ bound bodies with an asserting stub, so folding such a call runs
the stub and aborts the compiler. dagor hit this on
rel_hp_float_to_fixed_floor(1.0)
which only became constant after a small wrapper was inlined at a constant
call site.
Add BuiltInFunction::noFolding with a chainable noFold(), and test it at the
four builtin fold gates, so a binding that must not run at compile time can
say so:
DAS_ADD_FUN_BIND("rel_hp_float_to_fixed_floor", none, ...)->noFold();
Nothing is marked here. Folding stays on by default for every function.
The flag sits on BuiltInFunction because both Function flag words are full,
and builtins are registered by the host in every process, so nothing has to
be serialized. Mark at the binding rather than under DAS_AOT_COMPILER: the
same TU is compiled into both the AOT compiler and the runtime, so both fold
the same way and the AOT hashes keep matching.1 parent 0c18f85 commit 70e34f4
2 files changed
Lines changed: 16 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1038 | 1038 | | |
1039 | 1039 | | |
1040 | 1040 | | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
1041 | 1046 | | |
1042 | 1047 | | |
1043 | 1048 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
10 | 17 | | |
11 | 18 | | |
12 | 19 | | |
| |||
829 | 836 | | |
830 | 837 | | |
831 | 838 | | |
832 | | - | |
| 839 | + | |
833 | 840 | | |
834 | 841 | | |
835 | 842 | | |
| |||
880 | 887 | | |
881 | 888 | | |
882 | 889 | | |
883 | | - | |
| 890 | + | |
884 | 891 | | |
885 | 892 | | |
886 | 893 | | |
| |||
1089 | 1096 | | |
1090 | 1097 | | |
1091 | 1098 | | |
1092 | | - | |
| 1099 | + | |
1093 | 1100 | | |
1094 | 1101 | | |
1095 | 1102 | | |
| |||
1308 | 1315 | | |
1309 | 1316 | | |
1310 | 1317 | | |
1311 | | - | |
| 1318 | + | |
1312 | 1319 | | |
1313 | 1320 | | |
1314 | 1321 | | |
| |||
0 commit comments