Skip to content

Commit

Permalink
[TVMScript] Refactor IRDocsifier (#13593)
Browse files Browse the repository at this point in the history
This PR refactors the TVMScript printer and includes the following
changes:
- Consolidate the logics of VarTable into IRDocsifier
- Decouple TracedObject into Object and ObjectPath for less syntactic
  noise
- Restructure the folder to ensure logics and consistency

Some tests removed because the APIs do not exist any more due to the
consolidation.
  • Loading branch information
junrushao authored Jan 8, 2023
1 parent bd37515 commit a99f0c1
Show file tree
Hide file tree
Showing 54 changed files with 2,499 additions and 3,411 deletions.
56 changes: 0 additions & 56 deletions include/tvm/script/printer.h

This file was deleted.

70 changes: 6 additions & 64 deletions include/tvm/script/printer/doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
#include <tvm/ir/expr.h>
#include <tvm/node/node.h>
#include <tvm/runtime/data_type.h>
#include <tvm/script/printer/traced_object.h>

namespace tvm {
namespace script {
namespace printer {

class Doc;

/*!
* \brief The base class of all Doc.
*
Expand Down Expand Up @@ -88,15 +89,6 @@ class ExprDocNode : public DocNode {
*/
ExprDoc Attr(String attr) const;

/*!
* \brief Create a doc representing attribute access on the current ExprDoc
* \param attr The attribute to access.
*
* The ObjectPath of attr will be pushed to the source_path of the returned
* doc.
*/
ExprDoc Attr(TracedObject<String> attr) const;

/*!
* \brief Create a doc representing index access on the current ExprDoc
* \param indices The indices to access.
Expand Down Expand Up @@ -259,83 +251,33 @@ class LiteralDoc : public ExprDoc {
* \brief Create a LiteralDoc to represent None/null/empty value.
*/
static LiteralDoc None() { return LiteralDoc(ObjectRef(nullptr)); }

/*!
* \brief Create a LiteralDoc to represent None/null/empty value.
* \param object_path The source path of the returned Doc.
*/
static LiteralDoc None(ObjectPath object_path) {
return LiteralDoc(ObjectRef(nullptr), object_path);
}

/*!
* \brief Create a LiteralDoc to represent integer.
* \param v The integer value.
*/
static LiteralDoc Int(int v) { return LiteralDoc(IntImm(DataType::Int(64), v)); }

/*!
* \brief Create a LiteralDoc to represent integer.
* \param v The integer value.
*
* The ObjectPath of v will be pushed to the source_path of the returned doc.
*/
static LiteralDoc Int(const TracedObject<IntImm>& v) { return LiteralDoc(v.Get(), v.GetPath()); }

/*!
* \brief Create a LiteralDoc to represent integer.
* \param v The integer value.
*
* The ObjectPath of v will be pushed to the source_path of the returned doc.
*/
static LiteralDoc Int(const TracedBasicValue<int>& v) {
return LiteralDoc(IntImm(DataType::Int(64), v.Get()), v.GetPath());
}
static LiteralDoc Int(int64_t v) { return LiteralDoc(IntImm(DataType::Int(64), v)); }
/*!
* \brief Create a LiteralDoc to represent boolean.
* \param v The boolean value.
*/
static LiteralDoc Boolean(bool v) { return LiteralDoc(IntImm(DataType::Bool(), v)); }

/*!
* \brief Create a LiteralDoc to represent boolean.
* \param v The boolean value.
*
* The ObjectPath of v will be pushed to the source_path of the returned doc.
*/
static LiteralDoc Boolean(const TracedBasicValue<bool>& v) {
return LiteralDoc(IntImm(DataType::Bool(), v.Get()), v.GetPath());
}

/*!
* \brief Create a LiteralDoc to represent float.
* \param v The float value.
*/
static LiteralDoc Float(double v) { return LiteralDoc(FloatImm(DataType::Float(64), v)); }

/*!
* \brief Create a LiteralDoc to represent float.
* \param v The float value.
*
* The ObjectPath of v will be pushed to the source_path of the returned doc.
*/
static LiteralDoc Float(const TracedObject<FloatImm>& v) {
return LiteralDoc(v.Get(), v.GetPath());
}

/*!
* \brief Create a LiteralDoc to represent string.
* \param v The string value.
*/
static LiteralDoc Str(const String& v) { return LiteralDoc(v); }

/*!
* \brief Create a LiteralDoc to represent string.
* \param v The string value.
*
* The ObjectPath of v will be pushed to the source_path of the returned doc.
*/
static LiteralDoc Str(const TracedObject<String>& v) { return LiteralDoc(v.Get(), v.GetPath()); }
static LiteralDoc DataType(const DLDataType& v) {
return LiteralDoc::Str(runtime::DLDataType2String(v));
}

TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(LiteralDoc, ExprDoc, LiteralDocNode);
};
Expand Down
48 changes: 0 additions & 48 deletions include/tvm/script/printer/doc_printer.h

This file was deleted.

140 changes: 0 additions & 140 deletions include/tvm/script/printer/frame.h

This file was deleted.

Loading

0 comments on commit a99f0c1

Please sign in to comment.