Browse Source

Merged PR 113: Add -default-linkage option and export keyword

Add -default-linkage option and export keyword
Tex Riddell 7 years ago
parent
commit
178ffd1d71
72 changed files with 351 additions and 100 deletions
  1. 6 0
      include/dxc/HLSL/DxilConstants.h
  2. 5 0
      include/dxc/HLSL/HLModule.h
  3. 1 0
      include/dxc/Support/HLSLOptions.h
  4. 2 0
      include/dxc/Support/HLSLOptions.td
  5. 14 0
      lib/DxcSupport/HLSLOptions.cpp
  6. 8 0
      lib/HLSL/HLModule.cpp
  7. 6 0
      tools/clang/include/clang/Basic/Attr.td
  8. 3 0
      tools/clang/include/clang/Frontend/CodeGenOptions.h
  9. 20 0
      tools/clang/lib/CodeGen/CGHLSLMS.cpp
  10. 2 8
      tools/clang/lib/Parse/ParseDecl.cpp
  11. 1 0
      tools/clang/lib/Parse/ParseTentative.cpp
  12. 24 1
      tools/clang/lib/Sema/SemaHLSL.cpp
  13. 1 1
      tools/clang/test/CodeGenHLSL/lib_no_alias.hlsl
  14. 1 1
      tools/clang/test/CodeGenHLSL/lib_res_match.hlsl
  15. 1 1
      tools/clang/test/CodeGenHLSL/lib_resource.hlsl
  16. 1 1
      tools/clang/test/CodeGenHLSL/lib_unused_func.hlsl
  17. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/d3dreflect/raytracing_traceray.hlsl
  18. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/d3dreflect/reflect-lib-1.hlsl
  19. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/d3dreflect/structured_buffer_getdim_stride.hlsl
  20. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/fn_attr_experimental.hlsl
  21. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/half_mat.hlsl
  22. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/incomp_array.hlsl
  23. 40 0
      tools/clang/test/CodeGenHLSL/quick-test/lib_default_linkage.hlsl
  24. 40 0
      tools/clang/test/CodeGenHLSL/quick-test/lib_default_linkage_6_x.hlsl
  25. 40 0
      tools/clang/test/CodeGenHLSL/quick-test/lib_default_linkage_external.hlsl
  26. 40 0
      tools/clang/test/CodeGenHLSL/quick-test/lib_default_linkage_internal.hlsl
  27. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/lib_mat_array.hlsl
  28. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/lib_mat_cast.hlsl
  29. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/lib_mat_cast2.hlsl
  30. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/lib_mat_param8.hlsl
  31. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/lib_remove_res.hlsl
  32. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/lib_select_res.hlsl
  33. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/matrix_return_sub.hlsl
  34. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/noinline.hlsl
  35. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/raytracing_accept_ignore_hit_fail_lib.hlsl
  36. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/raytracing_builtin.hlsl
  37. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/raytracing_callshader.hlsl
  38. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/raytracing_reporthit.hlsl
  39. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/raytracing_sgv_intrin.hlsl
  40. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/raytracing_sgv_transforms.hlsl
  41. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/raytracing_sgv_transforms3x4.hlsl
  42. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/raytracing_sgv_transforms4x3.hlsl
  43. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/raytracing_traceray.hlsl
  44. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/res_in_struct.hlsl
  45. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/res_select2.hlsl
  46. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/res_select3.hlsl
  47. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/res_select4.hlsl
  48. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/res_select5.hlsl
  49. 1 1
      tools/clang/test/CodeGenHLSL/quick-test/structured_buffer_getdim_stride.hlsl
  50. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/createHandle_multi.hlsl
  51. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/createHandle_multi2.hlsl
  52. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/ignore_line_directives.hlsl
  53. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/inout_subscript.hlsl
  54. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_arg_flatten/lib_arg_flatten.hlsl
  55. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_arg_flatten/lib_arg_flatten2.hlsl
  56. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_arg_flatten/lib_arg_flatten3.hlsl
  57. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_arg_flatten/lib_arg_flatten4.hlsl
  58. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_arg_flatten/lib_empty_struct_arg.hlsl
  59. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_arg_flatten/lib_ret_struct.hlsl
  60. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_no_flat_extern_func.hlsl
  61. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_out_param_res.hlsl
  62. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_out_param_res_imp.hlsl
  63. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_out_undef.hlsl
  64. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_res_sel.hlsl
  65. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_ret_res.hlsl
  66. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_unresolved_func1.hlsl
  67. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_unresolved_func2.hlsl
  68. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/no_loop_unswitch.hlsl
  69. 1 1
      tools/clang/test/CodeGenHLSL/shader-compat-suite/static_const_field.hlsl
  70. 8 0
      tools/clang/tools/dxcompiler/dxcompilerobj.cpp
  71. 6 6
      tools/clang/unittests/HLSL/DxilContainerTest.cpp
  72. 32 32
      tools/clang/unittests/HLSL/ValidationTest.cpp

+ 6 - 0
include/dxc/HLSL/DxilConstants.h

@@ -248,6 +248,12 @@ namespace DXIL {
     Invalid,
   };
 
