Revert r354244 "[DAGCombiner] Eliminate dead stores to stack."
[llvm-complete.git] / tools / llvm-xray / func-id-helper.cpp
blob987eb43b73242a76fb8ea0b20a537017bf101c5f
1 //===- xray-fc-account.cpp: XRay Function Call Accounting Tool ------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Implementation of the helper tools dealing with XRay-generated function ids.
11 //===----------------------------------------------------------------------===//
13 #include "func-id-helper.h"
14 #include "llvm/Support/Path.h"
15 #include <sstream>
17 using namespace llvm;
18 using namespace xray;
20 std::string FuncIdConversionHelper::SymbolOrNumber(int32_t FuncId) const {
21 auto CacheIt = CachedNames.find(FuncId);
22 if (CacheIt != CachedNames.end())
23 return CacheIt->second;
25 std::ostringstream F;
26 auto It = FunctionAddresses.find(FuncId);
27 if (It == FunctionAddresses.end()) {
28 F << "#" << FuncId;
29 return F.str();
32 if (auto ResOrErr = Symbolizer.symbolizeCode(BinaryInstrMap, It->second)) {
33 auto &DI = *ResOrErr;
34 if (DI.FunctionName == "<invalid>")
35 F << "@(" << std::hex << It->second << ")";
36 else
37 F << DI.FunctionName;
38 } else
39 handleAllErrors(ResOrErr.takeError(), [&](const ErrorInfoBase &) {
40 F << "@(" << std::hex << It->second << ")";
41 });
43 auto S = F.str();
44 CachedNames[FuncId] = S;
45 return S;
48 std::string FuncIdConversionHelper::FileLineAndColumn(int32_t FuncId) const {
49 auto It = FunctionAddresses.find(FuncId);
50 if (It == FunctionAddresses.end())
51 return "(unknown)";
53 std::ostringstream F;
54 auto ResOrErr = Symbolizer.symbolizeCode(BinaryInstrMap, It->second);
55 if (!ResOrErr) {
56 consumeError(ResOrErr.takeError());
57 return "(unknown)";
60 auto &DI = *ResOrErr;
61 F << sys::path::filename(DI.FileName).str() << ":" << DI.Line << ":"
62 << DI.Column;
64 return F.str();