tvm
Classes | Public Types | Static Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
tvm::runtime::relax_vm::Instruction Struct Reference

A single virtual machine instruction. More...

#include <bytecode.h>

Collaboration diagram for tvm::runtime::relax_vm::Instruction:

Classes

class  Arg
 The auxiliary data structure for instruction argument. More...
 

Public Types

enum class  ArgKind : int { kRegister = 0 , kImmediate = 1 , kConstIdx = 2 , kFuncIdx = 3 }
 The kind of instruction's argument. More...
 

Static Public Member Functions

static Instruction Call (Index func_idx, Index num_args, Arg *args, RegName dst)
 Construct a Call instruction. More...
 
static Instruction Ret (RegName result)
 Construct a return instruction. More...
 
static Instruction Goto (RegName pc_offset)
 Construct a goto instruction. More...
 
static Instruction If (RegName cond, Index false_offset)
 Construct an If instruction. More...
 

Public Attributes

Opcode op
 The instruction opcode. More...
 
union {
   struct {
      RegName   dst
 The destination register. More...
 
      Index   func_idx
 The index into the packed function table. More...
 
      Index   num_args
 The number of arguments to the packed function. More...
 
      Arg *   args
 The arguments of the packed function. More...
 
   } 
 
   struct {
      RegName   result
 The return result. More...
 
   } 
 
   struct {
      Index   pc_offset
 The jump offset. More...
 
   } 
 
   struct {
      RegName   cond
 The register containing the cond value. More...
 
      Index   false_offset
 The program counter offset for the false branch. More...
 
   } 
 
}; 
 

Static Public Attributes

static constexpr ExecWord kKindBit = 8
 The number of bit for storing value. More...
 
static constexpr ExecWord kValueBit = sizeof(ExecWord) * 8 - kKindBit
 The number of bit for storing value. More...
 
static constexpr ExecWord kValueMask = (static_cast<ExecWord>(1) << kValueBit) - 1
 The bit mask of the value part. More...
 
static constexpr ExecWord kValueMaxLimit = (static_cast<ExecWord>(1) << (kValueBit - 1)) - 1
 Maximum possible value, use 1 bit for sign. More...
 
static constexpr ExecWord kValueMinLimit = -kValueMaxLimit
 Minimum possible value, remove 1 slot to keep things symmetric. More...
 
static constexpr RegName kBeginSpecialReg = static_cast<ExecWord>(1) << 54
 Beginning of special register section. More...
 
static constexpr RegName kVoidRegister = kBeginSpecialReg + 0
 Random magic number that represents void argument, indicate null value. More...
 
static constexpr RegName kVMRegister = kBeginSpecialReg + 1
 Random magic number that represents the VM context. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const ArgKind &kind)
 

Detailed Description

A single virtual machine instruction.

The representation of the instruction is as a tagged union.

The first field represents which instruction, and by extension which field of the union is active.

Member Enumeration Documentation

◆ ArgKind

The kind of instruction's argument.

Enumerator
kRegister 
kImmediate 
kConstIdx 
kFuncIdx 

Member Function Documentation

◆ Call()

static Instruction tvm::runtime::relax_vm::Instruction::Call ( Index  func_idx,
Index  num_args,
Arg args,
RegName  dst 
)
static

Construct a Call instruction.

Parameters
func_idxThe index of the function to call.
num_argsThe number of arguments.
argsThe input arguments.
dstThe destination register.
Returns
The call instruction.

◆ Goto()

static Instruction tvm::runtime::relax_vm::Instruction::Goto ( RegName  pc_offset)
static

Construct a goto instruction.

Parameters
pc_offsetThe register containing the jump offset.
Returns
The goto instruction.

◆ If()

static Instruction tvm::runtime::relax_vm::Instruction::If ( RegName  cond,
Index  false_offset 
)
static

Construct an If instruction.

Parameters
condThe register containing the cond value.
false_offsetThe program counter offset for the false branch.
Returns
The If instruction.

◆ Ret()

static Instruction tvm::runtime::relax_vm::Instruction::Ret ( RegName  result)
static

Construct a return instruction.

Parameters
resultThe register containing the return value.
Returns
The return instruction.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const ArgKind kind 
)
friend

Member Data Documentation

◆ 

union { ... }

◆ args

Arg* tvm::runtime::relax_vm::Instruction::args

The arguments of the packed function.

◆ cond

RegName tvm::runtime::relax_vm::Instruction::cond

The register containing the cond value.

◆ dst

RegName tvm::runtime::relax_vm::Instruction::dst

The destination register.

◆ false_offset

Index tvm::runtime::relax_vm::Instruction::false_offset

The program counter offset for the false branch.

◆ func_idx

Index tvm::runtime::relax_vm::Instruction::func_idx

The index into the packed function table.

◆ kBeginSpecialReg

constexpr RegName tvm::runtime::relax_vm::Instruction::kBeginSpecialReg = static_cast<ExecWord>(1) << 54
staticconstexpr

Beginning of special register section.

◆ kKindBit

constexpr ExecWord tvm::runtime::relax_vm::Instruction::kKindBit = 8
staticconstexpr

The number of bit for storing value.

◆ kValueBit

constexpr ExecWord tvm::runtime::relax_vm::Instruction::kValueBit = sizeof(ExecWord) * 8 - kKindBit
staticconstexpr

The number of bit for storing value.

◆ kValueMask

constexpr ExecWord tvm::runtime::relax_vm::Instruction::kValueMask = (static_cast<ExecWord>(1) << kValueBit) - 1
staticconstexpr

The bit mask of the value part.

◆ kValueMaxLimit

constexpr ExecWord tvm::runtime::relax_vm::Instruction::kValueMaxLimit = (static_cast<ExecWord>(1) << (kValueBit - 1)) - 1
staticconstexpr

Maximum possible value, use 1 bit for sign.

◆ kValueMinLimit

constexpr ExecWord tvm::runtime::relax_vm::Instruction::kValueMinLimit = -kValueMaxLimit
staticconstexpr

Minimum possible value, remove 1 slot to keep things symmetric.

◆ kVMRegister

constexpr RegName tvm::runtime::relax_vm::Instruction::kVMRegister = kBeginSpecialReg + 1
staticconstexpr

Random magic number that represents the VM context.

◆ kVoidRegister

constexpr RegName tvm::runtime::relax_vm::Instruction::kVoidRegister = kBeginSpecialReg + 0
staticconstexpr

Random magic number that represents void argument, indicate null value.

◆ num_args

Index tvm::runtime::relax_vm::Instruction::num_args

The number of arguments to the packed function.

◆ op

Opcode tvm::runtime::relax_vm::Instruction::op

The instruction opcode.

◆ pc_offset

Index tvm::runtime::relax_vm::Instruction::pc_offset

The jump offset.

◆ result

RegName tvm::runtime::relax_vm::Instruction::result

The return result.


The documentation for this struct was generated from the following file: