Skip to content

Commit 9ff848c

Browse files
committed
Revert "[OpenMP] Use irbuilder as default for masked and master construct"
This reverts commit 2908fc0.
1 parent 347f3c1 commit 9ff848c

File tree

3 files changed

+146
-111
lines changed

3 files changed

+146
-111
lines changed

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 61 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4034,56 +4034,82 @@ static void emitMaster(CodeGenFunction &CGF, const OMPExecutableDirective &S) {
40344034
}
40354035

40364036
void CodeGenFunction::EmitOMPMasterDirective(const OMPMasterDirective &S) {
4037-
llvm::OpenMPIRBuilder &OMPBuilder = CGM.getOpenMPRuntime().getOMPBuilder();
4038-
using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
4037+
if (CGM.getLangOpts().OpenMPIRBuilder) {
4038+
llvm::OpenMPIRBuilder &OMPBuilder = CGM.getOpenMPRuntime().getOMPBuilder();
4039+
using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
40394040

4040-
const Stmt *MasterRegionBodyStmt = S.getAssociatedStmt();
4041+
const Stmt *MasterRegionBodyStmt = S.getAssociatedStmt();
40414042

4042-
auto FiniCB = [this](InsertPointTy IP) {
4043-
OMPBuilderCBHelpers::FinalizeOMPRegion(*this, IP);
4044-
};
4043+
auto FiniCB = [this](InsertPointTy IP) {
4044+
OMPBuilderCBHelpers::FinalizeOMPRegion(*this, IP);
4045+
};
40454046

4046-
auto BodyGenCB = [MasterRegionBodyStmt, this](InsertPointTy AllocaIP,
4047-
InsertPointTy CodeGenIP,
4048-
llvm::BasicBlock &FiniBB) {
4049-
OMPBuilderCBHelpers::InlinedRegionBodyRAII IRB(*this, AllocaIP, FiniBB);
4050-
OMPBuilderCBHelpers::EmitOMPRegionBody(*this, MasterRegionBodyStmt,
4051-
CodeGenIP, FiniBB);
4052-
};
4047+
auto BodyGenCB = [MasterRegionBodyStmt, this](InsertPointTy AllocaIP,
4048+
InsertPointTy CodeGenIP,
4049+
llvm::BasicBlock &FiniBB) {
4050+
OMPBuilderCBHelpers::InlinedRegionBodyRAII IRB(*this, AllocaIP, FiniBB);
4051+
OMPBuilderCBHelpers::EmitOMPRegionBody(*this, MasterRegionBodyStmt,
4052+
CodeGenIP, FiniBB);
4053+
};
40534054

4055+
LexicalScope Scope(*this, S.getSourceRange());
4056+
EmitStopPoint(&S);
4057+
Builder.restoreIP(OMPBuilder.createMaster(Builder, BodyGenCB, FiniCB));
4058+
4059+
return;
4060+
}
40544061
LexicalScope Scope(*this, S.getSourceRange());
40554062
EmitStopPoint(&S);
4056-
Builder.restoreIP(OMPBuilder.createMaster(Builder, BodyGenCB, FiniCB));
4063+
emitMaster(*this, S);
40574064
}
40584065

4059-
void CodeGenFunction::EmitOMPMaskedDirective(const OMPMaskedDirective &S) {
4060-
llvm::OpenMPIRBuilder &OMPBuilder = CGM.getOpenMPRuntime().getOMPBuilder();
4061-
using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
4062-
4063-
const Stmt *MaskedRegionBodyStmt = S.getAssociatedStmt();
4064-
const Expr *Filter = nullptr;
4066+
static void emitMasked(CodeGenFunction &CGF, const OMPExecutableDirective &S) {
4067+
auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &Action) {
4068+
Action.Enter(CGF);
4069+
CGF.EmitStmt(S.getRawStmt());
4070+
};
4071+
Expr *Filter = nullptr;
40654072
if (const auto *FilterClause = S.getSingleClause<OMPFilterClause>())
40664073
Filter = FilterClause->getThreadID();
4067-
llvm::Value *FilterVal = Filter
4068-
? EmitScalarExpr(Filter, CGM.Int32Ty)
4069-
: llvm::ConstantInt::get(CGM.Int32Ty, /*V=*/0);
4074+
CGF.CGM.getOpenMPRuntime().emitMaskedRegion(CGF, CodeGen, S.getBeginLoc(),
4075+
Filter);
4076+
}
40704077

