Skip to content

Commit 024c3e4

Browse files
committed
Lowering of basic elemental functions (intrinsic and user-defined).
This handles the lowering of the basic cases. There are several TODOs in the code for other variants. This lowers expressions like the following where a and b are arrays. a = f(b) a = abs(b) These are transformed into loop (nests) where the right-hand side is fully evaluated by applying the function to each element in the array and then the resulting array is copied-out to the left-hand side.
1 parent 97c463d commit 024c3e4

File tree

7 files changed

+463
-90
lines changed

7 files changed

+463
-90
lines changed

flang/include/flang/Lower/CallInterface.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ class CallInterface {
106106
AddressAndLength,
107107
/// Value means passed by value at the mlir level, it is not necessarily
108108
/// implied by Fortran Value attribute.
109-
Value
109+
Value,
110+
/// ValueAttribute means dummy has the the Fortran VALUE attribute.
111+
ValueAttribute
110112
};
111113
/// Different properties of an entity that can be passed/returned.
112114
/// One-to-One mapping with PassEntityBy but for

flang/include/flang/Lower/ConvertExpr.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ createSomeMutableBox(mlir::Location loc, AbstractConverter &converter,
6464

6565
/// Create and return a projection of a subspace of an array value. This is the
6666
/// lhs onto which a newly constructed array value can be merged.
67+
/// This implements copy-in, copy-out semantics. In case that require it,
68+
/// results will be buffered so that the rhs values are preserved and the lhs is
69+
/// updated only after all intermediate computation is concluded.
6770
fir::ArrayLoadOp
6871
createSomeArraySubspace(AbstractConverter &converter,
6972
const evaluate::Expr<evaluate::SomeType> &expr,

flang/include/flang/Lower/FIRBuilder.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,21 @@ class FirOpBuilder : public mlir::OpBuilder {
122122
/// given a name via a front-end `Symbol` or a `StringRef`.
123123
mlir::Value createTemporary(mlir::Location loc, mlir::Type type,
124124
llvm::StringRef name = {},
125-
llvm::ArrayRef<mlir::Value> shape = {});
125+
mlir::ValueRange shape = {},
126+
mlir::ValueRange lenParams = {},
127+
llvm::ArrayRef<mlir::NamedAttribute> attrs = {});
126128

127129
/// Create an unnamed and untracked temporary on the stack.
128130
mlir::Value createTemporary(mlir::Location loc, mlir::Type type,
129-
llvm::ArrayRef<mlir::Value> shape) {
131+
mlir::ValueRange shape) {
130132
return createTemporary(loc, type, llvm::StringRef{}, shape);
131133
}
132134

135+
mlir::Value createTemporary(mlir::Location loc, mlir::Type type,
136+
llvm::ArrayRef<mlir::NamedAttribute> attrs) {
137+
return createTemporary(loc, type, llvm::StringRef{}, {}, {}, attrs);
138+
}
139+
133140
/// Create a global value.
134141
fir::GlobalOp createGlobal(mlir::Location loc, mlir::Type type,
135142
llvm::StringRef name,

flang/lib/Lower/CallInterface.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ class Fortran::lower::CallInterfaceImpl {
544544
using Attrs = Fortran::evaluate::characteristics::DummyDataObject::Attr;
545545

546546
bool isOptional = false;
547+
bool isValueAttr = false;
547548
[[maybe_unused]] auto loc = interface.converter.genLocation();
548549
llvm::SmallVector<mlir::NamedAttribute> attrs;
549550
auto addMLIRAttr = [&](llvm::StringRef attr) {
@@ -559,7 +560,7 @@ class Fortran::lower::CallInterfaceImpl {
559560
if (obj.attrs.test(Attrs::Contiguous))
560561
addMLIRAttr(fir::getContiguousAttrName());
561562
if (obj.attrs.test(Attrs::Value))
562-
TODO(loc, "Value in procedure interface");
563+
isValueAttr = true; // TODO: do we want an mlir::Attribute as well?
563564
if (obj.attrs.test(Attrs::Volatile))
564565
TODO(loc, "Volatile in procedure interface");
565566
if (obj.attrs.test(Attrs::Target))
@@ -609,7 +610,9 @@ class Fortran::lower::CallInterfaceImpl {
609610
auto refType = fir::ReferenceType::get(type);
610611
addFirInput(refType, nextPassedArgPosition(), Property::BaseAddress,
611612
attrs);
612-
addPassedArg(PassEntityBy::BaseAddress, entity, isOptional);
613+
addPassedArg(isValueAttr ? PassEntityBy::ValueAttribute
614+
: PassEntityBy::BaseAddress,
615+
entity, isOptional);
613616
}
614617
}
615618

0 commit comments

Comments
 (0)