-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang][OpenMP] Fix tile/unroll on iterator- and foreach-loops. #91459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d6057c4
c2bd6a5
4bc8e76
8eb4b90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -142,7 +142,7 @@ class OMPTeamsScope final : public OMPLexicalScope { | |||
/// of used expression from loop statement. | ||||
class OMPLoopScope : public CodeGenFunction::RunCleanupsScope { | ||||
void emitPreInitStmt(CodeGenFunction &CGF, const OMPLoopBasedDirective &S) { | ||||
const DeclStmt *PreInits; | ||||
const Stmt *PreInits; | ||||
CodeGenFunction::OMPMapVars PreCondVars; | ||||
if (auto *LD = dyn_cast<OMPLoopDirective>(&S)) { | ||||
llvm::DenseSet<const VarDecl *> EmittedAsPrivate; | ||||
|
@@ -182,17 +182,34 @@ class OMPLoopScope : public CodeGenFunction::RunCleanupsScope { | |||
} | ||||
return false; | ||||
}); | ||||
PreInits = cast_or_null<DeclStmt>(LD->getPreInits()); | ||||
PreInits = LD->getPreInits(); | ||||
} else if (const auto *Tile = dyn_cast<OMPTileDirective>(&S)) { | ||||
PreInits = cast_or_null<DeclStmt>(Tile->getPreInits()); | ||||
PreInits = Tile->getPreInits(); | ||||
} else if (const auto *Unroll = dyn_cast<OMPUnrollDirective>(&S)) { | ||||
PreInits = cast_or_null<DeclStmt>(Unroll->getPreInits()); | ||||
PreInits = Unroll->getPreInits(); | ||||
} else { | ||||
llvm_unreachable("Unknown loop-based directive kind."); | ||||
} | ||||
if (PreInits) { | ||||
for (const auto *I : PreInits->decls()) | ||||
CGF.EmitVarDecl(cast<VarDecl>(*I)); | ||||
// CompoundStmts and DeclStmts are used as lists of PreInit statements and | ||||
// declarations. Since declarations must be visible in the the following | ||||
// that they initialize, unpack the ComboundStmt they are nested in. | ||||
SmallVector<const Stmt *> PreInitStmts; | ||||
if (auto *PreInitCompound = dyn_cast<CompoundStmt>(PreInits)) | ||||
llvm::append_range(PreInitStmts, PreInitCompound->body()); | ||||
else | ||||
PreInitStmts.push_back(PreInits); | ||||
|
||||
for (const Stmt *S : PreInitStmts) { | ||||
// EmitStmt skips any OMPCapturedExprDecls, but needs to be emitted | ||||
// here. | ||||
if (auto *PreInitDecl = dyn_cast<DeclStmt>(S)) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, you still emit only DeclStmts? Then why you can't put all Decls into a single one DeclStmt upon creation in Sema? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everything else is emitted in
llvm-project/clang/lib/CodeGen/CGDecl.cpp Line 129 in a15b685
|
||||
for (Decl *I : PreInitDecl->decls()) | ||||
CGF.EmitVarDecl(cast<VarDecl>(*I)); | ||||
continue; | ||||
} | ||||
CGF.EmitStmt(S); | ||||
} | ||||
} | ||||
PreCondVars.restore(CGF); | ||||
} | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why need to create coumpound stmt? DeclStmt support multiple declarations itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is explained in the summary. In essence, the init-statement for a C++20 foreach-loop does not need to be a DeclStmt, but can be an arbitrary Stmt.