Separate IRGenerator and Compiler into separate DSLWriter fields.

The only actual use of Compiler is in dsl::ReleaseProgram. All other
uses of Compiler in DSLWriter were to gain access to its internal
IRGenerator.

Change-Id: I0169cb1debf837894b1be3321f3d920259f7e91a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/451741
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
John Stiles 2021-09-22 12:23:23 -04:00 committed by SkCQ
parent 1a117d7642
commit fe9bfe6eeb
3 changed files with 37 additions and 24 deletions

View File

@ -34,22 +34,24 @@ void Start(SkSL::Compiler* compiler, ProgramKind kind) {
}
void Start(SkSL::Compiler* compiler, ProgramKind kind, const ProgramSettings& settings) {
DSLWriter::SetInstance(std::make_unique<DSLWriter>(&compiler->context(),
compiler, kind, settings,
DSLWriter::SetInstance(std::make_unique<DSLWriter>(&compiler->context(), compiler,
&compiler->irGenerator(), kind, settings,
compiler->moduleForProgramKind(kind),
/*isModule=*/false));
}
void Start(SkSL::Context* context, ProgramKind kind, const ProgramSettings& settings) {
DSLWriter::SetInstance(std::make_unique<DSLWriter>(context, /*compiler=*/nullptr, kind,
settings, /*module=*/skstd::nullopt,
DSLWriter::SetInstance(std::make_unique<DSLWriter>(context, /*compiler=*/nullptr,
/*irGenerator=*/nullptr, kind, settings,
/*module=*/skstd::nullopt,
/*isModule=*/false));
}
void StartModule(SkSL::Compiler* compiler, ProgramKind kind, const ProgramSettings& settings,
SkSL::ParsedModule module) {
DSLWriter::SetInstance(std::make_unique<DSLWriter>(&compiler->context(), compiler, kind,
settings, module, /*isModule=*/true));
DSLWriter::SetInstance(std::make_unique<DSLWriter>(&compiler->context(), compiler,
&compiler->irGenerator(), kind, settings,
module, /*isModule=*/true));
}
void End() {
@ -72,11 +74,12 @@ public:
static std::unique_ptr<SkSL::Program> ReleaseProgram(std::unique_ptr<String> source) {
DSLWriter& instance = DSLWriter::Instance();
SkSL::IRGenerator& ir = DSLWriter::IRGenerator();
SkSL::Compiler& compiler = DSLWriter::Compiler();
IRGenerator::IRBundle bundle = ir.finish();
Pool* pool = DSLWriter::Instance().fPool.get();
auto result = std::make_unique<SkSL::Program>(std::move(source),
std::move(instance.fConfig),
DSLWriter::Compiler().fContext,
compiler.fContext,
std::move(bundle.fElements),
std::move(bundle.fSharedElements),
std::move(instance.fModifiersPool),
@ -84,9 +87,9 @@ public:
std::move(instance.fPool),
bundle.fInputs);
bool success = false;
if (!DSLWriter::Compiler().finalize(*result)) {
if (!compiler.finalize(*result)) {
// Do not return programs that failed to compile.
} else if (!DSLWriter::Compiler().optimize(*result)) {
} else if (!compiler.optimize(*result)) {
// Do not return programs that failed to optimize.
} else {
// We have a successful program!

View File

@ -29,11 +29,13 @@ namespace SkSL {
namespace dsl {
DSLWriter::DSLWriter(SkSL::Context* context, SkSL::Compiler* compiler, SkSL::ProgramKind kind,
DSLWriter::DSLWriter(SkSL::Context* context, SkSL::Compiler* compiler,
SkSL::IRGenerator* irGenerator, SkSL::ProgramKind kind,
const SkSL::ProgramSettings& settings,
skstd::optional<SkSL::ParsedModule> module, bool isModule)
: fContext(context)
, fCompiler(compiler)
, fIRGenerator(irGenerator)
, fOldErrorReporter(*fContext->fErrors)
, fSettings(settings)
, fIsModule(isModule) {
@ -41,6 +43,9 @@ DSLWriter::DSLWriter(SkSL::Context* context, SkSL::Compiler* compiler, SkSL::Pro
if (fCompiler) {
SkASSERT(fContext == fCompiler->fContext.get());
}
if (fIRGenerator) {
SkASSERT(fContext == &fIRGenerator->fContext);
}
fOldModifiersPool = fContext->fModifiersPool;
@ -61,15 +66,15 @@ DSLWriter::DSLWriter(SkSL::Context* context, SkSL::Compiler* compiler, SkSL::Pro
fContext->fConfig = fConfig.get();
fContext->fErrors = &fDefaultErrorReporter;
if (compiler && module.has_value()) {
fCompiler->fIRGenerator->start(*module, isModule, &fProgramElements, &fSharedElements);
if (fIRGenerator && module.has_value()) {
fIRGenerator->start(*module, isModule, &fProgramElements, &fSharedElements);
}
}
DSLWriter::~DSLWriter() {
if (SymbolTable()) {
if (fCompiler) {
fCompiler->fIRGenerator->finish();
if (fIRGenerator) {
fIRGenerator->finish();
}
fProgramElements.clear();
} else {
@ -84,8 +89,16 @@ DSLWriter::~DSLWriter() {
}
}
SkSL::Compiler& DSLWriter::Compiler() {
SkSL::Compiler* compiler = Instance().fCompiler;
SkASSERT(compiler);
return *compiler;
}
SkSL::IRGenerator& DSLWriter::IRGenerator() {
return *Compiler().fIRGenerator;
SkSL::IRGenerator* irGenerator = Instance().fIRGenerator;
SkASSERT(irGenerator);
return *irGenerator;
}
SkSL::Context& DSLWriter::Context() {

View File

@ -50,9 +50,9 @@ class DSLVar;
*/
class DSLWriter {
public:
DSLWriter(SkSL::Context* context, SkSL::Compiler* compiler, SkSL::ProgramKind kind,
const SkSL::ProgramSettings& settings, skstd::optional<SkSL::ParsedModule> module,
bool isModule);
DSLWriter(SkSL::Context* context, SkSL::Compiler* compiler, SkSL::IRGenerator* irGenerator,
SkSL::ProgramKind kind, const SkSL::ProgramSettings& settings,
skstd::optional<SkSL::ParsedModule> module, bool isModule);
~DSLWriter();
@ -64,11 +64,7 @@ public:
/**
* Returns the Compiler used by DSL operations in the current thread.
*/
static SkSL::Compiler& Compiler() {
SkSL::Compiler* compiler = Instance().fCompiler;
SkASSERT(compiler);
return *compiler;
}
static SkSL::Compiler& Compiler();
/**
* Returns the IRGenerator used by DSL operations in the current thread.
@ -282,7 +278,7 @@ public:
}
/**
* Forwards any pending Compiler errors to the DSL ErrorReporter.
* Forwards any pending errors to the DSL ErrorReporter.
*/
static void ReportErrors(PositionInfo pos);
@ -299,6 +295,7 @@ private:
std::unique_ptr<SkSL::ModifiersPool> fModifiersPool;
SkSL::Context* fContext;
SkSL::Compiler* fCompiler;
SkSL::IRGenerator* fIRGenerator;
std::unique_ptr<Pool> fPool;
SkSL::ProgramConfig* fOldConfig;
SkSL::ModifiersPool* fOldModifiersPool;