forked from OSchip/llvm-project
[BOLT] Bail frame analysis on PUSHes escaping vars
Summary: Some PUSH instructions may contain memory addresses pushed to the stack. If this memory address is from an object in the stack, cancel further frame analysis for this function since it may be escaping a variable. This fixes a bug with deleting used stores (in frameopt) in hhvm trunk. (cherry picked from FBD5270590)
This commit is contained in:
parent
37d0f81df5
commit
8233c7d204
|
@ -202,7 +202,7 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
if (BC.MIA->leaksStackAddress(Inst, *BC.MRI, SPT.HasFramePointer)) {
|
||||
if (BC.MIA->escapesVariable(Inst, *BC.MRI, SPT.HasFramePointer)) {
|
||||
DEBUG(dbgs() << "Leaked stack address, giving up on this function.\n");
|
||||
DEBUG(dbgs() << "Blame insn: ");
|
||||
DEBUG(Inst.dump());
|
||||
|
@ -286,6 +286,21 @@ void FrameAnalysis::traverseCG(BinaryFunctionCallGraph &CG) {
|
|||
});
|
||||
|
||||
CGWalker.walk();
|
||||
|
||||
DEBUG_WITH_TYPE("ra",
|
||||
for (auto &MapEntry : ArgsTouchedMap) {
|
||||
const auto *Func = MapEntry.first;
|
||||
const auto &Set = MapEntry.second;
|
||||
dbgs() << "Args accessed for " << Func->getPrintName() << ": ";
|
||||
if (!Set.empty() && Set.count(std::make_pair(-1, 0))) {
|
||||
dbgs() << "assume everything";
|
||||
} else {
|
||||
for (auto &Entry : Set) {
|
||||
dbgs() << "[" << Entry.first << ", " << (int)Entry.second << "] ";
|
||||
}
|
||||
}
|
||||
dbgs() << "\n";
|
||||
});
|
||||
}
|
||||
|
||||
bool FrameAnalysis::updateArgsTouchedFor(const BinaryFunction &BF, MCInst &Inst,
|
||||
|
@ -373,6 +388,8 @@ bool FrameAnalysis::computeArgsAccessed(BinaryFunction &BF) {
|
|||
return Updated;
|
||||
}
|
||||
|
||||
DEBUG(dbgs() << "Now computing args accessed for: " << BF.getPrintName()
|
||||
<< "\n");
|
||||
bool UpdatedArgsTouched = false;
|
||||
FrameAccessAnalysis FAA(BC, BF);
|
||||
|
||||
|
|
|
@ -197,6 +197,8 @@ void FrameOptimizerPass::removeUnusedStores(const FrameAnalysis &FA,
|
|||
DEBUG(dbgs() << "Unused store instruction: ");
|
||||
DEBUG(Inst.dump());
|
||||
DEBUG(dbgs() << "@BB: " << BB.getName() << "\n");
|
||||
DEBUG(dbgs() << "FIE offset = " << FIEX->StackOffset
|
||||
<< " size = " << (int)FIEX->Size << "\n");
|
||||
// Delete it!
|
||||
ToErase.push_back(std::make_pair(&BB, &Inst));
|
||||
Prev = &Inst;
|
||||
|
|
|
@ -68,7 +68,7 @@ RegAnalysis::RegAnalysis(BinaryContext &BC,
|
|||
CountFunctionsAllClobber += Count;
|
||||
++NumFunctionsAllClobber;
|
||||
}
|
||||
DEBUG_WITH_TYPE("fa",
|
||||
DEBUG_WITH_TYPE("ra",
|
||||
dbgs() << "Killed regs set for func: " << Func->getPrintName() << "\n";
|
||||
const BitVector &RegsKilled = Iter->second;
|
||||
int RegIdx = RegsKilled.find_first();
|
||||
|
|
|
@ -159,7 +159,7 @@ protected:
|
|||
return SUPERPOSITION;
|
||||
|
||||
if (!HasFramePointer) {
|
||||
if (MIA->leaksStackAddress(Point, *this->BC.MRI, false)) {
|
||||
if (MIA->escapesVariable(Point, *this->BC.MRI, false)) {
|
||||
HasFramePointer = true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue