| 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" |
| 17 | using namespace llvm; |
| 18 | |
| 19 | bool LLT::ExtendedLLT = false; |
| 20 | |
| 21 | static LLT::FpSemantics getFpSemanticsForMVT(MVT VT) { |
| 22 | switch (VT.getScalarType().SimpleTy) { |
| 23 | default: |
| 24 | llvm_unreachable("Unknown FP format" ); |
| 25 | case MVT::f16: |
| 26 | return LLT::FpSemantics::S_IEEEhalf; |
| 27 | case MVT::bf16: |
| 28 | return LLT::FpSemantics::S_BFloat; |
| 29 | case MVT::f32: |
| 30 | return LLT::FpSemantics::S_IEEEsingle; |
| 31 | case MVT::f64: |
| 32 | return LLT::FpSemantics::S_IEEEdouble; |
| 33 | case MVT::f80: |
| 34 | return LLT::FpSemantics::S_x87DoubleExtended; |
| 35 | case MVT::f128: |
| 36 | return LLT::FpSemantics::S_IEEEquad; |
| 37 | case MVT::ppcf128: |
| 38 | return LLT::FpSemantics::S_PPCDoubleDouble; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | LLT::LLT(MVT VT) { |
| 43 | if (!ExtendedLLT) { |
| 44 | if (VT.isVector()) { |
| 45 | bool AsVector = VT.getVectorMinNumElements() > 1 || VT.isScalableVector(); |
| 46 | Kind Info = AsVector ? Kind::VECTOR_ANY : Kind::ANY_SCALAR; |
| 47 | init(Info, EC: VT.getVectorElementCount(), |
| 48 | SizeInBits: VT.getVectorElementType().getSizeInBits()); |
| 49 | } else if (VT.isValid() && !VT.isScalableTargetExtVT()) { |
| 50 | init(Info: Kind::ANY_SCALAR, EC: ElementCount::getFixed(MinVal: 0), SizeInBits: VT.getSizeInBits()); |
| 51 | } else { |
| 52 | this->Info = Kind::INVALID; |
| 53 | this->RawData = 0; |
| 54 | } |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | bool IsFloatingPoint = VT.isFloatingPoint(); |
| 59 | bool AsVector = VT.isVector() && |
| 60 | (VT.getVectorMinNumElements() > 1 || VT.isScalableVector()); |
| 61 | |
| 62 | if (AsVector) { |
| 63 | if (IsFloatingPoint) |
| 64 | init(Info: LLT::Kind::VECTOR_FLOAT, EC: VT.getVectorElementCount(), |
| 65 | SizeInBits: VT.getVectorElementType().getSizeInBits(), Sem: getFpSemanticsForMVT(VT)); |
| 66 | else |
| 67 | init(Info: LLT::Kind::VECTOR_INTEGER, EC: VT.getVectorElementCount(), |
| 68 | SizeInBits: VT.getVectorElementType().getSizeInBits()); |
| 69 | } else if (VT.isValid() && !VT.isScalableTargetExtVT()) { |
| 70 | // Aggregates are no different from real scalars as far as GlobalISel is |
| 71 | // concerned. |
| 72 | if (IsFloatingPoint) |
| 73 | init(Info: LLT::Kind::FLOAT, EC: ElementCount::getFixed(MinVal: 0), SizeInBits: VT.getSizeInBits(), |
| 74 | Sem: getFpSemanticsForMVT(VT)); |
| 75 | else |
| 76 | init(Info: LLT::Kind::INTEGER, EC: ElementCount::getFixed(MinVal: 0), SizeInBits: VT.getSizeInBits()); |
| 77 | } else { |
| 78 | this->Info = Kind::INVALID; |
| 79 | this->RawData = 0; |
| 80 | } |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | void LLT::print(raw_ostream &OS) const { |
| 85 | if (isVector()) { |
| 86 | OS << "<" ; |
| 87 | OS << getElementCount() << " x " << getElementType() << ">" ; |
| 88 | } else if (isPointer()) { |
| 89 | OS << "p" << getAddressSpace(); |
| 90 | } else if (isBFloat16()) { |
| 91 | OS << "bf16" ; |
| 92 | } else if (isPPCF128()) { |
| 93 | OS << "ppcf128" ; |
| 94 | } else if (isFloatIEEE()) { |
| 95 | OS << "f" << getScalarSizeInBits(); |
| 96 | } else if (isInteger()) { |
| 97 | OS << "i" << getScalarSizeInBits(); |
| 98 | } else if (isValid()) { |
| 99 | assert(isScalar() && "unexpected type" ); |
| 100 | OS << "s" << getScalarSizeInBits(); |
| 101 | } else { |
| 102 | OS << "LLT_invalid" ; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
| 107 | LLVM_DUMP_METHOD void LLT::dump() const { |
| 108 | print(dbgs()); |
| 109 | dbgs() << '\n'; |
| 110 | } |
| 111 | #endif |
| 112 | |