statepoint-stackmap-format.ll 13 KB
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 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 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 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 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 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 495 496 497 498 499 500 501 502 503 504 505 506
; RUN: llc < %s -verify-machineinstrs -stack-symbol-ordering=0 -mtriple="x86_64-pc-linux-gnu" | FileCheck %s
; RUN: llc < %s -verify-machineinstrs -stack-symbol-ordering=0 -mtriple="x86_64-pc-unknown-elf" | FileCheck %s

; This test is a sanity check to ensure statepoints are generating StackMap
; sections correctly.  This is not intended to be a rigorous test of the 
; StackMap format (see the stackmap tests for that).

target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"

declare zeroext i1 @return_i1()

define i1 @test(i32 addrspace(1)* %ptr_base, i32 %arg)
  gc "statepoint-example" {
; CHECK-LABEL: test:
; Do we see two spills for the local values and the store to the
; alloca?
; CHECK: subq	$40, %rsp
; CHECK: movq	$0,   24(%rsp)
; CHECK: movq	%rdi, 16(%rsp)
; CHECK: movq	%rax, 8(%rsp)
; CHECK: callq return_i1
; CHECK: addq	$40, %rsp
; CHECK: retq
entry:
  %metadata1 = alloca i32 addrspace(1)*, i32 2, align 8
  store i32 addrspace(1)* null, i32 addrspace(1)** %metadata1
  %ptr_derived = getelementptr i32, i32 addrspace(1)* %ptr_base, i32 %arg
  %safepoint_token = tail call token (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0) ["gc-live"(i32 addrspace(1)* %ptr_base, i32 addrspace(1)* %ptr_derived, i32 addrspace(1)* null), "deopt" (i32 addrspace(1)* %ptr_base, i32 addrspace(1)* null)]
  %call1 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
  %a = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 0, i32 0)
  %b = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 0, i32 1)
  %c = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 2, i32 2)
; 
  ret i1 %call1
}

; This is similar to the previous test except that we have derived pointer as
; argument to the function. Despite that this can not happen after the
; RewriteSafepointForGC pass, lowering should be able to handle it anyway.
define i1 @test_derived_arg(i32 addrspace(1)* %ptr_base,
                            i32 addrspace(1)* %ptr_derived)
  gc "statepoint-example" {
; CHECK-LABEL: test_derived_arg
; Do we see two spills for the local values and the store to the
; alloca?
; CHECK: subq	$40, %rsp
; CHECK: movq	$0,   24(%rsp)
; CHECK: movq	%rdi, 16(%rsp)
; CHECK: movq	%rsi, 8(%rsp)
; CHECK: callq return_i1
; CHECK: addq	$40, %rsp
; CHECK: retq
entry:
  %metadata1 = alloca i32 addrspace(1)*, i32 2, align 8
  store i32 addrspace(1)* null, i32 addrspace(1)** %metadata1
  %safepoint_token = tail call token (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0) ["gc-live"(i32 addrspace(1)* %ptr_base, i32 addrspace(1)* %ptr_derived, i32 addrspace(1)* null), "deopt" (i32 addrspace(1)* %ptr_base, i32 addrspace(1)* null)]
  %call1 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
  %a = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 0, i32 0)
  %b = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 0, i32 1)
  %c = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 2, i32 2)
; 
  ret i1 %call1
}

; Simple test case to check that we emit the ID field correctly
define i1 @test_id() gc "statepoint-example" {
; CHECK-LABEL: test_id
entry:
  %safepoint_token = tail call token (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 237, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0)
  %call1 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
  ret i1 %call1
}

; This test checks that when SP is changed in the function
; (e.g. passing arguments on stack), the stack map entry
; takes this adjustment into account.
declare void @many_arg(i64, i64, i64, i64, i64, i64, i64, i64)

