[llvm] [CFIInserter] Improve `CSRSavedLocation` struct. (PR #168869)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 20 07:30:34 PST 2025
================
@@ -88,11 +88,60 @@ class CFIInstrInserter : public MachineFunctionPass {
#define INVALID_REG UINT_MAX
#define INVALID_OFFSET INT_MAX
/// contains the location where CSR register is saved.
- struct CSRSavedLocation {
- CSRSavedLocation(std::optional<unsigned> R, std::optional<int> O)
- : Reg(R), Offset(O) {}
- std::optional<unsigned> Reg;
- std::optional<int> Offset;
+ class CSRSavedLocation {
+ public:
+ enum Kind { INVALID, REGISTER, CFA_OFFSET };
+ Kind K;
+
+ private:
+ union {
+ // Dwarf register number
+ unsigned Reg;
+ // CFA offset
+ int64_t Offset;
+ } U;
+
+ public:
+ CSRSavedLocation() { K = Kind::INVALID; }
+
+ bool isValid() const { return K != Kind::INVALID; }
+
+ unsigned getRegister() const {
+ assert(K == REGISTER);
+ return U.Reg;
+ }
+
+ void setRegister(unsigned _Reg) {
----------------
s-barannikov wrote:
```suggestion
void setRegister(unsigned Reg) {
```
`_Reg` is reserved identifier
https://github.com/llvm/llvm-project/pull/168869
More information about the llvm-commits
mailing list