forked from OSchip/llvm-project
[OpenMP] Fix map clause for unused var: don't ignore it
For example, without this patch: ``` $ cat test.c int main() { int x[3]; #pragma omp target map(tofrom:x[0:3]) #ifdef USE x[0] = 1 #endif ; return 0; } $ clang -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -S -emit-llvm test.c $ grep '^@.offload_maptypes' test.ll $ echo $? 1 $ clang -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -S -emit-llvm test.c \ -DUSE $ grep '^@.offload_maptypes' test.ll @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 35] ``` With this patch, both greps produce the same result. Reviewed By: ABataev Differential Revision: https://reviews.llvm.org/D83922
This commit is contained in:
parent
c12f111846
commit
cbf64b5834
|
@ -7977,7 +7977,10 @@ public:
|
||||||
/// CombinedInfo). Also, for each item that relates with a device pointer, a
|
/// CombinedInfo). Also, for each item that relates with a device pointer, a
|
||||||
/// pair of the relevant declaration and index where it occurs is appended to
|
/// pair of the relevant declaration and index where it occurs is appended to
|
||||||
/// the device pointers info array.
|
/// the device pointers info array.
|
||||||
void generateAllInfo(MapCombinedInfoTy &CombinedInfo) const {
|
void generateAllInfo(
|
||||||
|
MapCombinedInfoTy &CombinedInfo,
|
||||||
|
const llvm::DenseSet<CanonicalDeclPtr<const Decl>> &SkipVarSet =
|
||||||
|
llvm::DenseSet<CanonicalDeclPtr<const Decl>>()) const {
|
||||||
// We have to process the component lists that relate with the same
|
// We have to process the component lists that relate with the same
|
||||||
// declaration in a single chunk so that we can generate the map flags
|
// declaration in a single chunk so that we can generate the map flags
|
||||||
// correctly. Therefore, we organize all lists in a map.
|
// correctly. Therefore, we organize all lists in a map.
|
||||||
|
@ -7986,14 +7989,17 @@ public:
|
||||||
// Helper function to fill the information map for the different supported
|
// Helper function to fill the information map for the different supported
|
||||||
// clauses.
|
// clauses.
|
||||||
auto &&InfoGen =
|
auto &&InfoGen =
|
||||||
[&Info](const ValueDecl *D,
|
[&Info, &SkipVarSet](
|
||||||
OMPClauseMappableExprCommon::MappableExprComponentListRef L,
|
const ValueDecl *D,
|
||||||
OpenMPMapClauseKind MapType,
|
OMPClauseMappableExprCommon::MappableExprComponentListRef L,
|
||||||
ArrayRef<OpenMPMapModifierKind> MapModifiers,
|
OpenMPMapClauseKind MapType,
|
||||||
bool ReturnDevicePointer, bool IsImplicit,
|
ArrayRef<OpenMPMapModifierKind> MapModifiers,
|
||||||
const ValueDecl *Mapper, bool ForDeviceAddr = false) {
|
bool ReturnDevicePointer, bool IsImplicit, const ValueDecl *Mapper,
|
||||||
|
bool ForDeviceAddr = false) {
|
||||||
const ValueDecl *VD =
|
const ValueDecl *VD =
|
||||||
D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
|
D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
|
||||||
|
if (SkipVarSet.count(VD))
|
||||||
|
return;
|
||||||
Info[VD].emplace_back(L, MapType, MapModifiers, ReturnDevicePointer,
|
Info[VD].emplace_back(L, MapType, MapModifiers, ReturnDevicePointer,
|
||||||
IsImplicit, Mapper, ForDeviceAddr);
|
IsImplicit, Mapper, ForDeviceAddr);
|
||||||
};
|
};
|
||||||
|
@ -8561,38 +8567,6 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate the base pointers, section pointers, sizes, map types, and
|
|
||||||
/// mappers associated with the declare target link variables (all included in
|
|
||||||
/// \a CombinedInfo).
|
|
||||||
void generateInfoForDeclareTargetLink(MapCombinedInfoTy &CombinedInfo) const {
|
|
||||||
assert(CurDir.is<const OMPExecutableDirective *>() &&
|
|
||||||
"Expect a executable directive");
|
|
||||||
const auto *CurExecDir = CurDir.get<const OMPExecutableDirective *>();
|
|
||||||
// Map other list items in the map clause which are not captured variables
|
|
||||||
// but "declare target link" global variables.
|
|
||||||
for (const auto *C : CurExecDir->getClausesOfKind<OMPMapClause>()) {
|
|
||||||
for (const auto L : C->component_lists()) {
|
|
||||||
if (!std::get<0>(L))
|
|
||||||
continue;
|
|
||||||
const auto *VD = dyn_cast_or_null<VarDecl>(std::get<0>(L));
|
|
||||||
if (!VD)
|
|
||||||
continue;
|
|
||||||
llvm::Optional<OMPDeclareTargetDeclAttr::MapTypeTy> Res =
|
|
||||||
OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD);
|
|
||||||
if (CGF.CGM.getOpenMPRuntime().hasRequiresUnifiedSharedMemory() ||
|
|
||||||
!Res || *Res != OMPDeclareTargetDeclAttr::MT_Link)
|
|
||||||
continue;
|
|
||||||
StructRangeInfoTy PartialStruct;
|
|
||||||
generateInfoForComponentList(
|
|
||||||
C->getMapType(), C->getMapTypeModifiers(), std::get<1>(L),
|
|
||||||
CombinedInfo, PartialStruct, /*IsFirstComponentList=*/true,
|
|
||||||
C->isImplicit());
|
|
||||||
assert(!PartialStruct.Base.isValid() &&
|
|
||||||
"No partial structs for declare target link expected.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Generate the default map information for a given capture \a CI,
|
/// Generate the default map information for a given capture \a CI,
|
||||||
/// record field declaration \a RI and captured value \a CV.
|
/// record field declaration \a RI and captured value \a CV.
|
||||||
void generateDefaultMapInfo(const CapturedStmt::Capture &CI,
|
void generateDefaultMapInfo(const CapturedStmt::Capture &CI,
|
||||||
|
@ -9521,6 +9495,7 @@ void CGOpenMPRuntime::emitTargetCall(
|
||||||
// Get mappable expression information.
|
// Get mappable expression information.
|
||||||
MappableExprsHandler MEHandler(D, CGF);
|
MappableExprsHandler MEHandler(D, CGF);
|
||||||
llvm::DenseMap<llvm::Value *, llvm::Value *> LambdaPointers;
|
llvm::DenseMap<llvm::Value *, llvm::Value *> LambdaPointers;
|
||||||
|
llvm::DenseSet<CanonicalDeclPtr<const Decl>> MappedVarSet;
|
||||||
|
|
||||||
auto RI = CS.getCapturedRecordDecl()->field_begin();
|
auto RI = CS.getCapturedRecordDecl()->field_begin();
|
||||||
auto CV = CapturedVars.begin();
|
auto CV = CapturedVars.begin();
|
||||||
|
@ -9546,6 +9521,10 @@ void CGOpenMPRuntime::emitTargetCall(
|
||||||
// If we have any information in the map clause, we use it, otherwise we
|
// If we have any information in the map clause, we use it, otherwise we
|
||||||
// just do a default mapping.
|
// just do a default mapping.
|
||||||
MEHandler.generateInfoForCapture(CI, *CV, CurInfo, PartialStruct);
|
MEHandler.generateInfoForCapture(CI, *CV, CurInfo, PartialStruct);
|
||||||
|
if (!CI->capturesThis())
|
||||||
|
MappedVarSet.insert(CI->getCapturedVar());
|
||||||
|
else
|
||||||
|
MappedVarSet.insert(nullptr);
|
||||||
if (CurInfo.BasePointers.empty())
|
if (CurInfo.BasePointers.empty())
|
||||||
MEHandler.generateDefaultMapInfo(*CI, **RI, *CV, CurInfo);
|
MEHandler.generateDefaultMapInfo(*CI, **RI, *CV, CurInfo);
|
||||||
// Generate correct mapping for variables captured by reference in
|
// Generate correct mapping for variables captured by reference in
|
||||||
|
@ -9575,9 +9554,9 @@ void CGOpenMPRuntime::emitTargetCall(
|
||||||
MEHandler.adjustMemberOfForLambdaCaptures(
|
MEHandler.adjustMemberOfForLambdaCaptures(
|
||||||
LambdaPointers, CombinedInfo.BasePointers, CombinedInfo.Pointers,
|
LambdaPointers, CombinedInfo.BasePointers, CombinedInfo.Pointers,
|
||||||
CombinedInfo.Types);
|
CombinedInfo.Types);
|
||||||
// Map other list items in the map clause which are not captured variables
|
// Map any list items in a map clause that were not captures because they
|
||||||
// but "declare target link" global variables.
|
// weren't referenced within the construct.
|
||||||
MEHandler.generateInfoForDeclareTargetLink(CombinedInfo);
|
MEHandler.generateAllInfo(CombinedInfo, MappedVarSet);
|
||||||
|
|
||||||
TargetDataInfo Info;
|
TargetDataInfo Info;
|
||||||
// Fill up the arrays and create the arguments.
|
// Fill up the arrays and create the arguments.
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -20,15 +20,16 @@
|
||||||
#ifndef HEADER
|
#ifndef HEADER
|
||||||
#define HEADER
|
#define HEADER
|
||||||
|
|
||||||
|
// HOST: @[[MAPTYPES_PRIVATE:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 35, i64 35]
|
||||||
// HOST: @[[MAPTYPES_FIRSTPRIVATE:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 35, i64 35]
|
// HOST: @[[MAPTYPES_FIRSTPRIVATE:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 35, i64 35]
|
||||||
// HOST: @[[MAPTYPES_REDUCTION:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 35, i64 35]
|
// HOST: @[[MAPTYPES_REDUCTION:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 35, i64 35]
|
||||||
// HOST: @[[MAPTYPES_FROM:.offload_maptypes[0-9.]*]] = private {{.*}}constant [1 x i64] [i64 34]
|
// HOST: @[[MAPTYPES_FROM:.offload_maptypes[0-9.]*]] = private {{.*}}constant [1 x i64] [i64 34]
|
||||||
// HOST: @[[MAPTYPES_TO:.offload_maptypes[0-9.]*]] = private {{.*}}constant [1 x i64] [i64 33]
|
// HOST: @[[MAPTYPES_TO:.offload_maptypes[0-9.]*]] = private {{.*}}constant [1 x i64] [i64 33]
|
||||||
// HOST: @[[MAPTYPES_ALLOC:.offload_maptypes[0-9.]*]] = private {{.*}}constant [1 x i64] [i64 32]
|
// HOST: @[[MAPTYPES_ALLOC:.offload_maptypes[0-9.]*]] = private {{.*}}constant [1 x i64] [i64 32]
|
||||||
// HOST: @[[MAPTYPES_ARRAY_R0:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 35, i64 35]
|
// HOST: @[[MAPTYPES_ARRAY_R0:.offload_maptypes[0-9.]*]] = private {{.*}}constant [3 x i64] [i64 35, i64 35, i64 35]
|
||||||
// HOST: @[[MAPTYPES_ARRAY_R1:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 33, i64 33]
|
// HOST: @[[MAPTYPES_ARRAY_R1:.offload_maptypes[0-9.]*]] = private {{.*}}constant [3 x i64] [i64 33, i64 33, i64 33]
|
||||||
// HOST-INT128: @[[MAPTYPES_INT128_R0:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 35, i64 35]
|
// HOST-INT128: @[[MAPTYPES_INT128_R0:.offload_maptypes[0-9.]*]] = private {{.*}}constant [3 x i64] [i64 35, i64 35, i64 35]
|
||||||
// HOST-INT128: @[[MAPTYPES_INT128_R1:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 34, i64 34]
|
// HOST-INT128: @[[MAPTYPES_INT128_R1:.offload_maptypes[0-9.]*]] = private {{.*}}constant [3 x i64] [i64 34, i64 34, i64 34]
|
||||||
//
|
//
|
||||||
// CHECK: @.omp_offloading.entry_name{{[0-9.]*}} = {{.*}} c"[[OFFLOAD_PRIVATE:__omp_offloading_[^"\\]*mapWithPrivate[^"\\]*]]\00"
|
// CHECK: @.omp_offloading.entry_name{{[0-9.]*}} = {{.*}} c"[[OFFLOAD_PRIVATE:__omp_offloading_[^"\\]*mapWithPrivate[^"\\]*]]\00"
|
||||||
// CHECK: @.omp_offloading.entry_name{{[0-9.]*}} = {{.*}} c"[[OFFLOAD_FIRSTPRIVATE:__omp_offloading_[^"\\]*mapWithFirstprivate[^"\\]*]]\00"
|
// CHECK: @.omp_offloading.entry_name{{[0-9.]*}} = {{.*}} c"[[OFFLOAD_FIRSTPRIVATE:__omp_offloading_[^"\\]*mapWithFirstprivate[^"\\]*]]\00"
|
||||||
|
@ -42,9 +43,7 @@
|
||||||
// INT128: @.omp_offloading.entry_name{{[0-9.]*}} = {{.*}} c"[[OFFLOAD_INT128_R1:__omp_offloading_[^"\\]*mapInt128[^"\\]*]]\00"
|
// INT128: @.omp_offloading.entry_name{{[0-9.]*}} = {{.*}} c"[[OFFLOAD_INT128_R1:__omp_offloading_[^"\\]*mapInt128[^"\\]*]]\00"
|
||||||
|
|
||||||
// HOST: define {{.*}}mapWithPrivate
|
// HOST: define {{.*}}mapWithPrivate
|
||||||
// HOST: call {{.*}} @.[[OFFLOAD_PRIVATE]].region_id
|
// HOST: call {{.*}} @.[[OFFLOAD_PRIVATE]].region_id{{.*}} @[[MAPTYPES_PRIVATE]]
|
||||||
// HOST-NOT: offload_maptypes
|
|
||||||
// HOST-SAME: {{$}}
|
|
||||||
//
|
//
|
||||||
// CHECK: define {{.*}} void @[[OFFLOAD_PRIVATE]]()
|
// CHECK: define {{.*}} void @[[OFFLOAD_PRIVATE]]()
|
||||||
// CHECK: call void ({{.*}}@[[OUTLINE_PRIVATE:.omp_outlined.[.0-9]*]]
|
// CHECK: call void ({{.*}}@[[OUTLINE_PRIVATE:.omp_outlined.[.0-9]*]]
|
||||||
|
|
Loading…
Reference in New Issue