Skip to content

Commit c2601f1

Browse files
authored
[flang][NFC] remove unused fir.constc operation (#110821)
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).
1 parent 2d784b1 commit c2601f1

File tree

5 files changed

+6
-139
lines changed

5 files changed

+6
-139
lines changed

flang/include/flang/Optimizer/Dialect/FIROps.td

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,29 +2609,6 @@ class fir_UnaryArithmeticOp<string mnemonic, list<Trait> traits = []> :
26092609
let assemblyFormat = "operands attr-dict `:` type($result)";
26102610
}
26112611

2612-
def fir_ConstcOp : fir_Op<"constc", [NoMemoryEffect]> {
2613-
let summary = "create a complex constant";
2614-
2615-
let description = [{
2616-
A complex constant. Similar to the standard dialect complex type, but this
2617-
extension allows constants with APFloat values that are not supported in
2618-
the standard dialect.
2619-
}];
2620-
2621-
let results = (outs fir_ComplexType);
2622-
2623-
let hasCustomAssemblyFormat = 1;
2624-
let hasVerifier = 1;
2625-
2626-
let extraClassDeclaration = [{
2627-
static constexpr llvm::StringRef getRealAttrName() { return "real"; }
2628-
static constexpr llvm::StringRef getImagAttrName() { return "imaginary"; }
2629-
2630-
mlir::Attribute getReal() { return (*this)->getAttr(getRealAttrName()); }
2631-
mlir::Attribute getImaginary() { return (*this)->getAttr(getImagAttrName()); }
2632-
}];
2633-
}
2634-
26352612
class ComplexUnaryArithmeticOp<string mnemonic, list<Trait> traits = []> :
26362613
fir_UnaryArithmeticOp<mnemonic, traits>,
26372614
Arguments<(ins fir_ComplexType:$operand)>;

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -637,33 +637,6 @@ struct CmpcOpConversion : public fir::FIROpConversion<fir::CmpcOp> {
637637
}
638638
};
639639

