File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3232,8 +3232,26 @@ Expr* ReverseModeVisitor::getStdInitListSizeExpr(const Expr* E) {
32323232 return Visit (EWC ->getSubExpr (), dfdx ());
32333233 }
32343234
3235+ // / Called in ShouldRecompute. In CUDA, to access a current thread/block id
3236+ // / we use functions that do not change the state of any variable, since no
3237+ // / point to store the value.
3238+ static bool isCUDABuiltInIndex (const Expr* E) {
3239+ const clang::Expr* B = E->IgnoreImplicit ();
3240+ if (const auto * pseudoE = llvm::dyn_cast<PseudoObjectExpr>(B)) {
3241+ if (const auto * opaqueE =
3242+ llvm::dyn_cast<OpaqueValueExpr>(pseudoE->getSemanticExpr (0 ))) {
3243+ const Expr* innerE = opaqueE->getSourceExpr ()->IgnoreImplicit ();
3244+ QualType innerT = innerE->getType ();
3245+ if (innerT.isConstQualified ())
3246+ return true ;
3247+ }
3248+ }
3249+ return false ;
3250+ }
3251+
32353252 bool ReverseModeVisitor::ShouldRecompute (const Expr* E) {
3236- return !(utils::ContainsFunctionCalls (E) || E->HasSideEffects (m_Context));
3253+ return !(utils::ContainsFunctionCalls (E) || E->HasSideEffects (m_Context)) ||
3254+ isCUDABuiltInIndex (E);
32373255 }
32383256
32393257 bool ReverseModeVisitor::UsefulToStoreGlobal (Expr* E) {
You can’t perform that action at this time.
0 commit comments