Skip to content

[flang][DRAFT] Copy-in/Copy-out determination #151408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions flang/include/flang/Evaluate/call.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ using SymbolRef = common::Reference<const Symbol>;

class ActualArgument {
public:
ENUM_CLASS(Attr, PassedObject, PercentVal, PercentRef);
ENUM_CLASS(Attr, PassedObject, PercentVal, PercentRef, CopyIn, CopyOut);
using Attrs = common::EnumSet<Attr, Attr_enumSize>;

// Dummy arguments that are TYPE(*) can be forwarded as actual arguments.
Expand Down Expand Up @@ -131,7 +131,6 @@ class ActualArgument {
return *this;
}

bool Matches(const characteristics::DummyArgument &) const;
common::Intent dummyIntent() const { return dummyIntent_; }
ActualArgument &set_dummyIntent(common::Intent intent) {
dummyIntent_ = intent;
Expand Down Expand Up @@ -161,6 +160,20 @@ class ActualArgument {
return *this;
}

// This actual argument may need copy-in before the procedure call
bool mayNeedCopyIn() const { return attrs_.test(Attr::CopyIn); };
ActualArgument &set_mayNeedCopyIn() {
attrs_ = attrs_ + Attr::CopyIn;
return *this;
}

// This actual argument may need copy-out after the procedure call
bool mayNeedCopyOut() const { return attrs_.test(Attr::CopyOut); };
ActualArgument &set_mayNeedCopyOut() {
attrs_ = attrs_ + Attr::CopyOut;
return *this;
}

private:
// Subtlety: There is a distinction that must be maintained here between an
// actual argument expression that is a variable and one that is not,
Expand Down Expand Up @@ -235,7 +248,11 @@ class ProcedureRef {
ProcedureRef(ProcedureDesignator &&p, ActualArguments &&a,
bool hasAlternateReturns = false)
: proc_{std::move(p)}, arguments_{std::move(a)},
hasAlternateReturns_{hasAlternateReturns} {}
hasAlternateReturns_{hasAlternateReturns} {
// Gathers necessary information to determine the need for copy-in and
// copy-out
DetermineCopyInOut();
}
~ProcedureRef();
static void Deleter(ProcedureRef *);

Expand Down Expand Up @@ -273,6 +290,8 @@ class ProcedureRef {
llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;

protected:
void DetermineCopyInOut();

ProcedureDesignator proc_;
ActualArguments arguments_;
Chevrons chevrons_;
Expand Down
16 changes: 16 additions & 0 deletions flang/lib/Evaluate/call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "flang/Evaluate/check-expression.h"
#include "flang/Evaluate/expression.h"
#include "flang/Evaluate/tools.h"
#include "flang/Semantics/semantics.h"
#include "flang/Semantics/symbol.h"
#include "flang/Support/Fortran.h"

Expand Down Expand Up @@ -247,4 +248,19 @@ ProcedureRef::~ProcedureRef() {}

void ProcedureRef::Deleter(ProcedureRef *p) { delete p; }

void ProcedureRef::DetermineCopyInOut() {
if (!proc().GetSymbol()) {
return;
}
// Get folding context of the call site owner
FoldingContext &fc{proc_.GetSymbol()->owner().context().foldingContext()};
auto procInfo{characteristics::Procedure::Characterize(
proc_, fc, /*emitError=*/true)};
if (!procInfo) {
return;
}
// TODO: at this point have dummy arguments as procInfo->dummyArguments
// and have actual arguments via arguments_
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here go through the actual args and dummy args and determine copy-in and copy-out needs.


} // namespace Fortran::evaluate
Loading