@@ -1525,6 +1525,37 @@ void CodeGenModule::GenOpenCLArgMetadata(llvm::Function *Fn,
1525
1525
QualType ty = parm->getType ();
1526
1526
std::string typeQuals;
1527
1527
1528
+ // Get image and pipe access qualifier:
1529
+ if (ty->isImageType () || ty->isPipeType ()) {
1530
+ const Decl *PDecl = parm;
1531
+ if (auto *TD = dyn_cast<TypedefType>(ty))
1532
+ PDecl = TD->getDecl ();
1533
+ const OpenCLAccessAttr *A = PDecl->getAttr <OpenCLAccessAttr>();
1534
+ if (A && A->isWriteOnly ())
1535
+ accessQuals.push_back (llvm::MDString::get (VMContext, " write_only" ));
1536
+ else if (A && A->isReadWrite ())
1537
+ accessQuals.push_back (llvm::MDString::get (VMContext, " read_write" ));
1538
+ else
1539
+ accessQuals.push_back (llvm::MDString::get (VMContext, " read_only" ));
1540
+ } else
1541
+ accessQuals.push_back (llvm::MDString::get (VMContext, " none" ));
1542
+
1543
+ // Get argument name.
1544
+ argNames.push_back (llvm::MDString::get (VMContext, parm->getName ()));
1545
+
1546
+ auto getTypeSpelling = [&](QualType Ty) {
1547
+ auto typeName = Ty.getUnqualifiedType ().getAsString (Policy);
1548
+
1549
+ if (Ty.isCanonical ()) {
1550
+ StringRef typeNameRef = typeName;
1551
+ // Turn "unsigned type" to "utype"
1552
+ if (typeNameRef.consume_front (" unsigned " ))
1553
+ return std::string (" u" ) + typeNameRef.str ();
1554
+ }
1555
+
1556
+ return typeName;
1557
+ };
1558
+
1528
1559
if (ty->isPointerType ()) {
1529
1560
QualType pointeeTy = ty->getPointeeType ();
1530
1561
@@ -1534,26 +1565,10 @@ void CodeGenModule::GenOpenCLArgMetadata(llvm::Function *Fn,
1534
1565
ArgInfoAddressSpace (pointeeTy.getAddressSpace ()))));
1535
1566
1536
1567
// Get argument type name.
1537
- std::string typeName =
1538
- pointeeTy.getUnqualifiedType ().getAsString (Policy) + " *" ;
1539
-
1540
- // Turn "unsigned type" to "utype"
1541
- std::string::size_type pos = typeName.find (" unsigned" );
1542
- if (pointeeTy.isCanonical () && pos != std::string::npos)
1543
- typeName.erase (pos + 1 , 8 );
1544
-
1545
- argTypeNames.push_back (llvm::MDString::get (VMContext, typeName));
1546
-
1568
+ std::string typeName = getTypeSpelling (pointeeTy) + " *" ;
1547
1569
std::string baseTypeName =
1548
- pointeeTy.getUnqualifiedType ().getCanonicalType ().getAsString (
1549
- Policy) +
1550
- " *" ;
1551
-
1552
- // Turn "unsigned type" to "utype"
1553
- pos = baseTypeName.find (" unsigned" );
1554
- if (pos != std::string::npos)
1555
- baseTypeName.erase (pos + 1 , 8 );
1556
-
1570
+ getTypeSpelling (pointeeTy.getCanonicalType ()) + " *" ;
1571
+ argTypeNames.push_back (llvm::MDString::get (VMContext, typeName));
1557
1572
argBaseTypeNames.push_back (
1558
1573
llvm::MDString::get (VMContext, baseTypeName));
1559
1574
@@ -1575,30 +1590,9 @@ void CodeGenModule::GenOpenCLArgMetadata(llvm::Function *Fn,
1575
1590
llvm::ConstantAsMetadata::get (CGF->Builder .getInt32 (AddrSpc)));
1576
1591
1577
1592
// Get argument type name.
1578
- std::string typeName;
1579
- if (isPipe)
1580
- typeName = ty.getCanonicalType ()
1581
- ->castAs <PipeType>()
1582
- ->getElementType ()
1583
- .getAsString (Policy);
1584
- else
1585
- typeName = ty.getUnqualifiedType ().getAsString (Policy);
1586
-
1587
- // Turn "unsigned type" to "utype"
1588
- std::string::size_type pos = typeName.find (" unsigned" );
1589
- if (ty.isCanonical () && pos != std::string::npos)
1590
- typeName.erase (pos + 1 , 8 );
1591
-
1592
- std::string baseTypeName;
1593
- if (isPipe)
1594
- baseTypeName = ty.getCanonicalType ()
1595
- ->castAs <PipeType>()
1596
- ->getElementType ()
1597
- .getCanonicalType ()
1598
- .getAsString (Policy);
1599
- else
1600
- baseTypeName =
1601
- ty.getUnqualifiedType ().getCanonicalType ().getAsString (Policy);
1593
+ ty = isPipe ? ty->castAs <PipeType>()->getElementType () : ty;
1594
+ std::string typeName = getTypeSpelling (ty);
1595
+ std::string baseTypeName = getTypeSpelling (ty.getCanonicalType ());
1602
1596
1603
1597
// Remove access qualifiers on images
1604
1598
// (as they are inseparable from type in clang implementation,
@@ -1610,39 +1604,14 @@ void CodeGenModule::GenOpenCLArgMetadata(llvm::Function *Fn,
1610
1604
}
1611
1605
1612
1606
argTypeNames.push_back (llvm::MDString::get (VMContext, typeName));
1613
-
1614
- // Turn "unsigned type" to "utype"
1615
- pos = baseTypeName.find (" unsigned" );
1616
- if (pos != std::string::npos)
1617
- baseTypeName.erase (pos + 1 , 8 );
1618
-
1619
1607
argBaseTypeNames.push_back (
1620
1608
llvm::MDString::get (VMContext, baseTypeName));
1621
1609
1622
1610
if (isPipe)
1623
1611
typeQuals = " pipe" ;
1624
1612
}
1625
-
1626
1613
argTypeQuals.push_back (llvm::MDString::get (VMContext, typeQuals));
1627
1614
1628
- // Get image and pipe access qualifier:
1629
- if (ty->isImageType () || ty->isPipeType ()) {
1630
- const Decl *PDecl = parm;
1631
- if (auto *TD = dyn_cast<TypedefType>(ty))
1632
- PDecl = TD->getDecl ();
1633
- const OpenCLAccessAttr *A = PDecl->getAttr <OpenCLAccessAttr>();
1634
- if (A && A->isWriteOnly ())
1635
- accessQuals.push_back (llvm::MDString::get (VMContext, " write_only" ));
1636
- else if (A && A->isReadWrite ())
1637
- accessQuals.push_back (llvm::MDString::get (VMContext, " read_write" ));
1638
- else
1639
- accessQuals.push_back (llvm::MDString::get (VMContext, " read_only" ));
1640
- } else
1641
- accessQuals.push_back (llvm::MDString::get (VMContext, " none" ));
1642
-
1643
- // Get argument name.
1644
- argNames.push_back (llvm::MDString::get (VMContext, parm->getName ()));
1645
-
1646
1615
auto *SYCLBufferLocationAttr =
1647
1616
parm->getAttr <SYCLIntelBufferLocationAttr>();
1648
1617
argSYCLBufferLocationAttr.push_back (
0 commit comments