Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Unified Diff: src/llvm2ice.cpp

Issue 353553004: Add support for vector types and vector constants. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: 1) Fix alignment in type table. 2) Add VECT128_BYTES constant. 3) add _movp() function. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/llvm2ice.cpp
diff --git a/src/llvm2ice.cpp b/src/llvm2ice.cpp
index c3a98dfed6b2d13a06f6dbeeb054d700990864ab..e00f9d983a0ae47b7bf142f8ca6a417c33835449 100644
--- a/src/llvm2ice.cpp
+++ b/src/llvm2ice.cpp
@@ -119,6 +119,28 @@ public:
return NULL;
} else if (const UndefValue *CU = dyn_cast<UndefValue>(Const)) {
return Ctx->getConstantUndef(convertType(CU->getType()));
+ } else if (const ConstantDataVector *CDV =
jvoung (off chromium) 2014/06/26 23:33:46 Perhaps we should leave a comment that this block
wala 2014/06/27 21:09:19 Also the next two blocks.
+ dyn_cast<ConstantDataVector>(Const)) {
+ llvm::StringRef Data = CDV->getRawDataValues();
+ assert(Data.size() == Ice::VECT128_BYTES);
+ Ice::Vect128 Value(Ice::VECT128_BYTES);
+ std::memcpy(Value.data(), Data.data(), Ice::VECT128_BYTES);
+ return Ctx->getConstantVector(convertType(CDV->getType()), Value);
+ } else if (const ConstantVector *CV = dyn_cast<ConstantVector>(Const)) {
+ Ice::Type Type = convertType(CV->getType());
+ // Only i1 vectors should be represented as ConstantVectors.
+ assert(Type == Ice::IceType_v4i1 || Type == Ice::IceType_v8i1 ||
+ Type == Ice::IceType_v16i1);
+ unsigned NumElements = typeNumElements(Type);
+ Ice::BitVect Value(NumElements);
+ for (unsigned Elt = 0; Elt != NumElements; ++Elt) {
+ Value[Elt] =
+ cast<ConstantInt>(CV->getAggregateElement(Elt))->getZExtValue();
+ }
+ return Ctx->getConstantBitVector(Type, Value);
+ } else if (const ConstantAggregateZero *CZ =
+ dyn_cast<ConstantAggregateZero>(Const)) {
+ return Ctx->getConstantZero(convertType(CZ->getType()));
} else {
llvm_unreachable("Unhandled constant type");
return NULL;
@@ -169,6 +191,43 @@ private:
}
}
+ Ice::Type convertVectorType(const VectorType *VecTy) const {
+ unsigned NumElements = VecTy->getNumElements();
+ const Type *ElementType = VecTy->getElementType();
+
+ if (ElementType->isFloatTy()) {
+ if (NumElements == 4)
+ return Ice::IceType_v4f32;
+ } else if (ElementType->isIntegerTy()) {
+ switch (cast<IntegerType>(ElementType)->getBitWidth()) {
+ case 1:
+ if (NumElements == 4)
+ return Ice::IceType_v4i1;
+ if (NumElements == 8)
+ return Ice::IceType_v8i1;
+ if (NumElements == 16)
+ return Ice::IceType_v16i1;
+ break;
+ case 8:
+ if (NumElements == 16)
+ return Ice::IceType_v16i8;
+ break;
+ case 16:
+ if (NumElements == 8)
+ return Ice::IceType_v8i16;
+ break;
+ case 32:
+ if (NumElements == 4)
+ return Ice::IceType_v4i32;
+ break;
+ }
+ }
+
+ report_fatal_error(std::string("Unhandled vector type: ") +
+ LLVMObjectAsString(VecTy));
+ return Ice::IceType_void;
+ }
+
Ice::Type convertType(const Type *Ty) const {
switch (Ty->getTypeID()) {
case Type::VoidTyID:
@@ -183,6 +242,8 @@ private:
return SubzeroPointerType;
case Type::FunctionTyID:
return SubzeroPointerType;
+ case Type::VectorTyID:
+ return convertVectorType(cast<VectorType>(Ty));
default:
report_fatal_error(std::string("Invalid PNaCl type: ") +
LLVMObjectAsString(Ty));

Powered by Google App Engine
This is Rietveld 408576698