clang 24.0.0git
CIRGenStmt.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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// Emit Stmt nodes as CIR code.
10//
11//===----------------------------------------------------------------------===//
12
13#include "CIRGenBuilder.h"
14#include "CIRGenFunction.h"
15
16#include "mlir/IR/Builders.h"
17#include "mlir/IR/Location.h"
18#include "mlir/Support/LLVM.h"
19#include "clang/AST/ExprCXX.h"
20#include "clang/AST/Stmt.h"
23#include "clang/AST/StmtSYCL.h"
25#include "llvm/Support/SaveAndRestore.h"
26
27using namespace clang;
28using namespace clang::CIRGen;
29using namespace cir;
30
31static mlir::LogicalResult emitStmtWithResult(CIRGenFunction &cgf,
32 const Stmt *exprResult,
33 AggValueSlot slot,
34 Address *lastValue) {
35 // We have to special case labels here. They are statements, but when put
36 // at the end of a statement expression, they yield the value of their
37 // subexpression. Handle this by walking through all labels we encounter,
38 // emitting them before we evaluate the subexpr.
39 // Similar issues arise for attributed statements.
40 while (!isa<Expr>(exprResult)) {
41 if (const auto *ls = dyn_cast<LabelStmt>(exprResult)) {
42 if (cgf.emitLabel(*ls->getDecl()).failed())
43 return mlir::failure();
44 exprResult = ls->getSubStmt();
45 } else if (const auto *as = dyn_cast<AttributedStmt>(exprResult)) {
46 // FIXME: Update this if we ever have attributes that affect the
47 // semantics of an expression.
48 exprResult = as->getSubStmt();
49 } else {
50 llvm_unreachable("Unknown value statement");
51 }
52 }
53
54 const Expr *e = cast<Expr>(exprResult);
55 QualType exprTy = e->getType();
56 if (cgf.hasAggregateEvaluationKind(exprTy)) {
57 cgf.emitAggExpr(e, slot);
58 } else {
59 // We can't return an RValue here because there might be cleanups at
60 // the end of the StmtExpr. Because of that, we have to emit the result
61 // here into a temporary alloca.
62 cgf.emitAnyExprToMem(e, *lastValue, Qualifiers(),
63 /*IsInit*/ false);
64 }
65
66 return mlir::success();
67}
68
70 const CompoundStmt &s, Address *lastValue, AggValueSlot slot) {
71 mlir::LogicalResult result = mlir::success();
72 const Stmt *exprResult = s.body_back();
73 assert((!lastValue || (lastValue && exprResult)) &&
74 "If lastValue is not null then the CompoundStmt must have a "
75 "StmtExprResult");
76
77 for (const Stmt *curStmt : s.body()) {
78 const bool saveResult = lastValue && exprResult == curStmt;
79 if (saveResult) {
80 if (emitStmtWithResult(*this, exprResult, slot, lastValue).failed())
81 result = mlir::failure();
82 } else {
83 if (emitStmt(curStmt, /*useCurrentScope=*/false).failed())
84 result = mlir::failure();
85 }
86 }
87 return result;
88}
89
90mlir::LogicalResult
92
93 bool noinline = inNoInlineAttributedStmt;
94 bool alwaysinline = inAlwaysInlineAttributedStmt;
95 const CallExpr *musttail = mustTailCall;
96
97 for (const Attr *attr : s.getAttrs()) {
98 switch (attr->getKind()) {
99 default:
100 break;
101 case attr::NoMerge:
102 case attr::NoConvergent:
103 case attr::Atomic:
104 case attr::AMDGPUAvailableVisible:
105 case attr::HLSLControlFlowHint:
106 cgm.errorNYI(s.getSourceRange(),
107 "Unimplemented statement attribute: ", attr->getKind());
108 break;
109 case attr::NoInline:
110 noinline = true;
111 alwaysinline = false;
112 break;
113 case attr::AlwaysInline:
114 alwaysinline = true;
115 noinline = false;
116 break;
117 case attr::MustTail: {
118 const Stmt *sub = s.getSubStmt();
119 const ReturnStmt *ret = cast<ReturnStmt>(sub);
120 musttail = cast<CallExpr>(ret->getRetValue()->IgnoreParens());
121 break;
122 }
123 case attr::CXXAssume: {
124 const Expr *assumptionExpr = cast<CXXAssumeAttr>(attr)->getAssumption();
125 if (getLangOpts().CXXAssumptions && builder.getInsertionBlock() &&
126 !assumptionExpr->HasSideEffects(getContext())) {
127 mlir::Value assumptionValue = emitCheckedArgForAssume(assumptionExpr);
128 cir::AssumeOp::create(builder, getLoc(s.getSourceRange()),
129 assumptionValue, cir::AssumeBundleKind::None,
130 mlir::ValueRange{});
131 }
132 } break;
133 }
134 }
135
136 assert(!(alwaysinline && noinline) &&
137 "alwaysinline and noinline are mutually exclusive");
138
139 SaveAndRestore save_noinline(inNoInlineAttributedStmt, noinline);
140 SaveAndRestore save_alwaysinline(inAlwaysInlineAttributedStmt, alwaysinline);
141
142 SaveAndRestore save_musttail(mustTailCall, musttail);
143
144 return emitStmt(s.getSubStmt(), /*useCurrentScope=*/true, s.getAttrs());
145}
146
148 Address *lastValue,
149 AggValueSlot slot) {
150 // Add local scope to track new declared variables.
152 mlir::Location scopeLoc = getLoc(s.getSourceRange());
153 mlir::OpBuilder::InsertPoint scopeInsPt;
154 cir::ScopeOp::create(
155 builder, scopeLoc,
156 [&](mlir::OpBuilder &b, mlir::Type &type, mlir::Location loc) {
157 scopeInsPt = b.saveInsertionPoint();
158 });
159 mlir::OpBuilder::InsertionGuard guard(builder);
160 builder.restoreInsertionPoint(scopeInsPt);
161 LexicalScope lexScope(*this, scopeLoc, builder.getInsertionBlock());
162 return emitCompoundStmtWithoutScope(s, lastValue, slot);
163}
164
168
169// Build CIR for a statement. useCurrentScope should be true if no new scopes
170// need to be created when finding a compound statement.
171mlir::LogicalResult CIRGenFunction::emitStmt(const Stmt *s,
172 bool useCurrentScope,
174 if (mlir::succeeded(emitSimpleStmt(s, useCurrentScope)))
175 return mlir::success();
176
177 switch (s->getStmtClass()) {
179 case Stmt::CXXCatchStmtClass:
180 case Stmt::SEHExceptStmtClass:
181 case Stmt::SEHFinallyStmtClass:
182 case Stmt::MSDependentExistsStmtClass:
183 case Stmt::UnresolvedSYCLKernelCallStmtClass:
184 llvm_unreachable("invalid statement class to emit generically");
185 case Stmt::BreakStmtClass:
186 case Stmt::NullStmtClass:
187 case Stmt::CompoundStmtClass:
188 case Stmt::ContinueStmtClass:
189 case Stmt::DeclStmtClass:
190 case Stmt::ReturnStmtClass:
191 llvm_unreachable("should have emitted these statements as simple");
192
193#define STMT(Type, Base)
194#define ABSTRACT_STMT(Op)
195#define EXPR(Type, Base) case Stmt::Type##Class:
196#include "clang/AST/StmtNodes.inc"
197 {
198 assert(builder.getInsertionBlock() &&
199 "expression emission must have an insertion point");
200
202
203 // Classic codegen has a check here to see if the emitter created a new
204 // block that isn't used (comparing the incoming and outgoing insertion
205 // points) and deletes the outgoing block if it's not used. In CIR, we
206 // will handle that during the cir.canonicalize pass.
207 return mlir::success();
208 }
209 case Stmt::IfStmtClass:
210 return emitIfStmt(cast<IfStmt>(*s));
211 case Stmt::SwitchStmtClass:
213 case Stmt::ForStmtClass:
214 return emitForStmt(cast<ForStmt>(*s));
215 case Stmt::WhileStmtClass:
216 return emitWhileStmt(cast<WhileStmt>(*s));
217 case Stmt::DoStmtClass:
218 return emitDoStmt(cast<DoStmt>(*s));
219 case Stmt::CXXTryStmtClass:
221 case Stmt::CXXForRangeStmtClass:
223 case Stmt::CoroutineBodyStmtClass:
225 case Stmt::IndirectGotoStmtClass:
227 case Stmt::CoreturnStmtClass:
229 case Stmt::SYCLKernelCallStmtClass:
231 case Stmt::OpenACCComputeConstructClass:
233 case Stmt::OpenACCLoopConstructClass:
235 case Stmt::OpenACCCombinedConstructClass:
237 case Stmt::OpenACCDataConstructClass:
239 case Stmt::OpenACCEnterDataConstructClass:
241 case Stmt::OpenACCExitDataConstructClass:
243 case Stmt::OpenACCHostDataConstructClass:
245 case Stmt::OpenACCWaitConstructClass:
247 case Stmt::OpenACCInitConstructClass:
249 case Stmt::OpenACCShutdownConstructClass:
251 case Stmt::OpenACCSetConstructClass:
253 case Stmt::OpenACCUpdateConstructClass:
255 case Stmt::OpenACCCacheConstructClass:
257 case Stmt::OpenACCAtomicConstructClass:
259 case Stmt::GCCAsmStmtClass:
260 case Stmt::MSAsmStmtClass:
261 return emitAsmStmt(cast<AsmStmt>(*s));
262 case Stmt::OMPScopeDirectiveClass:
264 case Stmt::OMPErrorDirectiveClass:
266 case Stmt::OMPParallelDirectiveClass:
268 case Stmt::OMPTaskwaitDirectiveClass:
270 case Stmt::OMPTaskyieldDirectiveClass:
272 case Stmt::OMPBarrierDirectiveClass:
274 case Stmt::OMPMetaDirectiveClass:
276 case Stmt::OMPCanonicalLoopClass:
278 case Stmt::OMPSimdDirectiveClass:
280 case Stmt::OMPTileDirectiveClass:
282 case Stmt::OMPUnrollDirectiveClass:
284 case Stmt::OMPFuseDirectiveClass:
286 case Stmt::OMPForDirectiveClass:
288 case Stmt::OMPForSimdDirectiveClass:
290 case Stmt::OMPSectionsDirectiveClass:
292 case Stmt::OMPSectionDirectiveClass:
294 case Stmt::OMPSingleDirectiveClass:
296 case Stmt::OMPMasterDirectiveClass:
298 case Stmt::OMPCriticalDirectiveClass:
300 case Stmt::OMPParallelForDirectiveClass:
302 case Stmt::OMPParallelForSimdDirectiveClass:
305 case Stmt::OMPParallelMasterDirectiveClass:
307 case Stmt::OMPParallelSectionsDirectiveClass:
310 case Stmt::OMPTaskDirectiveClass:
312 case Stmt::OMPTaskgroupDirectiveClass:
314 case Stmt::OMPFlushDirectiveClass:
316 case Stmt::OMPDepobjDirectiveClass:
318 case Stmt::OMPScanDirectiveClass:
320 case Stmt::OMPOrderedStandaloneDirectiveClass:
323 case Stmt::OMPOrderedBlockAssocDirectiveClass:
326 case Stmt::OMPAtomicDirectiveClass:
328 case Stmt::OMPTargetDirectiveClass:
330 case Stmt::OMPTeamsDirectiveClass:
332 case Stmt::OMPCancellationPointDirectiveClass:
335 case Stmt::OMPCancelDirectiveClass:
337 case Stmt::OMPTargetDataDirectiveClass:
339 case Stmt::OMPTargetEnterDataDirectiveClass:
342 case Stmt::OMPTargetExitDataDirectiveClass:
344 case Stmt::OMPTargetParallelDirectiveClass:
346 case Stmt::OMPTargetParallelForDirectiveClass:
349 case Stmt::OMPTaskLoopDirectiveClass:
351 case Stmt::OMPTaskLoopSimdDirectiveClass:
353 case Stmt::OMPMaskedTaskLoopDirectiveClass:
355 case Stmt::OMPMaskedTaskLoopSimdDirectiveClass:
358 case Stmt::OMPMasterTaskLoopDirectiveClass:
360 case Stmt::OMPMasterTaskLoopSimdDirectiveClass:
363 case Stmt::OMPParallelGenericLoopDirectiveClass:
366 case Stmt::OMPParallelMaskedDirectiveClass:
368 case Stmt::OMPParallelMaskedTaskLoopDirectiveClass:
371 case Stmt::OMPParallelMaskedTaskLoopSimdDirectiveClass:
374 case Stmt::OMPParallelMasterTaskLoopDirectiveClass:
377 case Stmt::OMPParallelMasterTaskLoopSimdDirectiveClass:
380 case Stmt::OMPDistributeDirectiveClass:
382 case Stmt::OMPDistributeParallelForDirectiveClass:
385 case Stmt::OMPDistributeParallelForSimdDirectiveClass:
388 case Stmt::OMPDistributeSimdDirectiveClass:
390 case Stmt::OMPTargetParallelGenericLoopDirectiveClass:
393 case Stmt::OMPTargetParallelForSimdDirectiveClass:
396 case Stmt::OMPTargetSimdDirectiveClass:
398 case Stmt::OMPTargetTeamsGenericLoopDirectiveClass:
401 case Stmt::OMPTargetUpdateDirectiveClass:
403 case Stmt::OMPTeamsDistributeDirectiveClass:
406 case Stmt::OMPTeamsDistributeSimdDirectiveClass:
409 case Stmt::OMPTeamsDistributeParallelForSimdDirectiveClass:
412 case Stmt::OMPTeamsDistributeParallelForDirectiveClass:
415 case Stmt::OMPTeamsGenericLoopDirectiveClass:
418 case Stmt::OMPTargetTeamsDirectiveClass:
420 case Stmt::OMPTargetTeamsDistributeDirectiveClass:
423 case Stmt::OMPTargetTeamsDistributeParallelForDirectiveClass:
426 case Stmt::OMPTargetTeamsDistributeParallelForSimdDirectiveClass:
429 case Stmt::OMPTargetTeamsDistributeSimdDirectiveClass:
432 case Stmt::OMPInteropDirectiveClass:
434 case Stmt::OMPDispatchDirectiveClass:
436 case Stmt::OMPGenericLoopDirectiveClass:
438 case Stmt::OMPReverseDirectiveClass:
440 case Stmt::OMPSplitDirectiveClass:
442 case Stmt::OMPInterchangeDirectiveClass:
444 case Stmt::OMPFlattenDirectiveClass:
446 case Stmt::OMPAssumeDirectiveClass:
448 case Stmt::OMPMaskedDirectiveClass:
450 case Stmt::OMPStripeDirectiveClass:
452 case Stmt::LabelStmtClass:
453 case Stmt::AttributedStmtClass:
454 case Stmt::GotoStmtClass:
455 case Stmt::DefaultStmtClass:
456 case Stmt::CaseStmtClass:
457 case Stmt::SEHLeaveStmtClass:
458 case Stmt::ObjCAtTryStmtClass:
459 case Stmt::ObjCAtThrowStmtClass:
460 case Stmt::ObjCAtSynchronizedStmtClass:
461 case Stmt::ObjCForCollectionStmtClass:
462 case Stmt::ObjCAutoreleasePoolStmtClass:
463 case Stmt::SEHTryStmtClass:
464 case Stmt::ObjCAtCatchStmtClass:
465 case Stmt::ObjCAtFinallyStmtClass:
466 case Stmt::DeferStmtClass:
467 case Stmt::CXXExpansionStmtPatternClass:
468 case Stmt::CXXExpansionStmtInstantiationClass:
469 cgm.errorNYI(s->getSourceRange(),
470 std::string("emitStmt: ") + s->getStmtClassName());
471 return mlir::failure();
472 case Stmt::CapturedStmtClass:
473 llvm_unreachable("CapturedStmt must be handled by the parent directive");
474 }
475
476 llvm_unreachable("Unexpected statement class");
477}
478
479mlir::LogicalResult CIRGenFunction::emitSimpleStmt(const Stmt *s,
480 bool useCurrentScope) {
481 switch (s->getStmtClass()) {
482 default:
483 return mlir::failure();
484 case Stmt::DeclStmtClass:
485 return emitDeclStmt(cast<DeclStmt>(*s));
486 case Stmt::CompoundStmtClass:
487 if (useCurrentScope)
490 case Stmt::GotoStmtClass:
491 return emitGotoStmt(cast<GotoStmt>(*s));
492 case Stmt::ContinueStmtClass:
494
495 // NullStmt doesn't need any handling, but we need to say we handled it.
496 case Stmt::NullStmtClass:
497 break;
498
499 case Stmt::LabelStmtClass:
500 return emitLabelStmt(cast<LabelStmt>(*s));
501 case Stmt::CaseStmtClass:
502 case Stmt::DefaultStmtClass:
503 // If we reached here, we must not handling a switch case in the top level.
505 /*buildingTopLevelCase=*/false);
506 break;
507
508 case Stmt::BreakStmtClass:
509 return emitBreakStmt(cast<BreakStmt>(*s));
510 case Stmt::ReturnStmtClass:
512 case Stmt::AttributedStmtClass:
514 }
515
516 return mlir::success();
517}
518
519mlir::LogicalResult CIRGenFunction::emitLabelStmt(const clang::LabelStmt &s) {
520
521 if (emitLabel(*s.getDecl()).failed())
522 return mlir::failure();
523
524 if (getContext().getLangOpts().EHAsynch && s.isSideEntry())
525 getCIRGenModule().errorNYI(s.getSourceRange(), "IsEHa: not implemented.");
526
527 return emitStmt(s.getSubStmt(), /*useCurrentScope*/ true);
528}
529
530// Add a terminating yield on a body region if no other terminators are used.
532 mlir::Location loc) {
533 if (r.empty())
534 return;
535
537 unsigned numBlocks = r.getBlocks().size();
538 for (auto &block : r.getBlocks()) {
539 // Already cleanup after return operations, which might create
540 // empty blocks if emitted as last stmt.
541 if (numBlocks != 1 && block.empty() && block.hasNoPredecessors() &&
542 block.hasNoSuccessors())
543 eraseBlocks.push_back(&block);
544
545 if (block.empty() ||
546 !block.back().hasTrait<mlir::OpTrait::IsTerminator>()) {
547 mlir::OpBuilder::InsertionGuard guardCase(builder);
548 builder.setInsertionPointToEnd(&block);
549 builder.createYield(loc);
550 }
551 }
552
553 for (auto *b : eraseBlocks)
554 b->erase();
555}
556
557mlir::LogicalResult CIRGenFunction::emitIfStmt(const IfStmt &s) {
558 mlir::LogicalResult res = mlir::success();
559 // The else branch of a consteval if statement is always the only branch
560 // that can be runtime evaluated.
561 const Stmt *constevalExecuted;
562 if (s.isConsteval()) {
563 constevalExecuted = s.isNegatedConsteval() ? s.getThen() : s.getElse();
564 if (!constevalExecuted) {
565 // No runtime code execution required
566 return res;
567 }
568 }
569
570 // C99 6.8.4.1: The first substatement is executed if the expression
571 // compares unequal to 0. The condition must be a scalar type.
572 auto ifStmtBuilder = [&]() -> mlir::LogicalResult {
573 if (s.isConsteval())
574 return emitStmt(constevalExecuted, /*useCurrentScope=*/true);
575
576 if (s.getInit())
577 if (emitStmt(s.getInit(), /*useCurrentScope=*/true).failed())
578 return mlir::failure();
579
580 if (s.getConditionVariable())
582
583 // If the condition folds to a constant and this is an 'if constexpr',
584 // we simplify it early in CIRGen to avoid emitting the full 'if'.
585 bool condConstant;
586 if (constantFoldsToBool(s.getCond(), condConstant, s.isConstexpr())) {
587 if (s.isConstexpr()) {
588 // Handle "if constexpr" explicitly here to avoid generating some
589 // ill-formed code since in CIR the "if" is no longer simplified
590 // in this lambda like in Clang but postponed to other MLIR
591 // passes.
592 if (const Stmt *executed = condConstant ? s.getThen() : s.getElse())
593 return emitStmt(executed, /*useCurrentScope=*/true);
594 // There is nothing to execute at runtime.
595 // TODO(cir): there is still an empty cir.scope generated by the caller.
596 return mlir::success();
597 }
598 }
599
602 return emitIfOnBoolExpr(s.getCond(), s.getThen(), s.getElse());
603 };
604
605 // TODO: Add a new scoped symbol table.
606 // LexicalScope ConditionScope(*this, S.getCond()->getSourceRange());
607 // The if scope contains the full source range for IfStmt.
608 mlir::Location scopeLoc = getLoc(s.getSourceRange());
609 cir::ScopeOp::create(builder, scopeLoc, /*scopeBuilder=*/
610 [&](mlir::OpBuilder &b, mlir::Location loc) {
611 LexicalScope lexScope{*this, scopeLoc,
612 builder.getInsertionBlock()};
613 res = ifStmtBuilder();
614 });
615
616 return res;
617}
618
619mlir::LogicalResult CIRGenFunction::emitDeclStmt(const DeclStmt &s) {
620 assert(builder.getInsertionBlock() && "expected valid insertion point");
621
622 for (const Decl *i : s.decls())
623 emitDecl(*i, /*evaluateConditionDecl=*/true);
624
625 return mlir::success();
626}
627
628mlir::LogicalResult CIRGenFunction::emitReturnStmt(const ReturnStmt &s) {
629 mlir::Location loc = getLoc(s.getSourceRange());
630 const Expr *rv = s.getRetValue();
631
632 RunCleanupsScope cleanupScope(*this);
633 bool createNewScope = false;
634 if (const auto *ewc = dyn_cast_or_null<ExprWithCleanups>(rv)) {
635 rv = ewc->getSubExpr();
636 createNewScope = true;
637 }
638
639 auto handleReturnVal = [&]() {
640 if (getContext().getLangOpts().ElideConstructors && s.getNRVOCandidate() &&
643 // Apply the named return value optimization for this return statement,
644 // which means doing nothing: the appropriate result has already been
645 // constructed into the NRVO variable.
646
647 // If there is an NRVO flag for this variable, set it to 1 into indicate
648 // that the cleanup code should not destroy the variable.
649 if (auto nrvoFlag = nrvoFlags[s.getNRVOCandidate()])
650 builder.createFlagStore(loc, true, nrvoFlag);
651 } else if (!rv) {
652 // No return expression. Do nothing.
653 } else if (rv->getType()->isVoidType()) {
654 // Make sure not to return anything, but evaluate the expression
655 // for side effects.
656 if (rv) {
657 emitAnyExpr(rv);
658 }
659 } else if (cast<FunctionDecl>(curGD.getDecl())
660 ->getReturnType()
661 ->isReferenceType()) {
662 // If this function returns a reference, take the address of the
663 // expression rather than the value.
665 builder.CIRBaseBuilderTy::createStore(loc, result.getValue(),
666 *fnRetAlloca);
667 } else {
668 mlir::Value value = nullptr;
670 case cir::TEK_Scalar:
671 value = emitScalarExpr(rv);
672 if (value) { // Change this to an assert once emitScalarExpr is complete
673 builder.CIRBaseBuilderTy::createStore(loc, value, *fnRetAlloca);
674 }
675 break;
676 case cir::TEK_Complex:
679 /*isInit=*/true);
680 break;
687 break;
688 }
689 }
690 };
691
692 if (!createNewScope) {
693 handleReturnVal();
694 } else {
695 FullExprCleanupScope fullExprScope(*this, rv);
696 handleReturnVal();
697 }
698
699 cleanupScope.forceCleanup();
700
701 // Classic codegen emits a branch through any cleanups before continuing to
702 // a shared return block. Because CIR handles branching through cleanups
703 // during the CFG flattening phase, we can just emit the return statement
704 // directly.
705 // TODO(cir): Eliminate this redundant load and the store above when we can.
706 if (fnRetAlloca) {
707 // Load the value from `__retval` and return it via the `cir.return` op.
708 cir::AllocaOp retAlloca =
709 mlir::cast<cir::AllocaOp>(fnRetAlloca->getDefiningOp());
710 auto value = cir::LoadOp::create(builder, loc, retAlloca.getAllocaType(),
711 *fnRetAlloca);
712
713 cir::ReturnOp::create(builder, loc, {value});
714 } else {
715 cir::ReturnOp::create(builder, loc);
716 }
717
718 // Insert the new block to continue codegen after the return statement.
719 // This will get deleted if we don't populate it. This handles the case of
720 // unreachable statements below a return.
721 builder.createBlock(builder.getBlock()->getParent());
722 return mlir::success();
723}
724
725mlir::LogicalResult CIRGenFunction::emitGotoStmt(const clang::GotoStmt &s) {
726 // FIXME: LLVM codegen inserts emit a stop point here for debug info
727 // sake when the insertion point is available, but doesn't do
728 // anything special when there isn't. We haven't implemented debug
729 // info support just yet, look at this again once we have it.
731
732 cir::GotoOp::create(builder, getLoc(s.getSourceRange()),
733 s.getLabel()->getName());
734
735 // A goto marks the end of a block, create a new one for codegen after
736 // emitGotoStmt can resume building in that block.
737 // Insert the new block to continue codegen after goto.
738 builder.createBlock(builder.getBlock()->getParent());
739
740 return mlir::success();
741}
742
743mlir::LogicalResult
745 // An indirect goto with an active cleanup may leave its scope. Determining
746 // whether its dynamic destination requires cleanup is not implemented.
747 if (ehStack.stable_begin() != prologueCleanupDepth) {
748 cgm.errorNYI(s.getSourceRange(), "indirect goto with active cleanup");
749 return mlir::success();
750 }
751
752 mlir::Value val = emitScalarExpr(s.getTarget());
753 // Emit a symbolic indirect goto. GotoSolver resolves it into the shared
754 // indirect-branch block after FlattenCFG merges regions, so this stays valid
755 // even when the goto sits inside a nested scope.
756 cir::IndirectGotoOp::create(builder, getLoc(s.getSourceRange()), val);
757
758 // The indirect goto ends the block; open a fresh one so codegen can resume.
759 builder.createBlock(builder.getBlock()->getParent());
760 return mlir::success();
761}
762
763mlir::LogicalResult
765 builder.createContinue(getLoc(s.getKwLoc()));
766
767 // Insert the new block to continue codegen after the continue statement.
768 builder.createBlock(builder.getBlock()->getParent());
769
770 return mlir::success();
771}
772
773mlir::LogicalResult CIRGenFunction::emitLabel(const clang::LabelDecl &d) {
774 // Create a new block to tag with a label and add a branch from
775 // the current one to it. If the block is empty just call attach it
776 // to this label.
777 mlir::Block *currBlock = builder.getBlock();
778 mlir::Block *labelBlock = currBlock;
779
780 if (!currBlock->empty() || currBlock->isEntryBlock()) {
781 {
782 mlir::OpBuilder::InsertionGuard guard(builder);
783 labelBlock = builder.createBlock(builder.getBlock()->getParent());
784 }
785 cir::BrOp::create(builder, getLoc(d.getSourceRange()), labelBlock);
786 }
787
788 builder.setInsertionPointToEnd(labelBlock);
789 cir::LabelOp::create(builder, getLoc(d.getSourceRange()), d.getName());
790 // FIXME: emit debug info for labels, incrementProfileCounter
793 return mlir::success();
794}
795
796mlir::LogicalResult CIRGenFunction::emitBreakStmt(const clang::BreakStmt &s) {
797 builder.createBreak(getLoc(s.getKwLoc()));
798
799 // Insert the new block to continue codegen after the break statement.
800 builder.createBlock(builder.getBlock()->getParent());
801
802 return mlir::success();
803}
804
805template <typename T>
806mlir::LogicalResult
808 mlir::ArrayAttr value, CaseOpKind kind,
809 bool buildingTopLevelCase) {
810
812 "only case or default stmt go here");
813
814 mlir::LogicalResult result = mlir::success();
815
816 mlir::Location loc = getLoc(stmt->getBeginLoc());
817
818 enum class SubStmtKind { Case, Default, Other };
819 SubStmtKind subStmtKind = SubStmtKind::Other;
820 const Stmt *sub = stmt->getSubStmt();
821
822 mlir::OpBuilder::InsertPoint insertPoint;
823 CaseOp::create(builder, loc, value, kind, insertPoint);
824
825 {
826 mlir::OpBuilder::InsertionGuard guardSwitch(builder);
827 builder.restoreInsertionPoint(insertPoint);
828
829 if (isa<DefaultStmt>(sub) && isa<CaseStmt>(stmt)) {
830 subStmtKind = SubStmtKind::Default;
831 builder.createYield(loc);
832 } else if (isa<CaseStmt>(sub) && isa<DefaultStmt, CaseStmt>(stmt)) {
833 subStmtKind = SubStmtKind::Case;
834 builder.createYield(loc);
835 } else {
836 result = emitStmt(sub, /*useCurrentScope=*/!isa<CompoundStmt>(sub));
837 }
838
839 insertPoint = builder.saveInsertionPoint();
840 }
841
842 // If the substmt is default stmt or case stmt, try to handle the special case
843 // to make it into the simple form. e.g.
844 //
845 // switch () {
846 // case 1:
847 // default:
848 // ...
849 // }
850 //
851 // we prefer generating
852 //
853 // cir.switch() {
854 // cir.case(equal, 1) {
855 // cir.yield
856 // }
857 // cir.case(default) {
858 // ...
859 // }
860 // }
861 //
862 // than
863 //
864 // cir.switch() {
865 // cir.case(equal, 1) {
866 // cir.case(default) {
867 // ...
868 // }
869 // }
870 // }
871 //
872 // We don't need to revert this if we find the current switch can't be in
873 // simple form later since the conversion itself should be harmless.
874 if (subStmtKind == SubStmtKind::Case) {
875 result = emitCaseStmt(*cast<CaseStmt>(sub), condType, buildingTopLevelCase);
876 } else if (subStmtKind == SubStmtKind::Default) {
877 result = emitDefaultStmt(*cast<DefaultStmt>(sub), condType,
878 buildingTopLevelCase);
879 } else if (buildingTopLevelCase) {
880 // If we're building a top level case, try to restore the insert point to
881 // the case we're building, then we can attach more random stmts to the
882 // case to make generating `cir.switch` operation to be a simple form.
883 builder.restoreInsertionPoint(insertPoint);
884 }
885
886 return result;
887}
888
889mlir::LogicalResult CIRGenFunction::emitCaseStmt(const CaseStmt &s,
890 mlir::Type condType,
891 bool buildingTopLevelCase) {
892 cir::CaseOpKind kind;
893 mlir::ArrayAttr value;
894 llvm::APSInt intVal = s.getLHS()->EvaluateKnownConstInt(getContext());
895
896 // Coerce a bool to an i1 for a switch, so we can just treat all its elements
897 // as an int later on.
898 if (isa<cir::BoolType>(condType))
899 condType = builder.getUIntNTy(1);
900
901 // If the case statement has an RHS value, it is representing a GNU
902 // case range statement, where LHS is the beginning of the range
903 // and RHS is the end of the range.
904 if (const Expr *rhs = s.getRHS()) {
905 llvm::APSInt endVal = rhs->EvaluateKnownConstInt(getContext());
906 value = builder.getArrayAttr({cir::IntAttr::get(condType, intVal),
907 cir::IntAttr::get(condType, endVal)});
908 kind = cir::CaseOpKind::Range;
909 } else {
910 value = builder.getArrayAttr({cir::IntAttr::get(condType, intVal)});
911 kind = cir::CaseOpKind::Equal;
912 }
913
914 return emitCaseDefaultCascade(&s, condType, value, kind,
915 buildingTopLevelCase);
916}
917
919 mlir::Type condType,
920 bool buildingTopLevelCase) {
921 return emitCaseDefaultCascade(&s, condType, builder.getArrayAttr({}),
922 cir::CaseOpKind::Default, buildingTopLevelCase);
923}
924
925mlir::LogicalResult CIRGenFunction::emitSwitchCase(const SwitchCase &s,
926 bool buildingTopLevelCase) {
927 assert(!condTypeStack.empty() &&
928 "build switch case without specifying the type of the condition");
929
930 if (s.getStmtClass() == Stmt::CaseStmtClass)
931 return emitCaseStmt(cast<CaseStmt>(s), condTypeStack.back(),
932 buildingTopLevelCase);
933
934 if (s.getStmtClass() == Stmt::DefaultStmtClass)
936 buildingTopLevelCase);
937
938 llvm_unreachable("expect case or default stmt");
939}
940
941mlir::LogicalResult
943 ArrayRef<const Attr *> forAttrs) {
944 cir::ForOp forOp;
945
946 // TODO(cir): pass in array of attributes.
947 auto forStmtBuilder = [&]() -> mlir::LogicalResult {
948 mlir::LogicalResult loopRes = mlir::success();
949 // Evaluate the first pieces before the loop.
950 if (s.getInit())
951 if (emitStmt(s.getInit(), /*useCurrentScope=*/true).failed())
952 return mlir::failure();
953 if (emitStmt(s.getRangeStmt(), /*useCurrentScope=*/true).failed())
954 return mlir::failure();
955 if (emitStmt(s.getBeginStmt(), /*useCurrentScope=*/true).failed())
956 return mlir::failure();
957 if (emitStmt(s.getEndStmt(), /*useCurrentScope=*/true).failed())
958 return mlir::failure();
959
961
962 forOp = builder.createFor(
964 /*condBuilder=*/
965 [&](mlir::OpBuilder &b, mlir::Location loc) {
966 assert(!cir::MissingFeatures::createProfileWeightsForLoop());
967 assert(!cir::MissingFeatures::emitCondLikelihoodViaExpectIntrinsic());
968 mlir::Value condVal = evaluateExprAsBool(s.getCond());
969 builder.createCondition(condVal);
970 },
971 /*bodyBuilder=*/
972 [&](mlir::OpBuilder &b, mlir::Location loc) {
973 // https://en.cppreference.com/w/cpp/language/for
974 // In C++ the scope of the init-statement and the scope of
975 // statement are one and the same.
976 RunCleanupsScope bodyScope(*this);
977 bool useCurrentScope = true;
978 if (emitStmt(s.getLoopVarStmt(), useCurrentScope).failed())
979 loopRes = mlir::failure();
980 if (emitStmt(s.getBody(), useCurrentScope).failed())
981 loopRes = mlir::failure();
982 emitStopPoint(&s);
983 },
984 /*stepBuilder=*/
985 [&](mlir::OpBuilder &b, mlir::Location loc) {
986 if (s.getInc())
987 if (emitStmt(s.getInc(), /*useCurrentScope=*/true).failed())
988 loopRes = mlir::failure();
989 builder.createYield(loc);
990 });
991 return loopRes;
992 };
993
994 mlir::LogicalResult res = mlir::success();
995 mlir::Location scopeLoc = getLoc(s.getSourceRange());
996 cir::ScopeOp::create(builder, scopeLoc, /*scopeBuilder=*/
997 [&](mlir::OpBuilder &b, mlir::Location loc) {
998 // Create a cleanup scope for the condition
999 // variable cleanups. Logical equivalent from
1000 // LLVM codegn for LexicalScope
1001 // ConditionScope(*this, S.getSourceRange())...
1002 LexicalScope lexScope{*this, loc,
1003 builder.getInsertionBlock()};
1004 res = forStmtBuilder();
1005 });
1006
1007 if (res.failed())
1008 return res;
1009
1010 terminateStructuredRegionBody(forOp.getBody(), getLoc(s.getEndLoc()));
1011 return mlir::success();
1012}
1013
1014mlir::LogicalResult CIRGenFunction::emitForStmt(const ForStmt &s) {
1015 cir::ForOp forOp;
1016
1017 // TODO: pass in an array of attributes.
1018 auto forStmtBuilder = [&]() -> mlir::LogicalResult {
1019 mlir::LogicalResult loopRes = mlir::success();
1020 // Evaluate the first part before the loop.
1021 if (s.getInit())
1022 if (emitStmt(s.getInit(), /*useCurrentScope=*/true).failed())
1023 return mlir::failure();
1025
1026 // A condition variable's lifetime is a single iteration, so capture its
1027 // destructor and lifetime-end cleanups and emit them into the loop's
1028 // per-iteration cleanup region. This scope is constructed after the
1029 // init-statement so the init-statement's cleanups are not captured.
1030 const VarDecl *condVar = s.getConditionVariable();
1031 bool needsCondCleanup =
1032 condVar &&
1034 shouldEmitLifetimeMarkersForAutoVar());
1035 DeferredLoopConditionCleanup loopCondScope(*this, needsCondCleanup);
1036
1037 auto condBuilder = [&](mlir::OpBuilder &b, mlir::Location loc) {
1040 mlir::Value condVal;
1041 if (s.getCond()) {
1042 // If the for statement declares a condition variable, emit that here.
1043 if (condVar)
1044 emitLoopConditionVariable(*condVar, loopCondScope);
1045 // C99 6.8.5p2/p4: The first substatement is executed if the
1046 // expression compares unequal to 0. The condition must be a
1047 // scalar type.
1048 condVal = evaluateExprAsBool(s.getCond());
1049 } else {
1050 condVal = cir::ConstantOp::create(b, loc, builder.getTrueAttr());
1051 }
1052 builder.createCondition(condVal);
1053 };
1054 auto bodyBuilder = [&](mlir::OpBuilder &b, mlir::Location loc) {
1055 // The scope of the for loop body is nested within the scope of the
1056 // for loop's init-statement and condition.
1057 RunCleanupsScope bodyScope(*this);
1058 if (emitStmt(s.getBody(), /*useCurrentScope=*/false).failed())
1059 loopRes = mlir::failure();
1060 emitStopPoint(&s);
1061 };
1062 auto stepBuilder = [&](mlir::OpBuilder &b, mlir::Location loc) {
1063 if (s.getInc())
1064 if (emitStmt(s.getInc(), /*useCurrentScope=*/true).failed())
1065 loopRes = mlir::failure();
1066 builder.createYield(loc);
1067 };
1068
1069 if (needsCondCleanup) {
1070 cir::CleanupKind cleanupKind = getLangOpts().Exceptions
1071 ? cir::CleanupKind::All
1072 : cir::CleanupKind::Normal;
1073 forOp = builder.createFor(
1074 getLoc(s.getSourceRange()), condBuilder, bodyBuilder, stepBuilder,
1075 /*cleanupBuilder=*/
1076 [&](mlir::OpBuilder &b, mlir::Location loc) {
1077 loopCondScope.emitIntoLoopCleanupRegion(loc);
1078 builder.createYield(loc);
1079 },
1080 cleanupKind);
1081 } else {
1082 forOp = builder.createFor(getLoc(s.getSourceRange()), condBuilder,
1083 bodyBuilder, stepBuilder);
1084 }
1085 return loopRes;
1086 };
1087
1088 auto res = mlir::success();
1089 auto scopeLoc = getLoc(s.getSourceRange());
1090 cir::ScopeOp::create(builder, scopeLoc, /*scopeBuilder=*/
1091 [&](mlir::OpBuilder &b, mlir::Location loc) {
1092 LexicalScope lexScope{*this, loc,
1093 builder.getInsertionBlock()};
1094 res = forStmtBuilder();
1095 });
1096
1097 if (res.failed())
1098 return res;
1099
1100 terminateStructuredRegionBody(forOp.getBody(), getLoc(s.getEndLoc()));
1101 return mlir::success();
1102}
1103
1104mlir::LogicalResult CIRGenFunction::emitDoStmt(const DoStmt &s) {
1105 cir::DoWhileOp doWhileOp;
1106
1107 // TODO: pass in array of attributes.
1108 auto doStmtBuilder = [&]() -> mlir::LogicalResult {
1109 mlir::LogicalResult loopRes = mlir::success();
1111
1112 doWhileOp = builder.createDoWhile(
1114 /*condBuilder=*/
1115 [&](mlir::OpBuilder &b, mlir::Location loc) {
1116 assert(!cir::MissingFeatures::createProfileWeightsForLoop());
1117 assert(!cir::MissingFeatures::emitCondLikelihoodViaExpectIntrinsic());
1118 // C99 6.8.5p2/p4: The first substatement is executed if the
1119 // expression compares unequal to 0. The condition must be a
1120 // scalar type.
1121 mlir::Value condVal = evaluateExprAsBool(s.getCond());
1122 builder.createCondition(condVal);
1123 },
1124 /*bodyBuilder=*/
1125 [&](mlir::OpBuilder &b, mlir::Location loc) {
1126 // The scope of the do-while loop body is a nested scope.
1127 RunCleanupsScope bodyScope(*this);
1128 if (emitStmt(s.getBody(), /*useCurrentScope=*/false).failed())
1129 loopRes = mlir::failure();
1130 emitStopPoint(&s);
1131 });
1132 return loopRes;
1133 };
1134
1135 mlir::LogicalResult res = mlir::success();
1136 mlir::Location scopeLoc = getLoc(s.getSourceRange());
1137 cir::ScopeOp::create(builder, scopeLoc, /*scopeBuilder=*/
1138 [&](mlir::OpBuilder &b, mlir::Location loc) {
1139 LexicalScope lexScope{*this, loc,
1140 builder.getInsertionBlock()};
1141 res = doStmtBuilder();
1142 });
1143
1144 if (res.failed())
1145 return res;
1146
1147 terminateStructuredRegionBody(doWhileOp.getBody(), getLoc(s.getEndLoc()));
1148 return mlir::success();
1149}
1150
1151mlir::LogicalResult CIRGenFunction::emitWhileStmt(const WhileStmt &s) {
1152 cir::WhileOp whileOp;
1153
1154 // TODO: pass in array of attributes.
1155 auto whileStmtBuilder = [&]() -> mlir::LogicalResult {
1156 mlir::LogicalResult loopRes = mlir::success();
1158
1159 // A condition variable's lifetime is a single iteration, so capture its
1160 // destructor and lifetime-end cleanups and emit them into the loop's
1161 // per-iteration cleanup region.
1162 const VarDecl *condVar = s.getConditionVariable();
1163 bool needsCondCleanup =
1164 condVar &&
1166 shouldEmitLifetimeMarkersForAutoVar());
1167 DeferredLoopConditionCleanup loopCondScope(*this, needsCondCleanup);
1168
1169 auto condBuilder = [&](mlir::OpBuilder &b, mlir::Location loc) {
1172 // If the while statement declares a condition variable, emit that here.
1173 if (condVar)
1174 emitLoopConditionVariable(*condVar, loopCondScope);
1175 // C99 6.8.5p2/p4: The first substatement is executed if the
1176 // expression compares unequal to 0. The condition must be a
1177 // scalar type.
1178 mlir::Value condVal = evaluateExprAsBool(s.getCond());
1179 builder.createCondition(condVal);
1180 };
1181 auto bodyBuilder = [&](mlir::OpBuilder &b, mlir::Location loc) {
1182 // The scope of the while loop body is a nested scope.
1183 RunCleanupsScope bodyScope(*this);
1184 if (emitStmt(s.getBody(), /*useCurrentScope=*/false).failed())
1185 loopRes = mlir::failure();
1186 emitStopPoint(&s);
1187 };
1188
1189 if (needsCondCleanup) {
1190 cir::CleanupKind cleanupKind = getLangOpts().Exceptions
1191 ? cir::CleanupKind::All
1192 : cir::CleanupKind::Normal;
1193 whileOp = builder.createWhile(
1194 getLoc(s.getSourceRange()), condBuilder, bodyBuilder,
1195 /*cleanupBuilder=*/
1196 [&](mlir::OpBuilder &b, mlir::Location loc) {
1197 loopCondScope.emitIntoLoopCleanupRegion(loc);
1198 builder.createYield(loc);
1199 },
1200 cleanupKind);
1201 } else {
1202 whileOp = builder.createWhile(getLoc(s.getSourceRange()), condBuilder,
1203 bodyBuilder);
1204 }
1205 return loopRes;
1206 };
1207
1208 mlir::LogicalResult res = mlir::success();
1209 mlir::Location scopeLoc = getLoc(s.getSourceRange());
1210 cir::ScopeOp::create(builder, scopeLoc, /*scopeBuilder=*/
1211 [&](mlir::OpBuilder &b, mlir::Location loc) {
1212 LexicalScope lexScope{*this, loc,
1213 builder.getInsertionBlock()};
1214 res = whileStmtBuilder();
1215 });
1216
1217 if (res.failed())
1218 return res;
1219
1220 terminateStructuredRegionBody(whileOp.getBody(), getLoc(s.getEndLoc()));
1221 return mlir::success();
1222}
1223
1224mlir::LogicalResult CIRGenFunction::emitSwitchBody(const Stmt *s) {
1225 // It is rare but legal if the switch body is not a compound stmt. e.g.,
1226 //
1227 // switch(a)
1228 // while(...) {
1229 // case1
1230 // ...
1231 // case2
1232 // ...
1233 // }
1234 if (!isa<CompoundStmt>(s))
1235 return emitStmt(s, /*useCurrentScope=*/true);
1236
1238
1239 ArrayRef<Stmt *> body{compoundStmt->body_begin(), compoundStmt->body_end()};
1240
1241 mlir::Block *switchBlock = builder.getBlock();
1242
1243 // Any statements appearing before the first case statement are 'unassociated'
1244 // with anything. So we have to create them FIRST in their own block. After
1245 // that, the 'case' regions will take care of future ones.
1246 if (!body.empty() && !isa<SwitchCase>(body.front())) {
1247 builder.setInsertionPointToEnd(switchBlock);
1248 {
1249 // This is needed to handle cleanups in a compound statement before the
1250 // first case statement.
1251 RunCleanupsScope preCaseScope(*this);
1252 while (!body.empty() && !isa<SwitchCase>(body.front())) {
1253
1254 auto *c = body.front();
1255 if (mlir::failed(
1256 emitStmt(c, /*useCurrentScope=*/!isa<CompoundStmt>(c))))
1257 return mlir::failure();
1258
1259 body = body.drop_front();
1260 }
1261 }
1262
1263 // Now that we've emitted ALL of the statements, we can create a new block
1264 // for the actual case statements/etc to appear.
1265 mlir::Block *lastBlock = builder.getBlock();
1266 switchBlock = builder.createBlock(switchBlock->getParent());
1267 builder.setInsertionPointToEnd(lastBlock);
1268 cir::BrOp::create(builder, getLoc(s->getSourceRange()), switchBlock);
1269 }
1270
1271 for (auto *c : body) {
1272 if (auto *switchCase = dyn_cast<SwitchCase>(c)) {
1273 builder.setInsertionPointToEnd(switchBlock);
1274 // Reset insert point automatically, so that we can attach following
1275 // random stmt to the region of previous built case op to try to make
1276 // the being generated `cir.switch` to be in simple form.
1277 if (mlir::failed(
1278 emitSwitchCase(*switchCase, /*buildingTopLevelCase=*/true)))
1279 return mlir::failure();
1280
1281 continue;
1282 }
1283
1284 // Otherwise, just build the statements in the nearest case region.
1285 if (mlir::failed(emitStmt(c, /*useCurrentScope=*/!isa<CompoundStmt>(c))))
1286 return mlir::failure();
1287 }
1288
1289 return mlir::success();
1290}
1291
1293 // TODO: LLVM codegen does some early optimization to fold the condition and
1294 // only emit live cases. CIR should use MLIR to achieve similar things,
1295 // nothing to be done here.
1296 // if (ConstantFoldsToSimpleInteger(S.getCond(), ConstantCondValue))...
1298
1299 SwitchOp swop;
1300 auto switchStmtBuilder = [&]() -> mlir::LogicalResult {
1301 if (s.getInit())
1302 if (emitStmt(s.getInit(), /*useCurrentScope=*/true).failed())
1303 return mlir::failure();
1304
1305 if (s.getConditionVariable())
1306 emitDecl(*s.getConditionVariable(), /*evaluateConditionDecl=*/true);
1307
1308 mlir::Value condV = emitScalarExpr(s.getCond());
1309
1310 // Coerce bool values to an i1. There is no real sensible reason we need to
1311 // represent a 'switch' of scoped-enum-with-bool-backing-type specially
1312 // here. It is a rarely used thing, and would result in a lot of work to
1313 // properly handle this everywhere.
1314 if (isa<cir::BoolType>(condV.getType()))
1315 condV = builder.createBoolToInt(condV, builder.getUIntNTy(1));
1316
1317 // TODO: PGO and likelihood (e.g. PGO.haveRegionCounts())
1320 // TODO: if the switch has a condition wrapped by __builtin_unpredictable?
1322
1323 mlir::LogicalResult res = mlir::success();
1324 swop = SwitchOp::create(
1325 builder, getLoc(s.getBeginLoc()), condV,
1326 /*switchBuilder=*/
1327 [&](mlir::OpBuilder &b, mlir::Location loc, mlir::OperationState &os) {
1328 curLexScope->setAsSwitch();
1329
1330 condTypeStack.push_back(condV.getType());
1331
1332 res = emitSwitchBody(s.getBody());
1333
1334 condTypeStack.pop_back();
1335 });
1336
1337 return res;
1338 };
1339
1340 // The switch scope contains the full source range for SwitchStmt.
1341 mlir::Location scopeLoc = getLoc(s.getSourceRange());
1342 mlir::LogicalResult res = mlir::success();
1343 cir::ScopeOp::create(builder, scopeLoc, /*scopeBuilder=*/
1344 [&](mlir::OpBuilder &b, mlir::Location loc) {
1345 LexicalScope lexScope{*this, loc,
1346 builder.getInsertionBlock()};
1347 res = switchStmtBuilder();
1348 });
1349
1351 swop.collectCases(cases);
1352 for (auto caseOp : cases)
1353 terminateStructuredRegionBody(caseOp.getCaseRegion(), caseOp.getLoc());
1354 terminateStructuredRegionBody(swop.getBody(), swop.getLoc());
1355
1356 swop.setAllEnumCasesCovered(s.isAllEnumCasesCovered());
1357
1358 return res;
1359}
1360
1361void CIRGenFunction::emitReturnOfRValue(mlir::Location loc, RValue rv,
1362 QualType ty) {
1363 if (rv.isScalar()) {
1364 builder.createStore(loc, rv.getValue(), returnValue);
1365 } else if (rv.isAggregate()) {
1366 Address rvAddr = rv.getAggregateAddress();
1367 // If the aggregate is already in the return slot (e.g. a callee was
1368 // invoked through a ReturnValueSlot bound to returnValue), the copy is
1369 // a no-op. Calling emitAggregateCopy here would also incorrectly
1370 // require the type to have a trivial copy/move.
1371 if (rvAddr.getPointer() != returnValue.getPointer()) {
1372 LValue dest = makeAddrLValue(returnValue, ty);
1373 LValue src = makeAddrLValue(rvAddr, ty);
1375 }
1376 } else {
1377 assert(rv.isComplex() && "Unknown rvalue kind?");
1378 builder.createStore(loc, rv.getComplexValue(), returnValue);
1379 }
1380
1381 // Classic codegen emits a branch through any cleanups before continuing to
1382 // a shared return block. Because CIR handles branching through cleanups
1383 // during the CFG flattening phase, we can just emit the return statement
1384 // directly.
1385 // TODO(cir): Eliminate this redundant load and the store above when we can.
1386 // Load the value from `__retval` and return it via the `cir.return` op.
1387 cir::AllocaOp retAlloca =
1388 mlir::cast<cir::AllocaOp>(fnRetAlloca->getDefiningOp());
1389 auto value = cir::LoadOp::create(builder, loc, retAlloca.getAllocaType(),
1390 *fnRetAlloca);
1391
1392 cir::ReturnOp::create(builder, loc, {value});
1393}
static mlir::LogicalResult emitStmtWithResult(CIRGenFunction &cgf, const Stmt *exprResult, AggValueSlot slot, Address *lastValue)
Defines the clang::Expr interface and subclasses for C++ expressions.
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
This file defines OpenACC AST classes for statement-level contructs.
This file defines OpenMP AST classes for executable directives and clauses.
This file defines SYCL AST classes used to represent calls to SYCL kernels.
Attr - This represents one attribute.
Definition Attr.h:46
Represents an attribute applied to a statement.
Definition Stmt.h:2215
Stmt * getSubStmt()
Definition Stmt.h:2251
ArrayRef< const Attr * > getAttrs() const
Definition Stmt.h:2247
BreakStmt - This represents a break.
Definition Stmt.h:3147
mlir::Value getPointer() const
Definition Address.h:98
An aggregate value slot.
static AggValueSlot forAddr(Address addr, clang::Qualifiers quals, IsDestructed_t isDestructed, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed)
Captures cleanups for a loop's condition variable so that they can be emitted into the loop op's per-...
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited.
void forceCleanup(ArrayRef< mlir::Value * > valuesToReload={})
Force the emission of cleanups now, instead of waiting until this object is destroyed.
mlir::LogicalResult emitOMPTargetParallelForDirective(const OMPTargetParallelForDirective &s)
mlir::LogicalResult emitOMPParallelMasterTaskLoopSimdDirective(const OMPParallelMasterTaskLoopSimdDirective &s)
mlir::LogicalResult emitOMPSimdDirective(const OMPSimdDirective &s)
mlir::Value emitCheckedArgForAssume(const Expr *e)
Emits an argument for a call to a __builtin_assume.
mlir::LogicalResult emitDoStmt(const clang::DoStmt &s)
mlir::LogicalResult emitOMPCriticalDirective(const OMPCriticalDirective &s)
static cir::TypeEvaluationKind getEvaluationKind(clang::QualType type)
Return the cir::TypeEvaluationKind of QualType type.
clang::GlobalDecl curGD
The GlobalDecl for the current function being compiled or the global variable currently being initial...
mlir::LogicalResult emitCoreturnStmt(const CoreturnStmt &s)
mlir::LogicalResult emitOpenACCDataConstruct(const OpenACCDataConstruct &s)
EHScopeStack::stable_iterator prologueCleanupDepth
The cleanup depth enclosing all the cleanups associated with the parameters.
mlir::LogicalResult emitOpenACCCombinedConstruct(const OpenACCCombinedConstruct &s)
mlir::LogicalResult emitOMPParallelMasterDirective(const OMPParallelMasterDirective &s)
mlir::LogicalResult emitOpenACCWaitConstruct(const OpenACCWaitConstruct &s)
mlir::LogicalResult emitOMPCancellationPointDirective(const OMPCancellationPointDirective &s)
mlir::LogicalResult emitOMPParallelMaskedTaskLoopDirective(const OMPParallelMaskedTaskLoopDirective &s)
mlir::LogicalResult emitOMPReverseDirective(const OMPReverseDirective &s)
const clang::LangOptions & getLangOpts() const
mlir::LogicalResult emitOpenACCUpdateConstruct(const OpenACCUpdateConstruct &s)
mlir::LogicalResult emitOMPTileDirective(const OMPTileDirective &s)
mlir::LogicalResult emitIfOnBoolExpr(const clang::Expr *cond, const clang::Stmt *thenS, const clang::Stmt *elseS)
Emit an if on a boolean condition to the specified blocks.
mlir::LogicalResult emitOMPTargetTeamsDirective(const OMPTargetTeamsDirective &s)
mlir::LogicalResult emitOMPTeamsDistributeParallelForDirective(const OMPTeamsDistributeParallelForDirective &s)
mlir::LogicalResult emitOMPBarrierDirective(const OMPBarrierDirective &s)
mlir::LogicalResult emitOMPTargetParallelDirective(const OMPTargetParallelDirective &s)
mlir::LogicalResult emitOpenACCCacheConstruct(const OpenACCCacheConstruct &s)
mlir::LogicalResult emitOMPTargetDirective(const OMPTargetDirective &s)
mlir::LogicalResult emitCXXForRangeStmt(const CXXForRangeStmt &s, llvm::ArrayRef< const Attr * > attrs)
mlir::Value evaluateExprAsBool(const clang::Expr *e)
Perform the usual unary conversions on the specified expression and compare the result against zero,...
void emitAggregateCopy(LValue dest, LValue src, QualType eltTy, AggValueSlot::Overlap_t mayOverlap, bool isVolatile=false)
Emit an aggregate copy.
mlir::LogicalResult emitOMPScopeDirective(const OMPScopeDirective &s)
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
mlir::LogicalResult emitOMPDepobjDirective(const OMPDepobjDirective &s)
bool constantFoldsToBool(const clang::Expr *cond, bool &resultBool, bool allowLabels=false)
If the specified expression does not fold to a constant, or if it does but contains a label,...
void emitLoopConditionVariable(const clang::VarDecl &d, DeferredLoopConditionCleanup &condCleanup)
Emit a loop's condition-variable declaration.
mlir::LogicalResult emitReturnStmt(const clang::ReturnStmt &s)
mlir::LogicalResult emitOpenACCInitConstruct(const OpenACCInitConstruct &s)
void emitAnyExprToMem(const Expr *e, Address location, Qualifiers quals, bool isInitializer)
Emits the code necessary to evaluate an arbitrary expression into the given memory location.
mlir::LogicalResult emitOMPDistributeParallelForSimdDirective(const OMPDistributeParallelForSimdDirective &s)
mlir::LogicalResult emitOMPUnrollDirective(const OMPUnrollDirective &s)
mlir::LogicalResult emitOMPTaskDirective(const OMPTaskDirective &s)
mlir::LogicalResult emitOpenACCSetConstruct(const OpenACCSetConstruct &s)
RValue emitReferenceBindingToExpr(const Expr *e)
Emits a reference binding to the passed in expression.
mlir::LogicalResult emitOMPTeamsGenericLoopDirective(const OMPTeamsGenericLoopDirective &s)
mlir::LogicalResult emitOMPCanonicalLoop(const OMPCanonicalLoop &s)
mlir::LogicalResult emitSwitchStmt(const clang::SwitchStmt &s)
mlir::LogicalResult emitOMPTeamsDirective(const OMPTeamsDirective &s)
mlir::LogicalResult emitCaseStmt(const clang::CaseStmt &s, mlir::Type condType, bool buildingTopLevelCase)
llvm::ScopedHashTableScope< const clang::Decl *, mlir::Value > SymTableScopeTy
mlir::LogicalResult emitOMPMaskedTaskLoopDirective(const OMPMaskedTaskLoopDirective &s)
mlir::LogicalResult emitOMPFuseDirective(const OMPFuseDirective &s)
mlir::LogicalResult emitSimpleStmt(const clang::Stmt *s, bool useCurrentScope)
mlir::LogicalResult emitOMPSectionDirective(const OMPSectionDirective &s)
mlir::LogicalResult emitAsmStmt(const clang::AsmStmt &s)
mlir::LogicalResult emitOMPFlattenDirective(const OMPFlattenDirective &s)
mlir::LogicalResult emitOMPParallelForSimdDirective(const OMPParallelForSimdDirective &s)
mlir::LogicalResult emitOMPDistributeParallelForDirective(const OMPDistributeParallelForDirective &s)
mlir::LogicalResult emitOMPOrderedStandaloneDirective(const OMPOrderedStandaloneDirective &s)
mlir::LogicalResult emitOpenACCComputeConstruct(const OpenACCComputeConstruct &s)
mlir::LogicalResult emitOMPMasterTaskLoopSimdDirective(const OMPMasterTaskLoopSimdDirective &s)
EHScopeStack ehStack
Tracks function scope overall cleanup handling.
mlir::LogicalResult emitSwitchBody(const clang::Stmt *s)
mlir::LogicalResult emitForStmt(const clang::ForStmt &s)
mlir::LogicalResult emitOMPTaskwaitDirective(const OMPTaskwaitDirective &s)
mlir::LogicalResult emitOMPFlushDirective(const OMPFlushDirective &s)
mlir::LogicalResult emitOMPGenericLoopDirective(const OMPGenericLoopDirective &s)
mlir::LogicalResult emitOMPTargetUpdateDirective(const OMPTargetUpdateDirective &s)
std::optional< mlir::Value > fnRetAlloca
The compiler-generated variable that holds the return value.
mlir::LogicalResult emitOMPTargetParallelForSimdDirective(const OMPTargetParallelForSimdDirective &s)
mlir::LogicalResult emitOMPInterchangeDirective(const OMPInterchangeDirective &s)
mlir::LogicalResult emitOMPDispatchDirective(const OMPDispatchDirective &s)
mlir::LogicalResult emitCXXTryStmt(const clang::CXXTryStmt &s, cxxTryBodyEmitter &bodyCallback)
mlir::LogicalResult emitOMPParallelDirective(const OMPParallelDirective &s)
mlir::LogicalResult emitAttributedStmt(const AttributedStmt &s)
mlir::LogicalResult emitOMPForSimdDirective(const OMPForSimdDirective &s)
mlir::LogicalResult emitOMPTaskLoopDirective(const OMPTaskLoopDirective &s)
Address returnValue
The temporary alloca to hold the return value.
mlir::LogicalResult emitOMPTargetDataDirective(const OMPTargetDataDirective &s)
mlir::LogicalResult emitLabel(const clang::LabelDecl &d)
mlir::LogicalResult emitOMPTargetParallelGenericLoopDirective(const OMPTargetParallelGenericLoopDirective &s)
static bool hasAggregateEvaluationKind(clang::QualType type)
mlir::LogicalResult emitOMPParallelMaskedDirective(const OMPParallelMaskedDirective &s)
mlir::LogicalResult emitOMPMaskedTaskLoopSimdDirective(const OMPMaskedTaskLoopSimdDirective &s)
mlir::LogicalResult emitOMPAtomicDirective(const OMPAtomicDirective &s)
mlir::LogicalResult emitOpenACCShutdownConstruct(const OpenACCShutdownConstruct &s)
mlir::LogicalResult emitBreakStmt(const clang::BreakStmt &s)
mlir::LogicalResult emitIndirectGotoStmt(const IndirectGotoStmt &s)
mlir::LogicalResult emitOMPTeamsDistributeParallelForSimdDirective(const OMPTeamsDistributeParallelForSimdDirective &s)
mlir::LogicalResult emitOMPTaskgroupDirective(const OMPTaskgroupDirective &s)
mlir::LogicalResult emitOMPParallelMaskedTaskLoopSimdDirective(const OMPParallelMaskedTaskLoopSimdDirective &s)
mlir::LogicalResult emitOMPTeamsDistributeDirective(const OMPTeamsDistributeDirective &s)
void emitReturnOfRValue(mlir::Location loc, RValue rv, QualType ty)
mlir::LogicalResult emitOMPInteropDirective(const OMPInteropDirective &s)
mlir::LogicalResult emitOMPErrorDirective(const OMPErrorDirective &s)
mlir::LogicalResult emitOMPSingleDirective(const OMPSingleDirective &s)
mlir::LogicalResult emitContinueStmt(const clang::ContinueStmt &s)
mlir::LogicalResult emitOMPTaskyieldDirective(const OMPTaskyieldDirective &s)
mlir::LogicalResult emitOMPTargetTeamsDistributeSimdDirective(const OMPTargetTeamsDistributeSimdDirective &s)
mlir::LogicalResult emitOMPScanDirective(const OMPScanDirective &s)
llvm::SmallVector< mlir::Type, 2 > condTypeStack
The type of the condition for the emitting switch statement.
mlir::LogicalResult emitOMPTargetEnterDataDirective(const OMPTargetEnterDataDirective &s)
void emitStopPoint(const Stmt *s)
Build a debug stoppoint if we are emitting debug info.
mlir::LogicalResult emitOMPMasterTaskLoopDirective(const OMPMasterTaskLoopDirective &s)
mlir::LogicalResult emitOpenACCHostDataConstruct(const OpenACCHostDataConstruct &s)
mlir::Value emitScalarExpr(const clang::Expr *e, bool ignoreResultAssign=false)
Emit the computation of the specified expression of scalar type.
mlir::LogicalResult emitIfStmt(const clang::IfStmt &s)
mlir::LogicalResult emitOMPForDirective(const OMPForDirective &s)
mlir::LogicalResult emitOMPMasterDirective(const OMPMasterDirective &s)
AggValueSlot::Overlap_t getOverlapForReturnValue()
Determine whether a return value slot may overlap some other object.
mlir::LogicalResult emitSwitchCase(const clang::SwitchCase &s, bool buildingTopLevelCase)
mlir::LogicalResult emitOMPMetaDirective(const OMPMetaDirective &s)
mlir::LogicalResult emitOMPDistributeSimdDirective(const OMPDistributeSimdDirective &s)
void emitDecl(const clang::Decl &d, bool evaluateConditionDecl=false)
mlir::LogicalResult emitOMPParallelGenericLoopDirective(const OMPParallelGenericLoopDirective &s)
mlir::LogicalResult emitOMPMaskedDirective(const OMPMaskedDirective &s)
mlir::LogicalResult emitOMPSplitDirective(const OMPSplitDirective &s)
llvm::DenseMap< const VarDecl *, mlir::Value > nrvoFlags
A mapping from NRVO variables to the flags used to indicate when the NRVO has been applied to this va...
mlir::LogicalResult emitOpenACCEnterDataConstruct(const OpenACCEnterDataConstruct &s)
mlir::LogicalResult emitOMPTargetExitDataDirective(const OMPTargetExitDataDirective &s)
mlir::LogicalResult emitOMPOrderedBlockAssocDirective(const OMPOrderedBlockAssocDirective &s)
mlir::LogicalResult emitOMPTargetTeamsDistributeParallelForDirective(const OMPTargetTeamsDistributeParallelForDirective &s)
void emitComplexExprIntoLValue(const Expr *e, LValue dest, bool isInit)
mlir::LogicalResult emitOMPParallelForDirective(const OMPParallelForDirective &s)
mlir::LogicalResult emitCaseDefaultCascade(const T *stmt, mlir::Type condType, mlir::ArrayAttr value, cir::CaseOpKind kind, bool buildingTopLevelCase)
mlir::LogicalResult emitOMPSectionsDirective(const OMPSectionsDirective &s)
LValue makeAddrLValue(Address addr, QualType ty, AlignmentSource source=AlignmentSource::Type)
mlir::LogicalResult emitOMPDistributeDirective(const OMPDistributeDirective &s)
RValue emitAnyExpr(const clang::Expr *e, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
Emit code to compute the specified expression which can have any type.
mlir::LogicalResult emitOMPTargetTeamsDistributeParallelForSimdDirective(const OMPTargetTeamsDistributeParallelForSimdDirective &s)
mlir::LogicalResult emitOMPTargetTeamsGenericLoopDirective(const OMPTargetTeamsGenericLoopDirective &s)
mlir::LogicalResult emitDeclStmt(const clang::DeclStmt &s)
mlir::LogicalResult emitOMPTeamsDistributeSimdDirective(const OMPTeamsDistributeSimdDirective &s)
mlir::LogicalResult emitDefaultStmt(const clang::DefaultStmt &s, mlir::Type condType, bool buildingTopLevelCase)
mlir::LogicalResult emitWhileStmt(const clang::WhileStmt &s)
mlir::LogicalResult emitLabelStmt(const clang::LabelStmt &s)
mlir::LogicalResult emitOMPTaskLoopSimdDirective(const OMPTaskLoopSimdDirective &s)
void terminateStructuredRegionBody(mlir::Region &r, mlir::Location loc)
clang::ASTContext & getContext() const
mlir::LogicalResult emitCoroutineBody(const CoroutineBodyStmt &s)
mlir::LogicalResult emitCompoundStmt(const clang::CompoundStmt &s, Address *lastValue=nullptr, AggValueSlot slot=AggValueSlot::ignored())
mlir::LogicalResult emitGotoStmt(const clang::GotoStmt &s)
bool inAlwaysInlineAttributedStmt
True if the current statement has always_inline attribute.
bool inNoInlineAttributedStmt
True if the current statement has noinline attribute.
mlir::LogicalResult emitOMPParallelMasterTaskLoopDirective(const OMPParallelMasterTaskLoopDirective &s)
mlir::LogicalResult emitStmt(const clang::Stmt *s, bool useCurrentScope, llvm::ArrayRef< const Attr * > attrs={})
mlir::LogicalResult emitOMPCancelDirective(const OMPCancelDirective &s)
mlir::LogicalResult emitOMPStripeDirective(const OMPStripeDirective &s)
mlir::LogicalResult emitOMPTargetTeamsDistributeDirective(const OMPTargetTeamsDistributeDirective &s)
mlir::LogicalResult emitCompoundStmtWithoutScope(const clang::CompoundStmt &s, Address *lastValue=nullptr, AggValueSlot slot=AggValueSlot::ignored())
mlir::LogicalResult emitOMPParallelSectionsDirective(const OMPParallelSectionsDirective &s)
mlir::LogicalResult emitOpenACCExitDataConstruct(const OpenACCExitDataConstruct &s)
mlir::LogicalResult emitSYCLKernelCallStmt(const SYCLKernelCallStmt &s)
void emitIgnoredExpr(const clang::Expr *e)
Emit code to compute the specified expression, ignoring the result.
void emitAggExpr(const clang::Expr *e, AggValueSlot slot)
mlir::LogicalResult emitOpenACCAtomicConstruct(const OpenACCAtomicConstruct &s)
mlir::LogicalResult emitOMPTargetSimdDirective(const OMPTargetSimdDirective &s)
mlir::LogicalResult emitOMPAssumeDirective(const OMPAssumeDirective &s)
mlir::LogicalResult emitOpenACCLoopConstruct(const OpenACCLoopConstruct &s)
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
This trivial value class is used to represent the result of an expression that is evaluated.
Definition CIRGenValue.h:33
Address getAggregateAddress() const
Return the value of the address of the aggregate.
Definition CIRGenValue.h:69
bool isAggregate() const
Definition CIRGenValue.h:51
bool isComplex() const
Definition CIRGenValue.h:50
mlir::Value getValue() const
Return the value of this scalar value.
Definition CIRGenValue.h:57
bool isScalar() const
Definition CIRGenValue.h:49
mlir::Value getComplexValue() const
Return the value of this complex value.
Definition CIRGenValue.h:63
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition StmtCXX.h:136
DeclStmt * getBeginStmt()
Definition StmtCXX.h:164
DeclStmt * getEndStmt()
Definition StmtCXX.h:167
DeclStmt * getRangeStmt()
Definition StmtCXX.h:163
SourceLocation getEndLoc() const LLVM_READONLY
Definition StmtCXX.h:209
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2987
CaseStmt - Represent a case statement.
Definition Stmt.h:1932
Expr * getLHS()
Definition Stmt.h:2015
Expr * getRHS()
Definition Stmt.h:2027
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1752
body_range body()
Definition Stmt.h:1815
Stmt * body_back()
Definition Stmt.h:1820
ContinueStmt - This represents a continue.
Definition Stmt.h:3131
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1643
decl_range decls()
Definition Stmt.h:1691
DoStmt - This represents a 'do/while' stmt.
Definition Stmt.h:2844
SourceLocation getEndLoc() const
Definition Stmt.h:2881
This represents one expression.
Definition Expr.h:113
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3119
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:3722
QualType getType() const
Definition Expr.h:145
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2900
Stmt * getInit()
Definition Stmt.h:2915
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
Definition Stmt.cpp:1120
SourceLocation getEndLoc() const
Definition Stmt.h:2964
Stmt * getBody()
Definition Stmt.h:2944
Expr * getInc()
Definition Stmt.h:2943
Expr * getCond()
Definition Stmt.h:2942
GotoStmt - This represents a direct goto.
Definition Stmt.h:2981
LabelDecl * getLabel() const
Definition Stmt.h:2994
IfStmt - This represents an if/then/else.
Definition Stmt.h:2271
Stmt * getThen()
Definition Stmt.h:2360
Stmt * getInit()
Definition Stmt.h:2421
Expr * getCond()
Definition Stmt.h:2348
bool isConstexpr() const
Definition Stmt.h:2464
bool isNegatedConsteval() const
Definition Stmt.h:2460
Stmt * getElse()
Definition Stmt.h:2369
bool isConsteval() const
Definition Stmt.h:2451
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
Definition Stmt.cpp:1068
IndirectGotoStmt - This represents an indirect goto.
Definition Stmt.h:3020
Represents the declaration of a label.
Definition Decl.h:525
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:555
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2158
LabelDecl * getDecl() const
Definition Stmt.h:2176
bool isSideEntry() const
Definition Stmt.h:2205
Stmt * getSubStmt()
Definition Stmt.h:2180
SourceLocation getKwLoc() const
Definition Stmt.h:3094
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:302
A (possibly-)qualified type.
Definition TypeBase.h:938
The collection of all-type qualifiers we support.
Definition TypeBase.h:332
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition Stmt.h:3172
const VarDecl * getNRVOCandidate() const
Retrieve the variable that might be used for the named return value optimization.
Definition Stmt.h:3208
Expr * getRetValue()
Definition Stmt.h:3199
Stmt - This represents one statement.
Definition Stmt.h:85
@ NoStmtClass
Definition Stmt.h:88
StmtClass getStmtClass() const
Definition Stmt.h:1505
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:343
const char * getStmtClassName() const
Definition Stmt.cpp:86
SwitchStmt - This represents a 'switch' stmt.
Definition Stmt.h:2521
bool isAllEnumCasesCovered() const
Returns true if the SwitchStmt is a switch of an enum value and all cases have been explicitly covere...
Definition Stmt.h:2681
Expr * getCond()
Definition Stmt.h:2584
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
Definition Stmt.cpp:1186
Stmt * getInit()
Definition Stmt.h:2601
SourceLocation getBeginLoc() const
Definition Stmt.h:2685
bool isVoidType() const
Definition TypeBase.h:9037
Represents a variable declaration or definition.
Definition Decl.h:933
bool isNRVOVariable() const
Determine whether this local variable can be used with the named return value optimization (NRVO).
Definition Decl.h:1537
QualType::DestructionKind needsDestruction(const ASTContext &Ctx) const
Would the destruction of this variable have any effect, and if so, what kind?
Definition Decl.cpp:2821
WhileStmt - This represents a 'while' stmt.
Definition Stmt.h:2709
Expr * getCond()
Definition Stmt.h:2761
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
Definition Stmt.cpp:1247
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:2823
Stmt * getBody()
Definition Stmt.h:2773
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
const internal::VariadicDynCastAllOfMatcher< Stmt, CompoundStmt > compoundStmt
Matches compound statements.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicDynCastAllOfMatcher< Stmt, SwitchCase > switchCase
Matches case and default statements inside switch statements.
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
Definition Address.h:330
@ Default
Set to the current date and time.
const FunctionProtoType * T
U cast(CodeGen::Address addr)
Definition Address.h:327
@ Other
Other implicit parameter.
Definition Decl.h:1775
static bool aggValueSlotGC()
static bool createProfileWeightsForLoop()
static bool loopInfoStack()
static bool emitCondLikelihoodViaExpectIntrinsic()
static bool constantFoldSwitchStatement()
static bool insertBuiltinUnpredictable()
static bool generateDebugInfo()
static bool incrementProfileCounter()
Represents a scope, including function bodies, compound statements, and the substatements of if/while...