@@ -457,10 +457,11 @@ struct BuiltinArgTypeMangleInfo {
457
457
bool IsLocalArgBlock;
458
458
SPIR::TypePrimitiveEnum Enum;
459
459
unsigned Attr;
460
+ PointerIndirectPair PointerElementType;
460
461
BuiltinArgTypeMangleInfo ()
461
462
: IsSigned(true ), IsVoidPtr(false ), IsEnum(false ), IsSampler(false ),
462
463
IsAtomic (false ), IsLocalArgBlock(false ), Enum(SPIR::PRIMITIVE_NONE),
463
- Attr(0 ) {}
464
+ Attr(0 ), PointerElementType( nullptr , false ) {}
464
465
};
465
466
466
467
// / Information for mangling builtin function.
@@ -469,92 +470,61 @@ class BuiltinFuncMangleInfo {
469
470
// / Translate builtin function name and set
470
471
// / argument attributes and unsigned args.
471
472
BuiltinFuncMangleInfo (const std::string &UniqName = " " )
472
- : LocalArgBlockIdx(- 1 ), VarArgIdx(-1 ), DontMangle(false ) {
473
+ : VarArgIdx(-1 ), DontMangle(false ) {
473
474
if (!UniqName.empty ())
474
475
init (UniqName);
475
476
}
476
477
virtual ~BuiltinFuncMangleInfo () {}
477
478
const std::string &getUnmangledName () const { return UnmangledName; }
478
- void addUnsignedArg (int Ndx) { UnsignedArgs.insert (Ndx); }
479
+ void addUnsignedArg (int Ndx) {
480
+ if (Ndx == -1 )
481
+ return addUnsignedArgs (0 , 10 ); // 10 is enough for everybody, right?
482
+ getTypeMangleInfo (Ndx).IsSigned = false ;
483
+ }
479
484
void addUnsignedArgs (int StartNdx, int StopNdx) {
480
485
assert (StartNdx < StopNdx && " wrong parameters" );
481
486
for (int I = StartNdx; I <= StopNdx; ++I)
482
487
addUnsignedArg (I);
483
488
}
484
- void addVoidPtrArg (int Ndx) { VoidPtrArgs.insert (Ndx); }
485
- void addSamplerArg (int Ndx) { SamplerArgs.insert (Ndx); }
486
- void addAtomicArg (int Ndx) { AtomicArgs.insert (Ndx); }
487
- void setLocalArgBlock (int Ndx) {
488
- assert (0 <= Ndx && " it is not allowed to set less than zero index" );
489
- LocalArgBlockIdx = Ndx;
489
+ void addVoidPtrArg (unsigned Ndx) { getTypeMangleInfo (Ndx).IsVoidPtr = true ; }
490
+ void addSamplerArg (unsigned Ndx) { getTypeMangleInfo (Ndx).IsSampler = true ; }
491
+ void addAtomicArg (unsigned Ndx) { getTypeMangleInfo (Ndx).IsAtomic = true ; }
492
+ void setLocalArgBlock (unsigned Ndx) {
493
+ getTypeMangleInfo (Ndx).IsLocalArgBlock = true ;
490
494
}
491
- void setEnumArg (int Ndx, SPIR::TypePrimitiveEnum Enum) {
492
- EnumArgs[Ndx] = Enum;
495
+ void setEnumArg (unsigned Ndx, SPIR::TypePrimitiveEnum Enum) {
496
+ auto &Info = getTypeMangleInfo (Ndx);
497
+ Info.IsEnum = true ;
498
+ Info.Enum = Enum;
499
+ }
500
+ void setArgAttr (unsigned Ndx, unsigned Attr) {
501
+ getTypeMangleInfo (Ndx).Attr = Attr;
493
502
}
494
- void setArgAttr (int Ndx, unsigned Attr) { Attrs[Ndx] = Attr; }
495
503
void setVarArg (int Ndx) {
496
504
assert (0 <= Ndx && " it is not allowed to set less than zero index" );
497
505
VarArgIdx = Ndx;
498
506
}
499
507
void setAsDontMangle () { DontMangle = true ; }
500
- bool isArgUnsigned (int Ndx) {
501
- return UnsignedArgs.count (-1 ) || UnsignedArgs.count (Ndx);
502
- }
503
- bool isArgVoidPtr (int Ndx) {
504
- return VoidPtrArgs.count (-1 ) || VoidPtrArgs.count (Ndx);
505
- }
506
- bool isArgSampler (int Ndx) { return SamplerArgs.count (Ndx); }
507
- bool isArgAtomic (int Ndx) { return AtomicArgs.count (Ndx); }
508
- bool isLocalArgBlock (int Ndx) { return LocalArgBlockIdx == Ndx; }
509
- bool isArgEnum (int Ndx, SPIR::TypePrimitiveEnum *Enum = nullptr ) {
510
- auto Loc = EnumArgs.find (Ndx);
511
- if (Loc == EnumArgs.end ())
512
- Loc = EnumArgs.find (-1 );
513
- if (Loc == EnumArgs.end ())
514
- return false ;
515
- if (Enum)
516
- *Enum = Loc->second ;
517
- return true ;
518
- }
519
508
bool avoidMangling () { return DontMangle; }
520
- unsigned getArgAttr (int Ndx) {
521
- auto Loc = Attrs.find (Ndx);
522
- if (Loc == Attrs.end ())
523
- Loc = Attrs.find (-1 );
524
- if (Loc == Attrs.end ())
525
- return 0 ;
526
- return Loc->second ;
527
- }
528
509
// get ellipsis index, single ellipsis at the end of the function is possible
529
510
// only return value < 0 if none
530
511
int getVarArg () const { return VarArgIdx; }
531
- BuiltinArgTypeMangleInfo getTypeMangleInfo (int Ndx) {
532
- BuiltinArgTypeMangleInfo Info;
533
- Info.IsSigned = !isArgUnsigned (Ndx);
534
- Info.IsVoidPtr = isArgVoidPtr (Ndx);
535
- Info.IsEnum = isArgEnum (Ndx, &Info.Enum );
536
- Info.IsSampler = isArgSampler (Ndx);
537
- Info.IsAtomic = isArgAtomic (Ndx);
538
- Info.IsLocalArgBlock = isLocalArgBlock (Ndx);
539
- Info.Attr = getArgAttr (Ndx);
512
+ BuiltinArgTypeMangleInfo &getTypeMangleInfo (unsigned Ndx) {
513
+ while (Ndx >= ArgInfo.size ())
514
+ ArgInfo.emplace_back ();
515
+ BuiltinArgTypeMangleInfo &Info = ArgInfo[Ndx];
540
516
return Info;
541
517
}
542
518
virtual void init (StringRef UniqUnmangledName) {
543
519
UnmangledName = UniqUnmangledName.str ();
544
520
}
545
521
522
+ void fillPointerElementTypes (ArrayRef<PointerIndirectPair>);
523
+
546
524
protected:
547
525
std::string UnmangledName;
548
- std::set<int > UnsignedArgs; // unsigned arguments, or -1 if all are unsigned
549
- std::set<int > VoidPtrArgs; // void pointer arguments, or -1 if all are void
550
- // pointer
551
- std::set<int > SamplerArgs; // sampler arguments
552
- std::set<int > AtomicArgs; // atomic arguments
553
- std::map<int , SPIR::TypePrimitiveEnum> EnumArgs; // enum arguments
554
- std::map<int , unsigned > Attrs; // argument attributes
555
- int LocalArgBlockIdx; // index of a block with local arguments, idx < 0 if
556
- // none
557
- int VarArgIdx; // index of ellipsis argument, idx < 0 if none
526
+ std::vector<BuiltinArgTypeMangleInfo> ArgInfo;
527
+ int VarArgIdx; // index of ellipsis argument, idx < 0 if none
558
528
private:
559
529
bool DontMangle; // clang doesn't apply mangling for some builtin functions
560
530
// (i.e. enqueue_kernel)
@@ -598,7 +568,8 @@ void removeFnAttr(CallInst *Call, Attribute::AttrKind Attr);
598
568
void addFnAttr (CallInst *Call, Attribute::AttrKind Attr);
599
569
void saveLLVMModule (Module *M, const std::string &OutputFile);
600
570
std::string mapSPIRVTypeToOCLType (SPIRVType *Ty, bool Signed);
601
- std::string mapLLVMTypeToOCLType (const Type *Ty, bool Signed);
571
+ std::string mapLLVMTypeToOCLType (const Type *Ty, bool Signed,
572
+ Type *PointerElementType = nullptr );
602
573
SPIRVDecorate *mapPostfixToDecorate (StringRef Postfix, SPIRVEntry *Target);
603
574
604
575
// / Add decorations to a SPIR-V entry.
@@ -682,7 +653,8 @@ StringRef dePrefixSPIRVName(StringRef R, SmallVectorImpl<StringRef> &Postfix);
682
653
// / Get a canonical function name for a SPIR-V op code.
683
654
std::string getSPIRVFuncName (Op OC, StringRef PostFix = " " );
684
655
685
- std::string getSPIRVFuncName (Op OC, const Type *PRetTy, bool IsSigned = false );
656
+ std::string getSPIRVFuncName (Op OC, const Type *PRetTy, bool IsSigned = false ,
657
+ Type *PointerElementType = nullptr );
686
658
687
659
std::string getSPIRVFuncName (SPIRVBuiltinVariableKind BVKind);
688
660
@@ -785,6 +757,7 @@ CallInst *addCallInst(Module *M, StringRef FuncName, Type *RetTy,
785
757
// / Add a call instruction for SPIR-V builtin function.
786
758
CallInst *addCallInstSPIRV (Module *M, StringRef FuncName, Type *RetTy,
787
759
ArrayRef<Value *> Args, AttributeList *Attrs,
760
+ ArrayRef<Type *> PointerElementTypes,
788
761
Instruction *Pos, StringRef InstName);
789
762
790
763
// / Add a call of spir_block_bind function.
@@ -889,7 +862,8 @@ std::string getPostfix(Decoration Dec, unsigned Value = 0);
889
862
// / Get postfix _R{ReturnType} for return type
890
863
// / The returned postfix does not includ "_" at the beginning
891
864
std::string getPostfixForReturnType (CallInst *CI, bool IsSigned = false );
892
- std::string getPostfixForReturnType (const Type *PRetTy, bool IsSigned = false );
865
+ std::string getPostfixForReturnType (const Type *PRetTy, bool IsSigned = false ,
866
+ Type *PointerElementType = nullptr );
893
867
894
868
Constant *getScalarOrVectorConstantInt (Type *T, uint64_t V,
895
869
bool IsSigned = false );
@@ -1013,6 +987,7 @@ inline void getParameterTypes(CallInst *CI,
1013
987
// / manner
1014
988
std::string getSPIRVFriendlyIRFunctionName (OCLExtOpKind ExtOpId,
1015
989
ArrayRef<Type *> ArgTys,
990
+ ArrayRef<PointerIndirectPair> PETs,
1016
991
Type *RetTy = nullptr );
1017
992
1018
993
// / Mangle a function in SPIR-V friendly IR manner
@@ -1024,7 +999,8 @@ std::string getSPIRVFriendlyIRFunctionName(OCLExtOpKind ExtOpId,
1024
999
// / \param Types of arguments of SPIR-V built-in function
1025
1000
// / \return IA64 mangled name.
1026
1001
std::string getSPIRVFriendlyIRFunctionName (const std::string &UniqName,
1027
- spv::Op OC, ArrayRef<Type *> ArgTys);
1002
+ spv::Op OC, ArrayRef<Type *> ArgTys,
1003
+ ArrayRef<PointerIndirectPair> PETs);
1028
1004
1029
1005
// / Cast a function to a void(void) funtion pointer.
1030
1006
Constant *castToVoidFuncPtr (Function *F);
0 commit comments