Skip to content

Commit cc863b2

Browse files
committed
Let printf do the formatting instead aligning strings ourselves.
While at it, merge some format strings. llvm-svn: 142140
1 parent cb6b02a commit cc863b2

File tree

5 files changed

+24
-30
lines changed

5 files changed

+24
-30
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6592,7 +6592,7 @@ static void DumpNodesr(raw_ostream &OS, const SDNode *N, unsigned indent,
65926592
return;
65936593

65946594
// Dump the current SDNode, but don't end the line yet.
6595-
OS << std::string(indent, ' ');
6595+
OS.indent(indent);
65966596
N->printr(OS, G);
65976597

65986598
// Having printed this SDNode, walk the children:

llvm/lib/MC/SubtargetFeature.cpp

+10-11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "llvm/MC/SubtargetFeature.h"
1515
#include "llvm/Support/Debug.h"
16+
#include "llvm/Support/Format.h"
1617
#include "llvm/Support/raw_ostream.h"
1718
#include "llvm/ADT/StringExtras.h"
1819
#include <algorithm>
@@ -154,21 +155,19 @@ static void Help(const SubtargetFeatureKV *CPUTable, size_t CPUTableSize,
154155
// Print the CPU table.
155156
errs() << "Available CPUs for this target:\n\n";
156157
for (size_t i = 0; i != CPUTableSize; i++)
157-
errs() << " " << CPUTable[i].Key
158-
<< std::string(MaxCPULen - std::strlen(CPUTable[i].Key), ' ')
159-
<< " - " << CPUTable[i].Desc << ".\n";
160-
errs() << "\n";
161-
158+
errs() << format(" %-*s - %s.\n",
159+
MaxCPULen, CPUTable[i].Key, CPUTable[i].Desc);
160+
errs() << '\n';
161+
162162
// Print the Feature table.
163163
errs() << "Available features for this target:\n\n";
164164
for (size_t i = 0; i != FeatTableSize; i++)
165-
errs() << " " << FeatTable[i].Key
166-
<< std::string(MaxFeatLen - std::strlen(FeatTable[i].Key), ' ')
167-
<< " - " << FeatTable[i].Desc << ".\n";
168-
errs() << "\n";
169-
165+
errs() << format(" %-*s - %s.\n",
166+
MaxFeatLen, FeatTable[i].Key, FeatTable[i].Desc);
167+
errs() << '\n';
168+
170169
errs() << "Use +feature to enable a feature, or -feature to disable it.\n"
171-
<< "For example, llc -mcpu=mycpu -mattr=+feature1,-feature2\n";
170+
"For example, llc -mcpu=mycpu -mattr=+feature1,-feature2\n";
172171
std::exit(1);
173172
}
174173

llvm/lib/Support/Statistic.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "llvm/ADT/Statistic.h"
2525
#include "llvm/Support/CommandLine.h"
2626
#include "llvm/Support/Debug.h"
27+
#include "llvm/Support/Format.h"
2728
#include "llvm/Support/ManagedStatic.h"
2829
#include "llvm/Support/raw_ostream.h"
2930
#include "llvm/Support/Mutex.h"
@@ -126,13 +127,11 @@ void llvm::PrintStatistics(raw_ostream &OS) {
126127
<< "===" << std::string(73, '-') << "===\n\n";
127128

128129
// Print all of the statistics.
129-
for (size_t i = 0, e = Stats.Stats.size(); i != e; ++i) {
130-
std::string CountStr = utostr(Stats.Stats[i]->getValue());
131-
OS << std::string(MaxValLen-CountStr.size(), ' ')
132-
<< CountStr << " " << Stats.Stats[i]->getName()
133-
<< std::string(MaxNameLen-std::strlen(Stats.Stats[i]->getName()), ' ')
134-
<< " - " << Stats.Stats[i]->getDesc() << "\n";
135-
}
130+
for (size_t i = 0, e = Stats.Stats.size(); i != e; ++i)
131+
OS << format("%*u %-*s - %s\n",
132+
MaxValLen, Stats.Stats[i]->getValue(),
133+
MaxNameLen, Stats.Stats[i]->getName(),
134+
Stats.Stats[i]->getDesc());
136135

137136
OS << '\n'; // Flush the output stream.
138137
OS.flush();

llvm/lib/Support/Timer.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,8 @@ void Timer::stopTimer() {
168168
static void printVal(double Val, double Total, raw_ostream &OS) {
169169
if (Total < 1e-7) // Avoid dividing by zero.
170170
OS << " ----- ";
171-
else {
172-
OS << " " << format("%7.4f", Val) << " (";
173-
OS << format("%5.1f", Val*100/Total) << "%)";
174-
}
171+
else
172+
OS << format(" %7.4f (%5.1f%%)", Val, Val*100/Total);
175173
}
176174

177175
void TimeRecord::print(const TimeRecord &Total, raw_ostream &OS) const {
@@ -186,7 +184,7 @@ void TimeRecord::print(const TimeRecord &Total, raw_ostream &OS) const {
186184
OS << " ";
187185

188186
if (Total.getMemUsed())
189-
OS << format("%9lld", (long long)getMemUsed()) << " ";
187+
OS << format("%9lld ", (long long)getMemUsed());
190188
}
191189

192190

@@ -332,11 +330,9 @@ void TimerGroup::PrintQueuedTimers(raw_ostream &OS) {
332330
// If this is not an collection of ungrouped times, print the total time.
333331
// Ungrouped timers don't really make sense to add up. We still print the
334332
// TOTAL line to make the percentages make sense.
335-
if (this != DefaultTimerGroup) {
336-
OS << " Total Execution Time: ";
337-
OS << format("%5.4f", Total.getProcessTime()) << " seconds (";
338-
OS << format("%5.4f", Total.getWallTime()) << " wall clock)\n";
339-
}
333+
if (this != DefaultTimerGroup)
334+
OS << format(" Total Execution Time: %5.4f seconds (%5.4f wall clock)\n",
335+
Total.getProcessTime(), Total.getWallTime());
340336
OS << '\n';
341337

342338
if (Total.getUserTime())

llvm/lib/VMCore/PassManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ bool FunctionPassManagerImpl::run(Function &F) {
14741474
char FPPassManager::ID = 0;
14751475
/// Print passes managed by this manager
14761476
void FPPassManager::dumpPassStructure(unsigned Offset) {
1477-
llvm::dbgs() << std::string(Offset*2, ' ') << "FunctionPass Manager\n";
1477+
dbgs().indent(Offset*2) << "FunctionPass Manager\n";
14781478
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
14791479
FunctionPass *FP = getContainedPass(Index);
14801480
FP->dumpPassStructure(Offset + 1);

0 commit comments

Comments
 (0)