29#include "llvm/ADT/ScopeExit.h"
30#include "llvm/ADT/StringExtras.h"
31#include "llvm/ADT/StringRef.h"
43 case Stmt::IntegerLiteralClass:
45 case Stmt::StringLiteralClass: {
46 std::string ret(
"\"");
51 case Stmt::CharacterLiteralClass:
52 case Stmt::CXXNullPtrLiteralExprClass:
53 case Stmt::GNUNullExprClass:
54 case Stmt::CXXBoolLiteralExprClass:
55 case Stmt::FloatingLiteralClass:
56 case Stmt::ImaginaryLiteralClass:
57 case Stmt::ObjCStringLiteralClass:
65 if (
const auto *Ph = dyn_cast<til::Phi>(E))
76 if (
const auto *CA = TD.
getAttr<CapabilityAttr>())
77 return {CA->getName(), TD.
hasAttr<ReentrantCapabilityAttr>()};
121 while (
const auto *UO = dyn_cast<UnaryOperator>(Callee)) {
122 if (UO->getOpcode() != UO_Deref && UO->getOpcode() != UO_AddrOf &&
123 UO->getOpcode() != UO_Plus)
125 Callee = UO->getSubExpr()->IgnoreParenCasts();
127 return dyn_cast<MemberExpr>(Callee);
144 if (!DeclExp && !
Self)
153 else if (
const auto *ME = dyn_cast<MemberExpr>(DeclExp)) {
155 }
else if (
const auto *CE = dyn_cast<CXXMemberCallExpr>(DeclExp)) {
156 Ctx.
SelfArg = CE->getImplicitObjectArgument();
157 Ctx.
NumArgs = CE->getNumArgs();
159 }
else if (
const auto *CE = dyn_cast<CallExpr>(DeclExp)) {
163 Ctx.
NumArgs = CE->getNumArgs() - 1;
164 Ctx.
FunArgs = CE->getArgs() + 1;
168 Ctx.
NumArgs = CE->getNumArgs();
171 }
else if (
const auto *CE = dyn_cast<CXXConstructExpr>(DeclExp)) {
173 Ctx.
NumArgs = CE->getNumArgs();
181 if (
const auto *CMD = dyn_cast<CXXMethodDecl>(D))
182 if (CMD->getParent()->isLambda())
186 assert(!Ctx.
SelfArg &&
"Ambiguous self argument");
221 if (
const auto* SLit = dyn_cast<StringLiteral>(AttrExp)) {
222 if (SLit->getString() ==
"*")
233 if (
const auto *OE = dyn_cast<CXXOperatorCallExpr>(AttrExp)) {
234 if (OE->getOperator() == OO_Exclaim) {
236 AttrExp = OE->getArg(0);
239 else if (
const auto *UO = dyn_cast<UnaryOperator>(AttrExp)) {
240 if (UO->getOpcode() == UO_LNot) {
254 if (
const auto *CE = dyn_cast<til::Cast>(E)) {
272 llvm::scope_exit Cleanup([&, RestoreClosure = VarsBeingTranslated.empty()
275 VarsBeingTranslated.erase(VD->getCanonicalDecl());
276 if (VarsBeingTranslated.empty())
277 LookupLocalVarExpr = RestoreClosure;
284 if (LookupLocalVarExpr) {
288 if (
const Expr *E = LookupLocalVarExpr(VD)) {
315 case Stmt::DeclRefExprClass:
317 case Stmt::CXXThisExprClass:
319 case Stmt::MemberExprClass:
321 case Stmt::ObjCIvarRefExprClass:
323 case Stmt::CallExprClass:
325 case Stmt::CXXMemberCallExprClass:
327 case Stmt::CXXOperatorCallExprClass:
329 case Stmt::UnaryOperatorClass:
331 case Stmt::BinaryOperatorClass:
332 case Stmt::CompoundAssignOperatorClass:
335 case Stmt::ArraySubscriptExprClass:
337 case Stmt::ConditionalOperatorClass:
338 return translateAbstractConditionalOperator(
340 case Stmt::BinaryConditionalOperatorClass:
341 return translateAbstractConditionalOperator(
345 case Stmt::ConstantExprClass:
347 case Stmt::ParenExprClass:
349 case Stmt::ExprWithCleanupsClass:
351 case Stmt::CXXBindTemporaryExprClass:
353 case Stmt::MaterializeTemporaryExprClass:
357 case Stmt::CharacterLiteralClass:
360 case Stmt::CXXNullPtrLiteralExprClass:
361 case Stmt::GNUNullExprClass:
363 case Stmt::CXXBoolLiteralExprClass:
365 case Stmt::IntegerLiteralClass: {
368 const llvm::APInt &
Value = IL->getValue();
369 if (BT->isSignedInteger())
371 else if (BT->isUnsignedInteger())
374 llvm_unreachable(
"Invalid integer type");
376 case Stmt::StringLiteralClass:
378 case Stmt::ObjCStringLiteralClass:
382 case Stmt::DeclStmtClass:
384 case Stmt::StmtExprClass:
389 if (
const auto *CE = dyn_cast<CastExpr>(S))
390 return translateCastExpr(CE, Ctx);
399 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
401 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
403 if (
const auto *DD = dyn_cast<DeclaratorDecl>(D)) {
404 if (
auto *TSI = DD->getTypeSourceInfo()) {
405 TypeLoc TL = TSI->getTypeLoc();
407 TL = RTL.getPointeeLoc();
410 TL = PTL.getPointeeLoc();
412 if (I < FPTL.getNumParams())
413 return FPTL.getParam(I);
420 if (
const auto *
V = dyn_cast<til::Variable>(E))
421 return V->clangDecl();
422 if (
const auto *Ph = dyn_cast<til::Phi>(E))
423 return Ph->clangDecl();
424 if (
const auto *P = dyn_cast<til::Project>(E))
425 return P->clangDecl();
426 if (
const auto *L = dyn_cast<til::LiteralPtr>(E))
427 return L->clangDecl();
435 return VD->getType();
437 if (
const auto *
C = dyn_cast<til::Cast>(E))
439 if (
const auto *AI = dyn_cast<til::ArrayIndex>(E)) {
443 if (
const auto *AT =
T->getAsArrayTypeUnsafe())
444 return AT->getElementType();
445 return T->getPointeeType();
447 if (
const auto *
C = dyn_cast<til::Call>(E))
448 if (
const CallExpr *CE =
C->clangCallExpr())
449 return CE->getType();
457 if (
const auto *
C = dyn_cast<til::Cast>(E))
464 return !
T.isNull() &&
T->isAnyPointerType();
467til::SExpr *SExprBuilder::translateDeclRefExpr(
const DeclRefExpr *DRE,
472 if (
const auto *PV = dyn_cast<ParmVarDecl>(VD)) {
473 unsigned I = PV->getFunctionScopeIndex();
474 const DeclContext *D = PV->getDeclContext();
478 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
479 Match = (FD->getCanonicalDecl() == Canonical);
480 else if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
481 Match = (MD->getCanonicalDecl() == Canonical);
485 llvm_unreachable(
"ParmVarDecl does not belong to current declaration");
489 if (
const Expr *
const *FunArgs =
490 dyn_cast<const Expr *const *>(Ctx->
FunArgs)) {
491 assert(I < Ctx->NumArgs);
505 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
510 const auto *IFD = dyn_cast<IndirectFieldDecl>(VD);
512 VD = IFD->getAnonField();
519 if (
const auto *FD = dyn_cast<FieldDecl>(VD); FD && Ctx && Ctx->
SelfArg) {
522 assert((!IFD || !IFD->getVarDecl()) &&
523 "non-member IndirectFieldDecl should be a MemberExpr");
527 til::SExpr *E = translateFieldOwner(Owner, Ctx,
Found);
530 for (
const NamedDecl *ND : IFD->chain().drop_back())
532 til::Project *P = translateProject(E, FD);
539 return new (Arena) til::LiteralPtr(VD);
550til::SExpr *SExprBuilder::translateFieldOwner(
const RecordDecl *Owner,
555 const auto *SelfArg = dyn_cast_if_present<const Expr *>(Ctx->
SelfArg);
557 return translateCXXThisExpr(
nullptr, Ctx);
559 for (
const Expr *E = SelfArg;;) {
562 const Expr *Inner = E->IgnoreParenImpCasts();
568 T = AT->getElementType();
575 const auto *CRD = dyn_cast<CXXRecordDecl>(RD);
576 const auto *COwner = dyn_cast<CXXRecordDecl>(Owner);
577 if (CRD && COwner && CRD->hasDefinition() && !CRD->isDependentType() &&
578 CRD->isDerivedFrom(COwner)) {
584 const auto *UO = dyn_cast<UnaryOperator>(Inner);
587 if (!UO || UO->getOpcode() != UO_AddrOf)
589 E = UO->getSubExpr();
590 }
else if (
const auto *ME = dyn_cast<MemberExpr>(Inner)) {
592 }
else if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(Inner)) {
594 }
else if (UO && UO->getOpcode() == UO_Deref) {
595 E = UO->getSubExpr();
604 const ValueDecl *D) {
605 til::SExpr *E =
new (Arena) til::SApply(BE);
606 til::Project *P =
new (Arena) til::Project(E, D);
612til::SExpr *SExprBuilder::translateCXXThisExpr(
const CXXThisExpr *TE,
616 if (
const auto *SelfArg = dyn_cast<const Expr *>(Ctx->
SelfArg))
621 assert(SelfVar &&
"We have no variable for 'this'!");
630 if (OverriddenMethods.begin() == OverriddenMethods.end())
633 D = *OverriddenMethods.begin();
638til::SExpr *SExprBuilder::translateMemberExpr(
const MemberExpr *ME,
643 if (
const auto *VD = dyn_cast<CXXMethodDecl>(D))
646 return translateProject(BE, D);
649til::SExpr *SExprBuilder::translateObjCIVarRefExpr(
const ObjCIvarRefExpr *IVRE,
653 return translateProject(BE, D);
656til::SExpr *SExprBuilder::translateCallExpr(
const CallExpr *CE,
659 if (CapabilityExprMode) {
661 if (
const auto *D = dyn_cast_or_null<NamedDecl>(CE->
getCalleeDecl())) {
662 const NamedDecl *AttrD = D;
663 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
665 if (
const auto *At = AttrD->
getAttr<LockReturnedAttr>()) {
667 LRCallCtx.AttrDecl = D;
668 LRCallCtx.SelfArg = SelfE;
671 LRCallCtx.SelfArg = ME->
getBase();
673 LRCallCtx.FunArgs = CE->
getArgs();
674 return const_cast<til::SExpr *
>(
684 for (
const auto *Arg : CE->
arguments()) {
686 E =
new (Arena) til::Apply(E, A);
688 return new (Arena) til::Call(E, CE);
691til::SExpr *SExprBuilder::translateCXXMemberCallExpr(
693 if (CapabilityExprMode) {
708til::SExpr *SExprBuilder::translateCXXOperatorCallExpr(
710 if (CapabilityExprMode) {
713 if (k == OO_Star || k == OO_Arrow) {
722til::SExpr *SExprBuilder::translateUnaryOperator(
const UnaryOperator *UO,
729 return new (Arena) til::Undefined(UO);
732 if (CapabilityExprMode) {
734 if (
const auto *DRE = dyn_cast<DeclRefExpr>(UO->
getSubExpr())) {
740 const ValueDecl *D = DRE->
getDecl();
741 if (
const auto *IFD = dyn_cast<IndirectFieldDecl>(D))
742 D = IFD->getAnonField();
743 auto *W =
new (Arena) til::Wildcard();
744 return new (Arena) til::Project(W, D);
771 return new (Arena) til::Undefined(UO);
773 return new (Arena) til::Undefined(UO);
777 const BinaryOperator *BO,
782 return new (Arena) til::BinaryOp(Op, E1, E0);
784 return new (Arena) til::BinaryOp(Op, E0, E1);
788 const BinaryOperator *BO,
791 const Expr *LHS = BO->
getLHS();
792 const Expr *RHS = BO->
getRHS();
796 const ValueDecl *VD =
nullptr;
797 til::SExpr *CV =
nullptr;
798 if (
const auto *DRE = dyn_cast<DeclRefExpr>(LHS)) {
800 CV = lookupVarDecl(VD);
804 til::SExpr *Arg = CV ? CV :
new (Arena) til::Load(E0);
805 E1 =
new (Arena) til::BinaryOp(Op, Arg, E1);
806 E1 = addStatement(E1,
nullptr, VD);
809 return updateVarDecl(VD, E1);
810 return new (Arena) til::Store(E0, E1);
813til::SExpr *SExprBuilder::translateBinaryOperator(
const BinaryOperator *BO,
818 return new (Arena) til::Undefined(BO);
820 case BO_Mul:
return translateBinOp(
til::BOP_Mul, BO, Ctx);
821 case BO_Div:
return translateBinOp(
til::BOP_Div, BO, Ctx);
822 case BO_Rem:
return translateBinOp(
til::BOP_Rem, BO, Ctx);
823 case BO_Add:
return translateBinOp(
til::BOP_Add, BO, Ctx);
824 case BO_Sub:
return translateBinOp(
til::BOP_Sub, BO, Ctx);
825 case BO_Shl:
return translateBinOp(
til::BOP_Shl, BO, Ctx);
826 case BO_Shr:
return translateBinOp(
til::BOP_Shr, BO, Ctx);
827 case BO_LT:
return translateBinOp(
til::BOP_Lt, BO, Ctx);
828 case BO_GT:
return translateBinOp(
til::BOP_Lt, BO, Ctx,
true);
829 case BO_LE:
return translateBinOp(
til::BOP_Leq, BO, Ctx);
830 case BO_GE:
return translateBinOp(
til::BOP_Leq, BO, Ctx,
true);
831 case BO_EQ:
return translateBinOp(
til::BOP_Eq, BO, Ctx);
832 case BO_NE:
return translateBinOp(
til::BOP_Neq, BO, Ctx);
833 case BO_Cmp:
return translateBinOp(
til::BOP_Cmp, BO, Ctx);
840 case BO_Assign:
return translateBinAssign(
til::BOP_Eq, BO, Ctx,
true);
841 case BO_MulAssign:
return translateBinAssign(
til::BOP_Mul, BO, Ctx);
842 case BO_DivAssign:
return translateBinAssign(
til::BOP_Div, BO, Ctx);
843 case BO_RemAssign:
return translateBinAssign(
til::BOP_Rem, BO, Ctx);
844 case BO_AddAssign:
return translateBinAssign(
til::BOP_Add, BO, Ctx);
845 case BO_SubAssign:
return translateBinAssign(
til::BOP_Sub, BO, Ctx);
846 case BO_ShlAssign:
return translateBinAssign(
til::BOP_Shl, BO, Ctx);
847 case BO_ShrAssign:
return translateBinAssign(
til::BOP_Shr, BO, Ctx);
848 case BO_AndAssign:
return translateBinAssign(
til::BOP_BitAnd, BO, Ctx);
849 case BO_XorAssign:
return translateBinAssign(
til::BOP_BitXor, BO, Ctx);
850 case BO_OrAssign:
return translateBinAssign(
til::BOP_BitOr, BO, Ctx);
856 return new (Arena) til::Undefined(BO);
863 case CK_LValueToRValue: {
864 if (
const auto *DRE = dyn_cast<DeclRefExpr>(CE->
getSubExpr())) {
865 til::SExpr *E0 = lookupVarDecl(DRE->
getDecl());
874 case CK_ArrayToPointerDecay:
880 case CK_DerivedToBase:
881 case CK_UncheckedDerivedToBase:
882 case CK_FunctionToPointerDecay: {
889 if (CapabilityExprMode)
897SExprBuilder::translateArraySubscriptExpr(
const ArraySubscriptExpr *E,
901 return new (Arena) til::ArrayIndex(E0, E1);
905SExprBuilder::translateAbstractConditionalOperator(
910 return new (Arena) til::IfThenElse(
C,
T, E);
914SExprBuilder::translateDeclStmt(
const DeclStmt *S,
CallingContext *Ctx) {
916 for (
auto *I : DGrp) {
917 if (
auto *VD = dyn_cast_or_null<VarDecl>(I)) {
918 Expr *E = VD->getInit();
924 return addVarDecl(VD, SE);
933til::SExpr *SExprBuilder::translateStmtExpr(
const StmtExpr *SE,
938 return CS->
body_empty() ?
new (Arena) til::Undefined(SE)
947 const ValueDecl *VD) {
951 E =
new (Arena) til::Variable(E, VD);
952 CurrentInstructions.push_back(E);
959til::SExpr *SExprBuilder::lookupVarDecl(
const ValueDecl *VD) {
960 auto It = LVarIdxMap.find(VD);
961 if (It != LVarIdxMap.end()) {
962 assert(CurrentLVarMap[It->second].first == VD);
963 return CurrentLVarMap[It->second].second;
972 if (
auto *
V = dyn_cast<til::Variable>(E)) {
981 LVarIdxMap.insert(std::make_pair(VD, CurrentLVarMap.size()));
982 CurrentLVarMap.makeWritable();
983 CurrentLVarMap.push_back(std::make_pair(VD, E));
990 auto It = LVarIdxMap.find(VD);
991 if (It == LVarIdxMap.end()) {
992 til::SExpr *
Ptr =
new (Arena) til::LiteralPtr(VD);
993 til::SExpr *St =
new (Arena) til::Store(Ptr, E);
996 CurrentLVarMap.makeWritable();
997 CurrentLVarMap.elem(It->second).second = E;
1004void SExprBuilder::makePhiNodeVar(
unsigned i,
unsigned NPreds,
til::SExpr *E) {
1005 unsigned ArgIndex = CurrentBlockInfo->ProcessedPredecessors;
1006 assert(ArgIndex > 0 && ArgIndex < NPreds);
1008 til::SExpr *CurrE = CurrentLVarMap[i].second;
1009 if (CurrE->
block() == CurrentBB) {
1012 auto *Ph = dyn_cast<til::Phi>(CurrE);
1013 assert(Ph &&
"Expecting Phi node.");
1015 Ph->values()[ArgIndex] = E;
1021 til::Phi *Ph =
new (Arena) til::Phi(Arena, NPreds);
1023 for (
unsigned PIdx = 0; PIdx < ArgIndex; ++PIdx)
1024 Ph->
values()[PIdx] = CurrE;
1026 Ph->
values()[ArgIndex] = E;
1034 CurrentArguments.push_back(Ph);
1036 IncompleteArgs.push_back(Ph);
1038 CurrentLVarMap.makeWritable();
1039 CurrentLVarMap.elem(i).second = Ph;
1044void SExprBuilder::mergeEntryMap(LVarDefinitionMap Map) {
1045 assert(CurrentBlockInfo &&
"Not processing a block!");
1047 if (!CurrentLVarMap.valid()) {
1049 CurrentLVarMap = std::move(Map);
1052 if (CurrentLVarMap.sameAs(Map))
1055 unsigned NPreds = CurrentBB->numPredecessors();
1056 unsigned ESz = CurrentLVarMap.size();
1057 unsigned MSz = Map.size();
1058 unsigned Sz = std::min(ESz, MSz);
1060 for (
unsigned i = 0; i < Sz; ++i) {
1061 if (CurrentLVarMap[i].first != Map[i].first) {
1063 CurrentLVarMap.makeWritable();
1064 CurrentLVarMap.downsize(i);
1067 if (CurrentLVarMap[i].second != Map[i].second)
1068 makePhiNodeVar(i, NPreds, Map[i].second);
1071 CurrentLVarMap.makeWritable();
1072 CurrentLVarMap.downsize(Map.size());
1078void SExprBuilder::mergeEntryMapBackEdge() {
1087 assert(CurrentBlockInfo &&
"Not processing a block!");
1089 if (CurrentBlockInfo->HasBackEdges)
1091 CurrentBlockInfo->HasBackEdges =
true;
1093 CurrentLVarMap.makeWritable();
1094 unsigned Sz = CurrentLVarMap.size();
1095 unsigned NPreds = CurrentBB->numPredecessors();
1097 for (
unsigned i = 0; i < Sz; ++i)
1098 makePhiNodeVar(i, NPreds,
nullptr);
1104void SExprBuilder::mergePhiNodesBackEdge(
const CFGBlock *Blk) {
1106 unsigned ArgIndex = BBInfo[Blk->
getBlockID()].ProcessedPredecessors;
1107 assert(ArgIndex > 0 && ArgIndex < BB->numPredecessors());
1109 for (til::SExpr *PE : BB->
arguments()) {
1110 auto *Ph = dyn_cast_or_null<til::Phi>(PE);
1111 assert(Ph &&
"Expecting Phi Node.");
1112 assert(Ph->
values()[ArgIndex] ==
nullptr &&
"Wrong index for back edge.");
1114 til::SExpr *E = lookupVarDecl(Ph->
clangDecl());
1115 assert(E &&
"Couldn't find local variable for Phi node.");
1116 Ph->
values()[ArgIndex] = E;
1120void SExprBuilder::enterCFG(CFG *Cfg,
const NamedDecl *D,
1121 const CFGBlock *
First) {
1124 Scfg =
new (Arena) til::SCFG(Arena, NBlocks);
1127 BBInfo.resize(NBlocks);
1128 BlockMap.resize(NBlocks,
nullptr);
1130 for (
auto *B : *Cfg) {
1131 auto *BB =
new (Arena) til::BasicBlock(Arena);
1133 BlockMap[B->getBlockID()] = BB;
1139 for (
auto *Pm : Parms) {
1140 QualType
T = Pm->getType();
1141 if (!
T.isTrivialType(Pm->getASTContext()))
1146 til::SExpr *Lp =
new (Arena) til::LiteralPtr(Pm);
1147 til::SExpr *Ld =
new (Arena) til::Load(Lp);
1148 til::SExpr *
V = addStatement(Ld,
nullptr, Pm);
1153void SExprBuilder::enterCFGBlock(
const CFGBlock *B) {
1156 CurrentBB->reservePredecessors(B->
pred_size());
1157 Scfg->add(CurrentBB);
1166void SExprBuilder::handlePredecessor(
const CFGBlock *Pred) {
1169 CurrentBB->addPredecessor(BlockMap[Pred->
getBlockID()]);
1170 BlockInfo *PredInfo = &BBInfo[Pred->
getBlockID()];
1171 assert(PredInfo->UnprocessedSuccessors > 0);
1173 if (--PredInfo->UnprocessedSuccessors == 0)
1174 mergeEntryMap(std::move(PredInfo->ExitMap));
1176 mergeEntryMap(PredInfo->ExitMap.clone());
1178 ++CurrentBlockInfo->ProcessedPredecessors;
1181void SExprBuilder::handlePredecessorBackEdge(
const CFGBlock *Pred) {
1182 mergeEntryMapBackEdge();
1185void SExprBuilder::enterCFGBlockBody(
const CFGBlock *B) {
1188 CurrentBB->arguments().reserve(
1189 static_cast<unsigned>(CurrentArguments.size()), Arena);
1190 for (
auto *A : CurrentArguments)
1191 CurrentBB->addArgument(A);
1194void SExprBuilder::handleStatement(
const Stmt *S) {
1199void SExprBuilder::handleDestructorCall(
const VarDecl *VD,
1200 const CXXDestructorDecl *DD) {
1201 til::SExpr *Sf =
new (Arena) til::LiteralPtr(VD);
1202 til::SExpr *Dr =
new (Arena) til::LiteralPtr(DD);
1203 til::SExpr *Ap =
new (Arena) til::Apply(Dr, Sf);
1204 til::SExpr *E =
new (Arena) til::Call(Ap);
1205 addStatement(E,
nullptr);
1208void SExprBuilder::exitCFGBlockBody(
const CFGBlock *B) {
1209 CurrentBB->instructions().reserve(
1210 static_cast<unsigned>(CurrentInstructions.size()), Arena);
1211 for (
auto *
V : CurrentInstructions)
1212 CurrentBB->addInstruction(
V);
1221 auto *Tm =
new (Arena) til::Goto(BB, Idx);
1222 CurrentBB->setTerminator(Tm);
1230 auto *Tm =
new (Arena) til::Branch(
C, BB1, BB2);
1231 CurrentBB->setTerminator(Tm);
1235void SExprBuilder::handleSuccessor(
const CFGBlock *Succ) {
1236 ++CurrentBlockInfo->UnprocessedSuccessors;
1239void SExprBuilder::handleSuccessorBackEdge(
const CFGBlock *Succ) {
1240 mergePhiNodesBackEdge(Succ);
1241 ++BBInfo[Succ->
getBlockID()].ProcessedPredecessors;
1244void SExprBuilder::exitCFGBlock(
const CFGBlock *B) {
1245 CurrentArguments.clear();
1246 CurrentInstructions.clear();
1247 CurrentBlockInfo->ExitMap = std::move(CurrentLVarMap);
1248 CurrentBB =
nullptr;
1249 CurrentBlockInfo =
nullptr;
1252void SExprBuilder::exitCFG(
const CFGBlock *
Last) {
1253 for (
auto *Ph : IncompleteArgs) {
1258 CurrentArguments.clear();
1259 CurrentInstructions.clear();
1260 IncompleteArgs.clear();
1275 llvm::BumpPtrAllocator Bpa;
1279 TILPrinter::print(Scfg, llvm::errs());
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::Expr interface and subclasses for C++ expressions.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines an enumeration for C++ overloaded operators.
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
Defines various enumerations that describe declaration and type specifiers.
static bool isIncompletePhi(const til::SExpr *E)
static const MemberExpr * getFunPtrFieldCallee(const CallExpr *CE, const NamedDecl *D)
If CE calls through a function pointer field D, return the member access through which the field was ...
SExprBuilder::CallingContext CallingContext
static const ParmVarDecl * getCanonicalParamDecl(const Decl *D, unsigned I)
Helper to extract the canonical parameter declaration from a function or function pointer.
static QualType getSExprType(const til::SExpr *E)
static const ValueDecl * getValueDeclFromSExpr(const til::SExpr *E)
static void maybeUpdateVD(til::SExpr *E, const ValueDecl *VD)
static bool hasAnyPointerType(const til::SExpr *E)
static const CXXMethodDecl * getFirstVirtualDecl(const CXXMethodDecl *D)
static std::pair< StringRef, bool > classifyCapability(const TypeDecl &TD)
static constexpr std::pair< StringRef, bool > ClassifyCapabilityFallback
C Language Family Type Representation.
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
succ_iterator succ_begin()
unsigned pred_size() const
const Stmt * getTerminatorCondition(bool StripParens=true) const
unsigned getBlockID() const
unsigned succ_size() const
unsigned getNumBlockIDs() const
Returns the total number of BlockIDs allocated (which start at 0).
CXXMethodDecl * getMethodDecl() const
Retrieve the declaration of the called method.
Expr * getImplicitObjectArgument() const
Retrieve the implicit object argument for the member call.
Represents a static or instance method of a struct/union/class.
overridden_method_range overridden_methods() const
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Expr ** getArgs()
Retrieve the call arguments.
CastKind getCastKind() const
const DeclGroupRef getDeclGroup() const
Decl - This represents one declaration (or definition), e.g.
ASTContext & getASTContext() const LLVM_READONLY
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
This represents one expression.
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
This represents a decl that may have a name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
NamedDecl * getMostRecentDecl()
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
ObjCIvarDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this field.
const Expr * getBase() const
Represents a parameter to a function.
Wrapper for source info for pointers.
A (possibly-)qualified type.
CompoundStmt * getSubStmt()
Stmt - This represents one statement.
StmtClass getStmtClass() const
Represents a declaration of a type.
Base wrapper for a particular "section" of type source info.
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isPointerType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isPointerOrReferenceType() const
bool isAnyPointerType() const
const T * getAs() const
Member-template getAs<specific type>'.
Expr * getSubExpr() const
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.
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
const til::SExpr * sexpr() const
CapabilityExpr translateAttrExpr(const Expr *AttrExp, const NamedDecl *D, const Expr *DeclExp, til::SExpr *Self=nullptr)
Translate a clang expression in an attribute to a til::SExpr.
til::SExpr * translate(const Stmt *S, CallingContext *Ctx)
til::SExpr * lookupStmt(const Stmt *S)
til::SCFG * buildCFG(CFGWalker &Walker)
til::SExpr * translateVariable(const VarDecl *VD, CallingContext *Ctx)
til::BasicBlock * lookupBlock(const CFGBlock *B)
const InstrArray & arguments() const
void reserveInstructions(unsigned Nins)
unsigned findPredecessorIndex(const BasicBlock *BB) const
Return the index of BB, or Predecessors.size if BB is not a predecessor.
A Literal pointer to an object allocated in memory.
const ValueDecl * clangDecl() const
Return the clang declaration of the variable for this Phi node, if any.
void setClangDecl(const ValueDecl *Cvd)
Set the clang variable associated with this Phi node.
const ValArray & values() const
Project a named slot from a C++ struct or class.
void setQualified(bool b)
An SCFG is a control-flow graph.
Base class for AST nodes in the typed intermediate language.
BasicBlock * block() const
Returns the block, if this is an instruction in a basic block, otherwise returns null.
void setValues(unsigned Sz, const T &C)
Placeholder for expressions that cannot be represented in the TIL.
Placeholder for a wildcard that matches any other expression.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
bool isTrivial(const SExpr *E)
void simplifyIncompleteArg(til::Phi *Ph)
TIL_BinaryOpcode
Opcode for binary arithmetic operations.
void printSCFG(CFGWalker &Walker)
std::string getSourceLiteralString(const Expr *CE)
Top level wrappers for InstallAPI frontend operations.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ Match
This is not an overload because the signature exactly matches an existing declaration.
bool isa(CodeGen::Address addr)
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
@ Result
The result type of a method or function.
const FunctionProtoType * T
CastKind
CastKind - The kind of operation required for a conversion.
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
U cast(CodeGen::Address addr)
Encapsulates the lexical context of a function call.
llvm::PointerUnion< const Expr *const *, til::SExpr * > FunArgs
const NamedDecl * AttrDecl
llvm::PointerUnion< const Expr *, til::SExpr * > SelfArg