define i32 @test_spadj(i32 addrspace(1)* %p) gc "statepoint-example" {
  ; CHECK-LABEL: test_spadj
  ; CHECK: movq %rdi, (%rsp)
  ; CHECK: xorl %edi, %edi
  ; CHECK: xorl %esi, %esi
  ; CHECK: xorl %edx, %edx
  ; CHECK: xorl %ecx, %ecx
  ; CHECK: xorl %r8d, %r8d
  ; CHECK: xorl %r9d, %r9d
  ; CHECK: pushq $0
  ; CHECK: pushq $0
  ; CHECK: callq many_arg
  ; CHECK: addq $16, %rsp
  ; CHECK: movq (%rsp)
  %statepoint_token = call token (i64, i32, void (i64, i64, i64, i64, i64, i64, i64, i64)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidi64i64i64i64i64i64i64i64f(i64 0, i32 0, void (i64, i64, i64, i64, i64, i64, i64, i64)* @many_arg, i32 8, i32 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i32 0, i32 0) ["gc-live"(i32 addrspace(1)* %p)]
  %p.relocated = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %statepoint_token, i32 0, i32 0) ; (%p, %p)
  %ld = load i32, i32 addrspace(1)* %p.relocated
  ret i32 %ld
}

; Test that function arguments at fixed stack offset
; can be directly encoded in the stack map, without
; spilling.
%struct = type { i64, i64, i64 }

declare void @use(%struct*)

