================
@@ -30,22 +30,36 @@
 #include <optional>
 #include <vector>
 
+#define GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(FunctionName,                 
\
+                                                 IntrinsicPostfix)             
\
+  GENERATE_HLSL_INTRINSIC_FUNCTION(FunctionName, IntrinsicPostfix, 1, 1)
+
 // A function generator macro for picking the right intrinsic
 // for the target backend
-#define GENERATE_HLSL_INTRINSIC_FUNCTION(FunctionName, IntrinsicPostfix)       
\
+#define GENERATE_HLSL_INTRINSIC_FUNCTION(FunctionName, IntrinsicPostfix,       
\
+                                         IncludeDXIL, IncludeSPIRV)            
\
   llvm::Intrinsic::ID get##FunctionName##Intrinsic() {                         
\
     llvm::Triple::ArchType Arch = getArch();                                   
\
     switch (Arch) {                                                            
\
-    case llvm::Triple::dxil:                                                   
\
-      return llvm::Intrinsic::dx_##IntrinsicPostfix;                           
\
-    case llvm::Triple::spirv:                                                  
\
-      return llvm::Intrinsic::spv_##IntrinsicPostfix;                          
\
+      /* Include DXIL case only if IncludeDXIL is true */                      
\
+      IF_INCLUDE(IncludeDXIL, case llvm::Triple::dxil                          
\
+                 : return llvm::Intrinsic::dx_##IntrinsicPostfix;)             
\
+      /* Include SPIRV case only if IncludeSPIRV is true */                    
\
+      IF_INCLUDE(IncludeSPIRV, case llvm::Triple::spirv                        
\
+                 : return llvm::Intrinsic::spv_##IntrinsicPostfix;)            
\
+                                                                               
\
     default:                                                                   
\
       llvm_unreachable("Intrinsic " #IntrinsicPostfix                          
\
                        " not supported by target architecture");               
\
     }                                                                          
\
   }
 
+#define IF_INCLUDE(Condition, Code) IF_INCLUDE_IMPL(Condition, Code)
+#define IF_INCLUDE_IMPL(Condition, Code) IF_INCLUDE_##Condition(Code)
+
+#define IF_INCLUDE_1(Code) Code
+#define IF_INCLUDE_0(Code)
----------------
farzonl wrote:

I don't see how creating target specific macros is better than just using 
`llvm::Intrinsic::spv_*` or `llvm::Intrinsic::dx_*`. The idea behind making it 
arguments is that if we have more targets after spv and dx we aren't adding an  
`N` number of new macros its just one more argument and one more `IF_INCLUDE` 
case block. 

instead of `DEFAULT` I could rename to `ALL`? 

- I could also make `GENERATE_HLSL_DX_INTRINSIC_FUNCTION`  --> 
`GENERATE_HLSL_INTRINSIC_FUNCTION(FunctionName, IntrinsicPostfix, 1, 0)` 
- and `GENERATE_HLSL_SPV_INTRINSIC_FUNCTION` --> 
`GENERATE_HLSL_INTRINSIC_FUNCTION(FunctionName, IntrinsicPostfix, 0, 1)`

 

https://github.com/llvm/llvm-project/pull/117648
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to