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
This commit is contained in:
Jennifer Yu 2022-03-23 07:34:28 -07:00
parent 64838ba365
commit a6cdac48ff
2 changed files with 39 additions and 14 deletions

View File

@ -11939,16 +11939,16 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const FunctionDecl *FD,
llvm::Function *Fn) {
ASTContext &C = CGM.getContext();
FD = FD->getMostRecentDecl();
// Map params to their positions in function decl.
llvm::DenseMap<const Decl *, unsigned> ParamPositions;
if (isa<CXXMethodDecl>(FD))
ParamPositions.try_emplace(FD, 0);
unsigned ParamPos = ParamPositions.size();
for (const ParmVarDecl *P : FD->parameters()) {
ParamPositions.try_emplace(P->getCanonicalDecl(), ParamPos);
++ParamPos;
}
while (FD) {
// Map params to their positions in function decl.
llvm::DenseMap<const Decl *, unsigned> ParamPositions;
if (isa<CXXMethodDecl>(FD))
ParamPositions.try_emplace(FD, 0);
unsigned ParamPos = ParamPositions.size();
for (const ParmVarDecl *P : FD->parameters()) {
ParamPositions.try_emplace(P->getCanonicalDecl(), ParamPos);
++ParamPos;
}
for (const auto *Attr : FD->specific_attrs<OMPDeclareSimdDeclAttr>()) {
llvm::SmallVector<ParamAttrTy, 8> ParamAttrs(ParamPositions.size());
// Mark uniform parameters.
@ -11960,7 +11960,9 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const FunctionDecl *FD,
} else {
const auto *PVD = cast<ParmVarDecl>(cast<DeclRefExpr>(E)->getDecl())
->getCanonicalDecl();
Pos = ParamPositions[PVD];
auto It = ParamPositions.find(PVD);
assert(It != ParamPositions.end() && "Function parameter not found");
Pos = It->second;
}
ParamAttrs[Pos].Kind = Uniform;
}
@ -11976,7 +11978,9 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const FunctionDecl *FD,
} else {
const auto *PVD = cast<ParmVarDecl>(cast<DeclRefExpr>(E)->getDecl())
->getCanonicalDecl();
Pos = ParamPositions[PVD];
auto It = ParamPositions.find(PVD);
assert(It != ParamPositions.end() && "Function parameter not found");
Pos = It->second;
ParmTy = PVD->getType();
}
ParamAttrs[Pos].Alignment =
@ -12000,7 +12004,9 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const FunctionDecl *FD,
} else {
const auto *PVD = cast<ParmVarDecl>(cast<DeclRefExpr>(E)->getDecl())
->getCanonicalDecl();
Pos = ParamPositions[PVD];
auto It = ParamPositions.find(PVD);
assert(It != ParamPositions.end() && "Function parameter not found");
Pos = It->second;
if (auto *P = dyn_cast<PointerType>(PVD->getType()))
PtrRescalingFactor = CGM.getContext()
.getTypeSizeInChars(P->getPointeeType())
@ -12018,8 +12024,10 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const FunctionDecl *FD,
if (const auto *StridePVD =
dyn_cast<ParmVarDecl>(DRE->getDecl())) {
ParamAttr.Kind = LinearWithVarStride;
ParamAttr.StrideOrArg = llvm::APSInt::getUnsigned(
ParamPositions[StridePVD->getCanonicalDecl()]);
auto It = ParamPositions.find(StridePVD->getCanonicalDecl());
assert(It != ParamPositions.end() &&
"Function parameter not found");
ParamAttr.StrideOrArg = llvm::APSInt::getUnsigned(It->second);
}
}
} else {

View File

@ -153,6 +153,23 @@ double constlinear(const int i) { return 0.0; }
// CHECK-DAG: "_ZGVdN4v__Z5add_1Pf"
// CHECK-DAG: "_ZGVeN8v__Z5add_1Pf"
// CHECK-NOT: _ZGVbN2vv__Z5add_1Pf
// CHECK-NOT: _ZGVcN4vv__Z5add_1Pf
// CHECK-NOT: _ZGVdN4vv__Z5add_1Pf
// CHECK-NOT: _ZGVeN8vv__Z5add_1Pf
// CHECK-NOT: _ZGVbM32vv__Z5add_1Pf
// CHECK-NOT: _ZGVcM32vv__Z5add_1Pf
// CHECK-NOT: _ZGVdM32vv__Z5add_1Pf
// CHECK-NOT: _ZGVeM32vv__Z5add_1Pf
// CHECK-NOT: _ZGVbN4l32v__Z5add_1Pf
// CHECK-NOT: _ZGVcN8l32v__Z5add_1Pf
// CHECK-NOT: _ZGVdN8l32v__Z5add_1Pf
// CHECK-NOT: _ZGVeN16l32v__Z5add_1Pf
// CHECK-NOT: _ZGVbM4l32v__Z5add_1Pf
// CHECK-NOT: _ZGVcM8l32v__Z5add_1Pf
// CHECK-NOT: _ZGVdM8l32v__Z5add_1Pf
// CHECK-NOT: _ZGVeM16l32v__Z5add_1Pf
// CHECK-DAG: "_ZGVbM2va16va16vv__Z1hIiEvPT_S1_S1_S1_"
// CHECK-DAG: "_ZGVbN2va16va16vv__Z1hIiEvPT_S1_S1_S1_"
// CHECK-DAG: "_ZGVcM4va16va16vv__Z1hIiEvPT_S1_S1_S1_"