Skip to content

Commit bda0bd4

Browse files
committed
[DRAFT][PRIF] Dialect PRIF operations
1 parent cbbf562 commit bda0bd4

File tree

2 files changed

+185
-0
lines changed

2 files changed

+185
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===-- PRIFDialect.td - PRIF dialect base definitions -----*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
///
9+
/// \file
10+
/// Definition of the PRIF (Parallel Runtime Interface for Fortran) dialect
11+
///
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef FORTRAN_DIALECT_PRIF_PRIFDIALECT
15+
#define FORTRAN_DIALECT_PRIF_PRIFDIALECT
16+
17+
include "mlir/IR/AttrTypeBase.td"
18+
include "mlir/IR/EnumAttr.td"
19+
include "mlir/IR/OpBase.td"
20+
21+
def PRIFDialect : Dialect {
22+
let name = "prif";
23+
24+
let summary = "PRIF (Parallel Runtime Interface for Fortran) dialect";
25+
26+
let description = [{
27+
The "prif" dialect is designed to contain the basic coarray operations
28+
in Fortran as descibed in the PRIF specificatin.
29+
This includes synchronization operations, atomic operations,
30+
image queries, teams, criticals, etc. The PRIF dialect operations use
31+
the FIR types and are tightly coupled with FIR and HLFIR.
32+
}];
33+
34+
let usePropertiesForAttributes = 1;
35+
let cppNamespace = "::prif";
36+
let dependentDialects = ["fir::FIROpsDialect"];
37+
}
38+
39+
#endif // FORTRAN_DIALECT_PRIF_PRIFDIALECT
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
//===-- PRIFOps.td - PRIF operation definitions ------------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
///
9+
/// \file
10+
/// Definition of the PRIF dialect operations
11+
///
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef FORTRAN_DIALECT_PRIF_PRIF_OPS
15+
#define FORTRAN_DIALECT_PRIF_PRIF_OPS
16+
17+
include "flang/Optimizer/Dialect/PRIF/PRIFDialect.td"
18+
include "flang/Optimizer/Dialect/FIRTypes.td"
19+
include "flang/Optimizer/Dialect/FIRAttr.td"
20+
include "mlir/Dialect/LLVMIR/LLVMAttrDefs.td"
21+
include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
22+
include "mlir/Interfaces/LoopLikeInterface.td"
23+
include "mlir/IR/BuiltinAttributes.td"
24+
25+
class prif_Op<string mnemonic, list<Trait> traits>
26+
: Op<PRIFDialect, mnemonic, traits>;
27+
28+
//===----------------------------------------------------------------------===//
29+
// Initialization and Finalization
30+
//===----------------------------------------------------------------------===//
31+
32+
def prif_InitOp : prif_Op<"init", []> {
33+
let summary = "Initialize the parallel environment";
34+
let description = [{This procedure will initialize the parallel environment}];
35+
36+
let arguments = (ins I32:$stat);
37+
}
38+
39+
def prif_StopOp : prif_Op<"stop", [AttrSizedOperandSegments]> {
40+
let summary = "Procedure that synchronizes all execution images, clean up the"
41+
"parallel runtime environment, and terminates the program.";
42+
let description = [{
43+
This procedure synchronizes all executing images, cleans up the parallel
44+
runtime environment, and terminates the program. Calls to this procedure do
45+
not return. This procedure supports both normal termination at the end of a
46+
program, as well as any STOP statements from the user source code.
47+
}];
48+
49+
let arguments = (ins AnyReferenceLike:$quiet,
50+
Optional<AnyReferenceLike>:$stop_code_int,
51+
Optional<AnyRefOrBoxType>:$stop_code_char);
52+
53+
let hasVerifier = 1;
54+
}
55+
56+
def prif_ErrorStopOp : prif_Op<"error_stop", [AttrSizedOperandSegments]> {
57+
let summary = "This procedure terminates all executing images."
58+
"Calls to this procedure do not return";
59+
let description = [{
60+
This procedure terminates all executing images and calls to this procedure
61+
do not return.
62+
}];
63+
64+
let arguments = (ins AnyReferenceLike:$quiet,
65+
Optional<AnyReferenceLike>:$stop_code_int,
66+
Optional<AnyRefOrBoxType>:$stop_code_char);
67+
68+
let hasVerifier = 1;
69+
}
70+
71+
//===----------------------------------------------------------------------===//
72+
// Image Queries
73+
//===----------------------------------------------------------------------===//
74+
75+
def prif_NumImagesOp : prif_Op<"num_images", [AttrSizedOperandSegments]> {
76+
let summary = "Query the number of images in the specified or current team";
77+
78+
let arguments = (ins Optional<AnyRefOrBoxType>:$team_number,
79+
Optional<AnyReferenceLike>:$team);
80+
let results = (outs I32);
81+
82+
let skipDefaultBuilders = 1;
83+
let builders = [
84+
OpBuilder<(ins CArg<"mlir::Value", "{}">:$team_number,
85+
CArg<"mlir::Value", "{}">:$team),
86+
[{ return build($_builder, $_state, team_number, team); }]>
87+
];
88+
89+
let hasVerifier = 1;
90+
}
91+
92+
def prif_ThisImageOp : prif_Op<"this_image", []> {
93+
let summary = "Determine the image index of the current image";
94+
95+
let arguments = (ins Optional<AnyRefOrBoxType>:$team);
96+
let results = (outs I32);
97+
}
98+
99+
//===----------------------------------------------------------------------===//
100+
// Coarray Queries
101+
//===----------------------------------------------------------------------===//
102+
103+
//===----------------------------------------------------------------------===//
104+
// Allocation and Deallocation
105+
//===----------------------------------------------------------------------===//
106+
107+
def prif_AllocateCoarrayOp : prif_Op<"allocate_coarray",
108+
[MemoryEffects<[MemAlloc<DefaultResource>]>]> {
109+
let summary = "Perform the allocation of a coarray and provide a "
110+
"corresponding coarray descriptor";
111+
112+
let description = [{
113+
This procedure allocates a coarray and provides a handle referencing a
114+
corresponding coarray descriptor. This call is collective over the
115+
current team.
116+
}];
117+
118+
let arguments = (ins Arg<AnyRefOrBoxType, "", [MemRead]>:$lcobounds,
119+
Arg<AnyRefOrBoxType, "", [MemRead]>:$ucobound,
120+
Arg<AnyReferenceLike, "", [MemRead]>:$size_in_bytes,
121+
Arg<FunctionType, "", [MemRead]>:$final_func,
122+
Arg<AnyRefOrBoxType, "", [MemWrite]>:$coarray_handle,
123+
Arg<AnyRefOrBoxType, "", [MemWrite]>:$allocated_memory,
124+
Arg<Optional<AnyRefOrBoxType>, "", [MemWrite]>:$errmsg);
125+
126+
let results = (outs I32:$stat);
127+
128+
let hasVerifier = 1;
129+
}
130+
131+
//===----------------------------------------------------------------------===//
132+
// Synchronization
133+
//===----------------------------------------------------------------------===//
134+
135+
def prif_SyncAllOp : prif_Op<"sync_all", [AttrSizedOperandSegments]> {
136+
let summary =
137+
"Performs a collective synchronization of all images in the current team";
138+
139+
let arguments = (ins Optional<AnyRefOrBoxType>:$errmsg);
140+
141+
let results = (outs I32:$stat);
142+
143+
let hasVerifier = 1;
144+
}
145+
146+
#endif // FORTRAN_DIALECT_PRIF_PRIF_OPS

0 commit comments

Comments
 (0)