File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3207,8 +3207,26 @@ Expr* ReverseModeVisitor::getStdInitListSizeExpr(const Expr* E) {
32073207 return Visit (EWC ->getSubExpr (), dfdx ());
32083208 }
32093209
3210+ // / Called in ShouldRecompute. In CUDA, to access a current thread/block id
3211+ // / we use functions that do not change the state of any variable, since no
3212+ // / point to store the value.
3213+ static bool isCUDABuiltInIndex (const Expr* E) {
3214+ const clang::Expr* B = E->IgnoreImplicit ();
3215+ if (const auto * pseudoE = llvm::dyn_cast<PseudoObjectExpr>(B)) {
3216+ if (const auto * opaqueE =
3217+ llvm::dyn_cast<OpaqueValueExpr>(pseudoE->getSemanticExpr (0 ))) {
3218+ const Expr* innerE = opaqueE->getSourceExpr ()->IgnoreImplicit ();
3219+ QualType innerT = innerE->getType ();
3220+ if (innerT.isConstQualified ())
3221+ return true ;
3222+ }
3223+ }
3224+ return false ;
3225+ }
3226+
32103227 bool ReverseModeVisitor::ShouldRecompute (const Expr* E) {
3211- return !(utils::ContainsFunctionCalls (E) || E->HasSideEffects (m_Context));
3228+ return !(utils::ContainsFunctionCalls (E) || E->HasSideEffects (m_Context)) ||
3229+ isCUDABuiltInIndex (E);
32123230 }
32133231
32143232 bool ReverseModeVisitor::UsefulToStoreGlobal (Expr* E) {
You can’t perform that action at this time.
0 commit comments