Skip to content

Commit a487d6b

Browse files
committed
address comments
1 parent ab7d81f commit a487d6b

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,11 +1675,8 @@ void NVPTXAsmPrinter::bufferAggregateConstant(const Constant *CPV,
16751675
const DataLayout &DL = getDataLayout();
16761676

16771677
auto ExtendBuffer = [](APInt Val, AggBuffer *Buffer) {
1678-
for (unsigned _ : llvm::seq(Val.getBitWidth() / 8)) {
1679-
uint8_t Byte = Val.getLoBits(8).getZExtValue();
1680-
Buffer->addBytes(&Byte, 1, 1);
1681-
Val.lshrInPlace(8);
1682-
}
1678+
for (unsigned I : llvm::seq(Val.getBitWidth() / 8))
1679+
Buffer->addByte(Val.extractBitsAsZExtValue(8, I * 8));
16831680
};
16841681

16851682
// Integers of arbitrary width
@@ -1704,23 +1701,21 @@ void NVPTXAsmPrinter::bufferAggregateConstant(const Constant *CPV,
17041701
}
17051702

17061703
if (const auto *CDS = dyn_cast<ConstantDataSequential>(CPV)) {
1707-
if (CDS->getNumElements())
1708-
for (unsigned i : llvm::seq(CDS->getNumElements()))
1709-
bufferLEByte(cast<Constant>(CDS->getElementAsConstant(i)), 0,
1710-
aggBuffer);
1704+
for (unsigned I : llvm::seq(CDS->getNumElements()))
1705+
bufferLEByte(cast<Constant>(CDS->getElementAsConstant(I)), 0, aggBuffer);
17111706
return;
17121707
}
17131708

17141709
if (isa<ConstantStruct>(CPV)) {
17151710
if (CPV->getNumOperands()) {
17161711
StructType *ST = cast<StructType>(CPV->getType());
1717-
for (unsigned i : llvm::seq(CPV->getNumOperands())) {
1718-
int EndOffset = (i + 1 == CPV->getNumOperands())
1712+
for (unsigned I : llvm::seq(CPV->getNumOperands())) {
1713+
int EndOffset = (I + 1 == CPV->getNumOperands())
17191714
? DL.getStructLayout(ST)->getElementOffset(0) +
17201715
DL.getTypeAllocSize(ST)
1721-
: DL.getStructLayout(ST)->getElementOffset(i + 1);
1722-
int Bytes = EndOffset - DL.getStructLayout(ST)->getElementOffset(i);
1723-
bufferLEByte(cast<Constant>(CPV->getOperand(i)), Bytes, aggBuffer);
1716+
: DL.getStructLayout(ST)->getElementOffset(I + 1);
1717+
int Bytes = EndOffset - DL.getStructLayout(ST)->getElementOffset(I);
1718+
bufferLEByte(cast<Constant>(CPV->getOperand(I)), Bytes, aggBuffer);
17241719
}
17251720
}
17261721
return;

llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ class LLVM_LIBRARY_VISIBILITY NVPTXAsmPrinter : public AsmPrinter {
125125
return curpos;
126126
}
127127

128+
void addByte(uint8_t Byte) {
129+
assert((curpos + 1) <= size);
130+
buffer[curpos] = Byte;
131+
curpos++;
132+
}
133+
128134
unsigned addZeros(int Num) {
129135
assert((curpos + Num) <= size);
130136
for (int i = 0; i < Num; ++i) {

0 commit comments

Comments
 (0)