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