Mercurial > hg > CbC > CbC_llvm
comparison include/llvm/Support/KnownBits.h @ 148:63bd29f05246
merged
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Aug 2019 19:46:37 +0900 |
parents | c2174574ed3a |
children |
comparison
equal
deleted
inserted
replaced
146:3fc4d5c3e21e | 148:63bd29f05246 |
---|---|
1 //===- llvm/Support/KnownBits.h - Stores known zeros/ones -------*- C++ -*-===// | 1 //===- llvm/Support/KnownBits.h - Stores known zeros/ones -------*- C++ -*-===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 // | 4 // See https://llvm.org/LICENSE.txt for license information. |
5 // This file is distributed under the University of Illinois Open Source | 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 // License. See LICENSE.TXT for details. | |
7 // | 6 // |
8 //===----------------------------------------------------------------------===// | 7 //===----------------------------------------------------------------------===// |
9 // | 8 // |
10 // This file contains a class for representing known zeros and ones used by | 9 // This file contains a class for representing known zeros and ones used by |
11 // computeKnownBits. | 10 // computeKnownBits. |
101 /// Make this value negative. | 100 /// Make this value negative. |
102 void makeNegative() { | 101 void makeNegative() { |
103 One.setSignBit(); | 102 One.setSignBit(); |
104 } | 103 } |
105 | 104 |
106 /// Make this value negative. | 105 /// Make this value non-negative. |
107 void makeNonNegative() { | 106 void makeNonNegative() { |
108 Zero.setSignBit(); | 107 Zero.setSignBit(); |
109 } | 108 } |
110 | 109 |
111 /// Truncate the underlying known Zero and One bits. This is equivalent | 110 /// Truncate the underlying known Zero and One bits. This is equivalent |
112 /// to truncating the value we're tracking. | 111 /// to truncating the value we're tracking. |
113 KnownBits trunc(unsigned BitWidth) { | 112 KnownBits trunc(unsigned BitWidth) const { |
114 return KnownBits(Zero.trunc(BitWidth), One.trunc(BitWidth)); | 113 return KnownBits(Zero.trunc(BitWidth), One.trunc(BitWidth)); |
115 } | 114 } |
116 | 115 |
117 /// Zero extends the underlying known Zero and One bits. This is equivalent | 116 /// Extends the underlying known Zero and One bits. |
118 /// to zero extending the value we're tracking. | 117 /// By setting ExtendedBitsAreKnownZero=true this will be equivalent to |
119 KnownBits zext(unsigned BitWidth) { | 118 /// zero extending the value we're tracking. |
120 return KnownBits(Zero.zext(BitWidth), One.zext(BitWidth)); | 119 /// With ExtendedBitsAreKnownZero=false the extended bits are set to unknown. |
120 KnownBits zext(unsigned BitWidth, bool ExtendedBitsAreKnownZero) const { | |
121 unsigned OldBitWidth = getBitWidth(); | |
122 APInt NewZero = Zero.zext(BitWidth); | |
123 if (ExtendedBitsAreKnownZero) | |
124 NewZero.setBitsFrom(OldBitWidth); | |
125 return KnownBits(NewZero, One.zext(BitWidth)); | |
121 } | 126 } |
122 | 127 |
123 /// Sign extends the underlying known Zero and One bits. This is equivalent | 128 /// Sign extends the underlying known Zero and One bits. This is equivalent |
124 /// to sign extending the value we're tracking. | 129 /// to sign extending the value we're tracking. |
125 KnownBits sext(unsigned BitWidth) { | 130 KnownBits sext(unsigned BitWidth) const { |
126 return KnownBits(Zero.sext(BitWidth), One.sext(BitWidth)); | 131 return KnownBits(Zero.sext(BitWidth), One.sext(BitWidth)); |
127 } | 132 } |
128 | 133 |
129 /// Zero extends or truncates the underlying known Zero and One bits. This is | 134 /// Extends or truncates the underlying known Zero and One bits. When |
130 /// equivalent to zero extending or truncating the value we're tracking. | 135 /// extending the extended bits can either be set as known zero (if |
131 KnownBits zextOrTrunc(unsigned BitWidth) { | 136 /// ExtendedBitsAreKnownZero=true) or as unknown (if |
137 /// ExtendedBitsAreKnownZero=false). | |
138 KnownBits zextOrTrunc(unsigned BitWidth, | |
139 bool ExtendedBitsAreKnownZero) const { | |
140 if (BitWidth > getBitWidth()) | |
141 return zext(BitWidth, ExtendedBitsAreKnownZero); | |
132 return KnownBits(Zero.zextOrTrunc(BitWidth), One.zextOrTrunc(BitWidth)); | 142 return KnownBits(Zero.zextOrTrunc(BitWidth), One.zextOrTrunc(BitWidth)); |
133 } | 143 } |
134 | 144 |
135 /// Returns the minimum number of trailing zero bits. | 145 /// Returns the minimum number of trailing zero bits. |
136 unsigned countMinTrailingZeros() const { | 146 unsigned countMinTrailingZeros() const { |
190 /// Returns the maximum number of bits that could be one. | 200 /// Returns the maximum number of bits that could be one. |
191 unsigned countMaxPopulation() const { | 201 unsigned countMaxPopulation() const { |
192 return getBitWidth() - Zero.countPopulation(); | 202 return getBitWidth() - Zero.countPopulation(); |
193 } | 203 } |
194 | 204 |
205 /// Compute known bits resulting from adding LHS, RHS and a 1-bit Carry. | |
206 static KnownBits computeForAddCarry( | |
207 const KnownBits &LHS, const KnownBits &RHS, const KnownBits &Carry); | |
208 | |
195 /// Compute known bits resulting from adding LHS and RHS. | 209 /// Compute known bits resulting from adding LHS and RHS. |
196 static KnownBits computeForAddSub(bool Add, bool NSW, const KnownBits &LHS, | 210 static KnownBits computeForAddSub(bool Add, bool NSW, const KnownBits &LHS, |
197 KnownBits RHS); | 211 KnownBits RHS); |
198 }; | 212 }; |
199 | 213 |