File: blink.ll

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (103 lines) | stat: -rw-r--r-- 2,014 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
; 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
}