Skip to content

Commit 89c3931

Browse files
trbauerigcbot
authored andcommitted
fix precomp import access viol.
corrects defect where getCallingFunction() may be nullptr also removes some pointer-based iteration (possible non-determinism)
1 parent 006cc87 commit 89c3931

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed

IGC/Compiler/Optimizer/PreCompiledFuncImport.cpp

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ SPDX-License-Identifier: MIT
3737
#include "AdaptorOCL/OCL/BuiltinResource.h"
3838
#include "AdaptorOCL/OCL/LoadBuffer.h"
3939

40-
#include <unordered_map>
40+
#include <vector>
41+
#include <utility>
4142

4243
using namespace llvm;
4344
using namespace IGC;
@@ -500,7 +501,7 @@ bool PreCompiledFuncImport::runOnModule(Module& M)
500501
//post-process the Int32 precompiled emulation function for div/rem
501502
if (isI32DivRem() || isI32DivRemSP() || isSPDiv())
502503
{
503-
std::unordered_map<CallInst*, CallInst*> replaceInsts;
504+
std::vector<std::pair<CallInst*,CallInst*>> replaceInsts;
504505
for (auto FI = M.begin(), FE = M.end(); FI != FE; )
505506
{
506507
llvm::Function* func = &(*FI);
@@ -515,41 +516,41 @@ bool PreCompiledFuncImport::runOnModule(Module& M)
515516
{
516517
if (CallInst * CI = dyn_cast<CallInst>(I))
517518
{
518-
Function* pFunc = nullptr;
519-
GenISAIntrinsic::ID GISAIntr = GenISAIntrinsic::no_intrinsic;
520-
//ATTN: This can be made generic/cleaned up through an enum or something
521-
if (CI->getCalledFunction()->getName().equals("GenISA_fma_rtz"))
522-
{
523-
GISAIntr = GenISAIntrinsic::GenISA_fma_rtz;
524-
}
525-
else if (CI->getCalledFunction()->getName().equals("GenISA_mul_rtz"))
526-
{
527-
GISAIntr = GenISAIntrinsic::GenISA_mul_rtz;
528-
}
529-
else if (CI->getCalledFunction()->getName().equals("GenISA_add_rtz"))
530-
{
531-
GISAIntr = GenISAIntrinsic::GenISA_add_rtz;
532-
}
533-
else if (CI->getCalledFunction()->getName().equals("GenISA_uitof_rtz"))
534-
{
535-
GISAIntr = GenISAIntrinsic::GenISA_uitof_rtz;
536-
}
537-
if (GISAIntr != GenISAIntrinsic::no_intrinsic)
538-
{
539-
IRBuilder<> builder(CI);
540-
std::vector<Value*> args;
541-
std::vector<Type*> types;
542-
543-
types.push_back(CI->getType());
544-
545-
for (unsigned int i = 0; i < CI->getNumArgOperands(); i++)
519+
if (const llvm::Function *calledFunc = CI->getCalledFunction()) {
520+
GenISAIntrinsic::ID GISAIntr = GenISAIntrinsic::no_intrinsic;
521+
if (calledFunc->getName().equals("GenISA_fma_rtz"))
522+
{
523+
GISAIntr = GenISAIntrinsic::GenISA_fma_rtz;
524+
}
525+
else if (calledFunc->getName().equals("GenISA_mul_rtz"))
526+
{
527+
GISAIntr = GenISAIntrinsic::GenISA_mul_rtz;
528+
}
529+
else if (calledFunc->getName().equals("GenISA_add_rtz"))
530+
{
531+
GISAIntr = GenISAIntrinsic::GenISA_add_rtz;
532+
}
533+
else if (calledFunc->getName().equals("GenISA_uitof_rtz"))
534+
{
535+
GISAIntr = GenISAIntrinsic::GenISA_uitof_rtz;
536+
}
537+
if (GISAIntr != GenISAIntrinsic::no_intrinsic)
546538
{
547-
types.push_back(CI->getArgOperand(i)->getType());
548-
args.push_back(CI->getArgOperand(i));
539+
IRBuilder<> builder(CI);
540+
std::vector<Value*> args;
541+
std::vector<Type*> types;
542+
543+
types.push_back(CI->getType());
544+
545+
for (unsigned i = 0; i < CI->getNumArgOperands(); i++)
546+
{
547+
types.push_back(CI->getArgOperand(i)->getType());
548+
args.push_back(CI->getArgOperand(i));
549+
}
550+
Function* pFunc = GenISAIntrinsic::getDeclaration(&M, GISAIntr, types);
551+
CallInst* pCall = builder.CreateCall(pFunc, args);
552+
replaceInsts.emplace_back(CI, pCall);
549553
}
550-
pFunc = GenISAIntrinsic::getDeclaration(&M, GISAIntr, types);
551-
CallInst* pCall = builder.CreateCall(pFunc, args);
552-
replaceInsts.insert(std::make_pair(CI, pCall));
553554
}
554555
}
555556
}

0 commit comments

Comments
 (0)