@@ -60,17 +60,21 @@ class OSSDependVisitor
60
60
// Utilities
61
61
// ===--------------------------------------------------------------------===//
62
62
63
- void FillBaseExprDimsAndType (const Expr *E) {
64
- BaseElementTy = E->getType ();
65
- if (BaseElementTy->isArrayType ()) {
66
- if (const ConstantArrayType *BaseArrayTy = CGF.getContext ().getAsConstantArrayType (BaseElementTy)){
67
- BaseElementTy = CGF.getContext ().getBaseElementType (BaseElementTy);
68
- } else if (const VariableArrayType *BaseArrayTy = CGF.getContext ().getAsVariableArrayType (BaseElementTy)){
69
- BaseElementTy = CGF.getContext ().getBaseElementType (BaseElementTy);
63
+ QualType GetInnermostElementType (const QualType &Q) {
64
+ if (Q->isArrayType ()) {
65
+ if (const ConstantArrayType *BaseArrayTy = CGF.getContext ().getAsConstantArrayType (Q)) {
66
+ return CGF.getContext ().getBaseElementType (Q);
67
+ } else if (const VariableArrayType *BaseArrayTy = CGF.getContext ().getAsVariableArrayType (Q)) {
68
+ return CGF.getContext ().getBaseElementType (Q);
70
69
} else {
71
70
llvm_unreachable (" Unhandled array type" );
72
71
}
73
72
}
73
+ return Q;
74
+ }
75
+
76
+ void FillBaseExprDimsAndType (const Expr *E) {
77
+ BaseElementTy = GetInnermostElementType (E->getType ());
74
78
QualType TmpTy = E->getType ();
75
79
// Add Dimensions
76
80
if (TmpTy->isPointerType () || !TmpTy->isArrayType ()) {
@@ -94,6 +98,34 @@ class OSSDependVisitor
94
98
}
95
99
}
96
100
101
+ // This is used in the innermost Expr * in ArraySubscripts and OSSArraySection
102
+ void FillDimsFromInnermostExpr (const Expr *E) {
103
+ // Go through the expression which may be a DeclRefExpr or MemberExpr
104
+ E = E->IgnoreParenImpCasts ();
105
+ QualType TmpTy = E->getType ();
106
+ // Add Dimensions
107
+ if (TmpTy->isPointerType ()) {
108
+ // T *
109
+ Dims.push_back (llvm::ConstantInt::getSigned (OSSArgTy, 1 ));
110
+ TmpTy = TmpTy->getPointeeType ();
111
+ }
112
+ while (TmpTy->isArrayType ()) {
113
+ // T []
114
+ if (const ConstantArrayType *BaseArrayTy = CGF.getContext ().getAsConstantArrayType (TmpTy)) {
115
+ uint64_t DimSize = BaseArrayTy->getSize ().getSExtValue ();
116
+ Dims.push_back (llvm::ConstantInt::getSigned (OSSArgTy, DimSize));
117
+ TmpTy = BaseArrayTy->getElementType ();
118
+ } else if (const VariableArrayType *BaseArrayTy = CGF.getContext ().getAsVariableArrayType (TmpTy)) {
119
+ auto VlaSize = CGF.getVLAElements1D (BaseArrayTy);
120
+ llvm::Value *DimExpr = CGF.Builder .CreateSExt (VlaSize.NumElts , OSSArgTy);
121
+ Dims.push_back (DimExpr);
122
+ TmpTy = BaseArrayTy->getElementType ();
123
+ } else {
124
+ llvm_unreachable (" Unhandled array type" );
125
+ }
126
+ }
127
+ }
128
+
97
129
// ===--------------------------------------------------------------------===//
98
130
// Visitor Methods
99
131
// ===--------------------------------------------------------------------===//
@@ -119,18 +151,9 @@ class OSSDependVisitor
119
151
void VisitOSSArraySectionExpr (const OSSArraySectionExpr *E) {
120
152
// Get Base Type
121
153
// An array section is considered a built-in type
122
- BaseElementTy = OSSArraySectionExpr::getBaseOriginalType (
123
- E->getBase ()->IgnoreParenImpCasts ())
124
- .getCanonicalType ();
125
- if (BaseElementTy->isArrayType ()) {
126
- if (const ConstantArrayType *BaseArrayTy = CGF.getContext ().getAsConstantArrayType (BaseElementTy)){
127
- BaseElementTy = CGF.getContext ().getBaseElementType (BaseElementTy);
128
- } else if (const VariableArrayType *BaseArrayTy = CGF.getContext ().getAsVariableArrayType (BaseElementTy)){
129
- BaseElementTy = CGF.getContext ().getBaseElementType (BaseElementTy);
130
- } else {
131
- llvm_unreachable (" Unhandled array type" );
132
- }
133
- }
154
+ BaseElementTy = GetInnermostElementType (
155
+ OSSArraySectionExpr::getBaseOriginalType (
156
+ E->getBase ()));
134
157
// Get the inner expr
135
158
const Expr *TmpE = E;
136
159
// First come OSSArraySection
@@ -143,7 +166,7 @@ class OSSDependVisitor
143
166
if (LowerB)
144
167
Idx = CGF.EmitScalarExpr (LowerB);
145
168
else
146
- // OpenMP 5.0 2.1.5 When the lower-bound is absent it defaults to 0.
169
+ // OpenMP 5.0 2.1.5 When the lower-bound is absent it defaults to 0.
147
170
Idx = llvm::ConstantInt::getSigned (OSSArgTy, 0 );
148
171
Idx = CGF.Builder .CreateSExt (Idx, OSSArgTy);
149
172
@@ -190,93 +213,35 @@ class OSSDependVisitor
190
213
llvm::Value *IdxEnd = CGF.Builder .CreateAdd (Idx, llvm::ConstantInt::getSigned (OSSArgTy, 1 ));
191
214
Starts.push_back (Idx);
192
215
Ends.push_back (IdxEnd);
216
+ // Stop in the innermost ArrayToPointerDecay
193
217
if (TmpE->IgnoreParenImpCasts ()->getType ()->isPointerType ())
194
218
break ;
195
219
}
196
220
197
221
Ptr = CGF.EmitScalarExpr (TmpE);
198
-
199
- TmpE = TmpE->IgnoreParenImpCasts ();
200
-
201
- QualType TmpTy = TmpE->getType ();
202
- // Add Dimensions
203
- if (TmpTy->isPointerType ()) {
204
- // T *
205
- Dims.push_back (llvm::ConstantInt::getSigned (OSSArgTy, 1 ));
206
- } else {
207
- while (TmpTy->isArrayType ()) {
208
- // T []
209
- if (const ConstantArrayType *BaseArrayTy = CGF.getContext ().getAsConstantArrayType (TmpTy)) {
210
- uint64_t DimSize = BaseArrayTy->getSize ().getSExtValue ();
211
- Dims.push_back (llvm::ConstantInt::getSigned (OSSArgTy, DimSize));
212
- TmpTy = BaseArrayTy->getElementType ();
213
- } else if (const VariableArrayType *BaseArrayTy = CGF.getContext ().getAsVariableArrayType (TmpTy)) {
214
- auto VlaSize = CGF.getVLAElements1D (BaseArrayTy);
215
- llvm::Value *DimExpr = CGF.Builder .CreateSExt (VlaSize.NumElts , OSSArgTy);
216
- Dims.push_back (DimExpr);
217
- TmpTy = BaseArrayTy->getElementType ();
218
- } else {
219
- llvm_unreachable (" Unhandled array type" );
220
- }
221
- }
222
- }
222
+ FillDimsFromInnermostExpr (TmpE);
223
223
}
224
224
225
225
void VisitArraySubscriptExpr (const ArraySubscriptExpr *E) {
226
226
// Get Base Type
227
- BaseElementTy = E->getType ();
228
- if (BaseElementTy->isArrayType ()) {
229
- if (const ConstantArrayType *BaseArrayTy = CGF.getContext ().getAsConstantArrayType (BaseElementTy)){
230
- BaseElementTy = CGF.getContext ().getBaseElementType (BaseElementTy);
231
- } else if (const VariableArrayType *BaseArrayTy = CGF.getContext ().getAsVariableArrayType (BaseElementTy)){
232
- BaseElementTy = CGF.getContext ().getBaseElementType (BaseElementTy);
233
- } else {
234
- llvm_unreachable (" Unhandled array type" );
235
- }
236
- }
227
+ BaseElementTy = GetInnermostElementType (E->getType ());
237
228
// Get the inner expr
238
- const Expr *Expr = E;
239
- while (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(Expr ->IgnoreParenImpCasts ())) {
240
- Expr = ASE->getBase ();
229
+ const Expr *TmpE = E;
230
+ while (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(TmpE ->IgnoreParenImpCasts ())) {
231
+ TmpE = ASE->getBase ();
241
232
// Add indexes
242
233
llvm::Value *Idx = CGF.EmitScalarExpr (ASE->getIdx ());
243
234
Idx = CGF.Builder .CreateSExt (Idx, OSSArgTy);
244
235
llvm::Value *IdxEnd = CGF.Builder .CreateAdd (Idx, llvm::ConstantInt::getSigned (OSSArgTy, 1 ));
245
236
Starts.push_back (Idx);
246
237
Ends.push_back (IdxEnd);
247
- if (Expr->IgnoreParenImpCasts ()->getType ()->isPointerType ())
238
+ // Stop in the innermost ArrayToPointerDecay
239
+ if (TmpE->IgnoreParenImpCasts ()->getType ()->isPointerType ())
248
240
break ;
249
241
}
250
242
251
- Ptr = CGF.EmitScalarExpr (Expr);
252
-
253
- if (const CastExpr *CE = dyn_cast<CastExpr>(Expr)) {
254
- QualType TmpTy = CE->getType ();
255
- // Add Dimensions
256
- if (TmpTy->isPointerType ()) {
257
- // T (*)[]
258
- Dims.push_back (llvm::ConstantInt::getSigned (OSSArgTy, 1 ));
259
- TmpTy = cast<PointerType>(TmpTy)->getPointeeType ();
260
- while (TmpTy->isArrayType ()) {
261
- // T []
262
- if (const ConstantArrayType *BaseArrayTy = CGF.getContext ().getAsConstantArrayType (TmpTy)) {
263
- uint64_t DimSize = BaseArrayTy->getSize ().getSExtValue ();
264
- Dims.push_back (llvm::ConstantInt::getSigned (OSSArgTy, DimSize));
265
- TmpTy = BaseArrayTy->getElementType ();
266
- } else if (const VariableArrayType *BaseArrayTy = CGF.getContext ().getAsVariableArrayType (TmpTy)) {
267
- auto VlaSize = CGF.getVLAElements1D (BaseArrayTy);
268
- llvm::Value *DimExpr = CGF.Builder .CreateSExt (VlaSize.NumElts , OSSArgTy);
269
- Dims.push_back (DimExpr);
270
- TmpTy = BaseArrayTy->getElementType ();
271
- } else {
272
- llvm_unreachable (" Unhandled array type" );
273
- }
274
- }
275
- } else {
276
- // T *
277
- Dims.push_back (llvm::ConstantInt::getSigned (OSSArgTy, 1 ));
278
- }
279
- }
243
+ Ptr = CGF.EmitScalarExpr (TmpE);
244
+ FillDimsFromInnermostExpr (TmpE);
280
245
}
281
246
282
247
void VisitMemberExpr (const MemberExpr *E) {
0 commit comments