LLVM  3.7.0
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/ConstantFolder.h"
23 #include "llvm/IR/DataLayout.h"
24 #include "llvm/IR/Function.h"
25 #include "llvm/IR/GlobalVariable.h"
26 #include "llvm/IR/Instructions.h"
27 #include "llvm/IR/LLVMContext.h"
28 #include "llvm/IR/Operator.h"
29 #include "llvm/IR/ValueHandle.h"
31 
32 namespace llvm {
33 class MDNode;
34 
35 /// \brief This provides the default implementation of the IRBuilder
36 /// 'InsertHelper' method that is called whenever an instruction is created by
37 /// IRBuilder and needs to be inserted.
38 ///
39 /// By default, this inserts the instruction at the insertion point.
40 template <bool preserveNames = true>
42 protected:
44  BasicBlock *BB, BasicBlock::iterator InsertPt) const {
45  if (BB) BB->getInstList().insert(InsertPt, I);
46  if (preserveNames)
47  I->setName(Name);
48  }
49 };
50 
51 /// \brief Common base class shared among various IRBuilders.
53  DebugLoc CurDbgLocation;
54 protected:
58 
61 public:
62 
63  IRBuilderBase(LLVMContext &context, MDNode *FPMathTag = nullptr)
64  : Context(context), DefaultFPMathTag(FPMathTag), FMF() {
66  }
67 
68  //===--------------------------------------------------------------------===//
69  // Builder configuration methods
70  //===--------------------------------------------------------------------===//
71 
72  /// \brief Clear the insertion point: created instructions will not be
73  /// inserted into a block.
75  BB = nullptr;
76  InsertPt = nullptr;
77  }
78 
79  BasicBlock *GetInsertBlock() const { return BB; }
81  LLVMContext &getContext() const { return Context; }
82 
83  /// \brief This specifies that created instructions should be appended to the
84  /// end of the specified block.
85  void SetInsertPoint(BasicBlock *TheBB) {
86  BB = TheBB;
87  InsertPt = BB->end();
88  }
89 
90  /// \brief This specifies that created instructions should be inserted before
91  /// the specified instruction.
93  BB = I->getParent();
94  InsertPt = I;
95  assert(I != BB->end() && "Can't read debug loc from end()");
97  }
98 
99  /// \brief This specifies that created instructions should be inserted at the
100  /// specified point.
102  BB = TheBB;
103  InsertPt = IP;
104  if (IP != TheBB->end())
105  SetCurrentDebugLocation(IP->getDebugLoc());
106  }
107 
108  /// \brief Set location information used by debugging information.
109  void SetCurrentDebugLocation(DebugLoc L) { CurDbgLocation = std::move(L); }
110 
111  /// \brief Get location information used by debugging information.
112  const DebugLoc &getCurrentDebugLocation() const { return CurDbgLocation; }
113 
114  /// \brief If this builder has a current debug location, set it on the
115  /// specified instruction.
117  if (CurDbgLocation)
118  I->setDebugLoc(CurDbgLocation);
119  }
120 
121  /// \brief Get the return type of the current function that we're emitting
122  /// into.
124 
125  /// InsertPoint - A saved insertion point.
126  class InsertPoint {
127  BasicBlock *Block;
128  BasicBlock::iterator Point;
129 
130  public:
131  /// \brief Creates a new insertion point which doesn't point to anything.
132  InsertPoint() : Block(nullptr) {}
133 
134  /// \brief Creates a new insertion point at the given location.
136  : Block(InsertBlock), Point(InsertPoint) {}
137 
138  /// \brief Returns true if this insert point is set.
139  bool isSet() const { return (Block != nullptr); }
140 
141  llvm::BasicBlock *getBlock() const { return Block; }
142  llvm::BasicBlock::iterator getPoint() const { return Point; }
143  };
144 
145  /// \brief Returns the current insert point.
146  InsertPoint saveIP() const {
148  }
149 
150  /// \brief Returns the current insert point, clearing it in the process.
154  return IP;
155  }
156 
157  /// \brief Sets the current insert point to a previously-saved location.
159  if (IP.isSet())
160  SetInsertPoint(IP.getBlock(), IP.getPoint());
161  else
163  }
164 
165  /// \brief Get the floating point math metadata being used.
167 
168  /// \brief Get the flags to be applied to created floating point ops
169  FastMathFlags getFastMathFlags() const { return FMF; }
170 
171  /// \brief Clear the fast-math flags.
173 
174  /// \brief Set the floating point math metadata to be used.
175  void SetDefaultFPMathTag(MDNode *FPMathTag) { DefaultFPMathTag = FPMathTag; }
176 
177  /// \brief Set the fast-math flags to be used with generated fp-math operators
178  void SetFastMathFlags(FastMathFlags NewFMF) { FMF = NewFMF; }
179 
180  //===--------------------------------------------------------------------===//
181  // RAII helpers.
182  //===--------------------------------------------------------------------===//
183 
184  // \brief RAII object that stores the current insertion point and restores it
185  // when the object is destroyed. This includes the debug location.
187  IRBuilderBase &Builder;
189  BasicBlock::iterator Point;
190  DebugLoc DbgLoc;
191 
192  InsertPointGuard(const InsertPointGuard &) = delete;
193  InsertPointGuard &operator=(const InsertPointGuard &) = delete;
194 
195  public:
197  : Builder(B), Block(B.GetInsertBlock()), Point(B.GetInsertPoint()),
198  DbgLoc(B.getCurrentDebugLocation()) {}
199 
201  Builder.restoreIP(InsertPoint(Block, Point));
202  Builder.SetCurrentDebugLocation(DbgLoc);
203  }
204  };
205 
206  // \brief RAII object that stores the current fast math settings and restores
207  // them when the object is destroyed.
209  IRBuilderBase &Builder;
210  FastMathFlags FMF;
211  MDNode *FPMathTag;
212 
213  FastMathFlagGuard(const FastMathFlagGuard &) = delete;
214  FastMathFlagGuard &operator=(
215  const FastMathFlagGuard &) = delete;
216 
217  public:
219  : Builder(B), FMF(B.FMF), FPMathTag(B.DefaultFPMathTag) {}
220 
222  Builder.FMF = FMF;
223  Builder.DefaultFPMathTag = FPMathTag;
224  }
225  };
226 
227  //===--------------------------------------------------------------------===//
228  // Miscellaneous creation methods.
229  //===--------------------------------------------------------------------===//
230 
231  /// \brief Make a new global variable with initializer type i8*
232  ///
233  /// Make a new global variable with an initializer that has array of i8 type
234  /// filled in with the null terminated string value specified. The new global
235  /// variable will be marked mergable with any others of the same contents. If
236  /// Name is specified, it is the name of the global variable created.
238  unsigned AddressSpace = 0);
239 
240  /// \brief Get a constant value representing either true or false.
241  ConstantInt *getInt1(bool V) {
242  return ConstantInt::get(getInt1Ty(), V);
243  }
244 
245  /// \brief Get the constant value for i1 true.
248  }
249 
250  /// \brief Get the constant value for i1 false.
253  }
254 
255  /// \brief Get a constant 8-bit value.
256  ConstantInt *getInt8(uint8_t C) {
257  return ConstantInt::get(getInt8Ty(), C);
258  }
259 
260  /// \brief Get a constant 16-bit value.
261  ConstantInt *getInt16(uint16_t C) {
262  return ConstantInt::get(getInt16Ty(), C);
263  }
264 
265  /// \brief Get a constant 32-bit value.
266  ConstantInt *getInt32(uint32_t C) {
267  return ConstantInt::get(getInt32Ty(), C);
268  }
269 
270  /// \brief Get a constant 64-bit value.
271  ConstantInt *getInt64(uint64_t C) {
272  return ConstantInt::get(getInt64Ty(), C);
273  }
274 
275  /// \brief Get a constant N-bit value, zero extended or truncated from
276  /// a 64-bit value.
277  ConstantInt *getIntN(unsigned N, uint64_t C) {
278  return ConstantInt::get(getIntNTy(N), C);
279  }
280 
281  /// \brief Get a constant integer value.
282  ConstantInt *getInt(const APInt &AI) {
283  return ConstantInt::get(Context, AI);
284  }
285 
286  //===--------------------------------------------------------------------===//
287  // Type creation methods
288  //===--------------------------------------------------------------------===//
289 
290  /// \brief Fetch the type representing a single bit
292  return Type::getInt1Ty(Context);
293  }
294 
295  /// \brief Fetch the type representing an 8-bit integer.
297  return Type::getInt8Ty(Context);
298  }
299 
300  /// \brief Fetch the type representing a 16-bit integer.
302  return Type::getInt16Ty(Context);
303  }
304 
305  /// \brief Fetch the type representing a 32-bit integer.
307  return Type::getInt32Ty(Context);
308  }
309 
310  /// \brief Fetch the type representing a 64-bit integer.
312  return Type::getInt64Ty(Context);
313  }
314 
315  /// \brief Fetch the type representing a 128-bit integer.
317  return Type::getInt128Ty(Context);
318  }
319 
320  /// \brief Fetch the type representing an N-bit integer.
321  IntegerType *getIntNTy(unsigned N) {
322  return Type::getIntNTy(Context, N);
323  }
324 
325  /// \brief Fetch the type representing a 16-bit floating point value.
327  return Type::getHalfTy(Context);
328  }
329 
330  /// \brief Fetch the type representing a 32-bit floating point value.
332  return Type::getFloatTy(Context);
333  }
334 
335  /// \brief Fetch the type representing a 64-bit floating point value.
337  return Type::getDoubleTy(Context);
338  }
339 
340  /// \brief Fetch the type representing void.
342  return Type::getVoidTy(Context);
343  }
344 
345  /// \brief Fetch the type representing a pointer to an 8-bit integer value.
346  PointerType *getInt8PtrTy(unsigned AddrSpace = 0) {
347  return Type::getInt8PtrTy(Context, AddrSpace);
348  }
349 
350  /// \brief Fetch the type representing a pointer to an integer value.
351  IntegerType *getIntPtrTy(const DataLayout &DL, unsigned AddrSpace = 0) {
352  return DL.getIntPtrType(Context, AddrSpace);
353  }
354 
355  //===--------------------------------------------------------------------===//
356  // Intrinsic creation methods
357  //===--------------------------------------------------------------------===//
358 
359  /// \brief Create and insert a memset to the specified pointer and the
360  /// specified value.
361  ///
362  /// If the pointer isn't an i8*, it will be converted. If a TBAA tag is
363  /// specified, it will be added to the instruction. Likewise with alias.scope
364  /// and noalias tags.
365  CallInst *CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, unsigned Align,
366  bool isVolatile = false, MDNode *TBAATag = nullptr,
367  MDNode *ScopeTag = nullptr,
368  MDNode *NoAliasTag = nullptr) {
369  return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile,
370  TBAATag, ScopeTag, NoAliasTag);
371  }
372 
373  CallInst *CreateMemSet(Value *Ptr, Value *Val, Value *Size, unsigned Align,
374  bool isVolatile = false, MDNode *TBAATag = nullptr,
375  MDNode *ScopeTag = nullptr,
376  MDNode *NoAliasTag = nullptr);
377 
378  /// \brief Create and insert a memcpy between the specified pointers.
379  ///
380  /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
381  /// specified, it will be added to the instruction. Likewise with alias.scope
382  /// and noalias tags.
383  CallInst *CreateMemCpy(Value *Dst, Value *Src, uint64_t Size, unsigned Align,
384  bool isVolatile = false, MDNode *TBAATag = nullptr,
385  MDNode *TBAAStructTag = nullptr,
386  MDNode *ScopeTag = nullptr,
387  MDNode *NoAliasTag = nullptr) {
388  return CreateMemCpy(Dst, Src, getInt64(Size), Align, isVolatile, TBAATag,
389  TBAAStructTag, ScopeTag, NoAliasTag);
390  }
391 
392  CallInst *CreateMemCpy(Value *Dst, Value *Src, Value *Size, unsigned Align,
393  bool isVolatile = false, MDNode *TBAATag = nullptr,
394  MDNode *TBAAStructTag = nullptr,
395  MDNode *ScopeTag = nullptr,
396  MDNode *NoAliasTag = nullptr);
397 
398  /// \brief Create and insert a memmove between the specified
399  /// pointers.
400  ///
401  /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
402  /// specified, it will be added to the instruction. Likewise with alias.scope
403  /// and noalias tags.
404  CallInst *CreateMemMove(Value *Dst, Value *Src, uint64_t Size, unsigned Align,
405  bool isVolatile = false, MDNode *TBAATag = nullptr,
406  MDNode *ScopeTag = nullptr,
407  MDNode *NoAliasTag = nullptr) {
408  return CreateMemMove(Dst, Src, getInt64(Size), Align, isVolatile,
409  TBAATag, ScopeTag, NoAliasTag);
410  }
411 
412  CallInst *CreateMemMove(Value *Dst, Value *Src, Value *Size, unsigned Align,
413  bool isVolatile = false, MDNode *TBAATag = nullptr,
414  MDNode *ScopeTag = nullptr,
415  MDNode *NoAliasTag = nullptr);
416 
417  /// \brief Create a lifetime.start intrinsic.
418  ///
419  /// If the pointer isn't i8* it will be converted.
420  CallInst *CreateLifetimeStart(Value *Ptr, ConstantInt *Size = nullptr);
421 
422  /// \brief Create a lifetime.end intrinsic.
423  ///
424  /// If the pointer isn't i8* it will be converted.
425  CallInst *CreateLifetimeEnd(Value *Ptr, ConstantInt *Size = nullptr);
426 
427  /// \brief Create a call to Masked Load intrinsic
428  CallInst *CreateMaskedLoad(Value *Ptr, unsigned Align, Value *Mask,
429  Value *PassThru = 0, const Twine &Name = "");
430 
431  /// \brief Create a call to Masked Store intrinsic
432  CallInst *CreateMaskedStore(Value *Val, Value *Ptr, unsigned Align,
433  Value *Mask);
434 
435  /// \brief Create an assume intrinsic call that allows the optimizer to
436  /// assume that the provided condition will be true.
438 
439  /// \brief Create a call to the experimental.gc.statepoint intrinsic to
440  /// start a new statepoint sequence.
441  CallInst *CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes,
442  Value *ActualCallee,
443  ArrayRef<Value *> CallArgs,
444  ArrayRef<Value *> DeoptArgs,
445  ArrayRef<Value *> GCArgs,
446  const Twine &Name = "");
447 
448  // \brief Conveninence function for the common case when CallArgs are filled
449  // in using makeArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be
450  // .get()'ed to get the Value pointer.
451  CallInst *CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes,
452  Value *ActualCallee, ArrayRef<Use> CallArgs,
453  ArrayRef<Value *> DeoptArgs,
454  ArrayRef<Value *> GCArgs,
455  const Twine &Name = "");
456 
457  /// brief Create an invoke to the experimental.gc.statepoint intrinsic to
458  /// start a new statepoint sequence.
459  InvokeInst *
460  CreateGCStatepointInvoke(uint64_t ID, uint32_t NumPatchBytes,
461  Value *ActualInvokee, BasicBlock *NormalDest,
462  BasicBlock *UnwindDest, ArrayRef<Value *> InvokeArgs,
463  ArrayRef<Value *> DeoptArgs,
464  ArrayRef<Value *> GCArgs, const Twine &Name = "");
465 
466  // Conveninence function for the common case when CallArgs are filled in using
467  // makeArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be .get()'ed to
468  // get the Value *.
469  InvokeInst *
470  CreateGCStatepointInvoke(uint64_t ID, uint32_t NumPatchBytes,
471  Value *ActualInvokee, BasicBlock *NormalDest,
472  BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
473  ArrayRef<Value *> DeoptArgs,
474  ArrayRef<Value *> GCArgs, const Twine &Name = "");
475 
476  /// \brief Create a call to the experimental.gc.result intrinsic to extract
477  /// the result from a call wrapped in a statepoint.
479  Type *ResultType,
480  const Twine &Name = "");
481 
482  /// \brief Create a call to the experimental.gc.relocate intrinsics to
483  /// project the relocated value of one pointer from the statepoint.
485  int BaseOffset,
486  int DerivedOffset,
487  Type *ResultType,
488  const Twine &Name = "");
489 
490 private:
491  /// \brief Create a call to a masked intrinsic with given Id.
492  /// Masked intrinsic has only one overloaded type - data type.
493  CallInst *CreateMaskedIntrinsic(Intrinsic::ID Id, ArrayRef<Value *> Ops,
494  Type *DataTy, const Twine &Name = "");
495 
496  Value *getCastedInt8PtrValue(Value *Ptr);
497 };
498 
499 /// \brief This provides a uniform API for creating instructions and inserting
500 /// them into a basic block: either at the end of a BasicBlock, or at a specific
501 /// iterator location in a block.
502 ///
503 /// Note that the builder does not expose the full generality of LLVM
504 /// instructions. For access to extra instruction properties, use the mutators
505 /// (e.g. setVolatile) on the instructions after they have been
506 /// created. Convenience state exists to specify fast-math flags and fp-math
507 /// tags.
508 ///
509 /// The first template argument handles whether or not to preserve names in the
510 /// final instruction output. This defaults to on. The second template argument
511 /// specifies a class to use for creating constants. This defaults to creating
512 /// minimally folded constants. The third template argument allows clients to
513 /// specify custom insertion hooks that are called on every newly created
514 /// insertion.
515 template<bool preserveNames = true, typename T = ConstantFolder,
516  typename Inserter = IRBuilderDefaultInserter<preserveNames> >
517 class IRBuilder : public IRBuilderBase, public Inserter {
518  T Folder;
519 public:
520  IRBuilder(LLVMContext &C, const T &F, const Inserter &I = Inserter(),
521  MDNode *FPMathTag = nullptr)
522  : IRBuilderBase(C, FPMathTag), Inserter(I), Folder(F) {
523  }
524 
525  explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr)
526  : IRBuilderBase(C, FPMathTag), Folder() {
527  }
528 
529  explicit IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag = nullptr)
530  : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder(F) {
531  SetInsertPoint(TheBB);
532  }
533 
534  explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr)
535  : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder() {
536  SetInsertPoint(TheBB);
537  }
538 
539  explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr)
540  : IRBuilderBase(IP->getContext(), FPMathTag), Folder() {
541  SetInsertPoint(IP);
542  }
543 
545  MDNode *FPMathTag = nullptr)
546  : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder(F) {
547  SetInsertPoint(TheBB, IP);
548  }
549 
551  MDNode *FPMathTag = nullptr)
552  : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder() {
553  SetInsertPoint(TheBB, IP);
554  }
555 
556  /// \brief Get the constant folder being used.
557  const T &getFolder() { return Folder; }
558 
559  /// \brief Return true if this builder is configured to actually add the
560  /// requested names to IR created through it.
561  bool isNamePreserving() const { return preserveNames; }
562 
563  /// \brief Insert and return the specified instruction.
564  template<typename InstTy>
565  InstTy *Insert(InstTy *I, const Twine &Name = "") const {
566  this->InsertHelper(I, Name, BB, InsertPt);
567  this->SetInstDebugLocation(I);
568  return I;
569  }
570 
571  /// \brief No-op overload to handle constants.
572  Constant *Insert(Constant *C, const Twine& = "") const {
573  return C;
574  }
575 
576  //===--------------------------------------------------------------------===//
577  // Instruction creation methods: Terminators
578  //===--------------------------------------------------------------------===//
579 
580 private:
581  /// \brief Helper to add branch weight metadata onto an instruction.
582  /// \returns The annotated instruction.
583  template <typename InstTy>
584  InstTy *addBranchWeights(InstTy *I, MDNode *Weights) {
585  if (Weights)
586  I->setMetadata(LLVMContext::MD_prof, Weights);
587  return I;
588  }
589 
590 public:
591  /// \brief Create a 'ret void' instruction.
594  }
595 
596  /// \brief Create a 'ret <val>' instruction.
598  return Insert(ReturnInst::Create(Context, V));
599  }
600 
601  /// \brief Create a sequence of N insertvalue instructions,
602  /// with one Value from the retVals array each, that build a aggregate
603  /// return value one value at a time, and a ret instruction to return
604  /// the resulting aggregate value.
605  ///
606  /// This is a convenience function for code that uses aggregate return values
607  /// as a vehicle for having multiple return values.
608  ReturnInst *CreateAggregateRet(Value *const *retVals, unsigned N) {
610  for (unsigned i = 0; i != N; ++i)
611  V = CreateInsertValue(V, retVals[i], i, "mrv");
612  return Insert(ReturnInst::Create(Context, V));
613  }
614 
615  /// \brief Create an unconditional 'br label X' instruction.
617  return Insert(BranchInst::Create(Dest));
618  }
619 
620  /// \brief Create a conditional 'br Cond, TrueDest, FalseDest'
621  /// instruction.
623  MDNode *BranchWeights = nullptr) {
624  return Insert(addBranchWeights(BranchInst::Create(True, False, Cond),
625  BranchWeights));
626  }
627 
628  /// \brief Create a switch instruction with the specified value, default dest,
629  /// and with a hint for the number of cases that will be added (for efficient
630  /// allocation).
631  SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10,
632  MDNode *BranchWeights = nullptr) {
633  return Insert(addBranchWeights(SwitchInst::Create(V, Dest, NumCases),
634  BranchWeights));
635  }
636 
637  /// \brief Create an indirect branch instruction with the specified address
638  /// operand, with an optional hint for the number of destinations that will be
639  /// added (for efficient allocation).
640  IndirectBrInst *CreateIndirectBr(Value *Addr, unsigned NumDests = 10) {
641  return Insert(IndirectBrInst::Create(Addr, NumDests));
642  }
643 
644  InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
645  BasicBlock *UnwindDest, const Twine &Name = "") {
646  return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, None),
647  Name);
648  }
649  InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
650  BasicBlock *UnwindDest, Value *Arg1,
651  const Twine &Name = "") {
652  return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Arg1),
653  Name);
654  }
655  InvokeInst *CreateInvoke3(Value *Callee, BasicBlock *NormalDest,
656  BasicBlock *UnwindDest, Value *Arg1,
657  Value *Arg2, Value *Arg3,
658  const Twine &Name = "") {
659  Value *Args[] = { Arg1, Arg2, Arg3 };
660  return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args),
661  Name);
662  }
663  /// \brief Create an invoke instruction.
664  InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
665  BasicBlock *UnwindDest, ArrayRef<Value *> Args,
666  const Twine &Name = "") {
667  return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args),
668  Name);
669  }
670 
672  return Insert(ResumeInst::Create(Exn));
673  }
674 
676  return Insert(new UnreachableInst(Context));
677  }
678 
679  //===--------------------------------------------------------------------===//
680  // Instruction creation methods: Binary Operators
681  //===--------------------------------------------------------------------===//
682 private:
683  BinaryOperator *CreateInsertNUWNSWBinOp(BinaryOperator::BinaryOps Opc,
684  Value *LHS, Value *RHS,
685  const Twine &Name,
686  bool HasNUW, bool HasNSW) {
687  BinaryOperator *BO = Insert(BinaryOperator::Create(Opc, LHS, RHS), Name);
688  if (HasNUW) BO->setHasNoUnsignedWrap();
689  if (HasNSW) BO->setHasNoSignedWrap();
690  return BO;
691  }
692 
693  Instruction *AddFPMathAttributes(Instruction *I,
694  MDNode *FPMathTag,
695  FastMathFlags FMF) const {
696  if (!FPMathTag)
697  FPMathTag = DefaultFPMathTag;
698  if (FPMathTag)
699  I->setMetadata(LLVMContext::MD_fpmath, FPMathTag);
700  I->setFastMathFlags(FMF);
701  return I;
702  }
703 public:
704  Value *CreateAdd(Value *LHS, Value *RHS, const Twine &Name = "",
705  bool HasNUW = false, bool HasNSW = false) {
706  if (Constant *LC = dyn_cast<Constant>(LHS))
707  if (Constant *RC = dyn_cast<Constant>(RHS))
708  return Insert(Folder.CreateAdd(LC, RC, HasNUW, HasNSW), Name);
709  return CreateInsertNUWNSWBinOp(Instruction::Add, LHS, RHS, Name,
710  HasNUW, HasNSW);
711  }
712  Value *CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
713  return CreateAdd(LHS, RHS, Name, false, true);
714  }
715  Value *CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
716  return CreateAdd(LHS, RHS, Name, true, false);
717  }
718  Value *CreateFAdd(Value *LHS, Value *RHS, const Twine &Name = "",
719  MDNode *FPMathTag = nullptr) {
720  if (Constant *LC = dyn_cast<Constant>(LHS))
721  if (Constant *RC = dyn_cast<Constant>(RHS))
722  return Insert(Folder.CreateFAdd(LC, RC), Name);
723  return Insert(AddFPMathAttributes(BinaryOperator::CreateFAdd(LHS, RHS),
724  FPMathTag, FMF), Name);
725  }
726  Value *CreateSub(Value *LHS, Value *RHS, const Twine &Name = "",
727  bool HasNUW = false, bool HasNSW = false) {
728  if (Constant *LC = dyn_cast<Constant>(LHS))
729  if (Constant *RC = dyn_cast<Constant>(RHS))
730  return Insert(Folder.CreateSub(LC, RC, HasNUW, HasNSW), Name);
731  return CreateInsertNUWNSWBinOp(Instruction::Sub, LHS, RHS, Name,
732  HasNUW, HasNSW);
733  }
734  Value *CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
735  return CreateSub(LHS, RHS, Name, false, true);
736  }
737  Value *CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
738  return CreateSub(LHS, RHS, Name, true, false);
739  }
740  Value *CreateFSub(Value *LHS, Value *RHS, const Twine &Name = "",
741  MDNode *FPMathTag = nullptr) {
742  if (Constant *LC = dyn_cast<Constant>(LHS))
743  if (Constant *RC = dyn_cast<Constant>(RHS))
744  return Insert(Folder.CreateFSub(LC, RC), Name);
745  return Insert(AddFPMathAttributes(BinaryOperator::CreateFSub(LHS, RHS),
746  FPMathTag, FMF), Name);
747  }
748  Value *CreateMul(Value *LHS, Value *RHS, const Twine &Name = "",
749  bool HasNUW = false, bool HasNSW = false) {
750  if (Constant *LC = dyn_cast<Constant>(LHS))
751  if (Constant *RC = dyn_cast<Constant>(RHS))
752  return Insert(Folder.CreateMul(LC, RC, HasNUW, HasNSW), Name);
753  return CreateInsertNUWNSWBinOp(Instruction::Mul, LHS, RHS, Name,
754  HasNUW, HasNSW);
755  }
756  Value *CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
757  return CreateMul(LHS, RHS, Name, false, true);
758  }
759  Value *CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
760  return CreateMul(LHS, RHS, Name, true, false);
761  }
762  Value *CreateFMul(Value *LHS, Value *RHS, const Twine &Name = "",
763  MDNode *FPMathTag = nullptr) {
764  if (Constant *LC = dyn_cast<Constant>(LHS))
765  if (Constant *RC = dyn_cast<Constant>(RHS))
766  return Insert(Folder.CreateFMul(LC, RC), Name);
767  return Insert(AddFPMathAttributes(BinaryOperator::CreateFMul(LHS, RHS),
768  FPMathTag, FMF), Name);
769  }
770  Value *CreateUDiv(Value *LHS, Value *RHS, const Twine &Name = "",
771  bool isExact = false) {
772  if (Constant *LC = dyn_cast<Constant>(LHS))
773  if (Constant *RC = dyn_cast<Constant>(RHS))
774  return Insert(Folder.CreateUDiv(LC, RC, isExact), Name);
775  if (!isExact)
776  return Insert(BinaryOperator::CreateUDiv(LHS, RHS), Name);
777  return Insert(BinaryOperator::CreateExactUDiv(LHS, RHS), Name);
778  }
779  Value *CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
780  return CreateUDiv(LHS, RHS, Name, true);
781  }
782  Value *CreateSDiv(Value *LHS, Value *RHS, const Twine &Name = "",
783  bool isExact = false) {
784  if (Constant *LC = dyn_cast<Constant>(LHS))
785  if (Constant *RC = dyn_cast<Constant>(RHS))
786  return Insert(Folder.CreateSDiv(LC, RC, isExact), Name);
787  if (!isExact)
788  return Insert(BinaryOperator::CreateSDiv(LHS, RHS), Name);
789  return Insert(BinaryOperator::CreateExactSDiv(LHS, RHS), Name);
790  }
791  Value *CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
792  return CreateSDiv(LHS, RHS, Name, true);
793  }
794  Value *CreateFDiv(Value *LHS, Value *RHS, const Twine &Name = "",
795  MDNode *FPMathTag = nullptr) {
796  if (Constant *LC = dyn_cast<Constant>(LHS))
797  if (Constant *RC = dyn_cast<Constant>(RHS))
798  return Insert(Folder.CreateFDiv(LC, RC), Name);
799  return Insert(AddFPMathAttributes(BinaryOperator::CreateFDiv(LHS, RHS),
800  FPMathTag, FMF), Name);
801  }
802  Value *CreateURem(Value *LHS, Value *RHS, const Twine &Name = "") {
803  if (Constant *LC = dyn_cast<Constant>(LHS))
804  if (Constant *RC = dyn_cast<Constant>(RHS))
805  return Insert(Folder.CreateURem(LC, RC), Name);
806  return Insert(BinaryOperator::CreateURem(LHS, RHS), Name);
807  }
808  Value *CreateSRem(Value *LHS, Value *RHS, const Twine &Name = "") {
809  if (Constant *LC = dyn_cast<Constant>(LHS))
810  if (Constant *RC = dyn_cast<Constant>(RHS))
811  return Insert(Folder.CreateSRem(LC, RC), Name);
812  return Insert(BinaryOperator::CreateSRem(LHS, RHS), Name);
813  }
814  Value *CreateFRem(Value *LHS, Value *RHS, const Twine &Name = "",
815  MDNode *FPMathTag = nullptr) {
816  if (Constant *LC = dyn_cast<Constant>(LHS))
817  if (Constant *RC = dyn_cast<Constant>(RHS))
818  return Insert(Folder.CreateFRem(LC, RC), Name);
819  return Insert(AddFPMathAttributes(BinaryOperator::CreateFRem(LHS, RHS),
820  FPMathTag, FMF), Name);
821  }
822 
823  Value *CreateShl(Value *LHS, Value *RHS, const Twine &Name = "",
824  bool HasNUW = false, bool HasNSW = false) {
825  if (Constant *LC = dyn_cast<Constant>(LHS))
826  if (Constant *RC = dyn_cast<Constant>(RHS))
827  return Insert(Folder.CreateShl(LC, RC, HasNUW, HasNSW), Name);
828  return CreateInsertNUWNSWBinOp(Instruction::Shl, LHS, RHS, Name,
829  HasNUW, HasNSW);
830  }
831  Value *CreateShl(Value *LHS, const APInt &RHS, const Twine &Name = "",
832  bool HasNUW = false, bool HasNSW = false) {
833  return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
834  HasNUW, HasNSW);
835  }
836  Value *CreateShl(Value *LHS, uint64_t RHS, const Twine &Name = "",
837  bool HasNUW = false, bool HasNSW = false) {
838  return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
839  HasNUW, HasNSW);
840  }
841 
842  Value *CreateLShr(Value *LHS, Value *RHS, const Twine &Name = "",
843  bool isExact = false) {
844  if (Constant *LC = dyn_cast<Constant>(LHS))
845  if (Constant *RC = dyn_cast<Constant>(RHS))
846  return Insert(Folder.CreateLShr(LC, RC, isExact), Name);
847  if (!isExact)
848  return Insert(BinaryOperator::CreateLShr(LHS, RHS), Name);
849  return Insert(BinaryOperator::CreateExactLShr(LHS, RHS), Name);
850  }
851  Value *CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
852  bool isExact = false) {
853  return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
854  }
855  Value *CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name = "",
856  bool isExact = false) {
857  return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
858  }
859 
860  Value *CreateAShr(Value *LHS, Value *RHS, const Twine &Name = "",
861  bool isExact = false) {
862  if (Constant *LC = dyn_cast<Constant>(LHS))
863  if (Constant *RC = dyn_cast<Constant>(RHS))
864  return Insert(Folder.CreateAShr(LC, RC, isExact), Name);
865  if (!isExact)
866  return Insert(BinaryOperator::CreateAShr(LHS, RHS), Name);
867  return Insert(BinaryOperator::CreateExactAShr(LHS, RHS), Name);
868  }
869  Value *CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
870  bool isExact = false) {
871  return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
872  }
873  Value *CreateAShr(Value *LHS, uint64_t RHS, const Twine &Name = "",
874  bool isExact = false) {
875  return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
876  }
877 
878  Value *CreateAnd(Value *LHS, Value *RHS, const Twine &Name = "") {
879  if (Constant *RC = dyn_cast<Constant>(RHS)) {
880  if (isa<ConstantInt>(RC) && cast<ConstantInt>(RC)->isAllOnesValue())
881  return LHS; // LHS & -1 -> LHS
882  if (Constant *LC = dyn_cast<Constant>(LHS))
883  return Insert(Folder.CreateAnd(LC, RC), Name);
884  }
885  return Insert(BinaryOperator::CreateAnd(LHS, RHS), Name);
886  }
887  Value *CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name = "") {
888  return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
889  }
890  Value *CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name = "") {
891  return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
892  }
893 
894  Value *CreateOr(Value *LHS, Value *RHS, const Twine &Name = "") {
895  if (Constant *RC = dyn_cast<Constant>(RHS)) {
896  if (RC->isNullValue())
897  return LHS; // LHS | 0 -> LHS
898  if (Constant *LC = dyn_cast<Constant>(LHS))
899  return Insert(Folder.CreateOr(LC, RC), Name);
900  }
901  return Insert(BinaryOperator::CreateOr(LHS, RHS), Name);
902  }
903  Value *CreateOr(Value *LHS, const APInt &RHS, const Twine &Name = "") {
904  return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
905  }
906  Value *CreateOr(Value *LHS, uint64_t RHS, const Twine &Name = "") {
907  return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
908  }
909 
910  Value *CreateXor(Value *LHS, Value *RHS, const Twine &Name = "") {
911  if (Constant *LC = dyn_cast<Constant>(LHS))
912  if (Constant *RC = dyn_cast<Constant>(RHS))
913  return Insert(Folder.CreateXor(LC, RC), Name);
914  return Insert(BinaryOperator::CreateXor(LHS, RHS), Name);
915  }
916  Value *CreateXor(Value *LHS, const APInt &RHS, const Twine &Name = "") {
917  return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
918  }
919  Value *CreateXor(Value *LHS, uint64_t RHS, const Twine &Name = "") {
920  return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
921  }
922 
924  Value *LHS, Value *RHS, const Twine &Name = "",
925  MDNode *FPMathTag = nullptr) {
926  if (Constant *LC = dyn_cast<Constant>(LHS))
927  if (Constant *RC = dyn_cast<Constant>(RHS))
928  return Insert(Folder.CreateBinOp(Opc, LC, RC), Name);
929  llvm::Instruction *BinOp = BinaryOperator::Create(Opc, LHS, RHS);
930  if (isa<FPMathOperator>(BinOp))
931  BinOp = AddFPMathAttributes(BinOp, FPMathTag, FMF);
932  return Insert(BinOp, Name);
933  }
934 
935  Value *CreateNeg(Value *V, const Twine &Name = "",
936  bool HasNUW = false, bool HasNSW = false) {
937  if (Constant *VC = dyn_cast<Constant>(V))
938  return Insert(Folder.CreateNeg(VC, HasNUW, HasNSW), Name);
940  if (HasNUW) BO->setHasNoUnsignedWrap();
941  if (HasNSW) BO->setHasNoSignedWrap();
942  return BO;
943  }
944  Value *CreateNSWNeg(Value *V, const Twine &Name = "") {
945  return CreateNeg(V, Name, false, true);
946  }
947  Value *CreateNUWNeg(Value *V, const Twine &Name = "") {
948  return CreateNeg(V, Name, true, false);
949  }
950  Value *CreateFNeg(Value *V, const Twine &Name = "",
951  MDNode *FPMathTag = nullptr) {
952  if (Constant *VC = dyn_cast<Constant>(V))
953  return Insert(Folder.CreateFNeg(VC), Name);
954  return Insert(AddFPMathAttributes(BinaryOperator::CreateFNeg(V),
955  FPMathTag, FMF), Name);
956  }
957  Value *CreateNot(Value *V, const Twine &Name = "") {
958  if (Constant *VC = dyn_cast<Constant>(V))
959  return Insert(Folder.CreateNot(VC), Name);
960  return Insert(BinaryOperator::CreateNot(V), Name);
961  }
962 
963  //===--------------------------------------------------------------------===//
964  // Instruction creation methods: Memory Instructions
965  //===--------------------------------------------------------------------===//
966 
967  AllocaInst *CreateAlloca(Type *Ty, Value *ArraySize = nullptr,
968  const Twine &Name = "") {
969  return Insert(new AllocaInst(Ty, ArraySize), Name);
970  }
971  // \brief Provided to resolve 'CreateLoad(Ptr, "...")' correctly, instead of
972  // converting the string to 'bool' for the isVolatile parameter.
973  LoadInst *CreateLoad(Value *Ptr, const char *Name) {
974  return Insert(new LoadInst(Ptr), Name);
975  }
976  LoadInst *CreateLoad(Value *Ptr, const Twine &Name = "") {
977  return Insert(new LoadInst(Ptr), Name);
978  }
979  LoadInst *CreateLoad(Type *Ty, Value *Ptr, const Twine &Name = "") {
980  return Insert(new LoadInst(Ty, Ptr), Name);
981  }
982  LoadInst *CreateLoad(Value *Ptr, bool isVolatile, const Twine &Name = "") {
983  return Insert(new LoadInst(Ptr, nullptr, isVolatile), Name);
984  }
985  StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) {
986  return Insert(new StoreInst(Val, Ptr, isVolatile));
987  }
988  // \brief Provided to resolve 'CreateAlignedLoad(Ptr, Align, "...")'
989  // correctly, instead of converting the string to 'bool' for the isVolatile
990  // parameter.
991  LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name) {
992  LoadInst *LI = CreateLoad(Ptr, Name);
993  LI->setAlignment(Align);
994  return LI;
995  }
997  const Twine &Name = "") {
998  LoadInst *LI = CreateLoad(Ptr, Name);
999  LI->setAlignment(Align);
1000  return LI;
1001  }
1003  const Twine &Name = "") {
1004  LoadInst *LI = CreateLoad(Ptr, isVolatile, Name);
1005  LI->setAlignment(Align);
1006  return LI;
1007  }
1009  bool isVolatile = false) {
1010  StoreInst *SI = CreateStore(Val, Ptr, isVolatile);
1011  SI->setAlignment(Align);
1012  return SI;
1013  }
1015  SynchronizationScope SynchScope = CrossThread,
1016  const Twine &Name = "") {
1017  return Insert(new FenceInst(Context, Ordering, SynchScope), Name);
1018  }
1021  AtomicOrdering SuccessOrdering,
1022  AtomicOrdering FailureOrdering,
1023  SynchronizationScope SynchScope = CrossThread) {
1024  return Insert(new AtomicCmpXchgInst(Ptr, Cmp, New, SuccessOrdering,
1025  FailureOrdering, SynchScope));
1026  }
1028  AtomicOrdering Ordering,
1029  SynchronizationScope SynchScope = CrossThread) {
1030  return Insert(new AtomicRMWInst(Op, Ptr, Val, Ordering, SynchScope));
1031  }
1033  const Twine &Name = "") {
1034  return CreateGEP(nullptr, Ptr, IdxList, Name);
1035  }
1037  const Twine &Name = "") {
1038  if (Constant *PC = dyn_cast<Constant>(Ptr)) {
1039  // Every index must be constant.
1040  size_t i, e;
1041  for (i = 0, e = IdxList.size(); i != e; ++i)
1042  if (!isa<Constant>(IdxList[i]))
1043  break;
1044  if (i == e)
1045  return Insert(Folder.CreateGetElementPtr(Ty, PC, IdxList), Name);
1046  }
1047  return Insert(GetElementPtrInst::Create(Ty, Ptr, IdxList), Name);
1048  }
1050  const Twine &Name = "") {
1051  return CreateInBoundsGEP(nullptr, Ptr, IdxList, Name);
1052  }
1054  const Twine &Name = "") {
1055  if (Constant *PC = dyn_cast<Constant>(Ptr)) {
1056  // Every index must be constant.
1057  size_t i, e;
1058  for (i = 0, e = IdxList.size(); i != e; ++i)
1059  if (!isa<Constant>(IdxList[i]))
1060  break;
1061  if (i == e)
1062  return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, IdxList),
1063  Name);
1064  }
1065  return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, IdxList), Name);
1066  }
1067  Value *CreateGEP(Value *Ptr, Value *Idx, const Twine &Name = "") {
1068  return CreateGEP(nullptr, Ptr, Idx, Name);
1069  }
1070  Value *CreateGEP(Type *Ty, Value *Ptr, Value *Idx, const Twine &Name = "") {
1071  if (Constant *PC = dyn_cast<Constant>(Ptr))
1072  if (Constant *IC = dyn_cast<Constant>(Idx))
1073  return Insert(Folder.CreateGetElementPtr(Ty, PC, IC), Name);
1074  return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
1075  }
1077  const Twine &Name = "") {
1078  if (Constant *PC = dyn_cast<Constant>(Ptr))
1079  if (Constant *IC = dyn_cast<Constant>(Idx))
1080  return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, IC), Name);
1081  return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
1082  }
1083  Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name = "") {
1084  return CreateConstGEP1_32(nullptr, Ptr, Idx0, Name);
1085  }
1086  Value *CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
1087  const Twine &Name = "") {
1089 
1090  if (Constant *PC = dyn_cast<Constant>(Ptr))
1091  return Insert(Folder.CreateGetElementPtr(Ty, PC, Idx), Name);
1092 
1093  return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
1094  }
1095  Value *CreateConstInBoundsGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
1096  const Twine &Name = "") {
1098 
1099  if (Constant *PC = dyn_cast<Constant>(Ptr))
1100  return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idx), Name);
1101 
1102  return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
1103  }
1104  Value *CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1,
1105  const Twine &Name = "") {
1106  Value *Idxs[] = {
1109  };
1110 
1111  if (Constant *PC = dyn_cast<Constant>(Ptr))
1112  return Insert(Folder.CreateGetElementPtr(Ty, PC, Idxs), Name);
1113 
1114  return Insert(GetElementPtrInst::Create(Ty, Ptr, Idxs), Name);
1115  }
1116  Value *CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0,
1117  unsigned Idx1, const Twine &Name = "") {
1118  Value *Idxs[] = {
1121  };
1122 
1123  if (Constant *PC = dyn_cast<Constant>(Ptr))
1124  return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idxs), Name);
1125 
1126  return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idxs), Name);
1127  }
1128  Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name = "") {
1130 
1131  if (Constant *PC = dyn_cast<Constant>(Ptr))
1132  return Insert(Folder.CreateGetElementPtr(nullptr, PC, Idx), Name);
1133 
1134  return Insert(GetElementPtrInst::Create(nullptr, Ptr, Idx), Name);
1135  }
1137  const Twine &Name = "") {
1139 
1140  if (Constant *PC = dyn_cast<Constant>(Ptr))
1141  return Insert(Folder.CreateInBoundsGetElementPtr(nullptr, PC, Idx), Name);
1142 
1143  return Insert(GetElementPtrInst::CreateInBounds(nullptr, Ptr, Idx), Name);
1144  }
1145  Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1146  const Twine &Name = "") {
1147  Value *Idxs[] = {
1150  };
1151 
1152  if (Constant *PC = dyn_cast<Constant>(Ptr))
1153  return Insert(Folder.CreateGetElementPtr(nullptr, PC, Idxs), Name);
1154 
1155  return Insert(GetElementPtrInst::Create(nullptr, Ptr, Idxs), Name);
1156  }
1157  Value *CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1158  const Twine &Name = "") {
1159  Value *Idxs[] = {
1162  };
1163 
1164  if (Constant *PC = dyn_cast<Constant>(Ptr))
1165  return Insert(Folder.CreateInBoundsGetElementPtr(nullptr, PC, Idxs),
1166  Name);
1167 
1168  return Insert(GetElementPtrInst::CreateInBounds(nullptr, Ptr, Idxs), Name);
1169  }
1170  Value *CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx,
1171  const Twine &Name = "") {
1172  return CreateConstInBoundsGEP2_32(Ty, Ptr, 0, Idx, Name);
1173  }
1174 
1175  /// \brief Same as CreateGlobalString, but return a pointer with "i8*" type
1176  /// instead of a pointer to array of i8.
1177  Value *CreateGlobalStringPtr(StringRef Str, const Twine &Name = "",
1178  unsigned AddressSpace = 0) {
1181  Value *Args[] = { zero, zero };
1182  return CreateInBoundsGEP(gv->getValueType(), gv, Args, Name);
1183  }
1184 
1185  //===--------------------------------------------------------------------===//
1186  // Instruction creation methods: Cast/Conversion Operators
1187  //===--------------------------------------------------------------------===//
1188 
1189  Value *CreateTrunc(Value *V, Type *DestTy, const Twine &Name = "") {
1190  return CreateCast(Instruction::Trunc, V, DestTy, Name);
1191  }
1192  Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "") {
1193  return CreateCast(Instruction::ZExt, V, DestTy, Name);
1194  }
1195  Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") {
1196  return CreateCast(Instruction::SExt, V, DestTy, Name);
1197  }
1198  /// \brief Create a ZExt or Trunc from the integer value V to DestTy. Return
1199  /// the value untouched if the type of V is already DestTy.
1201  const Twine &Name = "") {
1202  assert(V->getType()->isIntOrIntVectorTy() &&
1203  DestTy->isIntOrIntVectorTy() &&
1204  "Can only zero extend/truncate integers!");
1205  Type *VTy = V->getType();
1206  if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
1207  return CreateZExt(V, DestTy, Name);
1208  if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
1209  return CreateTrunc(V, DestTy, Name);
1210  return V;
1211  }
1212  /// \brief Create a SExt or Trunc from the integer value V to DestTy. Return
1213  /// the value untouched if the type of V is already DestTy.
1215  const Twine &Name = "") {
1216  assert(V->getType()->isIntOrIntVectorTy() &&
1217  DestTy->isIntOrIntVectorTy() &&
1218  "Can only sign extend/truncate integers!");
1219  Type *VTy = V->getType();
1220  if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
1221  return CreateSExt(V, DestTy, Name);
1222  if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
1223  return CreateTrunc(V, DestTy, Name);
1224  return V;
1225  }
1226  Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = ""){
1227  return CreateCast(Instruction::FPToUI, V, DestTy, Name);
1228  }
1229  Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = ""){
1230  return CreateCast(Instruction::FPToSI, V, DestTy, Name);
1231  }
1232  Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
1233  return CreateCast(Instruction::UIToFP, V, DestTy, Name);
1234  }
1235  Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
1236  return CreateCast(Instruction::SIToFP, V, DestTy, Name);
1237  }
1239  const Twine &Name = "") {
1240  return CreateCast(Instruction::FPTrunc, V, DestTy, Name);
1241  }
1242  Value *CreateFPExt(Value *V, Type *DestTy, const Twine &Name = "") {
1243  return CreateCast(Instruction::FPExt, V, DestTy, Name);
1244  }
1246  const Twine &Name = "") {
1247  return CreateCast(Instruction::PtrToInt, V, DestTy, Name);
1248  }
1250  const Twine &Name = "") {
1251  return CreateCast(Instruction::IntToPtr, V, DestTy, Name);
1252  }
1254  const Twine &Name = "") {
1255  return CreateCast(Instruction::BitCast, V, DestTy, Name);
1256  }
1258  const Twine &Name = "") {
1259  return CreateCast(Instruction::AddrSpaceCast, V, DestTy, Name);
1260  }
1262  const Twine &Name = "") {
1263  if (V->getType() == DestTy)
1264  return V;
1265  if (Constant *VC = dyn_cast<Constant>(V))
1266  return Insert(Folder.CreateZExtOrBitCast(VC, DestTy), Name);
1267  return Insert(CastInst::CreateZExtOrBitCast(V, DestTy), Name);
1268  }
1270  const Twine &Name = "") {
1271  if (V->getType() == DestTy)
1272  return V;
1273  if (Constant *VC = dyn_cast<Constant>(V))
1274  return Insert(Folder.CreateSExtOrBitCast(VC, DestTy), Name);
1275  return Insert(CastInst::CreateSExtOrBitCast(V, DestTy), Name);
1276  }
1278  const Twine &Name = "") {
1279  if (V->getType() == DestTy)
1280  return V;
1281  if (Constant *VC = dyn_cast<Constant>(V))
1282  return Insert(Folder.CreateTruncOrBitCast(VC, DestTy), Name);
1283  return Insert(CastInst::CreateTruncOrBitCast(V, DestTy), Name);
1284  }
1286  const Twine &Name = "") {
1287  if (V->getType() == DestTy)
1288  return V;
1289  if (Constant *VC = dyn_cast<Constant>(V))
1290  return Insert(Folder.CreateCast(Op, VC, DestTy), Name);
1291  return Insert(CastInst::Create(Op, V, DestTy), Name);
1292  }
1294  const Twine &Name = "") {
1295  if (V->getType() == DestTy)
1296  return V;
1297  if (Constant *VC = dyn_cast<Constant>(V))
1298  return Insert(Folder.CreatePointerCast(VC, DestTy), Name);
1299  return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
1300  }
1301 
1303  const Twine &Name = "") {
1304  if (V->getType() == DestTy)
1305  return V;
1306 
1307  if (Constant *VC = dyn_cast<Constant>(V)) {
1308  return Insert(Folder.CreatePointerBitCastOrAddrSpaceCast(VC, DestTy),
1309  Name);
1310  }
1311 
1313  Name);
1314  }
1315 
1316  Value *CreateIntCast(Value *V, Type *DestTy, bool isSigned,
1317  const Twine &Name = "") {
1318  if (V->getType() == DestTy)
1319  return V;
1320  if (Constant *VC = dyn_cast<Constant>(V))
1321  return Insert(Folder.CreateIntCast(VC, DestTy, isSigned), Name);
1322  return Insert(CastInst::CreateIntegerCast(V, DestTy, isSigned), Name);
1323  }
1324 
1326  const Twine &Name = "") {
1327  if (V->getType() == DestTy)
1328  return V;
1329  if (V->getType()->isPointerTy() && DestTy->isIntegerTy())
1330  return CreatePtrToInt(V, DestTy, Name);
1331  if (V->getType()->isIntegerTy() && DestTy->isPointerTy())
1332  return CreateIntToPtr(V, DestTy, Name);
1333 
1334  return CreateBitCast(V, DestTy, Name);
1335  }
1336 private:
1337  // \brief Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a
1338  // compile time error, instead of converting the string to bool for the
1339  // isSigned parameter.
1340  Value *CreateIntCast(Value *, Type *, const char *) = delete;
1341 public:
1342  Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "") {
1343  if (V->getType() == DestTy)
1344  return V;
1345  if (Constant *VC = dyn_cast<Constant>(V))
1346  return Insert(Folder.CreateFPCast(VC, DestTy), Name);
1347  return Insert(CastInst::CreateFPCast(V, DestTy), Name);
1348  }
1349 
1350  //===--------------------------------------------------------------------===//
1351  // Instruction creation methods: Compare Instructions
1352  //===--------------------------------------------------------------------===//
1353 
1354  Value *CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
1355  return CreateICmp(ICmpInst::ICMP_EQ, LHS, RHS, Name);
1356  }
1357  Value *CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name = "") {
1358  return CreateICmp(ICmpInst::ICMP_NE, LHS, RHS, Name);
1359  }
1360  Value *CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name = "") {
1361  return CreateICmp(ICmpInst::ICMP_UGT, LHS, RHS, Name);
1362  }
1363  Value *CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name = "") {
1364  return CreateICmp(ICmpInst::ICMP_UGE, LHS, RHS, Name);
1365  }
1366  Value *CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name = "") {
1367  return CreateICmp(ICmpInst::ICMP_ULT, LHS, RHS, Name);
1368  }
1369  Value *CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name = "") {
1370  return CreateICmp(ICmpInst::ICMP_ULE, LHS, RHS, Name);
1371  }
1372  Value *CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name = "") {
1373  return CreateICmp(ICmpInst::ICMP_SGT, LHS, RHS, Name);
1374  }
1375  Value *CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name = "") {
1376  return CreateICmp(ICmpInst::ICMP_SGE, LHS, RHS, Name);
1377  }
1378  Value *CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name = "") {
1379  return CreateICmp(ICmpInst::ICMP_SLT, LHS, RHS, Name);
1380  }
1381  Value *CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name = "") {
1382  return CreateICmp(ICmpInst::ICMP_SLE, LHS, RHS, Name);
1383  }
1384 
1385  Value *CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name = "",
1386  MDNode *FPMathTag = nullptr) {
1387  return CreateFCmp(FCmpInst::FCMP_OEQ, LHS, RHS, Name, FPMathTag);
1388  }
1389  Value *CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name = "",
1390  MDNode *FPMathTag = nullptr) {
1391  return CreateFCmp(FCmpInst::FCMP_OGT, LHS, RHS, Name, FPMathTag);
1392  }
1393  Value *CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name = "",
1394  MDNode *FPMathTag = nullptr) {
1395  return CreateFCmp(FCmpInst::FCMP_OGE, LHS, RHS, Name, FPMathTag);
1396  }
1397  Value *CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name = "",
1398  MDNode *FPMathTag = nullptr) {
1399  return CreateFCmp(FCmpInst::FCMP_OLT, LHS, RHS, Name, FPMathTag);
1400  }
1401  Value *CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name = "",
1402  MDNode *FPMathTag = nullptr) {
1403  return CreateFCmp(FCmpInst::FCMP_OLE, LHS, RHS, Name, FPMathTag);
1404  }
1405  Value *CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name = "",
1406  MDNode *FPMathTag = nullptr) {
1407  return CreateFCmp(FCmpInst::FCMP_ONE, LHS, RHS, Name, FPMathTag);
1408  }
1409  Value *CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name = "",
1410  MDNode *FPMathTag = nullptr) {
1411  return CreateFCmp(FCmpInst::FCMP_ORD, LHS, RHS, Name, FPMathTag);
1412  }
1413  Value *CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name = "",
1414  MDNode *FPMathTag = nullptr) {
1415  return CreateFCmp(FCmpInst::FCMP_UNO, LHS, RHS, Name, FPMathTag);
1416  }
1417  Value *CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name = "",
1418  MDNode *FPMathTag = nullptr) {
1419  return CreateFCmp(FCmpInst::FCMP_UEQ, LHS, RHS, Name, FPMathTag);
1420  }
1421  Value *CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name = "",
1422  MDNode *FPMathTag = nullptr) {
1423  return CreateFCmp(FCmpInst::FCMP_UGT, LHS, RHS, Name, FPMathTag);
1424  }
1425  Value *CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name = "",
1426  MDNode *FPMathTag = nullptr) {
1427  return CreateFCmp(FCmpInst::FCMP_UGE, LHS, RHS, Name, FPMathTag);
1428  }
1429  Value *CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name = "",
1430  MDNode *FPMathTag = nullptr) {
1431  return CreateFCmp(FCmpInst::FCMP_ULT, LHS, RHS, Name, FPMathTag);
1432  }
1433  Value *CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name = "",
1434  MDNode *FPMathTag = nullptr) {
1435  return CreateFCmp(FCmpInst::FCMP_ULE, LHS, RHS, Name, FPMathTag);
1436  }
1437  Value *CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name = "",
1438  MDNode *FPMathTag = nullptr) {
1439  return CreateFCmp(FCmpInst::FCMP_UNE, LHS, RHS, Name, FPMathTag);
1440  }
1441 
1443  const Twine &Name = "") {
1444  if (Constant *LC = dyn_cast<Constant>(LHS))
1445  if (Constant *RC = dyn_cast<Constant>(RHS))
1446  return Insert(Folder.CreateICmp(P, LC, RC), Name);
1447  return Insert(new ICmpInst(P, LHS, RHS), Name);
1448  }
1450  const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1451  if (Constant *LC = dyn_cast<Constant>(LHS))
1452  if (Constant *RC = dyn_cast<Constant>(RHS))
1453  return Insert(Folder.CreateFCmp(P, LC, RC), Name);
1454  return Insert(AddFPMathAttributes(new FCmpInst(P, LHS, RHS),
1455  FPMathTag, FMF), Name);
1456  }
1457 
1458  //===--------------------------------------------------------------------===//
1459  // Instruction creation methods: Other Instructions
1460  //===--------------------------------------------------------------------===//
1461 
1462  PHINode *CreatePHI(Type *Ty, unsigned NumReservedValues,
1463  const Twine &Name = "") {
1464  return Insert(PHINode::Create(Ty, NumReservedValues), Name);
1465  }
1466 
1468  const Twine &Name = "") {
1469  return Insert(CallInst::Create(Callee, Args), Name);
1470  }
1471 
1473  ArrayRef<Value *> Args, const Twine &Name = "") {
1474  return Insert(CallInst::Create(FTy, Callee, Args), Name);
1475  }
1476 
1478  const Twine &Name = "") {
1479  return CreateCall(Callee->getFunctionType(), Callee, Args, Name);
1480  }
1481 
1482  Value *CreateSelect(Value *C, Value *True, Value *False,
1483  const Twine &Name = "") {
1484  if (Constant *CC = dyn_cast<Constant>(C))
1485  if (Constant *TC = dyn_cast<Constant>(True))
1486  if (Constant *FC = dyn_cast<Constant>(False))
1487  return Insert(Folder.CreateSelect(CC, TC, FC), Name);
1488  return Insert(SelectInst::Create(C, True, False), Name);
1489  }
1490 
1491  VAArgInst *CreateVAArg(Value *List, Type *Ty, const Twine &Name = "") {
1492  return Insert(new VAArgInst(List, Ty), Name);
1493  }
1494 
1496  const Twine &Name = "") {
1497  if (Constant *VC = dyn_cast<Constant>(Vec))
1498  if (Constant *IC = dyn_cast<Constant>(Idx))
1499  return Insert(Folder.CreateExtractElement(VC, IC), Name);
1500  return Insert(ExtractElementInst::Create(Vec, Idx), Name);
1501  }
1502 
1503  Value *CreateExtractElement(Value *Vec, uint64_t Idx,
1504  const Twine &Name = "") {
1505  return CreateExtractElement(Vec, getInt64(Idx), Name);
1506  }
1507 
1509  const Twine &Name = "") {
1510  if (Constant *VC = dyn_cast<Constant>(Vec))
1511  if (Constant *NC = dyn_cast<Constant>(NewElt))
1512  if (Constant *IC = dyn_cast<Constant>(Idx))
1513  return Insert(Folder.CreateInsertElement(VC, NC, IC), Name);
1514  return Insert(InsertElementInst::Create(Vec, NewElt, Idx), Name);
1515  }
1516 
1517  Value *CreateInsertElement(Value *Vec, Value *NewElt, uint64_t Idx,
1518  const Twine &Name = "") {
1519  return CreateInsertElement(Vec, NewElt, getInt64(Idx), Name);
1520  }
1521 
1523  const Twine &Name = "") {
1524  if (Constant *V1C = dyn_cast<Constant>(V1))
1525  if (Constant *V2C = dyn_cast<Constant>(V2))
1526  if (Constant *MC = dyn_cast<Constant>(Mask))
1527  return Insert(Folder.CreateShuffleVector(V1C, V2C, MC), Name);
1528  return Insert(new ShuffleVectorInst(V1, V2, Mask), Name);
1529  }
1530 
1532  const Twine &Name = "") {
1533  size_t MaskSize = IntMask.size();
1534  SmallVector<Constant*, 8> MaskVec(MaskSize);
1535  for (size_t i = 0; i != MaskSize; ++i)
1536  MaskVec[i] = getInt32(IntMask[i]);
1537  Value *Mask = ConstantVector::get(MaskVec);
1538  return CreateShuffleVector(V1, V2, Mask, Name);
1539  }
1540 
1542  ArrayRef<unsigned> Idxs,
1543  const Twine &Name = "") {
1544  if (Constant *AggC = dyn_cast<Constant>(Agg))
1545  return Insert(Folder.CreateExtractValue(AggC, Idxs), Name);
1546  return Insert(ExtractValueInst::Create(Agg, Idxs), Name);
1547  }
1548 
1550  ArrayRef<unsigned> Idxs,
1551  const Twine &Name = "") {
1552  if (Constant *AggC = dyn_cast<Constant>(Agg))
1553  if (Constant *ValC = dyn_cast<Constant>(Val))
1554  return Insert(Folder.CreateInsertValue(AggC, ValC, Idxs), Name);
1555  return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name);
1556  }
1557 
1558  LandingPadInst *CreateLandingPad(Type *Ty, unsigned NumClauses,
1559  const Twine &Name = "") {
1560  return Insert(LandingPadInst::Create(Ty, NumClauses), Name);
1561  }
1562 
1563  //===--------------------------------------------------------------------===//
1564  // Utility creation methods
1565  //===--------------------------------------------------------------------===//
1566 
1567  /// \brief Return an i1 value testing if \p Arg is null.
1568  Value *CreateIsNull(Value *Arg, const Twine &Name = "") {
1569  return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()),
1570  Name);
1571  }
1572 
1573  /// \brief Return an i1 value testing if \p Arg is not null.
1574  Value *CreateIsNotNull(Value *Arg, const Twine &Name = "") {
1575  return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()),
1576  Name);
1577  }
1578 
1579  /// \brief Return the i64 difference between two pointer values, dividing out
1580  /// the size of the pointed-to objects.
1581  ///
1582  /// This is intended to implement C-style pointer subtraction. As such, the
1583  /// pointers must be appropriately aligned for their element types and
1584  /// pointing into the same object.
1585  Value *CreatePtrDiff(Value *LHS, Value *RHS, const Twine &Name = "") {
1586  assert(LHS->getType() == RHS->getType() &&
1587  "Pointer subtraction operand types must match!");
1588  PointerType *ArgType = cast<PointerType>(LHS->getType());
1589  Value *LHS_int = CreatePtrToInt(LHS, Type::getInt64Ty(Context));
1590  Value *RHS_int = CreatePtrToInt(RHS, Type::getInt64Ty(Context));
1591  Value *Difference = CreateSub(LHS_int, RHS_int);
1592  return CreateExactSDiv(Difference,
1593  ConstantExpr::getSizeOf(ArgType->getElementType()),
1594  Name);
1595  }
1596 
1597  /// \brief Return a vector value that contains \arg V broadcasted to \p
1598  /// NumElts elements.
1599  Value *CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name = "") {
1600  assert(NumElts > 0 && "Cannot splat to an empty vector!");
1601 
1602  // First insert it into an undef vector so we can shuffle it.
1603  Type *I32Ty = getInt32Ty();
1604  Value *Undef = UndefValue::get(VectorType::get(V->getType(), NumElts));
1605  V = CreateInsertElement(Undef, V, ConstantInt::get(I32Ty, 0),
1606  Name + ".splatinsert");
1607 
1608  // Shuffle the value across the desired number of elements.
1609  Value *Zeros = ConstantAggregateZero::get(VectorType::get(I32Ty, NumElts));
1610  return CreateShuffleVector(V, Undef, Zeros, Name + ".splat");
1611  }
1612 
1613  /// \brief Return a value that has been extracted from a larger integer type.
1615  IntegerType *ExtractedTy, uint64_t Offset,
1616  const Twine &Name) {
1617  IntegerType *IntTy = cast<IntegerType>(From->getType());
1618  assert(DL.getTypeStoreSize(ExtractedTy) + Offset <=
1619  DL.getTypeStoreSize(IntTy) &&
1620  "Element extends past full value");
1621  uint64_t ShAmt = 8 * Offset;
1622  Value *V = From;
1623  if (DL.isBigEndian())
1624  ShAmt = 8 * (DL.getTypeStoreSize(IntTy) -
1625  DL.getTypeStoreSize(ExtractedTy) - Offset);
1626  if (ShAmt) {
1627  V = CreateLShr(V, ShAmt, Name + ".shift");
1628  }
1629  assert(ExtractedTy->getBitWidth() <= IntTy->getBitWidth() &&
1630  "Cannot extract to a larger integer!");
1631  if (ExtractedTy != IntTy) {
1632  V = CreateTrunc(V, ExtractedTy, Name + ".trunc");
1633  }
1634  return V;
1635  }
1636 
1637  /// \brief Create an assume intrinsic call that represents an alignment
1638  /// assumption on the provided pointer.
1639  ///
1640  /// An optional offset can be provided, and if it is provided, the offset
1641  /// must be subtracted from the provided pointer to get the pointer with the
1642  /// specified alignment.
1644  unsigned Alignment,
1645  Value *OffsetValue = nullptr) {
1646  assert(isa<PointerType>(PtrValue->getType()) &&
1647  "trying to create an alignment assumption on a non-pointer?");
1648 
1649  PointerType *PtrTy = cast<PointerType>(PtrValue->getType());
1650  Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
1651  Value *PtrIntValue = CreatePtrToInt(PtrValue, IntPtrTy, "ptrint");
1652 
1653  Value *Mask = ConstantInt::get(IntPtrTy,
1654  Alignment > 0 ? Alignment - 1 : 0);
1655  if (OffsetValue) {
1656  bool IsOffsetZero = false;
1657  if (ConstantInt *CI = dyn_cast<ConstantInt>(OffsetValue))
1658  IsOffsetZero = CI->isZero();
1659 
1660  if (!IsOffsetZero) {
1661  if (OffsetValue->getType() != IntPtrTy)
1662  OffsetValue = CreateIntCast(OffsetValue, IntPtrTy, /*isSigned*/ true,
1663  "offsetcast");
1664  PtrIntValue = CreateSub(PtrIntValue, OffsetValue, "offsetptr");
1665  }
1666  }
1667 
1668  Value *Zero = ConstantInt::get(IntPtrTy, 0);
1669  Value *MaskedPtr = CreateAnd(PtrIntValue, Mask, "maskedptr");
1670  Value *InvCond = CreateICmpEQ(MaskedPtr, Zero, "maskcond");
1671 
1672  return CreateAssumption(InvCond);
1673  }
1674 };
1675 
1676 // Create wrappers for C Binding types (see CBindingWrapping.h).
1678 
1679 }
1680 
1681 #endif
IntegerType * getInt16Ty()
Fetch the type representing a 16-bit integer.
Definition: IRBuilder.h:301
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:842
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:52
Value * CreateGEP(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
Definition: IRBuilder.h:1032
Value * CreateNUWNeg(Value *V, const Twine &Name="")
Definition: IRBuilder.h:947
ReturnInst - Return a value (possibly void), from a function.
LoadInst * CreateLoad(Value *Ptr, const Twine &Name="")
Definition: IRBuilder.h:976
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:104
static ConstantInt * getFalse(LLVMContext &Context)
Definition: Constants.cpp:537
IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:529
AllocaInst * CreateAlloca(Type *Ty, Value *ArraySize=nullptr, const Twine &Name="")
Definition: IRBuilder.h:967
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1285
static Type * getDoubleTy(LLVMContext &C)
Definition: Type.cpp:229
static IntegerType * getInt1Ty(LLVMContext &C)
Definition: Type.cpp:236
Value * CreateSIToFP(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1235
BasicBlock::iterator GetInsertPoint() const
Definition: IRBuilder.h:80
LoadInst * CreateLoad(Value *Ptr, const char *Name)
Definition: IRBuilder.h:973
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const Twine &Name="")
Definition: IRBuilder.h:979
static BinaryOperator * CreateNot(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
Value * CreateInsertElement(Value *Vec, Value *NewElt, uint64_t Idx, const Twine &Name="")
Definition: IRBuilder.h:1517
IRBuilder(LLVMContext &C, MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:525
Value * CreateExtractElement(Value *Vec, uint64_t Idx, const Twine &Name="")
Definition: IRBuilder.h:1503
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1442
CallInst * CreateCall(Function *Callee, ArrayRef< Value * > Args, const Twine &Name="")
Definition: IRBuilder.h:1477
Value * CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1417
Value * CreateSExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a SExt or Trunc from the integer value V to DestTy.
Definition: IRBuilder.h:1214
Value * CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1381
Value * CreateExtractInteger(const DataLayout &DL, Value *From, IntegerType *ExtractedTy, uint64_t Offset, const Twine &Name)
Return a value that has been extracted from a larger integer type.
Definition: IRBuilder.h:1614
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Definition: IRBuilder.h:1316
VAArgInst * CreateVAArg(Value *List, Type *Ty, const Twine &Name="")
Definition: IRBuilder.h:1491
static ResumeInst * Create(Value *Exn, Instruction *InsertBefore=nullptr)
FenceInst - an instruction for ordering other memory operations.
Definition: Instructions.h:445
Value * CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:734
Value * CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1378
AtomicCmpXchgInst - an instruction that atomically checks whether a specified value is in a memory lo...
Definition: Instructions.h:515
Value * CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1429
FastMathFlags FMF
Definition: IRBuilder.h:60
Value * CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1397
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:608
static ConstantAggregateZero * get(Type *Ty)
Definition: Constants.cpp:1377
IRBuilder(Instruction *IP, MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:539
CallInst * CreateGCRelocate(Instruction *Statepoint, int BaseOffset, int DerivedOffset, Type *ResultType, const Twine &Name="")
Create a call to the experimental.gc.relocate intrinsics to project the relocated value of one pointe...
Definition: IRBuilder.cpp:346
Type * getValueType() const
Definition: GlobalValue.h:187
CallInst - This class represents a function call, abstracting a target machine's calling convention...
Value * CreateSRem(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:808
void SetInsertPoint(BasicBlock *TheBB, BasicBlock::iterator IP)
This specifies that created instructions should be inserted at the specified point.
Definition: IRBuilder.h:101
SwitchInst * CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases=10, MDNode *BranchWeights=nullptr)
Create a switch instruction with the specified value, default dest, and with a hint for the number of...
Definition: IRBuilder.h:631
Value * CreatePointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1293
AtomicCmpXchgInst * CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, SynchronizationScope SynchScope=CrossThread)
Definition: IRBuilder.h:1020
unsigned less or equal
Definition: InstrTypes.h:723
unsigned less than
Definition: InstrTypes.h:722
Value * CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:791
0 1 0 0 True if ordered and less than
Definition: InstrTypes.h:703
InvokeInst * CreateGCStatepointInvoke(uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > InvokeArgs, ArrayRef< Value * > DeoptArgs, ArrayRef< Value * > GCArgs, const Twine &Name="")
brief Create an invoke to the experimental.gc.statepoint intrinsic to start a new statepoint sequence...
Definition: IRBuilder.cpp:301
ShuffleVectorInst - This instruction constructs a fixed permutation of two input vectors.
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1366
1 1 1 0 True if unordered or not equal
Definition: InstrTypes.h:713
Value * CreateFPCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1342
Value * CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:759
A debug info location.
Definition: DebugLoc.h:34
Metadata node.
Definition: Metadata.h:740
F(f)
CallInst * CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, unsigned Align, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert a memset to the specified pointer and the specified value.
Definition: IRBuilder.h:365
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:472
LoadInst - an instruction for reading from memory.
Definition: Instructions.h:177
Value * CreateGEP(Value *Ptr, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:1067
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
Definition: DerivedTypes.h:61
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:240
AtomicRMWInst - an instruction that atomically reads a memory location, combines it with another valu...
Definition: Instructions.h:674
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1354
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=nullptr)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
Definition: IRBuilder.h:622
static IntegerType * getInt16Ty(LLVMContext &C)
Definition: Type.cpp:238
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
Definition: IRBuilder.h:1522
Value * CreateOr(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition: IRBuilder.h:903
LoadInst * CreateAlignedLoad(Value *Ptr, unsigned Align, bool isVolatile, const Twine &Name="")
Definition: IRBuilder.h:1002
Value * CreateInBoundsGEP(Type *Ty, Value *Ptr, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:1076
static LandingPadInst * Create(Type *RetTy, unsigned NumReservedClauses, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedClauses is a hint for the number of incoming clauses that this landingpad w...
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:726
InstTy * Insert(InstTy *I, const Twine &Name="") const
Insert and return the specified instruction.
Definition: IRBuilder.h:565
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:923
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:1508
static Constant * getNullValue(Type *Ty)
Definition: Constants.cpp:178
Value * CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:712
LLVMContext & Context
Definition: IRBuilder.h:57
Value * CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1369
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Definition: IRBuilder.h:306
Value * CreateGEP(Type *Ty, Value *Ptr, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:1070
1 0 0 1 True if unordered or equal
Definition: InstrTypes.h:708
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition: IRBuilder.h:1541
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
Definition: IRBuilder.h:1462
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:910
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition: InstrTypes.h:707
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
Definition: IRBuilder.h:311
static Type * getFloatTy(LLVMContext &C)
Definition: Type.cpp:228
Value * CreateAShr(Value *LHS, uint64_t RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:873
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1249
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
llvm::BasicBlock * getBlock() const
Definition: IRBuilder.h:141
static Constant * get(ArrayRef< Constant * > V)
Definition: Constants.cpp:1057
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:517
IntegerType * getIntPtrTy(const DataLayout &DL, unsigned AddrSpace=0)
Fetch the type representing a pointer to an integer value.
Definition: IRBuilder.h:351
0 1 0 1 True if ordered and less than or equal
Definition: InstrTypes.h:704
Value * CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition: IRBuilder.h:1128
SynchronizationScope
Definition: Instructions.h:49
Value * CreateConstInBoundsGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0, const Twine &Name="")
Definition: IRBuilder.h:1095
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:250
Value * CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:756
Value * CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1372
ConstantInt * getInt16(uint16_t C)
Get a constant 16-bit value.
Definition: IRBuilder.h:261
Type * getVoidTy()
Fetch the type representing void.
Definition: IRBuilder.h:341
BasicBlock * BB
Definition: IRBuilder.h:55
AtomicOrdering
Definition: Instructions.h:38
static Constant * getSizeOf(Type *Ty)
getSizeOf constant expr - computes the (alloc) size of a type (in address-units, not bits) in a targe...
Definition: Constants.cpp:1948
FunctionType - Class to represent function types.
Definition: DerivedTypes.h:96
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1449
static GetElementPtrInst * CreateInBounds(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Create an "inbounds" getelementptr.
Definition: Instructions.h:887
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:878
InvokeInst * CreateInvoke3(Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, Value *Arg1, Value *Arg2, Value *Arg3, const Twine &Name="")
Definition: IRBuilder.h:655
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:894
void SetFastMathFlags(FastMathFlags NewFMF)
Set the fast-math flags to be used with generated fp-math operators.
Definition: IRBuilder.h:178
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:686
InsertPoint saveIP() const
Returns the current insert point.
Definition: IRBuilder.h:146
UnreachableInst * CreateUnreachable()
Definition: IRBuilder.h:675
void ClearInsertionPoint()
Clear the insertion point: created instructions will not be inserted into a block.
Definition: IRBuilder.h:74
This instruction compares its operands according to the predicate given to the constructor.
CallInst * CreateMemMove(Value *Dst, Value *Src, uint64_t Size, unsigned Align, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert a memmove between the specified pointers.
Definition: IRBuilder.h:404
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:31
StoreInst - an instruction for storing to memory.
Definition: Instructions.h:316
void SetCurrentDebugLocation(DebugLoc L)
Set location information used by debugging information.
Definition: IRBuilder.h:109
Value * CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1393
MDNode * getDefaultFPMathTag() const
Get the floating point math metadata being used.
Definition: IRBuilder.h:166
Value * CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name="")
Definition: IRBuilder.h:1083
Value * CreateAShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:860
Value * CreateShl(Value *LHS, const APInt &RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:831
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition: IRBuilder.h:985
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:134
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
Definition: IRBuilder.h:85
ConstantInt * getIntN(unsigned N, uint64_t C)
Get a constant N-bit value, zero extended or truncated from a 64-bit value.
Definition: IRBuilder.h:277
PointerType - Class to represent pointers.
Definition: DerivedTypes.h:449
Value * CreateNSWNeg(Value *V, const Twine &Name="")
Definition: IRBuilder.h:944
Type * getHalfTy()
Fetch the type representing a 16-bit floating point value.
Definition: IRBuilder.h:326
LoadInst * CreateLoad(Value *Ptr, bool isVolatile, const Twine &Name="")
Definition: IRBuilder.h:982
Value * CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:851
InsertPoint saveAndClearIP()
Returns the current insert point, clearing it in the process.
Definition: IRBuilder.h:151
Type * getDoubleTy()
Fetch the type representing a 64-bit floating point value.
Definition: IRBuilder.h:336
Value * CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:737
#define P(N)
Value * CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1302
bool isIntOrIntVectorTy() const
isIntOrIntVectorTy - Return true if this is an integer type or a vector of integer types...
Definition: Type.h:201
void restoreIP(InsertPoint IP)
Sets the current insert point to a previously-saved location.
Definition: IRBuilder.h:158
static IntegerType * getInt128Ty(LLVMContext &C)
Definition: Type.cpp:241
LandingPadInst - The landingpad instruction holds all of the information necessary to generate correc...
IntegerType * getInt128Ty()
Fetch the type representing a 128-bit integer.
Definition: IRBuilder.h:316
void setDebugLoc(DebugLoc Loc)
setDebugLoc - Set the debug location information for this instruction.
Definition: Instruction.h:227
InvokeInst * CreateInvoke(Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, Value *Arg1, const Twine &Name="")
Definition: IRBuilder.h:649
Value * CreateConstInBoundsGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition: IRBuilder.h:1136
Value * CreateShl(Value *LHS, uint64_t RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:836
Value * CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1375
Value * CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition: IRBuilder.h:1145
InsertPoint(BasicBlock *InsertBlock, BasicBlock::iterator InsertPoint)
Creates a new insertion point at the given location.
Definition: IRBuilder.h:135
LLVM Basic Block Representation.
Definition: BasicBlock.h:65
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
Value * CreateFRem(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:814
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:41
ConstantInt * getTrue()
Get the constant value for i1 true.
Definition: IRBuilder.h:246
BranchInst - Conditional or Unconditional Branch instruction.
static ExtractValueInst * Create(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Value * CreateNot(Value *V, const Twine &Name="")
Definition: IRBuilder.h:957
Value * CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1401
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:704
UnreachableInst - This function has undefined behavior.
ConstantInt * getInt1(bool V)
Get a constant value representing either true or false.
Definition: IRBuilder.h:241
Type * getCurrentFunctionReturnType() const
Get the return type of the current function that we're emitting into.
Definition: IRBuilder.cpp:41
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1245
This is an important base class in LLVM.
Definition: Constant.h:41
Value * CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:869
Value * CreateFPToSI(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1229
ResumeInst - Resume the propagation of an exception.
IndirectBrInst - Indirect Branch Instruction.
ReturnInst * CreateRet(Value *V)
Create a 'ret <val>' instruction.
Definition: IRBuilder.h:597
CallInst * CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue, unsigned Alignment, Value *OffsetValue=nullptr)
Create an assume intrinsic call that represents an alignment assumption on the provided pointer...
Definition: IRBuilder.h:1643
LoadInst * CreateAlignedLoad(Value *Ptr, unsigned Align, const Twine &Name="")
Definition: IRBuilder.h:996
CallInst * CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, ArrayRef< Value * > CallArgs, ArrayRef< Value * > DeoptArgs, ArrayRef< Value * > GCArgs, const Twine &Name="")
Create a call to the experimental.gc.statepoint intrinsic to start a new statepoint sequence...
Definition: IRBuilder.cpp:269
Value * CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1409
const DebugLoc & getDebugLoc() const
getDebugLoc - Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:230
Value * CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1425
Value * CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="")
Definition: IRBuilder.h:1104
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:225
Value * CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1421
Value * CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="")
Definition: IRBuilder.h:1116
const InstListType & getInstList() const
Return the underlying instruction list container.
Definition: BasicBlock.h:252
This instruction compares its operands according to the predicate given to the constructor.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:697
iterator insert(iterator where, NodeTy *New)
Definition: ilist.h:412
Value * CreateGlobalStringPtr(StringRef Str, const Twine &Name="", unsigned AddressSpace=0)
Same as CreateGlobalString, but return a pointer with "i8*" type instead of a pointer to array of i8...
Definition: IRBuilder.h:1177
A specialization of it's base class for read-write access to a gc.statepoint.
Definition: Statepoint.h:296
0 1 1 1 True if ordered (no nans)
Definition: InstrTypes.h:706
static CastInst * CreatePointerBitCastOrAddrSpaceCast(Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
Create a BitCast or an AddrSpaceCast cast instruction.
void clearFastMathFlags()
Clear the fast-math flags.
Definition: IRBuilder.h:172
Value * CreateUIToFP(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1232
Class to represent integer types.
Definition: DerivedTypes.h:37
Value * CreateOr(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition: IRBuilder.h:906
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
Definition: IRBuilder.h:271
static CastInst * CreatePointerCast(Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
Create a BitCast AddrSpaceCast, or a PtrToInt cast instruction.
IntegerType * getIntNTy(unsigned N)
Fetch the type representing an N-bit integer.
Definition: IRBuilder.h:321
Value * CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition: IRBuilder.h:890
void setAlignment(unsigned Align)
NUW NUW NUW NUW Exact static Exact BinaryOperator * CreateNeg(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
Helper functions to construct and inspect unary operations (NEG and NOT) via binary operators SUB and...
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:550
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:1585
bool isPointerTy() const
isPointerTy - True if this is an instance of PointerType.
Definition: Type.h:217
Value * CreateInBoundsGEP(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
Definition: IRBuilder.h:1049
static UndefValue * get(Type *T)
get() - Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1473
VAArgInst - This class represents the va_arg llvm instruction, which returns an argument of the speci...
void SetInsertPoint(Instruction *I)
This specifies that created instructions should be inserted before the specified instruction.
Definition: IRBuilder.h:92
LLVMContext & getContext() const
Definition: IRBuilder.h:81
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:640
CallInst * CreateCall(Value *Callee, ArrayRef< Value * > Args=None, const Twine &Name="")
Definition: IRBuilder.h:1467
static CastInst * CreateZExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a ZExt or BitCast cast instruction.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:283
PointerType * getInt8PtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer to an 8-bit integer value.
Definition: IRBuilder.h:346
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, unsigned Align, bool isVolatile=false)
Definition: IRBuilder.h:1008
LoadInst * CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name)
Definition: IRBuilder.h:991
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:854
1 1 0 1 True if unordered, less than, or equal
Definition: InstrTypes.h:712
static IndirectBrInst * Create(Value *Address, unsigned NumDests, Instruction *InsertBefore=nullptr)
signed greater than
Definition: InstrTypes.h:724
Value * CreateFPToUI(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1226
Value * CreateXor(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition: IRBuilder.h:916
Value * CreateGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
Definition: IRBuilder.h:1036
Value * CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1405
This provides the default implementation of the IRBuilder 'InsertHelper' method that is called whenev...
Definition: IRBuilder.h:41
Value * CreateFDiv(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:794
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
Definition: DataLayout.cpp:694
0 0 1 0 True if ordered and greater than
Definition: InstrTypes.h:701
bool isNamePreserving() const
Return true if this builder is configured to actually add the requested names to IR created through i...
Definition: IRBuilder.h:561
CallInst * CreateLifetimeEnd(Value *Ptr, ConstantInt *Size=nullptr)
Create a lifetime.end intrinsic.
Definition: IRBuilder.cpp:179
static BinaryOperator * CreateFNeg(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
static Type * getHalfTy(LLVMContext &C)
Definition: Type.cpp:227
static InvokeInst * Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static CastInst * CreateIntegerCast(Value *S, Type *Ty, bool isSigned, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a ZExt, BitCast, or Trunc for int -> int casts.
Value * CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:715
This is the shared class of boolean and integer constants.
Definition: Constants.h:47
InsertPoint - A saved insertion point.
Definition: IRBuilder.h:126
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:1495
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1192
GlobalVariable * CreateGlobalString(StringRef Str, const Twine &Name="", unsigned AddressSpace=0)
Make a new global variable with initializer type i8*.
Definition: IRBuilder.cpp:27
CallInst * CreateAssumption(Value *Cond)
Create an assume intrinsic call that allows the optimizer to assume that the provided condition will ...
Definition: IRBuilder.cpp:194
iterator end()
Definition: BasicBlock.h:233
static SwitchInst * Create(Value *Value, BasicBlock *Default, unsigned NumCases, Instruction *InsertBefore=nullptr)
unsigned getScalarSizeInBits() const LLVM_READONLY
getScalarSizeInBits - If this is a vector type, return the getPrimitiveSizeInBits value for the eleme...
Definition: Type.cpp:139
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1253
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
1 1 0 0 True if unordered or less than
Definition: InstrTypes.h:711
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:222
AddressSpace
Definition: NVPTXBaseInfo.h:22
signed less than
Definition: InstrTypes.h:726
CallInst * CreateMaskedLoad(Value *Ptr, unsigned Align, Value *Mask, Value *PassThru=0, const Twine &Name="")
Create a call to Masked Load intrinsic.
Definition: IRBuilder.cpp:212
Value * CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1363
CallInst * CreateMaskedStore(Value *Val, Value *Ptr, unsigned Align, Value *Mask)
Create a call to Masked Store intrinsic.
Definition: IRBuilder.cpp:231
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition: IRBuilder.h:266
static CastInst * CreateFPCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create an FPExt, BitCast, or FPTrunc for fp -> fp casts.
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition: Type.cpp:243
BasicBlock * GetInsertBlock() const
Definition: IRBuilder.h:79
Value * CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0, const Twine &Name="")
Definition: IRBuilder.h:1086
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:748
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:582
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
#define NC
Definition: regutils.h:42
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(NoStrictAlign), cl::values(clEnumValN(StrictAlign,"aarch64-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"aarch64-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:530
Value handle that asserts if the Value is deleted.
Definition: ValueHandle.h:187
Value * CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1261
signed less or equal
Definition: InstrTypes.h:727
Value * CreateURem(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:802
Class for arbitrary precision integers.
Definition: APInt.h:73
Value * CreateSDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:782
bool isIntegerTy() const
isIntegerTy - True if this is an instance of IntegerType.
Definition: Type.h:193
Value * CreateUDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:770
const DebugLoc & getCurrentDebugLocation() const
Get location information used by debugging information.
Definition: IRBuilder.h:112
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), Instruction *InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="")
Definition: IRBuilder.h:1482
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Definition: IRBuilder.h:296
Value * CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx, const Twine &Name="")
Definition: IRBuilder.h:1170
Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
Definition: IRBuilder.h:1599
Value * CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1277
void InsertHelper(Instruction *I, const Twine &Name, BasicBlock *BB, BasicBlock::iterator InsertPt) const
Definition: IRBuilder.h:43
Value * CreateFAdd(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:718
void clear()
Set all the flags to false.
Definition: Operator.h:186
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition: IRBuilder.h:1549
Value * CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1433
ConstantInt * getFalse()
Get the constant value for i1 false.
Definition: IRBuilder.h:251
MDNode * DefaultFPMathTag
Definition: IRBuilder.h:59
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
Definition: IRBuilder.h:291
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:823
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return an i1 value testing if Arg is not null.
Definition: IRBuilder.h:1574
Value * CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition: IRBuilder.h:1157
IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:534
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
Constant * Insert(Constant *C, const Twine &="") const
No-op overload to handle constants.
Definition: IRBuilder.h:572
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
Definition: IRBuilder.h:1200
Value * CreateInBoundsGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
Definition: IRBuilder.h:1053
Value * CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition: IRBuilder.h:887
Value * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1257
CallInst * CreateMemCpy(Value *Dst, Value *Src, uint64_t Size, unsigned Align, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert a memcpy between the specified pointers.
Definition: IRBuilder.h:383
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:239
CallInst * CreateCall(llvm::FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args, const Twine &Name="")
Definition: IRBuilder.h:1472
static CastInst * CreateTruncOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a Trunc or BitCast cast instruction.
AtomicRMWInst * CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val, AtomicOrdering Ordering, SynchronizationScope SynchScope=CrossThread)
Definition: IRBuilder.h:1027
unsigned greater or equal
Definition: InstrTypes.h:721
Value * CreateShuffleVector(Value *V1, Value *V2, ArrayRef< int > IntMask, const Twine &Name="")
Definition: IRBuilder.h:1531
Value * CreateSExt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1195
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T &F, MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:544
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
IRBuilderBase(LLVMContext &context, MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:63
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
CallInst * CreateGCResult(Instruction *Statepoint, Type *ResultType, const Twine &Name="")
Create a call to the experimental.gc.result intrinsic to extract the result from a call wrapped in a ...
Definition: IRBuilder.cpp:334
FunctionType * getFunctionType() const
Definition: Function.cpp:227
Value * CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1389
0 1 1 0 True if ordered and operands are unequal
Definition: InstrTypes.h:705
const T & getFolder()
Get the constant folder being used.
Definition: IRBuilder.h:557
FenceInst * CreateFence(AtomicOrdering Ordering, SynchronizationScope SynchScope=CrossThread, const Twine &Name="")
Definition: IRBuilder.h:1014
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1357
Value * CreateXor(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition: IRBuilder.h:919
Type * getFloatTy()
Fetch the type representing a 32-bit floating point value.
Definition: IRBuilder.h:331
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
Definition: DataLayout.h:371
Value * CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:779
1 0 1 0 True if unordered or greater than
Definition: InstrTypes.h:709
InvokeInst * CreateInvoke(Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args, const Twine &Name="")
Create an invoke instruction.
Definition: IRBuilder.h:664
SwitchInst - Multiway switch.
Value * CreateFMul(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:762
static CastInst * CreateSExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a SExt or BitCast cast instruction.
IRBuilder(LLVMContext &C, const T &F, const Inserter &I=Inserter(), MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:520
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:935
Value * CreateIsNull(Value *Arg, const Twine &Name="")
Return an i1 value testing if Arg is null.
Definition: IRBuilder.h:1568
llvm::BasicBlock::iterator getPoint() const
Definition: IRBuilder.h:142
0 0 0 1 True if ordered and equal
Definition: InstrTypes.h:700
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1189
LLVM Value Representation.
Definition: Value.h:69
void setAlignment(unsigned Align)
1 0 1 1 True if unordered, greater than, or equal
Definition: InstrTypes.h:710
Value * CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1385
static VectorType * get(Type *ElementType, unsigned NumElements)
VectorType::get - This static method is the primary way to construct an VectorType.
Definition: Type.cpp:713
ReturnInst * CreateRetVoid()
Create a 'ret void' instruction.
Definition: IRBuilder.h:592
FastMathFlags getFastMathFlags() const
Get the flags to be applied to created floating point ops.
Definition: IRBuilder.h:169
bool isSet() const
Returns true if this insert point is set.
Definition: IRBuilder.h:139
BranchInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
Definition: IRBuilder.h:616
InvokeInst - Invoke instruction.
InsertPoint()
Creates a new insertion point which doesn't point to anything.
Definition: IRBuilder.h:132
ConstantInt * getInt8(uint8_t C)
Get a constant 8-bit value.
Definition: IRBuilder.h:256
CallInst * CreateLifetimeStart(Value *Ptr, ConstantInt *Size=nullptr)
Create a lifetime.start intrinsic.
Definition: IRBuilder.cpp:164
struct LLVMOpaqueBuilder * LLVMBuilderRef
Represents an LLVM basic block builder.
Definition: Core.h:106
Convenience struct for specifying and reasoning about fast-math flags.
Definition: Operator.h:164
unsigned greater than
Definition: InstrTypes.h:720
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
Value * CreateBitOrPointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1325
static bool isVolatile(Instruction *Inst)
InvokeInst * CreateInvoke(Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, const Twine &Name="")
Definition: IRBuilder.h:644
Value * CreateFPExt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1242
Value * CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1413
static ExtractElementInst * Create(Value *Vec, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
ConstantInt * getInt(const APInt &AI)
Get a constant integer value.
Definition: IRBuilder.h:282
Value * CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1437
Value * CreateFPTrunc(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1238
LandingPadInst * CreateLandingPad(Type *Ty, unsigned NumClauses, const Twine &Name="")
Definition: IRBuilder.h:1558
0 0 1 1 True if ordered and greater than or equal
Definition: InstrTypes.h:702
bool isBigEndian() const
Definition: DataLayout.h:218
Value * CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1360
Value * CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:855
Value * CreateFNeg(Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:950
ResumeInst * CreateResume(Value *Exn)
Definition: IRBuilder.h:671
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:237
BasicBlock::iterator InsertPt
Definition: IRBuilder.h:56
const BasicBlock * getParent() const
Definition: Instruction.h:72
Value * CreateFSub(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:740
signed greater or equal
Definition: InstrTypes.h:725
Value * CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1269
AllocaInst - an instruction to allocate memory on the stack.
Definition: Instructions.h:76
void SetInstDebugLocation(Instruction *I) const
If this builder has a current debug location, set it on the specified instruction.
Definition: IRBuilder.h:116
void SetDefaultFPMathTag(MDNode *FPMathTag)
Set the floating point math metadata to be used.
Definition: IRBuilder.h:175