+  enum class DefaultLinkage : unsigned {
+    Default = 0,
+    Internal = 1,
+    External = 2,
+  };
+
   enum class SamplerKind : unsigned {
     Default = 0,
     Comparison,

+ 5 - 0
include/dxc/HLSL/HLModule.h

@@ -156,6 +156,10 @@ public:
   void SetFloat32DenormMode(const DXIL::Float32DenormMode mode);
   DXIL::Float32DenormMode GetFloat32DenormMode() const;
 
+  // Default function linkage for libraries
+  DXIL::DefaultLinkage GetDefaultLinkage() const;
+  void SetDefaultLinkage(const DXIL::DefaultLinkage linkage);
+
   // HLDXIR metadata manipulation.
   /// Serialize HLDXIR in-memory form to metadata form.
   void EmitHLMetadata();
@@ -275,6 +279,7 @@ private:
   std::unique_ptr<OP> m_pOP;
   size_t m_pUnused;
   uint32_t m_AutoBindingSpace;
+  DXIL::DefaultLinkage m_DefaultLinkage;
 
   // DXIL metadata serialization/deserialization.
   llvm::MDTuple *EmitHLResources();

+ 1 - 0
include/dxc/Support/HLSLOptions.h

@@ -110,6 +110,7 @@ public:
   llvm::StringRef RootSignatureDefine; // OPT_rootsig_define
   llvm::StringRef FloatDenormalMode; // OPT_denorm
   std::vector<std::string> Exports; // OPT_exports
+  llvm::StringRef DefaultLinkage; // OPT_default_linkage
 
   bool AllResourcesBound = false; // OPT_all_resources_bound
   bool AstDump = false; // OPT_ast_dump

+ 2 - 0
include/dxc/Support/HLSLOptions.td

@@ -238,6 +238,8 @@ def exports : Separate<["-", "/"], "exports">, Group<hlslcomp_Group>, Flags<[Cor
   HelpText<"Specify exports when compiling a library: export1[[,export1_clone,...]=internal_name][;...]">;
 def export_shaders_only : Flag<["-", "/"], "export-shaders-only">, Group<hlslcomp_Group>, Flags<[CoreOption]>,
   HelpText<"Only export shaders when compiling a library">;
+def default_linkage : Separate<["-", "/"], "default-linkage">, Group<hlslcomp_Group>, Flags<[CoreOption]>,
+  HelpText<"Set default linkage for non-shader functions when compiling or linking to a library target (internal, external)">;
 
 // SPIRV Change Starts
 def spirv : Flag<["-"], "spirv">, Group<spirv_Group>, Flags<[CoreOption, DriverOption]>,

+ 14 - 0
lib/DxcSupport/HLSLOptions.cpp

@@ -304,9 +304,13 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
     } else if (Args.hasFlag(OPT_export_shaders_only, OPT_INVALID, false)) {
       errors << "library profile required when using -export-shaders-only option";
       return 1;
+    } else if (Args.getLastArg(OPT_default_linkage)) {
+      errors << "library profile required when using -default-linkage option";
+      return 1;
     }
   }
 
