llvm-project
67 строк · 2.5 Кб
1//===-- llvm/CodeGenTypes/LowLevelType.cpp
2//---------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9//
10/// \file This file implements the more header-heavy bits of the LLT class to
11/// avoid polluting users' namespaces.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/CodeGenTypes/LowLevelType.h"16#include "llvm/Support/raw_ostream.h"17using namespace llvm;18
19LLT::LLT(MVT VT) {20if (VT.isVector()) {21bool asVector = VT.getVectorMinNumElements() > 1 || VT.isScalableVector();22init(/*IsPointer=*/false, asVector, /*IsScalar=*/!asVector,23VT.getVectorElementCount(), VT.getVectorElementType().getSizeInBits(),24/*AddressSpace=*/0);25} else if (VT.isValid() && !VT.isScalableTargetExtVT()) {26// Aggregates are no different from real scalars as far as GlobalISel is27// concerned.28init(/*IsPointer=*/false, /*IsVector=*/false, /*IsScalar=*/true,29ElementCount::getFixed(0), VT.getSizeInBits(), /*AddressSpace=*/0);30} else {31IsScalar = false;32IsPointer = false;33IsVector = false;34RawData = 0;35}36}
37
38void LLT::print(raw_ostream &OS) const {39if (isVector()) {40OS << "<";41OS << getElementCount() << " x " << getElementType() << ">";42} else if (isPointer())43OS << "p" << getAddressSpace();44else if (isValid()) {45assert(isScalar() && "unexpected type");46OS << "s" << getScalarSizeInBits();47} else48OS << "LLT_invalid";49}
50
51#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)52LLVM_DUMP_METHOD void LLT::dump() const {53print(dbgs());54dbgs() << '\n';55}
56#endif57
58const constexpr LLT::BitFieldInfo LLT::ScalarSizeFieldInfo;59const constexpr LLT::BitFieldInfo LLT::PointerSizeFieldInfo;60const constexpr LLT::BitFieldInfo LLT::PointerAddressSpaceFieldInfo;61const constexpr LLT::BitFieldInfo LLT::VectorElementsFieldInfo;62const constexpr LLT::BitFieldInfo LLT::VectorScalableFieldInfo;63const constexpr LLT::BitFieldInfo LLT::VectorSizeFieldInfo;64const constexpr LLT::BitFieldInfo LLT::PointerVectorElementsFieldInfo;65const constexpr LLT::BitFieldInfo LLT::PointerVectorScalableFieldInfo;66const constexpr LLT::BitFieldInfo LLT::PointerVectorSizeFieldInfo;67const constexpr LLT::BitFieldInfo LLT::PointerVectorAddressSpaceFieldInfo;68