Skip to content

Commit

Permalink
Generate per-block CFG by default; --cfg-i option for per-instruction…
Browse files Browse the repository at this point in the history
… CFG.
  • Loading branch information
kpyzhov committed Oct 10, 2018
1 parent 7e2b12d commit c7d81b6
Show file tree
Hide file tree
Showing 17 changed files with 122 additions and 81 deletions.
Binary file modified Core/ShaderAnalysis/Linux/x64/shae
Binary file not shown.
Binary file modified Core/ShaderAnalysis/Windows/x86/shae.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions Core/ShaderAnalysis/src/shae.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,15 +716,15 @@ def _Max(s):
print(' \'^\' means that the current instruction writes to the register', file=output)
print(' \'v\' means that the current instruction reads from the register', file=output)
print(' \'x\' means that the current instruction both reads from the register and writes to it', file=output)
print(' \'Ra\': Number of allocated registers\n', file=output)
print(' \'Rn\': Number of live registers\n', file=output)

maxVGPR = 0
highestVGPR = 0
for node in instructionNodes:
maxVGPR = max (len (set.union (node.In, node.Out)), maxVGPR)
highestVGPR = max (highestVGPR, _Max (node.In), _Max (node.Out))

print(' Line | Ra | {:{width}} | Instruction'.format('Reg State', width=highestVGPR+1), file=output)
print(' Line | Rn | {:{width}} | Instruction'.format('Reg State', width=highestVGPR+1), file=output)
print('--------------------------------------------------------------------------------------------------------------------------', file=output)

if not summaryOnly:
Expand Down
3 changes: 0 additions & 3 deletions RadeonGPUAnalyzerBackend/include/beProgramBuilderVulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ struct VulkanOptions : public beKA::CompileOptions
// True to perform live register analysis.
bool m_isLiveRegisterAnalysisRequired;

// True to generate control flow graph.
bool m_isControlFlowGraphRequired;

// True to generate shader compiler statistics.
bool m_isScStatsRequired;
};
Expand Down
3 changes: 2 additions & 1 deletion RadeonGPUAnalyzerBackend/include/beStaticIsaAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ class RGA_BACKEND_DECLDIR beStaticIsaAnalyzer
/// Params:
/// isaFileName: the file name that contains the ISA to be analyzed.
/// outputFileName: the output file name (will contain the graph representation in dot format).
// perInst: generate per-instruction CFG.
/// printCmd: print the command line.
/// Returns: true if the operation succeeded, false otherwise.
static beStatus GenerateControlFlowGraph(const gtString& isaFileName, const gtString& outputFileName, bool printCmd);
static beStatus GenerateControlFlowGraph(const gtString& isaFileName, const gtString& outputFileName, bool perInst, bool printCmd);

private:
// No instances.
Expand Down
16 changes: 11 additions & 5 deletions RadeonGPUAnalyzerBackend/src/beStaticIsaAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
#include <AMDTOSWrappers/Include/osProcess.h>
#include <AMDTOSWrappers/Include/osFilePath.h>
#include <AMDTOSWrappers/Include/osFile.h>
#include <RadeonGPUAnalyzerCLI/src/kcUtils.h>

// Local.
#include <RadeonGPUAnalyzerBackend/include/beStaticIsaAnalyzer.h>
#include <RadeonGPUAnalyzerBackend/include/beUtils.h>

using namespace beKA;

// Static constants.
static const std::string RGA_SHAE_OPT_LIVEREG = "analyse-liveness";
static const std::string RGA_SHAE_OPT_BLOCK_CFG = "dump-bb-cfg";
static const std::string RGA_SHAE_OPT_INST_CFG = "dump-pi-cfg";

