diff options
| author | Theresa Foley <10618364+tangent-vector@users.noreply.github.com> | 2022-04-11 12:01:31 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-11 12:01:31 -0700 |
| commit | 1409a5379d38ac153eabb4c19c7f4463a8b030ca (patch) | |
| tree | 0b5abbc64dbb46521b52453c9bee09469f032a2c /source/slang/slang-ir-specialize-resources.cpp | |
| parent | 2aac3700741f47caa6e8d674872979e2cdc251ab (diff) | |
Refactor: eliminate BackEndCompileRequest (#2178)
An earlier refactoring pass over the compiler codebase split the
type that had been called `CompileRequest` into three distinct
pieces:
* `FrontEndCompileRequest` which was supposed to own state and
options related to running the compiler front end and producing
IR + reflection (e.g., what translation units and source
files/strings are included).
* `BackEndCompileRequest` which was supposed to own state and options
related to running the compiler back end to translate the IR
for a `ComponentType` (program) into output code. (Note that the
`BackEndCompileRequest` was conceived of as orthogonal to the
`TargetRequest`s, which store per-target and target-specific
options.)
* `EndToEndCompileRequest` which was an umbrella object that owns
separate front-end and back-end requests, plus any state that is
only relevant when doing a true end-to-end compile (such as the
kinds of compiles initiated with `slangc`). As originally conceived,
the only state that this type was supposed to own was stuff related
to "pass-through" compilation, as well as state related to writing
of generated code to output files.
That refactoring work was very useful at the time, because it allowed
us to "scrub" the back end compilation steps to remove all
dependencies on front-end and AST state (this was important for our
goals of enabling linking and codegen from serialized Slang IR).
At this point, however, it is clear that the hierarchy that was built
up serves very little purpose:
* The `BackEndCompileRequest` type is only used in two places:
* As part of an `EndToEndCompileRequest`, where the settings on
the `BackEndCompileRequest` can be configured, but only through
the `EndToEndCompileRequest`
* As part of on-demand code generation through the `IComponentType`
APIs. In this case, the settings stored on the
`BackEndCompileRequest` are not accessible to the application
at all, and will always use their default values, so that
instantiating a "request" object doesn't really make any sense.
* The `FrontEndCompileRequest` type has a similar situation:
* Front-end compilation as part of an `EndToEndCompileRequest`
supports user configuration of `FrontEndCompileRequest` settings,
but only through the `EndToEndCompileRequest`
* Front-end compilation triggered by an `import` or a `loadModule()`
call does not support user configuration of settings at all. It
will always derive all relevant settings from thsoe on the
session ("linkage").
In addition, subsequent changes have been made to the compiler that
show a bit of a "code smell" and/or forward-looking worries for this
decomposition:
* In some cases we've had to add the same setting to multiple types
in the breakdown (front-end, back-end, end-to-end, linkage, target,
etc.) which makes it harder for us to validate that all the possible
mixtures of state work correctly.
* Related to the above, in some cases we have manual logic that copies
state from one of the objects in the breakdown to another, in order
to ensure that the user's intention is actually followed.
* As a forward-looking concern, it seems that developers have sometimes
added new configuration options and state to places that don't really
make sense according to the rationale of the original decomposition
(e.g., we probably don't want to have a lot of state that is only
available via end-to-end requests, given that the API structure is
meant to push users *away* from end-to-end compiles).
As a result of all of the above, I've been planning a large refactor
with the following big-picture goals:
* Eliminate `BackEndCompileRequest`
* Move all relevant state/options from the back-end request to
the end-to-end request, since that is the only place they could
be set anyway.
* Introduce a transient "context" type to be used for the duration
of code generation that serves the main functions that back-end
requests really served in the codebase
* Make `EndToEndCompileRequest` be a subclass of
`FrontEndCompileRequest`
* Consider addding a transient "context" type for front-end
compiles that can be used in `import`-like cases rather than
needing a full front-end request object. If this works, then
eliminate `FrontEndCompileRequest` and be back to world with
just a single `CompileRequest` type
* Move *all* compiler configuration options to a distinct type (named
something like `CompilerConfig` or `CompilerOptions` or whatever)
which stores setting as key-value pairs, and has a notion of
"inheritance" such that one configuration can extend or build on top
of another. Make all the relevant types use this catch-all structure
instead of redundantly storing flags in many places.
This change deals with the first of those bullets: removeal of
`BackEndCompileRequest`. The addition of the `CodeGenContext` type is
perhaps an unncessary additional step, but making that change helps
clean up a bunch of the code related to per-target code generation,
so I think it is the right choice.
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-ir-specialize-resources.cpp')
| -rw-r--r-- | source/slang/slang-ir-specialize-resources.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/source/slang/slang-ir-specialize-resources.cpp b/source/slang/slang-ir-specialize-resources.cpp index 01e1c396c..05a7c23de 100644 --- a/source/slang/slang-ir-specialize-resources.cpp +++ b/source/slang/slang-ir-specialize-resources.cpp @@ -85,17 +85,16 @@ struct ResourceParameterSpecializationCondition : FunctionCallSpecializeConditio }; bool specializeResourceParameters( - BackEndCompileRequest* compileRequest, - TargetRequest* targetRequest, + CodeGenContext* codeGenContext, IRModule* module) { bool result = false; ResourceParameterSpecializationCondition condition; - condition.targetRequest = targetRequest; + condition.targetRequest = codeGenContext->getTargetReq(); bool changed = true; while (changed) { - changed = specializeFunctionCalls(compileRequest, targetRequest, module, &condition); + changed = specializeFunctionCalls(codeGenContext, module, &condition); simplifyIR(module); result |= changed; } @@ -112,7 +111,7 @@ struct ResourceOutputSpecializationPass // via `return` or `out`/`inout` parmeters), and then specializes the // *call sites* for those functions based on the values that are output. - BackEndCompileRequest* compileRequest; + CodeGenContext* codeGenContext; TargetRequest* targetRequest; IRModule* module; @@ -1116,11 +1115,11 @@ struct ResourceOutputSpecializationPass }; bool specializeResourceOutputs( - BackEndCompileRequest* compileRequest, - TargetRequest* targetRequest, + CodeGenContext* codeGenContext, IRModule* module, List<IRFunc*>& unspecializableFuncs) { + auto targetRequest = codeGenContext->getTargetReq(); if(isD3DTarget(targetRequest) || isKhronosTarget(targetRequest)) {} else @@ -1136,7 +1135,7 @@ bool specializeResourceOutputs( } ResourceOutputSpecializationPass pass; - pass.compileRequest = compileRequest; + pass.codeGenContext = codeGenContext; pass.targetRequest = targetRequest; pass.module = module; pass.unspecializableFuncs = &unspecializableFuncs; @@ -1144,7 +1143,8 @@ bool specializeResourceOutputs( } bool specializeResourceUsage( - BackEndCompileRequest* compileRequest, TargetRequest* targetRequest, IRModule* irModule) + CodeGenContext* codeGenContext, + IRModule* irModule) { bool result = false; // We apply two kinds of specialization to clean up resource value usage: @@ -1173,8 +1173,8 @@ bool specializeResourceUsage( // pass down the target request along with the IR. // changed |= specializeResourceOutputs( - compileRequest, targetRequest, irModule, unspecializableFuncs); - changed |= specializeResourceParameters(compileRequest, targetRequest, irModule); + codeGenContext, irModule, unspecializableFuncs); + changed |= specializeResourceParameters(codeGenContext, irModule); // After specialization of function outputs, we may find that there // are cases where opaque-typed local variables can now be eliminated |
