|
15 | 15 | #define LLVM_CLANG_LIB_CIR_ADDRESS_H |
16 | 16 |
|
17 | 17 | #include "clang/AST/CharUnits.h" |
| 18 | +#include "clang/CIR/Dialect/IR/CIROpsEnums.h" |
18 | 19 | #include "clang/CIR/Dialect/IR/CIRTypes.h" |
19 | 20 |
|
20 | 21 | #include "llvm/IR/Constants.h" |
@@ -185,77 +186,6 @@ class Address { |
185 | 186 | } |
186 | 187 | }; |
187 | 188 |
|
188 | | -/// An abstract representation of an aligned address. This is designed to be an |
189 | | -/// IR-level abstraction, carrying just the information necessary to perform IR |
190 | | -/// operations on an address like loads and stores. In particular, it doesn't |
191 | | -/// carry C type information or allow the representation of things like |
192 | | -/// bit-fields; clients working at that level should generally be using |
193 | | -/// `LValue`. |
194 | | -/// The pointer contained in this class is known to be unsigned. |
195 | | -class RawAddress { |
196 | | - llvm::PointerIntPair<mlir::Value *, 1, bool> PointerAndKnownNonNull; |
197 | | - mlir::Type *ElementType; |
198 | | - CharUnits Alignment; |
199 | | - |
200 | | -protected: |
201 | | - RawAddress(std::nullptr_t) : ElementType(nullptr) {} |
202 | | - |
203 | | -public: |
204 | | - RawAddress(mlir::Value *Pointer, mlir::Type *ElementType, CharUnits Alignment, |
205 | | - KnownNonNull_t IsKnownNonNull = NotKnownNonNull) |
206 | | - : PointerAndKnownNonNull(Pointer, IsKnownNonNull), |
207 | | - ElementType(ElementType), Alignment(Alignment) { |
208 | | - assert(Pointer != nullptr && "Pointer cannot be null"); |
209 | | - assert(ElementType != nullptr && "Element type cannot be null"); |
210 | | - } |
211 | | - |
212 | | - inline RawAddress(Address Addr); |
213 | | - |
214 | | - static RawAddress invalid() { return RawAddress(nullptr); } |
215 | | - bool isValid() const { |
216 | | - return PointerAndKnownNonNull.getPointer() != nullptr; |
217 | | - } |
218 | | - |
219 | | - mlir::Value *getPointer() const { |
220 | | - assert(isValid()); |
221 | | - return PointerAndKnownNonNull.getPointer(); |
222 | | - } |
223 | | - |
224 | | - /// Return the type of the pointer value. |
225 | | - llvm::PointerType *getType() const { |
226 | | - return llvm::cast<llvm::PointerType>(getPointer()->getType()); |
227 | | - } |
228 | | - |
229 | | - /// Return the type of the values stored in this address. |
230 | | - mlir::Type *getElementType() const { |
231 | | - assert(isValid()); |
232 | | - return ElementType; |
233 | | - } |
234 | | - |
235 | | - /// Return the address space that this address resides in. |
236 | | - unsigned getAddressSpace() const { return getType()->getAddressSpace(); } |
237 | | - |
238 | | - /// Return the IR name of the pointer value. |
239 | | - llvm::StringRef getName() const { return getPointer()->getName(); } |
240 | | - |
241 | | - /// Return the alignment of this pointer. |
242 | | - CharUnits getAlignment() const { |
243 | | - assert(isValid()); |
244 | | - return Alignment; |
245 | | - } |
246 | | - |
247 | | - /// Return address with different element type, but same pointer and |
248 | | - /// alignment. |
249 | | - RawAddress withElementType(mlir::Type *ElemTy) const { |
250 | | - return RawAddress(getPointer(), ElemTy, getAlignment(), isKnownNonNull()); |
251 | | - } |
252 | | - |
253 | | - KnownNonNull_t isKnownNonNull() const { |
254 | | - assert(isValid()); |
255 | | - return (KnownNonNull_t)PointerAndKnownNonNull.getInt(); |
256 | | - } |
257 | | -}; |
258 | | - |
259 | 189 | } // namespace clang::CIRGen |
260 | 190 |
|
261 | 191 | #endif // LLVM_CLANG_LIB_CIR_ADDRESS_H |
0 commit comments