[MIRParser][GlobalISel] Parsing vector pointer types (<M x pA>)
authorRoman Tereshin <rtereshin@apple.com>
Tue, 8 May 2018 02:02:50 +0000 (02:02 +0000)
committerRoman Tereshin <rtereshin@apple.com>
Tue, 8 May 2018 02:02:50 +0000 (02:02 +0000)
MIParser wasn't able to parse LLTs like `<4 x p0>`, fixing that.

Reviewers: qcolombet t.p.northover aditya_nandakumar

Reviewed By: qcolombet

Subscribers: rovka, kristof.beyls, llvm-commits

Differential Revision: https://reviews.llvm.org/D46490

llvm-svn: 331712

llvm/lib/CodeGen/MIRParser/MIParser.cpp
llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid0.mir [new file with mode: 0644]
llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid1.mir [new file with mode: 0644]
llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid2.mir [new file with mode: 0644]
llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid3.mir [new file with mode: 0644]
llvm/test/CodeGen/MIR/AArch64/print-parse-vector-of-pointers-llt.mir [new file with mode: 0644]
llvm/test/CodeGen/MIR/WebAssembly/typed-immediate-operand-invalid0.mir
llvm/test/CodeGen/MIR/WebAssembly/typed-immediate-operand-invalid1.mir

index acb4ab6ad1b289e448421c77119c117978d46371..c1c93575e3507a69189c9b1ec424a2467eec720a 100644 (file)
@@ -1306,7 +1306,7 @@ bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) {
   if (Token.range().front() == 's' || Token.range().front() == 'p') {
     StringRef SizeStr = Token.range().drop_front();
     if (SizeStr.size() == 0 || !llvm::all_of(SizeStr, isdigit))
-      return error("Expected integers after 's'/'p' type character");
+      return error("expected integers after 's'/'p' type character");
   }
 
   if (Token.range().front() == 's') {
@@ -1324,32 +1324,39 @@ bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) {
   // Now we're looking for a vector.
   if (Token.isNot(MIToken::less))
     return error(Loc,
-                 "expected unsized, pN, sN or <N x sM> for GlobalISel type");
-
+                 "expected sN, pA, <M x sN>, or <M x pA> for GlobalISel type");
   lex();
 
   if (Token.isNot(MIToken::IntegerLiteral))
-    return error(Loc, "expected <N x sM> for vctor type");
+    return error(Loc, "expected <M x sN> or <M x pA> for vector type");
   uint64_t NumElements = Token.integerValue().getZExtValue();
   lex();
 
   if (Token.isNot(MIToken::Identifier) || Token.stringValue() != "x")
-    return error(Loc, "expected '<N x sM>' for vector type");
+    return error(Loc, "expected <M x sN> or <M x pA> for vector type");
   lex();
 
-  if (Token.range().front() != 's')
-    return error(Loc, "expected '<N x sM>' for vector type");
+  if (Token.range().front() != 's' && Token.range().front() != 'p')
+    return error(Loc, "expected <M x sN> or <M x pA> for vector type");
   StringRef SizeStr = Token.range().drop_front();
   if (SizeStr.size() == 0 || !llvm::all_of(SizeStr, isdigit))
-    return error("Expected integers after 's' type character");
-  uint64_t ScalarSize = APSInt(Token.range().drop_front()).getZExtValue();
+    return error("expected integers after 's'/'p' type character");
+
+  if (Token.range().front() == 's')
+    Ty = LLT::scalar(APSInt(Token.range().drop_front()).getZExtValue());
+  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));
+  } else
+    return error(Loc, "expected <M x sN> or <M x pA> for vector type");
   lex();
 
   if (Token.isNot(MIToken::greater))
-    return error(Loc, "expected '<N x sM>' for vector type");
+    return error(Loc, "expected <M x sN> or <M x pA> for vector type");
   lex();
 
-  Ty = LLT::vector(NumElements, ScalarSize);
+  Ty = LLT::vector(NumElements, Ty);
   return false;
 }
 
@@ -1359,10 +1366,10 @@ bool MIParser::parseTypedImmediateOperand(MachineOperand &Dest) {
   if (TypeStr.front() != 'i' && TypeStr.front() != 's' &&
       TypeStr.front() != 'p')
     return error(
-        "A typed immediate operand should start with one of 'i', 's', or 'p'");
+        "a typed immediate operand should start with one of 'i', 's', or 'p'");
   StringRef SizeStr = Token.range().drop_front();
   if (SizeStr.size() == 0 || !llvm::all_of(SizeStr, isdigit))
-    return error("Expected integers after 'i'/'s'/'p' type character");
+    return error("expected integers after 'i'/'s'/'p' type character");
 
   auto Loc = Token.location();
   lex();
