Files
RedBear-OS/local/recipes/dev/libclc/source/mlir/lib/ExecutionEngine/ArmRunnerUtils.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

81 lines
2.7 KiB
C++

//===- ArmRunnerUtils.cpp - Utilities for configuring architecture properties //
//
// 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/Support/MathExtras.h"
#include <iostream>
#include <stdint.h>
#include <string_view>
#if (defined(_WIN32) || defined(__CYGWIN__))
#define MLIR_ARMRUNNERUTILS_EXPORTED __declspec(dllexport)
#else
#define MLIR_ARMRUNNERUTILS_EXPORTED __attribute__((visibility("default")))
#endif
#ifdef __linux__
#include <sys/prctl.h>
#endif
extern "C" {
// Defines for prctl() calls. These may not necessarily exist in the host
// <sys/prctl.h>, but will still be useable under emulation.
//
// https://www.kernel.org/doc/html/v5.3/arm64/sve.html#prctl-extensions
#ifndef PR_SVE_SET_VL
#define PR_SVE_SET_VL 50
#endif
// https://docs.kernel.org/arch/arm64/sme.html#prctl-extensions
#ifndef PR_SME_SET_VL
#define PR_SME_SET_VL 63
#endif
// Note: This mask is the same as both PR_SME_VL_LEN_MASK and
// PR_SVE_VL_LEN_MASK.
#define PR_VL_LEN_MASK 0xffff
/// Sets the vector length (streaming or not, as indicated by `option`) to
/// `bits`.
///
/// Caveat emptor: If a function has allocated stack slots for SVE registers
/// (e.g. slots for callee-saved SVE registers or spill slots) changing
/// the vector length is tricky and error prone - it may cause incorrect stack
/// deallocation or incorrect access to stack slots.
///
/// The recommended strategy is to call `setArmVectorLength` only from functions
/// that do not access SVE registers, either by themselves or by inlining other
/// functions.
static void setArmVectorLength(std::string_view helper_name, int option,
uint32_t bits) {
#if defined(__linux__) && defined(__aarch64__)
if (bits < 128 || bits > 2048 || !llvm::isPowerOf2_32(bits)) {
std::cerr << "[error] Attempted to set an invalid vector length (" << bits
<< "-bit)" << std::endl;
abort();
}
uint32_t vl = bits / 8;
if (auto ret = prctl(option, vl & PR_VL_LEN_MASK); ret < 0) {
std::cerr << "[error] prctl failed (" << ret << ")" << std::endl;
abort();
}
#else
std::cerr << "[error] " << helper_name << " is unsupported" << std::endl;
abort();
#endif
}
/// Sets the SVE vector length (in bits) to `bits`.
void MLIR_ARMRUNNERUTILS_EXPORTED setArmVLBits(uint32_t bits) {
setArmVectorLength(__func__, PR_SVE_SET_VL, bits);
}
/// Sets the SME streaming vector length (in bits) to `bits`.
void MLIR_ARMRUNNERUTILS_EXPORTED setArmSVLBits(uint32_t bits) {
setArmVectorLength(__func__, PR_SME_SET_VL, bits);
}
}