Skip to content

Commit 846e717

Browse files
Daniel Grabansys_zuul
authored andcommitted
PromoteResourcesToBindless pass refactor.
Change-Id: Iff18c4b2ad4af280905f65a4ea9493b67415907d
1 parent bba01f4 commit 846e717

File tree

2 files changed

+38
-138
lines changed

2 files changed

+38
-138
lines changed

IGC/Compiler/CISACodeGen/helper.cpp

Lines changed: 38 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -671,12 +671,12 @@ namespace IGC
671671
return false;
672672
}
673673

674+
674675
///
675-
/// Wrapper method for changing PTRType for PromoteToBindless Pass.
676676
/// Replaces oldPtr with newPtr in a sample/ld intrinsic's argument list. The new instrinsic will
677677
/// replace the old one in the module
678678
///
679-
void ChangePtrTypeInIntrinsic(llvm::GenIntrinsicInst*& pIntr, llvm::Value* oldPtr, llvm::Value* newPtr, bool isExtendedForBindlessPromotion)
679+
void ChangePtrTypeInIntrinsic(llvm::GenIntrinsicInst*& pIntr, llvm::Value* oldPtr, llvm::Value* newPtr)
680680
{
681681
llvm::Module* pModule = pIntr->getParent()->getParent()->getParent();
682682
llvm::Function* pCalledFunc = pIntr->getCalledFunction();
@@ -696,17 +696,23 @@ namespace IGC
696696
llvm::Function* pNewIntr = nullptr;
697697
llvm::SmallVector<llvm::Type*, 4> overloadedTys;
698698
GenISAIntrinsic::ID id = pIntr->getIntrinsicID();
699-
700-
bool isPointerChangedInFallbackMethod = false;
701-
702699
switch (id)
703700
{
704701
case llvm::GenISAIntrinsic::GenISA_ldmcsptr:
702+
overloadedTys.push_back(pCalledFunc->getReturnType());
703+
overloadedTys.push_back(args[0]->getType());
704+
overloadedTys.push_back(newPtr->getType());
705+
break;
705706
case llvm::GenISAIntrinsic::GenISA_ldptr:
706707
case llvm::GenISAIntrinsic::GenISA_ldmsptr:
708+
overloadedTys.push_back(pCalledFunc->getReturnType());
709+
overloadedTys.push_back(newPtr->getType());
710+
break;
707711
case llvm::GenISAIntrinsic::GenISA_resinfoptr:
708712
case llvm::GenISAIntrinsic::GenISA_readsurfaceinfoptr:
709713
case llvm::GenISAIntrinsic::GenISA_sampleinfoptr:
714+
overloadedTys.push_back(newPtr->getType());
715+
break;
710716
case llvm::GenISAIntrinsic::GenISA_sampleptr:
711717
case llvm::GenISAIntrinsic::GenISA_sampleBptr:
712718
case llvm::GenISAIntrinsic::GenISA_sampleCptr:
@@ -720,23 +726,43 @@ namespace IGC
720726
case llvm::GenISAIntrinsic::GenISA_gather4Cptr:
721727
case llvm::GenISAIntrinsic::GenISA_gather4POCptr:
722728
case llvm::GenISAIntrinsic::GenISA_lodptr:
729+
{
730+
// Figure out the intrinsic operands for texture & sampler
731+
llvm::Value* pTextureValue = nullptr, * pSamplerValue = nullptr;
732+
getTextureAndSamplerOperands(pIntr, pTextureValue, pSamplerValue);
733+
734+
overloadedTys.push_back(pCalledFunc->getReturnType());
735+
overloadedTys.push_back(pIntr->getOperand(0)->getType());
736+
737+
if (pTextureValue == oldPtr)
738+
{
739+
overloadedTys.push_back(newPtr->getType());
740+
if (pSamplerValue)
741+
{
742+
// Samplerless messages will not have sampler in signature.
743+
overloadedTys.push_back(pSamplerValue->getType());
744+
}
745+
}
746+
else if (pSamplerValue == oldPtr)
747+
{
748+
overloadedTys.push_back(pTextureValue->getType());
749+
overloadedTys.push_back(newPtr->getType());
750+
}
751+
752+
break;
753+
}
723754
case llvm::GenISAIntrinsic::GenISA_typedread:
724755
case llvm::GenISAIntrinsic::GenISA_typedwrite:
756+
overloadedTys.push_back(newPtr->getType());
757+
break;
725758
case llvm::GenISAIntrinsic::GenISA_intatomicraw:
726759
case llvm::GenISAIntrinsic::GenISA_icmpxchgatomicraw:
727760
case llvm::GenISAIntrinsic::GenISA_intatomicrawA64:
728761
case llvm::GenISAIntrinsic::GenISA_icmpxchgatomicrawA64:
729-
730-
// fallback to not extended version
731-
ChangePtrTypeInIntrinsic(pIntr, oldPtr, newPtr);
732-
isPointerChangedInFallbackMethod = true;
733-
break;
734-
735762
case llvm::GenISAIntrinsic::GenISA_floatatomicraw:
736763
case llvm::GenISAIntrinsic::GenISA_floatatomicrawA64:
737764
case llvm::GenISAIntrinsic::GenISA_fcmpxchgatomicraw:
738765
case llvm::GenISAIntrinsic::GenISA_fcmpxchgatomicrawA64:
739-
740766
overloadedTys.push_back(pIntr->getType());
741767
overloadedTys.push_back(newPtr->getType());
742768
if (id == GenISAIntrinsic::GenISA_intatomicrawA64)
@@ -789,131 +815,6 @@ namespace IGC
789815
case llvm::GenISAIntrinsic::GenISA_storeraw_indexed:
790816
overloadedTys.push_back(newPtr->getType());
791817
overloadedTys.push_back(args[2]->getType());
792-
793-
break;
794-
default:
795-
assert(0 && "Unknown intrinsic encountered while changing pointer types");
796-
break;
797-
}
798-
799-
// if processed by this method, let's replace instruction here.
800-
if (!isPointerChangedInFallbackMethod)
801-
{
802-
pNewIntr = llvm::GenISAIntrinsic::getDeclaration(
803-
pModule,
804-
id,
805-
overloadedTys);
806-
807-
llvm::CallInst* pNewCall = llvm::CallInst::Create(pNewIntr, args, "", pIntr);
808-
809-
pIntr->replaceAllUsesWith(pNewCall);
810-
pIntr->eraseFromParent();
811-
812-
pIntr = llvm::cast<llvm::GenIntrinsicInst>(pNewCall);
813-
}
814-
}
815-
816-
///
817-
/// Replaces oldPtr with newPtr in a sample/ld intrinsic's argument list. The new instrinsic will
818-
/// replace the old one in the module
819-
///
820-
void ChangePtrTypeInIntrinsic(llvm::GenIntrinsicInst*& pIntr, llvm::Value* oldPtr, llvm::Value* newPtr)
821-
{
822-
llvm::Module* pModule = pIntr->getParent()->getParent()->getParent();
823-
llvm::Function* pCalledFunc = pIntr->getCalledFunction();
824-
825-
// Look at the intrinsic and figure out which pointer to change
826-
int num_ops = pIntr->getNumArgOperands();
827-
llvm::SmallVector<llvm::Value*, 5> args;
828-
829-
for (int i = 0; i < num_ops; ++i)
830-
{
831-
if (pIntr->getArgOperand(i) == oldPtr)
832-
args.push_back(newPtr);
833-
else
834-
args.push_back(pIntr->getArgOperand(i));
835-
}
836-
837-
llvm::Function* pNewIntr = nullptr;
838-
llvm::SmallVector<llvm::Type*, 4> overloadedTys;
839-
GenISAIntrinsic::ID id = pIntr->getIntrinsicID();
840-
switch (id)
841-
{
842-
case llvm::GenISAIntrinsic::GenISA_ldmcsptr:
843-
overloadedTys.push_back(pCalledFunc->getReturnType());
844-
overloadedTys.push_back(args[0]->getType());
845-
overloadedTys.push_back(newPtr->getType());
846-
break;
847-
case llvm::GenISAIntrinsic::GenISA_ldptr:
848-
case llvm::GenISAIntrinsic::GenISA_ldmsptr:
849-
overloadedTys.push_back(pCalledFunc->getReturnType());
850-
overloadedTys.push_back(newPtr->getType());
851-
break;
852-
case llvm::GenISAIntrinsic::GenISA_resinfoptr:
853-
case llvm::GenISAIntrinsic::GenISA_readsurfaceinfoptr:
854-
case llvm::GenISAIntrinsic::GenISA_sampleinfoptr:
855-
overloadedTys.push_back(newPtr->getType());
856-
break;
857-
case llvm::GenISAIntrinsic::GenISA_sampleptr:
858-
case llvm::GenISAIntrinsic::GenISA_sampleBptr:
859-
case llvm::GenISAIntrinsic::GenISA_sampleCptr:
860-
case llvm::GenISAIntrinsic::GenISA_sampleDptr:
861-
case llvm::GenISAIntrinsic::GenISA_sampleLptr:
862-
case llvm::GenISAIntrinsic::GenISA_sampleBCptr:
863-
case llvm::GenISAIntrinsic::GenISA_sampleDCptr:
864-
case llvm::GenISAIntrinsic::GenISA_sampleLCptr:
865-
case llvm::GenISAIntrinsic::GenISA_gather4ptr:
866-
case llvm::GenISAIntrinsic::GenISA_gather4POptr:
867-
case llvm::GenISAIntrinsic::GenISA_gather4Cptr:
868-
case llvm::GenISAIntrinsic::GenISA_gather4POCptr:
869-
case llvm::GenISAIntrinsic::GenISA_lodptr:
870-
{
871-
// Figure out the intrinsic operands for texture & sampler
872-
llvm::Value* pTextureValue = nullptr, * pSamplerValue = nullptr;
873-
getTextureAndSamplerOperands(pIntr, pTextureValue, pSamplerValue);
874-
875-
overloadedTys.push_back(pCalledFunc->getReturnType());
876-
overloadedTys.push_back(pIntr->getOperand(0)->getType());
877-
878-
if (pTextureValue == oldPtr)
879-
{
880-
overloadedTys.push_back(newPtr->getType());
881-
if (pSamplerValue)
882-
{
883-
// Samplerless messages will not have sampler in signature.
884-
overloadedTys.push_back(pSamplerValue->getType());
885-
}
886-
}
887-
else if (pSamplerValue == oldPtr)
888-
{
889-
overloadedTys.push_back(pTextureValue->getType());
890-
overloadedTys.push_back(newPtr->getType());
891-
}
892-
893-
break;
894-
}
895-
case llvm::GenISAIntrinsic::GenISA_typedread:
896-
case llvm::GenISAIntrinsic::GenISA_typedwrite:
897-
overloadedTys.push_back(newPtr->getType());
898-
break;
899-
case llvm::GenISAIntrinsic::GenISA_intatomicraw:
900-
case llvm::GenISAIntrinsic::GenISA_icmpxchgatomicraw:
901-
case llvm::GenISAIntrinsic::GenISA_intatomicrawA64:
902-
case llvm::GenISAIntrinsic::GenISA_icmpxchgatomicrawA64:
903-
overloadedTys.push_back(pIntr->getType());
904-
overloadedTys.push_back(newPtr->getType());
905-
if (id == GenISAIntrinsic::GenISA_intatomicrawA64)
906-
{
907-
args[0] = args[1];
908-
args[1] = CastInst::CreatePointerCast(args[1], Type::getInt32Ty(pModule->getContext()), "", pIntr);
909-
id = GenISAIntrinsic::GenISA_intatomicraw;
910-
}
911-
else if (id == GenISAIntrinsic::GenISA_icmpxchgatomicrawA64)
912-
{
913-
args[0] = args[1];
914-
args[1] = CastInst::CreatePointerCast(args[1], Type::getInt32Ty(pModule->getContext()), "", pIntr);
915-
id = GenISAIntrinsic::GenISA_icmpxchgatomicraw;
916-
}
917818
break;
918819
default:
919820
assert(0 && "Unknown intrinsic encountered while changing pointer types");

IGC/Compiler/CISACodeGen/helper.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ namespace IGC
149149
llvm::Value* CreateStoreRawIntrinsic(llvm::StoreInst* inst, llvm::Instruction* bufPtr, llvm::Value* offsetVal);
150150

151151
void getTextureAndSamplerOperands(llvm::GenIntrinsicInst* pIntr, llvm::Value*& pTextureValue, llvm::Value*& pSamplerValue);
152-
void ChangePtrTypeInIntrinsic(llvm::GenIntrinsicInst*& pIntr, llvm::Value* oldPtr, llvm::Value* newPtr, bool isExtendedForBindlessPromotion);
153152
void ChangePtrTypeInIntrinsic(llvm::GenIntrinsicInst*& pIntr, llvm::Value* oldPtr, llvm::Value* newPtr);
154153

155154
llvm::Value* TracePointerSource(llvm::Value* resourcePtr);

0 commit comments

Comments
 (0)