LLVM  10.0.0svn
LowLevelType.cpp
Go to the documentation of this file.
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 
15 #include "llvm/IR/DataLayout.h"
16 #include "llvm/IR/DerivedTypes.h"
18 using namespace llvm;
19 
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 }
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:112
static LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:265
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Definition: DataLayout.h:618
static LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
LLT getLLTForType(Type &Ty, const DataLayout &DL)
Construct a low-level type based on an LLVM type.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
static LLT vector(uint16_t NumElements, unsigned ScalarSizeInBits)
Get a low-level vector of some number of elements and element width.