summaryrefslogtreecommitdiff
path: root/source/slang
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2020-06-30 12:25:27 -0700
committerGitHub <noreply@github.com>2020-06-30 12:25:27 -0700
commit8ced9d2a0efaca8f6dbdaf427be1db52844787b5 (patch)
tree20dc0a8d3ec838253823558fc4df8a82ddd1a910 /source/slang
parentdc44b08ec377106a0c6d1c022e2754d9e11c579f (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.
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/slang-ir-insts.h11
-rw-r--r--source/slang/slang-ir-serialize-types.cpp81
-rw-r--r--source/slang/slang-ir-serialize-types.h20
-rw-r--r--source/slang/slang-ir-serialize.cpp2
-rw-r--r--source/slang/slang-ir-serialize.h4
-rw-r--r--source/slang/slang-ir.h8
6 files changed, 9 insertions, 117 deletions
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.