MuCtxIRBuilderPart.scala 26.8 KB
Newer Older
Kunshan Wang's avatar
Kunshan Wang committed
1 2 3
package uvm.refimpl

import uvm._
4 5
import uvm.types._
import uvm.ssavariables._
Kunshan Wang's avatar
Kunshan Wang committed
6
import uvm.refimpl.itpr._
7
import uvm.ir.irbuilder._
Kunshan Wang's avatar
Kunshan Wang committed
8

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
object MuCtxIRBuilderPart {
  implicit def bundleNodeToHandle(bundleNode: BundleNode): MuBundleNode = {
    MuBundleNode(InternalTypes.IRNODEREF, BoxIRNode(Some(bundleNode)))
  }

  implicit def childNodeToHandle[T <: Identified, U <: MuIRNode](childNode: ChildNode[T]): U = childNode.obj match {
    case n: Type        => MuTypeNode(InternalTypes.IRNODEREF, BoxIRNode(Some(childNode))).asInstanceOf[U]
    case n: FuncSig     => MuFuncSigNode(InternalTypes.IRNODEREF, BoxIRNode(Some(childNode))).asInstanceOf[U]
    case n: Constant    => MuConstNode(InternalTypes.IRNODEREF, BoxIRNode(Some(childNode))).asInstanceOf[U]
    case n: GlobalCell  => MuGlobalNode(InternalTypes.IRNODEREF, BoxIRNode(Some(childNode))).asInstanceOf[U]
    case n: Function    => MuFuncNode(InternalTypes.IRNODEREF, BoxIRNode(Some(childNode))).asInstanceOf[U]
    case n: ExposedFunc => MuExpFuncNode(InternalTypes.IRNODEREF, BoxIRNode(Some(childNode))).asInstanceOf[U]
    case n: FuncVer     => MuFuncVerNode(InternalTypes.IRNODEREF, BoxIRNode(Some(childNode))).asInstanceOf[U]
    case n: BasicBlock  => MuBBNode(InternalTypes.IRNODEREF, BoxIRNode(Some(childNode))).asInstanceOf[U]
    case n: NorParam    => MuNorParamNode(InternalTypes.IRNODEREF, BoxIRNode(Some(childNode))).asInstanceOf[U]
    case n: ExcParam    => MuExcParamNode(InternalTypes.IRNODEREF, BoxIRNode(Some(childNode))).asInstanceOf[U]
    case n: InstResult  => MuInstResNode(InternalTypes.IRNODEREF, BoxIRNode(Some(childNode))).asInstanceOf[U]
    case n: Instruction => MuInstNode(InternalTypes.IRNODEREF, BoxIRNode(Some(childNode))).asInstanceOf[U]
    case n => {
      throw new UvmRuntimeException("Oops. It looks like a ChildNode is holding an unexpected object. type: %s"
        .format(n.getClass.getName))
    }
  }
  
  implicit def bundleNodeHandleToBundleNode(handle: MuBundleNode): BundleNode = {
    handle.vb.node.get.asInstanceOf[BundleNode]
  }
  
  implicit def childNodeHandleToChildNode[T <: Identified](handle: MuChildNode): ChildNode[T] = {
    handle.vb.node.get.asInstanceOf[ChildNode[T]]
  }
  
  implicit def childNodeHandleToChildNodeMany[T <: Identified](handles: Seq[MuChildNode]): Seq[ChildNode[T]] = {
    handles.map(childNodeHandleToChildNode)
  }

  implicit def childNodeHandleToChildNodeOption[T <: Identified](handles: Option[MuChildNode]): Option[ChildNode[T]] = {
    handles.map(childNodeHandleToChildNode)
  }
}

Kunshan Wang's avatar
Kunshan Wang committed
50 51 52 53
/**
 * Mix-in to MuCtx to support the IR building API.
 */
trait MuCtxIRBuilderPart {
54 55
  import MuCtxIRBuilderPart._

Kunshan Wang's avatar
Kunshan Wang committed
56
  protected def microVM: MicroVM
57

Kunshan Wang's avatar
Kunshan Wang committed
58 59 60
  protected def addHandle[T <: MuValue](h: T): T

