[llvm] [Support] Add helper struct `indent` for adding indentation (PR #108966)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 17 05:17:20 PDT 2024
https://github.com/jurahul updated https://github.com/llvm/llvm-project/pull/108966
>From 9173e2305bef9170e73c69d9d8ff80a9a1c5b737 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Tue, 17 Sep 2024 04:58:49 -0700
Subject: [PATCH] [Support] Add helper struct `indent` for adding indentation
Add helper struct indent() for adding indentation to raw_ostream.
---
llvm/include/llvm/Support/raw_ostream.h | 18 ++
llvm/utils/TableGen/Common/DAGISelMatcher.cpp | 192 +++++++++---------
llvm/utils/TableGen/Common/DAGISelMatcher.h | 78 +++----
llvm/utils/TableGen/DAGISelMatcherOpt.cpp | 5 +-
llvm/utils/TableGen/DecoderEmitter.cpp | 158 +++++++-------
llvm/utils/yaml-bench/YAMLBench.cpp | 11 -
6 files changed, 228 insertions(+), 234 deletions(-)
diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
index 2570c826502e7c..186998a37a7e9b 100644
--- a/llvm/include/llvm/Support/raw_ostream.h
+++ b/llvm/include/llvm/Support/raw_ostream.h
@@ -769,6 +769,24 @@ class buffer_unique_ostream : public raw_svector_ostream {
~buffer_unique_ostream() override { *OS << str(); }
};
+// Helper struct to add indentation to raw_ostream. Instead of
+// OS.indent(6) << "more stuff";
+// you can use
+// OS << indent(6) << "more stuff";
+// which has better ergonomics.
+struct indent {
+ explicit indent(unsigned NumSpaces) : NumSpaces(NumSpaces) {}
+ unsigned NumSpaces;
+ void operator+=(unsigned N) { NumSpaces += N; }
+ void operator-=(unsigned N) { NumSpaces -= N; }
+ indent operator+(unsigned N) { return indent(NumSpaces + N); }
+ indent operator-(unsigned N) { return indent(NumSpaces - N); }
+};
+
+inline raw_ostream &operator<<(raw_ostream &OS, const indent &Indent) {
+ return OS.indent(Indent.NumSpaces);
+}
+
class Error;
/// This helper creates an output stream and then passes it to \p Write.
diff --git a/llvm/utils/TableGen/Common/DAGISelMatcher.cpp b/llvm/utils/TableGen/Common/DAGISelMatcher.cpp
index d235114871b52c..8780c4f5b61c27 100644
--- a/llvm/utils/TableGen/Common/DAGISelMatcher.cpp
+++ b/llvm/utils/TableGen/Common/DAGISelMatcher.cpp
@@ -17,15 +17,15 @@ using namespace llvm;
void Matcher::anchor() {}
-void Matcher::dump() const { print(errs(), 0); }
+void Matcher::dump() const { print(errs()); }
-void Matcher::print(raw_ostream &OS, unsigned indent) const {
- printImpl(OS, indent);
+void Matcher::print(raw_ostream &OS, indent Indent) const {
+ printImpl(OS, Indent);
if (Next)
- return Next->print(OS, indent);
+ return Next->print(OS, Indent);
}
-void Matcher::printOne(raw_ostream &OS) const { printImpl(OS, 0); }
+void Matcher::printOne(raw_ostream &OS) const { printImpl(OS, indent(0)); }
/// unlinkNode - Unlink the specified node from this chain. If Other == this,
/// we unlink the next pointer and return it. Otherwise we unlink Other from
@@ -111,156 +111,150 @@ unsigned CheckPredicateMatcher::getOperandNo(unsigned i) const {
// printImpl methods.
-void ScopeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "Scope\n";
+void ScopeMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "Scope\n";
for (const Matcher *C : Children) {
if (!C)
- OS.indent(indent + 1) << "NULL POINTER\n";
+ OS << Indent + 1 << "NULL POINTER\n";
else
- C->print(OS, indent + 2);
+ C->print(OS, Indent + 2);
}
}
-void RecordMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "Record\n";
+void RecordMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "Record\n";
}
-void RecordChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "RecordChild: " << ChildNo << '\n';
+void RecordChildMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "RecordChild: " << ChildNo << '\n';
}
-void RecordMemRefMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "RecordMemRef\n";
+void RecordMemRefMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "RecordMemRef\n";
}
-void CaptureGlueInputMatcher::printImpl(raw_ostream &OS,
- unsigned indent) const {
- OS.indent(indent) << "CaptureGlueInput\n";
+void CaptureGlueInputMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "CaptureGlueInput\n";
}
-void MoveChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "MoveChild " << ChildNo << '\n';
+void MoveChildMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "MoveChild " << ChildNo << '\n';
}
-void MoveSiblingMatcher::printImpl(raw_ostream &OS, unsigned Indent) const {
- OS.indent(Indent) << "MoveSibling " << SiblingNo << '\n';
+void MoveSiblingMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "MoveSibling " << SiblingNo << '\n';
}
-void MoveParentMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "MoveParent\n";
+void MoveParentMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "MoveParent\n";
}
-void CheckSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "CheckSame " << MatchNumber << '\n';
+void CheckSameMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "CheckSame " << MatchNumber << '\n';
}
-void CheckChildSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "CheckChild" << ChildNo << "Same\n";
+void CheckChildSameMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "CheckChild" << ChildNo << "Same\n";
}
void CheckPatternPredicateMatcher::printImpl(raw_ostream &OS,
- unsigned indent) const {
- OS.indent(indent) << "CheckPatternPredicate " << Predicate << '\n';
+ indent Indent) const {
+ OS << Indent << "CheckPatternPredicate " << Predicate << '\n';
}
-void CheckPredicateMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "CheckPredicate " << getPredicate().getFnName() << '\n';
+void CheckPredicateMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "CheckPredicate " << getPredicate().getFnName() << '\n';
}
-void CheckOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "CheckOpcode " << Opcode.getEnumName() << '\n';
+void CheckOpcodeMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "CheckOpcode " << Opcode.getEnumName() << '\n';
}
-void SwitchOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "SwitchOpcode: {\n";
+void SwitchOpcodeMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "SwitchOpcode: {\n";
for (const auto &C : Cases) {
- OS.indent(indent) << "case " << C.first->getEnumName() << ":\n";
- C.second->print(OS, indent + 2);
+ OS << Indent << "case " << C.first->getEnumName() << ":\n";
+ C.second->print(OS, Indent + 2);
}
- OS.indent(indent) << "}\n";
+ OS << Indent << "}\n";
}
-void CheckTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "CheckType " << getEnumName(Type) << ", ResNo=" << ResNo
- << '\n';
+void CheckTypeMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "CheckType " << getEnumName(Type) << ", ResNo=" << ResNo
+ << '\n';
}
-void SwitchTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "SwitchType: {\n";
+void SwitchTypeMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "SwitchType: {\n";
for (const auto &C : Cases) {
- OS.indent(indent) << "case " << getEnumName(C.first) << ":\n";
- C.second->print(OS, indent + 2);
+ OS << Indent << "case " << getEnumName(C.first) << ":\n";
+ C.second->print(OS, Indent + 2);
}
- OS.indent(indent) << "}\n";
+ OS << Indent << "}\n";
}
-void CheckChildTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "CheckChildType " << ChildNo << " " << getEnumName(Type)
- << '\n';
+void CheckChildTypeMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "CheckChildType " << ChildNo << " " << getEnumName(Type)
+ << '\n';
}
-void CheckIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "CheckInteger " << Value << '\n';
+void CheckIntegerMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "CheckInteger " << Value << '\n';
}
-void CheckChildIntegerMatcher::printImpl(raw_ostream &OS,
- unsigned indent) const {
- OS.indent(indent) << "CheckChildInteger " << ChildNo << " " << Value << '\n';
+void CheckChildIntegerMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "CheckChildInteger " << ChildNo << " " << Value << '\n';
}
-void CheckCondCodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "CheckCondCode ISD::" << CondCodeName << '\n';
+void CheckCondCodeMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "CheckCondCode ISD::" << CondCodeName << '\n';
}
void CheckChild2CondCodeMatcher::printImpl(raw_ostream &OS,
- unsigned indent) const {
- OS.indent(indent) << "CheckChild2CondCode ISD::" << CondCodeName << '\n';
+ indent Indent) const {
+ OS << Indent << "CheckChild2CondCode ISD::" << CondCodeName << '\n';
}
-void CheckValueTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "CheckValueType " << getEnumName(VT) << '\n';
+void CheckValueTypeMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "CheckValueType " << getEnumName(VT) << '\n';
}
-void CheckComplexPatMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "CheckComplexPat " << Pattern.getSelectFunc() << '\n';
+void CheckComplexPatMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "CheckComplexPat " << Pattern.getSelectFunc() << '\n';
}
-void CheckAndImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "CheckAndImm " << Value << '\n';
+void CheckAndImmMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "CheckAndImm " << Value << '\n';
}
-void CheckOrImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "CheckOrImm " << Value << '\n';
+void CheckOrImmMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "CheckOrImm " << Value << '\n';
}
void CheckFoldableChainNodeMatcher::printImpl(raw_ostream &OS,
- unsigned indent) const {
- OS.indent(indent) << "CheckFoldableChainNode\n";
+ indent Indent) const {
+ OS << Indent << "CheckFoldableChainNode\n";
}
-void CheckImmAllOnesVMatcher::printImpl(raw_ostream &OS,
- unsigned indent) const {
- OS.indent(indent) << "CheckAllOnesV\n";
+void CheckImmAllOnesVMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "CheckAllOnesV\n";
}
-void CheckImmAllZerosVMatcher::printImpl(raw_ostream &OS,
- unsigned indent) const {
- OS.indent(indent) << "CheckAllZerosV\n";
+void CheckImmAllZerosVMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "CheckAllZerosV\n";
}
-void EmitIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "EmitInteger " << Val << " VT=" << getEnumName(VT)
- << '\n';
+void EmitIntegerMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "EmitInteger " << Val << " VT=" << getEnumName(VT) << '\n';
}
-void EmitStringIntegerMatcher::printImpl(raw_ostream &OS,
- unsigned indent) const {
- OS.indent(indent) << "EmitStringInteger " << Val << " VT=" << getEnumName(VT)
- << '\n';
+void EmitStringIntegerMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "EmitStringInteger " << Val << " VT=" << getEnumName(VT)
+ << '\n';
}
-void EmitRegisterMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "EmitRegister ";
+void EmitRegisterMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "EmitRegister ";
if (Reg)
OS << Reg->getName();
else
@@ -269,26 +263,26 @@ void EmitRegisterMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
}
void EmitConvertToTargetMatcher::printImpl(raw_ostream &OS,
- unsigned indent) const {
- OS.indent(indent) << "EmitConvertToTarget " << Slot << '\n';
+ indent Indent) const {
+ OS << Indent << "EmitConvertToTarget " << Slot << '\n';
}
void EmitMergeInputChainsMatcher::printImpl(raw_ostream &OS,
- unsigned indent) const {
- OS.indent(indent) << "EmitMergeInputChains <todo: args>\n";
+ indent Indent) const {
+ OS << Indent << "EmitMergeInputChains <todo: args>\n";
}
-void EmitCopyToRegMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "EmitCopyToReg <todo: args>\n";
+void EmitCopyToRegMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "EmitCopyToReg <todo: args>\n";
}
-void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "EmitNodeXForm " << NodeXForm->getName()
- << " Slot=" << Slot << '\n';
+void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "EmitNodeXForm " << NodeXForm->getName() << " Slot=" << Slot
+ << '\n';
}
-void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent);
+void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent;
OS << (isa<MorphNodeToMatcher>(this) ? "MorphNodeTo: " : "EmitNode: ")
<< CGI.Namespace << "::" << CGI.TheDef->getName() << ": <todo flags> ";
@@ -300,10 +294,10 @@ void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, unsigned indent) const {
OS << ")\n";
}
-void CompleteMatchMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "CompleteMatch <todo args>\n";
- OS.indent(indent) << "Src = " << Pattern.getSrcPattern() << "\n";
- OS.indent(indent) << "Dst = " << Pattern.getDstPattern() << "\n";
+void CompleteMatchMatcher::printImpl(raw_ostream &OS, indent Indent) const {
+ OS << Indent << "CompleteMatch <todo args>\n";
+ OS << Indent << "Src = " << Pattern.getSrcPattern() << "\n";
+ OS << Indent << "Dst = " << Pattern.getDstPattern() << "\n";
}
bool CheckOpcodeMatcher::isEqualImpl(const Matcher *M) const {
diff --git a/llvm/utils/TableGen/Common/DAGISelMatcher.h b/llvm/utils/TableGen/Common/DAGISelMatcher.h
index 49dc4726552af6..44ca704a2351e5 100644
--- a/llvm/utils/TableGen/Common/DAGISelMatcher.h
+++ b/llvm/utils/TableGen/Common/DAGISelMatcher.h
@@ -185,12 +185,12 @@ class Matcher {
return Other->isContradictoryImpl(this);
}
- void print(raw_ostream &OS, unsigned indent = 0) const;
+ void print(raw_ostream &OS, indent Indent = indent(0)) const;
void printOne(raw_ostream &OS) const;
void dump() const;
protected:
- virtual void printImpl(raw_ostream &OS, unsigned indent) const = 0;
+ virtual void printImpl(raw_ostream &OS, indent Indent) const = 0;
virtual bool isEqualImpl(const Matcher *M) const = 0;
virtual bool isContradictoryImpl(const Matcher *M) const { return false; }
};
@@ -234,7 +234,7 @@ class ScopeMatcher : public Matcher {
static bool classof(const Matcher *N) { return N->getKind() == Scope; }
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override { return false; }
};
@@ -258,7 +258,7 @@ class RecordMatcher : public Matcher {
static bool classof(const Matcher *N) { return N->getKind() == RecordNode; }
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override { return true; }
};
@@ -289,7 +289,7 @@ class RecordChildMatcher : public Matcher {
static bool classof(const Matcher *N) { return N->getKind() == RecordChild; }
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<RecordChildMatcher>(M)->getChildNo() == getChildNo();
}
@@ -303,7 +303,7 @@ class RecordMemRefMatcher : public Matcher {
static bool classof(const Matcher *N) { return N->getKind() == RecordMemRef; }
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override { return true; }
};
@@ -318,7 +318,7 @@ class CaptureGlueInputMatcher : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override { return true; }
};
@@ -335,7 +335,7 @@ class MoveChildMatcher : public Matcher {
static bool classof(const Matcher *N) { return N->getKind() == MoveChild; }
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<MoveChildMatcher>(M)->getChildNo() == getChildNo();
}
@@ -355,7 +355,7 @@ class MoveSiblingMatcher : public Matcher {
static bool classof(const Matcher *N) { return N->getKind() == MoveSibling; }
private:
- void printImpl(raw_ostream &OS, unsigned Indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<MoveSiblingMatcher>(M)->getSiblingNo() == getSiblingNo();
}
@@ -370,7 +370,7 @@ class MoveParentMatcher : public Matcher {
static bool classof(const Matcher *N) { return N->getKind() == MoveParent; }
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override { return true; }
};
@@ -389,7 +389,7 @@ class CheckSameMatcher : public Matcher {
static bool classof(const Matcher *N) { return N->getKind() == CheckSame; }
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<CheckSameMatcher>(M)->getMatchNumber() == getMatchNumber();
}
@@ -414,7 +414,7 @@ class CheckChildSameMatcher : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<CheckChildSameMatcher>(M)->ChildNo == ChildNo &&
cast<CheckChildSameMatcher>(M)->MatchNumber == MatchNumber;
@@ -438,7 +438,7 @@ class CheckPatternPredicateMatcher : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<CheckPatternPredicateMatcher>(M)->getPredicate() == Predicate;
}
@@ -463,7 +463,7 @@ class CheckPredicateMatcher : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<CheckPredicateMatcher>(M)->Pred == Pred;
}
@@ -483,7 +483,7 @@ class CheckOpcodeMatcher : public Matcher {
static bool classof(const Matcher *N) { return N->getKind() == CheckOpcode; }
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override;
bool isContradictoryImpl(const Matcher *M) const override;
};
@@ -510,7 +510,7 @@ class SwitchOpcodeMatcher : public Matcher {
const Matcher *getCaseMatcher(unsigned i) const { return Cases[i].second; }
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override { return false; }
};
@@ -530,7 +530,7 @@ class CheckTypeMatcher : public Matcher {
static bool classof(const Matcher *N) { return N->getKind() == CheckType; }
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<CheckTypeMatcher>(M)->Type == Type;
}
@@ -559,7 +559,7 @@ class SwitchTypeMatcher : public Matcher {
const Matcher *getCaseMatcher(unsigned i) const { return Cases[i].second; }
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override { return false; }
};
@@ -581,7 +581,7 @@ class CheckChildTypeMatcher : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<CheckChildTypeMatcher>(M)->ChildNo == ChildNo &&
cast<CheckChildTypeMatcher>(M)->Type == Type;
@@ -602,7 +602,7 @@ class CheckIntegerMatcher : public Matcher {
static bool classof(const Matcher *N) { return N->getKind() == CheckInteger; }
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<CheckIntegerMatcher>(M)->Value == Value;
}
@@ -627,7 +627,7 @@ class CheckChildIntegerMatcher : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<CheckChildIntegerMatcher>(M)->ChildNo == ChildNo &&
cast<CheckChildIntegerMatcher>(M)->Value == Value;
@@ -651,7 +651,7 @@ class CheckCondCodeMatcher : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<CheckCondCodeMatcher>(M)->CondCodeName == CondCodeName;
}
@@ -674,7 +674,7 @@ class CheckChild2CondCodeMatcher : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<CheckChild2CondCodeMatcher>(M)->CondCodeName == CondCodeName;
}
@@ -697,7 +697,7 @@ class CheckValueTypeMatcher : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<CheckValueTypeMatcher>(M)->VT == VT;
}
@@ -737,7 +737,7 @@ class CheckComplexPatMatcher : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return &cast<CheckComplexPatMatcher>(M)->Pattern == &Pattern &&
cast<CheckComplexPatMatcher>(M)->MatchNumber == MatchNumber;
@@ -757,7 +757,7 @@ class CheckAndImmMatcher : public Matcher {
static bool classof(const Matcher *N) { return N->getKind() == CheckAndImm; }
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<CheckAndImmMatcher>(M)->Value == Value;
}
@@ -776,7 +776,7 @@ class CheckOrImmMatcher : public Matcher {
static bool classof(const Matcher *N) { return N->getKind() == CheckOrImm; }
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<CheckOrImmMatcher>(M)->Value == Value;
}
@@ -793,7 +793,7 @@ class CheckImmAllOnesVMatcher : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override { return true; }
bool isContradictoryImpl(const Matcher *M) const override;
};
@@ -809,7 +809,7 @@ class CheckImmAllZerosVMatcher : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override { return true; }
bool isContradictoryImpl(const Matcher *M) const override;
};
@@ -825,7 +825,7 @@ class CheckFoldableChainNodeMatcher : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override { return true; }
};
@@ -845,7 +845,7 @@ class EmitIntegerMatcher : public Matcher {
static bool classof(const Matcher *N) { return N->getKind() == EmitInteger; }
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<EmitIntegerMatcher>(M)->Val == Val &&
cast<EmitIntegerMatcher>(M)->VT == VT;
@@ -870,7 +870,7 @@ class EmitStringIntegerMatcher : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<EmitStringIntegerMatcher>(M)->Val == Val &&
cast<EmitStringIntegerMatcher>(M)->VT == VT;
@@ -894,7 +894,7 @@ class EmitRegisterMatcher : public Matcher {
static bool classof(const Matcher *N) { return N->getKind() == EmitRegister; }
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<EmitRegisterMatcher>(M)->Reg == Reg &&
cast<EmitRegisterMatcher>(M)->VT == VT;
@@ -918,7 +918,7 @@ class EmitConvertToTargetMatcher : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<EmitConvertToTargetMatcher>(M)->Slot == Slot;
}
@@ -947,7 +947,7 @@ class EmitMergeInputChainsMatcher : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<EmitMergeInputChainsMatcher>(M)->ChainNodes == ChainNodes;
}
@@ -972,7 +972,7 @@ class EmitCopyToRegMatcher : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<EmitCopyToRegMatcher>(M)->SrcSlot == SrcSlot &&
cast<EmitCopyToRegMatcher>(M)->DestPhysReg == DestPhysReg;
@@ -997,7 +997,7 @@ class EmitNodeXFormMatcher : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<EmitNodeXFormMatcher>(M)->Slot == Slot &&
cast<EmitNodeXFormMatcher>(M)->NodeXForm == NodeXForm;
@@ -1056,7 +1056,7 @@ class EmitNodeMatcherCommon : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override;
};
@@ -1122,7 +1122,7 @@ class CompleteMatchMatcher : public Matcher {
}
private:
- void printImpl(raw_ostream &OS, unsigned indent) const override;
+ void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<CompleteMatchMatcher>(M)->Results == Results &&
&cast<CompleteMatchMatcher>(M)->Pattern == &Pattern;
diff --git a/llvm/utils/TableGen/DAGISelMatcherOpt.cpp b/llvm/utils/TableGen/DAGISelMatcherOpt.cpp
index 224102e49d9891..590786bb7fced3 100644
--- a/llvm/utils/TableGen/DAGISelMatcherOpt.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherOpt.cpp
@@ -310,8 +310,9 @@ static void FactorNodes(std::unique_ptr<Matcher> &InputMatcherPtr) {
if (J != E &&
// Don't print if it's obvious nothing extract could be merged anyway.
std::next(J) != E) {
- LLVM_DEBUG(errs() << "Couldn't merge this:\n"; Optn->print(errs(), 4);
- errs() << "into this:\n"; (*J)->print(errs(), 4);
+ LLVM_DEBUG(errs() << "Couldn't merge this:\n";
+ Optn->print(errs(), indent(4)); errs() << "into this:\n";
+ (*J)->print(errs(), indent(4));
(*std::next(J))->printOne(errs());
if (std::next(J, 2) != E)(*std::next(J, 2))->printOne(errs());
errs() << "\n");
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index b5da37b5134696..7d70edd46fa8b0 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -164,15 +164,15 @@ class DecoderEmitter {
// Emit the decoder state machine table.
void emitTable(formatted_raw_ostream &o, DecoderTable &Table,
- unsigned Indentation, unsigned BitWidth, StringRef Namespace,
+ indent Indentation, unsigned BitWidth, StringRef Namespace,
const EncodingIDsVec &EncodingIDs) const;
void emitInstrLenTable(formatted_raw_ostream &OS,
std::vector<unsigned> &InstrLen) const;
void emitPredicateFunction(formatted_raw_ostream &OS,
PredicateSet &Predicates,
- unsigned Indentation) const;
+ indent Indentation) const;
void emitDecoderFunction(formatted_raw_ostream &OS, DecoderSet &Decoders,
- unsigned Indentation) const;
+ indent Indentation) const;
// run - Output the code emitter
void run(raw_ostream &o);
@@ -524,8 +524,7 @@ class FilterChooser {
// Emits code to check the Predicates member of an instruction are true.
// Returns true if predicate matches were emitted, false otherwise.
- bool emitPredicateMatch(raw_ostream &o, unsigned &Indentation,
- unsigned Opc) const;
+ bool emitPredicateMatch(raw_ostream &OS, unsigned Opc) const;
bool emitPredicateMatchAux(const Init &Val, bool ParenIfBinOp,
raw_ostream &OS) const;
@@ -543,11 +542,11 @@ class FilterChooser {
void emitSingletonTableEntry(DecoderTableInfo &TableInfo,
const Filter &Best) const;
- void emitBinaryParser(raw_ostream &o, unsigned &Indentation,
+ void emitBinaryParser(raw_ostream &OS, indent Indentation,
const OperandInfo &OpInfo,
bool &OpHasCompleteDecoder) const;
- void emitDecoder(raw_ostream &OS, unsigned Indentation, unsigned Opc,
+ void emitDecoder(raw_ostream &OS, indent Indentation, unsigned Opc,
bool &HasCompleteDecoder) const;
unsigned getDecoderIndex(DecoderSet &Decoders, unsigned Opc,
bool &HasCompleteDecoder) const;
@@ -793,7 +792,7 @@ unsigned Filter::usefulness() const {
// Emit the decoder state machine table.
void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
- unsigned Indentation, unsigned BitWidth,
+ indent Indentation, unsigned BitWidth,
StringRef Namespace,
const EncodingIDsVec &EncodingIDs) const {
// We'll need to be able to map from a decoded opcode into the corresponding
@@ -804,8 +803,8 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
for (const auto &EI : EncodingIDs)
OpcodeToEncodingID[EI.Opcode] = EI.EncodingID;
- OS.indent(Indentation) << "static const uint8_t DecoderTable" << Namespace
- << BitWidth << "[] = {\n";
+ OS << Indentation << "static const uint8_t DecoderTable" << Namespace
+ << BitWidth << "[] = {\n";
Indentation += 2;
@@ -852,7 +851,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
PrintFatalError("invalid decode table opcode");
case MCD::OPC_ExtractField: {
++I;
- OS.indent(Indentation) << "MCD::OPC_ExtractField, ";
+ OS << Indentation << "MCD::OPC_ExtractField, ";
// ULEB128 encoded start value.
const char *ErrMsg = nullptr;
@@ -870,7 +869,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
}
case MCD::OPC_FilterValue: {
++I;
- OS.indent(Indentation) << "MCD::OPC_FilterValue, ";
+ OS << Indentation << "MCD::OPC_FilterValue, ";
// The filter value is ULEB128 encoded.
I += emitULEB128(I, OS);
@@ -882,7 +881,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
}
case MCD::OPC_CheckField: {
++I;
- OS.indent(Indentation) << "MCD::OPC_CheckField, ";
+ OS << Indentation << "MCD::OPC_CheckField, ";
// ULEB128 encoded start value.
I += emitULEB128(I, OS);
// 8-bit length.
@@ -899,7 +898,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
}
case MCD::OPC_CheckPredicate: {
++I;
- OS.indent(Indentation) << "MCD::OPC_CheckPredicate, ";
+ OS << Indentation << "MCD::OPC_CheckPredicate, ";
I += emitULEB128(I, OS);
// 24-bit numtoskip value.
@@ -918,8 +917,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
Table.data() + Table.size(), &ErrMsg);
assert(ErrMsg == nullptr && "ULEB128 value too large!");
- OS.indent(Indentation)
- << "MCD::OPC_" << (IsTry ? "Try" : "") << "Decode, ";
+ OS << Indentation << "MCD::OPC_" << (IsTry ? "Try" : "") << "Decode, ";
I += emitULEB128(I, OS);
// Decoder index.
@@ -946,7 +944,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
}
case MCD::OPC_SoftFail: {
++I;
- OS.indent(Indentation) << "MCD::OPC_SoftFail";
+ OS << Indentation << "MCD::OPC_SoftFail";
// Positive mask
uint64_t Value = 0;
unsigned Shift = 0;
@@ -978,16 +976,16 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
}
case MCD::OPC_Fail: {
++I;
- OS.indent(Indentation) << "MCD::OPC_Fail,\n";
+ OS << Indentation << "MCD::OPC_Fail,\n";
break;
}
}
}
- OS.indent(Indentation) << "0\n";
+ OS << Indentation << "0\n";
Indentation -= 2;
- OS.indent(Indentation) << "};\n\n";
+ OS << Indentation << "};\n\n";
}
void DecoderEmitter::emitInstrLenTable(formatted_raw_ostream &OS,
@@ -1001,61 +999,60 @@ void DecoderEmitter::emitInstrLenTable(formatted_raw_ostream &OS,
void DecoderEmitter::emitPredicateFunction(formatted_raw_ostream &OS,
PredicateSet &Predicates,
- unsigned Indentation) const {
+ indent Indentation) const {
// The predicate function is just a big switch statement based on the
// input predicate index.
- OS.indent(Indentation) << "static bool checkDecoderPredicate(unsigned Idx, "
- << "const FeatureBitset &Bits) {\n";
+ OS << Indentation << "static bool checkDecoderPredicate(unsigned Idx, "
+ << "const FeatureBitset &Bits) {\n";
Indentation += 2;
if (!Predicates.empty()) {
- OS.indent(Indentation) << "switch (Idx) {\n";
- OS.indent(Indentation)
- << "default: llvm_unreachable(\"Invalid index!\");\n";
+ OS << Indentation << "switch (Idx) {\n";
+ OS << Indentation << "default: llvm_unreachable(\"Invalid index!\");\n";
unsigned Index = 0;
for (const auto &Predicate : Predicates) {
- OS.indent(Indentation) << "case " << Index++ << ":\n";
- OS.indent(Indentation + 2) << "return (" << Predicate << ");\n";
+ OS << Indentation << "case " << Index++ << ":\n";
+ OS << Indentation + 2 << "return (" << Predicate << ");\n";
}
- OS.indent(Indentation) << "}\n";
+ OS << Indentation << "}\n";
} else {
// No case statement to emit
- OS.indent(Indentation) << "llvm_unreachable(\"Invalid index!\");\n";
+ OS << Indentation << "llvm_unreachable(\"Invalid index!\");\n";
}
Indentation -= 2;
- OS.indent(Indentation) << "}\n\n";
+ OS << Indentation << "}\n\n";
}
void DecoderEmitter::emitDecoderFunction(formatted_raw_ostream &OS,
DecoderSet &Decoders,
- unsigned Indentation) const {
+ indent Indentation) const {
// The decoder function is just a big switch statement based on the
// input decoder index.
- OS.indent(Indentation) << "template <typename InsnType>\n";
- OS.indent(Indentation) << "static DecodeStatus decodeToMCInst(DecodeStatus S,"
- << " unsigned Idx, InsnType insn, MCInst &MI,\n";
- OS.indent(Indentation)
- << " uint64_t "
- << "Address, const MCDisassembler *Decoder, bool &DecodeComplete) {\n";
+ OS << Indentation << "template <typename InsnType>\n";
+ OS << Indentation << "static DecodeStatus decodeToMCInst(DecodeStatus S,"
+ << " unsigned Idx, InsnType insn, MCInst &MI,\n";
+ OS << Indentation << " uint64_t "
+ << "Address, const MCDisassembler *Decoder, bool &DecodeComplete) {\n";
Indentation += 2;
- OS.indent(Indentation) << "DecodeComplete = true;\n";
+ OS << Indentation << "DecodeComplete = true;\n";
// TODO: When InsnType is large, using uint64_t limits all fields to 64 bits
// It would be better for emitBinaryParser to use a 64-bit tmp whenever
// possible but fall back to an InsnType-sized tmp for truly large fields.
- OS.indent(Indentation) << "using TmpType = "
- "std::conditional_t<std::is_integral<InsnType>::"
- "value, InsnType, uint64_t>;\n";
- OS.indent(Indentation) << "TmpType tmp;\n";
- OS.indent(Indentation) << "switch (Idx) {\n";
- OS.indent(Indentation) << "default: llvm_unreachable(\"Invalid index!\");\n";
+ OS << Indentation
+ << "using TmpType = "
+ "std::conditional_t<std::is_integral<InsnType>::"
+ "value, InsnType, uint64_t>;\n";
+ OS << Indentation << "TmpType tmp;\n";
+ OS << Indentation << "switch (Idx) {\n";
+ OS << Indentation << "default: llvm_unreachable(\"Invalid index!\");\n";
unsigned Index = 0;
for (const auto &Decoder : Decoders) {
- OS.indent(Indentation) << "case " << Index++ << ":\n";
+ OS << Indentation << "case " << Index++ << ":\n";
OS << Decoder;
- OS.indent(Indentation + 2) << "return S;\n";
+ OS << Indentation + 2 << "return S;\n";
}
- OS.indent(Indentation) << "}\n";
+ OS << Indentation << "}\n";
Indentation -= 2;
- OS.indent(Indentation) << "}\n";
+ OS << Indentation << "}\n";
}
// Populates the field of the insn given the start position and the number of
@@ -1176,7 +1173,7 @@ unsigned FilterChooser::getIslands(std::vector<unsigned> &StartBits,
return Num;
}
-void FilterChooser::emitBinaryParser(raw_ostream &o, unsigned &Indentation,
+void FilterChooser::emitBinaryParser(raw_ostream &OS, indent Indentation,
const OperandInfo &OpInfo,
bool &OpHasCompleteDecoder) const {
const std::string &Decoder = OpInfo.Decoder;
@@ -1184,39 +1181,38 @@ void FilterChooser::emitBinaryParser(raw_ostream &o, unsigned &Indentation,
bool UseInsertBits = OpInfo.numFields() != 1 || OpInfo.InitValue != 0;
if (UseInsertBits) {
- o.indent(Indentation) << "tmp = 0x";
- o.write_hex(OpInfo.InitValue);
- o << ";\n";
+ OS << Indentation << "tmp = 0x";
+ OS.write_hex(OpInfo.InitValue);
+ OS << ";\n";
}
for (const EncodingField &EF : OpInfo) {
- o.indent(Indentation);
+ OS << Indentation;
if (UseInsertBits)
- o << "insertBits(tmp, ";
+ OS << "insertBits(tmp, ";
else
- o << "tmp = ";
- o << "fieldFromInstruction(insn, " << EF.Base << ", " << EF.Width << ')';
+ OS << "tmp = ";
+ OS << "fieldFromInstruction(insn, " << EF.Base << ", " << EF.Width << ')';
if (UseInsertBits)
- o << ", " << EF.Offset << ", " << EF.Width << ')';
+ OS << ", " << EF.Offset << ", " << EF.Width << ')';
else if (EF.Offset != 0)
- o << " << " << EF.Offset;
- o << ";\n";
+ OS << " << " << EF.Offset;
+ OS << ";\n";
}
if (Decoder != "") {
OpHasCompleteDecoder = OpInfo.HasCompleteDecoder;
- o.indent(Indentation) << "if (!Check(S, " << Decoder
- << "(MI, tmp, Address, Decoder))) { "
- << (OpHasCompleteDecoder ? ""
- : "DecodeComplete = false; ")
- << "return MCDisassembler::Fail; }\n";
+ OS << Indentation << "if (!Check(S, " << Decoder
+ << "(MI, tmp, Address, Decoder))) { "
+ << (OpHasCompleteDecoder ? "" : "DecodeComplete = false; ")
+ << "return MCDisassembler::Fail; }\n";
} else {
OpHasCompleteDecoder = true;
- o.indent(Indentation) << "MI.addOperand(MCOperand::createImm(tmp));\n";
+ OS << Indentation << "MI.addOperand(MCOperand::createImm(tmp));\n";
}
}
-void FilterChooser::emitDecoder(raw_ostream &OS, unsigned Indentation,
+void FilterChooser::emitDecoder(raw_ostream &OS, indent Indentation,
unsigned Opc, bool &HasCompleteDecoder) const {
HasCompleteDecoder = true;
@@ -1224,11 +1220,10 @@ void FilterChooser::emitDecoder(raw_ostream &OS, unsigned Indentation,
// If a custom instruction decoder was specified, use that.
if (Op.numFields() == 0 && !Op.Decoder.empty()) {
HasCompleteDecoder = Op.HasCompleteDecoder;
- OS.indent(Indentation)
- << "if (!Check(S, " << Op.Decoder
- << "(MI, insn, Address, Decoder))) { "
- << (HasCompleteDecoder ? "" : "DecodeComplete = false; ")
- << "return MCDisassembler::Fail; }\n";
+ OS << Indentation << "if (!Check(S, " << Op.Decoder
+ << "(MI, insn, Address, Decoder))) { "
+ << (HasCompleteDecoder ? "" : "DecodeComplete = false; ")
+ << "return MCDisassembler::Fail; }\n";
break;
}
@@ -1246,8 +1241,7 @@ unsigned FilterChooser::getDecoderIndex(DecoderSet &Decoders, unsigned Opc,
// FIXME: emitDecoder() function can take a buffer directly rather than
// a stream.
raw_svector_ostream S(Decoder);
- unsigned I = 4;
- emitDecoder(S, I, Opc, HasCompleteDecoder);
+ emitDecoder(S, indent(4), Opc, HasCompleteDecoder);
// Using the full decoder string as the key value here is a bit
// heavyweight, but is effective. If the string comparisons become a
@@ -1296,8 +1290,7 @@ bool FilterChooser::emitPredicateMatchAux(const Init &Val, bool ParenIfBinOp,
return true;
}
-bool FilterChooser::emitPredicateMatch(raw_ostream &o, unsigned &Indentation,
- unsigned Opc) const {
+bool FilterChooser::emitPredicateMatch(raw_ostream &OS, unsigned Opc) const {
ListInit *Predicates =
AllInstructions[Opc].EncodingDef->getValueAsListInit("Predicates");
bool IsFirstEmission = true;
@@ -1310,9 +1303,9 @@ bool FilterChooser::emitPredicateMatch(raw_ostream &o, unsigned &Indentation,
continue;
if (!IsFirstEmission)
- o << " && ";
+ OS << " && ";
if (emitPredicateMatchAux(*Pred->getValueAsDag("AssemblerCondDag"),
- Predicates->size() > 1, o))
+ Predicates->size() > 1, OS))
PrintFatalError(Pred->getLoc(), "Invalid AssemblerCondDag!");
IsFirstEmission = false;
}
@@ -1358,8 +1351,7 @@ void FilterChooser::emitPredicateTableEntry(DecoderTableInfo &TableInfo,
// FIXME: emitPredicateMatch() functions can take a buffer directly rather
// than a stream.
raw_svector_ostream PS(Predicate);
- unsigned I = 0;
- emitPredicateMatch(PS, I, Opc);
+ emitPredicateMatch(PS, Opc);
// Figure out the index into the predicate table for the predicate just
// computed.
@@ -2630,7 +2622,7 @@ namespace llvm {
TableInfo.Table.push_back(MCD::OPC_Fail);
// Print the table to the output stream.
- emitTable(OS, TableInfo.Table, 0, FC.getBitWidth(), Opc.first.first,
+ emitTable(OS, TableInfo.Table, indent(0), FC.getBitWidth(), Opc.first.first,
Opc.second);
}
@@ -2640,10 +2632,10 @@ namespace llvm {
if (IsVarLenInst)
emitInstrLenTable(OS, InstrLen);
// Emit the predicate function.
- emitPredicateFunction(OS, TableInfo.Predicates, 0);
+ emitPredicateFunction(OS, TableInfo.Predicates, indent(0));
// Emit the decoder function.
- emitDecoderFunction(OS, TableInfo.Decoders, 0);
+ emitDecoderFunction(OS, TableInfo.Decoders, indent(0));
// Emit the main entry point for the decoder, decodeInstruction().
emitDecodeInstruction(OS, IsVarLenInst);
diff --git a/llvm/utils/yaml-bench/YAMLBench.cpp b/llvm/utils/yaml-bench/YAMLBench.cpp
index 50e55538a011cb..4dc6caeb6fdbfc 100644
--- a/llvm/utils/yaml-bench/YAMLBench.cpp
+++ b/llvm/utils/yaml-bench/YAMLBench.cpp
@@ -56,17 +56,6 @@ cl::opt<cl::boolOrDefault>
UseColor("use-color", cl::desc("Emit colored output (default=autodetect)"),
cl::init(cl::BOU_UNSET));
-struct indent {
- unsigned distance;
- indent(unsigned d) : distance(d) {}
-};
-
-static raw_ostream &operator <<(raw_ostream &os, const indent &in) {
- for (unsigned i = 0; i < in.distance; ++i)
- os << " ";
- return os;
-}
-
/// Pretty print a tag by replacing tag:yaml.org,2002: with !!.
static std::string prettyTag(yaml::Node *N) {
std::string Tag = N->getVerbatimTag();
More information about the llvm-commits
mailing list