2003-09-30 20:37:50 +02:00
|
|
|
//===-- llvm/User.h - User class definition ---------------------*- C++ -*-===//
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-06 22:29:01 +02:00
|
|
|
//
|
2012-05-17 00:08:58 +02:00
|
|
|
// This class defines the interface that one who uses a Value must implement.
|
2001-06-06 22:29:01 +02:00
|
|
|
// Each instance of the Value class keeps track of what User's have handles
|
|
|
|
// to it.
|
|
|
|
//
|
2012-05-17 00:08:58 +02:00
|
|
|
// * Instructions are the largest class of Users.
|
2001-06-06 22:29:01 +02:00
|
|
|
// * Constants may be users of other constants (think arrays and stuff)
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 01:45:19 +01:00
|
|
|
#ifndef LLVM_IR_USER_H
|
|
|
|
#define LLVM_IR_USER_H
|
2001-06-06 22:29:01 +02:00
|
|
|
|
[IR] Teach `llvm::User` to co-allocate a descriptor.
Summary:
With this change, subclasses of `llvm::User` will be able to co-allocate
a variable number of bytes (called a "descriptor") with the `llvm::User`
instance. The co-allocated descriptor can later be accessed using
`llvm::User::getDescriptor`. This will be used in later changes to
implement operand bundles.
This change steals one bit from `NumUserOperands`, but given that it is
still 28 bits wide I don't think this will be a practical issue.
This change does not allow allocating hung off uses with descriptors.
This only for simplicity, not for any fundamental reason; and we can
easily add this functionality later if needed.
Reviewers: reames, chandlerc, dexonsmith, kmod, majnemer, pete, JosephTremoulet
Subscribers: pete, sanjoy, llvm-commits
Differential Revision: http://reviews.llvm.org/D12455
llvm-svn: 248453
2015-09-24 03:00:49 +02:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2014-04-24 07:33:53 +02:00
|
|
|
#include "llvm/ADT/iterator.h"
|
2014-03-03 11:42:58 +01:00
|
|
|
#include "llvm/ADT/iterator_range.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/Value.h"
|
2015-06-17 03:21:20 +02:00
|
|
|
#include "llvm/Support/AlignOf.h"
|
2012-02-05 23:14:15 +01:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2001-06-06 22:29:01 +02:00
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
namespace llvm {
|
|
|
|
|
2014-10-15 22:28:31 +02:00
|
|
|
/// \brief Compile-time customization of User operands.
|
|
|
|
///
|
|
|
|
/// Customizes operand-related allocators and accessors.
|
2008-05-10 10:32:32 +02:00
|
|
|
template <class>
|
|
|
|
struct OperandTraits;
|
|
|
|
|
2001-06-06 22:29:01 +02:00
|
|
|
class User : public Value {
|
2015-02-15 23:54:22 +01:00
|
|
|
User(const User &) = delete;
|
2008-05-10 10:32:32 +02:00
|
|
|
template <unsigned>
|
|
|
|
friend struct HungoffOperandTraits;
|
2011-12-01 09:00:17 +01:00
|
|
|
virtual void anchor();
|
Instead of storing operands as std::vector<Use>, just maintain a pointer
and num operands in the User class. this allows us to embed the operands
directly in the subclasses if possible. For example, for binary operators
we store the two operands in the derived class.
The has several effects:
1. it improves locality because the operands and instruction are together
2. it makes accesses to operands faster (one less load) if you access them
through the derived class pointer. For example this:
Value *GetBinaryOperatorOp(BinaryOperator *I, int i) {
return I->getOperand(i);
}
Was compiled to:
_Z19GetBinaryOperatorOpPN4llvm14BinaryOperatorEi:
movl 4(%esp), %edx
movl 8(%esp), %eax
sall $4, %eax
movl 24(%edx), %ecx
addl %ecx, %eax
movl (%eax), %eax
ret
and is now compiled to:
_Z19GetBinaryOperatorOpPN4llvm14BinaryOperatorEi:
movl 8(%esp), %eax
movl 4(%esp), %edx
sall $4, %eax
addl %edx, %eax
movl 44(%eax), %eax
ret
Accesses through "Instruction*" are unmodified.
3. This reduces memory consumption (by about 3%) by eliminating 1 word of
vector overhead and a malloc header on a seperate object.
4. This speeds up gccas about 10% (both debug and release builds) on
large things (such as 176.gcc). For example, it takes a debug build
from 172.9 -> 155.6s and a release gccas from 67.7 -> 61.8s
llvm-svn: 19883
2005-01-29 01:29:39 +01:00
|
|
|
|
[IR] Teach `llvm::User` to co-allocate a descriptor.
Summary:
With this change, subclasses of `llvm::User` will be able to co-allocate
a variable number of bytes (called a "descriptor") with the `llvm::User`
instance. The co-allocated descriptor can later be accessed using
`llvm::User::getDescriptor`. This will be used in later changes to
implement operand bundles.
This change steals one bit from `NumUserOperands`, but given that it is
still 28 bits wide I don't think this will be a practical issue.
This change does not allow allocating hung off uses with descriptors.
This only for simplicity, not for any fundamental reason; and we can
easily add this functionality later if needed.
Reviewers: reames, chandlerc, dexonsmith, kmod, majnemer, pete, JosephTremoulet
Subscribers: pete, sanjoy, llvm-commits
Differential Revision: http://reviews.llvm.org/D12455
llvm-svn: 248453
2015-09-24 03:00:49 +02:00
|
|
|
LLVM_ATTRIBUTE_ALWAYS_INLINE inline static void *
|
|
|
|
allocateFixedOperandUser(size_t, unsigned, unsigned);
|
|
|
|
|
2015-06-12 19:48:05 +02:00
|
|
|
protected:
|
2015-06-12 19:48:14 +02:00
|
|
|
/// Allocate a User with an operand pointer co-allocated.
|
|
|
|
///
|
|
|
|
/// This is used for subclasses which need to allocate a variable number
|
|
|
|
/// of operands, ie, 'hung off uses'.
|
|
|
|
void *operator new(size_t Size);
|
|
|
|
|
|
|
|
/// Allocate a User with the operands co-allocated.
|
|
|
|
///
|
|
|
|
/// This is used for subclasses which have a fixed number of operands.
|
|
|
|
void *operator new(size_t Size, unsigned Us);
|
2015-06-12 19:48:05 +02:00
|
|
|
|
[IR] Teach `llvm::User` to co-allocate a descriptor.
Summary:
With this change, subclasses of `llvm::User` will be able to co-allocate
a variable number of bytes (called a "descriptor") with the `llvm::User`
instance. The co-allocated descriptor can later be accessed using
`llvm::User::getDescriptor`. This will be used in later changes to
implement operand bundles.
This change steals one bit from `NumUserOperands`, but given that it is
still 28 bits wide I don't think this will be a practical issue.
This change does not allow allocating hung off uses with descriptors.
This only for simplicity, not for any fundamental reason; and we can
easily add this functionality later if needed.
Reviewers: reames, chandlerc, dexonsmith, kmod, majnemer, pete, JosephTremoulet
Subscribers: pete, sanjoy, llvm-commits
Differential Revision: http://reviews.llvm.org/D12455
llvm-svn: 248453
2015-09-24 03:00:49 +02:00
|
|
|
/// Allocate a User with the operands co-allocated. If DescBytes is non-zero
|
|
|
|
/// then allocate an additional DescBytes bytes before the operands. These
|
|
|
|
/// bytes can be accessed by calling getDescriptor.
|
|
|
|
///
|
|
|
|
/// DescBytes needs to be divisible by sizeof(void *). The allocated
|
|
|
|
/// descriptor, if any, is aligned to sizeof(void *) bytes.
|
|
|
|
///
|
|
|
|
/// This is used for subclasses which have a fixed number of operands.
|
|
|
|
void *operator new(size_t Size, unsigned Us, unsigned DescBytes);
|
|
|
|
|
2011-07-18 06:54:35 +02:00
|
|
|
User(Type *ty, unsigned vty, Use *OpList, unsigned NumOps)
|
2015-06-12 19:48:05 +02:00
|
|
|
: Value(ty, vty) {
|
2015-06-12 19:48:10 +02:00
|
|
|
assert(NumOps < (1u << NumUserOperandsBits) && "Too many operands");
|
|
|
|
NumUserOperands = NumOps;
|
2015-06-12 19:48:18 +02:00
|
|
|
// If we have hung off uses, then the operand list should initially be
|
|
|
|
// null.
|
|
|
|
assert((!HasHungOffUses || !getOperandList()) &&
|
|
|
|
"Error in initializing hung off uses for User");
|
IR: Move NumOperands from User to Value, NFC
Store `User::NumOperands` (and `MDNode::NumOperands`) in `Value`.
On 64-bit host architectures, this reduces `sizeof(User)` and all
subclasses by 8, and has no effect on `sizeof(Value)` (or, incidentally,
on `sizeof(MDNode)`).
On 32-bit host architectures, this increases `sizeof(Value)` by 4.
However, it has no effect on `sizeof(User)` and `sizeof(MDNode)`, so the
only concrete subclasses of `Value` that actually see the increase are
`BasicBlock`, `Argument`, `InlineAsm`, and `MDString`. Moreover, I'll
be shocked and confused if this causes a tangible memory regression.
This has no functionality change (other than memory footprint).
llvm-svn: 219845
2014-10-15 22:39:05 +02:00
|
|
|
}
|
2015-06-11 00:38:30 +02:00
|
|
|
|
|
|
|
/// \brief Allocate the array of Uses, followed by a pointer
|
|
|
|
/// (with bottom bit set) to the User.
|
|
|
|
/// \param IsPhi identifies callers which are phi nodes and which need
|
|
|
|
/// N BasicBlock* allocated along with N
|
2015-06-11 00:38:46 +02:00
|
|
|
void allocHungoffUses(unsigned N, bool IsPhi = false);
|
2015-06-11 00:38:41 +02:00
|
|
|
|
|
|
|
/// \brief Grow the number of hung off uses. Note that allocHungoffUses
|
|
|
|
/// should be called if there are no uses.
|
|
|
|
void growHungoffUses(unsigned N, bool IsPhi = false);
|
|
|
|
|
2008-04-06 22:25:17 +02:00
|
|
|
public:
|
2015-08-31 23:06:08 +02:00
|
|
|
~User() override {
|
|
|
|
}
|
2014-10-15 22:28:31 +02:00
|
|
|
/// \brief Free memory allocated for User and Use objects.
|
2008-05-15 03:23:11 +02:00
|
|
|
void operator delete(void *Usr);
|
2014-10-15 22:28:31 +02:00
|
|
|
/// \brief Placement delete - required by std, but never called.
|
2008-05-22 15:16:42 +02:00
|
|
|
void operator delete(void*, unsigned) {
|
2012-02-05 23:14:15 +01:00
|
|
|
llvm_unreachable("Constructor throws?");
|
2008-05-22 15:16:42 +02:00
|
|
|
}
|
2014-10-15 22:28:31 +02:00
|
|
|
/// \brief Placement delete - required by std, but never called.
|
2009-03-20 00:26:52 +01:00
|
|
|
void operator delete(void*, unsigned, bool) {
|
2012-02-05 23:14:15 +01:00
|
|
|
llvm_unreachable("Constructor throws?");
|
2009-03-20 00:26:52 +01:00
|
|
|
}
|
2009-03-09 20:57:49 +01:00
|
|
|
protected:
|
2009-03-11 00:02:13 +01:00
|
|
|
template <int Idx, typename U> static Use &OpFrom(const U *that) {
|
|
|
|
return Idx < 0
|
|
|
|
? OperandTraits<U>::op_end(const_cast<U*>(that))[Idx]
|
|
|
|
: OperandTraits<U>::op_begin(const_cast<U*>(that))[Idx];
|
2008-05-10 10:32:32 +02:00
|
|
|
}
|
2009-03-11 00:02:13 +01:00
|
|
|
template <int Idx> Use &Op() {
|
|
|
|
return OpFrom<Idx>(this);
|
|
|
|
}
|
|
|
|
template <int Idx> const Use &Op() const {
|
|
|
|
return OpFrom<Idx>(this);
|
2008-05-10 10:32:32 +02:00
|
|
|
}
|
2015-06-12 19:48:05 +02:00
|
|
|
private:
|
2015-06-12 19:48:18 +02:00
|
|
|
Use *&getHungOffOperands() { return *(reinterpret_cast<Use **>(this) - 1); }
|
|
|
|
|
|
|
|
Use *getIntrusiveOperands() {
|
|
|
|
return reinterpret_cast<Use *>(this) - NumUserOperands;
|
|
|
|
}
|
|
|
|
|
2015-06-12 19:48:05 +02:00
|
|
|
void setOperandList(Use *NewList) {
|
2015-06-12 19:48:18 +02:00
|
|
|
assert(HasHungOffUses &&
|
|
|
|
"Setting operand list only required for hung off uses");
|
|
|
|
getHungOffOperands() = NewList;
|
2015-06-12 19:48:05 +02:00
|
|
|
}
|
2009-03-09 20:57:49 +01:00
|
|
|
public:
|
2015-06-12 19:48:18 +02:00
|
|
|
Use *getOperandList() {
|
|
|
|
return HasHungOffUses ? getHungOffOperands() : getIntrusiveOperands();
|
|
|
|
}
|
|
|
|
const Use *getOperandList() const {
|
|
|
|
return const_cast<User *>(this)->getOperandList();
|
2015-06-12 19:48:05 +02:00
|
|
|
}
|
2005-04-21 22:19:05 +02:00
|
|
|
Value *getOperand(unsigned i) const {
|
2015-06-12 19:48:10 +02:00
|
|
|
assert(i < NumUserOperands && "getOperand() out of range!");
|
2015-06-12 19:48:05 +02:00
|
|
|
return getOperandList()[i];
|
2001-07-07 10:36:50 +02:00
|
|
|
}
|
Instead of storing operands as std::vector<Use>, just maintain a pointer
and num operands in the User class. this allows us to embed the operands
directly in the subclasses if possible. For example, for binary operators
we store the two operands in the derived class.
The has several effects:
1. it improves locality because the operands and instruction are together
2. it makes accesses to operands faster (one less load) if you access them
through the derived class pointer. For example this:
Value *GetBinaryOperatorOp(BinaryOperator *I, int i) {
return I->getOperand(i);
}
Was compiled to:
_Z19GetBinaryOperatorOpPN4llvm14BinaryOperatorEi:
movl 4(%esp), %edx
movl 8(%esp), %eax
sall $4, %eax
movl 24(%edx), %ecx
addl %ecx, %eax
movl (%eax), %eax
ret
and is now compiled to:
_Z19GetBinaryOperatorOpPN4llvm14BinaryOperatorEi:
movl 8(%esp), %eax
movl 4(%esp), %edx
sall $4, %eax
addl %edx, %eax
movl 44(%eax), %eax
ret
Accesses through "Instruction*" are unmodified.
3. This reduces memory consumption (by about 3%) by eliminating 1 word of
vector overhead and a malloc header on a seperate object.
4. This speeds up gccas about 10% (both debug and release builds) on
large things (such as 176.gcc). For example, it takes a debug build
from 172.9 -> 155.6s and a release gccas from 67.7 -> 61.8s
llvm-svn: 19883
2005-01-29 01:29:39 +01:00
|
|
|
void setOperand(unsigned i, Value *Val) {
|
2015-06-12 19:48:10 +02:00
|
|
|
assert(i < NumUserOperands && "setOperand() out of range!");
|
2008-10-28 18:22:40 +01:00
|
|
|
assert((!isa<Constant>((const Value*)this) ||
|
|
|
|
isa<GlobalValue>((const Value*)this)) &&
|
|
|
|
"Cannot mutate a constant with setOperand!");
|
2015-06-12 19:48:05 +02:00
|
|
|
getOperandList()[i] = Val;
|
2001-07-07 10:36:50 +02:00
|
|
|
}
|
2009-01-31 08:34:19 +01:00
|
|
|
const Use &getOperandUse(unsigned i) const {
|
2015-06-12 19:48:10 +02:00
|
|
|
assert(i < NumUserOperands && "getOperandUse() out of range!");
|
2015-06-12 19:48:05 +02:00
|
|
|
return getOperandList()[i];
|
2009-01-31 08:34:19 +01:00
|
|
|
}
|
|
|
|
Use &getOperandUse(unsigned i) {
|
2015-06-12 19:48:10 +02:00
|
|
|
assert(i < NumUserOperands && "getOperandUse() out of range!");
|
2015-06-12 19:48:05 +02:00
|
|
|
return getOperandList()[i];
|
2009-01-31 08:34:19 +01:00
|
|
|
}
|
2012-10-09 18:55:14 +02:00
|
|
|
|
2015-06-12 19:48:10 +02:00
|
|
|
unsigned getNumOperands() const { return NumUserOperands; }
|
|
|
|
|
[IR] Teach `llvm::User` to co-allocate a descriptor.
Summary:
With this change, subclasses of `llvm::User` will be able to co-allocate
a variable number of bytes (called a "descriptor") with the `llvm::User`
instance. The co-allocated descriptor can later be accessed using
`llvm::User::getDescriptor`. This will be used in later changes to
implement operand bundles.
This change steals one bit from `NumUserOperands`, but given that it is
still 28 bits wide I don't think this will be a practical issue.
This change does not allow allocating hung off uses with descriptors.
This only for simplicity, not for any fundamental reason; and we can
easily add this functionality later if needed.
Reviewers: reames, chandlerc, dexonsmith, kmod, majnemer, pete, JosephTremoulet
Subscribers: pete, sanjoy, llvm-commits
Differential Revision: http://reviews.llvm.org/D12455
llvm-svn: 248453
2015-09-24 03:00:49 +02:00
|
|
|
/// Returns the descriptor co-allocated with this User instance.
|
|
|
|
ArrayRef<const uint8_t> getDescriptor() const;
|
|
|
|
|
|
|
|
/// Returns the descriptor co-allocated with this User instance.
|
|
|
|
MutableArrayRef<uint8_t> getDescriptor();
|
|
|
|
|
2015-06-12 19:48:10 +02:00
|
|
|
/// Set the number of operands on a GlobalVariable.
|
|
|
|
///
|
|
|
|
/// GlobalVariable always allocates space for a single operands, but
|
|
|
|
/// doesn't always use it.
|
|
|
|
///
|
|
|
|
/// FIXME: As that the number of operands is used to find the start of
|
|
|
|
/// the allocated memory in operator delete, we need to always think we have
|
|
|
|
/// 1 operand before delete.
|
|
|
|
void setGlobalVariableNumOperands(unsigned NumOps) {
|
|
|
|
assert(NumOps <= 1 && "GlobalVariable can only have 0 or 1 operands");
|
|
|
|
NumUserOperands = NumOps;
|
|
|
|
}
|
|
|
|
|
2015-06-17 22:52:32 +02:00
|
|
|
/// Set the number of operands on a Function.
|
|
|
|
///
|
|
|
|
/// Function always allocates space for a single operands, but
|
|
|
|
/// doesn't always use it.
|
|
|
|
///
|
|
|
|
/// FIXME: As that the number of operands is used to find the start of
|
|
|
|
/// the allocated memory in operator delete, we need to always think we have
|
|
|
|
/// 1 operand before delete.
|
|
|
|
void setFunctionNumOperands(unsigned NumOps) {
|
|
|
|
assert(NumOps <= 1 && "Function can only have 0 or 1 operands");
|
|
|
|
NumUserOperands = NumOps;
|
|
|
|
}
|
|
|
|
|
2015-06-12 19:48:10 +02:00
|
|
|
/// \brief Subclasses with hung off uses need to manage the operand count
|
|
|
|
/// themselves. In these instances, the operand count isn't used to find the
|
|
|
|
/// OperandList, so there's no issue in having the operand count change.
|
|
|
|
void setNumHungOffUseOperands(unsigned NumOps) {
|
|
|
|
assert(HasHungOffUses && "Must have hung off uses to use this method");
|
|
|
|
assert(NumOps < (1u << NumUserOperandsBits) && "Too many operands");
|
|
|
|
NumUserOperands = NumOps;
|
|
|
|
}
|
2001-07-07 10:36:50 +02:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// Operand Iterator interface...
|
2001-06-06 22:29:01 +02:00
|
|
|
//
|
Instead of storing operands as std::vector<Use>, just maintain a pointer
and num operands in the User class. this allows us to embed the operands
directly in the subclasses if possible. For example, for binary operators
we store the two operands in the derived class.
The has several effects:
1. it improves locality because the operands and instruction are together
2. it makes accesses to operands faster (one less load) if you access them
through the derived class pointer. For example this:
Value *GetBinaryOperatorOp(BinaryOperator *I, int i) {
return I->getOperand(i);
}
Was compiled to:
_Z19GetBinaryOperatorOpPN4llvm14BinaryOperatorEi:
movl 4(%esp), %edx
movl 8(%esp), %eax
sall $4, %eax
movl 24(%edx), %ecx
addl %ecx, %eax
movl (%eax), %eax
ret
and is now compiled to:
_Z19GetBinaryOperatorOpPN4llvm14BinaryOperatorEi:
movl 8(%esp), %eax
movl 4(%esp), %edx
sall $4, %eax
addl %edx, %eax
movl 44(%eax), %eax
ret
Accesses through "Instruction*" are unmodified.
3. This reduces memory consumption (by about 3%) by eliminating 1 word of
vector overhead and a malloc header on a seperate object.
4. This speeds up gccas about 10% (both debug and release builds) on
large things (such as 176.gcc). For example, it takes a debug build
from 172.9 -> 155.6s and a release gccas from 67.7 -> 61.8s
llvm-svn: 19883
2005-01-29 01:29:39 +01:00
|
|
|
typedef Use* op_iterator;
|
|
|
|
typedef const Use* const_op_iterator;
|
2014-03-03 11:42:58 +01:00
|
|
|
typedef iterator_range<op_iterator> op_range;
|
|
|
|
typedef iterator_range<const_op_iterator> const_op_range;
|
2001-07-07 10:36:50 +02:00
|
|
|
|
2015-06-12 19:48:21 +02:00
|
|
|
op_iterator op_begin() { return getOperandList(); }
|
|
|
|
const_op_iterator op_begin() const { return getOperandList(); }
|
|
|
|
op_iterator op_end() {
|
2015-06-12 19:48:10 +02:00
|
|
|
return getOperandList() + NumUserOperands;
|
2015-06-12 19:48:05 +02:00
|
|
|
}
|
2015-06-12 19:48:21 +02:00
|
|
|
const_op_iterator op_end() const {
|
2015-06-12 19:48:10 +02:00
|
|
|
return getOperandList() + NumUserOperands;
|
2015-06-12 19:48:05 +02:00
|
|
|
}
|
2015-06-12 19:48:21 +02:00
|
|
|
op_range operands() {
|
2014-03-03 11:59:41 +01:00
|
|
|
return op_range(op_begin(), op_end());
|
2014-03-03 11:42:58 +01:00
|
|
|
}
|
2015-06-12 19:48:21 +02:00
|
|
|
const_op_range operands() const {
|
2014-03-03 11:59:41 +01:00
|
|
|
return const_op_range(op_begin(), op_end());
|
2014-03-03 11:42:58 +01:00
|
|
|
}
|
2003-06-18 00:15:55 +02:00
|
|
|
|
2014-10-15 22:28:31 +02:00
|
|
|
/// \brief Iterator for directly iterating over the operand Values.
|
2014-04-24 07:33:53 +02:00
|
|
|
struct value_op_iterator
|
2014-04-29 03:57:35 +02:00
|
|
|
: iterator_adaptor_base<value_op_iterator, op_iterator,
|
|
|
|
std::random_access_iterator_tag, Value *,
|
|
|
|
ptrdiff_t, Value *, Value *> {
|
2014-04-24 07:33:53 +02:00
|
|
|
explicit value_op_iterator(Use *U = nullptr) : iterator_adaptor_base(U) {}
|
2012-10-09 18:55:14 +02:00
|
|
|
|
2014-04-24 07:33:53 +02:00
|
|
|
Value *operator*() const { return *I; }
|
2012-10-09 18:55:14 +02:00
|
|
|
Value *operator->() const { return operator*(); }
|
|
|
|
};
|
|
|
|
|
2015-06-12 19:48:21 +02:00
|
|
|
value_op_iterator value_op_begin() {
|
2012-10-09 18:55:14 +02:00
|
|
|
return value_op_iterator(op_begin());
|
|
|
|
}
|
2015-06-12 19:48:21 +02:00
|
|
|
value_op_iterator value_op_end() {
|
2012-10-09 18:55:14 +02:00
|
|
|
return value_op_iterator(op_end());
|
|
|
|
}
|
2015-06-12 19:48:21 +02:00
|
|
|
iterator_range<value_op_iterator> operand_values() {
|
2014-03-03 11:59:41 +01:00
|
|
|
return iterator_range<value_op_iterator>(value_op_begin(), value_op_end());
|
2014-03-03 11:42:58 +01:00
|
|
|
}
|
2012-10-09 18:55:14 +02:00
|
|
|
|
2014-10-15 22:28:31 +02:00
|
|
|
/// \brief Drop all references to operands.
|
|
|
|
///
|
|
|
|
/// This function is in charge of "letting go" of all objects that this User
|
|
|
|
/// refers to. This allows one to 'delete' a whole class at a time, even
|
|
|
|
/// though there may be circular references... First all references are
|
|
|
|
/// dropped, and all use counts go to zero. Then everything is deleted for
|
|
|
|
/// real. Note that no operations are valid on an object that has "dropped
|
|
|
|
/// all references", except operator delete.
|
Instead of storing operands as std::vector<Use>, just maintain a pointer
and num operands in the User class. this allows us to embed the operands
directly in the subclasses if possible. For example, for binary operators
we store the two operands in the derived class.
The has several effects:
1. it improves locality because the operands and instruction are together
2. it makes accesses to operands faster (one less load) if you access them
through the derived class pointer. For example this:
Value *GetBinaryOperatorOp(BinaryOperator *I, int i) {
return I->getOperand(i);
}
Was compiled to:
_Z19GetBinaryOperatorOpPN4llvm14BinaryOperatorEi:
movl 4(%esp), %edx
movl 8(%esp), %eax
sall $4, %eax
movl 24(%edx), %ecx
addl %ecx, %eax
movl (%eax), %eax
ret
and is now compiled to:
_Z19GetBinaryOperatorOpPN4llvm14BinaryOperatorEi:
movl 8(%esp), %eax
movl 4(%esp), %edx
sall $4, %eax
addl %edx, %eax
movl 44(%eax), %eax
ret
Accesses through "Instruction*" are unmodified.
3. This reduces memory consumption (by about 3%) by eliminating 1 word of
vector overhead and a malloc header on a seperate object.
4. This speeds up gccas about 10% (both debug and release builds) on
large things (such as 176.gcc). For example, it takes a debug build
from 172.9 -> 155.6s and a release gccas from 67.7 -> 61.8s
llvm-svn: 19883
2005-01-29 01:29:39 +01:00
|
|
|
void dropAllReferences() {
|
2014-03-10 16:03:06 +01:00
|
|
|
for (Use &U : operands())
|
2014-04-09 08:08:46 +02:00
|
|
|
U.set(nullptr);
|
2001-07-07 10:36:50 +02:00
|
|
|
}
|
2001-06-06 22:29:01 +02:00
|
|
|
|
2014-10-15 22:28:31 +02:00
|
|
|
/// \brief Replace uses of one Value with another.
|
2002-08-26 00:54:55 +02:00
|
|
|
///
|
2014-10-15 22:28:31 +02:00
|
|
|
/// Replaces all references to the "From" definition with references to the
|
|
|
|
/// "To" definition.
|
2001-06-06 22:29:01 +02:00
|
|
|
void replaceUsesOfWith(Value *From, Value *To);
|
2001-07-08 20:38:18 +02:00
|
|
|
|
2001-10-13 08:18:05 +02:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Value *V) {
|
2004-07-18 01:32:11 +02:00
|
|
|
return isa<Instruction>(V) || isa<Constant>(V);
|
2001-10-13 08:18:05 +02:00
|
|
|
}
|
2001-06-06 22:29:01 +02:00
|
|
|
};
|
2015-06-17 03:21:20 +02:00
|
|
|
// Either Use objects, or a Use pointer can be prepended to User.
|
|
|
|
static_assert(AlignOf<Use>::Alignment >= AlignOf<User>::Alignment,
|
2015-06-17 15:53:12 +02:00
|
|
|
"Alignment is insufficient after objects prepended to User");
|
2015-06-17 03:21:20 +02:00
|
|
|
static_assert(AlignOf<Use *>::Alignment >= AlignOf<User>::Alignment,
|
2015-06-17 15:53:12 +02:00
|
|
|
"Alignment is insufficient after objects prepended to User");
|
2001-06-06 22:29:01 +02:00
|
|
|
|
2003-05-29 17:08:33 +02:00
|
|
|
template<> struct simplify_type<User::op_iterator> {
|
|
|
|
typedef Value* SimpleType;
|
2013-03-27 17:43:11 +01:00
|
|
|
static SimpleType getSimplifiedValue(User::op_iterator &Val) {
|
|
|
|
return Val->get();
|
2003-05-29 17:08:33 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
template<> struct simplify_type<User::const_op_iterator> {
|
2013-03-27 17:43:11 +01:00
|
|
|
typedef /*const*/ Value* SimpleType;
|
|
|
|
static SimpleType getSimplifiedValue(User::const_op_iterator &Val) {
|
|
|
|
return Val->get();
|
2003-05-29 17:08:33 +02:00
|
|
|
}
|
|
|
|
};
|
2005-02-27 07:15:51 +01:00
|
|
|
|
2015-06-23 11:49:53 +02:00
|
|
|
} // End llvm namespace
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2001-06-06 22:29:01 +02:00
|
|
|
#endif
|