@@ -3403,32 +3403,15 @@ void CodeGenFunction::EmitOMPAtomicDirective(const OMPAtomicDirective &S) {
3403
3403
CGM.getOpenMPRuntime ().emitInlinedDirective (*this , OMPD_atomic, CodeGen);
3404
3404
}
3405
3405
3406
- std::pair<llvm::Function * /* OutlinedFn*/ , llvm::Constant * /* OutlinedFnID*/ >
3407
- CodeGenFunction::EmitOMPTargetDirectiveOutlinedFunction (
3408
- CodeGenModule &CGM, const OMPTargetDirective &S, StringRef ParentName,
3409
- bool IsOffloadEntry) {
3410
- llvm::Function *OutlinedFn = nullptr ;
3411
- llvm::Constant *OutlinedFnID = nullptr ;
3412
- auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &Action) {
3413
- OMPPrivateScope PrivateScope (CGF);
3414
- (void )CGF.EmitOMPFirstprivateClause (S, PrivateScope);
3415
- CGF.EmitOMPPrivateClause (S, PrivateScope);
3416
- (void )PrivateScope.Privatize ();
3417
-
3418
- Action.Enter (CGF);
3419
- CGF.EmitStmt (cast<CapturedStmt>(S.getAssociatedStmt ())->getCapturedStmt ());
3420
- };
3421
- // Emit target region as a standalone region.
3422
- CGM.getOpenMPRuntime ().emitTargetOutlinedFunction (
3423
- S, ParentName, OutlinedFn, OutlinedFnID, IsOffloadEntry, CodeGen);
3424
- return std::make_pair (OutlinedFn, OutlinedFnID);
3425
- }
3426
-
3427
- void CodeGenFunction::EmitOMPTargetDirective (const OMPTargetDirective &S) {
3406
+ static void emitCommonOMPTargetDirective (CodeGenFunction &CGF,
3407
+ const OMPExecutableDirective &S,
3408
+ const RegionCodeGenTy &CodeGen) {
3409
+ assert (isOpenMPTargetExecutionDirective (S.getDirectiveKind ()));
3410
+ CodeGenModule &CGM = CGF.CGM ;
3428
3411
const CapturedStmt &CS = *cast<CapturedStmt>(S.getAssociatedStmt ());
3429
3412
3430
3413
llvm::SmallVector<llvm::Value *, 16 > CapturedVars;
3431
- GenerateOpenMPCapturedVars (CS, CapturedVars);
3414
+ CGF. GenerateOpenMPCapturedVars (CS, CapturedVars);
3432
3415
3433
3416
llvm::Function *Fn = nullptr ;
3434
3417
llvm::Constant *FnID = nullptr ;
@@ -3452,31 +3435,64 @@ void CodeGenFunction::EmitOMPTargetDirective(const OMPTargetDirective &S) {
3452
3435
bool IsOffloadEntry = true ;
3453
3436
if (IfCond) {
3454
3437
bool Val;
3455
- if (ConstantFoldsToSimpleInteger (IfCond, Val) && !Val)
3438
+ if (CGF. ConstantFoldsToSimpleInteger (IfCond, Val) && !Val)
3456
3439
IsOffloadEntry = false ;
3457
3440
}
3458
3441
if (CGM.getLangOpts ().OMPTargetTriples .empty ())
3459
3442
IsOffloadEntry = false ;
3460
3443
3461
- assert (CurFuncDecl && " No parent declaration for target region!" );
3444
+ assert (CGF. CurFuncDecl && " No parent declaration for target region!" );
3462
3445
StringRef ParentName;
3463
3446
// In case we have Ctors/Dtors we use the complete type variant to produce
3464
3447
// the mangling of the device outlined kernel.
3465
- if (auto *D = dyn_cast<CXXConstructorDecl>(CurFuncDecl))
3448
+ if (auto *D = dyn_cast<CXXConstructorDecl>(CGF. CurFuncDecl ))
3466
3449
ParentName = CGM.getMangledName (GlobalDecl (D, Ctor_Complete));
3467
- else if (auto *D = dyn_cast<CXXDestructorDecl>(CurFuncDecl))
3450
+ else if (auto *D = dyn_cast<CXXDestructorDecl>(CGF. CurFuncDecl ))
3468
3451
ParentName = CGM.getMangledName (GlobalDecl (D, Dtor_Complete));
3469
3452
else
3470
3453
ParentName =
3471
- CGM.getMangledName (GlobalDecl (cast<FunctionDecl>(CurFuncDecl)));
3454
+ CGM.getMangledName (GlobalDecl (cast<FunctionDecl>(CGF. CurFuncDecl )));
3472
3455
3473
- std::tie (Fn, FnID) = EmitOMPTargetDirectiveOutlinedFunction (
3474
- CGM, S, ParentName, IsOffloadEntry);
3475
- OMPLexicalScope Scope (*this , S);
3476
- CGM.getOpenMPRuntime ().emitTargetCall (*this , S, Fn, FnID, IfCond, Device,
3456
+ // Emit target region as a standalone region.
3457
+ CGM.getOpenMPRuntime ().emitTargetOutlinedFunction (S, ParentName, Fn, FnID,
3458
+ IsOffloadEntry, CodeGen);
3459
+ OMPLexicalScope Scope (CGF, S);
3460
+ CGM.getOpenMPRuntime ().emitTargetCall (CGF, S, Fn, FnID, IfCond, Device,
3477
3461
CapturedVars);
3478
3462
}
3479
3463
3464
+ static void emitTargetRegion (CodeGenFunction &CGF, const OMPTargetDirective &S,
3465
+ PrePostActionTy &Action) {
3466
+ CodeGenFunction::OMPPrivateScope PrivateScope (CGF);
3467
+ (void )CGF.EmitOMPFirstprivateClause (S, PrivateScope);
3468
+ CGF.EmitOMPPrivateClause (S, PrivateScope);
3469
+ (void )PrivateScope.Privatize ();
3470
+
3471
+ Action.Enter (CGF);
3472
+ CGF.EmitStmt (cast<CapturedStmt>(S.getAssociatedStmt ())->getCapturedStmt ());
3473
+ }
3474
+
3475
+ void CodeGenFunction::EmitOMPTargetDeviceFunction (CodeGenModule &CGM,
3476
+ StringRef ParentName,
3477
+ const OMPTargetDirective &S) {
3478
+ auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &Action) {
3479
+ emitTargetRegion (CGF, S, Action);
3480
+ };
3481
+ llvm::Function *Fn;
3482
+ llvm::Constant *Addr;
3483
+ // Emit target region as a standalone region.
3484
+ CGM.getOpenMPRuntime ().emitTargetOutlinedFunction (
3485
+ S, ParentName, Fn, Addr, /* IsOffloadEntry=*/ true , CodeGen);
3486
+ assert (Fn && Addr && " Target device function emission failed." );
3487
+ }
3488
+
3489
+ void CodeGenFunction::EmitOMPTargetDirective (const OMPTargetDirective &S) {
3490
+ auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &Action) {
3491
+ emitTargetRegion (CGF, S, Action);
3492
+ };
3493
+ emitCommonOMPTargetDirective (*this , S, CodeGen);
3494
+ }
3495
+
3480
3496
static void emitCommonOMPTeamsDirective (CodeGenFunction &CGF,
3481
3497
const OMPExecutableDirective &S,
3482
3498
OpenMPDirectiveKind InnermostKind,
0 commit comments