LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IRBuilder.h
Go to the documentation of this file.
1 //===---- llvm/IRBuilder.h - Builder for LLVM Instructions ------*- 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 //
10 // This file defines the IRBuilder class, which is used as a convenient way
11 // to create LLVM instructions with a consistent and simplified interface.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_IR_IRBUILDER_H
16 #define LLVM_IR_IRBUILDER_H
17 
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/ADT/Twine.h"
21 #include "llvm/IR/BasicBlock.h"
22 #include "llvm/IR/DataLayout.h"
23 #include "llvm/IR/Instructions.h"
24 #include "llvm/IR/LLVMContext.h"
25 #include "llvm/IR/Operator.h"
29 
30 namespace llvm {
31  class MDNode;
32 
33 /// \brief This provides the default implementation of the IRBuilder
34 /// 'InsertHelper' method that is called whenever an instruction is created by
35 /// IRBuilder and needs to be inserted.
36 ///
37 /// By default, this inserts the instruction at the insertion point.
38 template <bool preserveNames = true>
40 protected:
42  BasicBlock *BB, BasicBlock::iterator InsertPt) const {
43  if (BB) BB->getInstList().insert(InsertPt, I);
44  if (preserveNames)
45  I->setName(Name);
46  }
47 };
48 
49 /// \brief Common base class shared among various IRBuilders.
51  DebugLoc CurDbgLocation;
52 protected:
56 
59 public:
60 
61  IRBuilderBase(LLVMContext &context, MDNode *FPMathTag = 0)
62  : Context(context), DefaultFPMathTag(FPMathTag), FMF() {
64  }
65 
66  //===--------------------------------------------------------------------===//
67  // Builder configuration methods
68  //===--------------------------------------------------------------------===//
69 
70  /// \brief Clear the insertion point: created instructions will not be
71  /// inserted into a block.
73  BB = 0;
74  InsertPt = 0;
75  }
76 
77  BasicBlock *GetInsertBlock() const { return BB; }
79  LLVMContext &getContext() const { return Context; }
80 
81  /// \brief This specifies that created instructions should be appended to the
82  /// end of the specified block.
83  void SetInsertPoint(BasicBlock *TheBB) {
84  BB = TheBB;
85  InsertPt = BB->end();
86  }
87 
88  /// \brief This specifies that created instructions should be inserted before
89  /// the specified instruction.
91  BB = I->getParent();
92  InsertPt = I;
93  assert(I != BB->end() && "Can't read debug loc from end()");
95  }
96 
97  /// \brief This specifies that created instructions should be inserted at the
98  /// specified point.
100  BB = TheBB;
101  InsertPt = IP;
102  }
103 
104  /// \brief Find the nearest point that dominates this use, and specify that
105  /// created instructions should be inserted at this point.
106  void SetInsertPoint(Use &U) {
107  Instruction *UseInst = cast<Instruction>(U.getUser());
108  if (PHINode *Phi = dyn_cast<PHINode>(UseInst)) {
109  BasicBlock *PredBB = Phi->getIncomingBlock(U);
110  assert(U != PredBB->getTerminator() && "critical edge not split");
111  SetInsertPoint(PredBB, PredBB->getTerminator());
112  return;
113  }
114  SetInsertPoint(UseInst);
115  }
116 
117  /// \brief Set location information used by debugging information.
119  CurDbgLocation = L;
120  }
121 
122  /// \brief Get location information used by debugging information.
123  DebugLoc getCurrentDebugLocation() const { return CurDbgLocation; }
124 
125  /// \brief If this builder has a current debug location, set it on the
126  /// specified instruction.
128  if (!CurDbgLocation.isUnknown())
129  I->setDebugLoc(CurDbgLocation);
130  }
131 
132  /// \brief Get the return type of the current function that we're emitting
133  /// into.
135 
136  /// InsertPoint - A saved insertion point.
137  class InsertPoint {
138  BasicBlock *Block;
139  BasicBlock::iterator Point;
140 
141  public:
142  /// \brief Creates a new insertion point which doesn't point to anything.
143  InsertPoint() : Block(0) {}
144 
145  /// \brief Creates a new insertion point at the given location.
147  : Block(InsertBlock), Point(InsertPoint) {}
148 
149  /// \brief Returns true if this insert point is set.
150  bool isSet() const { return (Block != 0); }
151 
152  llvm::BasicBlock *getBlock() const { return Block; }
153  llvm::BasicBlock::iterator getPoint() const { return Point; }
154  };
155 
156  /// \brief Returns the current insert point.
157  InsertPoint saveIP() const {
159  }
160 
161  /// \brief Returns the current insert point, clearing it in the process.
165  return IP;
166  }
167 
168  /// \brief Sets the current insert point to a previously-saved location.
170  if (IP.isSet())
171  SetInsertPoint(IP.getBlock(), IP.getPoint());
172  else
174  }
175 
176  /// \brief Get the floating point math metadata being used.
178 
179  /// \brief Get the flags to be applied to created floating point ops
180  FastMathFlags getFastMathFlags() const { return FMF; }
181 
182  /// \brief Clear the fast-math flags.
184 
185  /// \brief Set the floating point math metadata to be used.
186  void SetDefaultFPMathTag(MDNode *FPMathTag) { DefaultFPMathTag = FPMathTag; }
187 
188  /// \brief Set the fast-math flags to be used with generated fp-math operators
189  void SetFastMathFlags(FastMathFlags NewFMF) { FMF = NewFMF; }
190 
191  //===--------------------------------------------------------------------===//
192  // RAII helpers.
193  //===--------------------------------------------------------------------===//
194 
195  // \brief RAII object that stores the current insertion point and restores it
196  // when the object is destroyed. This includes the debug location.
198  IRBuilderBase &Builder;
200  BasicBlock::iterator Point;
201  DebugLoc DbgLoc;
202 
205 
206  public:
208  : Builder(B), Block(B.GetInsertBlock()), Point(B.GetInsertPoint()),
209  DbgLoc(B.getCurrentDebugLocation()) {}
210 
212  Builder.restoreIP(InsertPoint(Block, Point));
213  Builder.SetCurrentDebugLocation(DbgLoc);
214  }
215  };
216 
217  // \brief RAII object that stores the current fast math settings and restores
218  // them when the object is destroyed.
220  IRBuilderBase &Builder;
221  FastMathFlags FMF;
222  MDNode *FPMathTag;
223 
225  FastMathFlagGuard &operator=(
227 
228  public:
230  : Builder(B), FMF(B.FMF), FPMathTag(B.DefaultFPMathTag) {}
231 
233  Builder.FMF = FMF;
234  Builder.DefaultFPMathTag = FPMathTag;
235  }
236  };
237 
238  //===--------------------------------------------------------------------===//
239  // Miscellaneous creation methods.
240  //===--------------------------------------------------------------------===//
241 
242  /// \brief Make a new global variable with initializer type i8*
243  ///
244  /// Make a new global variable with an initializer that has array of i8 type
245  /// filled in with the null terminated string value specified. The new global
246  /// variable will be marked mergable with any others of the same contents. If
247  /// Name is specified, it is the name of the global variable created.
248  Value *CreateGlobalString(StringRef Str, const Twine &Name = "");
249 
250  /// \brief Get a constant value representing either true or false.
251  ConstantInt *getInt1(bool V) {
252  return ConstantInt::get(getInt1Ty(), V);
253  }
254 
255  /// \brief Get the constant value for i1 true.
258  }
259 
260  /// \brief Get the constant value for i1 false.
263  }
264 
265  /// \brief Get a constant 8-bit value.
266  ConstantInt *getInt8(uint8_t C) {
267  return ConstantInt::get(getInt8Ty(), C);
268  }
269 
270  /// \brief Get a constant 16-bit value.
271  ConstantInt *getInt16(uint16_t C) {
272  return ConstantInt::get(getInt16Ty(), C);
273  }
274 
275  /// \brief Get a constant 32-bit value.
276  ConstantInt *getInt32(uint32_t C) {
277  return ConstantInt::get(getInt32Ty(), C);
278  }
279 
280  /// \brief Get a constant 64-bit value.
281  ConstantInt *getInt64(uint64_t C) {
282  return ConstantInt::get(getInt64Ty(), C);
283  }
284 
285  /// \brief Get a constant integer value.
286  ConstantInt *getInt(const APInt &AI) {
287  return ConstantInt::get(Context, AI);
288  }
289 
290  //===--------------------------------------------------------------------===//
291  // Type creation methods
292  //===--------------------------------------------------------------------===//
293 
294  /// \brief Fetch the type representing a single bit
296  return Type::getInt1Ty(Context);
297  }
298 
299  /// \brief Fetch the type representing an 8-bit integer.
301  return Type::getInt8Ty(Context);
302  }
303 
304  /// \brief Fetch the type representing a 16-bit integer.
306  return Type::getInt16Ty(Context);
307  }
308 
309  /// \brief Fetch the type representing a 32-bit integer.
311  return Type::getInt32Ty(Context);
312  }
313 
314  /// \brief Fetch the type representing a 64-bit integer.
316  return Type::getInt64Ty(Context);
317  }
318 
319  /// \brief Fetch the type representing a 32-bit floating point value.
321  return Type::getFloatTy(Context);
322  }
323 
324  /// \brief Fetch the type representing a 64-bit floating point value.
326  return Type::getDoubleTy(Context);
327  }
328 
329  /// \brief Fetch the type representing void.
331  return Type::getVoidTy(Context);
332  }
333 
334  /// \brief Fetch the type representing a pointer to an 8-bit integer value.
335  PointerType *getInt8PtrTy(unsigned AddrSpace = 0) {
336  return Type::getInt8PtrTy(Context, AddrSpace);
337  }
338 
339  /// \brief Fetch the type representing a pointer to an integer value.
340  IntegerType* getIntPtrTy(const DataLayout *DL, unsigned AddrSpace = 0) {
341  return DL->getIntPtrType(Context, AddrSpace);
342  }
343 
344  //===--------------------------------------------------------------------===//
345  // Intrinsic creation methods
346  //===--------------------------------------------------------------------===//
347 
348  /// \brief Create and insert a memset to the specified pointer and the
349  /// specified value.
350  ///
351  /// If the pointer isn't an i8*, it will be converted. If a TBAA tag is
352  /// specified, it will be added to the instruction.
353  CallInst *CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, unsigned Align,
354  bool isVolatile = false, MDNode *TBAATag = 0) {
355  return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile, TBAATag);
356  }
357 
358  CallInst *CreateMemSet(Value *Ptr, Value *Val, Value *Size, unsigned Align,
359  bool isVolatile = false, MDNode *TBAATag = 0);
360 
361  /// \brief Create and insert a memcpy between the specified pointers.
362  ///
363  /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
364  /// specified, it will be added to the instruction.
365  CallInst *CreateMemCpy(Value *Dst, Value *Src, uint64_t Size, unsigned Align,
366  bool isVolatile = false, MDNode *TBAATag = 0,
367  MDNode *TBAAStructTag = 0) {
368  return CreateMemCpy(Dst, Src, getInt64(Size), Align, isVolatile, TBAATag,
369  TBAAStructTag);
370  }
371 
372  CallInst *CreateMemCpy(Value *Dst, Value *Src, Value *Size, unsigned Align,
373  bool isVolatile = false, MDNode *TBAATag = 0,
374  MDNode *TBAAStructTag = 0);
375 
376  /// \brief Create and insert a memmove between the specified
377  /// pointers.
378  ///
379  /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
380  /// specified, it will be added to the instruction.
381  CallInst *CreateMemMove(Value *Dst, Value *Src, uint64_t Size, unsigned Align,
382  bool isVolatile = false, MDNode *TBAATag = 0) {
383  return CreateMemMove(Dst, Src, getInt64(Size), Align, isVolatile, TBAATag);
384  }
385 
386  CallInst *CreateMemMove(Value *Dst, Value *Src, Value *Size, unsigned Align,
387  bool isVolatile = false, MDNode *TBAATag = 0);
388 
389  /// \brief Create a lifetime.start intrinsic.
390  ///
391  /// If the pointer isn't i8* it will be converted.
392  CallInst *CreateLifetimeStart(Value *Ptr, ConstantInt *Size = 0);
393 
394  /// \brief Create a lifetime.end intrinsic.
395  ///
396  /// If the pointer isn't i8* it will be converted.
397  CallInst *CreateLifetimeEnd(Value *Ptr, ConstantInt *Size = 0);
398 
399 private:
400  Value *getCastedInt8PtrValue(Value *Ptr);
401 };
402 
403 /// \brief This provides a uniform API for creating instructions and inserting
404 /// them into a basic block: either at the end of a BasicBlock, or at a specific
405 /// iterator location in a block.
406 ///
407 /// Note that the builder does not expose the full generality of LLVM
408 /// instructions. For access to extra instruction properties, use the mutators
409 /// (e.g. setVolatile) on the instructions after they have been
410 /// created. Convenience state exists to specify fast-math flags and fp-math
411 /// tags.
412 ///
413 /// The first template argument handles whether or not to preserve names in the
414 /// final instruction output. This defaults to on. The second template argument
415 /// specifies a class to use for creating constants. This defaults to creating
416 /// minimally folded constants. The fourth template argument allows clients to
417 /// specify custom insertion hooks that are called on every newly created
418 /// insertion.
419 template<bool preserveNames = true, typename T = ConstantFolder,
420  typename Inserter = IRBuilderDefaultInserter<preserveNames> >
421 class IRBuilder : public IRBuilderBase, public Inserter {
422  T Folder;
423 public:
424  IRBuilder(LLVMContext &C, const T &F, const Inserter &I = Inserter(),
425  MDNode *FPMathTag = 0)
426  : IRBuilderBase(C, FPMathTag), Inserter(I), Folder(F) {
427  }
428 
429  explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = 0)
430  : IRBuilderBase(C, FPMathTag), Folder() {
431  }
432 
433  explicit IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag = 0)
434  : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder(F) {
435  SetInsertPoint(TheBB);
436  }
437 
438  explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = 0)
439  : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder() {
440  SetInsertPoint(TheBB);
441  }
442 
443  explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = 0)
444  : IRBuilderBase(IP->getContext(), FPMathTag), Folder() {
445  SetInsertPoint(IP);
447  }
448 
449  explicit IRBuilder(Use &U, MDNode *FPMathTag = 0)
450  : IRBuilderBase(U->getContext(), FPMathTag), Folder() {
451  SetInsertPoint(U);
452  SetCurrentDebugLocation(cast<Instruction>(U.getUser())->getDebugLoc());
453  }
454 
456  MDNode *FPMathTag = 0)
457  : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder(F) {
458  SetInsertPoint(TheBB, IP);
459  }
460 
461  IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, MDNode *FPMathTag = 0)
462  : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder() {
463  SetInsertPoint(TheBB, IP);
464  }
465 
466  /// \brief Get the constant folder being used.
467  const T &getFolder() { return Folder; }
468 
469  /// \brief Return true if this builder is configured to actually add the
470  /// requested names to IR created through it.
471  bool isNamePreserving() const { return preserveNames; }
472 
473  /// \brief Insert and return the specified instruction.
474  template<typename InstTy>
475  InstTy *Insert(InstTy *I, const Twine &Name = "") const {
476  this->InsertHelper(I, Name, BB, InsertPt);
477  this->SetInstDebugLocation(I);
478  return I;
479  }
480 
481  /// \brief No-op overload to handle constants.
482  Constant *Insert(Constant *C, const Twine& = "") const {
483  return C;
484  }
485 
486  //===--------------------------------------------------------------------===//
487  // Instruction creation methods: Terminators
488  //===--------------------------------------------------------------------===//
489 
490 private:
491  /// \brief Helper to add branch weight metadata onto an instruction.
492  /// \returns The annotated instruction.
493  template <typename InstTy>
494  InstTy *addBranchWeights(InstTy *I, MDNode *Weights) {
495  if (Weights)
496  I->setMetadata(LLVMContext::MD_prof, Weights);
497  return I;
498  }
499 
500 public:
501  /// \brief Create a 'ret void' instruction.
504  }
505 
506  /// \brief Create a 'ret <val>' instruction.
508  return Insert(ReturnInst::Create(Context, V));
509  }
510 
511  /// \brief Create a sequence of N insertvalue instructions,
512  /// with one Value from the retVals array each, that build a aggregate
513  /// return value one value at a time, and a ret instruction to return
514  /// the resulting aggregate value.
515  ///
516  /// This is a convenience function for code that uses aggregate return values
517  /// as a vehicle for having multiple return values.
518  ReturnInst *CreateAggregateRet(Value *const *retVals, unsigned N) {
520  for (unsigned i = 0; i != N; ++i)
521  V = CreateInsertValue(V, retVals[i], i, "mrv");
522  return Insert(ReturnInst::Create(Context, V));
523  }
524 
525  /// \brief Create an unconditional 'br label X' instruction.
527  return Insert(BranchInst::Create(Dest));
528  }
529 
530  /// \brief Create a conditional 'br Cond, TrueDest, FalseDest'
531  /// instruction.
533  MDNode *BranchWeights = 0) {
534  return Insert(addBranchWeights(BranchInst::Create(True, False, Cond),
535  BranchWeights));
536  }
537 
538  /// \brief Create a switch instruction with the specified value, default dest,
539  /// and with a hint for the number of cases that will be added (for efficient
540  /// allocation).
541  SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10,
542  MDNode *BranchWeights = 0) {
543  return Insert(addBranchWeights(SwitchInst::Create(V, Dest, NumCases),
544  BranchWeights));
545  }
546 
547  /// \brief Create an indirect branch instruction with the specified address
548  /// operand, with an optional hint for the number of destinations that will be
549  /// added (for efficient allocation).
550  IndirectBrInst *CreateIndirectBr(Value *Addr, unsigned NumDests = 10) {
551  return Insert(IndirectBrInst::Create(Addr, NumDests));
552  }
553 
554  InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
555  BasicBlock *UnwindDest, const Twine &Name = "") {
556  return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest,
558  Name);
559  }
560  InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
561  BasicBlock *UnwindDest, Value *Arg1,
562  const Twine &Name = "") {
563  return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Arg1),
564  Name);
565  }
566  InvokeInst *CreateInvoke3(Value *Callee, BasicBlock *NormalDest,
567  BasicBlock *UnwindDest, Value *Arg1,
568  Value *Arg2, Value *Arg3,
569  const Twine &Name = "") {
570  Value *Args[] = { Arg1, Arg2, Arg3 };
571  return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args),
572  Name);
573  }
574  /// \brief Create an invoke instruction.
575  InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
576  BasicBlock *UnwindDest, ArrayRef<Value *> Args,
577  const Twine &Name = "") {
578  return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args),
579  Name);
580  }
581 
583  return Insert(ResumeInst::Create(Exn));
584  }
585 
587  return Insert(new UnreachableInst(Context));
588  }
589 
590  //===--------------------------------------------------------------------===//
591  // Instruction creation methods: Binary Operators
592  //===--------------------------------------------------------------------===//
593 private:
594  BinaryOperator *CreateInsertNUWNSWBinOp(BinaryOperator::BinaryOps Opc,
595  Value *LHS, Value *RHS,
596  const Twine &Name,
597  bool HasNUW, bool HasNSW) {
598  BinaryOperator *BO = Insert(BinaryOperator::Create(Opc, LHS, RHS), Name);
599  if (HasNUW) BO->setHasNoUnsignedWrap();
600  if (HasNSW) BO->setHasNoSignedWrap();
601  return BO;
602  }
603 
604  Instruction *AddFPMathAttributes(Instruction *I,
605  MDNode *FPMathTag,
606  FastMathFlags FMF) const {
607  if (!FPMathTag)
608  FPMathTag = DefaultFPMathTag;
609  if (FPMathTag)
610  I->setMetadata(LLVMContext::MD_fpmath, FPMathTag);
611  I->setFastMathFlags(FMF);
612  return I;
613  }
614 public:
615  Value *CreateAdd(Value *LHS, Value *RHS, const Twine &Name = "",
616  bool HasNUW = false, bool HasNSW = false) {
617  if (Constant *LC = dyn_cast<Constant>(LHS))
618  if (Constant *RC = dyn_cast<Constant>(RHS))
619  return Insert(Folder.CreateAdd(LC, RC, HasNUW, HasNSW), Name);
620  return CreateInsertNUWNSWBinOp(Instruction::Add, LHS, RHS, Name,
621  HasNUW, HasNSW);
622  }
623  Value *CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
624  return CreateAdd(LHS, RHS, Name, false, true);
625  }
626  Value *CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
627  return CreateAdd(LHS, RHS, Name, true, false);
628  }
629  Value *CreateFAdd(Value *LHS, Value *RHS, const Twine &Name = "",
630  MDNode *FPMathTag = 0) {
631  if (Constant *LC = dyn_cast<Constant>(LHS))
632  if (Constant *RC = dyn_cast<Constant>(RHS))
633  return Insert(Folder.CreateFAdd(LC, RC), Name);
634  return Insert(AddFPMathAttributes(BinaryOperator::CreateFAdd(LHS, RHS),
635  FPMathTag, FMF), Name);
636  }
637  Value *CreateSub(Value *LHS, Value *RHS, const Twine &Name = "",
638  bool HasNUW = false, bool HasNSW = false) {
639  if (Constant *LC = dyn_cast<Constant>(LHS))
640  if (Constant *RC = dyn_cast<Constant>(RHS))
641  return Insert(Folder.CreateSub(LC, RC), Name);
642  return CreateInsertNUWNSWBinOp(Instruction::Sub, LHS, RHS, Name,
643  HasNUW, HasNSW);
644  }
645  Value *CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
646  return CreateSub(LHS, RHS, Name, false, true);
647  }
648  Value *CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
649  return CreateSub(LHS, RHS, Name, true, false);
650  }
651  Value *CreateFSub(Value *LHS, Value *RHS, const Twine &Name = "",
652  MDNode *FPMathTag = 0) {
653  if (Constant *LC = dyn_cast<Constant>(LHS))
654  if (Constant *RC = dyn_cast<Constant>(RHS))
655  return Insert(Folder.CreateFSub(LC, RC), Name);
656  return Insert(AddFPMathAttributes(BinaryOperator::CreateFSub(LHS, RHS),
657  FPMathTag, FMF), Name);
658  }
659  Value *CreateMul(Value *LHS, Value *RHS, const Twine &Name = "",
660  bool HasNUW = false, bool HasNSW = false) {
661  if (Constant *LC = dyn_cast<Constant>(LHS))
662  if (Constant *RC = dyn_cast<Constant>(RHS))
663  return Insert(Folder.CreateMul(LC, RC), Name);
664  return CreateInsertNUWNSWBinOp(Instruction::Mul, LHS, RHS, Name,
665  HasNUW, HasNSW);
666  }
667  Value *CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
668  return CreateMul(LHS, RHS, Name, false, true);
669  }
670  Value *CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
671  return CreateMul(LHS, RHS, Name, true, false);
672  }
673  Value *CreateFMul(Value *LHS, Value *RHS, const Twine &Name = "",
674  MDNode *FPMathTag = 0) {
675  if (Constant *LC = dyn_cast<Constant>(LHS))
676  if (Constant *RC = dyn_cast<Constant>(RHS))
677  return Insert(Folder.CreateFMul(LC, RC), Name);
678  return Insert(AddFPMathAttributes(BinaryOperator::CreateFMul(LHS, RHS),
679  FPMathTag, FMF), Name);
680  }
681  Value *CreateUDiv(Value *LHS, Value *RHS, const Twine &Name = "",
682  bool isExact = false) {
683  if (Constant *LC = dyn_cast<Constant>(LHS))
684  if (Constant *RC = dyn_cast<Constant>(RHS))
685  return Insert(Folder.CreateUDiv(LC, RC, isExact), Name);
686  if (!isExact)
687  return Insert(BinaryOperator::CreateUDiv(LHS, RHS), Name);
688  return Insert(BinaryOperator::CreateExactUDiv(LHS, RHS), Name);
689  }
690  Value *CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
691  return CreateUDiv(LHS, RHS, Name, true);
692  }
693  Value *CreateSDiv(Value *LHS, Value *RHS, const Twine &Name = "",
694  bool isExact = false) {
695  if (Constant *LC = dyn_cast<Constant>(LHS))
696  if (Constant *RC = dyn_cast<Constant>(RHS))
697  return Insert(Folder.CreateSDiv(LC, RC, isExact), Name);
698  if (!isExact)
699  return Insert(BinaryOperator::CreateSDiv(LHS, RHS), Name);
700  return Insert(BinaryOperator::CreateExactSDiv(LHS, RHS), Name);
701  }
702  Value *CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
703  return CreateSDiv(LHS, RHS, Name, true);
704  }
705  Value *CreateFDiv(Value *LHS, Value *RHS, const Twine &Name = "",
706  MDNode *FPMathTag = 0) {
707  if (Constant *LC = dyn_cast<Constant>(LHS))
708  if (Constant *RC = dyn_cast<Constant>(RHS))
709  return Insert(Folder.CreateFDiv(LC, RC), Name);
710  return Insert(AddFPMathAttributes(BinaryOperator::CreateFDiv(LHS, RHS),
711  FPMathTag, FMF), Name);
712  }
713  Value *CreateURem(Value *LHS, Value *RHS, const Twine &Name = "") {
714  if (Constant *LC = dyn_cast<Constant>(LHS))
715  if (Constant *RC = dyn_cast<Constant>(RHS))
716  return Insert(Folder.CreateURem(LC, RC), Name);
717  return Insert(BinaryOperator::CreateURem(LHS, RHS), Name);
718  }
719  Value *CreateSRem(Value *LHS, Value *RHS, const Twine &Name = "") {
720  if (Constant *LC = dyn_cast<Constant>(LHS))
721  if (Constant *RC = dyn_cast<Constant>(RHS))
722  return Insert(Folder.CreateSRem(LC, RC), Name);
723  return Insert(BinaryOperator::CreateSRem(LHS, RHS), Name);
724  }
725  Value *CreateFRem(Value *LHS, Value *RHS, const Twine &Name = "",
726  MDNode *FPMathTag = 0) {
727  if (Constant *LC = dyn_cast<Constant>(LHS))
728  if (Constant *RC = dyn_cast<Constant>(RHS))
729  return Insert(Folder.CreateFRem(LC, RC), Name);
730  return Insert(AddFPMathAttributes(BinaryOperator::CreateFRem(LHS, RHS),
731  FPMathTag, FMF), Name);
732  }
733 
734  Value *CreateShl(Value *LHS, Value *RHS, const Twine &Name = "",
735  bool HasNUW = false, bool HasNSW = false) {
736  if (Constant *LC = dyn_cast<Constant>(LHS))
737  if (Constant *RC = dyn_cast<Constant>(RHS))
738  return Insert(Folder.CreateShl(LC, RC, HasNUW, HasNSW), Name);
739  return CreateInsertNUWNSWBinOp(Instruction::Shl, LHS, RHS, Name,
740  HasNUW, HasNSW);
741  }
742  Value *CreateShl(Value *LHS, const APInt &RHS, const Twine &Name = "",
743  bool HasNUW = false, bool HasNSW = false) {
744  return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
745  HasNUW, HasNSW);
746  }
747  Value *CreateShl(Value *LHS, uint64_t RHS, const Twine &Name = "",
748  bool HasNUW = false, bool HasNSW = false) {
749  return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
750  HasNUW, HasNSW);
751  }
752 
753  Value *CreateLShr(Value *LHS, Value *RHS, const Twine &Name = "",
754  bool isExact = false) {
755  if (Constant *LC = dyn_cast<Constant>(LHS))
756  if (Constant *RC = dyn_cast<Constant>(RHS))
757  return Insert(Folder.CreateLShr(LC, RC, isExact), Name);
758  if (!isExact)
759  return Insert(BinaryOperator::CreateLShr(LHS, RHS), Name);
760  return Insert(BinaryOperator::CreateExactLShr(LHS, RHS), Name);
761  }
762  Value *CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
763  bool isExact = false) {
764  return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
765  }
766  Value *CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name = "",
767  bool isExact = false) {
768  return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
769  }
770 
771  Value *CreateAShr(Value *LHS, Value *RHS, const Twine &Name = "",
772  bool isExact = false) {
773  if (Constant *LC = dyn_cast<Constant>(LHS))
774  if (Constant *RC = dyn_cast<Constant>(RHS))
775  return Insert(Folder.CreateAShr(LC, RC, isExact), Name);
776  if (!isExact)
777  return Insert(BinaryOperator::CreateAShr(LHS, RHS), Name);
778  return Insert(BinaryOperator::CreateExactAShr(LHS, RHS), Name);
779  }
780  Value *CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
781  bool isExact = false) {
782  return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
783  }
784  Value *CreateAShr(Value *LHS, uint64_t RHS, const Twine &Name = "",
785  bool isExact = false) {
786  return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
787  }
788 
789  Value *CreateAnd(Value *LHS, Value *RHS, const Twine &Name = "") {
790  if (Constant *RC = dyn_cast<Constant>(RHS)) {
791  if (isa<ConstantInt>(RC) && cast<ConstantInt>(RC)->isAllOnesValue())
792  return LHS; // LHS & -1 -> LHS
793  if (Constant *LC = dyn_cast<Constant>(LHS))
794  return Insert(Folder.CreateAnd(LC, RC), Name);
795  }
796  return Insert(BinaryOperator::CreateAnd(LHS, RHS), Name);
797  }
798  Value *CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name = "") {
799  return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
800  }
801  Value *CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name = "") {
802  return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
803  }
804 
805  Value *CreateOr(Value *LHS, Value *RHS, const Twine &Name = "") {
806  if (Constant *RC = dyn_cast<Constant>(RHS)) {
807  if (RC->isNullValue())
808  return LHS; // LHS | 0 -> LHS
809  if (Constant *LC = dyn_cast<Constant>(LHS))
810  return Insert(Folder.CreateOr(LC, RC), Name);
811  }
812  return Insert(BinaryOperator::CreateOr(LHS, RHS), Name);
813  }
814  Value *CreateOr(Value *LHS, const APInt &RHS, const Twine &Name = "") {
815  return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
816  }
817  Value *CreateOr(Value *LHS, uint64_t RHS, const Twine &Name = "") {
818  return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
819  }
820 
821  Value *CreateXor(Value *LHS, Value *RHS, const Twine &Name = "") {
822  if (Constant *LC = dyn_cast<Constant>(LHS))
823  if (Constant *RC = dyn_cast<Constant>(RHS))
824  return Insert(Folder.CreateXor(LC, RC), Name);
825  return Insert(BinaryOperator::CreateXor(LHS, RHS), Name);
826  }
827  Value *CreateXor(Value *LHS, const APInt &RHS, const Twine &Name = "") {
828  return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
829  }
830  Value *CreateXor(Value *LHS, uint64_t RHS, const Twine &Name = "") {
831  return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
832  }
833 
835  Value *LHS, Value *RHS, const Twine &Name = "") {
836  if (Constant *LC = dyn_cast<Constant>(LHS))
837  if (Constant *RC = dyn_cast<Constant>(RHS))
838  return Insert(Folder.CreateBinOp(Opc, LC, RC), Name);
839  return Insert(BinaryOperator::Create(Opc, LHS, RHS), Name);
840  }
841 
842  Value *CreateNeg(Value *V, const Twine &Name = "",
843  bool HasNUW = false, bool HasNSW = false) {
844  if (Constant *VC = dyn_cast<Constant>(V))
845  return Insert(Folder.CreateNeg(VC, HasNUW, HasNSW), Name);
847  if (HasNUW) BO->setHasNoUnsignedWrap();
848  if (HasNSW) BO->setHasNoSignedWrap();
849  return BO;
850  }
851  Value *CreateNSWNeg(Value *V, const Twine &Name = "") {
852  return CreateNeg(V, Name, false, true);
853  }
854  Value *CreateNUWNeg(Value *V, const Twine &Name = "") {
855  return CreateNeg(V, Name, true, false);
856  }
857  Value *CreateFNeg(Value *V, const Twine &Name = "", MDNode *FPMathTag = 0) {
858  if (Constant *VC = dyn_cast<Constant>(V))
859  return Insert(Folder.CreateFNeg(VC), Name);
860  return Insert(AddFPMathAttributes(BinaryOperator::CreateFNeg(V),
861  FPMathTag, FMF), Name);
862  }
863  Value *CreateNot(Value *V, const Twine &Name = "") {
864  if (Constant *VC = dyn_cast<Constant>(V))
865  return Insert(Folder.CreateNot(VC), Name);
866  return Insert(BinaryOperator::CreateNot(V), Name);
867  }
868 
869  //===--------------------------------------------------------------------===//
870  // Instruction creation methods: Memory Instructions
871  //===--------------------------------------------------------------------===//
872 
873  AllocaInst *CreateAlloca(Type *Ty, Value *ArraySize = 0,
874  const Twine &Name = "") {
875  return Insert(new AllocaInst(Ty, ArraySize), Name);
876  }
877  // \brief Provided to resolve 'CreateLoad(Ptr, "...")' correctly, instead of
878  // converting the string to 'bool' for the isVolatile parameter.
879  LoadInst *CreateLoad(Value *Ptr, const char *Name) {
880  return Insert(new LoadInst(Ptr), Name);
881  }
882  LoadInst *CreateLoad(Value *Ptr, const Twine &Name = "") {
883  return Insert(new LoadInst(Ptr), Name);
884  }
885  LoadInst *CreateLoad(Value *Ptr, bool isVolatile, const Twine &Name = "") {
886  return Insert(new LoadInst(Ptr, 0, isVolatile), Name);
887  }
888  StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) {
889  return Insert(new StoreInst(Val, Ptr, isVolatile));
890  }
891  // \brief Provided to resolve 'CreateAlignedLoad(Ptr, Align, "...")'
892  // correctly, instead of converting the string to 'bool' for the isVolatile
893  // parameter.
894  LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name) {
895  LoadInst *LI = CreateLoad(Ptr, Name);
896  LI->setAlignment(Align);
897  return LI;
898  }
900  const Twine &Name = "") {
901  LoadInst *LI = CreateLoad(Ptr, Name);
902  LI->setAlignment(Align);
903  return LI;
904  }
905  LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align, bool isVolatile,
906  const Twine &Name = "") {
907  LoadInst *LI = CreateLoad(Ptr, isVolatile, Name);
908  LI->setAlignment(Align);
909  return LI;
910  }
912  bool isVolatile = false) {
913  StoreInst *SI = CreateStore(Val, Ptr, isVolatile);
914  SI->setAlignment(Align);
915  return SI;
916  }
918  SynchronizationScope SynchScope = CrossThread) {
919  return Insert(new FenceInst(Context, Ordering, SynchScope));
920  }
922  AtomicOrdering Ordering,
923  SynchronizationScope SynchScope = CrossThread) {
924  return Insert(new AtomicCmpXchgInst(Ptr, Cmp, New, Ordering, SynchScope));
925  }
927  AtomicOrdering Ordering,
928  SynchronizationScope SynchScope = CrossThread) {
929  return Insert(new AtomicRMWInst(Op, Ptr, Val, Ordering, SynchScope));
930  }
932  const Twine &Name = "") {
933  if (Constant *PC = dyn_cast<Constant>(Ptr)) {
934  // Every index must be constant.
935  size_t i, e;
936  for (i = 0, e = IdxList.size(); i != e; ++i)
937  if (!isa<Constant>(IdxList[i]))
938  break;
939  if (i == e)
940  return Insert(Folder.CreateGetElementPtr(PC, IdxList), Name);
941  }
942  return Insert(GetElementPtrInst::Create(Ptr, IdxList), Name);
943  }
945  const Twine &Name = "") {
946  if (Constant *PC = dyn_cast<Constant>(Ptr)) {
947  // Every index must be constant.
948  size_t i, e;
949  for (i = 0, e = IdxList.size(); i != e; ++i)
950  if (!isa<Constant>(IdxList[i]))
951  break;
952  if (i == e)
953  return Insert(Folder.CreateInBoundsGetElementPtr(PC, IdxList), Name);
954  }
955  return Insert(GetElementPtrInst::CreateInBounds(Ptr, IdxList), Name);
956  }
957  Value *CreateGEP(Value *Ptr, Value *Idx, const Twine &Name = "") {
958  if (Constant *PC = dyn_cast<Constant>(Ptr))
959  if (Constant *IC = dyn_cast<Constant>(Idx))
960  return Insert(Folder.CreateGetElementPtr(PC, IC), Name);
961  return Insert(GetElementPtrInst::Create(Ptr, Idx), Name);
962  }
963  Value *CreateInBoundsGEP(Value *Ptr, Value *Idx, const Twine &Name = "") {
964  if (Constant *PC = dyn_cast<Constant>(Ptr))
965  if (Constant *IC = dyn_cast<Constant>(Idx))
966  return Insert(Folder.CreateInBoundsGetElementPtr(PC, IC), Name);
967  return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idx), Name);
968  }
969  Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name = "") {
971 
972  if (Constant *PC = dyn_cast<Constant>(Ptr))
973  return Insert(Folder.CreateGetElementPtr(PC, Idx), Name);
974 
975  return Insert(GetElementPtrInst::Create(Ptr, Idx), Name);
976  }
977  Value *CreateConstInBoundsGEP1_32(Value *Ptr, unsigned Idx0,
978  const Twine &Name = "") {
980 
981  if (Constant *PC = dyn_cast<Constant>(Ptr))
982  return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idx), Name);
983 
984  return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idx), Name);
985  }
986  Value *CreateConstGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1,
987  const Twine &Name = "") {
988  Value *Idxs[] = {
991  };
992 
993  if (Constant *PC = dyn_cast<Constant>(Ptr))
994  return Insert(Folder.CreateGetElementPtr(PC, Idxs), Name);
995 
996  return Insert(GetElementPtrInst::Create(Ptr, Idxs), Name);
997  }
998  Value *CreateConstInBoundsGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1,
999  const Twine &Name = "") {
1000  Value *Idxs[] = {
1003  };
1004 
1005  if (Constant *PC = dyn_cast<Constant>(Ptr))
1006  return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idxs), Name);
1007 
1008  return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idxs), Name);
1009  }
1010  Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name = "") {
1012 
1013  if (Constant *PC = dyn_cast<Constant>(Ptr))
1014  return Insert(Folder.CreateGetElementPtr(PC, Idx), Name);
1015 
1016  return Insert(GetElementPtrInst::Create(Ptr, Idx), Name);
1017  }
1019  const Twine &Name = "") {
1021 
1022  if (Constant *PC = dyn_cast<Constant>(Ptr))
1023  return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idx), Name);
1024 
1025  return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idx), Name);
1026  }
1027  Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1028  const Twine &Name = "") {
1029  Value *Idxs[] = {
1032  };
1033 
1034  if (Constant *PC = dyn_cast<Constant>(Ptr))
1035  return Insert(Folder.CreateGetElementPtr(PC, Idxs), Name);
1036 
1037  return Insert(GetElementPtrInst::Create(Ptr, Idxs), Name);
1038  }
1039  Value *CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1040  const Twine &Name = "") {
1041  Value *Idxs[] = {
1044  };
1045 
1046  if (Constant *PC = dyn_cast<Constant>(Ptr))
1047  return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idxs), Name);
1048 
1049  return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idxs), Name);
1050  }
1051  Value *CreateStructGEP(Value *Ptr, unsigned Idx, const Twine &Name = "") {
1052  return CreateConstInBoundsGEP2_32(Ptr, 0, Idx, Name);
1053  }
1054 
1055  /// \brief Same as CreateGlobalString, but return a pointer with "i8*" type
1056  /// instead of a pointer to array of i8.
1057  Value *CreateGlobalStringPtr(StringRef Str, const Twine &Name = "") {
1058  Value *gv = CreateGlobalString(Str, Name);
1060  Value *Args[] = { zero, zero };
1061  return CreateInBoundsGEP(gv, Args, Name);
1062  }
1063 
1064  //===--------------------------------------------------------------------===//
1065  // Instruction creation methods: Cast/Conversion Operators
1066  //===--------------------------------------------------------------------===//
1067 
1068  Value *CreateTrunc(Value *V, Type *DestTy, const Twine &Name = "") {
1069  return CreateCast(Instruction::Trunc, V, DestTy, Name);
1070  }
1071  Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "") {
1072  return CreateCast(Instruction::ZExt, V, DestTy, Name);
1073  }
1074  Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") {
1075  return CreateCast(Instruction::SExt, V, DestTy, Name);
1076  }
1077  /// \brief Create a ZExt or Trunc from the integer value V to DestTy. Return
1078  /// the value untouched if the type of V is already DestTy.
1080  const Twine &Name = "") {
1081  assert(V->getType()->isIntOrIntVectorTy() &&
1082  DestTy->isIntOrIntVectorTy() &&
1083  "Can only zero extend/truncate integers!");
1084  Type *VTy = V->getType();
1085  if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
1086  return CreateZExt(V, DestTy, Name);
1087  if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
1088  return CreateTrunc(V, DestTy, Name);
1089  return V;
1090  }
1091  /// \brief Create a SExt or Trunc from the integer value V to DestTy. Return
1092  /// the value untouched if the type of V is already DestTy.
1094  const Twine &Name = "") {
1095  assert(V->getType()->isIntOrIntVectorTy() &&
1096  DestTy->isIntOrIntVectorTy() &&
1097  "Can only sign extend/truncate integers!");
1098  Type *VTy = V->getType();
1099  if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
1100  return CreateSExt(V, DestTy, Name);
1101  if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
1102  return CreateTrunc(V, DestTy, Name);
1103  return V;
1104  }
1105  Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = ""){
1106  return CreateCast(Instruction::FPToUI, V, DestTy, Name);
1107  }
1108  Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = ""){
1109  return CreateCast(Instruction::FPToSI, V, DestTy, Name);
1110  }
1111  Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
1112  return CreateCast(Instruction::UIToFP, V, DestTy, Name);
1113  }
1114  Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
1115  return CreateCast(Instruction::SIToFP, V, DestTy, Name);
1116  }
1118  const Twine &Name = "") {
1119  return CreateCast(Instruction::FPTrunc, V, DestTy, Name);
1120  }
1121  Value *CreateFPExt(Value *V, Type *DestTy, const Twine &Name = "") {
1122  return CreateCast(Instruction::FPExt, V, DestTy, Name);
1123  }
1125  const Twine &Name = "") {
1126  return CreateCast(Instruction::PtrToInt, V, DestTy, Name);
1127  }
1129  const Twine &Name = "") {
1130  return CreateCast(Instruction::IntToPtr, V, DestTy, Name);
1131  }
1133  const Twine &Name = "") {
1134  return CreateCast(Instruction::BitCast, V, DestTy, Name);
1135  }
1137  const Twine &Name = "") {
1138  return CreateCast(Instruction::AddrSpaceCast, V, DestTy, Name);
1139  }
1141  const Twine &Name = "") {
1142  if (V->getType() == DestTy)
1143  return V;
1144  if (Constant *VC = dyn_cast<Constant>(V))
1145  return Insert(Folder.CreateZExtOrBitCast(VC, DestTy), Name);
1146  return Insert(CastInst::CreateZExtOrBitCast(V, DestTy), Name);
1147  }
1149  const Twine &Name = "") {
1150  if (V->getType() == DestTy)
1151  return V;
1152  if (Constant *VC = dyn_cast<Constant>(V))
1153  return Insert(Folder.CreateSExtOrBitCast(VC, DestTy), Name);
1154  return Insert(CastInst::CreateSExtOrBitCast(V, DestTy), Name);
1155  }
1157  const Twine &Name = "") {
1158  if (V->getType() == DestTy)
1159  return V;
1160  if (Constant *VC = dyn_cast<Constant>(V))
1161  return Insert(Folder.CreateTruncOrBitCast(VC, DestTy), Name);
1162  return Insert(CastInst::CreateTruncOrBitCast(V, DestTy), Name);
1163  }
1165  const Twine &Name = "") {
1166  if (V->getType() == DestTy)
1167  return V;
1168  if (Constant *VC = dyn_cast<Constant>(V))
1169  return Insert(Folder.CreateCast(Op, VC, DestTy), Name);
1170  return Insert(CastInst::Create(Op, V, DestTy), Name);
1171  }
1173  const Twine &Name = "") {
1174  if (V->getType() == DestTy)
1175  return V;
1176  if (Constant *VC = dyn_cast<Constant>(V))
1177  return Insert(Folder.CreatePointerCast(VC, DestTy), Name);
1178  return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
1179  }
1180  Value *CreateIntCast(Value *V, Type *DestTy, bool isSigned,
1181  const Twine &Name = "") {
1182  if (V->getType() == DestTy)
1183  return V;
1184  if (Constant *VC = dyn_cast<Constant>(V))
1185  return Insert(Folder.CreateIntCast(VC, DestTy, isSigned), Name);
1186  return Insert(CastInst::CreateIntegerCast(V, DestTy, isSigned), Name);
1187  }
1188 private:
1189  // \brief Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a
1190  // compile time error, instead of converting the string to bool for the
1191  // isSigned parameter.
1192  Value *CreateIntCast(Value *, Type *, const char *) LLVM_DELETED_FUNCTION;
1193 public:
1194  Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "") {
1195  if (V->getType() == DestTy)
1196  return V;
1197  if (Constant *VC = dyn_cast<Constant>(V))
1198  return Insert(Folder.CreateFPCast(VC, DestTy), Name);
1199  return Insert(CastInst::CreateFPCast(V, DestTy), Name);
1200  }
1201 
1202  //===--------------------------------------------------------------------===//
1203  // Instruction creation methods: Compare Instructions
1204  //===--------------------------------------------------------------------===//
1205 
1206  Value *CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
1207  return CreateICmp(ICmpInst::ICMP_EQ, LHS, RHS, Name);
1208  }
1209  Value *CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name = "") {
1210  return CreateICmp(ICmpInst::ICMP_NE, LHS, RHS, Name);
1211  }
1212  Value *CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name = "") {
1213  return CreateICmp(ICmpInst::ICMP_UGT, LHS, RHS, Name);
1214  }
1215  Value *CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name = "") {
1216  return CreateICmp(ICmpInst::ICMP_UGE, LHS, RHS, Name);
1217  }
1218  Value *CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name = "") {
1219  return CreateICmp(ICmpInst::ICMP_ULT, LHS, RHS, Name);
1220  }
1221  Value *CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name = "") {
1222  return CreateICmp(ICmpInst::ICMP_ULE, LHS, RHS, Name);
1223  }
1224  Value *CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name = "") {
1225  return CreateICmp(ICmpInst::ICMP_SGT, LHS, RHS, Name);
1226  }
1227  Value *CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name = "") {
1228  return CreateICmp(ICmpInst::ICMP_SGE, LHS, RHS, Name);
1229  }
1230  Value *CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name = "") {
1231  return CreateICmp(ICmpInst::ICMP_SLT, LHS, RHS, Name);
1232  }
1233  Value *CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name = "") {
1234  return CreateICmp(ICmpInst::ICMP_SLE, LHS, RHS, Name);
1235  }
1236 
1237  Value *CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
1238  return CreateFCmp(FCmpInst::FCMP_OEQ, LHS, RHS, Name);
1239  }
1240  Value *CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name = "") {
1241  return CreateFCmp(FCmpInst::FCMP_OGT, LHS, RHS, Name);
1242  }
1243  Value *CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name = "") {
1244  return CreateFCmp(FCmpInst::FCMP_OGE, LHS, RHS, Name);
1245  }
1246  Value *CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name = "") {
1247  return CreateFCmp(FCmpInst::FCMP_OLT, LHS, RHS, Name);
1248  }
1249  Value *CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name = "") {
1250  return CreateFCmp(FCmpInst::FCMP_OLE, LHS, RHS, Name);
1251  }
1252  Value *CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name = "") {
1253  return CreateFCmp(FCmpInst::FCMP_ONE, LHS, RHS, Name);
1254  }
1255  Value *CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name = "") {
1256  return CreateFCmp(FCmpInst::FCMP_ORD, LHS, RHS, Name);
1257  }
1258  Value *CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name = "") {
1259  return CreateFCmp(FCmpInst::FCMP_UNO, LHS, RHS, Name);
1260  }
1261  Value *CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
1262  return CreateFCmp(FCmpInst::FCMP_UEQ, LHS, RHS, Name);
1263  }
1264  Value *CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name = "") {
1265  return CreateFCmp(FCmpInst::FCMP_UGT, LHS, RHS, Name);
1266  }
1267  Value *CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name = "") {
1268  return CreateFCmp(FCmpInst::FCMP_UGE, LHS, RHS, Name);
1269  }
1270  Value *CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name = "") {
1271  return CreateFCmp(FCmpInst::FCMP_ULT, LHS, RHS, Name);
1272  }
1273  Value *CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name = "") {
1274  return CreateFCmp(FCmpInst::FCMP_ULE, LHS, RHS, Name);
1275  }
1276  Value *CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name = "") {
1277  return CreateFCmp(FCmpInst::FCMP_UNE, LHS, RHS, Name);
1278  }
1279 
1281  const Twine &Name = "") {
1282  if (Constant *LC = dyn_cast<Constant>(LHS))
1283  if (Constant *RC = dyn_cast<Constant>(RHS))
1284  return Insert(Folder.CreateICmp(P, LC, RC), Name);
1285  return Insert(new ICmpInst(P, LHS, RHS), Name);
1286  }
1288  const Twine &Name = "") {
1289  if (Constant *LC = dyn_cast<Constant>(LHS))
1290  if (Constant *RC = dyn_cast<Constant>(RHS))
1291  return Insert(Folder.CreateFCmp(P, LC, RC), Name);
1292  return Insert(new FCmpInst(P, LHS, RHS), Name);
1293  }
1294 
1295  //===--------------------------------------------------------------------===//
1296  // Instruction creation methods: Other Instructions
1297  //===--------------------------------------------------------------------===//
1298 
1299  PHINode *CreatePHI(Type *Ty, unsigned NumReservedValues,
1300  const Twine &Name = "") {
1301  return Insert(PHINode::Create(Ty, NumReservedValues), Name);
1302  }
1303 
1304  CallInst *CreateCall(Value *Callee, const Twine &Name = "") {
1305  return Insert(CallInst::Create(Callee), Name);
1306  }
1307  CallInst *CreateCall(Value *Callee, Value *Arg, const Twine &Name = "") {
1308  return Insert(CallInst::Create(Callee, Arg), Name);
1309  }
1310  CallInst *CreateCall2(Value *Callee, Value *Arg1, Value *Arg2,
1311  const Twine &Name = "") {
1312  Value *Args[] = { Arg1, Arg2 };
1313  return Insert(CallInst::Create(Callee, Args), Name);
1314  }
1315  CallInst *CreateCall3(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3,
1316  const Twine &Name = "") {
1317  Value *Args[] = { Arg1, Arg2, Arg3 };
1318  return Insert(CallInst::Create(Callee, Args), Name);
1319  }
1320  CallInst *CreateCall4(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3,
1321  Value *Arg4, const Twine &Name = "") {
1322  Value *Args[] = { Arg1, Arg2, Arg3, Arg4 };
1323  return Insert(CallInst::Create(Callee, Args), Name);
1324  }
1325  CallInst *CreateCall5(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3,
1326  Value *Arg4, Value *Arg5, const Twine &Name = "") {
1327  Value *Args[] = { Arg1, Arg2, Arg3, Arg4, Arg5 };
1328  return Insert(CallInst::Create(Callee, Args), Name);
1329  }
1330 
1332  const Twine &Name = "") {
1333  return Insert(CallInst::Create(Callee, Args), Name);
1334  }
1335 
1336  Value *CreateSelect(Value *C, Value *True, Value *False,
1337  const Twine &Name = "") {
1338  if (Constant *CC = dyn_cast<Constant>(C))
1339  if (Constant *TC = dyn_cast<Constant>(True))
1340  if (Constant *FC = dyn_cast<Constant>(False))
1341  return Insert(Folder.CreateSelect(CC, TC, FC), Name);
1342  return Insert(SelectInst::Create(C, True, False), Name);
1343  }
1344 
1345  VAArgInst *CreateVAArg(Value *List, Type *Ty, const Twine &Name = "") {
1346  return Insert(new VAArgInst(List, Ty), Name);
1347  }
1348 
1350  const Twine &Name = "") {
1351  if (Constant *VC = dyn_cast<Constant>(Vec))
1352  if (Constant *IC = dyn_cast<Constant>(Idx))
1353  return Insert(Folder.CreateExtractElement(VC, IC), Name);
1354  return Insert(ExtractElementInst::Create(Vec, Idx), Name);
1355  }
1356 
1358  const Twine &Name = "") {
1359  if (Constant *VC = dyn_cast<Constant>(Vec))
1360  if (Constant *NC = dyn_cast<Constant>(NewElt))
1361  if (Constant *IC = dyn_cast<Constant>(Idx))
1362  return Insert(Folder.CreateInsertElement(VC, NC, IC), Name);
1363  return Insert(InsertElementInst::Create(Vec, NewElt, Idx), Name);
1364  }
1365 
1367  const Twine &Name = "") {
1368  if (Constant *V1C = dyn_cast<Constant>(V1))
1369  if (Constant *V2C = dyn_cast<Constant>(V2))
1370  if (Constant *MC = dyn_cast<Constant>(Mask))
1371  return Insert(Folder.CreateShuffleVector(V1C, V2C, MC), Name);
1372  return Insert(new ShuffleVectorInst(V1, V2, Mask), Name);
1373  }
1374 
1376  ArrayRef<unsigned> Idxs,
1377  const Twine &Name = "") {
1378  if (Constant *AggC = dyn_cast<Constant>(Agg))
1379  return Insert(Folder.CreateExtractValue(AggC, Idxs), Name);
1380  return Insert(ExtractValueInst::Create(Agg, Idxs), Name);
1381  }
1382 
1384  ArrayRef<unsigned> Idxs,
1385  const Twine &Name = "") {
1386  if (Constant *AggC = dyn_cast<Constant>(Agg))
1387  if (Constant *ValC = dyn_cast<Constant>(Val))
1388  return Insert(Folder.CreateInsertValue(AggC, ValC, Idxs), Name);
1389  return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name);
1390  }
1391 
1392  LandingPadInst *CreateLandingPad(Type *Ty, Value *PersFn, unsigned NumClauses,
1393  const Twine &Name = "") {
1394  return Insert(LandingPadInst::Create(Ty, PersFn, NumClauses), Name);
1395  }
1396 
1397  //===--------------------------------------------------------------------===//
1398  // Utility creation methods
1399  //===--------------------------------------------------------------------===//
1400 
1401  /// \brief Return an i1 value testing if \p Arg is null.
1402  Value *CreateIsNull(Value *Arg, const Twine &Name = "") {
1403  return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()),
1404  Name);
1405  }
1406 
1407  /// \brief Return an i1 value testing if \p Arg is not null.
1408  Value *CreateIsNotNull(Value *Arg, const Twine &Name = "") {
1409  return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()),
1410  Name);
1411  }
1412 
1413  /// \brief Return the i64 difference between two pointer values, dividing out
1414  /// the size of the pointed-to objects.
1415  ///
1416  /// This is intended to implement C-style pointer subtraction. As such, the
1417  /// pointers must be appropriately aligned for their element types and
1418  /// pointing into the same object.
1419  Value *CreatePtrDiff(Value *LHS, Value *RHS, const Twine &Name = "") {
1420  assert(LHS->getType() == RHS->getType() &&
1421  "Pointer subtraction operand types must match!");
1422  PointerType *ArgType = cast<PointerType>(LHS->getType());
1423  Value *LHS_int = CreatePtrToInt(LHS, Type::getInt64Ty(Context));
1424  Value *RHS_int = CreatePtrToInt(RHS, Type::getInt64Ty(Context));
1425  Value *Difference = CreateSub(LHS_int, RHS_int);
1426  return CreateExactSDiv(Difference,
1427  ConstantExpr::getSizeOf(ArgType->getElementType()),
1428  Name);
1429  }
1430 
1431  /// \brief Return a vector value that contains \arg V broadcasted to \p
1432  /// NumElts elements.
1433  Value *CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name = "") {
1434  assert(NumElts > 0 && "Cannot splat to an empty vector!");
1435 
1436  // First insert it into an undef vector so we can shuffle it.
1437  Type *I32Ty = getInt32Ty();
1438  Value *Undef = UndefValue::get(VectorType::get(V->getType(), NumElts));
1439  V = CreateInsertElement(Undef, V, ConstantInt::get(I32Ty, 0),
1440  Name + ".splatinsert");
1441 
1442  // Shuffle the value across the desired number of elements.
1443  Value *Zeros = ConstantAggregateZero::get(VectorType::get(I32Ty, NumElts));
1444  return CreateShuffleVector(V, Undef, Zeros, Name + ".splat");
1445  }
1446 };
1447 
1448 // Create wrappers for C Binding types (see CBindingWrapping.h).
1450 
1451 }
1452 
1453 #endif
IntegerType * getInt16Ty()
Fetch the type representing a 16-bit integer.
Definition: IRBuilder.h:305
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:753
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:50
Value * CreateGEP(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
Definition: IRBuilder.h:931
Value * CreateNUWNeg(Value *V, const Twine &Name="")
Definition: IRBuilder.h:854
LoadInst * CreateLoad(Value *Ptr, const Twine &Name="")
Definition: IRBuilder.h:882
static ConstantInt * getFalse(LLVMContext &Context)
Definition: Constants.cpp:445
SwitchInst * CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases=10, MDNode *BranchWeights=0)
Create a switch instruction with the specified value, default dest, and with a hint for the number of...
Definition: IRBuilder.h:541
void setHasNoSignedWrap(bool b=true)
Value * CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1261
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1164
static Type * getDoubleTy(LLVMContext &C)
Definition: Type.cpp:231
static IntegerType * getInt1Ty(LLVMContext &C)
Definition: Type.cpp:238
Value * CreateFAdd(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=0)
Definition: IRBuilder.h:629
Value * CreateSIToFP(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1114
BasicBlock::iterator GetInsertPoint() const
Definition: IRBuilder.h:78
LoadInst * CreateLoad(Value *Ptr, const char *Name)
Definition: IRBuilder.h:879
void SetCurrentDebugLocation(const DebugLoc &L)
Set location information used by debugging information.
Definition: IRBuilder.h:118
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1280
Value * CreateSExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a SExt or Trunc from the integer value V to DestTy. Return the value untouched if the type of ...
Definition: IRBuilder.h:1093
Value * CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1233
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Definition: IRBuilder.h:1180
unsigned getScalarSizeInBits()
Definition: Type.cpp:135
VAArgInst * CreateVAArg(Value *List, Type *Ty, const Twine &Name="")
Definition: IRBuilder.h:1345
Value * CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:645
Value * CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1230
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=0)
FastMathFlags FMF
Definition: IRBuilder.h:58
ReturnInst * CreateAggregateRet(Value *const *retVals, unsigned N)
Create a sequence of N insertvalue instructions, with one Value from the retVals array each...
Definition: IRBuilder.h:518
static ConstantAggregateZero * get(Type *Ty)
Definition: Constants.cpp:1231
Value * CreateSRem(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:719
void SetInsertPoint(BasicBlock *TheBB, BasicBlock::iterator IP)
This specifies that created instructions should be inserted at the specified point.
Definition: IRBuilder.h:99
Value * CreatePointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1172
unsigned less or equal
Definition: InstrTypes.h:677
unsigned less than
Definition: InstrTypes.h:676
Value * CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:702
0 1 0 0 True if ordered and less than
Definition: InstrTypes.h:657
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1218
1 1 1 0 True if unordered or not equal
Definition: InstrTypes.h:667
Value * CreateFPCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1194
Value * CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:670
MDNode - a tuple of other values.
Definition: Metadata.h:69
Value * CreateConstGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="")
Definition: IRBuilder.h:986
F(f)
static ExtractValueInst * Create(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=0)
Value * CreateGEP(Value *Ptr, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:957
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:242
IRBuilder(Use &U, MDNode *FPMathTag=0)
Definition: IRBuilder.h:449
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1206
static IndirectBrInst * Create(Value *Address, unsigned NumDests, Instruction *InsertBefore=0)
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, MDNode *FPMathTag=0)
Definition: IRBuilder.h:461
static IntegerType * getInt16Ty(LLVMContext &C)
Definition: Type.cpp:240
Value * CreateFSub(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=0)
Definition: IRBuilder.h:651
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
Definition: IRBuilder.h:1366
Value * CreateOr(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition: IRBuilder.h:814
void setDebugLoc(const DebugLoc &Loc)
setDebugLoc - Set the debug location information for this instruction.
Definition: Instruction.h:175
CallInst * CreateCall5(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3, Value *Arg4, Value *Arg5, const Twine &Name="")
Definition: IRBuilder.h:1325
LoadInst * CreateAlignedLoad(Value *Ptr, unsigned Align, bool isVolatile, const Twine &Name="")
Definition: IRBuilder.h:905
CallInst * CreateLifetimeEnd(Value *Ptr, ConstantInt *Size=0)
Create a lifetime.end intrinsic.
Definition: IRBuilder.cpp:140
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:637
LoopInfoBase< BlockT, LoopT > * LI
Definition: LoopInfoImpl.h:411
InstTy * Insert(InstTy *I, const Twine &Name="") const
Insert and return the specified instruction.
Definition: IRBuilder.h:475
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:1357
static Constant * getNullValue(Type *Ty)
Definition: Constants.cpp:111
Value * CreateConstInBoundsGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name="")
Definition: IRBuilder.h:977
Value * CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:623
LLVMContext & Context
Definition: IRBuilder.h:55
Value * CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1221
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Definition: IRBuilder.h:310
1 0 0 1 True if unordered or equal
Definition: InstrTypes.h:662
Value * CreateFMul(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=0)
Definition: IRBuilder.h:673
CallInst * CreateMemMove(Value *Dst, Value *Src, uint64_t Size, unsigned Align, bool isVolatile=false, MDNode *TBAATag=0)
Create and insert a memmove between the specified pointers.
Definition: IRBuilder.h:381
CallInst * CreateCall(Value *Callee, Value *Arg, const Twine &Name="")
Definition: IRBuilder.h:1307
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition: IRBuilder.h:1375
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
Definition: IRBuilder.h:1299
bool isUnknown() const
isUnknown - Return true if this is an unknown location.
Definition: DebugLoc.h:70
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:821
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition: InstrTypes.h:661
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
Definition: IRBuilder.h:315
static Type * getFloatTy(LLVMContext &C)
Definition: Type.cpp:230
Value * CreateAShr(Value *LHS, uint64_t RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:784
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1128
Definition: Use.h:60
void setHasNoUnsignedWrap(bool b=true)
Value * CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1237
static CastInst * CreateTruncOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=0)
Create a Trunc or BitCast cast instruction.
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=0)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
Definition: IRBuilder.h:532
llvm::BasicBlock * getBlock() const
Definition: IRBuilder.h:152
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:421
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=0)
0 1 0 1 True if ordered and less than or equal
Definition: InstrTypes.h:658
Value * CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition: IRBuilder.h:1010
SynchronizationScope
Definition: Instructions.h:47
IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag=0)
Definition: IRBuilder.h:438
void setName(const Twine &Name)
Definition: Value.cpp:175
Value * CreateFRem(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=0)
Definition: IRBuilder.h:725
Value * CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:667
Value * CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1224
ConstantInt * getInt16(uint16_t C)
Get a constant 16-bit value.
Definition: IRBuilder.h:271
AllocaInst * CreateAlloca(Type *Ty, Value *ArraySize=0, const Twine &Name="")
Definition: IRBuilder.h:873
Type * getVoidTy()
Fetch the type representing void.
Definition: IRBuilder.h:330
BasicBlock * BB
Definition: IRBuilder.h:53
AtomicOrdering
Definition: Instructions.h:36
IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag=0)
Definition: IRBuilder.h:433
static Constant * getSizeOf(Type *Ty)
Definition: Constants.cpp:1756
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1287
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:789
InvokeInst * CreateInvoke3(Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, Value *Arg1, Value *Arg2, Value *Arg3, const Twine &Name="")
Definition: IRBuilder.h:566
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:805
void SetFastMathFlags(FastMathFlags NewFMF)
Set the fast-math flags to be used with generated fp-math operators.
Definition: IRBuilder.h:189
InsertPoint saveIP() const
Returns the current insert point.
Definition: IRBuilder.h:157
CallInst * CreateCall(Value *Callee, ArrayRef< Value * > Args, const Twine &Name="")
Definition: IRBuilder.h:1331
FenceInst * CreateFence(AtomicOrdering Ordering, SynchronizationScope SynchScope=CrossThread)
Definition: IRBuilder.h:917
UnreachableInst * CreateUnreachable()
Definition: IRBuilder.h:586
void ClearInsertionPoint()
Clear the insertion point: created instructions will not be inserted into a block.
Definition: IRBuilder.h:72
Represents a floating point comparison operator.
static LandingPadInst * Create(Type *RetTy, Value *PersonalityFn, unsigned NumReservedClauses, const Twine &NameStr="", Instruction *InsertBefore=0)
Value * CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1246
CallInst * CreateCall4(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3, Value *Arg4, const Twine &Name="")
Definition: IRBuilder.h:1320
MDNode * getDefaultFPMathTag() const
Get the floating point math metadata being used.
Definition: IRBuilder.h:177
Value * CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name="")
Definition: IRBuilder.h:969
Value * CreateAShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:771
Value * CreateShl(Value *LHS, const APInt &RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:742
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition: IRBuilder.h:888
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:109
Value * CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1255
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
Definition: IRBuilder.h:83
Value * CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1267
Value * CreateNSWNeg(Value *V, const Twine &Name="")
Definition: IRBuilder.h:851
IRBuilderBase(LLVMContext &context, MDNode *FPMathTag=0)
Definition: IRBuilder.h:61
void SetInsertPoint(Use &U)
Find the nearest point that dominates this use, and specify that created instructions should be inser...
Definition: IRBuilder.h:106
LoadInst * CreateLoad(Value *Ptr, bool isVolatile, const Twine &Name="")
Definition: IRBuilder.h:885
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=0)
Construct any of the CastInst subclasses.
Value * CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:762
InsertPoint saveAndClearIP()
Returns the current insert point, clearing it in the process.
Definition: IRBuilder.h:162
Type * getDoubleTy()
Fetch the type representing a 64-bit floating point value.
Definition: IRBuilder.h:325
Value * CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:648
#define P(N)
bool isIntOrIntVectorTy() const
Definition: Type.h:204
void restoreIP(InsertPoint IP)
Sets the current insert point to a previously-saved location.
Definition: IRBuilder.h:169
Value * CreateGlobalStringPtr(StringRef Str, const Twine &Name="")
Same as CreateGlobalString, but return a pointer with "i8*" type instead of a pointer to array of i8...
Definition: IRBuilder.h:1057
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:834
InvokeInst * CreateInvoke(Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, Value *Arg1, const Twine &Name="")
Definition: IRBuilder.h:560
Value * CreateConstInBoundsGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition: IRBuilder.h:1018
Value * CreateShl(Value *LHS, uint64_t RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:747
Value * CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1227
Value * CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition: IRBuilder.h:1027
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=0)
InsertPoint(BasicBlock *InsertBlock, BasicBlock::iterator InsertPoint)
Creates a new insertion point at the given location.
Definition: IRBuilder.h:146
LLVM Basic Block Representation.
Definition: BasicBlock.h:72
ConstantInt * getTrue()
Get the constant value for i1 true.
Definition: IRBuilder.h:256
Value * CreateNot(Value *V, const Twine &Name="")
Definition: IRBuilder.h:863
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:615
ConstantInt * getInt1(bool V)
Get a constant value representing either true or false.
Definition: IRBuilder.h:251
Type * getCurrentFunctionReturnType() const
Get the return type of the current function that we're emitting into.
Definition: IRBuilder.cpp:37
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1124
LLVM Constant Representation.
Definition: Constant.h:41
Value * CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:780
Value * CreateFPToSI(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1108
IRBuilder(LLVMContext &C, MDNode *FPMathTag=0)
Definition: IRBuilder.h:429
ReturnInst * CreateRet(Value *V)
Create a 'ret <val>' instruction.
Definition: IRBuilder.h:507
static InvokeInst * Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=0)
static ExtractElementInst * Create(Value *Vec, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=0)
LoadInst * CreateAlignedLoad(Value *Ptr, unsigned Align, const Twine &Name="")
Definition: IRBuilder.h:899
static CastInst * CreateFPCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=0)
Create an FPExt, BitCast, or FPTrunc for fp -> fp casts.
AtomicCmpXchgInst * CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New, AtomicOrdering Ordering, SynchronizationScope SynchScope=CrossThread)
Definition: IRBuilder.h:921
const DebugLoc & getDebugLoc() const
getDebugLoc - Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:178
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=0)
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:227
const InstListType & getInstList() const
Return the underlying instruction list container.
Definition: BasicBlock.h:214
Represent an integer comparison operator.
Definition: Instructions.h:911
iterator insert(iterator where, NodeTy *New)
Definition: ilist.h:412
NUW NUW NUW NUW Exact static Exact BinaryOperator * CreateNeg(Value *Op, const Twine &Name="", Instruction *InsertBefore=0)
User * getUser() const
Definition: Use.cpp:137
0 1 1 1 True if ordered (no nans)
Definition: InstrTypes.h:660
DebugLoc getCurrentDebugLocation() const
Get location information used by debugging information.
Definition: IRBuilder.h:123
void clearFastMathFlags()
Clear the fast-math flags.
Definition: IRBuilder.h:183
Value * CreateUIToFP(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1111
Integer representation type.
Definition: DerivedTypes.h:37
Value * CreateOr(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition: IRBuilder.h:817
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
Definition: IRBuilder.h:281
static CastInst * CreatePointerCast(Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
Create a BitCast or a PtrToInt cast instruction.
Value * CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition: IRBuilder.h:801
Value * CreateStructGEP(Value *Ptr, unsigned Idx, const Twine &Name="")
Definition: IRBuilder.h:1051
Value * CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1249
void setAlignment(unsigned Align)
Value * CreatePtrDiff(Value *LHS, Value *RHS, const Twine &Name="")
Return the i64 difference between two pointer values, dividing out the size of the pointed-to objects...
Definition: IRBuilder.h:1419
static CastInst * CreateZExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=0)
Create a ZExt or BitCast cast instruction.
Value * CreateInBoundsGEP(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
Definition: IRBuilder.h:944
static UndefValue * get(Type *T)
Definition: Constants.cpp:1334
void SetInsertPoint(Instruction *I)
This specifies that created instructions should be inserted before the specified instruction.
Definition: IRBuilder.h:90
LLVMContext & getContext() const
Definition: IRBuilder.h:79
IndirectBrInst * CreateIndirectBr(Value *Addr, unsigned NumDests=10)
Create an indirect branch instruction with the specified address operand, with an optional hint for t...
Definition: IRBuilder.h:550
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:284
PointerType * getInt8PtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer to an 8-bit integer value.
Definition: IRBuilder.h:335
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, unsigned Align, bool isVolatile=false)
Definition: IRBuilder.h:911
LoadInst * CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name)
Definition: IRBuilder.h:894
1 1 0 1 True if unordered, less than, or equal
Definition: InstrTypes.h:666
signed greater than
Definition: InstrTypes.h:678
Value * CreateFPToUI(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1105
Value * CreateFNeg(Value *V, const Twine &Name="", MDNode *FPMathTag=0)
Definition: IRBuilder.h:857
IntegerType * getIntPtrTy(const DataLayout *DL, unsigned AddrSpace=0)
Fetch the type representing a pointer to an integer value.
Definition: IRBuilder.h:340
Value * CreateXor(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition: IRBuilder.h:827
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=0)
static CastInst * CreateSExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=0)
Create a SExt or BitCast cast instruction.
This provides the default implementation of the IRBuilder 'InsertHelper' method that is called whenev...
Definition: IRBuilder.h:39
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Definition: DataLayout.cpp:610
0 0 1 0 True if ordered and greater than
Definition: InstrTypes.h:655
bool isNamePreserving() const
Return true if this builder is configured to actually add the requested names to IR created through i...
Definition: IRBuilder.h:471
Value * CreateInBoundsGEP(Value *Ptr, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:963
Value * CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:626
Class for constant integers.
Definition: Constants.h:51
Value * CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1243
InsertPoint - A saved insertion point.
Definition: IRBuilder.h:137
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:1349
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1071
iterator end()
Definition: BasicBlock.h:195
Value * CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1240
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1132
1 1 0 0 True if unordered or less than
Definition: InstrTypes.h:665
Type * getType() const
Definition: Value.h:111
signed less than
Definition: InstrTypes.h:680
Value * CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1215
Value * CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1270
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition: IRBuilder.h:276
BasicBlock * GetInsertBlock() const
Definition: IRBuilder.h:77
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:659
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
Definition: Constants.cpp:492
static GetElementPtrInst * Create(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=0)
Definition: Instructions.h:726
#define NC
Definition: regutils.h:39
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:438
#define LLVM_DELETED_FUNCTION
Definition: Compiler.h:137
Value * CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1140
signed less or equal
Definition: InstrTypes.h:681
Value * CreateURem(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:713
Class for arbitrary precision integers.
Definition: APInt.h:75
Value * CreateSDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:693
Value * CreateUDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:681
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="")
Definition: IRBuilder.h:1336
Value * CreateFDiv(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=0)
Definition: IRBuilder.h:705
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Definition: IRBuilder.h:300
Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
Definition: IRBuilder.h:1433
static CastInst * CreateIntegerCast(Value *S, Type *Ty, bool isSigned, const Twine &Name="", Instruction *InsertBefore=0)
Create a ZExt, BitCast, or Trunc for int -> int casts.
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(DefaultAlign), cl::values(clEnumValN(DefaultAlign,"arm-default-align","Generate unaligned accesses only on hardware/OS ""combinations that are known to support them"), clEnumValN(StrictAlign,"arm-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"arm-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
Value * CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1156
void InsertHelper(Instruction *I, const Twine &Name, BasicBlock *BB, BasicBlock::iterator InsertPt) const
Definition: IRBuilder.h:41
void clear()
Set all the flags to false.
Definition: Operator.h:192
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition: IRBuilder.h:1383
ConstantInt * getFalse()
Get the constant value for i1 false.
Definition: IRBuilder.h:261
MDNode * DefaultFPMathTag
Definition: IRBuilder.h:57
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
Definition: IRBuilder.h:295
Value * CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1258
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:734
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=0)
LandingPadInst * CreateLandingPad(Type *Ty, Value *PersFn, unsigned NumClauses, const Twine &Name="")
Definition: IRBuilder.h:1392
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return an i1 value testing if Arg is not null.
Definition: IRBuilder.h:1408
Value * CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1252
Value * CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition: IRBuilder.h:1039
Value * CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1276
IRBuilder(LLVMContext &C, const T &F, const Inserter &I=Inserter(), MDNode *FPMathTag=0)
Definition: IRBuilder.h:424
Constant * Insert(Constant *C, const Twine &="") const
No-op overload to handle constants.
Definition: IRBuilder.h:482
Value * CreateConstInBoundsGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="")
Definition: IRBuilder.h:998
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy. Return the value untouched if the type of ...
Definition: IRBuilder.h:1079
Value * CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition: IRBuilder.h:798
Value * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1136
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:241
AtomicRMWInst * CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val, AtomicOrdering Ordering, SynchronizationScope SynchScope=CrossThread)
Definition: IRBuilder.h:926
unsigned greater or equal
Definition: InstrTypes.h:675
Value * CreateSExt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1074
Value * CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1273
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.cpp:120
0 1 1 0 True if ordered and operands are unequal
Definition: InstrTypes.h:659
const T & getFolder()
Get the constant folder being used.
Definition: IRBuilder.h:467
CallInst * CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, unsigned Align, bool isVolatile=false, MDNode *TBAATag=0)
Create and insert a memset to the specified pointer and the specified value.
Definition: IRBuilder.h:353
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), Instruction *InsertBefore=0)
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1209
Value * CreateXor(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition: IRBuilder.h:830
Type * getFloatTy()
Fetch the type representing a 32-bit floating point value.
Definition: IRBuilder.h:320
Value * CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:690
1 0 1 0 True if unordered or greater than
Definition: InstrTypes.h:663
static ReturnInst * Create(LLVMContext &C, Value *retVal=0, Instruction *InsertBefore=0)
IRBuilder(Instruction *IP, MDNode *FPMathTag=0)
Definition: IRBuilder.h:443
InvokeInst * CreateInvoke(Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args, const Twine &Name="")
Create an invoke instruction.
Definition: IRBuilder.h:575
CallInst * CreateCall2(Value *Callee, Value *Arg1, Value *Arg2, const Twine &Name="")
Definition: IRBuilder.h:1310
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:842
Value * CreateIsNull(Value *Arg, const Twine &Name="")
Return an i1 value testing if Arg is null.
Definition: IRBuilder.h:1402
llvm::BasicBlock::iterator getPoint() const
Definition: IRBuilder.h:153
0 0 0 1 True if ordered and equal
Definition: InstrTypes.h:654
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1068
LLVM Value Representation.
Definition: Value.h:66
void setAlignment(unsigned Align)
1 0 1 1 True if unordered, greater than, or equal
Definition: InstrTypes.h:664
CallInst * CreateCall(Value *Callee, const Twine &Name="")
Definition: IRBuilder.h:1304
static VectorType * get(Type *ElementType, unsigned NumElements)
Definition: Type.cpp:706
CallInst * CreateLifetimeStart(Value *Ptr, ConstantInt *Size=0)
Create a lifetime.start intrinsic.
Definition: IRBuilder.cpp:125
ReturnInst * CreateRetVoid()
Create a 'ret void' instruction.
Definition: IRBuilder.h:502
FastMathFlags getFastMathFlags() const
Get the flags to be applied to created floating point ops.
Definition: IRBuilder.h:180
bool isSet() const
Returns true if this insert point is set.
Definition: IRBuilder.h:150
BranchInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
Definition: IRBuilder.h:526
InsertPoint()
Creates a new insertion point which doesn't point to anything.
Definition: IRBuilder.h:143
ConstantInt * getInt8(uint8_t C)
Get a constant 8-bit value.
Definition: IRBuilder.h:266
struct LLVMOpaqueBuilder * LLVMBuilderRef
Definition: Core.h:108
Convenience struct for specifying and reasoning about fast-math flags.
Definition: Operator.h:170
unsigned greater than
Definition: InstrTypes.h:674
Value * CreateGlobalString(StringRef Str, const Twine &Name="")
Make a new global variable with initializer type i8*.
Definition: IRBuilder.cpp:26
Value * CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1264
static BinaryOperator * CreateFNeg(Value *Op, const Twine &Name="", Instruction *InsertBefore=0)
static GetElementPtrInst * CreateInBounds(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=0)
Definition: Instructions.h:743
InvokeInst * CreateInvoke(Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, const Twine &Name="")
Definition: IRBuilder.h:554
Value * CreateFPExt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1121
ConstantInt * getInt(const APInt &AI)
Get a constant integer value.
Definition: IRBuilder.h:286
static BinaryOperator * CreateNot(Value *Op, const Twine &Name="", Instruction *InsertBefore=0)
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T &F, MDNode *FPMathTag=0)
Definition: IRBuilder.h:455
Value * CreateFPTrunc(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1117
0 0 1 1 True if ordered and greater than or equal
Definition: InstrTypes.h:656
Value * CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1212
Value * CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:766
ResumeInst * CreateResume(Value *Exn)
Definition: IRBuilder.h:582
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:239
static ResumeInst * Create(Value *Exn, Instruction *InsertBefore=0)
BasicBlock::iterator InsertPt
Definition: IRBuilder.h:54
static SwitchInst * Create(Value *Value, BasicBlock *Default, unsigned NumCases, Instruction *InsertBefore=0)
const BasicBlock * getParent() const
Definition: Instruction.h:52
CallInst * CreateMemCpy(Value *Dst, Value *Src, uint64_t Size, unsigned Align, bool isVolatile=false, MDNode *TBAATag=0, MDNode *TBAAStructTag=0)
Create and insert a memcpy between the specified pointers.
Definition: IRBuilder.h:365
signed greater or equal
Definition: InstrTypes.h:679
Value * CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1148
void SetInstDebugLocation(Instruction *I) const
If this builder has a current debug location, set it on the specified instruction.
Definition: IRBuilder.h:127
CallInst * CreateCall3(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3, const Twine &Name="")
Definition: IRBuilder.h:1315
void SetDefaultFPMathTag(MDNode *FPMathTag)
Set the floating point math metadata to be used.
Definition: IRBuilder.h:186