Mercurial > hg > CbC > CbC_llvm
comparison clang/lib/Basic/ProfileList.cpp @ 236:c4bab56944e8 llvm-original
LLVM 16
author | kono |
---|---|
date | Wed, 09 Nov 2022 17:45:10 +0900 |
parents | 79ff65ed7e25 |
children | 1f2b6ac9f198 |
comparison
equal
deleted
inserted
replaced
232:70dce7da266c | 236:c4bab56944e8 |
---|---|
56 ProfileSpecialCaseList::createOrDie(const std::vector<std::string> &Paths, | 56 ProfileSpecialCaseList::createOrDie(const std::vector<std::string> &Paths, |
57 llvm::vfs::FileSystem &VFS) { | 57 llvm::vfs::FileSystem &VFS) { |
58 std::string Error; | 58 std::string Error; |
59 if (auto PSCL = create(Paths, VFS, Error)) | 59 if (auto PSCL = create(Paths, VFS, Error)) |
60 return PSCL; | 60 return PSCL; |
61 llvm::report_fatal_error(Error); | 61 llvm::report_fatal_error(llvm::Twine(Error)); |
62 } | 62 } |
63 | 63 |
64 } | 64 } |
65 | 65 |
66 ProfileList::ProfileList(ArrayRef<std::string> Paths, SourceManager &SM) | 66 ProfileList::ProfileList(ArrayRef<std::string> Paths, SourceManager &SM) |
67 : SCL(ProfileSpecialCaseList::createOrDie( | 67 : SCL(ProfileSpecialCaseList::createOrDie( |
68 Paths, SM.getFileManager().getVirtualFileSystem())), | 68 Paths, SM.getFileManager().getVirtualFileSystem())), |
69 Empty(SCL->isEmpty()), | 69 Empty(SCL->isEmpty()), SM(SM) {} |
70 Default(SCL->hasPrefix("fun") || SCL->hasPrefix("src")), SM(SM) {} | |
71 | 70 |
72 ProfileList::~ProfileList() = default; | 71 ProfileList::~ProfileList() = default; |
73 | 72 |
74 static StringRef getSectionName(CodeGenOptions::ProfileInstrKind Kind) { | 73 static StringRef getSectionName(CodeGenOptions::ProfileInstrKind Kind) { |
75 switch (Kind) { | 74 switch (Kind) { |
83 return "csllvm"; | 82 return "csllvm"; |
84 } | 83 } |
85 llvm_unreachable("Unhandled CodeGenOptions::ProfileInstrKind enum"); | 84 llvm_unreachable("Unhandled CodeGenOptions::ProfileInstrKind enum"); |
86 } | 85 } |
87 | 86 |
88 llvm::Optional<bool> | 87 ProfileList::ExclusionType |
88 ProfileList::getDefault(CodeGenOptions::ProfileInstrKind Kind) const { | |
89 StringRef Section = getSectionName(Kind); | |
90 // Check for "default:<type>" | |
91 if (SCL->inSection(Section, "default", "allow")) | |
92 return Allow; | |
93 if (SCL->inSection(Section, "default", "skip")) | |
94 return Skip; | |
95 if (SCL->inSection(Section, "default", "forbid")) | |
96 return Forbid; | |
97 // If any cases use "fun" or "src", set the default to FORBID. | |
98 if (SCL->hasPrefix("fun") || SCL->hasPrefix("src")) | |
99 return Forbid; | |
100 return Allow; | |
101 } | |
102 | |
103 llvm::Optional<ProfileList::ExclusionType> | |
104 ProfileList::inSection(StringRef Section, StringRef Prefix, | |
105 StringRef Query) const { | |
106 if (SCL->inSection(Section, Prefix, Query, "allow")) | |
107 return Allow; | |
108 if (SCL->inSection(Section, Prefix, Query, "skip")) | |
109 return Skip; | |
110 if (SCL->inSection(Section, Prefix, Query, "forbid")) | |
111 return Forbid; | |
112 if (SCL->inSection(Section, Prefix, Query)) | |
113 return Allow; | |
114 return None; | |
115 } | |
116 | |
117 llvm::Optional<ProfileList::ExclusionType> | |
89 ProfileList::isFunctionExcluded(StringRef FunctionName, | 118 ProfileList::isFunctionExcluded(StringRef FunctionName, |
90 CodeGenOptions::ProfileInstrKind Kind) const { | 119 CodeGenOptions::ProfileInstrKind Kind) const { |
91 StringRef Section = getSectionName(Kind); | 120 StringRef Section = getSectionName(Kind); |
121 // Check for "function:<regex>=<case>" | |
122 if (auto V = inSection(Section, "function", FunctionName)) | |
123 return V; | |
92 if (SCL->inSection(Section, "!fun", FunctionName)) | 124 if (SCL->inSection(Section, "!fun", FunctionName)) |
93 return true; | 125 return Forbid; |
94 if (SCL->inSection(Section, "fun", FunctionName)) | 126 if (SCL->inSection(Section, "fun", FunctionName)) |
95 return false; | 127 return Allow; |
96 return None; | 128 return None; |
97 } | 129 } |
98 | 130 |
99 llvm::Optional<bool> | 131 llvm::Optional<ProfileList::ExclusionType> |
100 ProfileList::isLocationExcluded(SourceLocation Loc, | 132 ProfileList::isLocationExcluded(SourceLocation Loc, |
101 CodeGenOptions::ProfileInstrKind Kind) const { | 133 CodeGenOptions::ProfileInstrKind Kind) const { |
102 return isFileExcluded(SM.getFilename(SM.getFileLoc(Loc)), Kind); | 134 return isFileExcluded(SM.getFilename(SM.getFileLoc(Loc)), Kind); |
103 } | 135 } |
104 | 136 |
105 llvm::Optional<bool> | 137 llvm::Optional<ProfileList::ExclusionType> |
106 ProfileList::isFileExcluded(StringRef FileName, | 138 ProfileList::isFileExcluded(StringRef FileName, |
107 CodeGenOptions::ProfileInstrKind Kind) const { | 139 CodeGenOptions::ProfileInstrKind Kind) const { |
108 StringRef Section = getSectionName(Kind); | 140 StringRef Section = getSectionName(Kind); |
141 // Check for "source:<regex>=<case>" | |
142 if (auto V = inSection(Section, "source", FileName)) | |
143 return V; | |
109 if (SCL->inSection(Section, "!src", FileName)) | 144 if (SCL->inSection(Section, "!src", FileName)) |
110 return true; | 145 return Forbid; |
111 if (SCL->inSection(Section, "src", FileName)) | 146 if (SCL->inSection(Section, "src", FileName)) |
112 return false; | 147 return Allow; |
113 return None; | 148 return None; |
114 } | 149 } |