diff --git a/llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid0.mir b/llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid0.mir
new file mode 100644 (file)
index 0000000..cece360
--- /dev/null
@@ -0,0 +1,10 @@
+# RUN: not llc -mtriple=aarch64-- -run-pass none -o /dev/null %s 2>&1 | FileCheck %s
+# When a low-level type is only a single 's'/'p' character
+---
+name: test_low_level_type_is_single_s_p
+body: |
+  bb.0:
+    liveins: $x0
+    ; CHECK: [[@LINE+1]]:10: expected integers after 's'/'p' type character
+    %0:_(s) = COPY $x0
+...
diff --git a/llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid1.mir b/llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid1.mir
new file mode 100644 (file)
index 0000000..3545640
--- /dev/null
@@ -0,0 +1,10 @@
+# RUN: not llc -mtriple=aarch64-- -run-pass none -o /dev/null %s 2>&1 | FileCheck %s
+# When a low-level type does not start with 's', 'p', or '<'
+---
+name: test_low_level_type_does_not_start_with_s_p_lt
+body: |
+  bb.0:
+    liveins: $x0
+    ; CHECK: [[@LINE+1]]:10: expected sN, pA, <M x sN>, or <M x pA> for GlobalISel type
+    %0:_(i64) = COPY $x0
+...
diff --git a/llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid2.mir b/llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid2.mir
new file mode 100644 (file)
index 0000000..1bff7a5
--- /dev/null
@@ -0,0 +1,10 @@
+# RUN: not llc -mtriple=aarch64-- -run-pass none -o /dev/null %s 2>&1 | FileCheck %s
+# When a low-level type is a vector with only a single 's'/'p' character for element type
+---
+name: test_low_level_type_is_single_s_p
+body: |
+  bb.0:
+    liveins: $q0
+    ; CHECK: [[@LINE+1]]:15: expected integers after 's'/'p' type character
+    %0:_(<2 x p>) = COPY $q0
+...
diff --git a/llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid3.mir b/llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid3.mir
new file mode 100644 (file)
index 0000000..ebb3d37
--- /dev/null
@@ -0,0 +1,10 @@
+# RUN: not llc -mtriple=aarch64-- -run-pass none -o /dev/null %s 2>&1 | FileCheck %s
+# When a low-level type is a vector which element type does not start with 's' or 'p'
+---
+name: test_low_level_type_does_not_start_with_s_p
+body: |
+  bb.0:
+    liveins: $q0
+    ; CHECK: [[@LINE+1]]:10: expected <M x sN> or <M x pA> for vector type
+    %0:_(<2 x i64>) = COPY $q0
+...
diff --git a/llvm/test/CodeGen/MIR/AArch64/print-parse-vector-of-pointers-llt.mir b/llvm/test/CodeGen/MIR/AArch64/print-parse-vector-of-pointers-llt.mir
new file mode 100644 (file)
index 0000000..a91b974
--- /dev/null
@@ -0,0 +1,11 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+# RUN: llc -mtriple=aarch64-- -run-pass none -o - %s 2>&1 | FileCheck %s
+---
+name: test_vector_of_pointers_llt
+body: |
+  bb.0:
+    liveins: $q0
+    ; CHECK-LABEL: name: test_vector_of_pointers_llt
+    ; CHECK: [[COPY:%[0-9]+]]:_(<2 x p0>) = COPY $q0
+    %0:_(<2 x p0>) = COPY $q0
+...
index dcb940cc6ac290ef72f5e7d65c1d3caa96b549c8..b9f138c14b00356c472dda305ba73bd29701d894 100644 (file)
@@ -7,7 +7,7 @@ liveins:
 body: |
   bb.0:
     liveins: $arguments
-    ; CHECK: [[@LINE+1]]:24: Expected integers after 'i'/'s'/'p' type character
+    ; CHECK: [[@LINE+1]]:24: expected integers after 'i'/'s'/'p' type character
     %0:i32 = CONST_I32 i 0, implicit-def dead $arguments
     RETURN_VOID implicit-def dead $arguments
 ...
index 032bdf3d8faa2ebbb65e415af38637df258e185a..03e722f6c3c29d5cd0fbf46b2ce73f012e899e61 100644 (file)
@@ -7,7 +7,7 @@ liveins:
 body: |
   bb.0:
     liveins: $arguments
-    ; CHECK: [[@LINE+1]]:24: A typed immediate operand should start with one of 'i', 's', or 'p'
+    ; CHECK: [[@LINE+1]]:24: a typed immediate operand should start with one of 'i', 's', or 'p'
     %0:i32 = CONST_I32 abc 0, implicit-def dead $arguments
     RETURN_VOID implicit-def dead $arguments
 ...