Skip to content

Commit 9497a39

Browse files
raghushiigcbot
authored andcommitted
[Autobackout][FuncReg]Revert of change: 54e89df
change the forceSpillCompression input to optional change the forceSpillCompression input to optional
1 parent fd57cee commit 9497a39

File tree

14 files changed

+49
-245
lines changed

14 files changed

+49
-245
lines changed

IGC/AdaptorCommon/LegalizeFunctionSignatures.cpp

Lines changed: 44 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,6 @@ static const unsigned int MAX_RETVAL_SIZE_IN_BITS = 64;
7676
static const unsigned int MAX_STRUCT_SIZE_IN_BITS = 128;
7777
static const unsigned int MAX_SUBROUTINE_STRUCT_SIZE_IN_BITS = 512;
7878

79-
enum ReturnOpt
80-
{
81-
RETURN_DEFAULT = 0,
82-
RETURN_BY_REF,
83-
RETURN_STRUCT,
84-
RETURN_LEGAL_INT
85-
};
86-
8779
bool LegalizeFunctionSignatures::runOnModule(Module& M)
8880
{
8981
auto pMdUtils = getAnalysis<MetaDataUtilsWrapper>().getMetaDataUtils();
@@ -275,7 +267,8 @@ void LegalizeFunctionSignatures::FixFunctionSignatures(Module& M)
275267
continue;
276268
}
277269

278-
ReturnOpt retTypeOption = ReturnOpt::RETURN_DEFAULT;
270+
bool legalizeReturnType = false;
271+
bool promoteSRetType = false;
279272
bool fixArgType = false;
280273
std::vector<Type*> argTypes;
281274

@@ -287,18 +280,14 @@ void LegalizeFunctionSignatures::FixFunctionSignatures(Module& M)
287280
// Create the new function signature by replacing the illegal types
288281
if (FunctionHasPromotableSRetArg(M, pFunc))
289282
{
290-
retTypeOption = ReturnOpt::RETURN_STRUCT;
283+
promoteSRetType = true;
291284
ai++; // Skip adding the first arg
292285
}
293286
else if (!isLegalSignatureType(M, pFunc->getReturnType(), isStackCall))
294287
{
295-
retTypeOption = ReturnOpt::RETURN_BY_REF;
288+
legalizeReturnType = true;
296289
argTypes.push_back(PointerType::get(pFunc->getReturnType(), 0));
297290
}
298-
else if (!isLegalIntVectorType(M, pFunc->getReturnType()))
299-
{
300-
retTypeOption = ReturnOpt::RETURN_LEGAL_INT;
301-
}
302291

303292
for (; ai != ei; ai++)
304293
{
@@ -324,32 +313,33 @@ void LegalizeFunctionSignatures::FixFunctionSignatures(Module& M)
324313
}
325314
}
326315

327-
if (retTypeOption != ReturnOpt::RETURN_DEFAULT || fixArgType)
316+
if (!legalizeReturnType && !promoteSRetType && !fixArgType)
328317
{
329-
// Clone function with new signature
330-
Type* returnType =
331-
retTypeOption == ReturnOpt::RETURN_BY_REF ? Type::getVoidTy(M.getContext()) :
332-
retTypeOption == ReturnOpt::RETURN_STRUCT ? PromotedStructValueType(M, pFunc->arg_begin()->getType()) :
333-
retTypeOption == ReturnOpt::RETURN_LEGAL_INT ? LegalizedIntVectorType(M, pFunc->getReturnType()) :
334-
pFunc->getReturnType();
335-
FunctionType* signature = FunctionType::get(returnType, argTypes, false);
336-
Function* pNewFunc = Function::Create(signature, pFunc->getLinkage(), pFunc->getName(), pFunc->getParent());
337-
pNewFunc->takeName(pFunc);
338-
pNewFunc->setCallingConv(pFunc->getCallingConv());
339-
pNewFunc->setAttributes(pFunc->getAttributes());
340-
341-
// Since we need to pass in pointers to be dereferenced by the new function, remove the "readnone" attribute
342-
// Also we need to create allocas for these pointers, so set the flag to true
343-
if (retTypeOption == ReturnOpt::RETURN_BY_REF)
344-
{
345-
pNewFunc->removeFnAttr(llvm::Attribute::ReadNone);
346-
pNewFunc->removeFnAttr(llvm::Attribute::ReadOnly);
347-
pContext->m_instrTypes.hasNonPrimitiveAlloca = true;
348-
}
318+
// Nothing to fix
319+
continue;
320+
}
349321

