Author: Nikita Popov Date: 2021-07-09T21:41:20+02:00 New Revision: 2e3f4694d61dd50c8ec1278331edee84a60555f8
URL: https://github.com/llvm/llvm-project/commit/2e3f4694d61dd50c8ec1278331edee84a60555f8 DIFF: https://github.com/llvm/llvm-project/commit/2e3f4694d61dd50c8ec1278331edee84a60555f8.diff LOG: [IR] Add GEPOperator::indices() (NFC) In order to mirror the GetElementPtrInst::indices() API. Wanted to use this in the IRForTarget code, and was surprised to find that it didn't exist yet. Added: Modified: lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp llvm/include/llvm/IR/Operator.h llvm/lib/Analysis/ScalarEvolution.cpp Removed: ################################################################################ diff --git a/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp b/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp index b3188ec56fdf..5655d548ee34 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp @@ -1582,14 +1582,7 @@ bool IRForTarget::UnfoldConstant(Constant *old_constant, ptr = value_maker.GetValue(function); std::vector<Value *> index_vector; - - unsigned operand_index; - unsigned num_operands = constant_expr->getNumOperands(); - - for (operand_index = 1; operand_index < num_operands; - ++operand_index) { - Value *operand = constant_expr->getOperand(operand_index); - + for (Value *operand : gep->indices()) { if (operand == old_constant) operand = value_maker.GetValue(function); diff --git a/llvm/include/llvm/IR/Operator.h b/llvm/include/llvm/IR/Operator.h index 46c1dfc3e735..d0bce742cc96 100644 --- a/llvm/include/llvm/IR/Operator.h +++ b/llvm/include/llvm/IR/Operator.h @@ -488,6 +488,14 @@ class GEPOperator inline op_iterator idx_end() { return op_end(); } inline const_op_iterator idx_end() const { return op_end(); } + inline iterator_range<op_iterator> indices() { + return make_range(idx_begin(), idx_end()); + } + + inline iterator_range<const_op_iterator> indices() const { + return make_range(idx_begin(), idx_end()); + } + Value *getPointerOperand() { return getOperand(0); } @@ -544,7 +552,7 @@ class GEPOperator } unsigned countNonConstantIndices() const { - return count_if(make_range(idx_begin(), idx_end()), [](const Use& use) { + return count_if(indices(), [](const Use& use) { return !isa<ConstantInt>(*use); }); } diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 843c04855bf7..221b116d4371 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -5732,8 +5732,8 @@ const SCEV *ScalarEvolution::createNodeForGEP(GEPOperator *GEP) { return getUnknown(GEP); SmallVector<const SCEV *, 4> IndexExprs; - for (auto Index = GEP->idx_begin(); Index != GEP->idx_end(); ++Index) - IndexExprs.push_back(getSCEV(*Index)); + for (Value *Index : GEP->indices()) + IndexExprs.push_back(getSCEV(Index)); return getGEPExpr(GEP, IndexExprs); } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits