#ifndef LLVM_IR_INTRINSICINST_H
#define LLVM_IR_INTRINSICINST_H
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/FPEnv.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/Casting.h"
#include <cassert>
#include <cstdint>
namespace llvm {
class Metadata;
class IntrinsicInst : public CallInst {
public:
IntrinsicInst() = delete;
IntrinsicInst(const IntrinsicInst &) = delete;
IntrinsicInst &operator=(const IntrinsicInst &) = delete;
Intrinsic::ID getIntrinsicID() const {
return getCalledFunction()->getIntrinsicID();
}
bool isCommutative() const {
switch (getIntrinsicID()) {
case Intrinsic::maxnum:
case Intrinsic::minnum:
case Intrinsic::maximum:
case Intrinsic::minimum:
case Intrinsic::smax:
case Intrinsic::smin:
case Intrinsic::umax:
case Intrinsic::umin:
case Intrinsic::sadd_sat:
case Intrinsic::uadd_sat:
case Intrinsic::sadd_with_overflow:
case Intrinsic::uadd_with_overflow:
case Intrinsic::smul_with_overflow:
case Intrinsic::umul_with_overflow:
case Intrinsic::smul_fix:
case Intrinsic::umul_fix:
case Intrinsic::smul_fix_sat:
case Intrinsic::umul_fix_sat:
case Intrinsic::fma:
case Intrinsic::fmuladd:
return true;
default:
return false;
}
}
bool isAssumeLikeIntrinsic() const {
switch (getIntrinsicID()) {
default: break;
case Intrinsic::assume:
case Intrinsic::sideeffect:
case Intrinsic::pseudoprobe:
case Intrinsic::dbg_declare:
case Intrinsic::dbg_value:
case Intrinsic::dbg_label:
case Intrinsic::invariant_start:
case Intrinsic::invariant_end:
case Intrinsic::lifetime_start:
case Intrinsic::lifetime_end:
case Intrinsic::experimental_noalias_scope_decl:
case Intrinsic::objectsize:
case Intrinsic::ptr_annotation:
case Intrinsic::var_annotation:
return true;
}
return false;
}
static bool mayLowerToFunctionCall(Intrinsic::ID IID);
static bool classof(const CallInst *I) {
if (const Function *CF = I->getCalledFunction())
return CF->isIntrinsic();
return false;
}
static bool classof(const Value *V) {
return isa<CallInst>(V) && classof(cast<CallInst>(V));
}
};
static inline bool isDbgInfoIntrinsic(Intrinsic::ID ID) {
switch (ID) {
case Intrinsic::dbg_declare:
case Intrinsic::dbg_value:
case Intrinsic::dbg_addr:
case Intrinsic::dbg_label:
return true;
default:
return false;
}
}
class DbgInfoIntrinsic : public IntrinsicInst {
public:
static bool classof(const IntrinsicInst *I) {
return isDbgInfoIntrinsic(I->getIntrinsicID());
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class DbgVariableIntrinsic : public DbgInfoIntrinsic {
public:
class location_op_iterator
: public iterator_facade_base<location_op_iterator,
std::bidirectional_iterator_tag, Value *> {
PointerUnion<ValueAsMetadata *, ValueAsMetadata **> I;
public:
location_op_iterator(ValueAsMetadata *SingleIter) : I(SingleIter) {}
location_op_iterator(ValueAsMetadata **MultiIter) : I(MultiIter) {}
location_op_iterator(const location_op_iterator &R) : I(R.I) {}
location_op_iterator &operator=(const location_op_iterator &R) {
I = R.I;
return *this;
}
bool operator==(const location_op_iterator &RHS) const {
return I == RHS.I;
}
const Value *operator*() const {
ValueAsMetadata *VAM = I.is<ValueAsMetadata *>()
? I.get<ValueAsMetadata *>()
: *I.get<ValueAsMetadata **>();
return VAM->getValue();
};
Value *operator*() {
ValueAsMetadata *VAM = I.is<ValueAsMetadata *>()
? I.get<ValueAsMetadata *>()
: *I.get<ValueAsMetadata **>();
return VAM->getValue();
}
location_op_iterator &operator++() {
if (I.is<ValueAsMetadata *>())
I = I.get<ValueAsMetadata *>() + 1;
else
I = I.get<ValueAsMetadata **>() + 1;
return *this;
}
location_op_iterator &operator--() {
if (I.is<ValueAsMetadata *>())
I = I.get<ValueAsMetadata *>() - 1;
else
I = I.get<ValueAsMetadata **>() - 1;
return *this;
}
};
iterator_range<location_op_iterator> location_ops() const;
Value *getVariableLocationOp(unsigned OpIdx) const;
void replaceVariableLocationOp(Value *OldValue, Value *NewValue);
void replaceVariableLocationOp(unsigned OpIdx, Value *NewValue);
void addVariableLocationOps(ArrayRef<Value *> NewValues,
DIExpression *NewExpr);
void setVariable(DILocalVariable *NewVar) {
setArgOperand(1, MetadataAsValue::get(NewVar->getContext(), NewVar));
}
void setExpression(DIExpression *NewExpr) {
setArgOperand(2, MetadataAsValue::get(NewExpr->getContext(), NewExpr));
}
unsigned getNumVariableLocationOps() const {
if (hasArgList())
return cast<DIArgList>(getRawLocation())->getArgs().size();
return 1;
}
bool hasArgList() const { return isa<DIArgList>(getRawLocation()); }
bool isAddressOfVariable() const {
return getIntrinsicID() != Intrinsic::dbg_value;
}
void setUndef() {
SmallPtrSet<Value *, 4> RemovedValues;
for (Value *OldValue : location_ops()) {
if (!RemovedValues.insert(OldValue).second)
continue;
Value *Undef = UndefValue::get(OldValue->getType());
replaceVariableLocationOp(OldValue, Undef);
}
}
bool isUndef() const {
return (getNumVariableLocationOps() == 0 &&
!getExpression()->isComplex()) ||
any_of(location_ops(), [](Value *V) { return isa<UndefValue>(V); });
}
DILocalVariable *getVariable() const {
return cast<DILocalVariable>(getRawVariable());
}
DIExpression *getExpression() const {
return cast<DIExpression>(getRawExpression());
}
Metadata *getRawLocation() const {
return cast<MetadataAsValue>(getArgOperand(0))->getMetadata();
}
Metadata *getRawVariable() const {
return cast<MetadataAsValue>(getArgOperand(1))->getMetadata();
}
Metadata *getRawExpression() const {
return cast<MetadataAsValue>(getArgOperand(2))->getMetadata();
}
void setRawLocation(Metadata *Location) {
return setArgOperand(0, MetadataAsValue::get(getContext(), Location));
}
Optional<uint64_t> getFragmentSizeInBits() const;
static bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::dbg_declare:
case Intrinsic::dbg_value:
case Intrinsic::dbg_addr:
return true;
default:
return false;
}
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
private:
void setArgOperand(unsigned i, Value *v) {
DbgInfoIntrinsic::setArgOperand(i, v);
}
void setOperand(unsigned i, Value *v) { DbgInfoIntrinsic::setOperand(i, v); }
};
class DbgDeclareInst : public DbgVariableIntrinsic {
public:
Value *getAddress() const {
assert(getNumVariableLocationOps() == 1 &&
"dbg.declare must have exactly 1 location operand.");
return getVariableLocationOp(0);
}
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::dbg_declare;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class DbgAddrIntrinsic : public DbgVariableIntrinsic {
public:
Value *getAddress() const {
assert(getNumVariableLocationOps() == 1 &&
"dbg.addr must have exactly 1 location operand.");
return getVariableLocationOp(0);
}
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::dbg_addr;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class DbgValueInst : public DbgVariableIntrinsic {
public:
Value *getValue(unsigned OpIdx = 0) const {
return getVariableLocationOp(OpIdx);
}
iterator_range<location_op_iterator> getValues() const {
return location_ops();
}
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::dbg_value;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class DbgLabelInst : public DbgInfoIntrinsic {
public:
DILabel *getLabel() const { return cast<DILabel>(getRawLabel()); }
Metadata *getRawLabel() const {
return cast<MetadataAsValue>(getArgOperand(0))->getMetadata();
}
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::dbg_label;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class VPIntrinsic : public IntrinsicInst {
public:
static Function *getDeclarationForParams(Module *M, Intrinsic::ID,
Type *ReturnType,
ArrayRef<Value *> Params);
static Optional<unsigned> getMaskParamPos(Intrinsic::ID IntrinsicID);
static Optional<unsigned> getVectorLengthParamPos(Intrinsic::ID IntrinsicID);
static Intrinsic::ID getForOpcode(unsigned OC);
static bool isVPIntrinsic(Intrinsic::ID);
Value *getMaskParam() const;
void setMaskParam(Value *);
Value *getVectorLengthParam() const;
void setVectorLengthParam(Value *);
bool canIgnoreVectorLengthParam() const;
ElementCount getStaticVectorLength() const;
MaybeAlign getPointerAlignment() const;
Value *getMemoryPointerParam() const;
static Optional<unsigned> getMemoryPointerParamPos(Intrinsic::ID);
Value *getMemoryDataParam() const;
static Optional<unsigned> getMemoryDataParamPos(Intrinsic::ID);
static bool classof(const IntrinsicInst *I) {
return isVPIntrinsic(I->getIntrinsicID());
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
Optional<unsigned> getFunctionalOpcode() const {
return getFunctionalOpcodeForVP(getIntrinsicID());
}
static Optional<unsigned> getFunctionalOpcodeForVP(Intrinsic::ID ID);
};
class VPReductionIntrinsic : public VPIntrinsic {
public:
static bool isVPReduction(Intrinsic::ID ID);
unsigned getStartParamPos() const;
unsigned getVectorParamPos() const;
static Optional<unsigned> getStartParamPos(Intrinsic::ID ID);
static Optional<unsigned> getVectorParamPos(Intrinsic::ID ID);
static bool classof(const IntrinsicInst *I) {
return VPReductionIntrinsic::isVPReduction(I->getIntrinsicID());
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class VPCastIntrinsic : public VPIntrinsic {
public:
static bool isVPCast(Intrinsic::ID ID);
static bool classof(const IntrinsicInst *I) {
return VPCastIntrinsic::isVPCast(I->getIntrinsicID());
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class VPCmpIntrinsic : public VPIntrinsic {
public:
static bool isVPCmp(Intrinsic::ID ID);
CmpInst::Predicate getPredicate() const;
static bool classof(const IntrinsicInst *I) {
return VPCmpIntrinsic::isVPCmp(I->getIntrinsicID());
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class ConstrainedFPIntrinsic : public IntrinsicInst {
public:
bool isUnaryOp() const;
bool isTernaryOp() const;
Optional<RoundingMode> getRoundingMode() const;
Optional<fp::ExceptionBehavior> getExceptionBehavior() const;
bool isDefaultFPEnvironment() const;
static bool classof(const IntrinsicInst *I);
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class ConstrainedFPCmpIntrinsic : public ConstrainedFPIntrinsic {
public:
FCmpInst::Predicate getPredicate() const;
bool isSignaling() const {
return getIntrinsicID() == Intrinsic::experimental_constrained_fcmps;
}
static bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::experimental_constrained_fcmp:
case Intrinsic::experimental_constrained_fcmps:
return true;
default:
return false;
}
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class MinMaxIntrinsic : public IntrinsicInst {
public:
static bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::umin:
case Intrinsic::umax:
case Intrinsic::smin:
case Intrinsic::smax:
return true;
default:
return false;
}
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
Value *getLHS() const { return const_cast<Value *>(getArgOperand(0)); }
Value *getRHS() const { return const_cast<Value *>(getArgOperand(1)); }
static ICmpInst::Predicate getPredicate(Intrinsic::ID ID) {
switch (ID) {
case Intrinsic::umin:
return ICmpInst::Predicate::ICMP_ULT;
case Intrinsic::umax:
return ICmpInst::Predicate::ICMP_UGT;
case Intrinsic::smin:
return ICmpInst::Predicate::ICMP_SLT;
case Intrinsic::smax:
return ICmpInst::Predicate::ICMP_SGT;
default:
llvm_unreachable("Invalid intrinsic");
}
}
ICmpInst::Predicate getPredicate() const {
return getPredicate(getIntrinsicID());
}
static bool isSigned(Intrinsic::ID ID) {
return ICmpInst::isSigned(getPredicate(ID));
};
bool isSigned() const { return isSigned(getIntrinsicID()); };
static APInt getSaturationPoint(Intrinsic::ID ID, unsigned numBits) {
switch (ID) {
case Intrinsic::umin:
return APInt::getMinValue(numBits);
case Intrinsic::umax:
return APInt::getMaxValue(numBits);
case Intrinsic::smin:
return APInt::getSignedMinValue(numBits);
case Intrinsic::smax:
return APInt::getSignedMaxValue(numBits);
default:
llvm_unreachable("Invalid intrinsic");
}
}
APInt getSaturationPoint(unsigned numBits) const {
return getSaturationPoint(getIntrinsicID(), numBits);
}
static Constant *getSaturationPoint(Intrinsic::ID ID, Type *Ty) {
return Constant::getIntegerValue(
Ty, getSaturationPoint(ID, Ty->getScalarSizeInBits()));
}
Constant *getSaturationPoint(Type *Ty) const {
return getSaturationPoint(getIntrinsicID(), Ty);
}
};
class BinaryOpIntrinsic : public IntrinsicInst {
public:
static bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::uadd_with_overflow:
case Intrinsic::sadd_with_overflow:
case Intrinsic::usub_with_overflow:
case Intrinsic::ssub_with_overflow:
case Intrinsic::umul_with_overflow:
case Intrinsic::smul_with_overflow:
case Intrinsic::uadd_sat:
case Intrinsic::sadd_sat:
case Intrinsic::usub_sat:
case Intrinsic::ssub_sat:
return true;
default:
return false;
}
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
Value *getLHS() const { return const_cast<Value *>(getArgOperand(0)); }
Value *getRHS() const { return const_cast<Value *>(getArgOperand(1)); }
Instruction::BinaryOps getBinaryOp() const;
bool isSigned() const;
unsigned getNoWrapKind() const;
};
class WithOverflowInst : public BinaryOpIntrinsic {
public:
static bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::uadd_with_overflow:
case Intrinsic::sadd_with_overflow:
case Intrinsic::usub_with_overflow:
case Intrinsic::ssub_with_overflow:
case Intrinsic::umul_with_overflow:
case Intrinsic::smul_with_overflow:
return true;
default:
return false;
}
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class SaturatingInst : public BinaryOpIntrinsic {
public:
static bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::uadd_sat:
case Intrinsic::sadd_sat:
case Intrinsic::usub_sat:
case Intrinsic::ssub_sat:
return true;
default:
return false;
}
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
template <typename Derived> class MemIntrinsicBase : public IntrinsicInst {
private:
enum { ARG_DEST = 0, ARG_LENGTH = 2 };
public:
Value *getRawDest() const {
return const_cast<Value *>(getArgOperand(ARG_DEST));
}
const Use &getRawDestUse() const { return getArgOperandUse(ARG_DEST); }
Use &getRawDestUse() { return getArgOperandUse(ARG_DEST); }
Value *getLength() const {
return const_cast<Value *>(getArgOperand(ARG_LENGTH));
}
const Use &getLengthUse() const { return getArgOperandUse(ARG_LENGTH); }
Use &getLengthUse() { return getArgOperandUse(ARG_LENGTH); }
Value *getDest() const { return getRawDest()->stripPointerCasts(); }
unsigned getDestAddressSpace() const {
return cast<PointerType>(getRawDest()->getType())->getAddressSpace();
}
unsigned getDestAlignment() const {
if (auto MA = getParamAlign(ARG_DEST))
return MA->value();
return 0;
}
MaybeAlign getDestAlign() const { return getParamAlign(ARG_DEST); }
void setDest(Value *Ptr) {
assert(getRawDest()->getType() == Ptr->getType() &&
"setDest called with pointer of wrong type!");
setArgOperand(ARG_DEST, Ptr);
}
void setDestAlignment(MaybeAlign Alignment) {
removeParamAttr(ARG_DEST, Attribute::Alignment);
if (Alignment)
addParamAttr(ARG_DEST,
Attribute::getWithAlignment(getContext(), *Alignment));
}
void setDestAlignment(Align Alignment) {
removeParamAttr(ARG_DEST, Attribute::Alignment);
addParamAttr(ARG_DEST,
Attribute::getWithAlignment(getContext(), Alignment));
}
void setLength(Value *L) {
assert(getLength()->getType() == L->getType() &&
"setLength called with value of wrong type!");
setArgOperand(ARG_LENGTH, L);
}
};
template <class BaseCL> class MemTransferBase : public BaseCL {
private:
enum { ARG_SOURCE = 1 };
public:
Value *getRawSource() const {
return const_cast<Value *>(BaseCL::getArgOperand(ARG_SOURCE));
}
const Use &getRawSourceUse() const {
return BaseCL::getArgOperandUse(ARG_SOURCE);
}
Use &getRawSourceUse() { return BaseCL::getArgOperandUse(ARG_SOURCE); }
Value *getSource() const { return getRawSource()->stripPointerCasts(); }
unsigned getSourceAddressSpace() const {
return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
}
unsigned getSourceAlignment() const {
if (auto MA = BaseCL::getParamAlign(ARG_SOURCE))
return MA->value();
return 0;
}
MaybeAlign getSourceAlign() const {
return BaseCL::getParamAlign(ARG_SOURCE);
}
void setSource(Value *Ptr) {
assert(getRawSource()->getType() == Ptr->getType() &&
"setSource called with pointer of wrong type!");
BaseCL::setArgOperand(ARG_SOURCE, Ptr);
}
void setSourceAlignment(unsigned Alignment) {
setSourceAlignment(MaybeAlign(Alignment));
}
void setSourceAlignment(MaybeAlign Alignment) {
BaseCL::removeParamAttr(ARG_SOURCE, Attribute::Alignment);
if (Alignment)
BaseCL::addParamAttr(ARG_SOURCE, Attribute::getWithAlignment(
BaseCL::getContext(), *Alignment));
}
void setSourceAlignment(Align Alignment) {
BaseCL::removeParamAttr(ARG_SOURCE, Attribute::Alignment);
BaseCL::addParamAttr(ARG_SOURCE, Attribute::getWithAlignment(
BaseCL::getContext(), Alignment));
}
};
template <class BaseCL> class MemSetBase : public BaseCL {
private:
enum { ARG_VALUE = 1 };
public:
Value *getValue() const {
return const_cast<Value *>(BaseCL::getArgOperand(ARG_VALUE));
}
const Use &getValueUse() const { return BaseCL::getArgOperandUse(ARG_VALUE); }
Use &getValueUse() { return BaseCL::getArgOperandUse(ARG_VALUE); }
void setValue(Value *Val) {
assert(getValue()->getType() == Val->getType() &&
"setValue called with value of wrong type!");
BaseCL::setArgOperand(ARG_VALUE, Val);
}
};
class AtomicMemIntrinsic : public MemIntrinsicBase<AtomicMemIntrinsic> {
private:
enum { ARG_ELEMENTSIZE = 3 };
public:
Value *getRawElementSizeInBytes() const {
return const_cast<Value *>(getArgOperand(ARG_ELEMENTSIZE));
}
ConstantInt *getElementSizeInBytesCst() const {
return cast<ConstantInt>(getRawElementSizeInBytes());
}
uint32_t getElementSizeInBytes() const {
return getElementSizeInBytesCst()->getZExtValue();
}
void setElementSizeInBytes(Constant *V) {
assert(V->getType() == Type::getInt8Ty(getContext()) &&
"setElementSizeInBytes called with value of wrong type!");
setArgOperand(ARG_ELEMENTSIZE, V);
}
static bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::memcpy_element_unordered_atomic:
case Intrinsic::memmove_element_unordered_atomic:
case Intrinsic::memset_element_unordered_atomic:
return true;
default:
return false;
}
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class AtomicMemSetInst : public MemSetBase<AtomicMemIntrinsic> {
public:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::memset_element_unordered_atomic;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class AtomicMemTransferInst : public MemTransferBase<AtomicMemIntrinsic> {
public:
static bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::memcpy_element_unordered_atomic:
case Intrinsic::memmove_element_unordered_atomic:
return true;
default:
return false;
}
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class AtomicMemCpyInst : public AtomicMemTransferInst {
public:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::memcpy_element_unordered_atomic;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class AtomicMemMoveInst : public AtomicMemTransferInst {
public:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::memmove_element_unordered_atomic;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class MemIntrinsic : public MemIntrinsicBase<MemIntrinsic> {
private:
enum { ARG_VOLATILE = 3 };
public:
ConstantInt *getVolatileCst() const {
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(ARG_VOLATILE)));
}
bool isVolatile() const { return !getVolatileCst()->isZero(); }
void setVolatile(Constant *V) { setArgOperand(ARG_VOLATILE, V); }
static bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::memcpy:
case Intrinsic::memmove:
case Intrinsic::memset:
case Intrinsic::memset_inline:
case Intrinsic::memcpy_inline:
return true;
default:
return false;
}
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class MemSetInst : public MemSetBase<MemIntrinsic> {
public:
static bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::memset:
case Intrinsic::memset_inline:
return true;
default:
return false;
}
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class MemSetInlineInst : public MemSetInst {
public:
ConstantInt *getLength() const {
return cast<ConstantInt>(MemSetInst::getLength());
}
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::memset_inline;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class MemTransferInst : public MemTransferBase<MemIntrinsic> {
public:
static bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::memcpy:
case Intrinsic::memmove:
case Intrinsic::memcpy_inline:
return true;
default:
return false;
}
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class MemCpyInst : public MemTransferInst {
public:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::memcpy ||
I->getIntrinsicID() == Intrinsic::memcpy_inline;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class MemMoveInst : public MemTransferInst {
public:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::memmove;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class MemCpyInlineInst : public MemCpyInst {
public:
ConstantInt *getLength() const {
return cast<ConstantInt>(MemCpyInst::getLength());
}
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::memcpy_inline;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class AnyMemIntrinsic : public MemIntrinsicBase<AnyMemIntrinsic> {
public:
bool isVolatile() const {
if (auto *MI = dyn_cast<MemIntrinsic>(this))
return MI->isVolatile();
return false;
}
static bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::memcpy:
case Intrinsic::memcpy_inline:
case Intrinsic::memmove:
case Intrinsic::memset:
case Intrinsic::memset_inline:
case Intrinsic::memcpy_element_unordered_atomic:
case Intrinsic::memmove_element_unordered_atomic:
case Intrinsic::memset_element_unordered_atomic:
return true;
default:
return false;
}
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class AnyMemSetInst : public MemSetBase<AnyMemIntrinsic> {
public:
static bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::memset:
case Intrinsic::memset_inline:
case Intrinsic::memset_element_unordered_atomic:
return true;
default:
return false;
}
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class AnyMemTransferInst : public MemTransferBase<AnyMemIntrinsic> {
public:
static bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::memcpy:
case Intrinsic::memcpy_inline:
case Intrinsic::memmove:
case Intrinsic::memcpy_element_unordered_atomic:
case Intrinsic::memmove_element_unordered_atomic:
return true;
default:
return false;
}
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class AnyMemCpyInst : public AnyMemTransferInst {
public:
static bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::memcpy:
case Intrinsic::memcpy_inline:
case Intrinsic::memcpy_element_unordered_atomic:
return true;
default:
return false;
}
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class AnyMemMoveInst : public AnyMemTransferInst {
public:
static bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::memmove:
case Intrinsic::memmove_element_unordered_atomic:
return true;
default:
return false;
}
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class VAStartInst : public IntrinsicInst {
public:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::vastart;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
Value *getArgList() const { return const_cast<Value *>(getArgOperand(0)); }
};
class VAEndInst : public IntrinsicInst {
public:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::vaend;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
Value *getArgList() const { return const_cast<Value *>(getArgOperand(0)); }
};
class VACopyInst : public IntrinsicInst {
public:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::vacopy;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
Value *getDest() const { return const_cast<Value *>(getArgOperand(0)); }
Value *getSrc() const { return const_cast<Value *>(getArgOperand(1)); }
};
class InstrProfInstBase : public IntrinsicInst {
public:
GlobalVariable *getName() const {
return cast<GlobalVariable>(
const_cast<Value *>(getArgOperand(0))->stripPointerCasts());
}
ConstantInt *getHash() const {
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
}
ConstantInt *getNumCounters() const;
ConstantInt *getIndex() const;
};
class InstrProfCoverInst : public InstrProfInstBase {
public:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::instrprof_cover;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class InstrProfIncrementInst : public InstrProfInstBase {
public:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::instrprof_increment;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
Value *getStep() const;
};
class InstrProfIncrementInstStep : public InstrProfIncrementInst {
public:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::instrprof_increment_step;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class InstrProfValueProfileInst : public InstrProfInstBase {
public:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::instrprof_value_profile;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
Value *getTargetValue() const {
return cast<Value>(const_cast<Value *>(getArgOperand(2)));
}
ConstantInt *getValueKind() const {
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
}
ConstantInt *getIndex() const {
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(4)));
}
};
class PseudoProbeInst : public IntrinsicInst {
public:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::pseudoprobe;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
ConstantInt *getFuncGuid() const {
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(0)));
}
ConstantInt *getIndex() const {
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
}
ConstantInt *getAttributes() const {
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
}
ConstantInt *getFactor() const {
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
}
};
class NoAliasScopeDeclInst : public IntrinsicInst {
public:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
MDNode *getScopeList() const {
auto *MV =
cast<MetadataAsValue>(getOperand(Intrinsic::NoAliasScopeDeclScopeArg));
return cast<MDNode>(MV->getMetadata());
}
void setScopeList(MDNode *ScopeList) {
setOperand(Intrinsic::NoAliasScopeDeclScopeArg,
MetadataAsValue::get(getContext(), ScopeList));
}
};
class GCProjectionInst : public IntrinsicInst {
public:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::experimental_gc_relocate ||
I->getIntrinsicID() == Intrinsic::experimental_gc_result;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
bool isTiedToInvoke() const {
const Value *Token = getArgOperand(0);
return isa<LandingPadInst>(Token) || isa<InvokeInst>(Token);
}
const Value *getStatepoint() const;
};
class GCRelocateInst : public GCProjectionInst {
public:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::experimental_gc_relocate;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
unsigned getBasePtrIndex() const {
return cast<ConstantInt>(getArgOperand(1))->getZExtValue();
}
unsigned getDerivedPtrIndex() const {
return cast<ConstantInt>(getArgOperand(2))->getZExtValue();
}
Value *getBasePtr() const;
Value *getDerivedPtr() const;
};
class GCResultInst : public GCProjectionInst {
public:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::experimental_gc_result;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class AssumeInst : public IntrinsicInst {
public:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::assume;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
}
#endif