瀏覽代碼

impl (#3200)

Co-authored-by: Jeff Noyle <[email protected]>
Jeff Noyle 4 年之前
父節點
當前提交
b85f1affc6
共有 4 個文件被更改,包括 160 次插入1 次删除
  1. 14 1
      include/dxc/dxcpix.h
  2. 76 0
      lib/DxilDia/DxcPixDxilDebugInfo.cpp
  3. 38 0
      lib/DxilDia/DxcPixDxilDebugInfo.h
  4. 32 0
      lib/DxilDia/DxcPixEntrypoints.cpp

+ 14 - 1
include/dxc/dxcpix.h

@@ -140,7 +140,16 @@ struct __declspec(uuid("eb71f85e-8542-44b5-87da-9d76045a1910"))
   virtual STDMETHODIMP_(DWORD) GetOffsetByIndex(_In_ DWORD Index) = 0;
 };
 
-struct __declspec(uuid("6dd5d45e-a417-4a26-b0ff-bdb7d6dcc63d"))
+struct __declspec(uuid("761c833d-e7b8-4624-80f8-3a3fb4146342"))
+  IDxcPixDxilSourceLocations : public IUnknown
+{
+  virtual STDMETHODIMP_(DWORD) GetCount() = 0;
+  virtual STDMETHODIMP_(DWORD) GetLineNumberByIndex(_In_ DWORD Index) = 0;
+  virtual STDMETHODIMP_(DWORD) GetColumnByIndex(_In_ DWORD Index) = 0;
+  virtual STDMETHODIMP GetFileNameByIndex(_In_ DWORD Index, _Outptr_result_z_ BSTR *Name) = 0;
+};
+
+struct __declspec(uuid("b875638e-108a-4d90-a53a-68d63773cb38"))
 IDxcPixDxilDebugInfo : public IUnknown
 {
   virtual STDMETHODIMP GetLiveVariablesAt(
@@ -164,6 +173,10 @@ IDxcPixDxilDebugInfo : public IUnknown
       _In_ DWORD SourceLine,
       _In_ DWORD SourceColumn,
       _COM_Outptr_ IDxcPixDxilInstructionOffsets** ppOffsets) = 0;
+
+  virtual STDMETHODIMP SourceLocationsFromInstructionOffset(
+      _In_ DWORD InstructionOffset,
+      _COM_Outptr_ IDxcPixDxilSourceLocations**ppSourceLocations) = 0;
 };
 
 struct __declspec(uuid("61b16c95-8799-4ed8-bdb0-3b6c08a141b4"))

+ 76 - 0
lib/DxilDia/DxcPixDxilDebugInfo.cpp

@@ -127,6 +127,18 @@ dxil_debug_info::DxcPixDxilDebugInfo::InstructionOffsetsFromSourceLocation(
       ppOffsets, m_pMalloc, m_pSession, FileName, SourceLine, SourceColumn);
 }
 
+STDMETHODIMP
+dxil_debug_info::DxcPixDxilDebugInfo::SourceLocationsFromInstructionOffset(
+    _In_ DWORD InstructionOffset,
+    _COM_Outptr_ IDxcPixDxilSourceLocations **ppSourceLocations) {
+
+  llvm::Instruction *IP = FindInstruction(InstructionOffset);
+
+  return dxil_debug_info::NewDxcPixDxilDebugInfoObjectOrThrow<
+      dxil_debug_info::DxcPixDxilSourceLocations>(
+          ppSourceLocations, m_pMalloc, m_pSession, IP);
+}
+
 static bool CompareFilenames(const wchar_t * l, const char * r)
 {
   while (*l && *r) {
@@ -207,3 +219,67 @@ DWORD dxil_debug_info::DxcPixDxilInstructionOffsets::GetOffsetByIndex(DWORD Inde
   }
   return static_cast<DWORD>(-1);
 }
+
+
+dxil_debug_info::DxcPixDxilSourceLocations::DxcPixDxilSourceLocations(
+    IMalloc* pMalloc,
+    dxil_dia::Session* pSession,
+    llvm::Instruction* IP)
+{
+    const llvm::DITypeIdentifierMap EmptyMap;
+
+    if (const llvm::DebugLoc& DL = IP->getDebugLoc())
+    {
+        auto* S = llvm::dyn_cast<llvm::DIScope>(DL.getScope());
+        while (S != nullptr && !llvm::isa<llvm::DIFile>(S))
+        {
+            S = S->getScope().resolve(EmptyMap);
+        }
+
+        if (S != nullptr)
+        {
+          Location loc;
+          loc.Line = DL->getLine();
+          loc.Column = DL->getColumn();
+          loc.Filename = CA2W(S->getFilename().data());
+          m_locations.emplace_back(std::move(loc));
+        }
+    }
+}
+
+STDMETHODIMP_(DWORD) dxil_debug_info::DxcPixDxilSourceLocations::GetCount()
+{
+    return static_cast<DWORD>(m_locations.size());
+}
+
+STDMETHODIMP dxil_debug_info::DxcPixDxilSourceLocations::GetFileNameByIndex(
+    _In_ DWORD Index, _Outptr_result_z_ BSTR *Name)
+{
+  if (Index >= static_cast<DWORD>(m_locations.size()))
+  {
+    return E_BOUNDS;
+  }
+  *Name = m_locations[Index].Filename.Copy();
+  return S_OK;
+}
+
+STDMETHODIMP_(DWORD) dxil_debug_info::DxcPixDxilSourceLocations::GetColumnByIndex(
+    _In_ DWORD Index) 
+{
+  if (Index >= static_cast<DWORD>(m_locations.size()))
+  {
+    return E_BOUNDS;
+  }
+  return m_locations[Index].Column;
+}
+
+STDMETHODIMP_(DWORD) dxil_debug_info::DxcPixDxilSourceLocations::GetLineNumberByIndex(
+    _In_ DWORD Index) 
+{
+    if (Index >= static_cast<DWORD>(m_locations.size()))
+    {
+        return E_BOUNDS;
+    }
+    return m_locations[Index].Line;
+}
+

+ 38 - 0
lib/DxilDia/DxcPixDxilDebugInfo.h

@@ -84,6 +84,10 @@ public:
       _In_ DWORD SourceColumn, 
       _COM_Outptr_ IDxcPixDxilInstructionOffsets **ppOffsets) override;
 
