LLVM: lib/DebugInfo/LogicalView/Core/LVReader.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
18#include
19
20using namespace llvm;
22
23#define DEBUG_TYPE "Reader"
24
25
26
27
29 using LVDuplicateEntry = std::tuple<LVElement *, LVScope *, LVScope *>;
30 using LVDuplicate = std::vector;
31 LVDuplicate Duplicate;
32
33 using LVIntegrity = std::map<LVElement *, LVScope *>;
35
36
38 LVIntegrity::iterator Iter = Integrity.find(Element);
40 Integrity.emplace(Element, Scope);
41 else
42
43 Duplicate.emplace_back(Element, Scope, Iter->second);
44 };
45
46
47 std::function<void(LVScope * Parent)> TraverseScope = [&](LVScope *Parent) {
48 auto Traverse = [&](const auto *Set) {
49 if (Set)
50 for (const auto &Entry : *Set)
51 AddElement(Entry, Parent);
52 };
55 AddElement(Scope, Parent);
56 TraverseScope(Scope);
57 }
58 }
62 };
63
64
65 TraverseScope(Root);
66 bool PassIntegrity = true;
67 if (Duplicate.size()) {
68 std::stable_sort(begin(Duplicate), end(Duplicate),
69 [](const auto &l, const auto &r) {
70 return std::get<0>(l)->getID() < std::get<0>(r)->getID();
71 });
72
73 auto PrintIndex = [](unsigned Index) {
74 if (Index)
76 else
78 };
79 auto PrintElement = [&](LVElement *Element, unsigned Index = 0) {
80 PrintIndex(Index);
81 std::string ElementName(Element->getName());
82 dbgs() << format("%15s ID=0x%08x '%s'\n", Element->kind(),
83 Element->getID(), ElementName.c_str());
84 };
85
86 std::string RootName(Root->getName());
88 dbgs() << format("Root: '%s'\nDuplicated elements: %d\n", RootName.c_str(),
89 Duplicate.size());
91
92 unsigned Index = 0;
93 for (const LVDuplicateEntry &Entry : Duplicate) {
97 std::tie(Element, First, Second) = Entry;
99 PrintElement(Element, ++Index);
100 PrintElement(First);
101 PrintElement(Second);
103 }
104 PassIntegrity = false;
105 }
106 return PassIntegrity;
107}
108
109
110
111
113
114
115
116 Location = std::string(Where);
117
118
119 size_t Pos = Location.find_last_of('/');
120 if (Location.length() != Pos + 1)
121 Location.append("/");
122
123
126 Location.c_str());
127
129}
130
133 assert(OutputFile == nullptr && "OutputFile already set.");
134
135
137 Name.append(Extension);
138
139 if (!Location.empty())
140 Name.insert(0, Location);
141
142 std::error_code EC;
144 if (EC)
145 return EC;
146
147
148 OutputFile->keep();
149 return std::error_code();
150}
151
156 outs() << "Invalid instance reader.\n";
158}
160
161Error LVReader::createSplitFolder() {
162 if (OutputSplit) {
163
164
165 if (options().getOutputFolder().empty())
167
169 SplitFolder = options().getOutputFolder();
171
172
174 return Err;
175
176 OS << "\nSplit View Location: '" << SplitContext.getLocation() << "'\n";
177 }
178
180}
181
182
184
185
186
187 if (CompileUnits.size()) {
188
189 LVCompileUnits::const_iterator Iter =
190 std::prev(CompileUnits.lower_bound(Object->getOffset()));
191 if (Iter != CompileUnits.end())
192 return Iter->second->getFilename(Index);
193 }
194
196}
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
215
217
218
219
222
223
229
230
231
233
234
236 return Err;
237
239 return llvm::make_error("Duplicated elements in Scopes Tree",
241
242
244
245
246
247
249
252}
253
254
256
258
259
260 if (options().getReportExecute()) {
261
262 if (options().getReportList())
264 return Err;
265
266 if (options().getReportChildren() && ().getReportParents())
268 return Err;
269
270 if (options().getReportParents() || options().getReportView())
272 return Err;
273
275 }
276
278}
279
281 if (bool DoPrint =
282 (options().getPrintExecute() || options().getComparePrint())) {
283 if (Error Err = createSplitFolder())
284 return Err;
285
286
287 bool DoMatch = options().getSelectGenericPattern() ||
288 options().getSelectGenericKind() ||
289 options().getSelectOffsetPattern();
290 return Root->doPrint(OutputSplit, DoMatch, DoPrint, OS);
291 }
292
294}
295
297 if (Error Err = createSplitFolder())
298 return Err;
299
301}
302
304 OS << "LVReader\n";
306}
AMDGPU Register Bank Select
bool checkIntegrityScopesTree(LVScope *Root)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef - Represent a constant reference to a string, i.e.
Stores all information relating to a compile unit, be it in its original instance in the object file ...
StringRef getName() const override
virtual const char * kind() const
void addGenericPatterns(StringSet<> &Patterns)
void updateReportOptions()
void addOffsetPatterns(const LVOffsetSet &Patterns)
The logical reader owns of all the logical elements created during the debug information parsing.
virtual void sortScopes()
void print(raw_ostream &OS) const
StringRef getFilename() const
static LVReader & getInstance()
static void setInstance(LVReader *Reader)
virtual Error printMatchedElements(bool UseMatchedElements)
virtual Error printScopes()
virtual Error createScopes()
void processRangeInformation()
Error doPrintMatches(bool Split, raw_ostream &OS, bool UseMatchedElements) const
const LVLines * getLines() const
const LVScopes * getScopes() const
const LVSymbols * getSymbols() const
const LVTypes * getTypes() const
Error doPrint(bool Split, bool Match, bool Print, raw_ostream &OS, bool Full=true) const override
std::string getLocation() const
Error createSplitFolder(StringRef Where)
std::error_code open(std::string Name, std::string Extension, raw_ostream &OS)
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::string flattenedFilePath(StringRef Path)
void make_absolute(const Twine ¤t_directory, SmallVectorImpl< char > &path)
Make path an absolute path.
std::error_code create_directories(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create all the non-existent directories in path.
This is an optimization pass for GlobalISel generic memory operations.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
support::detail::RepeatAdapter< T > fmt_repeat(T &&Item, size_t Count)