@@ -457,10 +457,11 @@ struct BuiltinArgTypeMangleInfo {
457457 bool IsLocalArgBlock;
458458 SPIR::TypePrimitiveEnum Enum;
459459 unsigned Attr;
460+ PointerIndirectPair PointerElementType;
460461 BuiltinArgTypeMangleInfo ()
461462 : IsSigned(true ), IsVoidPtr(false ), IsEnum(false ), IsSampler(false ),
462463 IsAtomic (false ), IsLocalArgBlock(false ), Enum(SPIR::PRIMITIVE_NONE),
463- Attr(0 ) {}
464+ Attr(0 ), PointerElementType( nullptr , false ) {}
464465};
465466
466467// / Information for mangling builtin function.
@@ -469,92 +470,61 @@ class BuiltinFuncMangleInfo {
469470 // / Translate builtin function name and set
470471 // / argument attributes and unsigned args.
471472 BuiltinFuncMangleInfo (const std::string &UniqName = " " )
472- : LocalArgBlockIdx(- 1 ), VarArgIdx(-1 ), DontMangle(false ) {
473+ : VarArgIdx(-1 ), DontMangle(false ) {
473474 if (!UniqName.empty ())
474475 init (UniqName);
475476 }
476477 virtual ~BuiltinFuncMangleInfo () {}
477478 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+ }
479484 void addUnsignedArgs (int StartNdx, int StopNdx) {
480485 assert (StartNdx < StopNdx && " wrong parameters" );
481486 for (int I = StartNdx; I <= StopNdx; ++I)
482487 addUnsignedArg (I);
483488 }
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 ;
490494 }
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;
493502 }
494- void setArgAttr (int Ndx, unsigned Attr) { Attrs[Ndx] = Attr; }
495503 void setVarArg (int Ndx) {
496504 assert (0 <= Ndx && " it is not allowed to set less than zero index" );
497505 VarArgIdx = Ndx;
498506 }
499507 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- }
519508 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- }
528509 // get ellipsis index, single ellipsis at the end of the function is possible
529510 // only return value < 0 if none
530511 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];
540516 return Info;
541517 }
542518 virtual void init (StringRef UniqUnmangledName) {
543519 UnmangledName = UniqUnmangledName.str ();
544520 }
545521
522+ void fillPointerElementTypes (ArrayRef<PointerIndirectPair>);
523+
546524protected:
547525 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
558528private:
559529 bool DontMangle; // clang doesn't apply mangling for some builtin functions
560530 // (i.e. enqueue_kernel)
@@ -598,7 +568,8 @@ void removeFnAttr(CallInst *Call, Attribute::AttrKind Attr);
598568void addFnAttr (CallInst *Call, Attribute::AttrKind Attr);
599569void saveLLVMModule (Module *M, const std::string &OutputFile);
600570std::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 );
602573SPIRVDecorate *mapPostfixToDecorate (StringRef Postfix, SPIRVEntry *Target);
603574
604575// / Add decorations to a SPIR-V entry.
@@ -682,7 +653,8 @@ StringRef dePrefixSPIRVName(StringRef R, SmallVectorImpl<StringRef> &Postfix);
682653// / Get a canonical function name for a SPIR-V op code.
683654std::string getSPIRVFuncName (Op OC, StringRef PostFix = " " );
684655
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 );
686658
687659std::string getSPIRVFuncName (SPIRVBuiltinVariableKind BVKind);
688660
@@ -785,6 +757,7 @@ CallInst *addCallInst(Module *M, StringRef FuncName, Type *RetTy,
785757// / Add a call instruction for SPIR-V builtin function.
786758CallInst *addCallInstSPIRV (Module *M, StringRef FuncName, Type *RetTy,
787759 ArrayRef<Value *> Args, AttributeList *Attrs,
760+ ArrayRef<Type *> PointerElementTypes,
788761 Instruction *Pos, StringRef InstName);
789762
790763// / Add a call of spir_block_bind function.
@@ -889,7 +862,8 @@ std::string getPostfix(Decoration Dec, unsigned Value = 0);
889862// / Get postfix _R{ReturnType} for return type
890863// / The returned postfix does not includ "_" at the beginning
891864std::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 );
893867
894868Constant *getScalarOrVectorConstantInt (Type *T, uint64_t V,
895869 bool IsSigned = false );
@@ -1013,6 +987,7 @@ inline void getParameterTypes(CallInst *CI,
1013987// / manner
1014988std::string getSPIRVFriendlyIRFunctionName (OCLExtOpKind ExtOpId,
1015989 ArrayRef<Type *> ArgTys,
990+ ArrayRef<PointerIndirectPair> PETs,
1016991 Type *RetTy = nullptr );
1017992
1018993// / Mangle a function in SPIR-V friendly IR manner
@@ -1024,7 +999,8 @@ std::string getSPIRVFriendlyIRFunctionName(OCLExtOpKind ExtOpId,
1024999// / \param Types of arguments of SPIR-V built-in function
10251000// / \return IA64 mangled name.
10261001std::string getSPIRVFriendlyIRFunctionName (const std::string &UniqName,
1027- spv::Op OC, ArrayRef<Type *> ArgTys);
1002+ spv::Op OC, ArrayRef<Type *> ArgTys,
1003+ ArrayRef<PointerIndirectPair> PETs);
10281004
10291005// / Cast a function to a void(void) funtion pointer.
10301006Constant *castToVoidFuncPtr (Function *F);
0 commit comments