diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-11-20 13:45:10 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-20 13:45:10 -0800 |
| commit | 37315c96ea48045fae60f0e1cb1a3293f3ddd962 (patch) | |
| tree | a96f139a7a2dae57f67956711be14bf773a50ec2 /source/slang/ir.h | |
| parent | 3dff5a53a21ab2404918e772962004767024c0f3 (diff) | |
IR: support global variable with initializers (#294)
The big change here is that the ability to contain basic blocks with instructions in them has been hoisted from `IRFunc` into a new base type `IRGlobalValueWithCode` shared with `IRGlobalVar`.
The basic blocks of a global variable define initialization logic for it; they can be looked at like a function that returns the initial value.
Places in the IR that used to assume functions contain all the code need to be updated, but so far I only handled the cloning step.
The emit logic currently handles an initializer for a global variable by outputting its logic as a separate function, and then having the variable call that function to initialize itself. This should be cleaned up over time so that we generate an ordinary expression whenever possible.
I also made the emit logic correctly label any global variable without a layout (that is, any that don't represent a shader parameter) as `static` so that the downstream HLSL compiler sees them as variables rather than parameters.
Diffstat (limited to 'source/slang/ir.h')
| -rw-r--r-- | source/slang/ir.h | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/source/slang/ir.h b/source/slang/ir.h index 12dc08e13..f2069e7c3 100644 --- a/source/slang/ir.h +++ b/source/slang/ir.h @@ -19,6 +19,7 @@ class Type; class Session; struct IRFunc; +struct IRGlobalValueWithCode; struct IRInst; struct IRModule; struct IRUser; @@ -364,9 +365,9 @@ struct IRBlock : IRValue void addParam(IRParam* param); // The parent function that contains this block - IRFunc* parentFunc; + IRGlobalValueWithCode* parentFunc; - IRFunc* getParent() { return parentFunc; } + IRGlobalValueWithCode* getParent() { return parentFunc; } }; @@ -405,11 +406,26 @@ struct IRGlobalValue : IRValue void moveToEnd(); }; +/// @brief A global value that potentially holds executable code. +/// +struct IRGlobalValueWithCode : IRGlobalValue +{ + // The list of basic blocks in this function + IRBlock* firstBlock = nullptr; + IRBlock* lastBlock = nullptr; + + IRBlock* getFirstBlock() { return firstBlock; } + IRBlock* getLastBlock() { return lastBlock; } + + // Add a block to the end of this function. + void addBlock(IRBlock* block); +}; + // A function is a parent to zero or more blocks of instructions. // // A function is itself a value, so that it can be a direct operand of // an instruction (e.g., a call). -struct IRFunc : IRGlobalValue +struct IRFunc : IRGlobalValueWithCode { // The type of the IR-level function IRFuncType* getType() { return (IRFuncType*) type.Ptr(); } @@ -425,16 +441,6 @@ struct IRFunc : IRGlobalValue UInt getParamCount(); Type* getParamType(UInt index); - // The list of basic blocks in this function - IRBlock* firstBlock = nullptr; - IRBlock* lastBlock = nullptr; - - IRBlock* getFirstBlock() { return firstBlock; } - IRBlock* getLastBlock() { return lastBlock; } - - // Add a block to the end of this function. - void addBlock(IRBlock* block); - // Convenience accessor for the IR parameters, // which are actually the parameters of the first // block. |
