Skip to content

Commit 2557c11

Browse files
MichalMroz12igcbot
authored andcommitted
Coverity Fixes & Refactors
Coverity Fixes & Refactors
1 parent fee0a7d commit 2557c11

18 files changed

+34
-34
lines changed

IGC/AdaptorOCL/preprocess_spvir/ConvertUserSemanticDecoratorOnFunctions.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static void convertAnnotationsToAttributes(llvm::Function* function, const std::
6161
::isspace),
6262
numThreadPerEU.end());
6363

64-
function->addFnAttr("num-thread-per-eu", numThreadPerEU == "auto" ? "0" : numThreadPerEU);
64+
function->addFnAttr("num-thread-per-eu", numThreadPerEU == "auto" ? "0" : std::move(numThreadPerEU));
6565
}
6666
}
6767
}

IGC/AdaptorOCL/preprocess_spvir/PromoteBools.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ void PromoteBools::setPromotedAttributes(Function* newFunction, AttributeList& a
520520

521521
// set function attributes
522522
AttrBuilder attrBuilder(newFunction->getContext());
523-
for (auto attr : IGCLLVM::getFnAttrs(attributeList))
523+
for (const auto& attr : IGCLLVM::getFnAttrs(attributeList))
524524
{
525525
attrBuilder.addAttribute(getPromoted(attr));
526526
}

IGC/Compiler/CISACodeGen/CISABuilder.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ namespace IGC
770770
WA_TABLE m_vISAWaTable = {};
771771

772772
// Keeps current state of denorm mode set in cr0 register.
773-
uint32_t m_fpDenormMode;
773+
uint32_t m_fpDenormMode{};
774774

775775
enum OpType
776776
{

IGC/Compiler/CISACodeGen/CapLoopIterationsPass.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ bool CapLoopIterations::runOnFunction(Function& F)
7878

7979
loop->getExitEdges(exitedges);
8080

81-
for (auto [exitingbb, exitbb] : exitedges)
81+
for (const auto& [exitingbb, exitbb] : exitedges)
8282
{
8383
if (auto br = dyn_cast<BranchInst>(exitingbb->getTerminator()))
8484
{

IGC/Compiler/CISACodeGen/GenCodeGenModule.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1287,8 +1287,8 @@ namespace {
12871287
/// \brief Custom inliner for subroutines.
12881288
class SubroutineInliner : public LegacyInlinerBase, public llvm::InstVisitor<SubroutineInliner>
12891289
{
1290-
EstimateFunctionSize* FSA;
1291-
MetaDataUtilsWrapper* MDUW;
1290+
EstimateFunctionSize* FSA = nullptr;
1291+
MetaDataUtilsWrapper* MDUW = nullptr;
12921292
public:
12931293
static char ID; // Pass identification, replacement for typeid
12941294

IGC/Compiler/CISACodeGen/MemOpt.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ namespace {
324324
// This is for enabling the mergeload improvement (comparing GEP's last
325325
// index instead) as it requires to turn off GEP canonicalization.
326326
bool EnableCanonicalizeGEP() const {
327+
IGC_ASSERT(CGC != nullptr);
327328
// The new mergeload improvement is intended for PVC+ for now.
328329
if (CGC->platform.getPlatformInfo().eProductFamily != IGFX_PVC &&
329330
!CGC->platform.isProductChildOf(IGFX_PVC)) {
@@ -336,7 +337,7 @@ namespace {
336337
return false;
337338
case 2:
338339
{
339-
if (CGC && CGC->type == ShaderType::OPENCL_SHADER)
340+
if (CGC->type == ShaderType::OPENCL_SHADER)
340341
return false;
341342
break;
342343
}
@@ -4951,7 +4952,7 @@ void BundleInfo::print(raw_ostream& O, int BundleID) const
49514952
<< "num of elements = " << bundle_numElts << " "
49524953
<< "useD64 = " << (useD64 ? "true" : "false") << "\n\n";
49534954

4954-
for (const auto II : LoadStores) {
4955+
for (const auto& II : LoadStores) {
49554956
const LdStInfo& LSI = II;
49564957
O << " (" << format_decimal(LSI.ByteOffset, 3) << ") ";
49574958
O << *LSI.Inst << "\n";

IGC/Compiler/CISACodeGen/RematAddressArithmetic.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void putAddrSpaceCastClose(Function &F) {
113113
auto User = U->getUser();
114114
auto UserInst = llvm::dyn_cast<Instruction>(User);
115115

116-
if(llvm::isa<PHINode>(UserInst)) continue;
116+
if(llvm::isa_and_nonnull<PHINode>(UserInst)) continue;
117117

118118
if(UserInst) {
119119
auto Clone = I->clone();

IGC/Compiler/CISACodeGen/VectorPreProcess.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ bool VectorPreProcess::splitLoadStore(
10071007
// so that the stored value will be directly from loaded values
10081008
// without adding insert/extract instructions.
10091009
Optional<AbstractLoadInst> aALI = ASI && !InMap(ASI->getValueOperand()) ?
1010-
AbstractLoadInst::get(ASI->getValueOperand(), *m_DL) : ALI;
1010+
AbstractLoadInst::get(ASI->getValueOperand(), *m_DL) : std::move(ALI);
10111011

10121012
if (aALI)
10131013
{

IGC/Compiler/Optimizer/SynchronizationObjectCoalescing.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ auto GetIterationFunc(
14511451
return;
14521452
}
14531453
auto currBBInstsRange = GetMapRange(currBBInstsIt->second, lookupTable, it, end);
1454-
for (auto [index, val] : currBBInstsRange.first)
1454+
for (const auto& [index, val] : currBBInstsRange.first)
14551455
{
14561456
if (IsExpectedInst(val))
14571457
{
@@ -1488,7 +1488,7 @@ auto GetIterationFunc(
14881488
return;
14891489
}
14901490
auto currBBInstsRange = GetMapRange(currBBInstsIt->second, lookupTable, it, end);
1491-
for (auto [index, val] : currBBInstsRange.first)
1491+
for (const auto& [index, val] : currBBInstsRange.first)
14921492
{
14931493
instructions.push_back(val);
14941494
}

IGC/VectorCompiler/lib/GenXCodeGen/GenXSimdCFConformance.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ bool GenXSimdCFConformance::hoistGotoUser(Instruction *Inst, CallInst *Goto,
14211421
std::map<BasicBlock *, Value *> foundVals;
14221422
std::vector<Value *> newOperands;
14231423
for (auto ui = Inst->use_begin(), ue = Inst->use_end(); ui != ue; ++ui) {
1424-
auto User = dyn_cast<Instruction>(ui->getUser());
1424+
auto User = cast<Instruction>(ui->getUser());
14251425
// TODO: it can be solved with duplicated instructions.
14261426
// Currently we are not going to duplicate them.
14271427
if (User->getParent() == Inst->getParent()) {
@@ -2080,7 +2080,7 @@ void GenXSimdCFConformance::lowerUnsuitableGetEMs() {
20802080
std::vector<Instruction *> ToDelete;
20812081
for (auto ui = GetEMDecl->use_begin(); ui != GetEMDecl->use_end();) {
20822082
std::set<Value *> Visited;
2083-
auto GetEM = dyn_cast<Instruction>(ui->getUser());
2083+
auto GetEM = cast<Instruction>(ui->getUser());
20842084
++ui;
20852085
auto GetEMPred = GetEM->getOperand(0);
20862086

IGC/VectorCompiler/lib/GenXCodeGen/GenXSimdCFRegion.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -871,9 +871,8 @@ bool GenXPredToSimdCF::analizeInsts(BBContainer *Container, Value *Cond) {
871871
std::function<void(User *, Value *, MatcherType)> TryToFindBlock;
872872
TryToFindBlock = [&](User *Usr, Value *PredInst, MatcherType Matcher) {
873873
if (Matcher(Usr, PredInst)) {
874-
auto *Inst = dyn_cast<Instruction>(Usr);
875-
LLVM_DEBUG(dbgs() << Inst->getFunction()->getName() << " - "
876-
<< Inst->getName() << "\n");
874+
auto *Inst = cast<Instruction>(Usr);
875+
LLVM_DEBUG(dbgs() << Inst->getFunction()->getName() << " - " << Inst->getName() << "\n");
877876
BBs.insert(Inst->getParent());
878877
}
879878
if (auto *Inst = dyn_cast<PHINode>(Usr))
@@ -1423,7 +1422,7 @@ void GenXPredToSimdCF::insertLoopGotoJoin(SimdCFLoopRegion *R) {
14231422

14241423
void GenXPredToSimdCF::replaceUses(Use *Ui, bool BuildEM) {
14251424
auto *Use = Ui->getUser();
1426-
auto *Inst = dyn_cast<Instruction>(Use);
1425+
auto *Inst = cast<Instruction>(Use);
14271426
LLVM_DEBUG(dbgs() << "replaceUses: for instruction " << *Inst);
14281427
auto OpNo = Ui->getOperandNo();
14291428
auto *CondTy = Inst->getOperand(OpNo)->getType();
@@ -1468,7 +1467,7 @@ void GenXPredToSimdCF::replaceUses(Use *Ui, bool BuildEM) {
14681467
bool GenXPredToSimdCF::TryReplace(SimdCFRegionBase *Reg, Use *Ui, bool IsEm) {
14691468
if (!Reg)
14701469
return false;
1471-
auto *Inst = dyn_cast<Instruction>(Ui->getUser());
1470+
auto *Inst = cast<Instruction>(Ui->getUser());
14721471
auto *Par = Inst->getParent();
14731472
if (isa<SelectInst>(Inst) && (Ui->getOperandNo() == 0)) {
14741473
auto Exit = Reg->getExit();

IGC/VectorCompiler/lib/GenXCodeGen/GenXStructSplitter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1783,7 +1783,7 @@ bool Substituter::processPTIsUses(Instruction &I,
17831783
uint64_t /*OUT*/ &MaxPtrOffset) {
17841784
uint64_t LocalPtrOffset{0};
17851785
for (const auto &U : I.uses()) {
1786-
Instruction *User = dyn_cast<Instruction>(U.getUser());
1786+
Instruction *User = cast<Instruction>(U.getUser());
17871787
auto Opcode = User->getOpcode();
17881788
if (Opcode == Instruction::Add || Opcode == Instruction::Or) {
17891789
IGC_ASSERT_EXIT(dyn_cast<BinaryOperator>(User));

IGC/common/SysUtils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ namespace IGC
127127
}
128128

129129
if (full_path != nullptr)
130-
*full_path = basedir;
130+
*full_path = std::move(basedir);
131131

132132
return true;
133133
}

IGC/common/debug/Dump.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ DumpName DumpName::Pass(std::string const& name, llvm::Optional<unsigned int> in
198198
[](const char s) { return s == '/' || s == '\\'; }, '_');
199199
IGC_ASSERT_MESSAGE(newName.find(' ') == std::string::npos, "Pass name must not contain spaces");
200200
DumpName copy(*this);
201-
CPassDescriptor pd = { newName, index };
201+
CPassDescriptor pd = { std::move(newName), index };
202202
copy.m_pass = pd;
203203
return copy;
204204
}

visa/BuildCISAIRImpl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2231,7 +2231,7 @@ bool CISA_IR_Builder::CISA_lookup_builtin_constant(int lineNum,
22312231
val = m_dispatchSimdSize;
22322232
return true;
22332233
} else {
2234-
RecordParseError(lineNum, sym, ": invalid built-in symbol");
2234+
RecordParseError(lineNum, std::move(sym), ": invalid built-in symbol");
22352235
val = -1;
22362236
return false;
22372237
}

visa/SpillCleanup.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ void CoalesceSpillFills::keepConsecutiveSpills(
620620
}
621621
}
622622

623-
instList = origInstList;
623+
instList = std::move(origInstList);
624624
for (auto coalIt = coalescable.begin(), instIt = instList.begin();
625625
coalIt != coalescable.end(); coalIt++) {
626626
if (*instIt == *coalIt)
@@ -699,7 +699,7 @@ CoalesceSpillFills::analyzeFillCoalescing(std::list<INST_LIST_ITER> &instList,
699699
fillHeuristic(coalesceableFills, instList, origInstList, min, max);
700700
if (!heuristic) {
701701
coalesceableFills.clear();
702-
instList = origInstList;
702+
instList = std::move(origInstList);
703703
instList.pop_front();
704704
}
705705

visa/iga/IGALibrary/Frontend/IRToString.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ std::string iga::ToSyntax(MathFC sf) {
7272
return fmtHex(static_cast<uint32_t>(sf)) + "?";
7373
}
7474
}
75-
template <> MathFC iga::FromSyntax<MathFC>(std::string syn) {
75+
template <> MathFC iga::FromSyntax<MathFC>(const std::string& syn) {
7676
for (auto sf : ALL_MathFCs) {
7777
if (syn == ToSyntax(sf))
7878
return sf;
@@ -126,7 +126,7 @@ std::string iga::ToSyntax(SFID sfid) {
126126
return ss.str();
127127
}
128128
}
129-
template <> SFID iga::FromSyntax<SFID>(std::string syn) {
129+
template <> SFID iga::FromSyntax<SFID>(const std::string& syn) {
130130
for (SFID sf : ALL_SFIDS) {
131131
if (syn == ToSyntax(sf))
132132
return sf;
@@ -155,7 +155,7 @@ std::string iga::ToSyntax(SyncFC sfc) {
155155
return fmtHex(static_cast<uint32_t>(sfc)) + "?";
156156
}
157157
}
158-
template <> SyncFC iga::FromSyntax<SyncFC>(std::string syn) {
158+
template <> SyncFC iga::FromSyntax<SyncFC>(const std::string& syn) {
159159
for (auto sf : ALL_SyncFCs) {
160160
if (syn == ToSyntax(sf))
161161
return sf;
@@ -237,7 +237,7 @@ std::string iga::ToSyntax(DpasFC sfc) {
237237
return fmtHex(static_cast<uint32_t>(sfc)) + "?";
238238
}
239239
}
240-
template <> DpasFC iga::FromSyntax<DpasFC>(std::string syn) {
240+
template <> DpasFC iga::FromSyntax<DpasFC>(const std::string& syn) {
241241
for (auto sf : ALL_DpasFCs) {
242242
if (syn == ToSyntax(sf))
243243
return sf;

visa/iga/IGALibrary/Frontend/IRToString.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -787,19 +787,19 @@ static inline std::string ToSyntax(const InstOptSet &instOpts) {
787787

788788
/////////////////////////////////////////////////////
789789
// manually defined enumerations from BXML
790-
template <typename T> T FromSyntax(std::string str);
790+
template <typename T> T FromSyntax(const std::string& str);
791791

792792
std::string ToSyntax(MathFC sfc);
793-
template <> MathFC FromSyntax<MathFC>(std::string str);
793+
template <> MathFC FromSyntax<MathFC>(const std::string& str);
794794

795795
std::string ToSyntax(SFID sfid);
796-
template <> SFID FromSyntax<SFID>(std::string str);
796+
template <> SFID FromSyntax<SFID>(const std::string& str);
797797

798798
std::string ToSyntax(SyncFC sfc);
799-
template <> SyncFC FromSyntax<SyncFC>(std::string str);
799+
template <> SyncFC FromSyntax<SyncFC>(const std::string& str);
800800

801801
std::string ToSyntax(DpasFC sfc);
802-
template <> DpasFC FromSyntax<DpasFC>(std::string str);
802+
template <> DpasFC FromSyntax<DpasFC>(const std::string& str);
803803

804804
} // namespace iga
805805

0 commit comments

Comments
 (0)