diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2020-06-30 12:25:27 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-30 12:25:27 -0700 |
| commit | 8ced9d2a0efaca8f6dbdaf427be1db52844787b5 (patch) | |
| tree | 20dc0a8d3ec838253823558fc4df8a82ddd1a910 | |
| parent | dc44b08ec377106a0c6d1c022e2754d9e11c579f (diff) | |
Clean up unused code for IR object ownership (#1416)
There was a small but non-trivial amount of code across `IRModule`, the `ObjectScopeManager`, and `StringRepresentationCache` that had to do with managing the lifetimes of `RefObject`s that might be referenced by IR instructions (and thus need to be kept alive for the lifetime of the IR module).
We have long since migrated to a model where IR instruction do not include owned references to `RefObject`s, so these facilities weren't actually needed. This streamlines `IRModule`'s declaration, and trims code that we aren't actually using.
One note for the future is that the `StringRepresentationCache` no longer does what its name implies (it is not a cache of `StringRepresentation`s), so we should consider giving it a more narrowly scoped name. I didn't include that in this change because I wanted to keep the diffs narrow and easy to review.
A follow-on renaming change should be trivial if/when we can agree on what the type should be called at this point. Alternatively, we could simply bake the functionality of `StringRepresentationCache` into he IR deserialiation logic itself, since that is the only code using it.
| -rw-r--r-- | source/core/core.vcxproj | 2 | ||||
| -rw-r--r-- | source/core/core.vcxproj.filters | 6 | ||||
| -rw-r--r-- | source/core/slang-object-scope-manager.cpp | 23 | ||||
| -rw-r--r-- | source/core/slang-object-scope-manager.h | 67 | ||||
| -rw-r--r-- | source/slang/slang-ir-insts.h | 11 | ||||
| -rw-r--r-- | source/slang/slang-ir-serialize-types.cpp | 81 | ||||
| -rw-r--r-- | source/slang/slang-ir-serialize-types.h | 20 | ||||
| -rw-r--r-- | source/slang/slang-ir-serialize.cpp | 2 | ||||
| -rw-r--r-- | source/slang/slang-ir-serialize.h | 4 | ||||
| -rw-r--r-- | source/slang/slang-ir.h | 8 |
10 files changed, 9 insertions, 215 deletions
diff --git a/source/core/core.vcxproj b/source/core/core.vcxproj index 636edb46a..8c4e7753c 100644 --- a/source/core/core.vcxproj +++ b/source/core/core.vcxproj @@ -189,7 +189,6 @@ <ClInclude Include="slang-math.h" /> <ClInclude Include="slang-memory-arena.h" /> <ClInclude Include="slang-nvrtc-compiler.h" /> - <ClInclude Include="slang-object-scope-manager.h" /> <ClInclude Include="slang-offset-container.h" /> <ClInclude Include="slang-platform.h" /> <ClInclude Include="slang-process-util.h" /> @@ -225,7 +224,6 @@ <ClCompile Include="slang-io.cpp" /> <ClCompile Include="slang-memory-arena.cpp" /> <ClCompile Include="slang-nvrtc-compiler.cpp" /> - <ClCompile Include="slang-object-scope-manager.cpp" /> <ClCompile Include="slang-offset-container.cpp" /> <ClCompile Include="slang-platform.cpp" /> <ClCompile Include="slang-random-generator.cpp" /> diff --git a/source/core/core.vcxproj.filters b/source/core/core.vcxproj.filters index 49d8a1065..312c24b17 100644 --- a/source/core/core.vcxproj.filters +++ b/source/core/core.vcxproj.filters @@ -66,9 +66,6 @@ <ClInclude Include="slang-nvrtc-compiler.h"> <Filter>Header Files</Filter> </ClInclude> - <ClInclude Include="slang-object-scope-manager.h"> - <Filter>Header Files</Filter> - </ClInclude> <ClInclude Include="slang-offset-container.h"> <Filter>Header Files</Filter> </ClInclude> @@ -170,9 +167,6 @@ <ClCompile Include="slang-nvrtc-compiler.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="slang-object-scope-manager.cpp"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="slang-offset-container.cpp"> <Filter>Source Files</Filter> </ClCompile> diff --git a/source/core/slang-object-scope-manager.cpp b/source/core/slang-object-scope-manager.cpp deleted file mode 100644 index 2e7b7dfe3..000000000 --- a/source/core/slang-object-scope-manager.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "slang-object-scope-manager.h" - -namespace Slang { - -void ObjectScopeManager::_releaseAll() -{ - RefObject*const* objs = m_objs.begin(); - const Index numObjs = m_objs.getCount(); - for (Index i = 0; i < numObjs; ++i) - { - objs[i]->decreaseReference(); - } -} - -void ObjectScopeManager::clear() -{ - _releaseAll(); - // Free the memory as well as resizing - m_objs = List<RefObject*>(); -} - -} // namespace Slang - diff --git a/source/core/slang-object-scope-manager.h b/source/core/slang-object-scope-manager.h deleted file mode 100644 index 9930e46ea..000000000 --- a/source/core/slang-object-scope-manager.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef SLANG_CORE_OBJECT_SCOPE_MANAGER_H -#define SLANG_CORE_OBJECT_SCOPE_MANAGER_H - -#include "slang-smart-pointer.h" -#include "slang-list.h" - -namespace Slang { - -/** Keep objects added in scope. - -This is currently about the most simple implementation possible. Objects are added to a list -which members are released when ObjectScopeManager loses scope, or clear is called. - -The same object can be added multiple times. This implementation will just add the same object -multiple times. A more complex implementation might notice that the object is already in scope -and not add a reference. - -Another potential improvement would be to hold the pointers in a MemoryArena. Doing so would remove -the requirement of a List of contiguous memory. - -In implementations that can hold multiple references to the same thing, we may want to add some -garbage collection to remove repeat references. -*/ -struct ObjectScopeManager -{ -public: - - /// Add an object which will be kept in scope until manager is destroyed - SLANG_INLINE RefObject* add(RefObject* obj); - /// Add an object, where it may be nullptr. If it null its a no-op - SLANG_INLINE RefObject* addMaybeNull(RefObject* obj); - - /// Clear the contents - void clear(); - - /// Dtor - ~ObjectScopeManager() { _releaseAll(); } - -protected: - void _releaseAll(); - - List<RefObject*> m_objs; -}; - -// --------------------------------------------------------------------------- -RefObject* ObjectScopeManager::addMaybeNull(RefObject* obj) -{ - if (obj) - { - obj->addReference(); - m_objs.add(obj); - } - return obj; -} - -// --------------------------------------------------------------------------- -RefObject* ObjectScopeManager::add(RefObject* obj) -{ - SLANG_ASSERT(obj); - obj->addReference(); - m_objs.add(obj); - return obj; -} - -} // namespace Slang - -#endif // SLANG_OBJECT_SCOPE_MANAGER_H diff --git a/source/slang/slang-ir-insts.h b/source/slang/slang-ir-insts.h index f3a0688a7..c74dfb4ea 100644 --- a/source/slang/slang-ir-insts.h +++ b/source/slang/slang-ir-insts.h @@ -1520,10 +1520,6 @@ struct SharedIRBuilder Dictionary<IRInstKey, IRInst*> globalValueNumberingMap; Dictionary<IRConstantKey, IRConstant*> constantMap; - // TODO: We probably shouldn't use this in the long run. - Dictionary<void*, IRLayout*> layoutMap; - - void insertBlockAlongEdge(IREdge const& edge); }; @@ -2079,13 +2075,6 @@ struct IRBuilder return addDecoration(value, op, operands, SLANG_COUNT_OF(operands)); } - template <typename T> - T* addRefObjectToFree(T* ptr) - { - getModule()->getObjectScopeManager()->addMaybeNull(ptr); - return ptr; - } - template<typename T> void addSimpleDecoration(IRInst* value) { diff --git a/source/slang/slang-ir-serialize-types.cpp b/source/slang/slang-ir-serialize-types.cpp index a9d9baae0..b57c46b58 100644 --- a/source/slang/slang-ir-serialize-types.cpp +++ b/source/slang/slang-ir-serialize-types.cpp @@ -64,17 +64,13 @@ struct CharReader // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! StringRepresentationCache !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! StringRepresentationCache::StringRepresentationCache(): - m_stringTable(nullptr), - m_namePool(nullptr), - m_scopeManager(nullptr) + m_stringTable(nullptr) { } -void StringRepresentationCache::init(const List<char>* stringTable, NamePool* namePool, ObjectScopeManager* scopeManager) +void StringRepresentationCache::init(const List<char>* stringTable) { m_stringTable = stringTable; - m_namePool = namePool; - m_scopeManager = scopeManager; // Decode the table m_entries.setCount(StringSlicePool::kDefaultHandlesCount); @@ -84,13 +80,11 @@ void StringRepresentationCache::init(const List<char>* stringTable, NamePool* na Entry& entry = m_entries[0]; entry.m_numChars = 0; entry.m_startIndex = 0; - entry.m_object = nullptr; } { Entry& entry = m_entries[1]; entry.m_numChars = 0; entry.m_startIndex = 0; - entry.m_object = nullptr; } { @@ -106,7 +100,6 @@ void StringRepresentationCache::init(const List<char>* stringTable, NamePool* na Entry entry; entry.m_startIndex = uint32_t(reader.m_pos - start); entry.m_numChars = len; - entry.m_object = nullptr; m_entries.add(entry); @@ -117,38 +110,6 @@ void StringRepresentationCache::init(const List<char>* stringTable, NamePool* na m_entries.compress(); } -Name* StringRepresentationCache::getName(Handle handle) -{ - if (handle == StringSlicePool::kNullHandle) - { - return nullptr; - } - - Entry& entry = m_entries[int(handle)]; - if (entry.m_object) - { - Name* name = dynamicCast<Name>(entry.m_object); - if (name) - { - return name; - } - StringRepresentation* stringRep = static_cast<StringRepresentation*>(entry.m_object); - // Promote it to a name - name = m_namePool->getName(String(stringRep)); - entry.m_object = name; - return name; - } - - Name* name = m_namePool->getName(String(getStringSlice(handle))); - entry.m_object = name; - return name; -} - -String StringRepresentationCache::getString(Handle handle) -{ - return String(getStringRepresentation(handle)); -} - UnownedStringSlice StringRepresentationCache::getStringSlice(Handle handle) const { const Entry& entry = m_entries[int(handle)]; @@ -157,44 +118,6 @@ UnownedStringSlice StringRepresentationCache::getStringSlice(Handle handle) cons return UnownedStringSlice(start + entry.m_startIndex, int(entry.m_numChars)); } -StringRepresentation* StringRepresentationCache::getStringRepresentation(Handle handle) -{ - if (handle == StringSlicePool::kNullHandle || handle == StringSlicePool::kEmptyHandle) - { - return nullptr; - } - - Entry& entry = m_entries[int(handle)]; - if (entry.m_object) - { - Name* name = dynamicCast<Name>(entry.m_object); - if (name) - { - return name->text.getStringRepresentation(); - } - return static_cast<StringRepresentation*>(entry.m_object); - } - - const UnownedStringSlice slice = getStringSlice(handle); - const UInt size = slice.getLength(); - - StringRepresentation* stringRep = StringRepresentation::createWithCapacityAndLength(size, size); - memcpy(stringRep->getData(), slice.begin(), size); - entry.m_object = stringRep; - - // Keep the StringRepresentation in scope - m_scopeManager->add(stringRep); - - return stringRep; -} - -char* StringRepresentationCache::getCStr(Handle handle) -{ - // It turns out StringRepresentation is always 0 terminated, so can just use that - StringRepresentation* rep = getStringRepresentation(handle); - return rep->getData(); -} - // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! SerialStringTableUtil !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! /* static */void SerialStringTableUtil::encodeStringTable(const StringSlicePool& pool, List<char>& stringTable) diff --git a/source/slang/slang-ir-serialize-types.h b/source/slang/slang-ir-serialize-types.h index f4340e37e..b6d4572bd 100644 --- a/source/slang/slang-ir-serialize-types.h +++ b/source/slang/slang-ir-serialize-types.h @@ -2,7 +2,6 @@ #ifndef SLANG_IR_SERIALIZE_TYPES_H_INCLUDED #define SLANG_IR_SERIALIZE_TYPES_H_INCLUDED -#include "../core/slang-object-scope-manager.h" #include "../core/slang-riff.h" #include "../core/slang-string-slice-pool.h" #include "../core/slang-array-view.h" @@ -22,6 +21,10 @@ enum class IRSerialCompressionType : uint8_t class StringRepresentationCache { + // TODO: The name of this type is no longer accurate to its function. + // It doesn't *cache* anything, and instead just provides convenient + // access to the contents of a serialized string table. + public: typedef StringSlicePool::Handle Handle; @@ -29,29 +32,18 @@ class StringRepresentationCache { uint32_t m_startIndex; uint32_t m_numChars; - RefObject* m_object; ///< Could be nullptr, Name, or StringRepresentation. }; - /// Get as a name - Name* getName(Handle handle); - /// Get as a string - String getString(Handle handle); - /// Get as string representation - StringRepresentation* getStringRepresentation(Handle handle); /// Get as a string slice UnownedStringSlice getStringSlice(Handle handle) const; - /// Get as a 0 terminated 'c style' string - char* getCStr(Handle handle); - /// Initialize a cache to use a string table, namePool and scopeManager - void init(const List<char>* stringTable, NamePool* namePool, ObjectScopeManager* scopeManager); + /// Initialize a cache to use a string table + void init(const List<char>* stringTable); /// Ctor StringRepresentationCache(); protected: - ObjectScopeManager* m_scopeManager; - NamePool* m_namePool; const List<char>* m_stringTable; List<Entry> m_entries; }; diff --git a/source/slang/slang-ir-serialize.cpp b/source/slang/slang-ir-serialize.cpp index 4588816f7..369ea37c5 100644 --- a/source/slang/slang-ir-serialize.cpp +++ b/source/slang/slang-ir-serialize.cpp @@ -1081,7 +1081,7 @@ static int _calcFixSourceLoc(const IRSerialData::DebugSourceInfo& info, SourceVi module->session = session; // Set up the string rep cache - m_stringRepresentationCache.init(&data.m_stringTable, session->getNamePool(), module->getObjectScopeManager()); + m_stringRepresentationCache.init(&data.m_stringTable); // Add all the instructions diff --git a/source/slang/slang-ir-serialize.h b/source/slang/slang-ir-serialize.h index 94c0666bb..cec672b24 100644 --- a/source/slang/slang-ir-serialize.h +++ b/source/slang/slang-ir-serialize.h @@ -4,7 +4,6 @@ #include "slang-ir-serialize-types.h" -#include "../core/slang-object-scope-manager.h" #include "../core/slang-riff.h" #include "slang-ir.h" @@ -132,9 +131,6 @@ struct IRSerialReader /// Read a module from serial data Result read(const IRSerialData& data, Session* session, SourceManager* sourceManager, RefPtr<IRModule>& moduleOut); - /// Get the representation cache - StringRepresentationCache& getStringRepresentationCache() { return m_stringRepresentationCache; } - IRSerialReader(): m_serialData(nullptr), m_module(nullptr) diff --git a/source/slang/slang-ir.h b/source/slang/slang-ir.h index f3eccad25..a23d6cfa2 100644 --- a/source/slang/slang-ir.h +++ b/source/slang/slang-ir.h @@ -12,7 +12,6 @@ #include "slang-source-loc.h" #include "../core/slang-memory-arena.h" -#include "../core/slang-object-scope-manager.h" #include "slang-type-system-shared.h" @@ -1356,9 +1355,6 @@ struct IRModule : RefObject IRInstListBase getGlobalInsts() const { return getModuleInst()->getChildren(); } - /// Get the object scope manager - SLANG_FORCE_INLINE ObjectScopeManager* getObjectScopeManager() { return &m_objectScopeManager; } - /// Ctor IRModule(): memoryArena(kMemoryArenaBlockSize) @@ -1370,10 +1366,6 @@ struct IRModule : RefObject // The compilation session in use. Session* session; IRModuleInst* moduleInst; - - protected: - - ObjectScopeManager m_objectScopeManager; }; /// How much detail to include in dumped IR. |
