llvm.org GIT mirror llvm / f718e70
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19883 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 15 years ago
1 changed file(s) with 31 addition(s) and 32 deletion(s). Raw diff Collapse all Expand all
2626 class User : public Value {
2727 User(const User &); // Do not implement
2828 protected:
29 std::vector Operands;
29 /// OperandList - This is a pointer to the array of Users for this operand.
30 /// For nodes of fixed arity (e.g. a binary operator) this array will live
31 /// embedded into the derived class. For nodes of variable arity
32 /// (e.g. ConstantArrays, CallInst, PHINodes, etc), this memory will be
33 /// dynamically allocated and should be destroyed by the classes virtual dtor.
34 Use *OperandList;
35
36 /// NumOperands - The number of values used by this User.
37 ///
38 unsigned NumOperands;
39
3040 public:
31 User(const Type *Ty, unsigned vty, const std::string &name = "")
32 : Value(Ty, vty, name) {}
41 User(const Type *Ty, unsigned vty, Use *OpList, unsigned NumOps,
42 const std::string &name = "")
43 : Value(Ty, vty, name), OperandList(OpList), NumOperands(NumOps) {}
3344
34 inline Value *getOperand(unsigned i) {
35 assert(i < Operands.size() && "getOperand() out of range!");
36 return Operands[i];
45 Value *getOperand(unsigned i) const {
46 assert(i < NumOperands && "getOperand() out of range!");
47 return OperandList[i];
3748 }
38 inline const Value *getOperand(unsigned i) const {
39 assert(i < Operands.size() && "getOperand() const out of range!");
40 return Operands[i];
49 void setOperand(unsigned i, Value *Val) {
50 assert(i < NumOperands && "setOperand() out of range!");
51 OperandList[i] = Val;
4152 }
42 inline void setOperand(unsigned i, Value *Val) {
43 assert(i < Operands.size() && "setOperand() out of range!");
44 Operands[i] = Val;
45 }
46 inline unsigned getNumOperands() const { return (unsigned)Operands.size(); }
53 unsigned getNumOperands() const { return NumOperands; }
4754
4855 // ---------------------------------------------------------------------------
4956 // Operand Iterator interface...
5057 //
51 typedef std::vector::iterator op_iterator;
52 typedef std::vector::const_iterator const_op_iterator;
58 typedef Use* op_iterator;
59 typedef const Use* const_op_iterator;
5360
54 void op_reserve(unsigned NumElements) { Operands.reserve(NumElements); }
55
56 inline op_iterator op_begin() { return Operands.begin(); }
57 inline const_op_iterator op_begin() const { return Operands.begin(); }
58 inline op_iterator op_end() { return Operands.end(); }
59 inline const_op_iterator op_end() const { return Operands.end(); }
60
61 /// op_erase - This method is used to remove one of the arguments from the
62 /// operands list. Only use this if you know what you are doing.
63 ///
64 op_iterator op_erase(op_iterator I) { return Operands.erase(I); }
65 op_iterator op_erase(op_iterator I, op_iterator E) {
66 return Operands.erase(I, E);
67 }
61 inline op_iterator op_begin() { return OperandList; }
62 inline const_op_iterator op_begin() const { return OperandList; }
63 inline op_iterator op_end() { return OperandList+NumOperands; }
64 inline const_op_iterator op_end() const { return OperandList+NumOperands; }
6865
6966 // dropAllReferences() - This function is in charge of "letting go" of all
7067 // objects that this User refers to. This allows one to
7471 // valid on an object that has "dropped all references", except operator
7572 // delete.
7673 //
77 inline void dropAllReferences() {
78 Operands.clear();
74 void dropAllReferences() {
75 Use *OL = OperandList;
76 for (unsigned i = 0, e = NumOperands; i != e; ++i)
77 OL[i].set(0);
7978 }
8079
8180 /// replaceUsesOfWith - Replaces all references to the "From" definition with