[llvm] r331586 - [MIRParser] Allow register class names in the form of integer/scalar
Heejin Ahn via llvm-commits
llvm-commits at lists.llvm.org
Sat May 5 00:05:51 PDT 2018
Author: aheejin
Date: Sat May 5 00:05:51 2018
New Revision: 331586
URL: http://llvm.org/viewvc/llvm-project?rev=331586&view=rev
Log:
[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
Added:
llvm/trunk/test/CodeGen/MIR/WebAssembly/
llvm/trunk/test/CodeGen/MIR/WebAssembly/int-type-register-class-name.mir
llvm/trunk/test/CodeGen/MIR/WebAssembly/lit.local.cfg
Modified:
llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp
llvm/trunk/lib/CodeGen/MIRParser/MILexer.h
llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp
Modified: llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp?rev=331586&r1=331585&r2=331586&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp Sat May 5 00:05:51 2018
@@ -179,23 +179,6 @@ static Cursor lexName(Cursor C, MIToken
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<MIToken::TokenKind>(Identifier)
.Case("_", MIToken::underscore)
@@ -650,8 +633,6 @@ StringRef llvm::lexMIToken(StringRef Sou
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))
Modified: llvm/trunk/lib/CodeGen/MIRParser/MILexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MILexer.h?rev=331586&r1=331585&r2=331586&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MILexer.h (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MILexer.h Sat May 5 00:05:51 2018
@@ -123,13 +123,10 @@ struct MIToken {
// Identifier tokens
Identifier,
- IntegerType,
NamedRegister,
NamedVirtualRegister,
MachineBasicBlockLabel,
MachineBasicBlock,
- PointerType,
- ScalarType,
StackObject,
FixedStackObject,
NamedGlobalValue,
Modified: llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp?rev=331586&r1=331585&r2=331586&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp Sat May 5 00:05:51 2018
@@ -1303,11 +1303,17 @@ bool MIParser::parseIRConstant(StringRef
}
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(StringR
return error(Loc, "expected '<N x sM>' for vector type");
lex();
- if (Token.isNot(MIToken::ScalarType))
+ if (Token.range().front() != 's')
return error(Loc, "expected '<N x sM>' 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(StringR
}
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(Machi
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(Machi
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");
Added: llvm/trunk/test/CodeGen/MIR/WebAssembly/int-type-register-class-name.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/WebAssembly/int-type-register-class-name.mir?rev=331586&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/WebAssembly/int-type-register-class-name.mir (added)
+++ llvm/trunk/test/CodeGen/MIR/WebAssembly/int-type-register-class-name.mir Sat May 5 00:05:51 2018
@@ -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
+...
Added: llvm/trunk/test/CodeGen/MIR/WebAssembly/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/WebAssembly/lit.local.cfg?rev=331586&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/WebAssembly/lit.local.cfg (added)
+++ llvm/trunk/test/CodeGen/MIR/WebAssembly/lit.local.cfg Sat May 5 00:05:51 2018
@@ -0,0 +1,2 @@
+if not 'WebAssembly' in config.root.targets:
+ config.unsupported = True
More information about the llvm-commits
mailing list