Skip to content

Commit cb510bb

Browse files
jeanPerieryuxuanchen1997
authored andcommitted
[flang][NFC] rename fircg op operand index accessors (#100584)
Summary: fircg operations have xxxOffset members to give the operand index of operand xxx. This is a bit weird when looking at usage (e.g. `arrayCoor.shiftOffset` reads like it is shifting some offset). Rename them to getXxxOperandIndex. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250528
1 parent 8f73d1f commit cb510bb

File tree

3 files changed

+73
-48
lines changed

3 files changed

+73
-48
lines changed

flang/include/flang/Optimizer/CodeGen/CGOps.td

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,24 @@ def fircg_XEmboxOp : fircg_Op<"ext_embox", [AttrSizedOperandSegments]> {
7878
unsigned getOutRank();
7979

8080
// The shape operands are mandatory and always start at 1.
81-
unsigned shapeOffset() { return 1; }
82-
unsigned shiftOffset() { return shapeOffset() + getShape().size(); }
83-
unsigned sliceOffset() { return shiftOffset() + getShift().size(); }
84-
unsigned subcomponentOffset() { return sliceOffset() + getSlice().size(); }
85-
unsigned substrOffset() {
86-
return subcomponentOffset() + getSubcomponent().size();
81+
unsigned getShapeOperandIndex() { return 1; }
82+
unsigned getShiftOperandIndex() {
83+
return getShapeOperandIndex() + getShape().size();
8784
}
88-
unsigned lenParamOffset() { return substrOffset() + getSubstr().size(); }
89-
unsigned getSourceBoxOffset() {
90-
return lenParamOffset() + getLenParams().size();
85+
unsigned getSliceOperandIndex() {
86+
return getShiftOperandIndex() + getShift().size();
87+
}
88+
unsigned getSubcomponentOperandIndex() {
89+
return getSliceOperandIndex() + getSlice().size();
90+
}
91+
unsigned getSubstrOperandIndex() {
92+
return getSubcomponentOperandIndex() + getSubcomponent().size();
93+
}
94+
unsigned getLenParamOperandIndex() {
95+
return getSubstrOperandIndex() + getSubstr().size();
96+
}
97+
unsigned getSourceBoxOperandIndex() {
98+
return getLenParamOperandIndex() + getLenParams().size();
9199
}
92100
}];
93101
}
@@ -135,12 +143,18 @@ def fircg_XReboxOp : fircg_Op<"ext_rebox", [AttrSizedOperandSegments]> {
135143
// The rank of the result box
136144
unsigned getOutRank();
137145

138-
unsigned shapeOffset() { return 1; }
139-
unsigned shiftOffset() { return shapeOffset() + getShape().size(); }
140-
unsigned sliceOffset() { return shiftOffset() + getShift().size(); }
141-
unsigned subcomponentOffset() { return sliceOffset() + getSlice().size(); }
142-
unsigned substrOffset() {
143-
return subcomponentOffset() + getSubcomponent().size();
146+
unsigned getShapeOperandIndex() { return 1; }
147+
unsigned getShiftOperandIndex() {
148+
return getShapeOperandIndex() + getShape().size();
149+
}
150+
unsigned getSliceOperandIndex() {
151+
return getShiftOperandIndex() + getShift().size();
152+
}
153+
unsigned getSubcomponentOperandIndex() {
154+
return getSliceOperandIndex() + getSlice().size();
155+
}
156+
unsigned getSubstrOperandIndex() {
157+
return getSubcomponentOperandIndex() + getSubcomponent().size();
144158
}
145159
}];
146160
}
@@ -193,14 +207,22 @@ def fircg_XArrayCoorOp : fircg_Op<"ext_array_coor", [AttrSizedOperandSegments]>
193207
unsigned getRank();
194208

