瀏覽代碼

Fixed linker not putting subprogram of inlined functions into CU (#3716)

Adam Yang 4 年之前
父節點
當前提交
b44890fe1e
共有 3 個文件被更改,包括 14 次插入5 次删除
  1. 2 0
      include/llvm/IR/DebugInfoMetadata.h
  2. 5 0
      include/llvm/IR/IntrinsicInst.h
  3. 7 5
      lib/HLSL/DxilLinker.cpp

+ 2 - 0
include/llvm/IR/DebugInfoMetadata.h

@@ -545,6 +545,7 @@ public:
 
 
   Metadata *getRawScope() const { return getOperand(1); }
+  void setScope(Metadata *scope) { setOperand(1, scope); } // HLSL Change
   MDString *getRawName() const { return getOperandAs<MDString>(2); }
 
   void setFlags(unsigned NewFlags) {
@@ -1826,6 +1827,7 @@ public:
     return "";
   }
 
+  void setScope(DIScope *scope) { setOperand(0, scope); } // HLSL Change
   Metadata *getRawScope() const { return getOperand(0); }
   MDString *getRawName() const { return getOperandAs<MDString>(1); }
   Metadata *getRawFile() const { return getOperand(2); }

+ 5 - 0
include/llvm/IR/IntrinsicInst.h

@@ -29,6 +29,7 @@
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/Metadata.h"
+#include "llvm/IR/DebugInfoMetadata.h" // HLSL Change
 
 namespace llvm {
   /// IntrinsicInst - A useful wrapper class for inspecting calls to intrinsic
@@ -89,6 +90,8 @@ namespace llvm {
       return cast<DIExpression>(getRawExpression());
     }
 
+    void setVariable(DIVariable *v) { setArgOperand(1, MetadataAsValue::get(getContext(), v)); } // HLSL Change
+
     Metadata *getRawVariable() const {
       return cast<MetadataAsValue>(getArgOperand(1))->getMetadata();
     }
@@ -122,6 +125,8 @@ namespace llvm {
       return cast<DIExpression>(getRawExpression());
     }
 
+    void setVariable(DIVariable *v) { setArgOperand(2, MetadataAsValue::get(getContext(), v)); } // HLSL Change
+
     Metadata *getRawVariable() const {
       return cast<MetadataAsValue>(getArgOperand(2))->getMetadata();
     }

+ 7 - 5
lib/HLSL/DxilLinker.cpp

@@ -1058,12 +1058,14 @@ void DxilLinkJob::StripDeadDebugInfo(Module &M) {
 
       // If the function referenced by DISP is not null, the function is live.
       if (Function *Func = DISP->getFunction()) {
-        if (Func->getParent() == &M)
-          LiveSubprograms.push_back(DISP);
-        else
-          SubprogramChange = true;
+        LiveSubprograms.push_back(DISP);
+        if (Func->getParent() != &M)
+          DISP->replaceFunction(nullptr);
       } else {
-        SubprogramChange = true;
+        // Copy it in anyway even if there's no function. When function is inlined
+        // the function reference is gone, but the subprogram is still valid as
+        // scope.
+        LiveSubprograms.push_back(DISP);
       }
     }