Skip to content

Commit 0d479dc

Browse files
houjenkosys_zuul
authored andcommitted
Changes in code.
Change-Id: Icb748a042da2f2b8e5fdd901a2f86fa67289d8fa
1 parent 18c56e0 commit 0d479dc

13 files changed

+83
-21
lines changed

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3733,7 +3733,6 @@ namespace IGC
37333733
{
37343734
params.push_back(param_uptr("-debug", literal_deleter));
37353735
}
3736-
37373736
if (context->getModuleMetaData()->compOpt.FastVISACompile)
37383737
{
37393738
params.push_back(param_uptr("-fasterRA", literal_deleter));
@@ -3794,7 +3793,7 @@ namespace IGC
37943793
}
37953794
}
37963795
}
3797-
void CEncoder::InitVISABuilderOptions(TARGET_PLATFORM VISAPlatform, bool canAbortOnSpill, bool hasStackCall, bool enableVISA_IR)
3796+
void CEncoder::InitVISABuilderOptions(TARGET_PLATFORM VISAPlatform, bool canAbortOnSpill, bool hasStackCall, bool enableVISA_IR, CODE_PATCH_T mode)
37983797
{
37993798
CodeGenContext* context = m_program->GetContext();
38003799
bool KernelDebugEnable = false;
@@ -3836,6 +3835,7 @@ namespace IGC
38363835
SaveOption(vISA_DumpCompilerStats, true);
38373836
}
38383837

3838+
38393839
if (IGC_IS_FLAG_ENABLED(ForceFFIDOverwrite)/*|| m_program->m_Platform->WaOverwriteFFID()*/)
38403840
{
38413841
unsigned int ffid[unsigned(ShaderType::END)] = {
@@ -4329,7 +4329,7 @@ namespace IGC
43294329
}
43304330
}
43314331

4332-
void CEncoder::InitEncoder(bool canAbortOnSpill, bool hasStackCall)
4332+
void CEncoder::InitEncoder(bool canAbortOnSpill, bool hasStackCall, VISAKernel* prevKernel, CODE_PATCH_T mode)
43334333
{
43344334
m_aliasesMap.clear();
43354335
m_encoderState.m_SubSpanDestination = false;
@@ -4367,7 +4367,7 @@ namespace IGC
43674367
V(CreateVISABuilder(vbuilder, builderMode, builderOpt, VISAPlatform, params.size(), params.data(),
43684368
&m_vISAWaTable));
43694369

4370-
InitVISABuilderOptions(VISAPlatform, canAbortOnSpill, hasStackCall, builderOpt == VISA_BUILDER_BOTH);
4370+
InitVISABuilderOptions(VISAPlatform, canAbortOnSpill, hasStackCall, builderOpt == VISA_BUILDER_BOTH, mode);
43714371

43724372
// Pass all build options to builder
43734373
SetBuilderOptions(vbuilder);
@@ -4429,7 +4429,7 @@ namespace IGC
44294429
asmName = "kernel.asm";
44304430
}
44314431

4432-
V(vbuilder->AddKernel(vKernel, kernelName.c_str()));
4432+
V(vbuilder->AddKernel(vKernel, kernelName.c_str(), prevKernel));
44334433
V(vKernel->AddKernelAttribute("OutputAsmPath", asmName.length(), asmName.c_str()));
44344434

44354435
vMainKernel = vKernel;

