[PATCH] D129773: [NVPTX][NFC] Simplify printing initialization of aggregates
Artem Belevich via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 14 13:06:03 PDT 2022
tra accepted this revision.
tra added inline comments.
This revision is now accepted and ready to land.
================
Comment at: llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h:140-141
- void print() {
- if (numSymbols == 0) {
- // print out in bytes
- for (unsigned i = 0; i < size; i++) {
- if (i)
- O << ", ";
- O << (unsigned int) buffer[i];
- }
- } else {
- // print out in 4-bytes or 8-bytes
- unsigned int pos = 0;
- unsigned int nSym = 0;
- unsigned int nextSymbolPos = symbolPosInBuffer[nSym];
- unsigned int nBytes = 4;
- if (static_cast<const NVPTXTargetMachine &>(AP.TM).is64Bit())
- nBytes = 8;
- for (pos = 0; pos < size; pos += nBytes) {
- if (pos)
- O << ", ";
- if (pos == nextSymbolPos) {
- const Value *v = Symbols[nSym];
- const Value *v0 = SymbolsBeforeStripping[nSym];
- if (const GlobalValue *GVar = dyn_cast<GlobalValue>(v)) {
- MCSymbol *Name = AP.getSymbol(GVar);
- PointerType *PTy = dyn_cast<PointerType>(v0->getType());
- bool IsNonGenericPointer = false; // Is v0 a non-generic pointer?
- if (PTy && PTy->getAddressSpace() != 0) {
- IsNonGenericPointer = true;
- }
- if (EmitGeneric && !isa<Function>(v) && !IsNonGenericPointer) {
- O << "generic(";
- Name->print(O, AP.MAI);
- O << ")";
- } else {
- Name->print(O, AP.MAI);
- }
- } else if (const ConstantExpr *CExpr = dyn_cast<ConstantExpr>(v0)) {
- const MCExpr *Expr =
- AP.lowerConstantForGV(cast<Constant>(CExpr), false);
- AP.printMCExpr(*Expr, O);
- } else
- llvm_unreachable("symbol type unknown");
- nSym++;
- if (nSym >= numSymbols)
- nextSymbolPos = size + 1;
- else
- nextSymbolPos = symbolPosInBuffer[nSym];
- } else if (nBytes == 4)
- O << *(unsigned int *)(&buffer[pos]);
- else
- O << *(unsigned long long *)(&buffer[pos]);
- }
- }
- }
+ void printInBytes();
+ void printInWords();
};
----------------
Nit: `printAsBytes`/ `printAsWords` or just `printBytes/printWords`.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D129773/new/
https://reviews.llvm.org/D129773
More information about the llvm-commits
mailing list