[PATCH] D45948: [MIRParser] Allow register class names in the form of integer/scalar

Heejin Ahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 23 06:26:42 PDT 2018


aheejin created this revision.
aheejin added a reviewer: MatzeB.
Herald added subscribers: llvm-commits, sunfish, jgravelle-google, sbc100, dschuff, jfb.

The current code cannot handle register class names like 'i32', which is
a valid register class name in WebAssembly.


Repository:
  rL LLVM

https://reviews.llvm.org/D45948

Files:
  lib/CodeGen/MIRParser/MIParser.cpp
  test/CodeGen/MIR/WebAssembly/int-type-register-class-name.mir
  test/CodeGen/MIR/WebAssembly/lit.local.cfg


Index: test/CodeGen/MIR/WebAssembly/lit.local.cfg
===================================================================
--- /dev/null
+++ test/CodeGen/MIR/WebAssembly/lit.local.cfg
@@ -0,0 +1,2 @@
+if not 'WebAssembly' in config.root.targets:
+    config.unsupported = True
Index: test/CodeGen/MIR/WebAssembly/int-type-register-class-name.mir
===================================================================
--- /dev/null
+++ test/CodeGen/MIR/WebAssembly/int-type-register-class-name.mir
@@ -0,0 +1,13 @@
+# RUN: llc -mtriple=wasm32-unknown-unknown-wasm -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
+...
Index: lib/CodeGen/MIRParser/MIParser.cpp
===================================================================
--- lib/CodeGen/MIRParser/MIParser.cpp
+++ lib/CodeGen/MIRParser/MIParser.cpp
@@ -1002,12 +1002,20 @@
 }
 
 bool MIParser::parseRegisterClassOrBank(VRegInfo &RegInfo) {
+  // It is possible a register class or register bank name can be in the form of
+  // integer of scalar type (e.g. i32). Fix token kind in that case.
+  auto Range = Token.range();
+  if (Token.isNot(MIToken::underscore) &&
+      (PFS.Names2RegClasses.find(Range) != PFS.Names2RegClasses.end() ||
+       PFS.Names2RegBanks.find(Range) != PFS.Names2RegBanks.end()))
+    Token.reset(MIToken::Identifier, Range).setStringValue(Range);
+
   if (Token.isNot(MIToken::Identifier) && Token.isNot(MIToken::underscore))
     return error("expected '_', register class, or register bank name");
   StringRef::iterator Loc = Token.location();
-  StringRef Name = Token.stringValue();
 
   // Was it a register class?
+  StringRef Name = Token.stringValue();
   auto RCNameI = PFS.Names2RegClasses.find(Name);
   if (RCNameI != PFS.Names2RegClasses.end()) {
     lex();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45948.143535.patch
Type: text/x-patch
Size: 2079 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180423/d68f7253/attachment.bin>


More information about the llvm-commits mailing list