Skip to content

Commit 60a91d6

Browse files
authored
Added -serial-ir command line option (shader-slang#664)
* Added -serial-ir option, to make generateIR always serialize in and out before further processing. Testing out serialization, and adding a kind of 'firewall' between compiler front end and backend. * Reduce peak memory usage, by discarding IR when stored in serialized form. Typo fix.
1 parent 7ea9ff0 commit 60a91d6

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

source/slang/compiler.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ namespace Slang
320320
List<RefPtr<TranslationUnitRequest> > translationUnits;
321321

322322
// Entry points we've been asked to compile (each
323-
// assocaited with a translation unit).
323+
// associated with a translation unit).
324324
List<RefPtr<EntryPointRequest> > entryPoints;
325325

326326
// Types constructed by reflection API
@@ -342,6 +342,10 @@ namespace Slang
342342
bool shouldValidateIR = false;
343343
bool shouldSkipCodegen = false;
344344

345+
// If true then generateIR will serialize out IR, and serialize back in again. Making
346+
// serialization a bottleneck or firewall between the front end and the backend
347+
bool useSerialIRBottleneck = false;
348+
345349
// How should `#line` directives be emitted (if at all)?
346350
LineDirectiveMode lineDirectiveMode = LineDirectiveMode::Default;
347351

source/slang/options.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ struct OptionsParser
320320
{
321321
requestImpl->shouldDumpIR = true;
322322
}
323+
else if (argStr == "-serial-ir")
324+
{
325+
requestImpl->useSerialIRBottleneck = true;
326+
}
323327
else if(argStr == "-validate-ir" )
324328
{
325329
requestImpl->shouldValidateIR = true;

source/slang/slang.cpp

+27-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "syntax-visitors.h"
1010
#include "../slang/type-layout.h"
1111

12+
#include "ir-serialize.h"
13+
1214
// Used to print exception type names in internal-compiler-error messages
1315
#include <typeinfo>
1416

@@ -484,7 +486,31 @@ void CompileRequest::generateIR()
484486
// in isolation.
485487
for( auto& translationUnit : translationUnits )
486488
{
487-
translationUnit->irModule = generateIRForTranslationUnit(translationUnit);
489+
if (useSerialIRBottleneck)
490+
{
491+
IRSerialData serialData;
492+
{
493+
/// Generate IR for translation unit
494+
RefPtr<IRModule> irModule(generateIRForTranslationUnit(translationUnit));
495+
496+
// Write IR out to serialData - copying over SourceLoc information directly
497+
IRSerialWriter writer;
498+
writer.write(irModule, sourceManager, IRSerialWriter::OptionFlag::RawSourceLocation, &serialData);
499+
}
500+
RefPtr<IRModule> irReadModule;
501+
{
502+
// Read IR back from serialData
503+
IRSerialReader reader;
504+
reader.read(serialData, mSession, irReadModule);
505+
}
506+
507+
// Use the serialized irModule
508+
translationUnit->irModule = irReadModule;
509+
}
510+
else
511+
{
512+
translationUnit->irModule = generateIRForTranslationUnit(translationUnit);
513+
}
488514
}
489515
}
490516

0 commit comments

Comments
 (0)