4071-
auto FiniCB = [this](InsertPointTy IP) {
4072-
OMPBuilderCBHelpers::FinalizeOMPRegion(*this, IP);
4073-
};
4078+
void CodeGenFunction::EmitOMPMaskedDirective(const OMPMaskedDirective &S) {
4079+
if (CGM.getLangOpts().OpenMPIRBuilder) {
4080+
llvm::OpenMPIRBuilder &OMPBuilder = CGM.getOpenMPRuntime().getOMPBuilder();
4081+
using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
40744082

4075-
auto BodyGenCB = [MaskedRegionBodyStmt, this](InsertPointTy AllocaIP,
4076-
InsertPointTy CodeGenIP,
4077-
llvm::BasicBlock &FiniBB) {
4078-
OMPBuilderCBHelpers::InlinedRegionBodyRAII IRB(*this, AllocaIP, FiniBB);
4079-
OMPBuilderCBHelpers::EmitOMPRegionBody(*this, MaskedRegionBodyStmt,
4080-
CodeGenIP, FiniBB);
4081-
};
4083+
const Stmt *MaskedRegionBodyStmt = S.getAssociatedStmt();
4084+
const Expr *Filter = nullptr;
4085+
if (const auto *FilterClause = S.getSingleClause<OMPFilterClause>())
4086+
Filter = FilterClause->getThreadID();
4087+
llvm::Value *FilterVal = Filter
4088+
? EmitScalarExpr(Filter, CGM.Int32Ty)
4089+
: llvm::ConstantInt::get(CGM.Int32Ty, /*V=*/0);
4090+
4091+
auto FiniCB = [this](InsertPointTy IP) {
4092+
OMPBuilderCBHelpers::FinalizeOMPRegion(*this, IP);
4093+
};
4094+
4095+
auto BodyGenCB = [MaskedRegionBodyStmt, this](InsertPointTy AllocaIP,
4096+
InsertPointTy CodeGenIP,
4097+
llvm::BasicBlock &FiniBB) {
4098+
OMPBuilderCBHelpers::InlinedRegionBodyRAII IRB(*this, AllocaIP, FiniBB);
4099+
OMPBuilderCBHelpers::EmitOMPRegionBody(*this, MaskedRegionBodyStmt,
4100+
CodeGenIP, FiniBB);
4101+
};
40824102

4103+
LexicalScope Scope(*this, S.getSourceRange());
4104+
EmitStopPoint(&S);
4105+
Builder.restoreIP(
4106+
OMPBuilder.createMasked(Builder, BodyGenCB, FiniCB, FilterVal));
4107+
4108+
return;
4109+
}
40834110
LexicalScope Scope(*this, S.getSourceRange());
40844111
EmitStopPoint(&S);
4085-
Builder.restoreIP(
4086-
OMPBuilder.createMasked(Builder, BodyGenCB, FiniCB, FilterVal));
4112+
emitMasked(*this, S);
40874113
}
40884114

