Skip to content

Navigation Menu

Sign in
Sign up

IfScope #146

jle-quel started this conversation in General
Jan 7, 2022 · 1 comment
Discussion options

Hello, I was looking at the generated code from Polygeist and I stumble upon this code pattern that is created for every function.

This code is generated by the MLIRScanner Ctor as well as the IfScope Ctor:

%true = arith.constant true
%11 = memref.alloca() : memref<i1>
memref.store %true, %11[] : memref<i1>
%13 = memref.load %11[] : memref<i1>
scf.if %13 {
 scf.execute_region {
 %16 = memref.load %11[] : memref<i1>
 scf.if %16 {
 scf.execute_region {
 ... do stuff until yield

I'm not getting the importance of this "branching" code. Since it's generated on hard-coded constant value true.

Why not just have the ... do stuff inside the function region instead of creating subregions?

You must be logged in to vote

Replies: 1 comment

Comment options

This pattern is generated to correctly handle return, break and continue.

For example, the register is set to false after a return has been seen to ensure no code after a return statement is run. This is necessary as MLIR does not support a return statement from a nested region.

This code should be simplified when run with mem2reg and canonicalize

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /