Files
RedBear-OS/local/recipes/dev/libclc/source/llvm/lib/CodeGen/MachineConvergenceVerifier.cpp
T
vasilito cb424d7448 build: static patch-sanity linter (shift-left the malformed-patch class)
verify-patch-sanity.py validates every active recipe .patch has internally-
consistent hunk line counts — catching the 'malformed patch at line N' failure
at commit/CI/preflight time instead of hours into a cook. This cycle hit that
class three times (qtwaylandscanner, sddm, xwayland), each only discovered when
cookbook tried to apply the patch.

Running it across the repo found 29 latent malformed patches (validated against
GNU patch: e.g. relibc/P3-sysv-ipc reproduces 'malformed patch at line 22').
They were harmless only because they sit in vendored recipes (baked, not re-
applied) — but would fail on any version-bump re-derivation. --fix recounts the
hunk headers (body untouched) and repaired all 29.

Wired into build-preflight.sh (Phase 1.0D) and redbear-ci.yml, with a unit test
(test-patch-sanity.sh). Skips archived/legacy trees and unvalidatable formats
(empty placeholders, bare-@@ git hunks).
2026-08-01 05:13:02 +03:00

99 lines
3.1 KiB
C++

//===- MachineConvergenceVerifier.cpp - Verify convergencectrl ------------===//
//
// 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/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::CONVERGENCECTRL_ENTRY:
return CONV_ENTRY;
case TargetOpcode::CONVERGENCECTRL_ANCHOR:
return CONV_ANCHOR;
case TargetOpcode::CONVERGENCECTRL_LOOP:
return CONV_LOOP;
}
}
template <>
void GenericConvergenceVerifier<
MachineSSAContext>::checkConvergenceTokenProduced(const MachineInstr &MI) {
Check(!MI.hasImplicitDef(),
"Convergence control tokens are defined explicitly.",
{Context.print(&MI)});
const MachineOperand &Def = MI.getOperand(0);
const MachineRegisterInfo &MRI = Context.getFunction()->getRegInfo();
Check(MRI.getUniqueVRegDef(Def.getReg()),
"Convergence control tokens must have unique definitions.",
{Context.print(&MI)});
}
template <>
const MachineInstr *
GenericConvergenceVerifier<MachineSSAContext>::findAndCheckConvergenceTokenUsed(
const MachineInstr &MI) {
const MachineRegisterInfo &MRI = Context.getFunction()->getRegInfo();
const MachineInstr *TokenDef = nullptr;
for (const MachineOperand &MO : MI.operands()) {
if (!MO.isReg() || !MO.isUse())
continue;
Register OpReg = MO.getReg();
if (!OpReg.isVirtual())
continue;
const MachineInstr *Def = MRI.getUniqueVRegDef(OpReg);
if (!Def)
continue;
if (getConvOp(*Def) == CONV_NONE)
continue;
CheckOrNull(
MI.isConvergent(),
"Convergence control tokens can only be used by convergent operations.",
{Context.print(OpReg), Context.print(&MI)});
CheckOrNull(!TokenDef,
"An operation can use at most one convergence control token.",
{Context.print(OpReg), Context.print(&MI)});
TokenDef = Def;
}
if (TokenDef)
Tokens[&MI] = TokenDef;
return TokenDef;
}
template <>
bool GenericConvergenceVerifier<MachineSSAContext>::isInsideConvergentFunction(
const MachineInstr &MI) {
// The class MachineFunction does not have any property to indicate whether it
// is convergent. Trivially return true so that the check always passes.
return true;
}
template <>
bool GenericConvergenceVerifier<MachineSSAContext>::isConvergent(
const MachineInstr &MI) {
return MI.isConvergent();
}
template class llvm::GenericConvergenceVerifier<MachineSSAContext>;