basic-tests.uir 26.1 KB
Newer Older
Kunshan Wang's avatar
Kunshan Wang committed
1
.typedef @i1 = int<1>
2
.typedef @i6 = int<6>
Kunshan Wang's avatar
Kunshan Wang committed
3 4 5
.typedef @i8 = int<8>
.typedef @i16 = int<16>
.typedef @i32 = int<32>
6
.typedef @i52 = int<52>
Kunshan Wang's avatar
Kunshan Wang committed
7 8 9 10 11 12 13 14
.typedef @i64 = int<64>
.typedef @float = float
.typedef @double = double

.typedef @void = void

.funcsig @noparamsnoret = @void ()

15 16 17 18 19 20
.typedef @funcdumb = func<@noparamsnoret>

.typedef @thread = thread
.typedef @stack = stack
.typedef @tagref64 = tagref64

Kunshan Wang's avatar
Kunshan Wang committed
21 22 23
.const @TRUE <@i64> = 1
.const @FALSE <@i64> = 0

Kunshan Wang's avatar
Kunshan Wang committed
24 25 26 27 28 29 30 31 32
.const @I32_0 <@i32> = 0
.const @I32_1 <@i32> = 1
.const @I32_2 <@i32> = 2
.const @I32_3 <@i32> = 3
.const @I32_4 <@i32> = 4
.const @I32_5 <@i32> = 5
.const @I32_6 <@i32> = 6
.const @I32_7 <@i32> = 7

Kunshan Wang's avatar
Kunshan Wang committed
33 34 35 36
.const @I64_0 <@i64> = 0
.const @I64_1 <@i64> = 1
.const @I64_2 <@i64> = 2
.const @I64_3 <@i64> = 3
Kunshan Wang's avatar
Kunshan Wang committed
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
.const @I64_4 <@i64> = 4
.const @I64_5 <@i64> = 5
.const @I64_6 <@i64> = 6
.const @I64_7 <@i64> = 7

.const @F_0 <@float> = 0.0f
.const @F_1 <@float> = 1.0f
.const @F_2 <@float> = 2.0f
.const @F_3 <@float> = 3.0f
.const @F_4 <@float> = 4.0f
.const @F_5 <@float> = 5.0f
.const @F_6 <@float> = 6.0f
.const @F_7 <@float> = 7.0f

.const @D_0 <@double> = 0.0d
.const @D_1 <@double> = 1.0d
.const @D_2 <@double> = 2.0d
.const @D_3 <@double> = 3.0d
.const @D_4 <@double> = 4.0d
.const @D_5 <@double> = 5.0d
.const @D_6 <@double> = 6.0d
.const @D_7 <@double> = 7.0d

.typedef @4xfloat  = vector <@float 4>
.typedef @4xi32    = vector <@i32 4>
.typedef @2xdouble = vector <@double 2>

64 65
.const @4xI32_V1 <@4xi32> = VEC {@I32_0 @I32_1 @I32_2 @I32_3}
.const @4xI32_V2 <@4xi32> = VEC {@I32_4 @I32_5 @I32_6 @I32_7}
Kunshan Wang's avatar
Kunshan Wang committed
66

67 68
.const @4xF_V1 <@4xfloat> = VEC {@F_0 @F_1 @F_2 @F_3}
.const @4xF_V2 <@4xfloat> = VEC {@F_4 @F_5 @F_6 @F_7}
Kunshan Wang's avatar
Kunshan Wang committed
69

70 71
.const @2xD_V1 <@2xdouble> = VEC {@D_0 @D_1}
.const @2xD_V2 <@2xdouble> = VEC {@D_2 @D_3}
Kunshan Wang's avatar
Kunshan Wang committed
72

Kunshan Wang's avatar
Kunshan Wang committed
73
.funcsig @i_i = @i64 (@i64)
Kunshan Wang's avatar
Kunshan Wang committed
74 75 76
.funcsig @i_ii = @i64 (@i64 @i64)

.typedef @refvoid = ref<@void>
77 78
.typedef @irefvoid = iref<@void>
.typedef @weakrefvoid = weakref<@void>
Kunshan Wang's avatar
Kunshan Wang committed
79 80
.const @NULLREF <@refvoid> = NULL

Kunshan Wang's avatar
Kunshan Wang committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
.funcsig @binops32_sig = @void (@i32 @i32)
.funcdef @binops32 VERSION @binops32_v1 <@binops32_sig> (%p0 %p1) {
    %entry:
        %add  = ADD  <@i32> %p0 %p1
        %sub  = SUB  <@i32> %p0 %p1
        %mul  = MUL  <@i32> %p0 %p1
        %udiv = UDIV <@i32> %p0 %p1
        %sdiv = SDIV <@i32> %p0 %p1
        %urem = UREM <@i32> %p0 %p1
        %srem = SREM <@i32> %p0 %p1
        %shl  = SHL  <@i32> %p0 %p1
        %lshr = LSHR <@i32> %p0 %p1
        %ashr = ASHR <@i32> %p0 %p1
        %and  = AND  <@i32> %p0 %p1
        %or   = OR   <@i32> %p0 %p1
        %xor  = XOR  <@i32> %p0 %p1
        
        %trap = TRAP <@void> KEEPALIVE (
            %add %sub %mul %udiv %sdiv %urem %srem
            %shl %lshr %ashr %and %or %xor
            )
            
        COMMINST @uvm.thread_exit
Kunshan Wang's avatar
Kunshan Wang committed
104 105
}

