diff options
| author | Yong He <yonghe@outlook.com> | 2018-12-13 12:26:36 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-13 12:26:36 -0800 |
| commit | 970b58a209e06afc7bd104e4701abfbb055f7c4d (patch) | |
| tree | cf57d89d6292d2f471c286b1b1c8d62d6b68bf84 /source/slang/ir.h | |
| parent | 8d13c06ab51f4993f5c56772e83fba3c384674df (diff) | |
| parent | 822ed708364b257b7d2f61ecb8a51a4c96f7edaa (diff) | |
Merge branch 'master' into dictfix
Diffstat (limited to 'source/slang/ir.h')
| -rw-r--r-- | source/slang/ir.h | 88 |
1 files changed, 45 insertions, 43 deletions
diff --git a/source/slang/ir.h b/source/slang/ir.h index 6fb0ff728..d68b3b8f3 100644 --- a/source/slang/ir.h +++ b/source/slang/ir.h @@ -257,10 +257,7 @@ struct IRInst // Look up a decoration in the list of decorations IRDecoration* findDecorationImpl(IROp op); template<typename T> - T* findDecoration() - { - return (T*) findDecorationImpl(IROp(T::kOp)); - } + T* findDecoration(); // The first use of this value (start of a linked list) IRUse* firstUse = nullptr; @@ -424,8 +421,18 @@ T* cast(IRInst* inst, T* /* */ = nullptr) return (T*)inst; } -// Now that `IRInst` is defined we can back-fill the `IRInstList<T>` members -// that need to access it. +// Now that `IRInst` is defined we can back-fill the definitions that need to access it. + +template<typename T> +T* IRInst::findDecoration() +{ + for( auto decoration : getDecorations() ) + { + if(auto match = as<T>(decoration)) + return match; + } + return nullptr; +} template<typename T> typename IRInstList<T>::Iterator IRInstList<T>::end() @@ -913,36 +920,8 @@ struct IRFuncType : IRType IR_LEAF_ISA(FuncType) }; -// A "global value" is an instruction that might have -// linkage, so that it can be declared in one module -// and then resolved to a definition in another module. -struct IRGlobalValue : IRInst -{ - // The mangled name, for a symbol that should have linkage, - // or which might have multiple declarations. - Name* mangledName = nullptr; - -#if 0 - // TODO: these all belong on `IRInst` - void insertBefore(IRGlobalValue* other); - void insertBefore(IRGlobalValue* other, IRModule* module); - void insertAtStart(IRModule* module); - - void insertAfter(IRGlobalValue* other); - void insertAfter(IRGlobalValue* other, IRModule* module); - void insertAtEnd(IRModule* module); - - void removeFromParent(); - - void moveToEnd(); -#endif - - IR_PARENT_ISA(GlobalValue) -}; - bool isDefinition( - IRGlobalValue* inVal); - + IRInst* inVal); // A structure type is represented as a parent instruction, // where the child instructions represent the fields of the @@ -953,7 +932,7 @@ bool isDefinition( // (that is, they have mangled names that can be used // for linkage). // -struct IRStructKey : IRGlobalValue +struct IRStructKey : IRInst { IR_LEAF_ISA(StructKey) }; @@ -978,7 +957,7 @@ struct IRStructField : IRInst // *not* contain the keys, because code needs to be able to // reference the keys from scopes outside of the struct. // -struct IRStructType : IRGlobalValue +struct IRStructType : IRInst { IRInstList<IRStructField> getFields() { return IRInstList<IRStructField>(getChildren()); } @@ -988,7 +967,7 @@ struct IRStructType : IRGlobalValue /// @brief A global value that potentially holds executable code. /// -struct IRGlobalValueWithCode : IRGlobalValue +struct IRGlobalValueWithCode : IRInst { // The children of a value with code will be the basic // blocks of its definition. @@ -1102,13 +1081,36 @@ struct IRModule : RefObject ObjectScopeManager m_objectScopeManager; }; -void printSlangIRAssembly(StringBuilder& builder, IRModule* module); -String getSlangIRAssembly(IRModule* module); + /// How much detail to include in dumped IR. + /// + /// Used with the `dumpIR` functions to determine + /// whether a completely faithful, but verbose, IR + /// dump is produced, or something simplified for ease + /// or reading. + /// +enum class IRDumpMode +{ + /// Produce a simplified IR dump. + /// + /// Simplified IR dumping will skip certain instructions + /// and print them at their use sites instead, so that + /// the overall dump is shorter and easier to read. + Simplified, + + /// Produce a detailed/accurate IR dump. + /// + /// A detailed IR dump will make sure to emit exactly + /// the instructions that were present with no attempt + /// to selectively skip them or give special formatting. + /// + Detailed, +}; -void dumpIR(IRModule* module, ISlangWriter* writer); -void dumpIR(IRGlobalValue* globalVal, ISlangWriter* writer); +void printSlangIRAssembly(StringBuilder& builder, IRModule* module, IRDumpMode mode = IRDumpMode::Simplified); +String getSlangIRAssembly(IRModule* module, IRDumpMode mode = IRDumpMode::Simplified); -String dumpIRFunc(IRFunc* func); +void dumpIR(IRModule* module, ISlangWriter* writer, IRDumpMode mode = IRDumpMode::Simplified); +void dumpIR(IRInst* globalVal, ISlangWriter* writer, IRDumpMode mode = IRDumpMode::Simplified); IRInst* createEmptyInst( IRModule* module, |
