Ayke van Laethem 6afc3de42f
[AVR] Fix private label prefix
This is a small pet peeve from me. This change makes sure the AVR backend uses
the correct private label prefix (.L) so that private labels are hidden in
avr-objdump.

Example code:

    define i8 @foo(i1 %cond) {
      br i1 %cond, label %then, label %else
    then:
      ret i8 3
    else:
      ret i8 5
    }

When compiling this:
  llc -march=avr -filetype=obj -o test.o test.ll
and then dumping it:
  avr-objdump -d test.o
You would previously get an ugly temporary label:

    00000000 <foo>:
       0:        81 70       andi       r24, 0x01    ; 1
       2:        80 30       cpi        r24, 0x00    ; 0
       4:        f9 f3       breq       .-2          ; 0x4 <foo+0x4>
       6:        83 e0       ldi        r24, 0x03    ; 3
       8:        08 95       ret

    0000000a <LBB0_2>:
       a:        85 e0       ldi        r24, 0x05    ; 5
       c:        08 95       ret

This patch fixes that, the output is now:

    00000000 <foo>:
       0:        81 70       andi       r24, 0x01    ; 1
       2:        80 30       cpi        r24, 0x00    ; 0
       4:        01 f0       breq       .+0          ; 0x6 <foo+0x6>
       6:        83 e0       ldi        r24, 0x03    ; 3
       8:        08 95       ret
       a:        85 e0       ldi        r24, 0x05    ; 5
       c:        08 95       ret

Note that as you can see the breq operand is different. However it is
still the same after linking:

       4:        11 f0       breq       .+4

Differential Revision: https://reviews.llvm.org/D75124
2020-02-26 20:32:25 +01:00

104 lines
2.0 KiB
LLVM

; RUN: llc < %s -march=avr -mcpu=atmega328p | FileCheck %s
; This test checks a basic 'blinking led' program.
; It is written for the ATmega328P
; Derived from the following C program (with some cleanups):
; #include <avr/io.h>
;
; void setup_ddr() {
; DDRB |= _BV(PB5);
; }
;
; void turn_on() {
; PORTB |= _BV(PB5);
; }
;
; void turn_off() {
; PORTB &= ~_BV(PB5);
; }
;
; int main() {
; setup_ddr();
;
; while(1) {
; turn_on();
; turn_off();
; }
;
; return 0;
; }
; Sets up the data direction register.
; CHECK-LABEL: setup_ddr
define void @setup_ddr() {
entry:
; This should set the 5th bit of DDRB.
; CHECK: sbi 4, 5
; CHECK-NEXT: ret
%0 = load volatile i8, i8* inttoptr (i16 36 to i8*), align 1
%conv = zext i8 %0 to i16
%or = or i16 %conv, 32
%conv1 = trunc i16 %or to i8
store volatile i8 %conv1, i8* inttoptr (i16 36 to i8*), align 1
ret void
}
; Turns on the LED.
; CHECK-LABEL: turn_on
define void @turn_on() {
entry:
; This should set the 5th bit of PORTB
; CHECK: sbi 5, 5
; CHECK-NEXT: ret
%0 = load volatile i8, i8* inttoptr (i16 37 to i8*), align 1
%conv = zext i8 %0 to i16
%or = or i16 %conv, 32
%conv1 = trunc i16 %or to i8
store volatile i8 %conv1, i8* inttoptr (i16 37 to i8*), align 1
ret void
}
; Turns off the LED.
; CHECK-LABEL: turn_off
define void @turn_off() {
entry:
; This should clear the 5th bit of PORTB
; CHECK: cbi 5, 5
; CHECK-NEXT: ret
%0 = load volatile i8, i8* inttoptr (i16 37 to i8*), align 1
%conv = zext i8 %0 to i16
%and = and i16 %conv, -33
%conv1 = trunc i16 %and to i8
store volatile i8 %conv1, i8* inttoptr (i16 37 to i8*), align 1
ret void
}
; CHECK-LABEL: main
define i16 @main() {
entry:
; CHECK: call setup_ddr
call void @setup_ddr()
br label %while.body
; CHECK-LABEL: .LBB3_1
while.body:
; CHECK: call turn_on
call void @turn_on()
; CHECK-NEXT: call turn_off
call void @turn_off()
; CHECK-NEXT: rjmp .LBB3_1
br label %while.body
}