tqchen commented on pull request #7619:
URL: https://github.com/apache/tvm/pull/7619#issuecomment-797490251


   ```
   struct AllocaScope {
       // tvm use pointer uniqueness so same name is fine
       Var stack_shape_ = Var("stack_shape", DataType::Handle());
       Var stack_array_ = Var("stack_array", DataType::Handle());
       Var stack_value_ = Var("stack_value", DataType::Handle());
       Var stack_tcode_ = Var("stack_tcode", DataType::Handle());
        int64_t max_shape_stack_{-1};
       uint64_t max_array_stack_{0};
        uint64_t max_arg_stack_{0};
   };
   
    Stmt RealizeAlloca(Stmt body) {
       alloca_scope_.emplace_back(AllocaScope());
   
       stmt = this->VisitStmt(stmt);
       auto scope = alloca_scope_.back();
       alloca_scope_.pop_back();
       // create a shape var if any shape is made (including scalar shapes)
       if (scope.max_shape_stack_ != -1) {
         stmt = LetStmt(scope.stack_shape_, StackAlloca("shape", 
max_shape_stack_), stmt);
       }
       if (scope.max_array_stack_ != 0) {
         stmt = LetStmt(scope.stack_array_, StackAlloca("array", 
max_array_stack_), stmt);
       }
       if (scope.max_arg_stack_ != 0) {
         stmt = LetStmt(scope.stack_value_, StackAlloca("arg_value", 
max_arg_stack_), stmt);
         stmt = LetStmt(scope.stack_tcode_, StackAlloca("arg_tcode", 
max_arg_stack_), stmt);
       }
       return stmt;
     }
   ```
   
   And in the functions, update the value using `alloca_scope_.back()`


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to