diff --git a/loopy/codegen/control.py b/loopy/codegen/control.py index 789c00d33b7bb41816e6901e24046d4b0eefb27d..e18a51c4d499570c034f3ef8682d48647485b511 100644 --- a/loopy/codegen/control.py +++ b/loopy/codegen/control.py @@ -240,6 +240,15 @@ def build_loop_nest(codegen_state, schedule_index): kernel = codegen_state.kernel + # If the AST builder does not implement conditionals, we can save us + # some work about hoisting conditionals and directly go into recursion. + if not codegen_state.ast_builder.can_implement_conditionals: + result = [] + inner = generate_code_for_sched_index(codegen_state, schedule_index) + if inner is not None: + result.append(inner) + return merge_codegen_results(codegen_state, result) + # {{{ pass 1: pre-scan schedule for my schedule item's siblings' indices # i.e. go up to the next LeaveLoop, and skip over inner loops. diff --git a/loopy/target/__init__.py b/loopy/target/__init__.py index 5d5743bae322fc59c989cafd85122c8ca619c422..59d051c50f20cea045e1edd88659f42fb8db5952 100644 --- a/loopy/target/__init__.py +++ b/loopy/target/__init__.py @@ -210,6 +210,10 @@ class ASTBuilderBase(object): static_lbound, static_ubound, inner): raise NotImplementedError() + @property + def can_implement_conditionals(self): + return False + def emit_if(self, condition_str, ast): raise NotImplementedError() @@ -274,28 +278,6 @@ class DummyHostASTBuilder(ASTBuilderBase): def ast_block_scope_class(self): return _DummyASTBlock - def emit_assignment(self, codegen_state, insn): - return None - - def emit_multiple_assignment(self, codegen_state, insn): - return None - - def emit_sequential_loop(self, codegen_state, iname, iname_dtype, - static_lbound, static_ubound, inner): - return None - - def emit_if(self, condition_str, ast): - return None - - def emit_initializer(self, codegen_state, dtype, name, val_str, is_const): - return None - - def emit_blank_line(self): - return None - - def emit_comment(self, s): - return None - # }}} diff --git a/loopy/target/c/__init__.py b/loopy/target/c/__init__.py index a2ad682505bbdb7ed5977a28e201ebc6655c7784..dfffcfae7b734b86bc1d454b72b148fab7f24394 100644 --- a/loopy/target/c/__init__.py +++ b/loopy/target/c/__init__.py @@ -789,6 +789,10 @@ class CASTBuilder(ASTBuilderBase): from cgen import Comment return Comment(s) + @property + def can_implement_conditionals(self): + return True + def emit_if(self, condition_str, ast): from cgen import If return If(condition_str, ast) diff --git a/loopy/target/python.py b/loopy/target/python.py index 11951abcf17e94c0fdba51042e3060735215b423..ce04986d3d2a39dcf7126339055d32fa16ffcc25 100644 --- a/loopy/target/python.py +++ b/loopy/target/python.py @@ -283,6 +283,10 @@ class PythonASTBuilderBase(ASTBuilderBase): from genpy import Comment return Comment(s) + @property + def can_implement_conditionals(self): + return True + def emit_if(self, condition_str, ast): from genpy import If return If(condition_str, ast)