@@ -411,19 +411,31 @@ bool AMDGPUPrintfRuntimeBindingImpl::lowerPrintfForGpu(Module &M) {
411
411
DataExtractor Extractor (S, /* IsLittleEndian=*/ true , 8 );
412
412
DataExtractor::Cursor Offset (0 );
413
413
while (Offset && Offset.tell () < S.size ()) {
414
- StringRef ReadBytes = Extractor.getBytes (
415
- Offset, std::min (ReadSize, S.size () - Offset.tell ()));
414
+ uint64_t ReadNow = std::min (ReadSize, S.size () - Offset.tell ());
415
+ uint64_t ReadBytes = 0 ;
416
+ switch (ReadNow) {
417
+ default : llvm_unreachable (" min(4, X) > 4?" );
418
+ case 1 :
419
+ ReadBytes = Extractor.getU8 (Offset);
420
+ break ;
421
+ case 2 :
422
+ ReadBytes = Extractor.getU16 (Offset);
423
+ break ;
424
+ case 3 :
425
+ ReadBytes = Extractor.getU24 (Offset);
426
+ break ;
427
+ case 4 :
428
+ ReadBytes = Extractor.getU32 (Offset);
429
+ break ;
430
+ }
416
431
417
432
cantFail (Offset.takeError (),
418
433
" failed to read bytes from constant array" );
419
434
420
- APInt IntVal (8 * ReadBytes.size (), 0 );
421
- LoadIntFromMemory (
422
- IntVal, reinterpret_cast <const uint8_t *>(ReadBytes.data ()),
423
- ReadBytes.size ());
435
+ APInt IntVal (8 * ReadSize, ReadBytes);
424
436
425
437
// TODO: Should not bothering aligning up.
426
- if (ReadBytes. size () < ReadSize)
438
+ if (ReadNow < ReadSize)
427
439
IntVal = IntVal.zext (8 * ReadSize);
428
440
429
441
Type *IntTy = Type::getIntNTy (Ctx, IntVal.getBitWidth ());
0 commit comments