Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/command-line-slangc-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ Print the hierarchy of the processed source files.

<a id="serial-ir"></a>
### -serial-ir
Serialize the IR between front-end and back-end.
\[REMOVED\] Serialize the IR between front-end and back-end.


<a id="skip-codegen"></a>
Expand Down
6 changes: 3 additions & 3 deletions include/slang.h
Original file line number Diff line number Diff line change
Expand Up @@ -963,9 +963,9 @@ typedef uint32_t SlangSizeT;
PreprocessorOutput,
OutputIncludes,
ReproFileSystem,
SerialIr, // bool
SkipCodeGen, // bool
ValidateIr, // bool
REMOVED_SerialIR, // deprecated and removed
SkipCodeGen, // bool
ValidateIr, // bool
VerbosePaths,
VerifyDebugSerialIr,
NoCodeGen, // Not used.
Expand Down
2 changes: 1 addition & 1 deletion source/slang-record-replay/util/emum-to-string.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ static Slang::String CompilerOptionNameToString(const slang::CompilerOptionName
CASE(PreprocessorOutput);
CASE(OutputIncludes);
CASE(ReproFileSystem);
CASE(SerialIr);
CASE(REMOVED_SerialIR);
CASE(SkipCodeGen);
CASE(ValidateIr);
CASE(VerbosePaths);
Expand Down
5 changes: 1 addition & 4 deletions source/slang/slang-compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2375,8 +2375,7 @@ SlangResult EndToEndCompileRequest::writeContainerToStream(Stream* stream)
// If debug information is enabled, enable writing out source locs
if (_shouldWriteSourceLocs(linkage))
{
options.optionFlags |= SerialOptionFlag::SourceLocation;
options.sourceManager = linkage->getSourceManager();
options.sourceManagerToUseWhenSerializingSourceLocs = linkage->getSourceManager();
}

SLANG_RETURN_ON_FAIL(SerialContainerUtil::write(this, options, stream));
Expand Down Expand Up @@ -2919,7 +2918,6 @@ bool CodeGenContext::isSpecializationDisabled()
SLANG_NO_THROW SlangResult SLANG_MCALL Module::serialize(ISlangBlob** outSerializedBlob)
{
SerialContainerUtil::WriteOptions writeOptions;
writeOptions.sourceManager = getLinkage()->getSourceManager();
OwnedMemoryStream memoryStream(FileAccess::Write);
SLANG_RETURN_ON_FAIL(SerialContainerUtil::write(this, writeOptions, &memoryStream));
*outSerializedBlob = RawBlob::create(
Expand All @@ -2932,7 +2930,6 @@ SLANG_NO_THROW SlangResult SLANG_MCALL Module::serialize(ISlangBlob** outSeriali
SLANG_NO_THROW SlangResult SLANG_MCALL Module::writeToFile(char const* fileName)
{
SerialContainerUtil::WriteOptions writeOptions;
writeOptions.sourceManager = getLinkage()->getSourceManager();
FileStream fileStream;
SLANG_RETURN_ON_FAIL(fileStream.init(fileName, FileMode::Create));
return SerialContainerUtil::write(this, writeOptions, &fileStream);
Expand Down
4 changes: 0 additions & 4 deletions source/slang/slang-compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2659,10 +2659,6 @@ class FrontEndCompileRequest : public CompileRequestBase
return translationUnits[index];
}

// If true then generateIR will serialize out IR, and serialize back in again. Making
// serialization a bottleneck or firewall between the front end and the backend
bool useSerialIRBottleneck = false;

// If true will serialize and de-serialize with debug information
bool verifyDebugSerialization = false;

Expand Down
7 changes: 2 additions & 5 deletions source/slang/slang-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,10 +809,10 @@ void initCommandOptions(CommandOptions& options)
"-output-includes",
nullptr,
"Print the hierarchy of the processed source files."},
{OptionKind::SerialIr,
{OptionKind::REMOVED_SerialIR,
"-serial-ir",
nullptr,
"Serialize the IR between front-end and back-end."},
"[REMOVED] Serialize the IR between front-end and back-end."},
{OptionKind::SkipCodeGen, "-skip-codegen", nullptr, "Skip the code generation phase."},
{OptionKind::ValidateIr, "-validate-ir", nullptr, "Validate the IR between the phases."},
{OptionKind::VerbosePaths,
Expand Down Expand Up @@ -2394,9 +2394,6 @@ SlangResult OptionsParser::_parse(int argc, char const* const* argv)
case OptionKind::ReproFileSystem:
SLANG_RETURN_ON_FAIL(_parseReproFileSystem(arg));
break;
case OptionKind::SerialIr:
m_frontEndReq->useSerialIRBottleneck = true;
break;
case OptionKind::VerbosePaths:
m_requestImpl->getSink()->setFlag(DiagnosticSink::Flag::VerbosePath);
break;
Expand Down
79 changes: 26 additions & 53 deletions source/slang/slang-serialize-container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace Slang
struct ModuleEncodingContext
{
private:
SerialContainerUtil::WriteOptions const& _options;
Stream* _stream = nullptr;

// The string pool used across the whole of the container
Expand All @@ -30,11 +29,12 @@ struct ModuleEncodingContext

public:
ModuleEncodingContext(SerialContainerUtil::WriteOptions const& options, Stream* stream)
: _options(options), _stream(stream), _containerStringPool(StringSlicePool::Style::Default)
: _stream(stream), _containerStringPool(StringSlicePool::Style::Default)
{
if (options.optionFlags & SerialOptionFlag::SourceLocation)
if (options.sourceManagerToUseWhenSerializingSourceLocs)
{
_sourceLocWriter = new SerialSourceLocWriter(options.sourceManager);
_sourceLocWriter =
new SerialSourceLocWriter(options.sourceManagerToUseWhenSerializingSourceLocs);
}

_cursor = RIFF::BuildCursor(_riff);
Expand Down Expand Up @@ -140,8 +140,7 @@ struct ModuleEncodingContext
IRSerialData serialData;
IRSerialWriter writer;

SLANG_RETURN_ON_FAIL(
writer.write(irModule, _sourceLocWriter, _options.optionFlags, &serialData));
SLANG_RETURN_ON_FAIL(writer.write(irModule, _sourceLocWriter, &serialData));
SLANG_RETURN_ON_FAIL(IRSerialWriter::writeTo(serialData, _cursor));

return SLANG_OK;
Expand Down Expand Up @@ -185,9 +184,6 @@ struct ModuleEncodingContext

SlangResult encode(Module* module)
{
if (!(_options.optionFlags & (SerialOptionFlag::IRModule | SerialOptionFlag::ASTModule)))
return SLANG_OK;

SLANG_SCOPED_RIFF_BUILDER_LIST_CHUNK(_cursor, SerialBinary::kModuleFourCC);

// The first piece that we write for a module is its header.
Expand Down Expand Up @@ -216,31 +212,22 @@ struct ModuleEncodingContext
encodeModuleDependencyPaths(module);
}

// If serialization of Slang IR modules is enabled, and there
// is IR available for this module, then we we encode it.
// If there is IR available for this module, then we we encode it.
//
if ((_options.optionFlags & SerialOptionFlag::IRModule))
if (auto irModule = module->getIRModule())
{
if (auto irModule = module->getIRModule())
{
IRSerialData serialData;
IRSerialWriter writer;
SLANG_RETURN_ON_FAIL(
writer.write(irModule, _sourceLocWriter, _options.optionFlags, &serialData));
SLANG_RETURN_ON_FAIL(IRSerialWriter::writeTo(serialData, _cursor));
}
IRSerialData serialData;
IRSerialWriter writer;
SLANG_RETURN_ON_FAIL(writer.write(irModule, _sourceLocWriter, &serialData));
SLANG_RETURN_ON_FAIL(IRSerialWriter::writeTo(serialData, _cursor));
}

// If serialization of AST information is enabled, and we have AST
// information available, then we serialize it here.
// If we have AST information available, then we serialize it here.
//
if (_options.optionFlags & SerialOptionFlag::ASTModule)
if (auto moduleDecl = module->getModuleDecl())
{
if (auto moduleDecl = module->getModuleDecl())
{
SLANG_SCOPED_RIFF_BUILDER_LIST_CHUNK(_cursor, PropertyKeys<Module>::ASTModule);
writeSerializedModuleAST(_cursor, moduleDecl, _sourceLocWriter);
}
SLANG_SCOPED_RIFF_BUILDER_LIST_CHUNK(_cursor, PropertyKeys<Module>::ASTModule);
writeSerializedModuleAST(_cursor, moduleDecl, _sourceLocWriter);
}

return SLANG_OK;
Expand Down Expand Up @@ -643,16 +630,16 @@ SlangResult decodeModuleIR(

RefPtr<SerialSourceLocWriter> sourceLocWriter;

if (options.optionFlags & SerialOptionFlag::SourceLocation)
if (options.sourceManagerToUseWhenSerializingSourceLocs)
{
sourceLocWriter = new SerialSourceLocWriter(options.sourceManager);
sourceLocWriter =
new SerialSourceLocWriter(options.sourceManagerToUseWhenSerializingSourceLocs);
}

{
// Write IR out to serialData - copying over SourceLoc information directly
// Write IR out to `irData`
IRSerialWriter writer;
SLANG_RETURN_ON_FAIL(
writer.write(module, sourceLocWriter, options.optionFlags, &irData));
SLANG_RETURN_ON_FAIL(writer.write(module, sourceLocWriter, &irData));
}
SLANG_RETURN_ON_FAIL(IRSerialWriter::writeTo(irData, cursor));

Expand All @@ -672,7 +659,7 @@ SlangResult decodeModuleIR(
memoryStream.seek(SeekOrigin::Start, 0);

SourceManager workSourceManager;
workSourceManager.initialize(options.sourceManager, nullptr);
workSourceManager.initialize(options.sourceManagerToUseWhenSerializingSourceLocs, nullptr);

// The read ir module
RefPtr<IRModule> irReadModule;
Expand All @@ -695,7 +682,7 @@ SlangResult decodeModuleIR(
RefPtr<SerialSourceLocReader> sourceLocReader;

// If we have debug info then find and read it
if (options.optionFlags & SerialOptionFlag::SourceLocation)
if (options.sourceManagerToUseWhenSerializingSourceLocs)
{
auto debugChunk = DebugChunk::find(moduleChunk);
if (!debugChunk)
Expand Down Expand Up @@ -742,23 +729,7 @@ SlangResult decodeModuleIR(
return SLANG_FAIL;
}

if (options.optionFlags & SerialOptionFlag::RawSourceLocation)
{
SLANG_ASSERT(readInsts[0] == originalInsts[0]);
// All the source locs should be identical
for (Index i = 1; i < readInsts.getCount(); ++i)
{
IRInst* origInst = originalInsts[i];
IRInst* readInst = readInsts[i];

if (origInst->sourceLoc.getRaw() != readInst->sourceLoc.getRaw())
{
SLANG_ASSERT(!"Source locs don't match");
return SLANG_FAIL;
}
}
}
else if (options.optionFlags & SerialOptionFlag::SourceLocation)
if (options.sourceManagerToUseWhenSerializingSourceLocs)
{
// They should be on the same line nos
for (Index i = 1; i < readInsts.getCount(); ++i)
Expand All @@ -772,7 +743,9 @@ SlangResult decodeModuleIR(
}

// Work out the
SourceView* origSourceView = options.sourceManager->findSourceView(origInst->sourceLoc);
SourceView* origSourceView =
options.sourceManagerToUseWhenSerializingSourceLocs->findSourceView(
origInst->sourceLoc);
SourceView* readSourceView = workSourceManager.findSourceView(readInst->sourceLoc);

// if both are null we are done
Expand Down
14 changes: 10 additions & 4 deletions source/slang/slang-serialize-container.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ struct SerialContainerUtil
{
struct WriteOptions
{
SerialOptionFlags optionFlags =
SerialOptionFlag::ASTModule |
SerialOptionFlag::IRModule; ///< Flags controlling what is written
SourceManager* sourceManager =
/// The source manager that is used by `SourceLoc`s in the input.
///
/// If null, source location information will not be serialized
/// as part of the output.
///
/// If non-null, it must be the `SourceManager` that was used to
/// create any `SourceLoc`s that appear in the module(s) that get
/// written.
///
SourceManager* sourceManagerToUseWhenSerializingSourceLocs =
nullptr; ///< The source manager used for the SourceLoc in the input
};

Expand Down
19 changes: 1 addition & 18 deletions source/slang/slang-serialize-ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ Result IRSerialWriter::_calcDebugInfo(SerialSourceLocWriter* sourceLocWriter)
Result IRSerialWriter::write(
IRModule* module,
SerialSourceLocWriter* sourceLocWriter,
SerialOptionFlags options,
IRSerialData* serialData)
{
typedef Ser::Inst::PayloadType PayloadType;
Expand Down Expand Up @@ -306,23 +305,7 @@ Result IRSerialWriter::write(
SerialStringTableUtil::encodeStringTable(m_stringSlicePool, serialData->m_stringTable);
}

// If the option to use RawSourceLocations is enabled, serialize out as is
if (options & SerialOptionFlag::RawSourceLocation)
{
const Index numInsts = m_insts.getCount();
serialData->m_rawSourceLocs.setCount(numInsts);

Ser::RawSourceLoc* dstLocs = serialData->m_rawSourceLocs.begin();
// 0 is null, just mark as no location
dstLocs[0] = Ser::RawSourceLoc(0);
for (Index i = 1; i < numInsts; ++i)
{
IRInst* srcInst = m_insts[i];
dstLocs[i] = Ser::RawSourceLoc(srcInst->sourceLoc.getRaw());
}
}

if ((options & SerialOptionFlag::SourceLocation) && sourceLocWriter)
if (sourceLocWriter)
{
_calcDebugInfo(sourceLocWriter);
}
Expand Down
1 change: 0 additions & 1 deletion source/slang/slang-serialize-ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ struct IRSerialWriter
Result write(
IRModule* module,
SerialSourceLocWriter* sourceLocWriter,
SerialOptionFlags flags,
IRSerialData* serialData);

/// Write to a container
Expand Down
19 changes: 0 additions & 19 deletions source/slang/slang-serialize-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,6 @@ namespace Slang
{
class Module;

// Options for IR/AST/Debug serialization

struct SerialOptionFlag
{
typedef uint32_t Type;
enum Enum : Type
{
RawSourceLocation =
0x01, ///< If set will store directly SourceLoc - only useful if current source locs
///< will be identical when read in (typically this is *NOT* the case)
SourceLocation = 0x02, ///< If set will output SourceLoc information, that can be
///< reconstructed when read after being stored.
ASTModule = 0x04, ///< If set will output AST modules - typically required, but potentially
///< not desired (for example with obsfucation)
IRModule = 0x08, ///< If set will output IR modules - typically required
};
};
typedef SerialOptionFlag::Type SerialOptionFlags;

struct SerialStringData
{
enum class StringIndex : uint32_t;
Expand Down
34 changes: 2 additions & 32 deletions source/slang/slang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,13 +637,11 @@ SlangResult Session::saveBuiltinModule(
// We want builtin modules to be saved with their source location
// information.
//
options.optionFlags |= SerialOptionFlag::SourceLocation;
//
// And in order to work with source locations, the serialization
// process will also need access to the source manager that
// can translate locations into their humane format.
//
options.sourceManager = m_builtinLinkage->getSourceManager();
options.sourceManagerToUseWhenSerializingSourceLocs = m_builtinLinkage->getSourceManager();

// At this point we can finally delegate down to the next level,
// which handles the serialization of a Slang module into a
Expand Down Expand Up @@ -3619,8 +3617,7 @@ void FrontEndCompileRequest::generateIR()
{
SerialContainerUtil::WriteOptions options;

options.sourceManager = getSourceManager();
options.optionFlags |= SerialOptionFlag::SourceLocation;
options.sourceManagerToUseWhenSerializingSourceLocs = getSourceManager();

// Verify debug information
if (SLANG_FAILED(
Expand All @@ -3632,33 +3629,6 @@ void FrontEndCompileRequest::generateIR()
}
}

if (useSerialIRBottleneck)
{
// Keep the obfuscated source map (if there is one)
ComPtr<IBoxValue<SourceMap>> obfuscatedSourceMap(irModule->getObfuscatedSourceMap());

IRSerialData serialData;
{
// Write IR out to serialData - copying over SourceLoc information directly
IRSerialWriter writer;
writer.write(irModule, nullptr, SerialOptionFlag::RawSourceLocation, &serialData);

// Destroy irModule such that memory can be used for newly constructed read
// irReadModule
irModule = nullptr;
}
RefPtr<IRModule> irReadModule;
{
// Read IR back from serialData
IRSerialReader reader;
reader.read(serialData, getSession(), nullptr, irReadModule);
}

// Set irModule to the read module
irModule = irReadModule;
irModule->setObfuscatedSourceMap(obfuscatedSourceMap);
}

// Set the module on the translation unit
translationUnit->getModule()->setIRModule(irModule);
}
Expand Down
Loading