Kunshan Wang's avatar
Kunshan Wang committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
.funcsig @binops64_sig = @void (@i64 @i64)
.funcdef @binops64 VERSION @binops64_v1 <@binops64_sig> (%p0 %p1) {
    %entry:
        %add  = ADD  <@i64> %p0 %p1
        %sub  = SUB  <@i64> %p0 %p1
        %mul  = MUL  <@i64> %p0 %p1
        %udiv = UDIV <@i64> %p0 %p1
        %sdiv = SDIV <@i64> %p0 %p1
        %urem = UREM <@i64> %p0 %p1
        %srem = SREM <@i64> %p0 %p1
        %shl  = SHL  <@i64> %p0 %p1
        %lshr = LSHR <@i64> %p0 %p1
        %ashr = ASHR <@i64> %p0 %p1
        %and  = AND  <@i64> %p0 %p1
        %or   = OR   <@i64> %p0 %p1
        %xor  = XOR  <@i64> %p0 %p1
Kunshan Wang's avatar
Kunshan Wang committed
122
        
Kunshan Wang's avatar
Kunshan Wang committed
123 124 125 126 127 128
        %trap = TRAP <@void> KEEPALIVE (
            %add %sub %mul %udiv %sdiv %urem %srem
            %shl %lshr %ashr %and %or %xor
            )
             
        COMMINST @uvm.thread_exit
Kunshan Wang's avatar
Kunshan Wang committed
129 130
}

Kunshan Wang's avatar
Kunshan Wang committed
131 132
.funcsig @binops64_div0_sig = @void (@i64 @i64 @i64 @i64 @i64)
.funcdef @binops64_div0 VERSION @binops64_div0_v1 <@binops64_div0_sig> (%p0 %p1 %p2 %p3 %p4) {
Kunshan Wang's avatar
Kunshan Wang committed
133
    %entry:
Kunshan Wang's avatar
Kunshan Wang committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147
        %udiv = UDIV <@i64> %p0 %p1 EXC(%bb2 %exc)
    %bb2:
        %sdiv = SDIV <@i64> %p0 %p2 EXC(%bb3 %exc)
    %bb3:
        %urem = UREM <@i64> %p0 %p3 EXC(%bb4 %exc)
    %bb4:
        %srem = SREM <@i64> %p0 %p4 EXC(%nor %exc)

    %nor:
        %trapnor = TRAP <@void>
        COMMINST @uvm.thread_exit

    %exc:
        %trapexc = TRAP <@void>
Kunshan Wang's avatar
Kunshan Wang committed
148
        COMMINST @uvm.thread_exit
Kunshan Wang's avatar
Kunshan Wang committed
149 150
}

Kunshan Wang's avatar
Kunshan Wang committed
151 152 153 154 155 156 157 158 159 160 161 162 163
.funcsig @binops_f_sig = @void (@float @float)
.funcdef @binops_f VERSION @binops_f_v1 <@binops_f_sig> (%p0 %p1) {
    %entry:
        %fadd = FADD <@float> %p0 %p1
        %fsub = FSUB <@float> %p0 %p1
        %fmul = FMUL <@float> %p0 %p1
        %fdiv = FDIV <@float> %p0 %p1
        %frem = FREM <@float> %p0 %p1
        
        %trap = TRAP <@void> KEEPALIVE (
            %fadd %fsub %fmul %fdiv %frem
            )
        COMMINST @uvm.thread_exit
Kunshan Wang's avatar
Kunshan Wang committed
164 165
}

Kunshan Wang's avatar
Kunshan Wang committed
166 167 168 169 170 171 172 173 174 175 176 177 178
.funcsig @binops_d_sig = @void (@double @double)
.funcdef @binops_d VERSION @binops_d_v1 <@binops_d_sig> (%p0 %p1) {
    %entry:
        %fadd = FADD <@double> %p0 %p1
        %fsub = FSUB <@double> %p0 %p1
        %fmul = FMUL <@double> %p0 %p1
        %fdiv = FDIV <@double> %p0 %p1
        %frem = FREM <@double> %p0 %p1
        
        %trap = TRAP <@void> KEEPALIVE (
            %fadd %fsub %fmul %fdiv %frem
            )
        COMMINST @uvm.thread_exit
Kunshan Wang's avatar
Kunshan Wang committed
179 180
}

Kunshan Wang's avatar
Kunshan Wang committed
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
.funcsig @binops_vec_sig = @void (@4xi32 @4xi32 @4xfloat @4xfloat @2xdouble @2xdouble)
.funcdef @binops_vec VERSION @binops_vec_v1 <@binops_vec_sig> (%p0 %p1 %p2 %p3 %p4 %p5) {
    %entry:
        %addi = ADD  <@4xi32>    %p0 %p1
        %subi = SUB  <@4xi32>    %p0 %p1
        %addf = FADD <@4xfloat>  %p2 %p3
        %subf = FSUB <@4xfloat>  %p2 %p3
        %addd = FADD <@2xdouble> %p4 %p5
        %subd = FSUB <@2xdouble> %p4 %p5

        %trap = TRAP <@void> KEEPALIVE (
            %addi %subi %addf %subf %addd %subd
            )
        COMMINST @uvm.thread_exit

}

