summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2018-10-09 15:09:32 -0400
committerGitHub <noreply@github.com>2018-10-09 15:09:32 -0400
commit60a91d63afab47a172690974c8b566af74072932 (patch)
treea5d2d3592618deecbf55f91cca8824600fb12036 /source
parent7ea9ff03f4fc766f21d5896aea220d17f236dd70 (diff)
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.
Diffstat (limited to 'source')
-rw-r--r--source/slang/compiler.h6
-rw-r--r--source/slang/options.cpp4
-rw-r--r--source/slang/slang.cpp28
3 files changed, 36 insertions, 2 deletions
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<RefPtr<TranslationUnitRequest> > translationUnits;
// Entry points we've been asked to compile (each
- // assocaited with a translation unit).
+ // associated with a translation unit).
List<RefPtr<EntryPointRequest> > 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 <typeinfo>
@@ -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> irModule(generateIRForTranslationUnit(translationUnit));
+
+ // Write IR out to serialData - copying over SourceLoc information directly
+ IRSerialWriter writer;
+ writer.write(irModule, sourceManager, IRSerialWriter::OptionFlag::RawSourceLocation, &serialData);
+ }
+ RefPtr<IRModule> 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);
+ }
}
}