32 std::unique_ptr<MemoryBuffer> MemBuf;
34 std::optional<StringRef>
35 load(
StringRef FileName,
const std::optional<StringRef> &EmbeddedSource) {
40 return EmbeddedSource;
46 MemBuf = std::move(*BufOrErr);
47 return MemBuf->getBuffer();
51 std::optional<StringRef> pruneSource(
const std::optional<StringRef> &Source) {
55 for (int64_t L = 1; L <=
LastLine; ++L, ++Pos) {
58 Pos = Source->find(
'\n', Pos);
66 : Pos - FirstLinePos);
77 const std::optional<StringRef> &EmbeddedSource =
78 std::optional<StringRef>())
82 PrunedSource(pruneSource(load(FileName, EmbeddedSource))) {}
87 size_t MaxLineNumberWidth = std::ceil(std::log10(
LastLine));
93 if (
String.ends_with(
"\r"))
108void PlainPrinterBase::printHeader(std::optional<uint64_t>
Address) {
128 OS << Prefix << FunctionName << Delimiter;
132void LLVMPrinter::printSimpleLocation(
StringRef Filename,
134 OS << Filename <<
':' <<
Info.Line <<
':' <<
Info.Column <<
'\n';
139void GNUPrinter::printSimpleLocation(
StringRef Filename,
141 OS << Filename <<
':' <<
Info.Line;
142 if (
Info.Discriminator)
143 OS <<
" (discriminator " <<
Info.Discriminator <<
')';
151 OS <<
" Filename: " << Filename <<
'\n';
152 if (
Info.StartLine) {
153 OS <<
" Function start filename: " <<
Info.StartFileName <<
'\n';
154 OS <<
" Function start line: " <<
Info.StartLine <<
'\n';
157 OS <<
" Line: " <<
Info.Line <<
'\n';
158 OS <<
" Column: " <<
Info.Column <<
'\n';
159 if (
Info.Discriminator)
160 OS <<
" Discriminator: " <<
Info.Discriminator <<
'\n';
164 if (
Info.StartAddress) {
165 OS <<
" Function start address: 0x";
171void LLVMPrinter::printFooter() {
OS <<
'\n'; }
209 if (
Global.DeclFile.empty())
217 const std::vector<DILocal> &Locals) {
222 for (
const DILocal &L : Locals) {
223 if (L.FunctionName.empty())
226 OS << L.FunctionName;
235 if (L.DeclFile.empty())
240 OS <<
':' << L.DeclLine <<
'\n';
243 OS << *L.FrameOffset;
264 const std::vector<DILineInfo> &Locations) {
265 if (Locations.empty()) {
291 if (!ErrorMsg.empty())
292 Json[
"Error"] =
json::Object({{
"Message", ErrorMsg.str()}});
309 {
"Line", LineInfo.
Line},
310 {
"Column", LineInfo.
Column},
327 std::string FormattedSource;
330 if (!FormattedSource.empty())
331 Object[
"Source"] = std::move(FormattedSource);
332 Array.push_back(std::move(Object));
335 Json[
"Symbol"] = std::move(Array);
337 ObjectList->push_back(std::move(Json));
339 printJSON(std::move(Json));
348 Json[
"Data"] = std::move(
Data);
350 ObjectList->push_back(std::move(Json));
352 printJSON(std::move(Json));
356 const std::vector<DILocal> &Locals) {
358 for (
const DILocal &Local : Locals) {
360 {{
"FunctionName", Local.FunctionName},
361 {
"Name", Local.Name},
362 {
"DeclFile", Local.DeclFile},
363 {
"DeclLine", int64_t(Local.DeclLine)},
364 {
"Size", Local.Size ?
toHex(*Local.Size) :
""},
365 {
"TagOffset", Local.TagOffset ?
toHex(*Local.TagOffset) :
""}});
366 if (Local.FrameOffset)
367 FrameObject[
"FrameOffset"] = *Local.FrameOffset;
371 Json[
"Frame"] = std::move(Frame);
373 ObjectList->push_back(std::move(Json));
375 printJSON(std::move(Json));
379 const std::vector<DILineInfo> &Locations) {
384 Json[
"Loc"] = std::move(Definitions);
386 ObjectList->push_back(std::move(Json));
388 printJSON(std::move(Json));
395 ObjectList->push_back(std::move(Json));
397 printJSON(std::move(Json));
403 ObjectList = std::make_unique<json::Array>();
408 printJSON(std::move(*ObjectList));
Analysis containing CSE Info
Provides ErrorOr<T> smart pointer.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A format-neutral container for inlined code description.
void addFrame(const DILineInfo &Frame)
Base class for error info classes.
virtual std::string message() const
Return the error message as a string.
Base class for user error types.
Represents either an error or a value T.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
constexpr bool empty() const
empty - Check if the string is empty.
static constexpr size_t npos
static Twine utohexstr(const uint64_t &Val)
An Array is a JSON array, which contains heterogeneous JSON values.
void push_back(const Value &E)
An Object is a JSON object, which maps strings to heterogenous JSON values.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write_hex(unsigned long long N)
Output N in hexadecimal, without any prefix or padding.
A raw_ostream that writes to an std::string.
void print(const Request &Request, const DILineInfo &Info) override
void listBegin() override
bool printError(const Request &Request, const ErrorInfoBase &ErrorInfo) override
void printContext(SourceCode SourceCode)
virtual void printFooter()
virtual void printStartAddress(const DILineInfo &Info)
bool printError(const Request &Request, const ErrorInfoBase &ErrorInfo) override
virtual void printSimpleLocation(StringRef Filename, const DILineInfo &Info)=0
void printVerbose(StringRef Filename, const DILineInfo &Info)
void printFunctionName(StringRef FunctionName, bool Inlined)
void print(const DILineInfo &Info, bool Inlined)
const std::optional< StringRef > PrunedSource
void format(raw_ostream &OS)
SourceCode(StringRef FileName, int64_t Line, int Lines, const std::optional< StringRef > &EmbeddedSource=std::optional< StringRef >())
static std::string toHex(uint64_t V)
static json::Object toJSON(const Request &Request, StringRef ErrorMsg="")
This is an optimization pass for GlobalISel generic memory operations.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
FormattedNumber format_decimal(int64_t N, unsigned Width)
format_decimal - Output N as a right justified, fixed-width decimal.
@ Global
Append to llvm.global_dtors.
Implement std::hash so that hash_code can be used in STL containers.
Container for description of a global variable.
A format-neutral container for source line information.
static constexpr const char *const BadString
std::optional< uint64_t > StartAddress
static constexpr const char *const Addr2LineBadString
std::optional< StringRef > Source
std::string StartFileName
std::optional< uint64_t > Address