forked from OSchip/llvm-project
[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
This commit is contained in:
parent
2569f3eb80
commit
c2ad096845
|
@ -179,23 +179,6 @@ static Cursor lexName(Cursor C, MIToken &Token, MIToken::TokenKind Type,
|
||||||
return C;
|
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) {
|
static MIToken::TokenKind getIdentifierKind(StringRef Identifier) {
|
||||||
return StringSwitch<MIToken::TokenKind>(Identifier)
|
return StringSwitch<MIToken::TokenKind>(Identifier)
|
||||||
.Case("_", MIToken::underscore)
|
.Case("_", MIToken::underscore)
|
||||||
|
@ -650,8 +633,6 @@ StringRef llvm::lexMIToken(StringRef Source, MIToken &Token,
|
||||||
return C.remaining();
|
return C.remaining();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Cursor R = maybeLexIntegerOrScalarType(C, Token))
|
|
||||||
return R.remaining();
|
|
||||||
if (Cursor R = maybeLexMachineBasicBlock(C, Token, ErrorCallback))
|
if (Cursor R = maybeLexMachineBasicBlock(C, Token, ErrorCallback))
|
||||||
return R.remaining();
|
return R.remaining();
|
||||||
if (Cursor R = maybeLexIdentifier(C, Token))
|
if (Cursor R = maybeLexIdentifier(C, Token))
|
||||||
|
|
|
@ -123,13 +123,10 @@ struct MIToken {
|
||||||
|
|
||||||
// Identifier tokens
|
// Identifier tokens
|
||||||
Identifier,
|
Identifier,
|
||||||
IntegerType,
|
|
||||||
NamedRegister,
|
NamedRegister,
|
||||||
NamedVirtualRegister,
|
NamedVirtualRegister,
|
||||||
MachineBasicBlockLabel,
|
MachineBasicBlockLabel,
|
||||||
MachineBasicBlock,
|
MachineBasicBlock,
|
||||||
PointerType,
|
|
||||||
ScalarType,
|
|
||||||
StackObject,
|
StackObject,
|
||||||
FixedStackObject,
|
FixedStackObject,
|
||||||
NamedGlobalValue,
|
NamedGlobalValue,
|
||||||
|
|
|
@ -1303,11 +1303,17 @@ bool MIParser::parseIRConstant(StringRef::iterator Loc, const Constant *&C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) {
|
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());
|
Ty = LLT::scalar(APSInt(Token.range().drop_front()).getZExtValue());
|
||||||
lex();
|
lex();
|
||||||
return false;
|
return false;
|
||||||
} else if (Token.is(MIToken::PointerType)) {
|
} else if (Token.range().front() == 'p') {
|
||||||
const DataLayout &DL = MF.getDataLayout();
|
const DataLayout &DL = MF.getDataLayout();
|
||||||
unsigned AS = APSInt(Token.range().drop_front()).getZExtValue();
|
unsigned AS = APSInt(Token.range().drop_front()).getZExtValue();
|
||||||
Ty = LLT::pointer(AS, DL.getPointerSizeInBits(AS));
|
Ty = LLT::pointer(AS, DL.getPointerSizeInBits(AS));
|
||||||
|
@ -1331,8 +1337,10 @@ bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) {
|
||||||
return error(Loc, "expected '<N x sM>' for vector type");
|
return error(Loc, "expected '<N x sM>' for vector type");
|
||||||
lex();
|
lex();
|
||||||
|
|
||||||
if (Token.isNot(MIToken::ScalarType))
|
if (Token.range().front() != 's')
|
||||||
return error(Loc, "expected '<N x sM>' for vector type");
|
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();
|
uint64_t ScalarSize = APSInt(Token.range().drop_front()).getZExtValue();
|
||||||
lex();
|
lex();
|
||||||
|
|
||||||
|
@ -1345,7 +1353,10 @@ bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MIParser::parseTypedImmediateOperand(MachineOperand &Dest) {
|
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();
|
auto Loc = Token.location();
|
||||||
lex();
|
lex();
|
||||||
if (Token.isNot(MIToken::IntegerLiteral))
|
if (Token.isNot(MIToken::IntegerLiteral))
|
||||||
|
@ -2004,8 +2015,6 @@ bool MIParser::parseMachineOperand(MachineOperand &Dest,
|
||||||
return parseRegisterOperand(Dest, TiedDefIdx);
|
return parseRegisterOperand(Dest, TiedDefIdx);
|
||||||
case MIToken::IntegerLiteral:
|
case MIToken::IntegerLiteral:
|
||||||
return parseImmediateOperand(Dest);
|
return parseImmediateOperand(Dest);
|
||||||
case MIToken::IntegerType:
|
|
||||||
return parseTypedImmediateOperand(Dest);
|
|
||||||
case MIToken::kw_half:
|
case MIToken::kw_half:
|
||||||
case MIToken::kw_float:
|
case MIToken::kw_float:
|
||||||
case MIToken::kw_double:
|
case MIToken::kw_double:
|
||||||
|
@ -2066,8 +2075,10 @@ bool MIParser::parseMachineOperand(MachineOperand &Dest,
|
||||||
Dest = MachineOperand::CreateRegMask(RegMask);
|
Dest = MachineOperand::CreateRegMask(RegMask);
|
||||||
lex();
|
lex();
|
||||||
break;
|
break;
|
||||||
} else
|
} else if (Token.stringValue() == "CustomRegMask") {
|
||||||
return parseCustomRegisterMaskOperand(Dest);
|
return parseCustomRegisterMaskOperand(Dest);
|
||||||
|
} else
|
||||||
|
return parseTypedImmediateOperand(Dest);
|
||||||
default:
|
default:
|
||||||
// FIXME: Parse the MCSymbol machine operand.
|
// FIXME: Parse the MCSymbol machine operand.
|
||||||
return error("expected a machine operand");
|
return error("expected a machine operand");
|
||||||
|
|
|
@ -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
|
||||||
|
...
|
|
@ -0,0 +1,2 @@
|
||||||
|
if not 'WebAssembly' in config.root.targets:
|
||||||
|
config.unsupported = True
|
Loading…
Reference in New Issue