X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FCodeGen%2FAsmPrinter.cpp;h=4ac8026a1b28ab52bc9beacd116019a288e7d56d;hb=ebcba612b537f45a033ccd9a60bee0c45e2e2ded;hp=3439460880755d36f769ae017da5f18701ed4efc;hpb=22c9e65643e0c6b43be37a19e59491ef0081092c;p=oota-llvm.git diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp index 34394608807..4ac8026a1b2 100644 --- a/lib/CodeGen/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter.cpp @@ -29,6 +29,7 @@ #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetLowering.h" #include "llvm/Target/TargetMachine.h" +#include "llvm/Target/TargetRegisterInfo.h" #include "llvm/ADT/SmallPtrSet.h" #include using namespace llvm; @@ -39,7 +40,8 @@ AsmVerbose("asm-verbose", cl::Hidden, cl::desc("Add comments to directives.")); char AsmPrinter::ID = 0; AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm, const TargetAsmInfo *T) - : MachineFunctionPass((intptr_t)&ID), FunctionNumber(0), O(o), TM(tm), TAI(T), + : MachineFunctionPass((intptr_t)&ID), FunctionNumber(0), O(o), + TM(tm), TAI(T), TRI(tm.getRegisterInfo()), IsInTextSection(false) {} @@ -190,14 +192,23 @@ bool AsmPrinter::doFinalization(Module &M) { E = CMM->begin(); I != E; ) (*--I)->finishAssembly(O, *this, *TAI); + // If we don't have any trampolines, then we don't require stack memory + // to be executable. Some targets have a directive to declare this. + Function* InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline"); + if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty()) + if (TAI->getNonexecutableStackDirective()) + O << TAI->getNonexecutableStackDirective() << "\n"; + delete Mang; Mang = 0; return false; } std::string AsmPrinter::getCurrentFunctionEHName(const MachineFunction *MF) { assert(MF && "No machine function?"); - return Mang->makeNameProper(MF->getFunction()->getName() + ".eh", - TAI->getGlobalPrefix()); + std::string Name = MF->getFunction()->getName(); + if (Name.empty()) + Name = Mang->getValueName(MF->getFunction()); + return Mang->makeNameProper(Name + ".eh", TAI->getGlobalPrefix()); } void AsmPrinter::SetupMachineFunction(MachineFunction &MF) { @@ -878,11 +889,9 @@ void AsmPrinter::EmitString(const ConstantArray *CVA) const { } /// EmitGlobalConstant - Print a general LLVM constant to the .s file. -/// If Packed is false, pad to the ABI size. -void AsmPrinter::EmitGlobalConstant(const Constant *CV, bool Packed) { +void AsmPrinter::EmitGlobalConstant(const Constant *CV) { const TargetData *TD = TM.getTargetData(); - unsigned Size = Packed ? - TD->getTypeStoreSize(CV->getType()) : TD->getABITypeSize(CV->getType()); + unsigned Size = TD->getABITypeSize(CV->getType()); if (CV->isNullValue() || isa(CV)) { EmitZeros(Size); @@ -892,7 +901,7 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV, bool Packed) { EmitString(CVA); } else { // Not a string. Print the values in successive locations for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i) - EmitGlobalConstant(CVA->getOperand(i), false); + EmitGlobalConstant(CVA->getOperand(i)); } return; } else if (const ConstantStruct *CVS = dyn_cast(CV)) { @@ -903,13 +912,13 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV, bool Packed) { const Constant* field = CVS->getOperand(i); // Check if padding is needed and insert one or more 0s. - uint64_t fieldSize = TD->getTypeStoreSize(field->getType()); + uint64_t fieldSize = TD->getABITypeSize(field->getType()); uint64_t padSize = ((i == e-1 ? Size : cvsLayout->getElementOffset(i+1)) - cvsLayout->getElementOffset(i)) - fieldSize; sizeSoFar += fieldSize + padSize; - // Now print the actual field value without ABI size padding. - EmitGlobalConstant(field, true); + // Now print the actual field value. + EmitGlobalConstant(field); // Insert padding - this may include padding to increase the size of the // current field up to the ABI size (if the struct is not packed) as well @@ -1055,7 +1064,7 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV, bool Packed) { const VectorType *PTy = CP->getType(); for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I) - EmitGlobalConstant(CP->getOperand(I), false); + EmitGlobalConstant(CP->getOperand(I)); return; } @@ -1063,6 +1072,11 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV, bool Packed) { const Type *type = CV->getType(); printDataDirective(type); EmitConstantValueOnly(CV); + if (const ConstantInt *CI = dyn_cast(CV)) { + O << "\t\t\t" + << TAI->getCommentString() + << " 0x" << CI->getValue().toStringUnsigned(16); + } O << "\n"; } @@ -1294,6 +1308,13 @@ void AsmPrinter::printInlineAsm(const MachineInstr *MI) const { O << "\n\t" << TAI->getInlineAsmEnd() << "\n"; } +/// printImplicitDef - This method prints the specified machine instruction +/// that is an implicit def. +void AsmPrinter::printImplicitDef(const MachineInstr *MI) const { + O << "\t" << TAI->getCommentString() << " implicit-def: " + << TRI->getAsmName(MI->getOperand(0).getReg()) << "\n"; +} + /// printLabel - This method prints a local label used by debug and /// exception handling tables. void AsmPrinter::printLabel(const MachineInstr *MI) const { @@ -1417,3 +1438,10 @@ void AsmPrinter::printDataDirective(const Type *type) { } } +void AsmPrinter::printSuffixedName(std::string &Name, const char* Suffix) { + if (Name[0]=='\"') + O << "\"" << TAI->getPrivateGlobalPrefix() << + Name.substr(1, Name.length()-2) << Suffix << "\""; + else + O << TAI->getPrivateGlobalPrefix() << Name << Suffix; +}