[PATCH] D71475: [WIP][OPENMP] Try to fix linear clause crash by emitting alloca for step
Chi Chun Chen via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 13 13:46:15 PST 2019
cchen updated this revision to Diff 233869.
cchen added a comment.
Remove debug code and some redundancy
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D71475/new/
https://reviews.llvm.org/D71475
Files:
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/parallel_for_linear_codegen.cpp
Index: clang/test/OpenMP/parallel_for_linear_codegen.cpp
===================================================================
--- clang/test/OpenMP/parallel_for_linear_codegen.cpp
+++ clang/test/OpenMP/parallel_for_linear_codegen.cpp
@@ -28,6 +28,19 @@
float f;
char cnt;
+int a[100];
+
+int foo (int i, int k)
+{
+#pragma omp parallel for linear (i: k + 1)
+ for (int j = 16; j < 64; j++)
+ {
+ a[i] = j;
+ i += 4;
+ }
+ return i;
+}
+
// CHECK: [[S_FLOAT_TY:%.+]] = type { float }
// CHECK: [[S_INT_TY:%.+]] = type { i32 }
// CHECK-DAG: [[F:@.+]] = global float 0.0
Index: clang/lib/Sema/SemaOpenMP.cpp
===================================================================
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -4404,6 +4404,32 @@
}
}
+namespace {
+class LinearStepVarChecker : public StmtVisitor<LinearStepVarChecker, bool> {
+ llvm::SmallVector<Expr *, 4> ImplicitFirstprivate;
+public:
+ bool VisitDeclRefExpr(DeclRefExpr *E) {
+ if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) {
+ ImplicitFirstprivate.push_back(cast<Expr>(E));
+ return true;
+ }
+ return false;
+ }
+ bool VisitStmt(Stmt *S) {
+ for (Stmt *Child : S->children()) {
+ if (Child && Visit(Child))
+ return true;
+ }
+ return false;
+ }
+ ArrayRef<Expr *> getImplicitFirstprivate() const {
+ return ImplicitFirstprivate;
+ }
+
+ explicit LinearStepVarChecker() {}
+};
+} // namespace
+
StmtResult Sema::ActOnOpenMPExecutableDirective(
OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName,
OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses,
@@ -4460,6 +4486,17 @@
for (Expr *E : IRC->taskgroup_descriptors())
if (E)
ImplicitFirstprivates.emplace_back(E);
+ } else if (auto *LC = dyn_cast<OMPLinearClause>(C)) {
+ Expr *E = LC->getStep();
+ if (E) {
+ LinearStepVarChecker LSVChecker;
+ LSVChecker.Visit(E);
+ ArrayRef<Expr *> LinearVars = LSVChecker.getImplicitFirstprivate();
+ ImplicitFirstprivates.insert(
+ ImplicitFirstprivates.end(),
+ std::make_move_iterator(LinearVars.begin()),
+ std::make_move_iterator(LinearVars.end()));
+ }
}
}
if (!ImplicitFirstprivates.empty()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71475.233869.patch
Type: text/x-patch
Size: 2336 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191213/43f20b94/attachment.bin>
More information about the cfe-commits
mailing list