Skip to content

[flang][NFC] remove unused fir.constc operation #110821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions flang/include/flang/Optimizer/Dialect/FIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -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)>;
Expand Down
39 changes: 6 additions & 33 deletions flang/lib/Optimizer/CodeGen/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
34 changes: 0 additions & 34 deletions flang/lib/Optimizer/Dialect/FIROps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//===----------------------------------------------------------------------===//
Expand Down
32 changes: 0 additions & 32 deletions flang/test/Fir/convert-to-llvm.fir
Original file line number Diff line number Diff line change
Expand Up @@ -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>) {
Expand Down
17 changes: 0 additions & 17 deletions flang/test/Fir/fir-ops.fir
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading