Skip to content

Commit

Permalink
[InlineCost] Move the code in isGEPOffsetConstant to a lambda.
Browse files Browse the repository at this point in the history
Differential revision: https://reviews.llvm.org/D30112

llvm-svn: 296208
  • Loading branch information
Easwaran Raman committed Feb 25, 2017
1 parent 7ff4c04 commit a8b9cdc
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions llvm/lib/Analysis/InlineCost.cpp
Expand Up @@ -142,7 +142,6 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
void disableSROA(Value *V);
void accumulateSROACost(DenseMap<Value *, int>::iterator CostIt,
int InstructionCost);
bool isGEPOffsetConstant(GetElementPtrInst &GEP);
bool isGEPFree(GetElementPtrInst &GEP);
bool accumulateGEPOffset(GEPOperator &GEP, APInt &Offset);
bool simplifyCallSite(Function *F, CallSite CS);
Expand Down Expand Up @@ -300,17 +299,6 @@ void CallAnalyzer::accumulateSROACost(DenseMap<Value *, int>::iterator CostIt,
SROACostSavings += InstructionCost;
}

/// \brief Check whether a GEP's indices are all constant.
///
/// Respects any simplified values known during the analysis of this callsite.
bool CallAnalyzer::isGEPOffsetConstant(GetElementPtrInst &GEP) {
for (User::op_iterator I = GEP.idx_begin(), E = GEP.idx_end(); I != E; ++I)
if (!isa<Constant>(*I) && !SimplifiedValues.lookup(*I))
return false;

return true;
}

/// \brief Accumulate a constant GEP offset into an APInt if possible.
///
/// Returns false if unable to compute the offset for any reason. Respects any
Expand Down Expand Up @@ -440,7 +428,15 @@ bool CallAnalyzer::visitGetElementPtr(GetElementPtrInst &I) {
}
}

if (isGEPOffsetConstant(I)) {
// Lambda to check whether a GEP's indices are all constant.
auto IsGEPOffsetConstant = [&](GetElementPtrInst &GEP) {
for (User::op_iterator I = GEP.idx_begin(), E = GEP.idx_end(); I != E; ++I)
if (!isa<Constant>(*I) && !SimplifiedValues.lookup(*I))
return false;
return true;
};

if (IsGEPOffsetConstant(I)) {
if (SROACandidate)
SROAArgValues[&I] = SROAArg;

Expand Down

0 comments on commit a8b9cdc

Please sign in to comment.