@@ -259,7 +259,7 @@ void NVPTXAsmPrinter::printReturnValStr(const Function *F, raw_ostream &O) {
259259 return ;
260260 O << " (" ;
261261
262- auto PrintScalarParam = [&](unsigned Size) {
262+ auto PrintScalarRetVal = [&](unsigned Size) {
263263 O << " .param .b" << promoteScalarArgumentSize (Size) << " func_retval0" ;
264264 };
265265 if (shouldPassAsArray (Ty)) {
@@ -269,11 +269,11 @@ void NVPTXAsmPrinter::printReturnValStr(const Function *F, raw_ostream &O) {
269269 O << " .param .align " << RetAlignment.value () << " .b8 func_retval0["
270270 << TotalSize << " ]" ;
271271 } else if (Ty->isFloatingPointTy ()) {
272- PrintScalarParam (Ty->getPrimitiveSizeInBits ());
272+ PrintScalarRetVal (Ty->getPrimitiveSizeInBits ());
273273 } else if (auto *ITy = dyn_cast<IntegerType>(Ty)) {
274- PrintScalarParam (ITy->getBitWidth ());
274+ PrintScalarRetVal (ITy->getBitWidth ());
275275 } else if (isa<PointerType>(Ty)) {
276- PrintScalarParam (TLI->getPointerTy (DL).getSizeInBits ());
276+ PrintScalarRetVal (TLI->getPointerTy (DL).getSizeInBits ());
277277 } else
278278 llvm_unreachable (" Unknown return type" );
279279 O << " ) " ;
@@ -1674,24 +1674,24 @@ void NVPTXAsmPrinter::bufferAggregateConstant(const Constant *CPV,
16741674 AggBuffer *aggBuffer) {
16751675 const DataLayout &DL = getDataLayout ();
16761676
1677- auto BufferConstant = [& ](APInt Val) {
1678- for (unsigned I = 0 , E = DL. getTypeAllocSize (CPV-> getType ()); I < E; ++I ) {
1677+ auto ExtendBuffer = [](APInt Val, AggBuffer *Buffer ) {
1678+ for (unsigned _ : llvm::seq (Val. getBitWidth () / 8 ) ) {
16791679 uint8_t Byte = Val.getLoBits (8 ).getZExtValue ();
1680- aggBuffer ->addBytes (&Byte, 1 , 1 );
1680+ Buffer ->addBytes (&Byte, 1 , 1 );
16811681 Val.lshrInPlace (8 );
16821682 }
16831683 };
16841684
16851685 // Integers of arbitrary width
16861686 if (const ConstantInt *CI = dyn_cast<ConstantInt>(CPV)) {
1687- BufferConstant (CI->getValue ());
1687+ ExtendBuffer (CI->getValue (), aggBuffer );
16881688 return ;
16891689 }
16901690
16911691 // f128
16921692 if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CPV)) {
16931693 if (CFP->getType ()->isFP128Ty ()) {
1694- BufferConstant (CFP->getValueAPF ().bitcastToAPInt ());
1694+ ExtendBuffer (CFP->getValueAPF ().bitcastToAPInt (), aggBuffer );
16951695 return ;
16961696 }
16971697 }
@@ -1705,7 +1705,7 @@ void NVPTXAsmPrinter::bufferAggregateConstant(const Constant *CPV,
17051705
17061706 if (const auto *CDS = dyn_cast<ConstantDataSequential>(CPV)) {
17071707 if (CDS->getNumElements ())
1708- for (unsigned i = 0 ; i < CDS->getNumElements (); ++i )
1708+ for (unsigned i : llvm::seq ( CDS->getNumElements ()) )
17091709 bufferLEByte (cast<Constant>(CDS->getElementAsConstant (i)), 0 ,
17101710 aggBuffer);
17111711 return ;
@@ -1714,15 +1714,12 @@ void NVPTXAsmPrinter::bufferAggregateConstant(const Constant *CPV,
17141714 if (isa<ConstantStruct>(CPV)) {
17151715 if (CPV->getNumOperands ()) {
17161716 StructType *ST = cast<StructType>(CPV->getType ());
1717- for (unsigned i = 0 , e = CPV->getNumOperands (); i != e; ++i) {
1718- int Bytes;
1719- if (i == (e - 1 ))
1720- Bytes = DL.getStructLayout (ST)->getElementOffset (0 ) +
1721- DL.getTypeAllocSize (ST) -
1722- DL.getStructLayout (ST)->getElementOffset (i);
1723- else
1724- Bytes = DL.getStructLayout (ST)->getElementOffset (i + 1 ) -
1725- DL.getStructLayout (ST)->getElementOffset (i);
1717+ for (unsigned i : llvm::seq (CPV->getNumOperands ())) {
1718+ int EndOffset = (i + 1 == CPV->getNumOperands ())
1719+ ? DL.getStructLayout (ST)->getElementOffset (0 ) +
1720+ DL.getTypeAllocSize (ST)
1721+ : DL.getStructLayout (ST)->getElementOffset (i + 1 );
1722+ int Bytes = EndOffset - DL.getStructLayout (ST)->getElementOffset (i);
17261723 bufferLEByte (cast<Constant>(CPV->getOperand (i)), Bytes, aggBuffer);
17271724 }
17281725 }
0 commit comments