aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Lower/ConvertProcedureDesignator.cpp
diff options
context:
space:
mode:
authorDaniel Chen <cdchen@ca.ibm.com>2023-11-22 11:51:12 -0500
committerJean Perier <jperier@nvidia.com>2023-11-23 13:43:35 +0100
commitaf09219edd87db860d1fc5a33dd49ecd31291699 (patch)
treef9b32640bb0b185429967270f1ff93c92a51f885 /flang/lib/Lower/ConvertProcedureDesignator.cpp
parentfd9a777e018d23d258646af613179eebf6df4b34 (diff)
downloadllvm-af09219edd87db860d1fc5a33dd49ecd31291699.zip
llvm-af09219edd87db860d1fc5a33dd49ecd31291699.tar.gz
llvm-af09219edd87db860d1fc5a33dd49ecd31291699.tar.bz2
[Flang] Add partial support for lowering procedure pointer assignment. (#70461)
**Scope of the PR:** 1. Lowering global and local procedure pointer declaration statement with explicit or implicit interface. The explicit interface can be from an interface block, a module procedure or an internal procedure. 2. Lowering procedure pointer assignment, where the target procedure could be external, module or internal procedures. 3. Lowering reference to procedure pointers so that it works end to end. **PR notes:** 1. The first commit of the PR does not include testing. I would like to collect some comments first, which may alter the output. Once I confirm the implementation, I will add some testing as a follow up commit to this PR. 2. No special handling of the host-associated entities when an internal procedure is the target of a procedure pointer assignment in this PR. **Implementation notes:** 1. The implementation is using the HLFIR path. 2. Flang currently uses `getUntypedBoxProcType` to get the `fir::BoxProcType` for `ProcedureDesignator` when getting the address of a procedure in order to pass it as an actual argument. This PR inherits the same design decision for procedure pointer as the `fir::StoreOp` requires the same memory type. Note: this commit is actually resubmitting the original commit from PR #70461 that was reverted. See PR #73221.
Diffstat (limited to 'flang/lib/Lower/ConvertProcedureDesignator.cpp')
-rw-r--r--flang/lib/Lower/ConvertProcedureDesignator.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/flang/lib/Lower/ConvertProcedureDesignator.cpp b/flang/lib/Lower/ConvertProcedureDesignator.cpp
index 20ade1a..84e04b0 100644
--- a/flang/lib/Lower/ConvertProcedureDesignator.cpp
+++ b/flang/lib/Lower/ConvertProcedureDesignator.cpp
@@ -11,11 +11,13 @@
#include "flang/Lower/AbstractConverter.h"
#include "flang/Lower/CallInterface.h"
#include "flang/Lower/ConvertCall.h"
+#include "flang/Lower/ConvertExprToHLFIR.h"
#include "flang/Lower/ConvertVariable.h"
#include "flang/Lower/Support/Utils.h"
#include "flang/Lower/SymbolMap.h"
#include "flang/Optimizer/Builder/Character.h"
#include "flang/Optimizer/Builder/IntrinsicCall.h"
+#include "flang/Optimizer/Builder/Todo.h"
#include "flang/Optimizer/Dialect/FIROps.h"
static bool areAllSymbolsInExprMapped(const Fortran::evaluate::ExtentExpr &expr,
@@ -98,6 +100,15 @@ hlfir::EntityWithAttributes Fortran::lower::convertProcedureDesignatorToHLFIR(
mlir::Location loc, Fortran::lower::AbstractConverter &converter,
const Fortran::evaluate::ProcedureDesignator &proc,
Fortran::lower::SymMap &symMap, Fortran::lower::StatementContext &stmtCtx) {
+ const auto *sym = proc.GetSymbol();
+ if (sym) {
+ if (sym->GetUltimate().attrs().test(Fortran::semantics::Attr::INTRINSIC))
+ TODO(loc, "Procedure pointer with intrinsic target.");
+ if (std::optional<fir::FortranVariableOpInterface> varDef =
+ symMap.lookupVariableDefinition(*sym))
+ return *varDef;
+ }
+
fir::ExtendedValue procExv =
convertProcedureDesignator(loc, converter, proc, symMap, stmtCtx);
// Directly package the procedure address as a fir.boxproc or
@@ -125,3 +136,15 @@ hlfir::EntityWithAttributes Fortran::lower::convertProcedureDesignatorToHLFIR(
[funcAddr](const auto &) { return funcAddr; });
return hlfir::EntityWithAttributes{res};
}
+
+mlir::Value Fortran::lower::convertProcedureDesignatorInitialTarget(
+ Fortran::lower::AbstractConverter &converter, mlir::Location loc,
+ const Fortran::semantics::Symbol &sym) {
+ Fortran::lower::SymMap globalOpSymMap;
+ Fortran::lower::StatementContext stmtCtx;
+ Fortran::evaluate::ProcedureDesignator proc(sym);
+ auto procVal{Fortran::lower::convertProcedureDesignatorToHLFIR(
+ loc, converter, proc, globalOpSymMap, stmtCtx)};
+ return fir::getBase(Fortran::lower::convertToAddress(
+ loc, converter, procVal, stmtCtx, procVal.getType()));
+}