Skip to content

Commit fe23779

Browse files
author
Alex B
committed
Address Feedback nr.1
1 parent ac48f2c commit fe23779

File tree

3 files changed

+25
-78
lines changed

3 files changed

+25
-78
lines changed

llvm/include/llvm/DebugInfo/GSYM/CallSiteInfo.h

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ namespace gsym {
3434
class FileWriter;
3535
struct FunctionInfo;
3636
struct CallSiteInfo {
37-
public:
3837
enum Flags : uint8_t {
3938
None = 0,
4039
// This flag specifies that the call site can only call a function within
@@ -52,7 +51,7 @@ struct CallSiteInfo {
5251
std::vector<uint32_t> MatchRegex;
5352

5453
/// Bitwise OR of CallSiteInfo::Flags values
55-
uint8_t Flags;
54+
uint8_t Flags = CallSiteInfo::Flags::None;
5655

5756
/// Decode a CallSiteInfo object from a binary data stream.
5857
///
@@ -73,16 +72,8 @@ struct CallSiteInfo {
7372
};
7473

7574
struct CallSiteInfoCollection {
76-
public:
7775
std::vector<CallSiteInfo> CallSites;
7876

79-
void clear() { CallSites.clear(); }
80-
81-
/// Query if a CallSiteInfoCollection object is valid.
82-
///
83-
/// \returns True if the collection is not empty.
84-
bool isValid() const { return !CallSites.empty(); }
85-
8677
/// Decode a CallSiteInfoCollection object from a binary data stream.
8778
///
8879
/// \param Data The binary stream to read the data from.
@@ -156,54 +147,27 @@ class CallSiteInfoLoader {
156147
/// \returns A 32-bit unsigned integer representing the offset of the string.
157148
uint32_t offsetFromString(StringRef str);
158149

159-
/// Reads the content of the YAML file specified by `YAMLFile` into
160-
/// `yamlContent`.
161-
///
162-
/// \param YAMLFile A StringRef representing the path to the YAML file.
163-
/// \param Buffer The memory buffer containing the YAML content.
164-
///
165-
/// \returns An `llvm::Error` indicating success or describing any issues
166-
/// encountered while reading the file.
167-
llvm::Error readYAMLFile(StringRef YAMLFile,
168-
std::unique_ptr<llvm::MemoryBuffer> &Buffer);
169-
170-
/// Parses the YAML content and populates `functionsYAML` with the parsed
171-
/// data.
172-
///
173-
/// \param Buffer The memory buffer containing the YAML content.
174-
/// \param functionsYAML A reference to an llvm::yaml::FunctionsYAML object to
175-
/// be populated.
176-
///
177-
/// \returns An `llvm::Error` indicating success or describing any issues
178-
/// encountered during parsing.
179-
llvm::Error parseYAML(llvm::MemoryBuffer &Buffer,
180-
llvm::yaml::FunctionsYAML &functionsYAML);
181-
182150
/// Builds a map from function names to FunctionInfo pointers based on the
183151
/// provided `Funcs` vector.
184152
///
185153
/// \param Funcs A reference to a vector of FunctionInfo objects.
186154
///
187-
/// \returns An unordered_map mapping function names (std::string) to their
155+
/// \returns A StringMap mapping function names (StringRef) to their
188156
/// corresponding FunctionInfo pointers.
189-
std::unordered_map<std::string, FunctionInfo *>
190-
buildFunctionMap(std::vector<FunctionInfo> &Funcs);
157+
StringMap<FunctionInfo *> buildFunctionMap(std::vector<FunctionInfo> &Funcs);
191158

192159
/// Processes the parsed YAML functions and updates the `FuncMap` accordingly.
193160
///
194161
/// \param functionsYAML A constant reference to an llvm::yaml::FunctionsYAML
195162
/// object containing parsed YAML data.
196-
/// \param FuncMap A reference to an unordered_map mapping function names to
163+
/// \param FuncMap A reference to a StringMap mapping function names to
197164
/// FunctionInfo pointers.
198-
/// \param YAMLFile A StringRef representing the name of the YAML file (used
199-
/// for error messages).
200165
///
201166
/// \returns An `llvm::Error` indicating success or describing any issues
202167
/// encountered during processing.
203168
llvm::Error
204169
processYAMLFunctions(const llvm::yaml::FunctionsYAML &functionsYAML,
205-
std::unordered_map<std::string, FunctionInfo *> &FuncMap,
206-
StringRef YAMLFile);
170+
StringMap<FunctionInfo *> &FuncMap);
207171

208172
/// Map of existing string offsets to CachedHashStringRef.
209173
DenseMap<uint64_t, CachedHashStringRef> &StringOffsetMap;

llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -162,49 +162,32 @@ uint32_t CallSiteInfoLoader::offsetFromString(StringRef str) {
162162

163163
llvm::Error CallSiteInfoLoader::loadYAML(std::vector<FunctionInfo> &Funcs,
164164
StringRef YAMLFile) {
165-
std::unique_ptr<llvm::MemoryBuffer> Buffer;
166165
// Step 1: Read YAML file
167-
if (auto Err = readYAMLFile(YAMLFile, Buffer))
168-
return Err;
169-
170-
// Step 2: Parse YAML content
171-
llvm::yaml::FunctionsYAML functionsYAML;
172-
if (auto Err = parseYAML(*Buffer, functionsYAML))
173-
return Err;
174-
175-
// Step 3: Build function map from Funcs
176-
auto FuncMap = buildFunctionMap(Funcs);
177-
178-
// Step 4: Process parsed YAML functions and update FuncMap
179-
return processYAMLFunctions(functionsYAML, FuncMap, YAMLFile);
180-
}
181-
182-
llvm::Error
183-
CallSiteInfoLoader::readYAMLFile(StringRef YAMLFile,
184-
std::unique_ptr<llvm::MemoryBuffer> &Buffer) {
185166
auto BufferOrError = llvm::MemoryBuffer::getFile(YAMLFile);
186167
if (!BufferOrError)
187168
return errorCodeToError(BufferOrError.getError());
188-
Buffer = std::move(*BufferOrError);
189-
return llvm::Error::success();
190-
}
191169

192-
llvm::Error
193-
CallSiteInfoLoader::parseYAML(llvm::MemoryBuffer &Buffer,
194-
llvm::yaml::FunctionsYAML &functionsYAML) {
195-
// Use the MemoryBufferRef constructor
196-
llvm::yaml::Input yin(Buffer.getMemBufferRef());
170+
std::unique_ptr<llvm::MemoryBuffer> Buffer = std::move(*BufferOrError);
171+
172+
// Step 2: Parse YAML content
173+
llvm::yaml::FunctionsYAML functionsYAML;
174+
llvm::yaml::Input yin(Buffer->getMemBufferRef());
197175
yin >> functionsYAML;
198176
if (yin.error()) {
199177
return llvm::createStringError(yin.error(), "Error parsing YAML file: %s\n",
200-
Buffer.getBufferIdentifier().str().c_str());
178+
Buffer->getBufferIdentifier().str().c_str());
201179
}
202-
return llvm::Error::success();
180+
181+
// Step 3: Build function map from Funcs
182+
auto FuncMap = buildFunctionMap(Funcs);
183+
184+
// Step 4: Process parsed YAML functions and update FuncMap
185+
return processYAMLFunctions(functionsYAML, FuncMap);
203186
}
204187

205-
std::unordered_map<std::string, FunctionInfo *>
188+
StringMap<FunctionInfo *>
206189
CallSiteInfoLoader::buildFunctionMap(std::vector<FunctionInfo> &Funcs) {
207-
std::unordered_map<std::string, FunctionInfo *> FuncMap;
190+
StringMap<FunctionInfo *> FuncMap;
208191
auto insertFunc = [&](auto &Function) {
209192
std::string FuncName = stringFromOffset(Function.Name).str();
210193
// If the function name is already in the map, don't update it. This way we
@@ -227,8 +210,7 @@ CallSiteInfoLoader::buildFunctionMap(std::vector<FunctionInfo> &Funcs) {
227210

228211
llvm::Error CallSiteInfoLoader::processYAMLFunctions(
229212
const llvm::yaml::FunctionsYAML &functionsYAML,
230-
std::unordered_map<std::string, FunctionInfo *> &FuncMap,
231-
StringRef YAMLFile) {
213+
StringMap<FunctionInfo *> &FuncMap) {
232214
// For each function in the YAML file
233215
for (const auto &FuncYAML : functionsYAML.functions) {
234216
auto it = FuncMap.find(FuncYAML.name);
@@ -247,9 +229,9 @@ llvm::Error CallSiteInfoLoader::processYAMLFunctions(
247229
// Since YAML has specifies relative return offsets, add the function
248230
// start address to make the offset absolute.
249231
CSI.ReturnAddress = FuncInfo->Range.start() + CallSiteYAML.return_offset;
250-
for (const auto &regex : CallSiteYAML.match_regex) {
251-
CSI.MatchRegex.push_back(offsetFromString(regex));
252-
}
232+
for (const auto &Regex : CallSiteYAML.match_regex)
233+
CSI.MatchRegex.push_back(offsetFromString(Regex));
234+
253235
// Initialize flags to None
254236
CSI.Flags = CallSiteInfo::None;
255237
// Parse flags and combine them

llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static void parseArgs(int argc, char **argv) {
180180
LookupAddressesFromStdin = Args.hasArg(OPT_addresses_from_stdin);
181181
StoreMergedFunctionInfo = Args.hasArg(OPT_merged_functions);
182182

183-
for (const llvm::opt::Arg *A : Args.filtered(OPT_callsites_from_yaml_EQ))
183+
if (const llvm::opt::Arg *A = Args.getLastArg(OPT_callsites_from_yaml_EQ)) {
184184
if (A->getValue() && A->getValue()[0] != '\0')
185185
CallSiteYamlPaths.emplace_back(A->getValue());
186186
else {
@@ -189,6 +189,7 @@ static void parseArgs(int argc, char **argv) {
189189
<< ": --callsites-from-yaml option requires a non-empty argument.\n";
190190
std::exit(1);
191191
}
192+
}
192193
}
193194

194195
/// @}

0 commit comments

Comments
 (0)