Subzero: Initial implementation of BB Local CSE
Adds Cfg::localCse for basic-block local common-subexpression elimination
If we have
t1 = op b c
t2 = op b c
This pass will replace future uses of t2 in a basic block by t1.
To enable, use -enable-experimental in O2
BUG=none
R=stichnot@chromium.org
Review URL: https://codereview.chromium.org/1997443002 .
diff --git a/src/IceOperand.h b/src/IceOperand.h
index b3e0f5f..fdb2a66 100644
--- a/src/IceOperand.h
+++ b/src/IceOperand.h
@@ -98,6 +98,12 @@
virtual Variable *asBoolean() { return nullptr; }
+ virtual SizeT hashValue() const {
+ llvm::report_fatal_error("Tried to hash unsupported operand type : " +
+ std::to_string(Kind));
+ return 0;
+ }
+
protected:
Operand(OperandKind Kind, Type Ty) : Ty(Ty), Kind(Kind) {
// It is undefined behavior to have a larger value in the enum
@@ -153,6 +159,7 @@
++LookupCount;
}
CounterType getLookupCount() const { return LookupCount; }
+ SizeT hashValue() const override { return 0; }
protected:
Constant(OperandKind Kind, Type Ty) : Operand(Kind, Ty) {
@@ -204,6 +211,10 @@
return Operand->getKind() == K;
}
+ SizeT hashValue() const override {
+ return std::hash<PrimType>()(Value);
+ }
+
virtual bool shouldBeRandomizedOrPooled() const override { return false; }
private:
@@ -769,6 +780,10 @@
return Kind >= kVariable && Kind <= kVariable_Max;
}
+ SizeT hashValue() const override {
+ return std::hash<SizeT>()(getIndex());
+ }
+
protected:
Variable(const Cfg *Func, OperandKind K, Type Ty, SizeT Index)
: Operand(K, Ty), Number(Index),