Skip to content
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

Allow lowering if-else from LLVM dialect to LLVMIR #23

Merged
merged 27 commits into from
Dec 1, 2024

Conversation

rikhuijzer
Copy link
Owner

@rikhuijzer rikhuijzer commented Nov 20, 2024

Allows lowering

module {
  llvm.func @main() -> i32 {
    %false = llvm.mlir.constant(false) : i1
    llvm.cond_br %false, ^then, ^else
  ^then:
    %c3_i32 = llvm.mlir.constant(3 : i32) : i32
    llvm.br ^merge(%c3_i32 : i32)
  ^else:
    %c4_i32 = llvm.mlir.constant(4 : i32) : i32
    llvm.br ^merge(%c4_i32 : i32)
  ^merge(%result : i32):
    llvm.br ^exit
  ^exit:
    llvm.return %result : i32
  }
}

to

; ModuleID = 'LLVMDialectModule'
source_filename = "LLVMDialectModule"

define i32 @main() {
  br i1 false, label %1, label %2

1:                                                
  br label %3

2:                                               
  br label %3

3:                                              
  %result = phi i32 [ 4, %2 ], [ 3, %1 ]
  br label %5

5:                                             
  ret i32 %result
}

!llvm.module.flags = !{!0}

!0 = !{i32 2, !"Debug Info Version", i32 3}

which is the same result as mlir-opt --convert-mlir-to-llvmir (functionality-wise at least, MLIR provides some extra debugging info as comments and renames %result to %4).

@rikhuijzer rikhuijzer merged commit e25f160 into main Dec 1, 2024
3 checks passed
@rikhuijzer rikhuijzer deleted the rh/lower-blocks-to-llvm branch December 1, 2024 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant