23#include "llvm/ADT/SmallPtrSet.h"
24#include "llvm/Frontend/OpenMP/OMPDeviceConstants.h"
25#include "llvm/Frontend/OpenMP/OMPGridValues.h"
29using namespace llvm::omp;
34 llvm::FunctionCallee EnterCallee =
nullptr;
35 ArrayRef<llvm::Value *> EnterArgs;
36 llvm::FunctionCallee ExitCallee =
nullptr;
37 ArrayRef<llvm::Value *> ExitArgs;
38 bool Conditional =
false;
39 llvm::BasicBlock *ContBlock =
nullptr;
42 NVPTXActionTy(llvm::FunctionCallee EnterCallee,
43 ArrayRef<llvm::Value *> EnterArgs,
44 llvm::FunctionCallee ExitCallee,
45 ArrayRef<llvm::Value *> ExitArgs,
bool Conditional =
false)
46 : EnterCallee(EnterCallee), EnterArgs(EnterArgs), ExitCallee(ExitCallee),
47 ExitArgs(ExitArgs), Conditional(Conditional) {}
48 void Enter(CodeGenFunction &CGF)
override {
51 llvm::Value *CallBool = CGF.
Builder.CreateIsNotNull(EnterRes);
55 CGF.
Builder.CreateCondBr(CallBool, ThenBlock, ContBlock);
59 void Done(CodeGenFunction &CGF) {
64 void Exit(CodeGenFunction &CGF)
override {
73class ExecutionRuntimeModesRAII {
82 : ExecMode(ExecMode) {
83 SavedExecMode = ExecMode;
86 ~ExecutionRuntimeModesRAII() { ExecMode = SavedExecMode; }
91 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr)) {
92 const Expr *
Base = ASE->getBase()->IgnoreParenImpCasts();
93 while (
const auto *TempASE = dyn_cast<ArraySubscriptExpr>(
Base))
94 Base = TempASE->getBase()->IgnoreParenImpCasts();
96 }
else if (
auto *OASE = dyn_cast<ArraySectionExpr>(RefExpr)) {
97 const Expr *
Base = OASE->getBase()->IgnoreParenImpCasts();
98 while (
const auto *TempOASE = dyn_cast<ArraySectionExpr>(
Base))
99 Base = TempOASE->getBase()->IgnoreParenImpCasts();
100 while (
const auto *TempASE = dyn_cast<ArraySubscriptExpr>(
Base))
101 Base = TempASE->getBase()->IgnoreParenImpCasts();
105 if (
const auto *DE = dyn_cast<DeclRefExpr>(RefExpr))
111static RecordDecl *buildRecordForGlobalizedVars(
114 llvm::SmallDenseMap<const ValueDecl *, const FieldDecl *>
118 if (EscapedDecls.empty() && EscapedDeclsForTeams.empty())
122 GlobalizedVars.emplace_back(
C.getDeclAlign(D), D);
123 for (
const ValueDecl *D : EscapedDeclsForTeams)
124 GlobalizedVars.emplace_back(
C.getDeclAlign(D), D);
130 RecordDecl *GlobalizedRD =
C.buildImplicitRecord(
"_globalized_locals_ty");
133 EscapedDeclsForTeams);
134 for (
const auto &Pair : GlobalizedVars) {
138 Type =
C.getPointerType(
Type.getNonReferenceType());
143 if (SingleEscaped.count(VD)) {
158 llvm::APInt ArraySize(32, BufSize);
159 Type =
C.getConstantArrayType(
Type, ArraySize,
nullptr,
168 llvm::APInt Align(32, Pair.first.getQuantity());
169 Field->addAttr(AlignedAttr::CreateImplicit(
172 C.getIntTypeForBitwidth(32, 0),
174 {}, AlignedAttr::GNU_aligned));
177 MappedDeclsFields.try_emplace(VD, Field);
184class CheckVarsEscapingDeclContext final
186 CodeGenFunction &CGF;
187 llvm::SetVector<const ValueDecl *> EscapedDecls;
188 llvm::SetVector<const ValueDecl *> EscapedVariableLengthDecls;
189 llvm::SetVector<const ValueDecl *> DelayedVariableLengthDecls;
190 llvm::SmallPtrSet<const Decl *, 4> EscapedParameters;
191 RecordDecl *GlobalizedRD =
nullptr;
192 llvm::SmallDenseMap<const ValueDecl *, const FieldDecl *> MappedDeclsFields;
193 bool AllEscaped =
false;
194 bool IsForCombinedParallelRegion =
false;
196 void markAsEscaped(
const ValueDecl *VD) {
199 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD))
206 bool IsCaptured =
false;
207 if (
auto *CSI = CGF.CapturedStmtInfo) {
212 if (!IsForCombinedParallelRegion) {
215 const auto *Attr = FD->getAttr<OMPCaptureKindAttr>();
218 if (((Attr->getCaptureKind() != OMPC_map) &&
220 ((Attr->getCaptureKind() == OMPC_map) &&
221 !FD->getType()->isAnyPointerType()))
224 if (!FD->getType()->isReferenceType()) {
226 "Parameter captured by value with variably modified type");
227 EscapedParameters.insert(VD);
228 }
else if (!IsForCombinedParallelRegion) {
233 if ((!CGF.CapturedStmtInfo ||
234 (IsForCombinedParallelRegion && CGF.CapturedStmtInfo)) &&
242 EscapedVariableLengthDecls.insert(VD);
244 DelayedVariableLengthDecls.insert(VD);
246 EscapedDecls.insert(VD);
249 void VisitValueDecl(
const ValueDecl *VD) {
252 if (
const auto *VarD = dyn_cast<VarDecl>(VD)) {
254 const bool SavedAllEscaped = AllEscaped;
256 Visit(VarD->getInit());
257 AllEscaped = SavedAllEscaped;
261 void VisitOpenMPCapturedStmt(
const CapturedStmt *S,
262 ArrayRef<OMPClause *> Clauses,
263 bool IsCombinedParallelRegion) {
266 for (
const CapturedStmt::Capture &
C : S->
captures()) {
267 if (
C.capturesVariable() && !
C.capturesVariableByCopy()) {
268 const ValueDecl *VD =
C.getCapturedVar();
269 bool SavedIsForCombinedParallelRegion = IsForCombinedParallelRegion;
270 if (IsCombinedParallelRegion) {
274 IsForCombinedParallelRegion =
false;
275 for (
const OMPClause *
C : Clauses) {
277 C->getClauseKind() == OMPC_reduction ||
278 C->getClauseKind() == OMPC_linear ||
279 C->getClauseKind() == OMPC_private)
281 ArrayRef<const Expr *> Vars;
282 if (
const auto *PC = dyn_cast<OMPFirstprivateClause>(
C))
283 Vars = PC->getVarRefs();
284 else if (
const auto *PC = dyn_cast<OMPLastprivateClause>(
C))
285 Vars = PC->getVarRefs();
287 llvm_unreachable(
"Unexpected clause.");
288 for (
const auto *E : Vars) {
292 IsForCombinedParallelRegion =
true;
296 if (IsForCombinedParallelRegion)
303 IsForCombinedParallelRegion = SavedIsForCombinedParallelRegion;
308 void buildRecordForGlobalizedVars(
bool IsInTTDRegion) {
309 assert(!GlobalizedRD &&
310 "Record for globalized variables is built already.");
311 ArrayRef<const ValueDecl *> EscapedDeclsForParallel, EscapedDeclsForTeams;
312 unsigned WarpSize = CGF.getTarget().getGridValue().GV_Warp_Size;
314 EscapedDeclsForTeams = EscapedDecls.getArrayRef();
316 EscapedDeclsForParallel = EscapedDecls.getArrayRef();
317 GlobalizedRD = ::buildRecordForGlobalizedVars(
318 CGF.getContext(), EscapedDeclsForParallel, EscapedDeclsForTeams,
319 MappedDeclsFields, WarpSize);
323 CheckVarsEscapingDeclContext(CodeGenFunction &CGF,
324 ArrayRef<const ValueDecl *> TeamsReductions)
325 : CGF(CGF), EscapedDecls(llvm::from_range, TeamsReductions) {}
326 ~CheckVarsEscapingDeclContext() =
default;
327 void VisitDeclStmt(
const DeclStmt *S) {
331 if (
const auto *VD = dyn_cast_or_null<ValueDecl>(D))
334 void VisitOMPExecutableDirective(
const OMPExecutableDirective *D) {
337 if (!D->hasAssociatedStmt())
340 dyn_cast_or_null<CapturedStmt>(D->getAssociatedStmt())) {
343 llvm::SmallVector<OpenMPDirectiveKind, 4> CaptureRegions;
345 if (CaptureRegions.size() == 1 && CaptureRegions.back() == OMPD_unknown) {
346 VisitStmt(S->getCapturedStmt());
349 VisitOpenMPCapturedStmt(
351 CaptureRegions.back() == OMPD_parallel &&
355 void VisitCapturedStmt(
const CapturedStmt *S) {
358 for (
const CapturedStmt::Capture &
C : S->
captures()) {
359 if (
C.capturesVariable() && !
C.capturesVariableByCopy()) {
360 const ValueDecl *VD =
C.getCapturedVar();
370 for (
const LambdaCapture &
C : E->
captures()) {
371 if (
C.capturesVariable()) {
373 const ValueDecl *VD =
C.getCapturedVar();
381 void VisitBlockExpr(
const BlockExpr *E) {
386 const VarDecl *VD =
C.getVariable();
393 void VisitCallExpr(
const CallExpr *E) {
399 if (Arg->isLValue()) {
400 const bool SavedAllEscaped = AllEscaped;
403 AllEscaped = SavedAllEscaped;
410 void VisitDeclRefExpr(
const DeclRefExpr *E) {
413 const ValueDecl *VD = E->
getDecl();
421 void VisitUnaryOperator(
const UnaryOperator *E) {
425 const bool SavedAllEscaped = AllEscaped;
428 AllEscaped = SavedAllEscaped;
433 void VisitImplicitCastExpr(
const ImplicitCastExpr *E) {
437 const bool SavedAllEscaped = AllEscaped;
440 AllEscaped = SavedAllEscaped;
445 void VisitExpr(
const Expr *E) {
448 bool SavedAllEscaped = AllEscaped;
451 for (
const Stmt *Child : E->
children())
454 AllEscaped = SavedAllEscaped;
456 void VisitStmt(
const Stmt *S) {
459 for (
const Stmt *Child : S->
children())
466 const RecordDecl *getGlobalizedRecord(
bool IsInTTDRegion) {
468 buildRecordForGlobalizedVars(IsInTTDRegion);
473 const FieldDecl *getFieldForGlobalizedVar(
const ValueDecl *VD)
const {
474 assert(GlobalizedRD &&
475 "Record for globalized variables must be generated already.");
476 return MappedDeclsFields.lookup(VD);
480 ArrayRef<const ValueDecl *> getEscapedDecls()
const {
481 return EscapedDecls.getArrayRef();
486 const llvm::SmallPtrSetImpl<const Decl *> &getEscapedParameters()
const {
487 return EscapedParameters;
492 ArrayRef<const ValueDecl *> getEscapedVariableLengthDecls()
const {
493 return EscapedVariableLengthDecls.getArrayRef();
498 ArrayRef<const ValueDecl *> getDelayedVariableLengthDecls()
const {
499 return DelayedVariableLengthDecls.getArrayRef();
505CGOpenMPRuntimeGPU::getExecutionMode()
const {
506 return CurrentExecutionMode;
510CGOpenMPRuntimeGPU::getDataSharingMode()
const {
511 return CurrentDataSharingMode;
517 const auto *CS = D.getInnermostCapturedStmt();
519 CS->getCapturedStmt()->IgnoreContainers(
true);
522 if (
const auto *NestedDir =
523 dyn_cast_or_null<OMPExecutableDirective>(ChildStmt)) {
525 switch (D.getDirectiveKind()) {
529 if (DKind == OMPD_teams) {
530 Body = NestedDir->getInnermostCapturedStmt()->IgnoreContainers(
535 if (
const auto *NND =
536 dyn_cast_or_null<OMPExecutableDirective>(ChildStmt)) {
537 DKind = NND->getDirectiveKind();
543 case OMPD_target_teams:
545 case OMPD_target_simd:
546 case OMPD_target_parallel:
547 case OMPD_target_parallel_for:
548 case OMPD_target_parallel_for_simd:
549 case OMPD_target_teams_distribute:
550 case OMPD_target_teams_distribute_simd:
551 case OMPD_target_teams_distribute_parallel_for:
552 case OMPD_target_teams_distribute_parallel_for_simd:
555 case OMPD_parallel_for:
556 case OMPD_parallel_master:
557 case OMPD_parallel_sections:
559 case OMPD_parallel_for_simd:
561 case OMPD_cancellation_point:
563 case OMPD_threadprivate:
581 case OMPD_target_data:
582 case OMPD_target_exit_data:
583 case OMPD_target_enter_data:
584 case OMPD_distribute:
585 case OMPD_distribute_simd:
586 case OMPD_distribute_parallel_for:
587 case OMPD_distribute_parallel_for_simd:
588 case OMPD_teams_distribute:
589 case OMPD_teams_distribute_simd:
590 case OMPD_teams_distribute_parallel_for:
591 case OMPD_teams_distribute_parallel_for_simd:
592 case OMPD_target_update:
593 case OMPD_declare_simd:
594 case OMPD_declare_variant:
595 case OMPD_begin_declare_variant:
596 case OMPD_end_declare_variant:
597 case OMPD_declare_target:
598 case OMPD_end_declare_target:
599 case OMPD_declare_reduction:
600 case OMPD_declare_mapper:
602 case OMPD_taskloop_simd:
603 case OMPD_master_taskloop:
604 case OMPD_master_taskloop_simd:
605 case OMPD_parallel_master_taskloop:
606 case OMPD_parallel_master_taskloop_simd:
610 llvm_unreachable(
"Unexpected directive.");
620 switch (DirectiveKind) {
622 case OMPD_target_teams:
624 case OMPD_target_parallel_loop:
625 case OMPD_target_parallel:
626 case OMPD_target_parallel_for:
627 case OMPD_target_parallel_for_simd:
628 case OMPD_target_teams_distribute_parallel_for:
629 case OMPD_target_teams_distribute_parallel_for_simd:
630 case OMPD_target_simd:
631 case OMPD_target_teams_distribute_simd:
633 case OMPD_target_teams_distribute:
635 case OMPD_target_teams_loop:
638 if (
auto *TTLD = dyn_cast<OMPTargetTeamsGenericLoopDirective>(&D))
639 return TTLD->canBeParallelFor();
643 case OMPD_parallel_for:
644 case OMPD_parallel_master:
645 case OMPD_parallel_sections:
647 case OMPD_parallel_for_simd:
649 case OMPD_cancellation_point:
651 case OMPD_threadprivate:
669 case OMPD_target_data:
670 case OMPD_target_exit_data:
671 case OMPD_target_enter_data:
672 case OMPD_distribute:
673 case OMPD_distribute_simd:
674 case OMPD_distribute_parallel_for:
675 case OMPD_distribute_parallel_for_simd:
676 case OMPD_teams_distribute:
677 case OMPD_teams_distribute_simd:
678 case OMPD_teams_distribute_parallel_for:
679 case OMPD_teams_distribute_parallel_for_simd:
680 case OMPD_target_update:
681 case OMPD_declare_simd:
682 case OMPD_declare_variant:
683 case OMPD_begin_declare_variant:
684 case OMPD_end_declare_variant:
685 case OMPD_declare_target:
686 case OMPD_end_declare_target:
687 case OMPD_declare_reduction:
688 case OMPD_declare_mapper:
690 case OMPD_taskloop_simd:
691 case OMPD_master_taskloop:
692 case OMPD_master_taskloop_simd:
693 case OMPD_parallel_master_taskloop:
694 case OMPD_parallel_master_taskloop_simd:
701 "Unknown programming model for OpenMP directive on NVPTX target.");
704void CGOpenMPRuntimeGPU::emitNonSPMDKernel(
const OMPExecutableDirective &D,
705 StringRef ParentName,
706 llvm::Function *&OutlinedFn,
707 llvm::Constant *&OutlinedFnID,
710 ExecutionRuntimeModesRAII ModeRAII(CurrentExecutionMode,
EM_NonSPMD);
711 EntryFunctionState EST;
712 WrapperFunctionsMap.clear();
714 [[maybe_unused]]
bool IsBareKernel = D.getSingleClause<OMPXBareClause>();
715 assert(!IsBareKernel &&
"bare kernel should not be at generic mode");
718 class NVPTXPrePostActionTy :
public PrePostActionTy {
719 CGOpenMPRuntimeGPU::EntryFunctionState &EST;
720 const OMPExecutableDirective &D;
723 NVPTXPrePostActionTy(CGOpenMPRuntimeGPU::EntryFunctionState &EST,
724 const OMPExecutableDirective &D)
726 void Enter(CodeGenFunction &CGF)
override {
728 RT.emitKernelInit(D, CGF, EST,
false);
730 RT.setLocThreadIdInsertPt(CGF,
true);
732 void Exit(CodeGenFunction &CGF)
override {
734 RT.clearLocThreadIdInsertPt(CGF);
735 RT.emitKernelDeinit(CGF, EST,
false);
739 IsInTTDRegion =
true;
741 IsOffloadEntry, CodeGen);
742 IsInTTDRegion =
false;
745void CGOpenMPRuntimeGPU::emitKernelInit(
const OMPExecutableDirective &D,
747 EntryFunctionState &EST,
bool IsSPMD) {
748 llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs Attrs;
750 IsSPMD ? llvm::omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_SPMD
751 : llvm::omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_GENERIC;
754 CGBuilderTy &Bld = CGF.
Builder;
755 Bld.restoreIP(
OMPBuilder.createTargetInit(Bld, Attrs));
757 emitGenericVarsProlog(CGF, EST.Loc);
761 EntryFunctionState &EST,
764 emitGenericVarsEpilog(CGF);
767 ASTContext &
C =
CGM.getContext();
768 RecordDecl *StaticRD =
C.buildImplicitRecord(
769 "_openmp_teams_reduction_type_$_", RecordDecl::TagKind::Union);
771 for (
const RecordDecl *TeamReductionRec : TeamsReductions) {
772 CanQualType RecTy =
C.getCanonicalTagType(TeamReductionRec);
774 C, StaticRD, SourceLocation(), SourceLocation(),
nullptr, RecTy,
775 C.getTrivialTypeSourceInfo(RecTy, SourceLocation()),
783 llvm::Type *LLVMReductionsBufferTy =
784 CGM.getTypes().ConvertTypeForMem(StaticTy);
785 const auto &DL =
CGM.getModule().getDataLayout();
787 TeamsReductions.empty()
789 : DL.getTypeAllocSize(LLVMReductionsBufferTy).getFixedValue();
790 CGBuilderTy &Bld = CGF.
Builder;
791 OMPBuilder.createTargetDeinit(Bld, ReductionDataSize,
792 C.getLangOpts().OpenMPCUDAReductionBufNum);
793 TeamsReductions.clear();
796void CGOpenMPRuntimeGPU::emitSPMDKernel(
const OMPExecutableDirective &D,
797 StringRef ParentName,
798 llvm::Function *&OutlinedFn,
799 llvm::Constant *&OutlinedFnID,
802 ExecutionRuntimeModesRAII ModeRAII(CurrentExecutionMode,
EM_SPMD);
803 EntryFunctionState EST;
805 bool IsBareKernel = D.getSingleClause<OMPXBareClause>();
808 class NVPTXPrePostActionTy :
public PrePostActionTy {
809 CGOpenMPRuntimeGPU &RT;
810 CGOpenMPRuntimeGPU::EntryFunctionState &EST;
812 DataSharingMode Mode;
813 const OMPExecutableDirective &D;
816 NVPTXPrePostActionTy(CGOpenMPRuntimeGPU &RT,
817 CGOpenMPRuntimeGPU::EntryFunctionState &EST,
818 bool IsBareKernel,
const OMPExecutableDirective &D)
819 : RT(RT), EST(EST), IsBareKernel(IsBareKernel),
820 Mode(RT.CurrentDataSharingMode), D(D) {}
821 void Enter(CodeGenFunction &CGF)
override {
823 RT.CurrentDataSharingMode = DataSharingMode::DS_CUDA;
826 RT.emitKernelInit(D, CGF, EST,
true);
828 RT.setLocThreadIdInsertPt(CGF,
true);
830 void Exit(CodeGenFunction &CGF)
override {
832 RT.CurrentDataSharingMode = Mode;
835 RT.clearLocThreadIdInsertPt(CGF);
836 RT.emitKernelDeinit(CGF, EST,
true);
838 } Action(*
this, EST, IsBareKernel, D);
840 IsInTTDRegion =
true;
842 IsOffloadEntry, CodeGen);
843 IsInTTDRegion =
false;
846void CGOpenMPRuntimeGPU::emitTargetOutlinedFunction(
847 const OMPExecutableDirective &D, StringRef ParentName,
848 llvm::Function *&OutlinedFn, llvm::Constant *&OutlinedFnID,
853 assert(!ParentName.empty() &&
"Invalid target region parent name!");
856 bool IsBareKernel = D.getSingleClause<OMPXBareClause>();
857 if (Mode || IsBareKernel)
858 emitSPMDKernel(D, ParentName, OutlinedFn, OutlinedFnID, IsOffloadEntry,
861 emitNonSPMDKernel(D, ParentName, OutlinedFn, OutlinedFnID, IsOffloadEntry,
867 llvm::OpenMPIRBuilderConfig Config(
868 CGM.getLangOpts().OpenMPIsTargetDevice,
isGPU(),
869 CGM.getLangOpts().OpenMPOffloadMandatory,
874 if (!
CGM.getLangOpts().OpenMPIsTargetDevice)
875 llvm_unreachable(
"OpenMP can only handle device code.");
877 if (
CGM.getLangOpts().OpenMPCUDAMode)
881 if (
CGM.getLangOpts().NoGPULib ||
CGM.getLangOpts().OMPHostIRFile.empty())
884 OMPBuilder.createGlobalFlag(
CGM.getLangOpts().OpenMPTargetDebug,
885 "__omp_rtl_debug_kind");
886 OMPBuilder.createGlobalFlag(
CGM.getLangOpts().OpenMPTeamSubscription,
887 "__omp_rtl_assume_teams_oversubscription");
888 OMPBuilder.createGlobalFlag(
CGM.getLangOpts().OpenMPThreadSubscription,
889 "__omp_rtl_assume_threads_oversubscription");
890 OMPBuilder.createGlobalFlag(
CGM.getLangOpts().OpenMPNoThreadState,
891 "__omp_rtl_assume_no_thread_state");
892 OMPBuilder.createGlobalFlag(
CGM.getLangOpts().OpenMPNoNestedParallelism,
893 "__omp_rtl_assume_no_nested_parallelism");
897 ProcBindKind ProcBind,
905 CGM.getDiags().Report(Loc, diag::warn_omp_gpu_unsupported_clause)
906 << getOpenMPClauseName(OMPC_message);
913 CGM.getDiags().Report(Loc, diag::warn_omp_gpu_unsupported_clause)
914 << getOpenMPClauseName(OMPC_severity);
923 if (Modifier == OMPC_NUMTHREADS_strict) {
924 CGM.getDiags().Report(Loc,
925 diag::warn_omp_gpu_unsupported_modifier_for_clause)
926 <<
"strict" << getOpenMPClauseName(OMPC_num_threads);
934 const Expr *NumTeams,
935 const Expr *ThreadLimit,
943 bool PrevIsInTTDRegion = IsInTTDRegion;
944 IsInTTDRegion =
false;
947 CGF, D, ThreadIDVar, InnermostKind,
CodeGen));
948 IsInTTDRegion = PrevIsInTTDRegion;
950 llvm::Function *WrapperFun =
951 createParallelDataSharingWrapper(OutlinedFun, D);
952 WrapperFunctionsMap[OutlinedFun] = WrapperFun;
964 "expected teams directive.");
969 D.getInnermostCapturedStmt()->getCapturedStmt()->IgnoreContainers(
971 Dir = dyn_cast_or_null<OMPExecutableDirective>(S);
979 for (
const Expr *E :
C->getVarRefs())
989 "expected teams directive.");
991 for (
const Expr *E :
C->privates())
1004 llvm::SmallDenseMap<const ValueDecl *, const FieldDecl *> MappedDeclsFields;
1005 unsigned WarpSize =
CGM.getTarget().getGridValue().GV_Warp_Size;
1011 if (!LastPrivatesReductions.empty()) {
1012 GlobalizedRD = ::buildRecordForGlobalizedVars(
1013 CGM.getContext(), {}, LastPrivatesReductions, MappedDeclsFields,
1016 }
else if (!LastPrivatesReductions.empty()) {
1017 assert(!TeamAndReductions.first &&
1018 "Previous team declaration is not expected.");
1019 TeamAndReductions.first = D.getCapturedStmt(OMPD_teams)->getCapturedDecl();
1020 std::swap(TeamAndReductions.second, LastPrivatesReductions);
1027 llvm::SmallDenseMap<const ValueDecl *, const FieldDecl *>
1031 NVPTXPrePostActionTy(
1033 llvm::SmallDenseMap<const ValueDecl *, const FieldDecl *>
1035 : Loc(Loc), GlobalizedRD(GlobalizedRD),
1036 MappedDeclsFields(MappedDeclsFields) {}
1041 auto I = Rt.FunctionGlobalizedDecls.try_emplace(CGF.
CurFn).first;
1042 I->getSecond().MappedParams =
1043 std::make_unique<CodeGenFunction::OMPMapVars>();
1044 DeclToAddrMapTy &
Data = I->getSecond().LocalVarData;
1045 for (
const auto &Pair : MappedDeclsFields) {
1046 assert(Pair.getFirst()->isCanonicalDecl() &&
1047 "Expected canonical declaration");
1048 Data.try_emplace(Pair.getFirst());
1051 Rt.emitGenericVarsProlog(CGF, Loc);
1055 .emitGenericVarsEpilog(CGF);
1057 } Action(Loc, GlobalizedRD, MappedDeclsFields);
1060 CGF, D, ThreadIDVar, InnermostKind,
CodeGen);
1072 const auto I = FunctionGlobalizedDecls.find(CGF.
CurFn);
1073 if (I == FunctionGlobalizedDecls.end())
1076 for (
auto &Rec : I->getSecond().LocalVarData) {
1078 bool EscapedParam = I->getSecond().EscapedParameters.count(Rec.first);
1082 llvm::Value *ParValue;
1091 llvm::CallBase *VoidPtr =
1096 VoidPtr->addRetAttr(llvm::Attribute::get(
1102 VoidPtr, Bld.getPtrTy(0), VD->
getName() +
"_on_stack");
1105 Rec.second.PrivateAddr = VarAddr.getAddress();
1106 Rec.second.GlobalizedVal = VoidPtr;
1111 I->getSecond().MappedParams->setVarAddr(CGF, VD, VarAddr.getAddress());
1114 VoidPtr->setDebugLoc(DI->SourceLocToDebugLoc(VD->
getLocation()));
1117 for (
const auto *ValueD : I->getSecond().EscapedVariableLengthDecls) {
1119 std::pair<llvm::Value *, llvm::Value *> AddrSizePair =
1121 I->getSecond().EscapedVariableLengthDeclsAddrs.emplace_back(AddrSizePair);
1123 CGM.getContext().getDeclAlign(VD),
1125 I->getSecond().MappedParams->setVarAddr(CGF, VD,
Base.getAddress());
1127 I->getSecond().MappedParams->apply(CGF);
1132 const auto I = FunctionGlobalizedDecls.find(CGF.
CurFn);
1133 if (I == FunctionGlobalizedDecls.end())
1137 return llvm::is_contained(I->getSecond().DelayedVariableLengthDecls, VD);
1140std::pair<llvm::Value *, llvm::Value *>
1148 Size = Bld.CreateNUWAdd(
1150 llvm::Value *AlignVal =
1152 Size = Bld.CreateUDiv(Size, AlignVal);
1153 Size = Bld.CreateNUWMul(Size, AlignVal);
1156 llvm::Value *AllocArgs[] = {Size};
1157 llvm::CallBase *VoidPtr =
1159 CGM.getModule(), OMPRTL___kmpc_alloc_shared),
1161 VoidPtr->addRetAttr(llvm::Attribute::get(
1162 CGM.getLLVMContext(), llvm::Attribute::Alignment, Align.
getQuantity()));
1164 return std::make_pair(VoidPtr, Size);
1169 const std::pair<llvm::Value *, llvm::Value *> &AddrSizePair) {
1172 CGM.getModule(), OMPRTL___kmpc_free_shared),
1173 {AddrSizePair.first, AddrSizePair.second});
1180 const auto I = FunctionGlobalizedDecls.find(CGF.
CurFn);
1181 if (I != FunctionGlobalizedDecls.end()) {
1184 for (
const auto &AddrSizePair :
1185 llvm::reverse(I->getSecond().EscapedVariableLengthDeclsAddrs)) {
1188 {AddrSizePair.first, AddrSizePair.second});
1191 for (
auto &Rec : llvm::reverse(I->getSecond().LocalVarData)) {
1193 I->getSecond().MappedParams->restore(CGF);
1195 llvm::Value *FreeArgs[] = {Rec.second.GlobalizedVal,
1207 llvm::Function *OutlinedFn,
1221 OutlinedFnArgs.push_back(llvm::ConstantPointerNull::get(
CGM.VoidPtrTy));
1224 OutlinedFnArgs.push_back(ZeroAddr.getPointer());
1225 OutlinedFnArgs.append(CapturedVars.begin(), CapturedVars.end());
1237 auto &&ParallelGen = [
this, Loc, OutlinedFn, CapturedVars, IfCond,
1241 llvm::Value *NumThreadsVal = NumThreads;
1242 llvm::Function *WFn = WrapperFunctionsMap[OutlinedFn];
1243 llvm::Value *ID = llvm::ConstantPointerNull::get(
CGM.Int8PtrTy);
1245 ID = Bld.CreateBitOrPointerCast(WFn,
CGM.Int8PtrTy);
1246 llvm::Value *FnPtr = Bld.CreateBitOrPointerCast(OutlinedFn,
CGM.Int8PtrTy);
1254 llvm::ArrayType::get(
CGM.VoidPtrTy, CapturedVars.size()),
1255 "captured_vars_addrs");
1257 if (!CapturedVars.empty()) {
1261 for (llvm::Value *
V : CapturedVars) {
1264 if (
V->getType()->isIntegerTy())
1274 llvm::Value *IfCondVal =
nullptr;
1279 IfCondVal = llvm::ConstantInt::get(CGF.
Int32Ty, 1);
1282 NumThreadsVal = llvm::ConstantInt::get(CGF.
Int32Ty, -1);
1284 NumThreadsVal = Bld.CreateZExtOrTrunc(NumThreadsVal, CGF.
Int32Ty);
1286 assert(IfCondVal &&
"Expected a value");
1288 llvm::Value *Args[] = {
1293 llvm::ConstantInt::get(CGF.
Int32Ty, -1),
1296 Bld.CreateBitOrPointerCast(CapturedVarsAddrs.
emitRawPointer(CGF),
1298 llvm::ConstantInt::get(
CGM.SizeTy, CapturedVars.size())};
1300 CGM.getModule(), OMPRTL___kmpc_parallel_51),
1314 llvm::Value *Args[] = {
1315 llvm::ConstantPointerNull::get(
1317 llvm::ConstantInt::get(CGF.
Int32Ty, 0,
true)};
1336 CGM.getModule(), OMPRTL___kmpc_barrier),
1354 CGM.getModule(), OMPRTL___kmpc_warp_active_thread_mask));
1356 llvm::Value *ThreadID = RT.getGPUThreadID(CGF);
1359 llvm::Value *TeamWidth = RT.getGPUNumThreads(CGF);
1372 llvm::Value *CmpLoopBound = CGF.
Builder.CreateICmpSLT(CounterVal, TeamWidth);
1373 CGF.
Builder.CreateCondBr(CmpLoopBound, TestBB, ExitBB);
1379 llvm::Value *CmpThreadToCounter =
1380 CGF.
Builder.CreateICmpEQ(ThreadID, CounterVal);
1381 CGF.
Builder.CreateCondBr(CmpThreadToCounter, BodyBB, SyncBB);
1397 CGM.getModule(), OMPRTL___kmpc_syncwarp),
1400 llvm::Value *IncCounterVal =
1414 "Cast type must sized.");
1416 "Val type must sized.");
1418 if (ValTy == CastTy)
1422 return CGF.
Builder.CreateBitCast(Val, LLVMCastTy);
1424 return CGF.
Builder.CreateIntCast(Val, LLVMCastTy,
1691 assert(!TeamsReduction && !ParallelReduction &&
1692 "Invalid reduction selection in emitReduction.");
1693 (void)ParallelReduction;
1695 ReductionOps, Options);
1699 llvm::SmallDenseMap<const ValueDecl *, const FieldDecl *> VarFieldMap;
1702 for (
const Expr *DRE : Privates) {
1706 const RecordDecl *ReductionRec = ::buildRecordForGlobalizedVars(
1707 CGM.getContext(), PrivatesReductions, {}, VarFieldMap, 1);
1710 TeamsReductions.push_back(ReductionRec);
1715 using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
1718 InsertPointTy CodeGenIP(CGF.
Builder.GetInsertBlock(),
1719 CGF.
Builder.GetInsertPoint());
1720 llvm::OpenMPIRBuilder::LocationDescription OmpLoc(
1727 llvm::Type *ElementType;
1728 llvm::Value *Variable;
1729 llvm::Value *PrivateVariable;
1730 llvm::OpenMPIRBuilder::ReductionGenAtomicCBTy AtomicReductionGen =
nullptr;
1732 const auto *RHSVar =
1735 const auto *LHSVar =
1738 llvm::OpenMPIRBuilder::EvalKind EvalKind;
1741 EvalKind = llvm::OpenMPIRBuilder::EvalKind::Scalar;
1744 EvalKind = llvm::OpenMPIRBuilder::EvalKind::Complex;
1747 EvalKind = llvm::OpenMPIRBuilder::EvalKind::Aggregate;
1750 auto ReductionGen = [&](InsertPointTy CodeGenIP,
unsigned I,
1751 llvm::Value **LHSPtr, llvm::Value **RHSPtr,
1752 llvm::Function *NewFunc) {
1753 CGF.
Builder.restoreIP(CodeGenIP);
1754 auto *CurFn = CGF.
CurFn;
1755 CGF.
CurFn = NewFunc;
1770 return InsertPointTy(CGF.
Builder.GetInsertBlock(),
1771 CGF.
Builder.GetInsertPoint());
1773 ReductionInfos.emplace_back(llvm::OpenMPIRBuilder::ReductionInfo(
1774 ElementType, Variable, PrivateVariable, EvalKind,
1775 nullptr, ReductionGen, AtomicReductionGen));
1779 llvm::OpenMPIRBuilder::InsertPointTy AfterIP =
1781 OmpLoc, AllocaIP, CodeGenIP, ReductionInfos,
false, TeamsReduction,
1782 llvm::OpenMPIRBuilder::ReductionGenCBKind::Clang,
1784 C.getLangOpts().OpenMPCUDAReductionBufNum, RTLoc));
1785 CGF.
Builder.restoreIP(AfterIP);
1790 const VarDecl *NativeParam)
const {
1797 if (
const auto *
Attr = FD->
getAttr<OMPCaptureKindAttr>()) {
1798 if (
Attr->getCaptureKind() == OMPC_map) {
1799 PointeeTy =
CGM.getContext().getAddrSpaceQualType(PointeeTy,
1803 ArgType =
CGM.getContext().getPointerType(PointeeTy);
1805 enum { NVPTX_local_addr = 5 };
1823 const VarDecl *TargetParam)
const {
1824 assert(NativeParam != TargetParam &&
1826 "Native arg must not be the same as target arg.");
1830 const Type *NonQualTy = QC.
strip(NativeParamType);
1832 unsigned NativePointeeAddrSpace =
1840 llvm::PointerType::get(CGF.
getLLVMContext(), NativePointeeAddrSpace));
1844 return NativeParamAddr;
1851 TargetArgs.reserve(Args.size());
1852 auto *FnType = OutlinedFn.getFunctionType();
1853 for (
unsigned I = 0, E = Args.size(); I < E; ++I) {
1854 if (FnType->isVarArg() && FnType->getNumParams() <= I) {
1855 TargetArgs.append(std::next(Args.begin(), I), Args.end());
1858 llvm::Type *TargetType = FnType->getParamType(I);
1859 llvm::Value *NativeArg = Args[I];
1860 if (!TargetType->isPointerTy()) {
1861 TargetArgs.emplace_back(NativeArg);
1864 TargetArgs.emplace_back(
1874llvm::Function *CGOpenMPRuntimeGPU::createParallelDataSharingWrapper(
1877 const auto &CS = *D.getCapturedStmt(OMPD_parallel);
1891 WrapperArgs.emplace_back(&ParallelLevelArg);
1892 WrapperArgs.emplace_back(&WrapperArg);
1897 auto *Fn = llvm::Function::Create(
1899 Twine(OutlinedParallelFn->getName(),
"_wrapper"), &
CGM.
getModule());
1907 Fn->addFnAttr(llvm::Attribute::NoInline);
1910 Fn->setLinkage(llvm::GlobalValue::InternalLinkage);
1911 Fn->setDoesNotRecurse();
1915 D.getBeginLoc(), D.getBeginLoc());
1917 const auto *RD = CS.getCapturedRecordDecl();
1918 auto CurField = RD->field_begin();
1930 auto CI = CS.capture_begin();
1936 llvm::Value *GlobalArgsPtr = GlobalArgs.
getPointer();
1937 llvm::Value *DataSharingArgs[] = {GlobalArgsPtr};
1945 if (CS.capture_size() > 0 ||
1956 Src, Bld.getPtrTy(0), CGF.
SizeTy);
1962 Args.emplace_back(LB);
1972 Args.emplace_back(UB);
1975 if (CS.capture_size() > 0) {
1977 for (
unsigned I = 0, E = CS.capture_size(); I < E; ++I, ++CI, ++CurField) {
1978 QualType ElemTy = CurField->getType();
1987 if (CI->capturesVariableByCopy() &&
1988 !CI->getCapturedVar()->getType()->isAnyPointerType()) {
1992 Args.emplace_back(Arg);
2006 assert(D &&
"Expected function or captured|block decl.");
2007 assert(FunctionGlobalizedDecls.count(CGF.
CurFn) == 0 &&
2008 "Function is registered already.");
2009 assert((!TeamAndReductions.first || TeamAndReductions.first == D) &&
2010 "Team is set but not processed.");
2011 const Stmt *Body =
nullptr;
2012 bool NeedToDelayGlobalization =
false;
2013 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
2014 Body = FD->getBody();
2015 }
else if (
const auto *BD = dyn_cast<BlockDecl>(D)) {
2016 Body = BD->getBody();
2017 }
else if (
const auto *CD = dyn_cast<CapturedDecl>(D)) {
2018 Body = CD->getBody();
2020 if (NeedToDelayGlobalization &&
2026 CheckVarsEscapingDeclContext VarChecker(CGF, TeamAndReductions.second);
2027 VarChecker.Visit(Body);
2029 VarChecker.getGlobalizedRecord(IsInTTDRegion);
2030 TeamAndReductions.first =
nullptr;
2031 TeamAndReductions.second.clear();
2033 VarChecker.getEscapedVariableLengthDecls();
2035 VarChecker.getDelayedVariableLengthDecls();
2036 if (!GlobalizedVarsRecord && EscapedVariableLengthDecls.empty() &&
2037 DelayedVariableLengthDecls.empty())
2039 auto I = FunctionGlobalizedDecls.try_emplace(CGF.
CurFn).first;
2040 I->getSecond().MappedParams =
2041 std::make_unique<CodeGenFunction::OMPMapVars>();
2042 I->getSecond().EscapedParameters.insert(
2043 VarChecker.getEscapedParameters().begin(),
2044 VarChecker.getEscapedParameters().end());
2045 I->getSecond().EscapedVariableLengthDecls.append(
2046 EscapedVariableLengthDecls.begin(), EscapedVariableLengthDecls.end());
2047 I->getSecond().DelayedVariableLengthDecls.append(
2048 DelayedVariableLengthDecls.begin(), DelayedVariableLengthDecls.end());
2049 DeclToAddrMapTy &
Data = I->getSecond().LocalVarData;
2050 for (
const ValueDecl *VD : VarChecker.getEscapedDecls()) {
2052 Data.try_emplace(VD);
2054 if (!NeedToDelayGlobalization) {
2056 struct GlobalizationScope final : EHScopeStack::Cleanup {
2057 GlobalizationScope() =
default;
2061 .emitGenericVarsEpilog(CGF);
2070 if (VD && VD->
hasAttr<OMPAllocateDeclAttr>()) {
2071 const auto *A = VD->
getAttr<OMPAllocateDeclAttr>();
2073 switch (A->getAllocatorType()) {
2074 case OMPAllocateDeclAttr::OMPNullMemAlloc:
2075 case OMPAllocateDeclAttr::OMPDefaultMemAlloc:
2076 case OMPAllocateDeclAttr::OMPHighBWMemAlloc:
2077 case OMPAllocateDeclAttr::OMPLowLatMemAlloc:
2079 case OMPAllocateDeclAttr::OMPThreadMemAlloc:
2081 case OMPAllocateDeclAttr::OMPUserDefinedMemAlloc:
2084 case OMPAllocateDeclAttr::OMPConstMemAlloc:
2087 case OMPAllocateDeclAttr::OMPPTeamMemAlloc:
2090 case OMPAllocateDeclAttr::OMPLargeCapMemAlloc:
2091 case OMPAllocateDeclAttr::OMPCGroupMemAlloc:
2095 auto *GV =
new llvm::GlobalVariable(
2096 CGM.getModule(), VarTy,
false,
2097 llvm::GlobalValue::InternalLinkage, llvm::PoisonValue::get(VarTy),
2099 nullptr, llvm::GlobalValue::NotThreadLocal,
2100 CGM.getContext().getTargetAddressSpace(AS));
2105 GV, CGF.
Builder.getPtrTy(
CGM.getContext().getTargetAddressSpace(
2114 auto I = FunctionGlobalizedDecls.find(CGF.
CurFn);
2115 if (I == FunctionGlobalizedDecls.end())
2117 auto VDI = I->getSecond().LocalVarData.find(VD);
2118 if (VDI != I->getSecond().LocalVarData.end())
2119 return VDI->second.PrivateAddr;
2124 auto VDI = I->getSecond().LocalVarData.find(
2126 ->getCanonicalDecl());
2127 if (VDI != I->getSecond().LocalVarData.end())
2128 return VDI->second.PrivateAddr;
2136 FunctionGlobalizedDecls.erase(CGF.
CurFn);
2143 llvm::Value *&Chunk)
const {
2146 ScheduleKind = OMPC_DIST_SCHEDULE_static;
2148 RT.getGPUNumThreads(CGF),
2150 S.getIterationVariable()->getType(), S.getBeginLoc());
2154 CGF, S, ScheduleKind, Chunk);
2160 const Expr *&ChunkExpr)
const {
2161 ScheduleKind = OMPC_SCHEDULE_static;
2163 llvm::APInt ChunkSize(32, 1);
2172 " Expected target-based directive.");
2173 const CapturedStmt *CS = D.getCapturedStmt(OMPD_target);
2177 if (!
C.capturesVariable())
2179 const VarDecl *VD =
C.getCapturedVar();
2180 const auto *RD = VD->
getType()
2184 if (!RD || !RD->isLambda())
2193 llvm::DenseMap<const ValueDecl *, FieldDecl *> Captures;
2195 RD->getCaptureFields(Captures, ThisCapture);
2205 const ValueDecl *VD = LC.getCapturedVar();
2210 auto It = Captures.find(VD);
2211 assert(It != Captures.end() &&
"Found lambda capture without field.");
2225 if (!VD || !VD->
hasAttr<OMPAllocateDeclAttr>())
2227 const auto *A = VD->
getAttr<OMPAllocateDeclAttr>();
2228 switch(A->getAllocatorType()) {
2229 case OMPAllocateDeclAttr::OMPNullMemAlloc:
2230 case OMPAllocateDeclAttr::OMPDefaultMemAlloc:
2232 case OMPAllocateDeclAttr::OMPLargeCapMemAlloc:
2233 case OMPAllocateDeclAttr::OMPCGroupMemAlloc:
2234 case OMPAllocateDeclAttr::OMPHighBWMemAlloc:
2235 case OMPAllocateDeclAttr::OMPLowLatMemAlloc:
2236 case OMPAllocateDeclAttr::OMPThreadMemAlloc:
2239 case OMPAllocateDeclAttr::OMPConstMemAlloc:
2242 case OMPAllocateDeclAttr::OMPPTeamMemAlloc:
2245 case OMPAllocateDeclAttr::OMPUserDefinedMemAlloc:
2246 llvm_unreachable(
"Expected predefined allocator for the variables with the "
2270 if (Clause->getClauseKind() == OMPC_unified_shared_memory) {
2283 llvm::raw_svector_ostream Out(Buffer);
2285 <<
" does not support unified addressing";
2286 CGM.Error(Clause->getBeginLoc(), Out.str());
2372 llvm_unreachable(
"Unexpected GPU arch.");
2382 const char *LocSize =
"__kmpc_get_hardware_num_threads_in_block";
2383 llvm::Function *F = M->getFunction(LocSize);
2385 F = llvm::Function::Create(llvm::FunctionType::get(CGF.
Int32Ty, {},
false),
2386 llvm::GlobalVariable::ExternalLinkage, LocSize,
2389 return Bld.CreateCall(F, {},
"nvptx_num_threads");
2396 CGM.getModule(), OMPRTL___kmpc_get_hardware_thread_id_in_block),
static void getTeamsReductionVars(ASTContext &Ctx, const OMPExecutableDirective &D, llvm::SmallVectorImpl< const ValueDecl * > &Vars)
Get list of reduction variables from the teams ... directives.
static llvm::Value * castValueToType(CodeGenFunction &CGF, llvm::Value *Val, QualType ValTy, QualType CastTy, SourceLocation Loc)
Cast value to the specified type.
static void getDistributeLastprivateVars(ASTContext &Ctx, const OMPExecutableDirective &D, llvm::SmallVectorImpl< const ValueDecl * > &Vars)
Get list of lastprivate variables from the teams distribute ... or teams {distribute ....
static bool hasNestedSPMDDirective(ASTContext &Ctx, const OMPExecutableDirective &D)
Check for inner (nested) SPMD construct, if any.
static bool supportsSPMDExecutionMode(ASTContext &Ctx, const OMPExecutableDirective &D)
static OffloadArch getOffloadArch(CodeGenModule &CGM)
This file defines OpenMP nodes for declarative directives.
This file defines OpenMP AST classes for clauses.
static std::pair< ValueDecl *, bool > getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc, SourceRange &ERange, bool AllowArraySection=false, bool AllowAssumedSizeArray=false, StringRef DiagType="")
This file defines OpenMP AST classes for executable directives and clauses.
static FieldDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getUIntPtrType() const
Return a type compatible with "uintptr_t" (C99 7.18.1.4), as defined by the target.
QualType getIntTypeForBitwidth(unsigned DestWidth, unsigned Signed) const
getIntTypeForBitwidth - sets integer QualTy according to specified details: bitwidth,...
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
QualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
const TargetInfo & getTargetInfo() const
Attr - This represents one attribute.
ArrayRef< Capture > captures() const
const BlockDecl * getBlockDecl() const
Describes the capture of either a variable, or 'this', or variable-length array type.
This captures a statement into a function.
bool capturesVariable(const VarDecl *Var) const
True if this variable has been captured.
CastKind getCastKind() const
CharUnits - This is an opaque type for sizes expressed in character units.
bool isZero() const
isZero - Test whether the quantity equals zero.
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
Address withElementType(llvm::Type *ElemTy) const
Return address with different element type, but same pointer and alignment.
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
Address CreatePointerBitCastOrAddrSpaceCast(Address Addr, llvm::Type *Ty, llvm::Type *ElementTy, const llvm::Twine &Name="")
Address CreateConstArrayGEP(Address Addr, uint64_t Index, const llvm::Twine &Name="")
Given addr = [n x T]* ... produce name = getelementptr inbounds addr, i64 0, i64 index where i64 is a...
Address CreateConstInBoundsGEP(Address Addr, uint64_t Index, const llvm::Twine &Name="")
Given addr = T* ... produce name = getelementptr inbounds addr, i64 index where i64 is actually the t...
CGFunctionInfo - Class to encapsulate the information about a function definition.
llvm::Function * emitTeamsOutlinedFunction(CodeGenFunction &CGF, const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen) override
Emits inlined function for the specified OpenMP teams.
void emitProcBindClause(CodeGenFunction &CGF, llvm::omp::ProcBindKind ProcBind, SourceLocation Loc) override
Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32global_tid, int proc_bind) to generate...
void emitReduction(CodeGenFunction &CGF, SourceLocation Loc, ArrayRef< const Expr * > Privates, ArrayRef< const Expr * > LHSExprs, ArrayRef< const Expr * > RHSExprs, ArrayRef< const Expr * > ReductionOps, ReductionOptionsTy Options) override
Emit a code for reduction clause.
DataSharingMode
Target codegen is specialized based on two data-sharing modes: CUDA, in which the local variables are...
@ DS_CUDA
CUDA data sharing mode.
@ DS_Generic
Generic data-sharing mode.
void getDefaultDistScheduleAndChunk(CodeGenFunction &CGF, const OMPLoopDirective &S, OpenMPDistScheduleClauseKind &ScheduleKind, llvm::Value *&Chunk) const override
Choose a default value for the dist_schedule clause.
Address getAddressOfLocalVariable(CodeGenFunction &CGF, const VarDecl *VD) override
Gets the OpenMP-specific address of the local variable.
void emitFunctionProlog(CodeGenFunction &CGF, const Decl *D) override
Emits OpenMP-specific function prolog.
void getDefaultScheduleAndChunk(CodeGenFunction &CGF, const OMPLoopDirective &S, OpenMPScheduleClauseKind &ScheduleKind, const Expr *&ChunkExpr) const override
Choose a default value for the schedule clause.
void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams, const Expr *ThreadLimit, SourceLocation Loc) override
This function ought to emit, in the general case, a call to.
void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName, const RegionCodeGenTy &CriticalOpGen, SourceLocation Loc, const Expr *Hint=nullptr) override
Emits a critical region.
void emitTeamsCall(CodeGenFunction &CGF, const OMPExecutableDirective &D, SourceLocation Loc, llvm::Function *OutlinedFn, ArrayRef< llvm::Value * > CapturedVars) override
Emits code for teams call of the OutlinedFn with variables captured in a record which address is stor...
bool hasAllocateAttributeForGlobalVar(const VarDecl *VD, LangAS &AS) override
Checks if the variable has associated OMPAllocateDeclAttr attribute with the predefined allocator and...
void getKmpcFreeShared(CodeGenFunction &CGF, const std::pair< llvm::Value *, llvm::Value * > &AddrSizePair) override
Get call to __kmpc_free_shared.
CGOpenMPRuntimeGPU(CodeGenModule &CGM)
llvm::Function * emitParallelOutlinedFunction(CodeGenFunction &CGF, const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen) override
Emits inlined function for the specified OpenMP parallel.
void functionFinished(CodeGenFunction &CGF) override
Cleans up references to the objects in finished function.
llvm::Value * getGPUThreadID(CodeGenFunction &CGF)
Get the id of the current thread on the GPU.
void processRequiresDirective(const OMPRequiresDecl *D) override
Perform check on requires decl to ensure that target architecture supports unified addressing.
bool isDelayedVariableLengthDecl(CodeGenFunction &CGF, const VarDecl *VD) const override
Declare generalized virtual functions which need to be defined by all specializations of OpenMPGPURun...
void emitOutlinedFunctionCall(CodeGenFunction &CGF, SourceLocation Loc, llvm::FunctionCallee OutlinedFn, ArrayRef< llvm::Value * > Args={}) const override
Emits call of the outlined function with the provided arguments, translating these arguments to corre...
Address getParameterAddress(CodeGenFunction &CGF, const VarDecl *NativeParam, const VarDecl *TargetParam) const override
Gets the address of the native argument basing on the address of the target-specific parameter.
ExecutionMode
Defines the execution mode.
@ EM_NonSPMD
Non-SPMD execution mode (1 master thread, others are workers).
@ EM_Unknown
Unknown execution mode (orphaned directive).
@ EM_SPMD
SPMD execution mode (all threads are worker threads).
void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDirectiveKind Kind, bool EmitChecks=true, bool ForceSimpleCall=false) override
Emit an implicit/explicit barrier for OpenMP threads.
llvm::Value * getGPUNumThreads(CodeGenFunction &CGF)
Get the maximum number of threads in a block of the GPU.
const VarDecl * translateParameter(const FieldDecl *FD, const VarDecl *NativeParam) const override
Translates the native parameter of outlined function if this is required for target.
std::pair< llvm::Value *, llvm::Value * > getKmpcAllocShared(CodeGenFunction &CGF, const VarDecl *VD) override
Get call to __kmpc_alloc_shared.
bool isGPU() const override
Returns true if the current target is a GPU.
virtual llvm::Value * emitSeverityClause(OpenMPSeverityClauseKind Severity, SourceLocation Loc) override
llvm::Value * emitMessageClause(CodeGenFunction &CGF, const Expr *Message, SourceLocation Loc) override
void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc, llvm::Function *OutlinedFn, ArrayRef< llvm::Value * > CapturedVars, const Expr *IfCond, llvm::Value *NumThreads, OpenMPNumThreadsClauseModifier NumThreadsModifier=OMPC_NUMTHREADS_unknown, OpenMPSeverityClauseKind Severity=OMPC_SEVERITY_fatal, const Expr *Message=nullptr) override
Emits code for parallel or serial call of the OutlinedFn with variables captured in a record which ad...
void emitNumThreadsClause(CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc, OpenMPNumThreadsClauseModifier Modifier=OMPC_NUMTHREADS_unknown, OpenMPSeverityClauseKind Severity=OMPC_SEVERITY_fatal, SourceLocation SeverityLoc=SourceLocation(), const Expr *Message=nullptr, SourceLocation MessageLoc=SourceLocation()) override
Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32global_tid, kmp_int32 num_threads) ...
void adjustTargetSpecificDataForLambdas(CodeGenFunction &CGF, const OMPExecutableDirective &D) const override
Adjust some parameters for the target-based directives, like addresses of the variables captured by r...
virtual Address emitThreadIDAddress(CodeGenFunction &CGF, SourceLocation Loc)
Emits address of the word in a memory where current thread id is stored.
CGOpenMPRuntime(CodeGenModule &CGM)
static const Stmt * getSingleCompoundChild(ASTContext &Ctx, const Stmt *Body)
Checks if the Body is the CompoundStmt and returns its child statement iff there is only one that is ...
llvm::Value * emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc, unsigned Flags=0, bool EmitLoc=false)
Emits object of ident_t type with info for source location.
virtual void functionFinished(CodeGenFunction &CGF)
Cleans up references to the objects in finished function.
virtual llvm::Function * emitTeamsOutlinedFunction(CodeGenFunction &CGF, const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen)
Emits outlined function for the specified OpenMP teams directive D.
llvm::OpenMPIRBuilder OMPBuilder
An OpenMP-IR-Builder instance.
virtual void emitTargetOutlinedFunctionHelper(const OMPExecutableDirective &D, StringRef ParentName, llvm::Function *&OutlinedFn, llvm::Constant *&OutlinedFnID, bool IsOffloadEntry, const RegionCodeGenTy &CodeGen)
Helper to emit outlined function for 'target' directive.
bool hasRequiresUnifiedSharedMemory() const
Return whether the unified_shared_memory has been specified.
virtual void processRequiresDirective(const OMPRequiresDecl *D)
Perform check on requires decl to ensure that target architecture supports unified addressing.
llvm::Value * getThreadID(CodeGenFunction &CGF, SourceLocation Loc)
Gets thread id value for the current thread.
void computeMinAndMaxThreadsAndTeams(const OMPExecutableDirective &D, CodeGenFunction &CGF, llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &Attrs)
Helper to determine the min/max number of threads/teams for D.
static unsigned getDefaultFlagsForBarriers(OpenMPDirectiveKind Kind)
Returns default flags for the barriers depending on the directive, for which this barier is going to ...
virtual llvm::Function * emitParallelOutlinedFunction(CodeGenFunction &CGF, const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen)
Emits outlined function for the specified OpenMP parallel directive D.
virtual void getDefaultDistScheduleAndChunk(CodeGenFunction &CGF, const OMPLoopDirective &S, OpenMPDistScheduleClauseKind &ScheduleKind, llvm::Value *&Chunk) const
Choose default schedule type and chunk value for the dist_schedule clause.
llvm::Type * getIdentTyPointerTy()
Returns pointer to ident_t type.
void emitSingleReductionCombiner(CodeGenFunction &CGF, const Expr *ReductionOp, const Expr *PrivateRef, const DeclRefExpr *LHS, const DeclRefExpr *RHS)
Emits single reduction combiner.
llvm::OpenMPIRBuilder & getOMPBuilder()
virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName, const RegionCodeGenTy &CriticalOpGen, SourceLocation Loc, const Expr *Hint=nullptr)
Emits a critical region.
virtual void emitOutlinedFunctionCall(CodeGenFunction &CGF, SourceLocation Loc, llvm::FunctionCallee OutlinedFn, ArrayRef< llvm::Value * > Args={}) const
Emits call of the outlined function with the provided arguments, translating these arguments to corre...
virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc, ArrayRef< const Expr * > Privates, ArrayRef< const Expr * > LHSExprs, ArrayRef< const Expr * > RHSExprs, ArrayRef< const Expr * > ReductionOps, ReductionOptionsTy Options)
Emit a code for reduction clause.
CapturedRegionKind getKind() const
bool isCXXThisExprCaptured() const
The scope used to remap some variables as private in the OpenMP loop body (or other captured region e...
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
LValue EmitLoadOfReferenceLValue(LValue RefLVal)
CGCapturedStmtInfo * CapturedStmtInfo
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
Address EmitLoadOfPointer(Address Ptr, const PointerType *PtrTy, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
Load a pointer with type PtrTy stored at address Ptr.
LValue MakeNaturalAlignPointeeRawAddrLValue(llvm::Value *V, QualType T)
Same as MakeNaturalAlignPointeeAddrLValue except that the pointer is known to be unsigned.
llvm::AssertingVH< llvm::Instruction > AllocaInsertPt
AllocaInsertPoint - This is an instruction in the entry block before which we prefer to insert alloca...
llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Location)
Converts Location to a DebugLoc, if debug information is enabled.
RawAddress CreateDefaultAlignTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
CreateDefaultAlignedTempAlloca - This creates an alloca with the default ABI alignment of the given L...
const TargetInfo & getTarget() const
void StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn, const CGFunctionInfo &FnInfo, const FunctionArgList &Args, SourceLocation Loc=SourceLocation(), SourceLocation StartLoc=SourceLocation())
Emit code for the start of a function.
llvm::Value * EvaluateExprAsBool(const Expr *E)
EvaluateExprAsBool - Perform the usual unary conversions on the specified expression and compare the ...
bool HaveInsertPoint() const
HaveInsertPoint - True if an insertion point is defined.
CGDebugInfo * getDebugInfo()
llvm::Value * getTypeSize(QualType Ty)
Returns calculated size of the specified type.
LValue EmitLValueForFieldInitialization(LValue Base, const FieldDecl *Field)
EmitLValueForFieldInitialization - Like EmitLValueForField, except that if the Field is a reference,...
ASTContext & getContext() const
llvm::Value * EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty, SourceLocation Loc, AlignmentSource Source=AlignmentSource::Type, bool isNontemporal=false)
EmitLoadOfScalar - Load a scalar value from an address, taking care to appropriately convert from the...
llvm::CallInst * EmitRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
llvm::Type * ConvertTypeForMem(QualType T)
CodeGenTypes & getTypes() const
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
void EmitBranch(llvm::BasicBlock *Block)
EmitBranch - Emit a branch to the specified basic block from the current insert block,...
RawAddress CreateMemTemp(QualType T, const Twine &Name="tmp", RawAddress *Alloca=nullptr)
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen and cas...
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
llvm::Value * LoadCXXThis()
LoadCXXThis - Load the value of 'this'.
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
llvm::LLVMContext & getLLVMContext()
llvm::Value * EmitScalarConversion(llvm::Value *Src, QualType SrcTy, QualType DstTy, SourceLocation Loc)
Emit a conversion from the specified type to the specified destination type, both of which are LLVM s...
void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, QualType Ty, AlignmentSource Source=AlignmentSource::Type, bool isInit=false, bool isNontemporal=false)
EmitStoreOfScalar - Store a scalar value to an address, taking care to appropriately convert from the...
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
This class organizes the cross-function state that is used while generating LLVM code.
void SetInternalFunctionAttributes(GlobalDecl GD, llvm::Function *F, const CGFunctionInfo &FI)
Set the attributes on the LLVM function for the given decl and function info.
llvm::Module & getModule() const
CodeGenTypes & getTypes()
const TargetInfo & getTarget() const
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
ASTContext & getContext() const
llvm::LLVMContext & getLLVMContext()
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
const CGFunctionInfo & arrangeBuiltinFunctionDeclaration(QualType resultType, const FunctionArgList &args)
A builtin function is a freestanding function using the default C conventions.
unsigned getTargetAddressSpace(QualType T) const
FunctionArgList - Type for representing both the decl and type of parameters to a function.
LValue - This represents an lvalue references.
Address getAddress() const
A basic class for pre|post-action for advanced codegen sequence for OpenMP region.
An abstract representation of an aligned address.
llvm::Value * getPointer() const
Class provides a way to call simple version of codegen for OpenMP region, or an advanced with possibl...
void setAction(PrePostActionTy &Action) const
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
void addDecl(Decl *D)
Add the declaration D into this context.
attr_iterator attr_end() const
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
attr_iterator attr_begin() const
SourceLocation getLocation() const
DeclContext * getDeclContext()
SourceLocation getBeginLoc() const LLVM_READONLY
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
SourceLocation getBeginLoc() const LLVM_READONLY
This represents one expression.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
Represents a member of a struct/union/class.
static FieldDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)
GlobalDecl - represents a global declaration.
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)
Create implicit parameter.
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Describes the capture of a variable or of this, or of a C++1y init-capture.
bool isInitCapture(const LambdaCapture *Capture) const
Determine whether one of this lambda's captures is an init-capture.
capture_range captures() const
Retrieve this lambda's captures.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
This is a basic class for representing single OpenMP clause.
This represents clause 'lastprivate' in the 'pragma omp ...' directives.
This represents clause 'reduction' in the 'pragma omp ...' directives.
This represents 'pragma omp requires...' directive.
clauselist_range clauselists()
This represents 'ompx_bare' clause in the 'pragma omp target teams ...' directive.
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
LangAS getAddressSpace() const
Return the address space of this type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getCanonicalType() const
A qualifier set is used to build a set of qualifiers.
const Type * strip(QualType type)
Collect any qualifiers on the given type and return an unqualified type.
QualType apply(const ASTContext &Context, QualType QT) const
Apply the collected qualifiers to the given type.
void addAddressSpace(LangAS space)
Represents a struct/union/class.
virtual void completeDefinition()
Note that the definition of this type is now complete.
Scope - A scope is a transient data structure that is used while parsing the program.
Encodes a location in the source.
Stmt - This represents one statement.
void startDefinition()
Starts the definition of this tag declaration.
unsigned getNewAlign() const
Return the largest alignment for which a suitably-sized allocation with 'operator new(size_t)' is gua...
TargetOptions & getTargetOpts() const
Retrieve the target options.
virtual const llvm::omp::GV & getGridValue() const
virtual bool hasFeature(StringRef Feature) const
Determine whether the given target has the given feature.
llvm::StringMap< bool > FeatureMap
The map of which features have been enabled disabled based on the command line.
The base class of the type hierarchy.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
bool isReferenceType() const
bool isLValueReferenceType() const
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g....
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
Expr * getSubExpr() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Represents a variable declaration or definition.
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
specific_attr_iterator - Iterates over a subrange of an AttrVec, only providing attributes that are o...
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
bool isa(CodeGen::Address addr)
@ ICIS_NoInit
No in-class initializer.
bool isOpenMPDistributeDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a distribute directive.
@ LCK_ByRef
Capturing by reference.
@ Private
'private' clause, allowed on 'parallel', 'serial', 'loop', 'parallel loop', and 'serial loop' constru...
bool isOpenMPParallelDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a parallel-kind directive.
bool isOpenMPPrivate(OpenMPClauseKind Kind)
Checks if the specified clause is one of private clauses like 'private', 'firstprivate',...
OpenMPDistScheduleClauseKind
OpenMP attributes for 'dist_schedule' clause.
bool isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a target code offload directive.
bool isOpenMPTeamsDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a teams-kind directive.
OffloadArch StringToOffloadArch(llvm::StringRef S)
OpenMPSeverityClauseKind
OpenMP attributes for 'severity' clause.
bool isOpenMPLoopBoundSharingDirective(OpenMPDirectiveKind Kind)
Checks if the specified directive kind is one of the composite or combined directives that need loop ...
LangAS
Defines the address space values used by the address space qualifier of QualType.
const char * OffloadArchToString(OffloadArch A)
llvm::omp::Directive OpenMPDirectiveKind
OpenMP directives.
void getOpenMPCaptureRegions(llvm::SmallVectorImpl< OpenMPDirectiveKind > &CaptureRegions, OpenMPDirectiveKind DKind)
Return the captured regions of an OpenMP directive.
OpenMPNumThreadsClauseModifier
U cast(CodeGen::Address addr)
LangAS getLangASFromTargetAS(unsigned TargetAS)
@ CXXThis
Parameter for C++ 'this' argument.
@ Other
Other implicit parameter.
OpenMPScheduleClauseKind
OpenMP attributes for 'schedule' clause.
OpenMPDirectiveKind ReductionKind
llvm::PointerType * VoidPtrTy
llvm::IntegerType * SizeTy
llvm::PointerType * VoidPtrPtrTy
llvm::IntegerType * Int32Ty