Skip to content

Commit 63c8972

Browse files
committed
[MLIR] Add OpenMP dialect with barrier operation
Summary: Barrier is a simple operation that takes no arguments and returns nothing, but implies a side effect (synchronization of all threads) Reviewers: jdoerfert Subscribers: mgorny, guansong, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72400
1 parent 7830c2d commit 63c8972

File tree

9 files changed

+125
-0
lines changed

9 files changed

+125
-0
lines changed

mlir/include/mlir/Dialect/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ add_subdirectory(GPU)
44
add_subdirectory(Linalg)
55
add_subdirectory(LLVMIR)
66
add_subdirectory(LoopOps)
7+
add_subdirectory(OpenMP)
78
add_subdirectory(QuantOps)
89
add_subdirectory(SPIRV)
910
add_subdirectory(StandardOps)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_mlir_dialect(OpenMPOps OpenMPOps)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===- OpenMPDialect.h - MLIR Dialect for OpenMP ----------------*- C++ -*-===//
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+
// This file declares the OpenMP dialect in MLIR.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef MLIR_DIALECT_OPENMP_OPENMPDIALECT_H_
14+
#define MLIR_DIALECT_OPENMP_OPENMPDIALECT_H_
15+
16+
#include "mlir/IR/Dialect.h"
17+
#include "mlir/IR/OpDefinition.h"
18+
19+
namespace mlir {
20+
namespace omp {
21+
22+
#define GET_OP_CLASSES
23+
#include "mlir/Dialect/OpenMP/OpenMPOps.h.inc"
24+
25+
class OpenMPDialect : public Dialect {
26+
public:
27+
explicit OpenMPDialect(MLIRContext *context);
28+
29+
static StringRef getDialectNamespace() { return "omp"; }
30+
};
31+
32+
} // namespace omp
33+
} // namespace mlir
34+
35+
#endif // MLIR_DIALECT_OPENMP_OPENMPDIALECT_H_
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===-- OpenMPOps.td - OpenMP dialect 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+
// This file defines the basic operations for the OpenMP dialect.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
14+
#ifndef OPENMP_OPS
15+
#define OPENMP_OPS
16+
17+
include "mlir/IR/OpBase.td"
18+
19+
def OpenMP_Dialect : Dialect {
20+
let name = "omp";
21+
}
22+
23+
class OpenMP_Op<string mnemonic, list<OpTrait> traits = []> :
24+
Op<OpenMP_Dialect, mnemonic, traits>;
25+
26+
def BarrierOp : OpenMP_Op<"barrier"> {
27+
let summary = "barrier construct";
28+
let description = [{
29+
The barrier construct specifies an explicit barrier at the point at which
30+
the construct appears.
31+
}];
32+
33+
let parser = [{ return success(); }];
34+
let printer = [{ p << getOperationName(); }];
35+
}
36+
37+
#endif // OPENMP_OPS

mlir/lib/Dialect/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ add_subdirectory(GPU)
44
add_subdirectory(Linalg)
55
add_subdirectory(LLVMIR)
66
add_subdirectory(LoopOps)
7+
add_subdirectory(OpenMP)
78
add_subdirectory(QuantOps)
89
add_subdirectory(SDBM)
910
add_subdirectory(SPIRV)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
add_llvm_library(MLIROpenMP
2+
IR/OpenMPDialect.cpp
3+
4+
ADDITIONAL_HEADER_DIRS
5+
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/OpenMP
6+
)
7+
8+
add_dependencies(MLIROpenMP MLIROpenMPOpsIncGen)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===- OpenMPDialect.cpp - MLIR Dialect for OpenMP implementation ---------===//
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+
// This file implements the OpenMP dialect and its operations.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
14+
#include "mlir/IR/OpImplementation.h"
15+
16+
using namespace mlir;
17+
using namespace mlir::omp;
18+
19+
OpenMPDialect::OpenMPDialect(MLIRContext *context)
20+
: Dialect(getDialectNamespace(), context) {
21+
addOperations<
22+
#define GET_OP_LIST
23+
#include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc"
24+
>();
25+
}
26+
27+
namespace mlir {
28+
namespace omp {
29+
#define GET_OP_CLASSES
30+
#include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc"
31+
} // namespace omp
32+
} // namespace mlir
33+
34+
static DialectRegistration<OpenMPDialect> ompDialect;

mlir/test/Dialect/OpenMP/ops.mlir

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: mlir-opt -verify-diagnostics %s | FileCheck %s
2+
3+
func @omp_barrier() -> () {
4+
// CHECK: omp.barrier
5+
omp.barrier
6+
return
7+
}

mlir/tools/mlir-opt/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ set(LIBS
3333
MLIRLLVMIR
3434
MLIRLoopOps
3535
MLIRNVVMIR
36+
MLIROpenMP
3637
MLIROptMain
3738
MLIRParser
3839
MLIRPass

0 commit comments

Comments
 (0)