Skip to content

Commit 0923641

Browse files
Winston0323igcbot
authored andcommitted
Enable Optimization Remark Emitter
Emit remark for passes, right now only enable for Divergent pass barrier
1 parent 09bdd4c commit 0923641

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

IGC/AdaptorCommon/DivergentBarrierPass.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ SPDX-License-Identifier: MIT
3737
#include "llvm/Transforms/Utils/Local.h"
3838
#include "llvmWrapper/Transforms/Utils/Cloning.h"
3939
#include "common/LLVMWarningsPop.hpp"
40+
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
4041

4142
using namespace llvm;
4243
using namespace IGC;
@@ -708,7 +709,23 @@ bool DivergentBarrierPass::runOnModule(Module& M)
708709

709710
for (auto* F : Shaders)
710711
{
711-
Changed |= processShader(F);
712+
bool hadDivBarrier = processShader(F);
713+
714+
if (IGC_IS_FLAG_ENABLED(EnableRemarks))
715+
{
716+
if (hadDivBarrier) {
717+
OptimizationRemarkEmitter ORE(F);
718+
719+
ORE.emit([&]() {
720+
return OptimizationRemark("divergent-barrier-pass", "DivergentBarrierPass", F)
721+
<< "Divergent Barriers detected and transformed."
722+
<< ore::NV("Function", F);
723+
});
724+
725+
}
726+
}
727+
Changed |= hadDivBarrier;
728+
712729
}
713730

714731
IGC_ASSERT(false == llvm::verifyModule(*m_CGCtx->getModule(), &dbgs()));

IGC/Compiler/CodeGenContext.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ SPDX-License-Identifier: MIT
1717
#include "Compiler/CISACodeGen/OpenCLKernelCodeGen.hpp"
1818
#include "Compiler/CodeGenPublic.h"
1919
#include "Probe/Assertion.h"
20+
#if LLVM_VERSION_MAJOR >= 11
21+
#include <llvm/IR/LLVMRemarkStreamer.h>
22+
#endif
2023

2124
namespace IGC
2225
{
@@ -1027,4 +1030,22 @@ namespace IGC
10271030
}
10281031
return MI->second;
10291032
}
1033+
void CodeGenContext::initializeRemarkEmitter(const ShaderHash & hash) {
1034+
#if LLVM_VERSION_MAJOR >= 11
1035+
//setting up optimization remark emitter
1036+
if (IGC_IS_FLAG_ENABLED(EnableRemarks))
1037+
{
1038+
std::string remark_file_name = IGC::Debug::DumpName("Remark_")
1039+
.Type(this->type)
1040+
.Hash(hash)
1041+
.Extension("yaml")
1042+
.str();
1043+
llvm::Expected<std::unique_ptr<llvm::ToolOutputFile>> RemarksFileOrErr =
1044+
setupLLVMOptimizationRemarks(*this->getLLVMContext(), remark_file_name, "",
1045+
"yaml", false, 0);
1046+
this->RemarksFile = std::move(*RemarksFileOrErr);
1047+
this->RemarksFile->keep();
1048+
}
1049+
#endif
1050+
}
10301051
}

IGC/Compiler/CodeGenPublic.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ SPDX-License-Identifier: MIT
4444
#include <llvm/IR/IRBuilder.h>
4545
#include "llvm/IR/Function.h"
4646
#include "llvm/IR/ValueMap.h"
47+
#include <llvm/Support/ToolOutputFile.h>
4748
#include "llvm/IR/AssemblyAnnotationWriter.h"
4849
#include "common/LLVMWarningsPop.hpp"
4950
#include "CodeGenPublicEnums.h"
@@ -1010,7 +1011,7 @@ namespace IGC
10101011
std::stringstream oclErrorMessage;
10111012
//For storing warning message
10121013
std::stringstream oclWarningMessage;
1013-
1014+
std::unique_ptr<llvm::ToolOutputFile> RemarksFile;
10141015
protected:
10151016
// Objects pointed to by these pointers are owned by this class.
10161017
LLVMContextWrapper* llvmCtxWrapper;
@@ -1226,6 +1227,9 @@ namespace IGC
12261227
int getFunctionID(llvm::Function* F);
12271228
std::string getFunctionDumpName(int functionId);
12281229
bool dumpUseShorterName() const { return m_enableDumpUseShorterName; }
1230+
1231+
// For remarks
1232+
void initializeRemarkEmitter(const ShaderHash& hash);
12291233
};
12301234

12311235
struct SComputeShaderSecondCompileInput

IGC/common/igc_flags.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ DECLARE_IGC_REGKEY(bool, PrintPsoDdiHash, true, "Print psoDDIHash
408408
DECLARE_IGC_REGKEY(bool, ShaderDataBaseStats, false, "Enable gathering sends' sizes for shader statistics", false)
409409
DECLARE_IGC_REGKEY(bool, DumpLoopSink, false, "Dump debug info in LoopSink", false)
410410
DECLARE_IGC_REGKEY(debugString, ShaderDataBaseStatsFilePath, 0, "Path to a file with dumped shader stats additional data e.g. data available during compilation only", false)
411+
DECLARE_IGC_REGKEY(bool, EnableRemarks, false, "Enable remark for Divergent Barrier", false)
411412
DECLARE_IGC_REGKEY(bool, AddExtraIntfInfo, false, "Will add extra inteference info from .extraintf files from c:\\Intel\\IGC\\ShaderOverride", false)
412413

413414
DECLARE_IGC_GROUP("Debugging features")

0 commit comments

Comments
 (0)