LLVM  8.0.1
LowLevelType.cpp
Go to the documentation of this file.
1 //===-- llvm/CodeGen/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 
16 #include "llvm/IR/DataLayout.h"
17 #include "llvm/IR/DerivedTypes.h"
19 using namespace llvm;
20 
22  if (auto VTy = dyn_cast<VectorType>(&Ty)) {
23  auto NumElements = VTy->getNumElements();
24  LLT ScalarTy = getLLTForType(*VTy->getElementType(), DL);
25  if (NumElements == 1)
26  return ScalarTy;
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
32  // concerned.
33  auto SizeInBits = DL.getTypeSizeInBits(&Ty);
34  assert(SizeInBits != 0 && "invalid zero-sized type");
35  return LLT::scalar(SizeInBits);
36  }
37  return LLT();
38 }
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
This class represents lattice values for constants.
Definition: AllocatorList.h:24
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:265
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.
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
Definition: DataLayout.h:568
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static LLT pointer(uint16_t AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space (defaulting to 0).
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.