@@ -1816,6 +1816,17 @@ VISA_Type CShader::GetType(llvm::Type* type)
18161816 return IGC::GetType (type, GetContext ());
18171817}
18181818
1819+ uint32_t CShader::GetNumElts (llvm::Type* type, bool isUniform)
1820+ {
1821+ uint32_t numElts = isUniform ? 1 : numLanes (m_SIMDSize);
1822+ if (type->isVectorTy ())
1823+ {
1824+ IGC_ASSERT (type->getVectorElementType ()->isIntegerTy () || type->getVectorElementType ()->isFloatingPointTy ());
1825+ numElts *= (uint16_t )type->getVectorNumElements ();
1826+ }
1827+ return numElts;
1828+ }
1829+
18191830uint64_t IGC::GetImmediateVal (llvm::Value* Const)
18201831{
18211832 // Constant integer
@@ -2129,15 +2140,10 @@ CVariable* CShader::getOrCreateReturnSymbol(llvm::Function* F)
21292140
21302141 IGC_ASSERT (retType->isSingleValueType ());
21312142 VISA_Type type = GetType (retType);
2132- uint16_t nElts = numLanes (m_SIMDSize);
2133- if (retType->isVectorTy ())
2134- {
2135- nElts *= (uint16_t )cast<VectorType>(retType)->getNumElements ();
2136- }
2143+ uint16_t nElts = (uint16_t )GetNumElts (retType, false );
21372144 e_alignment align = getGRFAlignment ();
2138- static const bool nonUniform = false ;
21392145 CVariable* var = GetNewVariable (
2140- nElts, type, align, nonUniform , m_numberInstance,
2146+ nElts, type, align, false , m_numberInstance,
21412147 CName (F->getName (), " _RETVAL" ));
21422148 globalSymbolMapping.insert (std::make_pair (F, var));
21432149 return var;
@@ -2157,31 +2163,34 @@ CVariable* CShader::getOrCreateArgumentSymbol(
21572163 return it->second ;
21582164 }
21592165
2160- // An explicit argument is not uniform, and for an implicit argument, it
2161- // is predefined. Note that it is not necessarily uniform.
2162- Function* F = Arg->getParent ();
2163- ImplicitArgs implicitArgs (*F, m_pMdUtils);
2164- unsigned numImplicitArgs = implicitArgs.size ();
2165- unsigned numPushArgsEntry = m_ModuleMetadata->pushInfo .pushAnalysisWIInfos .size ();
2166- unsigned numPushArgs = (isEntryFunc (m_pMdUtils, F) && !isNonEntryMultirateShader (F) ? numPushArgsEntry : 0 );
2167- unsigned numFuncArgs = IGCLLVM::GetFuncArgSize (F) - numImplicitArgs - numPushArgs;
2168-
21692166 CVariable* var = nullptr ;
2170- llvm::Function::arg_iterator arg = F->arg_begin ();
2171- std::advance (arg, numFuncArgs);
2172- for (unsigned i = 0 ; i < numImplicitArgs; ++i, ++arg)
2173- {
2174- Argument* argVal = &(*arg);
2175- if (argVal == Arg)
2167+
2168+ // Stack call does not use implicit args
2169+ if (!useStackCall)
2170+ {
2171+ // An explicit argument is not uniform, and for an implicit argument, it
2172+ // is predefined. Note that it is not necessarily uniform.
2173+ Function* F = Arg->getParent ();
2174+ ImplicitArgs implicitArgs (*F, m_pMdUtils);
2175+ unsigned numImplicitArgs = implicitArgs.size ();
2176+ unsigned numPushArgsEntry = m_ModuleMetadata->pushInfo .pushAnalysisWIInfos .size ();
2177+ unsigned numPushArgs = (isEntryFunc (m_pMdUtils, F) && !isNonEntryMultirateShader (F) ? numPushArgsEntry : 0 );
2178+ unsigned numFuncArgs = IGCLLVM::GetFuncArgSize (F) - numImplicitArgs - numPushArgs;
2179+
2180+ llvm::Function::arg_iterator arg = F->arg_begin ();
2181+ std::advance (arg, numFuncArgs);
2182+ for (unsigned i = 0 ; i < numImplicitArgs; ++i, ++arg)
21762183 {
2177- ImplicitArg implictArg = implicitArgs[i];
2178- auto ArgType = implictArg.getArgType ();
2179-
2180- // Just reuse the kernel arguments for the following.
2181- // Note that for read only general arguments, we may do similar
2182- // optimization, with some advanced analysis.
2183- if (!useStackCall &&
2184- (ArgType == ImplicitArg::ArgType::R0 ||
2184+ Argument* argVal = &(*arg);
2185+ if (argVal == Arg)
2186+ {
2187+ ImplicitArg implictArg = implicitArgs[i];
2188+ auto ArgType = implictArg.getArgType ();
2189+
2190+ // Just reuse the kernel arguments for the following.
2191+ // Note that for read only general arguments, we may do similar
2192+ // optimization, with some advanced analysis.
2193+ if (ArgType == ImplicitArg::ArgType::R0 ||
21852194 ArgType == ImplicitArg::ArgType::PAYLOAD_HEADER ||
21862195 ArgType == ImplicitArg::ArgType::WORK_DIM ||
21872196 ArgType == ImplicitArg::ArgType::NUM_GROUPS ||
@@ -2191,37 +2200,38 @@ CVariable* CShader::getOrCreateArgumentSymbol(
21912200 ArgType == ImplicitArg::ArgType::CONSTANT_BASE ||
21922201 ArgType == ImplicitArg::ArgType::GLOBAL_BASE ||
21932202 ArgType == ImplicitArg::ArgType::PRIVATE_BASE ||
2194- ArgType == ImplicitArg::ArgType::PRINTF_BUFFER))
2195- {
2196- Function& K = *m_FGA->getSubGroupMap (F);
2197- ImplicitArgs IAs (K, m_pMdUtils);
2198- uint32_t nIAs = (uint32_t )IAs.size ();
2199- uint32_t iArgIx = IAs.getArgIndex (ArgType);
2200- uint32_t argIx = (uint32_t )IGCLLVM::GetFuncArgSize (K) - nIAs + iArgIx;
2201- if (isEntryFunc (m_pMdUtils, &K) && !isNonEntryMultirateShader (&K)) {
2202- argIx = argIx - numPushArgsEntry;
2203- }
2204- Function::arg_iterator arg = K.arg_begin ();
2205- for (uint32_t j = 0 ; j < argIx; ++j, ++arg);
2206- Argument* kerArg = &(*arg);
2203+ ArgType == ImplicitArg::ArgType::PRINTF_BUFFER)
2204+ {
2205+ Function& K = *m_FGA->getSubGroupMap (F);
2206+ ImplicitArgs IAs (K, m_pMdUtils);
2207+ uint32_t nIAs = (uint32_t )IAs.size ();
2208+ uint32_t iArgIx = IAs.getArgIndex (ArgType);
2209+ uint32_t argIx = (uint32_t )IGCLLVM::GetFuncArgSize (K) - nIAs + iArgIx;
2210+ if (isEntryFunc (m_pMdUtils, &K) && !isNonEntryMultirateShader (&K)) {
2211+ argIx = argIx - numPushArgsEntry;
2212+ }
2213+ Function::arg_iterator arg = K.arg_begin ();
2214+ for (uint32_t j = 0 ; j < argIx; ++j, ++arg);
2215+ Argument* kerArg = &(*arg);
22072216
2208- // Pre-condition: all kernel arguments have been created already.
2209- IGC_ASSERT (pSymMap->count (kerArg));
2210- return (*pSymMap)[kerArg];
2211- }
2212- else
2213- {
2214- bool isUniform = implictArg.getDependency () == WIAnalysis::UNIFORM;
2215- uint16_t nbElements = (uint16_t )implictArg.getNumberElements ();
2217+ // Pre-condition: all kernel arguments have been created already.
2218+ IGC_ASSERT (pSymMap->count (kerArg));
2219+ return (*pSymMap)[kerArg];
2220+ }
2221+ else
2222+ {
2223+ bool isUniform = implictArg.getDependency () == WIAnalysis::UNIFORM;
2224+ uint16_t nbElements = (uint16_t )implictArg.getNumberElements ();
22162225
22172226
2218- var = GetNewVariable (nbElements,
2219- implictArg.getVISAType (*m_DL),
2220- implictArg.getAlignType (*m_DL), isUniform,
2221- isUniform ? 1 : m_numberInstance,
2222- argVal->getName ());
2227+ var = GetNewVariable (nbElements,
2228+ implictArg.getVISAType (*m_DL),
2229+ implictArg.getAlignType (*m_DL), isUniform,
2230+ isUniform ? 1 : m_numberInstance,
2231+ argVal->getName ());
2232+ }
2233+ break ;
22232234 }
2224- break ;
22252235 }
22262236 }
22272237
@@ -2240,18 +2250,18 @@ CVariable* CShader::getOrCreateArgumentSymbol(
22402250 }
22412251
22422252 VISA_Type type = GetType (Arg->getType ());
2243- uint16_t nElts = numLanes (m_SIMDSize);
2244- if (Arg->getType ()->isVectorTy ())
2245- {
2246- IGC_ASSERT ((Arg->getType ()->getVectorElementType ()->isIntegerTy ()) || (Arg->getType ()->getVectorElementType ()->isFloatingPointTy ()));
2247- nElts *= (uint16_t )cast<VectorType>(Arg->getType ())->getNumElements ();
2248- }
2253+ uint16_t nElts = (uint16_t )GetNumElts (Arg->getType (), isUniform);
22492254 var = GetNewVariable (nElts, type, align, isUniform, m_numberInstance, Arg->getName ());
22502255 }
22512256 pSymMap->insert (std::make_pair (Arg, var));
22522257 return var;
22532258}
22542259
2260+ void CShader::UpdateSymbolMap (llvm::Value* v, CVariable* CVar)
2261+ {
2262+ symbolMapping[v] = CVar;
2263+ }
2264+
22552265// Reuse a varable in the following case
22562266// %x = op1...
22572267// %y = op2 (%x, ...)
0 commit comments