LLVM  13.0.0git
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/ADT/APFloat.h"
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 = cast<FixedVectorType>(VTy)->getNumElements();
24  LLT ScalarTy = getLLTForType(*VTy->getElementType(), DL);
25  if (NumElements == 1)
26  return ScalarTy;
27  return LLT::vector(NumElements, ScalarTy);
28  }
29 
30  if (auto PTy = dyn_cast<PointerType>(&Ty)) {
31  unsigned AddrSpace = PTy->getAddressSpace();
32  return LLT::pointer(AddrSpace, DL.getPointerSizeInBits(AddrSpace));
33  }
34 
35  if (Ty.isSized()) {
36  // Aggregates are no different from real scalars as far as GlobalISel is
37  // concerned.
38  auto SizeInBits = DL.getTypeSizeInBits(&Ty);
39  assert(SizeInBits != 0 && "invalid zero-sized type");
40  return LLT::scalar(SizeInBits);
41  }
42 
43  return LLT();
44 }
45 
47  if (!Ty.isVector())
48  return MVT::getIntegerVT(Ty.getSizeInBits());
49 
50  return MVT::getVectorVT(
52  Ty.getNumElements());
53 }
54 
56  if (!Ty.isVector())
57  return LLT::scalar(Ty.getSizeInBits());
58 
61 }
62 
64  assert(Ty.isScalar() && "Expected a scalar type.");
65  switch (Ty.getSizeInBits()) {
66  case 16:
67  return APFloat::IEEEhalf();
68  case 32:
69  return APFloat::IEEEsingle();
70  case 64:
71  return APFloat::IEEEdouble();
72  case 128:
73  return APFloat::IEEEquad();
74  }
75  llvm_unreachable("Invalid FP type size.");
76 }
llvm::Type::isSized
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:272
llvm::MVT::getVectorElementType
MVT getVectorElementType() const
Definition: MachineValueType.h:499
LowLevelType.h
llvm
Definition: AllocatorList.h:23
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:112
llvm::APFloatBase::IEEEsingle
static const fltSemantics & IEEEsingle() LLVM_READNONE
Definition: APFloat.cpp:163
llvm::MVT::isVector
bool isVector() const
Return true if this is a vector value type.
Definition: MachineValueType.h:347
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
llvm::APFloatBase::IEEEquad
static const fltSemantics & IEEEquad() LLVM_READNONE
Definition: APFloat.cpp:169
llvm::getFltSemanticForLLT
const llvm::fltSemantics & getFltSemanticForLLT(LLT Ty)
Get the appropriate floating point arithmetic semantic based on the bit size of the given scalar LLT.
Definition: LowLevelType.cpp:63
llvm::getLLTForType
LLT getLLTForType(Type &Ty, const DataLayout &DL)
Construct a low-level type based on an LLVM type.
Definition: LowLevelType.cpp:21
llvm::APFloatBase::IEEEhalf
static const fltSemantics & IEEEhalf() LLVM_READNONE
Definition: APFloat.cpp:157
llvm::LLT::getSizeInBits
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
Definition: LowLevelTypeImpl.h:109
llvm::getLLTForMVT
LLT getLLTForMVT(MVT Ty)
Get a rough equivalent of an LLT for a given MVT.
Definition: LowLevelType.cpp:55
APFloat.h
This file declares a class to represent arbitrary precision floating point values and provide a varie...
llvm::LLT::vector
static LLT vector(uint16_t NumElements, unsigned ScalarSizeInBits)
Get a low-level vector of some number of elements and element width.
Definition: LowLevelTypeImpl.h:58
llvm::LLT::pointer
static LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
Definition: LowLevelTypeImpl.h:50
llvm::LLT::isVector
bool isVector() const
Definition: LowLevelTypeImpl.h:96
llvm::LLT::getNumElements
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
Definition: LowLevelTypeImpl.h:100
llvm::MVT::getVectorNumElements
unsigned getVectorNumElements() const
Definition: MachineValueType.h:650
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MVT::getSizeInBits
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
Definition: MachineValueType.h:815
llvm::MVT
Machine Value Type.
Definition: MachineValueType.h:30
llvm::LLT::isScalar
bool isScalar() const
Definition: LowLevelTypeImpl.h:92
llvm::MVT::getVectorVT
static MVT getVectorVT(MVT VT, unsigned NumElements)
Definition: MachineValueType.h:1119
DataLayout.h
llvm::APFloatBase::IEEEdouble
static const fltSemantics & IEEEdouble() LLVM_READNONE
Definition: APFloat.cpp:166
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::fltSemantics
Definition: APFloat.cpp:54
llvm::getMVTForLLT
MVT getMVTForLLT(LLT Ty)
Get a rough equivalent of an MVT for a given LLT.
Definition: LowLevelType.cpp:46
DerivedTypes.h
llvm::LLT::getElementType
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
Definition: LowLevelTypeImpl.h:188
raw_ostream.h
llvm::LLT::scalar
static LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
Definition: LowLevelTypeImpl.h:43
llvm::MVT::getIntegerVT
static MVT getIntegerVT(unsigned BitWidth)
Definition: MachineValueType.h:1100
llvm::LLT
Definition: LowLevelTypeImpl.h:40