@@ -18,16 +18,22 @@ bool EagerCalls::apply(Compiler& cmp, ClosureVersion* cls, Code* code,
1818 LogStream& log) const {
1919 AvailableCheckpoints checkpoint (cls, code, log);
2020
21+ struct Speculation {
22+ SEXP builtin;
23+ Checkpoint* cp;
24+ FeedbackOrigin origin;
25+ };
26+
2127 auto replaceLdFunBuiltinWithDeopt = [&](BB* bb, BB::Instrs::iterator ip,
22- Checkpoint* cp, SEXP builtin ,
28+ const Speculation& speculation ,
2329 LdFun* ldfun) {
2430 assert (LdFun::Cast (*ip));
25- assert (cp);
31+ assert (speculation. cp );
2632
2733 // skip ldfun
2834 ++ip;
2935
30- auto expected = new LdConst (builtin);
36+ auto expected = new LdConst (speculation. builtin );
3137 ip = bb->insert (ip, expected);
3238 ++ip;
3339 Instruction* given = ldfun;
@@ -54,7 +60,9 @@ bool EagerCalls::apply(Compiler& cmp, ClosureVersion* cls, Code* code,
5460 ip = bb->insert (ip, test);
5561 ++ip;
5662
57- auto assume = new Assume (test, cp);
63+ auto assume = new Assume (
64+ test, speculation.cp ,
65+ DeoptReason (speculation.origin , DeoptReason::Calltarget));
5866 ip = bb->insert (ip, assume);
5967 ++ip;
6068
@@ -105,7 +113,8 @@ bool EagerCalls::apply(Compiler& cmp, ClosureVersion* cls, Code* code,
105113 };
106114
107115 // Search for calls that likely point to a builtin.
108- std::unordered_map<LdFun*, std::pair<SEXP, Checkpoint*>> needsGuard;
116+ std::unordered_map<LdFun*, Speculation> needsGuard;
117+
109118 Visitor::run (code->entry , [&](BB* bb) {
110119 auto ip = bb->begin ();
111120 while (ip != bb->end ()) {
@@ -144,8 +153,8 @@ bool EagerCalls::apply(Compiler& cmp, ClosureVersion* cls, Code* code,
144153 Effect::DependsOnAssume));
145154 }
146155 } else if (auto ldfun = LdFun::Cast (call->cls ())) {
147- if (ldfun->hint && !ldfun->hintIsInnerFunction ) {
148- auto kind = TYPEOF (ldfun->hint );
156+ if (ldfun->hint () && !ldfun->hintIsInnerFunction ) {
157+ auto kind = TYPEOF (ldfun->hint () );
149158 // We also speculate on calls to CLOSXPs, these will
150159 // be picked up by MatchArgs opt pass and turned
151160 // into a static call. TODO, for inner functions we
@@ -157,9 +166,10 @@ bool EagerCalls::apply(Compiler& cmp, ClosureVersion* cls, Code* code,
157166 if (auto cp = checkpoint.at (ldfun)) {
158167 if (kind == BUILTINSXP) {
159168 ip = replaceCallWithCallBuiltin (
160- bb, ip, call, ldfun->hint , true );
169+ bb, ip, call, ldfun->hint () , true );
161170 }
162- needsGuard[ldfun] = {ldfun->hint , cp};
171+ needsGuard[ldfun] = {ldfun->hint (), cp,
172+ ldfun->hintOrigin ()};
163173 }
164174 }
165175 } else {
@@ -218,8 +228,7 @@ bool EagerCalls::apply(Compiler& cmp, ClosureVersion* cls, Code* code,
218228 if (auto ldfun = LdFun::Cast (*ip)) {
219229 auto r = needsGuard.find (ldfun);
220230 if (r != needsGuard.end ()) {
221- ip = replaceLdFunBuiltinWithDeopt (bb, ip, r->second .second ,
222- r->second .first , ldfun);
231+ ip = replaceLdFunBuiltinWithDeopt (bb, ip, r->second , ldfun);
223232 needsGuard.erase (r);
224233 continue ;
225234 }
0 commit comments