@@ -7776,14 +7776,27 @@ class NoLoopStepChecker final : public ConstStmtVisitor<NoLoopStepChecker> {
7776
7776
class XteamRedExprChecker final : public ConstStmtVisitor<XteamRedExprChecker> {
7777
7777
public:
7778
7778
XteamRedExprChecker (const CodeGenModule::XteamRedVarMap &RVM)
7779
- : RedMap{ RVM} , IsSupported{ true } {}
7779
+ : RedMap( RVM) , IsSupported( true ) {}
7780
7780
XteamRedExprChecker () = delete ;
7781
7781
7782
7782
bool isSupported () const { return IsSupported; }
7783
7783
7784
7784
void VisitStmt (const Stmt *S) {
7785
7785
if (!S)
7786
7786
return ;
7787
+
7788
+ auto isExprXteamRedVar = [this ](const Expr *E) {
7789
+ if (!isa<DeclRefExpr>(E))
7790
+ return false ;
7791
+ auto *Decl = cast<DeclRefExpr>(E)->getDecl ();
7792
+ if (!isa<VarDecl>(Decl))
7793
+ return false ;
7794
+ auto *VD = cast<VarDecl>(Decl);
7795
+ if (RedMap.find (VD) != RedMap.end ())
7796
+ return true ;
7797
+ return false ;
7798
+ };
7799
+
7787
7800
if (isa<BinaryOperator>(S)) {
7788
7801
const BinaryOperator *BinOpExpr = cast<BinaryOperator>(S);
7789
7802
// Even though we filtered out everything except the sum reduction
@@ -7793,19 +7806,7 @@ class XteamRedExprChecker final : public ConstStmtVisitor<XteamRedExprChecker> {
7793
7806
// red-var = red-var + <expr> and red-var = <expr> + red-var.
7794
7807
// We punt on anything more complex.
7795
7808
7796
- auto isExprXteamRedVar = [this ](Expr *E) {
7797
- if (!isa<DeclRefExpr>(E))
7798
- return false ;
7799
- auto *Decl = cast<DeclRefExpr>(E)->getDecl ();
7800
- if (!isa<VarDecl>(Decl))
7801
- return false ;
7802
- auto *VD = cast<VarDecl>(Decl);
7803
- if (RedMap.find (VD) != RedMap.end ())
7804
- return true ;
7805
- return false ;
7806
- };
7807
-
7808
- Expr *LHS = BinOpExpr->getLHS ()->IgnoreImpCasts ();
7809
+ const Expr *LHS = BinOpExpr->getLHS ()->IgnoreImpCasts ();
7809
7810
if (isExprXteamRedVar (LHS)) {
7810
7811
auto BinOpExprOp = BinOpExpr->getOpcode ();
7811
7812
if (BinOpExprOp != BO_Assign && BinOpExprOp != BO_AddAssign &&
@@ -7816,33 +7817,44 @@ class XteamRedExprChecker final : public ConstStmtVisitor<XteamRedExprChecker> {
7816
7817
// We only need to further examine the assignment case.
7817
7818
// If += or +, Codegen will extract the rhs.
7818
7819
if (BinOpExpr->getOpcode () == BO_Assign) {
7819
- Expr *RHS = BinOpExpr->getRHS ()->IgnoreImpCasts ();
7820
+ const Expr *RHS = BinOpExpr->getRHS ()->IgnoreImpCasts ();
7820
7821
if (!isa<BinaryOperator>(RHS)) {
7821
7822
IsSupported = false ;
7822
7823
return ;
7823
7824
}
7824
- BinaryOperator *BinOpRHS = cast<BinaryOperator>(RHS);
7825
+ const BinaryOperator *BinOpRHS = cast<BinaryOperator>(RHS);
7825
7826
if (BinOpRHS->getOpcode () != BO_Add) {
7826
7827
IsSupported = false ;
7827
7828
return ;
7828
7829
}
7829
- Expr *LHSBinOpRHS = BinOpRHS->getLHS ()->IgnoreImpCasts ();
7830
- Expr *RHSBinOpRHS = BinOpRHS->getRHS ()->IgnoreImpCasts ();
7830
+ const Expr *LHSBinOpRHS = BinOpRHS->getLHS ()->IgnoreImpCasts ();
7831
+ const Expr *RHSBinOpRHS = BinOpRHS->getRHS ()->IgnoreImpCasts ();
7831
7832
if (!isExprXteamRedVar (LHSBinOpRHS) &&
7832
7833
!isExprXteamRedVar (RHSBinOpRHS)) {
7833
7834
IsSupported = false ;
7834
7835
return ;
7835
7836
}
7836
7837
}
7837
7838
}
7839
+ } else if (isa<UnaryOperator>(S)) {
7840
+ const Expr *UnaryOpExpr =
7841
+ cast<UnaryOperator>(S)->getSubExpr ()->IgnoreImpCasts ();
7842
+ // Xteam reduction does not handle unary operators currently.
7843
+ if (isExprXteamRedVar (UnaryOpExpr)) {
7844
+ IsSupported = false ;
7845
+ return ;
7846
+ }
7838
7847
}
7848
+
7839
7849
for (const Stmt *Child : S->children ())
7840
7850
if (Child)
7841
7851
Visit (Child);
7842
7852
}
7843
7853
7844
7854
private:
7855
+ // / Map of reduction variables for this directive.
7845
7856
const CodeGenModule::XteamRedVarMap &RedMap;
7857
+ // / Set to false if codegen does not support the reduction expression.
7846
7858
bool IsSupported;
7847
7859
};
7848
7860
0 commit comments