summaryrefslogtreecommitdiffstats
path: root/llvm/lib/AsmParser/LLParser.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-07-27 21:53:46 +0000
committerDan Gohman <gohman@apple.com>2009-07-27 21:53:46 +0000
commit1639c3905e934654195318aba00f7eae3d5d677f (patch)
tree480fc9d2338e97b45b6fd2b06657dd8f23620dfe /llvm/lib/AsmParser/LLParser.cpp
parent52d03b252eb4abae3ad24c5757ffe683bf3620d6 (diff)
downloadbcm5719-llvm-1639c3905e934654195318aba00f7eae3d5d677f.tar.gz
bcm5719-llvm-1639c3905e934654195318aba00f7eae3d5d677f.zip
Add a new keyword 'inbounds' for use with getelementptr. See the
LangRef.html changes for details. llvm-svn: 77259
Diffstat (limited to 'llvm/lib/AsmParser/LLParser.cpp')
-rw-r--r--llvm/lib/AsmParser/LLParser.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index f9db40915ae..adcd79f40a3 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -457,7 +457,7 @@ bool LLParser::ParseStandaloneMetadata() {
/// Aliasee
/// ::= TypeAndValue
/// ::= 'bitcast' '(' TypeAndValue 'to' Type ')'
-/// ::= 'getelementptr' '(' ... ')'
+/// ::= 'getelementptr' 'inbounds'? '(' ... ')'
///
/// Everything through visibility has already been parsed.
///
@@ -2039,7 +2039,11 @@ bool LLParser::ParseValID(ValID &ID) {
case lltok::kw_select: {
unsigned Opc = Lex.getUIntVal();
SmallVector<Constant*, 16> Elts;
+ bool InBounds = false;
Lex.Lex();
+ if (Opc == Instruction::GetElementPtr)
+ if (EatIfPresent(lltok::kw_inbounds))
+ InBounds = true;
if (ParseToken(lltok::lparen, "expected '(' in constantexpr") ||
ParseGlobalValueVector(Elts) ||
ParseToken(lltok::rparen, "expected ')' in constantexpr"))
@@ -2055,6 +2059,8 @@ bool LLParser::ParseValID(ValID &ID) {
return Error(ID.Loc, "invalid indices for getelementptr");
ID.ConstantVal = Context.getConstantExprGetElementPtr(Elts[0],
Elts.data() + 1, Elts.size() - 1);
+ if (InBounds)
+ cast<GEPOperator>(ID.ConstantVal)->setIsInBounds(true);
} else if (Opc == Instruction::Select) {
if (Elts.size() != 3)
return Error(ID.Loc, "expected three operands to select");
@@ -3368,9 +3374,14 @@ bool LLParser::ParseGetResult(Instruction *&Inst, PerFunctionState &PFS) {
}
/// ParseGetElementPtr
-/// ::= 'getelementptr' TypeAndValue (',' TypeAndValue)*
+/// ::= 'getelementptr' 'inbounds'? TypeAndValue (',' TypeAndValue)*
bool LLParser::ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) {
Value *Ptr, *Val; LocTy Loc, EltLoc;
+ bool InBounds = false;
+
+ if (EatIfPresent(lltok::kw_inbounds))
+ InBounds = true;
+
if (ParseTypeAndValue(Ptr, Loc, PFS)) return true;
if (!isa<PointerType>(Ptr->getType()))
@@ -3388,6 +3399,8 @@ bool LLParser::ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) {
Indices.begin(), Indices.end()))
return Error(Loc, "invalid getelementptr indices");
Inst = GetElementPtrInst::Create(Ptr, Indices.begin(), Indices.end());
+ if (InBounds)
+ cast<GEPOperator>(Inst)->setIsInBounds(true);
return false;
}
OpenPOWER on IntegriCloud