From 60a91d63afab47a172690974c8b566af74072932 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 9 Oct 2018 15:09:32 -0400 Subject: Added -serial-ir command line option (#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. --- source/slang/compiler.h | 6 +++++- source/slang/options.cpp | 4 ++++ source/slang/slang.cpp | 28 +++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/slang/compiler.h b/source/slang/compiler.h index bf71dd217..a83d8b334 100644 --- a/source/slang/compiler.h +++ b/source/slang/compiler.h @@ -320,7 +320,7 @@ namespace Slang List > translationUnits; // Entry points we've been asked to compile (each - // assocaited with a translation unit). + // associated with a translation unit). List > entryPoints; // Types constructed by reflection API @@ -342,6 +342,10 @@ namespace Slang bool shouldValidateIR = false; bool shouldSkipCodegen = false; + // 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; + // How should `#line` directives be emitted (if at all)? LineDirectiveMode lineDirectiveMode = LineDirectiveMode::Default; diff --git a/source/slang/options.cpp b/source/slang/options.cpp index 4d4b61fc8..944f66403 100644 --- a/source/slang/options.cpp +++ b/source/slang/options.cpp @@ -320,6 +320,10 @@ struct OptionsParser { requestImpl->shouldDumpIR = true; } + else if (argStr == "-serial-ir") + { + requestImpl->useSerialIRBottleneck = true; + } else if(argStr == "-validate-ir" ) { requestImpl->shouldValidateIR = true; diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 7c06a11e7..e3b675cd7 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -9,6 +9,8 @@ #include "syntax-visitors.h" #include "../slang/type-layout.h" +#include "ir-serialize.h" + // Used to print exception type names in internal-compiler-error messages #include @@ -484,7 +486,31 @@ void CompileRequest::generateIR() // in isolation. for( auto& translationUnit : translationUnits ) { - translationUnit->irModule = generateIRForTranslationUnit(translationUnit); + if (useSerialIRBottleneck) + { + IRSerialData serialData; + { + /// Generate IR for translation unit + RefPtr irModule(generateIRForTranslationUnit(translationUnit)); + + // Write IR out to serialData - copying over SourceLoc information directly + IRSerialWriter writer; + writer.write(irModule, sourceManager, IRSerialWriter::OptionFlag::RawSourceLocation, &serialData); + } + RefPtr irReadModule; + { + // Read IR back from serialData + IRSerialReader reader; + reader.read(serialData, mSession, irReadModule); + } + + // Use the serialized irModule + translationUnit->irModule = irReadModule; + } + else + { + translationUnit->irModule = generateIRForTranslationUnit(translationUnit); + } } } -- cgit v1.2.3