[llvm] [GlobalISel] convergence control tokens and intrinsics (PR #67006)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 24 01:27:17 PDT 2023


================
@@ -0,0 +1,97 @@
+//===- ConvergenceVerifier.cpp - Verify convergence control -----*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CodeGen/MachineConvergenceVerifier.h"
+#include "llvm/CodeGen/GlobalISel/GenericMachineInstrs.h"
+#include "llvm/CodeGen/MachineDominators.h"
+#include "llvm/CodeGen/MachineRegisterInfo.h"
+#include "llvm/CodeGen/MachineSSAContext.h"
+#include "llvm/IR/GenericConvergenceVerifierImpl.h"
+
+using namespace llvm;
+
+template <>
+auto GenericConvergenceVerifier<MachineSSAContext>::getConvOp(
+    const MachineInstr &MI) -> ConvOpKind {
+  switch (MI.getOpcode()) {
+  default:
+    return CONV_NONE;
+  case TargetOpcode::G_CONVERGENCECTRL_ENTRY:
+    return CONV_ENTRY;
+  case TargetOpcode::G_CONVERGENCECTRL_ANCHOR:
+    return CONV_ANCHOR;
+  case TargetOpcode::G_CONVERGENCECTRL_LOOP:
+    return CONV_LOOP;
+  }
+}
+
+template <>
+const MachineInstr *
+GenericConvergenceVerifier<MachineSSAContext>::findAndCheckConvergenceTokenUsed(
+    const MachineInstr &MI) {
+  auto &MRI = Context.getFunction()->getRegInfo();
+  const MachineInstr *TokenDef = nullptr;
+
+  for (auto &MO : MI.uses()) {
+    if (!MO.isReg())
+      continue;
+
+    const auto RegTy = MRI.getType(MO.getReg());
+    if (RegTy != LLT::token())
+      continue;
+
+    // A token type operand is a convergence control token iff its unique
+    // definition is a convergence control intrinsic. We can't really verify
+    // that since the token type may have other implicit uses. Instead we use it
+    // as a way to identify convergence control token operands.
+    const auto *Def = MRI.getUniqueVRegDef(MO.getReg());
+    if (!Def)
----------------
arsenm wrote:

This can't happen for G_* instructions (and ideally would be impossible for all of SSA)

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


More information about the llvm-commits mailing list