+  STDMETHODIMP  SourceLocationsFromInstructionOffset(
+      _In_ DWORD InstructionOffset,
+      _COM_Outptr_ IDxcPixDxilSourceLocations** ppSourceLocations) override;
+
   llvm::Module *GetModuleRef();
 
   IMalloc *GetMallocNoRef()
@@ -118,4 +122,38 @@ public:
   virtual STDMETHODIMP_(DWORD) GetCount() override;
   virtual STDMETHODIMP_(DWORD) GetOffsetByIndex(_In_ DWORD Index) override;
 };
+
+class DxcPixDxilSourceLocations : public IDxcPixDxilSourceLocations
+{
+private:
+  DXC_MICROCOM_TM_REF_FIELDS()
+
+  DxcPixDxilSourceLocations(
+    IMalloc* pMalloc,
+    dxil_dia::Session *pSession,
+    llvm::Instruction* IP);
+
+  struct Location
+  {
+      CComBSTR Filename;
+      DWORD Line;
+      DWORD Column;
+  };
+  std::vector<Location> m_locations;
+
+public:
+  DXC_MICROCOM_TM_ADDREF_RELEASE_IMPL()
+  DXC_MICROCOM_TM_ALLOC(DxcPixDxilSourceLocations)
+
+  HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject) {
+    return DoBasicQueryInterface<IDxcPixDxilSourceLocations>(this, iid, ppvObject);
+  }
+
+  virtual STDMETHODIMP_(DWORD) GetCount() override;
+  virtual STDMETHODIMP_(DWORD) GetLineNumberByIndex(_In_ DWORD Index) override;
+  virtual STDMETHODIMP_(DWORD) GetColumnByIndex(_In_ DWORD Index)override;
+  virtual STDMETHODIMP GetFileNameByIndex(_In_ DWORD Index,
+                                          _Outptr_result_z_ BSTR *Name) override;
+};
+
 }  // namespace dxil_debug_info

+ 32 - 0
lib/DxilDia/DxcPixEntrypoints.cpp

@@ -728,6 +728,13 @@ struct IDxcPixDxilDebugInfoEntrypoint : public Entrypoint<IDxcPixDxilDebugInfo>
   {
     return InvokeOnReal(&IInterface::InstructionOffsetsFromSourceLocation, CheckNotNull(InParam(FileName)), SourceLine, SourceColumn, CheckNotNull(OutParam(ppOffsets)));
   }
+
+  STDMETHODIMP SourceLocationsFromInstructionOffset(
+      _In_ DWORD InstructionOffset,
+      _COM_Outptr_ IDxcPixDxilSourceLocations** ppSourceLocations) override
+  {
+      return InvokeOnReal(&IInterface::SourceLocationsFromInstructionOffset, InstructionOffset, CheckNotNull(OutParam(ppSourceLocations)));
+  }
 };
 DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IDxcPixDxilDebugInfo);
 
@@ -747,6 +754,31 @@ struct IDxcPixDxilInstructionOffsetsEntrypoint : public Entrypoint<IDxcPixDxilIn
 };
 DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IDxcPixDxilInstructionOffsets);
 
+struct IDxcPixDxilSourceLocationsEntrypoint : public Entrypoint<IDxcPixDxilSourceLocations>
+{
+  DEFINE_ENTRYPOINT_BOILERPLATE(IDxcPixDxilSourceLocationsEntrypoint);
+
+  STDMETHODIMP_(DWORD) GetCount() override
+  {
+      return InvokeOnReal(&IInterface::GetCount);
+  }
+
+  STDMETHODIMP_(DWORD) GetLineNumberByIndex(_In_ DWORD Index) override
+  {
+    return InvokeOnReal(&IInterface::GetLineNumberByIndex, Index);
+  }
+
+  STDMETHODIMP_(DWORD) GetColumnByIndex(_In_ DWORD Index) override
+  {
+    return InvokeOnReal(&IInterface::GetColumnByIndex, Index);
+  }
+  STDMETHODIMP GetFileNameByIndex(_In_ DWORD Index, _Outptr_result_z_ BSTR* Name) override
+  {
+    return InvokeOnReal(&IInterface::GetFileNameByIndex, Index, CheckNotNull(OutParam(Name)));
+  }
+};
+DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IDxcPixDxilSourceLocations);
+
 struct IDxcPixCompilationInfoEntrypoint
     : public Entrypoint<IDxcPixCompilationInfo>
 {