[PATCH] [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction
David Blaikie
dblaikie at gmail.com
Fri Feb 13 17:34:13 PST 2015
Line wrapping some text in the description.
http://reviews.llvm.org/D7636
Files:
include/llvm/IR/Instructions.h
lib/AsmParser/LLParser.cpp
lib/IR/AsmWriter.cpp
unittests/IR/ConstantsTest.cpp
Index: include/llvm/IR/Instructions.h
===================================================================
--- include/llvm/IR/Instructions.h
+++ include/llvm/IR/Instructions.h
@@ -845,6 +845,13 @@
return cast<SequentialType>(Instruction::getType());
}
+ Type *getSourceElementType() const {
+ SequentialType *Ty = cast<SequentialType>(getPointerOperandType());
+ if (VectorType *VTy = dyn_cast<VectorType>(Ty))
+ Ty = cast<SequentialType>(VTy->getElementType());
+ return Ty->getElementType();
+ }
+
/// \brief Returns the address space of this instruction's pointer type.
unsigned getAddressSpace() const {
// Note that this is always the same as the pointer operand's address space
Index: lib/AsmParser/LLParser.cpp
===================================================================
--- lib/AsmParser/LLParser.cpp
+++ lib/AsmParser/LLParser.cpp
@@ -5364,8 +5364,18 @@
bool InBounds = EatIfPresent(lltok::kw_inbounds);
+ Type *Ty = nullptr;
+ if (ParseType(Ty)) return true;
+ ParseToken(lltok::comma, "expected comma after getelementptr's type");
+
if (ParseTypeAndValue(Ptr, Loc, PFS)) return true;
+
+ Type *PtrTy = Ptr->getType();
+ if (VectorType *VT = dyn_cast<VectorType>(PtrTy))
+ PtrTy = VT->getElementType();
+ assert(Ty == cast<SequentialType>(PtrTy)->getElementType());
+
Type *BaseType = Ptr->getType();
PointerType *BasePointerType = dyn_cast<PointerType>(BaseType->getScalarType());
if (!BasePointerType)
Index: lib/IR/AsmWriter.cpp
===================================================================
--- lib/IR/AsmWriter.cpp
+++ lib/IR/AsmWriter.cpp
@@ -2880,6 +2880,11 @@
Out << ", ";
TypePrinter.print(I.getType(), Out);
} else if (Operand) { // Print the normal way.
+ if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(&I)) {
+ Out << ' ';
+ TypePrinter.print(GEP->getSourceElementType(), Out);
+ Out << ',';
+ }
// PrintAllTypes - Instructions who have operands of all the same type
// omit the type from all but the first operand. If the instruction has
Index: unittests/IR/ConstantsTest.cpp
===================================================================
--- unittests/IR/ConstantsTest.cpp
+++ unittests/IR/ConstantsTest.cpp
@@ -246,9 +246,9 @@
// FIXME: getGetElementPtr() actually creates an inbounds ConstantGEP,
// not a normal one!
//CHECK(ConstantExpr::getGetElementPtr(Global, V, false),
- // "getelementptr i32** @dummy, i32 1");
+ // "getelementptr i32*, i32** @dummy, i32 1");
CHECK(ConstantExpr::getInBoundsGetElementPtr(Global, V),
- "getelementptr inbounds i32** @dummy, i32 1");
+ "getelementptr inbounds i32*, i32** @dummy, i32 1");
CHECK(ConstantExpr::getExtractElement(P6, One), "extractelement <2 x i16> "
P6STR ", i32 1");
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7636.19952.patch
Type: text/x-patch
Size: 2858 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150214/982f9f7b/attachment.bin>
More information about the llvm-commits
mailing list