[llvm][NFC] Inliner.cpp: ensure InlineHistory ID is always initialized;

Summary:
The inline history is associated with a call site. There are two locations
we fetch inline history. In one, we fetch it together with the call
site. In the other, we initialize it under certain conditions, use it
later under same conditions (different if check), and otherwise is
uninitialized. Although currently there is no uninitialized use, the
code is more challenging to maintain correctly, than if the value were
always initialized.

Changed to the upfront initialization pattern already present in this
file.

Reviewers: davidxl, dblaikie

Subscribers: eraman, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77877
This commit is contained in:
Mircea Trofin 2020-04-10 08:16:49 -07:00
parent dfca98d6a8
commit da9bcdaad9
1 changed files with 9 additions and 12 deletions

View File

@ -613,7 +613,9 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
// calls to become direct calls.
// CallSites may be modified inside so ranged for loop can not be used.
for (unsigned CSi = 0; CSi != CallSites.size(); ++CSi) {
CallBase &CS = *CallSites[CSi].first;
auto &P = CallSites[CSi];
CallBase &CS = *P.first;
const int InlineHistoryID = P.second;
Function *Caller = CS.getCaller();
Function *Callee = CS.getCalledFunction();
@ -622,19 +624,14 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
if (!Callee || Callee->isDeclaration())
continue;
Instruction *Instr = &CS;
bool IsTriviallyDead = isInstructionTriviallyDead(&CS, &GetTLI(*Caller));
bool IsTriviallyDead =
isInstructionTriviallyDead(Instr, &GetTLI(*Caller));
int InlineHistoryID;
if (!IsTriviallyDead) {
// If this call site was obtained by inlining another function, verify
// that the include path for the function did not include the callee
// itself. If so, we'd be recursively inlining the same function,
// which would provide the same callsites, which would cause us to
// infinitely inline.
InlineHistoryID = CallSites[CSi].second;
if (InlineHistoryID != -1 &&
inlineHistoryIncludes(Callee, InlineHistoryID, InlineHistory)) {
setInlineRemark(CS, "recursive");
@ -667,11 +664,11 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
// size. This happens because IPSCCP propagates the result out of the
// call and then we're left with the dead call.
if (IsTriviallyDead) {
LLVM_DEBUG(dbgs() << " -> Deleting dead call: " << *Instr << "\n");
LLVM_DEBUG(dbgs() << " -> Deleting dead call: " << CS << "\n");
// Update the call graph by deleting the edge from Callee to Caller.
setInlineRemark(CS, "trivially dead");
CG[Caller]->removeCallEdgeFor(CS);
Instr->eraseFromParent();
CS.eraseFromParent();
++NumCallsDeleted;
} else {
// Get DebugLoc to report. CS will be invalid after Inliner.
@ -1039,9 +1036,9 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
// call graph and prepare the context of that new caller.
bool DidInline = false;
for (; I < (int)Calls.size() && Calls[I].first->getCaller() == &F; ++I) {
int InlineHistoryID;
CallBase *CS = nullptr;
std::tie(CS, InlineHistoryID) = Calls[I];
auto &P = Calls[I];
CallBase *CS = P.first;
const int InlineHistoryID = P.second;
Function &Callee = *CS->getCalledFunction();
if (InlineHistoryID != -1 &&