  @inline
61
  private def IRNODEREF = InternalTypes.IRNODEREF
62

63
  private def irBuilder = microVM.irBuilder
Kunshan Wang's avatar
Kunshan Wang committed
64 65 66 67 68 69

  def loadBundleFromNode(b: MuBundleNode): Unit = {
    require(!b.isNull, "bundle must not be NULL")
    val bundle = b.bundle
    microVM.addBundle(bundle)
  }
70

Kunshan Wang's avatar
Kunshan Wang committed
71 72 73 74
  def abortBundleNode(b: MuBundleNode): Unit = {
    // no op
  }
  
75 76 77
  // BEGIN: auto-generated code
  def newBundle(): MuBundleNode = {
    addHandle(irBuilder.newBundle())
Kunshan Wang's avatar
Kunshan Wang committed
78
  }
79 80 81 82

  def getNode(b: MuBundleNode, id: Int): MuChildNode = {
    require(!b.isNull, "b must not be NULL")
    irBuilder.getNode(b, id)
Kunshan Wang's avatar
Kunshan Wang committed
83
  }
84 85 86 87 88 89 90 91 92 93 94 95 96

  def getID(b: MuBundleNode, node: MuChildNode): Int = {
    require(!b.isNull, "b must not be NULL")
    require(!node.isNull, "node must not be NULL")
    irBuilder.getID(b, node)
  }

  def setName(b: MuBundleNode, node: MuChildNode, name: String): Unit = {
    require(!b.isNull, "b must not be NULL")
    require(!node.isNull, "node must not be NULL")
    irBuilder.setName(b, node, name)
  }

97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
  def newTypeInt           (b: MuBundleNode, len: Int): MuTypeNode            = {
    require(!b.isNull, "b must not be NULL")
    addHandle(irBuilder.newTypeInt(b, len))
  }

  def newTypeFloat         (b: MuBundleNode):           MuTypeNode          = {
    require(!b.isNull, "b must not be NULL")
    addHandle(irBuilder.newTypeFloat(b))
  }

  def newTypeDouble        (b: MuBundleNode):           MuTypeNode         = {
    require(!b.isNull, "b must not be NULL")
    addHandle(irBuilder.newTypeDouble(b))
  }

  def newTypeUPtr          (b: MuBundleNode):           MuTypeNode           = {
    require(!b.isNull, "b must not be NULL")
    addHandle(irBuilder.newTypeUPtr(b))
  }

  def newTypeUFuncPtr      (b: MuBundleNode):           MuTypeNode       = {
    require(!b.isNull, "b must not be NULL")
    addHandle(irBuilder.newTypeUFuncPtr(b))
  }

  def newTypeVoid          (b: MuBundleNode):           MuTypeNode           = {
    require(!b.isNull, "b must not be NULL")
    addHandle(irBuilder.newTypeVoid(b))
  }

  def newTypeRef           (b: MuBundleNode):           MuTypeNode            = {
    require(!b.isNull, "b must not be NULL")
    addHandle(irBuilder.newTypeRef(b))
  }

  def newTypeIRef          (b: MuBundleNode):           MuTypeNode           = {
    require(!b.isNull, "b must not be NULL")
    addHandle(irBuilder.newTypeIRef(b))
  }

  def newTypeWeakRef       (b: MuBundleNode):           MuTypeNode        = {
    require(!b.isNull, "b must not be NULL")
    addHandle(irBuilder.newTypeWeakRef(b))
  }

  def newTypeFuncRef       (b: MuBundleNode):           MuTypeNode        = {
    require(!b.isNull, "b must not be NULL")
    addHandle(irBuilder.newTypeFuncRef(b))
  }

  def newTypeTagRef64      (b: MuBundleNode):           MuTypeNode       = {
    require(!b.isNull, "b must not be NULL")
    addHandle(irBuilder.newTypeTagRef64(b))
  }

  def newTypeThreadRef     (b: MuBundleNode):           MuTypeNode      = {
    require(!b.isNull, "b must not be NULL")
    addHandle(irBuilder.newTypeThreadRef(b))
  }

