From: Evan Cheng Date: Tue, 1 Jul 2008 23:18:29 +0000 (+0000) Subject: Avoid creating expensive comment string if it's not going to be printed. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6547e406cf934346db7a206b61bcf09635afff0d;p=oota-llvm.git Avoid creating expensive comment string if it's not going to be printed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52992 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Target/TargetOptions.h b/include/llvm/Target/TargetOptions.h index ac3a6081edc..a9964f766b1 100644 --- a/include/llvm/Target/TargetOptions.h +++ b/include/llvm/Target/TargetOptions.h @@ -93,6 +93,10 @@ namespace llvm { /// RealignStack - This flag indicates, whether stack should be automatically /// realigned, if needed. extern bool RealignStack; + + /// VerboseAsm - When this flag is set, the asm printer prints additional + /// comments to asm directives. + extern bool VerboseAsm; } // End llvm namespace #endif diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp index 13206633972..35c36719807 100644 --- a/lib/CodeGen/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter.cpp @@ -21,7 +21,6 @@ #include "llvm/CodeGen/MachineConstantPool.h" #include "llvm/CodeGen/MachineJumpTableInfo.h" #include "llvm/CodeGen/MachineModuleInfo.h" -#include "llvm/Support/CommandLine.h" #include "llvm/Support/Mangler.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/Streams.h" @@ -29,14 +28,12 @@ #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetLowering.h" #include "llvm/Target/TargetMachine.h" +#include "llvm/Target/TargetOptions.h" #include "llvm/Target/TargetRegisterInfo.h" #include "llvm/ADT/SmallPtrSet.h" #include using namespace llvm; -static cl::opt -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) @@ -553,7 +550,7 @@ void AsmPrinter::EOL() const { } void AsmPrinter::EOL(const std::string &Comment) const { - if (AsmVerbose && !Comment.empty()) { + if (VerboseAsm && !Comment.empty()) { O << '\t' << TAI->getCommentString() << ' ' @@ -563,7 +560,7 @@ void AsmPrinter::EOL(const std::string &Comment) const { } void AsmPrinter::EOL(const char* Comment) const { - if (AsmVerbose && *Comment) { + if (VerboseAsm && *Comment) { O << '\t' << TAI->getCommentString() << ' ' diff --git a/lib/CodeGen/DwarfWriter.cpp b/lib/CodeGen/DwarfWriter.cpp index a33773904f5..68ec6c49ac3 100644 --- a/lib/CodeGen/DwarfWriter.cpp +++ b/lib/CodeGen/DwarfWriter.cpp @@ -2076,11 +2076,15 @@ private: // Emit the code (index) for the abbreviation. Asm->EmitULEB128Bytes(AbbrevNumber); - Asm->EOL(std::string("Abbrev [" + - utostr(AbbrevNumber) + - "] 0x" + utohexstr(Die->getOffset()) + - ":0x" + utohexstr(Die->getSize()) + " " + - TagString(Abbrev->getTag()))); + + if (VerboseAsm) + Asm->EOL(std::string("Abbrev [" + + utostr(AbbrevNumber) + + "] 0x" + utohexstr(Die->getOffset()) + + ":0x" + utohexstr(Die->getSize()) + " " + + TagString(Abbrev->getTag()))); + else + Asm->EOL(); SmallVector &Values = Die->getValues(); const SmallVector &AbbrevData = Abbrev->getData(); @@ -2297,8 +2301,7 @@ private: Asm->EmitInt8(1); Asm->EOL("DW_LNS_fixed_advance_pc arg count"); const UniqueVector &Directories = MMI->getDirectories(); - const UniqueVector - &SourceFiles = MMI->getSourceFiles(); + const UniqueVector &SourceFiles = MMI->getSourceFiles(); // Emit directories. for (unsigned DirectoryID = 1, NDID = Directories.size(); @@ -2328,8 +2331,11 @@ private: for (unsigned j = 0, M = SectionSourceLines.size(); j < M; ++j) { // Isolate current sections line info. const std::vector &LineInfos = SectionSourceLines[j]; - - Asm->EOL(std::string("Section ") + SectionMap[j + 1]); + + if (VerboseAsm) + Asm->EOL(std::string("Section ") + SectionMap[j + 1]); + else + Asm->EOL(); // Dwarf assumes we start with first line of first source file. unsigned Source = 1; @@ -2344,10 +2350,13 @@ private: unsigned SourceID = LineInfo.getSourceID(); const SourceFileInfo &SourceFile = SourceFiles[SourceID]; unsigned DirectoryID = SourceFile.getDirectoryID(); - Asm->EOL(Directories[DirectoryID] - + SourceFile.getName() - + ":" - + utostr_32(LineInfo.getLine())); + if (VerboseAsm) + Asm->EOL(Directories[DirectoryID] + + SourceFile.getName() + + ":" + + utostr_32(LineInfo.getLine())); + else + Asm->EOL(); // Define the line address. Asm->EmitInt8(0); Asm->EOL("Extended Op"); diff --git a/lib/Target/TargetMachine.cpp b/lib/Target/TargetMachine.cpp index 342aa0175df..0764968b230 100644 --- a/lib/Target/TargetMachine.cpp +++ b/lib/Target/TargetMachine.cpp @@ -36,8 +36,9 @@ namespace llvm { CodeModel::Model CMModel; bool PerformTailCallOpt; bool OptimizeForSize; - bool RealignStack; unsigned StackAlignment; + bool RealignStack; + bool VerboseAsm; } static cl::opt PrintCode("print-machineinstrs", @@ -138,17 +139,23 @@ EnableOptimizeForSize("optimize-size", cl::location(OptimizeForSize), cl::init(false)); +static cl::opt +OverrideStackAlignment("stack-alignment", + cl::desc("Override default stack alignment"), + cl::location(StackAlignment), + cl::init(0)); + static cl::opt EnableRealignStack("realign-stack", cl::desc("Realign stack if needed"), cl::location(RealignStack), cl::init(true)); -static cl::opt -OverrideStackAlignment("stack-alignment", - cl::desc("Override default stack alignment"), - cl::location(StackAlignment), - cl::init(0)); +static cl::opt +AsmVerbose("asm-verbose", cl::desc("Add comments to directives."), + cl::location(VerboseAsm), + cl::init(false)); + //--------------------------------------------------------------------------- // TargetMachine Class