summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/3rdparty/spirv-tools/source/opt/folding_rules.h
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/3rdparty/spirv-tools/source/opt/folding_rules.h')
-rw-r--r--3rdparty/bgfx/3rdparty/spirv-tools/source/opt/folding_rules.h53
1 files changed, 46 insertions, 7 deletions
diff --git a/3rdparty/bgfx/3rdparty/spirv-tools/source/opt/folding_rules.h b/3rdparty/bgfx/3rdparty/spirv-tools/source/opt/folding_rules.h
index 33fdbffe94b..f1a86395ca6 100644
--- a/3rdparty/bgfx/3rdparty/spirv-tools/source/opt/folding_rules.h
+++ b/3rdparty/bgfx/3rdparty/spirv-tools/source/opt/folding_rules.h
@@ -58,19 +58,58 @@ using FoldingRule = std::function<bool(
class FoldingRules {
public:
- FoldingRules();
+ using FoldingRuleSet = std::vector<FoldingRule>;
- const std::vector<FoldingRule>& GetRulesForOpcode(SpvOp opcode) const {
- auto it = rules_.find(opcode);
- if (it != rules_.end()) {
- return it->second;
+ explicit FoldingRules(IRContext* ctx) : context_(ctx) {}
+ virtual ~FoldingRules() = default;
+
+ const FoldingRuleSet& GetRulesForInstruction(Instruction* inst) const {
+ if (inst->opcode() != SpvOpExtInst) {
+ auto it = rules_.find(inst->opcode());
+ if (it != rules_.end()) {
+ return it->second;
+ }
+ } else {
+ uint32_t ext_inst_id = inst->GetSingleWordInOperand(0);
+ uint32_t ext_opcode = inst->GetSingleWordInOperand(1);
+ auto it = ext_rules_.find({ext_inst_id, ext_opcode});
+ if (it != ext_rules_.end()) {
+ return it->second;
+ }
}
return empty_vector_;
}
+ IRContext* context() { return context_; }
+
+ // Adds the folding rules for the object.
+ virtual void AddFoldingRules();
+
+ protected:
+ // The folding rules for core instructions.
+ std::unordered_map<uint32_t, FoldingRuleSet> rules_;
+
+ // The folding rules for extended instructions.
+ struct Key {
+ uint32_t instruction_set;
+ uint32_t opcode;
+ };
+
+ friend bool operator<(const Key& a, const Key& b) {
+ if (a.instruction_set < b.instruction_set) {
+ return true;
+ }
+ if (a.instruction_set > b.instruction_set) {
+ return false;
+ }
+ return a.opcode < b.opcode;
+ }
+
+ std::map<Key, FoldingRuleSet> ext_rules_;
+
private:
- std::unordered_map<uint32_t, std::vector<FoldingRule>> rules_;
- std::vector<FoldingRule> empty_vector_;
+ IRContext* context_;
+ FoldingRuleSet empty_vector_;
};
} // namespace opt