2023-01-13 20:36:28 +00:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Luau/Label.h"
|
|
|
|
#include "Luau/RegisterX64.h"
|
|
|
|
#include "Luau/RegisterA64.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2023-01-20 12:02:39 +00:00
|
|
|
struct Proto;
|
|
|
|
|
2023-01-13 20:36:28 +00:00
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
namespace CodeGen
|
|
|
|
{
|
|
|
|
|
2023-02-10 18:50:54 +00:00
|
|
|
// IR instruction command.
|
|
|
|
// In the command description, following abbreviations are used:
|
|
|
|
// * Rn - VM stack register slot, n in 0..254
|
|
|
|
// * Kn - VM proto constant slot, n in 0..2^23-1
|
|
|
|
// * UPn - VM function upvalue slot, n in 0..254
|
|
|
|
// * A, B, C, D, E are instruction arguments
|
2023-01-13 20:36:28 +00:00
|
|
|
enum class IrCmd : uint8_t
|
|
|
|
{
|
|
|
|
NOP,
|
|
|
|
|
2023-02-10 18:50:54 +00:00
|
|
|
// Load a tag from TValue
|
|
|
|
// A: Rn or Kn
|
2023-01-13 20:36:28 +00:00
|
|
|
LOAD_TAG,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Load a pointer (*) from TValue
|
|
|
|
// A: Rn or Kn
|
2023-01-13 20:36:28 +00:00
|
|
|
LOAD_POINTER,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Load a double number from TValue
|
|
|
|
// A: Rn or Kn
|
2023-01-13 20:36:28 +00:00
|
|
|
LOAD_DOUBLE,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Load an int from TValue
|
|
|
|
// A: Rn
|
2023-01-13 20:36:28 +00:00
|
|
|
LOAD_INT,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Load a TValue from memory
|
|
|
|
// A: Rn or Kn or pointer (TValue)
|
2023-01-13 20:36:28 +00:00
|
|
|
LOAD_TVALUE,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Load a TValue from table node value
|
|
|
|
// A: pointer (LuaNode)
|
2023-01-13 20:36:28 +00:00
|
|
|
LOAD_NODE_VALUE_TV, // TODO: we should find a way to generalize LOAD_TVALUE
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Load current environment table
|
2023-01-13 20:36:28 +00:00
|
|
|
LOAD_ENV,
|
|
|
|
|
2023-02-10 18:50:54 +00:00
|
|
|
// Get pointer (TValue) to table array at index
|
|
|
|
// A: pointer (Table)
|
|
|
|
// B: unsigned int
|
2023-01-13 20:36:28 +00:00
|
|
|
GET_ARR_ADDR,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Get pointer (LuaNode) to table node element at the active cached slot index
|
|
|
|
// A: pointer (Table)
|
2023-01-13 20:36:28 +00:00
|
|
|
GET_SLOT_NODE_ADDR,
|
|
|
|
|
2023-02-10 18:50:54 +00:00
|
|
|
// Store a tag into TValue
|
|
|
|
// A: Rn
|
|
|
|
// B: tag
|
2023-01-13 20:36:28 +00:00
|
|
|
STORE_TAG,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Store a pointer (*) into TValue
|
|
|
|
// A: Rn
|
|
|
|
// B: pointer
|
2023-01-13 20:36:28 +00:00
|
|
|
STORE_POINTER,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Store a double number into TValue
|
|
|
|
// A: Rn
|
|
|
|
// B: double
|
2023-01-13 20:36:28 +00:00
|
|
|
STORE_DOUBLE,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Store an int into TValue
|
|
|
|
// A: Rn
|
|
|
|
// B: int
|
2023-01-13 20:36:28 +00:00
|
|
|
STORE_INT,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Store a TValue into memory
|
|
|
|
// A: Rn or pointer (TValue)
|
|
|
|
// B: TValue
|
2023-01-13 20:36:28 +00:00
|
|
|
STORE_TVALUE,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Store a TValue into table node value
|
|
|
|
// A: pointer (LuaNode)
|
|
|
|
// B: TValue
|
2023-01-13 20:36:28 +00:00
|
|
|
STORE_NODE_VALUE_TV, // TODO: we should find a way to generalize STORE_TVALUE
|
|
|
|
|
2023-02-10 18:50:54 +00:00
|
|
|
// Add/Sub two integers together
|
|
|
|
// A, B: int
|
2023-01-13 20:36:28 +00:00
|
|
|
ADD_INT,
|
|
|
|
SUB_INT,
|
|
|
|
|
2023-02-10 18:50:54 +00:00
|
|
|
// Add/Sub/Mul/Div/Mod/Pow two double numbers
|
|
|
|
// A, B: double
|
|
|
|
// In final x64 lowering, B can also be Rn or Kn
|
2023-01-13 20:36:28 +00:00
|
|
|
ADD_NUM,
|
|
|
|
SUB_NUM,
|
|
|
|
MUL_NUM,
|
|
|
|
DIV_NUM,
|
|
|
|
MOD_NUM,
|
|
|
|
POW_NUM,
|
|
|
|
|
2023-02-10 18:50:54 +00:00
|
|
|
// Negate a double number
|
|
|
|
// A: double
|
2023-01-13 20:36:28 +00:00
|
|
|
UNM_NUM,
|
|
|
|
|
2023-02-10 18:50:54 +00:00
|
|
|
// Compute Luau 'not' operation on destructured TValue
|
|
|
|
// A: tag
|
|
|
|
// B: double
|
2023-01-13 20:36:28 +00:00
|
|
|
NOT_ANY, // TODO: boolean specialization will be useful
|
|
|
|
|
2023-02-10 18:50:54 +00:00
|
|
|
// Unconditional jump
|
|
|
|
// A: block
|
2023-01-13 20:36:28 +00:00
|
|
|
JUMP,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Jump if TValue is truthy
|
|
|
|
// A: Rn
|
|
|
|
// B: block (if true)
|
|
|
|
// C: block (if false)
|
2023-01-13 20:36:28 +00:00
|
|
|
JUMP_IF_TRUTHY,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Jump if TValue is falsy
|
|
|
|
// A: Rn
|
|
|
|
// B: block (if true)
|
|
|
|
// C: block (if false)
|
2023-01-13 20:36:28 +00:00
|
|
|
JUMP_IF_FALSY,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Jump if tags are equal
|
|
|
|
// A, B: tag
|
|
|
|
// C: block (if true)
|
|
|
|
// D: block (if false)
|
2023-01-13 20:36:28 +00:00
|
|
|
JUMP_EQ_TAG,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Jump if two int numbers are equal
|
|
|
|
// A, B: int
|
|
|
|
// C: block (if true)
|
|
|
|
// D: block (if false)
|
|
|
|
JUMP_EQ_INT,
|
|
|
|
|
|
|
|
// Jump if pointers are equal
|
|
|
|
// A, B: pointer (*)
|
|
|
|
// C: block (if true)
|
|
|
|
// D: block (if false)
|
2023-01-13 20:36:28 +00:00
|
|
|
JUMP_EQ_POINTER,
|
|
|
|
|
2023-02-10 18:50:54 +00:00
|
|
|
// Perform a conditional jump based on the result of double comparison
|
|
|
|
// A, B: double
|
|
|
|
// C: condition
|
|
|
|
// D: block (if true)
|
|
|
|
// E: block (if false)
|
2023-01-13 20:36:28 +00:00
|
|
|
JUMP_CMP_NUM,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Perform a conditional jump based on the result of TValue comparison
|
|
|
|
// A, B: Rn
|
|
|
|
// C: condition
|
|
|
|
// D: block (if true)
|
|
|
|
// E: block (if false)
|
2023-01-13 20:36:28 +00:00
|
|
|
JUMP_CMP_ANY,
|
|
|
|
|
2023-02-10 18:50:54 +00:00
|
|
|
// Get table length
|
|
|
|
// A: pointer (Table)
|
2023-01-13 20:36:28 +00:00
|
|
|
TABLE_LEN,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Allocate new table
|
|
|
|
// A: int (array element count)
|
|
|
|
// B: int (node element count)
|
2023-01-13 20:36:28 +00:00
|
|
|
NEW_TABLE,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Duplicate a table
|
|
|
|
// A: pointer (Table)
|
2023-01-13 20:36:28 +00:00
|
|
|
DUP_TABLE,
|
|
|
|
|
2023-02-10 18:50:54 +00:00
|
|
|
// Try to convert a double number into a table index or jump if it's not an integer
|
|
|
|
// A: double
|
|
|
|
// B: block
|
2023-01-13 20:36:28 +00:00
|
|
|
NUM_TO_INDEX,
|
|
|
|
|
2023-02-10 18:50:54 +00:00
|
|
|
// Convert integer into a double number
|
|
|
|
// A: int
|
|
|
|
INT_TO_NUM,
|
|
|
|
|
2023-01-13 20:36:28 +00:00
|
|
|
// Fallback functions
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Perform an arithmetic operation on TValues of any type
|
|
|
|
// A: Rn (where to store the result)
|
|
|
|
// B: Rn (lhs)
|
|
|
|
// C: Rn or Kn (rhs)
|
2023-01-13 20:36:28 +00:00
|
|
|
DO_ARITH,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Get length of a TValue of any type
|
|
|
|
// A: Rn (where to store the result)
|
|
|
|
// B: Rn
|
2023-01-13 20:36:28 +00:00
|
|
|
DO_LEN,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Lookup a value in TValue of any type using a key of any type
|
|
|
|
// A: Rn (where to store the result)
|
|
|
|
// B: Rn
|
|
|
|
// C: Rn or unsigned int (key)
|
2023-01-13 20:36:28 +00:00
|
|
|
GET_TABLE,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Store a value into TValue of any type using a key of any type
|
|
|
|
// A: Rn (value to store)
|
|
|
|
// B: Rn
|
|
|
|
// C: Rn or unsigned int (key)
|
2023-01-13 20:36:28 +00:00
|
|
|
SET_TABLE,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Lookup a value in the environment
|
|
|
|
// A: Rn (where to store the result)
|
|
|
|
// B: unsigned int (import path)
|
2023-01-13 20:36:28 +00:00
|
|
|
GET_IMPORT,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Concatenate multiple TValues
|
|
|
|
// A: Rn (where to store the result)
|
|
|
|
// B: unsigned int (index of the first VM stack slot)
|
|
|
|
// C: unsigned int (number of stack slots to go over)
|
2023-01-13 20:36:28 +00:00
|
|
|
CONCAT,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Load function upvalue into stack slot
|
|
|
|
// A: Rn
|
|
|
|
// B: UPn
|
2023-01-13 20:36:28 +00:00
|
|
|
GET_UPVALUE,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Store TValue from stack slot into a function upvalue
|
|
|
|
// A: UPn
|
|
|
|
// B: Rn
|
2023-01-13 20:36:28 +00:00
|
|
|
SET_UPVALUE,
|
|
|
|
|
2023-02-10 18:50:54 +00:00
|
|
|
// Convert TValues into numbers for a numerical for loop
|
|
|
|
// A: Rn (start)
|
|
|
|
// B: Rn (end)
|
|
|
|
// C: Rn (step)
|
|
|
|
PREPARE_FORN,
|
|
|
|
|
|
|
|
// Guards and checks (these instructions are not block terminators even though they jump to fallback)
|
|
|
|
|
|
|
|
// Guard against tag mismatch
|
|
|
|
// A, B: tag
|
|
|
|
// C: block
|
|
|
|
// In final x64 lowering, A can also be Rn
|
2023-01-13 20:36:28 +00:00
|
|
|
CHECK_TAG,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Guard against readonly table
|
|
|
|
// A: pointer (Table)
|
|
|
|
// B: block
|
2023-01-13 20:36:28 +00:00
|
|
|
CHECK_READONLY,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Guard against table having a metatable
|
|
|
|
// A: pointer (Table)
|
|
|
|
// B: block
|
2023-01-13 20:36:28 +00:00
|
|
|
CHECK_NO_METATABLE,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Guard against executing in unsafe environment
|
|
|
|
// A: block
|
2023-01-13 20:36:28 +00:00
|
|
|
CHECK_SAFE_ENV,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Guard against index overflowing the table array size
|
|
|
|
// A: pointer (Table)
|
|
|
|
// B: block
|
2023-01-13 20:36:28 +00:00
|
|
|
CHECK_ARRAY_SIZE,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Guard against cached table node slot not matching the actual table node slot for a key
|
|
|
|
// A: pointer (LuaNode)
|
|
|
|
// B: Kn
|
|
|
|
// C: block
|
2023-01-13 20:36:28 +00:00
|
|
|
CHECK_SLOT_MATCH,
|
|
|
|
|
|
|
|
// Special operations
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Check interrupt handler
|
|
|
|
// A: unsigned int (pcpos)
|
2023-01-13 20:36:28 +00:00
|
|
|
INTERRUPT,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Check and run GC assist if necessary
|
2023-01-13 20:36:28 +00:00
|
|
|
CHECK_GC,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Handle GC write barrier (forward)
|
|
|
|
// A: pointer (GCObject)
|
|
|
|
// B: Rn (TValue that was written to the object)
|
2023-01-13 20:36:28 +00:00
|
|
|
BARRIER_OBJ,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Handle GC write barrier (backwards) for a write into a table
|
|
|
|
// A: pointer (Table)
|
2023-01-13 20:36:28 +00:00
|
|
|
BARRIER_TABLE_BACK,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Handle GC write barrier (forward) for a write into a table
|
|
|
|
// A: pointer (Table)
|
|
|
|
// B: Rn (TValue that was written to the object)
|
2023-01-13 20:36:28 +00:00
|
|
|
BARRIER_TABLE_FORWARD,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Update savedpc value
|
|
|
|
// A: unsigned int (pcpos)
|
2023-01-13 20:36:28 +00:00
|
|
|
SET_SAVEDPC,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Close open upvalues for registers at specified index or higher
|
|
|
|
// A: Rn (starting register index)
|
2023-01-13 20:36:28 +00:00
|
|
|
CLOSE_UPVALS,
|
|
|
|
|
|
|
|
// While capture is a no-op right now, it might be useful to track register/upvalue lifetimes
|
2023-02-10 18:50:54 +00:00
|
|
|
// A: Rn or UPn
|
|
|
|
// B: boolean (true for reference capture, false for value capture)
|
2023-01-13 20:36:28 +00:00
|
|
|
CAPTURE,
|
|
|
|
|
|
|
|
// Operations that don't have an IR representation yet
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Set a list of values to table in target register
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
|
|
|
// B: Rn (target)
|
|
|
|
// C: Rn (source start)
|
|
|
|
// D: int (count or -1 to assign values up to stack top)
|
|
|
|
// E: unsigned int (table index to start from)
|
2023-01-13 20:36:28 +00:00
|
|
|
LOP_SETLIST,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Load function from source register using name into target register and copying source register into target register + 1
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
|
|
|
// B: Rn (target)
|
|
|
|
// C: Rn (source)
|
|
|
|
// D: block (next)
|
|
|
|
// E: block (fallback)
|
2023-01-20 12:02:39 +00:00
|
|
|
LOP_NAMECALL,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Call specified function
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
|
|
|
// B: Rn (function, followed by arguments)
|
|
|
|
// C: int (argument count or -1 to preserve all arguments up to stack top)
|
|
|
|
// D: int (result count or -1 to preserve all results and adjust stack top)
|
|
|
|
// Note: return values are placed starting from Rn specified in 'B'
|
2023-01-13 20:36:28 +00:00
|
|
|
LOP_CALL,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Return specified values from the function
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
|
|
|
// B: Rn (value start)
|
|
|
|
// B: int (result count or -1 to return all values up to stack top)
|
2023-01-13 20:36:28 +00:00
|
|
|
LOP_RETURN,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Perform a fast call of a built-in function
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
|
|
|
// B: Rn (argument start)
|
|
|
|
// C: int (argument count or -1 preserve all arguments up to stack top)
|
|
|
|
// D: block (fallback)
|
|
|
|
// Note: return values are placed starting from Rn specified in 'B'
|
2023-01-13 20:36:28 +00:00
|
|
|
LOP_FASTCALL,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Perform a fast call of a built-in function using 1 register argument
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
|
|
|
// B: Rn (result start)
|
|
|
|
// C: Rn (arg1)
|
|
|
|
// D: block (fallback)
|
2023-01-13 20:36:28 +00:00
|
|
|
LOP_FASTCALL1,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Perform a fast call of a built-in function using 2 register arguments
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
|
|
|
// B: Rn (result start)
|
|
|
|
// C: Rn (arg1)
|
|
|
|
// D: Rn (arg2)
|
|
|
|
// E: block (fallback)
|
2023-01-13 20:36:28 +00:00
|
|
|
LOP_FASTCALL2,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Perform a fast call of a built-in function using 1 register argument and 1 constant argument
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
|
|
|
// B: Rn (result start)
|
|
|
|
// C: Rn (arg1)
|
|
|
|
// D: Kn (arg2)
|
|
|
|
// E: block (fallback)
|
2023-01-13 20:36:28 +00:00
|
|
|
LOP_FASTCALL2K,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
2023-01-13 20:36:28 +00:00
|
|
|
LOP_FORGLOOP,
|
|
|
|
LOP_FORGLOOP_FALLBACK,
|
|
|
|
LOP_FORGPREP_XNEXT_FALLBACK,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Perform `and` or `or` operation (selecting lhs or rhs based on whether the lhs is truthy) and put the result into target register
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
|
|
|
// B: Rn (target)
|
|
|
|
// C: Rn (lhs)
|
|
|
|
// D: Rn or Kn (rhs)
|
2023-01-13 20:36:28 +00:00
|
|
|
LOP_AND,
|
|
|
|
LOP_ANDK,
|
|
|
|
LOP_OR,
|
|
|
|
LOP_ORK,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Increment coverage data (saturating 24 bit add)
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
2023-01-20 12:02:39 +00:00
|
|
|
LOP_COVERAGE,
|
2023-01-13 20:36:28 +00:00
|
|
|
|
|
|
|
// Operations that have a translation, but use a full instruction fallback
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Load a value from global table at specified key
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
|
|
|
// B: Rn (dest)
|
|
|
|
// C: Kn (key)
|
2023-01-13 20:36:28 +00:00
|
|
|
FALLBACK_GETGLOBAL,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Store a value into global table at specified key
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
|
|
|
// B: Rn (value)
|
|
|
|
// C: Kn (key)
|
2023-01-13 20:36:28 +00:00
|
|
|
FALLBACK_SETGLOBAL,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Load a value from table at specified key
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
|
|
|
// B: Rn (dest)
|
|
|
|
// C: Rn (table)
|
|
|
|
// D: Kn (key)
|
2023-01-13 20:36:28 +00:00
|
|
|
FALLBACK_GETTABLEKS,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Store a value into a table at specified key
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
|
|
|
// B: Rn (value)
|
|
|
|
// C: Rn (table)
|
|
|
|
// D: Kn (key)
|
2023-01-13 20:36:28 +00:00
|
|
|
FALLBACK_SETTABLEKS,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Load function from source register using name into target register and copying source register into target register + 1
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
|
|
|
// B: Rn (target)
|
|
|
|
// C: Rn (source)
|
|
|
|
// D: Kn (name)
|
2023-01-20 12:02:39 +00:00
|
|
|
FALLBACK_NAMECALL,
|
2023-01-13 20:36:28 +00:00
|
|
|
|
|
|
|
// Operations that don't have assembly lowering at all
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Prepare stack for variadic functions so that GETVARARGS works correctly
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
|
|
|
// B: int (numparams)
|
2023-01-13 20:36:28 +00:00
|
|
|
FALLBACK_PREPVARARGS,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Copy variables into the target registers from vararg storage for current function
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
|
|
|
// B: Rn (dest start)
|
|
|
|
// C: int (count)
|
2023-01-13 20:36:28 +00:00
|
|
|
FALLBACK_GETVARARGS,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Create closure from a child proto
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
|
|
|
// B: Rn (dest)
|
|
|
|
// C: unsigned int (protoid)
|
2023-01-13 20:36:28 +00:00
|
|
|
FALLBACK_NEWCLOSURE,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Create closure from a pre-created function object (reusing it unless environments diverge)
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
|
|
|
// B: Rn (dest)
|
|
|
|
// C: Kn (prototype)
|
2023-01-13 20:36:28 +00:00
|
|
|
FALLBACK_DUPCLOSURE,
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
// Prepare loop variables for a generic for loop, jump to the loop backedge unconditionally
|
|
|
|
// A: unsigned int (bytecode instruction index)
|
|
|
|
// B: Rn (loop state, updates Rn Rn+1 Rn+2)
|
|
|
|
// B: block
|
2023-01-13 20:36:28 +00:00
|
|
|
FALLBACK_FORGPREP,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class IrConstKind : uint8_t
|
|
|
|
{
|
|
|
|
Bool,
|
|
|
|
Int,
|
|
|
|
Uint,
|
|
|
|
Double,
|
|
|
|
Tag,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct IrConst
|
|
|
|
{
|
|
|
|
IrConstKind kind;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
bool valueBool;
|
|
|
|
int valueInt;
|
|
|
|
unsigned valueUint;
|
|
|
|
double valueDouble;
|
|
|
|
uint8_t valueTag;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class IrCondition : uint8_t
|
|
|
|
{
|
|
|
|
Equal,
|
|
|
|
NotEqual,
|
|
|
|
Less,
|
|
|
|
NotLess,
|
|
|
|
LessEqual,
|
|
|
|
NotLessEqual,
|
|
|
|
Greater,
|
|
|
|
NotGreater,
|
|
|
|
GreaterEqual,
|
|
|
|
NotGreaterEqual,
|
|
|
|
|
|
|
|
UnsignedLess,
|
|
|
|
UnsignedLessEqual,
|
|
|
|
UnsignedGreater,
|
|
|
|
UnsignedGreaterEqual,
|
|
|
|
|
|
|
|
Count
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class IrOpKind : uint32_t
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
|
|
|
|
// To reference a constant value
|
|
|
|
Constant,
|
|
|
|
|
|
|
|
// To specify a condition code
|
|
|
|
Condition,
|
|
|
|
|
|
|
|
// To reference a result of a previous instruction
|
|
|
|
Inst,
|
|
|
|
|
|
|
|
// To reference a basic block in control flow
|
|
|
|
Block,
|
|
|
|
|
|
|
|
// To reference a VM register
|
|
|
|
VmReg,
|
|
|
|
|
|
|
|
// To reference a VM constant
|
|
|
|
VmConst,
|
|
|
|
|
|
|
|
// To reference a VM upvalue
|
|
|
|
VmUpvalue,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct IrOp
|
|
|
|
{
|
|
|
|
IrOpKind kind : 4;
|
|
|
|
uint32_t index : 28;
|
|
|
|
|
|
|
|
IrOp()
|
|
|
|
: kind(IrOpKind::None)
|
|
|
|
, index(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
IrOp(IrOpKind kind, uint32_t index)
|
|
|
|
: kind(kind)
|
|
|
|
, index(index)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static_assert(sizeof(IrOp) == 4);
|
|
|
|
|
|
|
|
struct IrInst
|
|
|
|
{
|
|
|
|
IrCmd cmd;
|
|
|
|
|
|
|
|
// Operands
|
|
|
|
IrOp a;
|
|
|
|
IrOp b;
|
|
|
|
IrOp c;
|
|
|
|
IrOp d;
|
|
|
|
IrOp e;
|
|
|
|
|
|
|
|
uint32_t lastUse = 0;
|
|
|
|
uint16_t useCount = 0;
|
|
|
|
|
|
|
|
// Location of the result (optional)
|
|
|
|
RegisterX64 regX64 = noreg;
|
|
|
|
RegisterA64 regA64{KindA64::none, 0};
|
|
|
|
bool reusedReg = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class IrBlockKind : uint8_t
|
|
|
|
{
|
|
|
|
Bytecode,
|
|
|
|
Fallback,
|
|
|
|
Internal,
|
2023-02-10 18:50:54 +00:00
|
|
|
Dead,
|
2023-01-13 20:36:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct IrBlock
|
|
|
|
{
|
|
|
|
IrBlockKind kind;
|
|
|
|
|
2023-02-10 18:50:54 +00:00
|
|
|
uint16_t useCount = 0;
|
|
|
|
|
2023-01-13 20:36:28 +00:00
|
|
|
// Start points to an instruction index in a stream
|
|
|
|
// End is implicit
|
2023-02-10 18:50:54 +00:00
|
|
|
uint32_t start = ~0u;
|
2023-01-13 20:36:28 +00:00
|
|
|
|
|
|
|
Label label;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BytecodeMapping
|
|
|
|
{
|
|
|
|
uint32_t irLocation;
|
|
|
|
uint32_t asmLocation;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct IrFunction
|
|
|
|
{
|
|
|
|
std::vector<IrBlock> blocks;
|
|
|
|
std::vector<IrInst> instructions;
|
|
|
|
std::vector<IrConst> constants;
|
|
|
|
|
|
|
|
std::vector<BytecodeMapping> bcMapping;
|
2023-01-20 12:02:39 +00:00
|
|
|
|
|
|
|
Proto* proto = nullptr;
|
2023-02-10 18:50:54 +00:00
|
|
|
|
|
|
|
IrBlock& blockOp(IrOp op)
|
|
|
|
{
|
|
|
|
LUAU_ASSERT(op.kind == IrOpKind::Block);
|
|
|
|
return blocks[op.index];
|
|
|
|
}
|
|
|
|
|
|
|
|
IrInst& instOp(IrOp op)
|
|
|
|
{
|
|
|
|
LUAU_ASSERT(op.kind == IrOpKind::Inst);
|
|
|
|
return instructions[op.index];
|
|
|
|
}
|
|
|
|
|
|
|
|
IrConst& constOp(IrOp op)
|
|
|
|
{
|
|
|
|
LUAU_ASSERT(op.kind == IrOpKind::Constant);
|
|
|
|
return constants[op.index];
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t tagOp(IrOp op)
|
|
|
|
{
|
|
|
|
IrConst& value = constOp(op);
|
|
|
|
|
|
|
|
LUAU_ASSERT(value.kind == IrConstKind::Tag);
|
|
|
|
return value.valueTag;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool boolOp(IrOp op)
|
|
|
|
{
|
|
|
|
IrConst& value = constOp(op);
|
|
|
|
|
|
|
|
LUAU_ASSERT(value.kind == IrConstKind::Bool);
|
|
|
|
return value.valueBool;
|
|
|
|
}
|
|
|
|
|
|
|
|
int intOp(IrOp op)
|
|
|
|
{
|
|
|
|
IrConst& value = constOp(op);
|
|
|
|
|
|
|
|
LUAU_ASSERT(value.kind == IrConstKind::Int);
|
|
|
|
return value.valueInt;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned uintOp(IrOp op)
|
|
|
|
{
|
|
|
|
IrConst& value = constOp(op);
|
|
|
|
|
|
|
|
LUAU_ASSERT(value.kind == IrConstKind::Uint);
|
|
|
|
return value.valueUint;
|
|
|
|
}
|
|
|
|
|
|
|
|
double doubleOp(IrOp op)
|
|
|
|
{
|
|
|
|
IrConst& value = constOp(op);
|
|
|
|
|
|
|
|
LUAU_ASSERT(value.kind == IrConstKind::Double);
|
|
|
|
return value.valueDouble;
|
|
|
|
}
|
2023-01-13 20:36:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace CodeGen
|
|
|
|
} // namespace Luau
|