OLD | NEW |
---|---|
1 //===- subzero/src/IceOperand.cpp - High-level operand implementation -----===// | 1 //===- subzero/src/IceOperand.cpp - High-level operand implementation -----===// |
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 implements the Operand class and its target-independent | 10 // This file implements the Operand class and its target-independent |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 } | 230 } |
231 } | 231 } |
232 | 232 |
233 void ConstantRelocatable::dump(GlobalContext *Ctx) const { | 233 void ConstantRelocatable::dump(GlobalContext *Ctx) const { |
234 Ostream &Str = Ctx->getStrDump(); | 234 Ostream &Str = Ctx->getStrDump(); |
235 Str << "@" << Name; | 235 Str << "@" << Name; |
236 if (Offset) | 236 if (Offset) |
237 Str << "+" << Offset; | 237 Str << "+" << Offset; |
238 } | 238 } |
239 | 239 |
240 namespace { | |
241 | |
242 // Read an item of type T and return it. Advance the buffer pointer | |
243 // by the size of T. | |
244 template <typename T> T convertAndAdvance(const char *&Src) { | |
245 T Dest; | |
246 std::memcpy(&Dest, Src, sizeof(T)); | |
247 Src += sizeof(T); | |
248 return Dest; | |
249 } | |
250 | |
251 // Convert a vector to a list of strings. | |
Jim Stichnoth
2014/06/27 18:30:16
Seems overly complicated to build up a StringList
wala
2014/06/27 21:09:19
If it's being emitted directly to an Ostream, I co
| |
252 StringList getVectorRepr(const Vect128 &Vector, const Type Ty) { | |
253 StringList Repr; | |
254 const char *Window = Vector.data(); | |
255 | |
256 Type ElementType = typeElementType(Ty); | |
257 size_t NumElements = typeNumElements(Ty); | |
258 | |
259 assert(Vector.size() == VECT128_BYTES); | |
260 assert(typeElementType(Ty) != IceType_i1); | |
261 | |
262 for (unsigned I = 0; I < NumElements; ++I) { | |
263 IceString Result; | |
264 llvm::raw_string_ostream OS(Result); | |
265 switch (ElementType) { | |
266 default: | |
267 llvm_unreachable("Unknown element type"); | |
268 break; | |
269 case IceType_i8: | |
270 OS << (unsigned)convertAndAdvance<uint8_t>(Window); | |
271 break; | |
272 case IceType_i16: | |
273 OS << convertAndAdvance<uint16_t>(Window); | |
274 break; | |
275 case IceType_i32: | |
276 OS << convertAndAdvance<uint32_t>(Window); | |
277 break; | |
278 case IceType_f32: | |
279 OS << convertAndAdvance<float>(Window); | |
280 break; | |
281 } | |
282 Repr.push_back(OS.str()); | |
283 } | |
284 | |
285 assert(Window == Vector.data() + 16); | |
jvoung (off chromium)
2014/06/26 23:33:46
Could use VECT128_BYTES here too.
| |
286 return Repr; | |
287 } | |
288 } | |
Jim Stichnoth
2014/06/27 18:30:16
"end of anonymous namespace" comment
| |
289 | |
290 template <> void ConstantVector::dump(GlobalContext *Ctx) const { | |
291 Ostream &Str = Ctx->getStrDump(); | |
292 Type Ty = getType(); | |
293 StringList Elements = getVectorRepr(Value, Ty); | |
294 Str << "<"; | |
295 for (StringList::const_iterator I = Elements.begin(), E = Elements.end(); | |
296 I != E;) { | |
297 Str << typeElementType(Ty) << " " << *I; | |
298 ++I; | |
299 Str << (I != E ? ", " : ""); | |
300 } | |
301 Str << ">"; | |
302 } | |
303 | |
304 template <> void ConstantBitVector::dump(GlobalContext *Ctx) const { | |
305 Ostream &Str = Ctx->getStrDump(); | |
306 unsigned NumElements = typeNumElements(getType()); | |
307 Str << "<"; | |
308 for (unsigned I = 0; I != NumElements;) { | |
Jim Stichnoth
2014/06/27 18:30:16
This loop would probably be more "natural" written
| |
309 Str << "i1 " << (Value[I] ? "1" : "0"); | |
310 ++I; | |
311 Str << (I != NumElements ? ", " : ""); | |
312 } | |
313 Str << ">"; | |
314 } | |
315 | |
240 void LiveRange::dump(Ostream &Str) const { | 316 void LiveRange::dump(Ostream &Str) const { |
241 Str << "(weight=" << Weight << ") "; | 317 Str << "(weight=" << Weight << ") "; |
242 for (RangeType::const_iterator I = Range.begin(), E = Range.end(); I != E; | 318 for (RangeType::const_iterator I = Range.begin(), E = Range.end(); I != E; |
243 ++I) { | 319 ++I) { |
244 if (I != Range.begin()) | 320 if (I != Range.begin()) |
245 Str << ", "; | 321 Str << ", "; |
246 Str << "[" << (*I).first << ":" << (*I).second << ")"; | 322 Str << "[" << (*I).first << ":" << (*I).second << ")"; |
247 } | 323 } |
248 } | 324 } |
249 | 325 |
250 Ostream &operator<<(Ostream &Str, const LiveRange &L) { | 326 Ostream &operator<<(Ostream &Str, const LiveRange &L) { |
251 L.dump(Str); | 327 L.dump(Str); |
252 return Str; | 328 return Str; |
253 } | 329 } |
254 | 330 |
255 Ostream &operator<<(Ostream &Str, const RegWeight &W) { | 331 Ostream &operator<<(Ostream &Str, const RegWeight &W) { |
256 if (W.getWeight() == RegWeight::Inf) | 332 if (W.getWeight() == RegWeight::Inf) |
257 Str << "Inf"; | 333 Str << "Inf"; |
258 else | 334 else |
259 Str << W.getWeight(); | 335 Str << W.getWeight(); |
260 return Str; | 336 return Str; |
261 } | 337 } |
262 | 338 |
263 } // end of namespace Ice | 339 } // end of namespace Ice |
OLD | NEW |