Browse Source

Delete code to remove unused functions which is done by ASTContext::DeclMustBeEmitted (#294)

Xiang Li 8 years ago
parent
commit
7e5a340e67

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

@@ -3766,44 +3766,6 @@ void CGMSHLSLRuntime::FinishCodeGen() {
     return;
   }
 
-  // Remove all useless functions.
-  if (!CGM.getCodeGenOpts().HLSLHighLevel) {
-    Function *patchConstantFunc = nullptr;
-    if (m_pHLModule->GetShaderModel()->IsHS()) {
-      patchConstantFunc = m_pHLModule->GetHLFunctionProps(EntryFunc)
-                              .ShaderProps.HS.patchConstantFunc;
-    }
-
-    std::unordered_set<Function *> DeadFuncSet;
-
-    for (auto FIt = TheModule.functions().begin(),
-              FE = TheModule.functions().end();
-         FIt != FE;) {
-      Function *F = FIt++;
-      if (F != EntryFunc && F != patchConstantFunc && !F->isDeclaration()) {
-        if (F->user_empty())
-          F->eraseFromParent();
-        else
-          DeadFuncSet.insert(F);
-      }
-    }
-
-    while (!DeadFuncSet.empty()) {
-      bool noUpdate = true;
-      for (auto FIt = DeadFuncSet.begin(), FE = DeadFuncSet.end(); FIt != FE;) {
-        Function *F = *(FIt++);
-        if (F->user_empty()) {
-          DeadFuncSet.erase(F);
-          F->eraseFromParent();
-          noUpdate = false;
-        }
-      }
-      // Avoid dead loop.
-      if (noUpdate)
-        break;
-    }
-  }
-
   // Create copy for clip plane.
   for (Function *F : clipPlaneFuncList) {
     HLFunctionProps &props = m_pHLModule->GetHLFunctionProps(F);

+ 15 - 0
tools/clang/test/CodeGenHLSL/unused_func.hlsl

@@ -0,0 +1,15 @@
+// RUN: %dxc -T ps_6_1 -fcgl %s | FileCheck %s
+
+// Make sure unused function not generated.
+// CHECK-NOT: unused
+
+float unused() {
+  return 3;
+}
+
+
+float4 main(float4 a : A) : SV_TARGET
+{
+  return a;
+}
+

+ 5 - 0
tools/clang/unittests/HLSL/CompilerTest.cpp

@@ -656,6 +656,7 @@ public:
   TEST_METHOD(CodeGenUmaxObjectAtomic)
   TEST_METHOD(CodeGenUnrollDbg)
   TEST_METHOD(CodeGenUnsignedShortHandMatrixVector)
+  TEST_METHOD(CodeGenUnusedFunc)
   TEST_METHOD(CodeGenUnusedCB)
   TEST_METHOD(CodeGenUpdateCounter)
   TEST_METHOD(CodeGenUpperCaseRegister1);
@@ -3354,6 +3355,10 @@ TEST_F(CompilerTest, CodeGenUnsignedShortHandMatrixVector) {
   CodeGenTestCheck(L"..\\CodeGenHLSL\\unsignedShortHandMatrixVector.hlsl");
 }
 
+TEST_F(CompilerTest, CodeGenUnusedFunc) {
+  CodeGenTestCheck(L"..\\CodeGenHLSL\\unused_func.hlsl");
+}
+
 TEST_F(CompilerTest, CodeGenUnusedCB) {
   CodeGenTestCheck(L"..\\CodeGenHLSL\\unusedCB.hlsl");
 }