osr-tests.uir 2 KB
Newer Older
1 2
// requires "primitives.uir"

Kunshan Wang's avatar
Kunshan Wang committed
3
.funcsig @v_i = (@i64) -> ()
4

5 6
.funcdef @intro_test_base VERSION @intro_test_base_v1 <@v_i> {
    %entry(<@i64> %n):
Kunshan Wang's avatar
Kunshan Wang committed
7
        %rv = [%call] CALL <@i_i> @intro_rec (%n)
8 9 10 11
        
        COMMINST @uvm.thread_exit
}

Kunshan Wang's avatar
Kunshan Wang committed
12
.funcdef @intro_rec VERSION @intro_rec_v1 <@i_i> {
13
    %entry(<@i64> %n):
14
        %isz = EQ <@i64> %n @I64_0
15
        BRANCH2 %isz %zero(%n) %nz(%n)
16

17
    %zero(<@i64> %n):
Kunshan Wang's avatar
Kunshan Wang committed
18 19
        %v = [%trap_rec] TRAP <@i64> KEEPALIVE(%n)
        RET %v
20

21
    %nz(<@i64> %n):
22
        %nm1 = SUB <@i64> %n @I64_1
Kunshan Wang's avatar
Kunshan Wang committed
23
        %rv = [%call] CALL <@i_i> @intro_rec (%nm1) KEEPALIVE(%n %nm1)
24

25
        RET %rv
26 27
}

28 29
.funcdef @osr_test_base VERSION @osr_test_base_v1 <@v_i> {
    %entry(<@i64> %n):
Kunshan Wang's avatar
Kunshan Wang committed
30 31
        %rv = [%call] CALL <@i_i> @sum (%n)
        [%trap_base_exit] TRAP <> KEEPALIVE (%rv)
32 33 34 35 36 37
        COMMINST @uvm.thread_exit
}

.const @sum_v1.THRESHOLD <@i64> = 5

// Sum from 0..(n-1), but optimise when adding more than 5 numbers
38 39 40
.funcdef @sum VERSION @sum_v1 <@i_i> {
    %entry(<@i64> %n):
        BRANCH %head(%n @I64_0 @I64_0)
41

42
    %head(<@i64> %n <@i64> %i <@i64> %s):
43
        %ge_thr = SGE <@i64> %i @sum_v1.THRESHOLD
44
        BRANCH2 %ge_thr %opt(%n %i %s) %head2(%n %i %s)
45

46
    %head2(<@i64> %n <@i64> %i <@i64> %s):
47
        %lt_n = SLT <@i64> %i %n
48
        BRANCH2 %lt_n %body(%n %i %s) %exit(%s)
49

50
    %body(<@i64> %n <@i64> %i <@i64> %s):
51 52
        %i2 = ADD <@i64> %i @I64_1
        %s2 = ADD <@i64> %s %i
53
        BRANCH %head(%n %i2 %s2)
54

55 56
    %exit(<@i64> %s):
        RET %s
57

58
    %opt(<@i64> %n <@i64> %i <@i64> %s):
Kunshan Wang's avatar
Kunshan Wang committed
59
        [%trap_opt] TRAP <> KEEPALIVE(%n %i %s)
60 61
        THROW @NULLREF // unreachable
}
62 63 64 65 66 67 68 69 70

.funcdef @consecutive_push_main VERSION %v1 <@i_i> {
    %entry(<@i64> %n):
        [%trap] TRAP <> KEEPALIVE(%n)
        COMMINST @uvm.thread_exit
}

.const @I64_42 <@i64> = 42

71
.funcdef @forty_two_returner VERSION %v1 <@v_v> {
72 73 74
    %entry():
        RET @I64_42
}
75 76 77 78 79 80 81

.funcdef @add_one VERSION %v1 <@i_i> {
    %entry(<@i64> %n):
        %n2 = ADD <@i64> %n @I64_1
        [%trap] TRAP <> KEEPALIVE(%n %n2)
        RET %n2
}