LowLevelType.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. #include "llvm/CodeGen/LowLevelType.h"
  14. #include "llvm/IR/DataLayout.h"
  15. #include "llvm/IR/DerivedTypes.h"
  16. #include "llvm/Support/raw_ostream.h"
  17. using namespace llvm;
  18. LLT llvm::getLLTForType(Type &Ty, const DataLayout &DL) {
  19. if (auto VTy = dyn_cast<VectorType>(&Ty)) {
  20. auto NumElements = VTy->getNumElements();
  21. LLT ScalarTy = getLLTForType(*VTy->getElementType(), DL);
  22. if (NumElements == 1)
  23. return ScalarTy;
  24. return LLT::vector(NumElements, ScalarTy);
  25. } else if (auto PTy = dyn_cast<PointerType>(&Ty)) {
  26. return LLT::pointer(PTy->getAddressSpace(), DL.getTypeSizeInBits(&Ty));
  27. } else if (Ty.isSized()) {
  28. // Aggregates are no different from real scalars as far as GlobalISel is
  29. // concerned.
  30. auto SizeInBits = DL.getTypeSizeInBits(&Ty);
  31. assert(SizeInBits != 0 && "invalid zero-sized type");
  32. return LLT::scalar(SizeInBits);
  33. }
  34. return LLT();
  35. }