[llvm] [NVPTX] Basic support for fp128 as a storage type (PR #136006)
Artem Belevich via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 16 15:49:06 PDT 2025
================
@@ -1682,31 +1673,39 @@ void NVPTXAsmPrinter::bufferLEByte(const Constant *CPV, int Bytes,
void NVPTXAsmPrinter::bufferAggregateConstant(const Constant *CPV,
AggBuffer *aggBuffer) {
const DataLayout &DL = getDataLayout();
- int Bytes;
- // Integers of arbitrary width
- if (const ConstantInt *CI = dyn_cast<ConstantInt>(CPV)) {
- APInt Val = CI->getValue();
- for (unsigned I = 0, E = DL.getTypeAllocSize(CPV->getType()); I < E; ++I) {
+ auto ExtendBuffer = [](APInt Val, AggBuffer *Buffer) {
+ for (unsigned _ : llvm::seq(Val.getBitWidth() / 8)) {
uint8_t Byte = Val.getLoBits(8).getZExtValue();
- aggBuffer->addBytes(&Byte, 1, 1);
+ Buffer->addBytes(&Byte, 1, 1);
Val.lshrInPlace(8);
}
+ };
+
+ // Integers of arbitrary width
+ if (const ConstantInt *CI = dyn_cast<ConstantInt>(CPV)) {
+ ExtendBuffer(CI->getValue(), aggBuffer);
return;
}
+ // f128
+ if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CPV)) {
+ if (CFP->getType()->isFP128Ty()) {
+ ExtendBuffer(CFP->getValueAPF().bitcastToAPInt(), aggBuffer);
+ return;
+ }
+ }
+
// Old constants
if (isa<ConstantArray>(CPV) || isa<ConstantVector>(CPV)) {
- if (CPV->getNumOperands())
- for (unsigned i = 0, e = CPV->getNumOperands(); i != e; ++i)
- bufferLEByte(cast<Constant>(CPV->getOperand(i)), 0, aggBuffer);
+ for (const auto &Op : CPV->operands())
+ bufferLEByte(cast<Constant>(Op), 0, aggBuffer);
return;
}
- if (const ConstantDataSequential *CDS =
- dyn_cast<ConstantDataSequential>(CPV)) {
+ if (const auto *CDS = dyn_cast<ConstantDataSequential>(CPV)) {
if (CDS->getNumElements())
- for (unsigned i = 0; i < CDS->getNumElements(); ++i)
+ for (unsigned i : llvm::seq(CDS->getNumElements()))
----------------
Artem-B wrote:
Style nit: variables should start with a capital. Applies here and elsewhere.
https://github.com/llvm/llvm-project/pull/136006
More information about the llvm-commits
mailing list