195209
// Shape is optional, but if it exists, it will be at offset 1.
196-
unsigned shapeOffset() { return 1; }
197-
unsigned shiftOffset() { return shapeOffset() + getShape().size(); }
198-
unsigned sliceOffset() { return shiftOffset() + getShift().size(); }
199-
unsigned subcomponentOffset() { return sliceOffset() + getSlice().size(); }
200-
unsigned indicesOffset() {
201-
return subcomponentOffset() + getSubcomponent().size();
202-
}
203-
unsigned lenParamsOffset() { return indicesOffset() + getIndices().size(); }
210+
unsigned getShapeOperandIndex() { return 1; }
211+
unsigned getShiftOperandIndex() {
212+
return getShapeOperandIndex() + getShape().size();
213+
}
214+
unsigned getSliceOperandIndex() {
215+
return getShiftOperandIndex() + getShift().size();
216+
}
217+
unsigned getSubcomponentOperandIndex() {
218+
return getSliceOperandIndex() + getSlice().size();
219+
}
220+
unsigned getIndicesOperandIndex() {
221+
return getSubcomponentOperandIndex() + getSubcomponent().size();
222+
}
223+
unsigned getLenParamsOperandIndex() {
224+
return getIndicesOperandIndex() + getIndices().size();
225+
}
204226
}];
205227
}
206228

