Skip to content

Commit

Permalink
Select callee entry for inlining even if guard may fail when there's …
Browse files Browse the repository at this point in the history
…a single candidate

Summary:
When a function argument's type is relaxed (eg, because it's simply loaded from a local) but the callee
guards on a specific type, the JIT would refuse inlining because the argument type was not a subtype
of the guarded type in the callee. This diff relaxes that condition by searching for all entry blocks
where the guards may succeed (ie, if the argument type intersects the callee's guarded type) and,
in case there's only one such block, selecting that one.

Reviewed By: mofarrell

Differential Revision: D15640002

fbshipit-source-id: d6dff01ecbe38bbf60daf0c5c3f2457a710f46a3
  • Loading branch information
ottoni authored and hhvm-bot committed Jun 5, 2019
1 parent 041304c commit a962f2a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions hphp/runtime/vm/jit/inlining-decider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,8 @@ TransID findTransIDForCallee(const ProfData* profData,
TransID ret = kInvalidTransID;
bool hasThisVaries = callee->hasThisVaries() &&
ctxType.maybe(TObj) && !(ctxType <= TObj);
FTRACE(2, "findTransIDForCallee: offset={} hasThisVaries={}\n",
offset, hasThisVaries);
for (auto const id : idvec) {
auto const rec = profData->transRec(id);
if (rec->startBcOff() != offset) continue;
Expand All @@ -750,17 +752,16 @@ TransID findTransIDForCallee(const ProfData* profData,
if (typeloc.location.tag() != LTag::Local) continue;
auto const locId = typeloc.location.localId();

if (locId < numArgs && !(argTypes[locId] <= typeloc.type)) {
if (locId < numArgs && !(argTypes[locId].maybe(typeloc.type))) {
return false;
}
}
return true;
}();

if (!isvalid) continue;
if (!hasThisVaries) return id;
// The function may be called with or without $this, if we've seen
// both, give up.
// Found multiple entries that may match the arguments, so don't return
// any.
if (ret != kInvalidTransID) return kInvalidTransID;
ret = id;
}
Expand Down Expand Up @@ -858,6 +859,7 @@ RegionDescPtr selectCalleeRegion(const irgen::IRGS& irgs,
}
}

FTRACE(2, "selectCalleeRegion: callee = {}\n", callee->fullName()->data());
std::vector<Type> argTypes;
for (int i = fca.numArgs - 1; i >= 0; --i) {
// DataTypeGeneric is used because we're just passing the locals into the
Expand All @@ -873,6 +875,7 @@ RegionDescPtr selectCalleeRegion(const irgen::IRGS& irgs,
annotationsPtr);
return nullptr;
}
FTRACE(2, "arg {}: {}\n", i, type);
argTypes.push_back(type);
}

Expand Down

0 comments on commit a962f2a

Please sign in to comment.