Skip to content

Commit 671c235

Browse files
authored
Merge pull request #687 from flang-compiler/ch-elefun
Lowering of basic elemental functions (intrinsic and user-defined).
2 parents 6a9f909 + 3d1e8e8 commit 671c235

File tree

7 files changed

+449
-82
lines changed

7 files changed

+449
-82
lines changed

flang/include/flang/Lower/CallInterface.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ 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+
BaseAddressValueAttribute,
112+
CharBoxValueAttribute // BoxChar with VALUE
110113
};
111114
/// Different properties of an entity that can be passed/returned.
112115
/// 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: 8 additions & 3 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))
@@ -603,13 +604,17 @@ class Fortran::lower::CallInterfaceImpl {
603604
// Pass as fir.box_char
604605
auto boxCharTy = fir::BoxCharType::get(&mlirContext, dynamicType.kind());
605606
addFirInput(boxCharTy, nextPassedArgPosition(), Property::BoxChar, attrs);
606-
addPassedArg(PassEntityBy::BoxChar, entity, isOptional);
607+
addPassedArg(isValueAttr ? PassEntityBy::CharBoxValueAttribute
608+
: PassEntityBy::BoxChar,
609+
entity, isOptional);
607610
} else {
608611
// Pass as fir.ref
609612
auto refType = fir::ReferenceType::get(type);
610613
addFirInput(refType, nextPassedArgPosition(), Property::BaseAddress,
611614
attrs);
612-
addPassedArg(PassEntityBy::BaseAddress, entity, isOptional);
615+
addPassedArg(isValueAttr ? PassEntityBy::BaseAddressValueAttribute
616+
: PassEntityBy::BaseAddress,
617+
entity, isOptional);
613618
}
614619
}
615620

0 commit comments

Comments
 (0)