Kunshan Wang's avatar
Kunshan Wang committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
.funcsig @cmp64_sig = @void (@i64 @i64)
.funcdef @cmp64 VERSION @cmp64_v1 <@cmp64_sig> (%p0 %p1) {
    %entry:
        %eq  = EQ  <@i64> %p0 %p1
        %ne  = NE  <@i64> %p0 %p1
        %ult = ULT <@i64> %p0 %p1
        %ule = ULE <@i64> %p0 %p1
        %ugt = UGT <@i64> %p0 %p1
        %uge = UGE <@i64> %p0 %p1
        %slt = SLT <@i64> %p0 %p1
        %sle = SLE <@i64> %p0 %p1
        %sgt = SGT <@i64> %p0 %p1
        %sge = SGE <@i64> %p0 %p1
        
        %trap = TRAP <@void> KEEPALIVE (
            %eq %ne %ult %ule %ugt %uge %slt %sle %sgt %sge
            )
        COMMINST @uvm.thread_exit
Kunshan Wang's avatar
Kunshan Wang committed
216 217
}

Kunshan Wang's avatar
Kunshan Wang committed
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
.funcsig @cmp_f_sig = @void (@float @float)
.funcdef @cmp_f VERSION @cmp_f_v1 <@cmp_f_sig> (%p0 %p1) {
    %entry:
        %ftrue  = FTRUE  <@float> %p0 %p1
        %ffalse = FFALSE <@float> %p0 %p1
        %ford   = FORD   <@float> %p0 %p1
        %foeq   = FOEQ   <@float> %p0 %p1
        %fone   = FONE   <@float> %p0 %p1
        %folt   = FOLT   <@float> %p0 %p1
        %fole   = FOLE   <@float> %p0 %p1
        %fogt   = FOGT   <@float> %p0 %p1
        %foge   = FOGE   <@float> %p0 %p1
        %funo   = FUNO   <@float> %p0 %p1
        %fueq   = FUEQ   <@float> %p0 %p1
        %fune   = FUNE   <@float> %p0 %p1
        %fult   = FULT   <@float> %p0 %p1
        %fule   = FULE   <@float> %p0 %p1
        %fugt   = FUGT   <@float> %p0 %p1
        %fuge   = FUGE   <@float> %p0 %p1
    
        %trap = TRAP <@void> KEEPALIVE (
            %ftrue %ffalse %ford %foeq %fone %folt %fole %fogt %foge
            %funo %fueq %fune %fult %fule %fugt %fuge
            )
        COMMINST @uvm.thread_exit
Kunshan Wang's avatar
Kunshan Wang committed
243 244
}

Kunshan Wang's avatar
Kunshan Wang committed
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
.funcsig @cmp_d_sig = @void (@double @double)
.funcdef @cmp_d VERSION @cmp_d_v1 <@cmp_d_sig> (%p0 %p1) {
    %entry:
        %ftrue  = FTRUE  <@double> %p0 %p1
        %ffalse = FFALSE <@double> %p0 %p1
        %ford   = FORD   <@double> %p0 %p1
        %foeq   = FOEQ   <@double> %p0 %p1
        %fone   = FONE   <@double> %p0 %p1
        %folt   = FOLT   <@double> %p0 %p1
        %fole   = FOLE   <@double> %p0 %p1
        %fogt   = FOGT   <@double> %p0 %p1
        %foge   = FOGE   <@double> %p0 %p1
        %funo   = FUNO   <@double> %p0 %p1
        %fueq   = FUEQ   <@double> %p0 %p1
        %fune   = FUNE   <@double> %p0 %p1
        %fult   = FULT   <@double> %p0 %p1
        %fule   = FULE   <@double> %p0 %p1
        %fugt   = FUGT   <@double> %p0 %p1
        %fuge   = FUGE   <@double> %p0 %p1
    
        %trap = TRAP <@void> KEEPALIVE (
            %ftrue %ffalse %ford %foeq %fone %folt %fole %fogt %foge
            %funo %fueq %fune %fult %fule %fugt %fuge
            )
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
        COMMINST @uvm.thread_exit
}

.funcsig @cmp_vec_sig = @void (@4xi32 @4xi32 @4xfloat @4xfloat @2xdouble @2xdouble)
.funcdef @cmp_vec VERSION @cmp_vec_v1 <@cmp_vec_sig> (%p0 %p1 %p2 %p3 %p4 %p5) {
    %entry:
        %eq      = EQ   <@4xi32>    %p0 %p1
        %slt     = SLT  <@4xi32>    %p0 %p1
        %foeqf   = FOEQ <@4xfloat>  %p2 %p3
        %fultf   = FULT <@4xfloat>  %p2 %p3
        %foeqd   = FOEQ <@2xdouble> %p4 %p5
        %fultd   = FULT <@2xdouble> %p4 %p5

        %trap = TRAP <@void> KEEPALIVE (
            %eq %slt %foeqf %fultf %foeqd %fultd
            )
Kunshan Wang's avatar
Kunshan Wang committed
285 286
        COMMINST @uvm.thread_exit
}
Kunshan Wang's avatar
Kunshan Wang committed
287

