Browse Source

Don't export unused patch constant functions or candidates.

- also don't try to export unused patch constant functions when default
  is ExternalLinkage, when function is not compatible with linking.
Tex Riddell 7 years ago
parent
commit
6e9ba84de2
1 changed files with 27 additions and 1 deletions
  1. 27 1
      tools/clang/lib/CodeGen/CGHLSLMS.cpp

+ 27 - 1
tools/clang/lib/CodeGen/CGHLSLMS.cpp

@@ -1290,6 +1290,15 @@ void CGMSHLSLRuntime::AddHLSLFunctionInfo(Function *F, const FunctionDecl *FD) {
             GetHLSLInputPatchCount(parmDecl->getType());
             GetHLSLInputPatchCount(parmDecl->getType());
       }
       }
     }
     }
+
+    // Mark patch constant functions that cannot be linked as exports
+    // InternalLinkage.  Patch constant functions that are actually used
+    // will be set back to ExternalLinkage in FinishCodeGen.
+    if (funcProps->ShaderProps.HS.outputControlPoints ||
+        funcProps->ShaderProps.HS.inputControlPoints) {
+      PCI.Func->setLinkage(GlobalValue::InternalLinkage);
+    }
+
     funcProps->shaderKind = DXIL::ShaderKind::Hull;
     funcProps->shaderKind = DXIL::ShaderKind::Hull;
   }
   }
 
 
@@ -1970,7 +1979,8 @@ void CGMSHLSLRuntime::EmitHLSLFunctionProlog(Function *F, const FunctionDecl *FD
   }
   }
 
 
   // Update function linkage based on DefaultLinkage
   // Update function linkage based on DefaultLinkage
-  if (!m_pHLModule->HasDxilFunctionProps(F) && !IsPatchConstantFunction(F)) {
+  // We will take care of patch constant functions later, once identified for certain.
+  if (!m_pHLModule->HasDxilFunctionProps(F)) {
     if (F->getLinkage() == GlobalValue::LinkageTypes::ExternalLinkage) {
     if (F->getLinkage() == GlobalValue::LinkageTypes::ExternalLinkage) {
       if (!FD->hasAttr<HLSLExportAttr>()) {
       if (!FD->hasAttr<HLSLExportAttr>()) {
         switch (CGM.getCodeGenOpts().DefaultLinkage) {
         switch (CGM.getCodeGenOpts().DefaultLinkage) {
@@ -4723,6 +4733,22 @@ void CGMSHLSLRuntime::FinishCodeGen() {
     }
     }
   }
   }
 
 
+  // Now iterate hull shaders and make sure their corresponding patch constant
+  // functions are marked ExternalLinkage:
+  for (Function &f : m_pHLModule->GetModule()->functions()) {
+    if (f.isDeclaration() || f.isIntrinsic() ||
+        GetHLOpcodeGroup(&f) != HLOpcodeGroup::NotHL ||
+        f.getLinkage() != GlobalValue::LinkageTypes::ExternalLinkage ||
+        !m_pHLModule->HasDxilFunctionProps(&f))
+      continue;
+    DxilFunctionProps &props = m_pHLModule->GetDxilFunctionProps(&f);
+    if (!props.IsHS())
+      continue;
+    Function *PCFunc = props.ShaderProps.HS.patchConstantFunc;
+    if (PCFunc->getLinkage() != GlobalValue::LinkageTypes::ExternalLinkage)
+      PCFunc->setLinkage(GlobalValue::LinkageTypes::ExternalLinkage);
+  }
+
   // Disallow resource arguments in (non-entry) function exports
   // Disallow resource arguments in (non-entry) function exports
   // unless offline linking target.
   // unless offline linking target.
   if (m_bIsLib && m_pHLModule->GetShaderModel()->GetMinor() != ShaderModel::kOfflineMinor) {
   if (m_bIsLib && m_pHLModule->GetShaderModel()->GetMinor() != ShaderModel::kOfflineMinor) {