Skip to content

Commit 5851002

Browse files
committed
address comments
1 parent db1baa6 commit 5851002

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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 BufferConstant = [](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+
BufferConstant(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+
BufferConstant(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
}

llvm/test/CodeGen/NVPTX/global-variable-big.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ target triple = "nvptx64-nvidia-cuda"
1010
@gv = addrspace(1) externally_initialized global i128 21345817372864405881847059188222722561, align 16
1111
; CHECK: .visible .global .align 16 .b8 gv[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
1212

13-
@gv_fp128 = addrspace(1) externally_initialized global fp128 0xL33333333333333334004033333333333, align 16
14-
; CHECK: .visible .global .align 16 .b8 gv_fp128[16] = {51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 3, 4, 64};
13+
@gv_fp128 = addrspace(1) externally_initialized global fp128 0xL0807060504030201100F0E0D0C0B0A09, align 16
14+
; CHECK: .visible .global .align 16 .b8 gv_fp128[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
1515

1616
; Make sure that we do not overflow on large number of elements.
1717
; CHECK: .visible .global .align 1 .b8 large_data[4831838208];

0 commit comments

Comments
 (0)