Kunshan Wang's avatar
Kunshan Wang committed
288 289 290 291 292 293 294 295 296 297
.funcsig @conv_sig = @void (@i32 @i64 @float @double)
.funcdef @conv VERSION @conv_v1 <@conv_sig> (%p0 %p1 %p2 %p3) {
    %entry:
        %trunc = TRUNC <@i64 @i32> %p1
        %zext  = ZEXT  <@i32 @i64> %p0
        %sext  = SEXT  <@i32 @i64> %p0
        
        %fptrunc = FPTRUNC <@double @float> %p3
        %fpext   = FPEXT   <@float @double> %p2
        
298 299 300 301
        %fptoui1 = FPTOUI  <@double @i64> %p3
        %fptosi1 = FPTOSI  <@double @i64> %p3
        %fptoui2 = FPTOUI  <@float @i32> %p2
        %fptosi2 = FPTOSI  <@float @i32> %p2
Kunshan Wang's avatar
Kunshan Wang committed
302 303 304
        %uitofp  = UITOFP  <@i64 @double> %p1
        %sitofp  = SITOFP  <@i64 @double> %p1
        
305 306 307 308
        %bitcast1 = BITCAST <@float  @i32> %p2
        %bitcast2 = BITCAST <@double @i64> %p3
        %bitcast3 = BITCAST <@i32 @float > %bitcast1
        %bitcast4 = BITCAST <@i64 @double> %bitcast2
Kunshan Wang's avatar
Kunshan Wang committed
309 310
        
        %trap = TRAP <@void> KEEPALIVE (
311 312 313
            %trunc %zext %sext %fptrunc %fpext
            %fptoui1 %fptosi1 %fptoui2 %fptosi2 %uitofp %sitofp
            %bitcast1 %bitcast2 %bitcast3 %bitcast4
Kunshan Wang's avatar
Kunshan Wang committed
314 315
            )
        COMMINST @uvm.thread_exit
Kunshan Wang's avatar
Kunshan Wang committed
316 317
}

318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
.typedef @4xi16    = vector <@i16 4>
.typedef @4xi64    = vector <@i64 4>
.typedef @4xdouble = vector <@double 4>
.typedef @2xfloat  = vector <@float 2>

.funcsig @conv_vec_sig = @void (@4xi32 @4xfloat @2xdouble)
.funcdef @conv_vec VERSION @conv_vec_v1 <@conv_vec_sig> (%p0 %p1 %p2) {
    %entry:
        %trunc = TRUNC <@4xi32 @4xi16> %p0
        %zext  = ZEXT  <@4xi32 @4xi64> %p0
        %sext  = SEXT  <@4xi32 @4xi64> %p0
        
        %fptrunc = FPTRUNC <@2xdouble @2xfloat> %p2
        %fpext   = FPEXT   <@4xfloat @4xdouble> %p1

        %trap = TRAP <@void> KEEPALIVE (
            %trunc %zext %sext %fptrunc %fpext
            )
        COMMINST @uvm.thread_exit
}


Kunshan Wang's avatar
Kunshan Wang committed
340 341
.typedef @4xi1 = vector <@i1 4>

342
.const @4xI1_COND <@4xi1> = VEC {@TRUE @FALSE @FALSE @TRUE}
Kunshan Wang's avatar
Kunshan Wang committed
343 344

.funcdef @select VERSION @select_v1 <@noparamsnoret> () {
345
    %entry:
Kunshan Wang's avatar
Kunshan Wang committed
346 347 348 349 350 351 352
        %sel1 = SELECT <@i1 @i64> @TRUE  @I64_2 @I64_3
        %sel2 = SELECT <@i1 @i64> @FALSE @I64_2 @I64_3

        %sel3 = SELECT <@4xi1 @4xi32> @4xI1_COND @4xI32_V1 @4xI32_V2

        %sel4 = SELECT <@i1 @4xi32> @TRUE  @4xI32_V1 @4xI32_V2
        %sel5 = SELECT <@i1 @4xi32> @FALSE @4xI32_V1 @4xI32_V2
Kunshan Wang's avatar
Kunshan Wang committed
353
    
354
        %trap = TRAP <@void> KEEPALIVE (
Kunshan Wang's avatar
Kunshan Wang committed
355
            %sel1 %sel2 %sel3 %sel4 %sel5
356 357
            )
        COMMINST @uvm.thread_exit
358 359
}

360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
.funcsig @branch_sig = @void (@i64)
.funcdef @branch VERSION @branch_v1 <@branch_sig> (%p0) {
    %entry:
        BRANCH %head

    %head:
        %cmpz = EQ <@i64> %p0 @I64_0
        BRANCH2 %cmpz %iftrue %iffalse
        
    %iftrue:
        %traptrue = TRAP <@void>
        COMMINST @uvm.thread_exit
        
    %iffalse:
        %trapfalse = TRAP <@void>
        COMMINST @uvm.thread_exit
}


.funcsig @switch_phi_sig = @void (@i64)
.funcdef @switch_phi VERSION @switch_phi_v1 <@switch_phi_sig> (%p0) {
    %entry:
        SWITCH <@i64> %p0 %def {
            @I64_1: %one;
            @I64_2: %two;
            @I64_3: %three;
        }
        
    %def:
        %trapdef   = TRAP <@void> EXC(%exit %exit)
        
    %one:
        %trapone   = TRAP <@void> EXC(%exit %exit)
        
    %two:
        %traptwo   = TRAP <@void> EXC(%exit %exit)
        
    %three:
        %trapthree = TRAP <@void> EXC(%exit %exit)
        
    %exit:
        %phi = PHI <@i64> {
            %def:   @I64_4;
            %one:   @I64_5;
            %two:   @I64_6;
            %three: @I64_7;
        }
        %trapend = TRAP <@void> KEEPALIVE (%phi)
        COMMINST @uvm.thread_exit
}

