File: action.h

package info (click to toggle)
pytorch-cuda 2.6.0%2Bdfsg-7
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 161,620 kB
  • sloc: python: 1,278,832; cpp: 900,322; ansic: 82,710; asm: 7,754; java: 3,363; sh: 2,811; javascript: 2,443; makefile: 597; ruby: 195; xml: 84; objc: 68
file content (59 lines) | stat: -rw-r--r-- 1,424 bytes parent folder | download | duplicates (3)
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
#pragma once
#include <cstdint>
#include <ostream>

namespace torch::unwind {

enum {
  A_UNDEFINED = 0x0,
  A_REG_PLUS_DATA = 0x1, // exp = REG[reg] + data0
  A_LOAD_CFA_OFFSET = 0x2, // exp = *(cfa + data0)
  A_REG_PLUS_DATA_DEREF = 0x3 // exp = *(REG[reg] + data0)
};

// register numbers in dwarf info
enum {
  D_UNDEFINED = -1,
  D_RBP = 6,
  D_RSP = 7,
  D_RIP = 16,
  D_REG_SIZE = 17,
};

struct Action {
  uint8_t kind = A_UNDEFINED;
  int32_t reg = -1;
  int64_t data = 0;
  static Action undefined() {
    return Action{A_UNDEFINED};
  }
  static Action regPlusData(int32_t reg, int64_t offset) {
    return Action{A_REG_PLUS_DATA, reg, offset};
  }
  static Action regPlusDataDeref(int32_t reg, int64_t offset) {
    return Action{A_REG_PLUS_DATA_DEREF, reg, offset};
  }
  static Action loadCfaOffset(int64_t offset) {
    return Action{A_LOAD_CFA_OFFSET, D_UNDEFINED, offset};
  }

  friend std::ostream& operator<<(std::ostream& out, const Action& self) {
    switch (self.kind) {
      case A_UNDEFINED:
        out << "u";
        break;
      case A_REG_PLUS_DATA:
        out << "r" << (int)self.reg << " + " << self.data;
        break;
      case A_REG_PLUS_DATA_DEREF:
        out << "*(r" << (int)self.reg << " + " << self.data << ")";
        break;
      case A_LOAD_CFA_OFFSET:
        out << "*(cfa + " << self.data << ")";
        break;
    }
    return out;
  }
};

} // namespace torch::unwind