From c88f9a1a5789b28a9b85bae90fed5ed87e1ec3d9 Mon Sep 17 00:00:00 2001 From: Sander de Smalen Date: Wed, 11 Apr 2018 14:10:37 +0000 Subject: [PATCH] [AArch64][AsmParser] Split index parsing from vector list. Summary: Place parsing of a vector index into a separate function to reduce duplication, since the code is duplicated in both the parsing of a Neon vector register operand and a Neon vector list. This is patch [2/6] in a series to add assembler/disassembler support for SVE's contiguous ST1 (scalar+imm) instructions. Reviewers: fhahn, rengolin, javed.absar, huntergr, SjoerdMeijer, t.p.northover, echristo, evandro Reviewed By: rengolin Subscribers: kristof.beyls, llvm-commits Differential Revision: https://reviews.llvm.org/D45428 llvm-svn: 329809 --- .../Target/AArch64/AsmParser/AArch64AsmParser.cpp | 50 ++++++++++------------ 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp index ee49f41..b44cebe 100644 --- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -88,7 +88,7 @@ private: int tryParseRegister(); bool parseRegister(OperandVector &Operands); bool parseSymbolicImmVal(const MCExpr *&ImmVal); - bool parseVectorList(OperandVector &Operands); + bool parseNeonVectorList(OperandVector &Operands); bool parseOperand(OperandVector &Operands, bool isCondCode, bool invertCondCode); @@ -135,10 +135,12 @@ private: OperandMatchResultTy tryParseAddSubImm(OperandVector &Operands); OperandMatchResultTy tryParseGPR64sp0Operand(OperandVector &Operands); bool tryParseNeonVectorRegister(OperandVector &Operands); + OperandMatchResultTy tryParseVectorIndex(OperandVector &Operands); OperandMatchResultTy tryParseGPRSeqPair(OperandVector &Operands); template OperandMatchResultTy tryParseSVEDataVector(OperandVector &Operands); OperandMatchResultTy tryParseSVEPredicateVector(OperandVector &Operands); + bool tryParseVectorList(OperandVector &Operands); OperandMatchResultTy tryParseSVEPattern(OperandVector &Operands); public: @@ -2676,28 +2678,33 @@ bool AArch64AsmParser::tryParseNeonVectorRegister(OperandVector &Operands) { Operands.push_back( AArch64Operand::CreateToken(Kind, false, S, getContext())); - // If there is an index specifier following the register, parse that too. + return tryParseVectorIndex(Operands) == MatchOperand_ParseFail; +} + +OperandMatchResultTy +AArch64AsmParser::tryParseVectorIndex(OperandVector &Operands) { SMLoc SIdx = getLoc(); if (parseOptionalToken(AsmToken::LBrac)) { const MCExpr *ImmVal; if (getParser().parseExpression(ImmVal)) - return false; + return MatchOperand_NoMatch; const MCConstantExpr *MCE = dyn_cast(ImmVal); if (!MCE) { TokError("immediate value expected for vector index"); - return false; + return MatchOperand_ParseFail;; } SMLoc E = getLoc(); if (parseToken(AsmToken::RBrac, "']' expected")) - return false; + return MatchOperand_ParseFail;; Operands.push_back(AArch64Operand::CreateVectorIndex(MCE->getValue(), SIdx, E, getContext())); + return MatchOperand_Success; } - return false; + return MatchOperand_NoMatch; } // tryParseVectorRegister - Try to parse a vector register name with @@ -2876,8 +2883,8 @@ bool AArch64AsmParser::parseSymbolicImmVal(const MCExpr *&ImmVal) { return false; } -/// parseVectorList - Parse a vector list operand for AdvSIMD instructions. -bool AArch64AsmParser::parseVectorList(OperandVector &Operands) { +/// parseVectorList - Parse a vector list operand for vector instructions. +bool AArch64AsmParser::tryParseVectorList(OperandVector &Operands) { MCAsmParser &Parser = getParser(); assert(Parser.getTok().is(AsmToken::LCurly) && "Token is not a Left Bracket"); @@ -2961,26 +2968,15 @@ bool AArch64AsmParser::parseVectorList(OperandVector &Operands) { Operands.push_back(AArch64Operand::CreateVectorList( FirstReg, Count, NumElements, ElementWidth, S, getLoc(), getContext())); - // If there is an index specifier following the list, parse that too. - SMLoc SIdx = getLoc(); - if (parseOptionalToken(AsmToken::LBrac)) { // Eat left bracket token. - const MCExpr *ImmVal; - if (getParser().parseExpression(ImmVal)) - return false; - const MCConstantExpr *MCE = dyn_cast(ImmVal); - if (!MCE) { - TokError("immediate value expected for vector index"); - return false; - } + return false; +} - SMLoc E = getLoc(); - if (parseToken(AsmToken::RBrac, "']' expected")) - return false; +/// parseNeonVectorList - Parse a vector list operand for AdvSIMD instructions. +bool AArch64AsmParser::parseNeonVectorList(OperandVector &Operands) { + if (tryParseVectorList(Operands)) + return true; - Operands.push_back(AArch64Operand::CreateVectorIndex(MCE->getValue(), SIdx, - E, getContext())); - } - return false; + return tryParseVectorIndex(Operands) == MatchOperand_ParseFail; } OperandMatchResultTy @@ -3068,7 +3064,7 @@ bool AArch64AsmParser::parseOperand(OperandVector &Operands, bool isCondCode, return parseOperand(Operands, false, false); } case AsmToken::LCurly: - return parseVectorList(Operands); + return parseNeonVectorList(Operands); case AsmToken::Identifier: { // If we're expecting a Condition Code operand, then just parse that. if (isCondCode) -- 2.7.4