[llvm] [AMDGPU] Add DAG mutation to improve scheduling before barriers (PR #142716)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 13 21:29:40 PDT 2025
================
@@ -0,0 +1,87 @@
+//===--- AMDGPUBarrierLatency.cpp - AMDGPU Barrier Latency ----------------===//
+//
+// 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 a DAG scheduling mutation to add latency to
+/// barrier edges between ATOMIC_FENCE instructions and preceeding
+/// memory accesses potentially affected by the fence.
+/// This is beneficial when a fence would cause wait count insertion,
+/// as more instructions will be scheduled before the fence hiding
+/// memory latency.
+/// It also reduces the risk of a fence causing a premature wait
+/// on all active memory operations.
+//
+//===----------------------------------------------------------------------===//
+
+#include "AMDGPUBarrierLatency.h"
+#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
+#include "SIInstrInfo.h"
+#include "llvm/CodeGen/ScheduleDAGInstrs.h"
+
+using namespace llvm;
+
+namespace {
+
+class BarrierLatency : public ScheduleDAGMutation {
+public:
+ BarrierLatency() = default;
+ void apply(ScheduleDAGInstrs *DAG) override;
+};
+
+static bool isMemLoad(const MachineInstr *MI) {
+ auto isLoad = [](const MachineInstr *MI) {
+ return (SIInstrInfo::isDS(*MI) || SIInstrInfo::isVMEM(*MI) ||
+ SIInstrInfo::isSMRD(*MI)) &&
+ MI->mayLoad();
+ };
+
+ if (MI->isBundle()) {
+ auto I = std::next(MI->getIterator());
+ return I != MI->getParent()->instr_end() && I->isInsideBundle() &&
+ isLoad(&*I);
+ }
----------------
arsenm wrote:
mayLoad on bundle should work?
https://github.com/llvm/llvm-project/pull/142716
More information about the llvm-commits
mailing list