Skip to content

Commit fa94ba3

Browse files
smilczekigcbot
authored andcommitted
Minor fixes and refactors.
- Apply rule-of-three by explicitly deleting copy constructors. - Fix memory leak in DbgDecoder in case of error by moving fopen to constructor and fclose to destructor.
1 parent 7d3adc7 commit fa94ba3

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

visa/DebugInfo.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,6 @@ void DbgDecoder::ddCalleeCallerSave(uint32_t relocOffset, CallerCallee callCase)
237237
}
238238

239239
int DbgDecoder::ddDbg() {
240-
dbgFile = fopen(filename, "rb");
241-
242240
if (!dbgFile) {
243241
std::cerr << "Error opening and creating debug file: " << filename << "\n";
244242
vISA_ASSERT(false, "Unable to write debug file to disk.");
@@ -260,8 +258,6 @@ int DbgDecoder::ddDbg() {
260258
<< " *************"
261259
<< "\n";
262260

263-
fclose(dbgFile);
264-
265261
return -1;
266262
}
267263

@@ -453,8 +449,6 @@ int DbgDecoder::ddDbg() {
453449

454450
std::cout << "=== End of Debug Dump ===\n";
455451

456-
fclose(dbgFile);
457-
458452
return 0;
459453
}
460454

visa/DebugInfo.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,10 +468,20 @@ class DbgDecoder {
468468

469469
public:
470470
DbgDecoder(const char *f, TARGET_PLATFORM platform) : filename(f) {
471+
dbgFile = fopen(filename, "rb");
471472
platInfo = PlatformInfo::LookupPlatformInfo(platform);
472473
vISA_ASSERT(platInfo != nullptr, "failed to look up platform");
473474
}
474475

476+
~DbgDecoder() {
477+
if (dbgFile)
478+
fclose(dbgFile);
479+
}
480+
481+
DbgDecoder() = delete;
482+
DbgDecoder(const DbgDecoder &) = delete;
483+
DbgDecoder operator=(const DbgDecoder &) = delete;
484+
475485
int ddDbg();
476486
};
477487

visa/Passes/SRSubstitution.hpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ struct regMap {
3232
unsigned short dstReg;
3333
unsigned short srcReg;
3434

35-
regMap() : localID(-1), dstReg(-1), srcReg(-1) { ; }
35+
regMap() : localID(-1), dstReg(-1), srcReg(-1) {}
3636
regMap(unsigned int id, unsigned short dst, unsigned src)
37-
: localID(id), dstReg(dst), srcReg(src) {
38-
;
39-
}
40-
~regMap() {}
37+
: localID(id), dstReg(dst), srcReg(src) {}
4138
};
4239

4340
struct regMapBRA {
@@ -46,14 +43,9 @@ struct regMapBRA {
4643
unsigned int offset = 0;
4744
G4_Operand *opnd = nullptr;
4845

49-
regMapBRA() {}
50-
5146
regMapBRA(G4_INST *i, Gen4_Operand_Number n, unsigned int off,
5247
G4_Operand *src)
53-
: inst(i), opndNum(n), offset(off), opnd(src) {
54-
;
55-
}
56-
~regMapBRA() {}
48+
: inst(i), opndNum(n), offset(off), opnd(src) {}
5749
};
5850

5951
struct regCandidates {
@@ -83,8 +75,6 @@ class SRSubPassAfterRA {
8375
}
8476
SRSubPassAfterRA(const SRSubPassAfterRA &) = delete;
8577
SRSubPassAfterRA& operator=(const SRSubPassAfterRA&) = delete;
86-
~SRSubPassAfterRA() {
87-
};
8878

8979
void run() {
9080
for (auto bb : kernel.fg) {

0 commit comments

Comments
 (0)