640-
/// Lower complex constants
641-
struct ConstcOpConversion : public fir::FIROpConversion<fir::ConstcOp> {
642-
using FIROpConversion::FIROpConversion;
643-
644-
llvm::LogicalResult
645-
matchAndRewrite(fir::ConstcOp conc, OpAdaptor,
646-
mlir::ConversionPatternRewriter &rewriter) const override {
647-
mlir::Location loc = conc.getLoc();
648-
mlir::Type ty = convertType(conc.getType());
649-
mlir::Type ety = convertType(getComplexEleTy(conc.getType()));
650-
auto realPart = rewriter.create<mlir::LLVM::ConstantOp>(
651-
loc, ety, getValue(conc.getReal()));
652-
auto imPart = rewriter.create<mlir::LLVM::ConstantOp>(
653-
loc, ety, getValue(conc.getImaginary()));
654-
auto undef = rewriter.create<mlir::LLVM::UndefOp>(loc, ty);
655-
auto setReal =
656-
rewriter.create<mlir::LLVM::InsertValueOp>(loc, undef, realPart, 0);
657-
rewriter.replaceOpWithNewOp<mlir::LLVM::InsertValueOp>(conc, setReal,
658-
imPart, 1);
659-
return mlir::success();
660-
}
661-
662-
inline llvm::APFloat getValue(mlir::Attribute attr) const {
663-
return mlir::cast<fir::RealAttr>(attr).getValue();
664-
}
665-
};
666-
667640
/// convert value of from-type to value of to-type
668641
struct ConvertOpConversion : public fir::FIROpConversion<fir::ConvertOp> {
669642
using FIROpConversion::FIROpConversion;
@@ -3861,12 +3834,12 @@ void fir::populateFIRToLLVMConversionPatterns(
38613834
BoxIsAllocOpConversion, BoxIsArrayOpConversion, BoxIsPtrOpConversion,
38623835
BoxOffsetOpConversion, BoxProcHostOpConversion, BoxRankOpConversion,
38633836
BoxTypeCodeOpConversion, BoxTypeDescOpConversion, CallOpConversion,
3864-
CmpcOpConversion, ConstcOpConversion, ConvertOpConversion,
3865-
CoordinateOpConversion, DTEntryOpConversion, DeclareOpConversion,
3866-
DivcOpConversion, EmboxOpConversion, EmboxCharOpConversion,
3867-
EmboxProcOpConversion, ExtractValueOpConversion, FieldIndexOpConversion,
3868-
FirEndOpConversion, FreeMemOpConversion, GlobalLenOpConversion,
3869-
GlobalOpConversion, InsertOnRangeOpConversion, IsPresentOpConversion,
3837+
CmpcOpConversion, ConvertOpConversion, CoordinateOpConversion,
3838+
DTEntryOpConversion, DeclareOpConversion, DivcOpConversion,
3839+
EmboxOpConversion, EmboxCharOpConversion, EmboxProcOpConversion,
3840+
ExtractValueOpConversion, FieldIndexOpConversion, FirEndOpConversion,
3841+
FreeMemOpConversion, GlobalLenOpConversion, GlobalOpConversion,
3842+
InsertOnRangeOpConversion, IsPresentOpConversion,
38703843
LenParamIndexOpConversion, LoadOpConversion, MulcOpConversion,
38713844
NegcOpConversion, NoReassocOpConversion, SelectCaseOpConversion,
38723845
SelectOpConversion, SelectRankOpConversion, SelectTypeOpConversion,

flang/lib/Optimizer/Dialect/FIROps.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,40 +1304,6 @@ mlir::ParseResult fir::CmpcOp::parse(mlir::OpAsmParser &parser,
13041304
return parseCmpOp<fir::CmpcOp>(parser, result);
13051305
}
13061306

1307-
//===----------------------------------------------------------------------===//
1308-
// ConstcOp
1309-
//===----------------------------------------------------------------------===//
1310-
1311-
mlir::ParseResult fir::ConstcOp::parse(mlir::OpAsmParser &parser,
1312-
mlir::OperationState &result) {
1313-
fir::RealAttr realp;
1314-
fir::RealAttr imagp;
1315-
mlir::Type type;
1316-
if (parser.parseLParen() ||
1317-
parser.parseAttribute(realp, fir::ConstcOp::getRealAttrName(),
1318-
result.attributes) ||
1319-
parser.parseComma() ||
1320-
parser.parseAttribute(imagp, fir::ConstcOp::getImagAttrName(),
1321-
result.attributes) ||
1322-
parser.parseRParen() || parser.parseColonType(type) ||
1323-
parser.addTypesToList(type, result.types))
1324-
return mlir::failure();
1325-
return mlir::success();
1326-
}
1327-
1328-
void fir::ConstcOp::print(mlir::OpAsmPrinter &p) {
1329-
p << '(';
1330-
p << getOperation()->getAttr(fir::ConstcOp::getRealAttrName()) << ", ";
1331-
p << getOperation()->getAttr(fir::ConstcOp::getImagAttrName()) << ") : ";
1332-
p.printType(getType());
1333-
}
1334-
1335-
llvm::LogicalResult fir::ConstcOp::verify() {
1336-
if (!mlir::isa<fir::ComplexType>(getType()))
1337-
return emitOpError("must be a !fir.complex type");
1338-
return mlir::success();
1339-
}
1340-
13411307
//===----------------------------------------------------------------------===//
13421308
// ConvertOp
13431309
//===----------------------------------------------------------------------===//

flang/test/Fir/convert-to-llvm.fir

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -816,38 +816,6 @@ func.func @convert_complex16(%arg0 : !fir.complex<16>) -> !fir.complex<2> {
816816

817817
// -----
818818

819-
// Test constc.
820-
821-
func.func @test_constc4() -> !fir.complex<4> {
822-
%0 = fir.constc (#fir.real<4, 1.4>, #fir.real<4, 2.3>) : !fir.complex<4>
823-
return %0 : !fir.complex<4>
824-
}
825-
826-
// CHECK-LABEL: @test_constc4
827-
// CHECK-SAME: () -> !llvm.struct<(f32, f32)>
828-
// CHECK-DAG: [[rp:%.*]] = llvm.mlir.constant(1.400000e+00 : f32) : f32
829-
// CHECK-DAG: [[ip:%.*]] = llvm.mlir.constant(2.300000e+00 : f32) : f32
830-
// CHECK: [[undef:%.*]] = llvm.mlir.undef : !llvm.struct<(f32, f32)>
831-
// CHECK: [[withr:%.*]] = llvm.insertvalue [[rp]], [[undef]][0] : !llvm.struct<(f32, f32)>
832-
// CHECK: [[full:%.*]] = llvm.insertvalue [[ip]], [[withr]][1] : !llvm.struct<(f32, f32)>
833-
// CHECK: return [[full]] : !llvm.struct<(f32, f32)>
834-
835-
func.func @test_constc8() -> !fir.complex<8> {
836-
%0 = fir.constc (#fir.real<8, 1.8>, #fir.real<8, 2.3>) : !fir.complex<8>
837-
return %0 : !fir.complex<8>
838-
}
839-
840-
// CHECK-LABEL: @test_constc8
841-
// CHECK-SAME: () -> !llvm.struct<(f64, f64)>
842-
// CHECK-DAG: [[rp:%.*]] = llvm.mlir.constant(1.800000e+00 : f64) : f64
843-
// CHECK-DAG: [[ip:%.*]] = llvm.mlir.constant(2.300000e+00 : f64) : f64
844-
// CHECK: [[undef:%.*]] = llvm.mlir.undef : !llvm.struct<(f64, f64)>
845-
// CHECK: [[withr:%.*]] = llvm.insertvalue [[rp]], [[undef]][0] : !llvm.struct<(f64, f64)>
846-
// CHECK: [[full:%.*]] = llvm.insertvalue [[ip]], [[withr]][1] : !llvm.struct<(f64, f64)>
847-
// CHECK: return [[full]] : !llvm.struct<(f64, f64)>
848-
849-
// -----
850-
851819
// Test `fir.store` --> `llvm.store` conversion
852820

853821
func.func @test_store_index(%val_to_store : index, %addr : !fir.ref<index>) {

flang/test/Fir/fir-ops.fir

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -675,23 +675,6 @@ func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n :
675675
return
676676
}
677677

678-
// CHECK-LABEL: @test_const_complex
679-
func.func @test_const_complex() {
680-
// CHECK-DAG: {{%.*}} = fir.constc(#fir.real<2, i x3000>, #fir.real<2, i x4C40>) : !fir.complex<2>
681-
// CHECK-DAG: {{%.*}} = fir.constc(#fir.real<3, i x3E80>, #fir.real<3, i x4202>) : !fir.complex<3>
682-
// CHECK-DAG: {{%.*}} = fir.constc(#fir.real<4, i x3E800000>, #fir.real<4, i x42028000>) : !fir.complex<4>
683-
// CHECK-DAG: {{%.*}} = fir.constc(#fir.real<8, i x3FD0000000000000>, #fir.real<8, i x4040500000000000>) : !fir.complex<8>
684-
// CHECK-DAG: {{%.*}} = fir.constc(#fir.real<10, i x3FFD8000000000000000>, #fir.real<10, i x40048280000000000000>) : !fir.complex<10>
685-
// CHECK-DAG: {{%.*}} = fir.constc(#fir.real<16, i x3FFD0000000000000000000000000000>, #fir.real<16, i x40040500000000000000000000000000>) : !fir.complex<16>
686-
%c2 = fir.constc (#fir.real<2, 0.125>, #fir.real<2, 17.0>) : !fir.complex<2>
687-
%c3 = fir.constc (#fir.real<3, 0.25>, #fir.real<3, 32.625>) : !fir.complex<3>
688-
%c4 = fir.constc (#fir.real<4, 0.25>, #fir.real<4, 32.625>) : !fir.complex<4>
689-
%c8 = fir.constc (#fir.real<8, 0.25>, #fir.real<8, 32.625>) : !fir.complex<8>
690-
%c10 = fir.constc (#fir.real<10, 0.25>, #fir.real<10, 32.625>) : !fir.complex<10>
691-
%c16 = fir.constc (#fir.real<16, 0.25>, #fir.real<16, 32.625>) : !fir.complex<16>
692-
return
693-
}
694-
695678
// CHECK-LABEL: @insert_on_range_multi_dim
696679
// CHECK-SAME: %[[ARR:.*]]: !fir.array<10x20xi32>, %[[CST:.*]]: i32
697680
func.func @insert_on_range_multi_dim(%arr : !fir.array<10x20xi32>, %cst : i32) {

0 commit comments

Comments
 (0)