1 //===-- llvm/CodeGen/GlobalISel/LowLevelType.cpp --------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 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/CodeGen/LowLevelType.h" 16 #include "llvm/IR/DerivedTypes.h" 17 #include "llvm/Support/raw_ostream.h" 18 using namespace llvm; 19 20 LLT::LLT(const Type &Ty) { 21 if (auto VTy = dyn_cast<VectorType>(&Ty)) { 22 SizeOrAddrSpace = VTy->getElementType()->getPrimitiveSizeInBits(); 23 NumElements = VTy->getNumElements(); 24 Kind = NumElements == 1 ? Scalar : Vector; 25 } else if (auto PTy = dyn_cast<PointerType>(&Ty)) { 26 Kind = Pointer; 27 SizeOrAddrSpace = PTy->getAddressSpace(); 28 NumElements = 1; 29 } else if (Ty.isSized()) { 30 // Aggregates are no different from real scalars as far as GlobalISel is 31 // concerned. 32 Kind = Scalar; 33 SizeOrAddrSpace = Ty.getPrimitiveSizeInBits(); 34 NumElements = 1; 35 } else { 36 Kind = Unsized; 37 SizeOrAddrSpace = NumElements = 0; 38 } 39 } 40 41 void LLT::print(raw_ostream &OS) const { 42 if (isVector()) 43 OS << "<" << NumElements << " x s" << SizeOrAddrSpace << ">"; 44 else if (isPointer()) 45 OS << "p" << getAddressSpace(); 46 else if (isSized()) 47 OS << "s" << getScalarSizeInBits(); 48 else if (isValid()) 49 OS << "unsized"; 50 else 51 llvm_unreachable("trying to print an invalid type"); 52 } 53