Skip to content

Commit 25cbf42

Browse files
aus-intelAnton Sidorenko
authored and
Anton Sidorenko
committed
Implement profiling for cm expressions
Required for dependent expressions used as constant expressions.
1 parent 3a20f1e commit 25cbf42

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

clang/include/clang/AST/Expr.h

+4
Original file line numberDiff line numberDiff line change
@@ -2976,6 +2976,10 @@ class CMMemberExpr : public Expr {
29762976
child_range children() {
29772977
return child_range(SubExprs, SubExprs + NumSubExprs);
29782978
}
2979+
2980+
const_child_range children() const {
2981+
return const_child_range(SubExprs, SubExprs + NumSubExprs);
2982+
}
29792983
};
29802984

29812985
/// \brief Represent CM select member functions.

clang/include/clang/AST/ExprCM.h

+2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ class CMSizeExpr : public CMMemberExpr {
142142
C.IntTy, VK_RValue),
143143
Kind(SK), RParenLoc(RPLoc) {}
144144

145+
CMSizeExprKind getCMSizeKind() const { return Kind; }
146+
145147
bool isNElems() const { return Kind == SK_n_elems; }
146148
bool isNRows() const { return Kind == SK_n_rows; }
147149
bool isNCols() const { return Kind == SK_n_cols; }

clang/lib/AST/StmtProfile.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -1131,23 +1131,28 @@ void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
11311131
}
11321132

11331133
void StmtProfiler::VisitCMSelectExpr(const CMSelectExpr *S) {
1134-
llvm_unreachable("not implemented yet");
1134+
VisitExpr(S);
1135+
ID.AddInteger(S->getSelectKind());
1136+
ID.AddInteger(S->getNumConstArgs());
11351137
}
11361138

11371139
void StmtProfiler::VisitCMBoolReductionExpr(const CMBoolReductionExpr *S) {
1138-
llvm_unreachable("not implemented yet");
1140+
VisitExpr(S);
1141+
ID.AddInteger(S->getBoolReductionKind());
11391142
}
11401143

11411144
void StmtProfiler::VisitCMFormatExpr(const CMFormatExpr *S) {
1142-
llvm_unreachable("not implemented yet");
1145+
VisitExpr(S);
1146+
VisitType(S->getElementType());
11431147
}
11441148

11451149
void StmtProfiler::VisitCMMergeExpr(const CMMergeExpr *S) {
1146-
llvm_unreachable("not implemented yet");
1150+
VisitExpr(S);
11471151
}
11481152

11491153
void StmtProfiler::VisitCMSizeExpr(const CMSizeExpr *S) {
1150-
llvm_unreachable("not implemented yet");
1154+
VisitExpr(S);
1155+
ID.AddInteger(S->getCMSizeKind());
11511156
}
11521157

11531158
void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2022 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
9+
// Check that dependent CM expressions do not cause compiler crash.
10+
11+
// RUN: %cmc -march=SKL -S -emit-llvm -- %s
12+
13+
template<int N>
14+
int vec_size(vector<int, N> x) {
15+
vector<int, x.n_elems()> y;
16+
(void)y;
17+
}
18+
19+
template<int N>
20+
int mat_size(matrix<int, N, N> x) {
21+
vector<int, x.n_rows() + x.n_cols()> y;
22+
(void)y;
23+
}

0 commit comments

Comments
 (0)