[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
This commit is contained in:
David Truby 2020-01-29 11:31:25 +00:00
parent 7830c2d44f
commit 63c8972562
9 changed files with 125 additions and 0 deletions

View File

@ -4,6 +4,7 @@ add_subdirectory(GPU)
add_subdirectory(Linalg)
add_subdirectory(LLVMIR)
add_subdirectory(LoopOps)
add_subdirectory(OpenMP)
add_subdirectory(QuantOps)
add_subdirectory(SPIRV)
add_subdirectory(StandardOps)

View File

@ -0,0 +1 @@
add_mlir_dialect(OpenMPOps OpenMPOps)

View File

@ -0,0 +1,35 @@
//===- OpenMPDialect.h - MLIR Dialect for OpenMP ----------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file declares the OpenMP dialect in MLIR.
//
//===----------------------------------------------------------------------===//
#ifndef MLIR_DIALECT_OPENMP_OPENMPDIALECT_H_
#define MLIR_DIALECT_OPENMP_OPENMPDIALECT_H_
#include "mlir/IR/Dialect.h"
#include "mlir/IR/OpDefinition.h"
namespace mlir {
namespace omp {
#define GET_OP_CLASSES
#include "mlir/Dialect/OpenMP/OpenMPOps.h.inc"
class OpenMPDialect : public Dialect {
public:
explicit OpenMPDialect(MLIRContext *context);
static StringRef getDialectNamespace() { return "omp"; }
};
} // namespace omp
} // namespace mlir
#endif // MLIR_DIALECT_OPENMP_OPENMPDIALECT_H_

View File

@ -0,0 +1,37 @@
//===-- OpenMPOps.td - OpenMP dialect operation definitions *- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines the basic operations for the OpenMP dialect.
//
//===----------------------------------------------------------------------===//
#ifndef OPENMP_OPS
#define OPENMP_OPS
include "mlir/IR/OpBase.td"
def OpenMP_Dialect : Dialect {
let name = "omp";
}
class OpenMP_Op<string mnemonic, list<OpTrait> traits = []> :
Op<OpenMP_Dialect, mnemonic, traits>;
def BarrierOp : OpenMP_Op<"barrier"> {
let summary = "barrier construct";
let description = [{
The barrier construct specifies an explicit barrier at the point at which
the construct appears.
}];
let parser = [{ return success(); }];
let printer = [{ p << getOperationName(); }];
}
#endif // OPENMP_OPS

View File

@ -4,6 +4,7 @@ add_subdirectory(GPU)
add_subdirectory(Linalg)
add_subdirectory(LLVMIR)
add_subdirectory(LoopOps)
add_subdirectory(OpenMP)
add_subdirectory(QuantOps)
add_subdirectory(SDBM)
add_subdirectory(SPIRV)

View File

@ -0,0 +1,8 @@
add_llvm_library(MLIROpenMP
IR/OpenMPDialect.cpp
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/OpenMP
)
add_dependencies(MLIROpenMP MLIROpenMPOpsIncGen)

View File

@ -0,0 +1,34 @@
//===- OpenMPDialect.cpp - MLIR Dialect for OpenMP implementation ---------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements the OpenMP dialect and its operations.
//
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
#include "mlir/IR/OpImplementation.h"
using namespace mlir;
using namespace mlir::omp;
OpenMPDialect::OpenMPDialect(MLIRContext *context)
: Dialect(getDialectNamespace(), context) {
addOperations<
#define GET_OP_LIST
#include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc"
>();
}
namespace mlir {
namespace omp {
#define GET_OP_CLASSES
#include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc"
} // namespace omp
} // namespace mlir
static DialectRegistration<OpenMPDialect> ompDialect;

View File

@ -0,0 +1,7 @@
// RUN: mlir-opt -verify-diagnostics %s | FileCheck %s
func @omp_barrier() -> () {
// CHECK: omp.barrier
omp.barrier
return
}

View File

@ -33,6 +33,7 @@ set(LIBS
MLIRLLVMIR
MLIRLoopOps
MLIRNVVMIR
MLIROpenMP
MLIROptMain
MLIRParser
MLIRPass