411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
.funcdef @phi_cyclic_dep_test VERSION @phi_cyclic_dep_test_v1 <@noparamsnoret> () {
    %entry:
        BRANCH %head

    %head:
        %x = PHI <@i64> { %entry: @I64_1; %head: %y; }
        %y = PHI <@i64> { %entry: @I64_2; %head: %x; }
        %i = PHI <@i64> { %entry: @I64_0; %head: %i2; }
        %i2 = ADD <@i64> %i @I64_1
        %lt = SLT <@i64> %i @I64_1
        BRANCH2 %lt %head %end

    %end:
        %trap = TRAP <@void> KEEPALIVE (%x %y)
        COMMINST @uvm.thread_exit
}

428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
.funcdef @square_sum VERSION @square_sum_v1 <@i_ii> (%a %b) {
    %entry:
        %a2 = MUL <@i64> %a %a
        %b2 = MUL <@i64> %b %b
        %s  = ADD <@i64> %a2 %b2
        RET <@i64> %s
}

.funcdef @call_ret VERSION @call_ret_v1 <@i_ii> (%a %b) {
    %entry:
        %ss = CALL <@i_ii> @square_sum (%a %b)
        %trap = TRAP <@void> KEEPALIVE (%ss)
        COMMINST @uvm.thread_exit
}

Kunshan Wang's avatar
Kunshan Wang committed
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
.funcdef @thrower VERSION @thrower_v1 <@i_i> (%p0) {
    %entry:
        %n0 = NE <@i64> %p0 @I64_0
        BRANCH2 %n0 %nz %z
    %nz:
        RET <@i64> %p0
    %z:
        THROW @NULLREF
}

.funcdef @call_throw VERSION @call_throw_v1 <@i_i> (%p0) {
    %entry:
        %rv = CALL <@i_i> @thrower (%p0) EXC(%nor %exc)
    %nor:
        %trapnor = TRAP <@void> EXC(%exit %exit) KEEPALIVE (%rv)
    %exc:
        %lp = LANDINGPAD
        %trapexc = TRAP <@void> EXC(%exit %exit) KEEPALIVE (%lp)
    %exit:
        COMMINST @uvm.thread_exit
}

Kunshan Wang's avatar
Kunshan Wang committed
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
// Some simple struct constants

.typedef @StructFoo = struct <@i32 @i64 @float @double>

.const @STRUCT_FOO <@StructFoo> = {@I32_1 @I64_2 @F_3 @D_4}

.funcdef @aggregate_struct VERSION @aggregate_struct_v1 <@noparamsnoret> () {
    %entry:
        %f1  = EXTRACTVALUE <@StructFoo 1> @STRUCT_FOO
        %s2  = INSERTVALUE  <@StructFoo 1> @STRUCT_FOO @I64_7
        %f12 = EXTRACTVALUE <@StructFoo 1> %s2

        %trapnor = TRAP <@void> KEEPALIVE (%f1 %f12)
        COMMINST @uvm.thread_exit
}

.const @v1 <@4xfloat> = VEC {@F_0 @F_1 @F_2 @F_3}
.const @v2 <@4xfloat> = VEC {@F_4 @F_5 @F_6 @F_7}
.const @vshf <@4xi32> = VEC {@I32_0 @I32_2 @I32_4 @I32_6}

.funcdef @aggregate_vector VERSION @aggregate_vector_v1 <@noparamsnoret> () {
    %entry:
        %ee0 = EXTRACTELEMENT <@4xfloat @i32> @4xF_V1 @I32_0
        %ie0 = INSERTELEMENT  <@4xfloat @i32> @4xF_V1 @I32_1 @F_6
        %sv0 = SHUFFLEVECTOR  <@4xfloat @4xi32> @4xF_V1 @4xF_V2 @vshf

        %trapnor = TRAP <@void> KEEPALIVE (%ee0 %ie0 %sv0)
        COMMINST @uvm.thread_exit
}

495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
.typedef @refi64 = ref<@i64>
.typedef @irefi64 = iref<@i64>
.typedef @weakrefi64 = weakref<@i64>

.typedef @StructBar = struct <
    @i64 @i32 @i16 @i8 @float @double
    @refi64 @irefi64 @weakrefi64
>

.typedef @refBar = ref<@StructBar>
.typedef @irefBar = iref<@StructBar>

.typedef @hCharArray = hybrid<@i64 @i8>

.funcsig @allocs_sig = @void (@i64)
.funcdef @allocs VERSION @allocs_v1 <@allocs_sig> (%sz) {
    %entry:
        %new = NEW <@StructBar>
        %newhybrid = NEWHYBRID <@hCharArray @i64> %sz
        %alloca = ALLOCA <@StructBar>
        %allocahybrid = ALLOCAHYBRID <@hCharArray @i64> %sz

        %trap = TRAP <@void> KEEPALIVE (%new %newhybrid %alloca %allocahybrid)
        COMMINST @uvm.thread_exit
}

.typedef @ArrayBaz = array <@i16 1024>

.typedef @JavaLikeByteArray = hybrid <@i32 @i8>

.const @I64_1024 <@i64> = 1024

