1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

Internalize functions from various tools. NFC

And internalize some classes if I noticed them:)
This commit is contained in:
Fangrui Song 2020-09-26 15:57:09 -07:00
parent 366a2adebc
commit 4e56e25d41
15 changed files with 57 additions and 60 deletions

View File

@ -83,7 +83,7 @@ static bool canSafelyConvertTo16Bit(Value &V) {
} }
// Convert a value to 16-bit. // 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(); Type *VTy = V.getType();
if (isa<FPExtInst>(&V) || isa<SExtInst>(&V) || isa<ZExtInst>(&V)) if (isa<FPExtInst>(&V) || isa<SExtInst>(&V) || isa<ZExtInst>(&V))
return cast<Instruction>(&V)->getOperand(0); return cast<Instruction>(&V)->getOperand(0);

View File

@ -125,7 +125,7 @@ MODIFIERS:
[V] - display the version and exit [V] - display the version and exit
)"; )";
void printHelpMessage() { static void printHelpMessage() {
if (Stem.contains_lower("ranlib")) if (Stem.contains_lower("ranlib"))
outs() << RanlibHelp; outs() << RanlibHelp;
else if (Stem.contains_lower("ar")) else if (Stem.contains_lower("ar"))

View File

@ -60,7 +60,7 @@ cl::opt<bool> Summarize("summarize", cl::desc("Print the summary only."),
ExitOnError ExitOnErr; ExitOnError ExitOnErr;
void printBlameContext(const DILineInfo &LineInfo, unsigned Context) { static void printBlameContext(const DILineInfo &LineInfo, unsigned Context) {
auto FileOrErr = MemoryBuffer::getFile(LineInfo.FileName); auto FileOrErr = MemoryBuffer::getFile(LineInfo.FileName);
if (!FileOrErr) { if (!FileOrErr) {
errs() << "Could not open file: " << LineInfo.FileName << "\n"; errs() << "Could not open file: " << LineInfo.FileName << "\n";
@ -84,7 +84,7 @@ void printBlameContext(const DILineInfo &LineInfo, unsigned Context) {
} }
} }
void printInstructionInformation(const FileAnalysis &Analysis, static void printInstructionInformation(const FileAnalysis &Analysis,
const Instr &InstrMeta, const Instr &InstrMeta,
const GraphResult &Graph, const GraphResult &Graph,
CFIProtectionStatus ProtectionStatus) { CFIProtectionStatus ProtectionStatus) {
@ -97,7 +97,7 @@ void printInstructionInformation(const FileAnalysis &Analysis,
Graph.printToDOT(Analysis, outs()); Graph.printToDOT(Analysis, outs());
} }
void printInstructionStatus(unsigned BlameLine, bool CFIProtected, static void printInstructionStatus(unsigned BlameLine, bool CFIProtected,
const DILineInfo &LineInfo) { const DILineInfo &LineInfo) {
if (BlameLine) { if (BlameLine) {
outs() << "Blacklist Match: " << BlacklistFilename << ":" << BlameLine outs() << "Blacklist Match: " << BlacklistFilename << ":" << BlameLine
@ -122,7 +122,8 @@ void printInstructionStatus(unsigned BlameLine, bool CFIProtected,
} }
} }
void printIndirectCFInstructions(FileAnalysis &Analysis, static void
printIndirectCFInstructions(FileAnalysis &Analysis,
const SpecialCaseList *SpecialCaseList) { const SpecialCaseList *SpecialCaseList) {
uint64_t ExpectedProtected = 0; uint64_t ExpectedProtected = 0;
uint64_t UnexpectedProtected = 0; uint64_t UnexpectedProtected = 0;

View File

@ -67,7 +67,7 @@ public:
}; };
} }
LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg) { static LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg) {
errs() << Msg; errs() << Msg;
exit(1); exit(1);
} }
@ -76,13 +76,7 @@ static void reportError(StringRef Input, std::error_code EC) {
reportError(Twine(Input) + ": " + EC.message() + ".\n"); reportError(Twine(Input) + ": " + EC.message() + ".\n");
} }
void error(std::error_code EC) { static void error(Error EC) {
if (!EC)
return;
reportError(EC.message() + ".\n");
}
void error(Error EC) {
if (!EC) if (!EC)
return; return;
handleAllErrors(std::move(EC), handleAllErrors(std::move(EC),

View File

@ -377,7 +377,8 @@ writeIndex(MCStreamer &Out, MCSection *Section,
&DWARFUnitIndex::Entry::SectionContribution::Length); &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 = "\'"; std::string Text = "\'";
Text += Name; Text += Name;
Text += '\''; Text += '\'';

View File

@ -62,7 +62,7 @@ enum class IFSSymbolType {
Unknown = 16, Unknown = 16,
}; };
std::string getTypeName(IFSSymbolType Type) { static std::string getTypeName(IFSSymbolType Type) {
switch (Type) { switch (Type) {
case IFSSymbolType::NoType: case IFSSymbolType::NoType:
return "NoType"; return "NoType";
@ -213,7 +213,7 @@ static Expected<std::unique_ptr<IFSStub>> readInputFile(StringRef FilePath) {
return std::move(Stub); return std::move(Stub);
} }
int writeTbdStub(const llvm::Triple &T, const std::vector<IFSSymbol> &Symbols, static int writeTbdStub(const Triple &T, const std::vector<IFSSymbol> &Symbols,
const StringRef Format, raw_ostream &Out) { const StringRef Format, raw_ostream &Out) {
auto PlatformKindOrError = auto PlatformKindOrError =
@ -275,7 +275,7 @@ int writeTbdStub(const llvm::Triple &T, const std::vector<IFSSymbol> &Symbols,
return 0; return 0;
} }
int writeElfStub(const llvm::Triple &T, const std::vector<IFSSymbol> &Symbols, static int writeElfStub(const Triple &T, const std::vector<IFSSymbol> &Symbols,
const StringRef Format, raw_ostream &Out) { const StringRef Format, raw_ostream &Out) {
SmallString<0> Storage; SmallString<0> Storage;
Storage.clear(); Storage.clear();
@ -358,7 +358,7 @@ int writeElfStub(const llvm::Triple &T, const std::vector<IFSSymbol> &Symbols,
return convertYAML(YIn, Out, ErrHandler) ? 0 : 1; 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) { if (IsWriteIfs) {
yaml::Output YamlOut(Out, NULL, /*WrapColumn =*/0); yaml::Output YamlOut(Out, NULL, /*WrapColumn =*/0);
YamlOut << const_cast<IFSStub &>(Stub); YamlOut << const_cast<IFSStub &>(Stub);

View File

@ -770,7 +770,7 @@ Session::findSymbolInfo(StringRef SymbolName, Twine ErrorMsgStem) {
} // end namespace llvm } // end namespace llvm
Triple getFirstFileTriple() { static Triple getFirstFileTriple() {
assert(!InputFiles.empty() && "InputFiles can not be empty"); assert(!InputFiles.empty() && "InputFiles can not be empty");
auto ObjBuffer = auto ObjBuffer =
ExitOnErr(errorOrToExpected(MemoryBuffer::getFile(InputFiles.front()))); ExitOnErr(errorOrToExpected(MemoryBuffer::getFile(InputFiles.front())));
@ -779,7 +779,7 @@ Triple getFirstFileTriple() {
return Obj->makeTriple(); return Obj->makeTriple();
} }
Error sanitizeArguments(const Session &S) { static Error sanitizeArguments(const Session &S) {
if (EntryPointName.empty()) { if (EntryPointName.empty()) {
if (S.TPC->getTargetTriple().getObjectFormat() == Triple::MachO) if (S.TPC->getTargetTriple().getObjectFormat() == Triple::MachO)
EntryPointName = "_main"; EntryPointName = "_main";
@ -801,7 +801,7 @@ Error sanitizeArguments(const Session &S) {
return Error::success(); return Error::success();
} }
Error loadProcessSymbols(Session &S) { static Error loadProcessSymbols(Session &S) {
auto InternedEntryPointName = S.ES.intern(EntryPointName); auto InternedEntryPointName = S.ES.intern(EntryPointName);
auto FilterMainEntryPoint = [InternedEntryPointName](SymbolStringPtr Name) { auto FilterMainEntryPoint = [InternedEntryPointName](SymbolStringPtr Name) {
return Name != InternedEntryPointName; return Name != InternedEntryPointName;
@ -813,7 +813,7 @@ Error loadProcessSymbols(Session &S) {
return Error::success(); return Error::success();
} }
Error loadDylibs() { static Error loadDylibs() {
// FIXME: This should all be handled inside DynamicLibrary. // FIXME: This should all be handled inside DynamicLibrary.
for (const auto &Dylib : Dylibs) { for (const auto &Dylib : Dylibs) {
if (!sys::fs::is_regular_file(Dylib)) if (!sys::fs::is_regular_file(Dylib))
@ -827,12 +827,11 @@ Error loadDylibs() {
return Error::success(); return Error::success();
} }
void addPhonyExternalsGenerator(Session &S) { static void addPhonyExternalsGenerator(Session &S) {
S.MainJD->addGenerator(std::make_unique<PhonyExternalsGenerator>()); S.MainJD->addGenerator(std::make_unique<PhonyExternalsGenerator>());
} }
Error loadObjects(Session &S) { static Error loadObjects(Session &S) {
std::map<unsigned, JITDylib *> IdxToJLD; std::map<unsigned, JITDylib *> IdxToJLD;
// First, set up JITDylibs. // First, set up JITDylibs.
@ -941,7 +940,7 @@ Error loadObjects(Session &S) {
return Error::success(); return Error::success();
} }
Error runChecks(Session &S) { static Error runChecks(Session &S) {
auto TripleName = S.TPC->getTargetTriple().str(); auto TripleName = S.TPC->getTargetTriple().str();
std::string ErrorStr; std::string ErrorStr;
@ -1036,12 +1035,14 @@ static Expected<JITEvaluatedSymbol> getMainEntryPoint(Session &S) {
return S.ES.lookup(S.JDSearchOrder, EntryPointName); return S.ES.lookup(S.JDSearchOrder, EntryPointName);
} }
namespace {
struct JITLinkTimers { struct JITLinkTimers {
TimerGroup JITLinkTG{"llvm-jitlink timers", "timers for llvm-jitlink phases"}; TimerGroup JITLinkTG{"llvm-jitlink timers", "timers for llvm-jitlink phases"};
Timer LoadObjectsTimer{"load", "time to load/add object files", JITLinkTG}; Timer LoadObjectsTimer{"load", "time to load/add object files", JITLinkTG};
Timer LinkTimer{"link", "time to link object files", JITLinkTG}; Timer LinkTimer{"link", "time to link object files", JITLinkTG};
Timer RunTimer{"run", "time to execute jitlink'd code", JITLinkTG}; Timer RunTimer{"run", "time to execute jitlink'd code", JITLinkTG};
}; };
} // namespace
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
InitLLVM X(argc, argv); InitLLVM X(argc, argv);

View File

@ -337,7 +337,7 @@ getLocalLTOModule(StringRef Path, std::unique_ptr<MemoryBuffer> &Buffer,
} }
/// Print some statistics on the index for each input files. /// Print some statistics on the index for each input files.
void printIndexStats() { static void printIndexStats() {
for (auto &Filename : InputFilenames) { for (auto &Filename : InputFilenames) {
ExitOnError ExitOnErr("llvm-lto: error loading file '" + Filename + "': "); ExitOnError ExitOnErr("llvm-lto: error loading file '" + Filename + "': ");
std::unique_ptr<ModuleSummaryIndex> Index = std::unique_ptr<ModuleSummaryIndex> Index =

View File

@ -64,7 +64,7 @@ public:
}; };
} // namespace } // namespace
LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg) { LLVM_ATTRIBUTE_NORETURN static void reportError(Twine Msg) {
WithColor::error(errs(), "llvm-mt") << Msg << '\n'; WithColor::error(errs(), "llvm-mt") << Msg << '\n';
exit(1); exit(1);
} }
@ -73,12 +73,7 @@ static void reportError(StringRef Input, std::error_code EC) {
reportError(Twine(Input) + ": " + EC.message()); reportError(Twine(Input) + ": " + EC.message());
} }
void error(std::error_code EC) { static void error(Error EC) {
if (EC)
reportError(EC.message());
}
void error(Error EC) {
if (EC) if (EC)
handleAllErrors(std::move(EC), [&](const ErrorInfoBase &EI) { handleAllErrors(std::move(EC), [&](const ErrorInfoBase &EI) {
reportError(EI.message()); reportError(EI.message());

View File

@ -252,12 +252,14 @@ private:
/// maintain an index of unique functions, and provide a means of iterating /// maintain an index of unique functions, and provide a means of iterating
/// through all the instrumented call stacks which we know about. /// through all the instrumented call stacks which we know about.
namespace {
struct StackDuration { struct StackDuration {
llvm::SmallVector<int64_t, 4> TerminalDurations; llvm::SmallVector<int64_t, 4> TerminalDurations;
llvm::SmallVector<int64_t, 4> IntermediateDurations; llvm::SmallVector<int64_t, 4> IntermediateDurations;
}; };
} // namespace
StackDuration mergeStackDuration(const StackDuration &Left, static StackDuration mergeStackDuration(const StackDuration &Left,
const StackDuration &Right) { const StackDuration &Right) {
StackDuration Data{}; StackDuration Data{};
Data.TerminalDurations.reserve(Left.TerminalDurations.size() + Data.TerminalDurations.reserve(Left.TerminalDurations.size() +
@ -280,7 +282,7 @@ StackDuration mergeStackDuration(const StackDuration &Left,
using StackTrieNode = TrieNode<StackDuration>; using StackTrieNode = TrieNode<StackDuration>;
template <AggregationType AggType> template <AggregationType AggType>
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 // 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. // its callees and the timings from when it was a leaf.
@ -669,7 +671,7 @@ public:
} }
}; };
std::string CreateErrorMessage(StackTrie::AccountRecordStatus Error, static std::string CreateErrorMessage(StackTrie::AccountRecordStatus Error,
const XRayRecord &Record, const XRayRecord &Record,
const FuncIdConversionHelper &Converter) { const FuncIdConversionHelper &Converter) {
switch (Error) { switch (Error) {

View File

@ -446,8 +446,8 @@ static TargetMachine* GetTargetMachine(Triple TheTriple, StringRef CPUStr,
void initializeExampleIRTransforms(llvm::PassRegistry &Registry); void initializeExampleIRTransforms(llvm::PassRegistry &Registry);
#endif #endif
static void exportDebugifyStats(llvm::StringRef Path,
void exportDebugifyStats(llvm::StringRef Path, const DebugifyStatsMap &Map) { const DebugifyStatsMap &Map) {
std::error_code EC; std::error_code EC;
raw_fd_ostream OS{Path, EC}; raw_fd_ostream OS{Path, EC};
if (EC) { if (EC) {

View File

@ -36,7 +36,7 @@ inline uint64_t CountFromData(uint64_t Data, char SizeofPtr) {
return Data & ((1ull << (SizeofPtr * 8 - kSanitizerStatKindBits)) - 1); 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; uint64_t Result = 0;
char Pos = 0; char Pos = 0;
while (Begin < End && Pos != Size) { while (Begin < End && Pos != Size) {
@ -47,7 +47,8 @@ uint64_t ReadLE(char Size, const char *Begin, const char *End) {
return Result; 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; const char *FilenameBegin = Begin;
while (Begin != End && *Begin) while (Begin != End && *Begin)
++Begin; ++Begin;

View File

@ -324,7 +324,7 @@ struct InputAnnotation {
}; };
/// Get an abbreviation for the check type. /// Get an abbreviation for the check type.
std::string GetCheckTypeAbbreviation(Check::FileCheckType Ty) { static std::string GetCheckTypeAbbreviation(Check::FileCheckType Ty) {
switch (Ty) { switch (Ty) {
case Check::CheckPlain: case Check::CheckPlain:
if (Ty.getCount() > 1) if (Ty.getCount() > 1)

View File

@ -356,7 +356,7 @@ EmitRegUnitPressure(raw_ostream &OS, const CodeGenRegBank &RegBank,
using DwarfRegNumsMapPair = std::pair<Record*, std::vector<int64_t>>; using DwarfRegNumsMapPair = std::pair<Record*, std::vector<int64_t>>;
using DwarfRegNumsVecTy = std::vector<DwarfRegNumsMapPair>; using DwarfRegNumsVecTy = std::vector<DwarfRegNumsMapPair>;
void finalizeDwarfRegNumsKeys(DwarfRegNumsVecTy &DwarfRegNums) { static void finalizeDwarfRegNumsKeys(DwarfRegNumsVecTy &DwarfRegNums) {
// Sort and unique to get a map-like vector. We want the last assignment to // Sort and unique to get a map-like vector. We want the last assignment to
// match previous behaviour. // match previous behaviour.
std::stable_sort(DwarfRegNums.begin(), DwarfRegNums.end(), std::stable_sort(DwarfRegNums.begin(), DwarfRegNums.end(),

View File

@ -1507,7 +1507,8 @@ static void emitPredicates(const CodeGenSchedTransition &T,
// Used by method `SubtargetEmitter::emitSchedModelHelpersImpl()` to generate // Used by method `SubtargetEmitter::emitSchedModelHelpersImpl()` to generate
// epilogue code for the auto-generated helper. // epilogue code for the auto-generated helper.
void emitSchedModelHelperEpilogue(raw_ostream &OS, bool ShouldReturnZero) { static void emitSchedModelHelperEpilogue(raw_ostream &OS,
bool ShouldReturnZero) {
if (ShouldReturnZero) { if (ShouldReturnZero) {
OS << " // Don't know how to resolve this scheduling class.\n" OS << " // Don't know how to resolve this scheduling class.\n"
<< " return 0;\n"; << " return 0;\n";
@ -1517,13 +1518,13 @@ void emitSchedModelHelperEpilogue(raw_ostream &OS, bool ShouldReturnZero) {
OS << " report_fatal_error(\"Expected a variant SchedClass\");\n"; 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 all_of(T.PredTerm, [](const Record *Rec) {
return Rec->isSubClassOf("MCSchedPredicate"); return Rec->isSubClassOf("MCSchedPredicate");
}); });
} }
void collectVariantClasses(const CodeGenSchedModels &SchedModels, static void collectVariantClasses(const CodeGenSchedModels &SchedModels,
IdxVec &VariantClasses, IdxVec &VariantClasses,
bool OnlyExpandMCInstPredicates) { bool OnlyExpandMCInstPredicates) {
for (const CodeGenSchedClass &SC : SchedModels.schedClasses()) { for (const CodeGenSchedClass &SC : SchedModels.schedClasses()) {
@ -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 // A variant scheduling class may define transitions for multiple
// processors. This function identifies wich processors are associated with // processors. This function identifies wich processors are associated with
// transition rules specified by variant class `SC`. // transition rules specified by variant class `SC`.