@@ -162,49 +162,32 @@ uint32_t CallSiteInfoLoader::offsetFromString(StringRef str) {
162162
163163llvm::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 *>
206189CallSiteInfoLoader::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
228211llvm::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 ®ex : 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
0 commit comments