diff options
author | Justin Holewinski <justin.holewinski@gmail.com> | 2011-04-28 00:19:50 +0000 |
---|---|---|
committer | Justin Holewinski <justin.holewinski@gmail.com> | 2011-04-28 00:19:50 +0000 |
commit | 9583a86ba822602e25a8fcc8e9035ac5a4f9ce8c (patch) | |
tree | fb2bf2c0e9d5b165ea72ab3dce164075c6ae42cc /lib/Target/PTX/PTXAsmPrinter.cpp | |
parent | a7707ae19ab5f47d9dffb1d8e07a090e948a1a39 (diff) | |
download | external_llvm-9583a86ba822602e25a8fcc8e9035ac5a4f9ce8c.zip external_llvm-9583a86ba822602e25a8fcc8e9035ac5a4f9ce8c.tar.gz external_llvm-9583a86ba822602e25a8fcc8e9035ac5a4f9ce8c.tar.bz2 |
PTX: patch to AsmPrinter
- immediate value cast as long not int
- handles initializer for constant array
Patch by Dan Bailey
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130352 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/PTX/PTXAsmPrinter.cpp')
-rw-r--r-- | lib/Target/PTX/PTXAsmPrinter.cpp | 69 |
1 files changed, 47 insertions, 22 deletions
diff --git a/lib/Target/PTX/PTXAsmPrinter.cpp b/lib/Target/PTX/PTXAsmPrinter.cpp index 3363c73..29c4781 100644 --- a/lib/Target/PTX/PTXAsmPrinter.cpp +++ b/lib/Target/PTX/PTXAsmPrinter.cpp @@ -226,7 +226,7 @@ void PTXAsmPrinter::printOperand(const MachineInstr *MI, int opNum, 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 @@ void PTXAsmPrinter::EmitVariableDeclaration(const GlobalVariable *gv) { 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(); - - unsigned numElements = arrayTy->getNumElements(); - - while (elementTy->isArrayTy()) { + decl += ".b8 "; + decl += gvsym->getName(); + decl += "["; + + if (elementTy->isArrayTy()) + { + assert(elementTy->isArrayTy() && "Only pointers to arrays are supported"); - arrayTy = dyn_cast<const ArrayType>(elementTy); + const ArrayType* arrayTy = dyn_cast<const ArrayType>(elementTy); elementTy = arrayTy->getElementType(); - numElements *= arrayTy->getNumElements(); - } + unsigned numElements = arrayTy->getNumElements(); + + while (elementTy->isArrayTy()) { + + arrayTy = dyn_cast<const ArrayType>(elementTy); + elementTy = arrayTy->getElementType(); - // FIXME: isPrimitiveType() == false for i16? - assert(elementTy->isSingleValueType() && - "Non-primitive types are not handled"); + numElements *= arrayTy->getNumElements(); + } - // 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 |