| Gabor Greif | 697e94c | 2008-05-15 10:04:30 +0000 | [diff] [blame] | 1 | //===-- Use.cpp - Implement the Use class ---------------------------------===// |
| Gabor Greif | f6caff66 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| Gabor Greif | f6caff66 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| Gabor Greif | f6caff66 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 8 | |
| Chandler Carruth | 06d4918 | 2014-03-04 08:51:00 +0000 | [diff] [blame] | 9 | #include "llvm/IR/Use.h" |
| Chandler Carruth | 387e059 | 2014-03-04 09:19:43 +0000 | [diff] [blame] | 10 | #include "llvm/IR/User.h" |
| Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 11 | #include "llvm/IR/Value.h" |
| Douglas Gregor | c0f6380 | 2012-03-26 14:04:17 +0000 | [diff] [blame] | 12 | #include <new> |
| Gabor Greif | f6caff66 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 13 | |
| 14 | namespace llvm { |
| 15 | |
| Gabor Greif | 5ef7404 | 2008-05-13 22:51:52 +0000 | [diff] [blame] | 16 | void Use::swap(Use &RHS) { |
| Chandler Carruth | 4ffd9d2 | 2014-03-04 09:00:15 +0000 | [diff] [blame] | 17 | if (Val == RHS.Val) |
| 18 | return; |
| Gabor Greif | 5ef7404 | 2008-05-13 22:51:52 +0000 | [diff] [blame] | 19 | |
| Chandler Carruth | 4ffd9d2 | 2014-03-04 09:00:15 +0000 | [diff] [blame] | 20 | if (Val) |
| 21 | removeFromList(); |
| Gabor Greif | 5ef7404 | 2008-05-13 22:51:52 +0000 | [diff] [blame] | 22 | |
| Chandler Carruth | 4ffd9d2 | 2014-03-04 09:00:15 +0000 | [diff] [blame] | 23 | Value *OldVal = Val; |
| 24 | if (RHS.Val) { |
| 25 | RHS.removeFromList(); |
| 26 | Val = RHS.Val; |
| 27 | Val->addUse(*this); |
| 28 | } else { |
| Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 29 | Val = nullptr; |
| Chandler Carruth | 4ffd9d2 | 2014-03-04 09:00:15 +0000 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | if (OldVal) { |
| 33 | RHS.Val = OldVal; |
| 34 | RHS.Val->addUse(RHS); |
| 35 | } else { |
| Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 36 | RHS.Val = nullptr; |
| Gabor Greif | 5ef7404 | 2008-05-13 22:51:52 +0000 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | |
| Chandler Carruth | 387e059 | 2014-03-04 09:19:43 +0000 | [diff] [blame] | 40 | unsigned Use::getOperandNo() const { |
| 41 | return this - getUser()->op_begin(); |
| 42 | } |
| 43 | |
| Gabor Greif | f6caff66 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 44 | void Use::zap(Use *Start, const Use *Stop, bool del) { |
| Jay Foad | bbb91f2 | 2011-01-16 15:30:52 +0000 | [diff] [blame] | 45 | while (Start != Stop) |
| 46 | (--Stop)->~Use(); |
| 47 | if (del) |
| Gabor Greif | f6caff66 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 48 | ::operator delete(Start); |
| Gabor Greif | f6caff66 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 51 | } // End llvm namespace |