Skip to content

Commit 149ad3d

Browse files
committed
[flang][mlir][NFC] Replace uses of raw accessors with prefixed accessors
`kEmitAccessorPrefix_Raw ` is being removed, and so updating the accessors to `kEmitAccessorPrefix_Prefixed`. Reviewed By: clementval Differential Revision: https://reviews.llvm.org/D119812
1 parent 7dce12d commit 149ad3d

21 files changed

+438
-417
lines changed

flang/include/flang/Optimizer/Builder/FIRBuilder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,14 @@ class FirOpBuilder : public mlir::OpBuilder {
294294
: ifOp{ifOp}, builder{builder} {}
295295
template <typename CC>
296296
IfBuilder &genThen(CC func) {
297-
builder.setInsertionPointToStart(&ifOp.thenRegion().front());
297+
builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
298298
func();
299299
return *this;
300300
}
301301
template <typename CC>
302302
IfBuilder &genElse(CC func) {
303-
assert(!ifOp.elseRegion().empty() && "must have else region");
304-
builder.setInsertionPointToStart(&ifOp.elseRegion().front());
303+
assert(!ifOp.getElseRegion().empty() && "must have else region");
304+
builder.setInsertionPointToStart(&ifOp.getElseRegion().front());
305305
func();
306306
return *this;
307307
}

flang/include/flang/Optimizer/Dialect/FIRDialect.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
2424
def fir_Dialect : Dialect {
2525
let name = "fir";
2626
let cppNamespace = "::fir";
27-
let emitAccessorPrefix = kEmitAccessorPrefix_Both;
27+
let emitAccessorPrefix = kEmitAccessorPrefix_Prefixed;
2828
let useDefaultTypePrinterParser = 0;
2929
let useDefaultAttributePrinterParser = 0;
3030
}

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

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ def fir_AllocaOp : fir_Op<"alloca", [AttrSizedOperandSegments,
167167

168168
let extraClassDeclaration = [{
169169
mlir::Type getAllocatedType();
170-
bool hasLenParams() { return !typeparams().empty(); }
171-
bool hasShapeOperands() { return !shape().empty(); }
172-
unsigned numLenParams() { return typeparams().size(); }
173-
operand_range getLenParams() { return typeparams(); }
174-
unsigned numShapeOperands() { return shape().size(); }
175-
operand_range getShapeOperands() { return shape(); }
170+
bool hasLenParams() { return !getTypeparams().empty(); }
171+
bool hasShapeOperands() { return !getShape().empty(); }
172+
unsigned numLenParams() { return getTypeparams().size(); }
173+
operand_range getLenParams() { return getTypeparams(); }
174+
unsigned numShapeOperands() { return getShape().size(); }
175+
operand_range getShapeOperands() { return getShape(); }
176176
static mlir::Type getRefTy(mlir::Type ty);
177177
}];
178178
}
@@ -221,12 +221,12 @@ def fir_AllocMemOp : fir_Op<"allocmem",
221221

222222
let extraClassDeclaration = [{
223223
mlir::Type getAllocatedType();
224-
bool hasLenParams() { return !typeparams().empty(); }
225-
bool hasShapeOperands() { return !shape().empty(); }
226-
unsigned numLenParams() { return typeparams().size(); }
227-
operand_range getLenParams() { return typeparams(); }
228-
unsigned numShapeOperands() { return shape().size(); }
229-
operand_range getShapeOperands() { return shape(); }
224+
bool hasLenParams() { return !getTypeparams().empty(); }
225+
bool hasShapeOperands() { return !getShape().empty(); }
226+
unsigned numLenParams() { return getTypeparams().size(); }
227+
operand_range getLenParams() { return getTypeparams(); }
228+
unsigned numShapeOperands() { return getShape().size(); }
229+
operand_range getShapeOperands() { return getShape(); }
230230
static mlir::Type getRefTy(mlir::Type ty);
231231
}];
232232
}
@@ -872,8 +872,8 @@ def fir_EmboxOp : fir_Op<"embox", [NoSideEffect, AttrSizedOperandSegments]> {
872872
let hasVerifier = 1;
873873

874874
let extraClassDeclaration = [{
875-
bool hasLenParams() { return !typeparams().empty(); }
876-
unsigned numLenParams() { return typeparams().size(); }
875+
bool hasLenParams() { return !getTypeparams().empty(); }
876+
unsigned numLenParams() { return getTypeparams().size(); }
877877
}];
878878
}
879879

