LLVM  5.0.0
MachineIRBuilder.cpp
Go to the documentation of this file.
1 //===-- llvm/CodeGen/GlobalISel/MachineIRBuilder.cpp - MIBuilder--*- C++ -*-==//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 /// This file implements the MachineIRBuidler class.
11 //===----------------------------------------------------------------------===//
13 
18 #include "llvm/IR/DebugInfo.h"
22 
23 using namespace llvm;
24 
26  this->MF = &MF;
27  this->MBB = nullptr;
28  this->MRI = &MF.getRegInfo();
29  this->TII = MF.getSubtarget().getInstrInfo();
30  this->DL = DebugLoc();
31  this->II = MachineBasicBlock::iterator();
32  this->InsertedInstr = nullptr;
33 }
34 
36  this->MBB = &MBB;
37  this->II = MBB.end();
38  assert(&getMF() == MBB.getParent() &&
39  "Basic block is in a different function");
40 }
41 
43  assert(MI.getParent() && "Instruction is not part of a basic block");
44  setMBB(*MI.getParent());
45  this->II = MI.getIterator();
46 }
47 
50  assert(MBB.getParent() == &getMF() &&
51  "Basic block is in a different function");
52  this->MBB = &MBB;
53  this->II = II;
54 }
55 
57  std::function<void(MachineInstr *)> Inserted) {
58  InsertedInstr = std::move(Inserted);
59 }
60 
62  InsertedInstr = nullptr;
63 }
64 
65 //------------------------------------------------------------------------------
66 // Build instruction variants.
67 //------------------------------------------------------------------------------
68 
70  return insertInstr(buildInstrNoInsert(Opcode));
71 }
72 
74  MachineInstrBuilder MIB = BuildMI(getMF(), DL, getTII().get(Opcode));
75  return MIB;
76 }
77 
78 
80  getMBB().insert(getInsertPt(), MIB);
81  if (InsertedInstr)
82  InsertedInstr(MIB);
83  return MIB;
84 }
85 
87  unsigned Reg, const MDNode *Variable, const MDNode *Expr) {
88  assert(isa<DILocalVariable>(Variable) && "not a variable");
89  assert(cast<DIExpression>(Expr)->isValid() && "not an expression");
90  assert(cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(DL) &&
91  "Expected inlined-at fields to agree");
92  return buildInstr(TargetOpcode::DBG_VALUE)
93  .addReg(Reg, RegState::Debug)
95  .addMetadata(Variable)
96  .addMetadata(Expr);
97 }
98 
100  unsigned Reg, unsigned Offset, const MDNode *Variable, const MDNode *Expr) {
101  assert(isa<DILocalVariable>(Variable) && "not a variable");
102  assert(cast<DIExpression>(Expr)->isValid() && "not an expression");
103  assert(cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(DL) &&
104  "Expected inlined-at fields to agree");
105  return buildInstr(TargetOpcode::DBG_VALUE)
106  .addReg(Reg, RegState::Debug)
107  .addImm(Offset)
108  .addMetadata(Variable)
109  .addMetadata(Expr);
110 }
111 
113  const MDNode *Variable,
114  const MDNode *Expr) {
115  assert(isa<DILocalVariable>(Variable) && "not a variable");
116  assert(cast<DIExpression>(Expr)->isValid() && "not an expression");
117  assert(cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(DL) &&
118  "Expected inlined-at fields to agree");
119  return buildInstr(TargetOpcode::DBG_VALUE)
120  .addFrameIndex(FI)
121  .addImm(0)
122  .addMetadata(Variable)
123  .addMetadata(Expr);
124 }
125 
127  unsigned Offset,
128  const MDNode *Variable,
129  const MDNode *Expr) {
130  assert(isa<DILocalVariable>(Variable) && "not a variable");
131  assert(cast<DIExpression>(Expr)->isValid() && "not an expression");
132  assert(cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(DL) &&
133  "Expected inlined-at fields to agree");
134  auto MIB = buildInstr(TargetOpcode::DBG_VALUE);
135  if (auto *CI = dyn_cast<ConstantInt>(&C)) {
136  if (CI->getBitWidth() > 64)
137  MIB.addCImm(CI);
138  else
139  MIB.addImm(CI->getZExtValue());
140  } else if (auto *CFP = dyn_cast<ConstantFP>(&C)) {
141  MIB.addFPImm(CFP);
142  } else {
143  // Insert %noreg if we didn't find a usable constant and had to drop it.
144  MIB.addReg(0U);
145  }
146 
147  return MIB.addImm(Offset).addMetadata(Variable).addMetadata(Expr);
148 }
149 
151  assert(MRI->getType(Res).isPointer() && "invalid operand type");
152  return buildInstr(TargetOpcode::G_FRAME_INDEX)
153  .addDef(Res)
154  .addFrameIndex(Idx);
155 }
156 
158  const GlobalValue *GV) {
159  assert(MRI->getType(Res).isPointer() && "invalid operand type");
160  assert(MRI->getType(Res).getAddressSpace() ==
161  GV->getType()->getAddressSpace() &&
162  "address space mismatch");
163 
164  return buildInstr(TargetOpcode::G_GLOBAL_VALUE)
165  .addDef(Res)
166  .addGlobalAddress(GV);
167 }
168 
169 MachineInstrBuilder MachineIRBuilder::buildBinaryOp(unsigned Opcode, unsigned Res, unsigned Op0,
170  unsigned Op1) {
171  assert((MRI->getType(Res).isScalar() || MRI->getType(Res).isVector()) &&
172  "invalid operand type");
173  assert(MRI->getType(Res) == MRI->getType(Op0) &&
174  MRI->getType(Res) == MRI->getType(Op1) && "type mismatch");
175 
176  return buildInstr(Opcode)
177  .addDef(Res)
178  .addUse(Op0)
179  .addUse(Op1);
180 }
181 
183  unsigned Op1) {
184  return buildBinaryOp(TargetOpcode::G_ADD, Res, Op0, Op1);
185 }
186 
188  unsigned Op1) {
189  assert(MRI->getType(Res).isPointer() &&
190  MRI->getType(Res) == MRI->getType(Op0) && "type mismatch");
191  assert(MRI->getType(Op1).isScalar() && "invalid offset type");
192 
193  return buildInstr(TargetOpcode::G_GEP)
194  .addDef(Res)
195  .addUse(Op0)
196  .addUse(Op1);
197 }
198 
200 MachineIRBuilder::materializeGEP(unsigned &Res, unsigned Op0,
201  const LLT &ValueTy, uint64_t Value) {
202  assert(Res == 0 && "Res is a result argument");
203  assert(ValueTy.isScalar() && "invalid offset type");
204 
205  if (Value == 0) {
206  Res = Op0;
207  return None;
208  }
209 
210  Res = MRI->createGenericVirtualRegister(MRI->getType(Op0));
211  unsigned TmpReg = MRI->createGenericVirtualRegister(ValueTy);
212 
213  buildConstant(TmpReg, Value);
214  return buildGEP(Res, Op0, TmpReg);
215 }
216 
218  uint32_t NumBits) {
219  assert(MRI->getType(Res).isPointer() &&
220  MRI->getType(Res) == MRI->getType(Op0) && "type mismatch");
221 
222  return buildInstr(TargetOpcode::G_PTR_MASK)
223  .addDef(Res)
224  .addUse(Op0)
225  .addImm(NumBits);
226 }
227 
229  unsigned Op1) {
230  return buildBinaryOp(TargetOpcode::G_SUB, Res, Op0, Op1);
231 }
232 
234  unsigned Op1) {
235  return buildBinaryOp(TargetOpcode::G_MUL, Res, Op0, Op1);
236 }
237 
239  unsigned Op1) {
240  return buildBinaryOp(TargetOpcode::G_AND, Res, Op0, Op1);
241 }
242 
244  unsigned Op1) {
245  return buildBinaryOp(TargetOpcode::G_OR, Res, Op0, Op1);
246 }
247 
249  return buildInstr(TargetOpcode::G_BR).addMBB(&Dest);
250 }
251 
253  assert(MRI->getType(Tgt).isPointer() && "invalid branch destination");
254  return buildInstr(TargetOpcode::G_BRINDIRECT).addUse(Tgt);
255 }
256 
258  assert(MRI->getType(Res) == LLT() || MRI->getType(Op) == LLT() ||
259  MRI->getType(Res) == MRI->getType(Op));
260  return buildInstr(TargetOpcode::COPY).addDef(Res).addUse(Op);
261 }
262 
264  const ConstantInt &Val) {
265  LLT Ty = MRI->getType(Res);
266 
267  assert((Ty.isScalar() || Ty.isPointer()) && "invalid operand type");
268 
269  const ConstantInt *NewVal = &Val;
270  if (Ty.getSizeInBits() != Val.getBitWidth())
271  NewVal = ConstantInt::get(MF->getFunction()->getContext(),
272  Val.getValue().sextOrTrunc(Ty.getSizeInBits()));
273 
274  return buildInstr(TargetOpcode::G_CONSTANT).addDef(Res).addCImm(NewVal);
275 }
276 
278  int64_t Val) {
279  auto IntN = IntegerType::get(MF->getFunction()->getContext(),
280  MRI->getType(Res).getSizeInBits());
281  ConstantInt *CI = ConstantInt::get(IntN, Val, true);
282  return buildConstant(Res, *CI);
283 }
284 
286  const ConstantFP &Val) {
287  assert(MRI->getType(Res).isScalar() && "invalid operand type");
288 
289  return buildInstr(TargetOpcode::G_FCONSTANT).addDef(Res).addFPImm(&Val);
290 }
291 
293  MachineBasicBlock &Dest) {
294  assert(MRI->getType(Tst).isScalar() && "invalid operand type");
295 
296  return buildInstr(TargetOpcode::G_BRCOND).addUse(Tst).addMBB(&Dest);
297 }
298 
300  MachineMemOperand &MMO) {
301  assert(MRI->getType(Res).isValid() && "invalid operand type");
302  assert(MRI->getType(Addr).isPointer() && "invalid operand type");
303 
304  return buildInstr(TargetOpcode::G_LOAD)
305  .addDef(Res)
306  .addUse(Addr)
307  .addMemOperand(&MMO);
308 }
309 
311  MachineMemOperand &MMO) {
312  assert(MRI->getType(Val).isValid() && "invalid operand type");
313  assert(MRI->getType(Addr).isPointer() && "invalid operand type");
314 
315  return buildInstr(TargetOpcode::G_STORE)
316  .addUse(Val)
317  .addUse(Addr)
318  .addMemOperand(&MMO);
319 }
320 
322  unsigned CarryOut,
323  unsigned Op0, unsigned Op1,
324  unsigned CarryIn) {
325  assert(MRI->getType(Res).isScalar() && "invalid operand type");
326  assert(MRI->getType(Res) == MRI->getType(Op0) &&
327  MRI->getType(Res) == MRI->getType(Op1) && "type mismatch");
328  assert(MRI->getType(CarryOut).isScalar() && "invalid operand type");
329  assert(MRI->getType(CarryOut) == MRI->getType(CarryIn) && "type mismatch");
330 
331  return buildInstr(TargetOpcode::G_UADDE)
332  .addDef(Res)
333  .addDef(CarryOut)
334  .addUse(Op0)
335  .addUse(Op1)
336  .addUse(CarryIn);
337 }
338 
340  validateTruncExt(Res, Op, true);
341  return buildInstr(TargetOpcode::G_ANYEXT).addDef(Res).addUse(Op);
342 }
343 
345  validateTruncExt(Res, Op, true);
346  return buildInstr(TargetOpcode::G_SEXT).addDef(Res).addUse(Op);
347 }
348 
350  validateTruncExt(Res, Op, true);
351  return buildInstr(TargetOpcode::G_ZEXT).addDef(Res).addUse(Op);
352 }
353 
355  unsigned Op) {
356  assert(MRI->getType(Res).isScalar() || MRI->getType(Res).isVector());
357  assert(MRI->getType(Res).isScalar() == MRI->getType(Op).isScalar());
358 
359  unsigned Opcode = TargetOpcode::COPY;
360  if (MRI->getType(Res).getSizeInBits() > MRI->getType(Op).getSizeInBits())
361  Opcode = TargetOpcode::G_SEXT;
362  else if (MRI->getType(Res).getSizeInBits() < MRI->getType(Op).getSizeInBits())
363  Opcode = TargetOpcode::G_TRUNC;
364  else
365  assert(MRI->getType(Res) == MRI->getType(Op));
366 
367  return buildInstr(Opcode).addDef(Res).addUse(Op);
368 }
369 
371  unsigned Op) {
372  assert(MRI->getType(Res).isScalar() || MRI->getType(Res).isVector());
373  assert(MRI->getType(Res).isScalar() == MRI->getType(Op).isScalar());
374 
375  unsigned Opcode = TargetOpcode::COPY;
376  if (MRI->getType(Res).getSizeInBits() > MRI->getType(Op).getSizeInBits())
377  Opcode = TargetOpcode::G_ZEXT;
378  else if (MRI->getType(Res).getSizeInBits() < MRI->getType(Op).getSizeInBits())
379  Opcode = TargetOpcode::G_TRUNC;
380  else
381  assert(MRI->getType(Res) == MRI->getType(Op));
382 
383  return buildInstr(Opcode).addDef(Res).addUse(Op);
384 }
385 
387  LLT SrcTy = MRI->getType(Src);
388  LLT DstTy = MRI->getType(Dst);
389  if (SrcTy == DstTy)
390  return buildCopy(Dst, Src);
391 
392  unsigned Opcode;
393  if (SrcTy.isPointer() && DstTy.isScalar())
394  Opcode = TargetOpcode::G_PTRTOINT;
395  else if (DstTy.isPointer() && SrcTy.isScalar())
396  Opcode = TargetOpcode::G_INTTOPTR;
397  else {
398  assert(!SrcTy.isPointer() && !DstTy.isPointer() && "n G_ADDRCAST yet");
399  Opcode = TargetOpcode::G_BITCAST;
400  }
401 
402  return buildInstr(Opcode).addDef(Dst).addUse(Src);
403 }
404 
406  uint64_t Index) {
407 #ifndef NDEBUG
408  assert(MRI->getType(Src).isValid() && "invalid operand type");
409  assert(MRI->getType(Res).isValid() && "invalid operand type");
410  assert(Index + MRI->getType(Res).getSizeInBits() <=
411  MRI->getType(Src).getSizeInBits() &&
412  "extracting off end of register");
413 #endif
414 
415  if (MRI->getType(Res).getSizeInBits() == MRI->getType(Src).getSizeInBits()) {
416  assert(Index == 0 && "insertion past the end of a register");
417  return buildCast(Res, Src);
418  }
419 
420  return buildInstr(TargetOpcode::G_EXTRACT)
421  .addDef(Res)
422  .addUse(Src)
423  .addImm(Index);
424 }
425 
427  ArrayRef<uint64_t> Indices) {
428 #ifndef NDEBUG
429  assert(Ops.size() == Indices.size() && "incompatible args");
430  assert(!Ops.empty() && "invalid trivial sequence");
431  assert(std::is_sorted(Indices.begin(), Indices.end()) &&
432  "sequence offsets must be in ascending order");
433 
434  assert(MRI->getType(Res).isValid() && "invalid operand type");
435  for (auto Op : Ops)
436  assert(MRI->getType(Op).isValid() && "invalid operand type");
437 #endif
438 
439  LLT ResTy = MRI->getType(Res);
440  LLT OpTy = MRI->getType(Ops[0]);
441  unsigned OpSize = OpTy.getSizeInBits();
442  bool MaybeMerge = true;
443  for (unsigned i = 0; i < Ops.size(); ++i) {
444  if (MRI->getType(Ops[i]) != OpTy || Indices[i] != i * OpSize) {
445  MaybeMerge = false;
446  break;
447  }
448  }
449 
450  if (MaybeMerge && Ops.size() * OpSize == ResTy.getSizeInBits()) {
451  buildMerge(Res, Ops);
452  return;
453  }
454 
455  unsigned ResIn = MRI->createGenericVirtualRegister(ResTy);
456  buildUndef(ResIn);
457 
458  for (unsigned i = 0; i < Ops.size(); ++i) {
459  unsigned ResOut =
460  i + 1 == Ops.size() ? Res : MRI->createGenericVirtualRegister(ResTy);
461  buildInsert(ResOut, ResIn, Ops[i], Indices[i]);
462  ResIn = ResOut;
463  }
464 }
465 
467  return buildInstr(TargetOpcode::G_IMPLICIT_DEF).addDef(Res);
468 }
469 
471  ArrayRef<unsigned> Ops) {
472 
473 #ifndef NDEBUG
474  assert(!Ops.empty() && "invalid trivial sequence");
475  LLT Ty = MRI->getType(Ops[0]);
476  for (auto Reg : Ops)
477  assert(MRI->getType(Reg) == Ty && "type mismatch in input list");
478  assert(Ops.size() * MRI->getType(Ops[0]).getSizeInBits() ==
479  MRI->getType(Res).getSizeInBits() &&
480  "input operands do not cover output register");
481 #endif
482 
483  if (Ops.size() == 1)
484  return buildCast(Res, Ops[0]);
485 
486  MachineInstrBuilder MIB = buildInstr(TargetOpcode::G_MERGE_VALUES);
487  MIB.addDef(Res);
488  for (unsigned i = 0; i < Ops.size(); ++i)
489  MIB.addUse(Ops[i]);
490  return MIB;
491 }
492 
494  unsigned Op) {
495 
496 #ifndef NDEBUG
497  assert(!Res.empty() && "invalid trivial sequence");
498  LLT Ty = MRI->getType(Res[0]);
499  for (auto Reg : Res)
500  assert(MRI->getType(Reg) == Ty && "type mismatch in input list");
501  assert(Res.size() * MRI->getType(Res[0]).getSizeInBits() ==
502  MRI->getType(Op).getSizeInBits() &&
503  "input operands do not cover output register");
504 #endif
505 
506  MachineInstrBuilder MIB = buildInstr(TargetOpcode::G_UNMERGE_VALUES);
507  for (unsigned i = 0; i < Res.size(); ++i)
508  MIB.addDef(Res[i]);
509  MIB.addUse(Op);
510  return MIB;
511 }
512 
514  unsigned Op, unsigned Index) {
515  assert(Index + MRI->getType(Op).getSizeInBits() <=
516  MRI->getType(Res).getSizeInBits() &&
517  "insertion past the end of a register");
518 
519  if (MRI->getType(Res).getSizeInBits() == MRI->getType(Op).getSizeInBits()) {
520  return buildCast(Res, Op);
521  }
522 
523  return buildInstr(TargetOpcode::G_INSERT)
524  .addDef(Res)
525  .addUse(Src)
526  .addUse(Op)
527  .addImm(Index);
528 }
529 
531  unsigned Res,
532  bool HasSideEffects) {
533  auto MIB =
534  buildInstr(HasSideEffects ? TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS
535  : TargetOpcode::G_INTRINSIC);
536  if (Res)
537  MIB.addDef(Res);
538  MIB.addIntrinsicID(ID);
539  return MIB;
540 }
541 
543  validateTruncExt(Res, Op, false);
544  return buildInstr(TargetOpcode::G_TRUNC).addDef(Res).addUse(Op);
545 }
546 
548  validateTruncExt(Res, Op, false);
549  return buildInstr(TargetOpcode::G_FPTRUNC).addDef(Res).addUse(Op);
550 }
551 
553  unsigned Res, unsigned Op0,
554  unsigned Op1) {
555 #ifndef NDEBUG
556  assert(MRI->getType(Op0) == MRI->getType(Op0) && "type mismatch");
557  assert(CmpInst::isIntPredicate(Pred) && "invalid predicate");
558  if (MRI->getType(Op0).isScalar() || MRI->getType(Op0).isPointer())
559  assert(MRI->getType(Res).isScalar() && "type mismatch");
560  else
561  assert(MRI->getType(Res).isVector() &&
562  MRI->getType(Res).getNumElements() ==
563  MRI->getType(Op0).getNumElements() &&
564  "type mismatch");
565 #endif
566 
567  return buildInstr(TargetOpcode::G_ICMP)
568  .addDef(Res)
569  .addPredicate(Pred)
570  .addUse(Op0)
571  .addUse(Op1);
572 }
573 
575  unsigned Res, unsigned Op0,
576  unsigned Op1) {
577 #ifndef NDEBUG
578  assert((MRI->getType(Op0).isScalar() || MRI->getType(Op0).isVector()) &&
579  "invalid operand type");
580  assert(MRI->getType(Op0) == MRI->getType(Op1) && "type mismatch");
581  assert(CmpInst::isFPPredicate(Pred) && "invalid predicate");
582  if (MRI->getType(Op0).isScalar())
583  assert(MRI->getType(Res).isScalar() && "type mismatch");
584  else
585  assert(MRI->getType(Res).isVector() &&
586  MRI->getType(Res).getNumElements() ==
587  MRI->getType(Op0).getNumElements() &&
588  "type mismatch");
589 #endif
590 
591  return buildInstr(TargetOpcode::G_FCMP)
592  .addDef(Res)
593  .addPredicate(Pred)
594  .addUse(Op0)
595  .addUse(Op1);
596 }
597 
599  unsigned Op0, unsigned Op1) {
600 #ifndef NDEBUG
601  LLT ResTy = MRI->getType(Res);
602  assert((ResTy.isScalar() || ResTy.isVector() || ResTy.isPointer()) &&
603  "invalid operand type");
604  assert(ResTy == MRI->getType(Op0) && ResTy == MRI->getType(Op1) &&
605  "type mismatch");
606  if (ResTy.isScalar() || ResTy.isPointer())
607  assert(MRI->getType(Tst).isScalar() && "type mismatch");
608  else
609  assert((MRI->getType(Tst).isScalar() ||
610  (MRI->getType(Tst).isVector() &&
611  MRI->getType(Tst).getNumElements() ==
612  MRI->getType(Op0).getNumElements())) &&
613  "type mismatch");
614 #endif
615 
616  return buildInstr(TargetOpcode::G_SELECT)
617  .addDef(Res)
618  .addUse(Tst)
619  .addUse(Op0)
620  .addUse(Op1);
621 }
622 
624  unsigned Val,
625  unsigned Elt,
626  unsigned Idx) {
627 #ifndef NDEBUG
628  LLT ResTy = MRI->getType(Res);
629  LLT ValTy = MRI->getType(Val);
630  LLT EltTy = MRI->getType(Elt);
631  LLT IdxTy = MRI->getType(Idx);
632  assert(ResTy.isVector() && ValTy.isVector() && "invalid operand type");
633  assert(IdxTy.isScalar() && "invalid operand type");
634  assert(ResTy.getNumElements() == ValTy.getNumElements() && "type mismatch");
635  assert(ResTy.getElementType() == EltTy && "type mismatch");
636 #endif
637 
638  return buildInstr(TargetOpcode::G_INSERT_VECTOR_ELT)
639  .addDef(Res)
640  .addUse(Val)
641  .addUse(Elt)
642  .addUse(Idx);
643 }
644 
646  unsigned Val,
647  unsigned Idx) {
648 #ifndef NDEBUG
649  LLT ResTy = MRI->getType(Res);
650  LLT ValTy = MRI->getType(Val);
651  LLT IdxTy = MRI->getType(Idx);
652  assert(ValTy.isVector() && "invalid operand type");
653  assert((ResTy.isScalar() || ResTy.isPointer()) && "invalid operand type");
654  assert(IdxTy.isScalar() && "invalid operand type");
655  assert(ValTy.getElementType() == ResTy && "type mismatch");
656 #endif
657 
658  return buildInstr(TargetOpcode::G_EXTRACT_VECTOR_ELT)
659  .addDef(Res)
660  .addUse(Val)
661  .addUse(Idx);
662 }
663 
664 void MachineIRBuilder::validateTruncExt(unsigned Dst, unsigned Src,
665  bool IsExtend) {
666 #ifndef NDEBUG
667  LLT SrcTy = MRI->getType(Src);
668  LLT DstTy = MRI->getType(Dst);
669 
670  if (DstTy.isVector()) {
671  assert(SrcTy.isVector() && "mismatched cast between vecot and non-vector");
672  assert(SrcTy.getNumElements() == DstTy.getNumElements() &&
673  "different number of elements in a trunc/ext");
674  } else
675  assert(DstTy.isScalar() && SrcTy.isScalar() && "invalid extend/trunc");
676 
677  if (IsExtend)
678  assert(DstTy.getSizeInBits() > SrcTy.getSizeInBits() &&
679  "invalid narrowing extend");
680  else
681  assert(DstTy.getSizeInBits() < SrcTy.getSizeInBits() &&
682  "invalid widening trunc");
683 #endif
684 }
MachineBasicBlock & getMBB()
Getter for the basic block we currently build.
const MachineInstrBuilder & addMetadata(const MDNode *MD) const
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Definition: Function.cpp:194
MachineInstrBuilder buildGEP(unsigned Res, unsigned Op0, unsigned Op1)
Build and insert Res<def> = G_GEP Op0, Op1.
LLT getType(unsigned VReg) const
Get the low-level type of VReg or LLT{} if VReg is not a generic (target independent) virtual registe...
MachineInstrBuilder buildZExtOrTrunc(unsigned Res, unsigned Op)
Build and insert Res<def> = G_ZEXT Op, Res = G_TRUNC Op, or Res = COPY Op depending on the differing ...
MachineInstrBuilder buildZExt(unsigned Res, unsigned Op)
Build and insert Res<def> = G_ZEXT Op.
unsigned getBitWidth() const
getBitWidth - Return the bitwidth of this constant.
Definition: Constants.h:143
iterator end() const
Definition: ArrayRef.h:138
MachineInstrBuilder buildTrunc(unsigned Res, unsigned Op)
Build and insert Res<def> = G_TRUNC Op.
A debug info location.
Definition: DebugLoc.h:34
Metadata node.
Definition: Metadata.h:862
bool isPointer() const
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
MachineInstrBuilder buildSub(unsigned Res, unsigned Op0, unsigned Op1)
Build and insert Res<def> = G_SUB Op0, Op1.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:495
MachineInstrBuilder buildAnyExt(unsigned Res, unsigned Op)
Build and insert Res<def> = G_ANYEXT Op0.
unsigned createGenericVirtualRegister(LLT Ty)
Create and return a new generic virtual register with low-level type Ty.
MachineInstrBuilder buildExtract(unsigned Res, unsigned Src, uint64_t Index)
Build and insert `Res0<def>, ...
const MachineInstrBuilder & addDef(unsigned RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
MachineInstrBuilder buildFPTrunc(unsigned Res, unsigned Op)
Build and insert Res<def> = G_FPTRUNC Op.
MachineInstrBuilder buildSelect(unsigned Res, unsigned Tst, unsigned Op0, unsigned Op1)
Build and insert a Res = G_SELECT Tst, Op0, Op1.
MachineInstrBuilder buildFCmp(CmpInst::Predicate Pred, unsigned Res, unsigned Op0, unsigned Op1)
Build and insert a Res = G_FCMP PredOp0, Op1.
MachineInstrBuilder buildStore(unsigned Val, unsigned Addr, MachineMemOperand &MMO)
Build and insert G_STORE Val, Addr, MMO.
A description of a memory reference used in the backend.
void setInsertPt(MachineBasicBlock &MBB, MachineBasicBlock::iterator II)
Set the insertion point before the specified position.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
unsigned getAddressSpace() const
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:138
MachineInstrBuilder buildFConstant(unsigned Res, const ConstantFP &Val)
Build and insert Res = G_FCONSTANT Val.
Reg
All possible values of the reg field in the ModR/M byte.
MachineInstrBuilder buildExtractVectorElement(unsigned Res, unsigned Val, unsigned Idx)
Build and insert Res<def> = G_EXTRACT_VECTOR_ELT Val, Idx.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
MachineInstrBuilder buildInsertVectorElement(unsigned Res, unsigned Val, unsigned Elt, unsigned Idx)
Build and insert Res<def> = G_INSERT_VECTOR_ELT Val, Elt, Idx.
MachineInstrBuilder buildInstrNoInsert(unsigned Opcode)
Build but don't insert <empty> = Opcode <empty>.
MachineFunction & getMF()
Getter for the function we currently build.
void recordInsertions(std::function< void(MachineInstr *)> InsertedInstr)
MachineInstrBuilder buildConstDbgValue(const Constant &C, unsigned Offset, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instructions specifying that Variable is given by C (suitably modified b...
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:139
MachineBasicBlock::iterator getInsertPt()
Current insertion point for new instructions.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
MachineInstrBuilder buildBr(MachineBasicBlock &BB)
Build and insert G_BR Dest.
MachineInstrBundleIterator< MachineInstr > iterator
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
This is an important base class in LLVM.
Definition: Constant.h:42
MachineInstrBuilder buildPtrMask(unsigned Res, unsigned Op0, uint32_t NumBits)
Build and insert Res<def> = G_PTR_MASK Op0, NumBits.
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:264
MachineInstrBuilder buildIntrinsic(Intrinsic::ID ID, unsigned Res, bool HasSideEffects)
Build and insert either a G_INTRINSIC (if HasSideEffects is false) or G_INTRINSIC_W_SIDE_EFFECTS inst...
bool isIntPredicate() const
Definition: InstrTypes.h:952
MachineInstrBuilder buildICmp(CmpInst::Predicate Pred, unsigned Res, unsigned Op0, unsigned Op1)
Build and insert a Res = G_ICMP Pred, Op0, Op1.
void setInstr(MachineInstr &MI)
Set the insertion point to before MI.
const MachineInstrBuilder & addPredicate(CmpInst::Predicate Pred) const
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:860
iterator begin() const
Definition: ArrayRef.h:137
MachineInstrBuilder buildInsert(unsigned Res, unsigned Src, unsigned Op, unsigned Index)
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...
MachineInstrBuilder buildIndirectDbgValue(unsigned Reg, unsigned Offset, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in me...
self_iterator getIterator()
Definition: ilist_node.h:82
void setMF(MachineFunction &)
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:144
MachineInstrBuilder buildOr(unsigned Res, unsigned Op0, unsigned Op1)
Build and insert Res<def> = G_OR Op0, Op1.
MachineInstrBuilder buildBrIndirect(unsigned Tgt)
Build and insert G_BRINDIRECT Tgt.
MachineInstrBuilder buildSExtOrTrunc(unsigned Res, unsigned Op)
Build and insert Res<def> = G_SEXT Op, Res = G_TRUNC Op, or Res = COPY Op depending on the differing ...
MachineInstrBuilder buildUAdde(unsigned Res, unsigned CarryOut, unsigned Op0, unsigned Op1, unsigned CarryIn)
Build and insert Res<def>, CarryOut<def> = G_UADDE Op0, Op1, CarryIn.
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
MachineInstrBuilder buildFrameIndex(unsigned Res, int Idx)
Build and insert Res<def> = G_FRAME_INDEX Idx.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:240
This is the shared class of boolean and integer constants.
Definition: Constants.h:84
void buildSequence(unsigned Res, ArrayRef< unsigned > Ops, ArrayRef< uint64_t > Indices)
Build and insert instructions to put Ops together at the specified p Indices to form a larger registe...
MachineInstrBuilder buildCopy(unsigned Res, unsigned Op)
Build and insert Res<def> = COPY Op.
const MachineInstrBuilder & addCImm(const ConstantInt *Val) const
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:560
const MachineInstrBuilder & addFrameIndex(int Idx) const
This file declares the MachineIRBuilder class.
MachineInstrBuilder buildSExt(unsigned Res, unsigned Op)
Build and insert Res<def> = G_SEXT Op.
MachineInstrBuilder buildAnd(unsigned Res, unsigned Op0, unsigned Op1)
Build and insert Res<def> = G_AND Op0, Op1.
bool isScalar() const
bool isFPPredicate() const
Definition: InstrTypes.h:951
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned char TargetFlags=0) const
Representation of each machine instruction.
Definition: MachineInstr.h:59
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:260
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
MachineInstrBuilder buildUndef(unsigned Dst)
Build and insert Res = IMPLICIT_DEF.
MachineInstrBuilder buildDirectDbgValue(unsigned Reg, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in Re...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
MachineInstrBuilder buildAdd(unsigned Res, unsigned Op0, unsigned Op1)
Build and insert Res<def> = G_ADD Op0, Op1.
#define C
Definition: LargeTest.cpp:25
void setMBB(MachineBasicBlock &MBB)
Set the insertion point to the end of MBB.
MachineInstrBuilder buildConstant(unsigned Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
MachineInstrBuilder buildMul(unsigned Res, unsigned Op0, unsigned Op1)
Build and insert Res<def> = G_MUL Op0, Op1.
bool isValid() const
INITIALIZE_PASS(HexagonGenMux,"hexagon-gen-mux","Hexagon generate mux instructions", false, false) void HexagonGenMux I isValid()
Optional< MachineInstrBuilder > materializeGEP(unsigned &Res, unsigned Op0, const LLT &ValueTy, uint64_t Value)
Materialize and insert Res<def> = G_GEP Op0, (G_CONSTANT Value)
MachineInstrBuilder buildUnmerge(ArrayRef< unsigned > Res, unsigned Op)
Build and insert Res0<def>, ...
const MachineInstrBuilder & addFPImm(const ConstantFP *Val) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MachineInstrBuilder buildCast(unsigned Dst, unsigned Src)
Build and insert an appropriate cast between two registers of equal size.
const MachineInstrBuilder & addUse(unsigned RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
virtual const TargetInstrInfo * getInstrInfo() const
MachineInstrBuilder insertInstr(MachineInstrBuilder MIB)
Insert an existing instruction at the insertion point.
LLVM Value Representation.
Definition: Value.h:73
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
Definition: APInt.cpp:891
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
MachineInstrBuilder buildLoad(unsigned Res, unsigned Addr, MachineMemOperand &MMO)
Build and insert Res<def> = G_LOAD Addr, MMO.
print Print MemDeps of function
IRTranslator LLVM IR MI
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
bool isVector() const
MachineInstrBuilder buildGlobalValue(unsigned Res, const GlobalValue *GV)
Build and insert Res<def> = G_GLOBAL_VALUE GV.
MachineInstrBuilder buildMerge(unsigned Res, ArrayRef< unsigned > Ops)
Build and insert Res<def> = G_MERGE_VALUES Op0, ...
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
MachineInstrBuilder buildBrCond(unsigned Tst, MachineBasicBlock &BB)
Build and insert G_BRCOND Tst, Dest.