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