LLVM  15.0.0git
MachineIRBuilder.cpp
Go to the documentation of this file.
1 //===-- llvm/CodeGen/GlobalISel/MachineIRBuilder.cpp - MIBuilder--*- C++ -*-==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 /// This file implements the MachineIRBuidler class.
10 //===----------------------------------------------------------------------===//
21 
22 using namespace llvm;
23 
25  State.MF = &MF;
26  State.MBB = nullptr;
27  State.MRI = &MF.getRegInfo();
28  State.TII = MF.getSubtarget().getInstrInfo();
29  State.DL = DebugLoc();
31  State.Observer = nullptr;
32 }
33 
34 //------------------------------------------------------------------------------
35 // Build instruction variants.
36 //------------------------------------------------------------------------------
37 
39  MachineInstrBuilder MIB = BuildMI(getMF(), getDL(), getTII().get(Opcode));
40  return MIB;
41 }
42 
44  getMBB().insert(getInsertPt(), MIB);
45  recordInsertion(MIB);
46  return MIB;
47 }
48 
51  const MDNode *Expr) {
52  assert(isa<DILocalVariable>(Variable) && "not a variable");
53  assert(cast<DIExpression>(Expr)->isValid() && "not an expression");
54  assert(
55  cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(getDL()) &&
56  "Expected inlined-at fields to agree");
57  return insertInstr(BuildMI(getMF(), getDL(),
58  getTII().get(TargetOpcode::DBG_VALUE),
59  /*IsIndirect*/ false, Reg, Variable, Expr));
60 }
61 
64  const MDNode *Expr) {
65  assert(isa<DILocalVariable>(Variable) && "not a variable");
66  assert(cast<DIExpression>(Expr)->isValid() && "not an expression");
67  assert(
68  cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(getDL()) &&
69  "Expected inlined-at fields to agree");
70  return insertInstr(BuildMI(getMF(), getDL(),
71  getTII().get(TargetOpcode::DBG_VALUE),
72  /*IsIndirect*/ true, Reg, Variable, Expr));
73 }
74 
76  const MDNode *Variable,
77  const MDNode *Expr) {
78  assert(isa<DILocalVariable>(Variable) && "not a variable");
79  assert(cast<DIExpression>(Expr)->isValid() && "not an expression");
80  assert(
81  cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(getDL()) &&
82  "Expected inlined-at fields to agree");
83  return buildInstr(TargetOpcode::DBG_VALUE)
84  .addFrameIndex(FI)
85  .addImm(0)
86  .addMetadata(Variable)
87  .addMetadata(Expr);
88 }
89 
91  const MDNode *Variable,
92  const MDNode *Expr) {
93  assert(isa<DILocalVariable>(Variable) && "not a variable");
94  assert(cast<DIExpression>(Expr)->isValid() && "not an expression");
95  assert(
96  cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(getDL()) &&
97  "Expected inlined-at fields to agree");
98  auto MIB = buildInstrNoInsert(TargetOpcode::DBG_VALUE);
99  if (auto *CI = dyn_cast<ConstantInt>(&C)) {
100  if (CI->getBitWidth() > 64)
101  MIB.addCImm(CI);
102  else
103  MIB.addImm(CI->getZExtValue());
104  } else if (auto *CFP = dyn_cast<ConstantFP>(&C)) {
105  MIB.addFPImm(CFP);
106  } else {
107  // Insert $noreg if we didn't find a usable constant and had to drop it.
108  MIB.addReg(Register());
109  }
110 
111  MIB.addImm(0).addMetadata(Variable).addMetadata(Expr);
112  return insertInstr(MIB);
113 }
114 
116  assert(isa<DILabel>(Label) && "not a label");
117  assert(cast<DILabel>(Label)->isValidLocationForIntrinsic(State.DL) &&
118  "Expected inlined-at fields to agree");
119  auto MIB = buildInstr(TargetOpcode::DBG_LABEL);
120 
121  return MIB.addMetadata(Label);
122 }
123 
125  const SrcOp &Size,
126  Align Alignment) {
127  assert(Res.getLLTTy(*getMRI()).isPointer() && "expected ptr dst type");
128  auto MIB = buildInstr(TargetOpcode::G_DYN_STACKALLOC);
129  Res.addDefToMIB(*getMRI(), MIB);
130  Size.addSrcToMIB(MIB);
131  MIB.addImm(Alignment.value());
132  return MIB;
133 }
134 
136  int Idx) {
137  assert(Res.getLLTTy(*getMRI()).isPointer() && "invalid operand type");
138  auto MIB = buildInstr(TargetOpcode::G_FRAME_INDEX);
139  Res.addDefToMIB(*getMRI(), MIB);
140  MIB.addFrameIndex(Idx);
141  return MIB;
142 }
143 
145  const GlobalValue *GV) {
146  assert(Res.getLLTTy(*getMRI()).isPointer() && "invalid operand type");
148  GV->getType()->getAddressSpace() &&
149  "address space mismatch");
150 
151  auto MIB = buildInstr(TargetOpcode::G_GLOBAL_VALUE);
152  Res.addDefToMIB(*getMRI(), MIB);
153  MIB.addGlobalAddress(GV);
154  return MIB;
155 }
156 
158  unsigned JTI) {
159  return buildInstr(TargetOpcode::G_JUMP_TABLE, {PtrTy}, {})
160  .addJumpTableIndex(JTI);
161 }
162 
163 void MachineIRBuilder::validateUnaryOp(const LLT Res, const LLT Op0) {
164  assert((Res.isScalar() || Res.isVector()) && "invalid operand type");
165  assert((Res == Op0) && "type mismatch");
166 }
167 
168 void MachineIRBuilder::validateBinaryOp(const LLT Res, const LLT Op0,
169  const LLT Op1) {
170  assert((Res.isScalar() || Res.isVector()) && "invalid operand type");
171  assert((Res == Op0 && Res == Op1) && "type mismatch");
172 }
173 
174 void MachineIRBuilder::validateShiftOp(const LLT Res, const LLT Op0,
175  const LLT Op1) {
176  assert((Res.isScalar() || Res.isVector()) && "invalid operand type");
177  assert((Res == Op0) && "type mismatch");
178 }
179 
181  const SrcOp &Op0,
182  const SrcOp &Op1) {
183  assert(Res.getLLTTy(*getMRI()).getScalarType().isPointer() &&
184  Res.getLLTTy(*getMRI()) == Op0.getLLTTy(*getMRI()) && "type mismatch");
185  assert(Op1.getLLTTy(*getMRI()).getScalarType().isScalar() && "invalid offset type");
186 
187  return buildInstr(TargetOpcode::G_PTR_ADD, {Res}, {Op0, Op1});
188 }
189 
192  const LLT ValueTy, uint64_t Value) {
193  assert(Res == 0 && "Res is a result argument");
194  assert(ValueTy.isScalar() && "invalid offset type");
195 
196  if (Value == 0) {
197  Res = Op0;
198  return None;
199  }
200 
202  auto Cst = buildConstant(ValueTy, Value);
203  return buildPtrAdd(Res, Op0, Cst.getReg(0));
204 }
205 
207  const SrcOp &Op0,
208  uint32_t NumBits) {
209  LLT PtrTy = Res.getLLTTy(*getMRI());
210  LLT MaskTy = LLT::scalar(PtrTy.getSizeInBits());
211  Register MaskReg = getMRI()->createGenericVirtualRegister(MaskTy);
212  buildConstant(MaskReg, maskTrailingZeros<uint64_t>(NumBits));
213  return buildPtrMask(Res, Op0, MaskReg);
214 }
215 
218  const SrcOp &Op0) {
219  LLT ResTy = Res.getLLTTy(*getMRI());
220  LLT Op0Ty = Op0.getLLTTy(*getMRI());
221 
222  assert((ResTy.isVector() && Op0Ty.isVector()) && "Non vector type");
223  assert((ResTy.getElementType() == Op0Ty.getElementType()) &&
224  "Different vector element types");
225  assert((ResTy.getNumElements() > Op0Ty.getNumElements()) &&
226  "Op0 has more elements");
227 
228  auto Unmerge = buildUnmerge(Op0Ty.getElementType(), Op0);
230  for (auto Op : Unmerge.getInstr()->defs())
231  Regs.push_back(Op.getReg());
233  unsigned NumberOfPadElts = ResTy.getNumElements() - Regs.size();
234  for (unsigned i = 0; i < NumberOfPadElts; ++i)
235  Regs.push_back(Undef);
236  return buildMerge(Res, Regs);
237 }
238 
241  const SrcOp &Op0) {
242  LLT ResTy = Res.getLLTTy(*getMRI());
243  LLT Op0Ty = Op0.getLLTTy(*getMRI());
244 
245  assert((ResTy.isVector() && Op0Ty.isVector()) && "Non vector type");
246  assert((ResTy.getElementType() == Op0Ty.getElementType()) &&
247  "Different vector element types");
248  assert((ResTy.getNumElements() < Op0Ty.getNumElements()) &&
249  "Op0 has fewer elements");
250 
252  auto Unmerge = buildUnmerge(Op0Ty.getElementType(), Op0);
253  for (unsigned i = 0; i < ResTy.getNumElements(); ++i)
254  Regs.push_back(Unmerge.getReg(i));
255  return buildMerge(Res, Regs);
256 }
257 
259  return buildInstr(TargetOpcode::G_BR).addMBB(&Dest);
260 }
261 
263  assert(getMRI()->getType(Tgt).isPointer() && "invalid branch destination");
264  return buildInstr(TargetOpcode::G_BRINDIRECT).addUse(Tgt);
265 }
266 
268  unsigned JTI,
269  Register IndexReg) {
270  assert(getMRI()->getType(TablePtr).isPointer() &&
271  "Table reg must be a pointer");
272  return buildInstr(TargetOpcode::G_BRJT)
273  .addUse(TablePtr)
274  .addJumpTableIndex(JTI)
275  .addUse(IndexReg);
276 }
277 
279  const SrcOp &Op) {
280  return buildInstr(TargetOpcode::COPY, Res, Op);
281 }
282 
284  const ConstantInt &Val) {
285  LLT Ty = Res.getLLTTy(*getMRI());
286  LLT EltTy = Ty.getScalarType();
287  assert(EltTy.getScalarSizeInBits() == Val.getBitWidth() &&
288  "creating constant with the wrong size");
289 
290  if (Ty.isVector()) {
291  auto Const = buildInstr(TargetOpcode::G_CONSTANT)
292  .addDef(getMRI()->createGenericVirtualRegister(EltTy))
293  .addCImm(&Val);
294  return buildSplatVector(Res, Const);
295  }
296 
297  auto Const = buildInstr(TargetOpcode::G_CONSTANT);
298  Const->setDebugLoc(DebugLoc());
299  Res.addDefToMIB(*getMRI(), Const);
300  Const.addCImm(&Val);
301  return Const;
302 }
303 
305  int64_t Val) {
306  auto IntN = IntegerType::get(getMF().getFunction().getContext(),
308  ConstantInt *CI = ConstantInt::get(IntN, Val, true);
309  return buildConstant(Res, *CI);
310 }
311 
313  const ConstantFP &Val) {
314  LLT Ty = Res.getLLTTy(*getMRI());
315  LLT EltTy = Ty.getScalarType();
316 
318  == EltTy.getSizeInBits() &&
319  "creating fconstant with the wrong size");
320 
321  assert(!Ty.isPointer() && "invalid operand type");
322 
323  if (Ty.isVector()) {
324  auto Const = buildInstr(TargetOpcode::G_FCONSTANT)
325  .addDef(getMRI()->createGenericVirtualRegister(EltTy))
326  .addFPImm(&Val);
327 
328  return buildSplatVector(Res, Const);
329  }
330 
331  auto Const = buildInstr(TargetOpcode::G_FCONSTANT);
332  Const->setDebugLoc(DebugLoc());
333  Res.addDefToMIB(*getMRI(), Const);
334  Const.addFPImm(&Val);
335  return Const;
336 }
337 
339  const APInt &Val) {
340  ConstantInt *CI = ConstantInt::get(getMF().getFunction().getContext(), Val);
341  return buildConstant(Res, *CI);
342 }
343 
345  double Val) {
346  LLT DstTy = Res.getLLTTy(*getMRI());
347  auto &Ctx = getMF().getFunction().getContext();
348  auto *CFP =
350  return buildFConstant(Res, *CFP);
351 }
352 
354  const APFloat &Val) {
355  auto &Ctx = getMF().getFunction().getContext();
356  auto *CFP = ConstantFP::get(Ctx, Val);
357  return buildFConstant(Res, *CFP);
358 }
359 
361  MachineBasicBlock &Dest) {
362  assert(Tst.getLLTTy(*getMRI()).isScalar() && "invalid operand type");
363 
364  auto MIB = buildInstr(TargetOpcode::G_BRCOND);
365  Tst.addSrcToMIB(MIB);
366  MIB.addMBB(&Dest);
367  return MIB;
368 }
369 
372  MachinePointerInfo PtrInfo, Align Alignment,
373  MachineMemOperand::Flags MMOFlags,
374  const AAMDNodes &AAInfo) {
375  MMOFlags |= MachineMemOperand::MOLoad;
376  assert((MMOFlags & MachineMemOperand::MOStore) == 0);
377 
378  LLT Ty = Dst.getLLTTy(*getMRI());
379  MachineMemOperand *MMO =
380  getMF().getMachineMemOperand(PtrInfo, MMOFlags, Ty, Alignment, AAInfo);
381  return buildLoad(Dst, Addr, *MMO);
382 }
383 
385  const DstOp &Res,
386  const SrcOp &Addr,
387  MachineMemOperand &MMO) {
388  assert(Res.getLLTTy(*getMRI()).isValid() && "invalid operand type");
389  assert(Addr.getLLTTy(*getMRI()).isPointer() && "invalid operand type");
390 
391  auto MIB = buildInstr(Opcode);
392  Res.addDefToMIB(*getMRI(), MIB);
393  Addr.addSrcToMIB(MIB);
394  MIB.addMemOperand(&MMO);
395  return MIB;
396 }
397 
399  const DstOp &Dst, const SrcOp &BasePtr,
400  MachineMemOperand &BaseMMO, int64_t Offset) {
401  LLT LoadTy = Dst.getLLTTy(*getMRI());
402  MachineMemOperand *OffsetMMO =
403  getMF().getMachineMemOperand(&BaseMMO, Offset, LoadTy);
404 
405  if (Offset == 0) // This may be a size or type changing load.
406  return buildLoad(Dst, BasePtr, *OffsetMMO);
407 
408  LLT PtrTy = BasePtr.getLLTTy(*getMRI());
409  LLT OffsetTy = LLT::scalar(PtrTy.getSizeInBits());
410  auto ConstOffset = buildConstant(OffsetTy, Offset);
411  auto Ptr = buildPtrAdd(PtrTy, BasePtr, ConstOffset);
412  return buildLoad(Dst, Ptr, *OffsetMMO);
413 }
414 
416  const SrcOp &Addr,
417  MachineMemOperand &MMO) {
418  assert(Val.getLLTTy(*getMRI()).isValid() && "invalid operand type");
419  assert(Addr.getLLTTy(*getMRI()).isPointer() && "invalid operand type");
420 
421  auto MIB = buildInstr(TargetOpcode::G_STORE);
422  Val.addSrcToMIB(MIB);
423  Addr.addSrcToMIB(MIB);
424  MIB.addMemOperand(&MMO);
425  return MIB;
426 }
427 
430  MachinePointerInfo PtrInfo, Align Alignment,
431  MachineMemOperand::Flags MMOFlags,
432  const AAMDNodes &AAInfo) {
433  MMOFlags |= MachineMemOperand::MOStore;
434  assert((MMOFlags & MachineMemOperand::MOLoad) == 0);
435 
436  LLT Ty = Val.getLLTTy(*getMRI());
437  MachineMemOperand *MMO =
438  getMF().getMachineMemOperand(PtrInfo, MMOFlags, Ty, Alignment, AAInfo);
439  return buildStore(Val, Addr, *MMO);
440 }
441 
443  const SrcOp &Op) {
444  return buildInstr(TargetOpcode::G_ANYEXT, Res, Op);
445 }
446 
448  const SrcOp &Op) {
449  return buildInstr(TargetOpcode::G_SEXT, Res, Op);
450 }
451 
453  const SrcOp &Op) {
454  return buildInstr(TargetOpcode::G_ZEXT, Res, Op);
455 }
456 
457 unsigned MachineIRBuilder::getBoolExtOp(bool IsVec, bool IsFP) const {
458  const auto *TLI = getMF().getSubtarget().getTargetLowering();
459  switch (TLI->getBooleanContents(IsVec, IsFP)) {
461  return TargetOpcode::G_SEXT;
463  return TargetOpcode::G_ZEXT;
464  default:
465  return TargetOpcode::G_ANYEXT;
466  }
467 }
468 
470  const SrcOp &Op,
471  bool IsFP) {
472  unsigned ExtOp = getBoolExtOp(getMRI()->getType(Op.getReg()).isVector(), IsFP);
473  return buildInstr(ExtOp, Res, Op);
474 }
475 
477  const DstOp &Res,
478  const SrcOp &Op) {
479  assert((TargetOpcode::G_ANYEXT == ExtOpc || TargetOpcode::G_ZEXT == ExtOpc ||
480  TargetOpcode::G_SEXT == ExtOpc) &&
481  "Expecting Extending Opc");
482  assert(Res.getLLTTy(*getMRI()).isScalar() ||
483  Res.getLLTTy(*getMRI()).isVector());
484  assert(Res.getLLTTy(*getMRI()).isScalar() ==
485  Op.getLLTTy(*getMRI()).isScalar());
486 
487  unsigned Opcode = TargetOpcode::COPY;
488  if (Res.getLLTTy(*getMRI()).getSizeInBits() >
489  Op.getLLTTy(*getMRI()).getSizeInBits())
490  Opcode = ExtOpc;
491  else if (Res.getLLTTy(*getMRI()).getSizeInBits() <
492  Op.getLLTTy(*getMRI()).getSizeInBits())
493  Opcode = TargetOpcode::G_TRUNC;
494  else
495  assert(Res.getLLTTy(*getMRI()) == Op.getLLTTy(*getMRI()));
496 
497  return buildInstr(Opcode, Res, Op);
498 }
499 
501  const SrcOp &Op) {
502  return buildExtOrTrunc(TargetOpcode::G_SEXT, Res, Op);
503 }
504 
506  const SrcOp &Op) {
507  return buildExtOrTrunc(TargetOpcode::G_ZEXT, Res, Op);
508 }
509 
511  const SrcOp &Op) {
512  return buildExtOrTrunc(TargetOpcode::G_ANYEXT, Res, Op);
513 }
514 
516  const SrcOp &Op,
517  int64_t ImmOp) {
518  LLT ResTy = Res.getLLTTy(*getMRI());
519  auto Mask = buildConstant(
520  ResTy, APInt::getLowBitsSet(ResTy.getScalarSizeInBits(), ImmOp));
521  return buildAnd(Res, Op, Mask);
522 }
523 
525  const SrcOp &Src) {
526  LLT SrcTy = Src.getLLTTy(*getMRI());
527  LLT DstTy = Dst.getLLTTy(*getMRI());
528  if (SrcTy == DstTy)
529  return buildCopy(Dst, Src);
530 
531  unsigned Opcode;
532  if (SrcTy.isPointer() && DstTy.isScalar())
533  Opcode = TargetOpcode::G_PTRTOINT;
534  else if (DstTy.isPointer() && SrcTy.isScalar())
535  Opcode = TargetOpcode::G_INTTOPTR;
536  else {
537  assert(!SrcTy.isPointer() && !DstTy.isPointer() && "n G_ADDRCAST yet");
538  Opcode = TargetOpcode::G_BITCAST;
539  }
540 
541  return buildInstr(Opcode, Dst, Src);
542 }
543 
545  const SrcOp &Src,
546  uint64_t Index) {
547  LLT SrcTy = Src.getLLTTy(*getMRI());
548  LLT DstTy = Dst.getLLTTy(*getMRI());
549 
550 #ifndef NDEBUG
551  assert(SrcTy.isValid() && "invalid operand type");
552  assert(DstTy.isValid() && "invalid operand type");
553  assert(Index + DstTy.getSizeInBits() <= SrcTy.getSizeInBits() &&
554  "extracting off end of register");
555 #endif
556 
557  if (DstTy.getSizeInBits() == SrcTy.getSizeInBits()) {
558  assert(Index == 0 && "insertion past the end of a register");
559  return buildCast(Dst, Src);
560  }
561 
562  auto Extract = buildInstr(TargetOpcode::G_EXTRACT);
563  Dst.addDefToMIB(*getMRI(), Extract);
564  Src.addSrcToMIB(Extract);
565  Extract.addImm(Index);
566  return Extract;
567 }
568 
570  return buildInstr(TargetOpcode::G_IMPLICIT_DEF, {Res}, {});
571 }
572 
574  ArrayRef<Register> Ops) {
575  // Unfortunately to convert from ArrayRef<LLT> to ArrayRef<SrcOp>,
576  // we need some temporary storage for the DstOp objects. Here we use a
577  // sufficiently large SmallVector to not go through the heap.
578  SmallVector<SrcOp, 8> TmpVec(Ops.begin(), Ops.end());
579  assert(TmpVec.size() > 1);
580  return buildInstr(TargetOpcode::G_MERGE_VALUES, Res, TmpVec);
581 }
582 
585  std::initializer_list<SrcOp> Ops) {
586  assert(Ops.size() > 1);
587  return buildInstr(TargetOpcode::G_MERGE_VALUES, Res, Ops);
588 }
589 
591  const SrcOp &Op) {
592  // Unfortunately to convert from ArrayRef<LLT> to ArrayRef<DstOp>,
593  // we need some temporary storage for the DstOp objects. Here we use a
594  // sufficiently large SmallVector to not go through the heap.
595  SmallVector<DstOp, 8> TmpVec(Res.begin(), Res.end());
596  assert(TmpVec.size() > 1);
597  return buildInstr(TargetOpcode::G_UNMERGE_VALUES, TmpVec, Op);
598 }
599 
601  const SrcOp &Op) {
602  unsigned NumReg = Op.getLLTTy(*getMRI()).getSizeInBits() / Res.getSizeInBits();
603  SmallVector<DstOp, 8> TmpVec(NumReg, Res);
604  return buildInstr(TargetOpcode::G_UNMERGE_VALUES, TmpVec, Op);
605 }
606 
608  const SrcOp &Op) {
609  // Unfortunately to convert from ArrayRef<Register> to ArrayRef<DstOp>,
610  // we need some temporary storage for the DstOp objects. Here we use a
611  // sufficiently large SmallVector to not go through the heap.
612  SmallVector<DstOp, 8> TmpVec(Res.begin(), Res.end());
613  assert(TmpVec.size() > 1);
614  return buildInstr(TargetOpcode::G_UNMERGE_VALUES, TmpVec, Op);
615 }
616 
618  ArrayRef<Register> Ops) {
619  // Unfortunately to convert from ArrayRef<Register> to ArrayRef<SrcOp>,
620  // we need some temporary storage for the DstOp objects. Here we use a
621  // sufficiently large SmallVector to not go through the heap.
622  SmallVector<SrcOp, 8> TmpVec(Ops.begin(), Ops.end());
623  return buildInstr(TargetOpcode::G_BUILD_VECTOR, Res, TmpVec);
624 }
625 
628  ArrayRef<APInt> Ops) {
629  SmallVector<SrcOp> TmpVec;
630  TmpVec.reserve(Ops.size());
631  LLT EltTy = Res.getLLTTy(*getMRI()).getElementType();
632  for (auto &Op : Ops)
633  TmpVec.push_back(buildConstant(EltTy, Op));
634  return buildInstr(TargetOpcode::G_BUILD_VECTOR, Res, TmpVec);
635 }
636 
638  const SrcOp &Src) {
639  SmallVector<SrcOp, 8> TmpVec(Res.getLLTTy(*getMRI()).getNumElements(), Src);
640  return buildInstr(TargetOpcode::G_BUILD_VECTOR, Res, TmpVec);
641 }
642 
645  ArrayRef<Register> Ops) {
646  // Unfortunately to convert from ArrayRef<Register> to ArrayRef<SrcOp>,
647  // we need some temporary storage for the DstOp objects. Here we use a
648  // sufficiently large SmallVector to not go through the heap.
649  SmallVector<SrcOp, 8> TmpVec(Ops.begin(), Ops.end());
650  return buildInstr(TargetOpcode::G_BUILD_VECTOR_TRUNC, Res, TmpVec);
651 }
652 
654  const SrcOp &Src) {
655  LLT DstTy = Res.getLLTTy(*getMRI());
656  assert(Src.getLLTTy(*getMRI()) == DstTy.getElementType() &&
657  "Expected Src to match Dst elt ty");
658  auto UndefVec = buildUndef(DstTy);
659  auto Zero = buildConstant(LLT::scalar(64), 0);
660  auto InsElt = buildInsertVectorElement(DstTy, UndefVec, Src, Zero);
661  SmallVector<int, 16> ZeroMask(DstTy.getNumElements());
662  return buildShuffleVector(DstTy, InsElt, UndefVec, ZeroMask);
663 }
664 
666  const SrcOp &Src1,
667  const SrcOp &Src2,
669  LLT DstTy = Res.getLLTTy(*getMRI());
670  LLT Src1Ty = Src1.getLLTTy(*getMRI());
671  LLT Src2Ty = Src2.getLLTTy(*getMRI());
672  assert((size_t)(Src1Ty.getNumElements() + Src2Ty.getNumElements()) >=
673  Mask.size());
674  assert(DstTy.getElementType() == Src1Ty.getElementType() &&
675  DstTy.getElementType() == Src2Ty.getElementType());
676  (void)DstTy;
677  (void)Src1Ty;
678  (void)Src2Ty;
680  return buildInstr(TargetOpcode::G_SHUFFLE_VECTOR, {Res}, {Src1, Src2})
681  .addShuffleMask(MaskAlloc);
682 }
683 
686  // Unfortunately to convert from ArrayRef<Register> to ArrayRef<SrcOp>,
687  // we need some temporary storage for the DstOp objects. Here we use a
688  // sufficiently large SmallVector to not go through the heap.
689  SmallVector<SrcOp, 8> TmpVec(Ops.begin(), Ops.end());
690  return buildInstr(TargetOpcode::G_CONCAT_VECTORS, Res, TmpVec);
691 }
692 
694  const SrcOp &Src,
695  const SrcOp &Op,
696  unsigned Index) {
697  assert(Index + Op.getLLTTy(*getMRI()).getSizeInBits() <=
698  Res.getLLTTy(*getMRI()).getSizeInBits() &&
699  "insertion past the end of a register");
700 
701  if (Res.getLLTTy(*getMRI()).getSizeInBits() ==
702  Op.getLLTTy(*getMRI()).getSizeInBits()) {
703  return buildCast(Res, Op);
704  }
705 
706  return buildInstr(TargetOpcode::G_INSERT, Res, {Src, Op, uint64_t(Index)});
707 }
708 
710  ArrayRef<Register> ResultRegs,
711  bool HasSideEffects) {
712  auto MIB =
713  buildInstr(HasSideEffects ? TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS
714  : TargetOpcode::G_INTRINSIC);
715  for (unsigned ResultReg : ResultRegs)
716  MIB.addDef(ResultReg);
717  MIB.addIntrinsicID(ID);
718  return MIB;
719 }
720 
723  bool HasSideEffects) {
724  auto MIB =
725  buildInstr(HasSideEffects ? TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS
726  : TargetOpcode::G_INTRINSIC);
727  for (DstOp Result : Results)
728  Result.addDefToMIB(*getMRI(), MIB);
729  MIB.addIntrinsicID(ID);
730  return MIB;
731 }
732 
734  const SrcOp &Op) {
735  return buildInstr(TargetOpcode::G_TRUNC, Res, Op);
736 }
737 
739  const SrcOp &Op,
740  Optional<unsigned> Flags) {
741  return buildInstr(TargetOpcode::G_FPTRUNC, Res, Op, Flags);
742 }
743 
745  const DstOp &Res,
746  const SrcOp &Op0,
747  const SrcOp &Op1) {
748  return buildInstr(TargetOpcode::G_ICMP, Res, {Pred, Op0, Op1});
749 }
750 
752  const DstOp &Res,
753  const SrcOp &Op0,
754  const SrcOp &Op1,
755  Optional<unsigned> Flags) {
756 
757  return buildInstr(TargetOpcode::G_FCMP, Res, {Pred, Op0, Op1}, Flags);
758 }
759 
761  const SrcOp &Tst,
762  const SrcOp &Op0,
763  const SrcOp &Op1,
764  Optional<unsigned> Flags) {
765 
766  return buildInstr(TargetOpcode::G_SELECT, {Res}, {Tst, Op0, Op1}, Flags);
767 }
768 
771  const SrcOp &Elt, const SrcOp &Idx) {
772  return buildInstr(TargetOpcode::G_INSERT_VECTOR_ELT, Res, {Val, Elt, Idx});
773 }
774 
777  const SrcOp &Idx) {
778  return buildInstr(TargetOpcode::G_EXTRACT_VECTOR_ELT, Res, {Val, Idx});
779 }
780 
782  Register OldValRes, Register SuccessRes, Register Addr, Register CmpVal,
783  Register NewVal, MachineMemOperand &MMO) {
784 #ifndef NDEBUG
785  LLT OldValResTy = getMRI()->getType(OldValRes);
786  LLT SuccessResTy = getMRI()->getType(SuccessRes);
787  LLT AddrTy = getMRI()->getType(Addr);
788  LLT CmpValTy = getMRI()->getType(CmpVal);
789  LLT NewValTy = getMRI()->getType(NewVal);
790  assert(OldValResTy.isScalar() && "invalid operand type");
791  assert(SuccessResTy.isScalar() && "invalid operand type");
792  assert(AddrTy.isPointer() && "invalid operand type");
793  assert(CmpValTy.isValid() && "invalid operand type");
794  assert(NewValTy.isValid() && "invalid operand type");
795  assert(OldValResTy == CmpValTy && "type mismatch");
796  assert(OldValResTy == NewValTy && "type mismatch");
797 #endif
798 
799  return buildInstr(TargetOpcode::G_ATOMIC_CMPXCHG_WITH_SUCCESS)
800  .addDef(OldValRes)
801  .addDef(SuccessRes)
802  .addUse(Addr)
803  .addUse(CmpVal)
804  .addUse(NewVal)
805  .addMemOperand(&MMO);
806 }
807 
810  Register CmpVal, Register NewVal,
811  MachineMemOperand &MMO) {
812 #ifndef NDEBUG
813  LLT OldValResTy = getMRI()->getType(OldValRes);
814  LLT AddrTy = getMRI()->getType(Addr);
815  LLT CmpValTy = getMRI()->getType(CmpVal);
816  LLT NewValTy = getMRI()->getType(NewVal);
817  assert(OldValResTy.isScalar() && "invalid operand type");
818  assert(AddrTy.isPointer() && "invalid operand type");
819  assert(CmpValTy.isValid() && "invalid operand type");
820  assert(NewValTy.isValid() && "invalid operand type");
821  assert(OldValResTy == CmpValTy && "type mismatch");
822  assert(OldValResTy == NewValTy && "type mismatch");
823 #endif
824 
825  return buildInstr(TargetOpcode::G_ATOMIC_CMPXCHG)
826  .addDef(OldValRes)
827  .addUse(Addr)
828  .addUse(CmpVal)
829  .addUse(NewVal)
830  .addMemOperand(&MMO);
831 }
832 
834  unsigned Opcode, const DstOp &OldValRes,
835  const SrcOp &Addr, const SrcOp &Val,
836  MachineMemOperand &MMO) {
837 
838 #ifndef NDEBUG
839  LLT OldValResTy = OldValRes.getLLTTy(*getMRI());
840  LLT AddrTy = Addr.getLLTTy(*getMRI());
841  LLT ValTy = Val.getLLTTy(*getMRI());
842  assert(OldValResTy.isScalar() && "invalid operand type");
843  assert(AddrTy.isPointer() && "invalid operand type");
844  assert(ValTy.isValid() && "invalid operand type");
845  assert(OldValResTy == ValTy && "type mismatch");
846  assert(MMO.isAtomic() && "not atomic mem operand");
847 #endif
848 
849  auto MIB = buildInstr(Opcode);
850  OldValRes.addDefToMIB(*getMRI(), MIB);
851  Addr.addSrcToMIB(MIB);
852  Val.addSrcToMIB(MIB);
853  MIB.addMemOperand(&MMO);
854  return MIB;
855 }
856 
859  Register Val, MachineMemOperand &MMO) {
860  return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_XCHG, OldValRes, Addr, Val,
861  MMO);
862 }
865  Register Val, MachineMemOperand &MMO) {
866  return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_ADD, OldValRes, Addr, Val,
867  MMO);
868 }
871  Register Val, MachineMemOperand &MMO) {
872  return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_SUB, OldValRes, Addr, Val,
873  MMO);
874 }
877  Register Val, MachineMemOperand &MMO) {
878  return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_AND, OldValRes, Addr, Val,
879  MMO);
880 }
883  Register Val, MachineMemOperand &MMO) {
884  return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_NAND, OldValRes, Addr, Val,
885  MMO);
886 }
888  Register Addr,
889  Register Val,
890  MachineMemOperand &MMO) {
891  return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_OR, OldValRes, Addr, Val,
892  MMO);
893 }
896  Register Val, MachineMemOperand &MMO) {
897  return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_XOR, OldValRes, Addr, Val,
898  MMO);
899 }
902  Register Val, MachineMemOperand &MMO) {
903  return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_MAX, OldValRes, Addr, Val,
904  MMO);
905 }
908  Register Val, MachineMemOperand &MMO) {
909  return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_MIN, OldValRes, Addr, Val,
910  MMO);
911 }
914  Register Val, MachineMemOperand &MMO) {
915  return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_UMAX, OldValRes, Addr, Val,
916  MMO);
917 }
920  Register Val, MachineMemOperand &MMO) {
921  return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_UMIN, OldValRes, Addr, Val,
922  MMO);
923 }
924 
927  const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val,
928  MachineMemOperand &MMO) {
929  return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_FADD, OldValRes, Addr, Val,
930  MMO);
931 }
932 
934 MachineIRBuilder::buildAtomicRMWFSub(const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val,
935  MachineMemOperand &MMO) {
936  return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_FSUB, OldValRes, Addr, Val,
937  MMO);
938 }
939 
941 MachineIRBuilder::buildFence(unsigned Ordering, unsigned Scope) {
942  return buildInstr(TargetOpcode::G_FENCE)
943  .addImm(Ordering)
944  .addImm(Scope);
945 }
946 
949 #ifndef NDEBUG
950  assert(getMRI()->getType(Res).isPointer() && "invalid res type");
951 #endif
952 
953  return buildInstr(TargetOpcode::G_BLOCK_ADDR).addDef(Res).addBlockAddress(BA);
954 }
955 
956 void MachineIRBuilder::validateTruncExt(const LLT DstTy, const LLT SrcTy,
957  bool IsExtend) {
958 #ifndef NDEBUG
959  if (DstTy.isVector()) {
960  assert(SrcTy.isVector() && "mismatched cast between vector and non-vector");
961  assert(SrcTy.getNumElements() == DstTy.getNumElements() &&
962  "different number of elements in a trunc/ext");
963  } else
964  assert(DstTy.isScalar() && SrcTy.isScalar() && "invalid extend/trunc");
965 
966  if (IsExtend)
967  assert(DstTy.getSizeInBits() > SrcTy.getSizeInBits() &&
968  "invalid narrowing extend");
969  else
970  assert(DstTy.getSizeInBits() < SrcTy.getSizeInBits() &&
971  "invalid widening trunc");
972 #endif
973 }
974 
975 void MachineIRBuilder::validateSelectOp(const LLT ResTy, const LLT TstTy,
976  const LLT Op0Ty, const LLT Op1Ty) {
977 #ifndef NDEBUG
978  assert((ResTy.isScalar() || ResTy.isVector() || ResTy.isPointer()) &&
979  "invalid operand type");
980  assert((ResTy == Op0Ty && ResTy == Op1Ty) && "type mismatch");
981  if (ResTy.isScalar() || ResTy.isPointer())
982  assert(TstTy.isScalar() && "type mismatch");
983  else
984  assert((TstTy.isScalar() ||
985  (TstTy.isVector() &&
986  TstTy.getNumElements() == Op0Ty.getNumElements())) &&
987  "type mismatch");
988 #endif
989 }
990 
992  ArrayRef<DstOp> DstOps,
993  ArrayRef<SrcOp> SrcOps,
994  Optional<unsigned> Flags) {
995  switch (Opc) {
996  default:
997  break;
998  case TargetOpcode::G_SELECT: {
999  assert(DstOps.size() == 1 && "Invalid select");
1000  assert(SrcOps.size() == 3 && "Invalid select");
1002  DstOps[0].getLLTTy(*getMRI()), SrcOps[0].getLLTTy(*getMRI()),
1003  SrcOps[1].getLLTTy(*getMRI()), SrcOps[2].getLLTTy(*getMRI()));
1004  break;
1005  }
1006  case TargetOpcode::G_FNEG:
1007  case TargetOpcode::G_ABS:
1008  // All these are unary ops.
1009  assert(DstOps.size() == 1 && "Invalid Dst");
1010  assert(SrcOps.size() == 1 && "Invalid Srcs");
1011  validateUnaryOp(DstOps[0].getLLTTy(*getMRI()),
1012  SrcOps[0].getLLTTy(*getMRI()));
1013  break;
1014  case TargetOpcode::G_ADD:
1015  case TargetOpcode::G_AND:
1016  case TargetOpcode::G_MUL:
1017  case TargetOpcode::G_OR:
1018  case TargetOpcode::G_SUB:
1019  case TargetOpcode::G_XOR:
1020  case TargetOpcode::G_UDIV:
1021  case TargetOpcode::G_SDIV:
1022  case TargetOpcode::G_UREM:
1023  case TargetOpcode::G_SREM:
1024  case TargetOpcode::G_SMIN:
1025  case TargetOpcode::G_SMAX:
1026  case TargetOpcode::G_UMIN:
1027  case TargetOpcode::G_UMAX:
1028  case TargetOpcode::G_UADDSAT:
1029  case TargetOpcode::G_SADDSAT:
1030  case TargetOpcode::G_USUBSAT:
1031  case TargetOpcode::G_SSUBSAT: {
1032  // All these are binary ops.
1033  assert(DstOps.size() == 1 && "Invalid Dst");
1034  assert(SrcOps.size() == 2 && "Invalid Srcs");
1035  validateBinaryOp(DstOps[0].getLLTTy(*getMRI()),
1036  SrcOps[0].getLLTTy(*getMRI()),
1037  SrcOps[1].getLLTTy(*getMRI()));
1038  break;
1039  }
1040  case TargetOpcode::G_SHL:
1041  case TargetOpcode::G_ASHR:
1042  case TargetOpcode::G_LSHR:
1043  case TargetOpcode::G_USHLSAT:
1044  case TargetOpcode::G_SSHLSAT: {
1045  assert(DstOps.size() == 1 && "Invalid Dst");
1046  assert(SrcOps.size() == 2 && "Invalid Srcs");
1047  validateShiftOp(DstOps[0].getLLTTy(*getMRI()),
1048  SrcOps[0].getLLTTy(*getMRI()),
1049  SrcOps[1].getLLTTy(*getMRI()));
1050  break;
1051  }
1052  case TargetOpcode::G_SEXT:
1053  case TargetOpcode::G_ZEXT:
1054  case TargetOpcode::G_ANYEXT:
1055  assert(DstOps.size() == 1 && "Invalid Dst");
1056  assert(SrcOps.size() == 1 && "Invalid Srcs");
1057  validateTruncExt(DstOps[0].getLLTTy(*getMRI()),
1058  SrcOps[0].getLLTTy(*getMRI()), true);
1059  break;
1060  case TargetOpcode::G_TRUNC:
1061  case TargetOpcode::G_FPTRUNC: {
1062  assert(DstOps.size() == 1 && "Invalid Dst");
1063  assert(SrcOps.size() == 1 && "Invalid Srcs");
1064  validateTruncExt(DstOps[0].getLLTTy(*getMRI()),
1065  SrcOps[0].getLLTTy(*getMRI()), false);
1066  break;
1067  }
1068  case TargetOpcode::G_BITCAST: {
1069  assert(DstOps.size() == 1 && "Invalid Dst");
1070  assert(SrcOps.size() == 1 && "Invalid Srcs");
1071  assert(DstOps[0].getLLTTy(*getMRI()).getSizeInBits() ==
1072  SrcOps[0].getLLTTy(*getMRI()).getSizeInBits() && "invalid bitcast");
1073  break;
1074  }
1075  case TargetOpcode::COPY:
1076  assert(DstOps.size() == 1 && "Invalid Dst");
1077  // If the caller wants to add a subreg source it has to be done separately
1078  // so we may not have any SrcOps at this point yet.
1079  break;
1080  case TargetOpcode::G_FCMP:
1081  case TargetOpcode::G_ICMP: {
1082  assert(DstOps.size() == 1 && "Invalid Dst Operands");
1083  assert(SrcOps.size() == 3 && "Invalid Src Operands");
1084  // For F/ICMP, the first src operand is the predicate, followed by
1085  // the two comparands.
1086  assert(SrcOps[0].getSrcOpKind() == SrcOp::SrcType::Ty_Predicate &&
1087  "Expecting predicate");
1088  assert([&]() -> bool {
1089  CmpInst::Predicate Pred = SrcOps[0].getPredicate();
1090  return Opc == TargetOpcode::G_ICMP ? CmpInst::isIntPredicate(Pred)
1091  : CmpInst::isFPPredicate(Pred);
1092  }() && "Invalid predicate");
1093  assert(SrcOps[1].getLLTTy(*getMRI()) == SrcOps[2].getLLTTy(*getMRI()) &&
1094  "Type mismatch");
1095  assert([&]() -> bool {
1096  LLT Op0Ty = SrcOps[1].getLLTTy(*getMRI());
1097  LLT DstTy = DstOps[0].getLLTTy(*getMRI());
1098  if (Op0Ty.isScalar() || Op0Ty.isPointer())
1099  return DstTy.isScalar();
1100  else
1101  return DstTy.isVector() &&
1102  DstTy.getNumElements() == Op0Ty.getNumElements();
1103  }() && "Type Mismatch");
1104  break;
1105  }
1106  case TargetOpcode::G_UNMERGE_VALUES: {
1107  assert(!DstOps.empty() && "Invalid trivial sequence");
1108  assert(SrcOps.size() == 1 && "Invalid src for Unmerge");
1109  assert(llvm::all_of(DstOps,
1110  [&, this](const DstOp &Op) {
1111  return Op.getLLTTy(*getMRI()) ==
1112  DstOps[0].getLLTTy(*getMRI());
1113  }) &&
1114  "type mismatch in output list");
1115  assert((TypeSize::ScalarTy)DstOps.size() *
1116  DstOps[0].getLLTTy(*getMRI()).getSizeInBits() ==
1117  SrcOps[0].getLLTTy(*getMRI()).getSizeInBits() &&
1118  "input operands do not cover output register");
1119  break;
1120  }
1121  case TargetOpcode::G_MERGE_VALUES: {
1122  assert(!SrcOps.empty() && "invalid trivial sequence");
1123  assert(DstOps.size() == 1 && "Invalid Dst");
1124  assert(llvm::all_of(SrcOps,
1125  [&, this](const SrcOp &Op) {
1126  return Op.getLLTTy(*getMRI()) ==
1127  SrcOps[0].getLLTTy(*getMRI());
1128  }) &&
1129  "type mismatch in input list");
1130  assert((TypeSize::ScalarTy)SrcOps.size() *
1131  SrcOps[0].getLLTTy(*getMRI()).getSizeInBits() ==
1132  DstOps[0].getLLTTy(*getMRI()).getSizeInBits() &&
1133  "input operands do not cover output register");
1134  if (SrcOps.size() == 1)
1135  return buildCast(DstOps[0], SrcOps[0]);
1136  if (DstOps[0].getLLTTy(*getMRI()).isVector()) {
1137  if (SrcOps[0].getLLTTy(*getMRI()).isVector())
1138  return buildInstr(TargetOpcode::G_CONCAT_VECTORS, DstOps, SrcOps);
1139  return buildInstr(TargetOpcode::G_BUILD_VECTOR, DstOps, SrcOps);
1140  }
1141  break;
1142  }
1143  case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
1144  assert(DstOps.size() == 1 && "Invalid Dst size");
1145  assert(SrcOps.size() == 2 && "Invalid Src size");
1146  assert(SrcOps[0].getLLTTy(*getMRI()).isVector() && "Invalid operand type");
1147  assert((DstOps[0].getLLTTy(*getMRI()).isScalar() ||
1148  DstOps[0].getLLTTy(*getMRI()).isPointer()) &&
1149  "Invalid operand type");
1150  assert(SrcOps[1].getLLTTy(*getMRI()).isScalar() && "Invalid operand type");
1151  assert(SrcOps[0].getLLTTy(*getMRI()).getElementType() ==
1152  DstOps[0].getLLTTy(*getMRI()) &&
1153  "Type mismatch");
1154  break;
1155  }
1156  case TargetOpcode::G_INSERT_VECTOR_ELT: {
1157  assert(DstOps.size() == 1 && "Invalid dst size");
1158  assert(SrcOps.size() == 3 && "Invalid src size");
1159  assert(DstOps[0].getLLTTy(*getMRI()).isVector() &&
1160  SrcOps[0].getLLTTy(*getMRI()).isVector() && "Invalid operand type");
1161  assert(DstOps[0].getLLTTy(*getMRI()).getElementType() ==
1162  SrcOps[1].getLLTTy(*getMRI()) &&
1163  "Type mismatch");
1164  assert(SrcOps[2].getLLTTy(*getMRI()).isScalar() && "Invalid index");
1165  assert(DstOps[0].getLLTTy(*getMRI()).getNumElements() ==
1166  SrcOps[0].getLLTTy(*getMRI()).getNumElements() &&
1167  "Type mismatch");
1168  break;
1169  }
1170  case TargetOpcode::G_BUILD_VECTOR: {
1171  assert((!SrcOps.empty() || SrcOps.size() < 2) &&
1172  "Must have at least 2 operands");
1173  assert(DstOps.size() == 1 && "Invalid DstOps");
1174  assert(DstOps[0].getLLTTy(*getMRI()).isVector() &&
1175  "Res type must be a vector");
1176  assert(llvm::all_of(SrcOps,
1177  [&, this](const SrcOp &Op) {
1178  return Op.getLLTTy(*getMRI()) ==
1179  SrcOps[0].getLLTTy(*getMRI());
1180  }) &&
1181  "type mismatch in input list");
1182  assert((TypeSize::ScalarTy)SrcOps.size() *
1183  SrcOps[0].getLLTTy(*getMRI()).getSizeInBits() ==
1184  DstOps[0].getLLTTy(*getMRI()).getSizeInBits() &&
1185  "input scalars do not exactly cover the output vector register");
1186  break;
1187  }
1188  case TargetOpcode::G_BUILD_VECTOR_TRUNC: {
1189  assert((!SrcOps.empty() || SrcOps.size() < 2) &&
1190  "Must have at least 2 operands");
1191  assert(DstOps.size() == 1 && "Invalid DstOps");
1192  assert(DstOps[0].getLLTTy(*getMRI()).isVector() &&
1193  "Res type must be a vector");
1194  assert(llvm::all_of(SrcOps,
1195  [&, this](const SrcOp &Op) {
1196  return Op.getLLTTy(*getMRI()) ==
1197  SrcOps[0].getLLTTy(*getMRI());
1198  }) &&
1199  "type mismatch in input list");
1200  if (SrcOps[0].getLLTTy(*getMRI()).getSizeInBits() ==
1201  DstOps[0].getLLTTy(*getMRI()).getElementType().getSizeInBits())
1202  return buildInstr(TargetOpcode::G_BUILD_VECTOR, DstOps, SrcOps);
1203  break;
1204  }
1205  case TargetOpcode::G_CONCAT_VECTORS: {
1206  assert(DstOps.size() == 1 && "Invalid DstOps");
1207  assert((!SrcOps.empty() || SrcOps.size() < 2) &&
1208  "Must have at least 2 operands");
1209  assert(llvm::all_of(SrcOps,
1210  [&, this](const SrcOp &Op) {
1211  return (Op.getLLTTy(*getMRI()).isVector() &&
1212  Op.getLLTTy(*getMRI()) ==
1213  SrcOps[0].getLLTTy(*getMRI()));
1214  }) &&
1215  "type mismatch in input list");
1216  assert((TypeSize::ScalarTy)SrcOps.size() *
1217  SrcOps[0].getLLTTy(*getMRI()).getSizeInBits() ==
1218  DstOps[0].getLLTTy(*getMRI()).getSizeInBits() &&
1219  "input vectors do not exactly cover the output vector register");
1220  break;
1221  }
1222  case TargetOpcode::G_UADDE: {
1223  assert(DstOps.size() == 2 && "Invalid no of dst operands");
1224  assert(SrcOps.size() == 3 && "Invalid no of src operands");
1225  assert(DstOps[0].getLLTTy(*getMRI()).isScalar() && "Invalid operand");
1226  assert((DstOps[0].getLLTTy(*getMRI()) == SrcOps[0].getLLTTy(*getMRI())) &&
1227  (DstOps[0].getLLTTy(*getMRI()) == SrcOps[1].getLLTTy(*getMRI())) &&
1228  "Invalid operand");
1229  assert(DstOps[1].getLLTTy(*getMRI()).isScalar() && "Invalid operand");
1230  assert(DstOps[1].getLLTTy(*getMRI()) == SrcOps[2].getLLTTy(*getMRI()) &&
1231  "type mismatch");
1232  break;
1233  }
1234  }
1235 
1236  auto MIB = buildInstr(Opc);
1237  for (const DstOp &Op : DstOps)
1238  Op.addDefToMIB(*getMRI(), MIB);
1239  for (const SrcOp &Op : SrcOps)
1240  Op.addSrcToMIB(MIB);
1241  if (Flags)
1242  MIB->setFlags(*Flags);
1243  return MIB;
1244 }
i
i
Definition: README.txt:29
llvm::MachineIRBuilder::setMF
void setMF(MachineFunction &MF)
Definition: MachineIRBuilder.cpp:24
llvm::MachineInstrBuilder::addCImm
const MachineInstrBuilder & addCImm(const ConstantInt *Val) const
Definition: MachineInstrBuilder.h:136
llvm::MachineIRBuilder::buildInsertVectorElement
MachineInstrBuilder buildInsertVectorElement(const DstOp &Res, const SrcOp &Val, const SrcOp &Elt, const SrcOp &Idx)
Build and insert Res = G_INSERT_VECTOR_ELT Val, Elt, Idx.
Definition: MachineIRBuilder.cpp:770
MachineInstr.h
llvm::MachineInstrBuilder::addImm
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Definition: MachineInstrBuilder.h:131
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::MachineIRBuilder::buildGlobalValue
MachineInstrBuilder buildGlobalValue(const DstOp &Res, const GlobalValue *GV)
Build and insert Res = G_GLOBAL_VALUE GV.
Definition: MachineIRBuilder.cpp:144
llvm::MachineIRBuilder::buildAtomicRMW
MachineInstrBuilder buildAtomicRMW(unsigned Opcode, const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_<Opcode> Addr, Val, MMO.
Definition: MachineIRBuilder.cpp:833
llvm::MachineInstrBuilder::addFPImm
const MachineInstrBuilder & addFPImm(const ConstantFP *Val) const
Definition: MachineInstrBuilder.h:141
llvm::MachineIRBuilder::buildICmp
MachineInstrBuilder buildICmp(CmpInst::Predicate Pred, const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1)
Build and insert a Res = G_ICMP Pred, Op0, Op1.
Definition: MachineIRBuilder.cpp:744
llvm::LLT::getScalarSizeInBits
unsigned getScalarSizeInBits() const
Definition: LowLevelTypeImpl.h:224
llvm::CmpInst::Predicate
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:719
llvm::MachineIRBuilderState::II
MachineBasicBlock::iterator II
Definition: MachineIRBuilder.h:57
llvm::ConstantInt::getBitWidth
unsigned getBitWidth() const
getBitWidth - Return the bitwidth of this constant.
Definition: Constants.h:136
DebugInfoMetadata.h
llvm::getAPFloatFromSize
APFloat getAPFloatFromSize(double Val, unsigned Size)
Returns an APFloat from Val converted to the appropriate size.
Definition: Utils.cpp:479
getFunction
static Function * getFunction(Constant *C)
Definition: Evaluator.cpp:233
llvm::TargetSubtargetInfo::getInstrInfo
virtual const TargetInstrInfo * getInstrInfo() const
Definition: TargetSubtargetInfo.h:93
llvm::MachineIRBuilder::buildSplatVector
MachineInstrBuilder buildSplatVector(const DstOp &Res, const SrcOp &Src)
Build and insert Res = G_BUILD_VECTOR with Src replicated to fill the number of elements.
Definition: MachineIRBuilder.cpp:637
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
llvm::MachineIRBuilder::getMRI
MachineRegisterInfo * getMRI()
Getter for MRI.
Definition: MachineIRBuilder.h:287
llvm::MachineIRBuilder::buildZExtInReg
MachineInstrBuilder buildZExtInReg(const DstOp &Res, const SrcOp &Op, int64_t ImmOp)
Build and inserts Res = G_AND Op, LowBitsSet(ImmOp) Since there is no G_ZEXT_INREG like G_SEXT_INREG,...
Definition: MachineIRBuilder.cpp:515
llvm::MachineFunction::getMachineMemOperand
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, Align base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
Definition: MachineFunction.cpp:454
llvm::MachineIRBuilder::buildAtomicRMWOr
MachineInstrBuilder buildAtomicRMWOr(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_OR Addr, Val, MMO.
Definition: MachineIRBuilder.cpp:887
llvm::X86Disassembler::Reg
Reg
All possible values of the reg field in the ModR/M byte.
Definition: X86DisassemblerDecoder.h:462
llvm::PointerType::getAddressSpace
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:682
llvm::MachineIRBuilder::buildZExtOrTrunc
MachineInstrBuilder buildZExtOrTrunc(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_ZEXT Op, Res = G_TRUNC Op, or Res = COPY Op depending on the differing sizes...
Definition: MachineIRBuilder.cpp:505
llvm::AAMDNodes
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition: Metadata.h:652
llvm::LLT::getScalarType
LLT getScalarType() const
Definition: LowLevelTypeImpl.h:167
llvm::Function::getContext
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition: Function.cpp:319
llvm::MachineIRBuilder::buildAtomicRMWAdd
MachineInstrBuilder buildAtomicRMWAdd(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_ADD Addr, Val, MMO.
Definition: MachineIRBuilder.cpp:864
llvm::MachineIRBuilder::buildAtomicCmpXchg
MachineInstrBuilder buildAtomicCmpXchg(Register OldValRes, Register Addr, Register CmpVal, Register NewVal, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMIC_CMPXCHG Addr, CmpVal, NewVal, MMO.
Definition: MachineIRBuilder.cpp:809
llvm::MachineIRBuilder::buildDbgLabel
MachineInstrBuilder buildDbgLabel(const MDNode *Label)
Build and insert a DBG_LABEL instructions specifying that Label is given.
Definition: MachineIRBuilder.cpp:115
TargetInstrInfo.h
llvm::MachineMemOperand
A description of a memory reference used in the backend.
Definition: MachineMemOperand.h:127
llvm::MachineIRBuilder::getDL
const DebugLoc & getDL()
Getter for DebugLoc.
Definition: MachineIRBuilder.h:284
llvm::MachineIRBuilder::buildFPTrunc
MachineInstrBuilder buildFPTrunc(const DstOp &Res, const SrcOp &Op, Optional< unsigned > Flags=None)
Build and insert Res = G_FPTRUNC Op.
Definition: MachineIRBuilder.cpp:738
llvm::ConstantFP::getValueAPF
const APFloat & getValueAPF() const
Definition: Constants.h:298
llvm::LLT::isValid
bool isValid() const
Definition: LowLevelTypeImpl.h:116
llvm::UnivariateLinearPolyBase< TypeSize >::ScalarTy
typename LinearPolyBaseTypeTraits< TypeSize >::ScalarTy ScalarTy
Definition: TypeSize.h:167
llvm::Optional
Definition: APInt.h:33
llvm::MachineIRBuilder::buildBuildVector
MachineInstrBuilder buildBuildVector(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_BUILD_VECTOR Op0, ...
Definition: MachineIRBuilder.cpp:617
Results
Function Alias Analysis Results
Definition: AliasAnalysis.cpp:848
llvm::MachineIRBuilder::buildInstrNoInsert
MachineInstrBuilder buildInstrNoInsert(unsigned Opcode)
Build but don't insert <empty> = Opcode <empty>.
Definition: MachineIRBuilder.cpp:38
MachineIRBuilder.h
llvm::MachineIRBuilder::buildExtOrTrunc
MachineInstrBuilder buildExtOrTrunc(unsigned ExtOpc, const DstOp &Res, const SrcOp &Op)
Build and insert Res = ExtOpc, Res = G_TRUNC Op, or Res = COPY Op depending on the differing sizes of...
Definition: MachineIRBuilder.cpp:476
llvm::MachineIRBuilderState::MBB
MachineBasicBlock * MBB
Definition: MachineIRBuilder.h:56
llvm::MachineIRBuilder::buildPtrMask
MachineInstrBuilder buildPtrMask(const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1)
Build and insert Res = G_PTRMASK Op0, Op1.
Definition: MachineIRBuilder.h:486
llvm::MachineIRBuilder::buildAtomicRMWFSub
MachineInstrBuilder buildAtomicRMWFSub(const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_FSUB Addr, Val, MMO.
Definition: MachineIRBuilder.cpp:934
llvm::MachineIRBuilder::buildFence
MachineInstrBuilder buildFence(unsigned Ordering, unsigned Scope)
Build and insert G_FENCE Ordering, Scope.
Definition: MachineIRBuilder.cpp:941
llvm::LegalityPredicates::isPointer
LegalityPredicate isPointer(unsigned TypeIdx)
True iff the specified type index is a pointer (with any address space).
Definition: LegalityPredicates.cpp:79
llvm::APFloat::getSemantics
const fltSemantics & getSemantics() const
Definition: APFloat.h:1223
llvm::SrcOp::SrcType::Ty_Predicate
@ Ty_Predicate
llvm::MachineIRBuilder::buildDynStackAlloc
MachineInstrBuilder buildDynStackAlloc(const DstOp &Res, const SrcOp &Size, Align Alignment)
Build and insert Res = G_DYN_STACKALLOC Size, Align.
Definition: MachineIRBuilder.cpp:124
llvm::MachineIRBuilder::validateSelectOp
void validateSelectOp(const LLT ResTy, const LLT TstTy, const LLT Op0Ty, const LLT Op1Ty)
Definition: MachineIRBuilder.cpp:975
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:159
llvm::MachineIRBuilder::buildConstant
virtual MachineInstrBuilder buildConstant(const DstOp &Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
Definition: MachineIRBuilder.cpp:283
llvm::MachineIRBuilder::validateBinaryOp
void validateBinaryOp(const LLT Res, const LLT Op0, const LLT Op1)
Definition: MachineIRBuilder.cpp:168
MachineRegisterInfo.h
llvm::AVR::getAddressSpace
AddressSpace getAddressSpace(T *V)
Definition: AVR.h:64
llvm::BitmaskEnumDetail::Mask
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:80
llvm::MachineInstrBuilder::addDef
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
Definition: MachineInstrBuilder.h:116
TargetLowering.h
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition: Constants.h:79
llvm::APFloatBase::getSizeInBits
static unsigned getSizeInBits(const fltSemantics &Sem)
Returns the size of the floating point number (in bits) in the given semantics.
Definition: APFloat.cpp:226
llvm::Intrinsic::getType
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
Definition: Function.cpp:1374
llvm::all_of
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1617
llvm::MachineFunction::getRegInfo
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Definition: MachineFunction.h:666
llvm::MachineIRBuilder::buildAtomicCmpXchgWithSuccess
MachineInstrBuilder buildAtomicCmpXchgWithSuccess(Register OldValRes, Register SuccessRes, Register Addr, Register CmpVal, Register NewVal, MachineMemOperand &MMO)
Build and insert OldValRes<def>, SuccessRes<def> = G_ATOMIC_CMPXCHG_WITH_SUCCESS Addr,...
Definition: MachineIRBuilder.cpp:781
llvm::MachineIRBuilder::buildUnmerge
MachineInstrBuilder buildUnmerge(ArrayRef< LLT > Res, const SrcOp &Op)
Build and insert Res0, ...
Definition: MachineIRBuilder.cpp:590
llvm::MachineIRBuilder::buildAtomicRMWMin
MachineInstrBuilder buildAtomicRMWMin(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_MIN Addr, Val, MMO.
Definition: MachineIRBuilder.cpp:907
llvm::MachineIRBuilder::buildZExt
MachineInstrBuilder buildZExt(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_ZEXT Op.
Definition: MachineIRBuilder.cpp:452
llvm::MachineInstrBuilder::addMBB
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
Definition: MachineInstrBuilder.h:146
llvm::MachineIRBuilder::buildExtractVectorElement
MachineInstrBuilder buildExtractVectorElement(const DstOp &Res, const SrcOp &Val, const SrcOp &Idx)
Build and insert Res = G_EXTRACT_VECTOR_ELT Val, Idx.
Definition: MachineIRBuilder.cpp:776
llvm::MachineIRBuilder::buildLoad
MachineInstrBuilder buildLoad(const DstOp &Res, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert Res = G_LOAD Addr, MMO.
Definition: MachineIRBuilder.h:888
llvm::CmpInst::isFPPredicate
bool isFPPredicate() const
Definition: InstrTypes.h:826
getScalarSizeInBits
static unsigned getScalarSizeInBits(Type *Ty)
Definition: SystemZTargetTransformInfo.cpp:403
llvm::DstOp::addDefToMIB
void addDefToMIB(MachineRegisterInfo &MRI, MachineInstrBuilder &MIB) const
Definition: MachineIRBuilder.h:80
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::MachineIRBuilder::buildBoolExt
MachineInstrBuilder buildBoolExt(const DstOp &Res, const SrcOp &Op, bool IsFP)
Definition: MachineIRBuilder.cpp:469
llvm::MachineIRBuilder::recordInsertion
void recordInsertion(MachineInstr *InsertedInstr) const
Definition: MachineIRBuilder.h:233
llvm::LLT::getSizeInBits
TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
Definition: LowLevelTypeImpl.h:152
llvm::MachineIRBuilder::buildAnyExtOrTrunc
MachineInstrBuilder buildAnyExtOrTrunc(const DstOp &Res, const SrcOp &Op)
Res = COPY Op depending on the differing sizes of Res and Op.
Definition: MachineIRBuilder.cpp:510
llvm::MachineIRBuilder::buildFCmp
MachineInstrBuilder buildFCmp(CmpInst::Predicate Pred, const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1, Optional< unsigned > Flags=None)
Build and insert a Res = G_FCMP PredOp0, Op1.
Definition: MachineIRBuilder.cpp:751
llvm::TargetLoweringBase::ZeroOrNegativeOneBooleanContent
@ ZeroOrNegativeOneBooleanContent
Definition: TargetLowering.h:233
llvm::MachineIRBuilder::buildFIDbgValue
MachineInstrBuilder buildFIDbgValue(int FI, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in th...
Definition: MachineIRBuilder.cpp:75
TargetOpcodes.h
llvm::MachineIRBuilder::buildConcatVectors
MachineInstrBuilder buildConcatVectors(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_CONCAT_VECTORS Op0, ...
Definition: MachineIRBuilder.cpp:685
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
llvm::MachineIRBuilder::buildAtomicRMWAnd
MachineInstrBuilder buildAtomicRMWAnd(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_AND Addr, Val, MMO.
Definition: MachineIRBuilder.cpp:876
llvm::MachineIRBuilder::getMF
MachineFunction & getMF()
Getter for the function we currently build.
Definition: MachineIRBuilder.h:269
llvm::ConstantFP
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:257
llvm::ConstantInt::get
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:928
llvm::MachineIRBuilder::buildAnd
MachineInstrBuilder buildAnd(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1)
Build and insert Res = G_AND Op0, Op1.
Definition: MachineIRBuilder.h:1550
llvm::MachineIRBuilder::buildIndirectDbgValue
MachineInstrBuilder buildIndirectDbgValue(Register Reg, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in me...
Definition: MachineIRBuilder.cpp:63
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::MachineIRBuilder::buildBrCond
MachineInstrBuilder buildBrCond(const SrcOp &Tst, MachineBasicBlock &Dest)
Build and insert G_BRCOND Tst, Dest.
Definition: MachineIRBuilder.cpp:360
llvm::MachineIRBuilder::buildLoadInstr
MachineInstrBuilder buildLoadInstr(unsigned Opcode, const DstOp &Res, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert Res = <opcode> Addr, MMO.
Definition: MachineIRBuilder.cpp:384
llvm::None
const NoneType None
Definition: None.h:24
llvm::MachineIRBuilder::buildAtomicRMWMax
MachineInstrBuilder buildAtomicRMWMax(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_MAX Addr, Val, MMO.
Definition: MachineIRBuilder.cpp:901
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
llvm::MachineInstrBuilder::getReg
Register getReg(unsigned Idx) const
Get the register for the operand index.
Definition: MachineInstrBuilder.h:94
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:94
llvm::MachineIRBuilder::buildBrIndirect
MachineInstrBuilder buildBrIndirect(Register Tgt)
Build and insert G_BRINDIRECT Tgt.
Definition: MachineIRBuilder.cpp:262
llvm::MachineIRBuilder::validateUnaryOp
void validateUnaryOp(const LLT Res, const LLT Op0)
Definition: MachineIRBuilder.cpp:163
llvm::MachineIRBuilder::buildBr
MachineInstrBuilder buildBr(MachineBasicBlock &Dest)
Build and insert G_BR Dest.
Definition: MachineIRBuilder.cpp:258
llvm::MachineIRBuilder::buildMaskLowPtrBits
MachineInstrBuilder buildMaskLowPtrBits(const DstOp &Res, const SrcOp &Op0, uint32_t NumBits)
Build and insert Res = G_PTRMASK Op0, G_CONSTANT (1 << NumBits) - 1.
Definition: MachineIRBuilder.cpp:206
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:656
llvm::MachineInstrBuilder::addFrameIndex
const MachineInstrBuilder & addFrameIndex(int Idx) const
Definition: MachineInstrBuilder.h:152
llvm::APFloat
Definition: APFloat.h:701
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::MachineIRBuilder::buildFConstant
virtual MachineInstrBuilder buildFConstant(const DstOp &Res, const ConstantFP &Val)
Build and insert Res = G_FCONSTANT Val.
Definition: MachineIRBuilder.cpp:312
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::MachineIRBuilder::buildBrJT
MachineInstrBuilder buildBrJT(Register TablePtr, unsigned JTI, Register IndexReg)
Build and insert G_BRJT TablePtr, JTI, IndexReg.
Definition: MachineIRBuilder.cpp:267
llvm::MachineIRBuilder::buildSExtOrTrunc
MachineInstrBuilder buildSExtOrTrunc(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_SEXT Op, Res = G_TRUNC Op, or Res = COPY Op depending on the differing sizes...
Definition: MachineIRBuilder.cpp:500
llvm::MachineInstrBuilder
Definition: MachineInstrBuilder.h:69
uint64_t
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:78
llvm::MachineIRBuilder::getInsertPt
MachineBasicBlock::iterator getInsertPt()
Current insertion point for new instructions.
Definition: MachineIRBuilder.h:308
llvm::MachinePointerInfo
This class contains a discriminated union of information about pointers in memory operands,...
Definition: MachineMemOperand.h:39
llvm::MachineIRBuilder::buildPtrAdd
MachineInstrBuilder buildPtrAdd(const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1)
Build and insert Res = G_PTR_ADD Op0, Op1.
Definition: MachineIRBuilder.cpp:180
llvm::LLT::isVector
bool isVector() const
Definition: LowLevelTypeImpl.h:122
llvm::LLT::getNumElements
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
Definition: LowLevelTypeImpl.h:126
llvm::MachineIRBuilder::buildAtomicRMWNand
MachineInstrBuilder buildAtomicRMWNand(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_NAND Addr, Val, MMO.
Definition: MachineIRBuilder.cpp:882
llvm::MachineIRBuilder::buildSelect
MachineInstrBuilder buildSelect(const DstOp &Res, const SrcOp &Tst, const SrcOp &Op0, const SrcOp &Op1, Optional< unsigned > Flags=None)
Build and insert a Res = G_SELECT Tst, Op0, Op1.
Definition: MachineIRBuilder.cpp:760
llvm::MachineMemOperand::Flags
Flags
Flags values. These may be or'd together.
Definition: MachineMemOperand.h:130
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::LLT::isPointer
bool isPointer() const
Definition: LowLevelTypeImpl.h:120
llvm::MachineIRBuilder::buildConstDbgValue
MachineInstrBuilder buildConstDbgValue(const Constant &C, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instructions specifying that Variable is given by C (suitably modified b...
Definition: MachineIRBuilder.cpp:90
llvm::MachineIRBuilder::getMBB
const MachineBasicBlock & getMBB() const
Getter for the basic block we currently build.
Definition: MachineIRBuilder.h:294
llvm::MachineInstrBuilder::addMemOperand
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
Definition: MachineInstrBuilder.h:202
llvm::MachineRegisterInfo::createGenericVirtualRegister
Register createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
Definition: MachineRegisterInfo.cpp:186
llvm::MachineInstrBuilder::addUse
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
Definition: MachineInstrBuilder.h:123
llvm::MachineIRBuilder::buildAtomicRMWFAdd
MachineInstrBuilder buildAtomicRMWFAdd(const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_FADD Addr, Val, MMO.
Definition: MachineIRBuilder.cpp:926
llvm::MDNode
Metadata node.
Definition: Metadata.h:937
llvm::LLT::isScalar
bool isScalar() const
Definition: LowLevelTypeImpl.h:118
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
llvm::MachineFunction
Definition: MachineFunction.h:257
llvm::CmpInst::isIntPredicate
bool isIntPredicate() const
Definition: InstrTypes.h:827
llvm::MachineIRBuilderState::Observer
GISelChangeObserver * Observer
Definition: MachineIRBuilder.h:60
llvm::MachineIRBuilder::buildInstr
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
Definition: MachineIRBuilder.h:374
llvm::BlockAddress
The address of a basic block.
Definition: Constants.h:849
llvm::SrcOp::addSrcToMIB
void addSrcToMIB(MachineInstrBuilder &MIB) const
Definition: MachineIRBuilder.h:148
llvm::MachineBasicBlock::iterator
MachineInstrBundleIterator< MachineInstr > iterator
Definition: MachineBasicBlock.h:242
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::MachineFunction::allocateShuffleMask
ArrayRef< int > allocateShuffleMask(ArrayRef< int > Mask)
Definition: MachineFunction.cpp:553
llvm::MachineIRBuilder::insertInstr
MachineInstrBuilder insertInstr(MachineInstrBuilder MIB)
Insert an existing instruction at the insertion point.
Definition: MachineIRBuilder.cpp:43
llvm::MachineInstrBuilder::addJumpTableIndex
const MachineInstrBuilder & addJumpTableIndex(unsigned Idx, unsigned TargetFlags=0) const
Definition: MachineInstrBuilder.h:171
llvm::MachineIRBuilder::buildCopy
MachineInstrBuilder buildCopy(const DstOp &Res, const SrcOp &Op)
Build and insert Res = COPY Op.
Definition: MachineIRBuilder.cpp:278
uint32_t
TargetSubtargetInfo.h
llvm::MachineIRBuilder::buildInsert
MachineInstrBuilder buildInsert(const DstOp &Res, const SrcOp &Src, const SrcOp &Op, unsigned Index)
Definition: MachineIRBuilder.cpp:693
llvm::MachineIRBuilderState::TII
const TargetInstrInfo * TII
Information used to access the description of the opcodes.
Definition: MachineIRBuilder.h:48
llvm::MachineIRBuilder::buildExtract
MachineInstrBuilder buildExtract(const DstOp &Res, const SrcOp &Src, uint64_t Index)
Build and insert Res0, ...
Definition: MachineIRBuilder.cpp:544
llvm::MachineInstrBuilder::addBlockAddress
const MachineInstrBuilder & addBlockAddress(const BlockAddress *BA, int64_t Offset=0, unsigned TargetFlags=0) const
Definition: MachineInstrBuilder.h:190
llvm::MachineMemOperand::MOLoad
@ MOLoad
The memory access reads data.
Definition: MachineMemOperand.h:134
llvm::MachineIRBuilder::buildAnyExt
MachineInstrBuilder buildAnyExt(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_ANYEXT Op0.
Definition: MachineIRBuilder.cpp:442
llvm::MachineIRBuilder::materializePtrAdd
Optional< MachineInstrBuilder > materializePtrAdd(Register &Res, Register Op0, const LLT ValueTy, uint64_t Value)
Materialize and insert Res = G_PTR_ADD Op0, (G_CONSTANT Value)
Definition: MachineIRBuilder.cpp:191
llvm::MachineIRBuilder::buildJumpTable
MachineInstrBuilder buildJumpTable(const LLT PtrTy, unsigned JTI)
Build and insert Res = G_JUMP_TABLE JTI.
Definition: MachineIRBuilder.cpp:157
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::LegalityPredicates::isScalar
LegalityPredicate isScalar(unsigned TypeIdx)
True iff the specified type index is a scalar.
Definition: LegalityPredicates.cpp:67
llvm::MachineIRBuilder::buildFrameIndex
MachineInstrBuilder buildFrameIndex(const DstOp &Res, int Idx)
Build and insert Res = G_FRAME_INDEX Idx.
Definition: MachineIRBuilder.cpp:135
llvm::MachineIRBuilder::buildTrunc
MachineInstrBuilder buildTrunc(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_TRUNC Op.
Definition: MachineIRBuilder.cpp:733
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:622
get
Should compile to something r4 addze r3 instead we get
Definition: README.txt:24
llvm::MachineIRBuilderState::DL
DebugLoc DL
Debug location to be set to any instruction we create.
Definition: MachineIRBuilder.h:52
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:345
llvm::ArrayRef::begin
iterator begin() const
Definition: ArrayRef.h:152
llvm::MachineBasicBlock::insert
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
Definition: MachineBasicBlock.cpp:1312
llvm::MachineIRBuilder::buildUndef
MachineInstrBuilder buildUndef(const DstOp &Res)
Build and insert Res = IMPLICIT_DEF.
Definition: MachineIRBuilder.cpp:569
llvm::MachineIRBuilder::buildDirectDbgValue
MachineInstrBuilder buildDirectDbgValue(Register Reg, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in Re...
Definition: MachineIRBuilder.cpp:50
llvm::ConstantFP::get
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
Definition: Constants.cpp:975
llvm::MachineIRBuilder::buildAtomicRMWUmin
MachineInstrBuilder buildAtomicRMWUmin(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_UMIN Addr, Val, MMO.
Definition: MachineIRBuilder.cpp:919
llvm::MachineIRBuilder::buildShuffleVector
MachineInstrBuilder buildShuffleVector(const DstOp &Res, const SrcOp &Src1, const SrcOp &Src2, ArrayRef< int > Mask)
Build and insert Res = G_SHUFFLE_VECTOR Src1, Src2, Mask.
Definition: MachineIRBuilder.cpp:665
llvm::MachineIRBuilder::buildBuildVectorConstant
MachineInstrBuilder buildBuildVectorConstant(const DstOp &Res, ArrayRef< APInt > Ops)
Build and insert Res = G_BUILD_VECTOR Op0, ...
Definition: MachineIRBuilder.cpp:627
llvm::MachineIRBuilder::buildAtomicRMWXor
MachineInstrBuilder buildAtomicRMWXor(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_XOR Addr, Val, MMO.
Definition: MachineIRBuilder.cpp:895
llvm::MachineIRBuilder::buildPadVectorWithUndefElements
MachineInstrBuilder buildPadVectorWithUndefElements(const DstOp &Res, const SrcOp &Op0)
Build and insert a, b, ..., x = G_UNMERGE_VALUES Op0 Res = G_BUILD_VECTOR a, b, .....
Definition: MachineIRBuilder.cpp:217
llvm::MachineMemOperand::isAtomic
bool isAtomic() const
Returns true if this operation has an atomic ordering requirement of unordered or higher,...
Definition: MachineMemOperand.h:296
llvm::TargetLoweringBase::ZeroOrOneBooleanContent
@ ZeroOrOneBooleanContent
Definition: TargetLowering.h:232
llvm::MachineIRBuilder::getTII
const TargetInstrInfo & getTII()
Definition: MachineIRBuilder.h:263
llvm::MachineIRBuilderState::MF
MachineFunction * MF
MachineFunction under construction.
Definition: MachineIRBuilder.h:46
llvm::MachineMemOperand::MOStore
@ MOStore
The memory access writes data.
Definition: MachineMemOperand.h:136
llvm::MachineIRBuilder::buildDeleteTrailingVectorElements
MachineInstrBuilder buildDeleteTrailingVectorElements(const DstOp &Res, const SrcOp &Op0)
Build and insert a, b, ..., x, y, z = G_UNMERGE_VALUES Op0 Res = G_BUILD_VECTOR a,...
Definition: MachineIRBuilder.cpp:240
llvm::MachineIRBuilder::buildBlockAddress
MachineInstrBuilder buildBlockAddress(Register Res, const BlockAddress *BA)
Build and insert Res = G_BLOCK_ADDR BA.
Definition: MachineIRBuilder.cpp:948
llvm::MachineIRBuilder::validateTruncExt
void validateTruncExt(const LLT Dst, const LLT Src, bool IsExtend)
Definition: MachineIRBuilder.cpp:956
llvm::DstOp::getLLTTy
LLT getLLTTy(const MachineRegisterInfo &MRI) const
Definition: MachineIRBuilder.h:94
llvm::MachineIRBuilder::buildAtomicRMWUmax
MachineInstrBuilder buildAtomicRMWUmax(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_UMAX Addr, Val, MMO.
Definition: MachineIRBuilder.cpp:913
llvm::LegalityPredicates::isVector
LegalityPredicate isVector(unsigned TypeIdx)
True iff the specified type index is a vector.
Definition: LegalityPredicates.cpp:73
isValid
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
Definition: RustDemangle.cpp:187
llvm::MachineIRBuilder::validateShiftOp
void validateShiftOp(const LLT Res, const LLT Op0, const LLT Op1)
Definition: MachineIRBuilder.cpp:174
llvm::TargetSubtargetInfo::getTargetLowering
virtual const TargetLowering * getTargetLowering() const
Definition: TargetSubtargetInfo.h:97
llvm::MachineIRBuilder::buildIntrinsic
MachineInstrBuilder buildIntrinsic(Intrinsic::ID ID, ArrayRef< Register > Res, bool HasSideEffects)
Build and insert either a G_INTRINSIC (if HasSideEffects is false) or G_INTRINSIC_W_SIDE_EFFECTS inst...
Definition: MachineIRBuilder.cpp:709
llvm::MachineRegisterInfo::getType
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
Definition: MachineRegisterInfo.h:740
MachineInstrBuilder.h
llvm::MachineIRBuilder::buildSExt
MachineInstrBuilder buildSExt(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_SEXT Op.
Definition: MachineIRBuilder.cpp:447
llvm::BuildMI
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Definition: MachineInstrBuilder.h:328
llvm::DstOp
Definition: MachineIRBuilder.h:65
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:164
llvm::MachineIRBuilder::buildMerge
MachineInstrBuilder buildMerge(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_MERGE_VALUES Op0, ...
Definition: MachineIRBuilder.cpp:573
llvm::SrcOp::getLLTTy
LLT getLLTTy(const MachineRegisterInfo &MRI) const
Definition: MachineIRBuilder.h:165
llvm::MachineInstrBuilder::addMetadata
const MachineInstrBuilder & addMetadata(const MDNode *MD) const
Definition: MachineInstrBuilder.h:236
llvm::MachineIRBuilder::buildLoadFromOffset
MachineInstrBuilder buildLoadFromOffset(const DstOp &Dst, const SrcOp &BasePtr, MachineMemOperand &BaseMMO, int64_t Offset)
Helper to create a load from a constant offset given a base address.
Definition: MachineIRBuilder.cpp:398
llvm::MachineIRBuilder::buildAtomicRMWSub
MachineInstrBuilder buildAtomicRMWSub(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_SUB Addr, Val, MMO.
Definition: MachineIRBuilder.cpp:870
llvm::GlobalValue::getType
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:276
llvm::APInt::getLowBitsSet
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
Definition: APInt.h:289
llvm::IntegerType::get
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:311
llvm::MachineIRBuilder::buildBuildVectorTrunc
MachineInstrBuilder buildBuildVectorTrunc(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_BUILD_VECTOR_TRUNC Op0, ...
Definition: MachineIRBuilder.cpp:644
llvm::MachineIRBuilder::getBoolExtOp
unsigned getBoolExtOp(bool IsVec, bool IsFP) const
Definition: MachineIRBuilder.cpp:457
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
llvm::MachineIRBuilder::buildStore
MachineInstrBuilder buildStore(const SrcOp &Val, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert G_STORE Val, Addr, MMO.
Definition: MachineIRBuilder.cpp:415
llvm::MachineIRBuilder::buildAtomicRMWXchg
MachineInstrBuilder buildAtomicRMWXchg(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_XCHG Addr, Val, MMO.
Definition: MachineIRBuilder.cpp:858
llvm::LLT::getElementType
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
Definition: LowLevelTypeImpl.h:248
MachineFunction.h
llvm::SmallVectorImpl::reserve
void reserve(size_type N)
Definition: SmallVector.h:644
llvm::LLT::scalar
static LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
Definition: LowLevelTypeImpl.h:42
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::ArrayRef::end
iterator end() const
Definition: ArrayRef.h:153
llvm::MachineIRBuilderState::MRI
MachineRegisterInfo * MRI
Information used to verify types are consistent and to create virtual registers.
Definition: MachineIRBuilder.h:50
llvm::SrcOp
Definition: MachineIRBuilder.h:126
llvm::MachineIRBuilder::buildCast
MachineInstrBuilder buildCast(const DstOp &Dst, const SrcOp &Src)
Build and insert an appropriate cast between two registers of equal size.
Definition: MachineIRBuilder.cpp:524
llvm::MachineIRBuilder::buildShuffleSplat
MachineInstrBuilder buildShuffleSplat(const DstOp &Res, const SrcOp &Src)
Build and insert a vector splat of a scalar Src using a G_INSERT_VECTOR_ELT and G_SHUFFLE_VECTOR idio...
Definition: MachineIRBuilder.cpp:653
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38
llvm::LLT
Definition: LowLevelTypeImpl.h:39
llvm::RegState::Undef
@ Undef
Value of the register doesn't matter.
Definition: MachineInstrBuilder.h:52