  def newTypeStackRef      (b: MuBundleNode):           MuTypeNode       = {
    require(!b.isNull, "b must not be NULL")
    addHandle(irBuilder.newTypeStackRef(b))
  }

162 163 164 165 166
  def newTypeFrameCursorRef(b: MuBundleNode):           MuTypeNode = {
    require(!b.isNull, "b must not be NULL")
    addHandle(irBuilder.newTypeFrameCursorRef(b))
  }

167 168 169 170 171
  def newTypeIRNodeRef     (b: MuBundleNode):           MuTypeNode      = {
    require(!b.isNull, "b must not be NULL")
    addHandle(irBuilder.newTypeIRNodeRef(b))
  }

172 173 174 175 176 177 178 179 180 181 182 183 184
  def newTypeStruct(b: MuBundleNode, fieldTys: Seq[MuTypeNode]):                  MuTypeNode = {
    require(!b.isNull, "b must not be NULL")
    for((n,i) <- fieldTys.zipWithIndex) require(!n.isNull, "fieldTys[%d] must not be NULL".format(i))
    addHandle(irBuilder.newTypeStruct(b, fieldTys))
  }

  def newTypeHybrid(b: MuBundleNode, fixedTys: Seq[MuTypeNode], varTy: MuTypeNode): MuTypeNode = {
    require(!b.isNull, "b must not be NULL")
    for((n,i) <- fixedTys.zipWithIndex) require(!n.isNull, "fixedTys[%d] must not be NULL".format(i))
    require(!varTy.isNull, "varTy must not be NULL")
    addHandle(irBuilder.newTypeHybrid(b, fixedTys, varTy))
  }

185 186 187 188 189 190
  def newTypeArray (b: MuBundleNode, elemTy: MuTypeNode, len: Long):              MuTypeNode  = {
    require(!b.isNull, "b must not be NULL")
    require(!elemTy.isNull, "elemTy must not be NULL")
    addHandle(irBuilder.newTypeArray(b, elemTy, len))
  }

191 192 193 194 195 196
  def newTypeVector(b: MuBundleNode, elemTy: MuTypeNode, len: Long):              MuTypeNode = {
    require(!b.isNull, "b must not be NULL")
    require(!elemTy.isNull, "elemTy must not be NULL")
    addHandle(irBuilder.newTypeVector(b, elemTy, len))
  }

197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
  def setTypeUPtr    (uptr:     MuTypeNode,     ty: MuTypeNode):            Unit = {
    require(!uptr.isNull, "uptr must not be NULL")
    require(!ty.isNull, "ty must not be NULL")
    irBuilder.setTypeUPtr(uptr, ty)
  }

  def setTypeRef     (ref:      MuTypeNode,      ty: MuTypeNode):     Unit = {
    require(!ref.isNull, "ref must not be NULL")
    require(!ty.isNull, "ty must not be NULL")
    irBuilder.setTypeRef(ref, ty)
  }

  def setTypeIRef    (iref:     MuTypeNode,     ty: MuTypeNode):     Unit = {
    require(!iref.isNull, "iref must not be NULL")
    require(!ty.isNull, "ty must not be NULL")
    irBuilder.setTypeIRef(iref, ty)
  }

  def setTypeWeakRef (weakref:  MuTypeNode,  ty: MuTypeNode):     Unit = {
    require(!weakref.isNull, "weakref must not be NULL")
    require(!ty.isNull, "ty must not be NULL")
    irBuilder.setTypeWeakRef(weakref, ty)
  }

  def setTypeUFuncPtr(ufuncptr: MuTypeNode, sig: MuFuncSigNode): Unit = {
222
    require(!ufuncptr.isNull, "ufuncptr must not be NULL")
223
    require(!sig.isNull, "sig must not be NULL")
224 225 226
    irBuilder.setTypeUFuncPtr(ufuncptr, sig)
  }

227 228 229 230 231 232
  def setTypeFuncRef (funcref:  MuTypeNode,  sig: MuFuncSigNode): Unit = {
    require(!funcref.isNull, "funcref must not be NULL")
    require(!sig.isNull, "sig must not be NULL")
    irBuilder.setTypeFuncRef(funcref, sig)
  }

233 234 235 236 237 238 239
  def newFuncSig(b: MuBundleNode, paramTys: Seq[MuTypeNode], retTys: Seq[MuTypeNode]): MuFuncSigNode = {
    require(!b.isNull, "b must not be NULL")
    for((n,i) <- paramTys.zipWithIndex) require(!n.isNull, "paramTys[%d] must not be NULL".format(i))
    for((n,i) <- retTys.zipWithIndex) require(!n.isNull, "retTys[%d] must not be NULL".format(i))
    addHandle(irBuilder.newFuncSig(b, paramTys, retTys))
  }

240 241 242 243 244 245 246 247 248 249 250 251
  def newConstInt   (b: MuBundleNode, ty: MuTypeNode, value: BigInt): MuConstNode    = {
    require(!b.isNull, "b must not be NULL")
    require(!ty.isNull, "ty must not be NULL")
    addHandle(irBuilder.newConstInt(b, ty, value))
  }

  def newConstFloat (b: MuBundleNode, ty: MuTypeNode, value: Float):  MuConstNode  = {
    require(!b.isNull, "b must not be NULL")
    require(!ty.isNull, "ty must not be NULL")
    addHandle(irBuilder.newConstFloat(b, ty, value))
  }

252 253 254 255 256 257
  def newConstDouble(b: MuBundleNode, ty: MuTypeNode, value: Double): MuConstNode = {
    require(!b.isNull, "b must not be NULL")
    require(!ty.isNull, "ty must not be NULL")
    addHandle(irBuilder.newConstDouble(b, ty, value))
  }

258 259 260 261 262 263 264 265 266 267 268 269 270
  def newConstNull  (b: MuBundleNode, ty: MuTypeNode):                MuConstNode   = {
    require(!b.isNull, "b must not be NULL")
    require(!ty.isNull, "ty must not be NULL")
    addHandle(irBuilder.newConstNull(b, ty))
  }

  def newConstSeq   (b: MuBundleNode, ty: MuTypeNode, elems: Seq[MuConstNode]): MuConstNode = {
    require(!b.isNull, "b must not be NULL")
    require(!ty.isNull, "ty must not be NULL")
    for((n,i) <- elems.zipWithIndex) require(!n.isNull, "elems[%d] must not be NULL".format(i))
    addHandle(irBuilder.newConstSeq(b, ty, elems))
  }

271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
  def newGlobalCell(b: MuBundleNode, ty: MuTypeNode): MuGlobalNode = {
    require(!b.isNull, "b must not be NULL")
    require(!ty.isNull, "ty must not be NULL")
    addHandle(irBuilder.newGlobalCell(b, ty))
  }

  def newFunc(b: MuBundleNode, sig: MuFuncSigNode): MuFuncNode = {
    require(!b.isNull, "b must not be NULL")
    require(!sig.isNull, "sig must not be NULL")
    addHandle(irBuilder.newFunc(b, sig))
  }

  def newFuncVer(b: MuBundleNode, func: MuFuncNode): MuFuncVerNode = {
    require(!b.isNull, "b must not be NULL")
    require(!func.isNull, "func must not be NULL")
    addHandle(irBuilder.newFuncVer(b, func))
  }

  def newExpFunc(b: MuBundleNode, func: MuFuncNode, callconv: Flag, cookie: MuConstNode): MuExpFuncNode = {
    require(!b.isNull, "b must not be NULL")
    require(!func.isNull, "func must not be NULL")
    require(!cookie.isNull, "cookie must not be NULL")
    addHandle(irBuilder.newExpFunc(b, func, callconv, cookie))
  }

  def newBB(fv: MuFuncVerNode): MuBBNode = {
    require(!fv.isNull, "fv must not be NULL")
    addHandle(irBuilder.newBB(fv))
  }