IGC/Compiler/CISACodeGen/CISABuilder.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ namespace IGC
130130
class CEncoder
131131
{
132132
public:
133-
void InitEncoder(bool canAbortOnSpill, bool hasStackCall);
133+
void InitEncoder(bool canAbortOnSpill, bool hasStackCall, VISAKernel* prevkernel, CODE_PATCH_T mode);
134134
void InitBuildParams(llvm::SmallVector<std::unique_ptr< char, std::function<void(char*)>>, 10> & params);
135-
void InitVISABuilderOptions(TARGET_PLATFORM VISAPlatform, bool canAbortOnSpill, bool hasStackCall, bool enableVISA_IR);
135+
void InitVISABuilderOptions(TARGET_PLATFORM VISAPlatform, bool canAbortOnSpill, bool hasStackCall, bool enableVISA_IR, CODE_PATCH_T mode = CodePatch_NOT_HANDLED);
136136
SEncoderState CopyEncoderState();
137137
void SetEncoderState(SEncoderState& newState);
138138

@@ -233,6 +233,7 @@ namespace IGC
233233
void File(std::string& s);
234234
void PredAdd(CVariable* flag, CVariable* dst, CVariable* src0, CVariable* src1);
235235
void DebugLinePlaceholder();
236+
void SetPrevKernel(VISAKernel* kernel);
236237
void SetCurrentInst(llvm::Instruction *inst);
237238

238239
inline void Jump(uint label);
@@ -532,6 +533,9 @@ namespace IGC
532533
// encoder states
533534
SEncoderState m_encoderState;
534535

536+
// directly patch code from the recorded simd
537+
CODE_PATCH_T m_codePatch;
538+
535539
llvm::DenseMap<SAlias, CVariable*, SAliasMapInfo> m_aliasesMap;
536540

537541
// vISA needs its own Wa-table as some of the W/A are applicable

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,18 @@ void EmitPass::CreateKernelShaderMap(CodeGenContext* ctx, MetaDataUtils* pMdUtil
358358
}
359359
}
360360

361+
CODE_PATCH_T EmitPass::GetCodePatchMode(
362+
SIMDMode fromSimd, ShaderDispatchMode fromDispatch,
363+
SIMDMode toSimd, ShaderDispatchMode toDispatch)
364+
{
365+
switch (fromSimd)
366+
{
367+
default:
368+
return CodePatch_NOT_HANDLED;
369+
}
370+
return CodePatch_NOT_HANDLED;
371+
}
372+
361373
bool EmitPass::runOnFunction(llvm::Function& F)
362374
{
363375
m_pCtx = getAnalysis<CodeGenContextWrapper>().getCodeGenContext();
@@ -440,8 +452,27 @@ bool EmitPass::runOnFunction(llvm::Function& F)
440452
{
441453
return false;
442454
}
455+
456+
m_prevShader = m_pCtx->m_prevShader;
457+
VISAKernel* prevKernel = nullptr;
458+
CODE_PATCH_T mode = CodePatch_NOT_HANDLED;
459+
if (m_prevShader)
460+
{
461+
mode = GetCodePatchMode(
462+
m_prevShader->m_SIMDSize,
463+
m_prevShader->m_ShaderDispatchMode,
464+
m_currShader->m_SIMDSize,
465+
m_currShader->m_ShaderDispatchMode
466+
);
467+
if (mode != CodePatch_NOT_HANDLED)
468+
{
469+
prevKernel = m_prevShader->GetEncoder().GetVISAKernel();
470+
}
471+
}
472+
443473
// call builder after pre-analysis pass where scratchspace offset to VISA is calculated
444-
m_encoder->InitEncoder(m_canAbortOnSpill, hasStackCall);
474+
m_encoder->InitEncoder(m_canAbortOnSpill, hasStackCall, prevKernel, mode);
475+
445476
initDefaultRoundingMode();
446477
m_currShader->PreCompile();
447478
if (hasStackCall)
@@ -687,6 +718,7 @@ bool EmitPass::runOnFunction(llvm::Function& F)
687718
Function* currHead = m_FGA ? m_FGA->getGroupHead(&F) : &F;
688719
bool compileWithSymbolTable = (currHead == uniqueEntry);
689720
m_encoder->Compile(compileWithSymbolTable);
721+
m_pCtx->m_prevShader = m_currShader;
690722
// if we are doing stack-call, do the following:
691723
// - Hard-code a large scratch-space for visa
692724
if (hasStackCall)

IGC/Compiler/CISACodeGen/EmitVISAPass.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ namespace IGC
7777
virtual bool runOnFunction(llvm::Function& F) override;
7878
virtual llvm::StringRef getPassName() const override { return "EmitPass"; }
7979

80+
CODE_PATCH_T GetCodePatchMode(
81+
SIMDMode fromSimd, ShaderDispatchMode fromDispatch,
82+
SIMDMode toSimd, ShaderDispatchMode toDispatch);
83+
8084
void CreateKernelShaderMap(CodeGenContext* ctx, IGC::IGCMD::MetaDataUtils* pMdUtils, llvm::Function& F);
8185

8286
void Frc(const SSource& source, const DstModifier& modifier);
@@ -534,6 +538,7 @@ namespace IGC
534538
ShaderDispatchMode m_ShaderMode;
535539
CShaderProgram::KernelShaderMap& m_shaders;
536540
CShader* m_currShader;
541+
CShader* m_prevShader;
537542
CEncoder* m_encoder;
538543
const llvm::DataLayout* m_DL;
539544
CoalescingEngine* m_CE;

IGC/Compiler/CodeGenPublic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,9 @@ namespace IGC
752752
std::vector<unsigned> m_indexableTempSize;
753753
bool m_highPsRegisterPressure = 0;
754754

755+
// Record previous simd for code patching
756+
CShader* m_prevShader = nullptr;
757+
755758
// For IR dump after pass
756759
unsigned m_numPasses = 0;
757760
bool m_threadCombiningOptDone = false;

visa/BuildCISAIR.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class CISA_IR_Builder : public VISABuilder
7979
const char* flags[],
8080
const PWA_TABLE pWaTable = nullptr);
8181
static int DestroyBuilder(CISA_IR_Builder *builder);
82-
VISA_BUILDER_API virtual int AddKernel(VISAKernel *& kernel, const char* kernelName);
82+
VISA_BUILDER_API virtual int AddKernel(VISAKernel *& kernel, const char* kernelName, VISAKernel* prevKernel = nullptr);
8383
VISA_BUILDER_API virtual int AddFunction(VISAFunction *& function, const char* functionName);
8484
VISA_BUILDER_API virtual int Compile(const char * isaFileNameint, std::ostream * os = nullptr, bool emit_visa_only = false);
8585

