[IR] Refactor memtransfer inst classes (NFC)
Summary: A simple refactor to remove duplicate code in the definitions of MemTransferInst, AtomicMemTransferInst, and AnyMemTransferInst. Introduce a templated base class that contains all of the methods unique to a memory transfer intrinsic, and derive these three classes from that. llvm-svn: 329744
This commit is contained in:
parent
e27d5016ef
commit
08a930a9c2
|
|
@ -266,6 +266,49 @@ namespace llvm {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Common base class for all memory transfer intrinsics. Simply provides
|
||||||
|
/// common methods.
|
||||||
|
template <class BaseCL> class MemTransferBase : public BaseCL {
|
||||||
|
private:
|
||||||
|
enum { ARG_SOURCE = 1 };
|
||||||
|
|
||||||
|
public:
|
||||||
|
/// Return the arguments to the instruction.
|
||||||
|
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); }
|
||||||
|
|
||||||
|
/// This is just like getRawSource, but it strips off any cast
|
||||||
|
/// instructions that feed it, giving the original input. The returned
|
||||||
|
/// value is guaranteed to be a pointer.
|
||||||
|
Value *getSource() const { return getRawSource()->stripPointerCasts(); }
|
||||||
|
|
||||||
|
unsigned getSourceAddressSpace() const {
|
||||||
|
return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned getSourceAlignment() const {
|
||||||
|
return BaseCL::getParamAlignment(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 Align) {
|
||||||
|
BaseCL::removeParamAttr(ARG_SOURCE, Attribute::Alignment);
|
||||||
|
if (Align > 0)
|
||||||
|
BaseCL::addParamAttr(ARG_SOURCE, Attribute::getWithAlignment(
|
||||||
|
BaseCL::getContext(), Align));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// The common base class for the atomic memset/memmove/memcpy intrinsics
|
// The common base class for the atomic memset/memmove/memcpy intrinsics
|
||||||
// i.e. llvm.element.unordered.atomic.memset/memcpy/memmove
|
// i.e. llvm.element.unordered.atomic.memset/memcpy/memmove
|
||||||
class AtomicMemIntrinsic : public MemIntrinsicBase<AtomicMemIntrinsic> {
|
class AtomicMemIntrinsic : public MemIntrinsicBase<AtomicMemIntrinsic> {
|
||||||
|
|
@ -335,44 +378,8 @@ namespace llvm {
|
||||||
|
|
||||||
// This class wraps the atomic memcpy/memmove intrinsics
|
// This class wraps the atomic memcpy/memmove intrinsics
|
||||||
// i.e. llvm.element.unordered.atomic.memcpy/memmove
|
// i.e. llvm.element.unordered.atomic.memcpy/memmove
|
||||||
class AtomicMemTransferInst : public AtomicMemIntrinsic {
|
class AtomicMemTransferInst : public MemTransferBase<AtomicMemIntrinsic> {
|
||||||
private:
|
|
||||||
enum { ARG_SOURCE = 1 };
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Return the arguments to the instruction.
|
|
||||||
Value *getRawSource() const {
|
|
||||||
return const_cast<Value *>(getArgOperand(ARG_SOURCE));
|
|
||||||
}
|
|
||||||
const Use &getRawSourceUse() const { return getArgOperandUse(ARG_SOURCE); }
|
|
||||||
Use &getRawSourceUse() { return getArgOperandUse(ARG_SOURCE); }
|
|
||||||
|
|
||||||
/// This is just like getRawSource, but it strips off any cast
|
|
||||||
/// instructions that feed it, giving the original input. The returned
|
|
||||||
/// value is guaranteed to be a pointer.
|
|
||||||
Value *getSource() const { return getRawSource()->stripPointerCasts(); }
|
|
||||||
|
|
||||||
unsigned getSourceAddressSpace() const {
|
|
||||||
return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned getSourceAlignment() const {
|
|
||||||
return getParamAlignment(ARG_SOURCE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setSource(Value *Ptr) {
|
|
||||||
assert(getRawSource()->getType() == Ptr->getType() &&
|
|
||||||
"setSource called with pointer of wrong type!");
|
|
||||||
setArgOperand(ARG_SOURCE, Ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setSourceAlignment(unsigned Align) {
|
|
||||||
removeParamAttr(ARG_SOURCE, Attribute::Alignment);
|
|
||||||
if (Align > 0)
|
|
||||||
addParamAttr(ARG_SOURCE,
|
|
||||||
Attribute::getWithAlignment(getContext(), Align));
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool classof(const IntrinsicInst *I) {
|
static bool classof(const IntrinsicInst *I) {
|
||||||
switch (I->getIntrinsicID()) {
|
switch (I->getIntrinsicID()) {
|
||||||
case Intrinsic::memcpy_element_unordered_atomic:
|
case Intrinsic::memcpy_element_unordered_atomic:
|
||||||
|
|
@ -467,42 +474,8 @@ namespace llvm {
|
||||||
};
|
};
|
||||||
|
|
||||||
/// This class wraps the llvm.memcpy/memmove intrinsics.
|
/// This class wraps the llvm.memcpy/memmove intrinsics.
|
||||||
class MemTransferInst : public MemIntrinsic {
|
class MemTransferInst : public MemTransferBase<MemIntrinsic> {
|
||||||
private:
|
|
||||||
enum { ARG_SOURCE = 1 };
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Return the arguments to the instruction.
|
|
||||||
Value *getRawSource() const { return const_cast<Value*>(getArgOperand(ARG_SOURCE)); }
|
|
||||||
const Use &getRawSourceUse() const { return getArgOperandUse(ARG_SOURCE); }
|
|
||||||
Use &getRawSourceUse() { return getArgOperandUse(ARG_SOURCE); }
|
|
||||||
|
|
||||||
/// This is just like getRawSource, but it strips off any cast
|
|
||||||
/// instructions that feed it, giving the original input. The returned
|
|
||||||
/// value is guaranteed to be a pointer.
|
|
||||||
Value *getSource() const { return getRawSource()->stripPointerCasts(); }
|
|
||||||
|
|
||||||
unsigned getSourceAddressSpace() const {
|
|
||||||
return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned getSourceAlignment() const {
|
|
||||||
return getParamAlignment(ARG_SOURCE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setSource(Value *Ptr) {
|
|
||||||
assert(getRawSource()->getType() == Ptr->getType() &&
|
|
||||||
"setSource called with pointer of wrong type!");
|
|
||||||
setArgOperand(ARG_SOURCE, Ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setSourceAlignment(unsigned Align) {
|
|
||||||
removeParamAttr(ARG_SOURCE, Attribute::Alignment);
|
|
||||||
if (Align > 0)
|
|
||||||
addParamAttr(ARG_SOURCE,
|
|
||||||
Attribute::getWithAlignment(getContext(), Align));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||||
static bool classof(const IntrinsicInst *I) {
|
static bool classof(const IntrinsicInst *I) {
|
||||||
return I->getIntrinsicID() == Intrinsic::memcpy ||
|
return I->getIntrinsicID() == Intrinsic::memcpy ||
|
||||||
|
|
@ -605,44 +578,8 @@ namespace llvm {
|
||||||
// This class wraps any memcpy/memmove intrinsics
|
// This class wraps any memcpy/memmove intrinsics
|
||||||
// i.e. llvm.element.unordered.atomic.memcpy/memmove
|
// i.e. llvm.element.unordered.atomic.memcpy/memmove
|
||||||
// and llvm.memcpy/memmove
|
// and llvm.memcpy/memmove
|
||||||
class AnyMemTransferInst : public AnyMemIntrinsic {
|
class AnyMemTransferInst : public MemTransferBase<AnyMemIntrinsic> {
|
||||||
private:
|
|
||||||
enum { ARG_SOURCE = 1 };
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Return the arguments to the instruction.
|
|
||||||
Value *getRawSource() const {
|
|
||||||
return const_cast<Value *>(getArgOperand(ARG_SOURCE));
|
|
||||||
}
|
|
||||||
const Use &getRawSourceUse() const { return getArgOperandUse(ARG_SOURCE); }
|
|
||||||
Use &getRawSourceUse() { return getArgOperandUse(ARG_SOURCE); }
|
|
||||||
|
|
||||||
/// This is just like getRawSource, but it strips off any cast
|
|
||||||
/// instructions that feed it, giving the original input. The returned
|
|
||||||
/// value is guaranteed to be a pointer.
|
|
||||||
Value *getSource() const { return getRawSource()->stripPointerCasts(); }
|
|
||||||
|
|
||||||
unsigned getSourceAddressSpace() const {
|
|
||||||
return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned getSourceAlignment() const {
|
|
||||||
return getParamAlignment(ARG_SOURCE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setSource(Value *Ptr) {
|
|
||||||
assert(getRawSource()->getType() == Ptr->getType() &&
|
|
||||||
"setSource called with pointer of wrong type!");
|
|
||||||
setArgOperand(ARG_SOURCE, Ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setSourceAlignment(unsigned Align) {
|
|
||||||
removeParamAttr(ARG_SOURCE, Attribute::Alignment);
|
|
||||||
if (Align > 0)
|
|
||||||
addParamAttr(ARG_SOURCE,
|
|
||||||
Attribute::getWithAlignment(getContext(), Align));
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool classof(const IntrinsicInst *I) {
|
static bool classof(const IntrinsicInst *I) {
|
||||||
switch (I->getIntrinsicID()) {
|
switch (I->getIntrinsicID()) {
|
||||||
case Intrinsic::memcpy:
|
case Intrinsic::memcpy:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue