[PowerPC] Optimize compares fed by ANDISo
[llvm-core.git] / tools / llvm-xray / func-id-helper.cpp
blobc2bef6ddfb3966c3f35c41b39f75313699bb1aa1
1 //===- xray-fc-account.cpp: XRay Function Call Accounting Tool ------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Implementation of the helper tools dealing with XRay-generated function ids.
12 //===----------------------------------------------------------------------===//
14 #include "func-id-helper.h"
15 #include "llvm/Support/Path.h"
16 #include <sstream>
18 using namespace llvm;
19 using namespace xray;
21 std::string FuncIdConversionHelper::SymbolOrNumber(int32_t FuncId) const {
22 auto CacheIt = CachedNames.find(FuncId);
23 if (CacheIt != CachedNames.end())
24 return CacheIt->second;
26 std::ostringstream F;
27 auto It = FunctionAddresses.find(FuncId);
28 if (It == FunctionAddresses.end()) {
29 F << "#" << FuncId;
30 return F.str();
33 if (auto ResOrErr = Symbolizer.symbolizeCode(BinaryInstrMap, It->second)) {
34 auto &DI = *ResOrErr;
35 if (DI.FunctionName == "<invalid>")
36 F << "@(" << std::hex << It->second << ")";
37 else
38 F << DI.FunctionName;
39 } else
40 handleAllErrors(ResOrErr.takeError(), [&](const ErrorInfoBase &) {
41 F << "@(" << std::hex << It->second << ")";
42 });
44 auto S = F.str();
45 CachedNames[FuncId] = S;
46 return S;
49 std::string FuncIdConversionHelper::FileLineAndColumn(int32_t FuncId) const {
50 auto It = FunctionAddresses.find(FuncId);
51 if (It == FunctionAddresses.end())
52 return "(unknown)";
54 std::ostringstream F;
55 auto ResOrErr = Symbolizer.symbolizeCode(BinaryInstrMap, It->second);
56 if (!ResOrErr) {
57 consumeError(ResOrErr.takeError());
58 return "(unknown)";
61 auto &DI = *ResOrErr;
62 F << sys::path::filename(DI.FileName).str() << ":" << DI.Line << ":"
63 << DI.Column;
65 return F.str();