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

Side by Side 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 unified diff | Download patch
OLDNEW
1 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===// 1 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This file defines a driver that uses LLVM capabilities to parse a 10 // This file defines a driver that uses LLVM capabilities to parse a
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(Const)) { 112 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(Const)) {
113 Ice::Type Type = convertType(CFP->getType()); 113 Ice::Type Type = convertType(CFP->getType());
114 if (Type == Ice::IceType_f32) 114 if (Type == Ice::IceType_f32)
115 return Ctx->getConstantFloat(CFP->getValueAPF().convertToFloat()); 115 return Ctx->getConstantFloat(CFP->getValueAPF().convertToFloat());
116 else if (Type == Ice::IceType_f64) 116 else if (Type == Ice::IceType_f64)
117 return Ctx->getConstantDouble(CFP->getValueAPF().convertToDouble()); 117 return Ctx->getConstantDouble(CFP->getValueAPF().convertToDouble());
118 llvm_unreachable("Unexpected floating point type"); 118 llvm_unreachable("Unexpected floating point type");
119 return NULL; 119 return NULL;
120 } else if (const UndefValue *CU = dyn_cast<UndefValue>(Const)) { 120 } else if (const UndefValue *CU = dyn_cast<UndefValue>(Const)) {
121 return Ctx->getConstantUndef(convertType(CU->getType())); 121 return Ctx->getConstantUndef(convertType(CU->getType()));
122 } 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.
123 dyn_cast<ConstantDataVector>(Const)) {
124 llvm::StringRef Data = CDV->getRawDataValues();
125 assert(Data.size() == Ice::VECT128_BYTES);
126 Ice::Vect128 Value(Ice::VECT128_BYTES);
127 std::memcpy(Value.data(), Data.data(), Ice::VECT128_BYTES);
128 return Ctx->getConstantVector(convertType(CDV->getType()), Value);
129 } else if (const ConstantVector *CV = dyn_cast<ConstantVector>(Const)) {
130 Ice::Type Type = convertType(CV->getType());
131 // Only i1 vectors should be represented as ConstantVectors.
132 assert(Type == Ice::IceType_v4i1 || Type == Ice::IceType_v8i1 ||
133 Type == Ice::IceType_v16i1);
134 unsigned NumElements = typeNumElements(Type);
135 Ice::BitVect Value(NumElements);
136 for (unsigned Elt = 0; Elt != NumElements; ++Elt) {
137 Value[Elt] =
138 cast<ConstantInt>(CV->getAggregateElement(Elt))->getZExtValue();
139 }
140 return Ctx->getConstantBitVector(Type, Value);
141 } else if (const ConstantAggregateZero *CZ =
142 dyn_cast<ConstantAggregateZero>(Const)) {
143 return Ctx->getConstantZero(convertType(CZ->getType()));
122 } else { 144 } else {
123 llvm_unreachable("Unhandled constant type"); 145 llvm_unreachable("Unhandled constant type");
124 return NULL; 146 return NULL;
125 } 147 }
126 } 148 }
127 149
128 private: 150 private:
129 // LLVM values (instructions, etc.) are mapped directly to ICE variables. 151 // LLVM values (instructions, etc.) are mapped directly to ICE variables.
130 // mapValueToIceVar has a version that forces an ICE type on the variable, 152 // mapValueToIceVar has a version that forces an ICE type on the variable,
131 // and a version that just uses convertType on V. 153 // and a version that just uses convertType on V.
(...skipping 30 matching lines...) Expand all
162 return Ice::IceType_i32; 184 return Ice::IceType_i32;
163 case 64: 185 case 64:
164 return Ice::IceType_i64; 186 return Ice::IceType_i64;
165 default: 187 default:
166 report_fatal_error(std::string("Invalid PNaCl int type: ") + 188 report_fatal_error(std::string("Invalid PNaCl int type: ") +
167 LLVMObjectAsString(IntTy)); 189 LLVMObjectAsString(IntTy));
168 return Ice::IceType_void; 190 return Ice::IceType_void;
169 } 191 }
170 } 192 }
171 193
194 Ice::Type convertVectorType(const VectorType *VecTy) const {
195 unsigned NumElements = VecTy->getNumElements();
196 const Type *ElementType = VecTy->getElementType();
197
198 if (ElementType->isFloatTy()) {
199 if (NumElements == 4)
200 return Ice::IceType_v4f32;
201 } else if (ElementType->isIntegerTy()) {
202 switch (cast<IntegerType>(ElementType)->getBitWidth()) {
203 case 1:
204 if (NumElements == 4)
205 return Ice::IceType_v4i1;
206 if (NumElements == 8)
207 return Ice::IceType_v8i1;
208 if (NumElements == 16)
209 return Ice::IceType_v16i1;
210 break;
211 case 8:
212 if (NumElements == 16)
213 return Ice::IceType_v16i8;
214 break;
215 case 16:
216 if (NumElements == 8)
217 return Ice::IceType_v8i16;
218 break;
219 case 32:
220 if (NumElements == 4)
221 return Ice::IceType_v4i32;
222 break;
223 }
224 }
225
226 report_fatal_error(std::string("Unhandled vector type: ") +
227 LLVMObjectAsString(VecTy));
228 return Ice::IceType_void;
229 }
230
172 Ice::Type convertType(const Type *Ty) const { 231 Ice::Type convertType(const Type *Ty) const {
173 switch (Ty->getTypeID()) { 232 switch (Ty->getTypeID()) {
174 case Type::VoidTyID: 233 case Type::VoidTyID:
175 return Ice::IceType_void; 234 return Ice::IceType_void;
176 case Type::IntegerTyID: 235 case Type::IntegerTyID:
177 return convertIntegerType(cast<IntegerType>(Ty)); 236 return convertIntegerType(cast<IntegerType>(Ty));
178 case Type::FloatTyID: 237 case Type::FloatTyID:
179 return Ice::IceType_f32; 238 return Ice::IceType_f32;
180 case Type::DoubleTyID: 239 case Type::DoubleTyID:
181 return Ice::IceType_f64; 240 return Ice::IceType_f64;
182 case Type::PointerTyID: 241 case Type::PointerTyID:
183 return SubzeroPointerType; 242 return SubzeroPointerType;
184 case Type::FunctionTyID: 243 case Type::FunctionTyID:
185 return SubzeroPointerType; 244 return SubzeroPointerType;
245 case Type::VectorTyID:
246 return convertVectorType(cast<VectorType>(Ty));
186 default: 247 default:
187 report_fatal_error(std::string("Invalid PNaCl type: ") + 248 report_fatal_error(std::string("Invalid PNaCl type: ") +
188 LLVMObjectAsString(Ty)); 249 LLVMObjectAsString(Ty));
189 } 250 }
190 251
191 llvm_unreachable("convertType"); 252 llvm_unreachable("convertType");
192 return Ice::IceType_void; 253 return Ice::IceType_void;
193 } 254 }
194 255
195 // Given an LLVM instruction and an operand number, produce the 256 // Given an LLVM instruction and an operand number, produce the
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 << " sec\n"; 837 << " sec\n";
777 } 838 }
778 } 839 }
779 } 840 }
780 841
781 if (!DisableTranslation && Func) 842 if (!DisableTranslation && Func)
782 Func->getTarget()->emitConstants(); 843 Func->getTarget()->emitConstants();
783 844
784 return ExitStatus; 845 return ExitStatus;
785 } 846 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698