OLD | NEW |
---|---|
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 Loading... | |
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 = | |
123 dyn_cast<ConstantDataVector>(Const)) { | |
124 // This case will never be encountered when processing valid PNaCl | |
125 // IR. Constants of vector type (except for undef) do not appear | |
126 // 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
| |
127 llvm::StringRef Data = CDV->getRawDataValues(); | |
128 assert(Data.size() == Ice::VECT128_BYTES); | |
129 Ice::Vect128 Value(Ice::VECT128_BYTES); | |
130 std::memcpy(Value.data(), Data.data(), Ice::VECT128_BYTES); | |
131 return Ctx->getConstantVector(convertType(CDV->getType()), Value); | |
132 } else if (const ConstantVector *CV = dyn_cast<ConstantVector>(Const)) { | |
133 // This case will never be encountered when processing valid PNaCl | |
134 // IR (see comment above in ConstantDataVector). | |
135 Ice::Type Type = convertType(CV->getType()); | |
136 // Only i1 vectors should be represented as ConstantVectors. | |
137 assert(Type == Ice::IceType_v4i1 || Type == Ice::IceType_v8i1 || | |
138 Type == Ice::IceType_v16i1); | |
139 unsigned NumElements = typeNumElements(Type); | |
140 Ice::BitVect Value(NumElements); | |
141 for (unsigned Elt = 0; Elt != NumElements; ++Elt) { | |
142 Value[Elt] = | |
143 cast<ConstantInt>(CV->getAggregateElement(Elt))->getZExtValue(); | |
144 } | |
145 return Ctx->getConstantBitVector(Type, Value); | |
146 } else if (const ConstantAggregateZero *CZ = | |
147 dyn_cast<ConstantAggregateZero>(Const)) { | |
148 // This case will never be encountered when processing valid PNaCl | |
149 // IR (see comment above in ConstantDataVector). | |
150 return Ctx->getConstantZero(convertType(CZ->getType())); | |
122 } else { | 151 } else { |
123 llvm_unreachable("Unhandled constant type"); | 152 llvm_unreachable("Unhandled constant type"); |
124 return NULL; | 153 return NULL; |
125 } | 154 } |
126 } | 155 } |
127 | 156 |
128 private: | 157 private: |
129 // LLVM values (instructions, etc.) are mapped directly to ICE variables. | 158 // LLVM values (instructions, etc.) are mapped directly to ICE variables. |
130 // mapValueToIceVar has a version that forces an ICE type on the variable, | 159 // mapValueToIceVar has a version that forces an ICE type on the variable, |
131 // and a version that just uses convertType on V. | 160 // and a version that just uses convertType on V. |
(...skipping 30 matching lines...) Expand all Loading... | |
162 return Ice::IceType_i32; | 191 return Ice::IceType_i32; |
163 case 64: | 192 case 64: |
164 return Ice::IceType_i64; | 193 return Ice::IceType_i64; |
165 default: | 194 default: |
166 report_fatal_error(std::string("Invalid PNaCl int type: ") + | 195 report_fatal_error(std::string("Invalid PNaCl int type: ") + |
167 LLVMObjectAsString(IntTy)); | 196 LLVMObjectAsString(IntTy)); |
168 return Ice::IceType_void; | 197 return Ice::IceType_void; |
169 } | 198 } |
170 } | 199 } |
171 | 200 |
201 Ice::Type convertVectorType(const VectorType *VecTy) const { | |
202 unsigned NumElements = VecTy->getNumElements(); | |
203 const Type *ElementType = VecTy->getElementType(); | |
204 | |
205 if (ElementType->isFloatTy()) { | |
206 if (NumElements == 4) | |
207 return Ice::IceType_v4f32; | |
208 } else if (ElementType->isIntegerTy()) { | |
209 switch (cast<IntegerType>(ElementType)->getBitWidth()) { | |
210 case 1: | |
211 if (NumElements == 4) | |
212 return Ice::IceType_v4i1; | |
213 if (NumElements == 8) | |
214 return Ice::IceType_v8i1; | |
215 if (NumElements == 16) | |
216 return Ice::IceType_v16i1; | |
217 break; | |
218 case 8: | |
219 if (NumElements == 16) | |
220 return Ice::IceType_v16i8; | |
221 break; | |
222 case 16: | |
223 if (NumElements == 8) | |
224 return Ice::IceType_v8i16; | |
225 break; | |
226 case 32: | |
227 if (NumElements == 4) | |
228 return Ice::IceType_v4i32; | |
229 break; | |
230 } | |
231 } | |
232 | |
233 report_fatal_error(std::string("Unhandled vector type: ") + | |
234 LLVMObjectAsString(VecTy)); | |
235 return Ice::IceType_void; | |
236 } | |
237 | |
172 Ice::Type convertType(const Type *Ty) const { | 238 Ice::Type convertType(const Type *Ty) const { |
173 switch (Ty->getTypeID()) { | 239 switch (Ty->getTypeID()) { |
174 case Type::VoidTyID: | 240 case Type::VoidTyID: |
175 return Ice::IceType_void; | 241 return Ice::IceType_void; |
176 case Type::IntegerTyID: | 242 case Type::IntegerTyID: |
177 return convertIntegerType(cast<IntegerType>(Ty)); | 243 return convertIntegerType(cast<IntegerType>(Ty)); |
178 case Type::FloatTyID: | 244 case Type::FloatTyID: |
179 return Ice::IceType_f32; | 245 return Ice::IceType_f32; |
180 case Type::DoubleTyID: | 246 case Type::DoubleTyID: |
181 return Ice::IceType_f64; | 247 return Ice::IceType_f64; |
182 case Type::PointerTyID: | 248 case Type::PointerTyID: |
183 return SubzeroPointerType; | 249 return SubzeroPointerType; |
184 case Type::FunctionTyID: | 250 case Type::FunctionTyID: |
185 return SubzeroPointerType; | 251 return SubzeroPointerType; |
252 case Type::VectorTyID: | |
253 return convertVectorType(cast<VectorType>(Ty)); | |
186 default: | 254 default: |
187 report_fatal_error(std::string("Invalid PNaCl type: ") + | 255 report_fatal_error(std::string("Invalid PNaCl type: ") + |
188 LLVMObjectAsString(Ty)); | 256 LLVMObjectAsString(Ty)); |
189 } | 257 } |
190 | 258 |
191 llvm_unreachable("convertType"); | 259 llvm_unreachable("convertType"); |
192 return Ice::IceType_void; | 260 return Ice::IceType_void; |
193 } | 261 } |
194 | 262 |
195 // Given an LLVM instruction and an operand number, produce the | 263 // Given an LLVM instruction and an operand number, produce the |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
776 << " sec\n"; | 844 << " sec\n"; |
777 } | 845 } |
778 } | 846 } |
779 } | 847 } |
780 | 848 |
781 if (!DisableTranslation && Func) | 849 if (!DisableTranslation && Func) |
782 Func->getTarget()->emitConstants(); | 850 Func->getTarget()->emitConstants(); |
783 | 851 |
784 return ExitStatus; | 852 return ExitStatus; |
785 } | 853 } |
OLD | NEW |