@@ -684,7 +684,7 @@ void NVPTXAsmPrinter::emitDeclaration(const Function *F, raw_ostream &O) {
684
684
else
685
685
O << " .func " ;
686
686
printReturnValStr (F, O);
687
- O << * getSymbol (F) << " \n " ;
687
+ O << getSymbolName (F) << " \n " ;
688
688
emitFunctionParamList (F, O);
689
689
O << " ;\n " ;
690
690
}
@@ -1209,7 +1209,7 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
1209
1209
else
1210
1210
O << getPTXFundamentalTypeStr (ETy, false );
1211
1211
O << " " ;
1212
- O << * getSymbol (GVar);
1212
+ O << getSymbolName (GVar);
1213
1213
1214
1214
// Ptx allows variable initilization only for constant and global state
1215
1215
// spaces.
@@ -1245,31 +1245,31 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
1245
1245
bufferAggregateConstant (Initializer, &aggBuffer);
1246
1246
if (aggBuffer.numSymbols ) {
1247
1247
if (nvptxSubtarget.is64Bit ()) {
1248
- O << " .u64 " << * getSymbol (GVar) << " [" ;
1248
+ O << " .u64 " << getSymbolName (GVar) << " [" ;
1249
1249
O << ElementSize / 8 ;
1250
1250
} else {
1251
- O << " .u32 " << * getSymbol (GVar) << " [" ;
1251
+ O << " .u32 " << getSymbolName (GVar) << " [" ;
1252
1252
O << ElementSize / 4 ;
1253
1253
}
1254
1254
O << " ]" ;
1255
1255
} else {
1256
- O << " .b8 " << * getSymbol (GVar) << " [" ;
1256
+ O << " .b8 " << getSymbolName (GVar) << " [" ;
1257
1257
O << ElementSize;
1258
1258
O << " ]" ;
1259
1259
}
1260
1260
O << " = {" ;
1261
1261
aggBuffer.print ();
1262
1262
O << " }" ;
1263
1263
} else {
1264
- O << " .b8 " << * getSymbol (GVar);
1264
+ O << " .b8 " << getSymbolName (GVar);
1265
1265
if (ElementSize) {
1266
1266
O << " [" ;
1267
1267
O << ElementSize;
1268
1268
O << " ]" ;
1269
1269
}
1270
1270
}
1271
1271
} else {
1272
- O << " .b8 " << * getSymbol (GVar);
1272
+ O << " .b8 " << getSymbolName (GVar);
1273
1273
if (ElementSize) {
1274
1274
O << " [" ;
1275
1275
O << ElementSize;
@@ -1376,7 +1376,7 @@ void NVPTXAsmPrinter::emitPTXGlobalVariable(const GlobalVariable *GVar,
1376
1376
O << " ." ;
1377
1377
O << getPTXFundamentalTypeStr (ETy);
1378
1378
O << " " ;
1379
- O << * getSymbol (GVar);
1379
+ O << getSymbolName (GVar);
1380
1380
return ;
1381
1381
}
1382
1382
@@ -1391,7 +1391,7 @@ void NVPTXAsmPrinter::emitPTXGlobalVariable(const GlobalVariable *GVar,
1391
1391
case Type::ArrayTyID:
1392
1392
case Type::VectorTyID:
1393
1393
ElementSize = TD->getTypeStoreSize (ETy);
1394
- O << " .b8 " << * getSymbol (GVar) << " [" ;
1394
+ O << " .b8 " << getSymbolName (GVar) << " [" ;
1395
1395
if (ElementSize) {
1396
1396
O << itostr (ElementSize);
1397
1397
}
@@ -1446,7 +1446,7 @@ void NVPTXAsmPrinter::printParamName(Function::const_arg_iterator I,
1446
1446
int paramIndex, raw_ostream &O) {
1447
1447
if ((nvptxSubtarget.getDrvInterface () == NVPTX::NVCL) ||
1448
1448
(nvptxSubtarget.getDrvInterface () == NVPTX::CUDA))
1449
- O << * getSymbol (I->getParent ()) << " _param_" << paramIndex;
1449
+ O << getSymbolName (I->getParent ()) << " _param_" << paramIndex;
1450
1450
else {
1451
1451
std::string argName = I->getName ();
1452
1452
const char *p = argName.c_str ();
@@ -1505,13 +1505,13 @@ void NVPTXAsmPrinter::emitFunctionParamList(const Function *F, raw_ostream &O) {
1505
1505
if (llvm::isImage (*I)) {
1506
1506
std::string sname = I->getName ();
1507
1507
if (llvm::isImageWriteOnly (*I))
1508
- O << " \t .param .surfref " << * getSymbol (F) << " _param_"
1508
+ O << " \t .param .surfref " << getSymbolName (F) << " _param_"
1509
1509
<< paramIndex;
1510
1510
else // Default image is read_only
1511
- O << " \t .param .texref " << * getSymbol (F) << " _param_"
1511
+ O << " \t .param .texref " << getSymbolName (F) << " _param_"
1512
1512
<< paramIndex;
1513
1513
} else // Should be llvm::isSampler(*I)
1514
- O << " \t .param .samplerref " << * getSymbol (F) << " _param_"
1514
+ O << " \t .param .samplerref " << getSymbolName (F) << " _param_"
1515
1515
<< paramIndex;
1516
1516
continue ;
1517
1517
}
@@ -1758,13 +1758,13 @@ void NVPTXAsmPrinter::printScalarConstant(const Constant *CPV, raw_ostream &O) {
1758
1758
return ;
1759
1759
}
1760
1760
if (const GlobalValue *GVar = dyn_cast<GlobalValue>(CPV)) {
1761
- O << * getSymbol (GVar);
1761
+ O << getSymbolName (GVar);
1762
1762
return ;
1763
1763
}
1764
1764
if (const ConstantExpr *Cexpr = dyn_cast<ConstantExpr>(CPV)) {
1765
1765
const Value *v = Cexpr->stripPointerCasts ();
1766
1766
if (const GlobalValue *GVar = dyn_cast<GlobalValue>(v)) {
1767
- O << * getSymbol (GVar);
1767
+ O << getSymbolName (GVar);
1768
1768
return ;
1769
1769
} else {
1770
1770
O << *LowerConstant (CPV, *this );
@@ -2078,7 +2078,7 @@ void NVPTXAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
2078
2078
break ;
2079
2079
2080
2080
case MachineOperand::MO_GlobalAddress:
2081
- O << * getSymbol (MO.getGlobal ());
2081
+ O << getSymbolName (MO.getGlobal ());
2082
2082
break ;
2083
2083
2084
2084
case MachineOperand::MO_MachineBasicBlock:
@@ -2139,6 +2139,33 @@ LineReader *NVPTXAsmPrinter::getReader(std::string filename) {
2139
2139
return reader;
2140
2140
}
2141
2141
2142
+ std::string NVPTXAsmPrinter::getSymbolName (const GlobalValue *GV) const {
2143
+ // Obtain the original symbol name.
2144
+ MCSymbol *Sym = getSymbol (GV);
2145
+ std::string OriginalName;
2146
+ raw_string_ostream OriginalNameStream (OriginalName);
2147
+ Sym->print (OriginalNameStream);
2148
+ OriginalNameStream.flush ();
2149
+
2150
+ // MCSymbol already does symbol-name sanitizing, so names it produces are
2151
+ // valid for object files. The only two characters valida in that context
2152
+ // and indigestible by the PTX assembler are '.' and '@'.
2153
+ std::string CleanName;
2154
+ raw_string_ostream CleanNameStream (CleanName);
2155
+ for (unsigned I = 0 , E = OriginalName.size (); I != E; ++I) {
2156
+ char C = OriginalName[I];
2157
+ if (C == ' .' ) {
2158
+ CleanNameStream << " _$_" ;
2159
+ } else if (C == ' @' ) {
2160
+ CleanNameStream << " _%_" ;
2161
+ } else {
2162
+ CleanNameStream << C;
2163
+ }
2164
+ }
2165
+
2166
+ return CleanNameStream.str ();
2167
+ }
2168
+
2142
2169
std::string LineReader::readLine (unsigned lineNum) {
2143
2170
if (lineNum < theCurLine) {
2144
2171
theCurLine = 0 ;
0 commit comments