aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/CodeGen/MachineFunctionAttributes.h
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-01 17:36:40 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-01 17:36:40 +0800
commit787f3a7a20958bfa6f231abccc617f4d8de25c4d (patch)
tree775d2913f48fc5f3a6e44bc6da986da9e52754ef /backend/include/rcc/CodeGen/MachineFunctionAttributes.h
parent77d76b73a614820bf45024b053db376f35b06d10 (diff)
downloadrcc-project-787f3a7a20958bfa6f231abccc617f4d8de25c4d.tar.gz
rcc-project-787f3a7a20958bfa6f231abccc617f4d8de25c4d.tar.xz
[CodeGen] Add MIR function and block attributes
Diffstat (limited to 'backend/include/rcc/CodeGen/MachineFunctionAttributes.h')
-rw-r--r--backend/include/rcc/CodeGen/MachineFunctionAttributes.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/backend/include/rcc/CodeGen/MachineFunctionAttributes.h b/backend/include/rcc/CodeGen/MachineFunctionAttributes.h
new file mode 100644
index 0000000..4344640
--- /dev/null
+++ b/backend/include/rcc/CodeGen/MachineFunctionAttributes.h
@@ -0,0 +1,100 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef RCC_CODEGEN_MACHINEFUNCTIONATTRIBUTES_H
+#define RCC_CODEGEN_MACHINEFUNCTIONATTRIBUTES_H
+
+#include "rcc/CodeGen/MachineIRTypes.h"
+#include "rcc/Support/Error.h"
+
+#include <cstdint>
+#include <optional>
+#include <string_view>
+
+namespace rcc {
+
+enum class MachineFunctionAttribute : std::uint8_t {
+ ExposesReturnsTwice,
+ HasWinCFI,
+ HasFakeUses,
+ CallsEHReturn,
+ CallsUnwindInit,
+ HasEHContTarget,
+ HasEHScopes,
+ HasEHFunclets,
+ IsOutlined,
+ DebugInstrRef,
+ TracksDebugUserValues,
+ Count,
+};
+
+[[nodiscard]] std::string_view
+getMachineFunctionAttributeName(MachineFunctionAttribute Attribute) noexcept;
+
+class MachineFunctionAttributes final {
+public:
+ constexpr MachineFunctionAttributes() noexcept = default;
+
+ [[nodiscard]] static Expected<MachineFunctionAttributes> fromRawFlags(std::uint16_t RawFlags);
+
+ [[nodiscard]] constexpr bool has(MachineFunctionAttribute Attribute) const noexcept {
+ if (!isValidAttribute(Attribute))
+ return false;
+ return (Flags & flagFor(Attribute)) != 0;
+ }
+
+ constexpr void set(MachineFunctionAttribute Attribute) noexcept {
+ if (isValidAttribute(Attribute))
+ Flags |= flagFor(Attribute);
+ }
+
+ constexpr void clear(MachineFunctionAttribute Attribute) noexcept {
+ if (isValidAttribute(Attribute))
+ Flags &= static_cast<std::uint16_t>(~flagFor(Attribute));
+ }
+
+ [[nodiscard]] constexpr std::uint16_t rawFlags() const noexcept {
+ return Flags;
+ }
+
+ [[nodiscard]] std::optional<Alignment> alignment() const noexcept {
+ return FunctionAlignment;
+ }
+
+ void setAlignment(Alignment NewAlignment) noexcept {
+ FunctionAlignment = NewAlignment;
+ }
+
+ void clearAlignment() noexcept {
+ FunctionAlignment.reset();
+ }
+
+ [[nodiscard]] Expected<void> verify() const;
+
+ friend bool operator==(const MachineFunctionAttributes &Left,
+ const MachineFunctionAttributes &Right) = default;
+
+private:
+ static constexpr std::uint16_t AttributeCount =
+ static_cast<std::uint16_t>(MachineFunctionAttribute::Count);
+ static_assert(AttributeCount < 16);
+
+ static constexpr std::uint16_t ValidFlags =
+ static_cast<std::uint16_t>((std::uint16_t{1} << AttributeCount) - 1);
+
+ [[nodiscard]] static constexpr bool
+ isValidAttribute(MachineFunctionAttribute Attribute) noexcept {
+ return static_cast<std::uint16_t>(Attribute) < AttributeCount;
+ }
+
+ [[nodiscard]] static constexpr std::uint16_t
+ flagFor(MachineFunctionAttribute Attribute) noexcept {
+ return static_cast<std::uint16_t>(std::uint16_t{1} << static_cast<std::uint16_t>(Attribute));
+ }
+
+ std::uint16_t Flags = 0;
+ std::optional<Alignment> FunctionAlignment;
+};
+
+} // namespace rcc
+
+#endif // RCC_CODEGEN_MACHINEFUNCTIONATTRIBUTES_H