1 | //===- DynamicAPInt.cpp - DynamicAPInt Implementation -----------*- C++ -*-===// |
---|---|
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 | #include "llvm/ADT/DynamicAPInt.h" |
9 | #include "llvm/ADT/Hashing.h" |
10 | #include "llvm/Support/Debug.h" |
11 | #include "llvm/Support/raw_ostream.h" |
12 | |
13 | using namespace llvm; |
14 | |
15 | hash_code llvm::hash_value(const DynamicAPInt &X) { |
16 | if (X.isSmall()) |
17 | return llvm::hash_value(value: X.getSmall()); |
18 | return detail::hash_value(X: X.getLarge()); |
19 | } |
20 | |
21 | void DynamicAPInt::static_assert_layout() { |
22 | constexpr size_t ValLargeOffset = |
23 | offsetof(DynamicAPInt, ValLarge.Val.BitWidth); |
24 | constexpr size_t ValSmallOffset = offsetof(DynamicAPInt, ValSmall); |
25 | constexpr size_t ValSmallSize = sizeof(ValSmall); |
26 | static_assert(ValLargeOffset >= ValSmallOffset + ValSmallSize); |
27 | } |
28 | |
29 | raw_ostream &DynamicAPInt::print(raw_ostream &OS) const { |
30 | if (isSmall()) |
31 | return OS << ValSmall; |
32 | return OS << ValLarge; |
33 | } |
34 | |
35 | void DynamicAPInt::dump() const { print(OS&: dbgs()); } |
36 |