LLVM  12.0.0git
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 //===----------------------------------------------------------------------===//
15 #include "llvm/IR/DataLayout.h"
16 #include "llvm/IR/DerivedTypes.h"
18 using namespace llvm;
21  if (auto VTy = dyn_cast<VectorType>(&Ty)) {
22  auto NumElements = cast<FixedVectorType>(VTy)->getNumElements();
23  LLT ScalarTy = getLLTForType(*VTy->getElementType(), DL);
24  if (NumElements == 1)
25  return ScalarTy;
26  return LLT::vector(NumElements, ScalarTy);
27  }
29  if (auto PTy = dyn_cast<PointerType>(&Ty)) {
30  unsigned AddrSpace = PTy->getAddressSpace();
31  return LLT::pointer(AddrSpace, DL.getPointerSizeInBits(AddrSpace));
32  }
34  if (Ty.isSized()) {
35  // Aggregates are no different from real scalars as far as GlobalISel is
36  // concerned.
37  auto SizeInBits = DL.getTypeSizeInBits(&Ty);
38  assert(SizeInBits != 0 && "invalid zero-sized type");
39  return LLT::scalar(SizeInBits);
40  }
42  return LLT();
43 }
46  if (!Ty.isVector())
47  return MVT::getIntegerVT(Ty.getSizeInBits());
49  return MVT::getVectorVT(
51  Ty.getNumElements());
52 }
55  if (!Ty.isVector())
56  return LLT::scalar(Ty.getSizeInBits());
60 }
static MVT getIntegerVT(unsigned BitWidth)
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
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
static MVT getVectorVT(MVT VT, unsigned NumElements)
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:268
bool isVector() const
Return true if this is a vector value type.
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
unsigned getVectorNumElements() const
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
Definition: DataLayout.h:396
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Definition: DataLayout.h:652
bool isVector() const
LLT getElementType() const
Returns the vector&#39;s element type. Only valid for vector types.
static LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
MVT getVectorElementType() const
Get a rough equivalent of an MVT for a given LLT.
Machine Value Type.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
Get a rough equivalent of an LLT for a given MVT.
LLT getLLTForType(Type &Ty, const DataLayout &DL)
Construct a low-level type based on an LLVM type.
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
static Value * getNumElements(BasicBlock *Preheader, Value *BTC)
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.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL