Skip to content

Commit fdf02a9

Browse files
committed
[flang][PRIF] Adding support of -fcoarray option
Adding support of -fcoarray (and -fcoarray=lib as an alias of -fcoarray). If this option is not passed, then coarray features are disabled and error is returned if a least one feature is present at compile time. Added lowering for `prif_init` and `prif_[error_]stop` to call them in ProgramStart and ProgramEnd.
1 parent 75e70b4 commit fdf02a9

File tree

16 files changed

+146
-98
lines changed

16 files changed

+146
-98
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6860,7 +6860,6 @@ def static_libgfortran : Flag<["-"], "static-libgfortran">, Group<gfortran_Group
68606860
// "f" options with values for gfortran.
68616861
def fblas_matmul_limit_EQ : Joined<["-"], "fblas-matmul-limit=">, Group<gfortran_Group>;
68626862
def fcheck_EQ : Joined<["-"], "fcheck=">, Group<gfortran_Group>;
6863-
def fcoarray_EQ : Joined<["-"], "fcoarray=">, Group<gfortran_Group>;
68646863
def ffpe_trap_EQ : Joined<["-"], "ffpe-trap=">, Group<gfortran_Group>;
68656864
def ffree_line_length_VALUE : Joined<["-"], "ffree-line-length-">, Group<gfortran_Group>;
68666865
def finit_character_EQ : Joined<["-"], "finit-character=">, Group<gfortran_Group>;
@@ -8563,6 +8562,22 @@ def fopenmp_host_ir_file_path : Separate<["-"], "fopenmp-host-ir-file-path">,
85638562

85648563
} // let Visibility = [CC1Option, FC1Option]
85658564

8565+
//===----------------------------------------------------------------------===//
8566+
// Coarray Options
8567+
//===----------------------------------------------------------------------===//
8568+
8569+
let Visibility = [FlangOption, FC1Option] in {
8570+
8571+
def fcoarray : Flag<["-"], "fcoarray">,
8572+
Group<f_Group>,
8573+
HelpText<"Enable Coarray features">;
8574+
def fcoarray_EQ : Joined<["-"], "fcoarray=">,
8575+
Group<f_Group>,
8576+
Values<"lib">,
8577+
Alias<fcoarray>;
8578+
8579+
} // let Visibility = [FlangOption, FC1Option]
8580+
85668581
//===----------------------------------------------------------------------===//
85678582
// SYCL Options
85688583
//===----------------------------------------------------------------------===//

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ void Flang::addCodegenOptions(const ArgList &Args,
178178
options::OPT_fstack_repack_arrays, options::OPT_fno_stack_repack_arrays,
179179
options::OPT_ftime_report, options::OPT_ftime_report_EQ,
180180
options::OPT_funroll_loops, options::OPT_fno_unroll_loops});
181+
if (Args.hasArg(clang::driver::options::OPT_fcoarray))
182+
CmdArgs.push_back("-fcoarray");
183+
if (Args.hasArg(clang::driver::options::OPT_fcoarray))
184+
CmdArgs.push_back("-fcoarray=");
185+
Args.AddLastArg(CmdArgs, options::OPT_fcoarray_EQ);
181186
}
182187

183188
void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {

flang-rt/lib/runtime/coarray.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "flang/Runtime/coarray.h"
10+
#include "flang-rt/runtime/descriptor.h"
1011
#include "flang-rt/runtime/type-info.h"
1112

1213
namespace Fortran::runtime {

flang/include/flang/Lower/Coarray.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ void genEndCriticalStmt(AbstractConverter &, pft::Evaluation &eval,
6363
// COARRAY utils
6464
//===----------------------------------------------------------------------===//
6565

66+
/// Check if CoarrayFeature from LoweringOptions is enabled.
67+
/// Emit an error if not.
68+
void checkCoarrayFeatureEnabled(AbstractConverter &converter,
69+
mlir::Location loc);
70+
6671
// Compute the colower and coupper bounds for a coarray and return an array of
6772
// bounds.
6873
std::pair<mlir::Value, mlir::Value>

flang/include/flang/Lower/LoweringOptions.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,8 @@ ENUM_LOWERINGOPT(RepackArraysWhole, unsigned, 1, 0)
6666
/// If true, CUDA Fortran runtime check is inserted.
6767
ENUM_LOWERINGOPT(CUDARuntimeCheck, unsigned, 1, 0)
6868

69+
/// Enable coarrays feature.
70+
ENUM_LOWERINGOPT(CoarrayFeature, unsigned, 1, 0)
71+
6972
#undef LOWERINGOPT
7073
#undef ENUM_LOWERINGOPT

flang/include/flang/Optimizer/Builder/IntrinsicCall.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,12 @@ struct IntrinsicLibrary {
586586

587587
void setResultMustBeFreed() { resultMustBeFreed = true; }
588588

589+
// Check support of coarray features
590+
void checkCoarrayEnabled() {
591+
if (converter && !converter->getLoweringOptions().getCoarrayFeature())
592+
mlir::emitError(loc, "Coarrays disabled, use '-fcoarray' to enable.");
593+
}
594+
589595
fir::FirOpBuilder &builder;
590596
mlir::Location loc;
591597
bool resultMustBeFreed = false;

flang/include/flang/Optimizer/Builder/Runtime/Coarray.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ void computeLastUcobound(fir::FirOpBuilder &builder, mlir::Location loc,
6262
void copy1DArrayToI64Array(fir::FirOpBuilder &builder, mlir::Location loc,
6363
mlir::Value from, mlir::Value to);
6464

65+
/// Generate Call to runtime prif_init
66+
mlir::Value genInitCoarray(fir::FirOpBuilder &builder, mlir::Location loc);
67+
68+
/// Generate Call to runtime prif_stop
69+
void genStopCoarray(fir::FirOpBuilder &builder, mlir::Location loc,
70+
mlir::Value quiet = {}, mlir::Value stopCodeInt = {},
71+
mlir::Value stopCodeChar = {}, bool isError = false);
72+
6573
/// Generate Call to runtime prif_num_images
6674
mlir::Value getNumImages(fir::FirOpBuilder &builder, mlir::Location loc);
6775

flang/include/flang/Optimizer/Builder/Runtime/Main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace fir::runtime {
2525

2626
void genMain(fir::FirOpBuilder &builder, mlir::Location loc,
2727
const std::vector<Fortran::lower::EnvironmentDefault> &defs,
28-
bool initCuda = false);
28+
bool initCuda = false, bool initCoarrayEnv = false);
2929
}
3030

3131
#endif // FORTRAN_OPTIMIZER_BUILDER_RUNTIME_MAIN_H

flang/include/flang/Runtime/coarray.h

Lines changed: 1 addition & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include "flang/Common/ISO_Fortran_binding_wrapper.h"
1313
#include "flang/Runtime/c-or-cpp.h"
1414
#include "flang/Runtime/entry-names.h"
15-
#include <iostream>
1615
#include <map>
16+
#include <stdio.h>
1717
#include <stdlib.h>
1818
#include <tuple>
1919
#include <vector>
@@ -30,97 +30,6 @@ void RTNAME(Copy1DArrayToI64Array)(
3030
const Descriptor &from, const Descriptor &to);
3131
} // namespace Fortran::runtime
3232

33-
// FIXME: Removing all declaration later
34-
// Unimplemented prif runtime functions
35-
#define DECLARE_UNIMPLEMENTED_PRIF(func_name, ...) \
36-
void _QMprifPprif_##func_name(__VA_ARGS__) { \
37-
std::fprintf(stderr, "unimplemented feature : prif_" #func_name "\n"); \
38-
std::exit(EXIT_FAILURE); \
39-
}
40-
41-
DECLARE_UNIMPLEMENTED_PRIF(init, void *)
42-
DECLARE_UNIMPLEMENTED_PRIF(stop, void *, void *, void *)
43-
DECLARE_UNIMPLEMENTED_PRIF(fail_image, void)
44-
DECLARE_UNIMPLEMENTED_PRIF(this_image_no_coarray, void *, void *)
45-
DECLARE_UNIMPLEMENTED_PRIF(this_image_with_coarray, void *, void *, void *)
46-
DECLARE_UNIMPLEMENTED_PRIF(this_image_with_dim, void *, void *, void *, void *)
47-
DECLARE_UNIMPLEMENTED_PRIF(num_images, void *)
48-
DECLARE_UNIMPLEMENTED_PRIF(num_images_with_team, void *, void *)
49-
DECLARE_UNIMPLEMENTED_PRIF(num_images_with_team_number, void *, void *)
50-
DECLARE_UNIMPLEMENTED_PRIF(image_index, void *, void *, void *)
51-
DECLARE_UNIMPLEMENTED_PRIF(
52-
image_index_with_team, void *, void *, void *, void *)
53-
DECLARE_UNIMPLEMENTED_PRIF(
54-
image_index_with_team_number, void *, void *, void *, void *)
55-
DECLARE_UNIMPLEMENTED_PRIF(image_status, void *, void *, void *)
56-
DECLARE_UNIMPLEMENTED_PRIF(coshape, void *, void *)
57-
DECLARE_UNIMPLEMENTED_PRIF(lcobound_no_dim, void *, void *)
58-
DECLARE_UNIMPLEMENTED_PRIF(lcobound_with_dim, void *, void *, void *)
59-
DECLARE_UNIMPLEMENTED_PRIF(ucobound_no_dim, void *, void *)
60-
DECLARE_UNIMPLEMENTED_PRIF(ucobound_with_dim, void *, void *, void *)
61-
DECLARE_UNIMPLEMENTED_PRIF(allocate_coarray, void *, void *, void *, void *,
62-
void *, void *, void *, void *, void *)
63-
DECLARE_UNIMPLEMENTED_PRIF(deallocate_coarray, void *, void *, void *, void *)
64-
DECLARE_UNIMPLEMENTED_PRIF(sync_memory, void *, void *, void *)
65-
DECLARE_UNIMPLEMENTED_PRIF(sync_all, void *, void *, void *)
66-
DECLARE_UNIMPLEMENTED_PRIF(sync_images, void *, void *, void *, void *)
67-
DECLARE_UNIMPLEMENTED_PRIF(sync_team, void *, void *, void *, void *)
68-
DECLARE_UNIMPLEMENTED_PRIF(
69-
lock, void *, void *, void *, void *, void *, void *, void *)
70-
DECLARE_UNIMPLEMENTED_PRIF(
71-
unlock, void *, void *, void *, void *, void *, void *, void *)
72-
DECLARE_UNIMPLEMENTED_PRIF(
73-
get, void *, void *, void *, void *, void *, void *, void *, void *)
74-
DECLARE_UNIMPLEMENTED_PRIF(get_stridded, void *, void *, void *, void *, void *,
75-
void *, void *, void *)
76-
DECLARE_UNIMPLEMENTED_PRIF(
77-
put, void *, void *, void *, void *, void *, void *, void *, void *)
78-
DECLARE_UNIMPLEMENTED_PRIF(put_stridded, void *, void *, void *, void *, void *,
79-
void *, void *, void *)
80-
DECLARE_UNIMPLEMENTED_PRIF(co_broadcast, void *, void *, void *, void *, void *)
81-
DECLARE_UNIMPLEMENTED_PRIF(co_max, void *, void *, void *, void *, void *)
82-
DECLARE_UNIMPLEMENTED_PRIF(
83-
co_max_character, void *, void *, void *, void *, void *)
84-
DECLARE_UNIMPLEMENTED_PRIF(co_min, void *, void *, void *, void *, void *)
85-
DECLARE_UNIMPLEMENTED_PRIF(
86-
co_min_character, void *, void *, void *, void *, void *)
87-
DECLARE_UNIMPLEMENTED_PRIF(co_sum, void *, void *, void *, void *, void *)
88-
DECLARE_UNIMPLEMENTED_PRIF(atomic_add, void *, void *, void *, void *, void *)
89-
DECLARE_UNIMPLEMENTED_PRIF(atomic_and, void *, void *, void *, void *, void *)
90-
DECLARE_UNIMPLEMENTED_PRIF(atomic_or, void *, void *, void *, void *, void *)
91-
DECLARE_UNIMPLEMENTED_PRIF(atomic_xor, void *, void *, void *, void *, void *)
92-
DECLARE_UNIMPLEMENTED_PRIF(
93-
atomic_fetch_add, void *, void *, void *, void *, void *, void *)
94-
DECLARE_UNIMPLEMENTED_PRIF(
95-
atomic_fetch_and, void *, void *, void *, void *, void *, void *)
96-
DECLARE_UNIMPLEMENTED_PRIF(
97-
atomic_fetch_or, void *, void *, void *, void *, void *, void *)
98-
DECLARE_UNIMPLEMENTED_PRIF(
99-
atomic_fetch_xor, void *, void *, void *, void *, void *, void *)
100-
DECLARE_UNIMPLEMENTED_PRIF(
101-
atomic_cas_int, void *, void *, void *, void *, void *, void *, void *)
102-
DECLARE_UNIMPLEMENTED_PRIF(
103-
atomic_cas_logical, void *, void *, void *, void *, void *, void *, void *)
104-
DECLARE_UNIMPLEMENTED_PRIF(
105-
atomic_define_int, void *, void *, void *, void *, void *)
106-
DECLARE_UNIMPLEMENTED_PRIF(
107-
atomic_define_logical, void *, void *, void *, void *, void *)
108-
DECLARE_UNIMPLEMENTED_PRIF(
109-
atomic_ref_int, void *, void *, void *, void *, void *)
110-
DECLARE_UNIMPLEMENTED_PRIF(
111-
atomic_ref_logical, void *, void *, void *, void *, void *)
112-
DECLARE_UNIMPLEMENTED_PRIF(
113-
form_team, void *, void *, void *, void *, void *, void *)
114-
DECLARE_UNIMPLEMENTED_PRIF(get_team, void *, void *)
115-
DECLARE_UNIMPLEMENTED_PRIF(team_number, void *, void *)
116-
DECLARE_UNIMPLEMENTED_PRIF(change_team, void *, void *, void *, void *)
117-
DECLARE_UNIMPLEMENTED_PRIF(end_team, void *, void *, void *)
118-
DECLARE_UNIMPLEMENTED_PRIF(
119-
event_post, void *, void *, void *, void *, void *, void *)
120-
DECLARE_UNIMPLEMENTED_PRIF(event_query, void *, void *, void *)
121-
DECLARE_UNIMPLEMENTED_PRIF(event_wait, void *, void *, void *, void *, void *)
122-
DECLARE_UNIMPLEMENTED_PRIF(notify_wait, void *, void *, void *, void *, void *)
123-
12433
FORTRAN_EXTERN_C_END
12534

12635
#endif // FORTRAN_RUNTIME_PRIF_H_

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,10 @@ static bool parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
11201120
diags.Report(diagID);
11211121
}
11221122
}
1123+
// -fcoarray
1124+
if (args.hasArg(clang::driver::options::OPT_fcoarray))
1125+
res.getLoweringOpts().setCoarrayFeature(1);
1126+
11231127
return diags.getNumErrors() == numErrorsBefore;
11241128
}
11251129

0 commit comments

Comments
 (0)