diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.h b/clang/lib/CodeGen/CGOpenMPRuntime.h --- a/clang/lib/CodeGen/CGOpenMPRuntime.h +++ b/clang/lib/CodeGen/CGOpenMPRuntime.h @@ -862,10 +862,6 @@ llvm::Function *TaskFunction, QualType SharedsTy, Address Shareds, const OMPTaskDataTy &Data); - /// Returns default address space for the constant firstprivates, 0 by - /// default. - virtual unsigned getDefaultFirstprivateAddressSpace() const { return 0; } - /// Emit code that pushes the trip count of loops associated with constructs /// 'target teams distribute' and 'teams distribute parallel for'. /// \param SizeEmitter Emits the int64 value for the number of iterations of @@ -1591,11 +1587,6 @@ virtual void registerTargetGlobalVariable(const VarDecl *VD, llvm::Constant *Addr); - /// Registers provided target firstprivate variable as global on the - /// target. - llvm::Constant *registerTargetFirstprivateCopy(CodeGenFunction &CGF, - const VarDecl *VD); - /// Emit the global \a GD if it is meaningful for the target. Returns /// if it was emitted successfully. /// \param GD Global to scan. diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -8224,10 +8224,6 @@ // 'private ptr' and 'map to' flag. Return the right flags if the captured // declaration is known as first-private in this handler. if (FirstPrivateDecls.count(Cap.getCapturedVar())) { - if (Cap.getCapturedVar()->getType().isConstant(CGF.getContext()) && - Cap.getCaptureKind() == CapturedStmt::VCK_ByRef) - return MappableExprsHandler::OMP_MAP_ALWAYS | - MappableExprsHandler::OMP_MAP_TO; if (Cap.getCapturedVar()->getType()->isAnyPointerType()) return MappableExprsHandler::OMP_MAP_TO | MappableExprsHandler::OMP_MAP_PTR_AND_OBJ; @@ -9163,30 +9159,15 @@ CombinedInfo.Types.push_back(getMapModifiersForPrivateClauses(CI)); const VarDecl *VD = CI.getCapturedVar(); auto I = FirstPrivateDecls.find(VD); - if (I != FirstPrivateDecls.end() && - VD->getType().isConstant(CGF.getContext())) { - llvm::Constant *Addr = - CGF.CGM.getOpenMPRuntime().registerTargetFirstprivateCopy(CGF, VD); - // Copy the value of the original variable to the new global copy. - CGF.Builder.CreateMemCpy( - CGF.MakeNaturalAlignAddrLValue(Addr, ElementType).getAddress(CGF), - Address(CV, CGF.getContext().getTypeAlignInChars(ElementType)), - CombinedInfo.Sizes.back(), /*IsVolatile=*/false); - // Use new global variable as the base pointers. - CombinedInfo.Exprs.push_back(VD->getCanonicalDecl()); - CombinedInfo.BasePointers.push_back(Addr); - CombinedInfo.Pointers.push_back(Addr); + CombinedInfo.Exprs.push_back(VD->getCanonicalDecl()); + CombinedInfo.BasePointers.push_back(CV); + if (I != FirstPrivateDecls.end() && ElementType->isAnyPointerType()) { + Address PtrAddr = CGF.EmitLoadOfReference(CGF.MakeAddrLValue( + CV, ElementType, CGF.getContext().getDeclAlign(VD), + AlignmentSource::Decl)); + CombinedInfo.Pointers.push_back(PtrAddr.getPointer()); } else { - CombinedInfo.Exprs.push_back(VD->getCanonicalDecl()); - CombinedInfo.BasePointers.push_back(CV); - if (I != FirstPrivateDecls.end() && ElementType->isAnyPointerType()) { - Address PtrAddr = CGF.EmitLoadOfReference(CGF.MakeAddrLValue( - CV, ElementType, CGF.getContext().getDeclAlign(VD), - AlignmentSource::Decl)); - CombinedInfo.Pointers.push_back(PtrAddr.getPointer()); - } else { - CombinedInfo.Pointers.push_back(CV); - } + CombinedInfo.Pointers.push_back(CV); } if (I != FirstPrivateDecls.end()) IsImplicit = I->getSecond(); @@ -10579,45 +10560,6 @@ return false; } -llvm::Constant * -CGOpenMPRuntime::registerTargetFirstprivateCopy(CodeGenFunction &CGF, - const VarDecl *VD) { - assert(VD->getType().isConstant(CGM.getContext()) && - "Expected constant variable."); - StringRef VarName; - llvm::Constant *Addr; - llvm::GlobalValue::LinkageTypes Linkage; - QualType Ty = VD->getType(); - SmallString<128> Buffer; - { - unsigned DeviceID; - unsigned FileID; - unsigned Line; - getTargetEntryUniqueInfo(CGM.getContext(), VD->getLocation(), DeviceID, - FileID, Line); - llvm::raw_svector_ostream OS(Buffer); - OS << "__omp_offloading_firstprivate_" << llvm::format("_%x", DeviceID) - << llvm::format("_%x_", FileID); - if (CGM.getLangOpts().CPlusPlus) { - CGM.getCXXABI().getMangleContext().mangleTypeName(VD->getType(), OS); - OS << "_"; - } - OS << VD->getName() << "_l" << Line; - VarName = OS.str(); - } - Linkage = llvm::GlobalValue::InternalLinkage; - Addr = - getOrCreateInternalVariable(CGM.getTypes().ConvertTypeForMem(Ty), VarName, - getDefaultFirstprivateAddressSpace()); - cast(Addr)->setLinkage(Linkage); - CharUnits VarSize = CGM.getContext().getTypeSizeInChars(Ty); - CGM.addCompilerUsedGlobal(cast(Addr)); - OffloadEntriesInfoManager.registerDeviceGlobalVarEntryInfo( - VarName, Addr, VarSize, - OffloadEntriesInfoManagerTy::OMPTargetGlobalVarEntryTo, Linkage); - return Addr; -} - void CGOpenMPRuntime::registerTargetGlobalVariable(const VarDecl *VD, llvm::Constant *Addr) { if (CGM.getLangOpts().OMPTargetTriples.empty() && diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.h b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.h --- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.h +++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.h @@ -399,10 +399,6 @@ /// supports unified addressing void processRequiresDirective(const OMPRequiresDecl *D) override; - /// Returns default address space for the constant firstprivates, __constant__ - /// address space by default. - unsigned getDefaultFirstprivateAddressSpace() const override; - /// Checks if the variable has associated OMPAllocateDeclAttr attribute with /// the predefined allocator and translates it into the corresponding address /// space. diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp --- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp @@ -3646,10 +3646,6 @@ if (Attr->getCaptureKind() == OMPC_map) { PointeeTy = CGM.getContext().getAddrSpaceQualType(PointeeTy, LangAS::opencl_global); - } else if (Attr->getCaptureKind() == OMPC_firstprivate && - PointeeTy.isConstant(CGM.getContext())) { - PointeeTy = CGM.getContext().getAddrSpaceQualType(PointeeTy, - LangAS::opencl_generic); } } ArgType = CGM.getContext().getPointerType(PointeeTy); @@ -4084,10 +4080,6 @@ } } -unsigned CGOpenMPRuntimeGPU::getDefaultFirstprivateAddressSpace() const { - return CGM.getContext().getTargetAddressSpace(LangAS::cuda_constant); -} - bool CGOpenMPRuntimeGPU::hasAllocateAttributeForGlobalVar(const VarDecl *VD, LangAS &AS) { if (!VD || !VD->hasAttr()) diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -786,9 +786,6 @@ OMPPrivateScope &PrivateScope) { if (!HaveInsertPoint()) return false; - bool DeviceConstTarget = - getLangOpts().OpenMPIsDevice && - isOpenMPTargetExecutionDirective(D.getDirectiveKind()); bool FirstprivateIsLastprivate = false; llvm::DenseMap Lastprivates; for (const auto *C : D.getClausesOfKind()) { @@ -821,17 +818,6 @@ ++InitsRef; continue; } - // Do not emit copy for firstprivate constant variables in target regions, - // captured by reference. - if (DeviceConstTarget && OrigVD->getType().isConstant(getContext()) && - FD && FD->getType()->isReferenceType() && - (!VD || !VD->hasAttr())) { - (void)CGM.getOpenMPRuntime().registerTargetFirstprivateCopy(*this, - OrigVD); - ++IRef; - ++InitsRef; - continue; - } FirstprivateIsLastprivate = FirstprivateIsLastprivate || ThisFirstprivateIsLastprivate; if (EmittedAsFirstprivate.insert(OrigVD->getCanonicalDecl()).second) { diff --git a/clang/test/OpenMP/nvptx_target_firstprivate_codegen.cpp b/clang/test/OpenMP/nvptx_target_firstprivate_codegen.cpp --- a/clang/test/OpenMP/nvptx_target_firstprivate_codegen.cpp +++ b/clang/test/OpenMP/nvptx_target_firstprivate_codegen.cpp @@ -18,9 +18,6 @@ // TCHECK-DAG: [[TT:%.+]] = type { i64, i8 } // TCHECK-DAG: [[S1:%.+]] = type { double } -// TCHECK: @__omp_offloading_firstprivate__{{.+}}_e_l30 = internal addrspace(4) global [[TTII]] zeroinitializer -// TCHECK: @__omp_offloading_firstprivate__{{.+}}_ZTSK2TTIiiE_t_l143 = internal addrspace(4) global [[TTII]] zeroinitializer -// TCHECK: @__omp_offloading_firstprivate__{{.+}}_ZTSK2TTIccE_t_l143 = internal addrspace(4) global [[TTIC]] zeroinitializer int foo(int n, double *ptr) { int a = 0; short aa = 0; @@ -37,11 +34,9 @@ } // TCHECK: define {{.*}}void @__omp_offloading_{{.+}}([10 x float] addrspace(1)* noalias [[B_IN:%.+]], i{{[0-9]+}} [[A_IN:%.+]], [[TTII]]* noalias [[E_IN:%.+]]) - // TCHECK-NOT: alloca [[TTII]], // TCHECK: [[A_ADDR:%.+]] = alloca i{{[0-9]+}}, - // TCHECK-NOT: alloca [[TTII]], - // TCHECK-NOT: alloca i{{[0-9]+}}, - // TCHECK-64: call void @llvm.dbg.declare(metadata [10 x float] addrspace(1)** %{{.+}}, metadata !{{[0-9]+}}, metadata !DIExpression()) + // TCHECK: alloca [[TTII]], + // TCHECK: alloca i{{[0-9]+}}, // TCHECK: store i{{[0-9]+}} [[A_IN]], i{{[0-9]+}}* [[A_ADDR]], // TCHECK: ret void diff --git a/clang/test/OpenMP/target_firstprivate_codegen.cpp b/clang/test/OpenMP/target_firstprivate_codegen.cpp --- a/clang/test/OpenMP/target_firstprivate_codegen.cpp +++ b/clang/test/OpenMP/target_firstprivate_codegen.cpp @@ -55,12 +55,11 @@ // TCHECK-DAG: [[TTII:%.+]] = type { i32, i32 } // TCHECK-DAG: [[S1:%.+]] = type { double } -// CHECK-DAG: [[FP_E:@__omp_offloading_firstprivate_.+_e_l79]] = internal global [[TTII]] zeroinitializer // CHECK-DAG: [[SIZET:@.+]] = private unnamed_addr constant [3 x i{{32|64}}] [i[[SZ:32|64]] 4, i{{64|32}} {{8|4}}, i[[SZ:32|64]] 4] // CHECK-DAG: [[MAPT:@.+]] = private unnamed_addr constant [3 x i64] [i64 288, i64 49, i64 288] // CHECK-DAG: [[MAPT2:@.+]] = private unnamed_addr constant [9 x i64] [i64 288, i64 161, i64 800, i64 161, i64 161, i64 800, i64 800, i64 161, i64 161] // CHECK-DAG: [[SIZET3:@.+]] = private unnamed_addr constant [2 x i{{32|64}}] [i{{32|64}} 0, i{{32|64}} 8] -// CHECK-DAG: [[MAPT3:@.+]] = private unnamed_addr constant [2 x i64] [i64 32, i64 37] +// CHECK-DAG: [[MAPT3:@.+]] = private unnamed_addr constant [2 x i64] [i64 32, i64 161] // CHECK-DAG: [[MAPT4:@.+]] = private unnamed_addr constant [5 x i64] [i64 547, i64 288, i64 800, i64 800, i64 161] // CHECK-DAG: [[SIZET5:@.+]] = private unnamed_addr constant [3 x i{{32|64}}] [i[[SZ]] 4, i[[SZ]] 1, i[[SZ]] 40] // CHECK-DAG: [[MAPT5:@.+]] = private unnamed_addr constant [3 x i64] [i64 288, i64 288, i64 161] @@ -92,6 +91,7 @@ // CHECK: [[SSTACK:%.+]] = alloca i8*, // CHECK: [[C:%.+]] = alloca [5 x [10 x double]], // CHECK: [[D:%.+]] = alloca [[TT]], + // CHECK: [[FP_E:%.+]] = alloca [[TTII]], // CHECK: [[P:%.+]] = alloca i32*, align 64 // CHECK: [[ACAST:%.+]] = alloca i{{[0-9]+}}, // CHECK: [[BASE_PTR_ARR:%.+]] = alloca [3 x i8*], @@ -347,8 +347,6 @@ } // CHECK: [[PTR_ADDR_REF:%.+]] = load double*, double** [[PTR_ADDR]], - // CHECK: [[E_BC:%.+]] = bitcast [[TTII]]* [[E:%.+]] to i8* - // CHECK: call void @llvm.memcpy.p0i8.p0i8.i{{64|32}}(i8* {{.*}} bitcast ([[TTII]]* [[FP_E]] to i8*), i8* {{.*}} [[E_BC]], i{{64|32}} 8, i1 false) // CHECK: [[BASE_PTR_GEP3_0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BASE_PTR_ARR3]], i{{[0-9]+}} 0, i{{[0-9]+}} 0 // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTR_GEP3_0]] to double** // CHECK: store double* [[PTR_ADDR_REF]], double** [[BCAST_TOPTR]], @@ -367,9 +365,8 @@ // CHECK: {{.+}} = call i32 @__tgt_target_mapper(%struct.ident_t* @{{.+}}, i64 -1, {{.+}}, i32 2, i8** [[BASE_PTR_GEP_ARG3]], i8** [[PTR_GEP_ARG3]], i[[SZ]]* getelementptr inbounds ([2 x i[[SZ]]], [2 x i[[SZ]]]* [[SIZET3]], i32 0, i32 0), i64* getelementptr inbounds ([2 x i64], [2 x i64]* [[MAPT3]], i32 0, i32 0), i8** null, i8** null) // TCHECK: define weak void @__omp_offloading_{{.+}}(double* [[PTR_IN:%.+]], [[TTII]]* nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) [[E:%.+]]) - // TCHECK-NOT: alloca [[TTII]], // TCHECK: [[PTR_ADDR:%.+]] = alloca double*, - // TCHECK-NOT: alloca [[TTII]], + // TCHECK: alloca [[TTII]], // TCHECK-NOT: alloca double*, // TCHECK: store double* [[PTR_IN]], double** [[PTR_ADDR]], // TCHECK-NOT: store double* %