@@ -491,12 +491,13 @@ Instruction *
491491getOrCreateSwitchFunc (StringRef MapName, Value *V,
492492 const SPIRVMap<KeyTy, ValTy, Identifier> &Map,
493493 bool IsReverse, Optional<int > DefaultCase,
494- Instruction *InsertPoint, Module *M, int KeyMask = 0 ) {
494+ Instruction *InsertPoint, int KeyMask = 0 ) {
495495 static_assert (std::is_convertible<KeyTy, int >::value &&
496496 std::is_convertible<ValTy, int >::value,
497497 " Can map only integer values" );
498498 Type *Ty = V->getType ();
499499 assert (Ty && Ty->isIntegerTy () && " Can't map non-integer types" );
500+ Module *M = InsertPoint->getModule ();
500501 Function *F = getOrCreateFunction (M, Ty, Ty, MapName);
501502 if (!F->empty ()) // The switch function already exists. just call it.
502503 return addCallInst (M, MapName, Ty, V, nullptr , InsertPoint);
@@ -538,6 +539,85 @@ getOrCreateSwitchFunc(StringRef MapName, Value *V,
538539 return addCallInst (M, MapName, Ty, V, nullptr , InsertPoint);
539540}
540541
542+ // / Performs conversion from OpenCL memory_scope into SPIR-V Scope.
543+ // /
544+ // / Supports both constant and non-constant values. To handle the latter case,
545+ // / function with switch..case statement will be inserted into module which
546+ // / \arg InsertBefore belongs to (in order to perform mapping at runtime)
547+ // /
548+ // / \param [in] MemScope memory_scope value which needs to be translated
549+ // / \param [in] DefaultCase default value for switch..case construct if
550+ // / dynamic mapping is used
551+ // / \param [in] InsertBefore insertion point for call into conversion function
552+ // / which is generated if \arg MemScope is not a constant
553+ // / \returns \c Value corresponding to SPIR-V Scope equivalent to OpenCL
554+ // / memory_scope passed in \arg MemScope
555+ Value *transOCLMemScopeIntoSPIRVScope (Value *MemScope,
556+ Optional<int > DefaultCase,
557+ Instruction *InsertBefore);
558+
559+ // / Performs conversion from OpenCL memory_order into SPIR-V Memory Semantics.
560+ // /
561+ // / Supports both constant and non-constant values. To handle the latter case,
562+ // / function with switch..case statement will be inserted into module which
563+ // / \arg InsertBefore belongs to (in order to perform mapping at runtime)
564+ // /
565+ // / \param [in] MemOrder memory_scope value which needs to be translated
566+ // / \param [in] DefaultCase default value for switch..case construct if
567+ // / dynamic mapping is used
568+ // / \param [in] InsertBefore insertion point for call into conversion function
569+ // / which is generated if \arg MemOrder is not a constant
570+ // / \returns \c Value corresponding to SPIR-V Memory Semantics equivalent to
571+ // / OpenCL memory_order passed in \arg MemOrder
572+ Value *transOCLMemOrderIntoSPIRVMemorySemantics (Value *MemOrder,
573+ Optional<int > DefaultCase,
574+ Instruction *InsertBefore);
575+
576+ // / Performs conversion from SPIR-V Scope into OpenCL memory_scope.
577+ // /
578+ // / Supports both constant and non-constant values. To handle the latter case,
579+ // / function with switch..case statement will be inserted into module which
580+ // / \arg InsertBefore belongs to (in order to perform mapping at runtime)
581+ // /
582+ // / \param [in] MemScope Scope value which needs to be translated
583+ // / \param [in] InsertBefore insertion point for call into conversion function
584+ // / which is generated if \arg MemScope is not a constant
585+ // / \returns \c Value corresponding to OpenCL memory_scope equivalent to SPIR-V
586+ // / Scope passed in \arg MemScope
587+ Value *transSPIRVMemoryScopeIntoOCLMemoryScope (Value *MemScope,
588+ Instruction *InsertBefore);
589+
590+ // / Performs conversion from SPIR-V Memory Semantics into OpenCL memory_order.
591+ // /
592+ // / Supports both constant and non-constant values. To handle the latter case,
593+ // / function with switch..case statement will be inserted into module which
594+ // / \arg InsertBefore belongs to (in order to perform mapping at runtime)
595+ // /
596+ // / \param [in] MemorySemantics Memory Semantics value which needs to be
597+ // / translated
598+ // / \param [in] InsertBefore insertion point for call into conversion function
599+ // / which is generated if \arg MemorySemantics is not a constant
600+ // / \returns \c Value corresponding to OpenCL memory_order equivalent to SPIR-V
601+ // / Memory Semantics passed in \arg MemorySemantics
602+ Value *transSPIRVMemorySemanticsIntoOCLMemoryOrder (Value *MemorySemantics,
603+ Instruction *InsertBefore);
604+
605+ // / Performs conversion from SPIR-V Memory Semantics into OpenCL
606+ // / mem_fence_flags.
607+ // /
608+ // / Supports both constant and non-constant values. To handle the latter case,
609+ // / function with switch..case statement will be inserted into module which
610+ // / \arg InsertBefore belongs to (in order to perform mapping at runtime)
611+ // /
612+ // / \param [in] MemorySemantics Memory Semantics value which needs to be
613+ // / translated
614+ // / \param [in] InsertBefore insertion point for call into conversion function
615+ // / which is generated if \arg MemorySemantics is not a constant
616+ // / \returns \c Value corresponding to OpenCL mem_fence_flags equivalent to
617+ // / SPIR-V Memory Semantics passed in \arg MemorySemantics
618+ Value *transSPIRVMemorySemanticsIntoOCLMemFenceFlags (Value *MemorySemantics,
619+ Instruction *InsertBefore);
620+
541621template <> inline void SPIRVMap<std::string, SPIRVGroupOperationKind>::init() {
542622 add (" reduce" , GroupOperationReduce);
543623 add (" scan_inclusive" , GroupOperationInclusiveScan);
0 commit comments