Go to the documentation of this file.
9 #ifndef LLVM_SUPPORT_SCOPEDPRINTER_H
10 #define LLVM_SUPPORT_SCOPEDPRINTER_H
24 template <
typename T>
struct EnumEntry {
51 :
Value(static_cast<unsigned long long>(
Value)) {}
92 template <
typename T,
typename TEnum>
95 if (EnumItem.Value ==
Value)
96 return std::string(EnumItem.AltName);
97 return utohexstr(
Value,
true);
109 : OS(OS), Kind(Kind) {}
121 void indent(
int Levels = 1) { IndentLevel += Levels; }
124 IndentLevel = IndentLevel > Levels ? IndentLevel - Levels : 0;
135 for (
int i = 0;
i < IndentLevel; ++
i)
141 template <
typename T,
typename TEnum>
146 for (
const auto &EnumItem : EnumValues) {
147 if (EnumItem.Value ==
Value) {
148 Name = EnumItem.Name;
160 template <
typename T,
typename TFlag>
162 TFlag EnumMask1 = {}, TFlag EnumMask2 = {},
163 TFlag EnumMask3 = {}) {
164 SmallVector<FlagEntry, 10> SetFlags;
166 for (
const auto &
Flag : Flags) {
171 if (
Flag.Value & EnumMask1)
172 EnumMask = EnumMask1;
173 else if (
Flag.Value & EnumMask2)
174 EnumMask = EnumMask2;
175 else if (
Flag.Value & EnumMask3)
176 EnumMask = EnumMask3;
177 bool IsEnum = (
Flag.Value & EnumMask) != 0;
179 (IsEnum && (
Value & EnumMask) ==
Flag.Value)) {
180 SetFlags.emplace_back(
Flag.Name,
Flag.Value);
185 printFlagsImpl(Label,
hex(
Value), SetFlags);
198 printFlagsImpl(Label,
hex(
Value), SetFlags);
237 template <
typename T>
248 printVersionInternal(
Version...);
252 template <
typename T>
255 for (
const auto &Item :
List)
261 printListImpl(Label,
List);
265 printListImpl(Label,
List);
269 printListImpl(Label,
List);
273 printListImpl(Label,
List);
277 printListImpl(Label,
List);
282 for (
const uint8_t &Item :
List)
284 printListImpl(Label, NumberList);
288 printListImpl(Label,
List);
292 printListImpl(Label,
List);
296 printListImpl(Label,
List);
301 for (
const int8_t &Item :
List)
303 printListImpl(Label, NumberList);
307 printListImpl(Label,
List);
310 template <
typename T,
typename U>
314 for (
const auto &Item :
List) {
323 for (
const auto &Item :
List)
325 printHexListImpl(Label, HexList);
333 printHexImpl(Label, Str,
hex(
Value));
336 template <
typename T>
348 printBinaryImpl(Label, Str,
Value,
false);
354 printBinaryImpl(Label, Str, V,
false);
364 printBinaryImpl(Label,
StringRef(), V,
false);
370 printBinaryImpl(Label,
StringRef(), V,
false);
385 printBinaryImpl(Label,
StringRef(), V,
true);
412 template <
typename T>
void printVersionInternal(T
Value) {
416 template <
typename S,
typename T,
typename... TArgs>
417 void printVersionInternal(
S Value, T Value2, TArgs...
Args) {
419 printVersionInternal(Value2,
Args...);
422 static bool flagName(
const FlagEntry &
LHS,
const FlagEntry &
RHS) {
423 return LHS.Name <
RHS.Name;
426 virtual void printBinaryImpl(StringRef Label, StringRef Str,
427 ArrayRef<uint8_t>
Value,
bool Block,
430 virtual void printFlagsImpl(StringRef Label, HexNumber
Value,
431 ArrayRef<FlagEntry> Flags) {
433 for (
const auto &
Flag : Flags)
438 virtual void printFlagsImpl(StringRef Label, HexNumber
Value,
439 ArrayRef<HexNumber> Flags) {
441 for (
const auto &
Flag : Flags)
446 template <
typename T>
void printListImpl(StringRef Label,
const T List) {
449 for (
const auto &Item : List)
454 virtual void printHexListImpl(StringRef Label,
455 const ArrayRef<HexNumber> List) {
458 for (
const auto &Item : List)
459 OS <<
LS <<
hex(Item);
463 virtual void printHexImpl(StringRef Label, HexNumber
Value) {
467 virtual void printHexImpl(StringRef Label, StringRef Str, HexNumber
Value) {
471 virtual void printSymbolOffsetImpl(StringRef Label, StringRef
Symbol,
476 virtual void printNumberImpl(StringRef Label, StringRef Str,
481 void scopedBegin(
char Symbol) {
486 void scopedBegin(StringRef Label,
char Symbol) {
494 void scopedEnd(
char Symbol) {
507 ScopedPrinter::printHex<support::ulittle16_t>(
StringRef Label,
509 startLine() << Label <<
": " << hex(
Value) <<
"\n";
512 struct DelimitedScope;
521 enum class ScopeKind {
527 struct ScopeContext {
530 ScopeContext(Scope
Context, ScopeKind Kind = ScopeKind::NoAttribute)
536 std::unique_ptr<DelimitedScope> OuterScope;
540 std::unique_ptr<DelimitedScope> &&OuterScope =
541 std::unique_ptr<DelimitedScope>{});
590 printListImpl(Label,
List);
594 printListImpl(Label,
List);
598 printListImpl(Label,
List);
602 printListImpl(Label,
List);
606 printListImpl(Label,
List);
610 printListImpl(Label,
List);
614 printListImpl(Label,
List);
618 printListImpl(Label,
List);
622 printListImpl(Label,
List);
626 printListImpl(Label,
List);
644 scopedBegin({Scope::Object, ScopeKind::NoAttribute});
648 scopedBegin(Label, Scope::Object);
654 scopedBegin({Scope::Array, ScopeKind::NoAttribute});
658 scopedBegin(Label, Scope::Array);
672 void printFlagsImpl(StringRef Label, HexNumber
Value,
673 ArrayRef<FlagEntry> Flags)
override {
677 for (
const FlagEntry &
Flag : Flags) {
687 void printFlagsImpl(StringRef Label, HexNumber
Value,
688 ArrayRef<HexNumber> Flags)
override {
692 for (
const HexNumber &
Flag : Flags) {
699 template <
typename T>
void printListImpl(StringRef Label,
const T &List) {
701 for (
const auto &Item : List)
706 void printHexListImpl(StringRef Label,
707 const ArrayRef<HexNumber> List)
override {
709 for (
const HexNumber &Item : List) {
710 JOS.
value(hexNumberToInt(Item));
715 void printHexImpl(StringRef Label, HexNumber
Value)
override {
719 void printHexImpl(StringRef Label, StringRef Str, HexNumber
Value)
override {
726 void printSymbolOffsetImpl(StringRef Label, StringRef
Symbol,
727 HexNumber
Value)
override {
734 void printNumberImpl(StringRef Label, StringRef Str,
735 StringRef
Value)
override {
745 void printBinaryImpl(StringRef Label, StringRef Str, ArrayRef<uint8_t>
Value,
746 bool Block,
uint32_t StartOffset = 0)
override {
752 for (uint8_t Val : Value)
758 void scopedBegin(ScopeContext ScopeCtx) {
759 if (ScopeCtx.Context == Scope::Object)
761 else if (ScopeCtx.Context == Scope::Array)
763 ScopeHistory.push_back(ScopeCtx);
766 void scopedBegin(StringRef Label, Scope Ctx) {
767 ScopeKind
Kind = ScopeKind::Attribute;
768 if (ScopeHistory.empty() || ScopeHistory.back().Context != Scope::Object) {
770 Kind = ScopeKind::NestedAttribute;
773 scopedBegin({Ctx,
Kind});
777 ScopeContext ScopeCtx = ScopeHistory.back();
778 if (ScopeCtx.Context == Scope::Object)
780 else if (ScopeCtx.Context == Scope::Array)
782 if (ScopeCtx.Kind == ScopeKind::Attribute ||
783 ScopeCtx.Kind == ScopeKind::NestedAttribute)
785 if (ScopeCtx.Kind == ScopeKind::NestedAttribute)
787 ScopeHistory.pop_back();
void printList(StringRef Label, const ArrayRef< APSInt > List) override
virtual void printNumber(StringRef Label, int8_t Value)
void printNumber(StringRef Label, int16_t Value) override
void attributeBegin(llvm::StringRef Key)
void printSymbolOffset(StringRef Label, StringRef Symbol, T Value)
void printVersion(StringRef Label, T... Version)
void printNumber(StringRef Label, StringRef Str, T Value)
This is an optimization pass for GlobalISel generic memory operations.
virtual ~ScopedPrinter()=default
DictScope(ScopedPrinter &W, StringRef N)
HexNumber(unsigned long long Value)
virtual void printList(StringRef Label, const ArrayRef< uint16_t > List)
FlagEntry(StringRef Name, unsigned long Value)
virtual void printList(StringRef Label, const ArrayRef< int32_t > List)
virtual void printNumber(StringRef Label, int64_t Value)
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
void printBinary(StringRef Label, StringRef Str, ArrayRef< char > Value)
A raw_ostream that writes to an std::string.
virtual void printNumber(StringRef Label, int32_t Value)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
void printNumber(StringRef Label, int32_t Value) override
constexpr EnumEntry(StringRef N, T V)
constexpr EnumEntry(StringRef N, StringRef A, T V)
void arrayBegin() override
FlagEntry(StringRef Name, signed char Value)
void printObject(StringRef Label, const T &Value)
virtual raw_ostream & getOStream()
virtual void printString(StringRef Label, StringRef Value)
virtual void objectBegin(StringRef Label)
void attributeArray(llvm::StringRef Key, Block Contents)
Emit an attribute whose value is an array with elements from the Block.
void printList(StringRef Label, const ArrayRef< std::string > List) override
void printNumber(StringRef Label, uint16_t Value) override
DelimitedScope(ScopedPrinter &W)
FlagEntry(StringRef Name, signed int Value)
virtual void printList(StringRef Label, const ArrayRef< int16_t > List)
void printList(StringRef Label, const ArrayRef< uint64_t > List) override
HexNumber(signed short Value)
void printList(StringRef Label, const ArrayRef< bool > List) override
FlagEntry(StringRef Name, signed long long Value)
void printList(StringRef Label, const ArrayRef< uint16_t > List) override
ListScope(ScopedPrinter &W, StringRef N)
void printBinaryBlock(StringRef Label, ArrayRef< uint8_t > Value)
void printHex(StringRef Label, StringRef Str, T Value)
void unindent(int Levels=1)
HexNumber(unsigned char Value)
HexNumber(signed int Value)
virtual void printList(StringRef Label, const ArrayRef< bool > List)
print alias Alias Set Printer
void printFlags(StringRef Label, T Value)
void printNumber(StringRef Label, uint8_t Value) override
void printString(StringRef Label, StringRef Value) override
virtual void printNumber(StringRef Label, const APSInt &Value)
Clang compiles this i1 i64 store i64 i64 store i64 i64 store i64 i64 store i64 align Which gets codegen d xmm0 movaps rbp movaps rbp movaps rbp movaps rbp rbp rbp rbp rbp It would be better to have movq s of instead of the movaps s LLVM produces ret int
virtual void printList(StringRef Label, const ArrayRef< uint32_t > List)
HexNumber(unsigned short Value)
void setPrinter(ScopedPrinter &W) override
void printList(StringRef Label, const ArrayRef< int8_t > List) override
HexNumber(signed char Value)
FlagEntry(StringRef Name, signed long Value)
void printBinary(StringRef Label, ArrayRef< char > Value)
void printBinary(StringRef Label, StringRef Value)
Flag
These should be considered private to the implementation of the MCInstrDesc class.
ScopedPrinterKind getKind() const
An arbitrary precision integer that knows its signedness.
This class implements an extremely fast bulk output stream that can only output to a stream.
FlagEntry(StringRef Name, unsigned int Value)
void printBoolean(StringRef Label, bool Value) override
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
void printString(StringRef Value) override
virtual void arrayBegin()
void objectBegin(StringRef Label) override
void printBinary(StringRef Label, StringRef Str, ArrayRef< uint8_t > Value)
virtual void printNumber(StringRef Label, uint64_t Value)
virtual void printNumber(StringRef Label, uint32_t Value)
void setPrefix(StringRef P)
FlagEntry(StringRef Name, unsigned char Value)
void arrayBegin(StringRef Label) override
void printFlags(StringRef Label, T Value, ArrayRef< EnumEntry< TFlag >> Flags, TFlag EnumMask1={}, TFlag EnumMask2={}, TFlag EnumMask3={})
virtual void printList(StringRef Label, const ArrayRef< uint64_t > List)
void setPrinter(ScopedPrinter &W) override
virtual void objectBegin()
json::OStream allows writing well-formed JSON without materializing all structures as json::Value ahe...
virtual void printBoolean(StringRef Label, bool Value)
void printEnum(StringRef Label, T Value, ArrayRef< EnumEntry< TEnum >> EnumValues)
void printList(StringRef Label, const ArrayRef< int64_t > List) override
virtual void printList(StringRef Label, const ArrayRef< int8_t > List)
void objectEnd() override
void printBinaryBlock(StringRef Label, ArrayRef< uint8_t > Value, uint32_t StartOffset)
HexNumber(signed long long Value)
ListScope(ScopedPrinter &W)
FlagEntry(StringRef Name, unsigned short Value)
virtual void printList(StringRef Label, const ArrayRef< int64_t > List)
static bool classof(const ScopedPrinter *SP)
void printNumber(StringRef Label, uint32_t Value) override
virtual void printNumber(StringRef Label, int16_t Value)
virtual void arrayBegin(StringRef Label)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
StringRef - Represent a constant reference to a string, i.e.
void printList(StringRef Label, const ArrayRef< uint32_t > List) override
void printList(StringRef Label, const ArrayRef< int32_t > List) override
static bool classof(const ScopedPrinter *SP)
void printBinaryBlock(StringRef Label, StringRef Value)
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
DictScope(ScopedPrinter &W)
virtual void printString(StringRef Value)
virtual void printNumber(StringRef Label, uint8_t Value)
virtual raw_ostream & startLine()
void printList(StringRef Label, const ArrayRef< uint8_t > List) override
virtual void setPrinter(ScopedPrinter &W)=0
void printNumber(StringRef Label, int64_t Value) override
FlagEntry(StringRef Name, char Value)
void printList(StringRef Label, const ArrayRef< T > List)
virtual void printList(StringRef Label, const ArrayRef< uint8_t > List)
void printHexList(StringRef Label, const T &List)
void printBinary(StringRef Label, ArrayRef< uint8_t > Value)
JSONScopedPrinter(raw_ostream &OS, bool PrettyPrint=false, std::unique_ptr< DelimitedScope > &&OuterScope=std::unique_ptr< DelimitedScope >{})
std::string enumToString(T Value, ArrayRef< EnumEntry< TEnum >> EnumValues)
FlagEntry(StringRef Name, unsigned long long Value)
void printNumber(StringRef Label, uint64_t Value) override
void printNumber(StringRef Label, int8_t Value) override
void objectBegin() override
void indent(int Levels=1)
void printNumber(StringRef Label, const APSInt &Value) override
void sort(IteratorTy Start, IteratorTy End)
void value(const Value &V)
Emit a self-contained value (number, string, vector<string> etc).
HexNumber(unsigned long Value)
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
void printList(StringRef Label, const ArrayRef< int16_t > List) override
FlagEntry(StringRef Name, signed short Value)
void printHex(StringRef Label, T Value)
virtual void printNumber(StringRef Label, uint16_t Value)
HexNumber(signed long Value)
HexNumber(unsigned int Value)
std::string to_string(const T &Value)
void attributeObject(llvm::StringRef Key, Block Contents)
Emit an attribute whose value is an object with attributes from the Block.
virtual void printList(StringRef Label, const ArrayRef< APSInt > List)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
void attribute(llvm::StringRef Key, const Value &Contents)
Emit an attribute whose value is self-contained (number, vector<int> etc).
void printList(StringRef Label, const T &List, const U &Printer)
std::string & str()
Returns the string's reference.
raw_ostream & rawValueBegin()
virtual ~DelimitedScope()=default
LLVM Value Representation.
virtual void printList(StringRef Label, const ArrayRef< std::string > List)
ScopedPrinter(raw_ostream &OS, ScopedPrinterKind Kind=ScopedPrinterKind::Base)
reference emplace_back(ArgTypes &&... Args)