[PATCH] D99341: [WIP][IR] allow `inrange` on non-constant GEP instructions.
Clement Courbet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 25 07:39:31 PDT 2021
courbet created this revision.
Herald added subscribers: dexonsmith, hiraditya.
courbet requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This is an experiment for the following RFC: https://groups.google.com/g/llvm-dev/c/T9o51zB1JHY. This only adds support for `inrange` in the parser.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D99341
Files:
llvm/include/llvm/IR/Instructions.h
llvm/include/llvm/IR/Operator.h
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/IR/Instructions.cpp
Index: llvm/lib/IR/Instructions.cpp
===================================================================
--- llvm/lib/IR/Instructions.cpp
+++ llvm/lib/IR/Instructions.cpp
@@ -1787,6 +1787,14 @@
return cast<GEPOperator>(this)->isInBounds();
}
+void GetElementPtrInst::setInRangeIndex(unsigned InRangeIndex) {
+ cast<GEPOperator>(this)->setInRangeIndex(InRangeIndex);
+}
+
+Optional<unsigned> GetElementPtrInst::getInRangeIndex() const {
+ return cast<GEPOperator>(this)->getInRangeIndex();
+}
+
bool GetElementPtrInst::accumulateConstantOffset(const DataLayout &DL,
APInt &Offset) const {
// Delegate to the generic GEPOperator implementation.
Index: llvm/lib/AsmParser/LLParser.cpp
===================================================================
--- llvm/lib/AsmParser/LLParser.cpp
+++ llvm/lib/AsmParser/LLParser.cpp
@@ -7643,7 +7643,7 @@
}
/// parseGetElementPtr
-/// ::= 'getelementptr' 'inbounds'? TypeAndValue (',' TypeAndValue)*
+/// ::= 'getelementptr' 'inbounds'? TypeAndValue (',' 'inrange'? TypeAndValue)*
int LLParser::parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) {
Value *Ptr = nullptr;
Value *Val = nullptr;
@@ -7675,11 +7675,14 @@
? cast<VectorType>(BaseType)->getElementCount()
: ElementCount::getFixed(0);
+ Optional<int> InRangeIndex;
while (EatIfPresent(lltok::comma)) {
if (Lex.getKind() == lltok::MetadataVar) {
AteExtraComma = true;
break;
}
+ if (EatIfPresent(lltok::kw_inrange) && !InRangeIndex)
+ InRangeIndex = Indices.size();
if (parseTypeAndValue(Val, EltLoc, PFS))
return true;
if (!Val->getType()->isIntOrIntVectorTy())
@@ -7705,6 +7708,8 @@
Inst = GetElementPtrInst::Create(Ty, Ptr, Indices);
if (InBounds)
cast<GetElementPtrInst>(Inst)->setIsInBounds(true);
+ if (InRangeIndex && *InRangeIndex < 63)
+ cast<GetElementPtrInst>(Inst)->setInRangeIndex(*InRangeIndex);
return AteExtraComma ? InstExtraComma : InstNormal;
}
Index: llvm/include/llvm/IR/Operator.h
===================================================================
--- llvm/include/llvm/IR/Operator.h
+++ llvm/include/llvm/IR/Operator.h
@@ -469,6 +469,12 @@
(SubclassOptionalData & ~IsInBounds) | (B * IsInBounds);
}
+ void setInRangeIndex(unsigned InRangeIndex) {
+ assert(InRangeIndex < 63 && "unsupported");
+ assert(!getInRangeIndex() && "trying to set multiple inrange indices");
+ SubclassOptionalData |= InRangeIndex << 1;
+ }
+
public:
/// Test whether this is an inbounds GEP, as defined by LangRef.html.
bool isInBounds() const {
Index: llvm/include/llvm/IR/Instructions.h
===================================================================
--- llvm/include/llvm/IR/Instructions.h
+++ llvm/include/llvm/IR/Instructions.h
@@ -1113,6 +1113,13 @@
/// Determine whether the GEP has the inbounds flag.
bool isInBounds() const;
+ /// Set the inrange index of this GEP instruction.
+ /// See LangRef.html for the meaning of inrange on a getelementptr.
+ void setInRangeIndex(unsigned InRangeIndex);
+
+ /// Determine whether the GEP has an inrange index.
+ Optional<unsigned> getInRangeIndex() const;
+
/// Accumulate the constant address offset of this GEP if possible.
///
/// This routine accepts an APInt into which it will accumulate the constant
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99341.333305.patch
Type: text/x-patch
Size: 3434 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210325/b113f975/attachment.bin>
More information about the llvm-commits
mailing list