summaryrefslogtreecommitdiff
path: root/lib/CodeGen/LowLevelType.cpp
diff options
context:
space:
mode:
authorDaniel Sanders <daniel_l_sanders@apple.com>2017-03-07 19:21:23 +0000
committerDaniel Sanders <daniel_l_sanders@apple.com>2017-03-07 19:21:23 +0000
commit428e17c613487f0ef8a1f57c32541f98a4f9e5fa (patch)
tree16572cb3972913da231b378d3f029cdf2fe16e3a /lib/CodeGen/LowLevelType.cpp
parent928a5d4ebaaa634229217cfea0a7b6e2dffe7d5a (diff)
Revert r297177: Change LLT constructor string into an LLT-based object ...
More module problems. This time it only showed up in the stage 2 compile of clang-x86_64-linux-selfhost-modules-2 but not the stage 1 compile. Somehow, this change causes the build to need Attributes.gen before it's been generated. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297188 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/LowLevelType.cpp')
-rw-r--r--lib/CodeGen/LowLevelType.cpp55
1 files changed, 44 insertions, 11 deletions
diff --git a/lib/CodeGen/LowLevelType.cpp b/lib/CodeGen/LowLevelType.cpp
index c4b9068fa90..d74b7306e0f 100644
--- a/lib/CodeGen/LowLevelType.cpp
+++ b/lib/CodeGen/LowLevelType.cpp
@@ -1,4 +1,4 @@
-//===-- llvm/CodeGen/LowLevelType.cpp -------------------------------------===//
+//===-- llvm/CodeGen/GlobalISel/LowLevelType.cpp --------------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -18,21 +18,54 @@
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
-LLT llvm::getLLTForType(Type &Ty, const DataLayout &DL) {
+LLT::LLT(Type &Ty, const DataLayout &DL) {
if (auto VTy = dyn_cast<VectorType>(&Ty)) {
- auto NumElements = VTy->getNumElements();
- auto ScalarSizeInBits = VTy->getElementType()->getPrimitiveSizeInBits();
- if (NumElements == 1)
- return LLT::scalar(ScalarSizeInBits);
- return LLT::vector(NumElements, ScalarSizeInBits);
+ SizeInBits = VTy->getElementType()->getPrimitiveSizeInBits();
+ ElementsOrAddrSpace = VTy->getNumElements();
+ Kind = ElementsOrAddrSpace == 1 ? Scalar : Vector;
} else if (auto PTy = dyn_cast<PointerType>(&Ty)) {
- return LLT::pointer(PTy->getAddressSpace(), DL.getTypeSizeInBits(&Ty));
+ Kind = Pointer;
+ SizeInBits = DL.getTypeSizeInBits(&Ty);
+ ElementsOrAddrSpace = PTy->getAddressSpace();
} else if (Ty.isSized()) {
// Aggregates are no different from real scalars as far as GlobalISel is
// concerned.
- auto SizeInBits = DL.getTypeSizeInBits(&Ty);
+ Kind = Scalar;
+ SizeInBits = DL.getTypeSizeInBits(&Ty);
+ ElementsOrAddrSpace = 1;
assert(SizeInBits != 0 && "invalid zero-sized type");
- return LLT::scalar(SizeInBits);
+ } else {
+ Kind = Invalid;
+ SizeInBits = ElementsOrAddrSpace = 0;
}
- return LLT();
+}
+
+LLT::LLT(MVT VT) {
+ if (VT.isVector()) {
+ SizeInBits = VT.getVectorElementType().getSizeInBits();
+ ElementsOrAddrSpace = VT.getVectorNumElements();
+ Kind = ElementsOrAddrSpace == 1 ? Scalar : Vector;
+ } else if (VT.isValid()) {
+ // Aggregates are no different from real scalars as far as GlobalISel is
+ // concerned.
+ Kind = Scalar;
+ SizeInBits = VT.getSizeInBits();
+ ElementsOrAddrSpace = 1;
+ assert(SizeInBits != 0 && "invalid zero-sized type");
+ } else {
+ Kind = Invalid;
+ SizeInBits = ElementsOrAddrSpace = 0;
+ }
+}
+
+void LLT::print(raw_ostream &OS) const {
+ if (isVector())
+ OS << "<" << ElementsOrAddrSpace << " x s" << SizeInBits << ">";
+ else if (isPointer())
+ OS << "p" << getAddressSpace();
+ else if (isValid()) {
+ assert(isScalar() && "unexpected type");
+ OS << "s" << getScalarSizeInBits();
+ } else
+ llvm_unreachable("trying to print an invalid type");
}