Skip to content

Commit

Permalink
[TIR] Add spans to all ExprNodes (apache#6860)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkonolige authored and trevor-m committed Dec 4, 2020
1 parent 366be3e commit 7ee57cd
Show file tree
Hide file tree
Showing 16 changed files with 635 additions and 324 deletions.
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

0 comments on commit 7ee57cd

Please sign in to comment.