@@ -1804,7 +1804,7 @@ def fir_FieldIndexOp : fir_OneResultOp<"field_index", [NoSideEffect]> {
18041804
let extraClassDeclaration = [{
18051805
static constexpr llvm::StringRef fieldAttrName() { return "field_id"; }
18061806
static constexpr llvm::StringRef typeAttrName() { return "on_type"; }
1807-
llvm::StringRef getFieldName() { return field_id(); }
1807+
llvm::StringRef getFieldName() { return getFieldId(); }
18081808
}];
18091809
}
18101810

@@ -1868,7 +1868,7 @@ def fir_ShapeShiftOp : fir_Op<"shape_shift", [NoSideEffect]> {
18681868
// Logically unzip the origins from the extent values.
18691869
std::vector<mlir::Value> getOrigins() {
18701870
std::vector<mlir::Value> result;
1871-
for (auto i : llvm::enumerate(pairs()))
1871+
for (auto i : llvm::enumerate(getPairs()))
18721872
if (!(i.index() & 1))
18731873
result.push_back(i.value());
18741874
return result;
@@ -1877,7 +1877,7 @@ def fir_ShapeShiftOp : fir_Op<"shape_shift", [NoSideEffect]> {
18771877
// Logically unzip the extents from the origin values.
18781878
std::vector<mlir::Value> getExtents() {
18791879
std::vector<mlir::Value> result;
1880-
for (auto i : llvm::enumerate(pairs()))
1880+
for (auto i : llvm::enumerate(getPairs()))
18811881
if (i.index() & 1)
18821882
result.push_back(i.value());
18831883
return result;
@@ -1970,7 +1970,7 @@ def fir_SliceOp : fir_Op<"slice", [NoSideEffect, AttrSizedOperandSegments]> {
19701970
let hasVerifier = 1;
19711971

19721972
let extraClassDeclaration = [{
1973-
unsigned getOutRank() { return getOutputRank(triples()); }
1973+
unsigned getOutRank() { return getOutputRank(getTriples()); }
19741974
static unsigned getOutputRank(mlir::ValueRange triples);
19751975
}];
19761976
}
@@ -2182,10 +2182,10 @@ def fir_DoLoopOp : region_Op<"do_loop",
21822182
}
21832183

21842184
/// Get the body of the loop
2185-
mlir::Block *getBody() { return &region().front(); }
2185+
mlir::Block *getBody() { return &getRegion().front(); }
21862186

21872187
void setUnordered() {
2188-
unorderedAttr(mlir::UnitAttr::get(getContext()));
2188+
setUnorderedAttr(mlir::UnitAttr::get(getContext()));
21892189
}
21902190

21912191
mlir::BlockArgument iterArgToBlockArg(mlir::Value iterArg);
@@ -2229,13 +2229,13 @@ def fir_IfOp : region_Op<"if", [NoRegionArguments]> {
22292229

22302230
let extraClassDeclaration = [{
22312231
mlir::OpBuilder getThenBodyBuilder() {
2232-
assert(!thenRegion().empty() && "Unexpected empty 'where' region.");
2233-
mlir::Block &body = thenRegion().front();
2232+
assert(!getThenRegion().empty() && "Unexpected empty 'where' region.");
2233+
mlir::Block &body = getThenRegion().front();
22342234
return mlir::OpBuilder(&body, std::prev(body.end()));
22352235
}
22362236
mlir::OpBuilder getElseBodyBuilder() {
2237-
assert(!elseRegion().empty() && "Unexpected empty 'other' region.");
2238-
mlir::Block &body = elseRegion().front();
2237+
assert(!getElseRegion().empty() && "Unexpected empty 'other' region.");
2238+
mlir::Block &body = getElseRegion().front();
22392239
return mlir::OpBuilder(&body, std::prev(body.end()));
22402240
}
22412241

@@ -2298,7 +2298,7 @@ def fir_IterWhileOp : region_Op<"iterate_while",
22982298
static constexpr llvm::StringRef getFinalValueAttrNameStr() {
22992299
return "finalValue";
23002300
}
2301-
mlir::Block *getBody() { return &region().front(); }
2301+
mlir::Block *getBody() { return &getRegion().front(); }
23022302
mlir::Value getIterateVar() { return getBody()->getArgument(1); }
23032303
mlir::Value getInductionVar() { return getBody()->getArgument(0); }
23042304
mlir::OpBuilder getBodyBuilder() {
@@ -2777,7 +2777,7 @@ def fir_GlobalOp : fir_Op<"global", [IsolatedFromAbove, Symbol]> {
27772777
mlir::Type resultType();
27782778

27792779
/// Return the initializer attribute if it exists, or a null attribute.
2780-
Attribute getValueOrNull() { return initVal().getValueOr(Attribute()); }
2780+
Attribute getValueOrNull() { return getInitVal().getValueOr(Attribute()); }
27812781

27822782
/// Append the next initializer value to the `GlobalOp` to construct
27832783
/// the variable's initial value.

flang/lib/Optimizer/Builder/Character.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ fir::factory::CharacterExprHelper::toExtendedValue(mlir::Value character,
138138
mlir::Value boxCharLen;
139139
if (auto *definingOp = character.getDefiningOp()) {
140140
if (auto box = dyn_cast<fir::EmboxCharOp>(definingOp)) {
141-
base = box.memref();
142-
boxCharLen = box.len();
141+
base = box.getMemref();
142+
boxCharLen = box.getLen();
143143
}
144144
}
145145
if (!boxCharLen) {

flang/lib/Optimizer/Builder/MutableBox.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ void fir::factory::genFinalization(fir::FirOpBuilder &builder,
436436
auto ifOp = builder.create<fir::IfOp>(loc, isAllocated,
437437
/*withElseRegion=*/false);
438438
auto insPt = builder.saveInsertionPoint();
439-
builder.setInsertionPointToStart(&ifOp.thenRegion().front());
439+
builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
440440
genFinalizeAndFree(builder, loc, addr);
441441
builder.restoreInsertionPoint(insPt);
442442
}

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ struct AddrOfOpConversion : public FIROpConversion<fir::AddrOfOp> {
309309
mlir::ConversionPatternRewriter &rewriter) const override {
310310
auto ty = convertType(addr.getType());
311311
rewriter.replaceOpWithNewOp<mlir::LLVM::AddressOfOp>(
312-
addr, ty, addr.symbol().getRootReference().getValue());
312+
addr, ty, addr.getSymbol().getRootReference().getValue());
313313
return success();
314314
}
315315
};
@@ -416,7 +416,7 @@ struct BoxAddrOpConversion : public FIROpConversion<fir::BoxAddrOp> {
416416
mlir::Value a = adaptor.getOperands()[0];
417417
auto loc = boxaddr.getLoc();
418418
mlir::Type ty = convertType(boxaddr.getType());
419-
if (auto argty = boxaddr.val().getType().dyn_cast<fir::BoxType>()) {
419+
if (auto argty = boxaddr.getVal().getType().dyn_cast<fir::BoxType>()) {
420420
rewriter.replaceOp(boxaddr, loadBaseAddrFromBox(loc, ty, a, rewriter));
421421
} else {
422422
auto c0attr = rewriter.getI32IntegerAttr(0);
@@ -640,7 +640,7 @@ struct CmpcOpConversion : public FIROpConversion<fir::CmpcOp> {
640640
mlir::ConversionPatternRewriter &rewriter) const override {
641641
mlir::ValueRange operands = adaptor.getOperands();
642642
mlir::MLIRContext *ctxt = cmp.getContext();
643-
mlir::Type eleTy = convertType(getComplexEleTy(cmp.lhs().getType()));
643+
mlir::Type eleTy = convertType(getComplexEleTy(cmp.getLhs().getType()));
644644
mlir::Type resTy = convertType(cmp.getType());
645645
mlir::Location loc = cmp.getLoc();
646646
auto pos0 = mlir::ArrayAttr::get(ctxt, rewriter.getI32IntegerAttr(0));
@@ -716,8 +716,8 @@ struct ConvertOpConversion : public FIROpConversion<fir::ConvertOp> {
716716
mlir::LogicalResult
717717
matchAndRewrite(fir::ConvertOp convert, OpAdaptor adaptor,
718718
mlir::ConversionPatternRewriter &rewriter) const override {
719-
auto fromTy = convertType(convert.value().getType());
720-
auto toTy = convertType(convert.res().getType());
719+
auto fromTy = convertType(convert.getValue().getType());
720+
auto toTy = convertType(convert.getRes().getType());
721721
mlir::Value op0 = adaptor.getOperands()[0];
722722
if (fromTy == toTy) {
723723
rewriter.replaceOp(convert, op0);
@@ -739,18 +739,18 @@ struct ConvertOpConversion : public FIROpConversion<fir::ConvertOp> {
739739
return rewriter.create<mlir::LLVM::FPExtOp>(loc, toTy, val);
740740
};
741741
// Complex to complex conversion.
742-
if (fir::isa_complex(convert.value().getType()) &&
743-
fir::isa_complex(convert.res().getType())) {
742+
if (fir::isa_complex(convert.getValue().getType()) &&
743+
fir::isa_complex(convert.getRes().getType())) {
744744
// Special case: handle the conversion of a complex such that both the
745745
// real and imaginary parts are converted together.
746746
auto zero = mlir::ArrayAttr::get(convert.getContext(),
747747
rewriter.getI32IntegerAttr(0));
748748
auto one = mlir::ArrayAttr::get(convert.getContext(),
749749
rewriter.getI32IntegerAttr(1));
750-
auto ty = convertType(getComplexEleTy(convert.value().getType()));
750+
auto ty = convertType(getComplexEleTy(convert.getValue().getType()));
751751
auto rp = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, ty, op0, zero);
752752
auto ip = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, ty, op0, one);
753-
auto nt = convertType(getComplexEleTy(convert.res().getType()));
753+
auto nt = convertType(getComplexEleTy(convert.getRes().getType()));
754754
auto fromBits = mlir::LLVM::getPrimitiveTypeSizeInBits(ty);
755755
auto toBits = mlir::LLVM::getPrimitiveTypeSizeInBits(nt);
756756
auto rc = convertFpToFp(rp, fromBits, toBits, nt);
@@ -1051,29 +1051,29 @@ struct GlobalOpConversion : public FIROpConversion<fir::GlobalOp> {
10511051
tyAttr = tyAttr.cast<mlir::LLVM::LLVMPointerType>().getElementType();
10521052
auto loc = global.getLoc();
10531053
mlir::Attribute initAttr{};
1054-
if (global.initVal())
1055-
initAttr = global.initVal().getValue();
1056-
auto linkage = convertLinkage(global.linkName());
1057-
auto isConst = global.constant().hasValue();
1054+
if (global.getInitVal())
1055+
initAttr = global.getInitVal().getValue();
1056+
auto linkage = convertLinkage(global.getLinkName());
1057+
auto isConst = global.getConstant().hasValue();
10581058
auto g = rewriter.create<mlir::LLVM::GlobalOp>(
10591059
loc, tyAttr, isConst, linkage, global.getSymName(), initAttr);
10601060
auto &gr = g.getInitializerRegion();
1061-
rewriter.inlineRegionBefore(global.region(), gr, gr.end());
1061+
rewriter.inlineRegionBefore(global.getRegion(), gr, gr.end());
10621062
if (!gr.empty()) {
10631063
// Replace insert_on_range with a constant dense attribute if the
10641064
// initialization is on the full range.
10651065
auto insertOnRangeOps = gr.front().getOps<fir::InsertOnRangeOp>();
10661066
for (auto insertOp : insertOnRangeOps) {
1067-
if (isFullRange(insertOp.coor(), insertOp.getType())) {
1067+
if (isFullRange(insertOp.getCoor(), insertOp.getType())) {
10681068
auto seqTyAttr = convertType(insertOp.getType());
1069-
auto *op = insertOp.val().getDefiningOp();
1069+
auto *op = insertOp.getVal().getDefiningOp();
10701070
auto constant = mlir::dyn_cast<mlir::arith::ConstantOp>(op);
10711071
if (!constant) {
10721072
auto convertOp = mlir::dyn_cast<fir::ConvertOp>(op);
10731073
if (!convertOp)
10741074
continue;
10751075
constant = cast<mlir::arith::ConstantOp>(
1076-
convertOp.value().getDefiningOp());
1076+
convertOp.getValue().getDefiningOp());
10771077
}
10781078
mlir::Type vecType = mlir::VectorType::get(
10791079
insertOp.getType().getShape(), constant.getType());
@@ -1248,7 +1248,7 @@ static void selectMatchAndRewrite(fir::LLVMTypeConverter &lowering, OP select,
12481248
mlir::ConversionPatternRewriter &rewriter) {
12491249
unsigned conds = select.getNumConditions();
12501250
auto cases = select.getCases().getValue();
1251-
mlir::Value selector = adaptor.selector();
1251+
mlir::Value selector = adaptor.getSelector();
12521252
auto loc = select.getLoc();
12531253
assert(conds > 0 && "select must have cases");
12541254

@@ -1372,7 +1372,7 @@ struct StoreOpConversion : public FIROpConversion<fir::StoreOp> {
13721372
mlir::LogicalResult
13731373
matchAndRewrite(fir::StoreOp store, OpAdaptor adaptor,
13741374
mlir::ConversionPatternRewriter &rewriter) const override {
1375-
if (store.value().getType().isa<fir::BoxType>()) {
1375+
if (store.getValue().getType().isa<fir::BoxType>()) {
13761376
// fir.box value is actually in memory, load it first before storing it.
13771377
mlir::Location loc = store.getLoc();
13781378
mlir::Type boxPtrTy = adaptor.getOperands()[0].getType();
@@ -2277,7 +2277,7 @@ struct ExtractValueOpConversion
22772277
mlir::LogicalResult
22782278
doRewrite(fir::ExtractValueOp extractVal, mlir::Type ty, OpAdaptor adaptor,
22792279
mlir::ConversionPatternRewriter &rewriter) const override {
2280-
auto attrs = collectIndices(rewriter, extractVal.coor());
2280+
auto attrs = collectIndices(rewriter, extractVal.getCoor());
22812281
toRowMajor(attrs, adaptor.getOperands()[0].getType());
22822282
auto position = mlir::ArrayAttr::get(extractVal.getContext(), attrs);
22832283
rewriter.replaceOpWithNewOp<mlir::LLVM::ExtractValueOp>(
@@ -2296,7 +2296,7 @@ struct InsertValueOpConversion
22962296
mlir::LogicalResult
22972297
doRewrite(fir::InsertValueOp insertVal, mlir::Type ty, OpAdaptor adaptor,
22982298
mlir::ConversionPatternRewriter &rewriter) const override {
2299-
auto attrs = collectIndices(rewriter, insertVal.coor());
2299+
auto attrs = collectIndices(rewriter, insertVal.getCoor());
23002300
toRowMajor(attrs, adaptor.getOperands()[0].getType());
23012301
auto position = mlir::ArrayAttr::get(insertVal.getContext(), attrs);
23022302
rewriter.replaceOpWithNewOp<mlir::LLVM::InsertValueOp>(
@@ -2339,7 +2339,7 @@ struct InsertOnRangeOpConversion
23392339
SmallVector<uint64_t> uBounds;
23402340

23412341
// Unzip the upper and lower bound and convert to a row major format.
2342-
mlir::DenseIntElementsAttr coor = range.coor();
2342+
mlir::DenseIntElementsAttr coor = range.getCoor();
23432343
auto reversedCoor = llvm::reverse(coor.getValues<int64_t>());
23442344
for (auto i = reversedCoor.begin(), e = reversedCoor.end(); i != e; ++i) {
23452345
uBounds.push_back(*i++);
@@ -2759,7 +2759,7 @@ struct IsPresentOpConversion : public FIROpConversion<fir::IsPresentOp> {
27592759
mlir::Location loc = isPresent.getLoc();
27602760
auto ptr = adaptor.getOperands()[0];
27612761

2762-
if (isPresent.val().getType().isa<fir::BoxCharType>()) {
2762+
if (isPresent.getVal().getType().isa<fir::BoxCharType>()) {
27632763
auto structTy = ptr.getType().cast<mlir::LLVM::LLVMStructType>();
27642764
assert(!structTy.isOpaque() && !structTy.getBody().empty());
27652765

@@ -2900,8 +2900,8 @@ struct FieldIndexOpConversion : public FIROpConversion<fir::FieldIndexOp> {
29002900
mlir::LogicalResult
29012901
matchAndRewrite(fir::FieldIndexOp field, OpAdaptor adaptor,
29022902
mlir::ConversionPatternRewriter &rewriter) const override {
2903-
auto recTy = field.on_type().cast<fir::RecordType>();
2904-
unsigned index = recTy.getFieldIndex(field.field_id());
2903+
auto recTy = field.getOnType().cast<fir::RecordType>();
2904+
unsigned index = recTy.getFieldIndex(field.getFieldId());
29052905

29062906
if (!fir::hasDynamicSize(recTy)) {
29072907
// Derived type has compile-time constant layout. Return index of the
@@ -2915,7 +2915,7 @@ struct FieldIndexOpConversion : public FIROpConversion<fir::FieldIndexOp> {
29152915
// generated function to determine the byte offset of the field at runtime.
29162916
// This returns a non-constant.
29172917
FlatSymbolRefAttr symAttr = mlir::SymbolRefAttr::get(
2918-
field.getContext(), getOffsetMethodName(recTy, field.field_id()));
2918+
field.getContext(), getOffsetMethodName(recTy, field.getFieldId()));
29192919
NamedAttribute callAttr = rewriter.getNamedAttr("callee", symAttr);
29202920
NamedAttribute fieldAttr = rewriter.getNamedAttr(
29212921
"field", mlir::IntegerAttr::get(lowerTy().indexType(), index));
@@ -3069,7 +3069,8 @@ struct CoordinateOpConversion
30693069
// %lenp = fir.len_param_index len1, !fir.type<derived{len1:i32}>
30703070
// %addr = coordinate_of %box, %lenp
30713071
if (coor.getNumOperands() == 2) {
3072-
mlir::Operation *coordinateDef = (*coor.coor().begin()).getDefiningOp();
3072+
mlir::Operation *coordinateDef =
3073+
(*coor.getCoor().begin()).getDefiningOp();
30733074
if (isa_and_nonnull<fir::LenParamIndexOp>(coordinateDef)) {
30743075
TODO(loc,
30753076
"fir.coordinate_of - fir.len_param_index is not supported yet");

0 commit comments

Comments
 (0)