llvm.org GIT mirror llvm / fd05924
Decrease usage of use_size() git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9135 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 17 years ago
12 changed file(s) with 25 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
102102
103103 // Loop over all of the uses of the GlobalValue. The only thing they are
104104 // allowed to be is ConstantPointerRef's.
105 assert(OldGV->use_size() == 1 && "Only one reference should exist!");
105 assert(OldGV->hasOneUse() && "Only one reference should exist!");
106106 User *U = OldGV->use_back(); // Must be a ConstantPointerRef...
107107 ConstantPointerRef *CPR = cast(U);
108108
296296 // is used directly, i.e., made a child of the instruction node.
297297 //
298298 InstrTreeNode* opTreeNode;
299 if (isa(operand) && operand->use_size() == 1 &&
299 if (isa(operand) && operand->hasOneUse() &&
300300 cast(operand)->getParent() == instr->getParent() &&
301301 instr->getOpcode() != Instruction::PHINode &&
302302 instr->getOpcode() != Instruction::Call)
8787 static bool isInlinableInst(const Instruction &I) {
8888 // Must be an expression, must be used exactly once. If it is dead, we
8989 // emit it inline where it would go.
90 if (I.getType() == Type::VoidTy || I.use_size() != 1 ||
90 if (I.getType() == Type::VoidTy || !I.hasOneUse() ||
9191 isa(I) || isa(I) || isa(I) ||
9292 isa(I) || isa(I))
9393 // Don't inline a load across a store or other bad things!
8787 static bool isInlinableInst(const Instruction &I) {
8888 // Must be an expression, must be used exactly once. If it is dead, we
8989 // emit it inline where it would go.
90 if (I.getType() == Type::VoidTy || I.use_size() != 1 ||
90 if (I.getType() == Type::VoidTy || !I.hasOneUse() ||
9191 isa(I) || isa(I) || isa(I) ||
9292 isa(I) || isa(I))
9393 // Don't inline a load across a store or other bad things!
296296 // is used directly, i.e., made a child of the instruction node.
297297 //
298298 InstrTreeNode* opTreeNode;
299 if (isa(operand) && operand->use_size() == 1 &&
299 if (isa(operand) && operand->hasOneUse() &&
300300 cast(operand)->getParent() == instr->getParent() &&
301301 instr->getOpcode() != Instruction::PHINode &&
302302 instr->getOpcode() != Instruction::Call)
553553 //
554554 static SetCondInst *canFoldSetCCIntoBranch(Value *V) {
555555 if (SetCondInst *SCI = dyn_cast(V))
556 if (SCI->use_size() == 1 && isa(SCI->use_back()) &&
556 if (SCI->hasOneUse() && isa(SCI->use_back()) &&
557557 SCI->getParent() == cast(SCI->use_back())->getParent()) {
558558 const Type *Ty = SCI->getOperand(0)->getType();
559559 if (Ty != Type::LongTy && Ty != Type::ULongTy)
553553 //
554554 static SetCondInst *canFoldSetCCIntoBranch(Value *V) {
555555 if (SetCondInst *SCI = dyn_cast(V))
556 if (SCI->use_size() == 1 && isa(SCI->use_back()) &&
556 if (SCI->hasOneUse() && isa(SCI->use_back()) &&
557557 SCI->getParent() == cast(SCI->use_back())->getParent()) {
558558 const Type *Ty = SCI->getOperand(0)->getType();
559559 if (Ty != Type::LongTy && Ty != Type::ULongTy)
12701270 }
12711271
12721272 ValueHandle::~ValueHandle() {
1273 if (Operands[0]->use_size() == 1) {
1273 if (Operands[0]->hasOneUse()) {
12741274 Value *V = Operands[0];
12751275 Operands[0] = 0; // Drop use!
12761276
4848 // If there is only one call of the function, and it has internal linkage,
4949 // make it almost guaranteed to be inlined.
5050 //
51 if (Callee->use_size() == 1 && Callee->hasInternalLinkage())
51 if (Callee->hasOneUse() && Callee->hasInternalLinkage())
5252 InlineCost -= 30000;
5353
5454 // Add to the inline quality for properties that make the call valuable to
378378 // Check the common case first: empty block, or block with just a setcc.
379379 if (BB->size() == 1 ||
380380 (BB->size() == 2 && &BB->front() == BI->getCondition() &&
381 BI->getCondition()->use_size() == 1))
381 BI->getCondition()->hasOneUse()))
382382 return true;
383383
384384 // Check the more complex case now...
158158 // isOnlyUse - Return true if this instruction will be deleted if we stop using
159159 // it.
160160 static bool isOnlyUse(Value *V) {
161 return V->use_size() == 1 || isa(V);
161 return V->hasOneUse() || isa(V);
162162 }
163163
164164 // SimplifyCommutative - This performs a few simplifications for commutative
237237 // non-constant operand of the multiply.
238238 //
239239 static inline Value *dyn_castFoldableMul(Value *V) {
240 if (V->use_size() == 1 && V->getType()->isInteger())
240 if (V->hasOneUse() && V->getType()->isInteger())
241241 if (Instruction *I = dyn_cast(V))
242242 if (I->getOpcode() == Instruction::Mul)
243243 if (isa(I->getOperand(1)))
291291
292292 // Otherwise, if the LHS is not of the same opcode as the root, return.
293293 Instruction *LHSI = dyn_cast(LHS);
294 while (LHSI && LHSI->getOpcode() == Opcode && LHSI->use_size() == 1) {
294 while (LHSI && LHSI->getOpcode() == Opcode && LHSI->hasOneUse()) {
295295 // Should we apply this transform to the RHS?
296296 bool ShouldApply = F.shouldApply(LHSI->getOperand(1));
297297
483483 return BinaryOperator::createNot(Op1);
484484
485485 if (BinaryOperator *Op1I = dyn_cast(Op1))
486 if (Op1I->use_size() == 1) {
486 if (Op1I->hasOneUse()) {
487487 // Replace (x - (y - z)) with (x + (z - y)) if the (y - z) subexpression
488488 // is not used by anyone else...
489489 //
748748 if ((*AndRHS & *OpRHS)->isNullValue()) {
749749 // (X ^ C1) & C2 --> (X & C2) iff (C1&C2) == 0
750750 return BinaryOperator::create(Instruction::And, X, AndRHS);
751 } else if (Op->use_size() == 1) {
751 } else if (Op->hasOneUse()) {
752752 // (X ^ C1) & C2 --> (X & C2) ^ (C1&C2)
753753 std::string OpName = Op->getName(); Op->setName("");
754754 Instruction *And = BinaryOperator::create(Instruction::And,
766766 if (Together == AndRHS) // (X | C) & C --> C
767767 return ReplaceInstUsesWith(TheAnd, AndRHS);
768768
769 if (Op->use_size() == 1 && Together != OpRHS) {
769 if (Op->hasOneUse() && Together != OpRHS) {
770770 // (X | C1) & C2 --> (X | (C1&C2)) & C2
771771 std::string Op0Name = Op->getName(); Op->setName("");
772772 Instruction *Or = BinaryOperator::create(Instruction::Or, X,
777777 }
778778 break;
779779 case Instruction::Add:
780 if (Op->use_size() == 1) {
780 if (Op->hasOneUse()) {
781781 // Adding a one to a single bit bit-field should be turned into an XOR
782782 // of the bit. First thing to check is to see if this AND is with a
783783 // single bit constant.
986986 if (BinaryOperator *Op0I = dyn_cast(Op0)) {
987987 // xor (setcc A, B), true = not (setcc A, B) = setncc A, B
988988 if (SetCondInst *SCI = dyn_cast(Op0I))
989 if (RHS == ConstantBool::True && SCI->use_size() == 1)
989 if (RHS == ConstantBool::True && SCI->hasOneUse())
990990 return new SetCondInst(SCI->getInverseCondition(),
991991 SCI->getOperand(0), SCI->getOperand(1));
992992
10251025 }
10261026
10271027 if (Instruction *Op0I = dyn_cast(Op0))
1028 if (Op0I->getOpcode() == Instruction::Or && Op0I->use_size() == 1) {
1028 if (Op0I->getOpcode() == Instruction::Or && Op0I->hasOneUse()) {
10291029 if (Op0I->getOperand(0) == Op1) // (B|A)^B == (A|B)^B
10301030 cast(Op0I)->swapOperands();
10311031 if (Op0I->getOperand(1) == Op1) { // (A|B)^B == A & ~B
11431143 return new SetCondInst(I.getOpcode(), BOp0, NegVal);
11441144 else if (Value *NegVal = dyn_castNegVal(BOp0))
11451145 return new SetCondInst(I.getOpcode(), NegVal, BOp1);
1146 else if (BO->use_size() == 1) {
1146 else if (BO->hasOneUse()) {
11471147 Instruction *Neg = BinaryOperator::createNeg(BOp1, BO->getName());
11481148 BO->setName("");
11491149 InsertNewInstBefore(Neg, I);
12901290
12911291 // If the operand is an bitwise operator with a constant RHS, and the
12921292 // shift is the only use, we can pull it out of the shift.
1293 if (Op0->use_size() == 1)
1293 if (Op0->hasOneUse())
12941294 if (BinaryOperator *Op0BO = dyn_cast(Op0))
12951295 if (ConstantInt *Op0C = dyn_cast(Op0BO->getOperand(1))) {
12961296 bool isValid = true; // Valid only for And, Or, Xor
15321532 // propagate the cast into the instruction. Also, only handle integral types
15331533 // for now.
15341534 if (Instruction *SrcI = dyn_cast(Src))
1535 if (SrcI->use_size() == 1 && Src->getType()->isIntegral() &&
1535 if (SrcI->hasOneUse() && Src->getType()->isIntegral() &&
15361536 CI.getType()->isInteger()) { // Don't mess with casts to bool here
15371537 const Type *DestTy = CI.getType();
15381538 unsigned SrcBitSize = getTypeSizeInBits(Src->getType());
125125 // only expression using it...
126126 //
127127 if (BinaryOperator *LHSI = dyn_cast(LHS))
128 if (LHSI->getOpcode() == I->getOpcode() && LHSI->use_size() == 1) {
128 if (LHSI->getOpcode() == I->getOpcode() && LHSI->hasOneUse()) {
129129 // If the rank of our current RHS is less than the rank of the LHS's LHS,
130130 // then we reassociate the two instructions...
131131
176176 // we introduce tons of unnecessary negation instructions...
177177 //
178178 if (Instruction *I = dyn_cast(V))
179 if (I->getOpcode() == Instruction::Add && I->use_size() == 1) {
179 if (I->getOpcode() == Instruction::Add && I->hasOneUse()) {
180180 Value *RHS = NegateValue(I->getOperand(1), BI);
181181 Value *LHS = NegateValue(I->getOperand(0), BI);
182182
241241 Instruction *RHSI = dyn_cast(I->getOperand(1));
242242 if (LHSI && (int)LHSI->getOpcode() == I->getOpcode() &&
243243 RHSI && (int)RHSI->getOpcode() == I->getOpcode() &&
244 RHSI->use_size() == 1) {
244 RHSI->hasOneUse()) {
245245 // Insert a new temporary instruction... (A+B)+C
246246 BinaryOperator *Tmp = BinaryOperator::create(I->getOpcode(), LHSI,
247247 RHSI->getOperand(0),