[flang-commits] [PATCH] D114081: [flang] Fix printing of constc and parsing of #fir.real

Diana Picus via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Nov 19 01:30:23 PST 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rGca3795541f49: [flang] Fix printing of constc and parsing of  #fir.real (authored by rovka).

Changed prior to commit:
  https://reviews.llvm.org/D114081?vs=387905&id=388414#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114081/new/

https://reviews.llvm.org/D114081

Files:
  flang/lib/Optimizer/Dialect/FIRAttr.cpp
  flang/lib/Optimizer/Dialect/FIROps.cpp
  flang/test/Fir/fir-ops.fir


Index: flang/test/Fir/fir-ops.fir
===================================================================
--- flang/test/Fir/fir-ops.fir
+++ flang/test/Fir/fir-ops.fir
@@ -647,6 +647,23 @@
   return
 }
 
+// CHECK-LABEL: @test_const_complex
+func @test_const_complex() {
+ // CHECK-DAG: {{%.*}} = fir.constc(#fir.real<2, i x3000>, #fir.real<2, i x4C40>) : !fir.complex<2>
+ // CHECK-DAG: {{%.*}} = fir.constc(#fir.real<3, i x3E80>, #fir.real<3, i x4202>) : !fir.complex<3>
+ // CHECK-DAG: {{%.*}} = fir.constc(#fir.real<4, i x3E800000>, #fir.real<4, i x42028000>) : !fir.complex<4>
+ // CHECK-DAG: {{%.*}} = fir.constc(#fir.real<8, i x3FD0000000000000>, #fir.real<8, i x4040500000000000>) : !fir.complex<8>
+ // CHECK-DAG: {{%.*}} = fir.constc(#fir.real<10, i x3FFD8000000000000000>, #fir.real<10, i x40048280000000000000>) : !fir.complex<10>
+ // CHECK-DAG: {{%.*}} = fir.constc(#fir.real<16, i x3FFD0000000000000000000000000000>, #fir.real<16, i x40040500000000000000000000000000>) : !fir.complex<16>
+  %c2 = fir.constc (#fir.real<2, 0.125>, #fir.real<2, 17.0>) : !fir.complex<2>
+  %c3 = fir.constc (#fir.real<3, 0.25>, #fir.real<3, 32.625>) : !fir.complex<3>
+  %c4 = fir.constc (#fir.real<4, 0.25>, #fir.real<4, 32.625>) : !fir.complex<4>
+  %c8 = fir.constc (#fir.real<8, 0.25>, #fir.real<8, 32.625>) : !fir.complex<8>
+  %c10 = fir.constc (#fir.real<10, 0.25>, #fir.real<10, 32.625>) : !fir.complex<10>
+  %c16 = fir.constc (#fir.real<16, 0.25>, #fir.real<16, 32.625>) : !fir.complex<16>
+  return
+}
+
 // CHECK-LABEL: @test_shift
 func @test_shift(%arg0: !fir.box<!fir.array<?xf32>>) -> !fir.ref<f32> {
   %c4 = arith.constant 4 : index
Index: flang/lib/Optimizer/Dialect/FIROps.cpp
===================================================================
--- flang/lib/Optimizer/Dialect/FIROps.cpp
+++ flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -760,19 +760,9 @@
 }
 
 static void print(mlir::OpAsmPrinter &p, fir::ConstcOp &op) {
-  p << " (0x";
-  auto f1 = op.getOperation()
-                ->getAttr(fir::ConstcOp::realAttrName())
-                .cast<mlir::FloatAttr>();
-  auto i1 = f1.getValue().bitcastToAPInt();
-  p.getStream().write_hex(i1.getZExtValue());
-  p << ", 0x";
-  auto f2 = op.getOperation()
-                ->getAttr(fir::ConstcOp::imagAttrName())
-                .cast<mlir::FloatAttr>();
-  auto i2 = f2.getValue().bitcastToAPInt();
-  p.getStream().write_hex(i2.getZExtValue());
-  p << ") : ";
+  p << '(';
+  p << op.getOperation()->getAttr(fir::ConstcOp::realAttrName()) << ", ";
+  p << op.getOperation()->getAttr(fir::ConstcOp::imagAttrName()) << ") : ";
   p.printType(op.getType());
 }
 
Index: flang/lib/Optimizer/Dialect/FIRAttr.cpp
===================================================================
--- flang/lib/Optimizer/Dialect/FIRAttr.cpp
+++ flang/lib/Optimizer/Dialect/FIRAttr.cpp
@@ -163,8 +163,10 @@
       parser.emitError(parser.getNameLoc(), "expected real constant '>'");
       return {};
     }
-    auto bits = llvm::APInt(kind * 8, hex.drop_front(), 16);
-    value = llvm::APFloat(kindMap.getFloatSemantics(kind), bits);
+    const llvm::fltSemantics &sem = kindMap.getFloatSemantics(kind);
+    unsigned int numBits = llvm::APFloat::semanticsSizeInBits(sem);
+    auto bits = llvm::APInt(numBits, hex.drop_front(), 16);
+    value = llvm::APFloat(sem, bits);
   }
   return RealAttr::get(dialect->getContext(), {kind, value});
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114081.388414.patch
Type: text/x-patch
Size: 3392 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20211119/b07c2778/attachment.bin>


More information about the flang-commits mailing list