Skip to content

Commit 488b475

Browse files
committed
Fix tests. Fix regressions. Remove system dependent checks.
Remove array_update referential support. Thread substring info down the traversal so it can be used as a tail production. Add rebox implementation. Use rebox on boxes as needed. Move substring handling to where we normally create SliceOps.
1 parent 6657995 commit 488b475

27 files changed

+1577
-1319
lines changed

flang/include/flang/Optimizer/Builder/Character.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ class CharacterExprHelper {
107107
/// Extract the kind of a character or array of character type.
108108
static fir::KindTy getCharacterOrSequenceKind(mlir::Type type);
109109

110+
// TODO: Do we really need all these flavors of unwrapping to get the fir.char
111+
// type? Or can we merge these? It would be better to merge them and eliminate
112+
// the confusion.
113+
110114
/// Determine the inner character type. Unwraps references, boxes, and
111115
/// sequences to find the !fir.char element type.
112116
static fir::CharacterType getCharType(mlir::Type type);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,19 @@ void genRecordAssignment(fir::FirOpBuilder &builder, mlir::Location loc,
465465
const fir::ExtendedValue &lhs,
466466
const fir::ExtendedValue &rhs);
467467

468+
/// Builds and returns the type of a ragged array header used to cache mask
469+
/// evaluations.
468470
mlir::TupleType getRaggedArrayHeaderType(fir::FirOpBuilder &builder);
469471

472+
/// Generate the, possibly dynamic, LEN of a CHARACTER. \p arrLoad determines
473+
/// the base array. After applying \p path, the result must be a reference to a
474+
/// `!fir.char` type object. \p substring must have 0, 1, or 2 members. The
475+
/// first member is the starting offset. The second is the ending offset.
476+
mlir::Value genLenOfCharacter(fir::FirOpBuilder &builder, mlir::Location loc,
477+
fir::ArrayLoadOp arrLoad,
478+
llvm::ArrayRef<mlir::Value> path,
479+
llvm::ArrayRef<mlir::Value> substring);
480+
470481
} // namespace fir::factory
471482

472483
#endif // FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H

flang/include/flang/Optimizer/Transforms/Factory.h renamed to flang/include/flang/Optimizer/Builder/Factory.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- Optimizer/Transforms/Factory.h --------------------------*- C++ -*-===//
1+
//===-- Optimizer/Builder/Factory.h -----------------------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -12,8 +12,8 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#ifndef FORTRAN_OPTIMIZER_TRANSFORMS_FACTORY_H
16-
#define FORTRAN_OPTIMIZER_TRANSFORMS_FACTORY_H
15+
#ifndef FORTRAN_OPTIMIZER_BUILDER_FACTORY_H
16+
#define FORTRAN_OPTIMIZER_BUILDER_FACTORY_H
1717

1818
#include "flang/Optimizer/Dialect/FIROps.h"
1919
#include "flang/Optimizer/Dialect/FIRType.h"
@@ -253,4 +253,4 @@ llvm::SmallVector<fir::DoLoopOp> createLoopNest(
253253

254254
} // namespace fir::factory
255255

