From 90c123a177b6282e797ee4c90b17bee867876c1a Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 17 May 2022 13:12:59 -0400 Subject: Liveness tracking with phis (#2233) * #include an absolute path didn't work - because paths were taken to always be relative. * Refactor Liveness pass, such that locations can be found independently of setting up ranges. * Refactor around different stages of liveness span analysis. * WIP Take into account PHI temporaries in liveness tracking. * WIP First pass of PHI liveness refactor. * Add BlockIndex. * WIP Refactor phi liveness around inst runs. * More improvements around liveness tracking. * Bug fixes. Special handling to not add multiple ends, at starts of blocks and after accesses. * Fix test output. * Use IRInsertLoc to track insertion point. * Liveness markers don't have side effects. * Fix typo in liveness test. * Small improvements around setting SuccessorResult. * Fix memory issue around reallocation and RAIIStackArray. Update test output. * Update test output for liveness.slang. * Fix typo in SuccessorResult blockIndex. * Small tidy up. * Handle the root start block, correctly scoping the run. * Split BlockInfo into 'Root' and 'Function'. Store successors as BlockIndices. * Tidy up around liveness tracking. * Add head/tail support to ArrayViews. Use Count where appropriate. Use head/tail in liveness impl. --- source/core/slang-array-view.h | 49 +++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 12 deletions(-) (limited to 'source/core') diff --git a/source/core/slang-array-view.h b/source/core/slang-array-view.h index 6f5277f5f..f6ac92004 100644 --- a/source/core/slang-array-view.h +++ b/source/core/slang-array-view.h @@ -14,19 +14,19 @@ namespace Slang public: typedef ConstArrayView ThisType; - const T* begin() const { return m_buffer; } + SLANG_FORCE_INLINE const T* begin() const { return m_buffer; } - const T* end() const { return m_buffer + m_count; } + SLANG_FORCE_INLINE const T* end() const { return m_buffer + m_count; } - inline Index getCount() const { return m_count; } + SLANG_FORCE_INLINE Count getCount() const { return m_count; } - inline const T& operator [](Index idx) const + SLANG_FORCE_INLINE const T& operator [](Index idx) const { SLANG_ASSERT(idx >= 0 && idx < m_count); return m_buffer[idx]; } - inline const T* getBuffer() const { return m_buffer; } + SLANG_FORCE_INLINE const T* getBuffer() const { return m_buffer; } template Index indexOf(const T2& val) const @@ -78,7 +78,7 @@ namespace Slang { return true; } - const Index count = getCount(); + const Count count = getCount(); if (count != rhs.getCount()) { return false; @@ -96,27 +96,38 @@ namespace Slang } SLANG_FORCE_INLINE bool operator!=(const ThisType& rhs) const { return !(*this == rhs); } + ThisType head(Index index) const + { + SLANG_ASSERT(index >= 0 && index <= m_count); + return ThisType(m_buffer, index); + } + ThisType tail(Index index) const + { + SLANG_ASSERT(index >= 0 && index <= m_count); + return ThisType(m_buffer + index, m_count - index); + } + ConstArrayView() : m_buffer(nullptr), m_count(0) { } - ConstArrayView(const T* buffer, Index count) : + ConstArrayView(const T* buffer, Count count) : m_buffer(const_cast(buffer)), m_count(count) { } protected: - ConstArrayView(T* buffer, Index count) : + ConstArrayView(T* buffer, Count count) : m_buffer(buffer), m_count(count) { } T* m_buffer; ///< Note that this isn't const, as is used for derived class ArrayView also - Index m_count; + Count m_count; }; template @@ -126,7 +137,7 @@ namespace Slang } template - ConstArrayView makeConstArrayView(const T* buffer, Index count) + ConstArrayView makeConstArrayView(const T* buffer, Count count) { return ConstArrayView(buffer, count); } @@ -157,6 +168,9 @@ namespace Slang using Super::end; T* end() { return m_buffer + m_count; } + using Super::head; + using Super::tail; + using Super::operator[]; inline T& operator [](Index idx) { @@ -167,6 +181,17 @@ namespace Slang using Super::getBuffer; inline T* getBuffer() { return m_buffer; } + ThisType head(Index index) + { + SLANG_ASSERT(index >= 0 && index <= m_count); + return ThisType(m_buffer, index); + } + ThisType tail(Index index) + { + SLANG_ASSERT(index >= 0 && index <= m_count); + return ThisType(m_buffer + index, m_count - index); + } + ArrayView() : Super() {} ArrayView(T* buffer, Index size) :Super(buffer, size) {} }; @@ -178,7 +203,7 @@ namespace Slang } template - ArrayView makeArrayView(T* buffer, Index count) + ArrayView makeArrayView(T* buffer, Count count) { return ArrayView(buffer, count); } @@ -186,7 +211,7 @@ namespace Slang template ArrayView makeArrayView(T (&arr)[N]) { - return ArrayView(arr, Index(N)); + return ArrayView(arr, Count(N)); } -- cgit v1.2.3