brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · d0c623b Raw
70 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// REQUIRES: target={{aarch64-.+}}10// UNSUPPORTED: target={{.*-windows.*}}11 12#include <libunwind.h>13#include <stdlib.h>14#include <string.h>15 16// Basic test of VG (Vector Granule) unwinding. This is meant to mimic SVE/SME17// unwind info without requiring those features for this test.18 19#define VG_REGNUM 4620 21__attribute__((noinline)) void baz() {22  // The previous value of VG is 223  asm(".cfi_escape 0x16, 0x2e, 0x01, 0x32");24 25  unw_context_t context;26  unw_cursor_t cursor;27  unw_getcontext(&context);28  unw_init_local(&cursor, &context);29 30  // Note: At this point VG is not defined (until we unw_step).31 32  uint16_t expected_vgs[]{/*qux*/ 2, /*bar*/ 2, /*foo*/ 8, /*main*/ 2};33  for (uint16_t expected_vg : expected_vgs) {34    unw_step(&cursor);35    unw_word_t vg;36    unw_get_reg(&cursor, VG_REGNUM, &vg);37    if (vg != expected_vg)38      exit(1);39  }40  exit(0);41}42 43__attribute__((noinline)) void qux() { baz(); }44 45__attribute__((noinline)) void bar() {46  // The previous value of VG is 847  asm(".cfi_escape 0x16, 0x2e, 0x01, 0x38");48  // The previous value of W21 is VG (used to force an evaluation of VG).49  asm(".cfi_escape 0x16, 0x15, 0x03, 0x92, 0x2e, 0x00");50 51  // smstop sm52  qux();53  // smstart sm54}55__attribute__((noinline)) void foo() {56  // The previous value of VG is 257  asm(".cfi_escape 0x16, 0x2e, 0x01, 0x32");58  // The previous value of W21 is VG (used to force an evaluation of VG).59  asm(".cfi_escape 0x16, 0x15, 0x03, 0x92, 0x2e, 0x00");60 61  // smstart sm62  bar();63  // smstop sm64}65 66int main(int, char **) {67  foo();68  return 0;69}70