-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IR] Add more efficient getOperand methods to some of the Operator subclasses. #79943
Conversation
…bclasses. ConstantExpr does not use HungOffUses. If we know that the Instruction the Operator subclass can represent also does not use HungOffUses, we can be more efficient than falling back to User::getOperand.
@llvm/pr-subscribers-llvm-ir Author: Craig Topper (topperc) ChangesConstantExpr does not use HungOffUses. If we know that the Instruction the Operator subclass can represent also does not use HungOffUses, we can be more efficient than falling back to User::getOperand. Full diff: https://github.com/llvm/llvm-project/pull/79943.diff 1 Files Affected:
diff --git a/llvm/include/llvm/IR/Operator.h b/llvm/include/llvm/IR/Operator.h
index 12733529a74dc..6e81ee9870f5b 100644
--- a/llvm/include/llvm/IR/Operator.h
+++ b/llvm/include/llvm/IR/Operator.h
@@ -94,6 +94,9 @@ class OverflowingBinaryOperator : public Operator {
}
public:
+ /// Transparently provide more efficient getOperand methods.
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+
/// Test whether this operation is known to never
/// undergo unsigned overflow, aka the nuw property.
bool hasNoUnsignedWrap() const {
@@ -124,6 +127,13 @@ class OverflowingBinaryOperator : public Operator {
}
};
+template <>
+struct OperandTraits<OverflowingBinaryOperator> :
+ public FixedNumOperandTraits<OverflowingBinaryOperator, 2> {
+};
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(OverflowingBinaryOperator, Value)
+
/// A udiv or sdiv instruction, which can be marked as "exact",
/// indicating that no bits are destroyed.
class PossiblyExactOperator : public Operator {
@@ -141,6 +151,9 @@ class PossiblyExactOperator : public Operator {
}
public:
+ /// Transparently provide more efficient getOperand methods.
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+
/// Test whether this division is known to be exact, with zero remainder.
bool isExact() const {
return SubclassOptionalData & IsExact;
@@ -165,6 +178,13 @@ class PossiblyExactOperator : public Operator {
}
};
+template <>
+struct OperandTraits<PossiblyExactOperator> :
+ public FixedNumOperandTraits<PossiblyExactOperator, 2> {
+};
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PossiblyExactOperator, Value)
+
/// Utility class for floating point operations which can have
/// information about relaxed accuracy requirements attached to them.
class FPMathOperator : public Operator {
@@ -383,6 +403,9 @@ class GEPOperator
}
public:
+ /// Transparently provide more efficient getOperand methods.
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+
/// Test whether this is an inbounds GEP, as defined by LangRef.html.
bool isInBounds() const {
return SubclassOptionalData & IsInBounds;
@@ -506,12 +529,22 @@ class GEPOperator
APInt &ConstantOffset) const;
};
+template <>
+struct OperandTraits<GEPOperator> :
+ public VariadicOperandTraits<GEPOperator, 1> {
+};
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GEPOperator, Value)
+
class PtrToIntOperator
: public ConcreteOperator<Operator, Instruction::PtrToInt> {
friend class PtrToInt;
friend class ConstantExpr;
public:
+ /// Transparently provide more efficient getOperand methods.
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+
Value *getPointerOperand() {
return getOperand(0);
}
@@ -534,12 +567,22 @@ class PtrToIntOperator
}
};
+template <>
+struct OperandTraits<PtrToIntOperator> :
+ public FixedNumOperandTraits<PtrToIntOperator, 1> {
+};
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PtrToIntOperator, Value)
+
class BitCastOperator
: public ConcreteOperator<Operator, Instruction::BitCast> {
friend class BitCastInst;
friend class ConstantExpr;
public:
+ /// Transparently provide more efficient getOperand methods.
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+
Type *getSrcTy() const {
return getOperand(0)->getType();
}
@@ -549,12 +592,22 @@ class BitCastOperator
}
};
+template <>
+struct OperandTraits<BitCastOperator> :
+ public FixedNumOperandTraits<BitCastOperator, 1> {
+};
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BitCastOperator, Value)
+
class AddrSpaceCastOperator
: public ConcreteOperator<Operator, Instruction::AddrSpaceCast> {
friend class AddrSpaceCastInst;
friend class ConstantExpr;
public:
+ /// Transparently provide more efficient getOperand methods.
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+
Value *getPointerOperand() { return getOperand(0); }
const Value *getPointerOperand() const { return getOperand(0); }
@@ -568,6 +621,13 @@ class AddrSpaceCastOperator
}
};
+template <>
+struct OperandTraits<AddrSpaceCastOperator> :
+ public FixedNumOperandTraits<AddrSpaceCastOperator, 1> {
+};
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AddrSpaceCastOperator, Value)
+
} // end namespace llvm
#endif // LLVM_IR_OPERATOR_H
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
ConstantExpr does not use HungOffUses. If we know that the Instruction the Operator subclass can represent also does not use HungOffUses, we can be more efficient than falling back to User::getOperand.