@@ -215,6 +215,43 @@ static Intrinsic::ID getWaveActiveMaxIntrinsic(llvm::Triple::ArchType Arch,
215215 }
216216}
217217
218+ // Returns the mangled name for a builtin function that the SPIR-V backend
219+ // will expand into a spec Constant.
220+ static std::string getSpecConstantFunctionName (clang::QualType SpecConstantType,
221+ ASTContext &Context) {
222+ // The parameter types for our conceptual intrinsic function.
223+ QualType ClangParamTypes[] = {Context.IntTy , SpecConstantType};
224+
225+ // Create a temporary FunctionDecl for the builtin fuction. It won't be
226+ // added to the AST.
227+ FunctionProtoType::ExtProtoInfo EPI;
228+ QualType FnType =
229+ Context.getFunctionType (SpecConstantType, ClangParamTypes, EPI);
230+ DeclarationName FuncName = &Context.Idents .get (" __spirv_SpecConstant" );
231+ FunctionDecl *FnDeclForMangling = FunctionDecl::Create (
232+ Context, Context.getTranslationUnitDecl (), SourceLocation (),
233+ SourceLocation (), FuncName, FnType, /* TSI=*/ nullptr , SC_Extern);
234+
235+ // Attach the created parameter declarations to the function declaration.
236+ SmallVector<ParmVarDecl *, 2 > ParamDecls;
237+ for (QualType ParamType : ClangParamTypes) {
238+ ParmVarDecl *PD = ParmVarDecl::Create (
239+ Context, FnDeclForMangling, SourceLocation (), SourceLocation (),
240+ /* IdentifierInfo*/ nullptr , ParamType, /* TSI*/ nullptr , SC_None,
241+ /* DefaultArg*/ nullptr );
242+ ParamDecls.push_back (PD);
243+ }
244+ FnDeclForMangling->setParams (ParamDecls);
245+
246+ // Get the mangled name.
247+ std::string Name;
248+ llvm::raw_string_ostream MangledNameStream (Name);
249+ MangleContext *Mangler = Context.createMangleContext ();
250+ Mangler->mangleName (FnDeclForMangling, MangledNameStream);
251+ MangledNameStream.flush ();
252+ return Name;
253+ }
254+
218255Value *CodeGenFunction::EmitHLSLBuiltinExpr (unsigned BuiltinID,
219256 const CallExpr *E,
220257 ReturnValueSlot ReturnValue) {
@@ -800,7 +837,8 @@ llvm::Function *clang::CodeGen::CodeGenFunction::getSpecConstantFunction(
800837
801838 // Find or create the declaration for the function.
802839 llvm::Module *M = &CGM.getModule ();
803- std::string MangledName = getSpecConstantFunctionName (SpecConstantType);
840+ std::string MangledName =
841+ getSpecConstantFunctionName (SpecConstantType, getContext ());
804842 llvm::Function *SpecConstantFn = M->getFunction (MangledName);
805843
806844 if (!SpecConstantFn) {
@@ -813,39 +851,3 @@ llvm::Function *clang::CodeGen::CodeGenFunction::getSpecConstantFunction(
813851 }
814852 return SpecConstantFn;
815853}
816-
817- std::string clang::CodeGen::CodeGenFunction::getSpecConstantFunctionName (
818- const clang::QualType &SpecConstantType) {
819- // The parameter types for our conceptual intrinsic function.
820- ASTContext &Context = getContext ();
821- QualType ClangParamTypes[] = {Context.IntTy , SpecConstantType};
822-
823- // Create a temporary FunctionDecl for the builtin fuction. It won't be
824- // added to the AST.
825- FunctionProtoType::ExtProtoInfo EPI;
826- QualType FnType =
827- Context.getFunctionType (SpecConstantType, ClangParamTypes, EPI);
828- DeclarationName FuncName = &Context.Idents .get (" __spirv_SpecConstant" );
829- FunctionDecl *FnDeclForMangling = FunctionDecl::Create (
830- Context, Context.getTranslationUnitDecl (), SourceLocation (),
831- SourceLocation (), FuncName, FnType, /* TSI=*/ nullptr , SC_Extern);
832-
833- // Attach the created parameter declarations to the function declaration.
834- SmallVector<ParmVarDecl *, 2 > ParamDecls;
835- for (QualType ParamType : ClangParamTypes) {
836- ParmVarDecl *PD = ParmVarDecl::Create (
837- Context, FnDeclForMangling, SourceLocation (), SourceLocation (),
838- /* IdentifierInfo*/ nullptr , ParamType, /* TSI*/ nullptr , SC_None,
839- /* DefaultArg*/ nullptr );
840- ParamDecls.push_back (PD);
841- }
842- FnDeclForMangling->setParams (ParamDecls);
843-
844- // Get the mangled name.
845- std::string Name;
846- llvm::raw_string_ostream MangledNameStream (Name);
847- MangleContext *Mangler = Context.createMangleContext ();
848- Mangler->mangleName (FnDeclForMangling, MangledNameStream);
849- MangledNameStream.flush ();
850- return Name;
851- }
0 commit comments