GitLab will be upgraded on June 2nd 2020 at 2.00 pm (AEDT) to 3.00 pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to local Gitlab admin team.

Commit ed7707c2 authored by Kunshan Wang's avatar Kunshan Wang

Updated basic data structures.

parent 5230f706
......@@ -165,7 +165,7 @@ instBody
dis=bbName ena=bbName ('WPEXC' '(' wpExc=bbName ')')? keepAliveClause # InstWatchPoint
// Foreign Function Interface
| 'CCALL' '<' type '>' callconv funcCallBody # InstCCall
| 'CCALL' '<' funcTy=type funcSig '>' callconv funcCallBody # InstCCall
// Thread and Stack Operations
| 'NEWSTACK' funcCallBody excClause # InstNewStack
......
package uvm
import uvm.types._
import uvm.ssavalues._
import uvm.ssavariables._
class Bundle {
val typeNs = new SimpleNamespace[Type]()
......
package uvm
import uvm.types._
case class GlobalData(var ty: Type) extends IdentifiedSettable
package uvm.comminsts
import uvm._
case class CommInst(val id: Int, val name: Option[String]) extends Identified
object CommInsts extends SimpleNamespace[CommInst] {
private def commInst(id: Int, name: String) {
val ci = CommInst(id, Some(name))
add(ci)
}
commInst(0x201, "@uvm.new_thread")
commInst(0x202, "@uvm.kill_stack")
commInst(0x203, "@uvm.thread_exit")
commInst(0x204, "@uvm.current_stack")
commInst(0x211, "@uvm.tr64.is_fp")
commInst(0x212, "@uvm.tr64.is_int")
commInst(0x213, "@uvm.tr64.is_ref")
commInst(0x214, "@uvm.tr64.from_fp")
commInst(0x215, "@uvm.tr64.from_int")
commInst(0x216, "@uvm.tr64.from_ref")
commInst(0x217, "@uvm.tr64.to_fp")
commInst(0x218, "@uvm.tr64.to_int")
commInst(0x219, "@uvm.tr64.to_ref")
commInst(0x21a, "@uvm.tr64.to_tag")
commInst(0x220, "@uvm.futex.wait")
commInst(0x221, "@uvm.futex.wake")
}
\ No newline at end of file
package uvm
import uvm.types._
import uvm.ssavalues._
import uvm.ssavariables._
case class FuncSig(var retTy: Type, var paramTy: Seq[Type]) extends IdentifiedSettable
......@@ -10,19 +10,21 @@ object FuncSig {
"%s (%s)".format(sig.retTy.repr, sig.paramTy.map(_.repr).mkString(" "))
}
class Function extends IdentifiedSettable {
class Function extends GlobalVariable {
var sig: FuncSig = null
var cfg: Option[CFG] = None
var versions: Seq[FuncVersion] = Nil
}
class CFG {
/**
* A version of a function. Also known as a "control flow graph".
*/
class FuncVersion extends IdentifiedSettable {
var func: Function = null
var bbs: Seq[BasicBlock] = null
var entry: BasicBlock = null
var params: Seq[Parameter] = null
val bbNs: Namespace[BasicBlock] = new SimpleNamespace[BasicBlock] // Consider using one global bb ns
val lvNs: Namespace[LocalValue] = new SimpleNamespace[LocalValue] // Consider using one global value ns
val bbNs: Namespace[BasicBlock] = new SimpleNamespace[BasicBlock]
}
class BasicBlock extends IdentifiedSettable {
......
package uvm.ifuncs
import uvm._
import uvm.types._
import uvm.types.CommonTypes._
case class IFunc(val id: Int, val name: Option[String], val sig: FuncSig) extends Identified {
def ty = sig.retTy
}
object IFuncs extends SimpleNamespace[IFunc] {
private def addIFunc(id: Int, name: String, retTy: Type, paramTy: Seq[Type]): IFunc = {
val iFunc = IFunc(id, Some(name), FuncSig(retTy, paramTy))
add(iFunc)
return iFunc
}
val UVM_NEW_THREAD = addIFunc(0x201, "@uvm.new_thread", VOID, Seq(THREAD))
val UVM_SWAP_STACK = addIFunc(0x202, "@uvm.swap_stack", VOID, Seq(STACK))
val UVM_KILL_STACK = addIFunc(0x203, "@uvm.kill_stack", VOID, Seq(STACK))
val UVM_SWAP_AND_KILL = addIFunc(0x204, "@uvm.swap_and_kill", VOID, Seq(STACK))
val UVM_THREAD_EXIT = addIFunc(0x205, "@uvm.thread_exit", VOID, Seq(THREAD))
val UVM_MATH_SIN = addIFunc(0x101, "@uvm.math.sin", DOUBLE, Seq(DOUBLE))
}
\ No newline at end of file
......@@ -4,8 +4,8 @@ import scala.collection.JavaConversions._
import uvm._
import uvm.types._
import uvm.ssavalues._
import uvm.ifuncs._
import uvm.ssavariables._
import uvm.comminsts._
import uvm.ir.textinput.gen._
import org.antlr.v4.runtime._
import org.antlr.v4.runtime.tree.TerminalNode
......
This diff is collapsed.
This diff is collapsed.
package uvm.ssavalues
import uvm._
import uvm.types._
import uvm.types.CommonTypes._
import uvm.ifuncs._
abstract class Value extends Identified {
def ty: Type
def resolve() {}
}
// Constants
abstract class GlobalValue extends Value
abstract class DeclaredConstant extends GlobalValue with IdentifiedSettable {
var constTy: Type
def ty = constTy
}
case class ConstInt(var constTy: Type, var num: BigInt) extends DeclaredConstant
case class ConstFloat(var constTy: Type, var num: Float) extends DeclaredConstant
case class ConstDouble(var constTy: Type, var num: Double) extends DeclaredConstant
case class ConstStruct(var constTy: Type, var fields: Seq[GlobalValue]) extends DeclaredConstant
case class ConstNull(var constTy: Type) extends DeclaredConstant
case class ConstFunc(var func: Function) extends GlobalValue {
def ty = func.sig.retTy
override def id: Int = func.id
override def name: Option[String] = func.name
}
case class ConstGlobalData(var gd: GlobalData) extends GlobalValue {
def ty = gd.ty
override def id: Int = gd.id
override def name: Option[String] = gd.name
}
// Local values: Parameter and Instructions
abstract class LocalValue extends Value
case class Parameter(var sig: FuncSig, var index: Int) extends LocalValue with IdentifiedSettable {
def ty = sig.retTy
}
// Instructions
abstract class Instruction extends LocalValue with IdentifiedSettable
/// enumerations
object BinOptr extends Enumeration {
type BinOptr = Value
val ADD, SUB, MUL, UDIV, SDIV, UREM, SREM, SHL, LSHR, ASHR, AND, OR, XOR = Value
val FADD, FSUB, FMUL, FDIV, FREM = Value
}
import BinOptr.BinOptr
object CmpOptr extends Enumeration {
type CmpOptr = Value
val EQ, NE, ULT, ULE, UGT, UGE, SLT, SLE, SGT, SGE = Value
val FTRUE, FFALSE, FORD, FOEQ, FONE, FOLT, FOLE, FOGT, FOGE = Value
val FUNO, FUEQ, FUNE, FULT, FULE, FUGT, FUGE = Value
}
import CmpOptr.CmpOptr
object ConvOptr extends Enumeration {
type ConvOptr = Value
val TRUNC, ZEXT, SEXT, FPTRUNC, FPEXT, FPTOUI, FPTOSI, UITOFP, SITOFP, BITCAST = Value
val REFCAST, IREFCAST, FUNCCAST = Value
}
import ConvOptr.ConvOptr
object MemoryOrdering extends Enumeration {
type MemoryOrdering = Value
val NOT_ATOMIC, UNORDERED, MONOTONIC, ACQUIRE, RELEASE, ACQ_REL, SEQ_CST = Value
}
import MemoryOrdering.MemoryOrdering
object AtomicRMWOptr extends Enumeration {
type AtomicRMWOptr = Value
val XCHG, ADD, SUB, AND, NAND, OR, XOR, MIN, MAX, UMIN, UMAX = Value
}
import AtomicRMWOptr.AtomicRMWOptr
object CallConv extends Enumeration {
type CallConv = Value
val DEFAULT = Value
}
import CallConv.CallConv
/// Abstract instructions and traits
trait HasArgs extends Instruction {
var args: Seq[Value]
}
trait CallLike extends HasArgs {
var sig: FuncSig
var callee: Value
}
trait HasExceptionalDest extends Instruction {
var nor: BasicBlock
var exc: BasicBlock
}
trait HasKeepAlives extends Instruction {
var keepAlives: Seq[Value]
}
abstract class AbstractCall extends HasArgs with CallLike
abstract class NonTailCall extends AbstractCall with HasKeepAlives {
def ty = sig.retTy
}
abstract class AbstractRet extends Instruction {
def ty = VOID
}
abstract class AbstractAlloc extends Instruction {
def allocTy: Type
var ty: Type = null
}
trait ScalarAlloc extends AbstractAlloc {
def allocTy: Type
}
trait HybridAlloc extends AbstractAlloc {
def allocTy: TypeHybrid
def length: Value
}
abstract class HeapAlloc extends AbstractAlloc {
override def resolve() { ty = TypeRef(allocTy) }
}
abstract class StackAlloc extends AbstractAlloc {
override def resolve() { ty = TypeIRef(allocTy) }
}
abstract class WeakRefLoader extends Instruction {
def referentTy: Type
var ty: Type = null
override def resolve() {
referentTy match {
case TypeWeakRef(t) => { ty = TypeRef(t) }
case t => { ty = t }
}
}
}
abstract class AbstractTrap extends HasExceptionalDest with HasKeepAlives {
var retTy: Type
def ty = retTy
}
abstract class AbstractICall extends HasArgs with HasKeepAlives {
var iFunc: IFunc
def ty = iFunc.ty
}
/// Concrete instructions
case class InstBinOp(var op: BinOptr, var opndTy: Type, var op1: Value, var op2: Value) extends Instruction {
def ty = opndTy
}
case class InstCmp(var op: CmpOptr, var opndTy: Type, var op1: Value, var op2: Value) extends Instruction {
def ty = I1
}
case class InstConv(var op: ConvOptr, var fromTy: Type, var toTy: Type, var opnd: Value) extends Instruction {
def ty = toTy
}
case class InstSelect(var opndTy: Type, var cond: Value, var ifTrue: Value, var ifFalse: Value) extends Instruction {
def ty = opndTy
}
case class InstBranch(var dest: BasicBlock) extends Instruction {
def ty = VOID
}
case class InstBranch2(var cond: Value, var ifTrue: BasicBlock, var ifFalse: BasicBlock) extends Instruction {
def ty = VOID
}
case class InstSwitch(var opndTy: Type, var opnd: Value, var defDest: BasicBlock,
var cases: Seq[(Value, BasicBlock)]) extends Instruction {
def ty = VOID
}
case class InstPhi(var opndTy: Type, var cases: Seq[(BasicBlock, Value)]) extends Instruction {
def ty = opndTy
}
case class InstCall(var sig: FuncSig, var callee: Value, var args: Seq[Value],
var keepAlives: Seq[Value]) extends NonTailCall
case class InstInvoke(var sig: FuncSig, var callee: Value, var args: Seq[Value],
var nor: BasicBlock, var exc: BasicBlock, var keepAlives: Seq[Value]) extends NonTailCall with HasExceptionalDest
case class InstTailCall(var sig: FuncSig, var callee: Value, var args: Seq[Value]) extends AbstractCall {
def ty = VOID
}
case class InstRet(var retTy: Type, var retVal: Value) extends AbstractRet
case class InstRetVoid() extends AbstractRet
case class InstThrow(var excVal: Value) extends Instruction {
def ty = VOID
}
case class InstLandingpad() extends Instruction {
def ty = REFVOID
}
case class InstExtractValue(var strTy: TypeStruct, var index: Int, var opnd: Value) extends Instruction {
def ty = strTy.fieldTy(index)
}
case class InstInsertValue(var strTy: TypeStruct, var index: Int, var opnd: Value, var newVal: Value) extends Instruction {
def ty = strTy
}
case class InstNew(var allocTy: Type) extends HeapAlloc with ScalarAlloc
case class InstNewHybrid(var allocTy: TypeHybrid, var length: Value) extends HeapAlloc with HybridAlloc
case class InstAlloca(var allocTy: Type) extends StackAlloc with ScalarAlloc
case class InstAllocaHybrid(var allocTy: TypeHybrid, var length: Value) extends StackAlloc with HybridAlloc
case class InstGetIRef(var referentTy: Type, var opnd: Value) extends Instruction {
var ty: Type = null
override def resolve() { ty = TypeIRef(referentTy) }
}
case class InstGetFieldIRef(var referentTy: TypeStruct, var index: Int, var opnd: Value) extends Instruction {
var ty: Type = null
override def resolve() { ty = TypeIRef(referentTy.fieldTy(index)) }
}
case class InstGetElemIRef(var referentTy: TypeArray, var opnd: Value, var index: Value) extends Instruction {
var ty: Type = null
override def resolve() { ty = TypeIRef(referentTy.elemTy) }
}
case class InstShiftIRef(var referentTy: Type, var opnd: Value, var offset: Value) extends Instruction {
var ty: Type = null
override def resolve() { ty = TypeIRef(referentTy) }
}
case class InstGetFixedPartIRef(var referentTy: TypeHybrid, var opnd: Value) extends Instruction {
var ty: Type = null
override def resolve() { ty = TypeIRef(referentTy.fixedPart) }
}
case class InstGetVarPartIRef(var referentTy: TypeHybrid, var opnd: Value) extends Instruction {
var ty: Type = null
override def resolve() { ty = TypeIRef(referentTy.varPart) }
}
case class InstLoad(var ord: MemoryOrdering, var referentTy: Type, var loc: Value)
extends WeakRefLoader
case class InstStore(var ord: MemoryOrdering, var referentTy: Type, var loc: Value, var newVal: Value) extends Instruction {
def ty = VOID
}
case class InstCmpXchg(var ordSucc: MemoryOrdering, var ordFail: MemoryOrdering,
var referentTy: Type, var loc: Value, var expected: Value, var desired: Value)
extends WeakRefLoader
case class InstFence(var ord: MemoryOrdering) extends Instruction {
def ty = VOID
}
case class InstAtomicRMW(var ord: MemoryOrdering, var op: AtomicRMWOptr,
var referentTy: Type, var loc: Value, var opnd: Value) extends Instruction {
def ty = referentTy
}
case class InstTrap(var retTy: Type, var nor: BasicBlock, var exc: BasicBlock,
var keepAlives: Seq[Value]) extends AbstractTrap
case class InstWatchpoint(var wpID: Int, var retTy: Type, var dis: BasicBlock,
var nor: BasicBlock, var exc: BasicBlock, var keepAlives: Seq[Value]) extends AbstractTrap
case class InstCCall(var callConv: CallConv, var sig: FuncSig, var callee: Value, var args: Seq[Value])
extends CallLike {
def ty = sig.retTy
}
case class InstNewStack(var sig: FuncSig, var callee: Value, var args: Seq[Value]) extends CallLike {
def ty = STACK
}
case class InstICall(var iFunc: IFunc, var args: Seq[Value], var keepAlives: Seq[Value])
extends AbstractICall
case class InstIInvoke(var iFunc: IFunc, var args: Seq[Value],
var nor: BasicBlock, var exc: BasicBlock, var keepAlives: Seq[Value])
extends AbstractICall with HasExceptionalDest
package uvm.ssavariables
import uvm._
import uvm.comminsts._
import uvm.types._
abstract class SSAVariable extends IdentifiedSettable
// Global variables: Constants, Global Cells and Functions (Function is defined in controlFlow.scala)
abstract class GlobalVariable extends SSAVariable
abstract class Constant extends GlobalVariable {
var constTy: Type
}
case class ConstInt(var constTy: Type, var num: BigInt) extends Constant
case class ConstFloat(var constTy: Type, var num: Float) extends Constant
case class ConstDouble(var constTy: Type, var num: Double) extends Constant
case class ConstStruct(var constTy: Type, var fields: Seq[GlobalVariable]) extends Constant
case class ConstNull(var constTy: Type) extends Constant
case class GlobalCell(var cellTy: Type) extends GlobalVariable
// Local variables: Parameters and Instructions
abstract class LocalVariable extends SSAVariable {
var funcVer: FuncVersion = null
}
case class Parameter(override var funcVer: FuncVersion, var index: Int) extends LocalVariable
// Instructions
abstract class Instruction extends LocalVariable
/// enumerations
object BinOptr extends Enumeration {
type BinOptr = Value
val ADD, SUB, MUL, UDIV, SDIV, UREM, SREM, SHL, LSHR, ASHR, AND, OR, XOR = Value
val FADD, FSUB, FMUL, FDIV, FREM = Value
}
import uvm.ssavariables.BinOptr.BinOptr
object CmpOptr extends Enumeration {
type CmpOptr = Value
val EQ, NE, ULT, ULE, UGT, UGE, SLT, SLE, SGT, SGE = Value
val FTRUE, FFALSE, FORD, FOEQ, FONE, FOLT, FOLE, FOGT, FOGE = Value
val FUNO, FUEQ, FUNE, FULT, FULE, FUGT, FUGE = Value
}
import uvm.ssavariables.CmpOptr.CmpOptr
object ConvOptr extends Enumeration {
type ConvOptr = Value
val TRUNC, ZEXT, SEXT, FPTRUNC, FPEXT, FPTOUI, FPTOSI, UITOFP, SITOFP, BITCAST, REFCAST = Value
}
import uvm.ssavariables.ConvOptr.ConvOptr
object MemoryOrder extends Enumeration {
type MemoryOrder = Value
val NOT_ATOMIC, RELAXED, CONSUME, ACQUIRE, RELEASE, ACQ_REL, SEQ_CST = Value
}
import uvm.ssavariables.MemoryOrder.MemoryOrder
object AtomicRMWOptr extends Enumeration {
type AtomicRMWOptr = Value
val XCHG, ADD, SUB, AND, NAND, OR, XOR, MIN, MAX, UMIN, UMAX = Value
}
import uvm.ssavariables.AtomicRMWOptr.AtomicRMWOptr
object CallConv extends Enumeration {
type CallConv = Value
val DEFAULT = Value
}
import uvm.ssavariables.CallConv.CallConv
/// Abstract instructions and traits
trait HasTypeList extends Instruction {
var typeList: Seq[Type]
}
trait HasArgList extends Instruction {
var argList: Seq[SSAVariable]
}
trait CallLike extends HasArgList {
var sig: FuncSig
var callee: SSAVariable
}
case class ExcClause(val nor: BasicBlock, val exc: BasicBlock)
trait HasExcClause extends Instruction {
var excClause: Option[ExcClause]
}
trait HasKeepAliveClause extends Instruction {
var keepAlives: Seq[SSAVariable]
}
abstract class AbstractCall extends CallLike
abstract class AbstractRet extends Instruction
abstract class AbstractAlloc extends Instruction {
def allocTy: Type
}
trait FixedAlloc extends AbstractAlloc
trait HybridAlloc extends AbstractAlloc {
def length: SSAVariable
}
abstract class HeapAlloc extends AbstractAlloc
abstract class StackAlloc extends AbstractAlloc
abstract class AbstractTrap extends HasKeepAliveClause {
var retTy: Type
}
abstract class CurStackAction
case class RetWith(var retTy: Type) extends CurStackAction
case class KillOld() extends CurStackAction
abstract class NewStackAction
case class PassParam(var argTy: Type, var arg: SSAVariable) extends NewStackAction
case class NoParam() extends NewStackAction
case class ThrowExc(var exc: SSAVariable) extends NewStackAction
/// Concrete instructions
case class InstBinOp(var op: BinOptr, var opndTy: Type, var op1: SSAVariable, var op2: SSAVariable,
var excClause: Option[ExcClause]) extends HasExcClause
case class InstCmp(var op: CmpOptr, var opndTy: Type, var op1: SSAVariable, var op2: SSAVariable) extends Instruction
case class InstConv(var op: ConvOptr, var fromTy: Type, var toTy: Type, var opnd: SSAVariable) extends Instruction
case class InstSelect(var opndTy: Type, var condTy: Type,
var cond: SSAVariable, var ifTrue: SSAVariable, var ifFalse: SSAVariable) extends Instruction
case class InstBranch(var dest: BasicBlock) extends Instruction
case class InstBranch2(var cond: SSAVariable, var ifTrue: BasicBlock, var ifFalse: BasicBlock) extends Instruction
case class InstSwitch(var opndTy: Type, var opnd: SSAVariable, var defDest: BasicBlock,
var cases: Seq[(SSAVariable, BasicBlock)]) extends Instruction
case class InstPhi(var opndTy: Type, var cases: Seq[(BasicBlock, SSAVariable)]) extends Instruction
case class InstCall(var sig: FuncSig, var callee: SSAVariable, var argList: Seq[SSAVariable],
var excClause: Option[ExcClause], var keepAlives: Seq[SSAVariable]
) extends AbstractCall with HasExcClause with HasKeepAliveClause
case class InstTailCall(var sig: FuncSig, var callee: SSAVariable, var argList: Seq[SSAVariable]) extends AbstractCall
case class InstRet(var retTy: Type, var retVal: SSAVariable) extends AbstractRet
case class InstRetVoid() extends AbstractRet
case class InstThrow(var excVal: SSAVariable) extends Instruction
case class InstLandingPad() extends Instruction
case class InstExtractValue(var strTy: Type, var index: Int, var opnd: SSAVariable) extends Instruction
case class InstInsertValue(var strTy: Type, var index: Int, var opnd: SSAVariable, var newVal: SSAVariable) extends Instruction
case class InstExtractElement(var vecTy: Type, var indTy: TypeInt,
var opnd: SSAVariable, var index: SSAVariable) extends Instruction
case class InstInsertElement(var vecTy: Type, var indTy: TypeInt,
var opnd: SSAVariable, var index: SSAVariable, var newVal: SSAVariable) extends Instruction
case class InstShuffleVector(var vecTy: Type, var maskTy: Type,
var vec1: SSAVariable, var vec2: SSAVariable, var mask: SSAVariable) extends Instruction
case class InstNew(var allocTy: Type) extends HeapAlloc with FixedAlloc
case class InstNewHybrid(var allocTy: Type, var length: SSAVariable) extends HeapAlloc with HybridAlloc
case class InstAlloca(var allocTy: Type) extends StackAlloc with FixedAlloc
case class InstAllocaHybrid(var allocTy: Type, var length: SSAVariable) extends StackAlloc with HybridAlloc
case class InstGetIRef(var referentTy: Type, var opnd: SSAVariable) extends Instruction
case class InstGetFieldIRef(var referentTy: Type, var index: Int, var opnd: SSAVariable) extends Instruction
case class InstGetElemIRef(var referentTy: Type, var indTy: TypeInt,
var opnd: SSAVariable, var index: SSAVariable) extends Instruction
case class InstShiftIRef(var referentTy: Type, var offTy: TypeInt,
var opnd: SSAVariable, var offset: SSAVariable) extends Instruction
case class InstGetFixedPartIRef(var referentTy: Type, var opnd: SSAVariable) extends Instruction
case class InstGetVarPartIRef(var referentTy: Type, var opnd: SSAVariable) extends Instruction
case class InstLoad(var ord: MemoryOrder, var referentTy: Type, var loc: SSAVariable) extends Instruction
case class InstStore(var ord: MemoryOrder, var referentTy: Type, var loc: SSAVariable, var newVal: SSAVariable) extends Instruction
case class InstCmpXchg(var weak: Boolean, var ordSucc: MemoryOrder, var ordFail: MemoryOrder, var referentTy: Type,
var loc: SSAVariable, var expected: SSAVariable, var desired: SSAVariable) extends Instruction
case class InstFence(var ord: MemoryOrder) extends Instruction
case class InstAtomicRMW(var ord: MemoryOrder, var op: AtomicRMWOptr,
var referentTy: Type, var loc: SSAVariable, var opnd: SSAVariable) extends Instruction
case class InstTrap(var retTy: Type, var excClause: Option[ExcClause], var keepAlives: Seq[SSAVariable]) extends AbstractTrap
case class InstWatchPoint(var wpID: Int, var retTy: Type,
var dis: BasicBlock, var ena: BasicBlock, var exc: Option[BasicBlock],
var keepAlives: Seq[SSAVariable]) extends AbstractTrap
case class InstCCall(var callConv: CallConv, var funcTy: Type,
var sig: FuncSig, var callee: SSAVariable, var argList: Seq[SSAVariable]) extends CallLike
case class InstNewStack(var sig: FuncSig, var callee: SSAVariable, var argList: Seq[SSAVariable