.funcdef @memAddressing VERSION @memAddressing_v1 <@noparamsnoret> () {
    %entry:
        %bar_ref  = NEW <@StructBar>
        %bar_iref = GETIREF <@StructBar> %bar_ref
        %bar_3    = GETFIELDIREF <@StructBar 3> %bar_iref
        
        %baz_iref = ALLOCA <@ArrayBaz>
        %baz_3    = GETELEMIREF <@ArrayBaz @i64> %baz_iref @I64_3
        %baz_6    = SHIFTIREF <@i16 @i64> %baz_3 @I64_3
        
        %ja_ref   = NEWHYBRID <@JavaLikeByteArray @i64> @I64_1024
        %ja_iref  = GETIREF <@JavaLikeByteArray> %ja_ref
        %ja_fix   = GETFIXEDPARTIREF <@JavaLikeByteArray> %ja_iref
        %ja_var   = GETVARPARTIREF <@JavaLikeByteArray> %ja_iref

        %trap = TRAP <@void> KEEPALIVE (%bar_ref %bar_iref %bar_3
                    %baz_iref %baz_3 %baz_6 %ja_ref %ja_iref %ja_fix %ja_var)
        COMMINST @uvm.thread_exit
}

Kunshan Wang's avatar
Kunshan Wang committed
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
.global @g_i8   <@i8>
.global @g_i16  <@i16>
.global @g_i32  <@i32>
.global @g_i64  <@i64>
.global @g_f    <@float>
.global @g_d    <@double>
.global @g_r    <@refvoid>
.global @g_ir   <@irefvoid>
.global @g_wr   <@weakrefvoid>
    
.global @g_func <@funcdumb>
    
.global @g_thr  <@thread>
.global @g_sta  <@stack>
.global @g_tr64 <@tagref64>

.const @I8_41  <@i8>     = 41
.const @I16_42 <@i16>    = 42
.const @I32_43 <@i32>    = 43
566 567
.const @I32_53 <@i32>    = 53
.const @I32_63 <@i32>    = 63
Kunshan Wang's avatar
Kunshan Wang committed
568
.const @I64_44 <@i64>    = 44
569 570
.const @I64_54 <@i64>    = 54
.const @I64_64 <@i64>    = 64
Kunshan Wang's avatar
Kunshan Wang committed
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
.const @F_45   <@float>  = 45.0f
.const @D_46   <@double> = 46.0d

.funcdef @memAccessing VERSION @memAccessing_v1 <@noparamsnoret> () {
    %entry:
        STORE <@i8>     @g_i8   @I8_41
        STORE <@i16>    @g_i16  @I16_42
        STORE <@i32>    @g_i32  @I32_43
        STORE <@i64>    @g_i64  @I64_44
        STORE <@float>  @g_f    @F_45
        STORE <@double> @g_d    @D_46
        
        %void_r  = NEW <@void>
        %void_ir = ALLOCA <@void>
        
        STORE <@refvoid>     @g_r  %void_r
        STORE <@irefvoid>    @g_ir %void_ir
        STORE <@weakrefvoid> @g_wr %void_r

        STORE <@funcdumb> @g_func @memAccessing
        
        %li8  = LOAD <@i8>      @g_i8
        %li16 = LOAD <@i16>     @g_i16
        %li32 = LOAD <@i32>     @g_i32
        %li64 = LOAD <@i64>     @g_i64
        %lf   = LOAD <@float>   @g_f
        %ld   = LOAD <@double>  @g_d
        
        %lr   = LOAD <@refvoid>     @g_r
        %lir  = LOAD <@irefvoid>    @g_ir
        %lwr  = LOAD <@weakrefvoid> @g_wr

        %lfunc = LOAD <@funcdumb> @g_func

        %trap = TRAP <@void> KEEPALIVE (%void_r %void_ir %li8 %li16
                    %li32 %li64 %lf %ld %lr %lir %lwr %lfunc)
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
        COMMINST @uvm.thread_exit
}

.const @I64_0x55ab              <@i64> = 0x55ab
.const @I64_0x5a5a              <@i64> = 0x5a5a
.const @I64_0x5000              <@i64> = 0x5000
.const @I64_0x55aa              <@i64> = 0x55aa
.const @I64_N0x7fffffffffffffde <@i64> = -0x7fffffffffffffde
.const @I64_42                  <@i64> = 42
.const @I64_11                  <@i64> = 11
.const @I64_0xffffffffffffffde  <@i64> = 0xffffffffffffffde

