Skip to content

Commit 967081c

Browse files
mikerice1969memfrob
authored andcommitted
[OpenMP] Fix mangling for linear modifiers with variable stride
This adds support for variable stride with the val, uval, and ref linear modifiers. Previously only the no modifer type ls<argno> was supported. val -> Ls<argno> uval -> Us<argno> ref -> Rs<argno> Differential Revision: https://reviews.llvm.org/D125330
1 parent 1de7514 commit 967081c

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11405,7 +11405,6 @@ void CGOpenMPRuntime::emitTargetDataStandAloneCall(
1140511405
namespace {
1140611406
/// Kind of parameter in a function with 'declare simd' directive.
1140711407
enum ParamKindTy {
11408-
LinearWithVarStride,
1140911408
Linear,
1141011409
LinearRef,
1141111410
LinearUVal,
@@ -11418,6 +11417,7 @@ struct ParamAttrTy {
1141811417
ParamKindTy Kind = Vector;
1141911418
llvm::APSInt StrideOrArg;
1142011419
llvm::APSInt Alignment;
11420+
bool HasVarStride = false;
1142111421
};
1142211422
} // namespace
1142311423

@@ -11481,9 +11481,6 @@ static std::string mangleVectorParameters(ArrayRef<ParamAttrTy> ParamAttrs) {
1148111481
llvm::raw_svector_ostream Out(Buffer);
1148211482
for (const auto &ParamAttr : ParamAttrs) {
1148311483
switch (ParamAttr.Kind) {
11484-
case LinearWithVarStride:
11485-
Out << "ls" << ParamAttr.StrideOrArg;
11486-
break;
1148711484
case Linear:
1148811485
Out << 'l';
1148911486
break;
@@ -11503,8 +11500,10 @@ static std::string mangleVectorParameters(ArrayRef<ParamAttrTy> ParamAttrs) {
1150311500
Out << 'v';
1150411501
break;
1150511502
}
11506-
if (ParamAttr.Kind == Linear || ParamAttr.Kind == LinearRef ||
11507-
ParamAttr.Kind == LinearUVal || ParamAttr.Kind == LinearVal) {
11503+
if (ParamAttr.HasVarStride)
11504+
Out << "s" << ParamAttr.StrideOrArg;
11505+
else if (ParamAttr.Kind == Linear || ParamAttr.Kind == LinearRef ||
11506+
ParamAttr.Kind == LinearUVal || ParamAttr.Kind == LinearVal) {
1150811507
// Don't print the step value if it is not present or if it is
1150911508
// equal to 1.
1151011509
if (ParamAttr.StrideOrArg != 1)
@@ -11579,11 +11578,7 @@ emitX86DeclareSimdFunction(const FunctionDecl *FD, llvm::Function *Fn,
1157911578
// available at
1158011579
// https://developer.arm.com/products/software-development-tools/hpc/arm-compiler-for-hpc/vector-function-abi.
1158111580

11582-
/// Maps To Vector (MTV), as defined in 3.1.1 of the AAVFABI.
11583-
///
11584-
/// TODO: Need to implement the behavior for reference marked with a
11585-
/// var or no linear modifiers (1.b in the section). For this, we
11586-
/// need to extend ParamKindTy to support the linear modifiers.
11581+
/// Maps To Vector (MTV), as defined in 4.1.1 of the AAVFABI (2021Q1).
1158711582
static bool getAArch64MTV(QualType QT, ParamKindTy Kind) {
1158811583
QT = QT.getCanonicalType();
1158911584

@@ -11593,12 +11588,11 @@ static bool getAArch64MTV(QualType QT, ParamKindTy Kind) {
1159311588
if (Kind == ParamKindTy::Uniform)
1159411589
return false;
1159511590

11596-
if (Kind == ParamKindTy::Linear)
11591+
if (Kind == ParamKindTy::LinearUVal || ParamKindTy::LinearRef)
1159711592
return false;
1159811593

11599-
// TODO: Handle linear references with modifiers
11600-
11601-
if (Kind == ParamKindTy::LinearWithVarStride)
11594+
if ((Kind == ParamKindTy::Linear || Kind == ParamKindTy::LinearVal) &&
11595+
!QT->isReferenceType())
1160211596
return false;
1160311597

1160411598
return true;
@@ -11949,7 +11943,7 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const FunctionDecl *FD,
1194911943
cast<DeclRefExpr>((*SI)->IgnoreParenImpCasts())) {
1195011944
if (const auto *StridePVD =
1195111945
dyn_cast<ParmVarDecl>(DRE->getDecl())) {
11952-
ParamAttr.Kind = LinearWithVarStride;
11946+
ParamAttr.HasVarStride = true;
1195311947
auto It = ParamPositions.find(StridePVD->getCanonicalDecl());
1195411948
assert(It != ParamPositions.end() &&
1195511949
"Function parameter not found");
@@ -11963,7 +11957,8 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const FunctionDecl *FD,
1196311957
// If we are using a linear clause on a pointer, we need to
1196411958
// rescale the value of linear_step with the byte size of the
1196511959
// pointee type.
11966-
if (ParamAttr.Kind == Linear || ParamAttr.Kind == LinearRef)
11960+
if (!ParamAttr.HasVarStride &&
11961+
(ParamAttr.Kind == Linear || ParamAttr.Kind == LinearRef))
1196711962
ParamAttr.StrideOrArg = ParamAttr.StrideOrArg * PtrRescalingFactor;
1196811963
++SI;
1196911964
++MI;

clang/test/OpenMP/declare_simd_codegen.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,17 @@ double Four(int& a, int &b) {
144144
return a;
145145
}
146146

147+
// Test reference parameters with variable stride.
148+
#pragma omp declare simd simdlen(4) uniform(a) \
149+
linear(b:2) linear(c:a) \
150+
linear(val(d):4) linear(val(e):a) \
151+
linear(uval(f):8) linear(uval(g):a) \
152+
linear(ref(h):16) linear(ref(i):a)
153+
double Five(int a, short &b, short &c, short &d, short &e, short &f, short &g,
154+
short &h, short &i) {
155+
return a + int(b);
156+
}
157+
147158
// CHECK-DAG: define {{.+}}@_Z5add_1Pf(
148159
// CHECK-DAG: define {{.+}}@_Z1hIiEvPT_S1_S1_S1_(
149160
// CHECK-DAG: define {{.+}}@_Z1hIfEvPT_S1_S1_S1_(
@@ -162,6 +173,11 @@ double Four(int& a, int &b) {
162173
// CHECK-DAG: define {{.+}}@_Z3food(
163174
// CHECK-DAG: declare {{.+}}@_Z5add_2Pf(
164175
// CHECK-DAG: define {{.+}}@_Z11constlineari(
176+
// CHECK-DAG: define {{.+}}@_Z3OneRiPiiS_S0_i
177+
// CHECK-DAG: define {{.+}}@_Z3TwoRiPiiS_S0_i
178+
// CHECK-DAG: define {{.+}}@_Z5ThreeRiS_
179+
// CHECK-DAG: define {{.+}}@_Z4FourRiS_
180+
// CHECK-DAG: define {{.+}}@_Z4FiveiRsS_S_S_S_S_S_S_
165181

166182
// CHECK-DAG: "_ZGVbM4l32__Z5add_1Pf"
167183
// CHECK-DAG: "_ZGVbN4l32__Z5add_1Pf"
@@ -381,6 +397,8 @@ double Four(int& a, int &b) {
381397
// CHECK-DAG: "_ZGVbN4U2U__Z5ThreeRiS_"
382398
// CHECK-DAG: "_ZGVbM4R8R4__Z4FourRiS_"
383399
// CHECK-DAG: "_ZGVbN4R8R4__Z4FourRiS_"
400+
// CHECK-DAG: "_ZGVbM4uL2Ls0L4Ls0U8Us0R32Rs0__Z4FiveiRsS_S_S_S_S_S_S_"
401+
// CHECK-DAG: "_ZGVbN4uL2Ls0L4Ls0U8Us0R32Rs0__Z4FiveiRsS_S_S_S_S_S_S_"
384402

385403
// CHECK-NOT: "_ZGV{{.+}}__Z1fRA_i
386404

0 commit comments

Comments
 (0)