Skip to content

Commit f62335b

Browse files
committed
[llvm][NFC] Style fixes in Inliner.cpp
Summary: Function names: camel case, lower case first letter. Variable names: start with upper letter. For iterators that were 'i', renamed with a descriptive name, as 'I' is 'Instruction&'. Lambda captures simplification. Opportunistic boolean return simplification. Reviewers: davidxl, dblaikie Subscribers: eraman, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77837
1 parent 6d7c25b commit f62335b

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

llvm/lib/Transforms/IPO/Inliner.cpp

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static void mergeInlinedArrayAllocas(
181181

182182
// Loop over all the allocas we have so far and see if they can be merged with
183183
// a previously inlined alloca. If not, remember that we had it.
184-
for (unsigned AllocaNo = 0, e = IFI.StaticAllocas.size(); AllocaNo != e;
184+
for (unsigned AllocaNo = 0, E = IFI.StaticAllocas.size(); AllocaNo != E;
185185
++AllocaNo) {
186186
AllocaInst *AI = IFI.StaticAllocas[AllocaNo];
187187

@@ -272,7 +272,7 @@ static void mergeInlinedArrayAllocas(
272272
/// available from other functions inlined into the caller. If we are able to
273273
/// inline this call site we attempt to reuse already available allocas or add
274274
/// any new allocas to the set if not possible.
275-
static InlineResult InlineCallIfPossible(
275+
static InlineResult inlineCallIfPossible(
276276
CallBase &CS, InlineFunctionInfo &IFI,
277277
InlinedArrayAllocasTy &InlinedArrayAllocas, int InlineHistory,
278278
bool InsertLifetime, function_ref<AAResults &(Function &)> &AARGetter,
@@ -338,7 +338,7 @@ shouldBeDeferred(Function *Caller, InlineCost IC, int &TotalSecondaryCost,
338338
// can apply a huge negative bonus to TotalSecondaryCost.
339339
bool ApplyLastCallBonus = Caller->hasLocalLinkage() && !Caller->hasOneUse();
340340
// This bool tracks what happens if we DO inline C into B.
341-
bool inliningPreventsSomeOuterInline = false;
341+
bool InliningPreventsSomeOuterInline = false;
342342
for (User *U : Caller->users()) {
343343
// If the caller will not be removed (either because it does not have a
344344
// local linkage or because the LastCallToStaticBonus has been already
@@ -368,7 +368,7 @@ shouldBeDeferred(Function *Caller, InlineCost IC, int &TotalSecondaryCost,
368368
// this callsite. We subtract off the penalty for the call instruction,
369369
// which we would be deleting.
370370
if (IC2.getCostDelta() <= CandidateCost) {
371-
inliningPreventsSomeOuterInline = true;
371+
InliningPreventsSomeOuterInline = true;
372372
TotalSecondaryCost += IC2.getCost();
373373
}
374374
}
@@ -379,10 +379,7 @@ shouldBeDeferred(Function *Caller, InlineCost IC, int &TotalSecondaryCost,
379379
if (ApplyLastCallBonus)
380380
TotalSecondaryCost -= InlineConstants::LastCallToStaticBonus;
381381

382-
if (inliningPreventsSomeOuterInline && TotalSecondaryCost < IC.getCost())
383-
return true;
384-
385-
return false;
382+
return InliningPreventsSomeOuterInline && TotalSecondaryCost < IC.getCost();
386383
}
387384

388385
static std::basic_ostream<char> &operator<<(std::basic_ostream<char> &R,
@@ -479,7 +476,7 @@ shouldInline(CallBase &CS, function_ref<InlineCost(CallBase &CS)> GetInlineCost,
479476

480477
/// Return true if the specified inline history ID
481478
/// indicates an inline history that includes the specified function.
482-
static bool InlineHistoryIncludes(
479+
static bool inlineHistoryIncludes(
483480
Function *F, int InlineHistoryID,
484481
const SmallVectorImpl<std::pair<Function *, int>> &InlineHistory) {
485482
while (InlineHistoryID != -1) {
@@ -504,9 +501,9 @@ bool LegacyInlinerBase::runOnSCC(CallGraphSCC &SCC) {
504501
return inlineCalls(SCC);
505502
}
506503

507-
static void emit_inlined_into(OptimizationRemarkEmitter &ORE, DebugLoc &DLoc,
508-
const BasicBlock *Block, const Function &Callee,
509-
const Function &Caller, const InlineCost &IC) {
504+
static void emitInlinedInto(OptimizationRemarkEmitter &ORE, DebugLoc &DLoc,
505+
const BasicBlock *Block, const Function &Callee,
506+
const Function &Caller, const InlineCost &IC) {
510507
ORE.emit([&]() {
511508
bool AlwaysInline = IC.isAlways();
512509
StringRef RemarkName = AlwaysInline ? "AlwaysInline" : "Inlined";
@@ -520,8 +517,8 @@ static void setInlineRemark(CallBase &CS, StringRef Message) {
520517
if (!InlineRemarkAttribute)
521518
return;
522519

523-
Attribute attr = Attribute::get(CS.getContext(), "inline-remark", Message);
524-
CS.addAttribute(AttributeList::FunctionIndex, attr);
520+
Attribute Attr = Attribute::get(CS.getContext(), "inline-remark", Message);
521+
CS.addAttribute(AttributeList::FunctionIndex, Attr);
525522
}
526523

527524
static bool
@@ -598,10 +595,10 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
598595
// Now that we have all of the call sites, move the ones to functions in the
599596
// current SCC to the end of the list.
600597
unsigned FirstCallInSCC = CallSites.size();
601-
for (unsigned i = 0; i < FirstCallInSCC; ++i)
602-
if (Function *F = CallSites[i].first->getCalledFunction())
598+
for (unsigned I = 0; I < FirstCallInSCC; ++I)
599+
if (Function *F = CallSites[I].first->getCalledFunction())
603600
if (SCCFunctions.count(F))
604-
std::swap(CallSites[i--], CallSites[--FirstCallInSCC]);
601+
std::swap(CallSites[I--], CallSites[--FirstCallInSCC]);
605602

606603
InlinedArrayAllocasTy InlinedArrayAllocas;
607604
InlineFunctionInfo InlineInfo(&CG, &GetAssumptionCache, PSI);
@@ -639,7 +636,7 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
639636
// infinitely inline.
640637
InlineHistoryID = CallSites[CSi].second;
641638
if (InlineHistoryID != -1 &&
642-
InlineHistoryIncludes(Callee, InlineHistoryID, InlineHistory)) {
639+
inlineHistoryIncludes(Callee, InlineHistoryID, InlineHistory)) {
643640
setInlineRemark(CS, "recursive");
644641
continue;
645642
}
@@ -684,7 +681,7 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
684681
// Attempt to inline the function.
685682
using namespace ore;
686683

687-
InlineResult IR = InlineCallIfPossible(
684+
InlineResult IR = inlineCallIfPossible(
688685
CS, InlineInfo, InlinedArrayAllocas, InlineHistoryID,
689686
InsertLifetime, AARGetter, ImportedFunctionsStats);
690687
if (!IR.isSuccess()) {
@@ -701,7 +698,7 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
701698
}
702699
++NumInlined;
703700

704-
emit_inlined_into(ORE, DLoc, Block, *Callee, *Caller, *OIC);
701+
emitInlinedInto(ORE, DLoc, Block, *Callee, *Caller, *OIC);
705702

706703
// If inlining this function gave us any new call sites, throw them
707704
// onto our worklist to process. They are useful inline candidates.
@@ -784,8 +781,8 @@ bool LegacyInlinerBase::inlineCalls(CallGraphSCC &SCC) {
784781
};
785782
return inlineCallsImpl(
786783
SCC, CG, GetAssumptionCache, PSI, GetTLI, InsertLifetime,
787-
[this](CallBase &CS) { return getInlineCost(CS); },
788-
LegacyAARGetter(*this), ImportedFunctionsStats);
784+
[&](CallBase &CS) { return getInlineCost(CS); }, LegacyAARGetter(*this),
785+
ImportedFunctionsStats);
789786
}
790787

791788
/// Remove now-dead linkonce functions at the end of
@@ -986,17 +983,17 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
986983

987984
// Loop forward over all of the calls. Note that we cannot cache the size as
988985
// inlining can introduce new calls that need to be processed.
989-
for (int i = 0; i < (int)Calls.size(); ++i) {
986+
for (int I = 0; I < (int)Calls.size(); ++I) {
990987
// We expect the calls to typically be batched with sequences of calls that
991988
// have the same caller, so we first set up some shared infrastructure for
992989
// this caller. We also do any pruning we can at this layer on the caller
993990
// alone.
994-
Function &F = *Calls[i].first->getCaller();
991+
Function &F = *Calls[I].first->getCaller();
995992
LazyCallGraph::Node &N = *CG.lookup(F);
996993
if (CG.lookupSCC(N) != C)
997994
continue;
998995
if (F.hasOptNone()) {
999-
setInlineRemark(*Calls[i].first, "optnone attribute");
996+
setInlineRemark(*Calls[I].first, "optnone attribute");
1000997
continue;
1001998
}
1002999

@@ -1041,14 +1038,14 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
10411038
// We bail out as soon as the caller has to change so we can update the
10421039
// call graph and prepare the context of that new caller.
10431040
bool DidInline = false;
1044-
for (; i < (int)Calls.size() && Calls[i].first->getCaller() == &F; ++i) {
1041+
for (; I < (int)Calls.size() && Calls[I].first->getCaller() == &F; ++I) {
10451042
int InlineHistoryID;
10461043
CallBase *CS = nullptr;
1047-
std::tie(CS, InlineHistoryID) = Calls[i];
1044+
std::tie(CS, InlineHistoryID) = Calls[I];
10481045
Function &Callee = *CS->getCalledFunction();
10491046

10501047
if (InlineHistoryID != -1 &&
1051-
InlineHistoryIncludes(&Callee, InlineHistoryID, InlineHistory)) {
1048+
inlineHistoryIncludes(&Callee, InlineHistoryID, InlineHistory)) {
10521049
setInlineRemark(*CS, "recursive");
10531050
continue;
10541051
}
@@ -1111,7 +1108,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
11111108

11121109
++NumInlined;
11131110

1114-
emit_inlined_into(ORE, DLoc, Block, Callee, F, *OIC);
1111+
emitInlinedInto(ORE, DLoc, Block, Callee, F, *OIC);
11151112

11161113
// Add any new callsites to defined functions to the worklist.
11171114
if (!IFI.InlinedCallSites.empty()) {
@@ -1152,8 +1149,8 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
11521149
Callee.removeDeadConstantUsers();
11531150
if (Callee.use_empty() && !CG.isLibFunction(Callee)) {
11541151
Calls.erase(
1155-
std::remove_if(Calls.begin() + i + 1, Calls.end(),
1156-
[&Callee](const std::pair<CallBase *, int> &Call) {
1152+
std::remove_if(Calls.begin() + I + 1, Calls.end(),
1153+
[&](const std::pair<CallBase *, int> &Call) {
11571154
return Call.first->getCaller() == &Callee;
11581155
}),
11591156
Calls.end());
@@ -1171,7 +1168,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
11711168

11721169
// Back the call index up by one to put us in a good position to go around
11731170
// the outer loop.
1174-
--i;
1171+
--I;
11751172

11761173
if (!DidInline)
11771174
continue;

0 commit comments

Comments
 (0)