.funcdef @memAccessingAtomic VERSION @memAccessingAtomic_v1 <@noparamsnoret> () {
    %entry:
        STORE SEQ_CST <@i32> @g_i32 @I32_43
        STORE SEQ_CST <@i64> @g_i64 @I64_44

        %void_r   = NEW <@void>
        %void_r2  = NEW <@void>
        %void_r3  = NEW <@void>
        
        STORE <@refvoid>     @g_r  %void_r

        %cx32_1 = CMPXCHG SEQ_CST RELAXED <@i32> @g_i32 @I32_43 @I32_53
        %cx32_2 = CMPXCHG SEQ_CST RELAXED <@i32> @g_i32 @I32_43 @I32_63
        %cx64_1 = CMPXCHG SEQ_CST RELAXED <@i64> @g_i64 @I64_44 @I64_54
        %cx64_2 = CMPXCHG SEQ_CST RELAXED <@i64> @g_i64 @I64_44 @I64_64
        
        %l32 = LOAD SEQ_CST <@i32> @g_i32
        %l64 = LOAD SEQ_CST <@i64> @g_i64
        
        %cxr_1 = CMPXCHG SEQ_CST RELAXED <@refvoid> @g_r %void_r %void_r2
        %cxr_2 = CMPXCHG SEQ_CST RELAXED <@refvoid> @g_r %void_r %void_r3
        
        %lr   = LOAD <@refvoid>     @g_r
        
        STORE <@i64> @g_i64 @I64_1
        
        %rmw0 = ATOMICRMW SEQ_CST XCHG  <@i64> @g_i64 @I64_0x55ab  // 1 -> 0x55ab
        %rmw1 = ATOMICRMW SEQ_CST ADD   <@i64> @g_i64 @I64_3       // 0x55ab -> 0x55ae 
        %rmw2 = ATOMICRMW SEQ_CST SUB   <@i64> @g_i64 @I64_4       // 0x55ae -> 0x55aa
        %rmw3 = ATOMICRMW SEQ_CST AND   <@i64> @g_i64 @I64_0x5a5a  // 0x55aa -> 0x500a
        %rmw4 = ATOMICRMW SEQ_CST NAND  <@i64> @g_i64 @I64_0x5a5a  // 0x500a -> ~0x500a
        %rmw5 = ATOMICRMW SEQ_CST OR    <@i64> @g_i64 @I64_0x5000  // ~0x500a -> ~0x000a
        %rmw6 = ATOMICRMW SEQ_CST XOR   <@i64> @g_i64 @I64_0x55aa  // ~0x000a -> ~0x55a0 
        %rmw7 = ATOMICRMW SEQ_CST MIN   <@i64> @g_i64 @I64_N0x7fffffffffffffde // ~0x55a0 -> -0x7fffffffffffffde
        %rmw8 = ATOMICRMW SEQ_CST MAX   <@i64> @g_i64 @I64_42      // -0x7fffffffffffffde -> 42
        %rmw9 = ATOMICRMW SEQ_CST UMIN  <@i64> @g_i64 @I64_11      // 42 -> 11
        %rmwA = ATOMICRMW SEQ_CST UMAX  <@i64> @g_i64 @I64_0xffffffffffffffde // 11 -> 0xffffffffffffffde
        
        %l64_2 = LOAD SEQ_CST <@i64> @g_i64

        %trap = TRAP <@void> KEEPALIVE (%void_r %void_r2 %void_r3
                    %cx32_1 %cx32_2 %cx64_1 %cx64_2 %l32 %l64 %cxr_1 %cxr_2 %lr
                    %rmw0 %rmw1 %rmw2 %rmw3 %rmw4 %rmw5 %rmw6 %rmw7 %rmw8 %rmw9 %rmwA %l64_2)
        COMMINST @uvm.thread_exit
}

.const @NULLIREF_I64 <@irefi64> = NULL

.funcdef @memAccessingNull VERSION @memAccessingNull_v1 <@noparamsnoret> () {
    %entry:
        %l = LOAD <@i64> @NULLIREF_I64 EXC(%unreachable %bb2)

    %bb2:
        %s = STORE <@i64> @NULLIREF_I64 @I64_0 EXC(%unreachable %bb3)

    %bb3:
        %c = CMPXCHG SEQ_CST RELAXED <@i64> @NULLIREF_I64 @I64_0 @I64_1 EXC(%unreachable %bb4)

    %bb4:
        %a = ATOMICRMW SEQ_CST XCHG <@i64> @NULLIREF_I64 @I64_0 EXC(%unreachable %exit)

Kunshan Wang's avatar
Kunshan Wang committed
680
    %exit:
681 682 683 684 685
        %trap_exit = TRAP <@void>
        COMMINST @uvm.thread_exit

    %unreachable:
        %trap_unreachable = TRAP <@void>
Kunshan Wang's avatar
Kunshan Wang committed
686 687 688
        COMMINST @uvm.thread_exit
}

689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
.funcdef @traptest VERSION @traptest_v1 <@noparamsnoret> () {
    %entry:
        %t1 = TRAP <@i64>
        %t2 = TRAP <@double> EXC(%bb2 %unreachable)

    %bb2:
        %t3 = TRAP <@void> EXC(%unreachable %exit)

    %exit:
        %lp = LANDINGPAD
        %trap_exit = TRAP <@void> KEEPALIVE (%t1 %t2 %lp)
        COMMINST @uvm.thread_exit

    %unreachable:
        %trap_unreachable = TRAP <@void>
        COMMINST @uvm.thread_exit
}

.funcdef @wptest VERSION @wptest_v1 <@noparamsnoret> () {
    %entry:
        %w1 = WATCHPOINT 1 <@i64> %dis %bb2

    %bb2:
        %w2 = WATCHPOINT 1 <@double> %dis %bb3 WPEXC(%unreachable)

    %bb3:
        %w3 = WATCHPOINT 1 <@void> %dis %unreachable WPEXC(%exit)

    %exit:
        %lp = LANDINGPAD
        %trap_exit = TRAP <@void> KEEPALIVE (%w1 %w2 %lp)
        COMMINST @uvm.thread_exit

    %unreachable:
        %trap_unreachable = TRAP <@void>
        COMMINST @uvm.thread_exit

    %dis:
        %trap_dis = TRAP <@void>
        COMMINST @uvm.thread_exit
}

Kunshan Wang's avatar
Kunshan Wang committed
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768
.funcdef @trapThrow VERSION @trapThrow_v1 <@noparamsnoret> () {
    %entry:
        %t = TRAP <@void>
        %trap_unreachable = TRAP <@void>
        COMMINST @uvm.thread_exit
}