@@ -231,8 +253,10 @@ def fircg_XDeclareOp : fircg_Op<"ext_declare", [AttrSizedOperandSegments]> {
231253

232254
let extraClassDeclaration = [{
233255
// Shape is optional, but if it exists, it will be at offset 1.
234-
unsigned shapeOffset() { return 1; }
235-
unsigned shiftOffset() { return shapeOffset() + getShape().size(); }
256+
unsigned getShapeOperandIndex() { return 1; }
257+
unsigned getShiftOperandIndex() {
258+
return getShapeOperandIndex() + getShape().size();
259+
}
236260
}];
237261
}
238262

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ def fir_EmboxOp : fir_Op<"embox", [NoMemoryEffect, AttrSizedOperandSegments]> {
817817
let extraClassDeclaration = [{
818818
bool hasLenParams() { return !getTypeparams().empty(); }
819819
unsigned numLenParams() { return getTypeparams().size(); }
820-
unsigned getSourceBoxOffset() {
820+
unsigned getSourceBoxOperandIndex() {
821821
return 1 + (getShape() ? 1 : 0) + (getSlice() ? 1 : 0)
822822
+ numLenParams();
823823
}

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,8 +1431,8 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
14311431
fir::unwrapPassByRefType(memref.getType()))))
14321432
TODO(xbox.getLoc(),
14331433
"fir.embox codegen dynamic size component in derived type");
1434-
indices.append(operands.begin() + xbox.subcomponentOffset(),
1435-
operands.begin() + xbox.subcomponentOffset() +
1434+
indices.append(operands.begin() + xbox.getSubcomponentOperandIndex(),
1435+
operands.begin() + xbox.getSubcomponentOperandIndex() +
14361436
xbox.getSubcomponent().size());
14371437
}
14381438

@@ -1487,7 +1487,7 @@ struct EmboxOpConversion : public EmboxCommonConversion<fir::EmboxOp> {
14871487
mlir::Value sourceBox;
14881488
mlir::Type sourceBoxType;
14891489
if (embox.getSourceBox()) {
1490-
sourceBox = operands[embox.getSourceBoxOffset()];
1490+
sourceBox = operands[embox.getSourceBoxOperandIndex()];
14911491
sourceBoxType = embox.getSourceBox().getType();
14921492
}
14931493
assert(!embox.getShape() && "There should be no dims on this embox op");
@@ -1519,7 +1519,7 @@ struct XEmboxOpConversion : public EmboxCommonConversion<fir::cg::XEmboxOp> {
15191519
mlir::Value sourceBox;
15201520
mlir::Type sourceBoxType;
15211521
if (xbox.getSourceBox()) {
1522-
sourceBox = operands[xbox.getSourceBoxOffset()];
1522+
sourceBox = operands[xbox.getSourceBoxOperandIndex()];
15231523
sourceBoxType = xbox.getSourceBox().getType();
15241524
}
15251525
auto [boxTy, dest, resultEleSize] = consDescriptorPrefix(
@@ -1529,11 +1529,11 @@ struct XEmboxOpConversion : public EmboxCommonConversion<fir::cg::XEmboxOp> {
15291529
// Generate the triples in the dims field of the descriptor
15301530
auto i64Ty = mlir::IntegerType::get(xbox.getContext(), 64);
15311531
assert(!xbox.getShape().empty() && "must have a shape");
1532-
unsigned shapeOffset = xbox.shapeOffset();
1532+
unsigned shapeOffset = xbox.getShapeOperandIndex();
15331533
bool hasShift = !xbox.getShift().empty();
1534-
unsigned shiftOffset = xbox.shiftOffset();
1534+
unsigned shiftOffset = xbox.getShiftOperandIndex();
15351535
bool hasSlice = !xbox.getSlice().empty();
1536-
unsigned sliceOffset = xbox.sliceOffset();
1536+
unsigned sliceOffset = xbox.getSliceOperandIndex();
15371537
mlir::Location loc = xbox.getLoc();
15381538
mlir::Value zero = genConstantIndex(loc, i64Ty, rewriter, 0);
15391539
mlir::Value one = genConstantIndex(loc, i64Ty, rewriter, 1);
@@ -1682,7 +1682,7 @@ struct XEmboxOpConversion : public EmboxCommonConversion<fir::cg::XEmboxOp> {
16821682
if (hasSubcomp)
16831683
getSubcomponentIndices(xbox, xbox.getMemref(), operands, fieldIndices);
16841684
if (hasSubstr)
1685-
substringOffset = operands[xbox.substrOffset()];
1685+
substringOffset = operands[xbox.getSubstrOperandIndex()];
16861686
mlir::Type llvmBaseType =
16871687
convertType(fir::unwrapRefType(xbox.getMemref().getType()));
16881688
base = genBoxOffsetGep(rewriter, loc, base, llvmBaseType, ptrOffset,
@@ -1843,7 +1843,7 @@ struct XReboxOpConversion : public EmboxCommonConversion<fir::cg::XReboxOp> {
18431843
if (!rebox.getSubcomponent().empty())
18441844
getSubcomponentIndices(rebox, rebox.getBox(), operands, fieldIndices);
18451845
if (!rebox.getSubstr().empty())
1846-
substringOffset = operands[rebox.substrOffset()];
1846+
substringOffset = operands[rebox.getSubstrOperandIndex()];
18471847
base = genBoxOffsetGep(rewriter, loc, base, llvmBaseObjectType, zero,
18481848
/*cstInteriorIndices=*/std::nullopt, fieldIndices,
18491849
substringOffset);
@@ -1862,8 +1862,8 @@ struct XReboxOpConversion : public EmboxCommonConversion<fir::cg::XReboxOp> {
18621862
llvm::SmallVector<mlir::Value> slicedStrides;
18631863
mlir::Value one = genConstantIndex(loc, idxTy, rewriter, 1);
18641864
const bool sliceHasOrigins = !rebox.getShift().empty();
1865-
unsigned sliceOps = rebox.sliceOffset();
1866-
unsigned shiftOps = rebox.shiftOffset();
1865+
unsigned sliceOps = rebox.getSliceOperandIndex();
1866+
unsigned shiftOps = rebox.getShiftOperandIndex();
18671867
auto strideOps = inputStrides.begin();
18681868
const unsigned inputRank = inputStrides.size();
18691869
for (unsigned i = 0; i < inputRank;
@@ -1912,9 +1912,10 @@ struct XReboxOpConversion : public EmboxCommonConversion<fir::cg::XReboxOp> {
19121912
mlir::Value base, mlir::ValueRange inputExtents,
19131913
mlir::ValueRange inputStrides, mlir::ValueRange operands,
19141914
mlir::ConversionPatternRewriter &rewriter) const {
1915-
mlir::ValueRange reboxShifts{operands.begin() + rebox.shiftOffset(),
1916-
operands.begin() + rebox.shiftOffset() +
1917-
rebox.getShift().size()};
1915+
mlir::ValueRange reboxShifts{
1916+
operands.begin() + rebox.getShiftOperandIndex(),
1917+
operands.begin() + rebox.getShiftOperandIndex() +
1918+
rebox.getShift().size()};
19181919
if (rebox.getShape().empty()) {
19191920
// Only setting new lower bounds.
19201921
return finalizeRebox(rebox, destBoxTy, dest, base, reboxShifts,
@@ -1934,7 +1935,7 @@ struct XReboxOpConversion : public EmboxCommonConversion<fir::cg::XReboxOp> {
19341935
? genConstantIndex(loc, idxTy, rewriter, 1)
19351936
: inputStrides[0];
19361937
for (unsigned i = 0; i < rebox.getShape().size(); ++i) {
1937-
mlir::Value rawExtent = operands[rebox.shapeOffset() + i];
1938+
mlir::Value rawExtent = operands[rebox.getShapeOperandIndex() + i];
19381939
mlir::Value extent = integerCast(loc, rewriter, idxTy, rawExtent);
19391940
newExtents.emplace_back(extent);
19401941
newStrides.emplace_back(stride);
@@ -2137,10 +2138,10 @@ struct XArrayCoorOpConversion
21372138
assert(coor.getShift().empty() || coor.getShift().size() == rank);
21382139
assert(coor.getSlice().empty() || coor.getSlice().size() == 3 * rank);
21392140
mlir::Type idxTy = lowerTy().indexType();
2140-
unsigned indexOffset = coor.indicesOffset();
2141-
unsigned shapeOffset = coor.shapeOffset();
2142-
unsigned shiftOffset = coor.shiftOffset();
2143-
unsigned sliceOffset = coor.sliceOffset();
2141+
unsigned indexOffset = coor.getIndicesOperandIndex();
2142+
unsigned shapeOffset = coor.getShapeOperandIndex();
2143+
unsigned shiftOffset = coor.getShiftOperandIndex();
2144+
unsigned sliceOffset = coor.getSliceOperandIndex();
21442145
auto sliceOps = coor.getSlice().begin();
21452146
mlir::Value one = genConstantIndex(loc, idxTy, rewriter, 1);
21462147
mlir::Value prevExt = one;
@@ -2238,7 +2239,7 @@ struct XArrayCoorOpConversion
22382239
}
22392240
llvm::SmallVector<mlir::Value> indices = convertSubcomponentIndices(
22402241
loc, elementType,
2241-
operands.slice(coor.subcomponentOffset(),
2242+
operands.slice(coor.getSubcomponentOperandIndex(),
22422243
coor.getSubcomponent().size()));
22432244
args.append(indices.begin(), indices.end());
22442245
rewriter.replaceOpWithNewOp<mlir::LLVM::GEPOp>(coor, llvmPtrTy,
@@ -2262,7 +2263,7 @@ struct XArrayCoorOpConversion
22622263
if (fir::characterWithDynamicLen(eleTy)) {
22632264
assert(coor.getLenParams().size() == 1);
22642265
auto length = integerCast(loc, rewriter, idxTy,
2265-
operands[coor.lenParamsOffset()]);
2266+
operands[coor.getLenParamsOperandIndex()]);
22662267
offset = rewriter.create<mlir::LLVM::MulOp>(loc, idxTy, offset,
22672268
length, nsw);
22682269
} else {
@@ -2275,7 +2276,7 @@ struct XArrayCoorOpConversion
22752276
args.push_back(offset);
22762277
llvm::SmallVector<mlir::Value> indices = convertSubcomponentIndices(
22772278
loc, gepObjectType,
2278-
operands.slice(coor.subcomponentOffset(),
2279+
operands.slice(coor.getSubcomponentOperandIndex(),
22792280
coor.getSubcomponent().size()));
22802281
args.append(indices.begin(), indices.end());
22812282
}

0 commit comments

Comments
 (0)