Skip to content

Commit b6576fd

Browse files
lukaszgotszaldintelsys_zuul
authored andcommitted
refactor IGC/common about IGC_ASSERT
Change-Id: I544a1f451a2b6434a3fc13b1d80f60c6eb406a93
1 parent 7ece6f2 commit b6576fd

File tree

11 files changed

+100
-75
lines changed

11 files changed

+100
-75
lines changed

IGC/common/FunctionUpgrader.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ void FunctionUpgrader::Clean()
4444

4545
llvm::Value* FunctionUpgrader::AddArgument(llvm::StringRef argName, llvm::Type* argType)
4646
{
47+
IGC_ASSERT(nullptr != m_pFunction);
48+
4749
llvm::IGCIRBuilder<> builder(m_pFunction->getContext());
4850
if (m_pFunction->begin()->empty())
4951
{
@@ -83,13 +85,13 @@ Argument* FunctionUpgrader::GetArgumentFromRebuild(llvm::LoadInst* pPlaceHolderA
8385
}
8486
else
8587
{
86-
IGC_ASSERT(false && "There is no created new argument, did you call RebuildFunction?");
88+
IGC_ASSERT_MESSAGE(0, "There is no created new argument, did you call RebuildFunction?");
8789
return nullptr;
8890
}
8991
}
9092
else
9193
{
92-
IGC_ASSERT(false && "Didn't found new argument!");
94+
IGC_ASSERT_MESSAGE(0, "Didn't found new argument!");
9395
return nullptr;
9496
}
9597
}
@@ -101,13 +103,18 @@ std::vector<LoadInst*> FunctionUpgrader::GetPlaceholderVec()
101103

102104
uint32_t FunctionUpgrader::GetArgumentsSize()
103105
{
106+
IGC_ASSERT(nullptr != m_pFunction);
107+
104108
return m_placeHolders.size() + m_pFunction->arg_size();
105109
}
106110

107111
Function* FunctionUpgrader::RebuildFunction()
108112
{
109113
Function* pFunctionRebuild = UpgradeFunctionWithNewArgs();
110114

115+
IGC_ASSERT(nullptr != m_pFunction);
116+
IGC_ASSERT(nullptr != pFunctionRebuild);
117+
111118
auto i_arg_old = m_pFunction->arg_begin();
112119
auto i_arg_new = pFunctionRebuild->arg_begin();
113120

@@ -160,6 +167,8 @@ FunctionType* FunctionUpgrader::UpgradeFunctionTypeWithNewArgs()
160167

161168
Function* FunctionUpgrader::UpgradeFunctionWithNewArgs()
162169
{
170+
IGC_ASSERT(nullptr != m_pFunction);
171+
163172
auto fType = UpgradeFunctionTypeWithNewArgs();
164173
auto fModule = m_pFunction->getParent();
165174
auto fName = m_pFunction->getName();
@@ -172,6 +181,8 @@ Function* FunctionUpgrader::UpgradeFunctionWithNewArgs()
172181
fLinkage,
173182
fName);
174183

184+
IGC_ASSERT(nullptr != fModule);
185+
175186
fModule->getFunctionList().insert(m_pFunction->getIterator(), pNewFunc);
176187

177188
// rename all args

IGC/common/ShaderOverride.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ iga_gen_t GetIGAPlatform(const IGC::CPlatform* platform)
146146
return IGA_GEN12p1;
147147
}
148148
default:
149-
IGC_ASSERT(0 && "unsupported platform");
149+
IGC_ASSERT_MESSAGE(0, "unsupported platform");
150150
break;
151151
}
152152
return IGA_GEN9;

IGC/common/Stats.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ const char* g_cShaderStatItems[STATS_MAX_SHADER_STATS_ITEMS+1] =
6969

7070
int ShaderStats::getShaderStats( SHADER_STATS_ITEMS compileInterval )
7171
{
72-
IGC_ASSERT(compileInterval >= 0 && compileInterval < STATS_MAX_SHADER_STATS_ITEMS);
72+
IGC_ASSERT(0 <= compileInterval);
73+
IGC_ASSERT(compileInterval < STATS_MAX_SHADER_STATS_ITEMS);
7374
return m_CompileShaderStats[compileInterval];
7475
}
7576

@@ -419,7 +420,8 @@ void ShaderStats::parseIsaShader( ShaderHash hash, ShaderType shaderType, SIMDMo
419420

420421
void ShaderStats::sumShaderStat( SHADER_STATS_ITEMS compileInterval, int count )
421422
{
422-
IGC_ASSERT(compileInterval >= 0 && compileInterval < STATS_MAX_SHADER_STATS_ITEMS);
423+
IGC_ASSERT(0 <= compileInterval);
424+
IGC_ASSERT(compileInterval < STATS_MAX_SHADER_STATS_ITEMS);
423425
m_CompileShaderStats[ compileInterval ] += count;
424426
};
425427

@@ -456,7 +458,7 @@ std::string str(COMPILE_TIME_INTERVALS cti)
456458
#define DEFINE_TIME_STAT( enumName, stringName, parentEnum, isVISA, isUnacc, isCoarseTimer, isDashBoardTimer ) case enumName: return #enumName;
457459
#include "timeStats.def"
458460
#undef DEFINE_TIME_STAT
459-
default: IGC_ASSERT(0 && "unreachable"); break;
461+
default: IGC_ASSERT_MESSAGE(0, "unreachable"); break;
460462
}
461463

462464
return "";
@@ -472,7 +474,7 @@ COMPILE_TIME_INTERVALS interval( std::string const& str )
472474
#include "timeStats.def"
473475
#undef DEFINE_TIME_STAT
474476
//llvm::errs() << str;
475-
IGC_ASSERT(0 && "unreachable" && "unknown COMPILE_TIME_INTERVALS name");
477+
IGC_ASSERT_MESSAGE(0, "unreachable, unknown COMPILE_TIME_INTERVALS name");
476478
return MAX_COMPILE_TIME_INTERVALS;
477479
}
478480

@@ -483,7 +485,7 @@ bool isVISATimer( COMPILE_TIME_INTERVALS cti )
483485
#define DEFINE_TIME_STAT( enumName, stringName, parentEnum, isVISA, isUnacc, isCoarseTimer, isDashBoardTimer ) case enumName: return isVISA;
484486
#include "timeStats.def"
485487
#undef DEFINE_TIME_STAT
486-
default: IGC_ASSERT(0 && "unreachable"); break;
488+
default: IGC_ASSERT_MESSAGE(0, "unreachable"); break;
487489
}
488490
return false;
489491
}
@@ -495,7 +497,7 @@ bool isUnaccounted( COMPILE_TIME_INTERVALS cti )
495497
#define DEFINE_TIME_STAT( enumName, stringName, parentEnum, isVISA, isUnacc, isCoarseTimer, isDashBoardTimer ) case enumName: return isUnacc;
496498
#include "timeStats.def"
497499
#undef DEFINE_TIME_STAT
498-
default: IGC_ASSERT(0 && "unreachable"); break;
500+
default: IGC_ASSERT_MESSAGE(0, "unreachable"); break;
499501
}
500502
return false;
501503
}
@@ -507,7 +509,7 @@ bool isCoarseTimer( COMPILE_TIME_INTERVALS cti )
507509
#define DEFINE_TIME_STAT( enumName, stringName, parentEnum, isVISA, isUnacc, isCoarseTimer, isDashBoardTimer ) case enumName: return isCoarseTimer;
508510
#include "timeStats.def"
509511
#undef DEFINE_TIME_STAT
510-
default: IGC_ASSERT(0 && "unreachable"); break;
512+
default: IGC_ASSERT_MESSAGE(0, "unreachable"); break;
511513
}
512514
return true;
513515
}
@@ -519,7 +521,7 @@ bool isDashboardTimer( COMPILE_TIME_INTERVALS cti )
519521
#define DEFINE_TIME_STAT( enumName, stringName, parentEnum, isVISA, isUnacc, isCoarseTimer, isDashBoardTimer ) case enumName: return isDashBoardTimer;
520522
#include "timeStats.def"
521523
#undef DEFINE_TIME_STAT
522-
default: IGC_ASSERT(0 && "unreachable"); break;
524+
default: IGC_ASSERT_MESSAGE(0, "unreachable"); break;
523525
}
524526

525527
return true;
@@ -532,7 +534,7 @@ COMPILE_TIME_INTERVALS parentInterval( COMPILE_TIME_INTERVALS cti )
532534
#define DEFINE_TIME_STAT( enumName, stringName, parentEnum, isVISA, isUnacc, isCoarseTimer, isDashBoardTimer ) case enumName: return parentEnum;
533535
#include "timeStats.def"
534536
#undef DEFINE_TIME_STAT
535-
default: IGC_ASSERT(0 && "unreachable"); break;
537+
default: IGC_ASSERT_MESSAGE(0, "unreachable"); break;
536538
}
537539
return MAX_COMPILE_TIME_INTERVALS;
538540
}
@@ -581,26 +583,30 @@ void TimeStats::recordVISATimers()
581583

582584
void TimeStats::recordTimerStart( COMPILE_TIME_INTERVALS compileInterval )
583585
{
584-
IGC_ASSERT(compileInterval >= 0 && compileInterval < MAX_COMPILE_TIME_INTERVALS);
586+
IGC_ASSERT(0 <= compileInterval);
587+
IGC_ASSERT(compileInterval < MAX_COMPILE_TIME_INTERVALS);
585588
m_wallclockStart[ compileInterval ] = iSTD::GetTimestampCounter();
586589
}
587590

588591
void TimeStats::recordTimerEnd( COMPILE_TIME_INTERVALS compileInterval )
589592
{
590-
IGC_ASSERT(compileInterval >= 0 && compileInterval < MAX_COMPILE_TIME_INTERVALS);
593+
IGC_ASSERT(0 <= compileInterval);
594+
IGC_ASSERT(compileInterval < MAX_COMPILE_TIME_INTERVALS);
591595
m_elapsedTime[ compileInterval ] += iSTD::GetTimestampCounter() - m_wallclockStart[ compileInterval ];
592596
m_hitCount[ compileInterval ]++;
593597
}
594598

595599
uint64_t TimeStats::getCompileTime( COMPILE_TIME_INTERVALS compileInterval ) const
596600
{
597-
IGC_ASSERT(compileInterval >= 0 && compileInterval < MAX_COMPILE_TIME_INTERVALS);
601+
IGC_ASSERT(0 <= compileInterval);
602+
IGC_ASSERT(compileInterval < MAX_COMPILE_TIME_INTERVALS);
598603
return m_elapsedTime[ compileInterval ];
599604
}
600605

601606
uint64_t TimeStats::getCompileHit( COMPILE_TIME_INTERVALS compileInterval ) const
602607
{
603-
IGC_ASSERT(compileInterval >= 0 && compileInterval < MAX_COMPILE_TIME_INTERVALS);
608+
IGC_ASSERT(0 <= compileInterval);
609+
IGC_ASSERT(compileInterval < MAX_COMPILE_TIME_INTERVALS);
604610
return m_hitCount[ compileInterval ];
605611
}
606612

@@ -712,7 +718,7 @@ bool TimeStats::skipTimer( int i ) const
712718
}
713719
void TimeStats::printSumTimeCSV(const char* outputFile) const
714720
{
715-
IGC_ASSERT(m_isPostProcessed && "Print functions should only be called on a Post-Processed TimeStats object");
721+
IGC_ASSERT_MESSAGE(m_isPostProcessed, "Print functions should only be called on a Post-Processed TimeStats object");
716722

717723
bool fileExist = false;
718724

@@ -786,7 +792,7 @@ void TimeStats::printSumTimeCSV(const char* outputFile) const
786792

787793
void TimeStats::printPerPassSumTimeCSV(const char* outputFile) const
788794
{
789-
IGC_ASSERT(m_isPostProcessed && "Print functions should only be called on a Post-Processed TimeStats object");
795+
IGC_ASSERT_MESSAGE(m_isPostProcessed, "Print functions should only be called on a Post-Processed TimeStats object");
790796

791797
if (m_PassTimeStatsMap.empty())
792798
{
@@ -898,7 +904,7 @@ namespace {
898904

899905
void TimeStats::printSumTimeTable( llvm::raw_ostream & OS ) const
900906
{
901-
IGC_ASSERT(m_isPostProcessed && "Print functions should only be called on a Post-Processed TimeStats object");
907+
IGC_ASSERT_MESSAGE(m_isPostProcessed, "Print functions should only be called on a Post-Processed TimeStats object");
902908

903909
llvm::formatted_raw_ostream FS(OS);
904910

@@ -1041,7 +1047,7 @@ void TimeStats::printPerPassSumTime(llvm::raw_ostream& OS) const
10411047

10421048
void TimeStats::printTimeCSV( std::string const& corpusName ) const
10431049
{
1044-
IGC_ASSERT(m_isPostProcessed && "Print functions should only be called on a Post-Processed TimeStats object");
1050+
IGC_ASSERT_MESSAGE(m_isPostProcessed, "Print functions should only be called on a Post-Processed TimeStats object");
10451051

10461052
const std::string outputFilePath = std::string("c:\\Intel\\") + "TimeStat_" + IGC::Debug::GetShaderCorpusName() + ".csv";
10471053
const char *outputFile = outputFilePath.c_str();
@@ -1090,7 +1096,7 @@ void TimeStats::printTimeCSV( std::string const& corpusName ) const
10901096

10911097
void TimeStats::printPerPassTimeCSV(std::string const& corpusName) const
10921098
{
1093-
IGC_ASSERT(m_isPostProcessed && "Print functions should only be called on a Post-Processed TimeStats object");
1099+
IGC_ASSERT_MESSAGE(m_isPostProcessed, "Print functions should only be called on a Post-Processed TimeStats object");
10941100

10951101
if (m_PassTimeStatsMap.empty())
10961102
{

IGC/common/SysUtils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@ namespace IGC
7575
#if defined (__linux__)
7676
ifstream in(MakeStr("/proc/", getpid(), "/cmdline"), ios::in);
7777
if (!in.is_open())
78-
IGC_ASSERT(0 && "Can not open cmdline pseudo file for current process");
78+
IGC_ASSERT_MESSAGE(0, "Can not open cmdline pseudo file for current process");
7979

8080
//in cmdline arguments are separated with \0
8181
getline(in, ret, '\0');
8282
if (!in.good())
83-
IGC_ASSERT(0 && "Error reading from cmdline pseudo file");
83+
IGC_ASSERT_MESSAGE(0, "Error reading from cmdline pseudo file");
8484

8585
#elif defined(_WIN64) || defined(_WIN32)
8686
ret.resize(MAX_PATH);
8787
DWORD size = ::GetModuleFileNameA(NULL, &ret[0], ret.size());
88-
IGC_ASSERT(size < ret.size() && "Windows path can have MAX_PATH characters max");
88+
IGC_ASSERT_MESSAGE(size < ret.size(), "Windows path can have MAX_PATH characters max");
8989
ret.resize(size);
9090
#endif
9191

IGC/common/SystemThread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ CGenSystemInstructionKernelProgram* CGenSystemInstructionKernelProgram::Create(
367367
}
368368
else
369369
{
370-
IGC_ASSERT((SIPIndex < SIPKernelInfo.size()) && ("Invalid SIPIndex while loading"));
370+
IGC_ASSERT_MESSAGE((SIPIndex < SIPKernelInfo.size()), "Invalid SIPIndex while loading");
371371
m_LinearAddress = SIPKernelInfo[SIPIndex].first;
372372
m_ProgramSize = SIPKernelInfo[SIPIndex].second;
373373
}

IGC/common/Types.hpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ inline uint16_t numLanes(SIMDMode width)
102102
case SIMDMode::SIMD16 : return 16;
103103
case SIMDMode::SIMD32 : return 32;
104104
case SIMDMode::UNKNOWN :
105-
default : IGC_ASSERT(0 && "unreachable"); break;
105+
default:
106+
IGC_ASSERT_MESSAGE(0, "unreachable");
107+
return 1;
106108
}
107-
return 1;
108109
}
109110

110111
inline SIMDMode lanesToSIMDMode(unsigned lanes) {
@@ -116,11 +117,9 @@ inline SIMDMode lanesToSIMDMode(unsigned lanes) {
116117
case 16: return SIMDMode::SIMD16;
117118
case 32: return SIMDMode::SIMD32;
118119
default:
119-
break;
120+
IGC_ASSERT_MESSAGE(0, "Unexpected number of lanes!");
121+
return SIMDMode::UNKNOWN;
120122
}
121-
122-
IGC_ASSERT(false && "Unexpected number of lanes!");
123-
return SIMDMode::UNKNOWN;
124123
}
125124

126125
enum class ShaderType
@@ -280,8 +279,9 @@ inline typename std::enable_if<
280279
static_assert(std::is_integral<TDst>::value && std::is_integral<TSrc>::value,
281280
"int_cast<>() should be used only for conversions between integer types.");
282281

283-
IGC_ASSERT(std::numeric_limits<TDst>::min() <= value &&
284-
value <= std::numeric_limits<TDst>::max());
282+
IGC_ASSERT(std::numeric_limits<TDst>::min() <= value);
283+
IGC_ASSERT(value <= std::numeric_limits<TDst>::max());
284+
285285
return static_cast<TDst>(value);
286286
}
287287

@@ -293,8 +293,8 @@ inline typename std::enable_if<
293293
static_assert(std::is_integral<TDst>::value && std::is_integral<TSrc>::value,
294294
"int_cast<>() should be used only for conversions between integer types.");
295295

296-
IGC_ASSERT(value <= static_cast<typename std::make_unsigned<TDst>::type>(
297-
std::numeric_limits<TDst>::max()));
296+
IGC_ASSERT(value <= static_cast<typename std::make_unsigned<TDst>::type>(std::numeric_limits<TDst>::max()));
297+
298298
return static_cast<TDst>(value);
299299
}
300300

@@ -306,8 +306,9 @@ inline typename std::enable_if<
306306
static_assert(std::is_integral<TDst>::value && std::is_integral<TSrc>::value,
307307
"int_cast<>() should be used only for conversions between integer types.");
308308

309-
IGC_ASSERT(0 <= value &&
310-
static_cast<typename std::make_unsigned<TSrc>::type>(value) <= std::numeric_limits<TDst>::max());
309+
IGC_ASSERT(0 <= value);
310+
IGC_ASSERT(static_cast<typename std::make_unsigned<TSrc>::type>(value) <= std::numeric_limits<TDst>::max());
311+
311312
return static_cast<TDst>(value);
312313
}
313314

@@ -344,8 +345,7 @@ inline typename std::enable_if<
344345
static_assert(std::is_integral<TDst>::value,
345346
"int_cast<>() should be used only for conversions between integer types.");
346347

347-
IGC_ASSERT(value.getFixedSize() <= static_cast<typename std::make_unsigned<TDst>::type>(
348-
std::numeric_limits<TDst>::max()));
348+
IGC_ASSERT(value.getFixedSize() <= static_cast<typename std::make_unsigned<TDst>::type>(std::numeric_limits<TDst>::max()));
349349
return static_cast<TDst>(value.getFixedSize());
350350
}
351351

0 commit comments

Comments
 (0)