[flang-commits] [flang] [flang][NFC] remove unused fir.constc operation (PR #110821)
via flang-commits
flang-commits at lists.llvm.org
Wed Oct 2 03:36:27 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
@llvm/pr-subscribers-flang-codegen
Author: None (jeanPerier)
<details>
<summary>Changes</summary>
As part of [RFC to replace fir.complex usages by mlir.complex type](https://discourse.llvm.org/t/rfc-flang-replace-usages-of-fir-complex-by-mlir-complex-type/82292).
fir.constc is unused so instead of porting it, just remove it.
Complex constants are currently created with inserts in lowering already. When using mlir complex, we may just want to start using [complex.constant](https://github.com/llvm/llvm-project/blob/4f6ad17adce1b87cadf0c896d3b38334045196ea/mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td#L131C5-L131C16).
---
Full diff: https://github.com/llvm/llvm-project/pull/110821.diff
5 Files Affected:
- (modified) flang/include/flang/Optimizer/Dialect/FIROps.td (-23)
- (modified) flang/lib/Optimizer/CodeGen/CodeGen.cpp (+6-33)
- (modified) flang/lib/Optimizer/Dialect/FIROps.cpp (-34)
- (modified) flang/test/Fir/convert-to-llvm.fir (-32)
- (modified) flang/test/Fir/fir-ops.fir (-17)
``````````diff
diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td
index 68847cfa2cbc25..b34d7629613bad 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROps.td
+++ b/flang/include/flang/Optimizer/Dialect/FIROps.td
@@ -2609,29 +2609,6 @@ class fir_UnaryArithmeticOp<string mnemonic, list<Trait> traits = []> :
let assemblyFormat = "operands attr-dict `:` type($result)";
}
-def fir_ConstcOp : fir_Op<"constc", [NoMemoryEffect]> {
- let summary = "create a complex constant";
-
- let description = [{
- A complex constant. Similar to the standard dialect complex type, but this
- extension allows constants with APFloat values that are not supported in
- the standard dialect.
- }];
-
- let results = (outs fir_ComplexType);
-
- let hasCustomAssemblyFormat = 1;
- let hasVerifier = 1;
-
- let extraClassDeclaration = [{
- static constexpr llvm::StringRef getRealAttrName() { return "real"; }
- static constexpr llvm::StringRef getImagAttrName() { return "imaginary"; }
-
- mlir::Attribute getReal() { return (*this)->getAttr(getRealAttrName()); }
- mlir::Attribute getImaginary() { return (*this)->getAttr(getImagAttrName()); }
- }];
-}
-
class ComplexUnaryArithmeticOp<string mnemonic, list<Trait> traits = []> :
fir_UnaryArithmeticOp<mnemonic, traits>,
Arguments<(ins fir_ComplexType:$operand)>;
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index efc28e9708e197..a8a92d8b046b5d 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -637,33 +637,6 @@ struct CmpcOpConversion : public fir::FIROpConversion<fir::CmpcOp> {
}
};
-/// Lower complex constants
-struct ConstcOpConversion : public fir::FIROpConversion<fir::ConstcOp> {
- using FIROpConversion::FIROpConversion;
-
- llvm::LogicalResult
- matchAndRewrite(fir::ConstcOp conc, OpAdaptor,
- mlir::ConversionPatternRewriter &rewriter) const override {
- mlir::Location loc = conc.getLoc();
- mlir::Type ty = convertType(conc.getType());
- mlir::Type ety = convertType(getComplexEleTy(conc.getType()));
- auto realPart = rewriter.create<mlir::LLVM::ConstantOp>(
- loc, ety, getValue(conc.getReal()));
- auto imPart = rewriter.create<mlir::LLVM::ConstantOp>(
- loc, ety, getValue(conc.getImaginary()));
- auto undef = rewriter.create<mlir::LLVM::UndefOp>(loc, ty);
- auto setReal =
- rewriter.create<mlir::LLVM::InsertValueOp>(loc, undef, realPart, 0);
- rewriter.replaceOpWithNewOp<mlir::LLVM::InsertValueOp>(conc, setReal,
- imPart, 1);
- return mlir::success();
- }
-
- inline llvm::APFloat getValue(mlir::Attribute attr) const {
- return mlir::cast<fir::RealAttr>(attr).getValue();
- }
-};
-
/// convert value of from-type to value of to-type
struct ConvertOpConversion : public fir::FIROpConversion<fir::ConvertOp> {
using FIROpConversion::FIROpConversion;
@@ -3861,12 +3834,12 @@ void fir::populateFIRToLLVMConversionPatterns(
BoxIsAllocOpConversion, BoxIsArrayOpConversion, BoxIsPtrOpConversion,
BoxOffsetOpConversion, BoxProcHostOpConversion, BoxRankOpConversion,
BoxTypeCodeOpConversion, BoxTypeDescOpConversion, CallOpConversion,
- CmpcOpConversion, ConstcOpConversion, ConvertOpConversion,
- CoordinateOpConversion, DTEntryOpConversion, DeclareOpConversion,
- DivcOpConversion, EmboxOpConversion, EmboxCharOpConversion,
- EmboxProcOpConversion, ExtractValueOpConversion, FieldIndexOpConversion,
- FirEndOpConversion, FreeMemOpConversion, GlobalLenOpConversion,
- GlobalOpConversion, InsertOnRangeOpConversion, IsPresentOpConversion,
+ CmpcOpConversion, ConvertOpConversion, CoordinateOpConversion,
+ DTEntryOpConversion, DeclareOpConversion, DivcOpConversion,
+ EmboxOpConversion, EmboxCharOpConversion, EmboxProcOpConversion,
+ ExtractValueOpConversion, FieldIndexOpConversion, FirEndOpConversion,
+ FreeMemOpConversion, GlobalLenOpConversion, GlobalOpConversion,
+ InsertOnRangeOpConversion, IsPresentOpConversion,
LenParamIndexOpConversion, LoadOpConversion, MulcOpConversion,
NegcOpConversion, NoReassocOpConversion, SelectCaseOpConversion,
SelectOpConversion, SelectRankOpConversion, SelectTypeOpConversion,
diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index 13a30a358a8660..79632ef9eadf99 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -1304,40 +1304,6 @@ mlir::ParseResult fir::CmpcOp::parse(mlir::OpAsmParser &parser,
return parseCmpOp<fir::CmpcOp>(parser, result);
}
-//===----------------------------------------------------------------------===//
-// ConstcOp
-//===----------------------------------------------------------------------===//
-
-mlir::ParseResult fir::ConstcOp::parse(mlir::OpAsmParser &parser,
- mlir::OperationState &result) {
- fir::RealAttr realp;
- fir::RealAttr imagp;
- mlir::Type type;
- if (parser.parseLParen() ||
- parser.parseAttribute(realp, fir::ConstcOp::getRealAttrName(),
- result.attributes) ||
- parser.parseComma() ||
- parser.parseAttribute(imagp, fir::ConstcOp::getImagAttrName(),
- result.attributes) ||
- parser.parseRParen() || parser.parseColonType(type) ||
- parser.addTypesToList(type, result.types))
- return mlir::failure();
- return mlir::success();
-}
-
-void fir::ConstcOp::print(mlir::OpAsmPrinter &p) {
- p << '(';
- p << getOperation()->getAttr(fir::ConstcOp::getRealAttrName()) << ", ";
- p << getOperation()->getAttr(fir::ConstcOp::getImagAttrName()) << ") : ";
- p.printType(getType());
-}
-
-llvm::LogicalResult fir::ConstcOp::verify() {
- if (!mlir::isa<fir::ComplexType>(getType()))
- return emitOpError("must be a !fir.complex type");
- return mlir::success();
-}
-
//===----------------------------------------------------------------------===//
// ConvertOp
//===----------------------------------------------------------------------===//
diff --git a/flang/test/Fir/convert-to-llvm.fir b/flang/test/Fir/convert-to-llvm.fir
index a4e8170af036c9..8f5406f1705a35 100644
--- a/flang/test/Fir/convert-to-llvm.fir
+++ b/flang/test/Fir/convert-to-llvm.fir
@@ -816,38 +816,6 @@ func.func @convert_complex16(%arg0 : !fir.complex<16>) -> !fir.complex<2> {
// -----
-// Test constc.
-
-func.func @test_constc4() -> !fir.complex<4> {
- %0 = fir.constc (#fir.real<4, 1.4>, #fir.real<4, 2.3>) : !fir.complex<4>
- return %0 : !fir.complex<4>
-}
-
-// CHECK-LABEL: @test_constc4
-// CHECK-SAME: () -> !llvm.struct<(f32, f32)>
-// CHECK-DAG: [[rp:%.*]] = llvm.mlir.constant(1.400000e+00 : f32) : f32
-// CHECK-DAG: [[ip:%.*]] = llvm.mlir.constant(2.300000e+00 : f32) : f32
-// CHECK: [[undef:%.*]] = llvm.mlir.undef : !llvm.struct<(f32, f32)>
-// CHECK: [[withr:%.*]] = llvm.insertvalue [[rp]], [[undef]][0] : !llvm.struct<(f32, f32)>
-// CHECK: [[full:%.*]] = llvm.insertvalue [[ip]], [[withr]][1] : !llvm.struct<(f32, f32)>
-// CHECK: return [[full]] : !llvm.struct<(f32, f32)>
-
-func.func @test_constc8() -> !fir.complex<8> {
- %0 = fir.constc (#fir.real<8, 1.8>, #fir.real<8, 2.3>) : !fir.complex<8>
- return %0 : !fir.complex<8>
-}
-
-// CHECK-LABEL: @test_constc8
-// CHECK-SAME: () -> !llvm.struct<(f64, f64)>
-// CHECK-DAG: [[rp:%.*]] = llvm.mlir.constant(1.800000e+00 : f64) : f64
-// CHECK-DAG: [[ip:%.*]] = llvm.mlir.constant(2.300000e+00 : f64) : f64
-// CHECK: [[undef:%.*]] = llvm.mlir.undef : !llvm.struct<(f64, f64)>
-// CHECK: [[withr:%.*]] = llvm.insertvalue [[rp]], [[undef]][0] : !llvm.struct<(f64, f64)>
-// CHECK: [[full:%.*]] = llvm.insertvalue [[ip]], [[withr]][1] : !llvm.struct<(f64, f64)>
-// CHECK: return [[full]] : !llvm.struct<(f64, f64)>
-
-// -----
-
// Test `fir.store` --> `llvm.store` conversion
func.func @test_store_index(%val_to_store : index, %addr : !fir.ref<index>) {
diff --git a/flang/test/Fir/fir-ops.fir b/flang/test/Fir/fir-ops.fir
index b8ae566e87a1fa..5d66bfe645de09 100644
--- a/flang/test/Fir/fir-ops.fir
+++ b/flang/test/Fir/fir-ops.fir
@@ -675,23 +675,6 @@ func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n :
return
}
-// CHECK-LABEL: @test_const_complex
-func.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: @insert_on_range_multi_dim
// CHECK-SAME: %[[ARR:.*]]: !fir.array<10x20xi32>, %[[CST:.*]]: i32
func.func @insert_on_range_multi_dim(%arr : !fir.array<10x20xi32>, %cst : i32) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/110821
More information about the flang-commits
mailing list