Skip to content

Respect @inline decorator in LLVM backend #1060

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

Merged
merged 3 commits into from
Aug 29, 2022
Merged

Conversation

czgdp1807
Copy link
Collaborator

@czgdp1807 czgdp1807 commented Aug 29, 2022

https://github.com/lcompilers/lpython/pull/1057/files#r957303054

Command - lpython --show-llvm integration_tests/expr_01.py

; ModuleID = 'LFortran'
source_filename = "LFortran"

@0 = private unnamed_addr constant [16 x i8] c"AssertionError\0A\00", align 1
@1 = private unnamed_addr constant [16 x i8] c"AssertionError\0A\00", align 1
@2 = private unnamed_addr constant [16 x i8] c"AssertionError\0A\00", align 1

define void @_lpython_main_program() {
.entry:
  call void @main0()
  br label %return

return:                                           ; preds = %.entry
  ret void
}

define void @main0() {
.entry:
  %_lpython_return_variable_add = alloca i32, align 4
  %_lpython_return_variable_and_op = alloca i32, align 4
  %x = alloca i32, align 4
  %x_add = alloca i32, align 4
  %x_and_op = alloca i32, align 4
  %y = alloca i32, align 4
  %y_add = alloca i32, align 4
  %y_and_op = alloca i32, align 4
  %z = alloca i32, align 4
  store i32 25, i32* %x, align 4
  %0 = load i32, i32* %x, align 4
  store i32 %0, i32* %x_add, align 4
  store i32 2, i32* %y_add, align 4
  %1 = load i32, i32* %x_add, align 4
  %2 = load i32, i32* %y_add, align 4
  %3 = add i32 %1, %2
  store i32 %3, i32* %_lpython_return_variable_add, align 4
  br label %goto_target

unreachable_after_goto:                           ; No predecessors!
  br label %goto_target

goto_target:                                      ; preds = %unreachable_after_goto, %.entry
  %4 = load i32, i32* %_lpython_return_variable_add, align 4
  %5 = mul i32 %4, 2
  store i32 %5, i32* %y, align 4
  %6 = load i32, i32* %x, align 4
  %7 = icmp eq i32 %6, 25
  br i1 %7, label %then, label %else

then:                                             ; preds = %goto_target
  br label %ifcont

else:                                             ; preds = %goto_target
  call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @0, i32 0, i32 0))
  call void @exit(i32 1)
  br label %ifcont

ifcont:                                           ; preds = %else, %then
  %8 = load i32, i32* %y, align 4
  %9 = icmp eq i32 %8, 54
  br i1 %9, label %then1, label %else2

then1:                                            ; preds = %ifcont
  br label %ifcont3

else2:                                            ; preds = %ifcont
  call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @1, i32 0, i32 0))
  call void @exit(i32 1)
  br label %ifcont3

ifcont3:                                          ; preds = %else2, %then1
  %10 = load i32, i32* %x, align 4
  store i32 %10, i32* %x_and_op, align 4
  %11 = load i32, i32* %y, align 4
  store i32 %11, i32* %y_and_op, align 4
  %12 = load i32, i32* %x_and_op, align 4
  %13 = load i32, i32* %y_and_op, align 4
  %14 = and i32 %12, %13
  store i32 %14, i32* %_lpython_return_variable_and_op, align 4
  br label %goto_target5

unreachable_after_goto4:                          ; No predecessors!
  br label %goto_target5

goto_target5:                                     ; preds = %unreachable_after_goto4, %ifcont3
  %15 = load i32, i32* %_lpython_return_variable_and_op, align 4
  store i32 %15, i32* %z, align 4
  %16 = load i32, i32* %z, align 4
  %17 = icmp eq i32 %16, 16
  br i1 %17, label %then6, label %else7

then6:                                            ; preds = %goto_target5
  br label %ifcont8

else7:                                            ; preds = %goto_target5
  call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @2, i32 0, i32 0))
  call void @exit(i32 1)
  br label %ifcont8

ifcont8:                                          ; preds = %else7, %then6
  br label %return

return:                                           ; preds = %ifcont8
  ret void
}

declare void @_lfortran_printf(i8*, ...)

declare void @exit(i32)

define i32 @main() {
.entry:
  call void @_lpython_main_program()
  ret i32 0
}

@czgdp1807 czgdp1807 marked this pull request as ready for review August 29, 2022 14:29
@czgdp1807 czgdp1807 requested a review from certik August 29, 2022 14:29
Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's fine, thanks!

@czgdp1807 czgdp1807 merged commit f4d6b11 into lcompilers:main Aug 29, 2022
@czgdp1807 czgdp1807 deleted the inline branch August 29, 2022 16:22
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.

2 participants