  def newNorParam(bb: MuBBNode, ty: MuTypeNode): MuNorParamNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!ty.isNull, "ty must not be NULL")
    addHandle(irBuilder.newNorParam(bb, ty))
  }

  def newExcParam(bb: MuBBNode): MuExcParamNode = {
    require(!bb.isNull, "bb must not be NULL")
    addHandle(irBuilder.newExcParam(bb))
  }

  def newInstRes(inst: MuInstNode): MuInstResNode = {
    require(!inst.isNull, "inst must not be NULL")
    addHandle(irBuilder.newInstRes(inst))
  }

  def addDest(inst: MuInstNode, kind: DestKind.Value, bb: MuBBNode, vars: Seq[MuVarNode]): Unit = {
    require(!inst.isNull, "inst must not be NULL")
    require(!bb.isNull, "bb must not be NULL")
    for((n,i) <- vars.zipWithIndex) require(!n.isNull, "vars[%d] must not be NULL".format(i))
    irBuilder.addDest(inst, kind, bb, vars)
  }

  def addKeepAlives(inst: MuInstNode, lvs: Seq[MuLocalVarNode]): Unit = {
    require(!inst.isNull, "inst must not be NULL")
    for((n,i) <- lvs.zipWithIndex) require(!n.isNull, "lvs[%d] must not be NULL".format(i))
    irBuilder.addKeepAlives(inst, lvs)
  }

  def newBinOp(bb: MuBBNode, optr: BinOptr.Value, ty: MuTypeNode, opnd1: MuVarNode, opnd2: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!ty.isNull, "ty must not be NULL")
    require(!opnd1.isNull, "opnd1 must not be NULL")
    require(!opnd2.isNull, "opnd2 must not be NULL")
    addHandle(irBuilder.newBinOp(bb, optr, ty, opnd1, opnd2))
  }

  def newCmp(bb: MuBBNode, optr: CmpOptr.Value, ty: MuTypeNode, opnd1: MuVarNode, opnd2: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!ty.isNull, "ty must not be NULL")
    require(!opnd1.isNull, "opnd1 must not be NULL")
    require(!opnd2.isNull, "opnd2 must not be NULL")
    addHandle(irBuilder.newCmp(bb, optr, ty, opnd1, opnd2))
  }

  def newConv(bb: MuBBNode, optr: ConvOptr.Value, fromTy: MuTypeNode, toTy: MuTypeNode, opnd: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!fromTy.isNull, "fromTy must not be NULL")
    require(!toTy.isNull, "toTy must not be NULL")
    require(!opnd.isNull, "opnd must not be NULL")
    addHandle(irBuilder.newConv(bb, optr, fromTy, toTy, opnd))
  }

  def newSelect(bb: MuBBNode, condTy: MuTypeNode, opndTy: MuTypeNode, cond: MuVarNode, ifTrue: MuVarNode, ifFalse: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!condTy.isNull, "condTy must not be NULL")
    require(!opndTy.isNull, "opndTy must not be NULL")
    require(!cond.isNull, "cond must not be NULL")
    require(!ifTrue.isNull, "ifTrue must not be NULL")
    require(!ifFalse.isNull, "ifFalse must not be NULL")
    addHandle(irBuilder.newSelect(bb, condTy, opndTy, cond, ifTrue, ifFalse))
  }

  def newBranch(bb: MuBBNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    addHandle(irBuilder.newBranch(bb))
  }

  def newBranch2(bb: MuBBNode, cond: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!cond.isNull, "cond must not be NULL")
    addHandle(irBuilder.newBranch2(bb, cond))
  }

  def newSwitch(bb: MuBBNode, opndTy: MuTypeNode, opnd: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!opndTy.isNull, "opndTy must not be NULL")
    require(!opnd.isNull, "opnd must not be NULL")
    addHandle(irBuilder.newSwitch(bb, opndTy, opnd))
  }

  def addSwitchDest(inst: MuInstNode, key: MuVarNode, bb: MuBBNode, vars: Seq[MuVarNode]): Unit = {
    require(!inst.isNull, "inst must not be NULL")
    require(!key.isNull, "key must not be NULL")
    require(!bb.isNull, "bb must not be NULL")
    for((n,i) <- vars.zipWithIndex) require(!n.isNull, "vars[%d] must not be NULL".format(i))
    irBuilder.addSwitchDest(inst, key, bb, vars)
  }

  def newCall(bb: MuBBNode, sig: MuFuncSigNode, callee: MuVarNode, args: Seq[MuVarNode]): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!sig.isNull, "sig must not be NULL")
    require(!callee.isNull, "callee must not be NULL")
    for((n,i) <- args.zipWithIndex) require(!n.isNull, "args[%d] must not be NULL".format(i))
    addHandle(irBuilder.newCall(bb, sig, callee, args))
  }

  def newTailCall(bb: MuBBNode, sig: MuFuncSigNode, callee: MuVarNode, args: Seq[MuVarNode]): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!sig.isNull, "sig must not be NULL")
    require(!callee.isNull, "callee must not be NULL")
    for((n,i) <- args.zipWithIndex) require(!n.isNull, "args[%d] must not be NULL".format(i))
    addHandle(irBuilder.newTailCall(bb, sig, callee, args))
  }

  def newRet(bb: MuBBNode, rvs: Seq[MuVarNode]): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    for((n,i) <- rvs.zipWithIndex) require(!n.isNull, "rvs[%d] must not be NULL".format(i))
    addHandle(irBuilder.newRet(bb, rvs))
  }

  def newThrow(bb: MuBBNode, exc: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!exc.isNull, "exc must not be NULL")
    addHandle(irBuilder.newThrow(bb, exc))
  }

  def newExtractValue(bb: MuBBNode, strTy: MuTypeNode, index: Int, opnd: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!strTy.isNull, "strTy must not be NULL")
    require(!opnd.isNull, "opnd must not be NULL")
    addHandle(irBuilder.newExtractValue(bb, strTy, index, opnd))
  }

  def newInsertValue(bb: MuBBNode, strTy: MuTypeNode, index: Int, opnd: MuVarNode, newVal: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!strTy.isNull, "strTy must not be NULL")
    require(!opnd.isNull, "opnd must not be NULL")
    require(!newVal.isNull, "newVal must not be NULL")
    addHandle(irBuilder.newInsertValue(bb, strTy, index, opnd, newVal))
  }

  def newExtractElement(bb: MuBBNode, seqTy: MuTypeNode, indTy: MuTypeNode, opnd: MuVarNode, index: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!seqTy.isNull, "seqTy must not be NULL")
    require(!indTy.isNull, "indTy must not be NULL")
    require(!opnd.isNull, "opnd must not be NULL")
    require(!index.isNull, "index must not be NULL")
    addHandle(irBuilder.newExtractElement(bb, seqTy, indTy, opnd, index))
  }

  def newInsertElement(bb: MuBBNode, seqTy: MuTypeNode, indTy: MuTypeNode, opnd: MuVarNode, index: MuVarNode, newVal: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!seqTy.isNull, "seqTy must not be NULL")
    require(!indTy.isNull, "indTy must not be NULL")
    require(!opnd.isNull, "opnd must not be NULL")
    require(!index.isNull, "index must not be NULL")
    require(!newVal.isNull, "newVal must not be NULL")
    addHandle(irBuilder.newInsertElement(bb, seqTy, indTy, opnd, index, newVal))
  }

  def newShuffleVector(bb: MuBBNode, vecTy: MuTypeNode, maskTy: MuTypeNode, vec1: MuVarNode, vec2: MuVarNode, mask: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!vecTy.isNull, "vecTy must not be NULL")
    require(!maskTy.isNull, "maskTy must not be NULL")
    require(!vec1.isNull, "vec1 must not be NULL")
    require(!vec2.isNull, "vec2 must not be NULL")
    require(!mask.isNull, "mask must not be NULL")
    addHandle(irBuilder.newShuffleVector(bb, vecTy, maskTy, vec1, vec2, mask))
  }

  def newNew(bb: MuBBNode, allocTy: MuTypeNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!allocTy.isNull, "allocTy must not be NULL")
    addHandle(irBuilder.newNew(bb, allocTy))
  }

  def newNewHybrid(bb: MuBBNode, allocTy: MuTypeNode, lenTy: MuTypeNode, len: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!allocTy.isNull, "allocTy must not be NULL")
    require(!lenTy.isNull, "lenTy must not be NULL")
    require(!len.isNull, "len must not be NULL")
    addHandle(irBuilder.newNewHybrid(bb, allocTy, lenTy, len))
  }

  def newAlloca(bb: MuBBNode, allocTy: MuTypeNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!allocTy.isNull, "allocTy must not be NULL")
    addHandle(irBuilder.newAlloca(bb, allocTy))
  }

  def newAllocaHybrid(bb: MuBBNode, allocTy: MuTypeNode, lenTy: MuTypeNode, len: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!allocTy.isNull, "allocTy must not be NULL")
    require(!lenTy.isNull, "lenTy must not be NULL")
    require(!len.isNull, "len must not be NULL")
    addHandle(irBuilder.newAllocaHybrid(bb, allocTy, lenTy, len))
  }

  def newGetIRef(bb: MuBBNode, refTy: MuTypeNode, opnd: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!refTy.isNull, "refTy must not be NULL")
    require(!opnd.isNull, "opnd must not be NULL")
    addHandle(irBuilder.newGetIRef(bb, refTy, opnd))
  }

  def newGetFieldIRef(bb: MuBBNode, isPtr: Boolean, refTy: MuTypeNode, index: Int, opnd: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!refTy.isNull, "refTy must not be NULL")
    require(!opnd.isNull, "opnd must not be NULL")
    addHandle(irBuilder.newGetFieldIRef(bb, isPtr, refTy, index, opnd))
  }

  def newGetElemIRef(bb: MuBBNode, isPtr: Boolean, refTy: MuTypeNode, indTy: MuTypeNode, opnd: MuVarNode, index: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!refTy.isNull, "refTy must not be NULL")
    require(!indTy.isNull, "indTy must not be NULL")
    require(!opnd.isNull, "opnd must not be NULL")
    require(!index.isNull, "index must not be NULL")
    addHandle(irBuilder.newGetElemIRef(bb, isPtr, refTy, indTy, opnd, index))
  }

  def newShiftIRef(bb: MuBBNode, isPtr: Boolean, refTy: MuTypeNode, offTy: MuTypeNode, opnd: MuVarNode, offset: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!refTy.isNull, "refTy must not be NULL")
    require(!offTy.isNull, "offTy must not be NULL")
    require(!opnd.isNull, "opnd must not be NULL")
    require(!offset.isNull, "offset must not be NULL")
    addHandle(irBuilder.newShiftIRef(bb, isPtr, refTy, offTy, opnd, offset))
  }

  def newGetVarPartIRef(bb: MuBBNode, isPtr: Boolean, refTy: MuTypeNode, opnd: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!refTy.isNull, "refTy must not be NULL")
    require(!opnd.isNull, "opnd must not be NULL")
    addHandle(irBuilder.newGetVarPartIRef(bb, isPtr, refTy, opnd))
  }

  def newLoad(bb: MuBBNode, isPtr: Boolean, ord: MemoryOrder.Value, refTy: MuTypeNode, loc: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!refTy.isNull, "refTy must not be NULL")
    require(!loc.isNull, "loc must not be NULL")
    addHandle(irBuilder.newLoad(bb, isPtr, ord, refTy, loc))
  }

  def newStore(bb: MuBBNode, isPtr: Boolean, ord: MemoryOrder.Value, refTy: MuTypeNode, loc: MuVarNode, newVal: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!refTy.isNull, "refTy must not be NULL")
    require(!loc.isNull, "loc must not be NULL")
    require(!newVal.isNull, "newVal must not be NULL")
    addHandle(irBuilder.newStore(bb, isPtr, ord, refTy, loc, newVal))
  }

  def newCmpXchg(bb: MuBBNode, isPtr: Boolean, isWeak: Boolean, ordSucc: MemoryOrder.Value, ordFail: MemoryOrder.Value,
    refTy: MuTypeNode, loc: MuVarNode, expected: MuVarNode, desired: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!refTy.isNull, "refTy must not be NULL")
    require(!loc.isNull, "loc must not be NULL")
    require(!expected.isNull, "expected must not be NULL")
    require(!desired.isNull, "desired must not be NULL")
    addHandle(irBuilder.newCmpXchg(bb, isPtr, isWeak, ordSucc, ordFail, refTy, loc, expected, desired))
  }

  def newAtomicRMW(bb: MuBBNode, isPtr: Boolean, ord: MemoryOrder.Value, optr: AtomicRMWOptr.Value, refTy: MuTypeNode, loc: MuVarNode, opnd: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!refTy.isNull, "refTy must not be NULL")
    require(!loc.isNull, "loc must not be NULL")
    require(!opnd.isNull, "opnd must not be NULL")
    addHandle(irBuilder.newAtomicRMW(bb, isPtr, ord, optr, refTy, loc, opnd))
  }

  def newFence(bb: MuBBNode, ord: MemoryOrder.Value): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    addHandle(irBuilder.newFence(bb, ord))
  }

  def newTrap(bb: MuBBNode, retTys: Seq[MuTypeNode]): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    for((n,i) <- retTys.zipWithIndex) require(!n.isNull, "retTys[%d] must not be NULL".format(i))
    addHandle(irBuilder.newTrap(bb, retTys))
  }

  def newWatchPoint(bb: MuBBNode, wpid: Int, retTys: Seq[MuTypeNode]): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    for((n,i) <- retTys.zipWithIndex) require(!n.isNull, "retTys[%d] must not be NULL".format(i))
    addHandle(irBuilder.newWatchPoint(bb, wpid, retTys))
  }

