Skip to content

[IR] Add more efficient getOperand methods to some of the Operator subclasses. #79943

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

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions llvm/include/llvm/IR/Operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -124,6 +127,12 @@ 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 {
Expand All @@ -141,6 +150,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;
Expand All @@ -165,6 +177,12 @@ 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 {
Expand Down Expand Up @@ -383,6 +401,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;
Expand Down Expand Up @@ -506,12 +527,21 @@ 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);
}
Expand All @@ -534,12 +564,21 @@ 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();
}
Expand All @@ -549,12 +588,21 @@ 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); }
Expand All @@ -568,6 +616,12 @@ class AddrSpaceCastOperator
}
};

template <>
struct OperandTraits<AddrSpaceCastOperator>
: public FixedNumOperandTraits<AddrSpaceCastOperator, 1> {};

DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AddrSpaceCastOperator, Value)

} // end namespace llvm

#endif // LLVM_IR_OPERATOR_H