static bool GetLiveRegAnalyzerPath(std::string& analyzerPath)
{
#ifdef AMD_INTERNAL
Expand Down Expand Up @@ -62,7 +66,7 @@ beKA::beStatus beKA::beStaticIsaAnalyzer::PerformLiveRegisterAnalysis(const gtSt
{
// Construct the command.
std::stringstream cmd;
cmd << analyzerPath << " analyse-liveness " << '"' << isaFileName.asASCIICharArray()
cmd << analyzerPath << " " << RGA_SHAE_OPT_LIVEREG << " \"" << isaFileName.asASCIICharArray()
<< "\" \"" << outputFileName.asASCIICharArray() << '"';

// Cancel signal. Not in use for now.
Expand Down Expand Up @@ -94,7 +98,8 @@ beKA::beStatus beKA::beStaticIsaAnalyzer::PerformLiveRegisterAnalysis(const gtSt
return ret;
}

beKA::beStatus beKA::beStaticIsaAnalyzer::GenerateControlFlowGraph(const gtString& isaFileName, const gtString& outputFileName, bool printCmd)
beKA::beStatus beKA::beStaticIsaAnalyzer::GenerateControlFlowGraph(const gtString& isaFileName, const gtString& outputFileName,
bool perInst, bool printCmd)
{
beStatus ret = beStatus_General_FAILED;

Expand All @@ -111,8 +116,9 @@ beKA::beStatus beKA::beStaticIsaAnalyzer::GenerateControlFlowGraph(const gtStrin
{
// Construct the command.
std::stringstream cmd;
cmd << analyzerPath << " dump-pi-cfg " << kcUtils::Quote(isaFileName.asASCIICharArray())
<< " " << kcUtils::Quote(outputFileName.asASCIICharArray());
std::string shaeOptCfg = perInst ? RGA_SHAE_OPT_INST_CFG : RGA_SHAE_OPT_BLOCK_CFG;
cmd << analyzerPath << " " << shaeOptCfg << " " << '"' << isaFileName.asASCIICharArray()
<< "\" \"" << outputFileName.asASCIICharArray() << '"';

// Cancel signal. Not in use for now.
bool shouldCancel = false;
Expand Down
13 changes: 6 additions & 7 deletions RadeonGPUAnalyzerCLI/src/kcCLICommanderCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ void kcCLICommanderCL::GetILText(const Config& config)
void kcCLICommanderCL::GetISAText(const Config& config)
{
if (!config.m_ISAFile.empty() || !config.m_AnalysisFile.empty() ||
!config.m_ControlFlowGraphFile.empty() || !config.m_LiveRegisterAnalysisFile.empty())
!config.m_blockCFGFile.empty() || !config.m_instCFGFile.empty() || !config.m_LiveRegisterAnalysisFile.empty())
{
bool isIsaFileTemp = config.m_ISAFile.empty();

Expand Down Expand Up @@ -482,18 +482,17 @@ void kcCLICommanderCL::GetISAText(const Config& config)
}

// Generate control flow graph.
bool isCfgRequired = !config.m_ControlFlowGraphFile.empty();

if (isCfgRequired)
if (!config.m_blockCFGFile.empty() || !config.m_instCFGFile.empty())
{
gtString cfgOutputFileName;
kcUtils::ConstructOutputFileName(config.m_ControlFlowGraphFile, KC_STR_DEFAULT_CFG_SUFFIX,
std::string baseName = (!config.m_blockCFGFile.empty() ? config.m_blockCFGFile : config.m_instCFGFile);
kcUtils::ConstructOutputFileName(baseName, KC_STR_DEFAULT_CFG_EXT,
kernelName, deviceName, cfgOutputFileName);

// Call the kcUtils routine to analyze <generatedFileName> and write
// the analysis file.
kcUtils::GenerateControlFlowGraph(isaOutputFileName, cfgOutputFileName,
m_LogCallback, config.m_printProcessCmdLines);
kcUtils::GenerateControlFlowGraph(isaOutputFileName, cfgOutputFileName, m_LogCallback,
!config.m_instCFGFile.empty(), config.m_printProcessCmdLines);
}

// Delete temporary files.
Expand Down
34 changes: 17 additions & 17 deletions RadeonGPUAnalyzerCLI/src/kcCLICommanderDX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ void kcCLICommanderDX::InitRequestedAsicListDX(const Config& config)


void kcCLICommanderDX::ExtractISA(const string& deviceName, const Config& config, size_t& isaSizeInBytes,
string isaBuffer, bool& isIsaSizeDetected, bool& shouldDetectIsaSize,
const bool bRegisterLiveness, const bool bControlFlow)
string isaBuffer, bool& isIsaSizeDetected, bool& shouldDetectIsaSize)
{
beProgramBuilderDX* pProgramBuilderDX = m_pBackEndHandler != nullptr ? m_pBackEndHandler->theOpenDXBuilder() : nullptr;
beStatus backendRet = beStatus_Invalid;
Expand Down Expand Up @@ -145,7 +144,7 @@ void kcCLICommanderDX::ExtractISA(const string& deviceName, const Config& config
// If we managed to detect the ISA size, don't do it again.
shouldDetectIsaSize = !isIsaSizeDetected;

if (bRegisterLiveness)
if (!config.m_LiveRegisterAnalysisFile.empty())
{
gtString liveRegAnalysisOutputFileName;
kcUtils::ConstructOutputFileName(config.m_LiveRegisterAnalysisFile, KC_STR_DEFAULT_LIVE_REG_ANALYSIS_SUFFIX,
Expand All @@ -157,14 +156,15 @@ void kcCLICommanderDX::ExtractISA(const string& deviceName, const Config& config
m_LogCallback, config.m_printProcessCmdLines);
}

if (bControlFlow)
if (!config.m_instCFGFile.empty() || !config.m_blockCFGFile.empty())
{
gtString cfgOutputFileName;
kcUtils::ConstructOutputFileName(config.m_ControlFlowGraphFile, KC_STR_DEFAULT_CFG_SUFFIX,
std::string baseName = (!config.m_instCFGFile.empty() ? config.m_instCFGFile : config.m_blockCFGFile);
kcUtils::ConstructOutputFileName(baseName, KC_STR_DEFAULT_CFG_EXT,
config.m_Function, deviceName, cfgOutputFileName);

kcUtils::GenerateControlFlowGraph(isaOutputFileName, cfgOutputFileName,
m_LogCallback, config.m_printProcessCmdLines);
kcUtils::GenerateControlFlowGraph(isaOutputFileName, cfgOutputFileName, m_LogCallback,
!config.m_instCFGFile.empty(), config.m_printProcessCmdLines);
}

// Delete temporary ISA file.
Expand Down Expand Up @@ -313,12 +313,12 @@ void kcCLICommanderDX::RunCompileCommands(const Config& config, LoggingCallBackF

if (isInitSuccessful)
{
const bool bISA = config.m_ISAFile.length() > 0;
const bool bIL = config.m_ILFile.length() > 0;
const bool bStatistics = config.m_AnalysisFile.length() > 0;
const bool bRegisterLiveness = config.m_LiveRegisterAnalysisFile.length() > 0;
const bool bControlFlow = config.m_ControlFlowGraphFile.length() > 0;
const bool bBinaryOutput = config.m_BinaryOutputFile.length() > 0;
const bool bISA = !config.m_ISAFile.empty();
const bool bIL = !config.m_ILFile.empty();
const bool bStatistics = !config.m_AnalysisFile.empty();
const bool bBinaryOutput = !config.m_BinaryOutputFile.empty();
const bool bLivereg = !config.m_LiveRegisterAnalysisFile.empty();
const bool bCfg = (!config.m_instCFGFile.empty() || !config.m_blockCFGFile.empty());

vector <AnalysisData> AnalysisDataVec;
vector <string> DeviceAnalysisDataVec;
Expand Down Expand Up @@ -394,18 +394,18 @@ void kcCLICommanderDX::RunCompileCommands(const Config& config, LoggingCallBackF
bool shouldDetectIsaSize = true;
size_t isaSizeInBytes(0);

if (bISA || bRegisterLiveness || bStatistics || bControlFlow)
if (bISA || bStatistics || bLivereg || bCfg)
{
ExtractISA(deviceName, config, isaSizeInBytes, isaBuffer, isIsaSizeDetected, shouldDetectIsaSize, bRegisterLiveness, bControlFlow);
ExtractISA(deviceName, config, isaSizeInBytes, isaBuffer, isIsaSizeDetected, shouldDetectIsaSize);
}
if (bIL)
{
ExtractIL(deviceName, config);
}
if (bStatistics)
{
isIsaSizeDetected = ExtractStats(deviceName, config, shouldDetectIsaSize, isaBuffer, isIsaSizeDetected, isaSizeInBytes, AnalysisDataVec, DeviceAnalysisDataVec);

isIsaSizeDetected = ExtractStats(deviceName, config, shouldDetectIsaSize, isaBuffer, isIsaSizeDetected,
isaSizeInBytes, AnalysisDataVec, DeviceAnalysisDataVec);
}
}

Expand Down
4 changes: 2 additions & 2 deletions RadeonGPUAnalyzerCLI/src/kcCLICommanderDX.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class kcCLICommanderDX : public kcCLICommander
bool Compile(const Config& config, const GDT_GfxCardInfo& gfxCardInfo, string sDevicenametoLog);
bool WriteAnalysisDataForDX(const Config& config, const std::vector<AnalysisData>& AnalysisDataVec, const std::vector<string>& DeviceAnalysisDataVec,
const std::string& sAnalysisFile, std::stringstream& log);
void ExtractISA(const std::string& deviceName, const Config& config, size_t& isaSizeInBytes, std::string isaBuffer,
bool& isIsaSizeDetected, bool& shouldDetectIsaSize, const bool bRegisterLiveness, const bool bControlFlow);
void ExtractISA(const std::string& deviceName, const Config& config, size_t& isaSizeInBytes,
std::string isaBuffer, bool& isIsaSizeDetected, bool& shouldDetectIsaSize);
void ExtractIL(const std::string& deviceName, const Config& config);
bool ExtractStats(const std::string& deviceName, const Config& config, bool shouldDetectIsaSize, std::string isaBuffer,
bool isIsaSizeDetected, size_t isaSizeInBytes, vector<AnalysisData>& AnalysisDataVec, vector<string>& DeviceAnalysisDataVec);
Expand Down
14 changes: 9 additions & 5 deletions RadeonGPUAnalyzerCLI/src/kcCLICommanderLightning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ beStatus kcCLICommanderLightning::CompileOpenCL(const Config& config, const Open

// Disassemble binary to ISA text.
if (!config.m_ISAFile.empty() || !config.m_AnalysisFile.empty() ||
!config.m_LiveRegisterAnalysisFile.empty() || !config.m_ControlFlowGraphFile.empty())
!config.m_LiveRegisterAnalysisFile.empty() || !config.m_blockCFGFile.empty() || !config.m_instCFGFile.empty())
{
LogPreStep(KA_CLI_STR_EXTRACTING_ISA, device);
currentStatus = DisassembleBinary(binFileName, config.m_ISAFile, clangDevice, config.m_Function, config.m_isLineNumbersRequired, errText);
Expand Down Expand Up @@ -767,7 +767,7 @@ void kcCLICommanderLightning::RunCompileCommands(const Config& config, LoggingCa
}

// Extract Control Flow Graph.
if ((status || multiDevices) && !config.m_ControlFlowGraphFile.empty())
if ((status || multiDevices) && (!config.m_blockCFGFile.empty() || !config.m_instCFGFile.empty()))
{
ExtractCFG(config);
}
Expand Down Expand Up @@ -875,7 +875,7 @@ bool kcCLICommanderLightning::PerformLiveRegAnalysis(const Config & config)
return ret;
}

bool kcCLICommanderLightning::ExtractCFG(const Config & config)
bool kcCLICommanderLightning::ExtractCFG(const Config& config)
{
bool ret = true;
std::stringstream errMsg;
Expand All @@ -894,10 +894,14 @@ bool kcCLICommanderLightning::ExtractCFG(const Config & config)
isaFileName << outputFiles.m_isaFile.c_str();

// Construct a name for the output livereg file.
kcUtils::ConstructOutputFileName(config.m_ControlFlowGraphFile, KC_STR_DEFAULT_CFG_SUFFIX, entryName, device, cfgOutFileName);
std::string baseFile = (!config.m_blockCFGFile.empty() ? config.m_blockCFGFile : config.m_instCFGFile);
kcUtils::ConstructOutputFileName(baseFile, KC_STR_DEFAULT_CFG_EXT,
entryName, device, cfgOutFileName);
if (!cfgOutFileName.isEmpty())
{
kcUtils::GenerateControlFlowGraph(isaFileName, cfgOutFileName, m_LogCallback, config.m_printProcessCmdLines);
kcUtils::GenerateControlFlowGraph(isaFileName, cfgOutFileName, m_LogCallback,
!config.m_instCFGFile.empty(), config.m_printProcessCmdLines);

if (!beProgramBuilderLightning::VerifyOutputFile(cfgOutFileName.asASCIICharArray()))
{
errMsg << STR_ERR_CANNOT_PERFORM_LIVE_REG_ANALYSIS << " " << STR_KERNEL_NAME << entryName << std::endl;
Expand Down

0 comments on commit c7d81b6

Please sign in to comment.