visa/BuildCISAIRImpl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ int CISA_IR_Builder::ClearAsmTextStreams()
361361
return VISA_FAILURE;
362362
}
363363

364-
int CISA_IR_Builder::AddKernel(VISAKernel *& kernel, const char* kernelName)
364+
int CISA_IR_Builder::AddKernel(VISAKernel *& kernel, const char* kernelName, VISAKernel* prevKernel)
365365
{
366366

367367
if( kernel != NULL )
@@ -377,7 +377,7 @@ int CISA_IR_Builder::AddKernel(VISAKernel *& kernel, const char* kernelName)
377377
m_kernel->setIsKernel(true);
378378
m_kernels.push_back(kerneltemp);
379379
m_kernel->setVersion((unsigned char)this->m_header.major_version, (unsigned char)this->m_header.minor_version);
380-
m_kernel->InitializeKernel(kernelName);
380+
m_kernel->InitializeKernel(kernelName, prevKernel);
381381
m_kernel->SetGTPinInit(getGtpinInit());
382382
this->m_kernel_count++;
383383

visa/FlowGraph.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,6 @@ void FlowGraph::constructFlowGraph(INST_LIST& instlist)
806806

807807
if (builder->getOption(vISA_DumpDotAll))
808808
{
809-
pKernel->dumpDotFile("beforeRemoveRedundantLabels");
810809
}
811810

812811
removeRedundantLabels();

visa/FlowGraph.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ class FlowGraph
675675
bool isStackCallFunc; // indicates the function itself is a STACK_CALL function
676676
unsigned int autoLabelId;
677677
G4_Kernel* pKernel; // back pointer to the kernel object
678+
G4_Kernel* m_prevKernel; // back pointer to the previous kernel object
678679

679680
// map each BB to its local RA GRF usage summary, populated in local RA
680681
std::map<G4_BB*, PhyRegSummary*> bbLocalRAMap;
@@ -852,6 +853,11 @@ class FlowGraph
852853
return pKernel;
853854
}
854855

856+
G4_Kernel* getPrevKernel()
857+
{
858+
return m_prevKernel;
859+
}
860+
855861
void mergeFReturns();
856862

857863
G4_Declare*& getFramePtrDcl() {return framePtrDcl;}
@@ -926,6 +932,7 @@ class FlowGraph
926932

927933
// functions for structure analysis
928934
G4_Kernel *getKernel() const { return pKernel; }
935+
G4_Kernel* getPrevKernel() const { return m_prevKernel; }
929936
G4_Label* insertEndif( G4_BB* bb, unsigned char execSize, bool createLabel );
930937
void setJIPForEndif( G4_INST* endif, G4_INST* target, G4_BB* targetBB);
931938
void convertGotoToJmpi(G4_INST *gotoInst)
@@ -963,10 +970,10 @@ class FlowGraph
963970
FlowGraph(const FlowGraph&) = delete;
964971
FlowGraph& operator=(const FlowGraph&) = delete;
965972