350-
// Map the old function to the new
351-
oldToNewFuncMap[pFunc] = pNewFunc;
322+
// Clone function with new signature
323+
Type* returnType = legalizeReturnType ? Type::getVoidTy(M.getContext()) :
324+
promoteSRetType ? PromotedStructValueType(M, pFunc->arg_begin()->getType()) :
325+
pFunc->getReturnType();
326+
FunctionType* signature = FunctionType::get(returnType, argTypes, false);
327+
Function* pNewFunc = Function::Create(signature, pFunc->getLinkage(), pFunc->getName(), pFunc->getParent());
328+
pNewFunc->takeName(pFunc);
329+
pNewFunc->setCallingConv(pFunc->getCallingConv());
330+
pNewFunc->setAttributes(pFunc->getAttributes());
331+
332+
// Since we need to pass in pointers to be dereferenced by the new function, remove the "readnone" attribute
333+
// Also we need to create allocas for these pointers, so set the flag to true
334+
if (legalizeReturnType)
335+
{
336+
pNewFunc->removeFnAttr(llvm::Attribute::ReadNone);
337+
pNewFunc->removeFnAttr(llvm::Attribute::ReadOnly);
338+
pContext->m_instrTypes.hasNonPrimitiveAlloca = true;
352339
}
340+
341+
// Map the old function to the new
342+
oldToNewFuncMap[pFunc] = pNewFunc;
353343
}
354344
}
355345

@@ -367,28 +357,26 @@ void LegalizeFunctionSignatures::FixFunctionBody(Module& M)
367357
llvm::SmallVector<llvm::ReturnInst*, 8> Returns;
368358
auto OldArgIt = pFunc->arg_begin();
369359
auto NewArgIt = pNewFunc->arg_begin();
370-
ReturnOpt retTypeOption = ReturnOpt::RETURN_DEFAULT;
360+
bool legalizeReturnType = false;
361+
bool promoteSRetType = false;
371362
bool isStackCall = pFunc->hasFnAttribute("visaStackCall");
372363
Value* tempAllocaForSRetPointer = nullptr;
373364
llvm::SmallVector<llvm::Argument*, 8> ArgByVal;
374365

375366
if (FunctionHasPromotableSRetArg(M, pFunc)) {
376-
retTypeOption = ReturnOpt::RETURN_STRUCT;
367+
promoteSRetType = true;
377368
}
378369
else if (!isLegalSignatureType(M, pFunc->getReturnType(), isStackCall)) {
379-
retTypeOption = ReturnOpt::RETURN_BY_REF;
370+
legalizeReturnType = true;
380371
++NewArgIt; // Skip first argument that we added.
381372
}
382-
else if (!isLegalIntVectorType(M, pFunc->getReturnType())) {
383-
retTypeOption = ReturnOpt::RETURN_LEGAL_INT;
384-
}
385373

386374
// Fix the usages of arguments that have changed
387375
BasicBlock* EntryBB = BasicBlock::Create(M.getContext(), "", pNewFunc);
388376
IGCLLVM::IRBuilder<> builder(EntryBB);
389377
for (; OldArgIt != pFunc->arg_end(); ++OldArgIt)
390378
{
391-
if (OldArgIt == pFunc->arg_begin() && retTypeOption == ReturnOpt::RETURN_STRUCT)
379+
if (OldArgIt == pFunc->arg_begin() && promoteSRetType)
392380
{
393381
// Create a temp alloca to map the old argument. This will be removed later by SROA.
394382
tempAllocaForSRetPointer = builder.CreateAlloca(PromotedStructValueType(M, OldArgIt->getType()));
@@ -449,7 +437,7 @@ void LegalizeFunctionSignatures::FixFunctionBody(Module& M)
449437
}
450438

451439
// Now fix the return values
452-
if (retTypeOption == ReturnOpt::RETURN_BY_REF)
440+
if (legalizeReturnType)
453441
{
454442
// Add the 'noalias' and 'sret' attribute to arg0
455443
auto retArg = pNewFunc->arg_begin();
@@ -471,7 +459,7 @@ void LegalizeFunctionSignatures::FixFunctionBody(Module& M)
471459
RetInst->eraseFromParent();
472460
}
473461
}
474-
else if (retTypeOption == ReturnOpt::RETURN_STRUCT)
462+
else if (promoteSRetType)
475463
{
476464
// For "sret" returns, we load from the temp alloca created earlier and return the loaded value instead
477465
for (auto RetInst : Returns)
@@ -482,19 +470,6 @@ void LegalizeFunctionSignatures::FixFunctionBody(Module& M)
482470
RetInst->eraseFromParent();
483471
}
484472
}
485-
else if (retTypeOption == ReturnOpt::RETURN_LEGAL_INT)
486-
{
487-
// Extend illegal int returns to legal type
488-
for (auto RetInst : Returns)
489-
{
490-
IGCLLVM::IRBuilder<> builder(RetInst);
491-
Value* retVal = RetInst->getReturnValue();
492-
Type* retTy = retVal->getType();
493-
retVal = builder.CreateZExt(retVal, LegalizedIntVectorType(M, retTy));
494-
builder.CreateRet(retVal);
495-
RetInst->eraseFromParent();
496-
}
497-
}
498473
}
499474

