@@ -1475,6 +1475,37 @@ void CodeGenModule::GenOpenCLArgMetadata(llvm::Function *Fn,
1475
1475
QualType ty = parm->getType ();
1476
1476
std::string typeQuals;
1477
1477
1478
+ // Get image and pipe access qualifier:
1479
+ if (ty->isImageType () || ty->isPipeType ()) {
1480
+ const Decl *PDecl = parm;
1481
+ if (auto *TD = dyn_cast<TypedefType>(ty))
1482
+ PDecl = TD->getDecl ();
1483
+ const OpenCLAccessAttr *A = PDecl->getAttr <OpenCLAccessAttr>();
1484
+ if (A && A->isWriteOnly ())
1485
+ accessQuals.push_back (llvm::MDString::get (VMContext, " write_only" ));
1486
+ else if (A && A->isReadWrite ())
1487
+ accessQuals.push_back (llvm::MDString::get (VMContext, " read_write" ));
1488
+ else
1489
+ accessQuals.push_back (llvm::MDString::get (VMContext, " read_only" ));
1490
+ } else
1491
+ accessQuals.push_back (llvm::MDString::get (VMContext, " none" ));
1492
+
1493
+ // Get argument name.
1494
+ argNames.push_back (llvm::MDString::get (VMContext, parm->getName ()));
1495
+
1496
+ auto getTypeSpelling = [&](QualType Ty) {
1497
+ auto typeName = Ty.getUnqualifiedType ().getAsString (Policy);
1498
+
1499
+ if (Ty.isCanonical ()) {
1500
+ StringRef typeNameRef = typeName;
1501
+ // Turn "unsigned type" to "utype"
1502
+ if (typeNameRef.consume_front (" unsigned " ))
1503
+ return std::string (" u" ) + typeNameRef.str ();
1504
+ }
1505
+
1506
+ return typeName;
1507
+ };
1508
+
1478
1509
if (ty->isPointerType ()) {
1479
1510
QualType pointeeTy = ty->getPointeeType ();
1480
1511
@@ -1484,26 +1515,10 @@ void CodeGenModule::GenOpenCLArgMetadata(llvm::Function *Fn,
1484
1515
ArgInfoAddressSpace (pointeeTy.getAddressSpace ()))));
1485
1516
1486
1517
// Get argument type name.
1487
- std::string typeName =
1488
- pointeeTy.getUnqualifiedType ().getAsString (Policy) + " *" ;
1489
-
1490
- // Turn "unsigned type" to "utype"
1491
- std::string::size_type pos = typeName.find (" unsigned" );
1492
- if (pointeeTy.isCanonical () && pos != std::string::npos)
1493
- typeName.erase (pos + 1 , 8 );
1494
-
1495
- argTypeNames.push_back (llvm::MDString::get (VMContext, typeName));
1496
-
1518
+ std::string typeName = getTypeSpelling (pointeeTy) + " *" ;
1497
1519
std::string baseTypeName =
1498
- pointeeTy.getUnqualifiedType ().getCanonicalType ().getAsString (
1499
- Policy) +
1500
- " *" ;
1501
-
1502
- // Turn "unsigned type" to "utype"
1503
- pos = baseTypeName.find (" unsigned" );
1504
- if (pos != std::string::npos)
1505
- baseTypeName.erase (pos + 1 , 8 );
1506
-
1520
+ getTypeSpelling (pointeeTy.getCanonicalType ()) + " *" ;
1521
+ argTypeNames.push_back (llvm::MDString::get (VMContext, typeName));
1507
1522
argBaseTypeNames.push_back (
1508
1523
llvm::MDString::get (VMContext, baseTypeName));
1509
1524
@@ -1525,30 +1540,9 @@ void CodeGenModule::GenOpenCLArgMetadata(llvm::Function *Fn,
1525
1540
llvm::ConstantAsMetadata::get (CGF->Builder .getInt32 (AddrSpc)));
1526
1541
1527
1542
// Get argument type name.
1528
- std::string typeName;
1529
- if (isPipe)
1530
- typeName = ty.getCanonicalType ()
1531
- ->castAs <PipeType>()
1532
- ->getElementType ()
1533
- .getAsString (Policy);
1534
- else
1535
- typeName = ty.getUnqualifiedType ().getAsString (Policy);
1536
-
1537
- // Turn "unsigned type" to "utype"
1538
- std::string::size_type pos = typeName.find (" unsigned" );
1539
- if (ty.isCanonical () && pos != std::string::npos)
1540
- typeName.erase (pos + 1 , 8 );
1541
-
1542
- std::string baseTypeName;
1543
- if (isPipe)
1544
- baseTypeName = ty.getCanonicalType ()
1545
- ->castAs <PipeType>()
1546
- ->getElementType ()
1547
- .getCanonicalType ()
1548
- .getAsString (Policy);
1549
- else
1550
- baseTypeName =
1551
- ty.getUnqualifiedType ().getCanonicalType ().getAsString (Policy);
1543
+ ty = isPipe ? ty->castAs <PipeType>()->getElementType () : ty;
1544
+ std::string typeName = getTypeSpelling (ty);
1545
+ std::string baseTypeName = getTypeSpelling (ty.getCanonicalType ());
1552
1546
1553
1547
// Remove access qualifiers on images
1554
1548
// (as they are inseparable from type in clang implementation,
@@ -1560,38 +1554,13 @@ void CodeGenModule::GenOpenCLArgMetadata(llvm::Function *Fn,
1560
1554
}
1561
1555
1562
1556
argTypeNames.push_back (llvm::MDString::get (VMContext, typeName));
1563
-
1564
- // Turn "unsigned type" to "utype"
1565
- pos = baseTypeName.find (" unsigned" );
1566
- if (pos != std::string::npos)
1567
- baseTypeName.erase (pos + 1 , 8 );
1568
-
1569
1557
argBaseTypeNames.push_back (
1570
1558
llvm::MDString::get (VMContext, baseTypeName));
1571
1559
1572
1560
if (isPipe)
1573
1561
typeQuals = " pipe" ;
1574
1562
}
1575
-
1576
1563
argTypeQuals.push_back (llvm::MDString::get (VMContext, typeQuals));
1577
-
1578
- // Get image and pipe access qualifier:
1579
- if (ty->isImageType () || ty->isPipeType ()) {
1580
- const Decl *PDecl = parm;
1581
- if (auto *TD = dyn_cast<TypedefType>(ty))
1582
- PDecl = TD->getDecl ();
1583
- const OpenCLAccessAttr *A = PDecl->getAttr <OpenCLAccessAttr>();
1584
- if (A && A->isWriteOnly ())
1585
- accessQuals.push_back (llvm::MDString::get (VMContext, " write_only" ));
1586
- else if (A && A->isReadWrite ())
1587
- accessQuals.push_back (llvm::MDString::get (VMContext, " read_write" ));
1588
- else
1589
- accessQuals.push_back (llvm::MDString::get (VMContext, " read_only" ));
1590
- } else
1591
- accessQuals.push_back (llvm::MDString::get (VMContext, " none" ));
1592
-
1593
- // Get argument name.
1594
- argNames.push_back (llvm::MDString::get (VMContext, parm->getName ()));
1595
1564
}
1596
1565
1597
1566
Fn->setMetadata (" kernel_arg_addr_space" ,
0 commit comments