[llvm-commits] [llvm] r130352 - /llvm/trunk/lib/Target/PTX/PTXAsmPrinter.cpp
Justin Holewinski
justin.holewinski at gmail.com
Wed Apr 27 17:19:50 PDT 2011
Author: jholewinski
Date: Wed Apr 27 19:19:50 2011
New Revision: 130352
URL: http://llvm.org/viewvc/llvm-project?rev=130352&view=rev
Log:
PTX: patch to AsmPrinter
- immediate value cast as long not int
- handles initializer for constant array
Patch by Dan Bailey
Modified:
llvm/trunk/lib/Target/PTX/PTXAsmPrinter.cpp
Modified: llvm/trunk/lib/Target/PTX/PTXAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PTX/PTXAsmPrinter.cpp?rev=130352&r1=130351&r2=130352&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PTX/PTXAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PTX/PTXAsmPrinter.cpp Wed Apr 27 19:19:50 2011
@@ -226,7 +226,7 @@
OS << *Mang->getSymbol(MO.getGlobal());
break;
case MachineOperand::MO_Immediate:
- OS << (int) MO.getImm();
+ OS << (long) MO.getImm();
break;
case MachineOperand::MO_MachineBasicBlock:
OS << *MO.getMBB()->getSymbol();
@@ -308,34 +308,59 @@
const PointerType* pointerTy = dyn_cast<const PointerType>(gv->getType());
const Type* elementTy = pointerTy->getElementType();
- assert(elementTy->isArrayTy() && "Only pointers to arrays are supported");
-
- const ArrayType* arrayTy = dyn_cast<const ArrayType>(elementTy);
- elementTy = arrayTy->getElementType();
+ decl += ".b8 ";
+ decl += gvsym->getName();
+ decl += "[";
+
+ if (elementTy->isArrayTy())
+ {
+ assert(elementTy->isArrayTy() && "Only pointers to arrays are supported");
- unsigned numElements = arrayTy->getNumElements();
+ const ArrayType* arrayTy = dyn_cast<const ArrayType>(elementTy);
+ elementTy = arrayTy->getElementType();
- while (elementTy->isArrayTy()) {
+ unsigned numElements = arrayTy->getNumElements();
+
+ while (elementTy->isArrayTy()) {
- arrayTy = dyn_cast<const ArrayType>(elementTy);
- elementTy = arrayTy->getElementType();
+ arrayTy = dyn_cast<const ArrayType>(elementTy);
+ elementTy = arrayTy->getElementType();
- numElements *= arrayTy->getNumElements();
- }
+ numElements *= arrayTy->getNumElements();
+ }
- // FIXME: isPrimitiveType() == false for i16?
- assert(elementTy->isSingleValueType() &&
- "Non-primitive types are not handled");
-
- // Compute the size of the array, in bytes.
- uint64_t arraySize = (elementTy->getPrimitiveSizeInBits() >> 3)
- * numElements;
+ // FIXME: isPrimitiveType() == false for i16?
+ assert(elementTy->isSingleValueType() &&
+ "Non-primitive types are not handled");
- decl += ".b8 ";
- decl += gvsym->getName();
- decl += "[";
- decl += utostr(arraySize);
+ // Compute the size of the array, in bytes.
+ uint64_t arraySize = (elementTy->getPrimitiveSizeInBits() >> 3)
+ * numElements;
+
+ decl += utostr(arraySize);
+ }
+
decl += "]";
+
+ // handle string constants (assume ConstantArray means string)
+
+ if (gv->hasInitializer())
+ {
+ Constant *C = gv->getInitializer();
+ if (const ConstantArray *CA = dyn_cast<ConstantArray>(C))
+ {
+ decl += " = {";
+
+ for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i)
+ {
+ if (i > 0) decl += ",";
+
+ decl += "0x" + utohexstr(cast<ConstantInt>(CA->getOperand(i))->getZExtValue());
+ }
+
+ decl += "}";
+ }
+ }
}
else {
// Note: this is currently the fall-through case and most likely generates
More information about the llvm-commits
mailing list