@@ -198,10 +198,20 @@ TBRAnalyzer::VarData::VarData(QualType QT, const ASTContext& C,
198198 const auto * recordDecl = recordType->getDecl ();
199199 auto & newArrMap = m_Val.m_ArrData ;
200200 newArrMap = std::unique_ptr<ArrMap>(new ArrMap ());
201- for (const auto * field : recordDecl->fields ()) {
202- const auto varType = field->getType ();
203- (*newArrMap)[getProfileID (field)] = VarData (varType, C);
204- }
201+
202+ // FIXME: For some reason if a variable is of kokkos-type we start creating
203+ // infinite amount of VarData objects.
204+ bool isInKokkosNS = false ;
205+ if (const auto * ns =
206+ llvm::dyn_cast<clang::NamespaceDecl>(recordDecl->getDeclContext ()))
207+ if (ns->getName () == " Kokkos" )
208+ isInKokkosNS = true ;
209+
210+ if (!isInKokkosNS)
211+ for (const auto * field : recordDecl->fields ()) {
212+ const auto varType = field->getType ();
213+ (*newArrMap)[getProfileID (field)] = VarData (varType, C);
214+ }
205215 }
206216}
207217
@@ -250,11 +260,13 @@ void TBRAnalyzer::addVar(const clang::VarDecl* VD, bool forceNonRefType) {
250260 varType = arrayParam->getOriginalType ();
251261 else
252262 varType = VD ->getType ();
263+
253264 // If varType represents auto or auto*, get the type of init.
254265 if (utils::IsAutoOrAutoPtrType (varType))
255266 varType = VD ->getInit ()->getType ();
256267
257- curBranch[VD ] = VarData (varType, m_Context, forceNonRefType);
268+ curBranch[VD ] =
269+ VarData (varType, m_AnalysisDC->getASTContext (), forceNonRefType);
258270}
259271
260272void TBRAnalyzer::markLocation (const clang::Expr* E) {
@@ -301,15 +313,11 @@ TBRAnalyzer::getVarDataFromDecl(const clang::VarDecl* VD) {
301313}
302314
303315void TBRAnalyzer::Analyze (const FunctionDecl* FD ) {
304- // Build the CFG (control-flow graph) of FD.
305- clang::CFG ::BuildOptions Options;
306- m_CFG = clang::CFG::buildCFG (FD , FD ->getBody (), &m_Context, Options);
307-
308- m_BlockData.resize (m_CFG->size ());
309- m_BlockPassCounter.resize (m_CFG->size (), 0 );
316+ m_BlockData.resize (m_AnalysisDC->getCFG ()->size ());
317+ m_BlockPassCounter.resize (m_AnalysisDC->getCFG ()->size (), 0 );
310318
311319 // Set current block ID to the ID of entry the block.
312- auto * entry = &m_CFG ->getEntry ();
320+ auto * entry = &m_AnalysisDC-> getCFG () ->getEntry ();
313321 m_CurBlockID = entry->getBlockID ();
314322 m_BlockData[m_CurBlockID] = std::unique_ptr<VarsData>(new VarsData ());
315323
@@ -319,7 +327,8 @@ void TBRAnalyzer::Analyze(const FunctionDecl* FD) {
319327 if (MD && !MD ->isStatic ()) {
320328 const Type* recordType = MD ->getParent ()->getTypeForDecl ();
321329 VarData& thisData = getCurBlockVarsData ()[nullptr ];
322- thisData = VarData (QualType::getFromOpaquePtr (recordType), m_Context);
330+ thisData = VarData (QualType::getFromOpaquePtr (recordType),
331+ m_AnalysisDC->getASTContext ());
323332 // We have to set all pointer/reference parameters to tbr
324333 // since method pullbacks aren't supposed to change objects.
325334 setIsRequired (thisData);
@@ -347,7 +356,7 @@ void TBRAnalyzer::Analyze(const FunctionDecl* FD) {
347356 LLVM_DEBUG (llvm::dbgs () << " successor: " << succ->getBlockID () << " \n " );
348357 }
349358
350- clang::SourceManager& SM = m_Context .getSourceManager ();
359+ clang::SourceManager& SM = m_AnalysisDC-> getASTContext () .getSourceManager ();
351360 for (SourceLocation Loc : m_TBRLocs) {
352361 unsigned line = SM .getPresumedLoc (Loc).getLine ();
353362 unsigned column = SM .getPresumedLoc (Loc).getColumn ();
@@ -415,7 +424,7 @@ void TBRAnalyzer::VisitCFGBlock(const CFGBlock& block) {
415424}
416425
417426CFGBlock* TBRAnalyzer::getCFGBlockByID (unsigned ID ) {
418- return *(m_CFG ->begin () + ID );
427+ return *(m_AnalysisDC-> getCFG () ->begin () + ID );
419428}
420429
421430TBRAnalyzer::VarsData*
@@ -571,9 +580,11 @@ bool TBRAnalyzer::TraverseDeclStmt(DeclStmt* DS) {
571580 if (auto * VD = dyn_cast<VarDecl>(D)) {
572581 addVar (VD );
573582 if (clang::Expr* init = VD ->getInit ()) {
583+
574584 setMode (Mode::kMarkingMode );
575585 TraverseStmt (init);
576586 resetMode ();
587+
577588 auto & VDExpr = getCurBlockVarsData ()[VD ];
578589 // if the declared variable is ref type attach its VarData to the
579590 // VarData of the RHS variable.
@@ -622,9 +633,10 @@ bool TBRAnalyzer::TraverseBinaryOperator(BinaryOperator* BinOp) {
622633 // Multiplication results in a linear expression if and only if one of the
623634 // factors is constant.
624635 Expr::EvalResult dummy;
625- bool nonLinear =
626- !clad_compat::Expr_EvaluateAsConstantExpr (R, dummy, m_Context) &&
627- !clad_compat::Expr_EvaluateAsConstantExpr (L, dummy, m_Context);
636+ bool nonLinear = !clad_compat::Expr_EvaluateAsConstantExpr (
637+ R, dummy, m_AnalysisDC->getASTContext ()) &&
638+ !clad_compat::Expr_EvaluateAsConstantExpr (
639+ L, dummy, m_AnalysisDC->getASTContext ());
628640 if (nonLinear)
629641 startNonLinearMode ();
630642
@@ -637,8 +649,8 @@ bool TBRAnalyzer::TraverseBinaryOperator(BinaryOperator* BinOp) {
637649 // Division normally only results in a linear expression when the
638650 // denominator is constant.
639651 Expr::EvalResult dummy;
640- bool nonLinear =
641- ! clad_compat::Expr_EvaluateAsConstantExpr ( R, dummy, m_Context );
652+ bool nonLinear = ! clad_compat::Expr_EvaluateAsConstantExpr (
653+ R, dummy, m_AnalysisDC-> getASTContext () );
642654 if (nonLinear)
643655 startNonLinearMode ();
644656
@@ -663,8 +675,8 @@ bool TBRAnalyzer::TraverseBinaryOperator(BinaryOperator* BinOp) {
663675 // represents the same operation as 'x = x * y' ('x = x / y') and,
664676 // therefore, LHS has to be visited in kMarkingMode|kNonLinearMode.
665677 Expr::EvalResult dummy;
666- bool RisNotConst =
667- ! clad_compat::Expr_EvaluateAsConstantExpr ( R, dummy, m_Context );
678+ bool RisNotConst = ! clad_compat::Expr_EvaluateAsConstantExpr (
679+ R, dummy, m_AnalysisDC-> getASTContext () );
668680 if (RisNotConst)
669681 setMode (Mode::kMarkingMode | Mode::kNonLinearMode );
670682 TraverseStmt (L);
0 commit comments