966-
FlowGraph(INST_LIST_NODE_ALLOCATOR& alloc, G4_Kernel* kernel, Mem_Manager& m) :
973+
FlowGraph(INST_LIST_NODE_ALLOCATOR& alloc, G4_Kernel* kernel, G4_Kernel* prevKernel, Mem_Manager& m) :
967974
traversalNum(0), numBBId(0), reducible(true),
968975
doIPA(false), hasStackCalls(false), isStackCallFunc(false), autoLabelId(0),
969-
pKernel(kernel), mem(m), instListAlloc(alloc),
976+
pKernel(kernel), m_prevKernel(prevKernel), mem(m), instListAlloc(alloc),
970977
kernelInfo(NULL), builder(NULL), globalOpndHT(m), framePtrDcl(NULL),
971978
stackPtrDcl(NULL), scratchRegDcl(NULL), pseudoVCEDcl(NULL) {}
972979

@@ -1461,15 +1468,15 @@ class G4_Kernel
14611468
unsigned char minor_version;
14621469

14631470
G4_Kernel(INST_LIST_NODE_ALLOCATOR& alloc,
1464-
Mem_Manager &m, Options *options, unsigned char major, unsigned char minor)
1471+
Mem_Manager &m, Options *options, unsigned char major, unsigned char minor, G4_Kernel *prevKernel)
14651472
: m_options(options), RAType(RA_Type::UNKNOWN_RA),
14661473
asmInstCount(0), kernelID(0), tokenInstructionCount(0), tokenReuseCount(0),
14671474
AWTokenReuseCount(0), ARTokenReuseCount(0), AATokenReuseCount(0),
14681475
mathInstCount(0), syncInstCount(0),mathReuseCount(0),
14691476
ARSyncInstCount(0), AWSyncInstCount(0), ARSyncAllCount(0), AWSyncAllCount(0),
14701477
prunedDepEdges(0), prunedGlobalEdgeNum(0), prunedDiffBBEdgeNum(0), prunedDiffBBSameTokenEdgeNum(0),
14711478
bank_good_num(0), bank_ok_num(0),
1472-
bank_bad_num(0), fg(alloc, this, m), major_version(major), minor_version(minor)
1479+
bank_bad_num(0), fg(alloc, this, prevKernel, m), major_version(major), minor_version(minor)
14731480
{
14741481
ASSERT_USER(
14751482
major < COMMON_ISA_MAJOR_VER ||

visa/VISAKernel.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class VISAKernelImpl : public VISAFunction
9797
m_forward_label_count = 0;
9898
m_jitInfo = NULL;
9999
errorMessage[0] = '\0';
100+
m_prevKernel = NULL;
100101
m_kernel = NULL;
101102
m_builder = NULL;
102103
m_globalMem = NULL;
@@ -134,7 +135,7 @@ class VISAKernelImpl : public VISAFunction
134135
virtual ~VISAKernelImpl();
135136

136137
void *operator new(size_t sz, vISA::Mem_Manager& m){ return m.alloc(sz); };
137-
int InitializeKernel(const char *kernel_name);
138+
int InitializeKernel(const char *kernel_name, VISAKernel* prevKernel = nullptr);
138139
int CISABuildPreDefinedDecls();
139140
void setVersion(unsigned char major_ver, unsigned char minor_ver){
140141
m_major_version = major_ver;
@@ -838,6 +839,8 @@ class VISAKernelImpl : public VISAFunction
838839

839840
void computeAndEmitDebugInfo(std::list<VISAKernelImpl*>& functions);
840841

842+
vISA::G4_Kernel* GetVISAPrevKernel() { return m_prevKernel; }
843+
841844
private:
842845
void setDefaultVariableName(Common_ISA_Var_Class Ty, const char *&varName);
843846
void dumpDebugFormatFile(std::vector<vISA::DebugInfoFormat>& debugSymbols, std::string filename);
@@ -964,6 +967,7 @@ class VISAKernelImpl : public VISAFunction
964967
char errorMessage[MAX_ERROR_MSG_LEN];
965968

966969
VISA_BUILDER_OPTION mBuildOption;
970+
vISA::G4_Kernel* m_prevKernel;
967971
vISA::G4_Kernel* m_kernel;
968972
CISA_IR_Builder* m_CISABuilder;
969973
vISA::IR_Builder* m_builder;

0 commit comments

Comments
 (0)