@@ -27,18 +27,16 @@ namespace fir {
27
27
class CharBoxValue ;
28
28
class ArrayBoxValue ;
29
29
class CharArrayBoxValue ;
30
- class BoxValue ;
31
30
class ProcBoxValue ;
32
31
class MutableBoxValue ;
33
- class IrBoxValue ;
32
+ class BoxValue ;
34
33
35
34
llvm::raw_ostream &operator <<(llvm::raw_ostream &, const CharBoxValue &);
36
35
llvm::raw_ostream &operator <<(llvm::raw_ostream &, const ArrayBoxValue &);
37
36
llvm::raw_ostream &operator <<(llvm::raw_ostream &, const CharArrayBoxValue &);
38
- llvm::raw_ostream &operator <<(llvm::raw_ostream &, const BoxValue &);
39
37
llvm::raw_ostream &operator <<(llvm::raw_ostream &, const ProcBoxValue &);
40
38
llvm::raw_ostream &operator <<(llvm::raw_ostream &, const MutableBoxValue &);
41
- llvm::raw_ostream &operator <<(llvm::raw_ostream &, const IrBoxValue &);
39
+ llvm::raw_ostream &operator <<(llvm::raw_ostream &, const BoxValue &);
42
40
43
41
// ===----------------------------------------------------------------------===//
44
42
//
@@ -184,47 +182,13 @@ class ProcBoxValue : public AbstractBox {
184
182
mlir::Value hostContext;
185
183
};
186
184
187
- // / In the generalized form, a boxed value can have a dynamic size, be an array
188
- // / with dynamic extents and lbounds, and take dynamic type parameters.
189
- class BoxValue : public AbstractBox , public AbstractArrayBox {
190
- public:
191
- BoxValue (mlir::Value addr) : AbstractBox{addr}, AbstractArrayBox{} {}
192
- BoxValue (mlir::Value addr, mlir::Value len)
193
- : AbstractBox{addr}, AbstractArrayBox{}, len{len} {}
194
- BoxValue (mlir::Value addr, llvm::ArrayRef<mlir::Value> extents,
195
- llvm::ArrayRef<mlir::Value> lbounds = {})
196
- : AbstractBox{addr}, AbstractArrayBox{extents, lbounds} {}
197
- BoxValue (mlir::Value addr, mlir::Value len,
198
- llvm::ArrayRef<mlir::Value> params,
199
- llvm::ArrayRef<mlir::Value> extents,
200
- llvm::ArrayRef<mlir::Value> lbounds = {})
201
- : AbstractBox{addr}, AbstractArrayBox{extents, lbounds}, len{len},
202
- params{params.begin (), params.end ()} {}
203
-
204
- BoxValue clone (mlir::Value newBase) const {
205
- return {newBase, len, params, extents, lbounds};
206
- }
207
-
208
- BoxValue cloneElement (mlir::Value newBase) const {
209
- return {newBase, len, params, {}, {}};
210
- }
211
-
212
- mlir::Value getLen () const { return len; }
213
-
214
- llvm::ArrayRef<mlir::Value> getLenTypeParams () const { return params; }
215
-
216
- friend llvm::raw_ostream &operator <<(llvm::raw_ostream &, const BoxValue &);
217
- LLVM_DUMP_METHOD void dump () const { llvm::errs () << *this ; }
218
-
219
- protected:
220
- mlir::Value len; // box is CHARACTER
221
- llvm::SmallVector<mlir::Value, 2 > params; // LENs, box is derived type
222
- };
223
-
224
185
// / Base class for values associated to a fir.box or fir.ref<fir.box>.
225
- class AbstractIrBox : public AbstractBox {
186
+ class AbstractIrBox : public AbstractBox , public AbstractArrayBox {
226
187
public:
227
188
AbstractIrBox (mlir::Value addr) : AbstractBox{addr} {}
189
+ AbstractIrBox (mlir::Value addr, llvm::ArrayRef<mlir::Value> lbounds,
190
+ llvm::ArrayRef<mlir::Value> extents)
191
+ : AbstractBox{addr}, AbstractArrayBox(extents, lbounds) {}
228
192
// / Get the fir.box<type> part of the address type.
229
193
fir::BoxType getBoxTy () const {
230
194
auto type = getAddr ().getType ();
@@ -255,8 +219,7 @@ class AbstractIrBox : public AbstractBox {
255
219
// / Returns the rank of the entity. Beware that zero will be returned for
256
220
// / both scalars and assumed rank.
257
221
unsigned rank () const {
258
- auto seqTy = getBaseTy ().dyn_cast <fir::SequenceType>();
259
- if (seqTy)
222
+ if (auto seqTy = getBaseTy ().dyn_cast <fir::SequenceType>())
260
223
return seqTy.getDimension ();
261
224
return 0 ;
262
225
}
@@ -271,61 +234,52 @@ class AbstractIrBox : public AbstractBox {
271
234
};
272
235
273
236
// / An entity described by a fir.box value that cannot be read into
274
- // / another BoxValue category, either because the fir.box may be an
237
+ // / another ExtendedValue category, either because the fir.box may be an
275
238
// / absent optional and we need to wait until the user is referencing it
276
239
// / to read it, or because it contains important information that cannot
277
240
// / be exposed in FIR (e.g. non contiguous byte stride).
278
241
// / It may also store explicit bounds or length parameters that were specified
279
242
// / for the entity.
280
- class IrBoxValue : public AbstractIrBox {
243
+ class BoxValue : public AbstractIrBox {
281
244
public:
282
- IrBoxValue (mlir::Value addr) : AbstractIrBox{addr} { assert (verify ()); }
283
- IrBoxValue (mlir::Value addr, llvm::ArrayRef<mlir::Value> lbounds,
284
- llvm::ArrayRef<mlir::Value> explicitParams,
285
- llvm::ArrayRef<mlir::Value> explicitExtents = {})
286
- : AbstractIrBox{addr}, lbounds{lbounds.begin (), lbounds.end ()},
287
- explicitParams{explicitParams.begin (), explicitParams.end ()},
288
- explicitExtents{explicitExtents.begin (), explicitExtents.end ()} {
245
+ BoxValue (mlir::Value addr) : AbstractIrBox{addr} { assert (verify ()); }
246
+ BoxValue (mlir::Value addr, llvm::ArrayRef<mlir::Value> lbounds,
247
+ llvm::ArrayRef<mlir::Value> explicitParams,
248
+ llvm::ArrayRef<mlir::Value> explicitExtents = {})
249
+ : AbstractIrBox{addr, lbounds, explicitExtents},
250
+ explicitParams{explicitParams.begin (), explicitParams.end ()} {
289
251
assert (verify ());
290
252
}
291
253
// TODO: check contiguous attribute of addr
292
254
bool isContiguous () const { return false ; }
293
255
294
- friend llvm::raw_ostream &operator <<(llvm::raw_ostream &, const IrBoxValue &);
256
+ friend llvm::raw_ostream &operator <<(llvm::raw_ostream &, const BoxValue &);
295
257
LLVM_DUMP_METHOD void dump () const { llvm::errs () << *this ; }
296
258
297
259
llvm::ArrayRef<mlir::Value> getLBounds () const { return lbounds; }
298
- llvm::ArrayRef<mlir::Value> getExplicitExtents () const {
299
- return explicitExtents;
300
- }
260
+
261
+ // The extents member is not guaranteed to be field for arrays. It is only
262
+ // guaranteed to be field for explicit shape arrays. In general,
263
+ // explicit-shape will not come as descriptors, so this field will be empty in
264
+ // most cases. The exception are derived types with length parameters and
265
+ // polymorphic dummy argument arrays. It may be possible for the explicit
266
+ // extents to conflict with the shape information that is in the box according
267
+ // to 15.5.2.11 sequence association rules.
268
+ llvm::ArrayRef<mlir::Value> getExplicitExtents () const { return extents; }
269
+
301
270
llvm::ArrayRef<mlir::Value> getExplicitParameters () const {
302
271
return explicitParams;
303
272
}
304
273
305
274
protected:
306
275
// Verify constructor invariants.
307
276
bool verify () const ;
308
- // Always field when the IrBoxValue has lower bounds other than one.
309
- llvm::SmallVector<mlir::Value, 4 > lbounds;
310
277
311
- // Only field when the IrBoxValue has explicit length parameters.
278
+ // Only field when the BoxValue has explicit length parameters.
312
279
// Otherwise, the length parameters are in the fir.box.
313
280
llvm::SmallVector<mlir::Value, 2 > explicitParams;
314
-
315
- // Only field with the explicit length parameters
316
- // Otherwise, the extents are in the fir.box.
317
- llvm::SmallVector<mlir::Value, 4 > explicitExtents;
318
- // Note about explicitExtents: In general, explicit-shape will not come as
319
- // descriptors, so this field will be empty in most cases. The exception are
320
- // derived types with length parameters and polymorphic dummy argument arrays.
321
- // It may be possible for the explicit extents to conflict with
322
- // the shape information that is in the box according to 15.5.2.11
323
- // sequence association rules.
324
281
};
325
282
326
- // / Used for triple notation (array slices)
327
- using RangeBoxValue = std::tuple<mlir::Value, mlir::Value, mlir::Value>;
328
-
329
283
// / Set of variables (addresses) holding the allocatable properties. These may
330
284
// / be empty in case it is not deemed safe to duplicate the descriptor
331
285
// / information locally (For instance, a volatile allocatable will always be
@@ -404,6 +358,9 @@ class MutableBoxValue : public AbstractIrBox {
404
358
MutableProperties mutableProperties;
405
359
};
406
360
361
+ // / Used for triple notation (array slices)
362
+ using RangeBoxValue = std::tuple<mlir::Value, mlir::Value, mlir::Value>;
363
+
407
364
class ExtendedValue ;
408
365
409
366
mlir::Value getBase (const ExtendedValue &exv);
@@ -419,9 +376,8 @@ bool isArray(const ExtendedValue &exv);
419
376
// / indices if it is an array entity.
420
377
class ExtendedValue : public details ::matcher<ExtendedValue> {
421
378
public:
422
- using VT =
423
- std::variant<UnboxedValue, CharBoxValue, ArrayBoxValue, CharArrayBoxValue,
424
- BoxValue, ProcBoxValue, IrBoxValue>;
379
+ using VT = std::variant<UnboxedValue, CharBoxValue, ArrayBoxValue,
380
+ CharArrayBoxValue, ProcBoxValue, BoxValue>;
425
381
426
382
ExtendedValue () : box{UnboxedValue{}} {}
427
383
ExtendedValue (const ExtendedValue &) = default ;
0 commit comments