summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir.h
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-07-12 16:00:05 -0700
committerGitHub <noreply@github.com>2023-07-12 16:00:05 -0700
commit261b2f1f2bc13ccf7db5ec68c825ffc7b0781f7f (patch)
tree4953e376e705a8110cb8164dda5b239c04f2768b /source/slang/slang-ir.h
parentbbd9c2e6d7b57f5acc3238083ab2f7c7b140df5e (diff)
Use scratchData on `IRInst` to replace HashSets. (#2978)
* Use scratchData on `IRInst` to replace HashSets. * Update test results. * Initialize scratchData. * Update autodiff documentation. * Use enum instead of bool. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir.h')
-rw-r--r--source/slang/slang-ir.h50
1 files changed, 45 insertions, 5 deletions
diff --git a/source/slang/slang-ir.h b/source/slang/slang-ir.h
index 44dc585ab..e7c7f4fb2 100644
--- a/source/slang/slang-ir.h
+++ b/source/slang/slang-ir.h
@@ -548,6 +548,12 @@ private:
IRInst* m_inst = nullptr;
};
+enum class SideEffectAnalysisOptions
+{
+ None,
+ UseDominanceTree,
+};
+
// Every value in the IR is an instruction (even things
// like literal values).
//
@@ -733,6 +739,11 @@ struct IRInst
getOperands()[index].init(this, value);
}
+ // Reserved memory space for use by individual IR passes.
+ // This field is not supposed to be valid outside an IR pass,
+ // and each IR pass should always treat it as uninitialized
+ // upon entry.
+ UInt64 scratchData = 0;
//
@@ -785,7 +796,7 @@ struct IRInst
/// It is possible that this instruction has side effects?
///
/// This is a conservative test, and will return `true` if an exact answer can't be determined.
- bool mightHaveSideEffects();
+ bool mightHaveSideEffects(SideEffectAnalysisOptions options = SideEffectAnalysisOptions::None);
// RTTI support
static bool isaImpl(IROp) { return true; }
@@ -1971,12 +1982,41 @@ struct IRModule;
// Description of an instruction to be used for global value numbering
struct IRInstKey
{
- IRInst* inst;
+private:
+ IRInst* inst = nullptr;
+ HashCode hashCode = 0;
+ HashCode _getHashCode();
- HashCode getHashCode();
-};
+public:
+ IRInstKey() = default;
+ IRInstKey(const IRInstKey& key) = default;
+ IRInstKey(IRInst* i)
+ : inst(i)
+ {
+ hashCode = _getHashCode();
+ }
+ HashCode getHashCode() const { return hashCode; }
+ IRInst* getInst() const { return inst; }
-bool operator==(IRInstKey const& left, IRInstKey const& right);
+ bool operator==(IRInstKey const& right) const
+ {
+ if (hashCode != right.getHashCode()) return false;
+ if (getInst()->getOp() != right.getInst()->getOp()) return false;
+ if (getInst()->getFullType() != right.getInst()->getFullType()) return false;
+ if (getInst()->operandCount != right.getInst()->operandCount) return false;
+
+ auto argCount = getInst()->operandCount;
+ auto leftArgs = getInst()->getOperands();
+ auto rightArgs = right.getInst()->getOperands();
+ for (UInt aa = 0; aa < argCount; ++aa)
+ {
+ if (leftArgs[aa].get() != rightArgs[aa].get())
+ return false;
+ }
+
+ return true;
+ }
+};
struct IRConstantKey
{