@@ -90,8 +90,100 @@ class ConstExprEmitter
90
90
}
91
91
92
92
mlir::Attribute VisitCastExpr (CastExpr *e, QualType destType) {
93
- cgm.errorNYI (e->getBeginLoc (), " ConstExprEmitter::VisitCastExpr" );
94
- return {};
93
+ if (const auto *ece = dyn_cast<ExplicitCastExpr>(e))
94
+ cgm.errorNYI (e->getBeginLoc (),
95
+ " ConstExprEmitter::VisitCastExpr explicit cast" );
96
+ Expr *subExpr = e->getSubExpr ();
97
+
98
+ switch (e->getCastKind ()) {
99
+ case CK_ToUnion:
100
+ case CK_AddressSpaceConversion:
101
+ case CK_ReinterpretMemberPointer:
102
+ case CK_DerivedToBaseMemberPointer:
103
+ case CK_BaseToDerivedMemberPointer:
104
+ cgm.errorNYI (e->getBeginLoc (), " ConstExprEmitter::VisitCastExpr" );
105
+ return {};
106
+
107
+ case CK_LValueToRValue:
108
+ case CK_AtomicToNonAtomic:
109
+ case CK_NonAtomicToAtomic:
110
+ case CK_NoOp:
111
+ case CK_ConstructorConversion:
112
+ return Visit (subExpr, destType);
113
+
114
+ case CK_IntToOCLSampler:
115
+ llvm_unreachable (" global sampler variables are not generated" );
116
+
117
+ case CK_Dependent:
118
+ llvm_unreachable (" saw dependent cast!" );
119
+
120
+ case CK_BuiltinFnToFnPtr:
121
+ llvm_unreachable (" builtin functions are handled elsewhere" );
122
+
123
+ // These will never be supported.
124
+ case CK_ObjCObjectLValueCast:
125
+ case CK_ARCProduceObject:
126
+ case CK_ARCConsumeObject:
127
+ case CK_ARCReclaimReturnedObject:
128
+ case CK_ARCExtendBlockObject:
129
+ case CK_CopyAndAutoreleaseBlockObject:
130
+ return {};
131
+
132
+ // These don't need to be handled here because Evaluate knows how to
133
+ // evaluate them in the cases where they can be folded.
134
+ case CK_BitCast:
135
+ case CK_ToVoid:
136
+ case CK_Dynamic:
137
+ case CK_LValueBitCast:
138
+ case CK_LValueToRValueBitCast:
139
+ case CK_NullToMemberPointer:
140
+ case CK_UserDefinedConversion:
141
+ case CK_CPointerToObjCPointerCast:
142
+ case CK_BlockPointerToObjCPointerCast:
143
+ case CK_AnyPointerToBlockPointerCast:
144
+ case CK_ArrayToPointerDecay:
145
+ case CK_FunctionToPointerDecay:
146
+ case CK_BaseToDerived:
147
+ case CK_DerivedToBase:
148
+ case CK_UncheckedDerivedToBase:
149
+ case CK_MemberPointerToBoolean:
150
+ case CK_VectorSplat:
151
+ case CK_FloatingRealToComplex:
152
+ case CK_FloatingComplexToReal:
153
+ case CK_FloatingComplexToBoolean:
154
+ case CK_FloatingComplexCast:
155
+ case CK_FloatingComplexToIntegralComplex:
156
+ case CK_IntegralRealToComplex:
157
+ case CK_IntegralComplexToReal:
158
+ case CK_IntegralComplexToBoolean:
159
+ case CK_IntegralComplexCast:
160
+ case CK_IntegralComplexToFloatingComplex:
161
+ case CK_PointerToIntegral:
162
+ case CK_PointerToBoolean:
163
+ case CK_NullToPointer:
164
+ case CK_IntegralCast:
165
+ case CK_BooleanToSignedIntegral:
166
+ case CK_IntegralToPointer:
167
+ case CK_IntegralToBoolean:
168
+ case CK_IntegralToFloating:
169
+ case CK_FloatingToIntegral:
170
+ case CK_FloatingToBoolean:
171
+ case CK_FloatingCast:
172
+ case CK_FloatingToFixedPoint:
173
+ case CK_FixedPointToFloating:
174
+ case CK_FixedPointCast:
175
+ case CK_FixedPointToBoolean:
176
+ case CK_FixedPointToIntegral:
177
+ case CK_IntegralToFixedPoint:
178
+ case CK_ZeroToOCLOpaqueType:
179
+ case CK_MatrixCast:
180
+ case CK_HLSLArrayRValue:
181
+ case CK_HLSLVectorTruncation:
182
+ case CK_HLSLElementwiseCast:
183
+ case CK_HLSLAggregateSplatCast:
184
+ return {};
185
+ }
186
+ llvm_unreachable (" Invalid CastKind" );
95
187
}
96
188
97
189
mlir::Attribute VisitCXXDefaultInitExpr (CXXDefaultInitExpr *die, QualType t) {
@@ -118,7 +210,28 @@ class ConstExprEmitter
118
210
}
119
211
120
212
mlir::Attribute VisitInitListExpr (InitListExpr *ile, QualType t) {
121
- cgm.errorNYI (ile->getBeginLoc (), " ConstExprEmitter::VisitInitListExpr" );
213
+ if (ile->isTransparent ())
214
+ return Visit (ile->getInit (0 ), t);
215
+
216
+ if (ile->getType ()->isArrayType ()) {
217
+ // If we return null here, the non-constant initializer will take care of
218
+ // it, but we would prefer to handle it here.
219
+ assert (!cir::MissingFeatures::constEmitterArrayILE ());
220
+ return {};
221
+ }
222
+
223
+ if (ile->getType ()->isRecordType ()) {
224
+ cgm.errorNYI (ile->getBeginLoc (), " ConstExprEmitter: record ILE" );
225
+ return {};
226
+ }
227
+
228
+ if (ile->getType ()->isVectorType ()) {
229
+ // If we return null here, the non-constant initializer will take care of
230
+ // it, but we would prefer to handle it here.
231
+ assert (!cir::MissingFeatures::constEmitterVectorILE ());
232
+ return {};
233
+ }
234
+
122
235
return {};
123
236
}
124
237
@@ -218,12 +331,33 @@ emitArrayConstant(CIRGenModule &cgm, mlir::Type desiredType,
218
331
// ConstantEmitter
219
332
// ===----------------------------------------------------------------------===//
220
333
334
+ mlir::Attribute ConstantEmitter::tryEmitForInitializer (const VarDecl &d) {
335
+ initializeNonAbstract ();
336
+ return markIfFailed (tryEmitPrivateForVarInit (d));
337
+ }
338
+
339
+ void ConstantEmitter::finalize (cir::GlobalOp gv) {
340
+ assert (initializedNonAbstract &&
341
+ " finalizing emitter that was used for abstract emission?" );
342
+ assert (!finalized && " finalizing emitter multiple times" );
343
+ assert (!gv.isDeclaration ());
344
+ #ifndef NDEBUG
345
+ // Note that we might also be Failed.
346
+ finalized = true ;
347
+ #endif // NDEBUG
348
+ }
349
+
221
350
mlir::Attribute
222
351
ConstantEmitter::tryEmitAbstractForInitializer (const VarDecl &d) {
223
352
AbstractStateRAII state (*this , true );
224
353
return tryEmitPrivateForVarInit (d);
225
354
}
226
355
356
+ ConstantEmitter::~ConstantEmitter () {
357
+ assert ((!initializedNonAbstract || finalized || failed) &&
358
+ " not finalized after being initialized for non-abstract emission" );
359
+ }
360
+
227
361
mlir::Attribute ConstantEmitter::tryEmitPrivateForVarInit (const VarDecl &d) {
228
362
// Make a quick check if variable can be default NULL initialized
229
363
// and avoid going through rest of code which may do, for c++11,
0 commit comments