.funcdef @wpThrow VERSION @wpThrow_v1 <@noparamsnoret> () {
    %entry:
        %w = WATCHPOINT 2 <@void> %dis %ena

    %dis:
        %trap_unreachable = TRAP <@void>
        COMMINST @uvm.thread_exit

    %ena:
        %trap_unreachable2 = TRAP <@void>
        COMMINST @uvm.thread_exit
}

.funcdef @trapExc VERSION @trapExc_v1 <@noparamsnoret> () {
    %entry:
        CALL <@noparamsnoret> @trapThrow () EXC(%unreachable %bb2)

    %bb2:
        %lp1 = LANDINGPAD
        CALL <@noparamsnoret> @wpThrow () EXC(%unreachable %exit)

    %exit:
        %lp2 = LANDINGPAD
        %trap_exit = TRAP <@void> KEEPALIVE (%lp1 %lp2)
        COMMINST @uvm.thread_exit

    %unreachable:
        %trap_unreachable = TRAP <@void>
        COMMINST @uvm.thread_exit
}

Kunshan Wang's avatar
Kunshan Wang committed
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
.funcsig @corostackfunc_sig = @void (@stack @i64)
.funcdef @corostackfunc VERSION @corostackfunc_v1 <@corostackfunc_sig> (%fromsta %p) {
    %entry:
        %trap_coro1 = TRAP <@void> KEEPALIVE(%fromsta %p)

        %pp1 = ADD <@i64> %p @I64_1

        %css1 = SWAPSTACK %fromsta RET_WITH <@double> PASS_VALUE <@i64> %pp1

        %trap_coro2 = TRAP <@void> KEEPALIVE(%css1)

        %css2 = SWAPSTACK %fromsta RET_WITH <@void> PASS_VOID KEEPALIVE(%css1)

        %excref = NEW <@i64>
        %exciref = GETIREF <@i64> %excref
        STORE <@i64> %exciref @I64_7    // Does not need to be atomic. It is single threaded.

        %css3 = SWAPSTACK %fromsta KILL_OLD THROW_EXC %excref
}

.funcdef @testswapstack VERSION @testswapstack_v1 <@noparamsnoret> () {
    %entry:
        %thisstack = COMMINST @uvm.current_stack ()
        
        %coro = NEWSTACK <@corostackfunc_sig> @corostackfunc (%thisstack @I64_2)

        %mss1 = SWAPSTACK %coro RET_WITH <@i64> PASS_VOID

        %trap_main1 = TRAP <@void> KEEPALIVE(%mss1)

        %mss2 = SWAPSTACK %coro RET_WITH <@void> PASS_VALUE <@double> @D_3

        %mss3 = SWAPSTACK %coro RET_WITH <@void> PASS_VOID EXC(%unreachable %exit)

    %exit:
        %exc = LANDINGPAD
        %excref = REFCAST <@refvoid @refi64> %exc
        %exciref = GETIREF <@i64> %excref
        %excval = LOAD <@i64> %exciref
        %trap_main2 = TRAP <@void> KEEPALIVE(%excval)
        COMMINST @uvm.thread_exit

    %unreachable:
        %trap_unreachable = TRAP <@void>
        COMMINST @uvm.thread_exit
}

816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847
.const @I6_31 <@i6> = 31
.const @I52_SAMPLE <@i52> = 0xfedcba9876543
.const @D_42 <@double> = 42.0d

.funcdef @testtr64 VERSION @testtr64_v1 <@noparamsnoret> () {
    %entry:
        %someobj = NEW <@i64>
        %rv = REFCAST <@refi64 @refvoid> %someobj

        %f = COMMINST @uvm.tr64.from_fp  (@D_42)
        %i = COMMINST @uvm.tr64.from_int (@I52_SAMPLE)
        %r = COMMINST @uvm.tr64.from_ref (%rv @I6_31)
        
        %f_is_f = COMMINST @uvm.tr64.is_fp  (%f)
        %f_is_i = COMMINST @uvm.tr64.is_int (%f)
        %f_is_r = COMMINST @uvm.tr64.is_ref (%f)
        %i_is_f = COMMINST @uvm.tr64.is_fp  (%i)
        %i_is_i = COMMINST @uvm.tr64.is_int (%i)
        %i_is_r = COMMINST @uvm.tr64.is_ref (%i)
        %r_is_f = COMMINST @uvm.tr64.is_fp  (%r)
        %r_is_i = COMMINST @uvm.tr64.is_int (%r)
        %r_is_r = COMMINST @uvm.tr64.is_ref (%r)
        
        %fb = COMMINST @uvm.tr64.to_fp  (%f)
        %ib = COMMINST @uvm.tr64.to_int (%i)
        %rb = COMMINST @uvm.tr64.to_ref (%r)
        %rt = COMMINST @uvm.tr64.to_tag (%r)
        
        TRAP <@void> KEEPALIVE (%rv %f %i %r %f_is_f %f_is_i %f_is_r
                %i_is_f %i_is_i %i_is_r %r_is_f %r_is_i %r_is_r %fb %ib %rb %rt)
        COMMINST @uvm.thread_exit
}
Kunshan Wang's avatar
Kunshan Wang committed
848

849 850 851 852 853 854 855
.funcdef @testdependency VERSION @testdependency_v1 <@noparamsnoret> () {
    %entry:
        %a = ADD <@i64> @I64_1 @I64_2
        %b = COMMINST @uvm.kill_dependency <@i64> (%a)
        TRAP <@void> KEEPALIVE (%b)
        COMMINST @uvm.thread_exit
}