LowLevelType.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/Support/LowLevelTypeImpl.h"
  14. #include "llvm/Support/raw_ostream.h"
  15. using namespace llvm;
  16. LLT::LLT(MVT VT) {
  17. if (VT.isVector()) {
  18. init(/*IsPointer=*/false, VT.getVectorNumElements() > 1,
  19. VT.getVectorNumElements(), VT.getVectorElementType().getSizeInBits(),
  20. /*AddressSpace=*/0);
  21. } else if (VT.isValid()) {
  22. // Aggregates are no different from real scalars as far as GlobalISel is
  23. // concerned.
  24. assert(VT.getSizeInBits() != 0 && "invalid zero-sized type");
  25. init(/*IsPointer=*/false, /*IsVector=*/false, /*NumElements=*/0,
  26. VT.getSizeInBits(), /*AddressSpace=*/0);
  27. } else {
  28. IsPointer = false;
  29. IsVector = false;
  30. RawData = 0;
  31. }
  32. }
  33. void LLT::print(raw_ostream &OS) const {
  34. if (isVector())
  35. OS << "<" << getNumElements() << " x " << getElementType() << ">";
  36. else if (isPointer())
  37. OS << "p" << getAddressSpace();
  38. else if (isValid()) {
  39. assert(isScalar() && "unexpected type");
  40. OS << "s" << getScalarSizeInBits();
  41. } else
  42. OS << "LLT_invalid";
  43. }
  44. const constexpr LLT::BitFieldInfo LLT::ScalarSizeFieldInfo;
  45. const constexpr LLT::BitFieldInfo LLT::PointerSizeFieldInfo;
  46. const constexpr LLT::BitFieldInfo LLT::PointerAddressSpaceFieldInfo;
  47. const constexpr LLT::BitFieldInfo LLT::VectorElementsFieldInfo;
  48. const constexpr LLT::BitFieldInfo LLT::VectorSizeFieldInfo;
  49. const constexpr LLT::BitFieldInfo LLT::PointerVectorElementsFieldInfo;
  50. const constexpr LLT::BitFieldInfo LLT::PointerVectorSizeFieldInfo;
  51. const constexpr LLT::BitFieldInfo LLT::PointerVectorAddressSpaceFieldInfo;