aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/CodeGen/MachineFunctionProperties.h
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-01 04:50:21 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-01 04:50:21 +0800
commit916b05ee8d79b22147c098cf52bba7fe86858f3f (patch)
treed798384e44ccdce3ffe34d5d5171034ba36d13e2 /backend/include/rcc/CodeGen/MachineFunctionProperties.h
parent81cf8b68eca2636574f3d0a9fa1cf0b428c163e9 (diff)
downloadrcc-project-916b05ee8d79b22147c098cf52bba7fe86858f3f.tar.gz
rcc-project-916b05ee8d79b22147c098cf52bba7fe86858f3f.tar.xz
[CodeGen] Add core machine type primitives
Introduce an independent 64-bit extended LLT representation that preserves exact floating-point semantics and supports fixed and scalable vectors. Add opaque physical and virtual registers, strongly typed monotonic stable IDs, and atomic MachineFunctionProperties transitions. Export the primitives through RCCBackend::CodeGen, cover their boundary and failure cases, record the frozen invariants, and normalize the architecture document permissions.
Diffstat (limited to 'backend/include/rcc/CodeGen/MachineFunctionProperties.h')
-rw-r--r--backend/include/rcc/CodeGen/MachineFunctionProperties.h131
1 files changed, 131 insertions, 0 deletions
diff --git a/backend/include/rcc/CodeGen/MachineFunctionProperties.h b/backend/include/rcc/CodeGen/MachineFunctionProperties.h
new file mode 100644
index 0000000..7d1a5ad
--- /dev/null
+++ b/backend/include/rcc/CodeGen/MachineFunctionProperties.h
@@ -0,0 +1,131 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef RCC_CODEGEN_MACHINEFUNCTIONPROPERTIES_H
+#define RCC_CODEGEN_MACHINEFUNCTIONPROPERTIES_H
+
+#include "rcc/Support/Error.h"
+
+#include <bit>
+#include <cstddef>
+#include <cstdint>
+#include <initializer_list>
+#include <string>
+#include <string_view>
+#include <type_traits>
+
+namespace rcc {
+
+enum class MachineFunctionProperty : std::uint8_t {
+ IsSSA,
+ NoPHIs,
+ TracksLiveness,
+ Legalized,
+ RegBankSelected,
+ Selected,
+ TiedOpsRewritten,
+ NoVRegs,
+ FrameFinalized,
+ NoFrameIndices,
+ NoExecutablePseudos,
+ Count,
+};
+
+[[nodiscard]] bool isKnownMachineFunctionProperty(MachineFunctionProperty Property) noexcept;
+[[nodiscard]] std::string_view
+getMachineFunctionPropertyName(MachineFunctionProperty Property) noexcept;
+
+class MachineFunctionProperties final {
+public:
+ constexpr MachineFunctionProperties() noexcept = default;
+
+ MachineFunctionProperties(std::initializer_list<MachineFunctionProperty> Properties) noexcept;
+
+ [[nodiscard]] static Expected<MachineFunctionProperties> fromRaw(std::uint64_t RawValue);
+
+ [[nodiscard]] constexpr bool empty() const noexcept {
+ return Mask == 0;
+ }
+
+ [[nodiscard]] constexpr std::size_t count() const noexcept {
+ return static_cast<std::size_t>(std::popcount(Mask));
+ }
+
+ [[nodiscard]] constexpr bool has(MachineFunctionProperty Property) const noexcept {
+ if (!isValidPropertyValue(Property))
+ return false;
+ return (Mask & maskFor(Property)) != 0;
+ }
+
+ [[nodiscard]] constexpr bool containsAll(MachineFunctionProperties Other) const noexcept {
+ return (Mask & Other.Mask) == Other.Mask;
+ }
+
+ [[nodiscard]] constexpr bool intersects(MachineFunctionProperties Other) const noexcept {
+ return (Mask & Other.Mask) != 0;
+ }
+
+ [[nodiscard]] constexpr MachineFunctionProperties
+ missingFrom(MachineFunctionProperties Available) const noexcept {
+ return MachineFunctionProperties(Mask & ~Available.Mask);
+ }
+
+ constexpr void set(MachineFunctionProperty Property) noexcept {
+ if (isValidPropertyValue(Property))
+ Mask |= maskFor(Property);
+ }
+
+ constexpr void clear(MachineFunctionProperty Property) noexcept {
+ if (isValidPropertyValue(Property))
+ Mask &= ~maskFor(Property);
+ }
+
+ [[nodiscard]] Expected<void> applyTransition(MachineFunctionProperties Required,
+ MachineFunctionProperties Sets,
+ MachineFunctionProperties Clears);
+
+ [[nodiscard]] constexpr std::uint64_t rawValue() const noexcept {
+ return Mask;
+ }
+
+ [[nodiscard]] std::string toString() const;
+
+ friend constexpr bool operator==(MachineFunctionProperties Left,
+ MachineFunctionProperties Right) noexcept = default;
+
+ friend constexpr MachineFunctionProperties operator|(MachineFunctionProperties Left,
+ MachineFunctionProperties Right) noexcept {
+ return MachineFunctionProperties(Left.Mask | Right.Mask);
+ }
+
+ friend constexpr MachineFunctionProperties operator&(MachineFunctionProperties Left,
+ MachineFunctionProperties Right) noexcept {
+ return MachineFunctionProperties(Left.Mask & Right.Mask);
+ }
+
+private:
+ static constexpr std::uint64_t PropertyCount =
+ static_cast<std::uint64_t>(MachineFunctionProperty::Count);
+ static_assert(PropertyCount < 64);
+
+ static constexpr std::uint64_t ValidMask = (std::uint64_t{1} << PropertyCount) - 1;
+
+ explicit constexpr MachineFunctionProperties(std::uint64_t Mask) noexcept : Mask(Mask) {}
+
+ [[nodiscard]] static constexpr bool
+ isValidPropertyValue(MachineFunctionProperty Property) noexcept {
+ return static_cast<std::uint64_t>(Property) < PropertyCount;
+ }
+
+ [[nodiscard]] static constexpr std::uint64_t maskFor(MachineFunctionProperty Property) noexcept {
+ return std::uint64_t{1} << static_cast<std::uint64_t>(Property);
+ }
+
+ std::uint64_t Mask = 0;
+};
+
+static_assert(sizeof(MachineFunctionProperties) == sizeof(std::uint64_t));
+static_assert(std::is_trivially_copyable_v<MachineFunctionProperties>);
+
+} // namespace rcc
+
+#endif // RCC_CODEGEN_MACHINEFUNCTIONPROPERTIES_H