Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit f6a1ff2

Browse files
committed
Reverting commit because an NVPTX patch sneaked in. Break up into two
patches. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@293003 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 105c8cd commit f6a1ff2

9 files changed

+41
-1424
lines changed

lib/Basic/OpenMPKinds.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -875,11 +875,8 @@ void clang::getOpenMPCaptureRegions(
875875
case OMPD_parallel_sections:
876876
CaptureRegions.push_back(OMPD_parallel);
877877
break;
878-
case OMPD_target_teams:
879-
CaptureRegions.push_back(OMPD_target);
880-
CaptureRegions.push_back(OMPD_teams);
881-
break;
882878
case OMPD_teams:
879+
case OMPD_target_teams:
883880
case OMPD_simd:
884881
case OMPD_for:
885882
case OMPD_for_simd:

lib/CodeGen/CGOpenMPRuntime.cpp

+22-53
Original file line numberDiff line numberDiff line change
@@ -4911,28 +4911,18 @@ emitNumTeamsForTargetDirective(CGOpenMPRuntime &OMPRuntime,
49114911
"teams directive expected to be "
49124912
"emitted only for the host!");
49134913

4914-
auto &Bld = CGF.Builder;
4915-
4916-
// If the target directive is combined with a teams directive:
4917-
// Return the value in the num_teams clause, if any.
4918-
// Otherwise, return 0 to denote the runtime default.
4919-
if (isOpenMPTeamsDirective(D.getDirectiveKind())) {
4920-
if (const auto *NumTeamsClause = D.getSingleClause<OMPNumTeamsClause>()) {
4921-
CodeGenFunction::RunCleanupsScope NumTeamsScope(CGF);
4922-
auto NumTeams = CGF.EmitScalarExpr(NumTeamsClause->getNumTeams(),
4923-
/*IgnoreResultAssign*/ true);
4924-
return Bld.CreateIntCast(NumTeams, CGF.Int32Ty,
4925-
/*IsSigned=*/true);
4926-
}
4927-
4928-
// The default value is 0.
4929-
return Bld.getInt32(0);
4930-
}
4931-
49324914
// If the target directive is combined with a parallel directive but not a
49334915
// teams directive, start one team.
4934-
if (isOpenMPParallelDirective(D.getDirectiveKind()))
4935-
return Bld.getInt32(1);
4916+
if (isOpenMPParallelDirective(D.getDirectiveKind()) &&
4917+
!isOpenMPTeamsDirective(D.getDirectiveKind()))
4918+
return CGF.Builder.getInt32(1);
4919+
4920+
// FIXME: For the moment we do not support combined directives with target and
4921+
// teams, so we do not expect to get any num_teams clause in the provided
4922+
// directive. Once we support that, this assertion can be replaced by the
4923+
// actual emission of the clause expression.
4924+
assert(D.getSingleClause<OMPNumTeamsClause>() == nullptr &&
4925+
"Not expecting clause in directive.");
49364926

49374927
// If the current target region has a teams region enclosed, we need to get
49384928
// the number of teams to pass to the runtime function call. This is done
@@ -4950,13 +4940,13 @@ emitNumTeamsForTargetDirective(CGOpenMPRuntime &OMPRuntime,
49504940
CGOpenMPInnerExprInfo CGInfo(CGF, CS);
49514941
CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, &CGInfo);
49524942
llvm::Value *NumTeams = CGF.EmitScalarExpr(NTE->getNumTeams());
4953-
return Bld.CreateIntCast(NumTeams, CGF.Int32Ty,
4954-
/*IsSigned=*/true);
4943+
return CGF.Builder.CreateIntCast(NumTeams, CGF.Int32Ty,
4944+
/*IsSigned=*/true);
49554945
}
49564946

49574947
// If we have an enclosed teams directive but no num_teams clause we use
49584948
// the default value 0.
4959-
return Bld.getInt32(0);
4949+
return CGF.Builder.getInt32(0);
49604950
}
49614951

