[llvm] r264608 - MIRParser: Add %subreg.xxx syntax for subregister index operands
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 28 11:18:47 PDT 2016
Author: matze
Date: Mon Mar 28 13:18:46 2016
New Revision: 264608
URL: http://llvm.org/viewvc/llvm-project?rev=264608&view=rev
Log:
MIRParser: Add %subreg.xxx syntax for subregister index operands
Differential Revision: http://reviews.llvm.org/D18279
Added:
llvm/trunk/test/CodeGen/MIR/X86/subregister-index-operands.mir
llvm/trunk/test/CodeGen/MIR/X86/unknown-subregister-index-op.mir
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=264608&r1=264607&r2=264608&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp Mon Mar 28 13:18:46 2016
@@ -325,6 +325,15 @@ static Cursor maybeLexConstantPoolItem(C
return maybeLexIndex(C, Token, "%const.", MIToken::ConstantPoolItem);
}
+static Cursor maybeLexSubRegisterIndex(Cursor C, MIToken &Token,
+ ErrorCallbackType ErrorCallback) {
+ const StringRef Rule = "%subreg.";
+ if (!C.remaining().startswith(Rule))
+ return None;
+ return lexName(C, Token, MIToken::SubRegisterIndex, Rule.size(),
+ ErrorCallback);
+}
+
static Cursor maybeLexIRBlock(Cursor C, MIToken &Token,
ErrorCallbackType ErrorCallback) {
const StringRef Rule = "%ir-block.";
@@ -570,6 +579,8 @@ StringRef llvm::lexMIToken(StringRef Sou
return R.remaining();
if (Cursor R = maybeLexConstantPoolItem(C, Token))
return R.remaining();
+ if (Cursor R = maybeLexSubRegisterIndex(C, Token, ErrorCallback))
+ return R.remaining();
if (Cursor R = maybeLexIRBlock(C, Token, ErrorCallback))
return R.remaining();
if (Cursor R = maybeLexIRValue(C, Token, ErrorCallback))
Modified: llvm/trunk/lib/CodeGen/MIRParser/MILexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MILexer.h?rev=264608&r1=264607&r2=264608&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MILexer.h (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MILexer.h Mon Mar 28 13:18:46 2016
@@ -118,7 +118,8 @@ struct MIToken {
IRBlock,
NamedIRValue,
IRValue,
- QuotedIRValue // `<constant value>`
+ QuotedIRValue, // `<constant value>`
+ SubRegisterIndex
};
private:
Modified: llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp?rev=264608&r1=264607&r2=264608&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp Mon Mar 28 13:18:46 2016
@@ -144,6 +144,7 @@ public:
bool parseGlobalValue(GlobalValue *&GV);
bool parseGlobalAddressOperand(MachineOperand &Dest);
bool parseConstantPoolIndexOperand(MachineOperand &Dest);
+ bool parseSubRegisterIndexOperand(MachineOperand &Dest);
bool parseJumpTableIndexOperand(MachineOperand &Dest);
bool parseExternalSymbolOperand(MachineOperand &Dest);
bool parseMDNode(MDNode *&Node);
@@ -1237,6 +1238,17 @@ bool MIParser::parseExternalSymbolOperan
return false;
}
+bool MIParser::parseSubRegisterIndexOperand(MachineOperand &Dest) {
+ assert(Token.is(MIToken::SubRegisterIndex));
+ StringRef Name = Token.stringValue();
+ unsigned SubRegIndex = getSubRegIndex(Token.stringValue());
+ if (SubRegIndex == 0)
+ return error(Twine("unknown subregister index '") + Name + "'");
+ lex();
+ Dest = MachineOperand::CreateImm(SubRegIndex);
+ return false;
+}
+
bool MIParser::parseMDNode(MDNode *&Node) {
assert(Token.is(MIToken::exclaim));
auto Loc = Token.location();
@@ -1482,6 +1494,8 @@ bool MIParser::parseMachineOperand(Machi
return parseJumpTableIndexOperand(Dest);
case MIToken::ExternalSymbol:
return parseExternalSymbolOperand(Dest);
+ case MIToken::SubRegisterIndex:
+ return parseSubRegisterIndexOperand(Dest);
case MIToken::exclaim:
return parseMetadataOperand(Dest);
case MIToken::kw_cfi_same_value:
Added: llvm/trunk/test/CodeGen/MIR/X86/subregister-index-operands.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/X86/subregister-index-operands.mir?rev=264608&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/X86/subregister-index-operands.mir (added)
+++ llvm/trunk/test/CodeGen/MIR/X86/subregister-index-operands.mir Mon Mar 28 13:18:46 2016
@@ -0,0 +1,32 @@
+# RUN: llc -march=x86-64 -start-after machine-sink -stop-after machine-sink -o /dev/null %s 2>&1 | FileCheck %s
+# This test ensures that the MIR parser parses and prints subregisters index
+# operands correctly.
+
+--- |
+
+ define zeroext i1 @t(i1 %c) {
+ entry:
+ ret i1 %c
+ }
+
+...
+---
+# CHECK-LABEL: name: t
+# CHECK: %0 = INSERT_SUBREG %edi, %al, {{[0-9]+}}
+# CHECK: %1 = EXTRACT_SUBREG %eax, {{[0-9]+}}
+# CHECK: %ax = REG_SEQUENCE %1, {{[0-9]+}}, %1, {{[0-9]+}}
+name: t
+isSSA: true
+tracksRegLiveness: true
+registers:
+ - { id: 0, class: gr32 }
+ - { id: 1, class: gr8 }
+body: |
+ bb.0.entry:
+ liveins: %edi, %eax
+ %0 = INSERT_SUBREG %edi, %al, %subreg.sub_8bit
+ %1 = EXTRACT_SUBREG %eax, %subreg.sub_8bit_hi
+ %ax = REG_SEQUENCE %1, %subreg.sub_8bit, %1, %subreg.sub_8bit_hi
+ RETQ %ax
+...
+
Added: llvm/trunk/test/CodeGen/MIR/X86/unknown-subregister-index-op.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/X86/unknown-subregister-index-op.mir?rev=264608&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/X86/unknown-subregister-index-op.mir (added)
+++ llvm/trunk/test/CodeGen/MIR/X86/unknown-subregister-index-op.mir Mon Mar 28 13:18:46 2016
@@ -0,0 +1,26 @@
+# RUN: not llc -march=x86-64 -start-after machine-sink -stop-after machine-sink -o /dev/null %s 2>&1 | FileCheck %s
+# This test ensures that an error is reported when an unknown subregister index
+# is encountered.
+
+--- |
+
+ define zeroext i1 @t(i1 %c) {
+ entry:
+ ret i1 %c
+ }
+
+...
+---
+name: t
+isSSA: true
+tracksRegLiveness: true
+registers:
+ - { id: 0, class: gr32 }
+ - { id: 1, class: gr8 }
+ - { id: 2, class: gr8 }
+body: |
+ bb.0.entry:
+ ; CHECK: [[@LINE+1]]:35: unknown subregister index 'bit8'
+ %0 = INSERT_SUBREG %edi, %al, %subreg.bit8
+ RETQ %0
+...
More information about the llvm-commits
mailing list