Skip to content

Commit 8369f61

Browse files
authored
[IR] Add more efficient getOperand methods to some of the Operator subclasses. (#79943)
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.
1 parent b40d5b1 commit 8369f61

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

llvm/include/llvm/IR/Operator.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ class OverflowingBinaryOperator : public Operator {
9494
}
9595

9696
public:
97+
/// Transparently provide more efficient getOperand methods.
98+
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
99+
97100
/// Test whether this operation is known to never
98101
/// undergo unsigned overflow, aka the nuw property.
99102
bool hasNoUnsignedWrap() const {
@@ -124,6 +127,12 @@ class OverflowingBinaryOperator : public Operator {
124127
}
125128
};
126129

130+
template <>
131+
struct OperandTraits<OverflowingBinaryOperator>
132+
: public FixedNumOperandTraits<OverflowingBinaryOperator, 2> {};
133+
134+
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(OverflowingBinaryOperator, Value)
135+
127136
/// A udiv or sdiv instruction, which can be marked as "exact",
128137
/// indicating that no bits are destroyed.
129138
class PossiblyExactOperator : public Operator {
@@ -141,6 +150,9 @@ class PossiblyExactOperator : public Operator {
141150
}
142151

143152
public:
153+
/// Transparently provide more efficient getOperand methods.
154+
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
155+
144156
/// Test whether this division is known to be exact, with zero remainder.
145157
bool isExact() const {
146158
return SubclassOptionalData & IsExact;
@@ -165,6 +177,12 @@ class PossiblyExactOperator : public Operator {
165177
}
166178
};
167179

180+
template <>
181+
struct OperandTraits<PossiblyExactOperator>
182+
: public FixedNumOperandTraits<PossiblyExactOperator, 2> {};
183+
184+
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PossiblyExactOperator, Value)
185+
168186
/// Utility class for floating point operations which can have
169187
/// information about relaxed accuracy requirements attached to them.
170188
class FPMathOperator : public Operator {
@@ -383,6 +401,9 @@ class GEPOperator
383401
}
384402

385403
public:
404+
/// Transparently provide more efficient getOperand methods.
405+
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
406+
386407
/// Test whether this is an inbounds GEP, as defined by LangRef.html.
387408
bool isInBounds() const {
388409
return SubclassOptionalData & IsInBounds;
@@ -506,12 +527,21 @@ class GEPOperator
506527
APInt &ConstantOffset) const;
507528
};
508529

530+
template <>
531+
struct OperandTraits<GEPOperator>
532+
: public VariadicOperandTraits<GEPOperator, 1> {};
533+
534+
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GEPOperator, Value)
535+
509536
class PtrToIntOperator
510537
: public ConcreteOperator<Operator, Instruction::PtrToInt> {
511538
friend class PtrToInt;
512539
friend class ConstantExpr;
513540

514541
public:
542+
/// Transparently provide more efficient getOperand methods.
543+
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
544+
515545
Value *getPointerOperand() {
516546
return getOperand(0);
517547
}
@@ -534,12 +564,21 @@ class PtrToIntOperator
534564
}
535565
};
536566

567+
template <>
568+
struct OperandTraits<PtrToIntOperator>
569+
: public FixedNumOperandTraits<PtrToIntOperator, 1> {};
570+
571+
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PtrToIntOperator, Value)
572+
537573
class BitCastOperator
538574
: public ConcreteOperator<Operator, Instruction::BitCast> {
539575
friend class BitCastInst;
540576
friend class ConstantExpr;
541577

542578
public:
579+
/// Transparently provide more efficient getOperand methods.
580+
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
581+
543582
Type *getSrcTy() const {
544583
return getOperand(0)->getType();
545584
}
@@ -549,12 +588,21 @@ class BitCastOperator
549588
}
550589
};
551590

591+
template <>
592+
struct OperandTraits<BitCastOperator>
593+
: public FixedNumOperandTraits<BitCastOperator, 1> {};
594+
595+
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BitCastOperator, Value)
596+
552597
class AddrSpaceCastOperator
553598
: public ConcreteOperator<Operator, Instruction::AddrSpaceCast> {
554599
friend class AddrSpaceCastInst;
555600
friend class ConstantExpr;
556601

557602
public:
603+
/// Transparently provide more efficient getOperand methods.
604+
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
605+
558606
Value *getPointerOperand() { return getOperand(0); }
559607

560608
const Value *getPointerOperand() const { return getOperand(0); }
@@ -568,6 +616,12 @@ class AddrSpaceCastOperator
568616
}
569617
};
570618

619+
template <>
620+
struct OperandTraits<AddrSpaceCastOperator>
621+
: public FixedNumOperandTraits<AddrSpaceCastOperator, 1> {};
622+
623+
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AddrSpaceCastOperator, Value)
624+
571625
} // end namespace llvm
572626

573627
#endif // LLVM_IR_OPERATOR_H

0 commit comments

Comments
 (0)