22 #include "llvm/ADT/StringExtras.h" 23 #include "llvm/IR/DataLayout.h" 24 #include "llvm/IR/InlineAsm.h" 25 #include "llvm/IR/Intrinsics.h" 26 #include "llvm/IR/MDBuilder.h" 28 using namespace clang;
29 using namespace CodeGen;
46 assert(S &&
"Null statement?");
63 assert(!isa<DeclStmt>(*S) &&
"Unexpected DeclStmt!");
77 if (
const auto *D = dyn_cast<OMPExecutableDirective>(S)) {
85 case Stmt::CXXCatchStmtClass:
86 case Stmt::SEHExceptStmtClass:
87 case Stmt::SEHFinallyStmtClass:
88 case Stmt::MSDependentExistsStmtClass:
89 llvm_unreachable(
"invalid statement class to emit generically");
90 case Stmt::NullStmtClass:
91 case Stmt::CompoundStmtClass:
92 case Stmt::DeclStmtClass:
93 case Stmt::LabelStmtClass:
94 case Stmt::AttributedStmtClass:
95 case Stmt::GotoStmtClass:
96 case Stmt::BreakStmtClass:
97 case Stmt::ContinueStmtClass:
98 case Stmt::DefaultStmtClass:
99 case Stmt::CaseStmtClass:
100 case Stmt::SEHLeaveStmtClass:
101 llvm_unreachable(
"should have emitted these statements as simple");
103 #define STMT(Type, Base) 104 #define ABSTRACT_STMT(Op) 105 #define EXPR(Type, Base) \ 106 case Stmt::Type##Class: 107 #include "clang/AST/StmtNodes.inc" 110 llvm::BasicBlock *incoming =
Builder.GetInsertBlock();
111 assert(incoming &&
"expression emission must have an insertion point");
115 llvm::BasicBlock *outgoing =
Builder.GetInsertBlock();
116 assert(outgoing &&
"expression emission cleared block!");
130 if (incoming != outgoing && outgoing->use_empty()) {
131 outgoing->eraseFromParent();
137 case Stmt::IndirectGotoStmtClass:
140 case Stmt::IfStmtClass:
EmitIfStmt(cast<IfStmt>(*S));
break;
141 case Stmt::WhileStmtClass:
EmitWhileStmt(cast<WhileStmt>(*S), Attrs);
break;
142 case Stmt::DoStmtClass:
EmitDoStmt(cast<DoStmt>(*S), Attrs);
break;
143 case Stmt::ForStmtClass:
EmitForStmt(cast<ForStmt>(*S), Attrs);
break;
145 case Stmt::ReturnStmtClass:
EmitReturnStmt(cast<ReturnStmt>(*S));
break;
147 case Stmt::SwitchStmtClass:
EmitSwitchStmt(cast<SwitchStmt>(*S));
break;
148 case Stmt::GCCAsmStmtClass:
149 case Stmt::MSAsmStmtClass:
EmitAsmStmt(cast<AsmStmt>(*S));
break;
150 case Stmt::CoroutineBodyStmtClass:
153 case Stmt::CoreturnStmtClass:
156 case Stmt::CapturedStmtClass: {
161 case Stmt::ObjCAtTryStmtClass:
164 case Stmt::ObjCAtCatchStmtClass:
166 "@catch statements should be handled by EmitObjCAtTryStmt");
167 case Stmt::ObjCAtFinallyStmtClass:
169 "@finally statements should be handled by EmitObjCAtTryStmt");
170 case Stmt::ObjCAtThrowStmtClass:
173 case Stmt::ObjCAtSynchronizedStmtClass:
176 case Stmt::ObjCForCollectionStmtClass:
179 case Stmt::ObjCAutoreleasePoolStmtClass:
183 case Stmt::CXXTryStmtClass:
186 case Stmt::CXXForRangeStmtClass:
189 case Stmt::SEHTryStmtClass:
192 case Stmt::OMPParallelDirectiveClass:
195 case Stmt::OMPSimdDirectiveClass:
198 case Stmt::OMPForDirectiveClass:
201 case Stmt::OMPForSimdDirectiveClass:
204 case Stmt::OMPSectionsDirectiveClass:
207 case Stmt::OMPSectionDirectiveClass:
210 case Stmt::OMPSingleDirectiveClass:
213 case Stmt::OMPMasterDirectiveClass:
216 case Stmt::OMPCriticalDirectiveClass:
219 case Stmt::OMPParallelForDirectiveClass:
222 case Stmt::OMPParallelForSimdDirectiveClass:
225 case Stmt::OMPParallelMasterDirectiveClass:
228 case Stmt::OMPParallelSectionsDirectiveClass:
231 case Stmt::OMPTaskDirectiveClass:
234 case Stmt::OMPTaskyieldDirectiveClass:
237 case Stmt::OMPBarrierDirectiveClass:
240 case Stmt::OMPTaskwaitDirectiveClass:
243 case Stmt::OMPTaskgroupDirectiveClass:
246 case Stmt::OMPFlushDirectiveClass:
249 case Stmt::OMPOrderedDirectiveClass:
252 case Stmt::OMPAtomicDirectiveClass:
255 case Stmt::OMPTargetDirectiveClass:
258 case Stmt::OMPTeamsDirectiveClass:
261 case Stmt::OMPCancellationPointDirectiveClass:
264 case Stmt::OMPCancelDirectiveClass:
267 case Stmt::OMPTargetDataDirectiveClass:
270 case Stmt::OMPTargetEnterDataDirectiveClass:
273 case Stmt::OMPTargetExitDataDirectiveClass:
276 case Stmt::OMPTargetParallelDirectiveClass:
279 case Stmt::OMPTargetParallelForDirectiveClass:
282 case Stmt::OMPTaskLoopDirectiveClass:
285 case Stmt::OMPTaskLoopSimdDirectiveClass:
288 case Stmt::OMPMasterTaskLoopDirectiveClass:
291 case Stmt::OMPMasterTaskLoopSimdDirectiveClass:
293 cast<OMPMasterTaskLoopSimdDirective>(*S));
295 case Stmt::OMPParallelMasterTaskLoopDirectiveClass:
297 cast<OMPParallelMasterTaskLoopDirective>(*S));
299 case Stmt::OMPParallelMasterTaskLoopSimdDirectiveClass:
301 cast<OMPParallelMasterTaskLoopSimdDirective>(*S));
303 case Stmt::OMPDistributeDirectiveClass:
306 case Stmt::OMPTargetUpdateDirectiveClass:
309 case Stmt::OMPDistributeParallelForDirectiveClass:
311 cast<OMPDistributeParallelForDirective>(*S));
313 case Stmt::OMPDistributeParallelForSimdDirectiveClass:
315 cast<OMPDistributeParallelForSimdDirective>(*S));
317 case Stmt::OMPDistributeSimdDirectiveClass:
320 case Stmt::OMPTargetParallelForSimdDirectiveClass:
322 cast<OMPTargetParallelForSimdDirective>(*S));
324 case Stmt::OMPTargetSimdDirectiveClass:
327 case Stmt::OMPTeamsDistributeDirectiveClass:
330 case Stmt::OMPTeamsDistributeSimdDirectiveClass:
332 cast<OMPTeamsDistributeSimdDirective>(*S));
334 case Stmt::OMPTeamsDistributeParallelForSimdDirectiveClass:
336 cast<OMPTeamsDistributeParallelForSimdDirective>(*S));
338 case Stmt::OMPTeamsDistributeParallelForDirectiveClass:
340 cast<OMPTeamsDistributeParallelForDirective>(*S));
342 case Stmt::OMPTargetTeamsDirectiveClass:
345 case Stmt::OMPTargetTeamsDistributeDirectiveClass:
347 cast<OMPTargetTeamsDistributeDirective>(*S));
349 case Stmt::OMPTargetTeamsDistributeParallelForDirectiveClass:
351 cast<OMPTargetTeamsDistributeParallelForDirective>(*S));
353 case Stmt::OMPTargetTeamsDistributeParallelForSimdDirectiveClass:
355 cast<OMPTargetTeamsDistributeParallelForSimdDirective>(*S));
357 case Stmt::OMPTargetTeamsDistributeSimdDirectiveClass:
359 cast<OMPTargetTeamsDistributeSimdDirective>(*S));
366 default:
return false;
367 case Stmt::NullStmtClass:
break;
368 case Stmt::CompoundStmtClass:
EmitCompoundStmt(cast<CompoundStmt>(*S));
break;
369 case Stmt::DeclStmtClass:
EmitDeclStmt(cast<DeclStmt>(*S));
break;
370 case Stmt::LabelStmtClass:
EmitLabelStmt(cast<LabelStmt>(*S));
break;
371 case Stmt::AttributedStmtClass:
373 case Stmt::GotoStmtClass:
EmitGotoStmt(cast<GotoStmt>(*S));
break;
374 case Stmt::BreakStmtClass:
EmitBreakStmt(cast<BreakStmt>(*S));
break;
375 case Stmt::ContinueStmtClass:
EmitContinueStmt(cast<ContinueStmt>(*S));
break;
376 case Stmt::DefaultStmtClass:
EmitDefaultStmt(cast<DefaultStmt>(*S));
break;
377 case Stmt::CaseStmtClass:
EmitCaseStmt(cast<CaseStmt>(*S));
break;
378 case Stmt::SEHLeaveStmtClass:
EmitSEHLeaveStmt(cast<SEHLeaveStmt>(*S));
break;
390 "LLVM IR generation of compound statement ('{}')");
404 assert((!GetLast || (GetLast && ExprResult)) &&
405 "If GetLast is true then the CompoundStmt must have a StmtExprResult");
409 for (
auto *CurStmt : S.
body()) {
410 if (GetLast && ExprResult == CurStmt) {
416 while (!isa<Expr>(ExprResult)) {
417 if (
const auto *LS = dyn_cast<LabelStmt>(ExprResult)) {
419 ExprResult = LS->getSubStmt();
420 }
else if (
const auto *AS = dyn_cast<AttributedStmt>(ExprResult)) {
423 ExprResult = AS->getSubStmt();
425 llvm_unreachable(
"unknown value statement");
452 llvm::BranchInst *BI = dyn_cast<llvm::BranchInst>(BB->getTerminator());
461 if (!BI || !BI->isUnconditional())
465 if (BI->getIterator() != BB->begin())
468 BB->replaceAllUsesWith(BI->getSuccessor(0));
469 BI->eraseFromParent();
470 BB->eraseFromParent();
474 llvm::BasicBlock *CurBB =
Builder.GetInsertBlock();
479 if (IsFinished && BB->use_empty()) {
486 if (CurBB && CurBB->getParent())
487 CurFn->getBasicBlockList().insertAfter(CurBB->getIterator(), BB);
489 CurFn->getBasicBlockList().push_back(BB);
497 llvm::BasicBlock *CurBB =
Builder.GetInsertBlock();
499 if (!CurBB || CurBB->getTerminator()) {
511 bool inserted =
false;
512 for (llvm::User *u : block->users()) {
513 if (llvm::Instruction *insn = dyn_cast<llvm::Instruction>(u)) {
514 CurFn->getBasicBlockList().insertAfter(insn->getParent()->getIterator(),
522 CurFn->getBasicBlockList().push_back(block);
530 if (Dest.
isValid())
return Dest;
577 assert(!Labels.empty());
579 = CGF.EHStack.getInnermostNormalCleanup();
583 i = Labels.begin(), e = Labels.end(); i != e; ++i) {
584 assert(CGF.LabelMap.count(*i));
585 JumpDest &dest = CGF.LabelMap.find(*i)->second;
586 assert(dest.getScopeDepth().isValid());
587 assert(innermostScope.encloses(dest.getScopeDepth()));
588 dest.setScopeDepth(innermostScope);
593 ParentScope->Labels.append(Labels.begin(), Labels.end());
627 llvm::BasicBlock *CurBB =
Builder.GetInsertBlock();
634 cast<llvm::PHINode>(IndGotoBB->begin())->addIncoming(V, CurBB);
659 std::swap(Executed, Skipped);
678 llvm::BasicBlock *ElseBlock = ContBlock;
733 BreakContinueStack.push_back(BreakContinue(LoopExit, LoopHeader));
754 bool EmitBoolCondBranch =
true;
755 if (llvm::ConstantInt *C = dyn_cast<llvm::ConstantInt>(BoolCondVal))
757 EmitBoolCondBranch =
false;
761 if (EmitBoolCondBranch) {
762 llvm::BasicBlock *ExitBlock = LoopExit.
getBlock();
766 BoolCondVal, LoopBody, ExitBlock,
769 if (ExitBlock != LoopExit.
getBlock()) {
784 BreakContinueStack.pop_back();
800 if (!EmitBoolCondBranch)
812 BreakContinueStack.push_back(BreakContinue(LoopExit, LoopCond));
838 BreakContinueStack.pop_back();
842 bool EmitBoolCondBranch =
true;
843 if (llvm::ConstantInt *C = dyn_cast<llvm::ConstantInt>(BoolCondVal))
845 EmitBoolCondBranch =
false;
848 if (EmitBoolCondBranch) {
851 BoolCondVal, LoopBody, LoopExit.
getBlock(),
852 createProfileWeightsForLoop(S.
getCond(), BackedgeCount));
862 if (!EmitBoolCondBranch)
880 llvm::BasicBlock *CondBlock = Continue.
getBlock();
896 BreakContinueStack.push_back(BreakContinue(LoopExit, Continue));
908 llvm::BasicBlock *ExitBlock = LoopExit.
getBlock();
911 if (ForScope.requiresCleanups())
921 BoolCondVal, ForBody, ExitBlock,
924 if (ExitBlock != LoopExit.
getBlock()) {
949 BreakContinueStack.pop_back();
951 ConditionScope.ForceCleanup();
956 ForScope.ForceCleanup();
991 llvm::BasicBlock *ExitBlock = LoopExit.
getBlock();
992 if (ForScope.requiresCleanups())
1002 BoolCondVal, ForBody, ExitBlock,
1005 if (ExitBlock != LoopExit.
getBlock()) {
1017 BreakContinueStack.push_back(BreakContinue(LoopExit, Continue));
1031 BreakContinueStack.pop_back();
1035 ForScope.ForceCleanup();
1043 void CodeGenFunction::EmitReturnOfRValue(
RValue RV,
QualType Ty) {
1061 if (requiresReturnValueCheck()) {
1064 new llvm::GlobalVariable(
CGM.
getModule(), SLoc->getType(),
false,
1065 llvm::GlobalVariable::PrivateLinkage, SLoc);
1066 SLocPtr->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
1068 assert(ReturnLocation.
isValid() &&
"No valid return location");
1076 Builder.ClearInsertionPoint();
1087 if (
const FullExpr *fe = dyn_cast_or_null<FullExpr>(RV)) {
1089 RV = fe->getSubExpr();
1138 ++NumSimpleReturnExprs;
1150 for (
const auto *I : S.
decls())
1155 assert(!BreakContinueStack.empty() &&
"break stmt not in a loop or switch!");
1167 assert(!BreakContinueStack.empty() &&
"continue stmt not in a loop!");
1182 assert(S.
getRHS() &&
"Expected RHS value in CaseStmt");
1195 if (LHS.isSigned() ? RHS.slt(LHS) : RHS.ult(LHS))
1200 if (Range.ult(
llvm::APInt(Range.getBitWidth(), 64))) {
1203 unsigned NCases = Range.getZExtValue() + 1;
1208 uint64_t Weight = Total / NCases, Rem = Total % NCases;
1209 for (
unsigned I = 0; I != NCases; ++I) {
1211 SwitchWeights->push_back(Weight + (Rem ? 1 : 0));
1214 SwitchInsn->addCase(
Builder.getInt(LHS), CaseDest);
1222 llvm::BasicBlock *RestoreBB =
Builder.GetInsertBlock();
1227 llvm::BasicBlock *FalseDest = CaseRangeBlock;
1230 CurFn->getBasicBlockList().push_back(CaseRangeBlock);
1231 Builder.SetInsertPoint(CaseRangeBlock);
1235 Builder.CreateSub(SwitchInsn->getCondition(),
Builder.getInt(LHS));
1239 llvm::MDNode *Weights =
nullptr;
1240 if (SwitchWeights) {
1242 uint64_t DefaultCount = (*SwitchWeights)[0];
1243 Weights = createProfileWeights(ThisCount, DefaultCount);
1248 (*SwitchWeights)[0] += ThisCount;
1250 Builder.CreateCondBr(Cond, CaseDest, FalseDest, Weights);
1254 Builder.SetInsertPoint(RestoreBB);
1256 Builder.ClearInsertionPoint();
1276 llvm::ConstantInt *CaseVal =
1285 JumpDest Block = BreakContinueStack.back().BreakBlock;
1291 SwitchInsn->addCase(CaseVal, Block.
getBlock());
1295 if (
Builder.GetInsertBlock()) {
1297 Builder.ClearInsertionPoint();
1307 SwitchInsn->addCase(CaseVal, CaseDest);
1322 while (NextCase && NextCase->
getRHS() ==
nullptr) {
1324 llvm::ConstantInt *CaseVal =
1334 SwitchInsn->addCase(CaseVal, CaseDest);
1351 llvm::BasicBlock *DefaultBlock = SwitchInsn->getDefaultDest();
1352 assert(DefaultBlock->empty() &&
1353 "EmitDefaultStmt: Default block already defined?");
1394 if (
const SwitchCase *SC = dyn_cast<SwitchCase>(S)) {
1408 if (!Case && isa<BreakStmt>(S))
1413 if (
const CompoundStmt *CS = dyn_cast<CompoundStmt>(S)) {
1417 bool StartedInLiveCode = FoundCase;
1418 unsigned StartSize = ResultStmts.size();
1425 bool HadSkippedDecl =
false;
1429 for (; Case && I != E; ++I) {
1445 for (++I; I != E; ++I)
1455 assert(FoundCase &&
"Didn't find case but returned fallthrough?");
1470 assert(!HadSkippedDecl &&
"fallthrough after skipping decl");
1475 bool AnyDecls =
false;
1476 for (; I != E; ++I) {
1489 for (++I; I != E; ++I)
1506 ResultStmts.resize(StartSize);
1507 ResultStmts.push_back(S);
1531 ResultStmts.push_back(S);
1552 if (
const DefaultStmt *DS = dyn_cast<DefaultStmt>(Case)) {
1558 const CaseStmt *CS = cast<CaseStmt>(Case);
1560 if (CS->
getRHS())
return false;
1585 bool FoundCase =
false;
1594 llvm::SwitchInst *SavedSwitchInsn = SwitchInsn;
1596 llvm::BasicBlock *SavedCRBlock = CaseRangeBlock;
1621 SwitchInsn =
nullptr;
1625 for (
unsigned i = 0, e = CaseStmts.size(); i != e; ++i)
1631 SwitchInsn = SavedSwitchInsn;
1653 SwitchInsn =
Builder.CreateSwitch(CondV, DefaultBlock);
1656 uint64_t DefaultCount = 0;
1657 unsigned NumCases = 0;
1661 if (isa<DefaultStmt>(Case))
1666 SwitchWeights->reserve(NumCases);
1669 SwitchWeights->push_back(DefaultCount);
1671 CaseRangeBlock = DefaultBlock;
1674 Builder.ClearInsertionPoint();
1679 if (!BreakContinueStack.empty())
1680 OuterContinue = BreakContinueStack.back().ContinueBlock;
1682 BreakContinueStack.push_back(BreakContinue(SwitchExit, OuterContinue));
1687 BreakContinueStack.pop_back();
1691 SwitchInsn->setDefaultDest(CaseRangeBlock);
1694 if (!DefaultBlock->getParent()) {
1702 DefaultBlock->replaceAllUsesWith(SwitchExit.
getBlock());
1703 delete DefaultBlock;
1718 auto *FD = dyn_cast_or_null<FunctionDecl>(Call->getCalleeDecl());
1719 if (FD && FD->getBuiltinID() == Builtin::BI__builtin_unpredictable) {
1721 SwitchInsn->setMetadata(llvm::LLVMContext::MD_unpredictable,
1722 MDHelper.createUnpredictable());
1726 if (SwitchWeights) {
1727 assert(SwitchWeights->size() == 1 + SwitchInsn->getNumCases() &&
1728 "switch weights do not match switch cases");
1730 if (SwitchWeights->size() > 1)
1731 SwitchInsn->setMetadata(llvm::LLVMContext::MD_prof,
1732 createProfileWeights(*SwitchWeights));
1733 delete SwitchWeights;
1735 SwitchInsn = SavedSwitchInsn;
1736 SwitchWeights = SavedSwitchWeights;
1737 CaseRangeBlock = SavedCRBlock;
1745 while (*Constraint) {
1746 switch (*Constraint) {
1758 while (Constraint[1] && Constraint[1] !=
',')
1763 Result += *Constraint;
1764 while (Constraint[1] && Constraint[1] == *Constraint)
1775 "Must pass output names to constraints with a symbolic name");
1778 assert(result &&
"Could not resolve symbolic name"); (void)result;
1779 Result += llvm::utostr(Index);
1806 AsmLabelAttr *
Attr = Variable->
getAttr<AsmLabelAttr>();
1809 StringRef Register = Attr->getLabel();
1815 !Info.allowsRegister()) {
1821 return (EarlyClobber ?
"&{" :
"{") + Register.str() +
"}";
1827 std::string &ConstraintStr,
1836 if (Size <= 64 && llvm::isPowerOf2_64(Size)) {
1838 Ty = llvm::PointerType::getUnqual(Ty);
1844 ConstraintStr +=
'*';
1849 ConstraintStr +=
'*';
1857 const Expr *InputExpr,
1858 std::string &ConstraintStr) {
1880 if (InputExpr->
getStmtClass() == Expr::CXXThisExprClass)
1884 return EmitAsmInputLValue(Info, Dest, InputExpr->
getType(), ConstraintStr,
1896 Locs.push_back(llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
1899 if (!StrVal.empty()) {
1902 unsigned StartToken = 0;
1903 unsigned ByteOffset = 0;
1907 for (
unsigned i = 0, e = StrVal.size() - 1; i != e; ++i) {
1908 if (StrVal[i] !=
'\n')
continue;
1910 i + 1, SM, LangOpts, CGF.
getTarget(), &StartToken, &ByteOffset);
1911 Locs.push_back(llvm::ConstantAsMetadata::get(
1920 bool ReadOnly,
bool ReadNone,
const AsmStmt &S,
1921 const std::vector<llvm::Type *> &ResultRegTypes,
1923 std::vector<llvm::Value *> &RegResults) {
1924 Result.addAttribute(llvm::AttributeList::FunctionIndex,
1925 llvm::Attribute::NoUnwind);
1927 if (!HasSideEffect) {
1929 Result.addAttribute(llvm::AttributeList::FunctionIndex,
1930 llvm::Attribute::ReadNone);
1932 Result.addAttribute(llvm::AttributeList::FunctionIndex,
1933 llvm::Attribute::ReadOnly);
1938 if (
const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(&S))
1939 Result.setMetadata(
"srcloc",
1943 llvm::Constant *Loc = llvm::ConstantInt::get(CGF.
Int32Ty,
1945 Result.setMetadata(
"srcloc",
1947 llvm::ConstantAsMetadata::get(Loc)));
1955 Result.addAttribute(llvm::AttributeList::FunctionIndex,
1956 llvm::Attribute::Convergent);
1958 if (ResultRegTypes.size() == 1) {
1959 RegResults.push_back(&Result);
1961 for (
unsigned i = 0, e = ResultRegTypes.size(); i != e; ++i) {
1963 RegResults.push_back(Tmp);
1978 if (
const GCCAsmStmt *GAS = dyn_cast<GCCAsmStmt>(&S))
1979 Name = GAS->getOutputName(i);
1982 assert(IsValid &&
"Failed to parse output constraint");
1983 OutputConstraintInfos.push_back(Info);
1986 for (
unsigned i = 0, e = S.
getNumInputs(); i != e; i++) {
1988 if (
const GCCAsmStmt *GAS = dyn_cast<GCCAsmStmt>(&S))
1989 Name = GAS->getInputName(i);
1993 assert(IsValid &&
"Failed to parse input constraint"); (void)IsValid;
1994 InputConstraintInfos.push_back(Info);
1997 std::string Constraints;
1999 std::vector<LValue> ResultRegDests;
2000 std::vector<QualType> ResultRegQualTys;
2001 std::vector<llvm::Type *> ResultRegTypes;
2002 std::vector<llvm::Type *> ResultTruncRegTypes;
2003 std::vector<llvm::Type *> ArgTypes;
2004 std::vector<llvm::Value*> Args;
2005 llvm::BitVector ResultTypeRequiresCast;
2008 std::string InOutConstraints;
2009 std::vector<llvm::Value*> InOutArgs;
2010 std::vector<llvm::Type*> InOutArgTypes;
2013 std::vector<std::string> OutputConstraints;
2021 bool ReadOnly =
true, ReadNone =
true;
2037 OutputConstraints.push_back(OutputConstraint);
2039 if (!Constraints.empty())
2044 bool isScalarizableAggregate =
2047 isScalarizableAggregate)) {
2048 Constraints +=
"=" + OutputConstraint;
2049 ResultRegQualTys.push_back(OutExpr->getType());
2050 ResultRegDests.push_back(Dest);
2053 ResultTypeRequiresCast.push_back(
true);
2056 ResultRegTypes.push_back(ConvTy);
2058 ResultTypeRequiresCast.push_back(
false);
2059 ResultRegTypes.push_back(ResultTruncRegTypes.back());
2066 for (InputNo = 0; InputNo != S.
getNumInputs(); ++InputNo) {
2071 assert(InputNo != S.
getNumInputs() &&
"Didn't find matching input!");
2074 QualType OutputType = OutExpr->getType();
2084 ResultRegTypes.back()))
2085 ResultRegTypes.back() = AdjTy;
2088 diag::err_asm_invalid_type_in_input)
2089 << OutExpr->getType() << OutputConstraint;
2093 if (
auto *VT = dyn_cast<llvm::VectorType>(ResultRegTypes.back()))
2094 LargestVectorWidth =
std::max((uint64_t)LargestVectorWidth,
2095 VT->getPrimitiveSizeInBits().getFixedSize());
2099 Constraints +=
"=*";
2100 Constraints += OutputConstraint;
2101 ReadOnly = ReadNone =
false;
2105 InOutConstraints +=
',';
2118 if (
auto *VT = dyn_cast<llvm::VectorType>(Arg->getType()))
2119 LargestVectorWidth =
std::max((uint64_t)LargestVectorWidth,
2120 VT->getPrimitiveSizeInBits().getFixedSize());
2122 InOutConstraints += llvm::utostr(i);
2124 InOutConstraints += OutputConstraint;
2126 InOutArgTypes.push_back(Arg->getType());
2127 InOutArgs.push_back(Arg);
2133 if (isa<MSAsmStmt>(&S)) {
2139 *
this, ReturnSlot, Constraints, ResultRegTypes, ResultTruncRegTypes,
2145 for (
unsigned i = 0, e = S.
getNumInputs(); i != e; i++) {
2153 if (!Constraints.empty())
2159 &OutputConstraintInfos);
2165 std::string ReplaceConstraint (InputConstraint);
2166 llvm::Value *Arg = EmitAsmInput(Info, InputExpr, Constraints);
2175 QualType OutputType = S.getOutputExpr(Output)->getType();
2181 if (isa<llvm::PointerType>(Arg->getType()))
2184 if (isa<llvm::IntegerType>(OutputTy))
2185 Arg =
Builder.CreateZExt(Arg, OutputTy);
2186 else if (isa<llvm::PointerType>(OutputTy))
2189 assert(OutputTy->isFloatingPointTy() &&
"Unexpected output type");
2190 Arg =
Builder.CreateFPExt(Arg, OutputTy);
2194 ReplaceConstraint = OutputConstraints[Output];
2202 << InputExpr->
getType() << InputConstraint;
2205 if (
auto *VT = dyn_cast<llvm::VectorType>(Arg->getType()))
2206 LargestVectorWidth =
std::max((uint64_t)LargestVectorWidth,
2207 VT->getPrimitiveSizeInBits().getFixedSize());
2209 ArgTypes.push_back(Arg->getType());
2210 Args.push_back(Arg);
2211 Constraints += InputConstraint;
2215 for (
unsigned i = 0, e = InOutArgs.size(); i != e; i++) {
2216 ArgTypes.push_back(InOutArgTypes[i]);
2217 Args.push_back(InOutArgs[i]);
2219 Constraints += InOutConstraints;
2223 llvm::BasicBlock *Fallthrough =
nullptr;
2224 bool IsGCCAsmGoto =
false;
2225 if (
const auto *GS = dyn_cast<GCCAsmStmt>(&S)) {
2226 IsGCCAsmGoto = GS->isAsmGoto();
2228 for (
auto *E : GS->labels()) {
2230 Transfer.push_back(Dest.
getBlock());
2231 llvm::BlockAddress *BA =
2234 ArgTypes.push_back(BA->getType());
2235 if (!Constraints.empty())
2239 StringRef Name =
"asm.fallthrough";
2248 if (Clobber ==
"memory")
2249 ReadOnly = ReadNone =
false;
2250 else if (Clobber !=
"cc")
2253 if (!Constraints.empty())
2256 Constraints +=
"~{";
2257 Constraints += Clobber;
2263 if (!MachineClobbers.empty()) {
2264 if (!Constraints.empty())
2266 Constraints += MachineClobbers;
2270 if (ResultRegTypes.empty())
2272 else if (ResultRegTypes.size() == 1)
2273 ResultType = ResultRegTypes[0];
2275 ResultType = llvm::StructType::get(
getLLVMContext(), ResultRegTypes);
2277 llvm::FunctionType *FTy =
2278 llvm::FunctionType::get(ResultType, ArgTypes,
false);
2281 llvm::InlineAsm::AsmDialect AsmDialect = isa<MSAsmStmt>(&S) ?
2282 llvm::InlineAsm::AD_Intel : llvm::InlineAsm::AD_ATT;
2283 llvm::InlineAsm *IA =
2284 llvm::InlineAsm::get(FTy, AsmString, Constraints, HasSideEffect,
2286 std::vector<llvm::Value*> RegResults;
2288 llvm::CallBrInst *Result =
2289 Builder.CreateCallBr(IA, Fallthrough, Transfer, Args);
2291 ReadNone, S, ResultRegTypes, *
this, RegResults);
2294 llvm::CallInst *Result =
2297 ReadNone, S, ResultRegTypes, *
this, RegResults);
2300 assert(RegResults.size() == ResultRegTypes.size());
2301 assert(RegResults.size() == ResultTruncRegTypes.size());
2302 assert(RegResults.size() == ResultRegDests.size());
2305 assert(ResultTypeRequiresCast.size() <= ResultRegDests.size());
2306 for (
unsigned i = 0, e = RegResults.size(); i != e; ++i) {
2311 if (ResultRegTypes[i] != ResultTruncRegTypes[i]) {
2312 llvm::Type *TruncTy = ResultTruncRegTypes[i];
2316 if (TruncTy->isFloatingPointTy())
2317 Tmp =
Builder.CreateFPTrunc(Tmp, TruncTy);
2318 else if (TruncTy->isPointerTy() && Tmp->getType()->isIntegerTy()) {
2320 Tmp =
Builder.CreateTrunc(Tmp,
2322 Tmp =
Builder.CreateIntToPtr(Tmp, TruncTy);
2323 }
else if (Tmp->getType()->isPointerTy() && TruncTy->isIntegerTy()) {
2325 Tmp =
Builder.CreatePtrToInt(Tmp,
2327 Tmp =
Builder.CreateTrunc(Tmp, TruncTy);
2328 }
else if (TruncTy->isIntegerTy()) {
2329 Tmp =
Builder.CreateZExtOrTrunc(Tmp, TruncTy);
2330 }
else if (TruncTy->isVectorTy()) {
2335 LValue Dest = ResultRegDests[i];
2338 if ((i < ResultTypeRequiresCast.size()) && ResultTypeRequiresCast[i]) {
2341 ResultRegTypes[i]->getPointerTo());
2347 "impossible constraint in asm: can't store value into a register");
2367 I != E; ++I, ++CurField) {
2369 if (CurField->hasCapturedVLAType()) {
2370 auto VAT = CurField->getCapturedVLAType();
2407 "CapturedStmtInfo should be set when generating the captured function");
2411 assert(CD->
hasBody() &&
"missing CapturedDecl body");
2428 F->addFnAttr(llvm::Attribute::NoUnwind);
2439 Ctx.getTagDeclType(RD));
2440 for (
auto *FD : RD->
fields()) {
2441 if (FD->hasCapturedVLAType()) {
2445 auto VAT = FD->getCapturedVLAType();
2446 VLASizeMap[VAT->getSizeExpr()] = ExprArg;
const CGFunctionInfo & arrangeBuiltinFunctionDeclaration(QualType resultType, const FunctionArgList &args)
A builtin function is a freestanding function using the default C conventions.
const llvm::DataLayout & getDataLayout() const
void EmitOMPMasterTaskLoopDirective(const OMPMasterTaskLoopDirective &S)
void EmitIndirectGotoStmt(const IndirectGotoStmt &S)
void EmitCoroutineBody(const CoroutineBodyStmt &S)
virtual void EmitBody(CodeGenFunction &CGF, const Stmt *S)
Emit the captured statement body.
This represents a GCC inline-assembly statement extension.
void EmitOMPTaskwaitDirective(const OMPTaskwaitDirective &S)
unsigned getNumInputs() const
SourceLocation getBeginLoc() const
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
A (possibly-)qualified type.
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument.
void EmitSEHLeaveStmt(const SEHLeaveStmt &S)
CodeGenTypes & getTypes()
llvm::Type * ConvertTypeForMem(QualType T)
void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, llvm::BasicBlock *FalseBlock, uint64_t TrueCount)
EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g.
const CodeGenOptions & getCodeGenOpts() const
static CSFC_Result CollectStatementsForCase(const Stmt *S, const SwitchCase *Case, bool &FoundCase, SmallVectorImpl< const Stmt *> &ResultStmts)
void EmitGotoStmt(const GotoStmt &S)
void EmitAttributedStmt(const AttributedStmt &S)
param_iterator param_begin() const
Retrieve an iterator pointing to the first parameter decl.
Address CreateMemTemp(QualType T, const Twine &Name="tmp", Address *Alloca=nullptr)
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen and cas...
void enterFullExpression(const FullExpr *E)
bool HaveInsertPoint() const
HaveInsertPoint - True if an insertion point is defined.
void EmitOMPDistributeDirective(const OMPDistributeDirective &S)
void EmitCXXTryStmt(const CXXTryStmt &S)
Stmt - This represents one statement.
IfStmt - This represents an if/then/else.
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...
static stable_iterator stable_end()
Create a stable reference to the bottom of the EH stack.
bool requiresCleanups() const
Determine whether this scope requires any cleanups.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
void EmitOMPTargetSimdDirective(const OMPTargetSimdDirective &S)
unsigned getNumOutputs() const
Defines the PrettyStackTraceEntry class, which is used to make crashes give more contextual informati...
llvm::Value * getTypeSize(QualType Ty)
Returns calculated size of the specified type.
Represents an attribute applied to a statement.
void EmitOMPOrderedDirective(const OMPOrderedDirective &S)
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
EmitStoreThroughLValue - Store the specified rvalue into the specified lvalue, where both are guarant...
void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit)
EmitComplexExprIntoLValue - Emit the given expression of complex type and place its result into the s...
Address GenerateCapturedStmtArgument(const CapturedStmt &S)
bool validateInputConstraint(MutableArrayRef< ConstraintInfo > OutputConstraints, ConstraintInfo &info) const
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
const RecordDecl * getCapturedRecordDecl() const
Retrieve the record declaration for captured variables.
stable_iterator stable_begin() const
Create a stable reference to the top of the EH stack.
LValue EmitLValueForFieldInitialization(LValue Base, const FieldDecl *Field)
EmitLValueForFieldInitialization - Like EmitLValueForField, except that if the Field is a reference...
bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result, bool AllowLabels=false)
ConstantFoldsToSimpleInteger - If the specified expression does not fold to a constant, or if it does but contains a label, return false.
Represents a point when we exit a loop.
bool empty() const
Determines whether the exception-scopes stack is empty.
void EmitOMPParallelForSimdDirective(const OMPParallelForSimdDirective &S)
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
Represents a variable declaration or definition.
void EmitOMPCriticalDirective(const OMPCriticalDirective &S)
const VarDecl * getNRVOCandidate() const
Retrieve the variable that might be used for the named return value optimization. ...
uint64_t getProfileCount(const Stmt *S)
Get the profiler's count for the given statement.
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
static bool mightAddDeclToScope(const Stmt *S)
Determine if the given statement might introduce a declaration into the current scope, by being a (possibly-labelled) DeclStmt.
DiagnosticsEngine & getDiags() const
void EmitLabel(const LabelDecl *D)
EmitLabel - Emit the block for the given label.
void EmitOMPParallelMasterTaskLoopSimdDirective(const OMPParallelMasterTaskLoopSimdDirective &S)
void EmitOMPTeamsDistributeDirective(const OMPTeamsDistributeDirective &S)
void SimplifyForwardingBlocks(llvm::BasicBlock *BB)
SimplifyForwardingBlocks - If the given basic block is only a branch to another basic block...
The collection of all-type qualifiers we support.
A jump destination is an abstract label, branching to which may require a jump out through normal cle...
void EmitOMPTargetTeamsDistributeParallelForSimdDirective(const OMPTargetTeamsDistributeParallelForSimdDirective &S)
bool isObviouslyBranchWithoutCleanups(JumpDest Dest) const
isObviouslyBranchWithoutCleanups - Return true if a branch to the specified destination obviously has...
LabelStmt - Represents a label, which has a substatement.
void EmitOMPTaskLoopSimdDirective(const OMPTaskLoopSimdDirective &S)
JumpDest getJumpDestForLabel(const LabelDecl *S)
getBasicBlockForLabel - Return the LLVM basicblock that the specified label maps to.
Represents a struct/union/class.
const TargetInfo & getTarget() const
void EmitOMPSimdDirective(const OMPSimdDirective &S)
void setScopeDepth(EHScopeStack::stable_iterator depth)
CGDebugInfo * getDebugInfo()
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
void EmitOMPMasterTaskLoopSimdDirective(const OMPMasterTaskLoopSimdDirective &S)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
StringRef getNormalizedGCCRegisterName(StringRef Name, bool ReturnCanonical=false) const
Returns the "normalized" GCC register name.
void addLabel(const LabelDecl *label)
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
FullExpr - Represents a "full-expression" node.
field_range fields() const
SourceLocation getBeginLoc() const LLVM_READONLY
Represents a member of a struct/union/class.
ImplicitParamDecl * getContextParam() const
Retrieve the parameter containing captured variables.
void rescopeLabels()
Change the cleanup scope of the labels in this lexical scope to match the scope of the enclosing cont...
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...
Stmt * getStmtExprResult()
bool isReferenceType() const
Stmt *const * const_body_iterator
virtual void setContextValue(llvm::Value *V)
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.
void EmitForStmt(const ForStmt &S, ArrayRef< const Attr *> Attrs=None)
__DEVICE__ int max(int __a, int __b)
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
void EmitOMPDistributeParallelForSimdDirective(const OMPDistributeParallelForSimdDirective &S)
void EmitInitializerForField(FieldDecl *Field, LValue LHS, Expr *Init)
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.
IndirectGotoStmt - This represents an indirect goto.
Stmt * getBody() const override
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
static bool hasScalarEvaluationKind(QualType T)
bool hasMatchingInput() const
Return true if this output operand has a matching (tied) input operand.
Expr *const * const_capture_init_iterator
Const iterator that walks over the capture initialization arguments.
void EmitOMPTargetTeamsDistributeSimdDirective(const OMPTargetTeamsDistributeSimdDirective &S)
ForStmt - This represents a 'for (init;cond;inc)' stmt.
bool assumeFunctionsAreConvergent() const
APValue Val
Val - This is the value the expression can be folded to.
void pop()
End the current loop.
LabelDecl * getDecl() const
SourceLocation getLBracLoc() const
void EmitOMPCancellationPointDirective(const OMPCancellationPointDirective &S)
RAII for correct setting/restoring of CapturedStmtInfo.
const Expr * getOutputExpr(unsigned i) const
param_iterator param_end() const
Retrieve an iterator one past the last parameter decl.
void EmitOMPTeamsDistributeParallelForSimdDirective(const OMPTeamsDistributeParallelForSimdDirective &S)
void EmitContinueStmt(const ContinueStmt &S)
void EmitOMPTargetDirective(const OMPTargetDirective &S)
bool hasNormalCleanups() const
Determines whether there are any normal cleanups on the stack.
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
bool isCXXThisExprCaptured() const
bool IsOutlinedSEHHelper
True if the current function is an outlined SEH helper.
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
void EmitOMPTargetUpdateDirective(const OMPTargetUpdateDirective &S)
void EmitSwitchStmt(const SwitchStmt &S)
If a crash happens while one of these objects are live, the message is printed out along with the spe...
static void UpdateAsmCallInst(llvm::CallBase &Result, bool HasSideEffect, bool ReadOnly, bool ReadNone, const AsmStmt &S, const std::vector< llvm::Type *> &ResultRegTypes, CodeGenFunction &CGF, std::vector< llvm::Value *> &RegResults)
Scope - A scope is a transient data structure that is used while parsing the program.
field_iterator field_begin() const
CaseStmt - Represent a case statement.
void EmitOMPParallelDirective(const OMPParallelDirective &S)
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
void EmitIgnoredExpr(const Expr *E)
EmitIgnoredExpr - Emit an expression in a context which ignores the result.
void assignRegionCounters(GlobalDecl GD, llvm::Function *Fn)
Assign counters to regions and configure them for PGO of a given function.
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...
void ForceCleanup(std::initializer_list< llvm::Value **> ValuesToReload={})
Force the emission of cleanups now, instead of waiting until this object is destroyed.
void EmitDefaultStmt(const DefaultStmt &S)
static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts=false)
ContainsLabel - Return true if the statement contains a label in it.
void EmitCaseStmtRange(const CaseStmt &S)
EmitCaseStmtRange - If case statement range is not too big then add multiple cases to switch instruct...
void incrementProfileCounter(const Stmt *S, llvm::Value *StepV=nullptr)
Increment the profiler's counter for the given statement by StepV.
uint64_t getCurrentProfileCount()
Get the profiler's current count.
Represents the body of a CapturedStmt, and serves as its DeclContext.
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
Address getAggregateAddress() const
getAggregateAddr() - Return the Value* of the address of the aggregate.
virtual bool isValidGCCRegisterName(StringRef Name) const
Returns whether the passed in string is a valid register name according to GCC.
LValue EmitLValueForField(LValue Base, const FieldDecl *Field)
StringRef getString() const
CompoundStmt - This represents a group of statements like { stmt stmt }.
ASTContext & getContext() const
void EmitOMPParallelSectionsDirective(const OMPParallelSectionsDirective &S)
const TargetCodeGenInfo & getTargetCodeGenInfo()
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 - This trivial value class is used to represent the result of an expression that is evaluated...
AggValueSlot::Overlap_t getOverlapForReturnValue()
Determine whether a return value slot may overlap some other object.
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
void EmitOMPParallelMasterDirective(const OMPParallelMasterDirective &S)
Exposes information about the current target.
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
EHScopeStack::stable_iterator getScopeDepth() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
This represents one expression.
Address getAddress(CodeGenFunction &CGF) const
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited...
void EmitCaseStmt(const CaseStmt &S)
std::pair< llvm::Value *, llvm::Value * > getComplexVal() const
getComplexVal - Return the real/imag components of this complex value.
void EmitOMPTeamsDirective(const OMPTeamsDirective &S)
llvm::BasicBlock * getBlock() const
Address EmitCompoundStmt(const CompoundStmt &S, bool GetLast=false, AggValueSlot AVS=AggValueSlot::ignored())
EmitCompoundStmt - Emit a compound statement {..} node.
bool requiresImmediateConstant() const
LabelDecl * getConstantTarget()
getConstantTarget - Returns the fixed target of this indirect goto, if one exists.
llvm::PointerType * getType() const
Return the type of the pointer value.
void EmitSEHTryStmt(const SEHTryStmt &S)
static llvm::MDNode * getAsmSrcLocInfo(const StringLiteral *Str, CodeGenFunction &CGF)
getAsmSrcLocInfo - Return the !srcloc metadata node to attach to an inline asm call instruction...
llvm::LLVMContext & getLLVMContext()
SmallVector< llvm::OperandBundleDef, 1 > getBundlesForFunclet(llvm::Value *Callee)
llvm::BasicBlock * GetIndirectGotoBlock()
llvm::IntegerType * Int32Ty
void EmitOMPMasterDirective(const OMPMasterDirective &S)
LabelDecl * getLabel() const
llvm::Function * GenerateCapturedStmtFunction(const CapturedStmt &S)
Creates the outlined function for a CapturedStmt.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;...
LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T)
QualType getRecordType(const RecordDecl *Decl) const
SwitchCase * getSwitchCaseList()
void ResolveBranchFixups(llvm::BasicBlock *Target)
SourceLocation getEnd() const
void EmitOMPBarrierDirective(const OMPBarrierDirective &S)
StringRef getClobber(unsigned i) const
const LangOptions & getLangOpts() const
ASTContext & getContext() const
bool isNull() const
Return true if this QualType doesn't point to a type yet.
llvm::StoreInst * CreateFlagStore(bool Value, llvm::Value *Addr)
Emit a store to an i1 flag variable.
GlobalDecl - represents a global declaration.
void EmitSimpleOMPExecutableDirective(const OMPExecutableDirective &D)
Emit simple code for OpenMP directives in Simd-only mode.
DoStmt - This represents a 'do/while' stmt.
AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
void EmitDeclStmt(const DeclStmt &S)
virtual bool hasBody() const
Returns true if this Decl represents a declaration for a body of code, such as a function or method d...
The l-value was considered opaque, so the alignment was determined from a type.
void EmitOMPFlushDirective(const OMPFlushDirective &S)
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...
virtual llvm::Value * getContextValue() const
bool SawAsmBlock
Whether we processed a Microsoft-style asm block during CodeGen.
Address CreateBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
StringRef getInputConstraint(unsigned i) const
getInputConstraint - Return the specified input constraint.
This captures a statement into a function.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
StringRef getOutputConstraint(unsigned i) const
getOutputConstraint - Return the constraint string for the specified output operand.
Encodes a location in the source.
void EmitDoStmt(const DoStmt &S, ArrayRef< const Attr *> Attrs=None)
void EnsureInsertPoint()
EnsureInsertPoint - Ensure that an insertion point is defined so that emitted IR has a place to go...
void EmitOMPForDirective(const OMPForDirective &S)
A saved depth on the scope stack.
llvm::Value * EvaluateExprAsBool(const Expr *E)
EvaluateExprAsBool - Perform the usual unary conversions on the specified expression and compare the ...
void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S)
llvm::Value * getPointer(CodeGenFunction &CGF) const
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
Represents the declaration of a label.
void EmitStmt(const Stmt *S, ArrayRef< const Attr *> Attrs=None)
EmitStmt - Emit the code for the statement.
void EmitOMPTaskgroupDirective(const OMPTaskgroupDirective &S)
void EmitOMPTargetParallelForSimdDirective(const OMPTargetParallelForSimdDirective &S)
bool validateOutputConstraint(ConstraintInfo &Info) const
void EmitOMPTeamsDistributeSimdDirective(const OMPTeamsDistributeSimdDirective &S)
SourceLocation getBeginLoc() const LLVM_READONLY
void EmitOMPSingleDirective(const OMPSingleDirective &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 EmitOMPForSimdDirective(const OMPForSimdDirective &S)
void EmitOMPAtomicDirective(const OMPAtomicDirective &S)
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...
void EmitOMPSectionDirective(const OMPSectionDirective &S)
void EmitOMPSectionsDirective(const OMPSectionsDirective &S)
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
void Error(SourceLocation loc, StringRef error)
Emit a general error that something can't be done.
void EmitOMPTaskLoopDirective(const OMPTaskLoopDirective &S)
virtual FieldDecl * getThisFieldDecl() const
const CGFunctionInfo * CurFnInfo
void EmitDecl(const Decl &D)
EmitDecl - Emit a declaration.
const TargetCodeGenInfo & getTargetHooks() const
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type, returning the result.
void EmitWhileStmt(const WhileStmt &S, ArrayRef< const Attr *> Attrs=None)
FunctionArgList - Type for representing both the decl and type of parameters to a function...
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
LabelStmt * getStmt() const
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 EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S)
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
CGFunctionInfo - Class to encapsulate the information about a function definition.
This class organizes the cross-function state that is used while generating LLVM code.
void EmitOMPTargetTeamsDirective(const OMPTargetTeamsDirective &S)
Dataflow Directional Tag Classes.
void EmitOMPTaskyieldDirective(const OMPTaskyieldDirective &S)
LValue InitCapturedStruct(const CapturedStmt &S)
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
EvalResult is a struct with detailed info about an evaluated expression.
void EmitOMPTargetParallelDirective(const OMPTargetParallelDirective &S)
bool allowsMemory() const
void EmitOMPParallelForDirective(const OMPParallelForDirective &S)
ArrayRef< const Attr * > getAttrs() const
CSFC_Result
CollectStatementsForCase - Given the body of a 'switch' statement and a constant value that is being ...
void push(llvm::BasicBlock *Header, const llvm::DebugLoc &StartLoc, const llvm::DebugLoc &EndLoc)
Begin a new structured loop.
void EmitOMPTargetParallelForDirective(const OMPTargetParallelForDirective &S)
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
llvm::IntegerType * IntPtrTy
StmtClass getStmtClass() const
void EmitOMPTeamsDistributeParallelForDirective(const OMPTeamsDistributeParallelForDirective &S)
void EmitOMPCancelDirective(const OMPCancelDirective &S)
bool hasTiedOperand() const
Return true if this input operand is a matching constraint that ties it to an output operand...
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
SourceLocation getBeginLoc() const LLVM_READONLY
llvm::Module & getModule() const
bool toIntegralConstant(APSInt &Result, QualType SrcTy, const ASTContext &Ctx) const
Try to convert this value to an integral constant.
void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S)
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
bool hasProfileClangInstr() const
Check if Clang profile instrumenation is on.
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
bool allowsRegister() const
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type. ...
void EmitCoreturnStmt(const CoreturnStmt &S)
JumpDest ReturnBlock
ReturnBlock - Unified return block.
virtual StringRef getHelperName() const
Get the name of the capture helper.
static bool hasAggregateEvaluationKind(QualType T)
SwitchStmt - This represents a 'switch' stmt.
static stable_iterator invalid()
API for captured statement code generation.
static std::string SimplifyConstraint(const char *Constraint, const TargetInfo &Target, SmallVectorImpl< TargetInfo::ConstraintInfo > *OutCons=nullptr)
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...
bool resolveSymbolicName(const char *&Name, ArrayRef< ConstraintInfo > OutputConstraints, unsigned &Index) const
llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Location)
Converts Location to a DebugLoc, if debug information is enabled.
void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
void EmitAsmStmt(const AsmStmt &S)
static std::string AddVariableConstraints(const std::string &Constraint, const Expr &AsmExpr, const TargetInfo &Target, CodeGenModule &CGM, const AsmStmt &Stmt, const bool EarlyClobber)
AddVariableConstraints - Look at AsmExpr and if it is a variable declared as using a particular regis...
llvm::PointerType * Int8PtrTy
const TargetInfo & Target
unsigned getTiedOperand() const
void EmitOMPParallelMasterTaskLoopDirective(const OMPParallelMasterTaskLoopDirective &S)
void SetInternalFunctionAttributes(GlobalDecl GD, llvm::Function *F, const CGFunctionInfo &FI)
Set the attributes on the LLVM function for the given decl and function info.
const Expr * getInputExpr(unsigned i) const
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
void EmitOMPTargetEnterDataDirective(const OMPTargetEnterDataDirective &S)
bool hasReducedDebugInfo() const
Check if type and variable info should be emitted.
ABIArgInfo & getReturnInfo()
unsigned getNumClobbers() const
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
SourceManager & getSourceManager()
void EmitOMPDistributeSimdDirective(const OMPDistributeSimdDirective &S)
DeclStmt * getRangeStmt()
void EmitStopPoint(const Stmt *S)
EmitStopPoint - Emit a debug stoppoint if we are emitting debug info.
SourceLocation getAsmLoc() const
GotoStmt - This represents a direct goto.
unsigned NextCleanupDestIndex
const SwitchCase * getNextSwitchCase() const
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
void setCurrentStmt(const Stmt *S)
If the execution count for the current statement is known, record that as the current count...
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 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...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
ActionResult< Expr * > ExprResult
void EmitOMPTargetTeamsDistributeDirective(const OMPTargetTeamsDistributeDirective &S)
void EmitIfStmt(const IfStmt &S)
ContinueStmt - This represents a continue.
void EmitBranch(llvm::BasicBlock *Block)
EmitBranch - Emit a branch to the specified basic block from the current insert block, taking care to avoid creation of branches from dummy blocks.
bool isNRVOVariable() const
Determine whether this local variable can be used with the named return value optimization (NRVO)...
void EmitReturnStmt(const ReturnStmt &S)
EmitReturnStmt - Note that due to GCC extensions, this can have an operand if the function returns vo...
llvm::Type * ConvertType(QualType T)
virtual llvm::Type * adjustInlineAsmType(CodeGen::CodeGenFunction &CGF, StringRef Constraint, llvm::Type *Ty) const
Corrects the low-level LLVM type for a given constraint and "usual" type.
WhileStmt - This represents a 'while' stmt.
LValue EmitLValue(const Expr *E)
EmitLValue - Emit code to compute a designator that specifies the location of the expression...
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
void EmitLabelStmt(const LabelStmt &S)
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
RValue EmitLoadOfLValue(LValue V, SourceLocation Loc)
EmitLoadOfLValue - Given an expression that represents a value lvalue, this method emits the address ...
StringLiteral - This represents a string literal expression, e.g.
Defines the clang::TargetInfo interface.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
virtual void addReturnRegisterOutputs(CodeGen::CodeGenFunction &CGF, CodeGen::LValue ReturnValue, std::string &Constraints, std::vector< llvm::Type *> &ResultRegTypes, std::vector< llvm::Type *> &ResultTruncRegTypes, std::vector< CodeGen::LValue > &ResultRegDests, std::string &AsmString, unsigned NumOutputs) const
Adds constraints and types for result registers.
CGCapturedStmtInfo * CapturedStmtInfo
void EmitOMPTargetExitDataDirective(const OMPTargetExitDataDirective &S)
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...
void EmitAggregateCopy(LValue Dest, LValue Src, QualType EltTy, AggValueSlot::Overlap_t MayOverlap, bool isVolatile=false)
EmitAggregateCopy - Emit an aggregate copy.
A reference to a declared variable, function, enum, etc.
static RValue get(llvm::Value *V)
bool EmitSimpleStmt(const Stmt *S)
EmitSimpleStmt - Try to emit a "simple" statement which does not necessarily require an insertion poi...
BreakStmt - This represents a break.
void EmitOMPTargetDataDirective(const OMPTargetDataDirective &S)
CapturedRegionKind
The different kinds of captured statement.
void EmitBranchThroughCleanup(JumpDest Dest)
EmitBranchThroughCleanup - Emit a branch from the current insert block through the normal cleanup han...
static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF)
Set the IRBuilder to not attach debug locations.
llvm::Constant * EmitCheckSourceLocation(SourceLocation Loc)
Emit a description of a source location in a format suitable for passing to a runtime sanitizer handl...
void EmitCXXForRangeStmt(const CXXForRangeStmt &S, ArrayRef< const Attr *> Attrs=None)
Address EmitCompoundStmtWithoutScope(const CompoundStmt &S, bool GetLast=false, AggValueSlot AVS=AggValueSlot::ignored())
void EmitOMPDistributeParallelForDirective(const OMPDistributeParallelForDirective &S)
DeclStmt * getLoopVarStmt()
A trivial tuple used to represent a source range.
void EmitObjCAtTryStmt(const ObjCAtTryStmt &S)
LValue - This represents an lvalue references.
SanitizerMetadata * getSanitizerMetadata()
void EmitBlockAfterUses(llvm::BasicBlock *BB)
EmitBlockAfterUses - Emit the given block somewhere hopefully near its uses, and leave the insertion ...
const LangOptions & getLangOpts() const
Expr * IgnoreParenNoopCasts(const ASTContext &Ctx) LLVM_READONLY
Skip past any parenthese and casts which do not change the value (including ptr->int casts of the sam...
DeclStmt * getBeginStmt()
void EmitBreakStmt(const BreakStmt &S)
void EmitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt &S)
static bool containsBreak(const Stmt *S)
containsBreak - Return true if the statement contains a break out of it.
SourceLocation getBegin() const
capture_init_iterator capture_init_end()
Retrieve the iterator pointing one past the last initialization argument.
This class handles loading and caching of source files into memory.
bool haveRegionCounts() const
Whether or not we have PGO region data for the current function.
Defines enum values for all the target-independent builtin functions.
void EmitOMPTaskDirective(const OMPTaskDirective &S)
SourceLocation getBodyRBrace() const
getBodyRBrace - Gets the right brace of the body, if a body exists.
CapturedRegionKind getCapturedRegionKind() const
Retrieve the captured region kind.
Attr - This represents one attribute.
SourceLocation getLocation() const
virtual std::string convertConstraint(const char *&Constraint) const
QualType getIntTypeForBitwidth(unsigned DestWidth, unsigned Signed) const
getIntTypeForBitwidth - sets integer QualTy according to specified details: bitwidth, signed/unsigned.
void EmitOMPTargetTeamsDistributeParallelForDirective(const OMPTargetTeamsDistributeParallelForDirective &S)
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> PL, ArrayRef< Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.
virtual const char * getClobbers() const =0
Returns a string of target-specific clobbers, in LLVM format.
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.