Skip to content

Commit 00d5960

Browse files
mmereckiigcbot
authored andcommitted
Add dual-instance aliases of single-instance variables
Add support for creating dual-instance aliases of single-instance variables to allow simd32 variables that are consecutive in GRFs.
1 parent 34c3c3a commit 00d5960

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5870,6 +5870,30 @@ namespace IGC
58705870
}
58715871
}
58725872
}
5873+
else if (var->GetSingleInstanceAlias() != NULL)
5874+
{
5875+
CVariable* singleInstanceVar = var->GetSingleInstanceAlias();
5876+
IGC_ASSERT(singleInstanceVar->GetNumberInstance() == 1);
5877+
IGC_ASSERT((singleInstanceVar->GetNumberElement() % var->GetNumberInstance()) == 0);
5878+
IGC_ASSERT(singleInstanceVar->GetNumberElement() == var->GetNumberElement() * var->GetNumberInstance());
5879+
for (uint i = 0; i < var->GetNumberInstance(); i++)
5880+
{
5881+
// Multi-instance aliases use VISA offset mechanism for the
5882+
// second instance.
5883+
int instanceOffset =
5884+
i * var->GetNumberElement() *
5885+
CEncoder::GetCISADataTypeSize(var->GetType());
5886+
5887+
V(vKernel->CreateVISAGenVar(
5888+
var->visaGenVariable[i],
5889+
var->getVisaCString(),
5890+
var->GetNumberElement(),
5891+
var->GetType(),
5892+
GetVISAAlign(singleInstanceVar), // Use parent's align as we create an alias of the parent.
5893+
singleInstanceVar->visaGenVariable[0],
5894+
instanceOffset));
5895+
}
5896+
}
58735897
else
58745898
{
58755899
uint num_elts = var->GetNumberElement();

IGC/Compiler/CISACodeGen/CShader.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3855,6 +3855,19 @@ CVariable* CShader::GetNewAlias(
38553855
return alias;
38563856
}
38573857

3858+
// Create a multi-instance alias of a single-instance variable.
3859+
CVariable* CShader::GetNewAlias(CVariable* var, uint16_t numInstances)
3860+
{
3861+
IGC_ASSERT_MESSAGE(false == var->IsImmediate(), "Trying to create an alias of an immediate");
3862+
IGC_ASSERT(var->GetNumberInstance() == 1);
3863+
IGC_ASSERT(var->GetSingleInstanceAlias() == nullptr);
3864+
IGC_ASSERT(var->GetAlias() == nullptr);
3865+
IGC_ASSERT(numInstances > 1);
3866+
CVariable* alias = new (Allocator)CVariable(var, numInstances);
3867+
encoder.CreateVISAVar(alias);
3868+
return alias;
3869+
}
3870+
38583871
// createAliasIfNeeded() returns the Var that is either BaseVar or
38593872
// its alias of the same size.
38603873
//

IGC/Compiler/CISACodeGen/CVariable.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ CVariable::CVariable(
4747
const CName &name) :
4848
m_immediateValue(0),
4949
m_alias(nullptr),
50+
m_singleInstanceAlias(nullptr),
5051
m_nbElement(nbElement),
5152
m_aliasOffset(0),
5253
m_numberOfInstance(int_cast<uint8_t>(numberOfInstance)),
@@ -100,6 +101,7 @@ CVariable::CVariable(
100101
UniformArgWrap uniform) :
101102
m_immediateValue(0),
102103
m_alias(var),
104+
m_singleInstanceAlias(var->m_singleInstanceAlias),
103105
m_aliasOffset(offset),
104106
m_numberOfInstance(var->m_numberOfInstance),
105107
m_type(type),
@@ -134,12 +136,43 @@ CVariable::CVariable(
134136
IGC_ASSERT_MESSAGE(var->m_varType == EVARTYPE_GENERAL, "only general variable can have alias");
135137
}
136138

139+
/// CVariable constructor for multi-instance alias of a single-instance variable
140+
///
141+
CVariable::CVariable(
142+
CVariable* var,
143+
uint16_t numInstances) :
144+
m_immediateValue(0),
145+
m_alias(nullptr),
146+
m_singleInstanceAlias(var),
147+
m_aliasOffset(0),
148+
m_nbElement(var->m_nbElement / numInstances),
149+
m_numberOfInstance(numInstances),
150+
m_type(var->m_type),
151+
m_varType(EVARTYPE_GENERAL),
152+
m_align(var->m_align),
153+
m_uniform(var->m_uniform),
154+
m_isImmediate(false),
155+
m_subspanUse(var->m_subspanUse),
156+
m_uniformVector(false),
157+
m_undef(false),
158+
m_isUnpacked(false),
159+
m_llvmName(var->m_llvmName)
160+
{
161+
IGC_ASSERT(var->m_varType == EVARTYPE_GENERAL);
162+
IGC_ASSERT(var->GetNumberInstance() == 1);
163+
IGC_ASSERT(var->GetSingleInstanceAlias() == nullptr);
164+
IGC_ASSERT(var->GetAlias() == nullptr);
165+
IGC_ASSERT(numInstances > 1);
166+
IGC_ASSERT((var->m_nbElement % numInstances) == 0);
167+
}
168+
137169
/// CVariable constructor, for immediate
138170
///
139171
CVariable::CVariable(
140172
uint64_t immediate, VISA_Type type, uint16_t nbElem, bool undef) :
141173
m_immediateValue(immediate),
142174
m_alias(nullptr),
175+
m_singleInstanceAlias(nullptr),
143176
m_aliasOffset(0),
144177
m_nbElement(nbElem),
145178
m_numberOfInstance(1),

IGC/Compiler/CISACodeGen/CVariable.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ namespace IGC {
174174
CVariable* var, VISA_Type type, uint16_t offset,
175175
uint16_t numElements, UniformArgWrap uniform);
176176

177+
// Create a multi-instance alias of single-instance variable. Instances
178+
// of the alias variable point to consecutive sub-regions of the parent
179+
// variable.
180+
CVariable(CVariable* var, uint16_t numInstances);
181+
177182
// general variable
178183
CVariable(
179184
uint16_t nbElement,
@@ -189,6 +194,7 @@ namespace IGC {
189194
CVariable(const CVariable& V, const CName& name = CName()) :
190195
m_immediateValue(V.m_immediateValue),
191196
m_alias(nullptr),
197+
m_singleInstanceAlias(nullptr),
192198
m_nbElement(V.m_nbElement),
193199
m_aliasOffset(0),
194200
m_numberOfInstance(V.m_numberOfInstance),
@@ -225,6 +231,7 @@ namespace IGC {
225231
uint GetElemSize() const { return GetCISADataTypeSize(m_type); }
226232

227233
CVariable* GetAlias() const { return m_alias; }
234+
CVariable* GetSingleInstanceAlias() const { return m_singleInstanceAlias; }
228235
uint16_t GetAliasOffset() const { return m_aliasOffset; }
229236
VISA_Type GetType() const { return m_type; }
230237
e_varType GetVarType() const { return m_varType; }
@@ -342,6 +349,7 @@ namespace IGC {
342349
const uint64_t m_immediateValue;
343350

344351
CVariable* m_alias;
352+
CVariable* m_singleInstanceAlias;
345353

346354
uint16_t m_nbElement;
347355
uint16_t m_aliasOffset;

IGC/Compiler/CISACodeGen/ShaderCodeGen.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ class CShader
210210
CVariable* GetNewVector(llvm::Value* val, e_alignment preferredAlign = EALIGN_AUTO);
211211
CVariable* GetNewAlias(CVariable* var, VISA_Type type, uint16_t offset, uint16_t numElements);
212212
CVariable* GetNewAlias(CVariable* var, VISA_Type type, uint16_t offset, uint16_t numElements, bool uniform);
213+
// Create a multi-instance alias of a single-instance variable.
214+
CVariable* GetNewAlias(CVariable* var, uint16_t numInstances);
213215

214216
// If BaseVar's type matches V's, return BaseVar; otherwise, create an new
215217
// alias CVariable to BaseVar. The newly-created alias CVariable's size

0 commit comments

Comments
 (0)