Skip to content

Commit 09ba703

Browse files
PiotrFusikigcbot
authored andcommitted
Modernize vISA code
1 parent 5b4569c commit 09ba703

File tree

6 files changed

+200
-207
lines changed

6 files changed

+200
-207
lines changed

visa/BuildCISAIR.h

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,8 @@ class CISA_IR_Builder : public VISABuilder
3838
CISA_IR_Builder(
3939
VISA_BUILDER_OPTION buildOption, vISABuilderMode mode,
4040
int majorVersion, int minorVersion, const WA_TABLE *pWaTable)
41-
: m_builderMode(mode), m_mem(4096), m_pWaTable(pWaTable)
41+
: mBuildOption(buildOption), m_builderMode(mode), m_mem(4096), m_pWaTable(pWaTable)
4242
{
43-
memset(&m_header, 0, sizeof(m_header));
44-
45-
mBuildOption = buildOption;
46-
m_kernel_count = 0;
47-
m_function_count = 0;
48-
m_prevKernel = nullptr;
49-
5043
m_header.major_version = majorVersion;
5144
m_header.minor_version = minorVersion;
5245
m_header.magic_number = COMMON_ISA_MAGIC_NUM;
@@ -67,40 +60,40 @@ class CISA_IR_Builder : public VISABuilder
6760
const char* flags[],
6861
const WA_TABLE *pWaTable = nullptr);
6962
static int DestroyBuilder(CISA_IR_Builder *builder);
70-
VISA_BUILDER_API virtual int AddKernel(VISAKernel *& kernel, const char* kernelName);
71-
VISA_BUILDER_API virtual int SetPrevKernel(VISAKernel *& prevKernel);
72-
VISA_BUILDER_API virtual int AddFunction(VISAFunction *& function, const char* functionName);
73-
VISA_BUILDER_API virtual int AddPayloadSection(VISAFunction *& function, const char* functionName);
74-
VISA_BUILDER_API virtual int Compile(const char * isaFileNameint, std::ostream * os = nullptr, bool emit_visa_only = false);
63+
VISA_BUILDER_API int AddKernel(VISAKernel *& kernel, const char* kernelName) override;
64+
VISA_BUILDER_API int SetPrevKernel(VISAKernel *& prevKernel) override;
65+
VISA_BUILDER_API int AddFunction(VISAFunction *& function, const char* functionName) override;
66+
VISA_BUILDER_API int AddPayloadSection(VISAFunction *& function, const char* functionName) override;
67+
VISA_BUILDER_API int Compile(const char * isaFileNameint, std::ostream * os = nullptr, bool emit_visa_only = false) override;
7568

76-
VISA_BUILDER_API void SetOption(vISAOptions option, bool val) { m_options.setOption(option, val); }
77-
VISA_BUILDER_API void SetOption(vISAOptions option, uint32_t val) { m_options.setOption(option, val); }
78-
VISA_BUILDER_API void SetOption(vISAOptions option, const char *val) { m_options.setOption(option, val); }
69+
VISA_BUILDER_API void SetOption(vISAOptions option, bool val) override { m_options.setOption(option, val); }
70+
VISA_BUILDER_API void SetOption(vISAOptions option, uint32_t val) override { m_options.setOption(option, val); }
71+
VISA_BUILDER_API void SetOption(vISAOptions option, const char *val) override { m_options.setOption(option, val); }
7972

8073
// Used for inline asm code generation
81-
VISA_BUILDER_API virtual int ParseVISAText(const std::string& visaText, const std::string& visaTextFile);
82-
VISA_BUILDER_API virtual int ParseVISAText(const std::string& visaFile);
83-
VISA_BUILDER_API std::stringstream& GetAsmTextStream() { return m_ssIsaAsm; }
84-
VISA_BUILDER_API virtual VISAKernel* GetVISAKernel(const std::string& kernelName);
85-
VISA_BUILDER_API virtual int ClearAsmTextStreams();
74+
VISA_BUILDER_API int ParseVISAText(const std::string& visaText, const std::string& visaTextFile) override;
75+
VISA_BUILDER_API int ParseVISAText(const std::string& visaFile) override;
76+
VISA_BUILDER_API std::stringstream& GetAsmTextStream() override { return m_ssIsaAsm; }
77+
VISA_BUILDER_API VISAKernel* GetVISAKernel(const std::string& kernelName) override;
78+
VISA_BUILDER_API int ClearAsmTextStreams() override;
8679

8780
/**************END VISA BUILDER API*************************/
8881

8982
string_pool_entry** branch_targets;
90-
common_isa_header m_header;
83+
common_isa_header m_header {};
9184

9285
// the current vISA kernel/function being processed
9386
VISAKernelImpl *m_kernel;
94-
VISAKernelImpl *m_prevKernel;
87+
VISAKernelImpl *m_prevKernel = nullptr;
9588
CisaFramework::CisaBinary *m_cisaBinary;
96-
VISAKernelImpl * get_kernel() { return m_kernel; }
89+
VISAKernelImpl * get_kernel() const { return m_kernel; }
9790

9891
std::stringstream& criticalMsgStream()
9992
{
10093
return criticalMsg;
10194
}
10295

103-
std::string GetCriticalMsg()
96+
std::string GetCriticalMsg() override
10497
{
10598
return criticalMsg.str();
10699
}
@@ -135,7 +128,7 @@ class CISA_IR_Builder : public VISABuilder
135128
criticalMsg << m_errorMessage << "\n";
136129
}
137130
bool HasParseError() const {return !m_errorMessage.empty();}
138-
std::string GetParseError() {return m_errorMessage;}
131+
std::string GetParseError() const {return m_errorMessage;}
139132

