clang 23.0.0git
CIRGenExprAggregate.cpp
Go to the documentation of this file.
1//===- CIRGenExprAggregrate.cpp - Emit CIR Code from Aggregate Expressions ===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This contains code to emit Aggregate Expr nodes as CIR code.
10//
11//===----------------------------------------------------------------------===//
12
13#include "CIRGenBuilder.h"
14#include "CIRGenFunction.h"
15#include "CIRGenValue.h"
16#include "mlir/IR/Builders.h"
18
19#include "clang/AST/Expr.h"
22#include <cstdint>
23
24using namespace clang;
25using namespace clang::CIRGen;
26
27namespace {
28// FIXME(cir): This should be a common helper between CIRGen
29// and traditional CodeGen
30/// Is the value of the given expression possibly a reference to or
31/// into a __block variable?
32static bool isBlockVarRef(const Expr *e) {
33 // Make sure we look through parens.
34 e = e->IgnoreParens();
35
36 // Check for a direct reference to a __block variable.
37 if (const DeclRefExpr *dre = dyn_cast<DeclRefExpr>(e)) {
38 const VarDecl *var = dyn_cast<VarDecl>(dre->getDecl());
39 return (var && var->hasAttr<BlocksAttr>());
40 }
41
42 // More complicated stuff.
43
44 // Binary operators.
45 if (const BinaryOperator *op = dyn_cast<BinaryOperator>(e)) {
46 // For an assignment or pointer-to-member operation, just care
47 // about the LHS.
48 if (op->isAssignmentOp() || op->isPtrMemOp())
49 return isBlockVarRef(op->getLHS());
50
51 // For a comma, just care about the RHS.
52 if (op->getOpcode() == BO_Comma)
53 return isBlockVarRef(op->getRHS());
54
55 // FIXME: pointer arithmetic?
56 return false;
57
58 // Check both sides of a conditional operator.
59 } else if (const AbstractConditionalOperator *op =
60 dyn_cast<AbstractConditionalOperator>(e)) {
61 return isBlockVarRef(op->getTrueExpr()) ||
62 isBlockVarRef(op->getFalseExpr());
63
64 // OVEs are required to support BinaryConditionalOperators.
65 } else if (const OpaqueValueExpr *op = dyn_cast<OpaqueValueExpr>(e)) {
66 if (const Expr *src = op->getSourceExpr())
67 return isBlockVarRef(src);
68
69 // Casts are necessary to get things like (*(int*)&var) = foo().
70 // We don't really care about the kind of cast here, except
71 // we don't want to look through l2r casts, because it's okay
72 // to get the *value* in a __block variable.
73 } else if (const CastExpr *cast = dyn_cast<CastExpr>(e)) {
74 if (cast->getCastKind() == CK_LValueToRValue)
75 return false;
76 return isBlockVarRef(cast->getSubExpr());
77
78 // Handle unary operators. Again, just aggressively look through
79 // it, ignoring the operation.
80 } else if (const UnaryOperator *uop = dyn_cast<UnaryOperator>(e)) {
81 return isBlockVarRef(uop->getSubExpr());
82
83 // Look into the base of a field access.
84 } else if (const MemberExpr *mem = dyn_cast<MemberExpr>(e)) {
85 return isBlockVarRef(mem->getBase());
86
87 // Look into the base of a subscript.
88 } else if (const ArraySubscriptExpr *sub = dyn_cast<ArraySubscriptExpr>(e)) {
89 return isBlockVarRef(sub->getBase());
90 }
91
92 return false;
93}
94
95class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
96
97 CIRGenFunction &cgf;
98 AggValueSlot dest;
99
100 // Calls `fn` with a valid return value slot, potentially creating a temporary
101 // to do so. If a temporary is created, an appropriate copy into `Dest` will
102 // be emitted, as will lifetime markers.
103 //
104 // The given function should take a ReturnValueSlot, and return an RValue that
105 // points to said slot.
106 void withReturnValueSlot(const Expr *e,
107 llvm::function_ref<RValue(ReturnValueSlot)> fn);
108
109 AggValueSlot ensureSlot(mlir::Location loc, QualType t) {
110 if (!dest.isIgnored())
111 return dest;
112 return cgf.createAggTemp(t, loc, "agg.tmp.ensured");
113 }
114
115 void ensureDest(mlir::Location loc, QualType ty) {
116 if (!dest.isIgnored())
117 return;
118 dest = cgf.createAggTemp(ty, loc, "agg.tmp.ensured");
119 }
120
121public:
122 AggExprEmitter(CIRGenFunction &cgf, AggValueSlot dest)
123 : cgf(cgf), dest(dest) {}
124
125 /// Given an expression with aggregate type that represents a value lvalue,
126 /// this method emits the address of the lvalue, then loads the result into
127 /// DestPtr.
128 void emitAggLoadOfLValue(const Expr *e);
129
130 void emitArrayInit(Address destPtr, cir::ArrayType arrayTy, QualType arrayQTy,
131 Expr *exprToVisit, ArrayRef<Expr *> args,
132 Expr *arrayFiller);
133
134 void emitFinalDestCopy(QualType type, RValue src);
135
136 /// Perform the final copy to DestPtr, if desired.
137 void emitFinalDestCopy(QualType type, const LValue &src,
138 CIRGenFunction::ExprValueKind srcValueKind =
140
141 void emitCopy(QualType type, const AggValueSlot &dest,
142 const AggValueSlot &src);
143
144 void emitInitializationToLValue(Expr *e, LValue lv);
145
146 void emitNullInitializationToLValue(mlir::Location loc, LValue lv);
147
148 void Visit(Expr *e) { StmtVisitor<AggExprEmitter>::Visit(e); }
149
150 void VisitArraySubscriptExpr(ArraySubscriptExpr *e) {
151 emitAggLoadOfLValue(e);
152 }
153
154 void VisitCallExpr(const CallExpr *e);
155 void VisitStmtExpr(const StmtExpr *e) {
156 CIRGenFunction::StmtExprEvaluation eval(cgf);
157 Address retAlloca =
158 cgf.createMemTemp(e->getType(), cgf.getLoc(e->getSourceRange()));
159 (void)cgf.emitCompoundStmt(*e->getSubStmt(), &retAlloca, dest);
160 }
161
162 void VisitBinAssign(const BinaryOperator *e) {
163 // For an assignment to work, the value on the right has
164 // to be compatible with the value on the left.
165 assert(cgf.getContext().hasSameUnqualifiedType(e->getLHS()->getType(),
166 e->getRHS()->getType()) &&
167 "Invalid assignment");
168
169 if (isBlockVarRef(e->getLHS()) &&
170 e->getRHS()->HasSideEffects(cgf.getContext())) {
171 cgf.cgm.errorNYI(e->getSourceRange(),
172 "block var reference with side effects");
173 return;
174 }
175
176 LValue lhs = cgf.emitLValue(e->getLHS());
177
178 // If we have an atomic type, evaluate into the destination and then
179 // do an atomic copy.
181
182 // Codegen the RHS so that it stores directly into the LHS.
184 AggValueSlot lhsSlot = AggValueSlot::forLValue(
187
188 // A non-volatile aggregate destination might have volatile member.
189 if (!lhsSlot.isVolatile() && cgf.hasVolatileMember(e->getLHS()->getType()))
190 lhsSlot.setVolatile(true);
191
192 cgf.emitAggExpr(e->getRHS(), lhsSlot);
193
194 // Copy into the destination if the assignment isn't ignored.
195 emitFinalDestCopy(e->getType(), lhs);
196
197 if (!dest.isIgnored() && !dest.isExternallyDestructed() &&
199 cgf.pushDestroy(QualType::DK_nontrivial_c_struct, dest.getAddress(),
200 e->getType());
201 }
202
203 void VisitDeclRefExpr(DeclRefExpr *e) { emitAggLoadOfLValue(e); }
204
205 void VisitInitListExpr(InitListExpr *e);
206 void VisitCXXConstructExpr(const CXXConstructExpr *e);
207
208 void visitCXXParenListOrInitListExpr(Expr *e, ArrayRef<Expr *> args,
209 FieldDecl *initializedFieldInUnion,
210 Expr *arrayFiller);
211 void VisitCXXDefaultInitExpr(CXXDefaultInitExpr *die) {
212 CIRGenFunction::CXXDefaultInitExprScope Scope(cgf, die);
213 Visit(die->getExpr());
214 }
215 void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *e) {
216 // Ensure that we have a slot, but if we already do, remember
217 // whether it was externally destructed.
218 bool wasExternallyDestructed = dest.isExternallyDestructed();
219 ensureDest(cgf.getLoc(e->getSourceRange()), e->getType());
220
221 // We're going to push a destructor if there isn't already one.
222 dest.setExternallyDestructed();
223
224 Visit(e->getSubExpr());
225
226 // Push that destructor we promised.
227 if (!wasExternallyDestructed)
228 cgf.emitCXXTemporary(e->getTemporary(), e->getType(), dest.getAddress());
229 }
230 void VisitLambdaExpr(LambdaExpr *e);
231 void VisitExprWithCleanups(ExprWithCleanups *e);
232
233 // Stubs -- These should be moved up when they are implemented.
234 void VisitCastExpr(CastExpr *e) {
235 switch (e->getCastKind()) {
236 case CK_LValueToRValueBitCast: {
237 if (dest.isIgnored()) {
238 cgf.emitAnyExpr(e->getSubExpr(), AggValueSlot::ignored(),
239 /*ignoreResult=*/true);
240 break;
241 }
242
243 LValue sourceLV = cgf.emitLValue(e->getSubExpr());
244 Address sourceAddress =
245 sourceLV.getAddress().withElementType(cgf.getBuilder(), cgf.voidTy);
246 Address destAddress =
247 dest.getAddress().withElementType(cgf.getBuilder(), cgf.voidTy);
248
249 mlir::Location loc = cgf.getLoc(e->getExprLoc());
250
251 mlir::Value sizeVal = cgf.getBuilder().getConstInt(
252 loc, cgf.sizeTy,
253 cgf.getContext().getTypeSizeInChars(e->getType()).getQuantity());
254 cgf.getBuilder().createMemCpy(loc, destAddress.getPointer(),
255 sourceAddress.getPointer(), sizeVal);
256
257 break;
258 }
259 case CK_LValueToRValue:
260 // If we're loading from a volatile type, force the destination
261 // into existence.
263 cgf.cgm.errorNYI(e->getSourceRange(),
264 "AggExprEmitter: volatile lvalue-to-rvalue cast");
265 [[fallthrough]];
266 case CK_NoOp:
267 case CK_UserDefinedConversion:
268 case CK_ConstructorConversion:
269 assert(cgf.getContext().hasSameUnqualifiedType(e->getSubExpr()->getType(),
270 e->getType()) &&
271 "Implicit cast types must be compatible");
272 Visit(e->getSubExpr());
273 break;
274 default:
275 cgf.cgm.errorNYI(e->getSourceRange(),
276 std::string("AggExprEmitter: VisitCastExpr: ") +
277 e->getCastKindName());
278 break;
279 }
280 }
281 void VisitStmt(Stmt *s) {
282 cgf.cgm.errorNYI(s->getSourceRange(),
283 std::string("AggExprEmitter::VisitStmt: ") +
284 s->getStmtClassName());
285 }
286 void VisitParenExpr(ParenExpr *pe) { Visit(pe->getSubExpr()); }
287 void VisitGenericSelectionExpr(GenericSelectionExpr *ge) {
288 Visit(ge->getResultExpr());
289 }
290 void VisitCoawaitExpr(CoawaitExpr *e) {
291 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitCoawaitExpr");
292 }
293 void VisitCoyieldExpr(CoyieldExpr *e) {
294 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitCoyieldExpr");
295 }
296 void VisitUnaryCoawait(UnaryOperator *e) {
297 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitUnaryCoawait");
298 }
299 void VisitUnaryExtension(UnaryOperator *e) { Visit(e->getSubExpr()); }
300 void VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *e) {
301 cgf.cgm.errorNYI(e->getSourceRange(),
302 "AggExprEmitter: VisitSubstNonTypeTemplateParmExpr");
303 }
304 void VisitConstantExpr(ConstantExpr *e) {
305 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitConstantExpr");
306 }
307 void VisitMemberExpr(MemberExpr *e) { emitAggLoadOfLValue(e); }
308 void VisitUnaryDeref(UnaryOperator *e) { emitAggLoadOfLValue(e); }
309 void VisitStringLiteral(StringLiteral *e) { emitAggLoadOfLValue(e); }
310 void VisitCompoundLiteralExpr(CompoundLiteralExpr *e);
311
312 void VisitPredefinedExpr(const PredefinedExpr *e) {
313 cgf.cgm.errorNYI(e->getSourceRange(),
314 "AggExprEmitter: VisitPredefinedExpr");
315 }
316 void VisitBinaryOperator(const BinaryOperator *e) {
317 cgf.cgm.errorNYI(e->getSourceRange(),
318 "AggExprEmitter: VisitBinaryOperator");
319 }
320 void VisitPointerToDataMemberBinaryOperator(const BinaryOperator *e) {
321 cgf.cgm.errorNYI(e->getSourceRange(),
322 "AggExprEmitter: VisitPointerToDataMemberBinaryOperator");
323 }
324 void VisitBinComma(const BinaryOperator *e) {
325 cgf.emitIgnoredExpr(e->getLHS());
326 Visit(e->getRHS());
327 }
328 void VisitBinCmp(const BinaryOperator *e) {
329 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitBinCmp");
330 }
331 void VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *e) {
332 cgf.cgm.errorNYI(e->getSourceRange(),
333 "AggExprEmitter: VisitCXXRewrittenBinaryOperator");
334 }
335 void VisitObjCMessageExpr(ObjCMessageExpr *e) {
336 cgf.cgm.errorNYI(e->getSourceRange(),
337 "AggExprEmitter: VisitObjCMessageExpr");
338 }
339 void VisitObjCIVarRefExpr(ObjCIvarRefExpr *e) {
340 cgf.cgm.errorNYI(e->getSourceRange(),
341 "AggExprEmitter: VisitObjCIVarRefExpr");
342 }
343
344 void VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *e) {
345 AggValueSlot dest = ensureSlot(cgf.getLoc(e->getExprLoc()), e->getType());
346 LValue destLV = cgf.makeAddrLValue(dest.getAddress(), e->getType());
347 emitInitializationToLValue(e->getBase(), destLV);
348 VisitInitListExpr(e->getUpdater());
349 }
350 void VisitAbstractConditionalOperator(const AbstractConditionalOperator *e) {
351 cgf.cgm.errorNYI(e->getSourceRange(),
352 "AggExprEmitter: VisitAbstractConditionalOperator");
353 }
354 void VisitChooseExpr(const ChooseExpr *e) { Visit(e->getChosenSubExpr()); }
355 void VisitCXXParenListInitExpr(CXXParenListInitExpr *e) {
356 visitCXXParenListOrInitListExpr(e, e->getInitExprs(),
358 e->getArrayFiller());
359 }
360
361 void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *e,
362 llvm::Value *outerBegin = nullptr) {
363 cgf.cgm.errorNYI(e->getSourceRange(),
364 "AggExprEmitter: VisitArrayInitLoopExpr");
365 }
366 void VisitImplicitValueInitExpr(ImplicitValueInitExpr *e) {
367 cgf.cgm.errorNYI(e->getSourceRange(),
368 "AggExprEmitter: VisitImplicitValueInitExpr");
369 }
370 void VisitNoInitExpr(NoInitExpr *e) {
371 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitNoInitExpr");
372 }
373 void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *dae) {
374 CIRGenFunction::CXXDefaultArgExprScope scope(cgf, dae);
375 Visit(dae->getExpr());
376 }
377 void VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *e) {
378 cgf.cgm.errorNYI(e->getSourceRange(),
379 "AggExprEmitter: VisitCXXInheritedCtorInitExpr");
380 }
381 void VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *e) {
382 cgf.cgm.errorNYI(e->getSourceRange(),
383 "AggExprEmitter: VisitCXXStdInitializerListExpr");
384 }
385 void VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *e) {
386 cgf.cgm.errorNYI(e->getSourceRange(),
387 "AggExprEmitter: VisitCXXScalarValueInitExpr");
388 }
389 void VisitCXXTypeidExpr(CXXTypeidExpr *e) {
390 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitCXXTypeidExpr");
391 }
392 void VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *e) {
393 Visit(e->getSubExpr());
394 }
395 void VisitOpaqueValueExpr(OpaqueValueExpr *e) {
396 cgf.cgm.errorNYI(e->getSourceRange(),
397 "AggExprEmitter: VisitOpaqueValueExpr");
398 }
399
400 void VisitPseudoObjectExpr(PseudoObjectExpr *e) {
401 cgf.cgm.errorNYI(e->getSourceRange(),
402 "AggExprEmitter: VisitPseudoObjectExpr");
403 }
404
405 void VisitVAArgExpr(VAArgExpr *e) {
406 // emitVAArg returns an aggregate value (not a pointer) at the CIR level.
407 // ABI-specific pointer handling will be done later in LoweringPrepare.
408 mlir::Value vaArgValue = cgf.emitVAArg(e);
409
410 // Create a temporary alloca to hold the aggregate value.
411 mlir::Location loc = cgf.getLoc(e->getSourceRange());
412 Address tmpAddr = cgf.createMemTemp(e->getType(), loc, "vaarg.tmp");
413
414 // Store the va_arg result into the temporary.
415 cgf.emitAggregateStore(vaArgValue, tmpAddr);
416
417 // Create an LValue from the temporary address.
418 LValue tmpLValue = cgf.makeAddrLValue(tmpAddr, e->getType());
419
420 // Copy the aggregate value from temporary to destination.
421 emitFinalDestCopy(e->getType(), tmpLValue);
422 }
423
424 void VisitCXXThrowExpr(const CXXThrowExpr *e) {
425 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitCXXThrowExpr");
426 }
427 void VisitAtomicExpr(AtomicExpr *e) {
428 RValue result = cgf.emitAtomicExpr(e);
429 emitFinalDestCopy(e->getType(), result);
430 }
431};
432
433} // namespace
434
435static bool isTrivialFiller(Expr *e) {
436 if (!e)
437 return true;
438
440 return true;
441
442 if (auto *ile = dyn_cast<InitListExpr>(e)) {
443 if (ile->getNumInits())
444 return false;
445 return isTrivialFiller(ile->getArrayFiller());
446 }
447
448 if (const auto *cons = dyn_cast_or_null<CXXConstructExpr>(e))
449 return cons->getConstructor()->isDefaultConstructor() &&
450 cons->getConstructor()->isTrivial();
451
452 return false;
453}
454
455/// Given an expression with aggregate type that represents a value lvalue, this
456/// method emits the address of the lvalue, then loads the result into DestPtr.
457void AggExprEmitter::emitAggLoadOfLValue(const Expr *e) {
458 LValue lv = cgf.emitLValue(e);
459
460 // If the type of the l-value is atomic, then do an atomic load.
462
463 emitFinalDestCopy(e->getType(), lv);
464}
465
466void AggExprEmitter::VisitCompoundLiteralExpr(CompoundLiteralExpr *e) {
467 if (dest.isPotentiallyAliased() && e->getType().isPODType(cgf.getContext())) {
468 // For a POD type, just emit a load of the lvalue + a copy, because our
469 // compound literal might alias the destination.
470 emitAggLoadOfLValue(e);
471 return;
472 }
473
474 AggValueSlot slot = ensureSlot(cgf.getLoc(e->getSourceRange()), e->getType());
475
476 // Block-scope compound literals are destroyed at the end of the enclosing
477 // scope in C.
478 bool destruct =
479 !cgf.getLangOpts().CPlusPlus && !slot.isExternallyDestructed();
480 if (destruct)
482
483 cgf.emitAggExpr(e->getInitializer(), slot);
484
485 if (destruct)
486 if ([[maybe_unused]] QualType::DestructionKind dtorKind =
488 cgf.cgm.errorNYI(e->getSourceRange(), "compound literal with destructor");
489}
490
491void AggExprEmitter::emitArrayInit(Address destPtr, cir::ArrayType arrayTy,
492 QualType arrayQTy, Expr *e,
493 ArrayRef<Expr *> args, Expr *arrayFiller) {
494 CIRGenBuilderTy &builder = cgf.getBuilder();
495 const mlir::Location loc = cgf.getLoc(e->getSourceRange());
496
497 const uint64_t numInitElements = args.size();
498
499 const QualType elementType =
500 cgf.getContext().getAsArrayType(arrayQTy)->getElementType();
501
502 if (elementType.isDestructedType() && cgf.cgm.getLangOpts().Exceptions) {
503 cgf.cgm.errorNYI(loc, "initialized array requires destruction");
504 return;
505 }
506
507 const QualType elementPtrType = cgf.getContext().getPointerType(elementType);
508
509 const mlir::Type cirElementType = cgf.convertType(elementType);
510 const cir::PointerType cirElementPtrType =
511 builder.getPointerTo(cirElementType);
512
513 auto begin = cir::CastOp::create(builder, loc, cirElementPtrType,
514 cir::CastKind::array_to_ptrdecay,
515 destPtr.getPointer());
516
517 const CharUnits elementSize =
518 cgf.getContext().getTypeSizeInChars(elementType);
519 const CharUnits elementAlign =
520 destPtr.getAlignment().alignmentOfArrayElement(elementSize);
521
522 // The 'current element to initialize'. The invariants on this
523 // variable are complicated. Essentially, after each iteration of
524 // the loop, it points to the last initialized element, except
525 // that it points to the beginning of the array before any
526 // elements have been initialized.
527 mlir::Value element = begin;
528
529 // Don't build the 'one' before the cycle to avoid
530 // emmiting the redundant `cir.const 1` instrs.
531 mlir::Value one;
532
533 // Emit the explicit initializers.
534 for (uint64_t i = 0; i != numInitElements; ++i) {
535 // Advance to the next element.
536 if (i > 0) {
537 one = builder.getConstantInt(loc, cgf.ptrDiffTy, i);
538 element = builder.createPtrStride(loc, begin, one);
539 }
540
541 const Address address = Address(element, cirElementType, elementAlign);
542 const LValue elementLV = cgf.makeAddrLValue(address, elementType);
543 emitInitializationToLValue(args[i], elementLV);
544 }
545
546 const uint64_t numArrayElements = arrayTy.getSize();
547
548 // Check whether there's a non-trivial array-fill expression.
549 const bool hasTrivialFiller = isTrivialFiller(arrayFiller);
550
551 // Any remaining elements need to be zero-initialized, possibly
552 // using the filler expression. We can skip this if the we're
553 // emitting to zeroed memory.
554 if (numInitElements != numArrayElements &&
555 !(dest.isZeroed() && hasTrivialFiller &&
556 cgf.getTypes().isZeroInitializable(elementType))) {
557 // Advance to the start of the rest of the array.
558 if (numInitElements) {
559 one = builder.getConstantInt(loc, cgf.ptrDiffTy, 1);
560 element = cir::PtrStrideOp::create(builder, loc, cirElementPtrType,
561 element, one);
562 }
563
564 // Allocate the temporary variable
565 // to store the pointer to first unitialized element
566 const Address tmpAddr = cgf.createTempAlloca(
567 cirElementPtrType, cgf.getPointerAlign(), loc, "arrayinit.temp");
568 LValue tmpLV = cgf.makeAddrLValue(tmpAddr, elementPtrType);
569 cgf.emitStoreThroughLValue(RValue::get(element), tmpLV);
570
571 // Compute the end of array
572 cir::ConstantOp numArrayElementsConst = builder.getConstInt(
573 loc, mlir::cast<cir::IntType>(cgf.ptrDiffTy), numArrayElements);
574 mlir::Value end = cir::PtrStrideOp::create(builder, loc, cirElementPtrType,
575 begin, numArrayElementsConst);
576
577 builder.createDoWhile(
578 loc,
579 /*condBuilder=*/
580 [&](mlir::OpBuilder &b, mlir::Location loc) {
581 cir::LoadOp currentElement = builder.createLoad(loc, tmpAddr);
582 cir::CmpOp cmp = cir::CmpOp::create(builder, loc, cir::CmpOpKind::ne,
583 currentElement, end);
584 builder.createCondition(cmp);
585 },
586 /*bodyBuilder=*/
587 [&](mlir::OpBuilder &b, mlir::Location loc) {
588 cir::LoadOp currentElement = builder.createLoad(loc, tmpAddr);
589
591
592 // Emit the actual filler expression.
593 LValue elementLV = cgf.makeAddrLValue(
594 Address(currentElement, cirElementType, elementAlign),
595 elementType);
596 if (arrayFiller)
597 emitInitializationToLValue(arrayFiller, elementLV);
598 else
599 emitNullInitializationToLValue(loc, elementLV);
600
601 // Tell the EH cleanup that we finished with the last element.
602 if (cgf.cgm.getLangOpts().Exceptions) {
603 cgf.cgm.errorNYI(loc, "update destructed array element for EH");
604 return;
605 }
606
607 // Advance pointer and store them to temporary variable
608 cir::ConstantOp one = builder.getConstInt(
609 loc, mlir::cast<cir::IntType>(cgf.ptrDiffTy), 1);
610 auto nextElement = cir::PtrStrideOp::create(
611 builder, loc, cirElementPtrType, currentElement, one);
612 cgf.emitStoreThroughLValue(RValue::get(nextElement), tmpLV);
613
614 builder.createYield(loc);
615 });
616 }
617}
618
619/// EmitFinalDestCopy - Perform the final copy to DestPtr, if desired.
620void AggExprEmitter::emitFinalDestCopy(QualType type, RValue src) {
621 assert(src.isAggregate() && "value must be aggregate value!");
622 LValue srcLV = cgf.makeAddrLValue(src.getAggregateAddress(), type);
623 emitFinalDestCopy(type, srcLV, CIRGenFunction::EVK_RValue);
624}
625
626/// Perform the final copy to destPtr, if desired.
627void AggExprEmitter::emitFinalDestCopy(
628 QualType type, const LValue &src,
629 CIRGenFunction::ExprValueKind srcValueKind) {
630 // If dest is ignored, then we're evaluating an aggregate expression
631 // in a context that doesn't care about the result. Note that loads
632 // from volatile l-values force the existence of a non-ignored
633 // destination.
634 if (dest.isIgnored())
635 return;
636
637 if (srcValueKind == CIRGenFunction::EVK_RValue) {
638 if (type.isNonTrivialToPrimitiveDestructiveMove() == QualType::PCK_Struct) {
639 cgf.cgm.errorNYI("emitFinalDestCopy: EVK_RValue & PCK_Struct");
640 }
641 } else {
642 if (type.isNonTrivialToPrimitiveCopy() == QualType::PCK_Struct) {
643 cgf.cgm.errorNYI("emitFinalDestCopy: !EVK_RValue & PCK_Struct");
644 }
645 }
646
650
651 AggValueSlot srcAgg = AggValueSlot::forLValue(src, AggValueSlot::IsDestructed,
654 emitCopy(type, dest, srcAgg);
655}
656
657/// Perform a copy from the source into the destination.
658///
659/// \param type - the type of the aggregate being copied; qualifiers are
660/// ignored
661void AggExprEmitter::emitCopy(QualType type, const AggValueSlot &dest,
662 const AggValueSlot &src) {
664
665 // If the result of the assignment is used, copy the LHS there also.
666 // It's volatile if either side is. Use the minimum alignment of
667 // the two sides.
668 LValue destLV = cgf.makeAddrLValue(dest.getAddress(), type);
669 LValue srcLV = cgf.makeAddrLValue(src.getAddress(), type);
671 cgf.emitAggregateCopy(destLV, srcLV, type, dest.mayOverlap(),
672 dest.isVolatile() || src.isVolatile());
673}
674
675void AggExprEmitter::emitInitializationToLValue(Expr *e, LValue lv) {
676 const QualType type = lv.getType();
677
679 const mlir::Location loc = e->getSourceRange().isValid()
680 ? cgf.getLoc(e->getSourceRange())
681 : *cgf.currSrcLoc;
682 return emitNullInitializationToLValue(loc, lv);
683 }
684
685 if (isa<NoInitExpr>(e))
686 return;
687
688 if (type->isReferenceType()) {
689 RValue rv = cgf.emitReferenceBindingToExpr(e);
690 return cgf.emitStoreThroughLValue(rv, lv);
691 }
692
693 switch (cgf.getEvaluationKind(type)) {
694 case cir::TEK_Complex:
695 cgf.emitComplexExprIntoLValue(e, lv, /*isInit*/ true);
696 break;
701 dest.isZeroed()));
702
703 return;
704 case cir::TEK_Scalar:
705 if (lv.isSimple())
706 cgf.emitScalarInit(e, cgf.getLoc(e->getSourceRange()), lv);
707 else
709 return;
710 }
711}
712
713void AggExprEmitter::VisitCXXConstructExpr(const CXXConstructExpr *e) {
714 AggValueSlot slot = ensureSlot(cgf.getLoc(e->getSourceRange()), e->getType());
715 cgf.emitCXXConstructExpr(e, slot);
716}
717
718void AggExprEmitter::emitNullInitializationToLValue(mlir::Location loc,
719 LValue lv) {
720 const QualType type = lv.getType();
721
722 // If the destination slot is already zeroed out before the aggregate is
723 // copied into it, we don't have to emit any zeros here.
724 if (dest.isZeroed() && cgf.getTypes().isZeroInitializable(type))
725 return;
726
727 if (cgf.hasScalarEvaluationKind(type)) {
728 // For non-aggregates, we can store the appropriate null constant.
729 mlir::Value null = cgf.cgm.emitNullConstant(type, loc);
730 if (lv.isSimple()) {
731 cgf.emitStoreOfScalar(null, lv, /* isInitialization */ true);
732 return;
733 }
734
736 return;
737 }
738
739 // There's a potential optimization opportunity in combining
740 // memsets; that would be easy for arrays, but relatively
741 // difficult for structures with the current code.
742 cgf.emitNullInitialization(loc, lv.getAddress(), lv.getType());
743}
744
745void AggExprEmitter::VisitLambdaExpr(LambdaExpr *e) {
746 CIRGenFunction::SourceLocRAIIObject loc{cgf, cgf.getLoc(e->getSourceRange())};
747 AggValueSlot slot = ensureSlot(cgf.getLoc(e->getSourceRange()), e->getType());
748 [[maybe_unused]] LValue slotLV =
749 cgf.makeAddrLValue(slot.getAddress(), e->getType());
750
751 // We'll need to enter cleanup scopes in case any of the element
752 // initializers throws an exception or contains branch out of the expressions.
754
755 for (auto [curField, capture, captureInit] : llvm::zip(
756 e->getLambdaClass()->fields(), e->captures(), e->capture_inits())) {
757 // Pick a name for the field.
758 llvm::StringRef fieldName = curField->getName();
759 if (capture.capturesVariable()) {
760 assert(!curField->isBitField() && "lambdas don't have bitfield members!");
761 ValueDecl *v = capture.getCapturedVar();
762 fieldName = v->getName();
763 cgf.cgm.lambdaFieldToName[curField] = fieldName;
764 } else if (capture.capturesThis()) {
765 cgf.cgm.lambdaFieldToName[curField] = "this";
766 } else {
767 cgf.cgm.errorNYI(e->getSourceRange(), "Unhandled capture kind");
768 cgf.cgm.lambdaFieldToName[curField] = "unhandled-capture-kind";
769 }
770
771 // Emit initialization
772 LValue lv =
773 cgf.emitLValueForFieldInitialization(slotLV, curField, fieldName);
774 if (curField->hasCapturedVLAType())
775 cgf.cgm.errorNYI(e->getSourceRange(), "lambda captured VLA type");
776
777 emitInitializationToLValue(captureInit, lv);
778
779 // Push a destructor if necessary.
780 if ([[maybe_unused]] QualType::DestructionKind DtorKind =
781 curField->getType().isDestructedType())
782 cgf.cgm.errorNYI(e->getSourceRange(), "lambda with destructed field");
783 }
784}
785
786void AggExprEmitter::VisitExprWithCleanups(ExprWithCleanups *e) {
787 CIRGenFunction::RunCleanupsScope cleanups(cgf);
788 CIRGenBuilderTy &builder = cgf.getBuilder();
789 mlir::Location scopeLoc = cgf.getLoc(e->getSourceRange());
790 mlir::OpBuilder::InsertPoint scopeBegin;
791
792 // Explicitly introduce a scope for cleanup expressions, even though this
793 // overlaps with the RunCleanupsScope above.
794 //
795 // CIR does not yet model cleanup scopes explicitly, so a lexical scope is
796 // used as a temporary approximation. This is expected to be revisited once
797 // cleanup handling is redesigned.
798 cir::ScopeOp::create(builder, scopeLoc, /*scopeBuilder=*/
799 [&](mlir::OpBuilder &b, mlir::Location loc) {
800 scopeBegin = b.saveInsertionPoint();
801 });
802
803 {
804 mlir::OpBuilder::InsertionGuard guard(builder);
805 builder.restoreInsertionPoint(scopeBegin);
806 CIRGenFunction::LexicalScope lexScope{cgf, scopeLoc,
807 builder.getInsertionBlock()};
808 Visit(e->getSubExpr());
809 }
810}
811
812void AggExprEmitter::VisitCallExpr(const CallExpr *e) {
814 cgf.cgm.errorNYI(e->getSourceRange(), "reference return type");
815 return;
816 }
817
818 withReturnValueSlot(
819 e, [&](ReturnValueSlot slot) { return cgf.emitCallExpr(e, slot); });
820}
821
822void AggExprEmitter::withReturnValueSlot(
823 const Expr *e, llvm::function_ref<RValue(ReturnValueSlot)> fn) {
824 QualType retTy = e->getType();
825
827 bool requiresDestruction =
829 if (requiresDestruction)
830 cgf.cgm.errorNYI(
831 e->getSourceRange(),
832 "withReturnValueSlot: return value requiring destruction is NYI");
833
834 // If it makes no observable difference, save a memcpy + temporary.
835 //
836 // We need to always provide our own temporary if destruction is required.
837 // Otherwise, fn will emit its own, notice that it's "unused", and end its
838 // lifetime before we have the chance to emit a proper destructor call.
841
842 Address retAddr = dest.getAddress();
844
847 fn(ReturnValueSlot(retAddr));
848}
849
850void AggExprEmitter::VisitInitListExpr(InitListExpr *e) {
852 llvm_unreachable("GNU array range designator extension");
853
854 if (e->isTransparent())
855 return Visit(e->getInit(0));
856
857 visitCXXParenListOrInitListExpr(
859}
860
861void AggExprEmitter::visitCXXParenListOrInitListExpr(
862 Expr *e, ArrayRef<Expr *> args, FieldDecl *initializedFieldInUnion,
863 Expr *arrayFiller) {
864
865 const mlir::Location loc = cgf.getLoc(e->getSourceRange());
866 const AggValueSlot dest = ensureSlot(loc, e->getType());
867
868 if (e->getType()->isConstantArrayType()) {
869 cir::ArrayType arrayTy =
871 emitArrayInit(dest.getAddress(), arrayTy, e->getType(), e, args,
872 arrayFiller);
873 return;
874 } else if (e->getType()->isVariableArrayType()) {
875 cgf.cgm.errorNYI(e->getSourceRange(),
876 "visitCXXParenListOrInitListExpr variable array type");
877 return;
878 }
879
880 if (e->getType()->isArrayType()) {
881 cgf.cgm.errorNYI(e->getSourceRange(),
882 "visitCXXParenListOrInitListExpr array type");
883 return;
884 }
885
886 assert(e->getType()->isRecordType() && "Only support structs/unions here!");
887
888 // Do struct initialization; this code just sets each individual member
889 // to the approprate value. This makes bitfield support automatic;
890 // the disadvantage is that the generated code is more difficult for
891 // the optimizer, especially with bitfields.
892 unsigned numInitElements = args.size();
893 auto *record = e->getType()->castAsRecordDecl();
894
895 // We'll need to enter cleanup scopes in case any of the element
896 // initializers throws an exception.
898
899 unsigned curInitIndex = 0;
900
901 // Emit initialization of base classes.
902 if (auto *cxxrd = dyn_cast<CXXRecordDecl>(record)) {
903 assert(numInitElements >= cxxrd->getNumBases() &&
904 "missing initializer for base class");
905 for (auto &base : cxxrd->bases()) {
906 assert(!base.isVirtual() && "should not see vbases here");
907 CXXRecordDecl *baseRD = base.getType()->getAsCXXRecordDecl();
908 Address address = cgf.getAddressOfDirectBaseInCompleteClass(
909 loc, dest.getAddress(), cxxrd, baseRD,
910 /*baseIsVirtual=*/false);
912 AggValueSlot aggSlot = AggValueSlot::forAddr(
913 address, Qualifiers(), AggValueSlot::IsDestructed,
915 cgf.getOverlapForBaseInit(cxxrd, baseRD, false));
916 cgf.emitAggExpr(args[curInitIndex++], aggSlot);
917 if (base.getType().isDestructedType()) {
918 cgf.cgm.errorNYI(e->getSourceRange(),
919 "push deferred deactivation cleanup");
920 return;
921 }
922 }
923 }
924
925 // Prepare a 'this' for CXXDefaultInitExprs.
926 CIRGenFunction::FieldConstructionScope fcScope(cgf, dest.getAddress());
927
928 LValue destLV = cgf.makeAddrLValue(dest.getAddress(), e->getType());
929
930 if (record->isUnion()) {
931 cgf.cgm.errorNYI(e->getSourceRange(),
932 "visitCXXParenListOrInitListExpr union type");
933 return;
934 }
935
936 // Here we iterate over the fields; this makes it simpler to both
937 // default-initialize fields and skip over unnamed fields.
938 for (const FieldDecl *field : record->fields()) {
939 // We're done once we hit the flexible array member.
940 if (field->getType()->isIncompleteArrayType())
941 break;
942
943 // Always skip anonymous bitfields.
944 if (field->isUnnamedBitField())
945 continue;
946
947 // We're done if we reach the end of the explicit initializers, we
948 // have a zeroed object, and the rest of the fields are
949 // zero-initializable.
950 if (curInitIndex == numInitElements && dest.isZeroed() &&
952 break;
953 LValue lv =
954 cgf.emitLValueForFieldInitialization(destLV, field, field->getName());
955 // We never generate write-barriers for initialized fields.
957
958 if (curInitIndex < numInitElements) {
959 // Store the initializer into the field.
960 CIRGenFunction::SourceLocRAIIObject loc{
961 cgf, cgf.getLoc(record->getSourceRange())};
962 emitInitializationToLValue(args[curInitIndex++], lv);
963 } else {
964 // We're out of initializers; default-initialize to null
965 emitNullInitializationToLValue(cgf.getLoc(e->getSourceRange()), lv);
966 }
967
968 // Push a destructor if necessary.
969 // FIXME: if we have an array of structures, all explicitly
970 // initialized, we can end up pushing a linear number of cleanups.
971 if (field->getType().isDestructedType()) {
972 cgf.cgm.errorNYI(e->getSourceRange(),
973 "visitCXXParenListOrInitListExpr destructor");
974 return;
975 }
976
977 // From classic codegen, maybe not useful for CIR:
978 // If the GEP didn't get used because of a dead zero init or something
979 // else, clean it up for -O0 builds and general tidiness.
980 }
981}
982
983// TODO(cir): This could be shared with classic codegen.
985 const CXXRecordDecl *rd, const CXXRecordDecl *baseRD, bool isVirtual) {
986 // If the most-derived object is a field declared with [[no_unique_address]],
987 // the tail padding of any virtual base could be reused for other subobjects
988 // of that field's class.
989 if (isVirtual)
991
992 // If the base class is laid out entirely within the nvsize of the derived
993 // class, its tail padding cannot yet be initialized, so we can issue
994 // stores at the full width of the base class.
995 const ASTRecordLayout &layout = getContext().getASTRecordLayout(rd);
996 if (layout.getBaseClassOffset(baseRD) +
997 getContext().getASTRecordLayout(baseRD).getSize() <=
998 layout.getNonVirtualSize())
1000
1001 // The tail padding may contain values we need to preserve.
1003}
1004
1006 AggExprEmitter(*this, slot).Visit(const_cast<Expr *>(e));
1007}
1008
1010 AggValueSlot::Overlap_t mayOverlap,
1011 bool isVolatile) {
1012 // TODO(cir): this function needs improvements, commented code for now since
1013 // this will be touched again soon.
1014 assert(!ty->isAnyComplexType() && "Unexpected copy of complex");
1015
1016 Address destPtr = dest.getAddress();
1017 Address srcPtr = src.getAddress();
1018
1019 if (getLangOpts().CPlusPlus) {
1020 if (auto *record = ty->getAsCXXRecordDecl()) {
1021 assert((record->hasTrivialCopyConstructor() ||
1022 record->hasTrivialCopyAssignment() ||
1023 record->hasTrivialMoveConstructor() ||
1024 record->hasTrivialMoveAssignment() ||
1025 record->hasAttr<TrivialABIAttr>() || record->isUnion()) &&
1026 "Trying to aggregate-copy a type without a trivial copy/move "
1027 "constructor or assignment operator");
1028 // Ignore empty classes in C++.
1029 if (record->isEmpty())
1030 return;
1031 }
1032 }
1033
1035
1036 // Aggregate assignment turns into llvm.memcpy. This is almost valid per
1037 // C99 6.5.16.1p3, which states "If the value being stored in an object is
1038 // read from another object that overlaps in anyway the storage of the first
1039 // object, then the overlap shall be exact and the two objects shall have
1040 // qualified or unqualified versions of a compatible type."
1041 //
1042 // memcpy is not defined if the source and destination pointers are exactly
1043 // equal, but other compilers do this optimization, and almost every memcpy
1044 // implementation handles this case safely. If there is a libc that does not
1045 // safely handle this, we can add a target hook.
1046
1047 // Get data size info for this aggregate. Don't copy the tail padding if this
1048 // might be a potentially-overlapping subobject, since the tail padding might
1049 // be occupied by a different object. Otherwise, copying it is fine.
1050 TypeInfoChars typeInfo;
1051 if (mayOverlap)
1052 typeInfo = getContext().getTypeInfoDataSizeInChars(ty);
1053 else
1054 typeInfo = getContext().getTypeInfoInChars(ty);
1055
1057
1058 // NOTE(cir): original codegen would normally convert destPtr and srcPtr to
1059 // i8* since memcpy operates on bytes. We don't need that in CIR because
1060 // cir.copy will operate on any CIR pointer that points to a sized type.
1061
1062 // Don't do any of the memmove_collectable tests if GC isn't set.
1063 if (cgm.getLangOpts().getGC() != LangOptions::NonGC)
1064 cgm.errorNYI("emitAggregateCopy: GC");
1065
1066 [[maybe_unused]] cir::CopyOp copyOp =
1067 builder.createCopy(destPtr.getPointer(), srcPtr.getPointer(), isVolatile);
1068
1070}
1071
1072// TODO(cir): This could be shared with classic codegen.
1075 if (!fd->hasAttr<NoUniqueAddressAttr>() || !fd->getType()->isRecordType())
1077
1078 // If the field lies entirely within the enclosing class's nvsize, its tail
1079 // padding cannot overlap any already-initialized object. (The only subobjects
1080 // with greater addresses that might already be initialized are vbases.)
1081 const RecordDecl *classRD = fd->getParent();
1082 const ASTRecordLayout &layout = getContext().getASTRecordLayout(classRD);
1083 if (layout.getFieldOffset(fd->getFieldIndex()) +
1084 getContext().getTypeSize(fd->getType()) <=
1085 (uint64_t)getContext().toBits(layout.getNonVirtualSize()))
1087
1088 // The tail padding may contain values we need to preserve.
1090}
1091
static bool isBlockVarRef(const Expr *E)
Is the value of the given expression possibly a reference to or into a __block variable?
static bool isTrivialFiller(Expr *e)
__device__ __2f16 b
__device__ __2f16 float __ockl_bool s
cir::ConditionOp createCondition(mlir::Value condition)
Create a loop condition.
cir::PtrStrideOp createPtrStride(mlir::Location loc, mlir::Value base, mlir::Value stride)
cir::PointerType getPointerTo(mlir::Type ty)
cir::DoWhileOp createDoWhile(mlir::Location loc, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> condBuilder, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> bodyBuilder)
Create a do-while operation.
cir::ConstantOp getConstantInt(mlir::Location loc, mlir::Type ty, int64_t value)
cir::YieldOp createYield(mlir::Location loc, mlir::ValueRange value={})
Create a yield operation.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
CharUnits getNonVirtualSize() const
getNonVirtualSize - Get the non-virtual size (in chars) of an object, which is the size of the object...
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Definition Expr.h:4353
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2721
QualType getElementType() const
Definition TypeBase.h:3735
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4038
Expr * getLHS() const
Definition Expr.h:4088
Expr * getRHS() const
Definition Expr.h:4090
mlir::Value getPointer() const
Definition Address.h:95
mlir::Type getElementType() const
Definition Address.h:122
clang::CharUnits getAlignment() const
Definition Address.h:135
An aggregate value slot.
IsZeroed_t isZeroed() const
Overlap_t mayOverlap() const
static AggValueSlot forAddr(Address addr, clang::Qualifiers quals, IsDestructed_t isDestructed, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed)
IsDestructed_t isExternallyDestructed() const
static AggValueSlot forLValue(const LValue &LV, IsDestructed_t isDestructed, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed)
void setExternallyDestructed(bool destructed=true)
static AggValueSlot ignored()
Returns an aggregate value slot indicating that the aggregate value is being ignored.
IsAliased_t isPotentiallyAliased() const
void setVolatile(bool flag)
cir::ConstantOp getConstInt(mlir::Location loc, llvm::APSInt intVal)
cir::LoadOp createLoad(mlir::Location loc, Address addr, bool isVolatile=false)
static bool hasScalarEvaluationKind(clang::QualType type)
mlir::Type convertType(clang::QualType t)
static cir::TypeEvaluationKind getEvaluationKind(clang::QualType type)
Return the cir::TypeEvaluationKind of QualType type.
CIRGenTypes & getTypes() const
const clang::LangOptions & getLangOpts() const
cir::AllocaOp createTempAlloca(mlir::Type ty, mlir::Location loc, const Twine &name="tmp", mlir::Value arraySize=nullptr, bool insertIntoFnEntryBlock=false)
This creates an alloca and inserts it into the entry block if ArraySize is nullptr,...
RValue emitCallExpr(const clang::CallExpr *e, ReturnValueSlot returnValue=ReturnValueSlot())
LValue emitLValue(const clang::Expr *e)
Emit code to compute a designator that specifies the location of the expression.
void emitAggregateCopy(LValue dest, LValue src, QualType eltTy, AggValueSlot::Overlap_t mayOverlap, bool isVolatile=false)
Emit an aggregate copy.
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
void emitNullInitialization(mlir::Location loc, Address destPtr, QualType ty)
RValue emitReferenceBindingToExpr(const Expr *e)
Emits a reference binding to the passed in expression.
AggValueSlot::Overlap_t getOverlapForFieldInit(const FieldDecl *fd)
void emitCXXConstructExpr(const clang::CXXConstructExpr *e, AggValueSlot dest)
LValue emitAggExprToLValue(const Expr *e)
void emitStoreOfScalar(mlir::Value value, Address addr, bool isVolatile, clang::QualType ty, LValueBaseInfo baseInfo, bool isInit=false, bool isNontemporal=false)
static bool hasAggregateEvaluationKind(clang::QualType type)
void emitScalarInit(const clang::Expr *init, mlir::Location loc, LValue lvalue, bool capturedByInit=false)
LValue emitLValueForFieldInitialization(LValue base, const clang::FieldDecl *field, llvm::StringRef fieldName)
Like emitLValueForField, excpet that if the Field is a reference, this will return the address of the...
mlir::Value emitScalarExpr(const clang::Expr *e, bool ignoreResultAssign=false)
Emit the computation of the specified expression of scalar type.
Address getAddressOfDirectBaseInCompleteClass(mlir::Location loc, Address value, const CXXRecordDecl *derived, const CXXRecordDecl *base, bool baseIsVirtual)
Convert the given pointer to a complete class to the given direct base.
CIRGenBuilderTy & getBuilder()
AggValueSlot::Overlap_t getOverlapForBaseInit(const CXXRecordDecl *rd, const CXXRecordDecl *baseRD, bool isVirtual)
Determine whether a base class initialization may overlap some other object.
void emitComplexExprIntoLValue(const Expr *e, LValue dest, bool isInit)
LValue makeAddrLValue(Address addr, QualType ty, AlignmentSource source=AlignmentSource::Type)
mlir::Value emitStoreThroughBitfieldLValue(RValue src, LValue dstresult)
std::optional< mlir::Location > currSrcLoc
Use to track source locations across nested visitor traversals.
clang::ASTContext & getContext() const
void emitStoreThroughLValue(RValue src, LValue dst, bool isInit=false)
Store the specified rvalue into the specified lvalue, where both are guaranteed to the have the same ...
Address createMemTemp(QualType t, mlir::Location loc, const Twine &name="tmp", Address *alloca=nullptr, mlir::OpBuilder::InsertPoint ip={})
Create a temporary memory object of the given type, with appropriate alignmen and cast it to the defa...
void emitAggExpr(const clang::Expr *e, AggValueSlot slot)
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
const clang::LangOptions & getLangOpts() const
mlir::Value emitNullConstant(QualType t, mlir::Location loc)
Return the result of value-initializing the given type, i.e.
llvm::DenseMap< const clang::FieldDecl *, llvm::StringRef > lambdaFieldToName
Keep a map between lambda fields and names, this needs to be per module since lambdas might get gener...
bool isZeroInitializable(clang::QualType ty)
Return whether a type can be zero-initialized (in the C++ sense) with an LLVM zeroinitializer.
Address getAddress() const
Address getAggregateAddress() const
Return the value of the address of the aggregate.
Definition CIRGenValue.h:69
bool isAggregate() const
Definition CIRGenValue.h:51
static RValue get(mlir::Value v)
Definition CIRGenValue.h:83
CXXTemporary * getTemporary()
Definition ExprCXX.h:1511
const Expr * getSubExpr() const
Definition ExprCXX.h:1515
Expr * getExpr()
Get the initialization expression that will be used.
Definition ExprCXX.cpp:1105
MutableArrayRef< Expr * > getInitExprs()
Definition ExprCXX.h:5181
FieldDecl * getInitializedFieldInUnion()
Definition ExprCXX.h:5219
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
SourceRange getSourceRange() const LLVM_READONLY
Definition ExprCXX.h:353
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range of the expression.
Definition ExprCXX.h:828
SourceRange getSourceRange() const LLVM_READONLY
Definition ExprCXX.h:902
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
Definition Expr.cpp:1602
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3676
CastKind getCastKind() const
Definition Expr.h:3720
static const char * getCastKindName(CastKind CK)
Definition Expr.cpp:1950
Expr * getSubExpr()
Definition Expr.h:3726
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
Definition CharUnits.h:214
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Definition Expr.h:4884
const Expr * getInitializer() const
Definition Expr.h:3633
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1270
bool hasAttr() const
Definition DeclBase.h:577
InitListExpr * getUpdater() const
Definition Expr.h:5936
This represents one expression.
Definition Expr.h:112
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3085
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
Definition Expr.cpp:3669
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition Expr.cpp:276
QualType getType() const
Definition Expr.h:144
Represents a member of a struct/union/class.
Definition Decl.h:3160
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition Decl.h:3245
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Definition Decl.h:3396
const Expr * getSubExpr() const
Definition Expr.h:1062
Expr * getResultExpr()
Return the result expression of this controlling expression.
Definition Expr.h:6462
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic,...
Definition Expr.cpp:2461
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition Expr.h:5425
bool hadArrayRangeDesignator() const
Definition Expr.h:5483
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition Expr.h:5401
const Expr * getInit(unsigned Init) const
Definition Expr.h:5353
ArrayRef< Expr * > inits()
Definition Expr.h:5349
llvm::iterator_range< capture_init_iterator > capture_inits()
Retrieve the initialization expressions for this lambda's captures.
Definition ExprCXX.h:2083
capture_range captures() const
Retrieve this lambda's captures.
Definition ExprCXX.cpp:1371
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition ExprCXX.cpp:1400
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
Definition ExprCXX.h:4937
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3364
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:301
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1178
const Expr * getSubExpr() const
Definition Expr.h:2199
A (possibly-)qualified type.
Definition TypeBase.h:937
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition TypeBase.h:8376
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
Definition TypeBase.h:1545
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
Definition Type.cpp:2695
@ PCK_Struct
The type is a struct containing a field whose type is neither PCK_Trivial nor PCK_VolatileTrivial.
Definition TypeBase.h:1517
Represents a struct/union/class.
Definition Decl.h:4324
field_range fields() const
Definition Decl.h:4527
CompoundStmt * getSubStmt()
Definition Expr.h:4612
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:338
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition Type.h:26
bool isConstantArrayType() const
Definition TypeBase.h:8632
bool isArrayType() const
Definition TypeBase.h:8628
bool isReferenceType() const
Definition TypeBase.h:8553
bool isVariableArrayType() const
Definition TypeBase.h:8640
RecordDecl * castAsRecordDecl() const
Definition Type.h:48
bool isAnyComplexType() const
Definition TypeBase.h:8664
bool isRecordType() const
Definition TypeBase.h:8656
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2244
Expr * getSubExpr() const
Definition Expr.h:2285
QualType getType() const
Definition Decl.h:723
Represents a variable declaration or definition.
Definition Decl.h:926
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
constexpr Variable var(Literal L)
Returns the variable of L.
Definition CNFFormula.h:64
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition Address.h:330
@ CPlusPlus
U cast(CodeGen::Address addr)
Definition Address.h:327
unsigned long uint64_t
static bool emitLifetimeMarkers()
static bool aggValueSlotDestructedFlag()
static bool aggValueSlotGC()
static bool aggValueSlotAlias()
static bool opLoadStoreAtomic()
static bool aggEmitFinalDestCopyRValue()
static bool aggValueSlotVolatile()
static bool opScopeCleanupRegion()
static bool atomicTypes()
static bool cudaSupport()
static bool requiresCleanups()
clang::CharUnits getPointerAlign() const