]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/lib/CodeGen/LowLevelType.cpp
Move all sources from the llvm project into contrib/llvm-project.
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / lib / CodeGen / LowLevelType.cpp
1 //===-- llvm/CodeGen/LowLevelType.cpp -------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 /// \file This file implements the more header-heavy bits of the LLT class to
10 /// avoid polluting users' namespaces.
11 //
12 //===----------------------------------------------------------------------===//
13
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"
18 using namespace llvm;
19
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);
24     if (NumElements == 1)
25       return ScalarTy;
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
31     // concerned.
32     auto SizeInBits = DL.getTypeSizeInBits(&Ty);
33     assert(SizeInBits != 0 && "invalid zero-sized type");
34     return LLT::scalar(SizeInBits);
35   }
36   return LLT();
37 }