140133
template <typename...Ts>
141134
void RecordParseWarning(int lineNum, Ts...ts)
@@ -155,7 +148,7 @@ class CISA_IR_Builder : public VISABuilder
155148
// holds the %DispatchSimdSize attribute
156149
int m_dispatchSimdSize = -1;
157150

158-
const WA_TABLE *getWATable() { return m_pWaTable; }
151+
const WA_TABLE *getWATable() const { return m_pWaTable; }
159152

160153
uint8_t getMajorVersion() const { return m_header.major_version; }
161154
uint8_t getMinorVersion() const { return m_header.minor_version; }
@@ -870,12 +863,12 @@ class CISA_IR_Builder : public VISABuilder
870863
private:
871864

872865
vISA::Mem_Manager m_mem;
873-
VISA_BUILDER_OPTION mBuildOption;
866+
const VISA_BUILDER_OPTION mBuildOption;
874867
// FIXME: we need to make 3D/media per kernel instead of per builder
875868
const vISABuilderMode m_builderMode;
876869

877-
unsigned int m_kernel_count;
878-
unsigned int m_function_count;
870+
unsigned int m_kernel_count = 0;
871+
unsigned int m_function_count = 0;
879872

880873
// list of kernels and functions added to this builder
881874
std::list<VISAKernelImpl *> m_kernelsAndFunctions;

visa/BuildIR.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ class FCPatchingInfo
101101
}
102102

103103
void setHasFCCalls(bool hasFC) { hasFCCalls = hasFC; }
104-
bool getHasFCCalls() { return hasFCCalls; }
104+
bool getHasFCCalls() const { return hasFCCalls; }
105105
void setIsCallableKernel(bool value) { isFCCallableKernel = value; }
106-
bool getIsCallableKernel() { return isFCCallableKernel; }
106+
bool getIsCallableKernel() const { return isFCCallableKernel; }
107107
void setFCComposableKernel(bool value) { isFCComposableKernel = value; }
108-
bool getFCComposableKernel() { return isFCComposableKernel; }
108+
bool getFCComposableKernel() const { return isFCComposableKernel; }
109109
void setIsEntryKernel(bool value) { isFCEntryKernel = value; }
110-
bool getIsEntryKernel() { return isFCEntryKernel; }
110+
bool getIsEntryKernel() const { return isFCEntryKernel; }
111111
std::vector<FCCalls*>& getFCCallsToPatch() { return FCCallsToPatch; }
112112
std::vector<unsigned int>& getFCReturnsToPatch() { return FCReturnOffsetsToPatch; }
113113

@@ -388,7 +388,7 @@ class IR_Builder
388388
// map of all stack functioncs ever invoked by this builder's kernel/function
389389
std::map<std::string, G4_Label*> m_fcallLabels;
390390

391-
G4_Label* getFcallLabel(std::string str)
391+
G4_Label* getFcallLabel(const std::string &str)
392392
{
393393
auto it = m_fcallLabels.find(str);
394394
if (it == m_fcallLabels.end())
@@ -1071,12 +1071,12 @@ class IR_Builder
10711071
// a new null-terminated copy of "lab" is created for the new label, so
10721072
// caller does not have to allocate memory for lab
10731073
//
1074-
G4_Label* createLabel(std::string lab, VISA_Label_Kind kind)
1074+
G4_Label* createLabel(const std::string &lab, VISA_Label_Kind kind)
10751075
{
10761076
auto labStr = lab.c_str();
10771077
size_t len = strlen(labStr) + 1;
10781078
char* new_str = (char*)mem.alloc(len); // +1 for null that ends the string
1079-
strcpy_s(new_str, len, labStr);
1079+
memcpy_s(new_str, len, labStr, len);
10801080
return new (mem) G4_Label(new_str);
10811081
}
10821082

visa/G4_Kernel.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class G4_Kernel
227227
void computeChannelSlicing();
228228
void calculateSimdSize();
229229
G4_ExecSize getSimdSize() { return simdSize; }
230-
bool getChannelSlicing() { return channelSliced; }
230+
bool getChannelSlicing() const { return channelSliced; }
231231
unsigned getSimdSizeWithSlicing() { return channelSliced ? simdSize/2 : simdSize; }
232232

233233
void setHasAddrTaken(bool val) { hasAddrTaken = val; }
@@ -237,16 +237,16 @@ class G4_Kernel
237237
unsigned getNumRegTotal() const { return numRegTotal; }
238238

239239
void setName(const char* n) { name = n; }
240-
const char* getName() { return name; }
240+
const char* getName() const { return name; }
241241

242242
void updateKernelByNumThreads(int nThreads);
243243

244244
void evalAddrExp();
245245

246246
void setRAType(RA_Type type) { RAType = type; }
247-
RA_Type getRAType() { return RAType; }
247+
RA_Type getRAType() const { return RAType; }
248248

249-
bool hasKernelDebugInfo() {return kernelDbgInfo;}
249+
bool hasKernelDebugInfo() const {return kernelDbgInfo;}
250250
void setKernelDebugInfo(KernelDebugInfo* k);
251251
KernelDebugInfo* getKernelDebugInfo();
252252

0 commit comments

Comments
 (0)