[llvm] 3c24eb3 - [LLVM][MIR] Support parsing bfloat immediates in MIR parser (#96010)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 25 13:44:17 PDT 2024


Author: Stephen Chou
Date: 2024-06-25T16:44:14-04:00
New Revision: 3c24eb39fb7e9c8b61992c86cb44d8cacc5853d2

URL: https://github.com/llvm/llvm-project/commit/3c24eb39fb7e9c8b61992c86cb44d8cacc5853d2
DIFF: https://github.com/llvm/llvm-project/commit/3c24eb39fb7e9c8b61992c86cb44d8cacc5853d2.diff

LOG: [LLVM][MIR] Support parsing bfloat immediates in MIR parser (#96010)

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

Added: 
    llvm/test/CodeGen/MIR/Generic/bfloat-immediates.mir

Modified: 
    llvm/lib/CodeGen/MIRParser/MILexer.cpp
    llvm/lib/CodeGen/MIRParser/MILexer.h
    llvm/lib/CodeGen/MIRParser/MIParser.cpp

Removed: 
    


################################################################################
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