Skip to content

Commit f3ad21a

Browse files
pratikasharigcbot
authored andcommitted
Add missing check on argument type.
Add missing check on argument type.
1 parent ffcf9fb commit f3ad21a

File tree

3 files changed

+52
-16
lines changed

3 files changed

+52
-16
lines changed

IGC/Compiler/DebugInfo/ScalarVISAModule.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,16 @@ ScalarVisaModule::GetVariableLocation(const llvm::Instruction* pInst) const
428428
{
429429
const std::string typeStr = modMD->FuncMD[const_cast<Function*>(curFunc)].m_OpenCLArgBaseTypes[pArgument->getArgNo()];
430430
KernelArg::ArgType argType = KernelArg::calcArgType(pArgument, typeStr);
431+
if (argType == KernelArg::ArgType::SAMPLER)
432+
{
433+
// SAMPLER and NOT_TO_ALLOCATE have same enum values so disambiguate these
434+
auto pr = KernelArg::getBufferType(pArgument, typeStr);
435+
if(!pr.isSampler)
436+
{
437+
// type is actually NOT_TO_ALLOCATE
438+
argType = KernelArg::ArgType::End;
439+
}
440+
}
431441
FunctionMetaData* funcMD = &modMD->FuncMD[const_cast<Function*>(curFunc)];
432442
ResourceAllocMD* resAllocMD = &funcMD->resAllocMD;
433443
IGC_ASSERT_MESSAGE(resAllocMD->argAllocMDList.size() == curFunc->arg_size(), "Invalid ArgAllocMDList");

IGC/Compiler/Optimizer/OpenCLPasses/KernelArgs.cpp

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,36 @@ unsigned int KernelArg::calcElemAllocateSize(const Argument* arg, const DataLayo
116116
return int_cast<unsigned int>(DL->getTypeAllocSize(arg->getType()->getScalarType()));
117117
}
118118

119+
// First member of pair is ArgType of buffer.
120+
// When ArgType is SAMPLER, second member should be true.
121+
// When ArgType is NOT_TO_ALLOCATE, second member should be false.
122+
// ArgType enum uses same values for SAMPLER and NOT_TO_ALLOCATE.
123+
// This function helps disambiguate between the two values.
124+
KernelArg::BufferArgType KernelArg::getBufferType(const Argument* arg, const StringRef typeStr)
125+
{
126+
if (arg->getType()->getTypeID() != Type::PointerTyID)
127+
return { KernelArg::ArgType::SAMPLER, true };
128+
129+
PointerType* ptrType = cast<PointerType>(arg->getType());
130+
131+
int address_space = ptrType->getPointerAddressSpace();
132+
bool directIdx = false;
133+
unsigned int bufId = 0;
134+
BufferType bufType = DecodeAS4GFXResource(address_space, directIdx, bufId);
135+
136+
// Check if this arg is an image
137+
if (bufType == BufferType::UAV)
138+
{
139+
ArgType imgArgType;
140+
// Check if argument is image
141+
if (isImage(arg, typeStr, imgArgType)) return { imgArgType, false };
142+
}
143+
else if (bufType == BufferType::SAMPLER)
144+
return { KernelArg::ArgType::SAMPLER, true };
145+
146+
return { KernelArg::ArgType::NOT_TO_ALLOCATE, false };
147+
}
148+
119149
KernelArg::ArgType KernelArg::calcArgType(const Argument* arg, const StringRef typeStr)
120150
{
121151
switch (arg->getType()->getTypeID())
@@ -185,22 +215,7 @@ KernelArg::ArgType KernelArg::calcArgType(const Argument* arg, const StringRef t
185215
IGC_ASSERT_MESSAGE(0, "Unrecognized address space");
186216
#endif
187217
// This is a buffer. Try to decode this
188-
int address_space = ptrType->getPointerAddressSpace();
189-
bool directIdx = false;
190-
unsigned int bufId = 0;
191-
BufferType bufType = DecodeAS4GFXResource(address_space, directIdx, bufId);
192-
193-
// Check if this arg is an image
194-
if (bufType == BufferType::UAV)
195-
{
196-
ArgType imgArgType;
197-
// Check if argument is image
198-
if (isImage(arg, typeStr, imgArgType)) return imgArgType;
199-
}
200-
else if (bufType == BufferType::SAMPLER)
201-
return KernelArg::ArgType::SAMPLER;
202-
203-
return KernelArg::ArgType::NOT_TO_ALLOCATE;
218+
return getBufferType(arg, typeStr).type;
204219
}
205220
}
206221
case Type::IntegerTyID:

IGC/Compiler/Optimizer/OpenCLPasses/KernelArgs.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,17 @@ namespace IGC
228228
/// @return The kernel argument type of the given explicit argument
229229
static ArgType calcArgType(const llvm::Argument* arg, const llvm::StringRef typeStr);
230230

231+
struct BufferArgType
232+
{
233+
KernelArg::ArgType type = KernelArg::ArgType::End;
234+
bool isSampler = false;
235+
};
236+
/// @brief Calculates the kernel arg type for buffer
237+
/// @param arg The explicit kernel argument
238+
/// @param typeStr The OpenCL type information for the kernel this argument belongs to
239+
/// @return Pair of the kernel argument type of the given explicit argument and whether the type is really SAMPLER
240+
static BufferArgType getBufferType(const llvm::Argument* arg, const llvm::StringRef typeStr);
241+
231242
/// @brief Checks whether the given argument is an image
232243
/// @param arg The kernel argument
233244
/// @param typeStr The OpenCL type information for the kernel this argument belongs to

0 commit comments

Comments
 (0)