From c2ad0968450085bb39b1750d3c43960610e15816 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Sat, 5 May 2018 07:05:51 +0000 Subject: [PATCH] [MIRParser] Allow register class names in the form of integer/scalar Summary: The current code cannot handle register class names like 'i32', which is a valid register class name in WebAssembly. This patch removes special handling for integer/scalar/pointer type parsing and treats them as normal identifiers. Reviewers: thegameg Subscribers: jfb, dschuff, sbc100, jgravelle-google, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D45948 llvm-svn: 331586 --- llvm/lib/CodeGen/MIRParser/MILexer.cpp | 19 -------------- llvm/lib/CodeGen/MIRParser/MILexer.h | 3 --- llvm/lib/CodeGen/MIRParser/MIParser.cpp | 25 +++++++++++++------ .../int-type-register-class-name.mir | 13 ++++++++++ .../CodeGen/MIR/WebAssembly/lit.local.cfg | 2 ++ 5 files changed, 33 insertions(+), 29 deletions(-) create mode 100644 llvm/test/CodeGen/MIR/WebAssembly/int-type-register-class-name.mir create mode 100644 llvm/test/CodeGen/MIR/WebAssembly/lit.local.cfg diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.cpp b/llvm/lib/CodeGen/MIRParser/MILexer.cpp index 64531b281deb..da05c9a22785 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.cpp +++ b/llvm/lib/CodeGen/MIRParser/MILexer.cpp @@ -179,23 +179,6 @@ static Cursor lexName(Cursor C, MIToken &Token, MIToken::TokenKind Type, return C; } -static Cursor maybeLexIntegerOrScalarType(Cursor C, MIToken &Token) { - if ((C.peek() != 'i' && C.peek() != 's' && C.peek() != 'p') || - !isdigit(C.peek(1))) - return None; - char Kind = C.peek(); - auto Range = C; - C.advance(); // Skip 'i', 's', or 'p' - while (isdigit(C.peek())) - C.advance(); - - Token.reset(Kind == 'i' - ? MIToken::IntegerType - : (Kind == 's' ? MIToken::ScalarType : MIToken::PointerType), - Range.upto(C)); - return C; -} - static MIToken::TokenKind getIdentifierKind(StringRef Identifier) { return StringSwitch(Identifier) .Case("_", MIToken::underscore) @@ -650,8 +633,6 @@ StringRef llvm::lexMIToken(StringRef Source, MIToken &Token, return C.remaining(); } - if (Cursor R = maybeLexIntegerOrScalarType(C, Token)) - return R.remaining(); if (Cursor R = maybeLexMachineBasicBlock(C, Token, ErrorCallback)) return R.remaining(); if (Cursor R = maybeLexIdentifier(C, Token)) diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.h b/llvm/lib/CodeGen/MIRParser/MILexer.h index 0f89adcf70b4..e21c71532f79 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.h +++ b/llvm/lib/CodeGen/MIRParser/MILexer.h @@ -123,13 +123,10 @@ struct MIToken { // Identifier tokens Identifier, - IntegerType, NamedRegister, NamedVirtualRegister, MachineBasicBlockLabel, MachineBasicBlock, - PointerType, - ScalarType, StackObject, FixedStackObject, NamedGlobalValue, diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index 59cd623d556c..3cc42582e4dd 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -1303,11 +1303,17 @@ bool MIParser::parseIRConstant(StringRef::iterator Loc, const Constant *&C) { } bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) { - if (Token.is(MIToken::ScalarType)) { + if (Token.range().front() == 's' || Token.range().front() == 'p') + if (!llvm::all_of(Token.range().drop_front(), isdigit)) + return error("Expected integers after 's'/'p' type character"); + if (!llvm::all_of(Token.range().drop_front(), isdigit)) + return error("Expected integers after 's'/'p' type character"); + + if (Token.range().front() == 's') { Ty = LLT::scalar(APSInt(Token.range().drop_front()).getZExtValue()); lex(); return false; - } else if (Token.is(MIToken::PointerType)) { + } else if (Token.range().front() == 'p') { const DataLayout &DL = MF.getDataLayout(); unsigned AS = APSInt(Token.range().drop_front()).getZExtValue(); Ty = LLT::pointer(AS, DL.getPointerSizeInBits(AS)); @@ -1331,8 +1337,10 @@ bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) { return error(Loc, "expected '' for vector type"); lex(); - if (Token.isNot(MIToken::ScalarType)) + if (Token.range().front() != 's') return error(Loc, "expected '' for vector type"); + if (!llvm::all_of(Token.range().drop_front(), isdigit)) + return error("Expected integers after 's' type character"); uint64_t ScalarSize = APSInt(Token.range().drop_front()).getZExtValue(); lex(); @@ -1345,7 +1353,10 @@ bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) { } bool MIParser::parseTypedImmediateOperand(MachineOperand &Dest) { - assert(Token.is(MIToken::IntegerType)); + assert(Token.is(MIToken::Identifier)); + if (!llvm::all_of(Token.range().drop_front(), isdigit)) + return error("Expected integers after 'i'/'s'/'p' type character"); + auto Loc = Token.location(); lex(); if (Token.isNot(MIToken::IntegerLiteral)) @@ -2004,8 +2015,6 @@ bool MIParser::parseMachineOperand(MachineOperand &Dest, return parseRegisterOperand(Dest, TiedDefIdx); case MIToken::IntegerLiteral: return parseImmediateOperand(Dest); - case MIToken::IntegerType: - return parseTypedImmediateOperand(Dest); case MIToken::kw_half: case MIToken::kw_float: case MIToken::kw_double: @@ -2066,8 +2075,10 @@ bool MIParser::parseMachineOperand(MachineOperand &Dest, Dest = MachineOperand::CreateRegMask(RegMask); lex(); break; - } else + } else if (Token.stringValue() == "CustomRegMask") { return parseCustomRegisterMaskOperand(Dest); + } else + return parseTypedImmediateOperand(Dest); default: // FIXME: Parse the MCSymbol machine operand. return error("expected a machine operand"); diff --git a/llvm/test/CodeGen/MIR/WebAssembly/int-type-register-class-name.mir b/llvm/test/CodeGen/MIR/WebAssembly/int-type-register-class-name.mir new file mode 100644 index 000000000000..e5d7076eedef --- /dev/null +++ b/llvm/test/CodeGen/MIR/WebAssembly/int-type-register-class-name.mir @@ -0,0 +1,13 @@ +# RUN: llc -mtriple=wasm32-unknown-unknown -run-pass none -o - %s | FileCheck %s +# When a register class has a name of an integer type (i32) +--- +name: regclass_name_test +liveins: + - { reg: '$arguments' } +body: | + bb.0: + liveins: $arguments + %0:i32 = CONST_I32 0, implicit-def dead $arguments + ; CHECK: %0:i32 = CONST_I32 0, implicit-def dead $arguments + RETURN_VOID implicit-def dead $arguments +... diff --git a/llvm/test/CodeGen/MIR/WebAssembly/lit.local.cfg b/llvm/test/CodeGen/MIR/WebAssembly/lit.local.cfg new file mode 100644 index 000000000000..743473517cd0 --- /dev/null +++ b/llvm/test/CodeGen/MIR/WebAssembly/lit.local.cfg @@ -0,0 +1,2 @@ +if not 'WebAssembly' in config.root.targets: + config.unsupported = True