1 //===-- llvm/CodeGen/LowLevelType.cpp -------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 /// \file This file implements the more header-heavy bits of the LLT class to
10 /// avoid polluting users' namespaces.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/LowLevelType.h"
15 #include "llvm/IR/DataLayout.h"
16 #include "llvm/IR/DerivedTypes.h"
17 #include "llvm/Support/raw_ostream.h"
20 LLT
llvm::getLLTForType(Type
&Ty
, const DataLayout
&DL
) {
21 if (auto VTy
= dyn_cast
<VectorType
>(&Ty
)) {
22 auto NumElements
= VTy
->getNumElements();
23 LLT ScalarTy
= getLLTForType(*VTy
->getElementType(), DL
);
26 return LLT::vector(NumElements
, ScalarTy
);
27 } else if (auto PTy
= dyn_cast
<PointerType
>(&Ty
)) {
28 return LLT::pointer(PTy
->getAddressSpace(), DL
.getTypeSizeInBits(&Ty
));
29 } else if (Ty
.isSized()) {
30 // Aggregates are no different from real scalars as far as GlobalISel is
32 auto SizeInBits
= DL
.getTypeSizeInBits(&Ty
);
33 assert(SizeInBits
!= 0 && "invalid zero-sized type");
34 return LLT::scalar(SizeInBits
);