+
   llvm::StringRef ver = Args.getLastArgValue(OPT_hlsl_version);
   if (ver.empty()) { opts.HLSLVersion = 2018; }   // Default to latest version
   else {
@@ -392,6 +396,16 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
 
   opts.Exports = Args.getAllArgValues(OPT_exports);
 
+  opts.DefaultLinkage = Args.getLastArgValue(OPT_default_linkage);
+  if (!opts.DefaultLinkage.empty()) {
+    if (!(opts.DefaultLinkage.equals_lower("internal") ||
+          opts.DefaultLinkage.equals_lower("external"))) {
+      errors << "Unsupported value '" << opts.DefaultLinkage
+             << "for -default-linkage option.";
+      return 1;
+    }
+  }
+
   // Check options only allowed in shader model >= 6.2FPDenormalMode
   unsigned Major = 0;
   unsigned Minor = 0;

+ 8 - 0
lib/HLSL/HLModule.cpp

@@ -429,6 +429,14 @@ void HLModule::SetFloat32DenormMode(const DXIL::Float32DenormMode mode) {
   m_Float32DenormMode = mode;
 }
 
+DXIL::DefaultLinkage HLModule::GetDefaultLinkage() const {
+  return m_DefaultLinkage;
+}
+
+void HLModule::SetDefaultLinkage(const DXIL::DefaultLinkage linkage) {
+  m_DefaultLinkage = linkage;
+}
+
 static const StringRef kHLDxilFunctionPropertiesMDName           = "dx.fnprops";
 static const StringRef kHLDxilOptionsMDName                      = "dx.options";
 static const StringRef kHLDxilResourceTypeAnnotationMDName       = "dx.resource.type.annotation";

+ 6 - 0
tools/clang/include/clang/Basic/Attr.td

@@ -865,6 +865,12 @@ def HLSLExperimental : InheritableAttr {
   let Documentation = [Undocumented];
 }
 
+def HLSLExport : InheritableAttr {
+  let Spellings = [CXX11<"", "export", 2015>];
+  let Subjects = SubjectList<[Function], ErrorDiag, "ExpectedFunction">;
+  let Documentation = [Undocumented];
+}
+
 // HLSL Change Ends
 
 // SPIRV Change Starts

+ 3 - 0
tools/clang/include/clang/Frontend/CodeGenOptions.h

@@ -206,6 +206,9 @@ public:
   std::vector<std::string> HLSLLibraryExports;
   /// ExportShadersOnly limits library export functions to shaders
   bool ExportShadersOnly = false;
+  /// DefaultLinkage Internal, External, or Default.  If Default, default
+  /// function linkage is determined by library target.
+  hlsl::DXIL::DefaultLinkage DefaultLinkage = hlsl::DXIL::DefaultLinkage::Default;
   // HLSL Change Ends
   /// Regular expression to select optimizations for which we should enable
   /// optimization remarks. Transformation passes whose name matches this

+ 20 - 0
tools/clang/lib/CodeGen/CGHLSLMS.cpp

@@ -421,6 +421,9 @@ CGMSHLSLRuntime::CGMSHLSLRuntime(CodeGenModule &CGM)
   // set Float Denorm Mode
   m_pHLModule->SetFloat32DenormMode(CGM.getCodeGenOpts().HLSLFloat32DenormMode);
 
+  // set DefaultLinkage
+  m_pHLModule->SetDefaultLinkage(CGM.getCodeGenOpts().DefaultLinkage);
+
   // Fill in m_ExportMap, which maps from internal name to zero or more renames
   m_ExportMap.clear();
   std::string errors;
@@ -1956,6 +1959,23 @@ void CGMSHLSLRuntime::EmitHLSLFunctionProlog(Function *F, const FunctionDecl *FD
 
     clipPlaneFuncList.emplace_back(F);
   }
+
+  // Update function linkage based on DefaultLinkage
+  if (!m_pHLModule->HasDxilFunctionProps(F) && !IsPatchConstantFunction(F)) {
+    if (F->getLinkage() == GlobalValue::LinkageTypes::ExternalLinkage) {
+      if (!FD->hasAttr<HLSLExportAttr>()) {
+        switch (CGM.getCodeGenOpts().DefaultLinkage) {
+        case DXIL::DefaultLinkage::Default:
+          if (m_pHLModule->GetShaderModel()->GetMinor() != ShaderModel::kOfflineMinor)
+            F->setLinkage(GlobalValue::LinkageTypes::InternalLinkage);
+          break;
+        case DXIL::DefaultLinkage::Internal:
+          F->setLinkage(GlobalValue::LinkageTypes::InternalLinkage);
+          break;
+        }
+      }
+    }
+  }
 }
 
 void CGMSHLSLRuntime::AddControlFlowHint(CodeGenFunction &CGF, const Stmt &S,

+ 2 - 8
tools/clang/lib/Parse/ParseDecl.cpp

@@ -1905,14 +1905,6 @@ Parser::DeclGroupPtrTy Parser::ParseDeclaration(unsigned Context,
     ProhibitAttributes(attrs);
     SingleDecl = ParseDeclarationStartingWithTemplate(Context, DeclEnd);
     break;
-    // HLSL Change Begin.
-  case tok::kw_export:
-    // Ignore export for now.
-    ConsumeToken();
-    return ParseSimpleDeclaration(Context, DeclEnd, attrs,
-                                  true);
-    break;
-    // HLSL Change End.
   case tok::kw_inline:
     // Could be the start of an inline namespace. Allowed as an ext in C++03.
     if (getLangOpts().CPlusPlus && NextToken().is(tok::kw_namespace) && !getLangOpts().HLSL) { // HLSL Change - disallowed in HLSL
@@ -3737,6 +3729,7 @@ HLSLReservedKeyword:
     case tok::kw_lineadj:
     case tok::kw_triangle:
     case tok::kw_triangleadj:
+    case tok::kw_export:
       if (getLangOpts().HLSL) {
         if (DS.getTypeSpecType() != DeclSpec::TST_unspecified) {
           PrevSpec = "";
@@ -5200,6 +5193,7 @@ bool Parser::isDeclarationSpecifier(bool DisambiguatingWithExpression) {
   case tok::kw_lineadj:
   case tok::kw_triangle:
   case tok::kw_triangleadj:
+  case tok::kw_export:
     return true;
   // HLSL Change Ends
 

+ 1 - 0
tools/clang/lib/Parse/ParseTentative.cpp

@@ -1306,6 +1306,7 @@ Parser::isCXXDeclarationSpecifier(Parser::TPResult BracedCastResult,
   case tok::kw_lineadj:
   case tok::kw_triangle:
   case tok::kw_triangleadj:
+  case tok::kw_export:
     return TPResult::True;
   // HLSL Change Ends
 

+ 24 - 1
tools/clang/lib/Sema/SemaHLSL.cpp

@@ -10674,6 +10674,9 @@ void hlsl::HandleDeclAttributeForHLSL(Sema &S, Decl *D, const AttributeList &A,
   case AttributeList::AT_NoInline:
     declAttr = ::new (S.Context) NoInlineAttr(A.getRange(), S.Context, A.getAttributeSpellingListIndex());
     break;
+  case AttributeList::AT_HLSLExport:
+    declAttr = ::new (S.Context) HLSLExportAttr(A.getRange(), S.Context, A.getAttributeSpellingListIndex());
+    break;
   default:
     Handled = false;
     break;  // SPIRV Change: was return;
@@ -11364,6 +11367,20 @@ bool Sema::DiagnoseHLSLDecl(Declarator &D, DeclContext *DC,
       pTopology = pAttr;
       break;
 
+    case AttributeList::AT_HLSLExport:
+      if (!isFunction) {
+        Diag(pAttr->getLoc(), diag::err_hlsl_varmodifierna)
+          << pAttr->getName() << declarationType << pAttr->getRange();
+        result = false;
+      }
+      if (isStatic) {
+        Diag(pAttr->getLoc(), diag::err_hlsl_varmodifiersna)
+          << "'static'" << pAttr->getName() << declarationType
+          << pAttr->getRange();
+        result = false;
+      }
+      break;
+
     default:
       break;
     }
@@ -11834,7 +11851,12 @@ void hlsl::CustomPrintHLSLAttr(const clang::Attr *A, llvm::raw_ostream &Out, con
     Out << "[noinline]\n";
     break;
 
-  // Statement attributes
+  case clang::attr::HLSLExport:
+    Indent(Indentation, Out);
+    Out << "export\n";
+    break;
+
+    // Statement attributes
   case clang::attr::HLSLAllowUAVCondition:
     Indent(Indentation, Out);
     Out << "[allow_uav_condition]\n";
@@ -11983,6 +12005,7 @@ bool hlsl::IsHLSLAttr(clang::attr::Kind AttrKind) {
   case clang::attr::HLSLTriangleAdj:
   case clang::attr::HLSLGloballyCoherent:
   case clang::attr::NoInline:
+  case clang::attr::HLSLExport:
   case clang::attr::VKBinding:
   case clang::attr::VKBuiltIn:
   case clang::attr::VKConstantId:

+ 1 - 1
tools/clang/test/CodeGenHLSL/lib_no_alias.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Make sure out param has no-alias.
 // CHECK: float @"\01?test@@YAMMUT@@AIAV?$matrix@M$01$01@@M@Z"(float %a, %struct.T* noalias nocapture %t, %class.matrix.float.2.2* noalias nocapture dereferenceable(16) %m, float %b)

+ 1 - 1
tools/clang/test/CodeGenHLSL/lib_res_match.hlsl

@@ -10,6 +10,6 @@ cbuffer A {
 Texture2D	tex;
 SamplerState	samp;
 
-float GetV() {
+export float GetV() {
   return v + tex.Load(uint3(a, v, a)).y;
 }

+ 1 - 1
tools/clang/test/CodeGenHLSL/lib_resource.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Make sure globals for resource exist.
 // CHECK: @"\01?g_txDiffuse@@3V?$Texture2D@V?$vector@M$03@@@@A" = external constant %"class.Texture2D<vector<float, 4> >", align 4

+ 1 - 1
tools/clang/test/CodeGenHLSL/lib_unused_func.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Make sure all function still exist.
 // CHECK: unused

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/d3dreflect/raytracing_traceray.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | %D3DReflect %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | %D3DReflect %s | FileCheck %s
 
 struct Payload {
    float2 t;

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/d3dreflect/reflect-lib-1.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | %D3DReflect %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | %D3DReflect %s | FileCheck %s
 
 float cbval1;
 cbuffer MyCB : register(b11, space2) { int4 cbval2, cbval3; }

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/d3dreflect/structured_buffer_getdim_stride.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | %D3DReflect %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | %D3DReflect %s | FileCheck %s
 
 struct Foo
 {

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/fn_attr_experimental.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // CHECK: define <4 x float>
 // CHECK: fn1

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/half_mat.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -enable-16bit-types -T lib_6_3 %s | FileCheck %s
+// RUN: %dxc -enable-16bit-types -T lib_6_3 -default-linkage external %s | FileCheck %s
 
 // CHECK: %class.matrix.half.4.3 = type { [4 x <3 x half>] }
 

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/incomp_array.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Verify no hang on incomplete array
 

+ 40 - 0
tools/clang/test/CodeGenHLSL/quick-test/lib_default_linkage.hlsl

@@ -0,0 +1,40 @@
+// RUN: %dxc -auto-binding-space 13 -T lib_6_3 %s | FileCheck %s
+
+// always has export_fn
+// CHECK: define float @"\01?export_fn
+// never has static_fn
+// CHECK-NOT: static_fn
+// default_fn depends on target (6.3 default is internal)
+// CHECK-NOT: define float @"\01?defaut_fn
+
+// Always has entry points:
+// CHECK: define void @"\01?AnyHit
+// CHECK: define void @"\01?Callable
+// CHECK: define void @PSMain
+
+export float export_fn() { return 2.0; }
+static float static_fn() { return 1.0; }
+float defaut_fn() { return 3.0; }
+
+struct Payload {
+  float f;
+};
+
+[shader("anyhit")]
+void AnyHit(inout Payload p, BuiltInTriangleIntersectionAttributes a) {
+  p.f += a.barycentrics.x;
+  if (p.f > 1.0)
+    AcceptHitAndEndSearch();
+  p.f += a.barycentrics.y;
+}
+
+[shader("callable")]
+void Callable(inout Payload p) {
+  p.f += 0.2;
+}
+
+[shader("pixel")]
+float4 PSMain(float2 coord : TEXCOORD) : SV_Target {
+  return coord.xyxy;
+}
+

+ 40 - 0
tools/clang/test/CodeGenHLSL/quick-test/lib_default_linkage_6_x.hlsl

@@ -0,0 +1,40 @@
+// RUN: %dxc -auto-binding-space 13 -T lib_6_x %s | FileCheck %s
+
+// always has export_fn
+// CHECK: define float @"\01?export_fn
+// never has static_fn
+// CHECK-NOT: static_fn
+// default_fn depends on target (6.x default is external)
+// CHECK: define float @"\01?defaut_fn
+
+// Always has entry points:
+// CHECK: define void @"\01?AnyHit
+// CHECK: define void @"\01?Callable
+// CHECK: define void @PSMain
+
+export float export_fn() { return 2.0; }
+static float static_fn() { return 1.0; }
+float defaut_fn() { return 3.0; }
+
+struct Payload {
+  float f;
+};
+
+[shader("anyhit")]
+void AnyHit(inout Payload p, BuiltInTriangleIntersectionAttributes a) {
+  p.f += a.barycentrics.x;
+  if (p.f > 1.0)
+    AcceptHitAndEndSearch();
+  p.f += a.barycentrics.y;
+}
+
+[shader("callable")]
+void Callable(inout Payload p) {
+  p.f += 0.2;
+}
+
+[shader("pixel")]
+float4 PSMain(float2 coord : TEXCOORD) : SV_Target {
+  return coord.xyxy;
+}
+

+ 40 - 0
tools/clang/test/CodeGenHLSL/quick-test/lib_default_linkage_external.hlsl

@@ -0,0 +1,40 @@
+// RUN: %dxc -auto-binding-space 13 -T lib_6_3 -default-linkage external %s | FileCheck %s
+
+// always has export_fn
+// CHECK: define float @"\01?export_fn
+// never has static_fn
+// CHECK-NOT: static_fn
+// has default_fn (default external)
+// CHECK: define float @"\01?defaut_fn
+
+// Always has entry points:
+// CHECK: define void @"\01?AnyHit
+// CHECK: define void @"\01?Callable
+// CHECK: define void @PSMain
+
+export float export_fn() { return 2.0; }
+static float static_fn() { return 1.0; }
+float defaut_fn() { return 3.0; }
+
+struct Payload {
+  float f;
+};
+
+[shader("anyhit")]
+void AnyHit(inout Payload p, BuiltInTriangleIntersectionAttributes a) {
+  p.f += a.barycentrics.x;
+  if (p.f > 1.0)
+    AcceptHitAndEndSearch();
+  p.f += a.barycentrics.y;
+}
+
+[shader("callable")]
+void Callable(inout Payload p) {
+  p.f += 0.2;
+}
+
+[shader("pixel")]
+float4 PSMain(float2 coord : TEXCOORD) : SV_Target {
+  return coord.xyxy;
+}
+

+ 40 - 0
tools/clang/test/CodeGenHLSL/quick-test/lib_default_linkage_internal.hlsl

@@ -0,0 +1,40 @@
+// RUN: %dxc -auto-binding-space 13 -T lib_6_x -default-linkage internal %s | FileCheck %s
+
+// always has export_fn
+// CHECK: define float @"\01?export_fn
+// never has static_fn
+// CHECK-NOT: static_fn
+// does not have default_fn (default internal)
+// CHECK-NOT: defaut_fn
+
+// Always has entry points:
+// CHECK: define void @"\01?AnyHit
+// CHECK: define void @"\01?Callable
+// CHECK: define void @PSMain
+
+export float export_fn() { return 2.0; }
+static float static_fn() { return 1.0; }
+float defaut_fn() { return 3.0; }
+
+struct Payload {
+  float f;
+};
+
+[shader("anyhit")]
+void AnyHit(inout Payload p, BuiltInTriangleIntersectionAttributes a) {
+  p.f += a.barycentrics.x;
+  if (p.f > 1.0)
+    AcceptHitAndEndSearch();
+  p.f += a.barycentrics.y;
+}
+
+[shader("callable")]
+void Callable(inout Payload p) {
+  p.f += 0.2;
+}
+
+[shader("pixel")]
+float4 PSMain(float2 coord : TEXCOORD) : SV_Target {
+  return coord.xyxy;
+}
+

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/lib_mat_array.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -Zpr %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external -Zpr %s | FileCheck %s
 
 // check that matrix lowering succeeds
 // CHECK-NOT: Fail to lower matrix load/store.

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/lib_mat_cast.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3  %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -default-linkage external %s | FileCheck %s
 
 // CHECK: bitcast %class.matrix.float.4.3* {{.*}} to <12 x float>*
 

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/lib_mat_cast2.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3  %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -default-linkage external %s | FileCheck %s
 
 // CHECK: bitcast %class.matrix.float.4.3* {{.*}} to <12 x float>*
 

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/lib_mat_param8.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3  %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -default-linkage external %s | FileCheck %s
 
 // Make sure return matrix struct works.
 // CHECK: bitcast %class.matrix.float.3.2* {{.*}} to <6 x float>*

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/lib_remove_res.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Ensure UnusedBuffer is removed:
 // CHECK-NOT: @"\01?UnusedBuffer@@3UByteAddressBuffer@@A"

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/lib_select_res.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -Zi -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -Zi -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // resource uses must resolve to a single resource global variable (single rangeID)
 // CHECK: local resource not guaranteed to map to unique global resource

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/matrix_return_sub.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -default-linkage external %s | FileCheck %s
 
 // Make sure this works on intrinsic that returns matrix
 // CHECK: call float @dx.op.worldToObject.f32(i32 152, i32 0, i8 1)

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/noinline.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Make sure noinline is present
 // CHECK: noinline

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/raytracing_accept_ignore_hit_fail_lib.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // verify failure for exported library function
 // CHECK: Opcode IgnoreHit not valid in shader model lib_6_3(lib)

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/raytracing_builtin.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // CHECK: %struct.BuiltInTriangleIntersectionAttributes
 

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/raytracing_callshader.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // CHECK: call void @dx.op.callShader.struct.Parameter(i32 159
 

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/raytracing_reporthit.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // CHECK: call i1 @dx.op.reportHit.struct.Attr(i32 158
 

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/raytracing_sgv_intrin.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // CHECK: call i32 @dx.op.dispatchRaysIndex.i32(i32 145, i8 0)
 // CHECK: call i32 @dx.op.dispatchRaysIndex.i32(i32 145, i8 1)

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/raytracing_sgv_transforms.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // CHECK: call float @dx.op.objectToWorld.f32(i32 151, i32 0, i8 0)
 // CHECK: call float @dx.op.objectToWorld.f32(i32 151, i32 0, i8 1)

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/raytracing_sgv_transforms3x4.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // CHECK: call float @dx.op.objectToWorld.f32(i32 151, i32 2, i8 0)
 // CHECK: call float @dx.op.objectToWorld.f32(i32 151, i32 2, i8 1)

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/raytracing_sgv_transforms4x3.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // CHECK: call float @dx.op.objectToWorld.f32(i32 151, i32 2, i8 0)
 // CHECK: call float @dx.op.objectToWorld.f32(i32 151, i32 2, i8 1)

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/raytracing_traceray.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // CHECK: call void @dx.op.traceRay.struct.Payload(i32 157,
 

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/res_in_struct.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_2 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -default-linkage external %s | FileCheck %s
 
 // resources in return/params disallowed for lib_6_3
 // CHECK: error: Exported function

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/res_select2.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Make sure index allocas are present for each dim of global resource
 // This handles local resource array with dynamic indexing

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/res_select3.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Make sure no phi/select of handle in lib.
 // CHECK: entry:

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/res_select4.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Make sure this fails
 // CHECK: error: local resource not guaranteed to map to unique global resource

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/res_select5.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Make sure this fails
 // CHECK: error: local resource not guaranteed to map to unique global resource

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/structured_buffer_getdim_stride.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // CHECK: ret i32 20
 

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/createHandle_multi.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s  | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s  | FileCheck %s
 
 // CHECK: %"class.Texture2D<float>" = type { float
 // CHECK: %"class.Texture2D<vector<float, 4> >" = type { <4 x float>

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/createHandle_multi2.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s  | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s  | FileCheck %s
 
 // CHECK: %"class.Texture2D<vector<float, 4> >" = type { <4 x float>
 // CHECK: %"class.Texture2D<float>" = type { float

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/ignore_line_directives.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -Zi  -ignore-line-directives %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external -Zi  -ignore-line-directives %s | FileCheck %s
 
 // Make sure only 1 DIFile exist in debug info when NoLineDirectives is enabled.
 // CHECK: !DIFile

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/inout_subscript.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Make sure subscript on inout vector works.
 // CHECK: noalias

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_arg_flatten/lib_arg_flatten.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Make sure function call on external function has correct type.
 // CHECK: call float @"\01?test_extern@@YAMUT@@Y01U1@U1@AIAV?$matrix@M$01$01@@@Z"(%struct.T* {{.*}}, [2 x %struct.T]* {{.*}}, %struct.T* nonnull {{.*}}, %class.matrix.float.2.2* dereferenceable(16) {{.*}})

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_arg_flatten/lib_arg_flatten2.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Make sure no undef in test3.
 // CHECK: define <4 x float>

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_arg_flatten/lib_arg_flatten3.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Make sure function call on external function has correct type.
 

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_arg_flatten/lib_arg_flatten4.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Make sure function call on external function has correct type.
 

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_arg_flatten/lib_empty_struct_arg.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Make sure empty struct arg works.
 // CHECK: call float @"\01?test@@YAMUT@@@Z"(%struct.T* %t)

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_arg_flatten/lib_ret_struct.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Make sure struct param used as out arg works.
 

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_no_flat_extern_func.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Make sure extern function don't need to flat is called.
 // CHECK: call void @"\01?test@@YAXMAIAM@Z"

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_out_param_res.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // resources in return/params disallowed for lib_6_3
 // CHECK: error: Exported function

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_out_param_res_imp.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // resources in return/params disallowed for lib_6_3
 // CHECK: error: Exported function

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_out_undef.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -Zpr %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external -Zpr %s | FileCheck %s
 
 // CHECK: call void @"\01?GetMat
 // CHECK-NOT: undef

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_res_sel.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // resource uses must resolve to a single resource global variable (single rangeID)
 // CHECK: error: local resource not guaranteed to map to unique global resource

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_ret_res.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -Zi -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -Zi -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // resources in return/params disallowed for lib_6_3
 // CHECK: error: Exported function

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_unresolved_func1.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // CHECK-DAG: define float @"\01?lib1_fn@@YAMXZ"()
 // CHECK-DAG: declare float @"\01?external_fn@@YAMXZ"()

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_unresolved_func2.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // CHECK-DAG: define float @"\01?lib2_fn@@YAMXZ"()
 // CHECK-DAG: declare float @"\01?external_fn@@YAMXZ"()

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/no_loop_unswitch.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Make sure only 1 barrier.
 // CHECK: call void @dx.op.barrier(i32 80, i32 9)

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/static_const_field.hlsl

@@ -1,4 +1,4 @@
-// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
 
 // Make sure static const field works.
 

+ 8 - 0
tools/clang/tools/dxcompiler/dxcompilerobj.cpp

@@ -937,6 +937,14 @@ public:
 
     // only export shader functions for library
     compiler.getCodeGenOpts().ExportShadersOnly = Opts.ExportShadersOnly;
+
+    if (Opts.DefaultLinkage.empty()) {
+      compiler.getCodeGenOpts().DefaultLinkage = DXIL::DefaultLinkage::Default;
+    } else if (Opts.DefaultLinkage.equals_lower("internal")) {
+      compiler.getCodeGenOpts().DefaultLinkage = DXIL::DefaultLinkage::Internal;
+    } else if (Opts.DefaultLinkage.equals_lower("external")) {
+      compiler.getCodeGenOpts().DefaultLinkage = DXIL::DefaultLinkage::External;
+    }
   }
 
   // IDxcVersionInfo

+ 6 - 6
tools/clang/unittests/HLSL/DxilContainerTest.cpp

@@ -680,12 +680,12 @@ TEST_F(DxilContainerTest, CompileWhenOkThenCheckRDAT) {
     "RasterizerOrderedByteAddressBuffer rov_buf;"
     "globallycoherent RWByteAddressBuffer gc_buf;"
     "float function_import(float x);"
-    "float function0(min16float x) { "
+    "export float function0(min16float x) { "
     "  return x + 1 + tex[0].x; }"
-    "float function1(float x, min12int i) {"
+    "export float function1(float x, min12int i) {"
     "  return x + c_buf + b_buf.Load(x) + tex2[i].x; }"
-    "float function2(float x) { return x + function_import(x); }"
-    "void function3(int i) {"
+    "export float function2(float x) { return x + function_import(x); }"
+    "export void function3(int i) {"
     "  Foo f = consume_buf.Consume();"
     "  f.f2 += 0.5; append_buf.Append(f);"
     "  rov_buf.Store(i, f.i2.x);"
@@ -1065,9 +1065,9 @@ TEST_F(DxilContainerTest, CompileWhenOkThenCheckReflection1) {
     "Texture1D<float4> tex2 : register(t0);"
     "SamplerState samp : register(s7);"
     "RWByteAddressBuffer b_buf;"
-    "float function0(min16float x) { "
+    "export float function0(min16float x) { "
     "  return x + cbval2.x + tex[0].x; }"
-    "float function1(float x, min12int i) {"
+    "export float function1(float x, min12int i) {"
     "  return x + cbval1 + b_buf.Load(x) + tex2.Sample(samp, x).x; }"
     "[shader(\"vertex\")]"
     "float function2(float4 x : POSITION) : SV_Position { return x + cbval1 + cbval3.x; }";

+ 32 - 32
tools/clang/unittests/HLSL/ValidationTest.cpp

@@ -2927,8 +2927,8 @@ TEST_F(ValidationTest, WhenPSVMismatchThenFail) {
 
 TEST_F(ValidationTest, WhenRDATMismatchThenFail) {
   ReplaceContainerPartsCheckMsgs(
-    "float4 main(float f) : semantic { return f; }",
-    "float4 main() : semantic { return 0; }",
+    "export float4 main(float f) : semantic { return f; }",
+    "export float4 main() : semantic { return 0; }",
     "lib_6_3",
     { DFCC_RuntimeData },
     {
@@ -3162,7 +3162,7 @@ TEST_F(ValidationTest, Float32DenormModeAttribute) {
 TEST_F(ValidationTest, ResCounter) {
     if (m_ver.SkipDxilVersion(1, 3)) return;
     RewriteAssemblyCheckMsg(
-        "RWStructuredBuffer<float4> buf; float GetCounter() {return buf.IncrementCounter();}",
+        "RWStructuredBuffer<float4> buf; export float GetCounter() {return buf.IncrementCounter();}",
         "lib_6_3",
         { "!\"buf\", i32 0, i32 -1, i32 1, i32 12, i1 false, i1 true, i1 false, !" },
         { "!\"buf\", i32 0, i32 -1, i32 1, i32 12, i1 false, i1 false, i1 false, !" },
@@ -3214,11 +3214,11 @@ TEST_F(ValidationTest, RayPayloadIsStruct) {
   RewriteAssemblyCheckMsg(
     "struct Payload { float f; }; struct Attributes { float2 b; };\n"
     "[shader(\"anyhit\")] void AnyHitProto(inout Payload p, in Attributes a) { p.f += a.b.x; }\n"
-    "void BadAnyHit(inout float f, in Attributes a) { f += a.b.x; }\n"
+    "export void BadAnyHit(inout float f, in Attributes a) { f += a.b.x; }\n"
     "[shader(\"closesthit\")] void ClosestHitProto(inout Payload p, in Attributes a) { p.f += a.b.y; }\n"
-    "void BadClosestHit(inout float f, in Attributes a) { f += a.b.y; }\n"
+    "export void BadClosestHit(inout float f, in Attributes a) { f += a.b.y; }\n"
     "[shader(\"miss\")] void MissProto(inout Payload p) { p.f += 1.0; }\n"
-    "void BadMiss(inout float f) { f += 1.0; }\n"
+    "export void BadMiss(inout float f) { f += 1.0; }\n"
     , "lib_6_3",
     { "!{void (%struct.Payload*, %struct.Attributes*)* @\"\\01?AnyHitProto@@YAXUPayload@@UAttributes@@@Z\", "
         "!\"\\01?AnyHitProto@@YAXUPayload@@UAttributes@@@Z\",",
@@ -3246,9 +3246,9 @@ TEST_F(ValidationTest, RayAttrIsStruct) {
   RewriteAssemblyCheckMsg(
     "struct Payload { float f; }; struct Attributes { float2 b; };\n"
     "[shader(\"anyhit\")] void AnyHitProto(inout Payload p, in Attributes a) { p.f += a.b.x; }\n"
-    "void BadAnyHit(inout Payload p, in float a) { p.f += a; }\n"
+    "export void BadAnyHit(inout Payload p, in float a) { p.f += a; }\n"
     "[shader(\"closesthit\")] void ClosestHitProto(inout Payload p, in Attributes a) { p.f += a.b.y; }\n"
-    "void BadClosestHit(inout Payload p, in float a) { p.f += a; }\n"
+    "export void BadClosestHit(inout Payload p, in float a) { p.f += a; }\n"
     , "lib_6_3",
     { "!{void (%struct.Payload*, %struct.Attributes*)* @\"\\01?AnyHitProto@@YAXUPayload@@UAttributes@@@Z\", "
         "!\"\\01?AnyHitProto@@YAXUPayload@@UAttributes@@@Z\",",
@@ -3271,7 +3271,7 @@ TEST_F(ValidationTest, CallableParamIsStruct) {
   RewriteAssemblyCheckMsg(
     "struct Param { float f; };\n"
     "[shader(\"callable\")] void CallableProto(inout Param p) { p.f += 1.0; }\n"
-    "void BadCallable(inout float f) { f += 1.0; }\n"
+    "export void BadCallable(inout float f) { f += 1.0; }\n"
     , "lib_6_3",
     { "!{void (%struct.Param*)* @\"\\01?CallableProto@@YAXUParam@@@Z\", "
         "!\"\\01?CallableProto@@YAXUParam@@@Z\","
@@ -3293,10 +3293,10 @@ TEST_F(ValidationTest, RayShaderExtraArg) {
     "[shader(\"closesthit\")] void ClosestHitProto(inout Payload p, in Attributes a) { p.f += a.b.y; }\n"
     "[shader(\"miss\")] void MissProto(inout Payload p) { p.f += 1.0; }\n"
     "[shader(\"callable\")] void CallableProto(inout Param p) { p.f += 1.0; }\n"
-    "void BadAnyHit(inout Payload p, in Attributes a, float f) { p.f += f; }\n"
-    "void BadClosestHit(inout Payload p, in Attributes a, float f) { p.f += f; }\n"
-    "void BadMiss(inout Payload p, float f) { p.f += f; }\n"
-    "void BadCallable(inout Param p, float f) { p.f += f; }\n"
+    "export void BadAnyHit(inout Payload p, in Attributes a, float f) { p.f += f; }\n"
+    "export void BadClosestHit(inout Payload p, in Attributes a, float f) { p.f += f; }\n"
+    "export void BadMiss(inout Payload p, float f) { p.f += f; }\n"
+    "export void BadCallable(inout Param p, float f) { p.f += f; }\n"
     , "lib_6_3",
     { "!{void (%struct.Payload*, %struct.Attributes*)* @\"\\01?AnyHitProto@@YAXUPayload@@UAttributes@@@Z\", "
         "!\"\\01?AnyHitProto@@YAXUPayload@@UAttributes@@@Z\"",
@@ -3332,14 +3332,14 @@ TEST_F(ValidationTest, ResInShaderStruct) {
     "struct ResStructInStruct { float f; ResInStruct S; };\n"
     "struct Payload { float f; }; struct Attributes { float2 b; };\n"
     "[shader(\"anyhit\")] void AnyHitProto(inout Payload p, in Attributes a) { p.f += a.b.x; }\n"
-    "void BadAnyHit(inout ResStructInStruct p, in Attributes a) { p.f += a.b.x; }\n"
+    "export void BadAnyHit(inout ResStructInStruct p, in Attributes a) { p.f += a.b.x; }\n"
     "[shader(\"closesthit\")] void ClosestHitProto(inout Payload p, in Attributes a) { p.f += a.b.y; }\n"
-    "void BadClosestHit(inout ResStructInStruct p, in Attributes a) { p.f += a.b.x; }\n"
+    "export void BadClosestHit(inout ResStructInStruct p, in Attributes a) { p.f += a.b.x; }\n"
     "[shader(\"miss\")] void MissProto(inout Payload p) { p.f += 1.0; }\n"
-    "void BadMiss(inout ResStructInStruct p) { p.f += 1.0; }\n"
+    "export void BadMiss(inout ResStructInStruct p) { p.f += 1.0; }\n"
     "struct Param { float f; };\n"
     "[shader(\"callable\")] void CallableProto(inout Param p) { p.f += 1.0; }\n"
-    "void BadCallable(inout ResStructInStruct p) { p.f += 1.0; }\n"
+    "export void BadCallable(inout ResStructInStruct p) { p.f += 1.0; }\n"
     , "lib_6_x",
     { "!{!\"lib\", i32 6, i32 15}", "!dx.valver = !{!2}",
       "!{void (%struct.Payload*, %struct.Attributes*)* @\"\\01?AnyHitProto@@YAXUPayload@@UAttributes@@@Z\", "
@@ -3383,12 +3383,12 @@ TEST_F(ValidationTest, WhenPayloadSizeTooSmallThenFail) {
     "\n"
     "struct BadPayload { float2 f; }; struct BadAttributes { float3 b; };\n"
     "struct BadParam { float2 f; };\n"
-    "void BadRayGen() { return; }\n"
-    "void BadIntersection() { return; }\n"
-    "void BadAnyHit(inout BadPayload p, in BadAttributes a) { p.f += a.b.x; }\n"
-    "void BadClosestHit(inout BadPayload p, in BadAttributes a) { p.f += a.b.y; }\n"
-    "void BadMiss(inout BadPayload p) { p.f += 1.0; }\n"
-    "void BadCallable(inout BadParam p) { p.f += 1.0; }\n"
+    "export void BadRayGen() { return; }\n"
+    "export void BadIntersection() { return; }\n"
+    "export void BadAnyHit(inout BadPayload p, in BadAttributes a) { p.f += a.b.x; }\n"
+    "export void BadClosestHit(inout BadPayload p, in BadAttributes a) { p.f += a.b.y; }\n"
+    "export void BadMiss(inout BadPayload p) { p.f += 1.0; }\n"
+    "export void BadCallable(inout BadParam p) { p.f += 1.0; }\n"
     , "lib_6_3",
     {  "!{void ()* @\"\\01?RayGenProto@@YAXXZ\", !\"\\01?RayGenProto@@YAXXZ\","
       ,"!{void ()* @\"\\01?IntersectionProto@@YAXXZ\", !\"\\01?IntersectionProto@@YAXXZ\","
@@ -3423,10 +3423,10 @@ TEST_F(ValidationTest, WhenMissingPayloadThenFail) {
     "[shader(\"closesthit\")] void ClosestHitProto(inout Payload p, in Attributes a) { p.f += a.b.y; }\n"
     "[shader(\"miss\")] void MissProto(inout Payload p) { p.f += 1.0; }\n"
     "[shader(\"callable\")] void CallableProto(inout Param p) { p.f += 1.0; }\n"
-    "void BadAnyHit(inout Payload p) { p.f += 1.0; }\n"
-    "void BadClosestHit() {}\n"
-    "void BadMiss() {}\n"
-    "void BadCallable() {}\n"
+    "export void BadAnyHit(inout Payload p) { p.f += 1.0; }\n"
+    "export void BadClosestHit() {}\n"
+    "export void BadMiss() {}\n"
+    "export void BadCallable() {}\n"
     , "lib_6_3",
     {  "!{void (%struct.Payload*, %struct.Attributes*)* @\"\\01?AnyHitProto@@YAXUPayload@@UAttributes@@@Z\", !\"\\01?AnyHitProto@@YAXUPayload@@UAttributes@@@Z\","
       ,"!{void (%struct.Payload*, %struct.Attributes*)* @\"\\01?ClosestHitProto@@YAXUPayload@@UAttributes@@@Z\", !\"\\01?ClosestHitProto@@YAXUPayload@@UAttributes@@@Z\","
@@ -3458,11 +3458,11 @@ TEST_F(ValidationTest, ShaderFunctionReturnTypeVoid) {
     "[shader(\"closesthit\")] void ClosestHitProto(inout Payload p, in Attributes a) { p.f += a.b.y; }\n"
     "[shader(\"miss\")] void MissProto(inout Payload p) { p.f += 1.0; }\n"
     "[shader(\"callable\")] void CallableProto(inout Param p) { p.f += 1.0; }\n"
-    "float BadRayGen() { return 1; }\n"
-    "float BadAnyHit(inout Payload p, in Attributes a) { return p.f; }\n"
-    "float BadClosestHit(inout Payload p, in Attributes a) { return p.f; }\n"
-    "float BadMiss(inout Payload p) { return p.f; }\n"
-    "float BadCallable(inout Param p) { return p.f; }\n"
+    "export float BadRayGen() { return 1; }\n"
+    "export float BadAnyHit(inout Payload p, in Attributes a) { return p.f; }\n"
+    "export float BadClosestHit(inout Payload p, in Attributes a) { return p.f; }\n"
+    "export float BadMiss(inout Payload p) { return p.f; }\n"
+    "export float BadCallable(inout Param p) { return p.f; }\n"
     , "lib_6_3",
     { "!{void ()* @\"\\01?RayGenProto@@YAXXZ\", "
         "!\"\\01?RayGenProto@@YAXXZ\",",