500475
// Now that all instructions are transferred to the new func, delete the old func
@@ -558,7 +533,8 @@ void LegalizeFunctionSignatures::FixCallInstruction(Module& M, CallInst* callIns
558533
{
559534
Function* calledFunc = callInst->getCalledFunction();
560535
SmallVector<Value*, 16> callArgs;
561-
ReturnOpt retTypeOption = ReturnOpt::RETURN_DEFAULT;
536+
bool legalizeReturnType = false;
537+
bool promoteSRetType = false;
562538
bool fixArgType = false;
563539
bool isStackCall = !calledFunc || calledFunc->hasFnAttribute("visaStackCall");
564540

@@ -577,7 +553,7 @@ void LegalizeFunctionSignatures::FixCallInstruction(Module& M, CallInst* callIns
577553
isPromotableStructType(M, callInst->getArgOperand(0)->getType(), isStackCall, true /* retval */))
578554
{
579555
opNum++; // Skip the first call operand
580-
retTypeOption = ReturnOpt::RETURN_STRUCT;
556+
promoteSRetType = true;
581557
}
582558
else if (!isLegalSignatureType(M, callInst->getType(), isStackCall))
583559
{
@@ -590,11 +566,7 @@ void LegalizeFunctionSignatures::FixCallInstruction(Module& M, CallInst* callIns
590566
ArgAttrs.addAttribute(llvm::Attribute::NoAlias);
591567
ArgAttrs.addStructRetAttr(callInst->getType());
592568
ArgAttrVec.push_back(AttributeSet::get(M.getContext(), ArgAttrs));
593-
retTypeOption = ReturnOpt::RETURN_BY_REF;
594-
}
595-
else if (!isLegalIntVectorType(M, callInst->getType()))
596-
{
597-
retTypeOption = ReturnOpt::RETURN_LEGAL_INT;
569+
legalizeReturnType = true;
598570
}
599571

600572
// Check call operands if it needs to be replaced
@@ -640,7 +612,7 @@ void LegalizeFunctionSignatures::FixCallInstruction(Module& M, CallInst* callIns
640612
}
641613
}
642614

643-
if (retTypeOption != ReturnOpt::RETURN_DEFAULT || fixArgType)
615+
if (legalizeReturnType || promoteSRetType || fixArgType)
644616
{
645617
IGCLLVM::IRBuilder<> builder(callInst);
646618
Value* newCalledValue = nullptr;
@@ -653,10 +625,8 @@ void LegalizeFunctionSignatures::FixCallInstruction(Module& M, CallInst* callIns
653625
{
654626
argTypes.push_back(arg->getType());
655627
}
656-
Type* retType =
657-
retTypeOption == ReturnOpt::RETURN_BY_REF ? Type::getVoidTy(callInst->getContext()) :
658-
retTypeOption == ReturnOpt::RETURN_STRUCT ? PromotedStructValueType(M, callInst->getArgOperand(0)->getType()) :
659-
retTypeOption == ReturnOpt::RETURN_LEGAL_INT ? LegalizedIntVectorType(M, callInst->getType()) :
628+
Type* retType = legalizeReturnType ? Type::getVoidTy(callInst->getContext()) :
629+
promoteSRetType ? PromotedStructValueType(M, callInst->getArgOperand(0)->getType()) :
660630
callInst->getType();
661631
newFnTy = FunctionType::get(retType, argTypes, false);
662632
Value* calledValue = IGCLLVM::getCalledValue(callInst);
@@ -676,24 +646,18 @@ void LegalizeFunctionSignatures::FixCallInstruction(Module& M, CallInst* callIns
676646
newCallInst->setAttributes(AttributeList::get(M.getContext(), IGCLLVM::getFnAttrs(PAL), IGCLLVM::getRetAttrs(PAL), ArgAttrVec));
677647
newCallInst->setDebugLoc(callInst->getDebugLoc());
678648

679-
if (retTypeOption == ReturnOpt::RETURN_BY_REF)
649+
if (legalizeReturnType)
680650
{
681651
// Load the return value from the arg pointer before using it
682652
IGC_ASSERT(returnPtr);
683653
Value* load = builder.CreateLoad(returnPtr);
684654
callInst->replaceAllUsesWith(load);
685655
}
686-
else if (retTypeOption == ReturnOpt::RETURN_STRUCT)
656+
else if (promoteSRetType)
687657
{
688658
// Store the struct value into the orginal pointer operand
689659
StoreToStruct(builder, newCallInst, callInst->getArgOperand(0));
690660
}
691-
else if (retTypeOption == ReturnOpt::RETURN_LEGAL_INT)
692-
{
693-
// Truncate legal type back into original value
694-
Value* trunc = builder.CreateTrunc(newCallInst, callInst->getType());
695-
callInst->replaceAllUsesWith(trunc);
696-
}
697661
else
698662
{
699663
callInst->replaceAllUsesWith(newCallInst);

IGC/BiFModule/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ generate_bif_src_checksum(${IGC_BUILD__PROJ__BiFModule_OCL})
637637
generate_bif_prebuild_pack(${IGC_BUILD__PROJ__BiFModule_OCL} "${IGC_BUILD__PROJ_DEPENDS_BiFModule_OCL}")
638638
set(IGC_BUILD__PROJ__BiFModuleCache_OCL "${IGC_BUILD__PROJ__BiFModuleCache_OCL}" PARENT_SCOPE)
639639

640+
640641
# =========================================== SPIRV Headers ============================================
641642

642643
add_library(IGCSPIRVHeaders INTERFACE)

IGC/Compiler/CISACodeGen/CShader.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ void CShader::InitEncoder(SIMDMode simdSize, bool canAbortOnSpill, ShaderDispatc
107107
m_SavedSRetPtr = nullptr;
108108
m_ImplArgBufPtr = nullptr;
109109
m_LocalIdBufPtr = nullptr;
110-
m_GlobalBufferArg = nullptr;
111110

112111
// SIMD32 is a SIMD16 shader with 2 instance of each instruction
113112
m_SIMDSize = (simdSize == SIMDMode::SIMD8 ? SIMDMode::SIMD8 : SIMDMode::SIMD16);
@@ -319,12 +318,6 @@ void CShader::InitializeStackVariables()
319318
m_LocalIdBufPtr = GetNewVariable(1, ISA_TYPE_UQ, EALIGN_QWORD, true, 1, "LocalIdPtr");
320319
encoder.GetVISAPredefinedVar(m_LocalIdBufPtr, PREDEFINED_LOCAL_ID_BUF_PTR);
321320
}
322-
// reserve a temp GRF for implicit arguments programmed by FE
323-
if (m_ctx->m_DriverInfo.SupportGlobalStackArgs() &&
324-
m_ctx->type != ShaderType::RAYTRACING_SHADER)
325-
{
326-
m_GlobalBufferArg = GetNewVariable(2, ISA_TYPE_UQ, EALIGN_QWORD, true, 1, "GlobalBufferArg");
327-
}
328321

329322
auto& argRegisterReservations = m_ctx->getModuleMetaData()->argRegisterReservations;
330323
m_ARGVReservedVariablesTotalSize = 0;
@@ -365,10 +358,9 @@ void CShader::RestoreStackState()
365358
// Restore FP to previous frame's FP
366359
encoder.Copy(m_FP, m_SavedFP);
367360
encoder.Push();
361+
368362
// Reset temp variables
369363
m_SavedFP = nullptr;
370-
m_GlobalBufferArg = nullptr;
371-
372364
for (auto& arg : m_ARGVReservedVariables)
373365
arg = nullptr;
374366
}
@@ -1055,11 +1047,6 @@ CVariable* CShader::GetLocalIdBufPtr()
10551047
return m_LocalIdBufPtr;
10561048
}
10571049

1058-
CVariable* CShader::GetGlobalBufferArg()
1059-
{
1060-
return m_GlobalBufferArg;
1061-
}
1062-
10631050
CVariable* CShader::GetFP()
10641051
{
10651052
IGC_ASSERT(m_FP);

IGC/Compiler/CISACodeGen/DriverInfo.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,6 @@ namespace IGC
205205
/// support predicate add pattern match
206206
virtual bool SupportMatchPredAdd() const { return false; }
207207

208-
/// Support passing globally accessed pointers implicitly to callees using argument registers
209-
virtual bool SupportGlobalStackArgs() const { return false; }
210-
211208
/// Adjust adapter to adjust the loop unrolling threshold
212209
virtual unsigned int GetLoopUnrollThreshold() const
213210
{

0 commit comments

Comments
 (0)