40894115
void CodeGenFunction::EmitOMPCriticalDirective(const OMPCriticalDirective &S) {

clang/test/OpenMP/masked_codegen.cpp

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s
1+
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefixes=ALL,NORMAL
22
// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
3-
// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
3+
// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=ALL,NORMAL
44
// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fopenmp-version=51 -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | FileCheck %s --check-prefix=TERM_DEBUG
5+
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -fopenmp-enable-irbuilder -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefixes=ALL,IRBUILDER
6+
// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -fopenmp-enable-irbuilder -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
7+
// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -fopenmp-enable-irbuilder -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=ALL,IRBUILDER
58

69
// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=51 -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
710
// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
@@ -12,66 +15,68 @@
1215
#ifndef HEADER
1316
#define HEADER
1417

15-
// CHECK: [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* }
18+
// ALL: [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* }
1619

17-
// CHECK: define {{.*}}void [[FOO:@.+]]()
20+
// ALL: define {{.*}}void [[FOO:@.+]]()
1821

1922
void foo() { extern void mayThrow(); mayThrow(); }
2023

21-
// CHECK-LABEL: @main
24+
// ALL-LABEL: @main
2225
// TERM_DEBUG-LABEL: @main
2326
int main() {
24-
// CHECK: [[A_ADDR:%.+]] = alloca i8
27+
// ALL: [[A_ADDR:%.+]] = alloca i8
2528
char a;
2629

27-
// CHECK: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:@.+]])
28-
// CHECK: [[RES:%.+]] = call {{.*}}i32 @__kmpc_masked([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 0)
29-
// CHECK-NEXT: [[IS_MASKED:%.+]] = icmp ne i32 [[RES]], 0
30-
// CHECK-NEXT: br i1 [[IS_MASKED]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:.+]]
31-
// CHECK: [[THEN]]
32-
// CHECK-NEXT: store i8 2, i8* [[A_ADDR]]
33-
// CHECK-NEXT: call {{.*}}void @__kmpc_end_masked([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
34-
// CHECK-NEXT: br label {{%?}}[[EXIT]]
35-
// CHECK: [[EXIT]]
30+
// ALL: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:@.+]])
31+
// ALL: [[RES:%.+]] = call {{.*}}i32 @__kmpc_masked([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 0)
32+
// ALL-NEXT: [[IS_MASKED:%.+]] = icmp ne i32 [[RES]], 0
33+
// ALL-NEXT: br i1 [[IS_MASKED]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:.+]]
34+
// ALL: [[THEN]]
35+
// ALL-NEXT: store i8 2, i8* [[A_ADDR]]
36+
// ALL-NEXT: call {{.*}}void @__kmpc_end_masked([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
37+
// ALL-NEXT: br label {{%?}}[[EXIT]]
38+
// ALL: [[EXIT]]
3639
#pragma omp masked
3740
a = 2;
38-
// CHECK: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:@.+]])
39-
// CHECK: [[RES:%.+]] = call {{.*}}i32 @__kmpc_masked([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 2)
40-
// CHECK-NEXT: [[IS_MASKED:%.+]] = icmp ne i32 [[RES]], 0
41-
// CHECK-NEXT: br i1 [[IS_MASKED]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:.+]]
42-
// CHECK: [[THEN]]
43-
// CHECK-NEXT: call {{.*}}void [[FOO]]()
44-
// CHECK: call {{.*}}void @__kmpc_end_masked([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
45-
// CHECK-NEXT: br label {{%?}}[[EXIT]]
46-
// CHECK: [[EXIT]]
41+
// IRBUILDER: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:@.+]])
42+
// ALL: [[RES:%.+]] = call {{.*}}i32 @__kmpc_masked([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 2)
43+
// ALL-NEXT: [[IS_MASKED:%.+]] = icmp ne i32 [[RES]], 0
44+
// ALL-NEXT: br i1 [[IS_MASKED]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:.+]]
45+
// ALL: [[THEN]]
46+
// IRBUILDER-NEXT: call {{.*}}void [[FOO]]()
47+
// NORMAL-NEXT: invoke {{.*}}void [[FOO]]()
48+
// ALL: call {{.*}}void @__kmpc_end_masked([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
49+
// ALL-NEXT: br label {{%?}}[[EXIT]]
50+
// ALL: [[EXIT]]
4751
#pragma omp masked filter(2)
4852
foo();
49-
// CHECK: store i32 9, i32* [[X:.+]],
50-
// CHECK: [[X_VAL:%.+]] = load i32, i32* [[X]]
51-
// CHECK: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:@.+]])
52-
// CHECK: [[RES:%.+]] = call {{.*}}i32 @__kmpc_masked([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 [[X_VAL]])
53-
// CHECK-NEXT: [[IS_MASKED:%.+]] = icmp ne i32 [[RES]], 0
54-
// CHECK-NEXT: br i1 [[IS_MASKED]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:.+]]
55-
// CHECK: [[THEN]]
56-
// CHECK-NEXT: call {{.*}}void [[FOO]]()
57-
// CHECK: call {{.*}}void @__kmpc_end_masked([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
58-
// CHECK-NEXT: br label {{%?}}[[EXIT]]
59-
// CHECK: [[EXIT]]
53+
// ALL: store i32 9, i32* [[X:.+]],
54+
// ALL: [[X_VAL:%.+]] = load i32, i32* [[X]]
55+
// IRBUILDER: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:@.+]])
56+
// ALL: [[RES:%.+]] = call {{.*}}i32 @__kmpc_masked([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 [[X_VAL]])
57+
// ALL-NEXT: [[IS_MASKED:%.+]] = icmp ne i32 [[RES]], 0
58+
// ALL-NEXT: br i1 [[IS_MASKED]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:.+]]
59+
// ALL: [[THEN]]
60+
// IRBUILDER-NEXT: call {{.*}}void [[FOO]]()
61+
// NORMAL-NEXT: invoke {{.*}}void [[FOO]]()
62+
// ALL: call {{.*}}void @__kmpc_end_masked([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
63+
// ALL-NEXT: br label {{%?}}[[EXIT]]
64+
// ALL: [[EXIT]]
6065
int x = 9;
6166
#pragma omp masked filter(x)
6267
foo();
63-
// CHECK-NOT: call i32 @__kmpc_masked
64-
// CHECK-NOT: call void @__kmpc_end_masked
68+
// ALL-NOT: call i32 @__kmpc_masked
69+
// ALL-NOT: call void @__kmpc_end_masked
6570
return a;
6671
}
6772

68-
// CHECK-LABEL: lambda_masked
73+
// ALL-LABEL: lambda_masked
6974
// TERM_DEBUG-LABEL: lambda_masked
7075
void lambda_masked(int a, int b) {
7176
auto l = [=]() {
7277
#pragma omp masked
7378
{
74-
// CHECK: call i32 @__kmpc_masked(
79+
// ALL: call i32 @__kmpc_masked(
7580
int c = a + b;
7681
}
7782
};
@@ -82,7 +87,7 @@ void lambda_masked(int a, int b) {
8287
#pragma omp parallel
8388
#pragma omp masked filter(1)
8489
{
85-
// CHECK: call i32 @__kmpc_masked(
90+
// ALL: call i32 @__kmpc_masked(
8691
int c = a + b;
8792
}
8893
};
@@ -94,20 +99,20 @@ void lambda_masked(int a, int b) {
9499
#pragma omp parallel
95100
#pragma omp masked filter(yy)
96101
{
97-
// CHECK: call i32 @__kmpc_masked(
102+
// ALL: call i32 @__kmpc_masked(
98103
int c = a + b;
99104
}
100105
};
101106

102107
l2(y);
103108
}
104109

105-
// CHECK-LABEL: parallel_masked
110+
// ALL-LABEL: parallel_masked
106111
// TERM_DEBUG-LABEL: parallel_masked
107112
void parallel_masked() {
108113
#pragma omp parallel
109114
#pragma omp masked filter(1)
110-
// TERM_DEBUG: __kmpc_global_thread_num
115+
// TERM_DEBUG-NOT: __kmpc_global_thread_num
111116
// TERM_DEBUG: call i32 @__kmpc_masked({{.+}}), !dbg [[DBG_LOC_START:![0-9]+]]
112117
// TERM_DEBUG: invoke void {{.*}}foo{{.*}}()
113118
// TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
@@ -121,7 +126,7 @@ void parallel_masked() {
121126
int x;
122127
#pragma omp parallel
123128
#pragma omp masked filter(x)
124-
// TERM_DEBUG: __kmpc_global_thread_num
129+
// TERM_DEBUG-NOT: __kmpc_global_thread_num
125130
// TERM_DEBUG: call i32 @__kmpc_masked({{.+}}), !dbg [[DBG_LOC_START:![0-9]+]]
126131
// TERM_DEBUG: invoke void {{.*}}foo{{.*}}()
127132
// TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],

0 commit comments

Comments
 (0)