浏览代码

Added support for functions without arguments. (#292)

yurido1 8 年之前
父节点
当前提交
35f727ac33
共有 2 个文件被更改,包括 23 次插入11 次删除
  1. 2 1
      include/dxc/HLSL/ComputeViewIdState.h
  2. 21 10
      lib/HLSL/ComputeViewIdState.cpp

+ 2 - 1
include/dxc/HLSL/ComputeViewIdState.h

@@ -129,7 +129,8 @@ private:
   void ComputeReachableFunctionsRec(llvm::CallGraph &CG, llvm::CallGraphNode *pNode, FunctionSetType &FuncSet);
   void AnalyzeFunctions(EntryInfo &Entry);
   void CollectValuesContributingToOutputs(EntryInfo &Entry);
-  void CollectValuesContributingToOutputRec(llvm::Value *pContributingValue,
+  void CollectValuesContributingToOutputRec(EntryInfo &Entry,
+                                            llvm::Value *pContributingValue,
                                             InstructionSetType &ContributingInstructions);
   const ValueSetType &CollectReachingDecls(llvm::Value *pValue);
   void CollectReachingDeclsRec(llvm::Value *pValue, ValueSetType &ReachingDecls, ValueSetType &Visited);

+ 21 - 10
lib/HLSL/ComputeViewIdState.cpp

@@ -341,11 +341,11 @@ void DxilViewIdState::CollectValuesContributingToOutputs(EntryInfo &Entry) {
       // Scalar or indexable with known index.
       unsigned index = GetLinearIndex(SigElem, startRow, col);
       InstructionSetType &ContributingInstructions = Entry.ContributingInstructions[index];
-      CollectValuesContributingToOutputRec(pContributingValue, ContributingInstructions);
+      CollectValuesContributingToOutputRec(Entry, pContributingValue, ContributingInstructions);
     } else {
       // Dynamically indexed output.
       InstructionSetType ContributingInstructions;
-      CollectValuesContributingToOutputRec(pContributingValue, ContributingInstructions);
+      CollectValuesContributingToOutputRec(Entry, pContributingValue, ContributingInstructions);
 
       for (int row = startRow; row <= endRow; row++) {
         unsigned index = GetLinearIndex(SigElem, row, col);
@@ -366,10 +366,13 @@ void DxilViewIdState::CollectValuesContributingToOutputs(EntryInfo &Entry) {
   }
 }
 
-void DxilViewIdState::CollectValuesContributingToOutputRec(Value *pContributingValue,
+void DxilViewIdState::CollectValuesContributingToOutputRec(EntryInfo &Entry,
+                                                           Value *pContributingValue,
                                                            InstructionSetType &ContributingInstructions) {
   if (Argument *pArg = dyn_cast<Argument>(pContributingValue)) {
-    // TODO: handle multiple functions.
+    // This must be a leftover signature argument of an entry function.
+    DXASSERT_NOMSG(Entry.pEntryFunc == m_pModule->GetEntryFunction() ||
+                   Entry.pEntryFunc == m_pModule->GetPatchConstantFunction());
     return;
   }
 
@@ -392,7 +395,7 @@ void DxilViewIdState::CollectValuesContributingToOutputRec(Value *pContributingV
       Value *O = phi->getOperand(iOp);
       if (isa<Constant>(O)) {
         BasicBlock *pPredBB = *it;
-        CollectValuesContributingToOutputRec(pPredBB->getTerminator(), ContributingInstructions);
+        CollectValuesContributingToOutputRec(Entry, pPredBB->getTerminator(), ContributingInstructions);
       }
     }
   } else if (isa<LoadInst>(pContributingInst) || 
@@ -405,13 +408,21 @@ void DxilViewIdState::CollectValuesContributingToOutputRec(Value *pContributingV
     for (Value *pDeclValue : ReachingDecls) {
       const ValueSetType &Stores = CollectStores(pDeclValue);
       for (Value *V : Stores) {
-        CollectValuesContributingToOutputRec(V, ContributingInstructions);
+        CollectValuesContributingToOutputRec(Entry, V, ContributingInstructions);
       }
     }
   } else if (CallInst *CI = dyn_cast<CallInst>(pContributingInst)) {
     if (!hlsl::OP::IsDxilOpFuncCallInst(CI)) {
-      // TODO: Return value of a user function.
-      return;
+      Function *F = CI->getCalledFunction();
+      if (!F->empty()) {
+        // Return value of a user function.
+        if (Entry.Functions.find(F) != Entry.Functions.end()) {
+          const FuncInfo &FI = *m_FuncInfo[F];
+          for (ReturnInst *pRetInst : FI.Returns) {
+            CollectValuesContributingToOutputRec(Entry, pRetInst, ContributingInstructions);
+          }
+        }
+      }
     }
   }
 
@@ -419,7 +430,7 @@ void DxilViewIdState::CollectValuesContributingToOutputRec(Value *pContributingV
   unsigned NumOps = pContributingInst->getNumOperands();
   for (unsigned i = 0; i < NumOps; i++) {
     Value *O = pContributingInst->getOperand(i);
-    CollectValuesContributingToOutputRec(O, ContributingInstructions);
+    CollectValuesContributingToOutputRec(Entry, O, ContributingInstructions);
   }
 
   // Handle control dependence of this instruction BB.
@@ -428,7 +439,7 @@ void DxilViewIdState::CollectValuesContributingToOutputRec(Value *pContributingV
   FuncInfo *pFuncInfo = m_FuncInfo[F].get();
   const BasicBlockSet &CtrlDepSet = pFuncInfo->CtrlDep.GetCDBlocks(pBB);
   for (BasicBlock *B : CtrlDepSet) {
-    CollectValuesContributingToOutputRec(B->getTerminator(), ContributingInstructions);
+    CollectValuesContributingToOutputRec(Entry, B->getTerminator(), ContributingInstructions);
   }
 }