@@ -360,6 +360,7 @@ class BinaryWrapper {
360
360
StructType *SyclDescTy = nullptr ;
361
361
StructType *SyclPropSetTy = nullptr ;
362
362
StructType *SyclPropTy = nullptr ;
363
+ PointerType *PtrTy = nullptr ;
363
364
364
365
// / Records all added device binary images per offload kind.
365
366
llvm::DenseMap<OffloadKind, std::unique_ptr<SameKindPack>> Packs;
@@ -392,7 +393,7 @@ class BinaryWrapper {
392
393
std::unique_ptr<SymPropReader> MySymPropReader;
393
394
394
395
IntegerType *getSizeTTy () {
395
- switch (M.getDataLayout ().getPointerTypeSize (PointerType::getUnqual (C ))) {
396
+ switch (M.getDataLayout ().getPointerTypeSize (getPtrTy ( ))) {
396
397
case 4u :
397
398
return Type::getInt32Ty (C);
398
399
case 8u :
@@ -409,7 +410,7 @@ class BinaryWrapper {
409
410
std::pair<Constant *, Constant *>
410
411
addStructArrayToModule (ArrayRef<Constant *> ArrayData, Type *ElemTy) {
411
412
412
- auto *PtrTy = llvm::PointerType::getUnqual (C );
413
+ auto *PtrTy = getPtrTy ( );
413
414
414
415
if (ArrayData.size () == 0 ) {
415
416
auto *NullPtr = Constant::getNullValue (PtrTy);
@@ -441,14 +442,12 @@ class BinaryWrapper {
441
442
// };
442
443
StructType *getEntryTy () {
443
444
if (!EntryTy)
444
- EntryTy = StructType::create (" __tgt_offload_entry" , PointerType::getUnqual (C ),
445
- PointerType::getUnqual (C ), getSizeTTy (),
445
+ EntryTy = StructType::create (" __tgt_offload_entry" , getPtrTy ( ),
446
+ getPtrTy ( ), getSizeTTy (),
446
447
Type::getInt32Ty (C), Type::getInt32Ty (C));
447
448
return EntryTy;
448
449
}
449
450
450
- PointerType *getEntryPtrTy () { return PointerType::getUnqual (getEntryTy ()); }
451
-
452
451
// struct __tgt_device_image {
453
452
// void *ImageStart;
454
453
// void *ImageEnd;
@@ -457,16 +456,11 @@ class BinaryWrapper {
457
456
// };
458
457
StructType *getDeviceImageTy () {
459
458
if (!ImageTy)
460
- ImageTy = StructType::create (" __tgt_device_image" , PointerType::getUnqual (C),
461
- PointerType::getUnqual (C), getEntryPtrTy (),
462
- getEntryPtrTy ());
459
+ ImageTy = StructType::create (" __tgt_device_image" , getPtrTy (), getPtrTy (),
460
+ getPtrTy (), getPtrTy ());
463
461
return ImageTy;
464
462
}
465
463
466
- PointerType *getDeviceImagePtrTy () {
467
- return PointerType::getUnqual (getDeviceImageTy ());
468
- }
469
-
470
464
// struct __tgt_bin_desc {
471
465
// int32_t NumDeviceImages;
472
466
// __tgt_device_image *DeviceImages;
@@ -476,15 +470,10 @@ class BinaryWrapper {
476
470
StructType *getBinDescTy () {
477
471
if (!DescTy)
478
472
DescTy = StructType::create (" __tgt_bin_desc" , Type::getInt32Ty (C),
479
- getDeviceImagePtrTy (), getEntryPtrTy (),
480
- getEntryPtrTy ());
473
+ getPtrTy (), getPtrTy (), getPtrTy ());
481
474
return DescTy;
482
475
}
483
476
484
- PointerType *getBinDescPtrTy () {
485
- return PointerType::getUnqual (getBinDescTy ());
486
- }
487
-
488
477
// DeviceImageStructVersion change log:
489
478
// -- version 2: updated to PI 1.2 binary image format
490
479
const uint16_t DeviceImageStructVersion = 2 ;
@@ -505,20 +494,16 @@ class BinaryWrapper {
505
494
if (!SyclPropTy) {
506
495
SyclPropTy = StructType::create (
507
496
{
508
- PointerType::getUnqual (C), // Name
509
- PointerType::getUnqual (C), // ValAddr
510
- Type::getInt32Ty (C), // Type
511
- Type::getInt64Ty (C) // ValSize
497
+ getPtrTy (), // Name
498
+ getPtrTy (), // ValAddr
499
+ Type::getInt32Ty (C), // Type
500
+ Type::getInt64Ty (C) // ValSize
512
501
},
513
502
" _pi_device_binary_property_struct" );
514
503
}
515
504
return SyclPropTy;
516
505
}
517
506
518
- PointerType *getSyclPropPtrTy () {
519
- return PointerType::getUnqual (getSyclPropTy ());
520
- }
521
-
522
507
// struct _pi_device_binary_property_set_struct {
523
508
// char *Name;
524
509
// _pi_device_binary_property_struct* PropertiesBegin;
@@ -529,19 +514,15 @@ class BinaryWrapper {
529
514
if (!SyclPropSetTy) {
530
515
SyclPropSetTy = StructType::create (
531
516
{
532
- PointerType::getUnqual (C ), // Name
533
- getSyclPropPtrTy (), // PropertiesBegin
534
- getSyclPropPtrTy () // PropertiesEnd
517
+ getPtrTy ( ), // Name
518
+ getPtrTy (), // PropertiesBegin
519
+ getPtrTy () // PropertiesEnd
535
520
},
536
521
" _pi_device_binary_property_set_struct" );
537
522
}
538
523
return SyclPropSetTy;
539
524
}
540
525
541
- PointerType *getSyclPropSetPtrTy () {
542
- return PointerType::getUnqual (getSyclPropSetTy ());
543
- }
544
-
545
526
// SYCL specific image descriptor type.
546
527
// struct __tgt_device_image {
547
528
// /// version of this structure - for backward compatibility;
@@ -581,28 +562,30 @@ class BinaryWrapper {
581
562
if (!SyclImageTy) {
582
563
SyclImageTy = StructType::create (
583
564
{
584
- Type::getInt16Ty (C), // Version
585
- Type::getInt8Ty (C), // OffloadKind
586
- Type::getInt8Ty (C), // Format
587
- PointerType::getUnqual (C), // DeviceTargetSpec
588
- PointerType::getUnqual (C), // CompileOptions
589
- PointerType::getUnqual (C), // LinkOptions
590
- PointerType::getUnqual (C), // ManifestStart
591
- PointerType::getUnqual (C), // ManifestEnd
592
- PointerType::getUnqual (C), // ImageStart
593
- PointerType::getUnqual (C), // ImageEnd
594
- getEntryPtrTy (), // EntriesBegin
595
- getEntryPtrTy (), // EntriesEnd
596
- getSyclPropSetPtrTy (), // PropertySetBegin
597
- getSyclPropSetPtrTy () // PropertySetEnd
565
+ Type::getInt16Ty (C), // Version
566
+ Type::getInt8Ty (C), // OffloadKind
567
+ Type::getInt8Ty (C), // Format
568
+ getPtrTy (), // DeviceTargetSpec
569
+ getPtrTy (), // CompileOptions
570
+ getPtrTy (), // LinkOptions
571
+ getPtrTy (), // ManifestStart
572
+ getPtrTy (), // ManifestEnd
573
+ getPtrTy (), // ImageStart
574
+ getPtrTy (), // ImageEnd
575
+ getPtrTy (), // EntriesBegin
576
+ getPtrTy (), // EntriesEnd
577
+ getPtrTy (), // PropertySetBegin
578
+ getPtrTy () // PropertySetEnd
598
579
},
599
580
" __tgt_device_image" );
600
581
}
601
582
return SyclImageTy;
602
583
}
603
584
604
- PointerType *getSyclDeviceImagePtrTy () {
605
- return PointerType::getUnqual (getSyclDeviceImageTy ());
585
+ PointerType *getPtrTy () {
586
+ PointerType *&Ty = PtrTy;
587
+ Ty = Ty ? Ty : getPtrTy ();
588
+ return Ty;
606
589
}
607
590
608
591
const uint16_t BinDescStructVersion = 1 ;
@@ -623,21 +606,17 @@ class BinaryWrapper {
623
606
if (!SyclDescTy) {
624
607
SyclDescTy = StructType::create (
625
608
{
626
- Type::getInt16Ty (C), // Version
627
- Type::getInt16Ty (C), // NumDeviceImages
628
- getSyclDeviceImagePtrTy (), // DeviceImages
629
- getEntryPtrTy (), // HostEntriesBegin
630
- getEntryPtrTy () // HostEntriesEnd
609
+ Type::getInt16Ty (C), // Version
610
+ Type::getInt16Ty (C), // NumDeviceImages
611
+ getPtrTy (), // DeviceImages
612
+ getPtrTy (), // HostEntriesBegin
613
+ getPtrTy () // HostEntriesEnd
631
614
},
632
615
" __tgt_bin_desc" );
633
616
}
634
617
return SyclDescTy;
635
618
}
636
619
637
- PointerType *getSyclBinDescPtrTy () {
638
- return PointerType::getUnqual (getSyclBinDescTy ());
639
- }
640
-
641
620
Expected<MemoryBuffer *> loadFile (llvm::StringRef Name) {
642
621
auto InputOrErr = MemoryBuffer::getFileOrSTDIN (Name);
643
622
@@ -649,11 +628,10 @@ class BinaryWrapper {
649
628
}
650
629
651
630
Function *addDeclarationForNativeCPU (StringRef Name) {
652
- static FunctionType *NativeCPUFuncTy = FunctionType::get (
653
- Type::getVoidTy (C),
654
- {PointerType::getUnqual (C), PointerType::getUnqual (C)}, false );
655
- static FunctionType *NativeCPUBuiltinTy = FunctionType::get (
656
- PointerType::getUnqual (C), {PointerType::getUnqual (C)}, false );
631
+ static FunctionType *NativeCPUFuncTy =
632
+ FunctionType::get (Type::getVoidTy (C), {getPtrTy (), getPtrTy ()}, false );
633
+ static FunctionType *NativeCPUBuiltinTy =
634
+ FunctionType::get (getPtrTy (), {getPtrTy ()}, false );
657
635
FunctionType *FTy;
658
636
if (Name.starts_with (" __dpcpp_nativecpu" ))
659
637
FTy = NativeCPUBuiltinTy;
@@ -678,9 +656,8 @@ class BinaryWrapper {
678
656
// char *kernelname;
679
657
// unsigned char *kernel_ptr;
680
658
// };
681
- StructType *NCPUEntryT = StructType::create (
682
- {PointerType::getUnqual (C), PointerType::getUnqual (C)},
683
- " __nativecpu_entry" );
659
+ StructType *NCPUEntryT =
660
+ StructType::create ({getPtrTy (), getPtrTy ()}, " __nativecpu_entry" );
684
661
SmallVector<Constant *, 5 > NativeCPUEntries;
685
662
for (line_iterator LI (*MB); !LI.is_at_eof (); ++LI) {
686
663
auto *NewDecl = addDeclarationForNativeCPU (*LI);
@@ -692,7 +669,7 @@ class BinaryWrapper {
692
669
// Add an empty entry that we use as end iterator
693
670
static auto *NativeCPUEndStr =
694
671
addStringToModule (" __nativecpu_end" , " __ncpu_end_str" );
695
- auto *NullPtr = llvm::ConstantPointerNull::get (PointerType::getUnqual (C ));
672
+ auto *NullPtr = llvm::ConstantPointerNull::get (getPtrTy ( ));
696
673
NativeCPUEntries.push_back (
697
674
ConstantStruct::get (NCPUEntryT, {NativeCPUEndStr, NullPtr}));
698
675
@@ -790,13 +767,13 @@ class BinaryWrapper {
790
767
Expected<std::pair<Constant *, Constant *>>
791
768
addSYCLOffloadEntriesToModule (StringRef EntriesFile) {
792
769
if (EntriesFile.empty () && !MySymPropReader) {
793
- auto *NullPtr = Constant::getNullValue (getEntryPtrTy ());
770
+ auto *NullPtr = Constant::getNullValue (getPtrTy ());
794
771
return std::pair<Constant *, Constant *>(NullPtr, NullPtr);
795
772
}
796
773
797
774
auto *Zero = ConstantInt::get (getSizeTTy (), 0u );
798
775
auto *i32Zero = ConstantInt::get (Type::getInt32Ty (C), 0u );
799
- auto *NullPtr = Constant::getNullValue (PointerType::getUnqual (C ));
776
+ auto *NullPtr = Constant::getNullValue (getPtrTy ( ));
800
777
801
778
std::vector<Constant *> EntriesInits;
802
779
// Only the name field is used for SYCL now, others are for future OpenMP
@@ -851,7 +828,7 @@ class BinaryWrapper {
851
828
switch (Prop.second .getType ()) {
852
829
case llvm::util::PropertyValue::UINT32: {
853
830
// for known scalar types ValAddr is null, ValSize keeps the value
854
- PropValAddr = Constant::getNullValue (PointerType::getUnqual (C ));
831
+ PropValAddr = Constant::getNullValue (getPtrTy ( ));
855
832
PropValSize =
856
833
ConstantInt::get (Type::getInt64Ty (C), Prop.second .asUint32 ());
857
834
break ;
@@ -917,7 +894,7 @@ class BinaryWrapper {
917
894
PropRegistry = MySymPropReader->getPropRegistry ();
918
895
} else {
919
896
if (PropRegistryFile.empty ()) {
920
- auto *NullPtr = Constant::getNullValue (llvm::PointerType::getUnqual (C ));
897
+ auto *NullPtr = Constant::getNullValue (getPtrTy ( ));
921
898
return std::pair<Constant *, Constant *>(NullPtr, NullPtr);
922
899
}
923
900
// load the property registry file
@@ -1036,12 +1013,12 @@ class BinaryWrapper {
1036
1013
}
1037
1014
} else {
1038
1015
// Host entry table is not used in SYCL
1039
- EntriesB = Constant::getNullValue (getEntryPtrTy ());
1040
- EntriesE = Constant::getNullValue (getEntryPtrTy ());
1016
+ EntriesB = Constant::getNullValue (getPtrTy ());
1017
+ EntriesE = Constant::getNullValue (getPtrTy ());
1041
1018
}
1042
1019
1043
1020
auto *Zero = ConstantInt::get (getSizeTTy (), 0u );
1044
- auto *NullPtr = Constant::getNullValue (PointerType::getUnqual (C ));
1021
+ auto *NullPtr = Constant::getNullValue (getPtrTy ( ));
1045
1022
Constant *ZeroZero[] = {Zero, Zero};
1046
1023
1047
1024
// Create initializer for the images array.
@@ -1270,10 +1247,8 @@ class BinaryWrapper {
1270
1247
Func->setSection (" .text.startup" );
1271
1248
1272
1249
// Get RegFuncName function declaration.
1273
- auto *RegFuncTy = FunctionType::get (
1274
- Type::getVoidTy (C),
1275
- Kind == OffloadKind::SYCL ? getSyclBinDescPtrTy () : getBinDescPtrTy (),
1276
- /* isVarArg=*/ false );
1250
+ auto *RegFuncTy = FunctionType::get (Type::getVoidTy (C), getPtrTy (),
1251
+ /* isVarArg=*/ false );
1277
1252
FunctionCallee RegFuncC =
1278
1253
M.getOrInsertFunction (Kind == OffloadKind::SYCL ? " __sycl_register_lib"
1279
1254
: " __tgt_register_lib" ,
@@ -1301,10 +1276,8 @@ class BinaryWrapper {
1301
1276
Func->setSection (" .text.startup" );
1302
1277
1303
1278
// Get UnregFuncName function declaration.
1304
- auto *UnRegFuncTy = FunctionType::get (
1305
- Type::getVoidTy (C),
1306
- Kind == OffloadKind::SYCL ? getSyclBinDescPtrTy () : getBinDescPtrTy (),
1307
- /* isVarArg=*/ false );
1279
+ auto *UnRegFuncTy = FunctionType::get (Type::getVoidTy (C), getPtrTy (),
1280
+ /* isVarArg=*/ false );
1308
1281
FunctionCallee UnRegFuncC = M.getOrInsertFunction (
1309
1282
Kind == OffloadKind::SYCL ? " __sycl_unregister_lib"
1310
1283
: " __tgt_unregister_lib" ,
0 commit comments