1 //===-- llvm/CodeGen/LowLevelType.cpp -------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// \file This file implements the more header-heavy bits of the LLT class to
11 /// avoid polluting users' namespaces.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/CodeGen/LowLevelType.h"
16 #include "llvm/IR/DataLayout.h"
17 #include "llvm/IR/DerivedTypes.h"
18 #include "llvm/Support/raw_ostream.h"
21 LLT llvm::getLLTForType(Type &Ty, const DataLayout &DL) {
22 if (auto VTy = dyn_cast<VectorType>(&Ty)) {
23 auto NumElements = VTy->getNumElements();
24 LLT ScalarTy = getLLTForType(*VTy->getElementType(), DL);
27 return LLT::vector(NumElements, ScalarTy);
28 } else if (auto PTy = dyn_cast<PointerType>(&Ty)) {
29 return LLT::pointer(PTy->getAddressSpace(), DL.getTypeSizeInBits(&Ty));
30 } else if (Ty.isSized()) {
31 // Aggregates are no different from real scalars as far as GlobalISel is
33 auto SizeInBits = DL.getTypeSizeInBits(&Ty);
34 assert(SizeInBits != 0 && "invalid zero-sized type");
35 return LLT::scalar(SizeInBits);