Skip to content

Commit

Permalink
Implement profiling for cm expressions
Browse files Browse the repository at this point in the history
Required for dependent expressions used as constant expressions.
  • Loading branch information
aus-intel authored and Anton Sidorenko committed Mar 2, 2022
1 parent 3a20f1e commit 25cbf42
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
4 changes: 4 additions & 0 deletions clang/include/clang/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2976,6 +2976,10 @@ class CMMemberExpr : public Expr {
child_range children() {
return child_range(SubExprs, SubExprs + NumSubExprs);
}

const_child_range children() const {
return const_child_range(SubExprs, SubExprs + NumSubExprs);
}
};

/// \brief Represent CM select member functions.
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/AST/ExprCM.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ class CMSizeExpr : public CMMemberExpr {
C.IntTy, VK_RValue),
Kind(SK), RParenLoc(RPLoc) {}

CMSizeExprKind getCMSizeKind() const { return Kind; }

bool isNElems() const { return Kind == SK_n_elems; }
bool isNRows() const { return Kind == SK_n_rows; }
bool isNCols() const { return Kind == SK_n_cols; }
Expand Down
15 changes: 10 additions & 5 deletions clang/lib/AST/StmtProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1131,23 +1131,28 @@ void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
}

void StmtProfiler::VisitCMSelectExpr(const CMSelectExpr *S) {
llvm_unreachable("not implemented yet");
VisitExpr(S);
ID.AddInteger(S->getSelectKind());
ID.AddInteger(S->getNumConstArgs());
}

void StmtProfiler::VisitCMBoolReductionExpr(const CMBoolReductionExpr *S) {
llvm_unreachable("not implemented yet");
VisitExpr(S);
ID.AddInteger(S->getBoolReductionKind());
}

void StmtProfiler::VisitCMFormatExpr(const CMFormatExpr *S) {
llvm_unreachable("not implemented yet");
VisitExpr(S);
VisitType(S->getElementType());
}

void StmtProfiler::VisitCMMergeExpr(const CMMergeExpr *S) {
llvm_unreachable("not implemented yet");
VisitExpr(S);
}

void StmtProfiler::VisitCMSizeExpr(const CMSizeExpr *S) {
llvm_unreachable("not implemented yet");
VisitExpr(S);
ID.AddInteger(S->getCMSizeKind());
}

void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Expand Down
23 changes: 23 additions & 0 deletions clang/test/CMFE/Sema/dependent_cm_expr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*========================== begin_copyright_notice ============================
Copyright (C) 2022 Intel Corporation
SPDX-License-Identifier: MIT
============================= end_copyright_notice ===========================*/

// Check that dependent CM expressions do not cause compiler crash.

// RUN: %cmc -march=SKL -S -emit-llvm -- %s

template<int N>
int vec_size(vector<int, N> x) {
vector<int, x.n_elems()> y;
(void)y;
}

template<int N>
int mat_size(matrix<int, N, N> x) {
vector<int, x.n_rows() + x.n_cols()> y;
(void)y;
}

0 comments on commit 25cbf42

Please sign in to comment.