Skip to content

Commit a6cdac4

Browse files
committed
Eliminate extra set of simd variant function attribute.
Current clang generates extra set of simd variant function attribute with extra 'v' encoding. For example: _ZGVbN2v__Z5add_1Pf vs _ZGVbN2vv__Z5add_1Pf The problem is due to declaration of ParamAttrs following: llvm::SmallVector<ParamAttrTy, 8> ParamAttrs(ParamPositions.size()); where ParamPositions.size() is grown after following assignment: Pos = ParamPositions[PVD]; So the PVD is not find in ParamPositions. The problem is ParamPositions need to set for each FD decl. To fix this Move ParamPositions's init inside while loop for each FD. Differential Revision: https://reviews.llvm.org/D122338
1 parent 64838ba commit a6cdac4

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11939,16 +11939,16 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const FunctionDecl *FD,
1193911939
llvm::Function *Fn) {
1194011940
ASTContext &C = CGM.getContext();
1194111941
FD = FD->getMostRecentDecl();
11942-
// Map params to their positions in function decl.
11943-
llvm::DenseMap<const Decl *, unsigned> ParamPositions;
11944-
if (isa<CXXMethodDecl>(FD))
11945-
ParamPositions.try_emplace(FD, 0);
11946-
unsigned ParamPos = ParamPositions.size();
11947-
for (const ParmVarDecl *P : FD->parameters()) {
11948-
ParamPositions.try_emplace(P->getCanonicalDecl(), ParamPos);
11949-
++ParamPos;
11950-
}
1195111942
while (FD) {
11943+
// Map params to their positions in function decl.
11944+
llvm::DenseMap<const Decl *, unsigned> ParamPositions;
11945+
if (isa<CXXMethodDecl>(FD))
11946+
ParamPositions.try_emplace(FD, 0);
11947+
unsigned ParamPos = ParamPositions.size();
11948+
for (const ParmVarDecl *P : FD->parameters()) {
11949+
ParamPositions.try_emplace(P->getCanonicalDecl(), ParamPos);
11950+
++ParamPos;
11951+
}
1195211952
for (const auto *Attr : FD->specific_attrs<OMPDeclareSimdDeclAttr>()) {
1195311953
llvm::SmallVector<ParamAttrTy, 8> ParamAttrs(ParamPositions.size());
1195411954
// Mark uniform parameters.
@@ -11960,7 +11960,9 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const FunctionDecl *FD,
1196011960
} else {
1196111961
const auto *PVD = cast<ParmVarDecl>(cast<DeclRefExpr>(E)->getDecl())
1196211962
->getCanonicalDecl();
11963-
Pos = ParamPositions[PVD];
11963+
auto It = ParamPositions.find(PVD);
11964+
assert(It != ParamPositions.end() && "Function parameter not found");
11965+
Pos = It->second;
1196411966
}
1196511967
ParamAttrs[Pos].Kind = Uniform;
1196611968
}
@@ -11976,7 +11978,9 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const FunctionDecl *FD,
1197611978
} else {
1197711979
const auto *PVD = cast<ParmVarDecl>(cast<DeclRefExpr>(E)->getDecl())
1197811980
->getCanonicalDecl();
11979-
Pos = ParamPositions[PVD];
11981+
auto It = ParamPositions.find(PVD);
11982+
assert(It != ParamPositions.end() && "Function parameter not found");
11983+
Pos = It->second;
1198011984
ParmTy = PVD->getType();
1198111985
}
1198211986
ParamAttrs[Pos].Alignment =
@@ -12000,7 +12004,9 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const FunctionDecl *FD,
1200012004
} else {
1200112005
const auto *PVD = cast<ParmVarDecl>(cast<DeclRefExpr>(E)->getDecl())
1200212006
->getCanonicalDecl();
12003-
Pos = ParamPositions[PVD];
12007+
auto It = ParamPositions.find(PVD);
12008+
assert(It != ParamPositions.end() && "Function parameter not found");
12009+
Pos = It->second;
1200412010
if (auto *P = dyn_cast<PointerType>(PVD->getType()))
1200512011
PtrRescalingFactor = CGM.getContext()
1200612012
.getTypeSizeInChars(P->getPointeeType())
@@ -12018,8 +12024,10 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const FunctionDecl *FD,
1201812024
if (const auto *StridePVD =
1201912025
dyn_cast<ParmVarDecl>(DRE->getDecl())) {
1202012026
ParamAttr.Kind = LinearWithVarStride;
12021-
ParamAttr.StrideOrArg = llvm::APSInt::getUnsigned(
12022-
ParamPositions[StridePVD->getCanonicalDecl()]);
12027+
auto It = ParamPositions.find(StridePVD->getCanonicalDecl());
12028+
assert(It != ParamPositions.end() &&
12029+
"Function parameter not found");
12030+
ParamAttr.StrideOrArg = llvm::APSInt::getUnsigned(It->second);
1202312031
}
1202412032
}
1202512033
} else {

clang/test/OpenMP/declare_simd_codegen.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,23 @@ double constlinear(const int i) { return 0.0; }
153153
// CHECK-DAG: "_ZGVdN4v__Z5add_1Pf"
154154
// CHECK-DAG: "_ZGVeN8v__Z5add_1Pf"
155155

156+
// CHECK-NOT: _ZGVbN2vv__Z5add_1Pf
157+
// CHECK-NOT: _ZGVcN4vv__Z5add_1Pf
158+
// CHECK-NOT: _ZGVdN4vv__Z5add_1Pf
159+
// CHECK-NOT: _ZGVeN8vv__Z5add_1Pf
160+
// CHECK-NOT: _ZGVbM32vv__Z5add_1Pf
161+
// CHECK-NOT: _ZGVcM32vv__Z5add_1Pf
162+
// CHECK-NOT: _ZGVdM32vv__Z5add_1Pf
163+
// CHECK-NOT: _ZGVeM32vv__Z5add_1Pf
164+
// CHECK-NOT: _ZGVbN4l32v__Z5add_1Pf
165+
// CHECK-NOT: _ZGVcN8l32v__Z5add_1Pf
166+
// CHECK-NOT: _ZGVdN8l32v__Z5add_1Pf
167+
// CHECK-NOT: _ZGVeN16l32v__Z5add_1Pf
168+
// CHECK-NOT: _ZGVbM4l32v__Z5add_1Pf
169+
// CHECK-NOT: _ZGVcM8l32v__Z5add_1Pf
170+
// CHECK-NOT: _ZGVdM8l32v__Z5add_1Pf
171+
// CHECK-NOT: _ZGVeM16l32v__Z5add_1Pf
172+
156173
// CHECK-DAG: "_ZGVbM2va16va16vv__Z1hIiEvPT_S1_S1_S1_"
157174
// CHECK-DAG: "_ZGVbN2va16va16vv__Z1hIiEvPT_S1_S1_S1_"
158175
// CHECK-DAG: "_ZGVcM4va16va16vv__Z1hIiEvPT_S1_S1_S1_"

0 commit comments

Comments
 (0)