[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](4f6ad17adc/mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td (L131C5-L131C16)).
This commit is contained in:
jeanPerier
2024-10-02 16:16:57 +02:00
committed by GitHub
parent 2d784b1946
commit c2601f1769
5 changed files with 6 additions and 139 deletions

View File

@@ -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)>;

View File

@@ -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,

View File

@@ -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
//===----------------------------------------------------------------------===//

View File

@@ -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>) {

View File

@@ -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) {