Skip to content

Commit a490f2c

Browse files
jgu222igcbot
authored andcommitted
Mimic llvm's -print-after an -print-before. This will enable llvm IR printout.
Those two keys take string. For example, PrintAfter=VectorPreProcess // print IR after pass VectorPreProcess PrintBefore=SROA // print IR after pass SROA PrintAfter=all // print IR after each pass, same as ShaderDumpEnableAll Pass name is case-insensitive.
1 parent 795f36e commit a490f2c

File tree

3 files changed

+61
-18
lines changed

3 files changed

+61
-18
lines changed

IGC/common/LLVMUtils.cpp

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ void IGCPassManager::add(Pass *P)
9191
return;
9292
}
9393

94+
if (isPrintBefore(P))
95+
{
96+
addPrintPass(P, true);
97+
}
98+
9499
if (IGC_REGKEY_OR_FLAG_ENABLED(DumpTimeStatsPerPass, TIME_STATS_PER_PASS))
95100
{
96101
PassManager::add(createTimeStatsIGCPass(m_pContext, m_name + '_' + std::string(P->getPassName()), STATS_COUNTER_START));
@@ -103,29 +108,61 @@ void IGCPassManager::add(Pass *P)
103108
PassManager::add(createTimeStatsIGCPass(m_pContext, m_name + '_' + std::string(P->getPassName()), STATS_COUNTER_END));
104109
}
105110

106-
if(IGC_IS_FLAG_ENABLED(ShaderDumpEnableAll))
111+
if (isPrintAfter(P))
107112
{
108-
std::string passName = m_name + '_' + std::string(P->getPassName());
109-
auto name =
110-
IGC::Debug::DumpName(IGC::Debug::GetShaderOutputName())
111-
.Type(m_pContext->type)
112-
.Hash(m_pContext->hash)
113-
.Pass(passName, m_pContext->m_numPasses++)
114-
.StagedInfo(m_pContext)
115-
.Extension("ll");
116-
// The dump object needs to be on the Heap because it owns the stream, and the stream
117-
// is taken by reference into the printer pass. If the Dump object had been on the
118-
// stack, then that reference would go bad as soon as we exit this scope, and then
119-
// the printer pass would access an invalid pointer later on when we call PassManager::run()
120-
IGC::Debug::Dump* pDump = new IGC::Debug::Dump(name, IGC::Debug::DumpType::PASS_IR_TEXT);
121-
PassManager::add(P->createPrinterPass(pDump->stream(), ""));
122-
m_irDumps.push_back(pDump);
113+
addPrintPass(P, false);
123114
}
124115
}
125116

126-
IGCPassManager::~IGCPassManager()
117+
bool IGCPassManager::isPrintBefore(Pass* P)
118+
{
119+
if (IGC_IS_FLAG_ENABLED(PrintBefore))
120+
{
121+
StringRef passName(IGC_GET_REGKEYSTRING(PrintBefore));
122+
StringRef PN = P->getPassName();
123+
return (passName.equals_lower("all") || passName.equals_lower(PN));
124+
}
125+
return false;
126+
}
127+
128+
bool IGCPassManager::isPrintAfter(Pass* P)
127129
{
128130
if (IGC_IS_FLAG_ENABLED(ShaderDumpEnableAll))
131+
{
132+
return true;
133+
}
134+
if (IGC_IS_FLAG_ENABLED(PrintAfter))
135+
{
136+
StringRef passName(IGC_GET_REGKEYSTRING(PrintAfter));
137+
StringRef PN = P->getPassName();
138+
return (passName.equals_lower("all") || passName.equals_lower(PN));
139+
}
140+
return false;
141+
}
142+
143+
void IGCPassManager::addPrintPass(Pass* P, bool isBefore)
144+
{
145+
std::string passName =
146+
m_name + (isBefore ? "_before_" : "_after_") + std::string(P->getPassName());
147+
auto name =
148+
IGC::Debug::DumpName(IGC::Debug::GetShaderOutputName())
149+
.Type(m_pContext->type)
150+
.Hash(m_pContext->hash)
151+
.Pass(passName, m_pContext->m_numPasses++)
152+
.StagedInfo(m_pContext)
153+
.Extension("ll");
154+
// The dump object needs to be on the Heap because it owns the stream, and the stream
155+
// is taken by reference into the printer pass. If the Dump object had been on the
156+
// stack, then that reference would go bad as soon as we exit this scope, and then
157+
// the printer pass would access an invalid pointer later on when we call PassManager::run()
158+
IGC::Debug::Dump* pDump = new IGC::Debug::Dump(name, IGC::Debug::DumpType::PASS_IR_TEXT);
159+
PassManager::add(P->createPrinterPass(pDump->stream(), ""));
160+
m_irDumps.push_back(pDump);
161+
}
162+
163+
IGCPassManager::~IGCPassManager()
164+
{
165+
if (!m_irDumps.empty())
129166
{
130167
for(auto it : m_irDumps)
131168
{

IGC/common/LLVMUtils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ namespace IGC
5151
CodeGenContext* const m_pContext;
5252
const std::string m_name;
5353
std::vector<Debug::Dump *> m_irDumps;
54+
55+
void addPrintPass(llvm::Pass* P, bool isBefore);
56+
bool isPrintBefore(llvm::Pass* P);
57+
bool isPrintAfter(llvm::Pass* P);
5458
};
5559
}
5660

IGC/common/igc_flags.def

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,10 @@ DECLARE_IGC_REGKEY(bool, EnableCisDump, false, "Enable cis dump", true)
242242
DECLARE_IGC_REGKEY(bool, DumpLLVMIR, false, "dump LLVM IR", true)
243243
DECLARE_IGC_REGKEY(bool, QualityMetricsEnable, false, "Enable Quality Metrics for IGC", true)
244244
DECLARE_IGC_REGKEY(bool, ShaderDumpEnable, false, "dump LLVM IR, visaasm, and GenISA", true)
245-
DECLARE_IGC_REGKEY(bool, InterleaveSourceShader, true, "Interleave the source shader in asm dump", true)
246245
DECLARE_IGC_REGKEY(bool, ShaderDumpEnableAll, false, "dump all LLVM IR passes, visaasm, and GenISA", true)
246+
DECLARE_IGC_REGKEY(debugString, PrintAfter, 0, "Take pass name or all. If set, enable print LLVM IR after the given pass is done (mimic llvm print-after)", true)
247+
DECLARE_IGC_REGKEY(debugString, PrintBefore, 0, "Take pass name or all. If set, enable print LLVM IR before the given pass is done (mimic llvm print-before)", true)
248+
DECLARE_IGC_REGKEY(bool, InterleaveSourceShader, true, "Interleave the source shader in asm dump", true)
247249
DECLARE_IGC_REGKEY(bool, ShaderDumpPidDisable, false, "disabled adding PID to the name of shader dump directory", true)
248250
DECLARE_IGC_REGKEY(bool, DumpToCurrentDir, false, "dump shaders to the current directory", true)
249251
DECLARE_IGC_REGKEY(debugString, DumpToCustomDir, 0, "Dump shaders to custom directory. Parent directory must exist.", true)

0 commit comments

Comments
 (0)