1; RUN: llc < %s -march=avr -mcpu=atmega328p | FileCheck %s 2 3; This test checks a basic 'blinking led' program. 4; It is written for the ATmega328P 5 6; Derived from the following C program (with some cleanups): 7; #include <avr/io.h> 8; 9; void setup_ddr() { 10; DDRB |= _BV(PB5); 11; } 12; 13; void turn_on() { 14; PORTB |= _BV(PB5); 15; } 16; 17; void turn_off() { 18; PORTB &= ~_BV(PB5); 19; } 20; 21; int main() { 22; setup_ddr(); 23; 24; while(1) { 25; turn_on(); 26; turn_off(); 27; } 28; 29; return 0; 30; } 31 32; Sets up the data direction register. 33; CHECK-LABEL: setup_ddr 34define void @setup_ddr() { 35entry: 36 37 ; This should set the 5th bit of DDRB. 38 ; CHECK: sbi 4, 5 39 ; CHECK-NEXT: ret 40 41 %0 = load volatile i8, i8* inttoptr (i16 36 to i8*), align 1 42 %conv = zext i8 %0 to i16 43 %or = or i16 %conv, 32 44 %conv1 = trunc i16 %or to i8 45 store volatile i8 %conv1, i8* inttoptr (i16 36 to i8*), align 1 46 ret void 47} 48 49; Turns on the LED. 50; CHECK-LABEL: turn_on 51define void @turn_on() { 52entry: 53 54 ; This should set the 5th bit of PORTB 55 ; CHECK: sbi 5, 5 56 ; CHECK-NEXT: ret 57 58 %0 = load volatile i8, i8* inttoptr (i16 37 to i8*), align 1 59 %conv = zext i8 %0 to i16 60 %or = or i16 %conv, 32 61 %conv1 = trunc i16 %or to i8 62 store volatile i8 %conv1, i8* inttoptr (i16 37 to i8*), align 1 63 ret void 64} 65 66; Turns off the LED. 67; CHECK-LABEL: turn_off 68define void @turn_off() { 69entry: 70 71 ; This should clear the 5th bit of PORTB 72 ; CHECK: cbi 5, 5 73 ; CHECK-NEXT: ret 74 75 %0 = load volatile i8, i8* inttoptr (i16 37 to i8*), align 1 76 %conv = zext i8 %0 to i16 77 %and = and i16 %conv, -33 78 %conv1 = trunc i16 %and to i8 79 store volatile i8 %conv1, i8* inttoptr (i16 37 to i8*), align 1 80 ret void 81} 82 83; CHECK-LABEL: main 84define i16 @main() { 85entry: 86 87 ; CHECK: call setup_ddr 88 call void @setup_ddr() 89 90 br label %while.body 91 92; CHECK-LABEL: .LBB3_1 93while.body: 94 95 ; CHECK: call turn_on 96 call void @turn_on() 97 98 ; CHECK-NEXT: call turn_off 99 call void @turn_off() 100 101 ; CHECK-NEXT: rjmp .LBB3_1 102 br label %while.body 103} 104