1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

[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:
Daniel Neilson 2018-04-10 19:23:11 +00:00
parent 803368e4c4
commit 22d16b8ea1

View File

@ -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
// i.e. llvm.element.unordered.atomic.memset/memcpy/memmove
class AtomicMemIntrinsic : public MemIntrinsicBase<AtomicMemIntrinsic> {
@ -335,44 +378,8 @@ namespace llvm {
// This class wraps the atomic memcpy/memmove intrinsics
// i.e. llvm.element.unordered.atomic.memcpy/memmove
class AtomicMemTransferInst : public AtomicMemIntrinsic {
private:
enum { ARG_SOURCE = 1 };
class AtomicMemTransferInst : public MemTransferBase<AtomicMemIntrinsic> {
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) {
switch (I->getIntrinsicID()) {
case Intrinsic::memcpy_element_unordered_atomic:
@ -467,42 +474,8 @@ namespace llvm {
};
/// This class wraps the llvm.memcpy/memmove intrinsics.
class MemTransferInst : public MemIntrinsic {
private:
enum { ARG_SOURCE = 1 };
class MemTransferInst : public MemTransferBase<MemIntrinsic> {
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:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::memcpy ||
@ -605,44 +578,8 @@ namespace llvm {
// This class wraps any memcpy/memmove intrinsics
// i.e. llvm.element.unordered.atomic.memcpy/memmove
// and llvm.memcpy/memmove
class AnyMemTransferInst : public AnyMemIntrinsic {
private:
enum { ARG_SOURCE = 1 };
class AnyMemTransferInst : public MemTransferBase<AnyMemIntrinsic> {
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) {
switch (I->getIntrinsicID()) {
case Intrinsic::memcpy: