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     ScalarSize = VTy->getElementType()->getPrimitiveSizeInBits();
23     NumElements = VTy->getNumElements();
24     Kind = NumElements == 1 ? Scalar : Vector;
25   } else if (Ty.isSized()) {
26     // Aggregates are no different from real scalars as far as GlobalISel is
27     // concerned.
28     Kind = Scalar;
29     ScalarSize = Ty.getPrimitiveSizeInBits();
30     NumElements = 1;
31   } else {
32     Kind = Unsized;
33     ScalarSize = NumElements = 0;
34   }
35 }
36 
37 void LLT::print(raw_ostream &OS) const {
38   if (isVector())
39     OS << "<" << NumElements << " x s" << ScalarSize << ">";
40   else if (isSized())
41     OS << "s" << ScalarSize;
42   else if (isValid())
43     OS << "unsized";
44   else
45     llvm_unreachable("trying to print an invalid type");
46 }
47