256-
#endif // FORTRAN_OPTIMIZER_TRANSFORMS_FACTORY_H
256+
#endif // FORTRAN_OPTIMIZER_BUILDER_FACTORY_H

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def fircg_XEmboxOp : fircg_Op<"ext_embox", [AttrSizedOperandSegments]> {
4242
The default is a vector of the value 1.
4343
- slice: A vector of triples that describe an array slice.
4444
- subcomponent: A vector of indices for subobject slicing.
45+
- substring: A substring operator (offset, length) for CHARACTER.
4546
- LEN type parameters: A vector of runtime LEN type parameters that
4647
describe an correspond to the elemental derived type.
4748

@@ -99,6 +100,7 @@ def fircg_XReboxOp : fircg_Op<"ext_rebox", [AttrSizedOperandSegments]> {
99100
The default is a vector of the value 1.
100101
- slice: A vector of triples that describe an array slice.
101102
- subcomponent: A vector of indices for subobject slicing.
103+
- substring: A substring operator (offset, length) for CHARACTER.
102104

103105
The box argument is mandatory, the other arguments are optional.
104106
There must not both be a shape and slice/subcomponent arguments
@@ -109,14 +111,15 @@ def fircg_XReboxOp : fircg_Op<"ext_rebox", [AttrSizedOperandSegments]> {
109111
Variadic<AnyIntegerType>:$shape,
110112
Variadic<AnyIntegerType>:$shift,
111113
Variadic<AnyIntegerType>:$slice,
112-
Variadic<AnyCoordinateType>:$subcomponent
114+
Variadic<AnyCoordinateType>:$subcomponent,
115+
Variadic<AnyIntegerType>:$substr
113116
);
114117
let results = (outs fir_BoxType);
115118

116119
let assemblyFormat = [{
117120
$box (`(`$shape^`)`)? (`origin` $shift^)? (`[`$slice^`]`)?
118-
(`path` $subcomponent^) ? attr-dict
119-
`:` functional-type(operands, results)
121+
(`path` $subcomponent^)? (`substr` $substr^)? attr-dict `:`
122+
functional-type(operands, results)
120123
}];
121124

122125
let extraClassDeclaration = [{
@@ -129,6 +132,9 @@ def fircg_XReboxOp : fircg_Op<"ext_rebox", [AttrSizedOperandSegments]> {
129132
unsigned shiftOffset() { return shapeOffset() + shape().size(); }
130133
unsigned sliceOffset() { return shiftOffset() + shift().size(); }
131134
unsigned subcomponentOffset() { return sliceOffset() + slice().size(); }
135+
unsigned substrOffset() {
136+
return subcomponentOffset() + subcomponent().size();
137+
}
132138
}];
133139
}
134140

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1974,7 +1974,7 @@ def fir_SliceOp : fir_Op<"slice", [NoSideEffect, AttrSizedOperandSegments]> {
19741974
substrings.
19751975

19761976
```mlir
1977-
%d = fir.slice %lo, %hi, %step substr %from, %to : (index, index, index, index, index) -> !fir.slice<1>
1977+
%d = fir.slice %lo, %hi, %step substr %offset, %width : (index, index, index, index, index) -> !fir.slice<1>
19781978
```
19791979
}];
19801980

flang/include/flang/Optimizer/Dialect/FIROpsSupport.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,33 @@
1515

1616
namespace fir {
1717

18-
/// return true iff the Operation is a non-volatile LoadOp
18+
/// Return true iff the Operation is a non-volatile LoadOp or ArrayLoadOp.
1919
inline bool nonVolatileLoad(mlir::Operation *op) {
2020
if (auto load = dyn_cast<fir::LoadOp>(op))
2121
return !load->getAttr("volatile");
22+
if (auto arrLoad = dyn_cast<fir::ArrayLoadOp>(op))
23+
return !arrLoad->getAttr("volatile");
2224
return false;
2325
}
2426

25-
/// return true iff the Operation is a call
27+
/// Return true iff the Operation is a call.
2628
inline bool isaCall(mlir::Operation *op) {
2729
return isa<fir::CallOp>(op) || isa<fir::DispatchOp>(op) ||
2830
isa<mlir::CallOp>(op) || isa<mlir::CallIndirectOp>(op);
2931
}
3032

31-
/// return true iff the Operation is a fir::CallOp, fir::DispatchOp,
33+
/// Return true iff the Operation is a fir::CallOp, fir::DispatchOp,
3234
/// mlir::CallOp, or mlir::CallIndirectOp and not pure
33-
/// NB: this is not the same as `!pureCall(op)`
35+
/// NB: This is not the same as `!pureCall(op)`.
3436
inline bool impureCall(mlir::Operation *op) {
3537
// Should we also auto-detect that the called function is pure if its
3638
// arguments are not references? For now, rely on a "pure" attribute.
3739
return op && isaCall(op) && !op->getAttr("pure");
3840
}
3941

40-
/// return true iff the Operation is a fir::CallOp, fir::DispatchOp,
42+
/// Return true iff the Operation is a fir::CallOp, fir::DispatchOp,
4143
/// mlir::CallOp, or mlir::CallIndirectOp and is also pure.
42-
/// NB: this is not the same as `!impureCall(op)`
44+
/// NB: This is not the same as `!impureCall(op)`.
4345
inline bool pureCall(mlir::Operation *op) {
4446
// Should we also auto-detect that the called function is pure if its
4547
// arguments are not references? For now, rely on a "pure" attribute.

0 commit comments

Comments
 (0)