xref: /freebsd/contrib/llvm-project/llvm/lib/Support/DynamicAPInt.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
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 
hash_value(const DynamicAPInt & X)15 hash_code llvm::hash_value(const DynamicAPInt &X) {
16   if (X.isSmall())
17     return llvm::hash_value(X.getSmall());
18   return detail::hash_value(X.getLarge());
19 }
20 
static_assert_layout()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 
print(raw_ostream & OS) const29 raw_ostream &DynamicAPInt::print(raw_ostream &OS) const {
30   if (isSmall())
31     return OS << ValSmall;
32   return OS << ValLarge;
33 }
34 
dump() const35 void DynamicAPInt::dump() const { print(dbgs()); }
36