Chromium Code Reviews| Index: src/llvm2ice.cpp |
| diff --git a/src/llvm2ice.cpp b/src/llvm2ice.cpp |
| index c3a98dfed6b2d13a06f6dbeeb054d700990864ab..7b2344924883e62c176f5e65ce68dbb1ed3093ed 100644 |
| --- a/src/llvm2ice.cpp |
| +++ b/src/llvm2ice.cpp |
| @@ -119,6 +119,35 @@ public: |
| return NULL; |
| } else if (const UndefValue *CU = dyn_cast<UndefValue>(Const)) { |
| return Ctx->getConstantUndef(convertType(CU->getType())); |
| + } else if (const ConstantDataVector *CDV = |
| + dyn_cast<ConstantDataVector>(Const)) { |
| + // This case will never be encountered when processing valid PNaCl |
| + // IR. Constants of vector type (except for undef) do not appear |
| + // in PNaCl IR. |
|
JF
2014/06/30 17:48:50
Why handle these if they never occur, instead of a
wala
2014/06/30 22:13:24
This was useful to me to test parts of my implemen
|
| + 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)) { |
| + // This case will never be encountered when processing valid PNaCl |
| + // IR (see comment above in ConstantDataVector). |
| + 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)) { |
| + // This case will never be encountered when processing valid PNaCl |
| + // IR (see comment above in ConstantDataVector). |
| + return Ctx->getConstantZero(convertType(CZ->getType())); |
| } else { |
| llvm_unreachable("Unhandled constant type"); |
| return NULL; |
| @@ -169,6 +198,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 +249,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)); |