@@ -1597,6 +1597,29 @@ void OCL20ToSPIRV::visitCallKernelQuery(CallInst *CI, StringRef DemangledName) {
1597
1597
/* BuiltinFuncMangleInfo*/ nullptr , &Attrs);
1598
1598
}
1599
1599
1600
+ // Add postfix to overloaded intel subgroup block read/write builtins
1601
+ // so new functions can be distinguished.
1602
+ static void processSubgroupBlockReadWriteINTEL (CallInst *CI,
1603
+ OCLBuiltinTransInfo &Info,
1604
+ const Type *DataTy, Module *M) {
1605
+ unsigned VectorNumElements = 1 ;
1606
+ if (DataTy->isVectorTy ())
1607
+ VectorNumElements = DataTy->getVectorNumElements ();
1608
+ unsigned ElementBitSize = DataTy->getScalarSizeInBits ();
1609
+ Info.Postfix = " _" ;
1610
+ Info.Postfix +=
1611
+ getIntelSubgroupBlockDataPostfix (ElementBitSize, VectorNumElements);
1612
+ assert (CI->getCalledFunction () && " Unexpected indirect call" );
1613
+ AttributeList Attrs = CI->getCalledFunction ()->getAttributes ();
1614
+ mutateCallInstSPIRV (
1615
+ M, CI,
1616
+ [&Info](CallInst *, std::vector<Value *> &Args) {
1617
+ Info.PostProc (Args);
1618
+ return Info.UniqName + Info.Postfix ;
1619
+ },
1620
+ &Attrs);
1621
+ }
1622
+
1600
1623
// The intel_sub_group_block_read built-ins are overloaded to support both
1601
1624
// buffers and images, but need to be mapped to distinct SPIR-V instructions.
1602
1625
// Additionally, for block reads, need to distinguish between scalar block
@@ -1607,70 +1630,24 @@ void OCL20ToSPIRV::visitSubgroupBlockReadINTEL(CallInst *CI) {
1607
1630
Info.UniqName = getSPIRVFuncName (spv::OpSubgroupImageBlockReadINTEL);
1608
1631
else
1609
1632
Info.UniqName = getSPIRVFuncName (spv::OpSubgroupBlockReadINTEL);
1610
- if (CI->getType ()->isVectorTy ()) {
1611
- switch (cast<VectorType>(CI->getType ())->getNumElements ()) {
1612
- case 2 :
1613
- Info.Postfix = " _v2" ;
1614
- break ;
1615
- case 4 :
1616
- Info.Postfix = " _v4" ;
1617
- break ;
1618
- case 8 :
1619
- Info.Postfix = " _v8" ;
1620
- break ;
1621
- default :
1622
- break ;
1623
- }
1624
- }
1625
- if (CI->getType ()->getScalarSizeInBits () == 16 )
1626
- Info.Postfix += " _us" ;
1627
- else
1628
- Info.Postfix += " _ui" ;
1629
- assert (CI->getCalledFunction () && " Unexpected indirect call" );
1630
- AttributeList Attrs = CI->getCalledFunction ()->getAttributes ();
1631
- mutateCallInstSPIRV (M, CI,
1632
- [=](CallInst *, std::vector<Value *> &Args) {
1633
- Info.PostProc (Args);
1634
- return Info.UniqName + Info.Postfix ;
1635
- },
1636
- &Attrs);
1633
+ Type *DataTy = CI->getType ();
1634
+ processSubgroupBlockReadWriteINTEL (CI, Info, DataTy, M);
1637
1635
}
1638
1636
1639
1637
// The intel_sub_group_block_write built-ins are similarly overloaded to support
1640
1638
// both buffers and images but need to be mapped to distinct SPIR-V
1641
- // instructions. Since the type of data to be written is encoded in the mangled
1642
- // name there is no need to do additional work to distinguish between scalar
1643
- // block writes and vector block writes.
1639
+ // instructions.
1644
1640
void OCL20ToSPIRV::visitSubgroupBlockWriteINTEL (CallInst *CI) {
1645
1641
OCLBuiltinTransInfo Info;
1646
1642
if (isOCLImageType (CI->getArgOperand (0 )->getType ()))
1647
1643
Info.UniqName = getSPIRVFuncName (spv::OpSubgroupImageBlockWriteINTEL);
1648
1644
else
1649
1645
Info.UniqName = getSPIRVFuncName (spv::OpSubgroupBlockWriteINTEL);
1650
- unsigned NumArgs = CI->getNumArgOperands ();
1651
- if (NumArgs && CI->getArgOperand (NumArgs - 1 )->getType ()->isVectorTy ()) {
1652
- switch (cast<VectorType>(CI->getArgOperand (NumArgs - 1 )->getType ())->getNumElements ()) {
1653
- case 2 :
1654
- Info.Postfix = " _v2" ;
1655
- break ;
1656
- case 4 :
1657
- Info.Postfix = " _v4" ;
1658
- break ;
1659
- case 8 :
1660
- Info.Postfix = " _v8" ;
1661
- break ;
1662
- default :
1663
- break ;
1664
- }
1665
- }
1666
- assert (CI->getCalledFunction () && " Unexpected indirect call" );
1667
- AttributeList Attrs = CI->getCalledFunction ()->getAttributes ();
1668
- mutateCallInstSPIRV (M, CI,
1669
- [=](CallInst *, std::vector<Value *> &Args) {
1670
- Info.PostProc (Args);
1671
- return Info.UniqName + Info.Postfix ;
1672
- },
1673
- &Attrs);
1646
+ assert (!CI->arg_empty () &&
1647
+ " Intel subgroup block write should have arguments" );
1648
+ unsigned DataArg = CI->getNumArgOperands () - 1 ;
1649
+ Type *DataTy = CI->getArgOperand (DataArg)->getType ();
1650
+ processSubgroupBlockReadWriteINTEL (CI, Info, DataTy, M);
1674
1651
}
1675
1652
1676
1653
void OCL20ToSPIRV::visitSubgroupImageMediaBlockINTEL (CallInst *CI,
0 commit comments