Skip to content

Commit

Permalink
split condition.
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Oct 29, 2024
1 parent bd66a95 commit 2d76a3a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/codegen/codegen_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,15 @@ std::string CodegenCppVisitor::breakpoint_current(std::string current) const {
* for(int id = 0; id < nodecount; id++) {
* \endcode
*/
void CodegenCppVisitor::print_parallel_iteration_hint(BlockType /* type */,
const ast::Block* block) {
void CodegenCppVisitor::print_parallel_iteration_hint(BlockType type, const ast::Block* block) {
if (parallel_iteration_condition(type, block)) {
printer->add_line("#pragma omp simd");
printer->add_line("#pragma ivdep");
}
}

bool CodegenCppVisitor::parallel_iteration_condition(BlockType /* type */,
const ast::Block* block) {
// ivdep allows SIMD parallelisation of a block/loop but doesn't provide
// a standard mechanism for atomics. Also, even with openmp 5.0, openmp
// atomics do not enable vectorisation under "omp simd" (gives compiler
Expand All @@ -405,10 +412,8 @@ void CodegenCppVisitor::print_parallel_iteration_hint(BlockType /* type */,
ast::AstNodeType::MUTEX_LOCK,
ast::AstNodeType::MUTEX_UNLOCK});
}
if (nodes.empty()) {
printer->add_line("#pragma omp simd");
printer->add_line("#pragma ivdep");
}

return nodes.empty();
}


Expand Down
4 changes: 4 additions & 0 deletions src/codegen/codegen_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,10 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor {
virtual void print_parallel_iteration_hint(BlockType type, const ast::Block* block);


/** Condition for parallel iteration. */
virtual bool parallel_iteration_condition(BlockType type, const ast::Block* block);


/****************************************************************************************/
/* Backend specific routines */
/****************************************************************************************/
Expand Down

0 comments on commit 2d76a3a

Please sign in to comment.