Skip to content

Commit

Permalink
[CIR][OpenMP] improve runtime skeleton and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eZWALT committed May 1, 2024
1 parent 4905880 commit 0e0d466
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 22 deletions.
22 changes: 20 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenOpenMPRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ void CIRGenOpenMPRuntime::emitTaskWaitCall(CIRGenBuilderTy &builder,
CIRGenFunction &CGF,
mlir::Location Loc,
const OMPTaskDataTy &Data) {

if (!CGF.HaveInsertPoint())
return;

if (CGF.CGM.getLangOpts().OpenMPIRBuilder && Data.Dependences.empty()) {
// TODO: Need to support taskwait with dependences in the OpenMPIRBuilder.
// TODO(cir): This could change in the near future when OpenMP 5.0 gets
Expand All @@ -65,24 +69,38 @@ void CIRGenOpenMPRuntime::emitTaskWaitCall(CIRGenBuilderTy &builder,
} else {
llvm_unreachable("NYI");
}
assert(!UnimplementedFeature::openMPRegionInfo());
}

void CIRGenOpenMPRuntime::emitBarrierCall(CIRGenBuilderTy &builder,
CIRGenFunction &CGF,
mlir::Location Loc) {

assert(!UnimplementedFeature::openMPRegionInfo());

if (CGF.CGM.getLangOpts().OpenMPIRBuilder) {
builder.create<mlir::omp::BarrierOp>(Loc);
} else {
llvm_unreachable("NYI");
return;
}

if (!CGF.HaveInsertPoint())
return;

llvm_unreachable("NYI");
}

void CIRGenOpenMPRuntime::emitTaskyieldCall(CIRGenBuilderTy &builder,
CIRGenFunction &CGF,
mlir::Location Loc) {

if (!CGF.HaveInsertPoint())
return;

if (CGF.CGM.getLangOpts().OpenMPIRBuilder) {
builder.create<mlir::omp::TaskyieldOp>(Loc);
} else {
llvm_unreachable("NYI");
}

assert(!UnimplementedFeature::openMPRegionInfo());
}
15 changes: 7 additions & 8 deletions clang/lib/CIR/CodeGen/CIRGenOpenMPRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "mlir/IR/Dialect.h"
#include "mlir/IR/Location.h"

#include "UnimplementedFeatureGuarding.h"

namespace clang {
class Decl;
class Expr;
Expand Down Expand Up @@ -94,17 +96,14 @@ class CIRGenOpenMPRuntime {
virtual bool emitTargetGlobal(clang::GlobalDecl &D);

/// Emit code for 'taskwait' directive
virtual void emitTaskWaitCall(CIRGenBuilderTy& builder,
CIRGenFunction &CGF,
mlir::Location Loc,
const OMPTaskDataTy &Data
);
virtual void emitTaskWaitCall(CIRGenBuilderTy &builder, CIRGenFunction &CGF,
mlir::Location Loc, const OMPTaskDataTy &Data);

virtual void emitBarrierCall(CIRGenBuilderTy& builder, CIRGenFunction &CGF,
virtual void emitBarrierCall(CIRGenBuilderTy &builder, CIRGenFunction &CGF,
mlir::Location Loc);

virtual void emitTaskyieldCall(CIRGenBuilderTy& builder, CIRGenFunction &CGF,
mlir::Location Loc);
virtual void emitTaskyieldCall(CIRGenBuilderTy &builder, CIRGenFunction &CGF,
mlir::Location Loc);

protected:
CIRGenModule &CGM;
Expand Down
15 changes: 6 additions & 9 deletions clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,27 @@ CIRGenFunction::buildOMPParallelDirective(const OMPParallelDirective &S) {
mlir::LogicalResult
CIRGenFunction::buildOMPTaskwaitDirective(const OMPTaskwaitDirective &S) {
mlir::LogicalResult res = mlir::success();
// Getting the source location information of AST node S scope
auto scopeLoc = getLoc(S.getSourceRange());
OMPTaskDataTy Data;
buildDependences(S, Data);
Data.HasNowaitClause = S.hasClausesOfKind<OMPNowaitClause>();
CGM.getOpenMPRuntime().emitTaskWaitCall(builder, *this, scopeLoc, Data);
CGM.getOpenMPRuntime().emitTaskWaitCall(builder, *this,
getLoc(S.getSourceRange()), Data);
return res;
}
mlir::LogicalResult
CIRGenFunction::buildOMPTaskyieldDirective(const OMPTaskyieldDirective &S) {
mlir::LogicalResult res = mlir::success();
// Getting the source location information of AST node S scope
auto scopeLoc = getLoc(S.getSourceRange());
// Creation of an omp.taskyield operation
CGM.getOpenMPRuntime().emitTaskyieldCall(builder, *this, scopeLoc);
CGM.getOpenMPRuntime().emitTaskyieldCall(builder, *this,
getLoc(S.getSourceRange()));
return res;
}

mlir::LogicalResult
CIRGenFunction::buildOMPBarrierDirective(const OMPBarrierDirective &S) {
mlir::LogicalResult res = mlir::success();
// Getting the source location information of AST node S scope
auto scopeLoc = getLoc(S.getSourceRange());
// Creation of an omp.barrier operation
CGM.getOpenMPRuntime().emitBarrierCall(builder, *this, scopeLoc);
CGM.getOpenMPRuntime().emitBarrierCall(builder, *this,
getLoc(S.getSourceRange()));
return res;
}
1 change: 1 addition & 0 deletions clang/lib/CIR/CodeGen/UnimplementedFeatureGuarding.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ struct UnimplementedFeature {
static bool CUDA() { return false; }
static bool openMP() { return false; }
static bool openMPRuntime() { return false; }
static bool openMPRegionInfo() { return false; }
static bool openMPTarget() { return false; }
static bool isVarArg() { return false; }
static bool setNonGC() { return false; }
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/CodeGen/OpenMP/barrier.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fopenmp -fclangir-enable -emit-cir %s -o %t.cir
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fopenmp-enable-irbuilder -fopenmp -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s

// CHECK: cir.func
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/CodeGen/OpenMP/taskwait.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fopenmp -fclangir-enable -emit-cir %s -o %t.cir
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fopenmp-enable-irbuilder -fopenmp -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s

// CHECK: cir.func
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/CodeGen/OpenMP/taskyield.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fopenmp -fclangir-enable -emit-cir %s -o %t.cir
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fopenmp-enable-irbuilder -fopenmp -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s

// CHECK: cir.func
Expand Down

0 comments on commit 0e0d466

Please sign in to comment.