diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-09-06 14:15:11 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-06 14:15:11 -0700 |
| commit | ca16ede67d3fc34ec1cc81b8f835199c5ef1ab9a (patch) | |
| tree | fd83b7e861dbc6a0d442d5a913a1bcd9df547408 /source/slang/ir.h | |
| parent | e59a1b39317c10815baaed3b70c4a6580dbe1e63 (diff) | |
| parent | 5900f32fff9970b4221ce7fb7e94133e387ff9de (diff) | |
Merge pull request #176 from tfoleyNV/ir-work
Continue work on IR-based codegen
Diffstat (limited to 'source/slang/ir.h')
| -rw-r--r-- | source/slang/ir.h | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/source/slang/ir.h b/source/slang/ir.h index fcebf5d15..aa7b6a045 100644 --- a/source/slang/ir.h +++ b/source/slang/ir.h @@ -7,6 +7,8 @@ // similar in spirit to LLVM (but much simpler). // +#include "type-layout.h" + // We need the definition of `BaseType` which currently belongs to the AST #include "syntax.h" @@ -72,6 +74,7 @@ struct IRUse enum IRDecorationOp : uint16_t { kIRDecorationOp_HighLevelDecl, + kIRDecorationOp_Layout, }; // A "decoration" that gets applied to an instruction. @@ -161,6 +164,15 @@ struct IRHighLevelDeclDecoration : IRDecoration Decl* decl; }; +// Associates an IR-level decoration with a source layout +struct IRLayoutDecoration : IRDecoration +{ + enum { kDecorationOp = kIRDecorationOp_Layout }; + + Layout* layout; +}; + + typedef long long IRIntegerValue; typedef double IRFloatingPointValue; @@ -211,6 +223,41 @@ struct IRFuncType : IRType } }; +struct IRPtrType : IRType +{ + IRUse valueType; + + IRType* getValueType() { return (IRType*) valueType.usedValue; } +}; + +struct IRTextureType : IRType +{ + IRUse flavor; + IRUse elementType; + + IRIntegerValue getFlavor() { return ((IRConstant*) flavor.usedValue)->u.intVal; } + IRType* getElementType() { return (IRType*) elementType.usedValue; } +}; + +struct IRUniformBufferType : IRType +{ + IRUse elementType; + IRType* getElementType() { return (IRType*) elementType.usedValue; } +}; + +struct IRConstantBufferType : IRUniformBufferType {}; +struct IRTextureBufferType : IRUniformBufferType {}; + +struct IRCall : IRInst +{ + IRUse func; +}; + +struct IRLoad : IRInst +{ + IRUse ptr; +}; + struct IRStructField; struct IRFieldExtract : IRInst { @@ -221,6 +268,16 @@ struct IRFieldExtract : IRInst IRStructField* getField() { return (IRStructField*) field.usedValue; } }; +struct IRFieldAddress : IRInst +{ + IRUse base; + IRUse field; + + IRInst* getBase() { return base.usedValue; } + IRStructField* getField() { return (IRStructField*) field.usedValue; } +}; + + // A instruction that ends a basic block (usually because of control flow) struct IRTerminatorInst : IRInst {}; @@ -285,6 +342,9 @@ struct IRParam : IRInst IRParam* getNextParam(); }; +struct IRVar : IRInst +{}; + // 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 @@ -360,6 +420,11 @@ struct IRBuilder IRType* getVoidType(); IRType* getBlockType(); + IRType* getIntrinsicType( + IROp op, + UInt argCount, + IRValue* const* args); + IRStructDecl* createStructType(); IRStructField* createStructField(IRType* fieldType); @@ -368,10 +433,19 @@ struct IRBuilder IRType* const* paramTypes, IRType* resultType); + IRType* getPtrType( + IRType* valueType); + IRValue* getBoolValue(bool value); IRValue* getIntValue(IRType* type, IRIntegerValue value); IRValue* getFloatValue(IRType* type, IRFloatingPointValue value); + IRInst* emitCallInst( + IRType* type, + IRValue* func, + UInt argCount, + IRValue* const* args); + IRInst* emitIntrinsicInst( IRType* type, IntrinsicOp intrinsicOp, @@ -393,11 +467,22 @@ struct IRBuilder IRParam* emitParam( IRType* type); + IRVar* emitVar( + IRType* type); + + IRInst* emitLoad( + IRValue* ptr); + IRInst* emitFieldExtract( IRType* type, IRValue* base, IRStructField* field); + IRInst* emitFieldAddress( + IRType* type, + IRValue* basePtr, + IRStructField* field); + IRInst* emitReturn( IRValue* val); @@ -414,7 +499,14 @@ struct IRBuilder return (T*) addDecorationImpl(inst, sizeof(T), op); } + template<typename T> + T* addDecoration(IRInst* inst) + { + return (T*) addDecorationImpl(inst, sizeof(T), IRDecorationOp(T::kDecorationOp)); + } + IRHighLevelDeclDecoration* addHighLevelDeclDecoration(IRInst* inst, Decl* decl); + IRLayoutDecoration* addLayoutDecoration(IRInst* inst, Layout* layout); }; void dumpIR(IRModule* module); |