49624952
// No teams associated with the directive.
@@ -4996,20 +4986,9 @@ emitNumThreadsForTargetDirective(CGOpenMPRuntime &OMPRuntime,
49964986
//
49974987
// If this is not a teams directive return nullptr.
49984988

4999-
if (isOpenMPTeamsDirective(D.getDirectiveKind()) ||
5000-
isOpenMPParallelDirective(D.getDirectiveKind())) {
4989+
if (isOpenMPParallelDirective(D.getDirectiveKind())) {
50014990
llvm::Value *DefaultThreadLimitVal = Bld.getInt32(0);
50024991
llvm::Value *NumThreadsVal = nullptr;
5003-
llvm::Value *ThreadLimitVal = nullptr;
5004-
5005-
if (const auto *ThreadLimitClause =
5006-
D.getSingleClause<OMPThreadLimitClause>()) {
5007-
CodeGenFunction::RunCleanupsScope ThreadLimitScope(CGF);
5008-
auto ThreadLimit = CGF.EmitScalarExpr(ThreadLimitClause->getThreadLimit(),
5009-
/*IgnoreResultAssign*/ true);
5010-
ThreadLimitVal = Bld.CreateIntCast(ThreadLimit, CGF.Int32Ty,
5011-
/*IsSigned=*/true);
5012-
}
50134992

50144993
if (const auto *NumThreadsClause =
50154994
D.getSingleClause<OMPNumThreadsClause>()) {
@@ -5021,22 +5000,16 @@ emitNumThreadsForTargetDirective(CGOpenMPRuntime &OMPRuntime,
50215000
Bld.CreateIntCast(NumThreads, CGF.Int32Ty, /*IsSigned=*/true);
50225001
}
50235002

5024-
// Select the lesser of thread_limit and num_threads.
5025-
if (NumThreadsVal)
5026-
ThreadLimitVal = ThreadLimitVal
5027-
? Bld.CreateSelect(Bld.CreateICmpSLT(NumThreadsVal,
5028-
ThreadLimitVal),
5029-
NumThreadsVal, ThreadLimitVal)
5030-
: NumThreadsVal;
5031-
5032-
// Set default value passed to the runtime if either teams or a target
5033-
// parallel type directive is found but no clause is specified.
5034-
if (!ThreadLimitVal)
5035-
ThreadLimitVal = DefaultThreadLimitVal;
5036-
5037-
return ThreadLimitVal;
5003+
return NumThreadsVal ? NumThreadsVal : DefaultThreadLimitVal;
50385004
}
50395005

5006+
// FIXME: For the moment we do not support combined directives with target and
5007+
// teams, so we do not expect to get any thread_limit clause in the provided
5008+
// directive. Once we support that, this assertion can be replaced by the
5009+
// actual emission of the clause expression.
5010+
assert(D.getSingleClause<OMPThreadLimitClause>() == nullptr &&
5011+
"Not expecting clause in directive.");
5012+
50405013
// If the current target region has a teams region enclosed, we need to get
50415014
// the thread limit to pass to the runtime function call. This is done
50425015
// by generating the expression in a inlined region. This is required because
@@ -6244,10 +6217,6 @@ void CGOpenMPRuntime::scanForTargetRegionsFunctions(const Stmt *S,
62446217
CodeGenFunction::EmitOMPTargetParallelDeviceFunction(
62456218
CGM, ParentName, cast<OMPTargetParallelDirective>(*S));
62466219
break;
6247-
case Stmt::OMPTargetTeamsDirectiveClass:
6248-
CodeGenFunction::EmitOMPTargetTeamsDeviceFunction(
6249-
CGM, ParentName, cast<OMPTargetTeamsDirective>(*S));
6250-
break;
62516220
default:
62526221
llvm_unreachable("Unknown target directive for OpenMP device codegen.");
62536222
}

lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ getExecutionModeForDirective(CodeGenModule &CGM,
198198
OpenMPDirectiveKind DirectiveKind = D.getDirectiveKind();
199199
switch (DirectiveKind) {
200200
case OMPD_target:
201-
case OMPD_target_teams:
202201
return CGOpenMPRuntimeNVPTX::ExecutionMode::Generic;
203202
case OMPD_target_parallel:
204203
return CGOpenMPRuntimeNVPTX::ExecutionMode::Spmd;

lib/CodeGen/CGStmtOpenMP.cpp

+13-52
Original file line numberDiff line numberDiff line change
@@ -98,22 +98,6 @@ class OMPParallelScope final : public OMPLexicalScope {
9898
/*EmitPreInitStmt=*/EmitPreInitStmt(S)) {}
9999
};
100100

101-
/// Lexical scope for OpenMP teams construct, that handles correct codegen
102-
/// for captured expressions.
103-
class OMPTeamsScope final : public OMPLexicalScope {
104-
bool EmitPreInitStmt(const OMPExecutableDirective &S) {
105-
OpenMPDirectiveKind Kind = S.getDirectiveKind();
106-
return !isOpenMPTargetExecutionDirective(Kind) &&
107-
isOpenMPTeamsDirective(Kind);
108-
}
109-
110-
public:
111-
OMPTeamsScope(CodeGenFunction &CGF, const OMPExecutableDirective &S)
112-
: OMPLexicalScope(CGF, S,
113-
/*AsInlined=*/false,
114-
/*EmitPreInitStmt=*/EmitPreInitStmt(S)) {}
115-
};
116-
117101
/// Private scope for OpenMP loop-based directives, that supports capturing
118102
/// of used expression from loop statement.
119103
class OMPLoopScope : public CodeGenFunction::RunCleanupsScope {
@@ -2034,6 +2018,15 @@ void CodeGenFunction::EmitOMPTeamsDistributeParallelForDirective(
20342018
});
20352019
}
20362020

2021+
void CodeGenFunction::EmitOMPTargetTeamsDirective(
2022+
const OMPTargetTeamsDirective &S) {
2023+
CGM.getOpenMPRuntime().emitInlinedDirective(
2024+
*this, OMPD_target_teams, [&S](CodeGenFunction &CGF, PrePostActionTy &) {
2025+
CGF.EmitStmt(
2026+
cast<CapturedStmt>(S.getAssociatedStmt())->getCapturedStmt());
2027+
});
2028+
}
2029+
20372030
void CodeGenFunction::EmitOMPTargetTeamsDistributeDirective(
20382031
const OMPTargetTeamsDistributeDirective &S) {
20392032
CGM.getOpenMPRuntime().emitInlinedDirective(
@@ -3526,8 +3519,9 @@ static void emitCommonOMPTeamsDirective(CodeGenFunction &CGF,
35263519
auto OutlinedFn = CGF.CGM.getOpenMPRuntime().emitTeamsOutlinedFunction(
35273520
S, *CS->getCapturedDecl()->param_begin(), InnermostKind, CodeGen);
35283521

3529-
const OMPNumTeamsClause *NT = S.getSingleClause<OMPNumTeamsClause>();
3530-
const OMPThreadLimitClause *TL = S.getSingleClause<OMPThreadLimitClause>();
3522+
const OMPTeamsDirective &TD = *dyn_cast<OMPTeamsDirective>(&S);
3523+
const OMPNumTeamsClause *NT = TD.getSingleClause<OMPNumTeamsClause>();
3524+
const OMPThreadLimitClause *TL = TD.getSingleClause<OMPThreadLimitClause>();
35313525
if (NT || TL) {
35323526
Expr *NumTeams = (NT) ? NT->getNumTeams() : nullptr;
35333527
Expr *ThreadLimit = (TL) ? TL->getThreadLimit() : nullptr;
@@ -3536,7 +3530,7 @@ static void emitCommonOMPTeamsDirective(CodeGenFunction &CGF,
35363530
S.getLocStart());
35373531
}
35383532

3539-
OMPTeamsScope Scope(CGF, S);
3533+
OMPLexicalScope Scope(CGF, S);
35403534
llvm::SmallVector<llvm::Value *, 16> CapturedVars;
35413535
CGF.GenerateOpenMPCapturedVars(*CS, CapturedVars);
35423536
CGF.CGM.getOpenMPRuntime().emitTeamsCall(CGF, S, S.getLocStart(), OutlinedFn,
@@ -3555,39 +3549,6 @@ void CodeGenFunction::EmitOMPTeamsDirective(const OMPTeamsDirective &S) {
35553549
emitCommonOMPTeamsDirective(*this, S, OMPD_teams, CodeGen);
35563550
}
35573551

3558-
static void emitTargetTeamsRegion(CodeGenFunction &CGF, PrePostActionTy &Action,
3559-
const OMPTargetTeamsDirective &S) {
3560-
auto *CS = S.getCapturedStmt(OMPD_teams);
3561-
Action.Enter(CGF);
3562-
auto &&CodeGen = [CS](CodeGenFunction &CGF, PrePostActionTy &) {
3563-
// TODO: Add support for clauses.
3564-
CGF.EmitStmt(CS->getCapturedStmt());
3565-
};
3566-
emitCommonOMPTeamsDirective(CGF, S, OMPD_teams, CodeGen);
3567-
}
3568-
3569-
void CodeGenFunction::EmitOMPTargetTeamsDeviceFunction(
3570-
CodeGenModule &CGM, StringRef ParentName,
3571-
const OMPTargetTeamsDirective &S) {
3572-
auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &Action) {
3573-
emitTargetTeamsRegion(CGF, Action, S);
3574-
};
3575-
llvm::Function *Fn;
3576-
llvm::Constant *Addr;
3577-
// Emit target region as a standalone region.
3578-
CGM.getOpenMPRuntime().emitTargetOutlinedFunction(
3579-
S, ParentName, Fn, Addr, /*IsOffloadEntry=*/true, CodeGen);
3580-
assert(Fn && Addr && "Target device function emission failed.");
3581-
}
3582-
3583-
void CodeGenFunction::EmitOMPTargetTeamsDirective(
3584-
const OMPTargetTeamsDirective &S) {
3585-
auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &Action) {
3586-
emitTargetTeamsRegion(CGF, Action, S);
3587-
};
3588-
emitCommonOMPTargetDirective(*this, S, CodeGen);
3589-
}
3590-
35913552
void CodeGenFunction::EmitOMPCancellationPointDirective(
35923553
const OMPCancellationPointDirective &S) {
35933554
CGM.getOpenMPRuntime().emitCancellationPointCall(*this, S.getLocStart(),

lib/CodeGen/CodeGenFunction.h

-3
Original file line numberDiff line numberDiff line change
@@ -2711,9 +2711,6 @@ class CodeGenFunction : public CodeGenTypeCache {
27112711
static void
27122712
EmitOMPTargetParallelDeviceFunction(CodeGenModule &CGM, StringRef ParentName,
27132713
const OMPTargetParallelDirective &S);
2714-
static void
2715-
EmitOMPTargetTeamsDeviceFunction(CodeGenModule &CGM, StringRef ParentName,
2716-
const OMPTargetTeamsDirective &S);
27172714
/// \brief Emit inner loop of the worksharing/simd construct.
27182715
///
27192716
/// \param S Directive, for which the inner loop must be emitted.

lib/Sema/SemaOpenMP.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -1594,7 +1594,8 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) {
15941594
case OMPD_parallel_for:
15951595
case OMPD_parallel_for_simd:
15961596
case OMPD_parallel_sections:
1597-
case OMPD_teams: {
1597+
case OMPD_teams:
1598+
case OMPD_target_teams: {
15981599
QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1);
15991600
QualType KmpInt32PtrTy =
16001601
Context.getPointerType(KmpInt32Ty).withConst().withRestrict();
@@ -1607,7 +1608,6 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) {
16071608
Params);
16081609
break;
16091610
}
1610-
case OMPD_target_teams:
16111611
case OMPD_target_parallel: {
16121612
Sema::CapturedParamNameType ParamsTarget[] = {
16131613
std::make_pair(StringRef(), QualType()) // __context with shared vars
@@ -1618,15 +1618,14 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) {
16181618
QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1);
16191619
QualType KmpInt32PtrTy =
16201620
Context.getPointerType(KmpInt32Ty).withConst().withRestrict();
1621-
Sema::CapturedParamNameType ParamsTeamsOrParallel[] = {
1621+
Sema::CapturedParamNameType ParamsParallel[] = {
16221622
std::make_pair(".global_tid.", KmpInt32PtrTy),
16231623
std::make_pair(".bound_tid.", KmpInt32PtrTy),
16241624
std::make_pair(StringRef(), QualType()) // __context with shared vars
16251625
};
1626-
// Start a captured region for 'teams' or 'parallel'. Both regions have
1627-
// the same implicit parameters.
1626+
// Start a captured region for 'parallel'.
16281627
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
1629-
ParamsTeamsOrParallel);
1628+
ParamsParallel);
16301629
break;
16311630
}
16321631
case OMPD_simd:

0 commit comments

Comments
 (0)