Line data Source code
1 : #ifdef __PLUMED_HAS_ASMJIT 2 : // This file is part of AsmJit project <https://asmjit.com> 3 : // 4 : // See asmjit.h or LICENSE.md for license and copyright information 5 : // SPDX-License-Identifier: Zlib 6 : 7 : #ifndef ASMJIT_CORE_RASTACK_P_H_INCLUDED 8 : #define ASMJIT_CORE_RASTACK_P_H_INCLUDED 9 : 10 : #include "api-config.h" 11 : #ifndef ASMJIT_NO_COMPILER 12 : 13 : #include "radefs_p.h" 14 : 15 : ASMJIT_BEGIN_NAMESPACE 16 : 17 : //! \cond INTERNAL 18 : //! \addtogroup asmjit_ra 19 : //! \{ 20 : 21 : //! Stack slot. 22 : struct RAStackSlot { 23 : //! Stack slot flags. 24 : //! 25 : //! TODO: kFlagStackArg is not used by the current implementation, do we need to keep it? 26 : enum Flags : uint16_t { 27 : //! Stack slot is register home slot. 28 : kFlagRegHome = 0x0001u, 29 : //! Stack slot position matches argument passed via stack. 30 : kFlagStackArg = 0x0002u 31 : }; 32 : 33 : enum ArgIndex : uint32_t { 34 : kNoArgIndex = 0xFF 35 : }; 36 : 37 : //! \name Members 38 : //! \{ 39 : 40 : //! Base register used to address the stack. 41 : uint8_t _baseRegId; 42 : //! Minimum alignment required by the slot. 43 : uint8_t _alignment; 44 : //! Reserved for future use. 45 : uint16_t _flags; 46 : //! Size of memory required by the slot. 47 : uint32_t _size; 48 : 49 : //! Usage counter (one unit equals one memory access). 50 : uint32_t _useCount; 51 : //! Weight of the slot, calculated by \ref RAStackAllocator::calculateStackFrame(). 52 : uint32_t _weight; 53 : //! Stack offset, calculated by \ref RAStackAllocator::calculateStackFrame(). 54 : int32_t _offset; 55 : 56 : //! \} 57 : 58 : //! \name Accessors 59 : //! \{ 60 : 61 71131 : inline uint32_t baseRegId() const noexcept { return _baseRegId; } 62 0 : inline void setBaseRegId(uint32_t id) noexcept { _baseRegId = uint8_t(id); } 63 : 64 30798 : inline uint32_t size() const noexcept { return _size; } 65 61596 : inline uint32_t alignment() const noexcept { return _alignment; } 66 : 67 : inline uint32_t flags() const noexcept { return _flags; } 68 61596 : inline bool hasFlag(uint32_t flag) const noexcept { return (_flags & flag) != 0; } 69 0 : inline void addFlags(uint32_t flags) noexcept { _flags = uint16_t(_flags | flags); } 70 : 71 : inline bool isRegHome() const noexcept { return hasFlag(kFlagRegHome); } 72 : inline bool isStackArg() const noexcept { return hasFlag(kFlagStackArg); } 73 : 74 30798 : inline uint32_t useCount() const noexcept { return _useCount; } 75 : inline void addUseCount(uint32_t n = 1) noexcept { _useCount += n; } 76 : 77 84519 : inline uint32_t weight() const noexcept { return _weight; } 78 30798 : inline void setWeight(uint32_t weight) noexcept { _weight = weight; } 79 : 80 101929 : inline int32_t offset() const noexcept { return _offset; } 81 30798 : inline void setOffset(int32_t offset) noexcept { _offset = offset; } 82 : 83 : //! \} 84 : }; 85 : 86 : typedef ZoneVector<RAStackSlot*> RAStackSlots; 87 : 88 : //! Stack allocator. 89 : class RAStackAllocator { 90 : public: 91 : ASMJIT_NONCOPYABLE(RAStackAllocator) 92 : 93 : enum Size : uint32_t { 94 : kSize1 = 0, 95 : kSize2 = 1, 96 : kSize4 = 2, 97 : kSize8 = 3, 98 : kSize16 = 4, 99 : kSize32 = 5, 100 : kSize64 = 6, 101 : kSizeCount = 7 102 : }; 103 : 104 : //! \name Members 105 : //! \{ 106 : 107 : //! Allocator used to allocate internal data. 108 : ZoneAllocator* _allocator; 109 : //! Count of bytes used by all slots. 110 : uint32_t _bytesUsed; 111 : //! Calculated stack size (can be a bit greater than `_bytesUsed`). 112 : uint32_t _stackSize; 113 : //! Minimum stack alignment. 114 : uint32_t _alignment; 115 : //! Stack slots vector. 116 : RAStackSlots _slots; 117 : 118 : //! \} 119 : 120 : //! \name Construction & Destruction 121 : //! \{ 122 : 123 : inline RAStackAllocator() noexcept 124 27492 : : _allocator(nullptr), 125 27492 : _bytesUsed(0), 126 27492 : _stackSize(0), 127 27492 : _alignment(1), 128 : _slots() {} 129 : 130 : inline void reset(ZoneAllocator* allocator) noexcept { 131 54984 : _allocator = allocator; 132 54984 : _bytesUsed = 0; 133 54984 : _stackSize = 0; 134 54984 : _alignment = 1; 135 : _slots.reset(); 136 : } 137 : 138 : //! \} 139 : 140 : //! \name Accessors 141 : //! \{ 142 : 143 61596 : inline ZoneAllocator* allocator() const noexcept { return _allocator; } 144 : 145 : inline uint32_t bytesUsed() const noexcept { return _bytesUsed; } 146 27492 : inline uint32_t stackSize() const noexcept { return _stackSize; } 147 27492 : inline uint32_t alignment() const noexcept { return _alignment; } 148 : 149 : inline RAStackSlots& slots() noexcept { return _slots; } 150 : inline const RAStackSlots& slots() const noexcept { return _slots; } 151 : inline uint32_t slotCount() const noexcept { return _slots.size(); } 152 : 153 : //! \} 154 : 155 : //! \name Utilities 156 : //! \{ 157 : 158 : RAStackSlot* newSlot(uint32_t baseRegId, uint32_t size, uint32_t alignment, uint32_t flags = 0) noexcept; 159 : 160 : Error calculateStackFrame() noexcept; 161 : Error adjustSlotOffsets(int32_t offset) noexcept; 162 : 163 : //! \} 164 : }; 165 : 166 : //! \} 167 : //! \endcond 168 : 169 : ASMJIT_END_NAMESPACE 170 : 171 : #endif // !ASMJIT_NO_COMPILER 172 : #endif // ASMJIT_CORE_RASTACK_P_H_INCLUDED 173 : 174 : #endif // __PLUMED_HAS_ASMJIT