[llvm] AMDGPU: Add NextUseAnalysis Pass (PR #178873)

via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 13 10:52:52 PDT 2026


================
@@ -0,0 +1,88 @@
+//===---------------------- AMDGPUNextUseAnalysis.h  ----------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements Next Use Analysis.
+// For each register it goes over all uses and returns the estimated distance of
+// the nearest use. This will be used for selecting which registers to spill
+// before register allocation.
+//
+// This is based on ideas from the paper:
+// "Register Spilling and Live-Range Splitting for SSA-Form Programs"
+// Matthias Braun and Sebastian Hack, CC'09
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUNEXTUSEANALYSIS_H
+#define LLVM_LIB_TARGET_AMDGPU_AMDGPUNEXTUSEANALYSIS_H
+
+#include "SIInstrInfo.h"
+#include "SIRegisterInfo.h"
+#include "llvm/CodeGen/LiveIntervals.h"
+#include "llvm/CodeGen/LiveVariables.h"
+#include "llvm/CodeGen/MachineLoopInfo.h"
+#include "llvm/CodeGen/MachineRegisterInfo.h"
+#include "llvm/CodeGen/TargetRegisterInfo.h"
+#include <optional>
+
+namespace llvm {
+
+//------------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------------
+class AMDGPUNextUseAnalysisImpl;
+class AMDGPUNextUseAnalysis {
+  friend class AMDGPUNextUseAnalysisPass;
+
+  std::unique_ptr<AMDGPUNextUseAnalysisImpl> Impl;
+
+  void initialize(const MachineFunction *, const MachineLoopInfo *,
+                  const MachineDominatorTree *);
+
+public:
+  enum CompatibilityMode { Compute, Graphics };
----------------
macurtis-amd wrote:

Added more semantically meaningful config options with presets for `compute` and `graphics`. See also this [comment](https://github.com/llvm/llvm-project/pull/178873#discussion_r3074795540).

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


More information about the llvm-commits mailing list