Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIR] Add spans to all ExprNodes #6860

Merged
merged 2 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions include/tvm/ir/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ using tvm::runtime::String;
*/
class BaseExprNode : public Object {
public:
/*!
* \brief Span that points to the original source code.
* Reserved debug information.
*/
mutable Span span;

static constexpr const char* _type_key = "BaseExpr";
static constexpr const bool _type_has_method_sequal_reduce = true;
static constexpr const bool _type_has_method_shash_reduce = true;
Expand Down Expand Up @@ -135,11 +141,6 @@ class PrimExpr : public BaseExpr {
*/
class RelayExprNode : public BaseExprNode {
public:
/*!
* \brief Span that points to the original source code.
* Reserved debug information.
*/
mutable Span span;
/*!
* \brief Stores the result of type inference(type checking).
*
Expand Down Expand Up @@ -263,8 +264,9 @@ class IntImm : public PrimExpr {
* \brief Constructor.
* \param dtype The data type of the value.
* \param value The internal value.
* \param span The location of this object in the source code.
*/
TVM_DLL IntImm(DataType dtype, int64_t value);
TVM_DLL IntImm(DataType dtype, int64_t value, Span span = Span());

TVM_DEFINE_OBJECT_REF_METHODS(IntImm, PrimExpr, IntImmNode);
};
Expand Down Expand Up @@ -307,8 +309,9 @@ class FloatImm : public PrimExpr {
* \brief Constructor.
* \param dtype The data type of the value.
* \param value The internal value.
* \param span The location in the source code.
*/
TVM_DLL FloatImm(DataType dtype, double value);
TVM_DLL FloatImm(DataType dtype, double value, Span span = Span());

TVM_DEFINE_OBJECT_REF_METHODS(FloatImm, PrimExpr, FloatImmNode);
};
Expand All @@ -321,7 +324,7 @@ class FloatImm : public PrimExpr {
*/
class Bool : public IntImm {
public:
explicit Bool(bool value) : IntImm(DataType::Bool(), value) {}
explicit Bool(bool value, Span span = Span()) : IntImm(DataType::Bool(), value, span) {}
Bool operator!() const { return Bool((*this)->value == 0); }
operator bool() const { return (*this)->value != 0; }

Expand Down Expand Up @@ -358,7 +361,7 @@ class Integer : public IntImm {
/*!
* \brief Construct integer from int value.
*/
Integer(int value) : IntImm(DataType::Int(32), value) {} // NOLINT(*)
Integer(int value, Span span = Span()) : IntImm(DataType::Int(32), value, span) {} // NOLINT(*)
/*!
* \brief Construct integer from int imm.
* \param other The other value.
Expand Down
10 changes: 8 additions & 2 deletions include/tvm/tir/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ class BufferNode : public Object {
int offset_factor;
/*! \brief buffer type */
BufferType buffer_type;
/*!
* \brief Span that points to the original source code.
* Reserved debug information.
*/
mutable Span span;
/*! \brief constructor */
BufferNode() {}

Expand Down Expand Up @@ -135,7 +140,7 @@ class Buffer : public ObjectRef {
// A default value will be picked.
TVM_DLL Buffer(Var ptr, DataType dtype, Array<PrimExpr> shape, Array<PrimExpr> strides,
PrimExpr elem_offset, String name, String scope, int data_alignment,
int offset_factor, BufferType buffer_type);
int offset_factor, BufferType buffer_type, Span span = Span());

/*!
* \brief Return a new buffer that is equivalent with current one
Expand Down Expand Up @@ -183,11 +188,12 @@ class Buffer : public ObjectRef {
* \param shape The shape of the buffer,
* \param dtype The content data type.
* \param name The name of the buffer
* \param span The location of this object in the source code.
* \return The created buffer.
* \sa Buffer for complete constructor.
*/
TVM_DLL Buffer decl_buffer(Array<PrimExpr> shape, DataType dtype = DataType::Float(32),
String name = "buffer");
String name = "buffer", Span span = Span());

/*!
* \brief Base node for data producers.
Expand Down
Loading