From 4e56e25d41b7f4307ab294a7e61e84098863395b Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 26 Sep 2020 15:57:09 -0700 Subject: [PATCH] Internalize functions from various tools. NFC And internalize some classes if I noticed them:) --- .../AMDGPU/AMDGPUInstCombineIntrinsic.cpp | 2 +- tools/llvm-ar/llvm-ar.cpp | 2 +- tools/llvm-cfi-verify/llvm-cfi-verify.cpp | 19 ++++++++++--------- tools/llvm-cvtres/llvm-cvtres.cpp | 10 ++-------- tools/llvm-dwp/llvm-dwp.cpp | 3 ++- tools/llvm-ifs/llvm-ifs.cpp | 12 ++++++------ tools/llvm-jitlink/llvm-jitlink.cpp | 17 +++++++++-------- tools/llvm-lto/llvm-lto.cpp | 2 +- tools/llvm-mt/llvm-mt.cpp | 9 ++------- tools/llvm-xray/xray-stacks.cpp | 14 ++++++++------ tools/opt/opt.cpp | 4 ++-- tools/sanstats/sanstats.cpp | 5 +++-- utils/FileCheck/FileCheck.cpp | 2 +- utils/TableGen/RegisterInfoEmitter.cpp | 2 +- utils/TableGen/SubtargetEmitter.cpp | 14 ++++++++------ 15 files changed, 57 insertions(+), 60 deletions(-) diff --git a/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp b/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp index 209f9325365..4b2624350b7 100644 --- a/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp +++ b/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp @@ -83,7 +83,7 @@ static bool canSafelyConvertTo16Bit(Value &V) { } // Convert a value to 16-bit. -Value *convertTo16Bit(Value &V, InstCombiner::BuilderTy &Builder) { +static Value *convertTo16Bit(Value &V, InstCombiner::BuilderTy &Builder) { Type *VTy = V.getType(); if (isa(&V) || isa(&V) || isa(&V)) return cast(&V)->getOperand(0); diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index d699d4323f0..4c26c8cad3f 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -125,7 +125,7 @@ MODIFIERS: [V] - display the version and exit )"; -void printHelpMessage() { +static void printHelpMessage() { if (Stem.contains_lower("ranlib")) outs() << RanlibHelp; else if (Stem.contains_lower("ar")) diff --git a/tools/llvm-cfi-verify/llvm-cfi-verify.cpp b/tools/llvm-cfi-verify/llvm-cfi-verify.cpp index 79bf63af5f4..1331442bc65 100644 --- a/tools/llvm-cfi-verify/llvm-cfi-verify.cpp +++ b/tools/llvm-cfi-verify/llvm-cfi-verify.cpp @@ -60,7 +60,7 @@ cl::opt Summarize("summarize", cl::desc("Print the summary only."), ExitOnError ExitOnErr; -void printBlameContext(const DILineInfo &LineInfo, unsigned Context) { +static void printBlameContext(const DILineInfo &LineInfo, unsigned Context) { auto FileOrErr = MemoryBuffer::getFile(LineInfo.FileName); if (!FileOrErr) { errs() << "Could not open file: " << LineInfo.FileName << "\n"; @@ -84,10 +84,10 @@ void printBlameContext(const DILineInfo &LineInfo, unsigned Context) { } } -void printInstructionInformation(const FileAnalysis &Analysis, - const Instr &InstrMeta, - const GraphResult &Graph, - CFIProtectionStatus ProtectionStatus) { +static void printInstructionInformation(const FileAnalysis &Analysis, + const Instr &InstrMeta, + const GraphResult &Graph, + CFIProtectionStatus ProtectionStatus) { outs() << "Instruction: " << format_hex(InstrMeta.VMAddress, 2) << " (" << stringCFIProtectionStatus(ProtectionStatus) << "): "; Analysis.printInstruction(InstrMeta, outs()); @@ -97,8 +97,8 @@ void printInstructionInformation(const FileAnalysis &Analysis, Graph.printToDOT(Analysis, outs()); } -void printInstructionStatus(unsigned BlameLine, bool CFIProtected, - const DILineInfo &LineInfo) { +static void printInstructionStatus(unsigned BlameLine, bool CFIProtected, + const DILineInfo &LineInfo) { if (BlameLine) { outs() << "Blacklist Match: " << BlacklistFilename << ":" << BlameLine << "\n"; @@ -122,8 +122,9 @@ void printInstructionStatus(unsigned BlameLine, bool CFIProtected, } } -void printIndirectCFInstructions(FileAnalysis &Analysis, - const SpecialCaseList *SpecialCaseList) { +static void +printIndirectCFInstructions(FileAnalysis &Analysis, + const SpecialCaseList *SpecialCaseList) { uint64_t ExpectedProtected = 0; uint64_t UnexpectedProtected = 0; uint64_t ExpectedUnprotected = 0; diff --git a/tools/llvm-cvtres/llvm-cvtres.cpp b/tools/llvm-cvtres/llvm-cvtres.cpp index 1322da47a70..2991485a57c 100644 --- a/tools/llvm-cvtres/llvm-cvtres.cpp +++ b/tools/llvm-cvtres/llvm-cvtres.cpp @@ -67,7 +67,7 @@ public: }; } -LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg) { +static LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg) { errs() << Msg; exit(1); } @@ -76,13 +76,7 @@ static void reportError(StringRef Input, std::error_code EC) { reportError(Twine(Input) + ": " + EC.message() + ".\n"); } -void error(std::error_code EC) { - if (!EC) - return; - reportError(EC.message() + ".\n"); -} - -void error(Error EC) { +static void error(Error EC) { if (!EC) return; handleAllErrors(std::move(EC), diff --git a/tools/llvm-dwp/llvm-dwp.cpp b/tools/llvm-dwp/llvm-dwp.cpp index d5ebe5ab0a5..7bd7575dab4 100644 --- a/tools/llvm-dwp/llvm-dwp.cpp +++ b/tools/llvm-dwp/llvm-dwp.cpp @@ -377,7 +377,8 @@ writeIndex(MCStreamer &Out, MCSection *Section, &DWARFUnitIndex::Entry::SectionContribution::Length); } -std::string buildDWODescription(StringRef Name, StringRef DWPName, StringRef DWOName) { +static std::string buildDWODescription(StringRef Name, StringRef DWPName, + StringRef DWOName) { std::string Text = "\'"; Text += Name; Text += '\''; diff --git a/tools/llvm-ifs/llvm-ifs.cpp b/tools/llvm-ifs/llvm-ifs.cpp index 0d1a7518dad..eb18be21976 100644 --- a/tools/llvm-ifs/llvm-ifs.cpp +++ b/tools/llvm-ifs/llvm-ifs.cpp @@ -62,7 +62,7 @@ enum class IFSSymbolType { Unknown = 16, }; -std::string getTypeName(IFSSymbolType Type) { +static std::string getTypeName(IFSSymbolType Type) { switch (Type) { case IFSSymbolType::NoType: return "NoType"; @@ -213,8 +213,8 @@ static Expected> readInputFile(StringRef FilePath) { return std::move(Stub); } -int writeTbdStub(const llvm::Triple &T, const std::vector &Symbols, - const StringRef Format, raw_ostream &Out) { +static int writeTbdStub(const Triple &T, const std::vector &Symbols, + const StringRef Format, raw_ostream &Out) { auto PlatformKindOrError = [](const llvm::Triple &T) -> llvm::Expected { @@ -275,8 +275,8 @@ int writeTbdStub(const llvm::Triple &T, const std::vector &Symbols, return 0; } -int writeElfStub(const llvm::Triple &T, const std::vector &Symbols, - const StringRef Format, raw_ostream &Out) { +static int writeElfStub(const Triple &T, const std::vector &Symbols, + const StringRef Format, raw_ostream &Out) { SmallString<0> Storage; Storage.clear(); raw_svector_ostream OS(Storage); @@ -358,7 +358,7 @@ int writeElfStub(const llvm::Triple &T, const std::vector &Symbols, return convertYAML(YIn, Out, ErrHandler) ? 0 : 1; } -int writeIfso(const IFSStub &Stub, bool IsWriteIfs, raw_ostream &Out) { +static int writeIfso(const IFSStub &Stub, bool IsWriteIfs, raw_ostream &Out) { if (IsWriteIfs) { yaml::Output YamlOut(Out, NULL, /*WrapColumn =*/0); YamlOut << const_cast(Stub); diff --git a/tools/llvm-jitlink/llvm-jitlink.cpp b/tools/llvm-jitlink/llvm-jitlink.cpp index a848bf029db..be3a26c1875 100644 --- a/tools/llvm-jitlink/llvm-jitlink.cpp +++ b/tools/llvm-jitlink/llvm-jitlink.cpp @@ -770,7 +770,7 @@ Session::findSymbolInfo(StringRef SymbolName, Twine ErrorMsgStem) { } // end namespace llvm -Triple getFirstFileTriple() { +static Triple getFirstFileTriple() { assert(!InputFiles.empty() && "InputFiles can not be empty"); auto ObjBuffer = ExitOnErr(errorOrToExpected(MemoryBuffer::getFile(InputFiles.front()))); @@ -779,7 +779,7 @@ Triple getFirstFileTriple() { return Obj->makeTriple(); } -Error sanitizeArguments(const Session &S) { +static Error sanitizeArguments(const Session &S) { if (EntryPointName.empty()) { if (S.TPC->getTargetTriple().getObjectFormat() == Triple::MachO) EntryPointName = "_main"; @@ -801,7 +801,7 @@ Error sanitizeArguments(const Session &S) { return Error::success(); } -Error loadProcessSymbols(Session &S) { +static Error loadProcessSymbols(Session &S) { auto InternedEntryPointName = S.ES.intern(EntryPointName); auto FilterMainEntryPoint = [InternedEntryPointName](SymbolStringPtr Name) { return Name != InternedEntryPointName; @@ -813,7 +813,7 @@ Error loadProcessSymbols(Session &S) { return Error::success(); } -Error loadDylibs() { +static Error loadDylibs() { // FIXME: This should all be handled inside DynamicLibrary. for (const auto &Dylib : Dylibs) { if (!sys::fs::is_regular_file(Dylib)) @@ -827,12 +827,11 @@ Error loadDylibs() { return Error::success(); } -void addPhonyExternalsGenerator(Session &S) { +static void addPhonyExternalsGenerator(Session &S) { S.MainJD->addGenerator(std::make_unique()); } -Error loadObjects(Session &S) { - +static Error loadObjects(Session &S) { std::map IdxToJLD; // First, set up JITDylibs. @@ -941,7 +940,7 @@ Error loadObjects(Session &S) { return Error::success(); } -Error runChecks(Session &S) { +static Error runChecks(Session &S) { auto TripleName = S.TPC->getTargetTriple().str(); std::string ErrorStr; @@ -1036,12 +1035,14 @@ static Expected getMainEntryPoint(Session &S) { return S.ES.lookup(S.JDSearchOrder, EntryPointName); } +namespace { struct JITLinkTimers { TimerGroup JITLinkTG{"llvm-jitlink timers", "timers for llvm-jitlink phases"}; Timer LoadObjectsTimer{"load", "time to load/add object files", JITLinkTG}; Timer LinkTimer{"link", "time to link object files", JITLinkTG}; Timer RunTimer{"run", "time to execute jitlink'd code", JITLinkTG}; }; +} // namespace int main(int argc, char *argv[]) { InitLLVM X(argc, argv); diff --git a/tools/llvm-lto/llvm-lto.cpp b/tools/llvm-lto/llvm-lto.cpp index d56cd30cca1..164254756f4 100644 --- a/tools/llvm-lto/llvm-lto.cpp +++ b/tools/llvm-lto/llvm-lto.cpp @@ -337,7 +337,7 @@ getLocalLTOModule(StringRef Path, std::unique_ptr &Buffer, } /// Print some statistics on the index for each input files. -void printIndexStats() { +static void printIndexStats() { for (auto &Filename : InputFilenames) { ExitOnError ExitOnErr("llvm-lto: error loading file '" + Filename + "': "); std::unique_ptr Index = diff --git a/tools/llvm-mt/llvm-mt.cpp b/tools/llvm-mt/llvm-mt.cpp index cac9b878abb..997e5acbe23 100644 --- a/tools/llvm-mt/llvm-mt.cpp +++ b/tools/llvm-mt/llvm-mt.cpp @@ -64,7 +64,7 @@ public: }; } // namespace -LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg) { +LLVM_ATTRIBUTE_NORETURN static void reportError(Twine Msg) { WithColor::error(errs(), "llvm-mt") << Msg << '\n'; exit(1); } @@ -73,12 +73,7 @@ static void reportError(StringRef Input, std::error_code EC) { reportError(Twine(Input) + ": " + EC.message()); } -void error(std::error_code EC) { - if (EC) - reportError(EC.message()); -} - -void error(Error EC) { +static void error(Error EC) { if (EC) handleAllErrors(std::move(EC), [&](const ErrorInfoBase &EI) { reportError(EI.message()); diff --git a/tools/llvm-xray/xray-stacks.cpp b/tools/llvm-xray/xray-stacks.cpp index 1e449028953..185a32439da 100644 --- a/tools/llvm-xray/xray-stacks.cpp +++ b/tools/llvm-xray/xray-stacks.cpp @@ -252,13 +252,15 @@ private: /// maintain an index of unique functions, and provide a means of iterating /// through all the instrumented call stacks which we know about. +namespace { struct StackDuration { llvm::SmallVector TerminalDurations; llvm::SmallVector IntermediateDurations; }; +} // namespace -StackDuration mergeStackDuration(const StackDuration &Left, - const StackDuration &Right) { +static StackDuration mergeStackDuration(const StackDuration &Left, + const StackDuration &Right) { StackDuration Data{}; Data.TerminalDurations.reserve(Left.TerminalDurations.size() + Right.TerminalDurations.size()); @@ -280,7 +282,7 @@ StackDuration mergeStackDuration(const StackDuration &Left, using StackTrieNode = TrieNode; template -std::size_t GetValueForStack(const StackTrieNode *Node); +static std::size_t GetValueForStack(const StackTrieNode *Node); // When computing total time spent in a stack, we're adding the timings from // its callees and the timings from when it was a leaf. @@ -669,9 +671,9 @@ public: } }; -std::string CreateErrorMessage(StackTrie::AccountRecordStatus Error, - const XRayRecord &Record, - const FuncIdConversionHelper &Converter) { +static std::string CreateErrorMessage(StackTrie::AccountRecordStatus Error, + const XRayRecord &Record, + const FuncIdConversionHelper &Converter) { switch (Error) { case StackTrie::AccountRecordStatus::ENTRY_NOT_FOUND: return std::string( diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index f269437c5f9..9f03606a738 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -446,8 +446,8 @@ static TargetMachine* GetTargetMachine(Triple TheTriple, StringRef CPUStr, void initializeExampleIRTransforms(llvm::PassRegistry &Registry); #endif - -void exportDebugifyStats(llvm::StringRef Path, const DebugifyStatsMap &Map) { +static void exportDebugifyStats(llvm::StringRef Path, + const DebugifyStatsMap &Map) { std::error_code EC; raw_fd_ostream OS{Path, EC}; if (EC) { diff --git a/tools/sanstats/sanstats.cpp b/tools/sanstats/sanstats.cpp index d470a5b5013..1f154e08f24 100644 --- a/tools/sanstats/sanstats.cpp +++ b/tools/sanstats/sanstats.cpp @@ -36,7 +36,7 @@ inline uint64_t CountFromData(uint64_t Data, char SizeofPtr) { return Data & ((1ull << (SizeofPtr * 8 - kSanitizerStatKindBits)) - 1); } -uint64_t ReadLE(char Size, const char *Begin, const char *End) { +static uint64_t ReadLE(char Size, const char *Begin, const char *End) { uint64_t Result = 0; char Pos = 0; while (Begin < End && Pos != Size) { @@ -47,7 +47,8 @@ uint64_t ReadLE(char Size, const char *Begin, const char *End) { return Result; } -const char *ReadModule(char SizeofPtr, const char *Begin, const char *End) { +static const char *ReadModule(char SizeofPtr, const char *Begin, + const char *End) { const char *FilenameBegin = Begin; while (Begin != End && *Begin) ++Begin; diff --git a/utils/FileCheck/FileCheck.cpp b/utils/FileCheck/FileCheck.cpp index 66b0a9776aa..b48ae0b10c9 100644 --- a/utils/FileCheck/FileCheck.cpp +++ b/utils/FileCheck/FileCheck.cpp @@ -324,7 +324,7 @@ struct InputAnnotation { }; /// Get an abbreviation for the check type. -std::string GetCheckTypeAbbreviation(Check::FileCheckType Ty) { +static std::string GetCheckTypeAbbreviation(Check::FileCheckType Ty) { switch (Ty) { case Check::CheckPlain: if (Ty.getCount() > 1) diff --git a/utils/TableGen/RegisterInfoEmitter.cpp b/utils/TableGen/RegisterInfoEmitter.cpp index b30a8b3fa6c..6a4ef1b8fec 100644 --- a/utils/TableGen/RegisterInfoEmitter.cpp +++ b/utils/TableGen/RegisterInfoEmitter.cpp @@ -356,7 +356,7 @@ EmitRegUnitPressure(raw_ostream &OS, const CodeGenRegBank &RegBank, using DwarfRegNumsMapPair = std::pair>; using DwarfRegNumsVecTy = std::vector; -void finalizeDwarfRegNumsKeys(DwarfRegNumsVecTy &DwarfRegNums) { +static void finalizeDwarfRegNumsKeys(DwarfRegNumsVecTy &DwarfRegNums) { // Sort and unique to get a map-like vector. We want the last assignment to // match previous behaviour. std::stable_sort(DwarfRegNums.begin(), DwarfRegNums.end(), diff --git a/utils/TableGen/SubtargetEmitter.cpp b/utils/TableGen/SubtargetEmitter.cpp index 4e70d6ea41b..ae675dbe910 100644 --- a/utils/TableGen/SubtargetEmitter.cpp +++ b/utils/TableGen/SubtargetEmitter.cpp @@ -1507,7 +1507,8 @@ static void emitPredicates(const CodeGenSchedTransition &T, // Used by method `SubtargetEmitter::emitSchedModelHelpersImpl()` to generate // epilogue code for the auto-generated helper. -void emitSchedModelHelperEpilogue(raw_ostream &OS, bool ShouldReturnZero) { +static void emitSchedModelHelperEpilogue(raw_ostream &OS, + bool ShouldReturnZero) { if (ShouldReturnZero) { OS << " // Don't know how to resolve this scheduling class.\n" << " return 0;\n"; @@ -1517,15 +1518,15 @@ void emitSchedModelHelperEpilogue(raw_ostream &OS, bool ShouldReturnZero) { OS << " report_fatal_error(\"Expected a variant SchedClass\");\n"; } -bool hasMCSchedPredicates(const CodeGenSchedTransition &T) { +static bool hasMCSchedPredicates(const CodeGenSchedTransition &T) { return all_of(T.PredTerm, [](const Record *Rec) { return Rec->isSubClassOf("MCSchedPredicate"); }); } -void collectVariantClasses(const CodeGenSchedModels &SchedModels, - IdxVec &VariantClasses, - bool OnlyExpandMCInstPredicates) { +static void collectVariantClasses(const CodeGenSchedModels &SchedModels, + IdxVec &VariantClasses, + bool OnlyExpandMCInstPredicates) { for (const CodeGenSchedClass &SC : SchedModels.schedClasses()) { // Ignore non-variant scheduling classes. if (SC.Transitions.empty()) @@ -1544,7 +1545,8 @@ void collectVariantClasses(const CodeGenSchedModels &SchedModels, } } -void collectProcessorIndices(const CodeGenSchedClass &SC, IdxVec &ProcIndices) { +static void collectProcessorIndices(const CodeGenSchedClass &SC, + IdxVec &ProcIndices) { // A variant scheduling class may define transitions for multiple // processors. This function identifies wich processors are associated with // transition rules specified by variant class `SC`.