Recommit r373598 "[yaml2obj/obj2yaml] - Add support for SHT_LLVM_ADDRSIG sections."
[llvm-complete.git] / lib / Support / LowLevelType.cpp
blobfe77cb3db4139a6e8f26120698f1204ae3c31086
1 //===-- llvm/Support/LowLevelType.cpp -------------------------------------===//
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 /// \file This file implements the more header-heavy bits of the LLT class to
10 /// avoid polluting users' namespaces.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Support/LowLevelTypeImpl.h"
15 #include "llvm/Support/raw_ostream.h"
16 using namespace llvm;
18 LLT::LLT(MVT VT) {
19 if (VT.isVector()) {
20 init(/*IsPointer=*/false, VT.getVectorNumElements() > 1,
21 VT.getVectorNumElements(), VT.getVectorElementType().getSizeInBits(),
22 /*AddressSpace=*/0);
23 } else if (VT.isValid()) {
24 // Aggregates are no different from real scalars as far as GlobalISel is
25 // concerned.
26 assert(VT.getSizeInBits() != 0 && "invalid zero-sized type");
27 init(/*IsPointer=*/false, /*IsVector=*/false, /*NumElements=*/0,
28 VT.getSizeInBits(), /*AddressSpace=*/0);
29 } else {
30 IsPointer = false;
31 IsVector = false;
32 RawData = 0;
36 void LLT::print(raw_ostream &OS) const {
37 if (isVector())
38 OS << "<" << getNumElements() << " x " << getElementType() << ">";
39 else if (isPointer())
40 OS << "p" << getAddressSpace();
41 else if (isValid()) {
42 assert(isScalar() && "unexpected type");
43 OS << "s" << getScalarSizeInBits();
44 } else
45 OS << "LLT_invalid";
48 const constexpr LLT::BitFieldInfo LLT::ScalarSizeFieldInfo;
49 const constexpr LLT::BitFieldInfo LLT::PointerSizeFieldInfo;
50 const constexpr LLT::BitFieldInfo LLT::PointerAddressSpaceFieldInfo;
51 const constexpr LLT::BitFieldInfo LLT::VectorElementsFieldInfo;
52 const constexpr LLT::BitFieldInfo LLT::VectorSizeFieldInfo;
53 const constexpr LLT::BitFieldInfo LLT::PointerVectorElementsFieldInfo;
54 const constexpr LLT::BitFieldInfo LLT::PointerVectorSizeFieldInfo;
55 const constexpr LLT::BitFieldInfo LLT::PointerVectorAddressSpaceFieldInfo;