std::ostream and std::string microoptimizations for asm printing.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52929 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2008-06-30 22:03:41 +00:00
parent f4d7708972
commit d19a53ba1d
2 changed files with 137 additions and 137 deletions

View File

@ -66,7 +66,7 @@ void AsmPrinter::SwitchToTextSection(const char *NewSection,
// Close the current section, if applicable. // Close the current section, if applicable.
if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty()) if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty())
O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << "\n"; O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << '\n';
CurrentSection = NS; CurrentSection = NS;
@ -92,7 +92,7 @@ void AsmPrinter::SwitchToDataSection(const char *NewSection,
// Close the current section, if applicable. // Close the current section, if applicable.
if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty()) if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty())
O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << "\n"; O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << '\n';
CurrentSection = NS; CurrentSection = NS;
@ -120,7 +120,7 @@ bool AsmPrinter::doInitialization(Module &M) {
if (!M.getModuleInlineAsm().empty()) if (!M.getModuleInlineAsm().empty())
O << TAI->getCommentString() << " Start of file scope inline assembly\n" O << TAI->getCommentString() << " Start of file scope inline assembly\n"
<< M.getModuleInlineAsm() << M.getModuleInlineAsm()
<< "\n" << TAI->getCommentString() << '\n' << TAI->getCommentString()
<< " End of file scope inline assembly\n"; << " End of file scope inline assembly\n";
SwitchToDataSection(""); // Reset back to no section. SwitchToDataSection(""); // Reset back to no section.
@ -140,7 +140,7 @@ bool AsmPrinter::doFinalization(Module &M) {
e = ExtWeakSymbols.end(); i != e; ++i) { e = ExtWeakSymbols.end(); i != e; ++i) {
const GlobalValue *GV = *i; const GlobalValue *GV = *i;
std::string Name = Mang->getValueName(GV); std::string Name = Mang->getValueName(GV);
O << TAI->getWeakRefDirective() << Name << "\n"; O << TAI->getWeakRefDirective() << Name << '\n';
} }
} }
@ -148,7 +148,7 @@ bool AsmPrinter::doFinalization(Module &M) {
if (!M.alias_empty()) if (!M.alias_empty())
SwitchToTextSection(TAI->getTextSection()); SwitchToTextSection(TAI->getTextSection());
O << "\n"; O << '\n';
for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end(); for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
I!=E; ++I) { I!=E; ++I) {
std::string Name = Mang->getValueName(I); std::string Name = Mang->getValueName(I);
@ -158,30 +158,30 @@ bool AsmPrinter::doFinalization(Module &M) {
Target = Mang->getValueName(GV); Target = Mang->getValueName(GV);
if (I->hasExternalLinkage() || !TAI->getWeakRefDirective()) if (I->hasExternalLinkage() || !TAI->getWeakRefDirective())
O << "\t.globl\t" << Name << "\n"; O << "\t.globl\t" << Name << '\n';
else if (I->hasWeakLinkage()) else if (I->hasWeakLinkage())
O << TAI->getWeakRefDirective() << Name << "\n"; O << TAI->getWeakRefDirective() << Name << '\n';
else if (!I->hasInternalLinkage()) else if (!I->hasInternalLinkage())
assert(0 && "Invalid alias linkage"); assert(0 && "Invalid alias linkage");
if (I->hasHiddenVisibility()) { if (I->hasHiddenVisibility()) {
if (const char *Directive = TAI->getHiddenDirective()) if (const char *Directive = TAI->getHiddenDirective())
O << Directive << Name << "\n"; O << Directive << Name << '\n';
} else if (I->hasProtectedVisibility()) { } else if (I->hasProtectedVisibility()) {
if (const char *Directive = TAI->getProtectedDirective()) if (const char *Directive = TAI->getProtectedDirective())
O << Directive << Name << "\n"; O << Directive << Name << '\n';
} }
O << TAI->getSetDirective() << ' ' << Name << ", " << Target << "\n"; O << TAI->getSetDirective() << ' ' << Name << ", " << Target << '\n';
// If the aliasee has external weak linkage it can be referenced only by // If the aliasee has external weak linkage it can be referenced only by
// alias itself. In this case it can be not in ExtWeakSymbols list. Emit // alias itself. In this case it can be not in ExtWeakSymbols list. Emit
// weak reference in such case. // weak reference in such case.
if (GV->hasExternalWeakLinkage()) { if (GV->hasExternalWeakLinkage()) {
if (TAI->getWeakRefDirective()) if (TAI->getWeakRefDirective())
O << TAI->getWeakRefDirective() << Target << "\n"; O << TAI->getWeakRefDirective() << Target << '\n';
else else
O << "\t.globl\t" << Target << "\n"; O << "\t.globl\t" << Target << '\n';
} }
} }
} }
@ -197,7 +197,7 @@ bool AsmPrinter::doFinalization(Module &M) {
Function* InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline"); Function* InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty()) if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty())
if (TAI->getNonexecutableStackDirective()) if (TAI->getNonexecutableStackDirective())
O << TAI->getNonexecutableStackDirective() << "\n"; O << TAI->getNonexecutableStackDirective() << '\n';
delete Mang; Mang = 0; delete Mang; Mang = 0;
return false; return false;
@ -265,7 +265,7 @@ void AsmPrinter::EmitConstantPool(unsigned Alignment, const char *Section,
EmitAlignment(Alignment); EmitAlignment(Alignment);
for (unsigned i = 0, e = CP.size(); i != e; ++i) { for (unsigned i = 0, e = CP.size(); i != e; ++i) {
O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_' O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
<< CP[i].second << ":\t\t\t\t\t" << TAI->getCommentString() << " "; << CP[i].second << ":\t\t\t\t\t" << TAI->getCommentString() << ' ';
WriteTypeSymbolic(O, CP[i].first.getType(), 0) << '\n'; WriteTypeSymbolic(O, CP[i].first.getType(), 0) << '\n';
if (CP[i].first.isMachineConstantPoolEntry()) if (CP[i].first.isMachineConstantPoolEntry())
EmitMachineConstantPoolValue(CP[i].first.Val.MachineCPVal); EmitMachineConstantPoolValue(CP[i].first.Val.MachineCPVal);
@ -429,7 +429,7 @@ void AsmPrinter::EmitLLVMUsedList(Constant *List) {
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) { for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
O << Directive; O << Directive;
EmitConstantValueOnly(InitList->getOperand(i)); EmitConstantValueOnly(InitList->getOperand(i));
O << "\n"; O << '\n';
} }
} }
@ -549,16 +549,16 @@ void AsmPrinter::PrintHex(int Value) const {
/// EOL - Print a newline character to asm stream. If a comment is present /// EOL - Print a newline character to asm stream. If a comment is present
/// then it will be printed first. Comments should not contain '\n'. /// then it will be printed first. Comments should not contain '\n'.
void AsmPrinter::EOL() const { void AsmPrinter::EOL() const {
O << "\n"; O << '\n';
} }
void AsmPrinter::EOL(const std::string &Comment) const { void AsmPrinter::EOL(const std::string &Comment) const {
if (AsmVerbose && !Comment.empty()) { if (AsmVerbose && !Comment.empty()) {
O << "\t" O << '\t'
<< TAI->getCommentString() << TAI->getCommentString()
<< " " << ' '
<< Comment; << Comment;
} }
O << "\n"; O << '\n';
} }
/// EmitULEB128Bytes - Emit an assembler byte data directive to compose an /// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
@ -614,10 +614,10 @@ void AsmPrinter::EmitInt64(uint64_t Value) const {
PrintHex(Value); PrintHex(Value);
} else { } else {
if (TM.getTargetData()->isBigEndian()) { if (TM.getTargetData()->isBigEndian()) {
EmitInt32(unsigned(Value >> 32)); O << "\n"; EmitInt32(unsigned(Value >> 32)); O << '\n';
EmitInt32(unsigned(Value)); EmitInt32(unsigned(Value));
} else { } else {
EmitInt32(unsigned(Value)); O << "\n"; EmitInt32(unsigned(Value)); O << '\n';
EmitInt32(unsigned(Value >> 32)); EmitInt32(unsigned(Value >> 32));
} }
} }
@ -664,13 +664,13 @@ void AsmPrinter::EmitString(const std::string &String) const {
O << AscizDirective; O << AscizDirective;
else else
O << TAI->getAsciiDirective(); O << TAI->getAsciiDirective();
O << "\""; O << '\"';
for (unsigned i = 0, N = String.size(); i < N; ++i) { for (unsigned i = 0, N = String.size(); i < N; ++i) {
unsigned char C = String[i]; unsigned char C = String[i];
printStringChar(O, C); printStringChar(O, C);
} }
if (AscizDirective) if (AscizDirective)
O << "\""; O << '\"';
else else
O << "\\0\""; O << "\\0\"";
} }
@ -683,7 +683,7 @@ void AsmPrinter::EmitFile(unsigned Number, const std::string &Name) const {
unsigned char C = Name[i]; unsigned char C = Name[i];
printStringChar(O, C); printStringChar(O, C);
} }
O << "\""; O << '\"';
} }
@ -716,7 +716,7 @@ void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV,
unsigned FillValue = TAI->getTextAlignFillValue(); unsigned FillValue = TAI->getTextAlignFillValue();
UseFillExpr &= IsInTextSection && FillValue; UseFillExpr &= IsInTextSection && FillValue;
if (UseFillExpr) O << ",0x" << std::hex << FillValue << std::dec; if (UseFillExpr) O << ",0x" << std::hex << FillValue << std::dec;
O << "\n"; O << '\n';
} }
@ -728,7 +728,7 @@ void AsmPrinter::EmitZeros(uint64_t NumZeros) const {
O << TAI->getZeroDirective() << NumZeros; O << TAI->getZeroDirective() << NumZeros;
if (TAI->getZeroDirectiveSuffix()) if (TAI->getZeroDirectiveSuffix())
O << TAI->getZeroDirectiveSuffix(); O << TAI->getZeroDirectiveSuffix();
O << "\n"; O << '\n';
} else { } else {
for (; NumZeros; --NumZeros) for (; NumZeros; --NumZeros)
O << TAI->getData8bitsDirective() << "0\n"; O << TAI->getData8bitsDirective() << "0\n";
@ -740,7 +740,7 @@ void AsmPrinter::EmitZeros(uint64_t NumZeros) const {
// constants valid in constant expressions can occur here. // constants valid in constant expressions can occur here.
void AsmPrinter::EmitConstantValueOnly(const Constant *CV) { void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
if (CV->isNullValue() || isa<UndefValue>(CV)) if (CV->isNullValue() || isa<UndefValue>(CV))
O << "0"; O << '0';
else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
O << CI->getZExtValue(); O << CI->getZExtValue();
} else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) { } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
@ -768,7 +768,7 @@ void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
if (int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), &idxVec[0], if (int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), &idxVec[0],
idxVec.size())) { idxVec.size())) {
if (Offset) if (Offset)
O << "("; O << '(';
EmitConstantValueOnly(ptrVal); EmitConstantValueOnly(ptrVal);
if (Offset > 0) if (Offset > 0)
O << ") + " << Offset; O << ") + " << Offset;
@ -823,9 +823,9 @@ void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
case Instruction::And: case Instruction::And:
case Instruction::Or: case Instruction::Or:
case Instruction::Xor: case Instruction::Xor:
O << "("; O << '(';
EmitConstantValueOnly(CE->getOperand(0)); EmitConstantValueOnly(CE->getOperand(0));
O << ")"; O << ')';
switch (Opcode) { switch (Opcode) {
case Instruction::Add: case Instruction::Add:
O << " + "; O << " + ";
@ -845,9 +845,9 @@ void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
default: default:
break; break;
} }
O << "("; O << '(';
EmitConstantValueOnly(CE->getOperand(1)); EmitConstantValueOnly(CE->getOperand(1));
O << ")"; O << ')';
break; break;
default: default:
assert(0 && "Unsupported operator!"); assert(0 && "Unsupported operator!");
@ -864,13 +864,13 @@ static void printAsCString(std::ostream &O, const ConstantArray *CVA,
unsigned LastElt) { unsigned LastElt) {
assert(CVA->isString() && "Array is not string compatible!"); assert(CVA->isString() && "Array is not string compatible!");
O << "\""; O << '\"';
for (unsigned i = 0; i != LastElt; ++i) { for (unsigned i = 0; i != LastElt; ++i) {
unsigned char C = unsigned char C =
(unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getZExtValue(); (unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getZExtValue();
printStringChar(O, C); printStringChar(O, C);
} }
O << "\""; O << '\"';
} }
/// EmitString - Emit a zero-byte-terminated string constant. /// EmitString - Emit a zero-byte-terminated string constant.
@ -885,7 +885,7 @@ void AsmPrinter::EmitString(const ConstantArray *CVA) const {
O << TAI->getAsciiDirective(); O << TAI->getAsciiDirective();
printAsCString(O, CVA, NumElts); printAsCString(O, CVA, NumElts);
} }
O << "\n"; O << '\n';
} }
/// EmitGlobalConstant - Print a general LLVM constant to the .s file. /// EmitGlobalConstant - Print a general LLVM constant to the .s file.
@ -935,29 +935,29 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
double Val = CFP->getValueAPF().convertToDouble(); // for comment only double Val = CFP->getValueAPF().convertToDouble(); // for comment only
uint64_t i = CFP->getValueAPF().convertToAPInt().getZExtValue(); uint64_t i = CFP->getValueAPF().convertToAPInt().getZExtValue();
if (TAI->getData64bitsDirective()) if (TAI->getData64bitsDirective())
O << TAI->getData64bitsDirective() << i << "\t" O << TAI->getData64bitsDirective() << i << '\t'
<< TAI->getCommentString() << " double value: " << Val << "\n"; << TAI->getCommentString() << " double value: " << Val << '\n';
else if (TD->isBigEndian()) { else if (TD->isBigEndian()) {
O << TAI->getData32bitsDirective() << unsigned(i >> 32) O << TAI->getData32bitsDirective() << unsigned(i >> 32)
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " double most significant word " << Val << "\n"; << " double most significant word " << Val << '\n';
O << TAI->getData32bitsDirective() << unsigned(i) O << TAI->getData32bitsDirective() << unsigned(i)
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " double least significant word " << Val << "\n"; << " double least significant word " << Val << '\n';
} else { } else {
O << TAI->getData32bitsDirective() << unsigned(i) O << TAI->getData32bitsDirective() << unsigned(i)
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " double least significant word " << Val << "\n"; << " double least significant word " << Val << '\n';
O << TAI->getData32bitsDirective() << unsigned(i >> 32) O << TAI->getData32bitsDirective() << unsigned(i >> 32)
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " double most significant word " << Val << "\n"; << " double most significant word " << Val << '\n';
} }
return; return;
} else if (CFP->getType() == Type::FloatTy) { } else if (CFP->getType() == Type::FloatTy) {
float Val = CFP->getValueAPF().convertToFloat(); // for comment only float Val = CFP->getValueAPF().convertToFloat(); // for comment only
O << TAI->getData32bitsDirective() O << TAI->getData32bitsDirective()
<< CFP->getValueAPF().convertToAPInt().getZExtValue() << CFP->getValueAPF().convertToAPInt().getZExtValue()
<< "\t" << TAI->getCommentString() << " float " << Val << "\n"; << '\t' << TAI->getCommentString() << " float " << Val << '\n';
return; return;
} else if (CFP->getType() == Type::X86_FP80Ty) { } else if (CFP->getType() == Type::X86_FP80Ty) {
// all long double variants are printed as hex // all long double variants are printed as hex
@ -968,37 +968,37 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
DoubleVal.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven); DoubleVal.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven);
if (TD->isBigEndian()) { if (TD->isBigEndian()) {
O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 48) O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 48)
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " long double most significant halfword of ~" << " long double most significant halfword of ~"
<< DoubleVal.convertToDouble() << "\n"; << DoubleVal.convertToDouble() << '\n';
O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 32) O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 32)
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " long double next halfword\n"; << " long double next halfword\n";
O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 16) O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 16)
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " long double next halfword\n"; << " long double next halfword\n";
O << TAI->getData16bitsDirective() << uint16_t(p[0]) O << TAI->getData16bitsDirective() << uint16_t(p[0])
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " long double next halfword\n"; << " long double next halfword\n";
O << TAI->getData16bitsDirective() << uint16_t(p[1]) O << TAI->getData16bitsDirective() << uint16_t(p[1])
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " long double least significant halfword\n"; << " long double least significant halfword\n";
} else { } else {
O << TAI->getData16bitsDirective() << uint16_t(p[1]) O << TAI->getData16bitsDirective() << uint16_t(p[1])
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " long double least significant halfword of ~" << " long double least significant halfword of ~"
<< DoubleVal.convertToDouble() << "\n"; << DoubleVal.convertToDouble() << '\n';
O << TAI->getData16bitsDirective() << uint16_t(p[0]) O << TAI->getData16bitsDirective() << uint16_t(p[0])
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " long double next halfword\n"; << " long double next halfword\n";
O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 16) O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 16)
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " long double next halfword\n"; << " long double next halfword\n";
O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 32) O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 32)
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " long double next halfword\n"; << " long double next halfword\n";
O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 48) O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 48)
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " long double most significant halfword\n"; << " long double most significant halfword\n";
} }
EmitZeros(Size - TD->getTypeStoreSize(Type::X86_FP80Ty)); EmitZeros(Size - TD->getTypeStoreSize(Type::X86_FP80Ty));
@ -1010,29 +1010,29 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
const uint64_t *p = api.getRawData(); const uint64_t *p = api.getRawData();
if (TD->isBigEndian()) { if (TD->isBigEndian()) {
O << TAI->getData32bitsDirective() << uint32_t(p[0] >> 32) O << TAI->getData32bitsDirective() << uint32_t(p[0] >> 32)
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " long double most significant word\n"; << " long double most significant word\n";
O << TAI->getData32bitsDirective() << uint32_t(p[0]) O << TAI->getData32bitsDirective() << uint32_t(p[0])
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " long double next word\n"; << " long double next word\n";
O << TAI->getData32bitsDirective() << uint32_t(p[1] >> 32) O << TAI->getData32bitsDirective() << uint32_t(p[1] >> 32)
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " long double next word\n"; << " long double next word\n";
O << TAI->getData32bitsDirective() << uint32_t(p[1]) O << TAI->getData32bitsDirective() << uint32_t(p[1])
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " long double least significant word\n"; << " long double least significant word\n";
} else { } else {
O << TAI->getData32bitsDirective() << uint32_t(p[1]) O << TAI->getData32bitsDirective() << uint32_t(p[1])
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " long double least significant word\n"; << " long double least significant word\n";
O << TAI->getData32bitsDirective() << uint32_t(p[1] >> 32) O << TAI->getData32bitsDirective() << uint32_t(p[1] >> 32)
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " long double next word\n"; << " long double next word\n";
O << TAI->getData32bitsDirective() << uint32_t(p[0]) O << TAI->getData32bitsDirective() << uint32_t(p[0])
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " long double next word\n"; << " long double next word\n";
O << TAI->getData32bitsDirective() << uint32_t(p[0] >> 32) O << TAI->getData32bitsDirective() << uint32_t(p[0] >> 32)
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " long double most significant word\n"; << " long double most significant word\n";
} }
return; return;
@ -1042,21 +1042,21 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
uint64_t Val = CI->getZExtValue(); uint64_t Val = CI->getZExtValue();
if (TAI->getData64bitsDirective()) if (TAI->getData64bitsDirective())
O << TAI->getData64bitsDirective() << Val << "\n"; O << TAI->getData64bitsDirective() << Val << '\n';
else if (TD->isBigEndian()) { else if (TD->isBigEndian()) {
O << TAI->getData32bitsDirective() << unsigned(Val >> 32) O << TAI->getData32bitsDirective() << unsigned(Val >> 32)
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " Double-word most significant word " << Val << "\n"; << " Double-word most significant word " << Val << '\n';
O << TAI->getData32bitsDirective() << unsigned(Val) O << TAI->getData32bitsDirective() << unsigned(Val)
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " Double-word least significant word " << Val << "\n"; << " Double-word least significant word " << Val << '\n';
} else { } else {
O << TAI->getData32bitsDirective() << unsigned(Val) O << TAI->getData32bitsDirective() << unsigned(Val)
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " Double-word least significant word " << Val << "\n"; << " Double-word least significant word " << Val << '\n';
O << TAI->getData32bitsDirective() << unsigned(Val >> 32) O << TAI->getData32bitsDirective() << unsigned(Val >> 32)
<< "\t" << TAI->getCommentString() << '\t' << TAI->getCommentString()
<< " Double-word most significant word " << Val << "\n"; << " Double-word most significant word " << Val << '\n';
} }
return; return;
} }
@ -1077,7 +1077,7 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
<< TAI->getCommentString() << TAI->getCommentString()
<< " 0x" << CI->getValue().toStringUnsigned(16); << " 0x" << CI->getValue().toStringUnsigned(16);
} }
O << "\n"; O << '\n';
} }
void void
@ -1141,7 +1141,7 @@ void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
// If this asmstr is empty, just print the #APP/#NOAPP markers. // If this asmstr is empty, just print the #APP/#NOAPP markers.
// These are useful to see where empty asm's wound up. // These are useful to see where empty asm's wound up.
if (AsmStr[0] == 0) { if (AsmStr[0] == 0) {
O << TAI->getInlineAsmStart() << "\n\t" << TAI->getInlineAsmEnd() << "\n"; O << TAI->getInlineAsmStart() << "\n\t" << TAI->getInlineAsmEnd() << '\n';
return; return;
} }
@ -1168,7 +1168,7 @@ void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
} }
case '\n': case '\n':
++LastEmitted; // Consume newline character. ++LastEmitted; // Consume newline character.
O << "\n"; // Indent code with newline. O << '\n'; // Indent code with newline.
break; break;
case '$': { case '$': {
++LastEmitted; // Consume '$' character. ++LastEmitted; // Consume '$' character.
@ -1305,14 +1305,14 @@ void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
} }
} }
} }
O << "\n\t" << TAI->getInlineAsmEnd() << "\n"; O << "\n\t" << TAI->getInlineAsmEnd() << '\n';
} }
/// printImplicitDef - This method prints the specified machine instruction /// printImplicitDef - This method prints the specified machine instruction
/// that is an implicit def. /// that is an implicit def.
void AsmPrinter::printImplicitDef(const MachineInstr *MI) const { void AsmPrinter::printImplicitDef(const MachineInstr *MI) const {
O << "\t" << TAI->getCommentString() << " implicit-def: " O << '\t' << TAI->getCommentString() << " implicit-def: "
<< TRI->getAsmName(MI->getOperand(0).getReg()) << "\n"; << TRI->getAsmName(MI->getOperand(0).getReg()) << '\n';
} }
/// printLabel - This method prints a local label used by debug and /// printLabel - This method prints a local label used by debug and
@ -1364,7 +1364,7 @@ void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
EmitAlignment(Log2_32(Align)); EmitAlignment(Log2_32(Align));
} }
O << TAI->getPrivateGlobalPrefix() << "BB" << getFunctionNumber() << "_" O << TAI->getPrivateGlobalPrefix() << "BB" << getFunctionNumber() << '_'
<< MBB->getNumber(); << MBB->getNumber();
if (printColon) if (printColon)
O << ':'; O << ':';
@ -1440,8 +1440,8 @@ void AsmPrinter::printDataDirective(const Type *type) {
void AsmPrinter::printSuffixedName(std::string &Name, const char* Suffix) { void AsmPrinter::printSuffixedName(std::string &Name, const char* Suffix) {
if (Name[0]=='\"') if (Name[0]=='\"')
O << "\"" << TAI->getPrivateGlobalPrefix() << O << '\"' << TAI->getPrivateGlobalPrefix() <<
Name.substr(1, Name.length()-2) << Suffix << "\""; Name.substr(1, Name.length()-2) << Suffix << '\"';
else else
O << TAI->getPrivateGlobalPrefix() << Name << Suffix; O << TAI->getPrivateGlobalPrefix() << Name << Suffix;
} }

View File

@ -41,7 +41,7 @@ static std::string getPICLabelString(unsigned FnNum,
if (Subtarget->isTargetDarwin()) if (Subtarget->isTargetDarwin())
label = "\"L" + utostr_32(FnNum) + "$pb\""; label = "\"L" + utostr_32(FnNum) + "$pb\"";
else if (Subtarget->isTargetELF()) else if (Subtarget->isTargetELF())
label = ".Lllvm$" + utostr_32(FnNum) + "." + "$piclabel"; label = ".Lllvm$" + utostr_32(FnNum) + "." "$piclabel";
else else
assert(0 && "Don't know how to print PIC label!\n"); assert(0 && "Don't know how to print PIC label!\n");
@ -183,28 +183,28 @@ void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
case Function::DLLExportLinkage: case Function::DLLExportLinkage:
case Function::ExternalLinkage: case Function::ExternalLinkage:
EmitAlignment(FnAlign, F); EmitAlignment(FnAlign, F);
O << "\t.globl\t" << CurrentFnName << "\n"; O << "\t.globl\t" << CurrentFnName << '\n';
break; break;
case Function::LinkOnceLinkage: case Function::LinkOnceLinkage:
case Function::WeakLinkage: case Function::WeakLinkage:
EmitAlignment(FnAlign, F); EmitAlignment(FnAlign, F);
if (Subtarget->isTargetDarwin()) { if (Subtarget->isTargetDarwin()) {
O << "\t.globl\t" << CurrentFnName << "\n"; O << "\t.globl\t" << CurrentFnName << '\n';
O << TAI->getWeakDefDirective() << CurrentFnName << "\n"; O << TAI->getWeakDefDirective() << CurrentFnName << '\n';
} else if (Subtarget->isTargetCygMing()) { } else if (Subtarget->isTargetCygMing()) {
O << "\t.globl\t" << CurrentFnName << "\n"; O << "\t.globl\t" << CurrentFnName << "\n"
O << "\t.linkonce discard\n"; "\t.linkonce discard\n";
} else { } else {
O << "\t.weak\t" << CurrentFnName << "\n"; O << "\t.weak\t" << CurrentFnName << '\n';
} }
break; break;
} }
if (F->hasHiddenVisibility()) { if (F->hasHiddenVisibility()) {
if (const char *Directive = TAI->getHiddenDirective()) if (const char *Directive = TAI->getHiddenDirective())
O << Directive << CurrentFnName << "\n"; O << Directive << CurrentFnName << '\n';
} else if (F->hasProtectedVisibility()) { } else if (F->hasProtectedVisibility()) {
if (const char *Directive = TAI->getProtectedDirective()) if (const char *Directive = TAI->getProtectedDirective())
O << Directive << CurrentFnName << "\n"; O << Directive << CurrentFnName << '\n';
} }
if (Subtarget->isTargetELF()) if (Subtarget->isTargetELF())
@ -287,7 +287,7 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
} }
if (TAI->hasDotTypeDotSizeDirective()) if (TAI->hasDotTypeDotSizeDirective())
O << "\t.size\t" << CurrentFnName << ", .-" << CurrentFnName << "\n"; O << "\t.size\t" << CurrentFnName << ", .-" << CurrentFnName << '\n';
// Emit post-function debug information. // Emit post-function debug information.
if (TAI->doesSupportDebugInformation()) if (TAI->doesSupportDebugInformation())
@ -345,7 +345,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
case MachineOperand::MO_JumpTableIndex: { case MachineOperand::MO_JumpTableIndex: {
bool isMemOp = Modifier && !strcmp(Modifier, "mem"); bool isMemOp = Modifier && !strcmp(Modifier, "mem");
if (!isMemOp) O << '$'; if (!isMemOp) O << '$';
O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() << "_" O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() << '_'
<< MO.getIndex(); << MO.getIndex();
if (TM.getRelocationModel() == Reloc::PIC_) { if (TM.getRelocationModel() == Reloc::PIC_) {
@ -363,7 +363,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
case MachineOperand::MO_ConstantPoolIndex: { case MachineOperand::MO_ConstantPoolIndex: {
bool isMemOp = Modifier && !strcmp(Modifier, "mem"); bool isMemOp = Modifier && !strcmp(Modifier, "mem");
if (!isMemOp) O << '$'; if (!isMemOp) O << '$';
O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_" O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
<< MO.getIndex(); << MO.getIndex();
if (TM.getRelocationModel() == Reloc::PIC_) { if (TM.getRelocationModel() == Reloc::PIC_) {
@ -376,7 +376,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
int Offset = MO.getOffset(); int Offset = MO.getOffset();
if (Offset > 0) if (Offset > 0)
O << "+" << Offset; O << '+' << Offset;
else if (Offset < 0) else if (Offset < 0)
O << Offset; O << Offset;
@ -459,7 +459,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
int Offset = MO.getOffset(); int Offset = MO.getOffset();
if (Offset > 0) if (Offset > 0)
O << "+" << Offset; O << '+' << Offset;
else if (Offset < 0) else if (Offset < 0)
O << Offset; O << Offset;
@ -532,7 +532,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
// popl %some_register // popl %some_register
// addl $_GLOBAL_ADDRESS_TABLE_ + [.-piclabel], %some_register // addl $_GLOBAL_ADDRESS_TABLE_ + [.-piclabel], %some_register
O << " + [.-" O << " + [.-"
<< getPICLabelString(getFunctionNumber(), TAI, Subtarget) << "]"; << getPICLabelString(getFunctionNumber(), TAI, Subtarget) << ']';
if (isCallOp) if (isCallOp)
O << "@PLT"; O << "@PLT";
@ -597,17 +597,17 @@ void X86ATTAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op,
std::swap(BaseRegOperand, IndexRegOperand); std::swap(BaseRegOperand, IndexRegOperand);
} }
O << "("; O << '(';
if (BaseReg.getReg()) if (BaseReg.getReg())
printOperand(MI, Op+BaseRegOperand, Modifier); printOperand(MI, Op+BaseRegOperand, Modifier);
if (IndexReg.getReg()) { if (IndexReg.getReg()) {
O << ","; O << ',';
printOperand(MI, Op+IndexRegOperand, Modifier); printOperand(MI, Op+IndexRegOperand, Modifier);
if (ScaleVal != 1) if (ScaleVal != 1)
O << "," << ScaleVal; O << ',' << ScaleVal;
} }
O << ")"; O << ')';
} }
} }
@ -632,7 +632,7 @@ void X86ATTAsmPrinter::printPICJumpTableSetLabel(unsigned uid,
void X86ATTAsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) { void X86ATTAsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) {
std::string label = getPICLabelString(getFunctionNumber(), TAI, Subtarget); std::string label = getPICLabelString(getFunctionNumber(), TAI, Subtarget);
O << label << "\n" << label << ":"; O << label << '\n' << label << ':';
} }
@ -795,10 +795,10 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
if (GVar->hasHiddenVisibility()) { if (GVar->hasHiddenVisibility()) {
if (const char *Directive = TAI->getHiddenDirective()) if (const char *Directive = TAI->getHiddenDirective())
O << Directive << name << "\n"; O << Directive << name << '\n';
} else if (GVar->hasProtectedVisibility()) { } else if (GVar->hasProtectedVisibility()) {
if (const char *Directive = TAI->getProtectedDirective()) if (const char *Directive = TAI->getProtectedDirective())
O << Directive << name << "\n"; O << Directive << name << '\n';
} }
if (Subtarget->isTargetELF()) if (Subtarget->isTargetELF())
@ -807,9 +807,9 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
if (C->isNullValue() && !GVar->hasSection()) { if (C->isNullValue() && !GVar->hasSection()) {
if (GVar->hasExternalLinkage()) { if (GVar->hasExternalLinkage()) {
if (const char *Directive = TAI->getZeroFillDirective()) { if (const char *Directive = TAI->getZeroFillDirective()) {
O << "\t.globl " << name << "\n"; O << "\t.globl " << name << '\n';
O << Directive << "__DATA, __common, " << name << ", " O << Directive << "__DATA, __common, " << name << ", "
<< Size << ", " << Align << "\n"; << Size << ", " << Align << '\n';
return; return;
} }
} }
@ -824,38 +824,38 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
SwitchToDataSection(TAI->getDataSection(), GVar); SwitchToDataSection(TAI->getDataSection(), GVar);
if (TAI->getLCOMMDirective() != NULL) { if (TAI->getLCOMMDirective() != NULL) {
if (GVar->hasInternalLinkage()) { if (GVar->hasInternalLinkage()) {
O << TAI->getLCOMMDirective() << name << "," << Size; O << TAI->getLCOMMDirective() << name << ',' << Size;
if (Subtarget->isTargetDarwin()) if (Subtarget->isTargetDarwin())
O << "," << Align; O << ',' << Align;
} else if (Subtarget->isTargetDarwin() && !GVar->hasCommonLinkage()) { } else if (Subtarget->isTargetDarwin() && !GVar->hasCommonLinkage()) {
O << "\t.globl " << name << "\n" O << "\t.globl " << name << '\n'
<< TAI->getWeakDefDirective() << name << "\n"; << TAI->getWeakDefDirective() << name << '\n';
SwitchToDataSection("\t.section __DATA,__datacoal_nt,coalesced", GVar); SwitchToDataSection("\t.section __DATA,__datacoal_nt,coalesced", GVar);
EmitAlignment(Align, GVar); EmitAlignment(Align, GVar);
O << name << ":\t\t\t\t" << TAI->getCommentString() << " "; O << name << ":\t\t\t\t" << TAI->getCommentString() << ' ';
PrintUnmangledNameSafely(GVar, O); PrintUnmangledNameSafely(GVar, O);
O << "\n"; O << '\n';
EmitGlobalConstant(C); EmitGlobalConstant(C);
return; return;
} else { } else {
O << TAI->getCOMMDirective() << name << "," << Size; O << TAI->getCOMMDirective() << name << ',' << Size;
// Leopard and above support aligned common symbols. // Leopard and above support aligned common symbols.
if (Subtarget->getDarwinVers() >= 9) if (Subtarget->getDarwinVers() >= 9)
O << "," << Align; O << ',' << Align;
} }
} else { } else {
if (!Subtarget->isTargetCygMing()) { if (!Subtarget->isTargetCygMing()) {
if (GVar->hasInternalLinkage()) if (GVar->hasInternalLinkage())
O << "\t.local\t" << name << "\n"; O << "\t.local\t" << name << '\n';
} }
O << TAI->getCOMMDirective() << name << "," << Size; O << TAI->getCOMMDirective() << name << ',' << Size;
if (TAI->getCOMMDirectiveTakesAlignment()) if (TAI->getCOMMDirectiveTakesAlignment())
O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align); O << ',' << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
} }
O << "\t\t" << TAI->getCommentString() << " "; O << "\t\t" << TAI->getCommentString() << ' ';
PrintUnmangledNameSafely(GVar, O); PrintUnmangledNameSafely(GVar, O);
O << "\n"; O << '\n';
return; return;
} }
} }
@ -865,8 +865,8 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
case GlobalValue::LinkOnceLinkage: case GlobalValue::LinkOnceLinkage:
case GlobalValue::WeakLinkage: case GlobalValue::WeakLinkage:
if (Subtarget->isTargetDarwin()) { if (Subtarget->isTargetDarwin()) {
O << "\t.globl " << name << "\n" O << "\t.globl " << name << '\n'
<< TAI->getWeakDefDirective() << name << "\n"; << TAI->getWeakDefDirective() << name << '\n';
if (!GVar->isConstant()) if (!GVar->isConstant())
SwitchToDataSection("\t.section __DATA,__datacoal_nt,coalesced", GVar); SwitchToDataSection("\t.section __DATA,__datacoal_nt,coalesced", GVar);
else { else {
@ -882,13 +882,13 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
",\"aw\""); ",\"aw\"");
SwitchToDataSection(SectionName.c_str(), GVar); SwitchToDataSection(SectionName.c_str(), GVar);
O << "\t.globl\t" << name << "\n" O << "\t.globl\t" << name << "\n"
<< "\t.linkonce same_size\n"; "\t.linkonce same_size\n";
} else { } else {
std::string SectionName("\t.section\t.llvm.linkonce.d." + std::string SectionName("\t.section\t.llvm.linkonce.d." +
name + name +
",\"aw\",@progbits"); ",\"aw\",@progbits");
SwitchToDataSection(SectionName.c_str(), GVar); SwitchToDataSection(SectionName.c_str(), GVar);
O << "\t.weak\t" << name << "\n"; O << "\t.weak\t" << name << '\n';
} }
break; break;
case GlobalValue::DLLExportLinkage: case GlobalValue::DLLExportLinkage:
@ -897,7 +897,7 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
// their name or something. For now, just emit them as external. // their name or something. For now, just emit them as external.
case GlobalValue::ExternalLinkage: case GlobalValue::ExternalLinkage:
// If external or appending, declare as a global symbol // If external or appending, declare as a global symbol
O << "\t.globl " << name << "\n"; O << "\t.globl " << name << '\n';
// FALL THROUGH // FALL THROUGH
case GlobalValue::InternalLinkage: { case GlobalValue::InternalLinkage: {
if (GVar->isConstant()) { if (GVar->isConstant()) {
@ -962,11 +962,11 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
} }
EmitAlignment(Align, GVar); EmitAlignment(Align, GVar);
O << name << ":\t\t\t\t" << TAI->getCommentString() << " "; O << name << ":\t\t\t\t" << TAI->getCommentString() << ' ';
PrintUnmangledNameSafely(GVar, O); PrintUnmangledNameSafely(GVar, O);
O << "\n"; O << '\n';
if (TAI->hasDotTypeDotSizeDirective()) if (TAI->hasDotTypeDotSizeDirective())
O << "\t.size\t" << name << ", " << Size << "\n"; O << "\t.size\t" << name << ", " << Size << '\n';
// If the initializer is a extern weak symbol, remember to emit the weak // If the initializer is a extern weak symbol, remember to emit the weak
// reference! // reference!
@ -1017,12 +1017,12 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) {
"self_modifying_code+pure_instructions,5", 0); "self_modifying_code+pure_instructions,5", 0);
std::string p = i->getKeyData(); std::string p = i->getKeyData();
printSuffixedName(p, "$stub"); printSuffixedName(p, "$stub");
O << ":\n"; O << ":\n"
O << "\t.indirect_symbol " << p << "\n"; "\t.indirect_symbol " << p << "\n"
O << "\thlt ; hlt ; hlt ; hlt ; hlt\n"; "\thlt ; hlt ; hlt ; hlt ; hlt\n";
} }
O << "\n"; O << '\n';
if (TAI->doesSupportExceptionHandling() && MMI && !Subtarget->is64Bit()) { if (TAI->doesSupportExceptionHandling() && MMI && !Subtarget->is64Bit()) {
// Add the (possibly multiple) personalities to the set of global values. // Add the (possibly multiple) personalities to the set of global values.
@ -1031,7 +1031,7 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) {
for (std::vector<Function *>::const_iterator I = Personalities.begin(), for (std::vector<Function *>::const_iterator I = Personalities.begin(),
E = Personalities.end(); I != E; ++I) E = Personalities.end(); I != E; ++I)
if (*I) GVStubs.insert("_" + (*I)->getName()); if (*I) GVStubs.insert('_' + (*I)->getName());
} }
// Output stubs for external and common global variables. // Output stubs for external and common global variables.
@ -1042,9 +1042,9 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) {
i != e; ++i) { i != e; ++i) {
std::string p = i->getKeyData(); std::string p = i->getKeyData();
printSuffixedName(p, "$non_lazy_ptr"); printSuffixedName(p, "$non_lazy_ptr");
O << ":\n"; O << ":\n"
O << "\t.indirect_symbol " << p << "\n"; "\t.indirect_symbol " << p << "\n"
O << "\t.long\t0\n"; "\t.long\t0\n";
} }
// Emit final debug information. // Emit final debug information.