1414#include < memory>
1515
1616#include " dxc/DXIL/DxilModule.h"
17+ #include " dxc/DXIL/DxilOperations.h"
1718#include " dxc/DxilPIXPasses/DxilPIXPasses.h"
1819#include " dxc/DxilPIXPasses/DxilPIXVirtualRegisters.h"
1920#include " dxc/Support/Global.h"
@@ -70,6 +71,7 @@ class DxilAnnotateWithVirtualRegister : public llvm::ModulePass {
7071 DxilAnnotateWithVirtualRegister () : llvm::ModulePass(ID) {}
7172
7273 bool runOnModule (llvm::Module &M) override ;
74+ void applyOptions (llvm::PassOptions O) override ;
7375
7476private:
7577 void AnnotateValues (llvm::Instruction *pI);
@@ -86,6 +88,8 @@ class DxilAnnotateWithVirtualRegister : public llvm::ModulePass {
8688 hlsl::DxilModule* m_DM;
8789 std::uint32_t m_uVReg;
8890 std::unique_ptr<llvm::ModuleSlotTracker> m_MST;
91+ int m_StartInstruction = 0 ;
92+
8993 void Init (llvm::Module &M) {
9094 m_DM = &M.GetOrCreateDxilModule ();
9195 m_uVReg = 0 ;
@@ -97,6 +101,10 @@ class DxilAnnotateWithVirtualRegister : public llvm::ModulePass {
97101 }
98102};
99103
104+ void DxilAnnotateWithVirtualRegister::applyOptions (llvm::PassOptions O) {
105+ GetPassOptionInt (O, " startInstruction" , &m_StartInstruction, 0 );
106+ }
107+
100108char DxilAnnotateWithVirtualRegister::ID = 0 ;
101109
102110bool DxilAnnotateWithVirtualRegister::runOnModule (llvm::Module &M) {
@@ -111,37 +119,55 @@ bool DxilAnnotateWithVirtualRegister::runOnModule(llvm::Module &M) {
111119 m_DM->SetValidatorVersion (1 , 4 );
112120 }
113121
114- std::uint32_t InstNum = 0 ;
115- auto blocks = PIXPassHelpers::GetAllBlocks (*m_DM);
116- for (auto * block : blocks) {
117- for (llvm::Instruction& I : block->getInstList ()) {
118- if (!llvm::isa<llvm::DbgDeclareInst>(&I)) {
119- pix_dxil::PixDxilInstNum::AddMD (M.getContext (), &I, InstNum++);
122+ std::uint32_t InstNum = m_StartInstruction;
123+ std::map<llvm::StringRef, std::pair<int , int >> InstructionRangeByFunctionName;
124+
125+ auto instrumentableFunctions = PIXPassHelpers::GetAllInstrumentableFunctions (*m_DM);
126+
127+ for (auto * F : instrumentableFunctions) {
128+ auto &EndInstruction = InstructionRangeByFunctionName[F->getName ()];
129+ EndInstruction.first = InstNum;
130+ for (auto &block : F->getBasicBlockList ()) {
131+ for (llvm::Instruction &I : block.getInstList ()) {
132+ if (!llvm::isa<llvm::DbgDeclareInst>(&I)) {
133+ pix_dxil::PixDxilInstNum::AddMD (M.getContext (), &I, InstNum++);
134+ EndInstruction.second = InstNum;
135+ }
120136 }
121137 }
122138 }
123139
124140 if (OSOverride != nullptr ) {
141+ // Print a set of strings of the exemplary form "InstructionCount: <n> <fnName>"
125142 *OSOverride << " \n InstructionCount:" << InstNum << " \n " ;
126- }
127-
128- if (OSOverride != nullptr ) {
129- *OSOverride << " \n End - instruction ID to line\n " ;
130- }
143+ for (auto const &fn : InstructionRangeByFunctionName) {
144+ *OSOverride << " InstructionRange: " ;
145+ int skipOverLeadingUnprintableCharacters = 0 ;
146+ if (fn.first .size () > 2 && fn.first [0 ] == ' \1 ' && fn.first [1 ] == ' ?' ) {
147+ skipOverLeadingUnprintableCharacters = 2 ;
148+ }
149+ *OSOverride << fn.second .first << " " << fn.second .second << " "
150+ << (fn.first .str ().c_str () +
151+ skipOverLeadingUnprintableCharacters)
152+ << " \n " ;
153+ }
131154
132- if (OSOverride != nullptr ) {
133155 *OSOverride << " \n Begin - dxil values to virtual register mapping\n " ;
134156 }
135157
136- for (auto * block : blocks) {
137- for (llvm::Instruction& I : block->getInstList ()) {
138- AnnotateValues (&I);
158+ for (auto * F : instrumentableFunctions) {
159+ for (auto &block : F->getBasicBlockList ()) {
160+ for (llvm::Instruction &I : block.getInstList ()) {
161+ AnnotateValues (&I);
162+ }
139163 }
140164 }
141165
142- for (auto * block : blocks) {
143- for (llvm::Instruction& I : block->getInstList ()) {
144- AnnotateStore (&I);
166+ for (auto * F : instrumentableFunctions) {
167+ for (auto &block : F->getBasicBlockList ()) {
168+ for (llvm::Instruction &I : block.getInstList ()) {
169+ AnnotateStore (&I);
170+ }
145171 }
146172 }
147173
0 commit comments