Kunshan Wang's avatar
Kunshan Wang committed
579 580 581 582 583
  def newWPBranch(bb: MuBBNode, wpid: Int): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    addHandle(irBuilder.newWPBranch(bb, wpid))
  }

584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
  def newCCall(bb: MuBBNode, callConv: Flag, calleeTy: MuTypeNode, sig: MuFuncSigNode, callee: MuVarNode, args: Seq[MuVarNode]): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!calleeTy.isNull, "calleeTy must not be NULL")
    require(!sig.isNull, "sig must not be NULL")
    require(!callee.isNull, "callee must not be NULL")
    for((n,i) <- args.zipWithIndex) require(!n.isNull, "args[%d] must not be NULL".format(i))
    addHandle(irBuilder.newCCall(bb, callConv, calleeTy, sig, callee, args))
  }

  def newNewThread(bb: MuBBNode, stack: MuVarNode, threadLocal: Option[MuVarNode]): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!stack.isNull, "stack must not be NULL")
    addHandle(irBuilder.newNewThread(bb, stack, threadLocal))
  }

  def newSwapStackRet(bb: MuBBNode, swappee: MuVarNode, retTys: Seq[MuTypeNode]): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!swappee.isNull, "swappee must not be NULL")
    for((n,i) <- retTys.zipWithIndex) require(!n.isNull, "retTys[%d] must not be NULL".format(i))
    addHandle(irBuilder.newSwapStackRet(bb, swappee, retTys))
  }

  def newSwapStackKill(bb: MuBBNode, swappee: MuVarNode): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    require(!swappee.isNull, "swappee must not be NULL")
    addHandle(irBuilder.newSwapStackKill(bb, swappee))
  }

  def setNewStackPassValues(inst: MuInstNode, tys: Seq[MuTypeNode], vars: Seq[MuVarNode]): Unit = {
    require(!inst.isNull, "inst must not be NULL")
    for((n,i) <- tys.zipWithIndex) require(!n.isNull, "tys[%d] must not be NULL".format(i))
    for((n,i) <- vars.zipWithIndex) require(!n.isNull, "vars[%d] must not be NULL".format(i))
    irBuilder.setNewStackPassValues(inst, tys, vars)
  }

Kunshan Wang's avatar
Kunshan Wang committed
619 620 621 622 623 624
  def setNewStackThrowExc(inst: MuInstNode, exc: MuVarNode): Unit = {
    require(!inst.isNull, "inst must not be NULL")
    require(!exc.isNull, "exc must not be NULL")
    irBuilder.setNewStackThrowExc(inst, exc)
  }

625 626 627 628 629 630 631 632
  def newCommInst(bb: MuBBNode, opcode: Int, flags: Seq[Flag], tys: Seq[MuTypeNode], sigs: Seq[MuFuncSigNode], args: Seq[MuVarNode]): MuInstNode = {
    require(!bb.isNull, "bb must not be NULL")
    for((n,i) <- tys.zipWithIndex) require(!n.isNull, "tys[%d] must not be NULL".format(i))
    for((n,i) <- sigs.zipWithIndex) require(!n.isNull, "sigs[%d] must not be NULL".format(i))
    for((n,i) <- args.zipWithIndex) require(!n.isNull, "args[%d] must not be NULL".format(i))
    addHandle(irBuilder.newCommInst(bb, opcode, flags, tys, sigs, args))
  }

633 634


635
  // END: auto-generated code
Kunshan Wang's avatar
Kunshan Wang committed
636
}