1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

[IR] Refactor memset inst classes (NFC)

Summary:
A simple refactor to remove duplicate code in the definitions of
MemSetInst, AtomicMemSetInst, and AnyMemSetInst. Introduce a
templated base class that contains all of the methods unique to
a memset intrinsic, and derive these three classes from that.

llvm-svn: 329747
This commit is contained in:
Daniel Neilson 2018-04-10 19:51:44 +00:00
parent 9222709676
commit 8bc1f45423

View File

@ -309,6 +309,28 @@ namespace llvm {
}
};
/// Common base class for all memset intrinsics. Simply provides
/// common methods.
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);
}
};
// 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> {
@ -351,23 +373,8 @@ namespace llvm {
/// This class represents atomic memset intrinsic
// i.e. llvm.element.unordered.atomic.memset
class AtomicMemSetInst : public AtomicMemIntrinsic {
private:
enum { ARG_VALUE = 1 };
class AtomicMemSetInst : public MemSetBase<AtomicMemIntrinsic> {
public:
Value *getValue() const {
return const_cast<Value *>(getArgOperand(ARG_VALUE));
}
const Use &getValueUse() const { return getArgOperandUse(ARG_VALUE); }
Use &getValueUse() { return getArgOperandUse(ARG_VALUE); }
void setValue(Value *Val) {
assert(getValue()->getType() == Val->getType() &&
"setValue called with value of wrong type!");
setArgOperand(ARG_VALUE, Val);
}
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::memset_element_unordered_atomic;
}
@ -451,19 +458,8 @@ namespace llvm {
};
/// This class wraps the llvm.memset intrinsic.
class MemSetInst : public MemIntrinsic {
class MemSetInst : public MemSetBase<MemIntrinsic> {
public:
/// Return the arguments to the instruction.
Value *getValue() const { return const_cast<Value*>(getArgOperand(1)); }
const Use &getValueUse() const { return getArgOperandUse(1); }
Use &getValueUse() { return getArgOperandUse(1); }
void setValue(Value *Val) {
assert(getValue()->getType() == Val->getType() &&
"setValue called with value of wrong type!");
setArgOperand(1, Val);
}
// Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::memset;
@ -544,23 +540,8 @@ namespace llvm {
/// This class represents any memset intrinsic
// i.e. llvm.element.unordered.atomic.memset
// and llvm.memset
class AnyMemSetInst : public AnyMemIntrinsic {
private:
enum { ARG_VALUE = 1 };
class AnyMemSetInst : public MemSetBase<AnyMemIntrinsic> {
public:
Value *getValue() const {
return const_cast<Value *>(getArgOperand(ARG_VALUE));
}
const Use &getValueUse() const { return getArgOperandUse(ARG_VALUE); }
Use &getValueUse() { return getArgOperandUse(ARG_VALUE); }
void setValue(Value *Val) {
assert(getValue()->getType() == Val->getType() &&
"setValue called with value of wrong type!");
setArgOperand(ARG_VALUE, Val);
}
static bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::memset: