Skip to content

Commit 3bb8c52

Browse files
fda0igcbot
authored andcommitted
Various vISA refactors
Pass arguments as references. Iterate in loops using references. Fix potential nullptr dereferences. Conform to rule of three or rule of five.
1 parent d8d4d6d commit 3bb8c52

19 files changed

+28
-16
lines changed

visa/BinaryEncodingIGA.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class BinaryEncodingIGA {
3636
const TARGET_PLATFORM platform;
3737

3838
public:
39-
BinaryEncodingIGA(vISA::G4_Kernel &k, std::string fname);
39+
BinaryEncodingIGA(vISA::G4_Kernel &k, const std::string& fname);
4040
~BinaryEncodingIGA() { delete IGAKernel; }
4141

4242
void SetSWSB(G4_INST *inst, SWSB &sw);
@@ -378,7 +378,7 @@ BinaryEncodingIGA::getIGAInternalPlatform(TARGET_PLATFORM genxPlatform) {
378378
return platform;
379379
}
380380

381-
BinaryEncodingIGA::BinaryEncodingIGA(vISA::G4_Kernel &k, std::string fname)
381+
BinaryEncodingIGA::BinaryEncodingIGA(vISA::G4_Kernel &k, const std::string& fname)
382382
: kernel(k), fileName(fname), m_kernelBuffer(nullptr),
383383
m_kernelBufferSize(0), platform(k.fg.builder->getPlatform()) {
384384
platformModel = Model::LookupModel(getIGAInternalPlatform(platform));

visa/BuildIR.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,8 @@ class IR_Builder {
651651
const WA_TABLE *pWaTable);
652652

653653
~IR_Builder();
654+
IR_Builder(const IR_Builder&) = delete;
655+
IR_Builder& operator=(const IR_Builder&) = delete;
654656

655657
void setR0ReadOnly() {
656658
// NONE is stronger than READ_ONLY, so don't change it

visa/Common_ISA.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ struct CISA_GEN_VAR {
535535
};
536536

537537
CISA_GEN_VAR(const CISA_GEN_VAR &) = delete;
538+
CISA_GEN_VAR& operator=(const CISA_GEN_VAR&) = delete;
538539
};
539540

540541
// vISA variables share the same implementation, but are distinct types

visa/FrequencyInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void FrequencyInfo::storeStaticFrequencyAsMetadata(G4_INST* i)
6363
void FrequencyInfo::updateStaticFrequencyForBasicBlock(G4_BB *bb) {
6464
G4_INST *lastInst =
6565
!bb->getInstList().empty() ? bb->getInstList().back() : nullptr;
66-
if (hasFreqMetaData(lastInst)) {
66+
if (lastInst && hasFreqMetaData(lastInst)) {
6767
MDNode *mn_digits = lastInst->getMetadata("stats.blockFrequency.digits");
6868
MDNode *mn_scale = lastInst->getMetadata("stats.blockFrequency.scale");
6969
Scaled64 freq =

visa/G4_Operand.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ class G4_SrcRegRegion final : public G4_Operand {
539539

540540
public:
541541
G4_SrcRegRegion(G4_SrcRegRegion &rgn);
542+
G4_SrcRegRegion& operator=(const G4_SrcRegRegion&) = delete;
542543
void *operator new(size_t sz, Mem_Manager &m) { return m.alloc(sz); }
543544

544545
bool operator==(const G4_SrcRegRegion &other) {
@@ -715,6 +716,7 @@ class G4_DstRegRegion final : public G4_Operand {
715716
G4_DstRegRegion(G4_DstRegRegion &rgn);
716717
G4_DstRegRegion(const IR_Builder &builder, G4_DstRegRegion &rgn,
717718
G4_VarBase *new_base);
719+
G4_DstRegRegion& operator=(const G4_DstRegRegion&) = delete;
718720

719721
void computeLeftBound(const IR_Builder &builder);
720722

@@ -847,6 +849,7 @@ class G4_Predicate final : public G4_Operand {
847849

848850
public:
849851
G4_Predicate(G4_Predicate &prd);
852+
G4_Predicate& operator=(const G4_Predicate&) = delete;
850853

851854
void *operator new(size_t sz, Mem_Manager &m) { return m.alloc(sz); }
852855
unsigned short getSubRegOff() const { return subRegOff; }

visa/LocalDataflow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class DefEscapeBBAnalysis {
5050
DefEscapeBBAnalysis(const FlowGraph &cfg) : fg(cfg) {}
5151

5252
DefEscapeBBAnalysis(const DefEscapeBBAnalysis &analysis) = delete;
53+
DefEscapeBBAnalysis& operator=(const DefEscapeBBAnalysis&) = delete;
5354

5455
virtual ~DefEscapeBBAnalysis() = default;
5556

visa/LocalScheduler/SWSB_G4IR.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ struct SBBitSets {
182182
SparseBitVector src;
183183

184184
SBBitSets() {}
185-
185+
SBBitSets(SBBitSets&& other) = delete;
186+
SBBitSets& operator=(SBBitSets&& other) = delete;
186187
~SBBitSets() {}
187188

188189
void setDst(int ID, bool value) {

visa/Passes/AccSubstitution.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class AccSubPass {
3636
AccSubPass(IR_Builder &B, G4_Kernel &K) : builder(B), kernel(K) {}
3737

3838
AccSubPass(const AccSubPass &) = delete;
39+
AccSubPass& operator=(const AccSubPass&) = delete;
3940

4041
virtual ~AccSubPass() = default;
4142

visa/Passes/StaticProfiling.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class StaticProfiling {
2424
: builder(B), kernel(K) {}
2525

2626
StaticProfiling(const StaticProfiling &) = delete;
27+
StaticProfiling& operator=(const StaticProfiling&) = delete;
2728
virtual ~StaticProfiling() = default;
2829

2930
void ALUInstructionProfile(G4_INST *inst);

visa/VISAKernel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ class VISAKernelImpl : public VISAFunction {
482482
VISA_BUILDER_API int
483483
AppendVISACFFunctionCallInst(VISA_PredOpnd *pred, VISA_EMask_Ctrl emask,
484484
VISA_Exec_Size executionSize,
485-
std::string funcName, unsigned char argSize,
485+
const std::string& funcName, unsigned char argSize,
486486
unsigned char returnSize) override;
487487

488488
VISA_BUILDER_API int
@@ -491,7 +491,7 @@ class VISAKernelImpl : public VISAFunction {
491491
VISA_VectorOpnd *funcAddr, uint8_t argSize,
492492
uint8_t returnSize) override;
493493

494-
VISA_BUILDER_API int AppendVISACFSymbolInst(std::string symbolName,
494+
VISA_BUILDER_API int AppendVISACFSymbolInst(const std::string& symbolName,
495495
VISA_VectorOpnd *dst) override;
496496

497497
VISA_BUILDER_API int

visa/VISAKernelImpl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3270,7 +3270,7 @@ int VISAKernelImpl::AppendVISACFLabelInst(VISA_LabelOpnd *label) {
32703270

32713271
int VISAKernelImpl::AppendVISACFFunctionCallInst(
32723272
VISA_PredOpnd *pred, VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize,
3273-
std::string funcName, unsigned char argSize, unsigned char returnSize) {
3273+
const std::string& funcName, unsigned char argSize, unsigned char returnSize) {
32743274
TIME_SCOPE(VISA_BUILDER_APPEND_INST);
32753275

32763276
AppendVISAInstCommon();
@@ -3383,7 +3383,7 @@ int VISAKernelImpl::AppendVISACFIndirectFuncCallInst(
33833383
return status;
33843384
}
33853385

3386-
int VISAKernelImpl::AppendVISACFSymbolInst(std::string symbolName,
3386+
int VISAKernelImpl::AppendVISACFSymbolInst(const std::string& symbolName,
33873387
VISA_VectorOpnd *dst) {
33883388
TIME_SCOPE(VISA_BUILDER_APPEND_INST);
33893389

visa/iga/IGALibrary/Backend/Native/InstDecoder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ struct InstDecoder {
221221

222222
///////////////////////////////////////////
223223
// PRIMITIVE FIELD ADDERS
224-
void addDecodedField(const Field &f, std::string meaning) {
224+
void addDecodedField(const Field &f, const std::string& meaning) {
225225
if (fields) {
226226
int encodedFragments = 0;
227227
for (const Fragment &fr : f.fragments) {

visa/iga/IGALibrary/Backend/Native/InstEncoder.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class InstEncoder : public BitProcessor {
127127
const Model &_model)
128128
: BitProcessor(_parent), opts(_opts), model(_model) {}
129129
InstEncoder(const InstEncoder &) = delete;
130+
InstEncoder& operator=(const InstEncoder&) = delete;
130131

131132
BackpatchList &getBackpatches() { return backpatches; }
132133

visa/iga/IGALibrary/IR/Block.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ Block::inferBlocks(ErrorHandler &errHandler, MemManager &mem, InstList &insts) {
182182
bi.run(errHandler, binaryLength, insts);
183183
#ifdef DEBUG_BLOCKS
184184
TRACE_BLOCK("**********************************************\n");
185-
for (auto bitr : blockStarts) {
185+
for (const auto& bitr : blockStarts) {
186186
auto instList = bitr.second->getInstList();
187187
TRACE_BLOCK("BLOCK ", (int)bitr.first, " (", bitr.second, ") => ",
188188
(int)instList.size(), " instrs\n");

visa/iga/IGALibrary/IR/Instruction.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class Instruction {
6262
{
6363
}
6464
Instruction(const Instruction &) = delete;
65+
Instruction& operator=(const Instruction&) = delete;
6566

6667
// for placement allocation
6768
void operator delete(void *, MemManager *) {}

visa/iga/IGALibrary/InstDiff.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ decodeFieldsWithWarnings(const Model &model, std::ostream &os, Loc loc,
8686
FragmentList fields;
8787
ErrorHandler errHandler;
8888
native::DecodeFields(loc, model, (const void *)mi, fields, errHandler);
89-
for (auto &e : errHandler.getErrors()) {
89+
for (const auto &e : errHandler.getErrors()) {
9090
std::stringstream ss;
9191
ss << "PC" << e.at.offset << ". " << e.message << "\n";
9292
emitYellowText(os, ss.str());

visa/iga/IGALibrary/api/igaEncoderWrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ iga_status_t KernelEncoder::encode(std::ostream &errStr) {
2424
#ifdef _DEBUG
2525
if (errHandler.hasErrors()) {
2626
// failed encode
27-
for (auto &e : errHandler.getErrors()) {
27+
for (const auto &e : errHandler.getErrors()) {
2828
errStr << "vISA inst $" << e.at.offset << ": " << e.message << "\n";
2929
}
3030
return IGA_ERROR;
3131
}
3232
if (errHandler.hasWarnings()) {
33-
for (auto &w : errHandler.getWarnings()) {
33+
for (const auto &w : errHandler.getWarnings()) {
3434
std::cerr << "line " << w.at.line << ", col " << w.at.col << ": "
3535
<< w.message << "\n";
3636
}

visa/iga/IGALibrary/api/kv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ kv_t *kv_create(iga_gen_t gen_platf, const void *bytes, size_t bytes_len,
136136
<< "\n";
137137
};
138138
if (kvImpl->m_errHandler.hasErrors()) {
139-
for (auto d : kvImpl->m_errHandler.getErrors()) {
139+
for (const auto& d : kvImpl->m_errHandler.getErrors()) {
140140
fmtDiag("ERROR", d);
141141
}
142142
}

visa/include/VISABuilderAPIDefinition.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ class VISAKernel {
634634
VISA_BUILDER_API virtual int
635635
AppendVISACFFunctionCallInst(VISA_PredOpnd *pred, VISA_EMask_Ctrl emask,
636636
VISA_Exec_Size executionSize,
637-
std::string funcName, unsigned char argSize,
637+
const std::string& funcName, unsigned char argSize,
638638
unsigned char returnSize) = 0;
639639

640640
/// AppendVISACFIndirectFuncCallInst -- append an indirect function call to
@@ -650,7 +650,7 @@ class VISAKernel {
650650
/// into <dst> faddr symbolName dst symbolName is the unique string to
651651
/// identify the symbol whose address is taken dst must have UD type with
652652
/// scalar region
653-
VISA_BUILDER_API virtual int AppendVISACFSymbolInst(std::string symbolName,
653+
VISA_BUILDER_API virtual int AppendVISACFSymbolInst(const std::string& symbolName,
654654
VISA_VectorOpnd *dst) = 0;
655655

656656
/// AppendVISACFFunctionRetInst -- append a function return instruction to

0 commit comments

Comments
 (0)