@@ -62,23 +62,35 @@ class OSSDependVisitor
62
62
63
63
void FillBaseExprDimsAndType (const Expr *E) {
64
64
BaseElementTy = E->getType ();
65
- if (const ConstantArrayType *BaseArrayTy = CGF.getContext ().getAsConstantArrayType (BaseElementTy)){
66
- BaseElementTy = CGF.getContext ().getBaseElementType (BaseElementTy);
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);
70
+ } else {
71
+ llvm_unreachable (" Unhandled array type" );
72
+ }
67
73
}
68
74
QualType TmpTy = E->getType ();
69
75
// Add Dimensions
70
- if (TmpTy->isPointerType ()) {
71
- // T *
72
- Dims.push_back (llvm::ConstantInt::getSigned (OSSArgTy, 1 ));
73
- } else if (!TmpTy->isArrayType ()) {
74
- // T
76
+ if (TmpTy->isPointerType () || !TmpTy->isArrayType ()) {
77
+ // T * || T
75
78
Dims.push_back (llvm::ConstantInt::getSigned (OSSArgTy, 1 ));
76
79
}
77
- while (const ConstantArrayType *BaseArrayTy = CGF. getContext (). getAsConstantArrayType (TmpTy)) {
80
+ while (TmpTy-> isArrayType ()) {
78
81
// T []
79
- uint64_t DimSize = BaseArrayTy->getSize ().getSExtValue ();
80
- Dims.push_back (llvm::ConstantInt::getSigned (OSSArgTy, DimSize));
81
- TmpTy = BaseArrayTy->getElementType ();
82
+ if (const ConstantArrayType *BaseArrayTy = CGF.getContext ().getAsConstantArrayType (TmpTy)) {
83
+ uint64_t DimSize = BaseArrayTy->getSize ().getSExtValue ();
84
+ Dims.push_back (llvm::ConstantInt::getSigned (OSSArgTy, DimSize));
85
+ TmpTy = BaseArrayTy->getElementType ();
86
+ } else if (const VariableArrayType *BaseArrayTy = CGF.getContext ().getAsVariableArrayType (TmpTy)) {
87
+ llvm::Value *DimExpr = CGF.EmitScalarExpr (BaseArrayTy->getSizeExpr ());
88
+ DimExpr = CGF.Builder .CreateSExt (DimExpr, OSSArgTy);
89
+ Dims.push_back (DimExpr);
90
+ TmpTy = BaseArrayTy->getElementType ();
91
+ } else {
92
+ llvm_unreachable (" Unhandled array type" );
93
+ }
82
94
}
83
95
}
84
96
@@ -105,18 +117,23 @@ class OSSDependVisitor
105
117
}
106
118
107
119
void VisitArraySubscriptExpr (const ArraySubscriptExpr *E) {
108
- BaseElementTy = E->getType ();
109
120
// Get Base Type
110
- if (const ConstantArrayType *BaseArrayTy = CGF.getContext ().getAsConstantArrayType (BaseElementTy)){
111
- BaseElementTy = CGF.getContext ().getBaseElementType (BaseElementTy);
121
+ BaseElementTy = E->getType ();
122
+ if (BaseElementTy->isArrayType ()) {
123
+ if (const ConstantArrayType *BaseArrayTy = CGF.getContext ().getAsConstantArrayType (BaseElementTy)){
124
+ BaseElementTy = CGF.getContext ().getBaseElementType (BaseElementTy);
125
+ } else if (const VariableArrayType *BaseArrayTy = CGF.getContext ().getAsVariableArrayType (BaseElementTy)){
126
+ BaseElementTy = CGF.getContext ().getBaseElementType (BaseElementTy);
127
+ } else {
128
+ llvm_unreachable (" Unhandled array type" );
129
+ }
112
130
}
113
131
// Get the inner expr
114
132
const Expr *Expr = E;
115
133
while (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(Expr->IgnoreParenImpCasts ())) {
116
134
Expr = ASE->getBase ();
117
135
// Add indexes
118
- llvm::Value *Idx = ConstantEmitter (CGF).emitAbstract (ASE->getIdx (),
119
- ASE->getIdx ()->getType ());
136
+ llvm::Value *Idx = CGF.EmitScalarExpr (ASE->getIdx ());
120
137
Idx = CGF.Builder .CreateSExt (Idx, OSSArgTy);
121
138
llvm::Value *IdxEnd = CGF.Builder .CreateAdd (Idx, llvm::ConstantInt::getSigned (OSSArgTy, 1 ));
122
139
Starts.push_back (Idx);
@@ -134,11 +151,20 @@ class OSSDependVisitor
134
151
// T (*)[]
135
152
Dims.push_back (llvm::ConstantInt::getSigned (OSSArgTy, 1 ));
136
153
TmpTy = cast<PointerType>(TmpTy)->getPointeeType ();
137
- while (const ConstantArrayType *BaseArrayTy = CGF. getContext (). getAsConstantArrayType (TmpTy)) {
154
+ while (TmpTy-> isArrayType ()) {
138
155
// T []
139
- uint64_t DimSize = BaseArrayTy->getSize ().getSExtValue ();
140
- Dims.push_back (llvm::ConstantInt::getSigned (OSSArgTy, DimSize));
141
- TmpTy = BaseArrayTy->getElementType ();
156
+ if (const ConstantArrayType *BaseArrayTy = CGF.getContext ().getAsConstantArrayType (TmpTy)) {
157
+ uint64_t DimSize = BaseArrayTy->getSize ().getSExtValue ();
158
+ Dims.push_back (llvm::ConstantInt::getSigned (OSSArgTy, DimSize));
159
+ TmpTy = BaseArrayTy->getElementType ();
160
+ } else if (const VariableArrayType *BaseArrayTy = CGF.getContext ().getAsVariableArrayType (TmpTy)) {
161
+ llvm::Value *DimExpr = CGF.EmitScalarExpr (BaseArrayTy->getSizeExpr ());
162
+ DimExpr = CGF.Builder .CreateSExt (DimExpr, OSSArgTy);
163
+ Dims.push_back (DimExpr);
164
+ TmpTy = BaseArrayTy->getElementType ();
165
+ } else {
166
+ llvm_unreachable (" Unhandled array type" );
167
+ }
142
168
}
143
169
} else {
144
170
// T *
@@ -182,8 +208,39 @@ class OSSDependVisitor
182
208
183
209
static void EmitDSA (StringRef Name, CodeGenFunction &CGF, const Expr *E,
184
210
SmallVectorImpl<llvm::OperandBundleDef> &TaskInfo) {
211
+ // C long -> LLVM long
212
+ llvm::Type *OSSArgTy = CGF.ConvertType (CGF.getContext ().LongTy );
213
+
214
+ std::string Basename = Name;
215
+
216
+ SmallVector<llvm::Value*, 4 > DsaData;
217
+ SmallVector<llvm::Value*, 4 > TmpDsaData; // save all dimensions always. if vla add all of them
185
218
if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
186
- TaskInfo.emplace_back (Name, CGF.EmitDeclRefLValue (DRE).getPointer ());
219
+ DsaData.push_back (CGF.EmitDeclRefLValue (DRE).getPointer ());
220
+ QualType TmpTy = DRE->getType ();
221
+ bool FirstTime = true ;
222
+ while (TmpTy->isArrayType ()) {
223
+ if (const VariableArrayType *BaseArrayTy = CGF.getContext ().getAsVariableArrayType (TmpTy)) {
224
+ // New type of bundle for vlas
225
+ if (FirstTime) {
226
+ FirstTime = false ;
227
+ Basename += " .VLA" ;
228
+ }
229
+ llvm::Value *DimExpr = CGF.EmitScalarExpr (BaseArrayTy->getSizeExpr ());
230
+ DimExpr = CGF.Builder .CreateSExt (DimExpr, OSSArgTy);
231
+ DsaData.push_back (DimExpr);
232
+ TmpTy = BaseArrayTy->getElementType ();
233
+ } else if (const ConstantArrayType *BaseArrayTy = CGF.getContext ().getAsConstantArrayType (TmpTy)) {
234
+ uint64_t DimSize = BaseArrayTy->getSize ().getSExtValue ();
235
+ TmpDsaData.push_back (llvm::ConstantInt::getSigned (OSSArgTy, DimSize));
236
+ TmpTy = BaseArrayTy->getElementType ();
237
+ } else {
238
+ llvm_unreachable (" Unhandled array type" );
239
+ }
240
+ }
241
+ if (!FirstTime) // We have seen a vla, save dimensions
242
+ DsaData.append (TmpDsaData.begin (), TmpDsaData.end ());
243
+ TaskInfo.emplace_back (Basename, DsaData);
187
244
}
188
245
else {
189
246
llvm_unreachable (" Unhandled expression" );
0 commit comments