summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/AsmWriter.cpp5
-rw-r--r--llvm/lib/IR/LLVMContextImpl.h2
-rw-r--r--llvm/lib/IR/Type.cpp13
-rw-r--r--llvm/lib/IR/Verifier.cpp35
4 files changed, 46 insertions, 9 deletions
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index ca7afd0d81a..402a1bd9df5 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -620,7 +620,10 @@ void TypePrinting::print(Type *Ty, raw_ostream &OS) {
}
case Type::VectorTyID: {
VectorType *PTy = cast<VectorType>(Ty);
- OS << "<" << PTy->getNumElements() << " x ";
+ OS << "<";
+ if (PTy->isScalable())
+ OS << "vscale x ";
+ OS << PTy->getNumElements() << " x ";
print(PTy->getElementType(), OS);
OS << '>';
return;
diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h
index 4560617624e..78cf707e0e7 100644
--- a/llvm/lib/IR/LLVMContextImpl.h
+++ b/llvm/lib/IR/LLVMContextImpl.h
@@ -1334,7 +1334,7 @@ public:
unsigned NamedStructTypesUniqueID = 0;
DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes;
- DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes;
+ DenseMap<std::pair<Type *, ElementCount>, VectorType*> VectorTypes;
DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0
DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes;
diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 4016bb10ba3..3d53134ca6d 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -599,21 +599,20 @@ bool ArrayType::isValidElementType(Type *ElemTy) {
// VectorType Implementation
//===----------------------------------------------------------------------===//
-VectorType::VectorType(Type *ElType, unsigned NumEl)
- : SequentialType(VectorTyID, ElType, NumEl) {}
+VectorType::VectorType(Type *ElType, ElementCount EC)
+ : SequentialType(VectorTyID, ElType, EC.Min), Scalable(EC.Scalable) {}
-VectorType *VectorType::get(Type *ElementType, unsigned NumElements) {
- assert(NumElements > 0 && "#Elements of a VectorType must be greater than 0");
+VectorType *VectorType::get(Type *ElementType, ElementCount EC) {
+ assert(EC.Min > 0 && "#Elements of a VectorType must be greater than 0");
assert(isValidElementType(ElementType) && "Element type of a VectorType must "
"be an integer, floating point, or "
"pointer type.");
LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
VectorType *&Entry = ElementType->getContext().pImpl
- ->VectorTypes[std::make_pair(ElementType, NumElements)];
-
+ ->VectorTypes[std::make_pair(ElementType, EC)];
if (!Entry)
- Entry = new (pImpl->Alloc) VectorType(ElementType, NumElements);
+ Entry = new (pImpl->Alloc) VectorType(ElementType, EC);
return Entry;
}
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 7369aa88abe..10bac6df3a5 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -43,6 +43,7 @@
//
//===----------------------------------------------------------------------===//
+#include "LLVMContextImpl.h"
#include "llvm/IR/Verifier.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
@@ -318,6 +319,31 @@ public:
bool hasBrokenDebugInfo() const { return BrokenDebugInfo; }
+ void verifyTypes() {
+ LLVMContext &Ctx = M.getContext();
+ for (auto &Entry : Ctx.pImpl->ArrayTypes) {
+ Type *EltTy = Entry.second->getElementType();
+ if (auto *VTy = dyn_cast<VectorType>(EltTy))
+ if (VTy->isScalable())
+ CheckFailed("Arrays cannot contain scalable vectors",
+ Entry.second, &M);
+ }
+
+ for (StructType* STy : Ctx.pImpl->AnonStructTypes)
+ for (Type *EltTy : STy->elements())
+ if (auto *VTy = dyn_cast<VectorType>(EltTy))
+ if (VTy->isScalable())
+ CheckFailed("Structs cannot contain scalable vectors", STy, &M);
+
+ for (auto &Entry : Ctx.pImpl->NamedStructTypes) {
+ StructType *STy = Entry.second;
+ for (Type *EltTy : STy->elements())
+ if (auto *VTy = dyn_cast<VectorType>(EltTy))
+ if (VTy->isScalable())
+ CheckFailed("Structs cannot contain scalable vectors", STy, &M);
+ }
+ }
+
bool verify(const Function &F) {
assert(F.getParent() == &M &&
"An instance of this class only works with a specific module!");
@@ -387,6 +413,8 @@ public:
verifyCompileUnits();
+ verifyTypes();
+
verifyDeoptimizeCallingConvs();
DISubprogramAttachments.clear();
return !Broken;
@@ -691,6 +719,13 @@ void Verifier::visitGlobalVariable(const GlobalVariable &GV) {
"DIGlobalVariableExpression");
}
+ // Scalable vectors cannot be global variables, since we don't know
+ // the runtime size. If the global is a struct or an array containing
+ // scalable vectors, that will be caught be verifyTypes instead.
+ if (auto *VTy = dyn_cast<VectorType>(GV.getValueType()))
+ if (VTy->isScalable())
+ CheckFailed("Globals cannot contain scalable vectors", &GV);
+
if (!GV.hasInitializer()) {
visitGlobalValue(GV);
return;
OpenPOWER on IntegriCloud