WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

internals.scala 7.61 KB
Newer Older
1
2
package uvm.refimpl

Kunshan Wang's avatar
Kunshan Wang committed
3
import uvm._
Kunshan Wang's avatar
Kunshan Wang committed
4
import uvm.FuncSig
Kunshan Wang's avatar
Kunshan Wang committed
5
import uvm.ssavariables._
Kunshan Wang's avatar
Kunshan Wang committed
6
import uvm.types._
Kunshan Wang's avatar
Kunshan Wang committed
7
import uvm.utils.IDFactory
Kunshan Wang's avatar
Kunshan Wang committed
8
import uvm.utils.LazyPool
9
10

object InternalTypes {
11
  import uvm.RichIdentifiedSettable._
Kunshan Wang's avatar
Kunshan Wang committed
12

Kunshan Wang's avatar
Kunshan Wang committed
13
14
  val internalIDFactory = IDFactory.newInternalIDFactory() // IDs from 32768-65535 are for implementation internal use.

Kunshan Wang's avatar
Kunshan Wang committed
15
  def internal(name: MuName): (MuID, MuName) = {
Kunshan Wang's avatar
Kunshan Wang committed
16
    val id = internalIDFactory.getID()
17
18
    val n = "@uvm.internal.types." + name
    (id, n)
Kunshan Wang's avatar
Kunshan Wang committed
19
  }
20
21
22
23
24
  
  val C_INT = TypeInt(32) := internal("c_int")
  val C_CHAR = TypeInt(8) := internal("c_char")
  val C_CHARP = TypeUPtr(C_CHAR) := internal("c_charp")
  val C_CHARPP = TypeUPtr(C_CHARP) := internal("c_charpp")
25

Kunshan Wang's avatar
Kunshan Wang committed
26
27
  val I1 = TypeInt(1) := internal("i1")
  val I6 = TypeInt(6) := internal("i6")
Kunshan Wang's avatar
Kunshan Wang committed
28
29
  val I8 = TypeInt(6) := internal("i8")
  val I16 = TypeInt(6) := internal("i16")
Kunshan Wang's avatar
Kunshan Wang committed
30
  val I32 = TypeInt(32) := internal("i32")
Kunshan Wang's avatar
Kunshan Wang committed
31
32
  val I52 = TypeInt(52) := internal("i52")
  val I64 = TypeInt(52) := internal("i64")
33
  val FLOAT = TypeFloat() := internal("float")
Kunshan Wang's avatar
Kunshan Wang committed
34
  val DOUBLE = TypeDouble() := internal("double")
Kunshan Wang's avatar
Kunshan Wang committed
35
  val VOID = TypeVoid() := internal("void")
Kunshan Wang's avatar
Kunshan Wang committed
36

Kunshan Wang's avatar
Kunshan Wang committed
37
  val BYTE = TypeInt(8) := internal("byte")
Kunshan Wang's avatar
Kunshan Wang committed
38
  val BYTE_ARRAY = TypeHybrid(Seq(), BYTE) := internal("byte_array")
Kunshan Wang's avatar
Kunshan Wang committed
39
40

  val REF_VOID = TypeRef(VOID) := internal("ref_void")
Kunshan Wang's avatar
Kunshan Wang committed
41
  val IREF_VOID = TypeIRef(VOID) := internal("iref_void")
Kunshan Wang's avatar
Kunshan Wang committed
42

Kunshan Wang's avatar
Kunshan Wang committed
43
44
45
46
47
  val SIG_VV = FuncSig(Seq(), Seq()) := internal("sig_vv")
  val FUNCREF_VV = TypeFuncRef(SIG_VV) := internal("funcref_vv")
  
  val STACKREF = TypeStackRef() := internal("stackref")
  val THREADREF = TypeThreadRef() := internal("threadref")
Kunshan Wang's avatar
Kunshan Wang committed
48
  val FRAMECURSORREF = TypeFrameCursorRef() := internal("framecursorref")
Kunshan Wang's avatar
Kunshan Wang committed
49
  val IRBUILDERREF = TypeIRBuilderRef() := internal("irbuilderref")
Kunshan Wang's avatar
Kunshan Wang committed
50
  val TAGREF64 = TypeTagRef64() := internal("tagref64")
Kunshan Wang's avatar
Kunshan Wang committed
51
52
53
54
55

  val BYTES = TypeHybrid(Seq(I64), I8) := (0x260, "@uvm.meta.bytes")
  val BYTES_R = TypeRef(BYTES) := (0x261, "@uvm.meta.bytes_r")
  val REFS = TypeHybrid(Seq(I64), REF_VOID) := (0x262, "@uvm.meta.refs")
  val REFS_R = TypeRef(BYTES) := (0x263, "@uvm.meta.refs_r")
Kunshan Wang's avatar
Kunshan Wang committed
56
57
58
59

  val NULL_REF_VOID = ConstNull(REF_VOID) := internal("null_ref_void")
  val NULL_IREF_VOID = ConstNull(IREF_VOID) := internal("null_iref_void")
  val NULL_FUNCREF_VV = ConstNull(FUNCREF_VV) := internal("null_funcref_vv")
Kunshan Wang's avatar
Kunshan Wang committed
60
61
  val NULL_THREADREF = ConstNull(THREADREF) := internal("null_threadref")
  val NULL_STACKREF = ConstNull(STACKREF) := internal("null_stackref")
62
63
64
}

object InternalTypePool {
65
  val intOf = LazyPool(TypeInt)
Kunshan Wang's avatar
Kunshan Wang committed
66
  val refOf = LazyPool(TypeRef)
Kunshan Wang's avatar
Kunshan Wang committed
67
  val irefOf = LazyPool(TypeIRef)
Kunshan Wang's avatar
Kunshan Wang committed
68
69
70
  val ptrOf = LazyPool(TypeUPtr)
  val funcOf = LazyPool(TypeFuncRef)
  val funcPtrOf = LazyPool(TypeUFuncPtr)
Kunshan Wang's avatar
Kunshan Wang committed
71
  val vecOf = LazyPool[(Type, Long), TypeVector] { case (t, l) => TypeVector(t, l) }
Kunshan Wang's avatar
Kunshan Wang committed
72
73
  def unmarkedOf(t: Type): Type = t match {
    case TypeWeakRef(r) => refOf(r)
74
    case _ => t
Kunshan Wang's avatar
Kunshan Wang committed
75
76
77
78
79
  }
}

object TypeInferer {
  import InternalTypePool._
Kunshan Wang's avatar
Kunshan Wang committed
80
  import InternalTypes._
Kunshan Wang's avatar
Kunshan Wang committed
81

Kunshan Wang's avatar
Kunshan Wang committed
82
83
84
  def ptrOrIRefOf(ptr: Boolean, ty: Type): Type = {
    if (ptr) ptrOf(ty) else irefOf(ty)
  }
Kunshan Wang's avatar
Kunshan Wang committed
85

Kunshan Wang's avatar
Kunshan Wang committed
86
  def inferType(v: SSAVariable): Type = v match {
87
    case c: Constant => c.constTy
Kunshan Wang's avatar
Kunshan Wang committed
88
    case g: GlobalCell => irefOf(g.cellTy)
89
    case f: Function => funcOf(f.sig)
Kunshan Wang's avatar
Kunshan Wang committed
90
    case e: ExposedFunc => funcPtrOf(e.func.sig)
91
92
    case p: NorParam => p.ty
    case p: ExcParam => REF_VOID
Kunshan Wang's avatar
Kunshan Wang committed
93
94
95
96
97
    case r: InstResult => {
      val resTys = inferInstResultTypes(r.inst)
      try {
        resTys(r.index)
      } catch {
Kunshan Wang's avatar
Kunshan Wang committed
98
        case e: IndexOutOfBoundsException => throw new UvmRefImplException(
Kunshan Wang's avatar
Kunshan Wang committed
99
100
101
102
103
104
105
          s"Instruction ${r.inst} produces only ${resTys.size} results, but result index ${r.index} is requested")
      }
    }
  }

  def inferInstResultTypes(inst: Instruction): Seq[Type] = inst match {
    case i: InstBinOp => Seq(i.opndTy)
106
    case i: InstCmp => i.opndTy match {
Kunshan Wang's avatar
Kunshan Wang committed
107
      case TypeVector(_, l) => Seq(vecOf(I1, l))
108
      case _ => Seq(I1)
109
    }
110
111
112
113
114
115
116
117
118
119
120
    case i: InstConv => Seq(i.toTy)
    case i: InstSelect => Seq(i.opndTy)
    case i: InstBranch => Seq()
    case i: InstBranch2 => Seq()
    case i: InstSwitch => Seq()
    case i: InstCall => i.sig.retTys
    case i: InstTailCall => Seq()
    case i: InstRet => Seq()
    case i: InstThrow => Seq()
    case i: InstExtractValue => Seq(i.strTy.fieldTys(i.index))
    case i: InstInsertValue => Seq(i.strTy)
Kunshan Wang's avatar
Kunshan Wang committed
121
    case i: InstExtractElement => Seq(i.seqTy.elemTy)
122
123
124
125
126
127
128
129
130
131
    case i: InstInsertElement => Seq(i.seqTy)
    case i: InstShuffleVector => Seq(vecOf((i.vecTy.elemTy, i.maskTy.len)))
    case i: InstNew => Seq(refOf(i.allocTy))
    case i: InstNewHybrid => Seq(refOf(i.allocTy))
    case i: InstAlloca => Seq(irefOf(i.allocTy))
    case i: InstAllocaHybrid => Seq(irefOf(i.allocTy))
    case i: InstGetIRef => Seq(irefOf(i.referentTy))
    case i: InstGetFieldIRef => Seq(ptrOrIRefOf(i.ptr, i.referentTy.fieldTys(i.index)))
    case i: InstGetElemIRef => Seq(ptrOrIRefOf(i.ptr, i.referentTy.elemTy))
    case i: InstShiftIRef => Seq(ptrOrIRefOf(i.ptr, i.referentTy))
Kunshan Wang's avatar
Kunshan Wang committed
132
    case i: InstGetVarPartIRef => Seq(ptrOrIRefOf(i.ptr, i.referentTy.varTy))
133
134
135
136
137
138
139
140
    case i: InstLoad => Seq(unmarkedOf(i.referentTy))
    case i: InstStore => Seq()
    case i: InstCmpXchg => Seq(unmarkedOf(i.referentTy), I1)
    case i: InstAtomicRMW => Seq(unmarkedOf(i.referentTy))
    case i: InstFence => Seq()
    case i: InstTrap => i.retTys
    case i: InstWatchPoint => i.retTys
    case i: InstCCall => i.sig.retTys
Kunshan Wang's avatar
Kunshan Wang committed
141
    case i: InstNewThread => Seq(THREADREF)
Kunshan Wang's avatar
Kunshan Wang committed
142
143
    case i: InstSwapStack => i.curStackAction match {
      case RetWith(t) => t
Kunshan Wang's avatar
Kunshan Wang committed
144
      case _: KillOld => Seq()
Kunshan Wang's avatar
Kunshan Wang committed
145
146
    }
    case i: InstCommInst => i.inst.name.get match {
Kunshan Wang's avatar
Kunshan Wang committed
147
      case "@uvm.new_stack" => Seq(STACKREF)
148
149
      case "@uvm.kill_stack" => Seq()
      case "@uvm.thread_exit" => Seq()
Kunshan Wang's avatar
Kunshan Wang committed
150
      case "@uvm.current_stack" => Seq(STACKREF)
151
152
      case "@uvm.set_threadlocal" => Seq()
      case "@uvm.get_threadlocal" => Seq(REF_VOID)
153
154
155
156
157
158
159
160
161
162
163
      case "@uvm.tr64.is_fp" => Seq(I1)
      case "@uvm.tr64.is_int" => Seq(I1)
      case "@uvm.tr64.is_ref" => Seq(I1)
      case "@uvm.tr64.from_fp" => Seq(TAGREF64)
      case "@uvm.tr64.from_int" => Seq(TAGREF64)
      case "@uvm.tr64.from_ref" => Seq(TAGREF64)
      case "@uvm.tr64.to_fp" => Seq(DOUBLE)
      case "@uvm.tr64.to_int" => Seq(I52)
      case "@uvm.tr64.to_ref" => Seq(REF_VOID)
      case "@uvm.tr64.to_tag" => Seq(I6)
      case "@uvm.futex.wait" => Seq(I32)
Kunshan Wang's avatar
Kunshan Wang committed
164
      case "@uvm.futex.wait_timeout" => Seq(I32)
165
166
167
      case "@uvm.futex.wake" => Seq(I32)
      case "@uvm.futex.cmp_requeue" => Seq(I32)
      case "@uvm.kill_dependency" => Seq(i.typeList(0))
Kunshan Wang's avatar
Kunshan Wang committed
168
      case "@uvm.native.pin" => i.typeList(0) match {
169
        case TypeRef(t) => Seq(ptrOf(t))
Kunshan Wang's avatar
Kunshan Wang committed
170
        case TypeIRef(t) => Seq(ptrOf(t))
Kunshan Wang's avatar
Kunshan Wang committed
171
      }
172
173
174
175
      case "@uvm.native.unpin" => Seq()
      case "@uvm.native.expose" => Seq(funcPtrOf(i.funcSigList(0)))
      case "@uvm.native.unexpose" => Seq()
      case "@uvm.native.get_cookie" => Seq(I64)
Kunshan Wang's avatar
Kunshan Wang committed
176

177
178
179
180
      case "@uvm.meta.id_of" => Seq(I32)
      case "@uvm.meta.name_of" => Seq(BYTES_R)
      case "@uvm.meta.load_bundle" => Seq(BYTES_R)
      case "@uvm.meta.load_hail" => Seq(BYTES_R)
Kunshan Wang's avatar
Kunshan Wang committed
181

Kunshan Wang's avatar
Kunshan Wang committed
182
183
184
185
186
      case "@uvm.meta.new_cursor" => Seq(FRAMECURSORREF)
      case "@uvm.meta.next_frame" => Seq()
      case "@uvm.meta.copy_cursor" => Seq(FRAMECURSORREF)
      case "@uvm.meta.close_cursor" => Seq()
      
187
188
189
190
      case "@uvm.meta.cur_func" => Seq(I32)
      case "@uvm.meta.cur_func_ver" => Seq(I32)
      case "@uvm.meta.cur_inst" => Seq(I32)
      case "@uvm.meta.dump_keepalives" => Seq(REFS_R)
Kunshan Wang's avatar
Kunshan Wang committed
191

Kunshan Wang's avatar
Kunshan Wang committed
192
      case "@uvm.meta.pop_frames_to" => Seq()
193
      case "@uvm.meta.push_frame" => Seq()
Kunshan Wang's avatar
Kunshan Wang committed
194

Kunshan Wang's avatar
Kunshan Wang committed
195
196
      case "@uvm.meta.enable_watchPoint" => Seq()
      case "@uvm.meta.disable_watchPoint" => Seq()
Kunshan Wang's avatar
Kunshan Wang committed
197

198
      case "@uvm.meta.set_trap_handler" => Seq()
Kunshan Wang's avatar
Kunshan Wang committed
199
200
201
      
      /// GEN:BEGIN:IRBUILDER_RETVALS
      /// GEN:END:IRBUILDER_RETVALS
Kunshan Wang's avatar
Kunshan Wang committed
202
203
    }
  }
204
}