[llvm] [MIR] Support parsing bfloat immediates in MIR parser. (PR #96010)

Stephen Chou via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 18 18:02:24 PDT 2024


https://github.com/stephenchouca created https://github.com/llvm/llvm-project/pull/96010

Adds support in MIR parser for parsing bfloat immediates, and adds a test for this.

>From ee7d4d3d6835c6d94fc467bddda073382d29319d Mon Sep 17 00:00:00 2001
From: Stephen Chou <stephenchou at google.com>
Date: Wed, 19 Jun 2024 00:59:50 +0000
Subject: [PATCH] [MIR] Support parsing bfloat immediates in MIR parser.

---
 llvm/lib/CodeGen/MIRParser/MILexer.cpp              |  1 +
 llvm/lib/CodeGen/MIRParser/MILexer.h                |  1 +
 llvm/lib/CodeGen/MIRParser/MIParser.cpp             |  1 +
 llvm/test/CodeGen/MIR/Generic/bfloat-immediates.mir | 12 ++++++++++++
 4 files changed, 15 insertions(+)
 create mode 100644 llvm/test/CodeGen/MIR/Generic/bfloat-immediates.mir

diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.cpp b/llvm/lib/CodeGen/MIRParser/MILexer.cpp
index 114f0e8a57108..0809f88fde56b 100644
--- a/llvm/lib/CodeGen/MIRParser/MILexer.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MILexer.cpp
@@ -242,6 +242,7 @@ static MIToken::TokenKind getIdentifierKind(StringRef Identifier) {
       .Case("intrinsic", MIToken::kw_intrinsic)
       .Case("target-index", MIToken::kw_target_index)
       .Case("half", MIToken::kw_half)
+      .Case("bfloat", MIToken::kw_bfloat)
       .Case("float", MIToken::kw_float)
       .Case("double", MIToken::kw_double)
       .Case("x86_fp80", MIToken::kw_x86_fp80)
diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.h b/llvm/lib/CodeGen/MIRParser/MILexer.h
index 49a19896804ee..22547483a8a86 100644
--- a/llvm/lib/CodeGen/MIRParser/MILexer.h
+++ b/llvm/lib/CodeGen/MIRParser/MILexer.h
@@ -100,6 +100,7 @@ struct MIToken {
     kw_intrinsic,
     kw_target_index,
     kw_half,
+    kw_bfloat,
     kw_float,
     kw_double,
     kw_x86_fp80,
diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp
index 95924f0566283..1a12eefc8675b 100644
--- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp
@@ -2916,6 +2916,7 @@ bool MIParser::parseMachineOperand(const unsigned OpCode, const unsigned OpIdx,
   case MIToken::IntegerLiteral:
     return parseImmediateOperand(Dest);
   case MIToken::kw_half:
+  case MIToken::kw_bfloat:
   case MIToken::kw_float:
   case MIToken::kw_double:
   case MIToken::kw_x86_fp80:
diff --git a/llvm/test/CodeGen/MIR/Generic/bfloat-immediates.mir b/llvm/test/CodeGen/MIR/Generic/bfloat-immediates.mir
new file mode 100644
index 0000000000000..c4e035a4f095c
--- /dev/null
+++ b/llvm/test/CodeGen/MIR/Generic/bfloat-immediates.mir
@@ -0,0 +1,12 @@
+# RUN: llc -run-pass none -o - %s | FileCheck %s
+# This test ensures that the MIR parser parses bfloat immediates correctly.
+
+---
+name: bfloat_immediates
+body: |
+  bb.0:
+    ; CHECK: %0:_(s16) = G_FCONSTANT bfloat 0xR3E80
+    ; CHECK: %1:_(s16) = G_FCONSTANT bfloat 0xR3E80
+    %0:_(s16) = G_FCONSTANT bfloat 0xR3E80
+    %1:_(s16) = G_FCONSTANT bfloat 0.25
+...



More information about the llvm-commits mailing list