define void @test_fixed_arg(%struct* byval %x) gc "statepoint-example" {
; CHECK-LABEL: test_fixed_arg
; CHECK: pushq %rax
; CHECK: leaq 16(%rsp), %rdi
; Should not spill fixed stack address.
; CHECK-NOT: movq %rdi, (%rsp)
; CHECK: callq use
; CHECK: popq %rax
; CHECK: retq
entry:
  br label %bb

bb:                                               ; preds = %entry
  %statepoint_token = call token (i64, i32, void (%struct*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidp0s_structsf(i64 0, i32 0, void (%struct*)* @use, i32 1, i32 0, %struct* %x, i32 0, i32 0) ["deopt" (%struct* %x)]
  ret void
}

declare token @llvm.experimental.gc.statepoint.p0f_i1f(i64, i32, i1 ()*, i32, i32, ...)
declare token @llvm.experimental.gc.statepoint.p0f_isVoidi64i64i64i64i64i64i64i64f(i64, i32, void (i64, i64, i64, i64, i64, i64, i64, i64)*, i32, i32, ...)
declare token @llvm.experimental.gc.statepoint.p0f_isVoidp0s_structsf(i64, i32, void (%struct*)*, i32, i32, ...)
declare i1 @llvm.experimental.gc.result.i1(token)
declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token, i32, i32) #3

; CHECK-LABEL: .section .llvm_stackmaps
; CHECK-NEXT:  __LLVM_StackMaps:
; Header
; CHECK-NEXT:   .byte 3
; CHECK-NEXT:   .byte 0
; CHECK-NEXT:   .short 0
; Num Functions
; CHECK-NEXT:   .long 5
; Num LargeConstants
; CHECK-NEXT:   .long 0
; Num Callsites
; CHECK-NEXT:   .long 5

; Functions and stack size
; CHECK-NEXT:   .quad test
; CHECK-NEXT:   .quad 40
; CHECK-NEXT:   .quad 1
; CHECK-NEXT:   .quad test_derived_arg
; CHECK-NEXT:   .quad 40
; CHECK-NEXT:   .quad 1
; CHECK-NEXT:   .quad test_id
; CHECK-NEXT:   .quad 8
; CHECK-NEXT:   .quad 1
; CHECK-NEXT:   .quad test_spadj
; CHECK-NEXT:   .quad 8
; CHECK-NEXT:   .quad 1
; CHECK-NEXT:   .quad test_fixed_arg
; CHECK-NEXT:   .quad 8
; CHECK-NEXT:   .quad 1

;
; test
;

; Statepoint ID
; CHECK-NEXT: .quad	0

; Callsites
; Constant arguments
; CHECK-NEXT: .long	.Ltmp0-test
; CHECK: .short	0
; CHECK: .short	11
; SmallConstant (0)
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	0
; SmallConstant (0)
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	0
; SmallConstant (2)
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	2
; Indirect Spill Slot [RSP+0]
; CHECK: .byte	3
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	7
; CHECK-NEXT:   .short  0
; CHECK: .long	16
; SmallConstant  (0)
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	0
; SmallConstant  (0)
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	0
; SmallConstant  (0)
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	0
; Indirect Spill Slot [RSP+16]
; CHECK: .byte	3
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	7
; CHECK-NEXT:   .short  0
; CHECK: .long	16
; Indirect Spill Slot [RSP+8]
; CHECK: .byte	3
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	7
; CHECK-NEXT:   .short  0
; CHECK: .long	8
; Indirect Spill Slot [RSP+16]
; CHECK: .byte	3
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	7
; CHECK-NEXT:   .short  0
; CHECK: .long	16
; Indirect Spill Slot [RSP+16]
; CHECK: .byte	3
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	7
; CHECK-NEXT:   .short  0
; CHECK: .long	16

; No Padding or LiveOuts
; CHECK: .short	0
; CHECK: .short	0
; CHECK: .p2align	3

;
; test_derived_arg

; Statepoint ID
; CHECK-NEXT: .quad	0

; Callsites
; Constant arguments
; CHECK-NEXT: .long	.Ltmp1-test_derived_arg
; CHECK: .short	0
; CHECK: .short	11
; SmallConstant (0)
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	0
; SmallConstant (2)
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	2
; Indirect Spill Slot [RSP+0]
; CHECK: .byte	3
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	7
; CHECK-NEXT:   .short  0
; CHECK: .long	16
; SmallConstant  (0)
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	0
; SmallConstant  (0)
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	0
; SmallConstant  (0)
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	0
; Indirect Spill Slot [RSP+16]
; CHECK: .byte	3
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	7
; CHECK-NEXT:   .short  0
; CHECK: .long	16
; Indirect Spill Slot [RSP+8]
; CHECK: .byte	3
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	7
; CHECK-NEXT:   .short  0
; CHECK: .long	8
; Indirect Spill Slot [RSP+16]
; CHECK: .byte	3
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	7
; CHECK-NEXT:   .short  0
; CHECK: .long	16
; Indirect Spill Slot [RSP+16]
; CHECK: .byte	3
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	7
; CHECK-NEXT:   .short  0
; CHECK: .long	16

; No Padding or LiveOuts
; CHECK: .short	0
; CHECK: .short	0
; CHECK: .p2align	3

; Records for the test_id function:

; The Statepoint ID:
; CHECK-NEXT: .quad	237

; Instruction Offset
; CHECK-NEXT: .long	.Ltmp2-test_id

; Reserved:
; CHECK: .short	0

; NumLocations:
; CHECK: .short	3

; StkMapRecord[0]:
; SmallConstant(0):
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	0

; StkMapRecord[1]:
; SmallConstant(0):
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	0

; StkMapRecord[2]:
; SmallConstant(0):
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	0

; No padding or LiveOuts
; CHECK: .short	0
; CHECK: .short	0
; CHECK: .p2align	3

;
; test_spadj

; Statepoint ID
; CHECK-NEXT: .quad	0

; Instruction Offset
; CHECK-NEXT: .long	.Ltmp3-test_spadj

; Reserved:
; CHECK: .short	0

; NumLocations:
; CHECK: .short	5

; StkMapRecord[0]:
; SmallConstant(0):
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	0

; StkMapRecord[1]:
; SmallConstant(0):
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	0

; StkMapRecord[2]:
; SmallConstant(0):
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	0

; StkMapRecord[3]:
; Indirect Spill Slot [RSP+16]
; CHECK: .byte	3
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	7
; CHECK-NEXT:   .short  0
; CHECK: .long	16

; StkMapRecord[4]:
; Indirect Spill Slot [RSP+16]
; CHECK: .byte	3
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	7
; CHECK-NEXT:   .short  0
; CHECK: .long	16

; No padding or LiveOuts
; CHECK: .short	0
; CHECK: .short	0
; CHECK: .p2align	3

;
; test_fixed_arg

; Statepoint ID
; CHECK-NEXT: .quad	0

; Instruction Offset
; CHECK-NEXT: .long	.Ltmp4-test_fixed_arg

; Reserved:
; CHECK: .short	0

; NumLocations:
; CHECK: .short	4

; StkMapRecord[0]:
; SmallConstant(0):
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	0

; StkMapRecord[1]:
; SmallConstant(0):
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	0

; StkMapRecord[2]:
; SmallConstant(1):
; CHECK: .byte	4
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	0
; CHECK-NEXT:   .short  0
; CHECK: .long	1

; StkMapRecord[3]:
; Direct RSP+16
; CHECK: .byte	2
; CHECK-NEXT:   .byte   0
; CHECK: .short 8
; CHECK: .short	7
; CHECK-NEXT:   .short  0
; CHECK: .long	16

; No padding or LiveOuts
; CHECK: .short	0
; CHECK: .short	0
; CHECK: .p2align	3