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))
407 if (
const auto *
V = dyn_cast<til::Variable>(E))
408 return V->clangDecl();
409 if (
const auto *Ph = dyn_cast<til::Phi>(E))
410 return Ph->clangDecl();
411 if (
const auto *P = dyn_cast<til::Project>(E))
412 return P->clangDecl();
413 if (
const auto *L = dyn_cast<til::LiteralPtr>(E))
414 return L->clangDecl();
422 return VD->getType();
424 if (
const auto *
C = dyn_cast<til::Cast>(E))
426 if (
const auto *AI = dyn_cast<til::ArrayIndex>(E)) {
430 if (
const auto *AT =
T->getAsArrayTypeUnsafe())
431 return AT->getElementType();
432 return T->getPointeeType();
434 if (
const auto *
C = dyn_cast<til::Call>(E))
435 if (
const CallExpr *CE =
C->clangCallExpr())
436 return CE->getType();
444 if (
const auto *
C = dyn_cast<til::Cast>(E))
451 return !
T.isNull() &&
T->isAnyPointerType();
454til::SExpr *SExprBuilder::translateDeclRefExpr(
const DeclRefExpr *DRE,
459 if (
const auto *PV = dyn_cast<ParmVarDecl>(VD)) {
460 unsigned I = PV->getFunctionScopeIndex();
461 const DeclContext *D = PV->getDeclContext();
465 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
466 Match = (FD->getCanonicalDecl() == Canonical);
467 }
else if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
468 Match = (MD->getCanonicalDecl() == Canonical);
478 const auto *AttrPV = dyn_cast<ParmVarDecl>(Ctx->
AttrDecl);
480 PV->getFunctionScopeDepth() > AttrPV->getFunctionScopeDepth();
482 llvm_unreachable(
"ParmVarDecl does not belong to current declaration");
487 if (
const Expr *
const *FunArgs =
488 dyn_cast<const Expr *const *>(Ctx->
FunArgs)) {
489 assert(I < Ctx->NumArgs);
503 if (
const auto *VarD = dyn_cast<VarDecl>(VD))
508 const auto *IFD = dyn_cast<IndirectFieldDecl>(VD);
510 VD = IFD->getAnonField();
517 if (
const auto *FD = dyn_cast<FieldDecl>(VD); FD && Ctx && Ctx->
SelfArg) {
520 assert((!IFD || !IFD->getVarDecl()) &&
521 "non-member IndirectFieldDecl should be a MemberExpr");
525 til::SExpr *E = translateFieldOwner(Owner, Ctx,
Found);
528 for (
const NamedDecl *ND : IFD->chain().drop_back())
530 til::Project *P = translateProject(E, FD);
537 return new (Arena) til::LiteralPtr(VD);
548til::SExpr *SExprBuilder::translateFieldOwner(
const RecordDecl *Owner,
553 const auto *SelfArg = dyn_cast_if_present<const Expr *>(Ctx->
SelfArg);
555 return translateCXXThisExpr(
nullptr, Ctx);
557 for (
const Expr *E = SelfArg;;) {
560 const Expr *Inner = E->IgnoreParenImpCasts();
566 T = AT->getElementType();
573 const auto *CRD = dyn_cast<CXXRecordDecl>(RD);
574 const auto *COwner = dyn_cast<CXXRecordDecl>(Owner);
575 if (CRD && COwner && CRD->hasDefinition() && !CRD->isDependentType() &&
576 CRD->isDerivedFrom(COwner)) {
582 const auto *UO = dyn_cast<UnaryOperator>(Inner);
585 if (!UO || UO->getOpcode() != UO_AddrOf)
587 E = UO->getSubExpr();
588 }
else if (
const auto *ME = dyn_cast<MemberExpr>(Inner)) {
590 }
else if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(Inner)) {
592 }
else if (UO && UO->getOpcode() == UO_Deref) {
593 E = UO->getSubExpr();
602 const ValueDecl *D) {
603 til::SExpr *E =
new (Arena) til::SApply(BE);
604 til::Project *P =
new (Arena) til::Project(E, D);
610til::SExpr *SExprBuilder::translateCXXThisExpr(
const CXXThisExpr *TE,
614 if (
const auto *SelfArg = dyn_cast<const Expr *>(Ctx->
SelfArg))
619 assert(SelfVar &&
"We have no variable for 'this'!");
628 if (OverriddenMethods.begin() == OverriddenMethods.end())
631 D = *OverriddenMethods.begin();
636til::SExpr *SExprBuilder::translateMemberExpr(
const MemberExpr *ME,
641 if (
const auto *VD = dyn_cast<CXXMethodDecl>(D))
644 return translateProject(BE, D);
647til::SExpr *SExprBuilder::translateObjCIVarRefExpr(
const ObjCIvarRefExpr *IVRE,
651 return translateProject(BE, D);
654til::SExpr *SExprBuilder::translateCallExpr(
const CallExpr *CE,
657 if (CapabilityExprMode) {
659 if (
const auto *D = dyn_cast_or_null<NamedDecl>(CE->
getCalleeDecl())) {
660 const NamedDecl *AttrD = D;
661 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
663 if (
const auto *At = AttrD->
getAttr<LockReturnedAttr>()) {
665 LRCallCtx.AttrDecl = D;
666 LRCallCtx.SelfArg = SelfE;
669 LRCallCtx.SelfArg = ME->
getBase();
671 LRCallCtx.FunArgs = CE->
getArgs();
672 return const_cast<til::SExpr *
>(
682 for (
const auto *Arg : CE->
arguments()) {
684 E =
new (Arena) til::Apply(E, A);
686 return new (Arena) til::Call(E, CE);
689til::SExpr *SExprBuilder::translateCXXMemberCallExpr(
691 if (CapabilityExprMode) {
706til::SExpr *SExprBuilder::translateCXXOperatorCallExpr(
708 if (CapabilityExprMode) {
711 if (k == OO_Star || k == OO_Arrow) {
720til::SExpr *SExprBuilder::translateUnaryOperator(
const UnaryOperator *UO,
727 return new (Arena) til::Undefined(UO);
730 if (CapabilityExprMode) {
732 if (
const auto *DRE = dyn_cast<DeclRefExpr>(UO->
getSubExpr())) {
738 const ValueDecl *D = DRE->
getDecl();
739 if (
const auto *IFD = dyn_cast<IndirectFieldDecl>(D))
740 D = IFD->getAnonField();
741 auto *W =
new (Arena) til::Wildcard();
742 return new (Arena) til::Project(W, D);
769 return new (Arena) til::Undefined(UO);
771 return new (Arena) til::Undefined(UO);
775 const BinaryOperator *BO,
780 return new (Arena) til::BinaryOp(Op, E1, E0);
782 return new (Arena) til::BinaryOp(Op, E0, E1);
786 const BinaryOperator *BO,
789 const Expr *LHS = BO->
getLHS();
790 const Expr *RHS = BO->
getRHS();
794 const ValueDecl *VD =
nullptr;
795 til::SExpr *CV =
nullptr;
796 if (
const auto *DRE = dyn_cast<DeclRefExpr>(LHS)) {
798 CV = lookupVarDecl(VD);
802 til::SExpr *Arg = CV ? CV :
new (Arena) til::Load(E0);
803 E1 =
new (Arena) til::BinaryOp(Op, Arg, E1);
804 E1 = addStatement(E1,
nullptr, VD);
807 return updateVarDecl(VD, E1);
808 return new (Arena) til::Store(E0, E1);
811til::SExpr *SExprBuilder::translateBinaryOperator(
const BinaryOperator *BO,
816 return new (Arena) til::Undefined(BO);
818 case BO_Mul:
return translateBinOp(
til::BOP_Mul, BO, Ctx);
819 case BO_Div:
return translateBinOp(
til::BOP_Div, BO, Ctx);
820 case BO_Rem:
return translateBinOp(
til::BOP_Rem, BO, Ctx);
821 case BO_Add:
return translateBinOp(
til::BOP_Add, BO, Ctx);
822 case BO_Sub:
return translateBinOp(
til::BOP_Sub, BO, Ctx);
823 case BO_Shl:
return translateBinOp(
til::BOP_Shl, BO, Ctx);
824 case BO_Shr:
return translateBinOp(
til::BOP_Shr, BO, Ctx);
825 case BO_LT:
return translateBinOp(
til::BOP_Lt, BO, Ctx);
826 case BO_GT:
return translateBinOp(
til::BOP_Lt, BO, Ctx,
true);
827 case BO_LE:
return translateBinOp(
til::BOP_Leq, BO, Ctx);
828 case BO_GE:
return translateBinOp(
til::BOP_Leq, BO, Ctx,
true);
829 case BO_EQ:
return translateBinOp(
til::BOP_Eq, BO, Ctx);
830 case BO_NE:
return translateBinOp(
til::BOP_Neq, BO, Ctx);
831 case BO_Cmp:
return translateBinOp(
til::BOP_Cmp, BO, Ctx);
838 case BO_Assign:
return translateBinAssign(
til::BOP_Eq, BO, Ctx,
true);
839 case BO_MulAssign:
return translateBinAssign(
til::BOP_Mul, BO, Ctx);
840 case BO_DivAssign:
return translateBinAssign(
til::BOP_Div, BO, Ctx);
841 case BO_RemAssign:
return translateBinAssign(
til::BOP_Rem, BO, Ctx);
842 case BO_AddAssign:
return translateBinAssign(
til::BOP_Add, BO, Ctx);
843 case BO_SubAssign:
return translateBinAssign(
til::BOP_Sub, BO, Ctx);
844 case BO_ShlAssign:
return translateBinAssign(
til::BOP_Shl, BO, Ctx);
845 case BO_ShrAssign:
return translateBinAssign(
til::BOP_Shr, BO, Ctx);
846 case BO_AndAssign:
return translateBinAssign(
til::BOP_BitAnd, BO, Ctx);
847 case BO_XorAssign:
return translateBinAssign(
til::BOP_BitXor, BO, Ctx);
848 case BO_OrAssign:
return translateBinAssign(
til::BOP_BitOr, BO, Ctx);
854 return new (Arena) til::Undefined(BO);
861 case CK_LValueToRValue: {
862 if (
const auto *DRE = dyn_cast<DeclRefExpr>(CE->
getSubExpr())) {
863 til::SExpr *E0 = lookupVarDecl(DRE->
getDecl());
872 case CK_ArrayToPointerDecay:
878 case CK_DerivedToBase:
879 case CK_UncheckedDerivedToBase:
880 case CK_FunctionToPointerDecay: {
887 if (CapabilityExprMode)
895SExprBuilder::translateArraySubscriptExpr(
const ArraySubscriptExpr *E,
899 return new (Arena) til::ArrayIndex(E0, E1);
903SExprBuilder::translateAbstractConditionalOperator(
908 return new (Arena) til::IfThenElse(
C,
T, E);
912SExprBuilder::translateDeclStmt(
const DeclStmt *S,
CallingContext *Ctx) {
914 for (
auto *I : DGrp) {
915 if (
auto *VD = dyn_cast_or_null<VarDecl>(I)) {
916 Expr *E = VD->getInit();
922 return addVarDecl(VD, SE);
931til::SExpr *SExprBuilder::translateStmtExpr(
const StmtExpr *SE,
936 return CS->
body_empty() ?
new (Arena) til::Undefined(SE)
945 const ValueDecl *VD) {
949 E =
new (Arena) til::Variable(E, VD);
950 CurrentInstructions.push_back(E);
957til::SExpr *SExprBuilder::lookupVarDecl(
const ValueDecl *VD) {
958 auto It = LVarIdxMap.find(VD);
959 if (It != LVarIdxMap.end()) {
960 assert(CurrentLVarMap[It->second].first == VD);
961 return CurrentLVarMap[It->second].second;
970 if (
auto *
V = dyn_cast<til::Variable>(E)) {
979 LVarIdxMap.insert(std::make_pair(VD, CurrentLVarMap.size()));
980 CurrentLVarMap.makeWritable();
981 CurrentLVarMap.push_back(std::make_pair(VD, E));
988 auto It = LVarIdxMap.find(VD);
989 if (It == LVarIdxMap.end()) {
990 til::SExpr *
Ptr =
new (Arena) til::LiteralPtr(VD);
991 til::SExpr *St =
new (Arena) til::Store(Ptr, E);
994 CurrentLVarMap.makeWritable();
995 CurrentLVarMap.elem(It->second).second = E;
1002void SExprBuilder::makePhiNodeVar(
unsigned i,
unsigned NPreds,
til::SExpr *E) {
1003 unsigned ArgIndex = CurrentBlockInfo->ProcessedPredecessors;
1004 assert(ArgIndex > 0 && ArgIndex < NPreds);
1006 til::SExpr *CurrE = CurrentLVarMap[i].second;
1007 if (CurrE->
block() == CurrentBB) {
1010 auto *Ph = dyn_cast<til::Phi>(CurrE);
1011 assert(Ph &&
"Expecting Phi node.");
1013 Ph->values()[ArgIndex] = E;
1019 til::Phi *Ph =
new (Arena) til::Phi(Arena, NPreds);
1021 for (
unsigned PIdx = 0; PIdx < ArgIndex; ++PIdx)
1022 Ph->
values()[PIdx] = CurrE;
1024 Ph->
values()[ArgIndex] = E;
1032 CurrentArguments.push_back(Ph);
1034 IncompleteArgs.push_back(Ph);
1036 CurrentLVarMap.makeWritable();
1037 CurrentLVarMap.elem(i).second = Ph;
1042void SExprBuilder::mergeEntryMap(LVarDefinitionMap Map) {
1043 assert(CurrentBlockInfo &&
"Not processing a block!");
1045 if (!CurrentLVarMap.valid()) {
1047 CurrentLVarMap = std::move(Map);
1050 if (CurrentLVarMap.sameAs(Map))
1053 unsigned NPreds = CurrentBB->numPredecessors();
1054 unsigned ESz = CurrentLVarMap.size();
1055 unsigned MSz = Map.size();
1056 unsigned Sz = std::min(ESz, MSz);
1058 for (
unsigned i = 0; i < Sz; ++i) {
1059 if (CurrentLVarMap[i].first != Map[i].first) {
1061 CurrentLVarMap.makeWritable();
1062 CurrentLVarMap.downsize(i);
1065 if (CurrentLVarMap[i].second != Map[i].second)
1066 makePhiNodeVar(i, NPreds, Map[i].second);
1069 CurrentLVarMap.makeWritable();
1070 CurrentLVarMap.downsize(Map.size());
1076void SExprBuilder::mergeEntryMapBackEdge() {
1085 assert(CurrentBlockInfo &&
"Not processing a block!");
1087 if (CurrentBlockInfo->HasBackEdges)
1089 CurrentBlockInfo->HasBackEdges =
true;
1091 CurrentLVarMap.makeWritable();
1092 unsigned Sz = CurrentLVarMap.size();
1093 unsigned NPreds = CurrentBB->numPredecessors();
1095 for (
unsigned i = 0; i < Sz; ++i)
1096 makePhiNodeVar(i, NPreds,
nullptr);
1102void SExprBuilder::mergePhiNodesBackEdge(
const CFGBlock *Blk) {
1104 unsigned ArgIndex = BBInfo[Blk->
getBlockID()].ProcessedPredecessors;
1105 assert(ArgIndex > 0 && ArgIndex < BB->numPredecessors());
1107 for (til::SExpr *PE : BB->
arguments()) {
1108 auto *Ph = dyn_cast_or_null<til::Phi>(PE);
1109 assert(Ph &&
"Expecting Phi Node.");
1110 assert(Ph->
values()[ArgIndex] ==
nullptr &&
"Wrong index for back edge.");
1112 til::SExpr *E = lookupVarDecl(Ph->
clangDecl());
1113 assert(E &&
"Couldn't find local variable for Phi node.");
1114 Ph->
values()[ArgIndex] = E;
1118void SExprBuilder::enterCFG(CFG *Cfg,
const NamedDecl *D,
1119 const CFGBlock *
First) {
1122 Scfg =
new (Arena) til::SCFG(Arena, NBlocks);
1125 BBInfo.resize(NBlocks);
1126 BlockMap.resize(NBlocks,
nullptr);
1128 for (
auto *B : *Cfg) {
1129 auto *BB =
new (Arena) til::BasicBlock(Arena);
1131 BlockMap[B->getBlockID()] = BB;
1137 for (
auto *Pm : Parms) {
1138 QualType
T = Pm->getType();
1139 if (!
T.isTrivialType(Pm->getASTContext()))
1144 til::SExpr *Lp =
new (Arena) til::LiteralPtr(Pm);
1145 til::SExpr *Ld =
new (Arena) til::Load(Lp);
1146 til::SExpr *
V = addStatement(Ld,
nullptr, Pm);
1151void SExprBuilder::enterCFGBlock(
const CFGBlock *B) {
1154 CurrentBB->reservePredecessors(B->
pred_size());
1155 Scfg->add(CurrentBB);
1164void SExprBuilder::handlePredecessor(
const CFGBlock *Pred) {
1167 CurrentBB->addPredecessor(BlockMap[Pred->
getBlockID()]);
1168 BlockInfo *PredInfo = &BBInfo[Pred->
getBlockID()];
1169 assert(PredInfo->UnprocessedSuccessors > 0);
1171 if (--PredInfo->UnprocessedSuccessors == 0)
1172 mergeEntryMap(std::move(PredInfo->ExitMap));
1174 mergeEntryMap(PredInfo->ExitMap.clone());
1176 ++CurrentBlockInfo->ProcessedPredecessors;
1179void SExprBuilder::handlePredecessorBackEdge(
const CFGBlock *Pred) {
1180 mergeEntryMapBackEdge();
1183void SExprBuilder::enterCFGBlockBody(
const CFGBlock *B) {
1186 CurrentBB->arguments().reserve(
1187 static_cast<unsigned>(CurrentArguments.size()), Arena);
1188 for (
auto *A : CurrentArguments)
1189 CurrentBB->addArgument(A);
1192void SExprBuilder::handleStatement(
const Stmt *S) {
1197void SExprBuilder::handleDestructorCall(
const VarDecl *VD,
1198 const CXXDestructorDecl *DD) {
1199 til::SExpr *Sf =
new (Arena) til::LiteralPtr(VD);
1200 til::SExpr *Dr =
new (Arena) til::LiteralPtr(DD);
1201 til::SExpr *Ap =
new (Arena) til::Apply(Dr, Sf);
1202 til::SExpr *E =
new (Arena) til::Call(Ap);
1203 addStatement(E,
nullptr);
1206void SExprBuilder::exitCFGBlockBody(
const CFGBlock *B) {
1207 CurrentBB->instructions().reserve(
1208 static_cast<unsigned>(CurrentInstructions.size()), Arena);
1209 for (
auto *
V : CurrentInstructions)
1210 CurrentBB->addInstruction(
V);
1219 auto *Tm =
new (Arena) til::Goto(BB, Idx);
1220 CurrentBB->setTerminator(Tm);
1228 auto *Tm =
new (Arena) til::Branch(
C, BB1, BB2);
1229 CurrentBB->setTerminator(Tm);
1233void SExprBuilder::handleSuccessor(
const CFGBlock *Succ) {
1234 ++CurrentBlockInfo->UnprocessedSuccessors;
1237void SExprBuilder::handleSuccessorBackEdge(
const CFGBlock *Succ) {
1238 mergePhiNodesBackEdge(Succ);
1239 ++BBInfo[Succ->
getBlockID()].ProcessedPredecessors;
1242void SExprBuilder::exitCFGBlock(
const CFGBlock *B) {
1243 CurrentArguments.clear();
1244 CurrentInstructions.clear();
1245 CurrentBlockInfo->ExitMap = std::move(CurrentLVarMap);
1246 CurrentBB =
nullptr;
1247 CurrentBlockInfo =
nullptr;
1250void SExprBuilder::exitCFG(
const CFGBlock *
Last) {
1251 for (
auto *Ph : IncompleteArgs) {
1256 CurrentArguments.clear();
1257 CurrentInstructions.clear();
1258 IncompleteArgs.clear();
1273 llvm::BumpPtrAllocator Bpa;
1277 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
bool isTranslationUnit() 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.
A (possibly-)qualified type.
CompoundStmt * getSubStmt()
Stmt - This represents one statement.
StmtClass getStmtClass() const
Represents a declaration of a type.
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