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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding extra newline after blocks #45

Open
jdreaver opened this issue May 2, 2018 · 1 comment
Open

Consider adding extra newline after blocks #45

jdreaver opened this issue May 2, 2018 · 1 comment

Comments

@jdreaver
Copy link

jdreaver commented May 2, 2018

Hello! I'm really excited you all have built this project. It is much nicer to debug LLVM IR issues in my compiler when I can see it printed, versus when I make a mistake and just see a segfault from the C++ LLVM library 馃槃

I noticed that when I print my LLVM IR using moduleLLVMAssembly, I get wonderful newlines after each block:

; ModuleID = 'amy-module'
source_filename = "<string>"

define i64 @main() {
entry:
  %0 = call i64 @fib(i64 10)
  ret i64 %0
}

define private i64 @fib(i64 %x) {
entry:
  switch i64 %x, label %case.default.0 [
    i64 0, label %case.0.0
    i64 1, label %case.1.0
  ]

case.default.0:                                   ; preds = %entry
  %0 = sub i64 %x, 1
  %1 = call i64 @fib(i64 %0)
  %2 = sub i64 %x, 2
  %3 = call i64 @fib(i64 %2)
  %4 = add i64 %1, %3
  br label %case.end.0

case.0.0:                                         ; preds = %entry
  br label %case.end.0

case.1.0:                                         ; preds = %entry
  br label %case.end.0

case.end.0:                                       ; preds = %case.1.0, %case.0.0, %case.default.0
  %end.0 = phi i64 [ %4, %case.default.0 ], [ 0, %case.0.0 ], [ 1, %case.1.0 ]
  ret i64 %end.0
}

When I use llvm-hs-pretty, those newlines are gone:

; ModuleID = 'amy-module'


define external ccc i64 @main(){
entry:
  %0 = call ccc i64 @fib(i64 10)
  ret i64 %0
}

define private ccc i64 @fib(i64 %x){
entry:
  switch i64 %x, label %case.default.0 [i64 0, label %case.0.0 i64 1, label %case.1.0]
case.default.0:
  %1 = sub i64 %x, 1
  %2 = call ccc i64 @fib(i64 %1)
  %3 = sub i64 %x, 2
  %4 = call ccc i64 @fib(i64 %3)
  %5 = add i64 %2, %4
  br label %case.end.0
case.0.0:
  br label %case.end.0
case.1.0:
  br label %case.end.0
case.end.0:
  %end.0 = phi i64 [%5, %case.default.0], [0, %case.0.0], [1, %case.1.0]
  ret i64 %end.0
}

Do you think those newlines are nice enough to add to llvm-hs-pretty? If not, feel free to close this issue. I'm mostly just popping in with a suggestion.

@sdiehl
Copy link
Member

sdiehl commented May 7, 2018

Not opposed I guess. Not sure if there is a canonical formatting for LLVM whitespace.

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

No branches or pull requests

2 participants