Skip to content

Commit a8b9cdc

Browse files
author
Easwaran Raman
committed
[InlineCost] Move the code in isGEPOffsetConstant to a lambda.
Differential revision: https://reviews.llvm.org/D30112 llvm-svn: 296208
1 parent 7ff4c04 commit a8b9cdc

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

llvm/lib/Analysis/InlineCost.cpp

+9-13
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
142142
void disableSROA(Value *V);
143143
void accumulateSROACost(DenseMap<Value *, int>::iterator CostIt,
144144
int InstructionCost);
145-
bool isGEPOffsetConstant(GetElementPtrInst &GEP);
146145
bool isGEPFree(GetElementPtrInst &GEP);
147146
bool accumulateGEPOffset(GEPOperator &GEP, APInt &Offset);
148147
bool simplifyCallSite(Function *F, CallSite CS);
@@ -300,17 +299,6 @@ void CallAnalyzer::accumulateSROACost(DenseMap<Value *, int>::iterator CostIt,
300299
SROACostSavings += InstructionCost;
301300
}
302301

303-
/// \brief Check whether a GEP's indices are all constant.
304-
///
305-
/// Respects any simplified values known during the analysis of this callsite.
306-
bool CallAnalyzer::isGEPOffsetConstant(GetElementPtrInst &GEP) {
307-
for (User::op_iterator I = GEP.idx_begin(), E = GEP.idx_end(); I != E; ++I)
308-
if (!isa<Constant>(*I) && !SimplifiedValues.lookup(*I))
309-
return false;
310-
311-
return true;
312-
}
313-
314302
/// \brief Accumulate a constant GEP offset into an APInt if possible.
315303
///
316304
/// Returns false if unable to compute the offset for any reason. Respects any
@@ -440,7 +428,15 @@ bool CallAnalyzer::visitGetElementPtr(GetElementPtrInst &I) {
440428
}
441429
}
442430

443-
if (isGEPOffsetConstant(I)) {
431+
// Lambda to check whether a GEP's indices are all constant.
432+
auto IsGEPOffsetConstant = [&](GetElementPtrInst &GEP) {
433+
for (User::op_iterator I = GEP.idx_begin(), E = GEP.idx_end(); I != E; ++I)
434+
if (!isa<Constant>(*I) && !SimplifiedValues.lookup(*I))
435+
return false;
436+
return true;
437+
};
438+
439+
if (IsGEPOffsetConstant(I)) {
444440
if (SROACandidate)
445441
SROAArgValues[&I] = SROAArg;
446442

0 commit comments

Comments
 (0)