28#include "llvm/ADT/ArrayRef.h"
29#include "llvm/ADT/DenseMap.h"
30#include "llvm/ADT/SmallSet.h"
31#include "llvm/ADT/StringExtras.h"
32#include "llvm/IR/Assumptions.h"
33#include "llvm/IR/DataLayout.h"
34#include "llvm/IR/InlineAsm.h"
35#include "llvm/IR/Intrinsics.h"
36#include "llvm/IR/MDBuilder.h"
37#include "llvm/Support/SaveAndRestore.h"
62 assert(S &&
"Null statement?");
63 PGO->setCurrentStmt(S);
80 PGO->markStmtMaybeUsed(S);
94 if (
const auto *D = dyn_cast<OMPExecutableDirective>(S)) {
102 case Stmt::CXXCatchStmtClass:
103 case Stmt::SEHExceptStmtClass:
104 case Stmt::SEHFinallyStmtClass:
105 case Stmt::MSDependentExistsStmtClass:
106 llvm_unreachable(
"invalid statement class to emit generically");
107 case Stmt::NullStmtClass:
108 case Stmt::CompoundStmtClass:
109 case Stmt::DeclStmtClass:
110 case Stmt::LabelStmtClass:
111 case Stmt::AttributedStmtClass:
112 case Stmt::GotoStmtClass:
113 case Stmt::BreakStmtClass:
114 case Stmt::ContinueStmtClass:
115 case Stmt::DefaultStmtClass:
116 case Stmt::CaseStmtClass:
117 case Stmt::SEHLeaveStmtClass:
118 case Stmt::SYCLKernelCallStmtClass:
119 llvm_unreachable(
"should have emitted these statements as simple");
121#define STMT(Type, Base)
122#define ABSTRACT_STMT(Op)
123#define EXPR(Type, Base) \
124 case Stmt::Type##Class:
125#include "clang/AST/StmtNodes.inc"
128 llvm::BasicBlock *incoming =
Builder.GetInsertBlock();
129 assert(incoming &&
"expression emission must have an insertion point");
133 llvm::BasicBlock *outgoing =
Builder.GetInsertBlock();
134 assert(outgoing &&
"expression emission cleared block!");
148 if (incoming != outgoing && outgoing->use_empty()) {
149 outgoing->eraseFromParent();
155 case Stmt::IndirectGotoStmtClass:
166 case Stmt::GCCAsmStmtClass:
168 case Stmt::CoroutineBodyStmtClass:
171 case Stmt::CoreturnStmtClass:
174 case Stmt::CapturedStmtClass: {
179 case Stmt::ObjCAtTryStmtClass:
182 case Stmt::ObjCAtCatchStmtClass:
184 "@catch statements should be handled by EmitObjCAtTryStmt");
185 case Stmt::ObjCAtFinallyStmtClass:
187 "@finally statements should be handled by EmitObjCAtTryStmt");
188 case Stmt::ObjCAtThrowStmtClass:
191 case Stmt::ObjCAtSynchronizedStmtClass:
194 case Stmt::ObjCForCollectionStmtClass:
197 case Stmt::ObjCAutoreleasePoolStmtClass:
201 case Stmt::CXXTryStmtClass:
204 case Stmt::CXXForRangeStmtClass:
207 case Stmt::SEHTryStmtClass:
210 case Stmt::OMPMetaDirectiveClass:
213 case Stmt::OMPCanonicalLoopClass:
216 case Stmt::OMPParallelDirectiveClass:
219 case Stmt::OMPSimdDirectiveClass:
222 case Stmt::OMPTileDirectiveClass:
225 case Stmt::OMPStripeDirectiveClass:
228 case Stmt::OMPUnrollDirectiveClass:
231 case Stmt::OMPReverseDirectiveClass:
234 case Stmt::OMPInterchangeDirectiveClass:
237 case Stmt::OMPForDirectiveClass:
240 case Stmt::OMPForSimdDirectiveClass:
243 case Stmt::OMPSectionsDirectiveClass:
246 case Stmt::OMPSectionDirectiveClass:
249 case Stmt::OMPSingleDirectiveClass:
252 case Stmt::OMPMasterDirectiveClass:
255 case Stmt::OMPCriticalDirectiveClass:
258 case Stmt::OMPParallelForDirectiveClass:
261 case Stmt::OMPParallelForSimdDirectiveClass:
264 case Stmt::OMPParallelMasterDirectiveClass:
267 case Stmt::OMPParallelSectionsDirectiveClass:
270 case Stmt::OMPTaskDirectiveClass:
273 case Stmt::OMPTaskyieldDirectiveClass:
276 case Stmt::OMPErrorDirectiveClass:
279 case Stmt::OMPBarrierDirectiveClass:
282 case Stmt::OMPTaskwaitDirectiveClass:
285 case Stmt::OMPTaskgroupDirectiveClass:
288 case Stmt::OMPFlushDirectiveClass:
291 case Stmt::OMPDepobjDirectiveClass:
294 case Stmt::OMPScanDirectiveClass:
297 case Stmt::OMPOrderedDirectiveClass:
300 case Stmt::OMPAtomicDirectiveClass:
303 case Stmt::OMPTargetDirectiveClass:
306 case Stmt::OMPTeamsDirectiveClass:
309 case Stmt::OMPCancellationPointDirectiveClass:
312 case Stmt::OMPCancelDirectiveClass:
315 case Stmt::OMPTargetDataDirectiveClass:
318 case Stmt::OMPTargetEnterDataDirectiveClass:
321 case Stmt::OMPTargetExitDataDirectiveClass:
324 case Stmt::OMPTargetParallelDirectiveClass:
327 case Stmt::OMPTargetParallelForDirectiveClass:
330 case Stmt::OMPTaskLoopDirectiveClass:
333 case Stmt::OMPTaskLoopSimdDirectiveClass:
336 case Stmt::OMPMasterTaskLoopDirectiveClass:
339 case Stmt::OMPMaskedTaskLoopDirectiveClass:
342 case Stmt::OMPMasterTaskLoopSimdDirectiveClass:
346 case Stmt::OMPMaskedTaskLoopSimdDirectiveClass:
350 case Stmt::OMPParallelMasterTaskLoopDirectiveClass:
354 case Stmt::OMPParallelMaskedTaskLoopDirectiveClass:
358 case Stmt::OMPParallelMasterTaskLoopSimdDirectiveClass:
362 case Stmt::OMPParallelMaskedTaskLoopSimdDirectiveClass:
366 case Stmt::OMPDistributeDirectiveClass:
369 case Stmt::OMPTargetUpdateDirectiveClass:
372 case Stmt::OMPDistributeParallelForDirectiveClass:
376 case Stmt::OMPDistributeParallelForSimdDirectiveClass:
380 case Stmt::OMPDistributeSimdDirectiveClass:
383 case Stmt::OMPTargetParallelForSimdDirectiveClass:
387 case Stmt::OMPTargetSimdDirectiveClass:
390 case Stmt::OMPTeamsDistributeDirectiveClass:
393 case Stmt::OMPTeamsDistributeSimdDirectiveClass:
397 case Stmt::OMPTeamsDistributeParallelForSimdDirectiveClass:
401 case Stmt::OMPTeamsDistributeParallelForDirectiveClass:
405 case Stmt::OMPTargetTeamsDirectiveClass:
408 case Stmt::OMPTargetTeamsDistributeDirectiveClass:
412 case Stmt::OMPTargetTeamsDistributeParallelForDirectiveClass:
416 case Stmt::OMPTargetTeamsDistributeParallelForSimdDirectiveClass:
420 case Stmt::OMPTargetTeamsDistributeSimdDirectiveClass:
424 case Stmt::OMPInteropDirectiveClass:
427 case Stmt::OMPDispatchDirectiveClass:
428 CGM.ErrorUnsupported(S,
"OpenMP dispatch directive");
430 case Stmt::OMPScopeDirectiveClass:
433 case Stmt::OMPMaskedDirectiveClass:
436 case Stmt::OMPGenericLoopDirectiveClass:
439 case Stmt::OMPTeamsGenericLoopDirectiveClass:
442 case Stmt::OMPTargetTeamsGenericLoopDirectiveClass:
446 case Stmt::OMPParallelGenericLoopDirectiveClass:
450 case Stmt::OMPTargetParallelGenericLoopDirectiveClass:
454 case Stmt::OMPParallelMaskedDirectiveClass:
457 case Stmt::OMPAssumeDirectiveClass:
460 case Stmt::OpenACCComputeConstructClass:
463 case Stmt::OpenACCLoopConstructClass:
466 case Stmt::OpenACCCombinedConstructClass:
469 case Stmt::OpenACCDataConstructClass:
472 case Stmt::OpenACCEnterDataConstructClass:
475 case Stmt::OpenACCExitDataConstructClass:
478 case Stmt::OpenACCHostDataConstructClass:
481 case Stmt::OpenACCWaitConstructClass:
484 case Stmt::OpenACCInitConstructClass:
487 case Stmt::OpenACCShutdownConstructClass:
490 case Stmt::OpenACCSetConstructClass:
493 case Stmt::OpenACCUpdateConstructClass:
496 case Stmt::OpenACCAtomicConstructClass:
499 case Stmt::OpenACCCacheConstructClass:
510 case Stmt::NullStmtClass:
512 case Stmt::CompoundStmtClass:
515 case Stmt::DeclStmtClass:
518 case Stmt::LabelStmtClass:
521 case Stmt::AttributedStmtClass:
524 case Stmt::GotoStmtClass:
527 case Stmt::BreakStmtClass:
530 case Stmt::ContinueStmtClass:
533 case Stmt::DefaultStmtClass:
536 case Stmt::CaseStmtClass:
539 case Stmt::SEHLeaveStmtClass:
542 case Stmt::SYCLKernelCallStmtClass:
569 "LLVM IR generation of compound statement ('{}')");
583 assert((!GetLast || (GetLast &&
ExprResult)) &&
584 "If GetLast is true then the CompoundStmt must have a StmtExprResult");
588 for (
auto *CurStmt : S.
body()) {
596 if (
const auto *LS = dyn_cast<LabelStmt>(
ExprResult)) {
599 }
else if (
const auto *AS = dyn_cast<AttributedStmt>(
ExprResult)) {
604 llvm_unreachable(
"unknown value statement");
631 llvm::BranchInst *BI = dyn_cast<llvm::BranchInst>(BB->getTerminator());
640 if (!BI || !BI->isUnconditional())
644 if (BI->getIterator() != BB->begin())
647 BB->replaceAllUsesWith(BI->getSuccessor(0));
648 BI->eraseFromParent();
649 BB->eraseFromParent();
653 llvm::BasicBlock *CurBB =
Builder.GetInsertBlock();
658 if (IsFinished && BB->use_empty()) {
665 if (CurBB && CurBB->getParent())
666 CurFn->insert(std::next(CurBB->getIterator()), BB);
676 llvm::BasicBlock *CurBB =
Builder.GetInsertBlock();
678 if (!CurBB || CurBB->getTerminator()) {
690 bool inserted =
false;
691 for (llvm::User *u : block->users()) {
692 if (llvm::Instruction *insn = dyn_cast<llvm::Instruction>(u)) {
693 CurFn->insert(std::next(insn->getParent()->getIterator()), block);
708 if (Dest.
isValid())
return Dest;
721 if (
EHStack.hasNormalCleanups() && CurLexicalScope)
722 CurLexicalScope->addLabel(D);
743 if (
CGM.getCodeGenOpts().hasReducedDebugInfo()) {
755 assert(!Labels.empty());
757 =
CGF.EHStack.getInnermostNormalCleanup();
761 assert(
CGF.LabelMap.count(Label));
770 ParentScope->Labels.append(Labels.begin(), Labels.end());
786 bool nomerge =
false;
787 bool noinline =
false;
788 bool alwaysinline =
false;
789 bool noconvergent =
false;
790 HLSLControlFlowHintAttr::Spelling flattenOrBranch =
791 HLSLControlFlowHintAttr::SpellingNotCalculated;
793 const AtomicAttr *AA =
nullptr;
795 for (
const auto *A : S.
getAttrs()) {
796 switch (A->getKind()) {
805 case attr::AlwaysInline:
808 case attr::NoConvergent:
811 case attr::MustTail: {
816 case attr::CXXAssume: {
821 Builder.CreateAssumption(AssumptionVal);
827 case attr::HLSLControlFlowHint: {
864 llvm::BasicBlock *CurBB =
Builder.GetInsertBlock();
874 if (CurBB && CurBB->getTerminator())
910 const Stmt *Skipped = Else;
912 std::swap(Executed, Skipped);
924 PGO->markStmtMaybeUsed(Skipped);
933 llvm::BasicBlock *ElseBlock = ContBlock;
951 CGM.getCodeGenOpts().OptimizationLevel)
960 if (!
CGM.getCodeGenOpts().MCDCCoverage) {
967 Builder.CreateCondBr(BoolCondVal, ThenBlock, ElseBlock);
1013 bool HasEmptyBody) {
1014 if (
CGM.getCodeGenOpts().getFiniteLoops() ==
1024 bool CondIsConstInt =
1025 !ControllingExpression ||
1029 bool CondIsTrue = CondIsConstInt && (!ControllingExpression ||
1030 Result.Val.getInt().getBoolValue());
1041 if (
CGM.getCodeGenOpts().getFiniteLoops() ==
1044 if (HasEmptyBody && CondIsTrue) {
1045 CurFn->removeFnAttr(llvm::Attribute::MustProgress);
1063 if constexpr (std::is_same_v<LoopStmt, ForStmt>) {
1067 const Stmt *Body = S.getBody();
1070 if (
const CompoundStmt *Compound = dyn_cast<CompoundStmt>(Body))
1071 return Compound->body_empty();
1082 if (
CGM.shouldEmitConvergenceTokens())
1084 emitConvergenceLoopToken(LoopHeader.
getBlock()));
1091 BreakContinueStack.push_back(BreakContinue(S,
LoopExit, LoopHeader));
1114 llvm::ConstantInt *
C = dyn_cast<llvm::ConstantInt>(BoolCondVal);
1115 bool EmitBoolCondBranch = !
C || !
C->isOne();
1128 if (EmitBoolCondBranch) {
1129 llvm::BasicBlock *ExitBlock =
LoopExit.getBlock();
1132 llvm::MDNode *Weights =
1134 if (!Weights &&
CGM.getCodeGenOpts().OptimizationLevel)
1135 BoolCondVal = emitCondLikelihoodViaExpectIntrinsic(
1137 auto *I =
Builder.CreateCondBr(BoolCondVal, LoopBody, ExitBlock, Weights);
1143 if (
auto *CondI = dyn_cast<llvm::Instruction>(BoolCondVal))
1147 if (ExitBlock !=
LoopExit.getBlock()) {
1152 CGM.getDiags().Report(A->getLocation(),
1153 diag::warn_attribute_has_no_effect_on_infinite_loop)
1154 << A << A->getRange();
1155 CGM.getDiags().Report(
1157 diag::note_attribute_has_no_effect_on_infinite_loop_here)
1174 BreakContinueStack.pop_back();
1190 if (!EmitBoolCondBranch)
1198 if (
CGM.shouldEmitConvergenceTokens())
1210 BreakContinueStack.push_back(BreakContinue(S,
LoopExit, LoopCond));
1220 if (
CGM.shouldEmitConvergenceTokens())
1241 BreakContinueStack.pop_back();
1245 llvm::ConstantInt *
C = dyn_cast<llvm::ConstantInt>(BoolCondVal);
1246 bool EmitBoolCondBranch = !
C || !
C->isZero();
1249 LoopStack.push(LoopBody,
CGM.getContext(),
CGM.getCodeGenOpts(), DoAttrs,
1255 if (EmitBoolCondBranch) {
1257 auto *I =
Builder.CreateCondBr(
1258 BoolCondVal, LoopBody,
LoopExit.getBlock(),
1259 createProfileWeightsForLoop(S.
getCond(), BackedgeCount));
1266 if (
auto *CondI = dyn_cast<llvm::Instruction>(BoolCondVal))
1278 if (!EmitBoolCondBranch)
1286 if (
CGM.shouldEmitConvergenceTokens())
1294 std::optional<LexicalScope> ForScope;
1306 llvm::BasicBlock *CondBlock = CondDest.
getBlock();
1309 if (
CGM.shouldEmitConvergenceTokens())
1313 LoopStack.push(CondBlock,
CGM.getContext(),
CGM.getCodeGenOpts(), ForAttrs,
1330 Continue = CondDest;
1333 BreakContinueStack.push_back(BreakContinue(S,
LoopExit, Continue));
1344 BreakContinueStack.back().ContinueBlock = Continue;
1352 llvm::BasicBlock *ExitBlock =
LoopExit.getBlock();
1355 if (ForScope && ForScope->requiresCleanups())
1367 llvm::MDNode *Weights =
1369 if (!Weights &&
CGM.getCodeGenOpts().OptimizationLevel)
1370 BoolCondVal = emitCondLikelihoodViaExpectIntrinsic(
1373 auto *I =
Builder.CreateCondBr(BoolCondVal, ForBody, ExitBlock, Weights);
1378 if (
auto *CondI = dyn_cast<llvm::Instruction>(BoolCondVal))
1382 if (ExitBlock !=
LoopExit.getBlock()) {
1407 auto *FinalBodyBB =
Builder.GetInsertBlock();
1417 BreakContinueStack.pop_back();
1425 ForScope->ForceCleanup();
1437 if (
CGM.shouldEmitConvergenceTokens())
1467 if (
CGM.shouldEmitConvergenceTokens())
1471 LoopStack.push(CondBlock,
CGM.getContext(),
CGM.getCodeGenOpts(), ForAttrs,
1477 llvm::BasicBlock *ExitBlock =
LoopExit.getBlock();
1487 llvm::MDNode *Weights =
1489 if (!Weights &&
CGM.getCodeGenOpts().OptimizationLevel)
1490 BoolCondVal = emitCondLikelihoodViaExpectIntrinsic(
1492 auto *I =
Builder.CreateCondBr(BoolCondVal, ForBody, ExitBlock, Weights);
1497 if (
auto *CondI = dyn_cast<llvm::Instruction>(BoolCondVal))
1501 if (ExitBlock !=
LoopExit.getBlock()) {
1516 BreakContinueStack.push_back(BreakContinue(S,
LoopExit, Continue));
1526 auto *FinalBodyBB =
Builder.GetInsertBlock();
1533 BreakContinueStack.pop_back();
1549 if (
CGM.shouldEmitConvergenceTokens())
1559void CodeGenFunction::EmitReturnOfRValue(
RValue RV,
QualType Ty) {
1575struct SaveRetExprRAII {
1576 SaveRetExprRAII(
const Expr *RetExpr, CodeGenFunction &CGF)
1577 : OldRetExpr(CGF.RetExpr), CGF(CGF) {
1580 ~SaveRetExprRAII() { CGF.RetExpr = OldRetExpr; }
1581 const Expr *OldRetExpr;
1582 CodeGenFunction &CGF;
1590 if (calleeQualType->isFunctionPointerType() ||
1591 calleeQualType->isFunctionReferenceType() ||
1592 calleeQualType->isBlockPointerType() ||
1593 calleeQualType->isMemberFunctionPointerType()) {
1595 }
else if (
auto *ty = dyn_cast<FunctionType>(calleeQualType)) {
1597 }
else if (
auto CMCE = dyn_cast<CXXMemberCallExpr>(CE)) {
1598 if (
auto methodDecl = CMCE->getMethodDecl()) {
1615 if (requiresReturnValueCheck()) {
1618 new llvm::GlobalVariable(
CGM.getModule(), SLoc->getType(),
false,
1619 llvm::GlobalVariable::PrivateLinkage, SLoc);
1620 SLocPtr->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
1621 CGM.getSanitizerMetadata()->disableSanitizerForGlobal(SLocPtr);
1622 assert(ReturnLocation.isValid() &&
"No valid return location");
1623 Builder.CreateStore(SLocPtr, ReturnLocation);
1629 Builder.ClearInsertionPoint();
1643 SaveRetExprRAII SaveRetExpr(RV, *
this);
1646 if (
const auto *EWC = dyn_cast_or_null<ExprWithCleanups>(RV))
1647 RV = EWC->getSubExpr();
1651 std::optional<llvm::SaveAndRestore<const CallExpr *>> SaveMustTail;
1654 if (
auto CE = dyn_cast<CallExpr>(RV)) {
1667 !
CGM.getOpenMPRuntime()
1686 }
else if (
FnRetTy->isReferenceType()) {
1722 ++NumSimpleReturnExprs;
1734 for (
const auto *I : S.
decls())
1739 ->
const BreakContinue * {
1740 if (!S.hasLabelTarget())
1741 return &BreakContinueStack.back();
1743 const Stmt *LoopOrSwitch = S.getNamedLoopOrSwitch();
1744 assert(LoopOrSwitch &&
"break/continue target not set?");
1745 for (
const BreakContinue &BC : llvm::reverse(BreakContinueStack))
1746 if (BC.LoopOrSwitch == LoopOrSwitch)
1749 llvm_unreachable(
"break/continue target not found");
1753 assert(!BreakContinueStack.empty() &&
"break stmt not in a loop or switch!");
1766 assert(!BreakContinueStack.empty() &&
"continue stmt not in a loop!");
1783 assert(S.
getRHS() &&
"Expected RHS value in CaseStmt");
1796 if (LHS.isSigned() ? RHS.slt(LHS) : RHS.ult(LHS))
1800 llvm::APInt Range = RHS - LHS;
1802 if (Range.ult(llvm::APInt(Range.getBitWidth(), 64))) {
1805 unsigned NCases = Range.getZExtValue() + 1;
1810 uint64_t Weight = Total / NCases, Rem = Total % NCases;
1811 for (
unsigned I = 0; I != NCases; ++I) {
1813 SwitchWeights->push_back(Weight + (Rem ? 1 : 0));
1814 else if (SwitchLikelihood)
1815 SwitchLikelihood->push_back(LH);
1819 SwitchInsn->addCase(
Builder.getInt(LHS), CaseDest);
1827 llvm::BasicBlock *RestoreBB =
Builder.GetInsertBlock();
1832 llvm::BasicBlock *FalseDest = CaseRangeBlock;
1836 Builder.SetInsertPoint(CaseRangeBlock);
1840 Builder.CreateSub(SwitchInsn->getCondition(),
Builder.getInt(LHS));
1844 llvm::MDNode *Weights =
nullptr;
1845 if (SwitchWeights) {
1847 uint64_t DefaultCount = (*SwitchWeights)[0];
1848 Weights = createProfileWeights(ThisCount, DefaultCount);
1853 (*SwitchWeights)[0] += ThisCount;
1854 }
else if (SwitchLikelihood)
1855 Cond = emitCondLikelihoodViaExpectIntrinsic(
Cond, LH);
1857 Builder.CreateCondBr(
Cond, CaseDest, FalseDest, Weights);
1861 Builder.SetInsertPoint(RestoreBB);
1863 Builder.ClearInsertionPoint();
1884 llvm::ConstantInt *CaseVal =
1889 if (
auto ICE = dyn_cast<ImplicitCastExpr>(S.
getLHS()))
1890 CE = dyn_cast<ConstantExpr>(ICE->getSubExpr());
1892 CE = dyn_cast<ConstantExpr>(S.
getLHS());
1894 if (
auto DE = dyn_cast<DeclRefExpr>(CE->
getSubExpr()))
1896 if (
CGM.getCodeGenOpts().hasReducedDebugInfo())
1897 Dbg->EmitGlobalVariable(DE->getDecl(),
1898 APValue(llvm::APSInt(CaseVal->getValue())));
1901 if (SwitchLikelihood)
1907 if (!
CGM.getCodeGenOpts().hasProfileClangInstr() &&
1908 CGM.getCodeGenOpts().OptimizationLevel > 0 &&
1916 SwitchInsn->addCase(CaseVal,
Block.getBlock());
1920 if (
Builder.GetInsertBlock()) {
1922 Builder.ClearInsertionPoint();
1932 SwitchInsn->addCase(CaseVal, CaseDest);
1951 while (NextCase && NextCase->
getRHS() ==
nullptr) {
1953 llvm::ConstantInt *CaseVal =
1958 if (
CGM.getCodeGenOpts().hasProfileClangInstr()) {
1964 if (SwitchLikelihood)
1967 SwitchInsn->addCase(CaseVal, CaseDest);
1968 NextCase = dyn_cast<CaseStmt>(CurCase->
getSubStmt());
1991 llvm::BasicBlock *DefaultBlock = SwitchInsn->getDefaultDest();
1992 assert(DefaultBlock->empty() &&
1993 "EmitDefaultStmt: Default block already defined?");
1995 if (SwitchLikelihood)
2037 if (
const SwitchCase *SC = dyn_cast<SwitchCase>(S)) {
2056 if (
const CompoundStmt *CS = dyn_cast<CompoundStmt>(S)) {
2060 bool StartedInLiveCode = FoundCase;
2061 unsigned StartSize = ResultStmts.size();
2068 bool HadSkippedDecl =
false;
2072 for (; Case && I != E; ++I) {
2088 for (++I; I != E; ++I)
2098 assert(FoundCase &&
"Didn't find case but returned fallthrough?");
2113 assert(!HadSkippedDecl &&
"fallthrough after skipping decl");
2118 bool AnyDecls =
false;
2119 for (; I != E; ++I) {
2132 for (++I; I != E; ++I)
2149 ResultStmts.resize(StartSize);
2150 ResultStmts.push_back(S);
2174 ResultStmts.push_back(S);
2183 const llvm::APSInt &ConstantCondValue,
2195 if (
const DefaultStmt *DS = dyn_cast<DefaultStmt>(Case)) {
2203 if (CS->
getRHS())
return false;
2228 bool FoundCase =
false;
2235static std::optional<SmallVector<uint64_t, 16>>
2238 if (Likelihoods.size() <= 1)
2239 return std::nullopt;
2241 uint64_t NumUnlikely = 0;
2242 uint64_t NumNone = 0;
2243 uint64_t NumLikely = 0;
2244 for (
const auto LH : Likelihoods) {
2259 if (NumUnlikely == 0 && NumLikely == 0)
2260 return std::nullopt;
2268 const uint64_t Likely = INT32_MAX / (NumLikely + 2);
2269 const uint64_t
None = Likely / (NumNone + 1);
2270 const uint64_t Unlikely = 0;
2273 Result.reserve(Likelihoods.size());
2274 for (
const auto LH : Likelihoods) {
2277 Result.push_back(Unlikely);
2280 Result.push_back(
None);
2283 Result.push_back(Likely);
2293 llvm::SwitchInst *SavedSwitchInsn = SwitchInsn;
2296 llvm::BasicBlock *SavedCRBlock = CaseRangeBlock;
2300 llvm::APSInt ConstantCondValue;
2321 SwitchInsn =
nullptr;
2328 PGO->markStmtMaybeUsed(S.
getBody());
2332 SwitchInsn = SavedSwitchInsn;
2355 SwitchInsn =
Builder.CreateSwitch(CondV, DefaultBlock);
2359 llvm::MDBuilder MDHelper(
CGM.getLLVMContext());
2360 llvm::ConstantInt *BranchHintConstant =
2362 HLSLControlFlowHintAttr::Spelling::Microsoft_branch
2363 ? llvm::ConstantInt::get(
CGM.Int32Ty, 1)
2364 : llvm::ConstantInt::get(
CGM.Int32Ty, 2);
2365 llvm::Metadata *Vals[] = {MDHelper.createString(
"hlsl.controlflow.hint"),
2366 MDHelper.createConstant(BranchHintConstant)};
2367 SwitchInsn->setMetadata(
"hlsl.controlflow.hint",
2368 llvm::MDNode::get(
CGM.getLLVMContext(), Vals));
2371 if (PGO->haveRegionCounts()) {
2373 uint64_t DefaultCount = 0;
2374 unsigned NumCases = 0;
2383 SwitchWeights->reserve(NumCases);
2386 SwitchWeights->push_back(DefaultCount);
2387 }
else if (
CGM.getCodeGenOpts().OptimizationLevel) {
2393 CaseRangeBlock = DefaultBlock;
2396 Builder.ClearInsertionPoint();
2401 if (!BreakContinueStack.empty())
2402 OuterContinue = BreakContinueStack.back().ContinueBlock;
2404 BreakContinueStack.push_back(BreakContinue(S, SwitchExit, OuterContinue));
2409 BreakContinueStack.pop_back();
2413 SwitchInsn->setDefaultDest(CaseRangeBlock);
2416 if (!DefaultBlock->getParent()) {
2424 DefaultBlock->replaceAllUsesWith(SwitchExit.
getBlock());
2425 delete DefaultBlock;
2439 if (
Call &&
CGM.getCodeGenOpts().OptimizationLevel != 0) {
2440 auto *FD = dyn_cast_or_null<FunctionDecl>(
Call->getCalleeDecl());
2441 if (FD && FD->getBuiltinID() == Builtin::BI__builtin_unpredictable) {
2443 SwitchInsn->setMetadata(llvm::LLVMContext::MD_unpredictable,
2444 MDHelper.createUnpredictable());
2448 if (SwitchWeights) {
2449 assert(SwitchWeights->size() == 1 + SwitchInsn->getNumCases() &&
2450 "switch weights do not match switch cases");
2452 if (SwitchWeights->size() > 1)
2453 SwitchInsn->setMetadata(llvm::LLVMContext::MD_prof,
2454 createProfileWeights(*SwitchWeights));
2455 delete SwitchWeights;
2456 }
else if (SwitchLikelihood) {
2457 assert(SwitchLikelihood->size() == 1 + SwitchInsn->getNumCases() &&
2458 "switch likelihoods do not match switch cases");
2459 std::optional<SmallVector<uint64_t, 16>> LHW =
2462 llvm::MDBuilder MDHelper(
CGM.getLLVMContext());
2463 SwitchInsn->setMetadata(llvm::LLVMContext::MD_prof,
2464 createProfileWeights(*LHW));
2466 delete SwitchLikelihood;
2468 SwitchInsn = SavedSwitchInsn;
2469 SwitchWeights = SavedSwitchWeights;
2470 SwitchLikelihood = SavedSwitchLikelihood;
2471 CaseRangeBlock = SavedCRBlock;
2479 while (*Constraint) {
2480 switch (*Constraint) {
2482 Result +=
Target.convertConstraint(Constraint);
2492 while (Constraint[1] && Constraint[1] !=
',')
2497 Result += *Constraint;
2498 while (Constraint[1] && Constraint[1] == *Constraint)
2509 "Must pass output names to constraints with a symbolic name");
2511 bool result =
Target.resolveSymbolicName(Constraint, *OutCons, Index);
2512 assert(result &&
"Could not resolve symbolic name"); (void)result;
2513 Result += llvm::utostr(Index);
2531 std::string *GCCReg =
nullptr) {
2532 const DeclRefExpr *AsmDeclRef = dyn_cast<DeclRefExpr>(&AsmExpr);
2541 AsmLabelAttr *
Attr = Variable->getAttr<AsmLabelAttr>();
2544 StringRef Register =
Attr->getLabel();
2545 assert(
Target.isValidGCCRegisterName(Register));
2549 if (
Target.validateOutputConstraint(Info) &&
2555 Register =
Target.getNormalizedGCCRegisterName(Register);
2556 if (GCCReg !=
nullptr)
2557 *GCCReg = Register.str();
2558 return (EarlyClobber ?
"&{" :
"{") + Register.str() +
"}";
2561std::pair<llvm::Value*, llvm::Type *> CodeGenFunction::EmitAsmInputLValue(
2562 const TargetInfo::ConstraintInfo &Info, LValue InputValue,
2563 QualType InputType, std::string &ConstraintStr, SourceLocation Loc) {
2570 if ((Size <= 64 && llvm::isPowerOf2_64(Size)) ||
2574 return {
Builder.CreateLoad(InputValue.getAddress().withElementType(Ty)),
2579 Address
Addr = InputValue.getAddress();
2580 ConstraintStr +=
'*';
2581 return {InputValue.getPointer(*
this),
Addr.getElementType()};
2584std::pair<llvm::Value *, llvm::Type *>
2585CodeGenFunction::EmitAsmInput(
const TargetInfo::ConstraintInfo &Info,
2586 const Expr *InputExpr,
2587 std::string &ConstraintStr) {
2592 Expr::EvalResult EVResult;
2595 llvm::APSInt IntResult;
2598 return {llvm::ConstantInt::get(
getLLVMContext(), IntResult),
nullptr};
2610 if (InputExpr->
getStmtClass() == Expr::CXXThisExprClass)
2614 return EmitAsmInputLValue(Info, Dest, InputExpr->
getType(), ConstraintStr,
2626 Locs.push_back(llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
2629 if (!StrVal.empty()) {
2632 unsigned StartToken = 0;
2633 unsigned ByteOffset = 0;
2637 for (
unsigned i = 0, e = StrVal.size() - 1; i != e; ++i) {
2638 if (StrVal[i] !=
'\n')
continue;
2640 i + 1,
SM, LangOpts, CGF.
getTarget(), &StartToken, &ByteOffset);
2641 Locs.push_back(llvm::ConstantAsMetadata::get(
2650 bool HasUnwindClobber,
bool ReadOnly,
2651 bool ReadNone,
bool NoMerge,
bool NoConvergent,
2653 const std::vector<llvm::Type *> &ResultRegTypes,
2654 const std::vector<llvm::Type *> &ArgElemTypes,
2656 std::vector<llvm::Value *> &RegResults) {
2657 if (!HasUnwindClobber)
2658 Result.addFnAttr(llvm::Attribute::NoUnwind);
2661 Result.addFnAttr(llvm::Attribute::NoMerge);
2663 if (!HasSideEffect) {
2665 Result.setDoesNotAccessMemory();
2667 Result.setOnlyReadsMemory();
2671 for (
auto Pair : llvm::enumerate(ArgElemTypes)) {
2673 auto Attr = llvm::Attribute::get(
2674 CGF.
getLLVMContext(), llvm::Attribute::ElementType, Pair.value());
2675 Result.addParamAttr(Pair.index(),
Attr);
2682 if (
const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(&S);
2684 (SL = dyn_cast<StringLiteral>(gccAsmStmt->getAsmStringExpr()))) {
2689 llvm::Constant *Loc =
2691 Result.setMetadata(
"srcloc",
2693 llvm::ConstantAsMetadata::get(Loc)));
2704 Result.addFnAttr(llvm::Attribute::Convergent);
2706 if (ResultRegTypes.size() == 1) {
2707 RegResults.push_back(&Result);
2709 for (
unsigned i = 0, e = ResultRegTypes.size(); i != e; ++i) {
2710 llvm::Value *Tmp = CGF.
Builder.CreateExtractValue(&Result, i,
"asmresult");
2711 RegResults.push_back(Tmp);
2723 const llvm::BitVector &ResultTypeRequiresCast,
2724 const llvm::BitVector &ResultRegIsFlagReg) {
2729 assert(RegResults.size() == ResultRegTypes.size());
2730 assert(RegResults.size() == ResultTruncRegTypes.size());
2731 assert(RegResults.size() == ResultRegDests.size());
2734 assert(ResultTypeRequiresCast.size() <= ResultRegDests.size());
2735 assert(ResultRegIsFlagReg.size() <= ResultRegDests.size());
2737 for (
unsigned i = 0, e = RegResults.size(); i != e; ++i) {
2738 llvm::Value *Tmp = RegResults[i];
2739 llvm::Type *TruncTy = ResultTruncRegTypes[i];
2741 if ((i < ResultRegIsFlagReg.size()) && ResultRegIsFlagReg[i]) {
2744 llvm::Constant *Two = llvm::ConstantInt::get(Tmp->getType(), 2);
2745 llvm::Value *IsBooleanValue =
2746 Builder.CreateCmp(llvm::CmpInst::ICMP_ULT, Tmp, Two);
2748 Builder.CreateCall(FnAssume, IsBooleanValue);
2753 if (ResultRegTypes[i] != TruncTy) {
2757 if (TruncTy->isFloatingPointTy())
2758 Tmp = Builder.CreateFPTrunc(Tmp, TruncTy);
2759 else if (TruncTy->isPointerTy() && Tmp->getType()->isIntegerTy()) {
2761 Tmp = Builder.CreateTrunc(
2762 Tmp, llvm::IntegerType::get(CTX, (
unsigned)ResSize));
2763 Tmp = Builder.CreateIntToPtr(Tmp, TruncTy);
2764 }
else if (Tmp->getType()->isPointerTy() && TruncTy->isIntegerTy()) {
2767 Tmp = Builder.CreatePtrToInt(
2768 Tmp, llvm::IntegerType::get(CTX, (
unsigned)TmpSize));
2769 Tmp = Builder.CreateTrunc(Tmp, TruncTy);
2770 }
else if (Tmp->getType()->isIntegerTy() && TruncTy->isIntegerTy()) {
2771 Tmp = Builder.CreateZExtOrTrunc(Tmp, TruncTy);
2772 }
else if (Tmp->getType()->isVectorTy() || TruncTy->isVectorTy()) {
2773 Tmp = Builder.CreateBitCast(Tmp, TruncTy);
2778 LValue Dest = ResultRegDests[i];
2781 if ((i < ResultTypeRequiresCast.size()) && ResultTypeRequiresCast[i]) {
2783 Address A = Dest.getAddress().withElementType(ResultRegTypes[i]);
2785 llvm::StoreInst *S = Builder.CreateStore(Tmp, A);
2795 diag::err_store_value_to_reg);
2806 constexpr auto Name =
"__ASM__hipstdpar_unsupported";
2809 if (
auto GCCAsm = dyn_cast<GCCAsmStmt>(&S))
2810 Asm = GCCAsm->getAsmString();
2814 auto StrTy = llvm::ConstantDataArray::getString(Ctx,
Asm);
2815 auto FnTy = llvm::FunctionType::get(llvm::Type::getVoidTy(Ctx),
2816 {StrTy->getType()},
false);
2817 auto UBF = CGF->
CGM.
getModule().getOrInsertFunction(Name, FnTy);
2819 CGF->
Builder.CreateCall(UBF, {StrTy});
2834 bool IsValidTargetAsm =
true;
2835 for (
unsigned i = 0, e = S.
getNumOutputs(); i != e && IsValidTargetAsm; i++) {
2837 if (
const GCCAsmStmt *GAS = dyn_cast<GCCAsmStmt>(&S))
2838 Name = GAS->getOutputName(i);
2841 if (IsHipStdPar && !IsValid)
2842 IsValidTargetAsm =
false;
2844 assert(IsValid &&
"Failed to parse output constraint");
2845 OutputConstraintInfos.push_back(Info);
2848 for (
unsigned i = 0, e = S.
getNumInputs(); i != e && IsValidTargetAsm; i++) {
2850 if (
const GCCAsmStmt *GAS = dyn_cast<GCCAsmStmt>(&S))
2851 Name = GAS->getInputName(i);
2855 if (IsHipStdPar && !IsValid)
2856 IsValidTargetAsm =
false;
2858 assert(IsValid &&
"Failed to parse input constraint");
2859 InputConstraintInfos.push_back(Info);
2862 if (!IsValidTargetAsm)
2865 std::string Constraints;
2867 std::vector<LValue> ResultRegDests;
2868 std::vector<QualType> ResultRegQualTys;
2869 std::vector<llvm::Type *> ResultRegTypes;
2870 std::vector<llvm::Type *> ResultTruncRegTypes;
2871 std::vector<llvm::Type *> ArgTypes;
2872 std::vector<llvm::Type *> ArgElemTypes;
2873 std::vector<llvm::Value*> Args;
2874 llvm::BitVector ResultTypeRequiresCast;
2875 llvm::BitVector ResultRegIsFlagReg;
2878 std::string InOutConstraints;
2879 std::vector<llvm::Value*> InOutArgs;
2880 std::vector<llvm::Type*> InOutArgTypes;
2881 std::vector<llvm::Type*> InOutArgElemTypes;
2884 std::vector<std::string> OutputConstraints;
2887 llvm::SmallSet<std::string, 8> PhysRegOutputs;
2895 bool ReadOnly =
true, ReadNone =
true;
2914 if (!GCCReg.empty() && !PhysRegOutputs.insert(GCCReg).second)
2915 CGM.Error(S.
getAsmLoc(),
"multiple outputs to hard register: " + GCCReg);
2917 OutputConstraints.push_back(OutputConstraint);
2919 if (!Constraints.empty())
2929 Constraints +=
"=" + OutputConstraint;
2930 ResultRegQualTys.push_back(QTy);
2931 ResultRegDests.push_back(Dest);
2933 bool IsFlagReg = llvm::StringRef(OutputConstraint).starts_with(
"{@cc");
2934 ResultRegIsFlagReg.push_back(IsFlagReg);
2939 Ty->isAggregateType());
2941 ResultTruncRegTypes.push_back(Ty);
2942 ResultTypeRequiresCast.push_back(RequiresCast);
2949 CGM.Error(OutExpr->
getExprLoc(),
"output size should not be zero");
2951 ResultRegTypes.push_back(Ty);
2957 for (InputNo = 0; InputNo != S.
getNumInputs(); ++InputNo) {
2962 assert(InputNo != S.
getNumInputs() &&
"Didn't find matching input!");
2973 if (llvm::Type* AdjTy =
2975 ResultRegTypes.back()))
2976 ResultRegTypes.back() = AdjTy;
2979 diag::err_asm_invalid_type_in_input)
2980 << OutExpr->
getType() << OutputConstraint;
2984 if (
auto *VT = dyn_cast<llvm::VectorType>(ResultRegTypes.back()))
2985 LargestVectorWidth =
2986 std::max((uint64_t)LargestVectorWidth,
2987 VT->getPrimitiveSizeInBits().getKnownMinValue());
2998 ArgTypes.push_back(DestAddr.
getType());
3001 Constraints +=
"=*";
3002 Constraints += OutputConstraint;
3003 ReadOnly = ReadNone =
false;
3007 InOutConstraints +=
',';
3011 llvm::Type *ArgElemType;
3012 std::tie(Arg, ArgElemType) = EmitAsmInputLValue(
3013 Info, Dest, InputExpr->
getType(), InOutConstraints,
3016 if (llvm::Type* AdjTy =
3019 Arg =
Builder.CreateBitCast(Arg, AdjTy);
3022 if (
auto *VT = dyn_cast<llvm::VectorType>(Arg->getType()))
3023 LargestVectorWidth =
3024 std::max((uint64_t)LargestVectorWidth,
3025 VT->getPrimitiveSizeInBits().getKnownMinValue());
3028 InOutConstraints += llvm::utostr(i);
3030 InOutConstraints += OutputConstraint;
3032 InOutArgTypes.push_back(Arg->getType());
3033 InOutArgElemTypes.push_back(ArgElemType);
3034 InOutArgs.push_back(Arg);
3045 CGM.getTargetCodeGenInfo().addReturnRegisterOutputs(
3046 *
this, ReturnSlot, Constraints, ResultRegTypes, ResultTruncRegTypes,
3052 for (
unsigned i = 0, e = S.
getNumInputs(); i != e; i++) {
3060 if (!Constraints.empty())
3066 &OutputConstraintInfos);
3072 std::string ReplaceConstraint (InputConstraint);
3074 llvm::Type *ArgElemType;
3075 std::tie(Arg, ArgElemType) = EmitAsmInput(Info, InputExpr, Constraints);
3094 Arg =
Builder.CreateZExt(Arg, OutputTy);
3097 else if (OutputTy->isFloatingPointTy())
3098 Arg =
Builder.CreateFPExt(Arg, OutputTy);
3101 ReplaceConstraint = OutputConstraints[Output];
3103 if (llvm::Type* AdjTy =
3106 Arg =
Builder.CreateBitCast(Arg, AdjTy);
3108 CGM.getDiags().Report(S.
getAsmLoc(), diag::err_asm_invalid_type_in_input)
3109 << InputExpr->
getType() << InputConstraint;
3112 if (
auto *VT = dyn_cast<llvm::VectorType>(Arg->getType()))
3113 LargestVectorWidth =
3114 std::max((uint64_t)LargestVectorWidth,
3115 VT->getPrimitiveSizeInBits().getKnownMinValue());
3117 ArgTypes.push_back(Arg->getType());
3118 ArgElemTypes.push_back(ArgElemType);
3119 Args.push_back(Arg);
3120 Constraints += InputConstraint;
3124 for (
unsigned i = 0, e = InOutArgs.size(); i != e; i++) {
3125 ArgTypes.push_back(InOutArgTypes[i]);
3126 ArgElemTypes.push_back(InOutArgElemTypes[i]);
3127 Args.push_back(InOutArgs[i]);
3129 Constraints += InOutConstraints;
3133 llvm::BasicBlock *Fallthrough =
nullptr;
3134 bool IsGCCAsmGoto =
false;
3135 if (
const auto *GS = dyn_cast<GCCAsmStmt>(&S)) {
3136 IsGCCAsmGoto = GS->isAsmGoto();
3138 for (
const auto *E : GS->labels()) {
3140 Transfer.push_back(Dest.
getBlock());
3141 if (!Constraints.empty())
3143 Constraints +=
"!i";
3149 bool HasUnwindClobber =
false;
3155 if (Clobber ==
"memory")
3156 ReadOnly = ReadNone =
false;
3157 else if (Clobber ==
"unwind") {
3158 HasUnwindClobber =
true;
3160 }
else if (Clobber !=
"cc") {
3162 if (
CGM.getCodeGenOpts().StackClashProtector &&
3165 diag::warn_stack_clash_protection_inline_asm);
3170 if (Clobber ==
"eax" || Clobber ==
"edx") {
3171 if (Constraints.find(
"=&A") != std::string::npos)
3173 std::string::size_type position1 =
3174 Constraints.find(
"={" + Clobber +
"}");
3175 if (position1 != std::string::npos) {
3176 Constraints.insert(position1 + 1,
"&");
3179 std::string::size_type position2 = Constraints.find(
"=A");
3180 if (position2 != std::string::npos) {
3181 Constraints.insert(position2 + 1,
"&");
3186 if (!Constraints.empty())
3189 Constraints +=
"~{";
3190 Constraints += Clobber;
3194 assert(!(HasUnwindClobber && IsGCCAsmGoto) &&
3195 "unwind clobber can't be used with asm goto");
3199 if (!MachineClobbers.empty()) {
3200 if (!Constraints.empty())
3202 Constraints += MachineClobbers;
3205 llvm::Type *ResultType;
3206 if (ResultRegTypes.empty())
3208 else if (ResultRegTypes.size() == 1)
3209 ResultType = ResultRegTypes[0];
3211 ResultType = llvm::StructType::get(
getLLVMContext(), ResultRegTypes);
3213 llvm::FunctionType *FTy =
3214 llvm::FunctionType::get(ResultType, ArgTypes,
false);
3218 llvm::InlineAsm::AsmDialect GnuAsmDialect =
3220 ? llvm::InlineAsm::AD_ATT
3221 : llvm::InlineAsm::AD_Intel;
3223 llvm::InlineAsm::AD_Intel : GnuAsmDialect;
3225 llvm::InlineAsm *IA = llvm::InlineAsm::get(
3226 FTy, AsmString, Constraints, HasSideEffect,
3227 false, AsmDialect, HasUnwindClobber);
3228 std::vector<llvm::Value*> RegResults;
3229 llvm::CallBrInst *CBR;
3230 llvm::DenseMap<llvm::BasicBlock *, SmallVector<llvm::Value *, 4>>
3233 CBR =
Builder.CreateCallBr(IA, Fallthrough, Transfer, Args);
3238 ArgElemTypes, *
this, RegResults);
3242 if (!RegResults.empty()) {
3244 for (llvm::BasicBlock *Dest : CBR->getIndirectDests()) {
3245 llvm::Twine SynthName = Dest->getName() +
".split";
3247 llvm::IRBuilderBase::InsertPointGuard IPG(
Builder);
3248 Builder.SetInsertPoint(SynthBB);
3250 if (ResultRegTypes.size() == 1) {
3251 CBRRegResults[SynthBB].push_back(CBR);
3253 for (
unsigned j = 0, e = ResultRegTypes.size(); j != e; ++j) {
3254 llvm::Value *Tmp =
Builder.CreateExtractValue(CBR, j,
"asmresult");
3255 CBRRegResults[SynthBB].push_back(Tmp);
3261 CBR->setIndirectDest(i++, SynthBB);
3264 }
else if (HasUnwindClobber) {
3269 ArgElemTypes, *
this, RegResults);
3276 ArgElemTypes, *
this, RegResults);
3279 EmitAsmStores(*
this, S, RegResults, ResultRegTypes, ResultTruncRegTypes,
3280 ResultRegDests, ResultRegQualTys, ResultTypeRequiresCast,
3281 ResultRegIsFlagReg);
3286 if (IsGCCAsmGoto && !CBRRegResults.empty()) {
3287 for (llvm::BasicBlock *Succ : CBR->getIndirectDests()) {
3288 llvm::IRBuilderBase::InsertPointGuard IPG(
Builder);
3289 Builder.SetInsertPoint(Succ, --(Succ->end()));
3290 EmitAsmStores(*
this, S, CBRRegResults[Succ], ResultRegTypes,
3291 ResultTruncRegTypes, ResultRegDests, ResultRegQualTys,
3292 ResultTypeRequiresCast, ResultRegIsFlagReg);
3308 I != E; ++I, ++CurField) {
3310 if (CurField->hasCapturedVLAType()) {
3327 CodeGenFunction CGF(
CGM,
true);
3347 "CapturedStmtInfo should be set when generating the captured function");
3351 assert(CD->
hasBody() &&
"missing CapturedDecl body");
3360 CGM.getTypes().arrangeBuiltinFunctionDeclaration(Ctx.
VoidTy, Args);
3361 llvm::FunctionType *FuncLLVMTy =
CGM.getTypes().GetFunctionType(FuncInfo);
3364 llvm::Function::Create(FuncLLVMTy, llvm::GlobalValue::InternalLinkage,
3366 CGM.SetInternalFunctionAttributes(CD, F, FuncInfo);
3368 F->addFnAttr(llvm::Attribute::NoUnwind);
3380 for (
auto *FD : RD->
fields()) {
3381 if (FD->hasCapturedVLAType()) {
3385 auto VAT = FD->getCapturedVLAType();
3386 VLASizeMap[VAT->getSizeExpr()] = ExprArg;
3397 PGO->assignRegionCounters(
GlobalDecl(CD), F);
3407 for (
auto &I : *BB) {
3408 if (
auto *CI = dyn_cast<llvm::ConvergenceControlInst>(&I))
3415CodeGenFunction::addConvergenceControlToken(llvm::CallBase *Input) {
3417 assert(ParentToken);
3419 llvm::Value *bundleArgs[] = {ParentToken};
3420 llvm::OperandBundleDef OB(
"convergencectrl", bundleArgs);
3421 auto *Output = llvm::CallBase::addOperandBundle(
3422 Input, llvm::LLVMContext::OB_convergencectrl, OB, Input->getIterator());
3423 Input->replaceAllUsesWith(Output);
3424 Input->eraseFromParent();
3428llvm::ConvergenceControlInst *
3429CodeGenFunction::emitConvergenceLoopToken(llvm::BasicBlock *BB) {
3431 assert(ParentToken);
3432 return llvm::ConvergenceControlInst::CreateLoop(*BB, ParentToken);
3435llvm::ConvergenceControlInst *
3436CodeGenFunction::getOrEmitConvergenceEntryToken(llvm::Function *F) {
3437 llvm::BasicBlock *BB = &F->getEntryBlock();
3445 return llvm::ConvergenceControlInst::CreateEntry(*BB);
Defines enum values for all the target-independent builtin functions.
static std::string AddVariableConstraints(const std::string &Constraint, const Expr &AsmExpr, const TargetInfo &Target, CodeGenModule &CGM, const AsmStmt &Stmt, const bool EarlyClobber, std::string *GCCReg=nullptr)
AddVariableConstraints - Look at AsmExpr and if it is a variable declared as using a particular regis...
static bool FindCaseStatementsForValue(const SwitchStmt &S, const llvm::APSInt &ConstantCondValue, SmallVectorImpl< const Stmt * > &ResultStmts, ASTContext &C, const SwitchCase *&ResultCase)
FindCaseStatementsForValue - Find the case statement being jumped to and then invoke CollectStatement...
static llvm::ConvergenceControlInst * getConvergenceToken(llvm::BasicBlock *BB)
static void EmitHipStdParUnsupportedAsm(CodeGenFunction *CGF, const AsmStmt &S)
static std::optional< SmallVector< uint64_t, 16 > > getLikelihoodWeights(ArrayRef< Stmt::Likelihood > Likelihoods)
static llvm::MDNode * getAsmSrcLocInfo(const StringLiteral *Str, CodeGenFunction &CGF)
getAsmSrcLocInfo - Return the !srcloc metadata node to attach to an inline asm call instruction.
static std::string SimplifyConstraint(const char *Constraint, const TargetInfo &Target, SmallVectorImpl< TargetInfo::ConstraintInfo > *OutCons=nullptr)
static bool isSwiftAsyncCallee(const CallExpr *CE)
Determine if the given call uses the swiftasync calling convention.
static CSFC_Result CollectStatementsForCase(const Stmt *S, const SwitchCase *Case, bool &FoundCase, SmallVectorImpl< const Stmt * > &ResultStmts)
static void EmitAsmStores(CodeGenFunction &CGF, const AsmStmt &S, const llvm::ArrayRef< llvm::Value * > RegResults, const llvm::ArrayRef< llvm::Type * > ResultRegTypes, const llvm::ArrayRef< llvm::Type * > ResultTruncRegTypes, const llvm::ArrayRef< LValue > ResultRegDests, const llvm::ArrayRef< QualType > ResultRegQualTys, const llvm::BitVector &ResultTypeRequiresCast, const llvm::BitVector &ResultRegIsFlagReg)
static bool hasEmptyLoopBody(const LoopStmt &S)
CSFC_Result
CollectStatementsForCase - Given the body of a 'switch' statement and a constant value that is being ...
static void UpdateAsmCallInst(llvm::CallBase &Result, bool HasSideEffect, bool HasUnwindClobber, bool ReadOnly, bool ReadNone, bool NoMerge, bool NoConvergent, const AsmStmt &S, const std::vector< llvm::Type * > &ResultRegTypes, const std::vector< llvm::Type * > &ArgElemTypes, CodeGenFunction &CGF, std::vector< llvm::Value * > &RegResults)
llvm::MachO::Target Target
Defines the PrettyStackTraceEntry class, which is used to make crashes give more contextual informati...
Defines the SourceManager interface.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
bool toIntegralConstant(APSInt &Result, QualType SrcTy, const ASTContext &Ctx) const
Try to convert this value to an integral constant.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
QualType getIntTypeForBitwidth(unsigned DestWidth, unsigned Signed) const
getIntTypeForBitwidth - sets integer QualTy according to specified details: bitwidth,...
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
CanQualType getCanonicalTagType(const TagDecl *TD) const
AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
std::string getInputConstraint(unsigned i) const
getInputConstraint - Return the specified input constraint.
std::string getOutputConstraint(unsigned i) const
getOutputConstraint - Return the constraint string for the specified output operand.
SourceLocation getAsmLoc() const
const Expr * getInputExpr(unsigned i) const
unsigned getNumClobbers() const
const Expr * getOutputExpr(unsigned i) const
unsigned getNumOutputs() const
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
unsigned getNumInputs() const
std::string getClobber(unsigned i) const
Attr - This represents one attribute.
Represents an attribute applied to a statement.
ArrayRef< const Attr * > getAttrs() const
BreakStmt - This represents a break.
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
DeclStmt * getBeginStmt()
DeclStmt * getLoopVarStmt()
DeclStmt * getRangeStmt()
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Represents the body of a CapturedStmt, and serves as its DeclContext.
ImplicitParamDecl * getContextParam() const
Retrieve the parameter containing captured variables.
param_iterator param_end() const
Retrieve an iterator one past the last parameter decl.
param_iterator param_begin() const
Retrieve an iterator pointing to the first parameter decl.
Stmt * getBody() const override
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
This captures a statement into a function.
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
const RecordDecl * getCapturedRecordDecl() const
Retrieve the record declaration for captured variables.
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument.
SourceLocation getBeginLoc() const LLVM_READONLY
capture_init_iterator capture_init_end()
Retrieve the iterator pointing one past the last initialization argument.
Expr *const * const_capture_init_iterator
Const iterator that walks over the capture initialization arguments.
CapturedRegionKind getCapturedRegionKind() const
Retrieve the captured region kind.
CaseStmt - Represent a case statement.
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
@ Indirect
Indirect - Pass the argument indirectly via a hidden pointer with the specified alignment (0 indicate...
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
llvm::Type * getElementType() const
Return the type of the values stored in this address.
Address withElementType(llvm::Type *ElemTy) const
Return address with different element type, but same pointer and alignment.
llvm::PointerType * getType() const
Return the type of the pointer value.
static AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
forAddr - Make a slot for an aggregate value.
A scoped helper to set the current source atom group for CGDebugInfo::addInstToCurrentSourceAtom.
A scoped helper to set the current debug location to the specified location or preferred location of ...
static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF)
Set the IRBuilder to not attach debug locations.
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
CGFunctionInfo - Class to encapsulate the information about a function definition.
API for captured statement code generation.
RAII for correct setting/restoring of CapturedStmtInfo.
void rescopeLabels()
Change the cleanup scope of the labels in this lexical scope to match the scope of the enclosing cont...
void ForceCleanup()
Force the emission of cleanups now, instead of waiting until this object is destroyed.
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited.
void ForceCleanup(std::initializer_list< llvm::Value ** > ValuesToReload={})
Force the emission of cleanups now, instead of waiting until this object is destroyed.
bool requiresCleanups() const
Determine whether this scope requires any cleanups.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
void EmitOMPParallelMaskedTaskLoopDirective(const OMPParallelMaskedTaskLoopDirective &S)
void EmitOMPParallelMaskedDirective(const OMPParallelMaskedDirective &S)
void EmitOMPTaskyieldDirective(const OMPTaskyieldDirective &S)
void EmitCXXTryStmt(const CXXTryStmt &S)
void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, llvm::BasicBlock *FalseBlock, uint64_t TrueCount, Stmt::Likelihood LH=Stmt::LH_None, const Expr *ConditionalOp=nullptr, const VarDecl *ConditionalDecl=nullptr)
EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g.
void EmitSehCppScopeBegin()
JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target)
The given basic block lies in the current EH scope, but may be a target of a potentially scope-crossi...
llvm::DenseMap< const VarDecl *, llvm::Value * > NRVOFlags
A mapping from NRVO variables to the flags used to indicate when the NRVO has been applied to this va...
bool IsOutlinedSEHHelper
True if the current function is an outlined SEH helper.
void EmitOMPCanonicalLoop(const OMPCanonicalLoop *S)
Emit an OMPCanonicalLoop using the OpenMPIRBuilder.
static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts=false)
ContainsLabel - Return true if the statement contains a label in it.
void EmitCXXForRangeStmt(const CXXForRangeStmt &S, ArrayRef< const Attr * > Attrs={})
void EmitOMPGenericLoopDirective(const OMPGenericLoopDirective &S)
void EmitOMPScanDirective(const OMPScanDirective &S)
void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit)
EmitComplexExprIntoLValue - Emit the given expression of complex type and place its result into the s...
static bool hasScalarEvaluationKind(QualType T)
llvm::Type * ConvertType(QualType T)
void EmitOpenACCExitDataConstruct(const OpenACCExitDataConstruct &S)
LValue InitCapturedStruct(const CapturedStmt &S)
void addInstToNewSourceAtom(llvm::Instruction *KeyInstruction, llvm::Value *Backup)
Add KeyInstruction and an optional Backup instruction to a new atom group (See ApplyAtomGroup for mor...
CGCapturedStmtInfo * CapturedStmtInfo
void EmitOMPDistributeDirective(const OMPDistributeDirective &S)
void EmitOMPParallelForDirective(const OMPParallelForDirective &S)
llvm::CallBase * EmitCallOrInvoke(llvm::FunctionCallee Callee, ArrayRef< llvm::Value * > Args, const Twine &Name="")
Emits a call or invoke instruction to the given function, depending on the current state of the EH st...
void EmitOMPMasterDirective(const OMPMasterDirective &S)
void EmitOMPParallelMasterTaskLoopSimdDirective(const OMPParallelMasterTaskLoopSimdDirective &S)
void EmitOpenACCInitConstruct(const OpenACCInitConstruct &S)
void EmitOMPFlushDirective(const OMPFlushDirective &S)
void EmitOMPTaskgroupDirective(const OMPTaskgroupDirective &S)
JumpDest getJumpDestForLabel(const LabelDecl *S)
getBasicBlockForLabel - Return the LLVM basicblock that the specified label maps to.
void EmitCoreturnStmt(const CoreturnStmt &S)
void EmitOMPTargetTeamsDistributeParallelForSimdDirective(const OMPTargetTeamsDistributeParallelForSimdDirective &S)
SmallVector< llvm::ConvergenceControlInst *, 4 > ConvergenceTokenStack
Stack to track the controlled convergence tokens.
void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S)
void EmitOMPDistributeSimdDirective(const OMPDistributeSimdDirective &S)
llvm::Constant * EmitCheckSourceLocation(SourceLocation Loc)
Emit a description of a source location in a format suitable for passing to a runtime sanitizer handl...
bool EmitSimpleStmt(const Stmt *S, ArrayRef< const Attr * > Attrs)
EmitSimpleStmt - Try to emit a "simple" statement which does not necessarily require an insertion poi...
void EmitOMPTaskwaitDirective(const OMPTaskwaitDirective &S)
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
void EmitOMPTargetParallelForDirective(const OMPTargetParallelForDirective &S)
void addInstToCurrentSourceAtom(llvm::Instruction *KeyInstruction, llvm::Value *Backup)
See CGDebugInfo::addInstToCurrentSourceAtom.
const LangOptions & getLangOpts() const
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
void EmitOpenACCShutdownConstruct(const OpenACCShutdownConstruct &S)
bool InNoConvergentAttributedStmt
True if the current statement has noconvergent attribute.
void EmitOpenACCWaitConstruct(const OpenACCWaitConstruct &S)
void EmitBlockAfterUses(llvm::BasicBlock *BB)
EmitBlockAfterUses - Emit the given block somewhere hopefully near its uses, and leave the insertion ...
void SimplifyForwardingBlocks(llvm::BasicBlock *BB)
SimplifyForwardingBlocks - If the given basic block is only a branch to another basic block,...
void EmitBranchThroughCleanup(JumpDest Dest)
EmitBranchThroughCleanup - Emit a branch from the current insert block through the normal cleanup han...
bool InNoMergeAttributedStmt
True if the current statement has nomerge attribute.
void EmitOMPScopeDirective(const OMPScopeDirective &S)
LValue MakeAddrLValueWithoutTBAA(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
JumpDest ReturnBlock
ReturnBlock - Unified return block.
void EmitOMPTargetTeamsDistributeSimdDirective(const OMPTargetTeamsDistributeSimdDirective &S)
llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Location)
Converts Location to a DebugLoc, if debug information is enabled.
void EmitOMPInterchangeDirective(const OMPInterchangeDirective &S)
void EmitAggregateCopy(LValue Dest, LValue Src, QualType EltTy, AggValueSlot::Overlap_t MayOverlap, bool isVolatile=false)
EmitAggregateCopy - Emit an aggregate copy.
LValue EmitLValueForField(LValue Base, const FieldDecl *Field, bool IsInBounds=true)
const TargetInfo & getTarget() const
Address EmitCompoundStmtWithoutScope(const CompoundStmt &S, bool GetLast=false, AggValueSlot AVS=AggValueSlot::ignored())
void EmitGotoStmt(const GotoStmt &S)
void EmitOMPDepobjDirective(const OMPDepobjDirective &S)
void EmitOMPMetaDirective(const OMPMetaDirective &S)
void EmitOMPCriticalDirective(const OMPCriticalDirective &S)
void EmitIgnoredExpr(const Expr *E)
EmitIgnoredExpr - Emit an expression in a context which ignores the result.
void EmitOMPTaskLoopDirective(const OMPTaskLoopDirective &S)
RValue EmitLoadOfLValue(LValue V, SourceLocation Loc)
EmitLoadOfLValue - Given an expression that represents a value lvalue, this method emits the address ...
void EmitOMPCancelDirective(const OMPCancelDirective &S)
const Expr * RetExpr
If a return statement is being visited, this holds the return statment's result expression.
void EmitOMPBarrierDirective(const OMPBarrierDirective &S)
void EmitOMPOrderedDirective(const OMPOrderedDirective &S)
void EmitForStmt(const ForStmt &S, ArrayRef< const Attr * > Attrs={})
void EmitOMPSectionsDirective(const OMPSectionsDirective &S)
void EmitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt &S)
void StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn, const CGFunctionInfo &FnInfo, const FunctionArgList &Args, SourceLocation Loc=SourceLocation(), SourceLocation StartLoc=SourceLocation())
Emit code for the start of a function.
void EmitOMPInteropDirective(const OMPInteropDirective &S)
void EmitOMPParallelSectionsDirective(const OMPParallelSectionsDirective &S)
void EmitOMPTargetParallelDirective(const OMPTargetParallelDirective &S)
llvm::Value * EvaluateExprAsBool(const Expr *E)
EvaluateExprAsBool - Perform the usual unary conversions on the specified expression and compare the ...
void EmitWhileStmt(const WhileStmt &S, ArrayRef< const Attr * > Attrs={})
void EmitOMPTargetParallelForSimdDirective(const OMPTargetParallelForSimdDirective &S)
void EmitOMPTargetParallelGenericLoopDirective(const OMPTargetParallelGenericLoopDirective &S)
Emit combined directive 'target parallel loop' as if its constituent constructs are 'target',...
void EmitOpenACCCombinedConstruct(const OpenACCCombinedConstruct &S)
void ResolveBranchFixups(llvm::BasicBlock *Target)
void EmitOMPTeamsDistributeParallelForSimdDirective(const OMPTeamsDistributeParallelForSimdDirective &S)
void EmitOMPMaskedDirective(const OMPMaskedDirective &S)
bool checkIfLoopMustProgress(const Expr *, bool HasEmptyBody)
Returns true if a loop must make progress, which means the mustprogress attribute can be added.
bool HaveInsertPoint() const
HaveInsertPoint - True if an insertion point is defined.
void EmitOMPTeamsDistributeSimdDirective(const OMPTeamsDistributeSimdDirective &S)
CGDebugInfo * getDebugInfo()
void EmitOMPMasterTaskLoopDirective(const OMPMasterTaskLoopDirective &S)
void EmitOMPReverseDirective(const OMPReverseDirective &S)
llvm::Value * getTypeSize(QualType Ty)
Returns calculated size of the specified type.
void EmitOMPCancellationPointDirective(const OMPCancellationPointDirective &S)
void EmitOpenACCDataConstruct(const OpenACCDataConstruct &S)
LValue EmitLValueForFieldInitialization(LValue Base, const FieldDecl *Field)
EmitLValueForFieldInitialization - Like EmitLValueForField, except that if the Field is a reference,...
void EmitOMPTargetTeamsDistributeParallelForDirective(const OMPTargetTeamsDistributeParallelForDirective &S)
void EmitOMPMaskedTaskLoopDirective(const OMPMaskedTaskLoopDirective &S)
void EmitObjCAtTryStmt(const ObjCAtTryStmt &S)
const TargetCodeGenInfo & getTargetHooks() const
void EmitOMPTargetExitDataDirective(const OMPTargetExitDataDirective &S)
void EmitSEHLeaveStmt(const SEHLeaveStmt &S)
void incrementProfileCounter(const Stmt *S, llvm::Value *StepV=nullptr)
Increment the profiler's counter for the given statement by StepV.
void EmitOMPTargetEnterDataDirective(const OMPTargetEnterDataDirective &S)
bool InNoInlineAttributedStmt
True if the current statement has noinline attribute.
SmallVector< llvm::OperandBundleDef, 1 > getBundlesForFunclet(llvm::Value *Callee)
void EmitOMPMaskedTaskLoopSimdDirective(const OMPMaskedTaskLoopSimdDirective &S)
void EmitCoroutineBody(const CoroutineBodyStmt &S)
void EmitOMPParallelDirective(const OMPParallelDirective &S)
void EmitOMPTaskDirective(const OMPTaskDirective &S)
void EmitOMPMasterTaskLoopSimdDirective(const OMPMasterTaskLoopSimdDirective &S)
void EmitOMPDistributeParallelForDirective(const OMPDistributeParallelForDirective &S)
void EmitOMPAssumeDirective(const OMPAssumeDirective &S)
void EmitOMPTeamsDistributeDirective(const OMPTeamsDistributeDirective &S)
ASTContext & getContext() const
void EmitStopPoint(const Stmt *S)
EmitStopPoint - Emit a debug stoppoint if we are emitting debug info.
void EmitOMPTargetUpdateDirective(const OMPTargetUpdateDirective &S)
void EmitOMPTargetTeamsGenericLoopDirective(const OMPTargetTeamsGenericLoopDirective &S)
void EmitIfStmt(const IfStmt &S)
void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
EmitStoreThroughLValue - Store the specified rvalue into the specified lvalue, where both are guarant...
void EmitOpenACCAtomicConstruct(const OpenACCAtomicConstruct &S)
void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S)
Address EmitCompoundStmt(const CompoundStmt &S, bool GetLast=false, AggValueSlot AVS=AggValueSlot::ignored())
EmitCompoundStmt - Emit a compound statement {..} node.
void EmitOpenACCCacheConstruct(const OpenACCCacheConstruct &S)
void EmitOpenACCLoopConstruct(const OpenACCLoopConstruct &S)
void EmitOMPTeamsDistributeParallelForDirective(const OMPTeamsDistributeParallelForDirective &S)
void EmitInitializerForField(FieldDecl *Field, LValue LHS, Expr *Init)
void EmitAsmStmt(const AsmStmt &S)
void EmitDefaultStmt(const DefaultStmt &S, ArrayRef< const Attr * > Attrs)
void EmitOMPTargetTeamsDistributeDirective(const OMPTargetTeamsDistributeDirective &S)
void EmitSwitchStmt(const SwitchStmt &S)
static bool mightAddDeclToScope(const Stmt *S)
Determine if the given statement might introduce a declaration into the current scope,...
void EmitAnyExprToMem(const Expr *E, Address Location, Qualifiers Quals, bool IsInitializer)
EmitAnyExprToMem - Emits the code necessary to evaluate an arbitrary expression into the given memory...
RValue EmitAnyExpr(const Expr *E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
EmitAnyExpr - Emit code to compute the specified expression which can have any type.
void EmitStmt(const Stmt *S, ArrayRef< const Attr * > Attrs={})
EmitStmt - Emit the code for the statement.
void EmitOMPParallelForSimdDirective(const OMPParallelForSimdDirective &S)
uint64_t getCurrentProfileCount()
Get the profiler's current count.
llvm::Type * ConvertTypeForMem(QualType T)
void EmitOMPTaskLoopSimdDirective(const OMPTaskLoopSimdDirective &S)
void EmitOMPTargetDirective(const OMPTargetDirective &S)
void EmitOpenACCEnterDataConstruct(const OpenACCEnterDataConstruct &S)
llvm::Function * EmitCapturedStmt(const CapturedStmt &S, CapturedRegionKind K)
Generate an outlined function for the body of a CapturedStmt, store any captured variables into the c...
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
void EmitOMPTeamsDirective(const OMPTeamsDirective &S)
static bool containsBreak(const Stmt *S)
containsBreak - Return true if the statement contains a break out of it.
void EmitSimpleOMPExecutableDirective(const OMPExecutableDirective &D)
Emit simple code for OpenMP directives in Simd-only mode.
HLSLControlFlowHintAttr::Spelling HLSLControlFlowAttr
HLSL Branch attribute.
bool InAlwaysInlineAttributedStmt
True if the current statement has always_inline attribute.
void EmitCaseStmt(const CaseStmt &S, ArrayRef< const Attr * > Attrs)
void EmitOMPErrorDirective(const OMPErrorDirective &S)
void EmitBreakStmt(const BreakStmt &S)
void EmitOMPParallelMaskedTaskLoopSimdDirective(const OMPParallelMaskedTaskLoopSimdDirective &S)
void EmitOMPTargetTeamsDirective(const OMPTargetTeamsDirective &S)
void EmitOpenACCComputeConstruct(const OpenACCComputeConstruct &S)
void EmitDoStmt(const DoStmt &S, ArrayRef< const Attr * > Attrs={})
void EmitOMPTargetDataDirective(const OMPTargetDataDirective &S)
const TargetInfo & Target
Address GenerateCapturedStmtArgument(const CapturedStmt &S)
void EmitBranch(llvm::BasicBlock *Block)
EmitBranch - Emit a branch to the specified basic block from the current insert block,...
void EmitOMPSimdDirective(const OMPSimdDirective &S)
RawAddress CreateMemTemp(QualType T, const Twine &Name="tmp", RawAddress *Alloca=nullptr)
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen and cas...
void EmitOMPParallelGenericLoopDirective(const OMPLoopDirective &S)
void EmitOMPTargetSimdDirective(const OMPTargetSimdDirective &S)
void EmitOMPTeamsGenericLoopDirective(const OMPTeamsGenericLoopDirective &S)
unsigned NextCleanupDestIndex
AggValueSlot::Overlap_t getOverlapForReturnValue()
Determine whether a return value slot may overlap some other object.
const BreakContinue * GetDestForLoopControlStmt(const LoopControlStmt &S)
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type.
llvm::BasicBlock * GetIndirectGotoBlock()
void EmitOpenACCHostDataConstruct(const OpenACCHostDataConstruct &S)
void EmitOpenACCUpdateConstruct(const OpenACCUpdateConstruct &S)
void EmitOMPUnrollDirective(const OMPUnrollDirective &S)
void EmitOMPStripeDirective(const OMPStripeDirective &S)
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type,...
static bool hasAggregateEvaluationKind(QualType T)
void EmitCaseStmtRange(const CaseStmt &S, ArrayRef< const Attr * > Attrs)
EmitCaseStmtRange - If case statement range is not too big then add multiple cases to switch instruct...
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
void EmitOMPSingleDirective(const OMPSingleDirective &S)
void EmitReturnStmt(const ReturnStmt &S)
EmitReturnStmt - Note that due to GCC extensions, this can have an operand if the function returns vo...
void EmitLambdaVLACapture(const VariableArrayType *VAT, LValue LV)
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
llvm::Value * EmitCheckedArgForAssume(const Expr *E)
Emits an argument for a call to a __builtin_assume.
llvm::Function * GenerateCapturedStmtFunction(const CapturedStmt &S)
Creates the outlined function for a CapturedStmt.
const CallExpr * MustTailCall
const CGFunctionInfo * CurFnInfo
uint64_t getProfileCount(const Stmt *S)
Get the profiler's count for the given statement.
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
void EmitDeclStmt(const DeclStmt &S)
void EmitLabelStmt(const LabelStmt &S)
bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result, bool AllowLabels=false)
ConstantFoldsToSimpleInteger - If the specified expression does not fold to a constant,...
void EmitOMPTileDirective(const OMPTileDirective &S)
void EmitDecl(const Decl &D, bool EvaluateConditionDecl=false)
EmitDecl - Emit a declaration.
void EmitOMPAtomicDirective(const OMPAtomicDirective &S)
void EmitOpenACCSetConstruct(const OpenACCSetConstruct &S)
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
LValue EmitLValue(const Expr *E, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
EmitLValue - Emit code to compute a designator that specifies the location of the expression.
void EmitAttributedStmt(const AttributedStmt &S)
void EmitOMPParallelMasterTaskLoopDirective(const OMPParallelMasterTaskLoopDirective &S)
void EmitOMPDistributeParallelForSimdDirective(const OMPDistributeParallelForSimdDirective &S)
void EmitOMPSectionDirective(const OMPSectionDirective &S)
void EnsureInsertPoint()
EnsureInsertPoint - Ensure that an insertion point is defined so that emitted IR has a place to go.
void EmitOMPForSimdDirective(const OMPForSimdDirective &S)
llvm::LLVMContext & getLLVMContext()
bool SawAsmBlock
Whether we processed a Microsoft-style asm block during CodeGen.
void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S)
void EmitIndirectGotoStmt(const IndirectGotoStmt &S)
void MaybeEmitDeferredVarDeclInit(const VarDecl *var)
bool isObviouslyBranchWithoutCleanups(JumpDest Dest) const
isObviouslyBranchWithoutCleanups - Return true if a branch to the specified destination obviously has...
void EmitSEHTryStmt(const SEHTryStmt &S)
void EmitOMPParallelMasterDirective(const OMPParallelMasterDirective &S)
void EmitBlockWithFallThrough(llvm::BasicBlock *BB, const Stmt *S)
When instrumenting to collect profile data, the counts for some blocks such as switch cases need to n...
void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, QualType Ty, AlignmentSource Source=AlignmentSource::Type, bool isInit=false, bool isNontemporal=false)
EmitStoreOfScalar - Store a scalar value to an address, taking care to appropriately convert from the...
void EmitOMPForDirective(const OMPForDirective &S)
void EmitLabel(const LabelDecl *D)
EmitLabel - Emit the block for the given label.
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
LValue MakeNaturalAlignRawAddrLValue(llvm::Value *V, QualType T)
void EmitContinueStmt(const ContinueStmt &S)
This class organizes the cross-function state that is used while generating LLVM code.
llvm::Module & getModule() const
DiagnosticsEngine & getDiags() const
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
const LangOptions & getLangOpts() const
const llvm::DataLayout & getDataLayout() const
ASTContext & getContext() const
llvm::LLVMContext & getLLVMContext()
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys={})
A saved depth on the scope stack.
bool encloses(stable_iterator I) const
Returns true if this scope encloses I.
static stable_iterator invalid()
static stable_iterator stable_end()
Create a stable reference to the bottom of the EH stack.
FunctionArgList - Type for representing both the decl and type of parameters to a function.
LValue - This represents an lvalue references.
llvm::Value * getPointer(CodeGenFunction &CGF) const
Address getAddress() const
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
static RValue get(llvm::Value *V)
Address getAggregateAddress() const
getAggregateAddr() - Return the Value* of the address of the aggregate.
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
std::pair< llvm::Value *, llvm::Value * > getComplexVal() const
getComplexVal - Return the real/imag components of this complex value.
virtual bool isScalarizableAsmOperand(CodeGen::CodeGenFunction &CGF, llvm::Type *Ty) const
Target hook to decide whether an inline asm operand can be passed by value.
CompoundStmt - This represents a group of statements like { stmt stmt }.
Stmt *const * const_body_iterator
SourceLocation getLBracLoc() const
Stmt * getStmtExprResult()
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
ContinueStmt - This represents a continue.
A reference to a declared variable, function, enum, etc.
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
SourceLocation getBodyRBrace() const
getBodyRBrace - Gets the right brace of the body, if a body exists.
virtual bool hasBody() const
Returns true if this Decl represents a declaration for a body of code, such as a function or method d...
SourceLocation getLocation() const
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
DoStmt - This represents a 'do/while' stmt.
This represents one expression.
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer,...
Expr * IgnoreParenNoopCasts(const ASTContext &Ctx) LLVM_READONLY
Skip past any parentheses and casts which do not change the value (including ptr->int casts of the sa...
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.
bool isEvaluatable(const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects) const
isEvaluatable - Call EvaluateAsRValue to see if this expression can be constant folded without side-e...
bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsRValue - Return true if this is a constant which we can fold to an rvalue using any crazy t...
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Represents a member of a struct/union/class.
ForStmt - This represents a 'for (init;cond;inc)' stmt.
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
const Expr * getSubExpr() const
FunctionType - C99 6.7.5.3 - Function Declarators.
CallingConv getCallConv() const
This represents a GCC inline-assembly statement extension.
GlobalDecl - represents a global declaration.
GotoStmt - This represents a direct goto.
LabelDecl * getLabel() const
IfStmt - This represents an if/then/else.
bool isNegatedConsteval() const
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
IndirectGotoStmt - This represents an indirect goto.
LabelDecl * getConstantTarget()
getConstantTarget - Returns the fixed target of this indirect goto, if one exists.
Represents the declaration of a label.
LabelStmt * getStmt() const
LabelStmt - Represents a label, which has a substatement.
LabelDecl * getDecl() const
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool assumeFunctionsAreConvergent() const
Base class for BreakStmt and ContinueStmt.
Represents a point when we exit a loop.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
If a crash happens while one of these objects are live, the message is printed out along with the spe...
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
QualType getCanonicalType() const
The collection of all-type qualifiers we support.
Represents a struct/union/class.
field_range fields() const
specific_decl_iterator< FieldDecl > field_iterator
field_iterator field_begin() const
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
SourceLocation getBeginLoc() const
const VarDecl * getNRVOCandidate() const
Retrieve the variable that might be used for the named return value optimization.
Scope - A scope is a transient data structure that is used while parsing the program.
Encodes a location in the source.
UIntTy getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
Stmt - This represents one statement.
StmtClass getStmtClass() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Likelihood
The likelihood of a branch being taken.
@ LH_Unlikely
Branch has the [[unlikely]] attribute.
@ LH_None
No attribute set or branches of the IfStmt have the same attribute.
@ LH_Likely
Branch has the [[likely]] attribute.
static const Attr * getLikelihoodAttr(const Stmt *S)
SourceLocation getBeginLoc() const LLVM_READONLY
static Likelihood getLikelihood(ArrayRef< const Attr * > Attrs)
StringLiteral - This represents a string literal expression, e.g.
SourceLocation getBeginLoc() const LLVM_READONLY
SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM, const LangOptions &Features, const TargetInfo &Target, unsigned *StartToken=nullptr, unsigned *StartTokenByteOffset=nullptr) const
getLocationOfByte - Return a source location that points to the specified byte of this string literal...
StringRef getString() const
const SwitchCase * getNextSwitchCase() const
SwitchStmt - This represents a 'switch' stmt.
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
SwitchCase * getSwitchCaseList()
Exposes information about the current target.
bool validateInputConstraint(MutableArrayRef< ConstraintInfo > OutputConstraints, ConstraintInfo &info) const
StringRef getNormalizedGCCRegisterName(StringRef Name, bool ReturnCanonical=false) const
Returns the "normalized" GCC register name.
bool validateOutputConstraint(ConstraintInfo &Info) const
virtual std::string_view getClobbers() const =0
Returns a string of target-specific clobbers, in LLVM format.
const T * castAs() const
Member-template castAs<specific type>.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
bool isNRVOVariable() const
Determine whether this local variable can be used with the named return value optimization (NRVO).
WhileStmt - This represents a 'while' stmt.
SourceLocation getWhileLoc() const
SourceLocation getRParenLoc() const
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
bool isa(CodeGen::Address addr)
CapturedRegionKind
The different kinds of captured statement.
@ Asm
Assembly: we accept this only so that we can preprocess it.
@ Result
The result type of a method or function.
U cast(CodeGen::Address addr)
ActionResult< Expr * > ExprResult
Diagnostic wrappers for TextAPI types for error reporting.
cl::opt< bool > EnableSingleByteCoverage
A jump destination is an abstract label, branching to which may require a jump out through normal cle...
void setScopeDepth(EHScopeStack::stable_iterator depth)
llvm::BasicBlock * getBlock() const
EHScopeStack::stable_iterator getScopeDepth() const
llvm::IntegerType * Int64Ty
llvm::IntegerType * IntPtrTy
llvm::PointerType * Int8PtrTy
EvalResult is a struct with detailed info about an evaluated expression.
APValue Val
Val - This is the value the expression can be folded to.
bool hasMatchingInput() const
Return true if this output operand has a matching (tied) input operand.
unsigned getTiedOperand() const
bool allowsMemory() const
bool requiresImmediateConstant() const
bool hasTiedOperand() const
Return true if this input operand is a matching constraint that ties it to an output operand.
bool allowsRegister() const