[llvm] Minimal unwinding information (DWARF CFI) checker (PR #145633)

Paul Kirth via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 25 12:49:48 PDT 2025


================
@@ -0,0 +1,68 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains helper functions to find and list registers that are
+/// tracked by the unwinding information checker.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_UNWINDINFOCHECKER_REGISTERS_H
+#define LLVM_UNWINDINFOCHECKER_REGISTERS_H
+
+#include "llvm/MC/MCRegister.h"
+#include "llvm/MC/MCRegisterInfo.h"
+#include <iterator>
+
+namespace llvm {
+
+/// This analysis only keeps track and cares about super registers, not the
+/// subregisters. All reads from/writes to subregisters are considered the
+/// same operation to super registers.
+inline bool isSuperReg(const MCRegisterInfo *MCRI, MCPhysReg Reg) {
+  return MCRI->superregs(Reg).empty();
+}
+
+inline SmallVector<MCPhysReg> getSuperRegs(const MCRegisterInfo *MCRI) {
+  SmallVector<MCPhysReg> SuperRegs;
+  for (auto &&RegClass : MCRI->regclasses()) {
+    for (unsigned I = 0; I < RegClass.getNumRegs(); I++) {
+      MCPhysReg Reg = RegClass.getRegister(I);
+      if (isSuperReg(MCRI, Reg))
+        SuperRegs.push_back(Reg);
+    }
+  }
+
+  std::sort(SuperRegs.begin(), SuperRegs.end());
----------------
ilovepi wrote:

```suggestion
  llvm::sort(SuperRegs.begin(), SuperRegs.end());
```
Default to `llvm::sort` over `std::sort`: https://llvm.org/docs/CodingStandards.html#beware-of-non-deterministic-sorting-order-of-equal-elements

https://github.com/llvm/llvm-project/pull/145633


More information about the llvm-commits mailing list