/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/IR/Use.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- Use.cpp - Implement the Use class ---------------------------------===// |
2 | | // |
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 |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
9 | | #include "llvm/IR/Use.h" |
10 | | #include "llvm/IR/User.h" |
11 | | #include "llvm/IR/Value.h" |
12 | | #include <new> |
13 | | |
14 | | namespace llvm { |
15 | | |
16 | 764k | void Use::swap(Use &RHS) { |
17 | 764k | if (Val == RHS.Val) |
18 | 0 | return; |
19 | 764k | |
20 | 764k | if (Val) |
21 | 764k | removeFromList(); |
22 | 764k | |
23 | 764k | Value *OldVal = Val; |
24 | 764k | if (RHS.Val) { |
25 | 764k | RHS.removeFromList(); |
26 | 764k | Val = RHS.Val; |
27 | 764k | Val->addUse(*this); |
28 | 764k | } else { |
29 | 0 | Val = nullptr; |
30 | 0 | } |
31 | 764k | |
32 | 764k | if (OldVal) { |
33 | 764k | RHS.Val = OldVal; |
34 | 764k | RHS.Val->addUse(RHS); |
35 | 764k | } else { |
36 | 0 | RHS.Val = nullptr; |
37 | 0 | } |
38 | 764k | } |
39 | | |
40 | 2.00G | User *Use::getUser() const { |
41 | 2.00G | const Use *End = getImpliedUser(); |
42 | 2.00G | const UserRef *ref = reinterpret_cast<const UserRef *>(End); |
43 | 2.00G | return ref->getInt() ? ref->getPointer()71.9M |
44 | 2.00G | : reinterpret_cast<User *>(const_cast<Use *>(End))1.92G ; |
45 | 2.00G | } |
46 | | |
47 | 8.19M | unsigned Use::getOperandNo() const { |
48 | 8.19M | return this - getUser()->op_begin(); |
49 | 8.19M | } |
50 | | |
51 | | // Sets up the waymarking algorithm's tags for a series of Uses. See the |
52 | | // algorithm details here: |
53 | | // |
54 | | // http://www.llvm.org/docs/ProgrammersManual.html#the-waymarking-algorithm |
55 | | // |
56 | 70.7M | Use *Use::initTags(Use *const Start, Use *Stop) { |
57 | 70.7M | ptrdiff_t Done = 0; |
58 | 187M | while (Done < 20) { |
59 | 187M | if (Start == Stop--) |
60 | 70.7M | return Start; |
61 | 116M | static const PrevPtrTag tags[20] = { |
62 | 116M | fullStopTag, oneDigitTag, stopTag, oneDigitTag, oneDigitTag, |
63 | 116M | stopTag, zeroDigitTag, oneDigitTag, oneDigitTag, stopTag, |
64 | 116M | zeroDigitTag, oneDigitTag, zeroDigitTag, oneDigitTag, stopTag, |
65 | 116M | oneDigitTag, oneDigitTag, oneDigitTag, oneDigitTag, stopTag}; |
66 | 116M | new (Stop) Use(tags[Done++]); |
67 | 116M | } |
68 | 70.7M | |
69 | 70.7M | ptrdiff_t Count = Done; |
70 | 894k | while (Start != Stop) { |
71 | 846k | --Stop; |
72 | 846k | if (!Count) { |
73 | 104k | new (Stop) Use(stopTag); |
74 | 104k | ++Done; |
75 | 104k | Count = Done; |
76 | 742k | } else { |
77 | 742k | new (Stop) Use(PrevPtrTag(Count & 1)); |
78 | 742k | Count >>= 1; |
79 | 742k | ++Done; |
80 | 742k | } |
81 | 846k | } |
82 | 48.0k | |
83 | 48.0k | return Start; |
84 | 70.7M | } |
85 | | |
86 | 54.1M | void Use::zap(Use *Start, const Use *Stop, bool del) { |
87 | 138M | while (Start != Stop) |
88 | 84.6M | (--Stop)->~Use(); |
89 | 54.1M | if (del) |
90 | 6.85M | ::operator delete(Start); |
91 | 54.1M | } |
92 | | |
93 | 2.00G | const Use *Use::getImpliedUser() const { |
94 | 2.00G | const Use *Current = this; |
95 | 2.00G | |
96 | 2.84G | while (true) { |
97 | 2.84G | unsigned Tag = (Current++)->Prev.getInt(); |
98 | 2.84G | switch (Tag) { |
99 | 2.84G | case zeroDigitTag: |
100 | 842M | case oneDigitTag: |
101 | 842M | continue; |
102 | 842M | |
103 | 842M | case stopTag: { |
104 | 255M | ++Current; |
105 | 255M | ptrdiff_t Offset = 1; |
106 | 321M | while (true) { |
107 | 321M | unsigned Tag = Current->Prev.getInt(); |
108 | 321M | switch (Tag) { |
109 | 321M | case zeroDigitTag: |
110 | 66.0M | case oneDigitTag: |
111 | 66.0M | ++Current; |
112 | 66.0M | Offset = (Offset << 1) + Tag; |
113 | 66.0M | continue; |
114 | 255M | default: |
115 | 255M | return Current + Offset; |
116 | 321M | } |
117 | 321M | } |
118 | 255M | } |
119 | 255M | |
120 | 1.74G | case fullStopTag: |
121 | 1.74G | return Current; |
122 | 2.84G | } |
123 | 2.84G | } |
124 | 2.00G | } |
125 | | |
126 | | } // End llvm namespace |