LLVM  8.0.0svn
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-c/Types.h"
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/None.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/ADT/Twine.h"
23 #include "llvm/IR/BasicBlock.h"
24 #include "llvm/IR/Constant.h"
25 #include "llvm/IR/ConstantFolder.h"
26 #include "llvm/IR/Constants.h"
27 #include "llvm/IR/DataLayout.h"
28 #include "llvm/IR/DebugLoc.h"
29 #include "llvm/IR/DerivedTypes.h"
30 #include "llvm/IR/Function.h"
31 #include "llvm/IR/GlobalVariable.h"
32 #include "llvm/IR/InstrTypes.h"
33 #include "llvm/IR/Instruction.h"
34 #include "llvm/IR/Instructions.h"
35 #include "llvm/IR/Intrinsics.h"
36 #include "llvm/IR/LLVMContext.h"
37 #include "llvm/IR/Module.h"
38 #include "llvm/IR/Operator.h"
39 #include "llvm/IR/Type.h"
40 #include "llvm/IR/Value.h"
41 #include "llvm/IR/ValueHandle.h"
44 #include "llvm/Support/Casting.h"
45 #include <cassert>
46 #include <cstddef>
47 #include <cstdint>
48 #include <functional>
49 #include <utility>
50 
51 namespace llvm {
52 
53 class APInt;
54 class MDNode;
55 class Use;
56 
57 /// 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(std::move(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 /// 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) {
107  ClearInsertionPoint();
108  }
109 
110  //===--------------------------------------------------------------------===//
111  // Builder configuration methods
112  //===--------------------------------------------------------------------===//
113 
114  /// Clear the insertion point: created instructions will not be
115  /// inserted into a block.
117  BB = nullptr;
118  InsertPt = BasicBlock::iterator();
119  }
120 
121  BasicBlock *GetInsertBlock() const { return BB; }
122  BasicBlock::iterator GetInsertPoint() const { return InsertPt; }
123  LLVMContext &getContext() const { return Context; }
124 
125  /// 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  /// 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()");
138  SetCurrentDebugLocation(I->getDebugLoc());
139  }
140 
141  /// 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  /// Set location information used by debugging information.
151  void SetCurrentDebugLocation(DebugLoc L) { CurDbgLocation = std::move(L); }
152 
153  /// Get location information used by debugging information.
154  const DebugLoc &getCurrentDebugLocation() const { return CurDbgLocation; }
155 
156  /// 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  /// Get the return type of the current function that we're emitting
164  /// into.
165  Type *getCurrentFunctionReturnType() const;
166 
167  /// InsertPoint - A saved insertion point.
168  class InsertPoint {
169  BasicBlock *Block = nullptr;
170  BasicBlock::iterator Point;
171 
172  public:
173  /// Creates a new insertion point which doesn't point to anything.
174  InsertPoint() = default;
175 
176  /// Creates a new insertion point at the given location.
178  : Block(InsertBlock), Point(InsertPoint) {}
179 
180  /// 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  /// Returns the current insert point.
188  InsertPoint saveIP() const {
189  return InsertPoint(GetInsertBlock(), GetInsertPoint());
190  }
191 
192  /// Returns the current insert point, clearing it in the process.
194  InsertPoint IP(GetInsertBlock(), GetInsertPoint());
195  ClearInsertionPoint();
196  return IP;
197  }
198 
199  /// Sets the current insert point to a previously-saved location.
201  if (IP.isSet())
202  SetInsertPoint(IP.getBlock(), IP.getPoint());
203  else
204  ClearInsertionPoint();
205  }
206 
207  /// Get the floating point math metadata being used.
208  MDNode *getDefaultFPMathTag() const { return DefaultFPMathTag; }
209 
210  /// Get the flags to be applied to created floating point ops
211  FastMathFlags getFastMathFlags() const { return FMF; }
212 
213  /// Clear the fast-math flags.
214  void clearFastMathFlags() { FMF.clear(); }
215 
216  /// Set the floating point math metadata to be used.
217  void setDefaultFPMathTag(MDNode *FPMathTag) { DefaultFPMathTag = FPMathTag; }
218 
219  /// 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  // 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  // 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  /// 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.
278  GlobalVariable *CreateGlobalString(StringRef Str, const Twine &Name = "",
279  unsigned AddressSpace = 0);
280 
281  /// Get a constant value representing either true or false.
282  ConstantInt *getInt1(bool V) {
283  return ConstantInt::get(getInt1Ty(), V);
284  }
285 
286  /// Get the constant value for i1 true.
288  return ConstantInt::getTrue(Context);
289  }
290 
291  /// Get the constant value for i1 false.
293  return ConstantInt::getFalse(Context);
294  }
295 
296  /// Get a constant 8-bit value.
297  ConstantInt *getInt8(uint8_t C) {
298  return ConstantInt::get(getInt8Ty(), C);
299  }
300 
301  /// Get a constant 16-bit value.
302  ConstantInt *getInt16(uint16_t C) {
303  return ConstantInt::get(getInt16Ty(), C);
304  }
305 
306  /// Get a constant 32-bit value.
308  return ConstantInt::get(getInt32Ty(), C);
309  }
310 
311  /// Get a constant 64-bit value.
312  ConstantInt *getInt64(uint64_t C) {
313  return ConstantInt::get(getInt64Ty(), C);
314  }
315 
316  /// 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  /// 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  /// Fetch the type representing a single bit
333  return Type::getInt1Ty(Context);
334  }
335 
336  /// Fetch the type representing an 8-bit integer.
338  return Type::getInt8Ty(Context);
339  }
340 
341  /// Fetch the type representing a 16-bit integer.
343  return Type::getInt16Ty(Context);
344  }
345 
346  /// Fetch the type representing a 32-bit integer.
348  return Type::getInt32Ty(Context);
349  }
350 
351  /// Fetch the type representing a 64-bit integer.
353  return Type::getInt64Ty(Context);
354  }
355 
356  /// Fetch the type representing a 128-bit integer.
357  IntegerType *getInt128Ty() { return Type::getInt128Ty(Context); }
358 
359  /// Fetch the type representing an N-bit integer.
360  IntegerType *getIntNTy(unsigned N) {
361  return Type::getIntNTy(Context, N);
362  }
363 
364  /// Fetch the type representing a 16-bit floating point value.
366  return Type::getHalfTy(Context);
367  }
368 
369  /// Fetch the type representing a 32-bit floating point value.
371  return Type::getFloatTy(Context);
372  }
373 
374  /// Fetch the type representing a 64-bit floating point value.
376  return Type::getDoubleTy(Context);
377  }
378 
379  /// Fetch the type representing void.
381  return Type::getVoidTy(Context);
382  }
383 
384  /// 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  /// 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  /// 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  /// Create and insert an element unordered-atomic memset of the region of
418  /// memory starting at the given pointer to the given value.
419  ///
420  /// If the pointer isn't an i8*, it will be converted. If a TBAA tag is
421  /// specified, it will be added to the instruction. Likewise with alias.scope
422  /// and noalias tags.
424  uint64_t Size, unsigned Align,
425  uint32_t ElementSize,
426  MDNode *TBAATag = nullptr,
427  MDNode *ScopeTag = nullptr,
428  MDNode *NoAliasTag = nullptr) {
429  return CreateElementUnorderedAtomicMemSet(Ptr, Val, getInt64(Size), Align,
430  ElementSize, TBAATag, ScopeTag,
431  NoAliasTag);
432  }
433 
434  CallInst *CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val,
435  Value *Size, unsigned Align,
436  uint32_t ElementSize,
437  MDNode *TBAATag = nullptr,
438  MDNode *ScopeTag = nullptr,
439  MDNode *NoAliasTag = nullptr);
440 
441  /// Create and insert a memcpy between the specified pointers.
442  ///
443  /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
444  /// specified, it will be added to the instruction. Likewise with alias.scope
445  /// and noalias tags.
446  CallInst *CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src,
447  unsigned SrcAlign, uint64_t Size,
448  bool isVolatile = false, MDNode *TBAATag = nullptr,
449  MDNode *TBAAStructTag = nullptr,
450  MDNode *ScopeTag = nullptr,
451  MDNode *NoAliasTag = nullptr) {
452  return CreateMemCpy(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
453  isVolatile, TBAATag, TBAAStructTag, ScopeTag,
454  NoAliasTag);
455  }
456 
457  CallInst *CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src,
458  unsigned SrcAlign, Value *Size,
459  bool isVolatile = false, MDNode *TBAATag = nullptr,
460  MDNode *TBAAStructTag = nullptr,
461  MDNode *ScopeTag = nullptr,
462  MDNode *NoAliasTag = nullptr);
463 
464  /// Create and insert an element unordered-atomic memcpy between the
465  /// specified pointers.
466  ///
467  /// DstAlign/SrcAlign are the alignments of the Dst/Src pointers, respectively.
468  ///
469  /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
470  /// specified, it will be added to the instruction. Likewise with alias.scope
471  /// and noalias tags.
473  Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
474  uint64_t Size, uint32_t ElementSize, MDNode *TBAATag = nullptr,
475  MDNode *TBAAStructTag = nullptr, MDNode *ScopeTag = nullptr,
476  MDNode *NoAliasTag = nullptr) {
477  return CreateElementUnorderedAtomicMemCpy(
478  Dst, DstAlign, Src, SrcAlign, getInt64(Size), ElementSize, TBAATag,
479  TBAAStructTag, ScopeTag, NoAliasTag);
480  }
481 
482  CallInst *CreateElementUnorderedAtomicMemCpy(
483  Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign, Value *Size,
484  uint32_t ElementSize, MDNode *TBAATag = nullptr,
485  MDNode *TBAAStructTag = nullptr, MDNode *ScopeTag = nullptr,
486  MDNode *NoAliasTag = nullptr);
487 
488  /// Create and insert a memmove between the specified
489  /// pointers.
490  ///
491  /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
492  /// specified, it will be added to the instruction. Likewise with alias.scope
493  /// and noalias tags.
494  CallInst *CreateMemMove(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
495  uint64_t Size, bool isVolatile = false,
496  MDNode *TBAATag = nullptr, MDNode *ScopeTag = nullptr,
497  MDNode *NoAliasTag = nullptr) {
498  return CreateMemMove(Dst, DstAlign, Src, SrcAlign, getInt64(Size), isVolatile,
499  TBAATag, ScopeTag, NoAliasTag);
500  }
501 
502  CallInst *CreateMemMove(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
503  Value *Size, bool isVolatile = false, MDNode *TBAATag = nullptr,
504  MDNode *ScopeTag = nullptr,
505  MDNode *NoAliasTag = nullptr);
506 
507  /// \brief Create and insert an element unordered-atomic memmove between the
508  /// specified pointers.
509  ///
510  /// DstAlign/SrcAlign are the alignments of the Dst/Src pointers,
511  /// respectively.
512  ///
513  /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
514  /// specified, it will be added to the instruction. Likewise with alias.scope
515  /// and noalias tags.
517  Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
518  uint64_t Size, uint32_t ElementSize, MDNode *TBAATag = nullptr,
519  MDNode *TBAAStructTag = nullptr, MDNode *ScopeTag = nullptr,
520  MDNode *NoAliasTag = nullptr) {
521  return CreateElementUnorderedAtomicMemMove(
522  Dst, DstAlign, Src, SrcAlign, getInt64(Size), ElementSize, TBAATag,
523  TBAAStructTag, ScopeTag, NoAliasTag);
524  }
525 
526  CallInst *CreateElementUnorderedAtomicMemMove(
527  Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign, Value *Size,
528  uint32_t ElementSize, MDNode *TBAATag = nullptr,
529  MDNode *TBAAStructTag = nullptr, MDNode *ScopeTag = nullptr,
530  MDNode *NoAliasTag = nullptr);
531 
532  /// Create a vector fadd reduction intrinsic of the source vector.
533  /// The first parameter is a scalar accumulator value for ordered reductions.
534  CallInst *CreateFAddReduce(Value *Acc, Value *Src);
535 
536  /// Create a vector fmul reduction intrinsic of the source vector.
537  /// The first parameter is a scalar accumulator value for ordered reductions.
538  CallInst *CreateFMulReduce(Value *Acc, Value *Src);
539 
540  /// Create a vector int add reduction intrinsic of the source vector.
541  CallInst *CreateAddReduce(Value *Src);
542 
543  /// Create a vector int mul reduction intrinsic of the source vector.
544  CallInst *CreateMulReduce(Value *Src);
545 
546  /// Create a vector int AND reduction intrinsic of the source vector.
547  CallInst *CreateAndReduce(Value *Src);
548 
549  /// Create a vector int OR reduction intrinsic of the source vector.
550  CallInst *CreateOrReduce(Value *Src);
551 
552  /// Create a vector int XOR reduction intrinsic of the source vector.
553  CallInst *CreateXorReduce(Value *Src);
554 
555  /// Create a vector integer max reduction intrinsic of the source
556  /// vector.
557  CallInst *CreateIntMaxReduce(Value *Src, bool IsSigned = false);
558 
559  /// Create a vector integer min reduction intrinsic of the source
560  /// vector.
561  CallInst *CreateIntMinReduce(Value *Src, bool IsSigned = false);
562 
563  /// Create a vector float max reduction intrinsic of the source
564  /// vector.
565  CallInst *CreateFPMaxReduce(Value *Src, bool NoNaN = false);
566 
567  /// Create a vector float min reduction intrinsic of the source
568  /// vector.
569  CallInst *CreateFPMinReduce(Value *Src, bool NoNaN = false);
570 
571  /// Create a lifetime.start intrinsic.
572  ///
573  /// If the pointer isn't i8* it will be converted.
574  CallInst *CreateLifetimeStart(Value *Ptr, ConstantInt *Size = nullptr);
575 
576  /// Create a lifetime.end intrinsic.
577  ///
578  /// If the pointer isn't i8* it will be converted.
579  CallInst *CreateLifetimeEnd(Value *Ptr, ConstantInt *Size = nullptr);
580 
581  /// Create a call to invariant.start intrinsic.
582  ///
583  /// If the pointer isn't i8* it will be converted.
584  CallInst *CreateInvariantStart(Value *Ptr, ConstantInt *Size = nullptr);
585 
586  /// Create a call to Masked Load intrinsic
587  CallInst *CreateMaskedLoad(Value *Ptr, unsigned Align, Value *Mask,
588  Value *PassThru = nullptr, const Twine &Name = "");
589 
590  /// Create a call to Masked Store intrinsic
591  CallInst *CreateMaskedStore(Value *Val, Value *Ptr, unsigned Align,
592  Value *Mask);
593 
594  /// Create a call to Masked Gather intrinsic
595  CallInst *CreateMaskedGather(Value *Ptrs, unsigned Align,
596  Value *Mask = nullptr,
597  Value *PassThru = nullptr,
598  const Twine& Name = "");
599 
600  /// Create a call to Masked Scatter intrinsic
601  CallInst *CreateMaskedScatter(Value *Val, Value *Ptrs, unsigned Align,
602  Value *Mask = nullptr);
603 
604  /// Create an assume intrinsic call that allows the optimizer to
605  /// assume that the provided condition will be true.
606  CallInst *CreateAssumption(Value *Cond);
607 
608  /// Create a call to the experimental.gc.statepoint intrinsic to
609  /// start a new statepoint sequence.
610  CallInst *CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes,
611  Value *ActualCallee,
612  ArrayRef<Value *> CallArgs,
613  ArrayRef<Value *> DeoptArgs,
614  ArrayRef<Value *> GCArgs,
615  const Twine &Name = "");
616 
617  /// Create a call to the experimental.gc.statepoint intrinsic to
618  /// start a new statepoint sequence.
619  CallInst *CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes,
620  Value *ActualCallee, uint32_t Flags,
621  ArrayRef<Use> CallArgs,
622  ArrayRef<Use> TransitionArgs,
623  ArrayRef<Use> DeoptArgs,
624  ArrayRef<Value *> GCArgs,
625  const Twine &Name = "");
626 
627  /// Conveninence function for the common case when CallArgs are filled
628  /// in using makeArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be
629  /// .get()'ed to get the Value pointer.
630  CallInst *CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes,
631  Value *ActualCallee, ArrayRef<Use> CallArgs,
632  ArrayRef<Value *> DeoptArgs,
633  ArrayRef<Value *> GCArgs,
634  const Twine &Name = "");
635 
636  /// Create an invoke to the experimental.gc.statepoint intrinsic to
637  /// start a new statepoint sequence.
638  InvokeInst *
639  CreateGCStatepointInvoke(uint64_t ID, uint32_t NumPatchBytes,
640  Value *ActualInvokee, BasicBlock *NormalDest,
641  BasicBlock *UnwindDest, ArrayRef<Value *> InvokeArgs,
642  ArrayRef<Value *> DeoptArgs,
643  ArrayRef<Value *> GCArgs, const Twine &Name = "");
644 
645  /// Create an invoke to the experimental.gc.statepoint intrinsic to
646  /// start a new statepoint sequence.
647  InvokeInst *CreateGCStatepointInvoke(
648  uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee,
649  BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
650  ArrayRef<Use> InvokeArgs, ArrayRef<Use> TransitionArgs,
651  ArrayRef<Use> DeoptArgs, ArrayRef<Value *> GCArgs,
652  const Twine &Name = "");
653 
654  // Convenience function for the common case when CallArgs are filled in using
655  // makeArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be .get()'ed to
656  // get the Value *.
657  InvokeInst *
658  CreateGCStatepointInvoke(uint64_t ID, uint32_t NumPatchBytes,
659  Value *ActualInvokee, BasicBlock *NormalDest,
660  BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
661  ArrayRef<Value *> DeoptArgs,
662  ArrayRef<Value *> GCArgs, const Twine &Name = "");
663 
664  /// Create a call to the experimental.gc.result intrinsic to extract
665  /// the result from a call wrapped in a statepoint.
666  CallInst *CreateGCResult(Instruction *Statepoint,
667  Type *ResultType,
668  const Twine &Name = "");
669 
670  /// Create a call to the experimental.gc.relocate intrinsics to
671  /// project the relocated value of one pointer from the statepoint.
672  CallInst *CreateGCRelocate(Instruction *Statepoint,
673  int BaseOffset,
674  int DerivedOffset,
675  Type *ResultType,
676  const Twine &Name = "");
677 
678  /// Create a call to intrinsic \p ID with 1 operand which is mangled on its
679  /// type.
680  CallInst *CreateUnaryIntrinsic(Intrinsic::ID ID, Value *V,
681  Instruction *FMFSource = nullptr,
682  const Twine &Name = "");
683 
684  /// Create a call to intrinsic \p ID with 2 operands which is mangled on the
685  /// first type.
686  CallInst *CreateBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS,
687  Instruction *FMFSource = nullptr,
688  const Twine &Name = "");
689 
690  /// Create a call to intrinsic \p ID with \p args, mangled using \p Types. If
691  /// \p FMFSource is provided, copy fast-math-flags from that instruction to
692  /// the intrinsic.
693  CallInst *CreateIntrinsic(Intrinsic::ID ID, ArrayRef<Type *> Types,
695  Instruction *FMFSource = nullptr,
696  const Twine &Name = "");
697 
698  /// Create call to the minnum intrinsic.
699  CallInst *CreateMinNum(Value *LHS, Value *RHS, const Twine &Name = "") {
700  return CreateBinaryIntrinsic(Intrinsic::minnum, LHS, RHS, nullptr, Name);
701  }
702 
703  /// Create call to the maxnum intrinsic.
704  CallInst *CreateMaxNum(Value *LHS, Value *RHS, const Twine &Name = "") {
705  return CreateBinaryIntrinsic(Intrinsic::maxnum, LHS, RHS, nullptr, Name);
706  }
707 
708  /// Create call to the minimum intrinsic.
709  CallInst *CreateMinimum(Value *LHS, Value *RHS, const Twine &Name = "") {
710  return CreateBinaryIntrinsic(Intrinsic::minimum, LHS, RHS, nullptr, Name);
711  }
712 
713  /// Create call to the maximum intrinsic.
714  CallInst *CreateMaximum(Value *LHS, Value *RHS, const Twine &Name = "") {
715  return CreateBinaryIntrinsic(Intrinsic::maximum, LHS, RHS, nullptr, Name);
716  }
717 
718 private:
719  /// Create a call to a masked intrinsic with given Id.
720  CallInst *CreateMaskedIntrinsic(Intrinsic::ID Id, ArrayRef<Value *> Ops,
721  ArrayRef<Type *> OverloadedTypes,
722  const Twine &Name = "");
723 
724  Value *getCastedInt8PtrValue(Value *Ptr);
725 };
726 
727 /// This provides a uniform API for creating instructions and inserting
728 /// them into a basic block: either at the end of a BasicBlock, or at a specific
729 /// iterator location in a block.
730 ///
731 /// Note that the builder does not expose the full generality of LLVM
732 /// instructions. For access to extra instruction properties, use the mutators
733 /// (e.g. setVolatile) on the instructions after they have been
734 /// created. Convenience state exists to specify fast-math flags and fp-math
735 /// tags.
736 ///
737 /// The first template argument specifies a class to use for creating constants.
738 /// This defaults to creating minimally folded constants. The second template
739 /// argument allows clients to specify custom insertion hooks that are called on
740 /// every newly created insertion.
741 template <typename T = ConstantFolder,
743 class IRBuilder : public IRBuilderBase, public Inserter {
744  T Folder;
745 
746 public:
747  IRBuilder(LLVMContext &C, const T &F, Inserter I = Inserter(),
748  MDNode *FPMathTag = nullptr,
749  ArrayRef<OperandBundleDef> OpBundles = None)
750  : IRBuilderBase(C, FPMathTag, OpBundles), Inserter(std::move(I)),
751  Folder(F) {}
752 
753  explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr,
754  ArrayRef<OperandBundleDef> OpBundles = None)
755  : IRBuilderBase(C, FPMathTag, OpBundles) {}
756 
757  explicit IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag = nullptr,
758  ArrayRef<OperandBundleDef> OpBundles = None)
759  : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder(F) {
760  SetInsertPoint(TheBB);
761  }
762 
763  explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr,
764  ArrayRef<OperandBundleDef> OpBundles = None)
765  : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles) {
766  SetInsertPoint(TheBB);
767  }
768 
769  explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr,
770  ArrayRef<OperandBundleDef> OpBundles = None)
771  : IRBuilderBase(IP->getContext(), FPMathTag, OpBundles) {
772  SetInsertPoint(IP);
773  }
774 
776  MDNode *FPMathTag = nullptr,
777  ArrayRef<OperandBundleDef> OpBundles = None)
778  : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder(F) {
779  SetInsertPoint(TheBB, IP);
780  }
781 
783  MDNode *FPMathTag = nullptr,
784  ArrayRef<OperandBundleDef> OpBundles = None)
785  : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles) {
786  SetInsertPoint(TheBB, IP);
787  }
788 
789  /// Get the constant folder being used.
790  const T &getFolder() { return Folder; }
791 
792  /// Insert and return the specified instruction.
793  template<typename InstTy>
794  InstTy *Insert(InstTy *I, const Twine &Name = "") const {
795  this->InsertHelper(I, Name, BB, InsertPt);
796  this->SetInstDebugLocation(I);
797  return I;
798  }
799 
800  /// No-op overload to handle constants.
801  Constant *Insert(Constant *C, const Twine& = "") const {
802  return C;
803  }
804 
805  //===--------------------------------------------------------------------===//
806  // Instruction creation methods: Terminators
807  //===--------------------------------------------------------------------===//
808 
809 private:
810  /// Helper to add branch weight and unpredictable metadata onto an
811  /// instruction.
812  /// \returns The annotated instruction.
813  template <typename InstTy>
814  InstTy *addBranchMetadata(InstTy *I, MDNode *Weights, MDNode *Unpredictable) {
815  if (Weights)
816  I->setMetadata(LLVMContext::MD_prof, Weights);
817  if (Unpredictable)
818  I->setMetadata(LLVMContext::MD_unpredictable, Unpredictable);
819  return I;
820  }
821 
822 public:
823  /// Create a 'ret void' instruction.
825  return Insert(ReturnInst::Create(Context));
826  }
827 
828  /// Create a 'ret <val>' instruction.
830  return Insert(ReturnInst::Create(Context, V));
831  }
832 
833  /// Create a sequence of N insertvalue instructions,
834  /// with one Value from the retVals array each, that build a aggregate
835  /// return value one value at a time, and a ret instruction to return
836  /// the resulting aggregate value.
837  ///
838  /// This is a convenience function for code that uses aggregate return values
839  /// as a vehicle for having multiple return values.
840  ReturnInst *CreateAggregateRet(Value *const *retVals, unsigned N) {
841  Value *V = UndefValue::get(getCurrentFunctionReturnType());
842  for (unsigned i = 0; i != N; ++i)
843  V = CreateInsertValue(V, retVals[i], i, "mrv");
844  return Insert(ReturnInst::Create(Context, V));
845  }
846 
847  /// Create an unconditional 'br label X' instruction.
849  return Insert(BranchInst::Create(Dest));
850  }
851 
852  /// Create a conditional 'br Cond, TrueDest, FalseDest'
853  /// instruction.
855  MDNode *BranchWeights = nullptr,
856  MDNode *Unpredictable = nullptr) {
857  return Insert(addBranchMetadata(BranchInst::Create(True, False, Cond),
858  BranchWeights, Unpredictable));
859  }
860 
861  /// Create a conditional 'br Cond, TrueDest, FalseDest'
862  /// instruction. Copy branch meta data if available.
864  Instruction *MDSrc) {
865  BranchInst *Br = BranchInst::Create(True, False, Cond);
866  if (MDSrc) {
869  Br->copyMetadata(*MDSrc, makeArrayRef(&WL[0], 4));
870  }
871  return Insert(Br);
872  }
873 
874  /// Create a switch instruction with the specified value, default dest,
875  /// and with a hint for the number of cases that will be added (for efficient
876  /// allocation).
877  SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10,
878  MDNode *BranchWeights = nullptr,
879  MDNode *Unpredictable = nullptr) {
880  return Insert(addBranchMetadata(SwitchInst::Create(V, Dest, NumCases),
881  BranchWeights, Unpredictable));
882  }
883 
884  /// Create an indirect branch instruction with the specified address
885  /// operand, with an optional hint for the number of destinations that will be
886  /// added (for efficient allocation).
887  IndirectBrInst *CreateIndirectBr(Value *Addr, unsigned NumDests = 10) {
888  return Insert(IndirectBrInst::Create(Addr, NumDests));
889  }
890 
891  /// Create an invoke instruction.
892  InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
893  BasicBlock *UnwindDest,
895  const Twine &Name = "") {
896  return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args),
897  Name);
898  }
899  InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
900  BasicBlock *UnwindDest, ArrayRef<Value *> Args,
901  ArrayRef<OperandBundleDef> OpBundles,
902  const Twine &Name = "") {
903  return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args,
904  OpBundles), Name);
905  }
906 
908  return Insert(ResumeInst::Create(Exn));
909  }
910 
912  BasicBlock *UnwindBB = nullptr) {
913  return Insert(CleanupReturnInst::Create(CleanupPad, UnwindBB));
914  }
915 
917  unsigned NumHandlers,
918  const Twine &Name = "") {
919  return Insert(CatchSwitchInst::Create(ParentPad, UnwindBB, NumHandlers),
920  Name);
921  }
922 
924  const Twine &Name = "") {
925  return Insert(CatchPadInst::Create(ParentPad, Args), Name);
926  }
927 
930  const Twine &Name = "") {
931  return Insert(CleanupPadInst::Create(ParentPad, Args), Name);
932  }
933 
935  return Insert(CatchReturnInst::Create(CatchPad, BB));
936  }
937 
939  return Insert(new UnreachableInst(Context));
940  }
941 
942  //===--------------------------------------------------------------------===//
943  // Instruction creation methods: Binary Operators
944  //===--------------------------------------------------------------------===//
945 private:
946  BinaryOperator *CreateInsertNUWNSWBinOp(BinaryOperator::BinaryOps Opc,
947  Value *LHS, Value *RHS,
948  const Twine &Name,
949  bool HasNUW, bool HasNSW) {
950  BinaryOperator *BO = Insert(BinaryOperator::Create(Opc, LHS, RHS), Name);
951  if (HasNUW) BO->setHasNoUnsignedWrap();
952  if (HasNSW) BO->setHasNoSignedWrap();
953  return BO;
954  }
955 
956  Instruction *setFPAttrs(Instruction *I, MDNode *FPMD,
957  FastMathFlags FMF) const {
958  if (!FPMD)
959  FPMD = DefaultFPMathTag;
960  if (FPMD)
962  I->setFastMathFlags(FMF);
963  return I;
964  }
965 
966  Value *foldConstant(Instruction::BinaryOps Opc, Value *L,
967  Value *R, const Twine &Name = nullptr) const {
968  auto *LC = dyn_cast<Constant>(L);
969  auto *RC = dyn_cast<Constant>(R);
970  return (LC && RC) ? Insert(Folder.CreateBinOp(Opc, LC, RC), Name) : nullptr;
971  }
972 
973 public:
974  Value *CreateAdd(Value *LHS, Value *RHS, const Twine &Name = "",
975  bool HasNUW = false, bool HasNSW = false) {
976  if (auto *LC = dyn_cast<Constant>(LHS))
977  if (auto *RC = dyn_cast<Constant>(RHS))
978  return Insert(Folder.CreateAdd(LC, RC, HasNUW, HasNSW), Name);
979  return CreateInsertNUWNSWBinOp(Instruction::Add, LHS, RHS, Name,
980  HasNUW, HasNSW);
981  }
982 
983  Value *CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
984  return CreateAdd(LHS, RHS, Name, false, true);
985  }
986 
987  Value *CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
988  return CreateAdd(LHS, RHS, Name, true, false);
989  }
990 
991  Value *CreateSub(Value *LHS, Value *RHS, const Twine &Name = "",
992  bool HasNUW = false, bool HasNSW = false) {
993  if (auto *LC = dyn_cast<Constant>(LHS))
994  if (auto *RC = dyn_cast<Constant>(RHS))
995  return Insert(Folder.CreateSub(LC, RC, HasNUW, HasNSW), Name);
996  return CreateInsertNUWNSWBinOp(Instruction::Sub, LHS, RHS, Name,
997  HasNUW, HasNSW);
998  }
999 
1000  Value *CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
1001  return CreateSub(LHS, RHS, Name, false, true);
1002  }
1003 
1004  Value *CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
1005  return CreateSub(LHS, RHS, Name, true, false);
1006  }
1007 
1008  Value *CreateMul(Value *LHS, Value *RHS, const Twine &Name = "",
1009  bool HasNUW = false, bool HasNSW = false) {
1010  if (auto *LC = dyn_cast<Constant>(LHS))
1011  if (auto *RC = dyn_cast<Constant>(RHS))
1012  return Insert(Folder.CreateMul(LC, RC, HasNUW, HasNSW), Name);
1013  return CreateInsertNUWNSWBinOp(Instruction::Mul, LHS, RHS, Name,
1014  HasNUW, HasNSW);
1015  }
1016 
1017  Value *CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
1018  return CreateMul(LHS, RHS, Name, false, true);
1019  }
1020 
1021  Value *CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
1022  return CreateMul(LHS, RHS, Name, true, false);
1023  }
1024 
1025  Value *CreateUDiv(Value *LHS, Value *RHS, const Twine &Name = "",
1026  bool isExact = false) {
1027  if (auto *LC = dyn_cast<Constant>(LHS))
1028  if (auto *RC = dyn_cast<Constant>(RHS))
1029  return Insert(Folder.CreateUDiv(LC, RC, isExact), Name);
1030  if (!isExact)
1031  return Insert(BinaryOperator::CreateUDiv(LHS, RHS), Name);
1032  return Insert(BinaryOperator::CreateExactUDiv(LHS, RHS), Name);
1033  }
1034 
1035  Value *CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
1036  return CreateUDiv(LHS, RHS, Name, true);
1037  }
1038 
1039  Value *CreateSDiv(Value *LHS, Value *RHS, const Twine &Name = "",
1040  bool isExact = false) {
1041  if (auto *LC = dyn_cast<Constant>(LHS))
1042  if (auto *RC = dyn_cast<Constant>(RHS))
1043  return Insert(Folder.CreateSDiv(LC, RC, isExact), Name);
1044  if (!isExact)
1045  return Insert(BinaryOperator::CreateSDiv(LHS, RHS), Name);
1046  return Insert(BinaryOperator::CreateExactSDiv(LHS, RHS), Name);
1047  }
1048 
1049  Value *CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
1050  return CreateSDiv(LHS, RHS, Name, true);
1051  }
1052 
1053  Value *CreateURem(Value *LHS, Value *RHS, const Twine &Name = "") {
1054  if (Value *V = foldConstant(Instruction::URem, LHS, RHS, Name)) return V;
1055  return Insert(BinaryOperator::CreateURem(LHS, RHS), Name);
1056  }
1057 
1058  Value *CreateSRem(Value *LHS, Value *RHS, const Twine &Name = "") {
1059  if (Value *V = foldConstant(Instruction::SRem, LHS, RHS, Name)) return V;
1060  return Insert(BinaryOperator::CreateSRem(LHS, RHS), Name);
1061  }
1062 
1063  Value *CreateShl(Value *LHS, Value *RHS, const Twine &Name = "",
1064  bool HasNUW = false, bool HasNSW = false) {
1065  if (auto *LC = dyn_cast<Constant>(LHS))
1066  if (auto *RC = dyn_cast<Constant>(RHS))
1067  return Insert(Folder.CreateShl(LC, RC, HasNUW, HasNSW), Name);
1068  return CreateInsertNUWNSWBinOp(Instruction::Shl, LHS, RHS, Name,
1069  HasNUW, HasNSW);
1070  }
1071 
1072  Value *CreateShl(Value *LHS, const APInt &RHS, const Twine &Name = "",
1073  bool HasNUW = false, bool HasNSW = false) {
1074  return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1075  HasNUW, HasNSW);
1076  }
1077 
1078  Value *CreateShl(Value *LHS, uint64_t RHS, const Twine &Name = "",
1079  bool HasNUW = false, bool HasNSW = false) {
1080  return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1081  HasNUW, HasNSW);
1082  }
1083 
1084  Value *CreateLShr(Value *LHS, Value *RHS, const Twine &Name = "",
1085  bool isExact = false) {
1086  if (auto *LC = dyn_cast<Constant>(LHS))
1087  if (auto *RC = dyn_cast<Constant>(RHS))
1088  return Insert(Folder.CreateLShr(LC, RC, isExact), Name);
1089  if (!isExact)
1090  return Insert(BinaryOperator::CreateLShr(LHS, RHS), Name);
1091  return Insert(BinaryOperator::CreateExactLShr(LHS, RHS), Name);
1092  }
1093 
1094  Value *CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1095  bool isExact = false) {
1096  return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1097  }
1098 
1099  Value *CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name = "",
1100  bool isExact = false) {
1101  return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1102  }
1103 
1104  Value *CreateAShr(Value *LHS, Value *RHS, const Twine &Name = "",
1105  bool isExact = false) {
1106  if (auto *LC = dyn_cast<Constant>(LHS))
1107  if (auto *RC = dyn_cast<Constant>(RHS))
1108  return Insert(Folder.CreateAShr(LC, RC, isExact), Name);
1109  if (!isExact)
1110  return Insert(BinaryOperator::CreateAShr(LHS, RHS), Name);
1111  return Insert(BinaryOperator::CreateExactAShr(LHS, RHS), Name);
1112  }
1113 
1114  Value *CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1115  bool isExact = false) {
1116  return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1117  }
1118 
1119  Value *CreateAShr(Value *LHS, uint64_t RHS, const Twine &Name = "",
1120  bool isExact = false) {
1121  return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1122  }
1123 
1124  Value *CreateAnd(Value *LHS, Value *RHS, const Twine &Name = "") {
1125  if (auto *RC = dyn_cast<Constant>(RHS)) {
1126  if (isa<ConstantInt>(RC) && cast<ConstantInt>(RC)->isMinusOne())
1127  return LHS; // LHS & -1 -> LHS
1128  if (auto *LC = dyn_cast<Constant>(LHS))
1129  return Insert(Folder.CreateAnd(LC, RC), Name);
1130  }
1131  return Insert(BinaryOperator::CreateAnd(LHS, RHS), Name);
1132  }
1133 
1134  Value *CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1135  return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1136  }
1137 
1138  Value *CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1139  return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1140  }
1141 
1142  Value *CreateOr(Value *LHS, Value *RHS, const Twine &Name = "") {
1143  if (auto *RC = dyn_cast<Constant>(RHS)) {
1144  if (RC->isNullValue())
1145  return LHS; // LHS | 0 -> LHS
1146  if (auto *LC = dyn_cast<Constant>(LHS))
1147  return Insert(Folder.CreateOr(LC, RC), Name);
1148  }
1149  return Insert(BinaryOperator::CreateOr(LHS, RHS), Name);
1150  }
1151 
1152  Value *CreateOr(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1153  return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1154  }
1155 
1156  Value *CreateOr(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1157  return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1158  }
1159 
1160  Value *CreateXor(Value *LHS, Value *RHS, const Twine &Name = "") {
1161  if (Value *V = foldConstant(Instruction::Xor, LHS, RHS, Name)) return V;
1162  return Insert(BinaryOperator::CreateXor(LHS, RHS), Name);
1163  }
1164 
1165  Value *CreateXor(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1166  return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1167  }
1168 
1169  Value *CreateXor(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1170  return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1171  }
1172 
1173  Value *CreateFAdd(Value *L, Value *R, const Twine &Name = "",
1174  MDNode *FPMD = nullptr) {
1175  if (Value *V = foldConstant(Instruction::FAdd, L, R, Name)) return V;
1176  Instruction *I = setFPAttrs(BinaryOperator::CreateFAdd(L, R), FPMD, FMF);
1177  return Insert(I, Name);
1178  }
1179 
1180  /// Copy fast-math-flags from an instruction rather than using the builder's
1181  /// default FMF.
1183  const Twine &Name = "") {
1184  if (Value *V = foldConstant(Instruction::FAdd, L, R, Name)) return V;
1185  Instruction *I = setFPAttrs(BinaryOperator::CreateFAdd(L, R), nullptr,
1186  FMFSource->getFastMathFlags());
1187  return Insert(I, Name);
1188  }
1189 
1190  Value *CreateFSub(Value *L, Value *R, const Twine &Name = "",
1191  MDNode *FPMD = nullptr) {
1192  if (Value *V = foldConstant(Instruction::FSub, L, R, Name)) return V;
1193  Instruction *I = setFPAttrs(BinaryOperator::CreateFSub(L, R), FPMD, FMF);
1194  return Insert(I, Name);
1195  }
1196 
1197  /// Copy fast-math-flags from an instruction rather than using the builder's
1198  /// default FMF.
1200  const Twine &Name = "") {
1201  if (Value *V = foldConstant(Instruction::FSub, L, R, Name)) return V;
1202  Instruction *I = setFPAttrs(BinaryOperator::CreateFSub(L, R), nullptr,
1203  FMFSource->getFastMathFlags());
1204  return Insert(I, Name);
1205  }
1206 
1207  Value *CreateFMul(Value *L, Value *R, const Twine &Name = "",
1208  MDNode *FPMD = nullptr) {
1209  if (Value *V = foldConstant(Instruction::FMul, L, R, Name)) return V;
1210  Instruction *I = setFPAttrs(BinaryOperator::CreateFMul(L, R), FPMD, FMF);
1211  return Insert(I, Name);
1212  }
1213 
1214  /// Copy fast-math-flags from an instruction rather than using the builder's
1215  /// default FMF.
1217  const Twine &Name = "") {
1218  if (Value *V = foldConstant(Instruction::FMul, L, R, Name)) return V;
1219  Instruction *I = setFPAttrs(BinaryOperator::CreateFMul(L, R), nullptr,
1220  FMFSource->getFastMathFlags());
1221  return Insert(I, Name);
1222  }
1223 
1224  Value *CreateFDiv(Value *L, Value *R, const Twine &Name = "",
1225  MDNode *FPMD = nullptr) {
1226  if (Value *V = foldConstant(Instruction::FDiv, L, R, Name)) return V;
1227  Instruction *I = setFPAttrs(BinaryOperator::CreateFDiv(L, R), FPMD, FMF);
1228  return Insert(I, Name);
1229  }
1230 
1231  /// Copy fast-math-flags from an instruction rather than using the builder's
1232  /// default FMF.
1234  const Twine &Name = "") {
1235  if (Value *V = foldConstant(Instruction::FDiv, L, R, Name)) return V;
1236  Instruction *I = setFPAttrs(BinaryOperator::CreateFDiv(L, R), nullptr,
1237  FMFSource->getFastMathFlags());
1238  return Insert(I, Name);
1239  }
1240 
1241  Value *CreateFRem(Value *L, Value *R, const Twine &Name = "",
1242  MDNode *FPMD = nullptr) {
1243  if (Value *V = foldConstant(Instruction::FRem, L, R, Name)) return V;
1244  Instruction *I = setFPAttrs(BinaryOperator::CreateFRem(L, R), FPMD, FMF);
1245  return Insert(I, Name);
1246  }
1247 
1248  /// Copy fast-math-flags from an instruction rather than using the builder's
1249  /// default FMF.
1251  const Twine &Name = "") {
1252  if (Value *V = foldConstant(Instruction::FRem, L, R, Name)) return V;
1253  Instruction *I = setFPAttrs(BinaryOperator::CreateFRem(L, R), nullptr,
1254  FMFSource->getFastMathFlags());
1255  return Insert(I, Name);
1256  }
1257 
1259  Value *LHS, Value *RHS, const Twine &Name = "",
1260  MDNode *FPMathTag = nullptr) {
1261  if (Value *V = foldConstant(Opc, LHS, RHS, Name)) return V;
1262  Instruction *BinOp = BinaryOperator::Create(Opc, LHS, RHS);
1263  if (isa<FPMathOperator>(BinOp))
1264  BinOp = setFPAttrs(BinOp, FPMathTag, FMF);
1265  return Insert(BinOp, Name);
1266  }
1267 
1268  Value *CreateNeg(Value *V, const Twine &Name = "",
1269  bool HasNUW = false, bool HasNSW = false) {
1270  if (auto *VC = dyn_cast<Constant>(V))
1271  return Insert(Folder.CreateNeg(VC, HasNUW, HasNSW), Name);
1272  BinaryOperator *BO = Insert(BinaryOperator::CreateNeg(V), Name);
1273  if (HasNUW) BO->setHasNoUnsignedWrap();
1274  if (HasNSW) BO->setHasNoSignedWrap();
1275  return BO;
1276  }
1277 
1278  Value *CreateNSWNeg(Value *V, const Twine &Name = "") {
1279  return CreateNeg(V, Name, false, true);
1280  }
1281 
1282  Value *CreateNUWNeg(Value *V, const Twine &Name = "") {
1283  return CreateNeg(V, Name, true, false);
1284  }
1285 
1286  Value *CreateFNeg(Value *V, const Twine &Name = "",
1287  MDNode *FPMathTag = nullptr) {
1288  if (auto *VC = dyn_cast<Constant>(V))
1289  return Insert(Folder.CreateFNeg(VC), Name);
1290  return Insert(setFPAttrs(BinaryOperator::CreateFNeg(V), FPMathTag, FMF),
1291  Name);
1292  }
1293 
1294  Value *CreateNot(Value *V, const Twine &Name = "") {
1295  if (auto *VC = dyn_cast<Constant>(V))
1296  return Insert(Folder.CreateNot(VC), Name);
1297  return Insert(BinaryOperator::CreateNot(V), Name);
1298  }
1299 
1300  //===--------------------------------------------------------------------===//
1301  // Instruction creation methods: Memory Instructions
1302  //===--------------------------------------------------------------------===//
1303 
1304  AllocaInst *CreateAlloca(Type *Ty, unsigned AddrSpace,
1305  Value *ArraySize = nullptr, const Twine &Name = "") {
1306  return Insert(new AllocaInst(Ty, AddrSpace, ArraySize), Name);
1307  }
1308 
1309  AllocaInst *CreateAlloca(Type *Ty, Value *ArraySize = nullptr,
1310  const Twine &Name = "") {
1311  const DataLayout &DL = BB->getParent()->getParent()->getDataLayout();
1312  return Insert(new AllocaInst(Ty, DL.getAllocaAddrSpace(), ArraySize), Name);
1313  }
1314 
1315  /// Provided to resolve 'CreateLoad(Ptr, "...")' correctly, instead of
1316  /// converting the string to 'bool' for the isVolatile parameter.
1317  LoadInst *CreateLoad(Value *Ptr, const char *Name) {
1318  return Insert(new LoadInst(Ptr), Name);
1319  }
1320 
1321  LoadInst *CreateLoad(Value *Ptr, const Twine &Name = "") {
1322  return Insert(new LoadInst(Ptr), Name);
1323  }
1324 
1325  LoadInst *CreateLoad(Type *Ty, Value *Ptr, const Twine &Name = "") {
1326  return Insert(new LoadInst(Ty, Ptr), Name);
1327  }
1328 
1329  LoadInst *CreateLoad(Value *Ptr, bool isVolatile, const Twine &Name = "") {
1330  return Insert(new LoadInst(Ptr, nullptr, isVolatile), Name);
1331  }
1332 
1333  StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) {
1334  return Insert(new StoreInst(Val, Ptr, isVolatile));
1335  }
1336 
1337  /// Provided to resolve 'CreateAlignedLoad(Ptr, Align, "...")'
1338  /// correctly, instead of converting the string to 'bool' for the isVolatile
1339  /// parameter.
1340  LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name) {
1341  LoadInst *LI = CreateLoad(Ptr, Name);
1342  LI->setAlignment(Align);
1343  return LI;
1344  }
1346  const Twine &Name = "") {
1347  LoadInst *LI = CreateLoad(Ptr, Name);
1348  LI->setAlignment(Align);
1349  return LI;
1350  }
1352  const Twine &Name = "") {
1353  LoadInst *LI = CreateLoad(Ptr, isVolatile, Name);
1354  LI->setAlignment(Align);
1355  return LI;
1356  }
1357 
1359  bool isVolatile = false) {
1360  StoreInst *SI = CreateStore(Val, Ptr, isVolatile);
1361  SI->setAlignment(Align);
1362  return SI;
1363  }
1364 
1367  const Twine &Name = "") {
1368  return Insert(new FenceInst(Context, Ordering, SSID), Name);
1369  }
1370 
1373  AtomicOrdering SuccessOrdering,
1374  AtomicOrdering FailureOrdering,
1376  return Insert(new AtomicCmpXchgInst(Ptr, Cmp, New, SuccessOrdering,
1377  FailureOrdering, SSID));
1378  }
1379 
1381  AtomicOrdering Ordering,
1383  return Insert(new AtomicRMWInst(Op, Ptr, Val, Ordering, SSID));
1384  }
1385 
1387  const Twine &Name = "") {
1388  return CreateGEP(nullptr, Ptr, IdxList, Name);
1389  }
1390 
1392  const Twine &Name = "") {
1393  if (auto *PC = dyn_cast<Constant>(Ptr)) {
1394  // Every index must be constant.
1395  size_t i, e;
1396  for (i = 0, e = IdxList.size(); i != e; ++i)
1397  if (!isa<Constant>(IdxList[i]))
1398  break;
1399  if (i == e)
1400  return Insert(Folder.CreateGetElementPtr(Ty, PC, IdxList), Name);
1401  }
1402  return Insert(GetElementPtrInst::Create(Ty, Ptr, IdxList), Name);
1403  }
1404 
1406  const Twine &Name = "") {
1407  return CreateInBoundsGEP(nullptr, Ptr, IdxList, Name);
1408  }
1409 
1411  const Twine &Name = "") {
1412  if (auto *PC = dyn_cast<Constant>(Ptr)) {
1413  // Every index must be constant.
1414  size_t i, e;
1415  for (i = 0, e = IdxList.size(); i != e; ++i)
1416  if (!isa<Constant>(IdxList[i]))
1417  break;
1418  if (i == e)
1419  return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, IdxList),
1420  Name);
1421  }
1422  return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, IdxList), Name);
1423  }
1424 
1425  Value *CreateGEP(Value *Ptr, Value *Idx, const Twine &Name = "") {
1426  return CreateGEP(nullptr, Ptr, Idx, Name);
1427  }
1428 
1429  Value *CreateGEP(Type *Ty, Value *Ptr, Value *Idx, const Twine &Name = "") {
1430  if (auto *PC = dyn_cast<Constant>(Ptr))
1431  if (auto *IC = dyn_cast<Constant>(Idx))
1432  return Insert(Folder.CreateGetElementPtr(Ty, PC, IC), Name);
1433  return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
1434  }
1435 
1437  const Twine &Name = "") {
1438  if (auto *PC = dyn_cast<Constant>(Ptr))
1439  if (auto *IC = dyn_cast<Constant>(Idx))
1440  return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, IC), Name);
1441  return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
1442  }
1443 
1444  Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name = "") {
1445  return CreateConstGEP1_32(nullptr, Ptr, Idx0, Name);
1446  }
1447 
1448  Value *CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
1449  const Twine &Name = "") {
1451 
1452  if (auto *PC = dyn_cast<Constant>(Ptr))
1453  return Insert(Folder.CreateGetElementPtr(Ty, PC, Idx), Name);
1454 
1455  return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
1456  }
1457 
1458  Value *CreateConstInBoundsGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
1459  const Twine &Name = "") {
1461 
1462  if (auto *PC = dyn_cast<Constant>(Ptr))
1463  return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idx), Name);
1464 
1465  return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
1466  }
1467 
1468  Value *CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1,
1469  const Twine &Name = "") {
1470  Value *Idxs[] = {
1473  };
1474 
1475  if (auto *PC = dyn_cast<Constant>(Ptr))
1476  return Insert(Folder.CreateGetElementPtr(Ty, PC, Idxs), Name);
1477 
1478  return Insert(GetElementPtrInst::Create(Ty, Ptr, Idxs), Name);
1479  }
1480 
1481  Value *CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0,
1482  unsigned Idx1, const Twine &Name = "") {
1483  Value *Idxs[] = {
1486  };
1487 
1488  if (auto *PC = dyn_cast<Constant>(Ptr))
1489  return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idxs), Name);
1490 
1491  return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idxs), Name);
1492  }
1493 
1494  Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name = "") {
1496 
1497  if (auto *PC = dyn_cast<Constant>(Ptr))
1498  return Insert(Folder.CreateGetElementPtr(nullptr, PC, Idx), Name);
1499 
1500  return Insert(GetElementPtrInst::Create(nullptr, Ptr, Idx), Name);
1501  }
1502 
1504  const Twine &Name = "") {
1506 
1507  if (auto *PC = dyn_cast<Constant>(Ptr))
1508  return Insert(Folder.CreateInBoundsGetElementPtr(nullptr, PC, Idx), Name);
1509 
1510  return Insert(GetElementPtrInst::CreateInBounds(nullptr, Ptr, Idx), Name);
1511  }
1512 
1513  Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1514  const Twine &Name = "") {
1515  Value *Idxs[] = {
1518  };
1519 
1520  if (auto *PC = dyn_cast<Constant>(Ptr))
1521  return Insert(Folder.CreateGetElementPtr(nullptr, PC, Idxs), Name);
1522 
1523  return Insert(GetElementPtrInst::Create(nullptr, Ptr, Idxs), Name);
1524  }
1525 
1526  Value *CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1527  const Twine &Name = "") {
1528  Value *Idxs[] = {
1531  };
1532 
1533  if (auto *PC = dyn_cast<Constant>(Ptr))
1534  return Insert(Folder.CreateInBoundsGetElementPtr(nullptr, PC, Idxs),
1535  Name);
1536 
1537  return Insert(GetElementPtrInst::CreateInBounds(nullptr, Ptr, Idxs), Name);
1538  }
1539 
1540  Value *CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx,
1541  const Twine &Name = "") {
1542  return CreateConstInBoundsGEP2_32(Ty, Ptr, 0, Idx, Name);
1543  }
1544 
1545  Value *CreateStructGEP(Value *Ptr, unsigned Idx, const Twine &Name = "") {
1546  return CreateConstInBoundsGEP2_32(nullptr, Ptr, 0, Idx, Name);
1547  }
1548 
1549  /// Same as CreateGlobalString, but return a pointer with "i8*" type
1550  /// instead of a pointer to array of i8.
1552  unsigned AddressSpace = 0) {
1553  GlobalVariable *GV = CreateGlobalString(Str, Name, AddressSpace);
1555  Constant *Indices[] = {Zero, Zero};
1557  Indices);
1558  }
1559 
1560  //===--------------------------------------------------------------------===//
1561  // Instruction creation methods: Cast/Conversion Operators
1562  //===--------------------------------------------------------------------===//
1563 
1564  Value *CreateTrunc(Value *V, Type *DestTy, const Twine &Name = "") {
1565  return CreateCast(Instruction::Trunc, V, DestTy, Name);
1566  }
1567 
1568  Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "") {
1569  return CreateCast(Instruction::ZExt, V, DestTy, Name);
1570  }
1571 
1572  Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") {
1573  return CreateCast(Instruction::SExt, V, DestTy, Name);
1574  }
1575 
1576  /// Create a ZExt or Trunc from the integer value V to DestTy. Return
1577  /// the value untouched if the type of V is already DestTy.
1579  const Twine &Name = "") {
1580  assert(V->getType()->isIntOrIntVectorTy() &&
1581  DestTy->isIntOrIntVectorTy() &&
1582  "Can only zero extend/truncate integers!");
1583  Type *VTy = V->getType();
1584  if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
1585  return CreateZExt(V, DestTy, Name);
1586  if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
1587  return CreateTrunc(V, DestTy, Name);
1588  return V;
1589  }
1590 
1591  /// Create a SExt or Trunc from the integer value V to DestTy. Return
1592  /// the value untouched if the type of V is already DestTy.
1594  const Twine &Name = "") {
1595  assert(V->getType()->isIntOrIntVectorTy() &&
1596  DestTy->isIntOrIntVectorTy() &&
1597  "Can only sign extend/truncate integers!");
1598  Type *VTy = V->getType();
1599  if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
1600  return CreateSExt(V, DestTy, Name);
1601  if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
1602  return CreateTrunc(V, DestTy, Name);
1603  return V;
1604  }
1605 
1606  Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = ""){
1607  return CreateCast(Instruction::FPToUI, V, DestTy, Name);
1608  }
1609 
1610  Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = ""){
1611  return CreateCast(Instruction::FPToSI, V, DestTy, Name);
1612  }
1613 
1614  Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
1615  return CreateCast(Instruction::UIToFP, V, DestTy, Name);
1616  }
1617 
1618  Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
1619  return CreateCast(Instruction::SIToFP, V, DestTy, Name);
1620  }
1621 
1623  const Twine &Name = "") {
1624  return CreateCast(Instruction::FPTrunc, V, DestTy, Name);
1625  }
1626 
1627  Value *CreateFPExt(Value *V, Type *DestTy, const Twine &Name = "") {
1628  return CreateCast(Instruction::FPExt, V, DestTy, Name);
1629  }
1630 
1632  const Twine &Name = "") {
1633  return CreateCast(Instruction::PtrToInt, V, DestTy, Name);
1634  }
1635 
1637  const Twine &Name = "") {
1638  return CreateCast(Instruction::IntToPtr, V, DestTy, Name);
1639  }
1640 
1642  const Twine &Name = "") {
1643  return CreateCast(Instruction::BitCast, V, DestTy, Name);
1644  }
1645 
1647  const Twine &Name = "") {
1648  return CreateCast(Instruction::AddrSpaceCast, V, DestTy, Name);
1649  }
1650 
1652  const Twine &Name = "") {
1653  if (V->getType() == DestTy)
1654  return V;
1655  if (auto *VC = dyn_cast<Constant>(V))
1656  return Insert(Folder.CreateZExtOrBitCast(VC, DestTy), Name);
1657  return Insert(CastInst::CreateZExtOrBitCast(V, DestTy), Name);
1658  }
1659 
1661  const Twine &Name = "") {
1662  if (V->getType() == DestTy)
1663  return V;
1664  if (auto *VC = dyn_cast<Constant>(V))
1665  return Insert(Folder.CreateSExtOrBitCast(VC, DestTy), Name);
1666  return Insert(CastInst::CreateSExtOrBitCast(V, DestTy), Name);
1667  }
1668 
1670  const Twine &Name = "") {
1671  if (V->getType() == DestTy)
1672  return V;
1673  if (auto *VC = dyn_cast<Constant>(V))
1674  return Insert(Folder.CreateTruncOrBitCast(VC, DestTy), Name);
1675  return Insert(CastInst::CreateTruncOrBitCast(V, DestTy), Name);
1676  }
1677 
1679  const Twine &Name = "") {
1680  if (V->getType() == DestTy)
1681  return V;
1682  if (auto *VC = dyn_cast<Constant>(V))
1683  return Insert(Folder.CreateCast(Op, VC, DestTy), Name);
1684  return Insert(CastInst::Create(Op, V, DestTy), Name);
1685  }
1686 
1688  const Twine &Name = "") {
1689  if (V->getType() == DestTy)
1690  return V;
1691  if (auto *VC = dyn_cast<Constant>(V))
1692  return Insert(Folder.CreatePointerCast(VC, DestTy), Name);
1693  return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
1694  }
1695 
1697  const Twine &Name = "") {
1698  if (V->getType() == DestTy)
1699  return V;
1700 
1701  if (auto *VC = dyn_cast<Constant>(V)) {
1702  return Insert(Folder.CreatePointerBitCastOrAddrSpaceCast(VC, DestTy),
1703  Name);
1704  }
1705 
1706  return Insert(CastInst::CreatePointerBitCastOrAddrSpaceCast(V, DestTy),
1707  Name);
1708  }
1709 
1710  Value *CreateIntCast(Value *V, Type *DestTy, bool isSigned,
1711  const Twine &Name = "") {
1712  if (V->getType() == DestTy)
1713  return V;
1714  if (auto *VC = dyn_cast<Constant>(V))
1715  return Insert(Folder.CreateIntCast(VC, DestTy, isSigned), Name);
1716  return Insert(CastInst::CreateIntegerCast(V, DestTy, isSigned), Name);
1717  }
1718 
1720  const Twine &Name = "") {
1721  if (V->getType() == DestTy)
1722  return V;
1723  if (V->getType()->isPtrOrPtrVectorTy() && DestTy->isIntOrIntVectorTy())
1724  return CreatePtrToInt(V, DestTy, Name);
1725  if (V->getType()->isIntOrIntVectorTy() && DestTy->isPtrOrPtrVectorTy())
1726  return CreateIntToPtr(V, DestTy, Name);
1727 
1728  return CreateBitCast(V, DestTy, Name);
1729  }
1730 
1731  Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "") {
1732  if (V->getType() == DestTy)
1733  return V;
1734  if (auto *VC = dyn_cast<Constant>(V))
1735  return Insert(Folder.CreateFPCast(VC, DestTy), Name);
1736  return Insert(CastInst::CreateFPCast(V, DestTy), Name);
1737  }
1738 
1739  // Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a
1740  // compile time error, instead of converting the string to bool for the
1741  // isSigned parameter.
1742  Value *CreateIntCast(Value *, Type *, const char *) = delete;
1743 
1744  //===--------------------------------------------------------------------===//
1745  // Instruction creation methods: Compare Instructions
1746  //===--------------------------------------------------------------------===//
1747 
1748  Value *CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
1749  return CreateICmp(ICmpInst::ICMP_EQ, LHS, RHS, Name);
1750  }
1751 
1752  Value *CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name = "") {
1753  return CreateICmp(ICmpInst::ICMP_NE, LHS, RHS, Name);
1754  }
1755 
1756  Value *CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name = "") {
1757  return CreateICmp(ICmpInst::ICMP_UGT, LHS, RHS, Name);
1758  }
1759 
1760  Value *CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name = "") {
1761  return CreateICmp(ICmpInst::ICMP_UGE, LHS, RHS, Name);
1762  }
1763 
1764  Value *CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name = "") {
1765  return CreateICmp(ICmpInst::ICMP_ULT, LHS, RHS, Name);
1766  }
1767 
1768  Value *CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name = "") {
1769  return CreateICmp(ICmpInst::ICMP_ULE, LHS, RHS, Name);
1770  }
1771 
1772  Value *CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name = "") {
1773  return CreateICmp(ICmpInst::ICMP_SGT, LHS, RHS, Name);
1774  }
1775 
1776  Value *CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name = "") {
1777  return CreateICmp(ICmpInst::ICMP_SGE, LHS, RHS, Name);
1778  }
1779 
1780  Value *CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name = "") {
1781  return CreateICmp(ICmpInst::ICMP_SLT, LHS, RHS, Name);
1782  }
1783 
1784  Value *CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name = "") {
1785  return CreateICmp(ICmpInst::ICMP_SLE, LHS, RHS, Name);
1786  }
1787 
1788  Value *CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name = "",
1789  MDNode *FPMathTag = nullptr) {
1790  return CreateFCmp(FCmpInst::FCMP_OEQ, LHS, RHS, Name, FPMathTag);
1791  }
1792 
1793  Value *CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name = "",
1794  MDNode *FPMathTag = nullptr) {
1795  return CreateFCmp(FCmpInst::FCMP_OGT, LHS, RHS, Name, FPMathTag);
1796  }
1797 
1798  Value *CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name = "",
1799  MDNode *FPMathTag = nullptr) {
1800  return CreateFCmp(FCmpInst::FCMP_OGE, LHS, RHS, Name, FPMathTag);
1801  }
1802 
1803  Value *CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name = "",
1804  MDNode *FPMathTag = nullptr) {
1805  return CreateFCmp(FCmpInst::FCMP_OLT, LHS, RHS, Name, FPMathTag);
1806  }
1807 
1808  Value *CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name = "",
1809  MDNode *FPMathTag = nullptr) {
1810  return CreateFCmp(FCmpInst::FCMP_OLE, LHS, RHS, Name, FPMathTag);
1811  }
1812 
1813  Value *CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name = "",
1814  MDNode *FPMathTag = nullptr) {
1815  return CreateFCmp(FCmpInst::FCMP_ONE, LHS, RHS, Name, FPMathTag);
1816  }
1817 
1818  Value *CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name = "",
1819  MDNode *FPMathTag = nullptr) {
1820  return CreateFCmp(FCmpInst::FCMP_ORD, LHS, RHS, Name, FPMathTag);
1821  }
1822 
1823  Value *CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name = "",
1824  MDNode *FPMathTag = nullptr) {
1825  return CreateFCmp(FCmpInst::FCMP_UNO, LHS, RHS, Name, FPMathTag);
1826  }
1827 
1828  Value *CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name = "",
1829  MDNode *FPMathTag = nullptr) {
1830  return CreateFCmp(FCmpInst::FCMP_UEQ, LHS, RHS, Name, FPMathTag);
1831  }
1832 
1833  Value *CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name = "",
1834  MDNode *FPMathTag = nullptr) {
1835  return CreateFCmp(FCmpInst::FCMP_UGT, LHS, RHS, Name, FPMathTag);
1836  }
1837 
1838  Value *CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name = "",
1839  MDNode *FPMathTag = nullptr) {
1840  return CreateFCmp(FCmpInst::FCMP_UGE, LHS, RHS, Name, FPMathTag);
1841  }
1842 
1843  Value *CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name = "",
1844  MDNode *FPMathTag = nullptr) {
1845  return CreateFCmp(FCmpInst::FCMP_ULT, LHS, RHS, Name, FPMathTag);
1846  }
1847 
1848  Value *CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name = "",
1849  MDNode *FPMathTag = nullptr) {
1850  return CreateFCmp(FCmpInst::FCMP_ULE, LHS, RHS, Name, FPMathTag);
1851  }
1852 
1853  Value *CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name = "",
1854  MDNode *FPMathTag = nullptr) {
1855  return CreateFCmp(FCmpInst::FCMP_UNE, LHS, RHS, Name, FPMathTag);
1856  }
1857 
1859  const Twine &Name = "") {
1860  if (auto *LC = dyn_cast<Constant>(LHS))
1861  if (auto *RC = dyn_cast<Constant>(RHS))
1862  return Insert(Folder.CreateICmp(P, LC, RC), Name);
1863  return Insert(new ICmpInst(P, LHS, RHS), Name);
1864  }
1865 
1867  const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1868  if (auto *LC = dyn_cast<Constant>(LHS))
1869  if (auto *RC = dyn_cast<Constant>(RHS))
1870  return Insert(Folder.CreateFCmp(P, LC, RC), Name);
1871  return Insert(setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMF), Name);
1872  }
1873 
1874  //===--------------------------------------------------------------------===//
1875  // Instruction creation methods: Other Instructions
1876  //===--------------------------------------------------------------------===//
1877 
1878  PHINode *CreatePHI(Type *Ty, unsigned NumReservedValues,
1879  const Twine &Name = "") {
1880  return Insert(PHINode::Create(Ty, NumReservedValues), Name);
1881  }
1882 
1884  const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1885  auto *PTy = cast<PointerType>(Callee->getType());
1886  auto *FTy = cast<FunctionType>(PTy->getElementType());
1887  return CreateCall(FTy, Callee, Args, Name, FPMathTag);
1888  }
1889 
1891  ArrayRef<Value *> Args, const Twine &Name = "",
1892  MDNode *FPMathTag = nullptr) {
1893  CallInst *CI = CallInst::Create(FTy, Callee, Args, DefaultOperandBundles);
1894  if (isa<FPMathOperator>(CI))
1895  CI = cast<CallInst>(setFPAttrs(CI, FPMathTag, FMF));
1896  return Insert(CI, Name);
1897  }
1898 
1900  ArrayRef<OperandBundleDef> OpBundles,
1901  const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1902  CallInst *CI = CallInst::Create(Callee, Args, OpBundles);
1903  if (isa<FPMathOperator>(CI))
1904  CI = cast<CallInst>(setFPAttrs(CI, FPMathTag, FMF));
1905  return Insert(CI, Name);
1906  }
1907 
1909  const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1910  return CreateCall(Callee->getFunctionType(), Callee, Args, Name, FPMathTag);
1911  }
1912 
1913  Value *CreateSelect(Value *C, Value *True, Value *False,
1914  const Twine &Name = "", Instruction *MDFrom = nullptr) {
1915  if (auto *CC = dyn_cast<Constant>(C))
1916  if (auto *TC = dyn_cast<Constant>(True))
1917  if (auto *FC = dyn_cast<Constant>(False))
1918  return Insert(Folder.CreateSelect(CC, TC, FC), Name);
1919 
1920  SelectInst *Sel = SelectInst::Create(C, True, False);
1921  if (MDFrom) {
1922  MDNode *Prof = MDFrom->getMetadata(LLVMContext::MD_prof);
1923  MDNode *Unpred = MDFrom->getMetadata(LLVMContext::MD_unpredictable);
1924  Sel = addBranchMetadata(Sel, Prof, Unpred);
1925  }
1926  return Insert(Sel, Name);
1927  }
1928 
1929  VAArgInst *CreateVAArg(Value *List, Type *Ty, const Twine &Name = "") {
1930  return Insert(new VAArgInst(List, Ty), Name);
1931  }
1932 
1934  const Twine &Name = "") {
1935  if (auto *VC = dyn_cast<Constant>(Vec))
1936  if (auto *IC = dyn_cast<Constant>(Idx))
1937  return Insert(Folder.CreateExtractElement(VC, IC), Name);
1938  return Insert(ExtractElementInst::Create(Vec, Idx), Name);
1939  }
1940 
1941  Value *CreateExtractElement(Value *Vec, uint64_t Idx,
1942  const Twine &Name = "") {
1943  return CreateExtractElement(Vec, getInt64(Idx), Name);
1944  }
1945 
1947  const Twine &Name = "") {
1948  if (auto *VC = dyn_cast<Constant>(Vec))
1949  if (auto *NC = dyn_cast<Constant>(NewElt))
1950  if (auto *IC = dyn_cast<Constant>(Idx))
1951  return Insert(Folder.CreateInsertElement(VC, NC, IC), Name);
1952  return Insert(InsertElementInst::Create(Vec, NewElt, Idx), Name);
1953  }
1954 
1955  Value *CreateInsertElement(Value *Vec, Value *NewElt, uint64_t Idx,
1956  const Twine &Name = "") {
1957  return CreateInsertElement(Vec, NewElt, getInt64(Idx), Name);
1958  }
1959 
1961  const Twine &Name = "") {
1962  if (auto *V1C = dyn_cast<Constant>(V1))
1963  if (auto *V2C = dyn_cast<Constant>(V2))
1964  if (auto *MC = dyn_cast<Constant>(Mask))
1965  return Insert(Folder.CreateShuffleVector(V1C, V2C, MC), Name);
1966  return Insert(new ShuffleVectorInst(V1, V2, Mask), Name);
1967  }
1968 
1970  const Twine &Name = "") {
1972  return CreateShuffleVector(V1, V2, Mask, Name);
1973  }
1974 
1976  ArrayRef<unsigned> Idxs,
1977  const Twine &Name = "") {
1978  if (auto *AggC = dyn_cast<Constant>(Agg))
1979  return Insert(Folder.CreateExtractValue(AggC, Idxs), Name);
1980  return Insert(ExtractValueInst::Create(Agg, Idxs), Name);
1981  }
1982 
1984  ArrayRef<unsigned> Idxs,
1985  const Twine &Name = "") {
1986  if (auto *AggC = dyn_cast<Constant>(Agg))
1987  if (auto *ValC = dyn_cast<Constant>(Val))
1988  return Insert(Folder.CreateInsertValue(AggC, ValC, Idxs), Name);
1989  return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name);
1990  }
1991 
1992  LandingPadInst *CreateLandingPad(Type *Ty, unsigned NumClauses,
1993  const Twine &Name = "") {
1994  return Insert(LandingPadInst::Create(Ty, NumClauses), Name);
1995  }
1996 
1997  //===--------------------------------------------------------------------===//
1998  // Utility creation methods
1999  //===--------------------------------------------------------------------===//
2000 
2001  /// Return an i1 value testing if \p Arg is null.
2002  Value *CreateIsNull(Value *Arg, const Twine &Name = "") {
2003  return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()),
2004  Name);
2005  }
2006 
2007  /// Return an i1 value testing if \p Arg is not null.
2008  Value *CreateIsNotNull(Value *Arg, const Twine &Name = "") {
2009  return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()),
2010  Name);
2011  }
2012 
2013  /// Return the i64 difference between two pointer values, dividing out
2014  /// the size of the pointed-to objects.
2015  ///
2016  /// This is intended to implement C-style pointer subtraction. As such, the
2017  /// pointers must be appropriately aligned for their element types and
2018  /// pointing into the same object.
2019  Value *CreatePtrDiff(Value *LHS, Value *RHS, const Twine &Name = "") {
2020  assert(LHS->getType() == RHS->getType() &&
2021  "Pointer subtraction operand types must match!");
2022  auto *ArgType = cast<PointerType>(LHS->getType());
2023  Value *LHS_int = CreatePtrToInt(LHS, Type::getInt64Ty(Context));
2024  Value *RHS_int = CreatePtrToInt(RHS, Type::getInt64Ty(Context));
2025  Value *Difference = CreateSub(LHS_int, RHS_int);
2026  return CreateExactSDiv(Difference,
2027  ConstantExpr::getSizeOf(ArgType->getElementType()),
2028  Name);
2029  }
2030 
2031  /// Create a launder.invariant.group intrinsic call. If Ptr type is
2032  /// different from pointer to i8, it's casted to pointer to i8 in the same
2033  /// address space before call and casted back to Ptr type after call.
2035  assert(isa<PointerType>(Ptr->getType()) &&
2036  "launder.invariant.group only applies to pointers.");
2037  // FIXME: we could potentially avoid casts to/from i8*.
2038  auto *PtrType = Ptr->getType();
2039  auto *Int8PtrTy = getInt8PtrTy(PtrType->getPointerAddressSpace());
2040  if (PtrType != Int8PtrTy)
2041  Ptr = CreateBitCast(Ptr, Int8PtrTy);
2042  Module *M = BB->getParent()->getParent();
2043  Function *FnLaunderInvariantGroup = Intrinsic::getDeclaration(
2044  M, Intrinsic::launder_invariant_group, {Int8PtrTy});
2045 
2046  assert(FnLaunderInvariantGroup->getReturnType() == Int8PtrTy &&
2047  FnLaunderInvariantGroup->getFunctionType()->getParamType(0) ==
2048  Int8PtrTy &&
2049  "LaunderInvariantGroup should take and return the same type");
2050 
2051  CallInst *Fn = CreateCall(FnLaunderInvariantGroup, {Ptr});
2052 
2053  if (PtrType != Int8PtrTy)
2054  return CreateBitCast(Fn, PtrType);
2055  return Fn;
2056  }
2057 
2058  /// \brief Create a strip.invariant.group intrinsic call. If Ptr type is
2059  /// different from pointer to i8, it's casted to pointer to i8 in the same
2060  /// address space before call and casted back to Ptr type after call.
2062  assert(isa<PointerType>(Ptr->getType()) &&
2063  "strip.invariant.group only applies to pointers.");
2064 
2065  // FIXME: we could potentially avoid casts to/from i8*.
2066  auto *PtrType = Ptr->getType();
2067  auto *Int8PtrTy = getInt8PtrTy(PtrType->getPointerAddressSpace());
2068  if (PtrType != Int8PtrTy)
2069  Ptr = CreateBitCast(Ptr, Int8PtrTy);
2070  Module *M = BB->getParent()->getParent();
2071  Function *FnStripInvariantGroup = Intrinsic::getDeclaration(
2072  M, Intrinsic::strip_invariant_group, {Int8PtrTy});
2073 
2074  assert(FnStripInvariantGroup->getReturnType() == Int8PtrTy &&
2075  FnStripInvariantGroup->getFunctionType()->getParamType(0) ==
2076  Int8PtrTy &&
2077  "StripInvariantGroup should take and return the same type");
2078 
2079  CallInst *Fn = CreateCall(FnStripInvariantGroup, {Ptr});
2080 
2081  if (PtrType != Int8PtrTy)
2082  return CreateBitCast(Fn, PtrType);
2083  return Fn;
2084  }
2085 
2086  /// Return a vector value that contains \arg V broadcasted to \p
2087  /// NumElts elements.
2088  Value *CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name = "") {
2089  assert(NumElts > 0 && "Cannot splat to an empty vector!");
2090 
2091  // First insert it into an undef vector so we can shuffle it.
2092  Type *I32Ty = getInt32Ty();
2093  Value *Undef = UndefValue::get(VectorType::get(V->getType(), NumElts));
2094  V = CreateInsertElement(Undef, V, ConstantInt::get(I32Ty, 0),
2095  Name + ".splatinsert");
2096 
2097  // Shuffle the value across the desired number of elements.
2098  Value *Zeros = ConstantAggregateZero::get(VectorType::get(I32Ty, NumElts));
2099  return CreateShuffleVector(V, Undef, Zeros, Name + ".splat");
2100  }
2101 
2102  /// Return a value that has been extracted from a larger integer type.
2104  IntegerType *ExtractedTy, uint64_t Offset,
2105  const Twine &Name) {
2106  auto *IntTy = cast<IntegerType>(From->getType());
2107  assert(DL.getTypeStoreSize(ExtractedTy) + Offset <=
2108  DL.getTypeStoreSize(IntTy) &&
2109  "Element extends past full value");
2110  uint64_t ShAmt = 8 * Offset;
2111  Value *V = From;
2112  if (DL.isBigEndian())
2113  ShAmt = 8 * (DL.getTypeStoreSize(IntTy) -
2114  DL.getTypeStoreSize(ExtractedTy) - Offset);
2115  if (ShAmt) {
2116  V = CreateLShr(V, ShAmt, Name + ".shift");
2117  }
2118  assert(ExtractedTy->getBitWidth() <= IntTy->getBitWidth() &&
2119  "Cannot extract to a larger integer!");
2120  if (ExtractedTy != IntTy) {
2121  V = CreateTrunc(V, ExtractedTy, Name + ".trunc");
2122  }
2123  return V;
2124  }
2125 
2126 private:
2127  /// Helper function that creates an assume intrinsic call that
2128  /// represents an alignment assumption on the provided Ptr, Mask, Type
2129  /// and Offset.
2130  CallInst *CreateAlignmentAssumptionHelper(const DataLayout &DL,
2131  Value *PtrValue, Value *Mask,
2132  Type *IntPtrTy,
2133  Value *OffsetValue) {
2134  Value *PtrIntValue = CreatePtrToInt(PtrValue, IntPtrTy, "ptrint");
2135 
2136  if (OffsetValue) {
2137  bool IsOffsetZero = false;
2138  if (const auto *CI = dyn_cast<ConstantInt>(OffsetValue))
2139  IsOffsetZero = CI->isZero();
2140 
2141  if (!IsOffsetZero) {
2142  if (OffsetValue->getType() != IntPtrTy)
2143  OffsetValue = CreateIntCast(OffsetValue, IntPtrTy, /*isSigned*/ true,
2144  "offsetcast");
2145  PtrIntValue = CreateSub(PtrIntValue, OffsetValue, "offsetptr");
2146  }
2147  }
2148 
2149  Value *Zero = ConstantInt::get(IntPtrTy, 0);
2150  Value *MaskedPtr = CreateAnd(PtrIntValue, Mask, "maskedptr");
2151  Value *InvCond = CreateICmpEQ(MaskedPtr, Zero, "maskcond");
2152  return CreateAssumption(InvCond);
2153  }
2154 
2155 public:
2156  /// Create an assume intrinsic call that represents an alignment
2157  /// assumption on the provided pointer.
2158  ///
2159  /// An optional offset can be provided, and if it is provided, the offset
2160  /// must be subtracted from the provided pointer to get the pointer with the
2161  /// specified alignment.
2163  unsigned Alignment,
2164  Value *OffsetValue = nullptr) {
2165  assert(isa<PointerType>(PtrValue->getType()) &&
2166  "trying to create an alignment assumption on a non-pointer?");
2167  auto *PtrTy = cast<PointerType>(PtrValue->getType());
2168  Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
2169 
2170  Value *Mask = ConstantInt::get(IntPtrTy, Alignment > 0 ? Alignment - 1 : 0);
2171  return CreateAlignmentAssumptionHelper(DL, PtrValue, Mask, IntPtrTy,
2172  OffsetValue);
2173  }
2174 
2175  /// Create an assume intrinsic call that represents an alignment
2176  /// assumption on the provided pointer.
2177  ///
2178  /// An optional offset can be provided, and if it is provided, the offset
2179  /// must be subtracted from the provided pointer to get the pointer with the
2180  /// specified alignment.
2181  ///
2182  /// This overload handles the condition where the Alignment is dependent
2183  /// on an existing value rather than a static value.
2185  Value *Alignment,
2186  Value *OffsetValue = nullptr) {
2187  assert(isa<PointerType>(PtrValue->getType()) &&
2188  "trying to create an alignment assumption on a non-pointer?");
2189  auto *PtrTy = cast<PointerType>(PtrValue->getType());
2190  Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
2191 
2192  if (Alignment->getType() != IntPtrTy)
2193  Alignment = CreateIntCast(Alignment, IntPtrTy, /*isSigned*/ true,
2194  "alignmentcast");
2195  Value *IsPositive =
2196  CreateICmp(CmpInst::ICMP_SGT, Alignment,
2197  ConstantInt::get(Alignment->getType(), 0), "ispositive");
2198  Value *PositiveMask =
2199  CreateSub(Alignment, ConstantInt::get(IntPtrTy, 1), "positivemask");
2200  Value *Mask = CreateSelect(IsPositive, PositiveMask,
2201  ConstantInt::get(IntPtrTy, 0), "mask");
2202 
2203  return CreateAlignmentAssumptionHelper(DL, PtrValue, Mask, IntPtrTy,
2204  OffsetValue);
2205  }
2206 };
2207 
2208 // Create wrappers for C Binding types (see CBindingWrapping.h).
2210 
2211 } // end namespace llvm
2212 
2213 #endif // LLVM_IR_IRBUILDER_H
IntegerType * getInt16Ty()
Fetch the type representing a 16-bit integer.
Definition: IRBuilder.h:342
Value * CreateInsertElement(Value *Vec, Value *NewElt, uint64_t Idx, const Twine &Name="")
Definition: IRBuilder.h:1955
Value * CreateNSWNeg(Value *V, const Twine &Name="")
Definition: IRBuilder.h:1278
Value * CreateConstInBoundsGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0, const Twine &Name="")
Definition: IRBuilder.h:1458
Value * CreateInBoundsGEP(Value *Ptr, ArrayRef< Value *> IdxList, const Twine &Name="")
Definition: IRBuilder.h:1405
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:89
uint64_t CallInst * C
Return a value (possibly void), from a function.
Value * CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1114
Value * CreateInBoundsGEP(Type *Ty, Value *Ptr, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:1436
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
static ConstantInt * getFalse(LLVMContext &Context)
Definition: Constants.cpp:585
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a conditional &#39;br Cond, TrueDest, FalseDest&#39; instruction.
Definition: IRBuilder.h:854
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1858
Value * CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name="")
Definition: IRBuilder.h:1444
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
static Type * getDoubleTy(LLVMContext &C)
Definition: Type.cpp:165
static IntegerType * getInt1Ty(LLVMContext &C)
Definition: Type.cpp:173
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T &F, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=None)
Definition: IRBuilder.h:775
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1258
Value * CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0, const Twine &Name="")
Definition: IRBuilder.h:1448
FastMathFlags getFastMathFlags() const
Get the flags to be applied to created floating point ops.
Definition: IRBuilder.h:211
LLVMContext & Context
LLVMContext & getContext() const
Definition: IRBuilder.h:123
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
Definition: IRBuilder.h:1304
static BinaryOperator * CreateNot(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1752
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return an i1 value testing if Arg is not null.
Definition: IRBuilder.h:2008
Atomic ordering constants.
Value * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1646
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
Definition: IRBuilder.h:1578
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Value * CreateFPTrunc(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1622
Type * getParamType(unsigned i) const
Parameter type accessors.
Definition: DerivedTypes.h:135
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1764
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value *> Args, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1890
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1160
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
static ResumeInst * Create(Value *Exn, Instruction *InsertBefore=nullptr)
CallInst * CreateCall(Value *Callee, ArrayRef< Value *> Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1899
An instruction for ordering other memory operations.
Definition: Instructions.h:444
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:518
CallInst * CreateElementUnorderedAtomicMemMove(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign, uint64_t Size, uint32_t ElementSize, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert an element unordered-atomic memmove between the specified pointers.
Definition: IRBuilder.h:516
FastMathFlags FMF
Definition: IRBuilder.h:98
Value * CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1808
bool isSet() const
Returns true if this insert point is set.
Definition: IRBuilder.h:181
LoadInst * CreateLoad(Value *Ptr, bool isVolatile, const Twine &Name="")
Definition: IRBuilder.h:1329
Value * CreateShl(Value *LHS, uint64_t RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1078
static ConstantAggregateZero * get(Type *Ty)
Definition: Constants.cpp:1332
Value * CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:987
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:2103
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value *> IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:869
Value * CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1780
This class represents a function call, abstracting a target machine&#39;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:1468
unsigned less or equal
Definition: InstrTypes.h:668
unsigned less than
Definition: InstrTypes.h:667
IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=None)
Definition: IRBuilder.h:763
0 1 0 0 True if ordered and less than
Definition: InstrTypes.h:648
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)
1 1 1 0 True if unordered or not equal
Definition: InstrTypes.h:658
Value * CreateFRemFMF(Value *L, Value *R, Instruction *FMFSource, const Twine &Name="")
Copy fast-math-flags from an instruction rather than using the builder&#39;s default FMF.
Definition: IRBuilder.h:1250
struct LLVMOpaqueBuilder * LLVMBuilderRef
Represents an LLVM basic block builder.
Definition: Types.h:111
Value * CreateSExt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1572
A debug info location.
Definition: DebugLoc.h:34
Metadata node.
Definition: Metadata.h:864
F(f)
static CallInst * Create(Value *Func, ArrayRef< Value *> Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Value * CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1838
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
An instruction for reading from memory.
Definition: Instructions.h:168
Value * CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1823
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:177
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Definition: Instructions.h:681
LLVM_READONLY APFloat maximum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2018 maximum semantics.
Definition: APFloat.h:1262
Value * CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1768
Value * CreateShuffleVector(Value *V1, Value *V2, ArrayRef< uint32_t > IntMask, const Twine &Name="")
Definition: IRBuilder.h:1969
static IntegerType * getInt16Ty(LLVMContext &C)
Definition: Type.cpp:175
CallInst * CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue, Value *Alignment, Value *OffsetValue=nullptr)
Create an assume intrinsic call that represents an alignment assumption on the provided pointer...
Definition: IRBuilder.h:2184
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 * CreateLaunderInvariantGroup(Value *Ptr)
Create a launder.invariant.group intrinsic call.
Definition: IRBuilder.h:2034
Value * CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:983
static Constant * getNullValue(Type *Ty)
Constructor to create a &#39;0&#39; constant of arbitrary type.
Definition: Constants.cpp:265
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, unsigned Align, bool isVolatile=false)
Definition: IRBuilder.h:1358
Value * CreateNot(Value *V, const Twine &Name="")
Definition: IRBuilder.h:1294
LLVMContext & Context
Definition: IRBuilder.h:95
Value * CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1833
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:653
Value * CreateOr(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition: IRBuilder.h:1156
AllocaInst * CreateAlloca(Type *Ty, Value *ArraySize=nullptr, const Twine &Name="")
Definition: IRBuilder.h:1309
unsigned getAllocaAddrSpace() const
Definition: DataLayout.h:258
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:652
amdgpu Simplify well known AMD library false Value Value const Twine & Name
Definition: BitVector.h:938
Value * CreateFRem(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition: IRBuilder.h:1241
Value * CreateFPExt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1627
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
This class represents the LLVM &#39;select&#39; 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:2019
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:1119
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
Definition: IRBuilder.h:352
static Type * getFloatTy(LLVMContext &C)
Definition: Type.cpp:164
LoadInst * CreateLoad(Value *Ptr, const Twine &Name="")
Definition: IRBuilder.h:1321
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:451
CleanupPadInst * CreateCleanupPad(Value *ParentPad, ArrayRef< Value *> Args=None, const Twine &Name="")
Definition: IRBuilder.h:928
Value * CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1660
ReturnInst * CreateRet(Value *V)
Create a &#39;ret <val>&#39; instruction.
Definition: IRBuilder.h:829
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:743
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:649
Value * CreateFAddFMF(Value *L, Value *R, Instruction *FMFSource, const Twine &Name="")
Copy fast-math-flags from an instruction rather than using the builder&#39;s default FMF.
Definition: IRBuilder.h:1182
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:2162
LLVM_READONLY APFloat minimum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2018 minimum semantics.
Definition: APFloat.h:1249
const DebugLoc & getCurrentDebugLocation() const
Get location information used by debugging information.
Definition: IRBuilder.h:154
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:974
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:286
CallInst * CreateMemMove(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign, uint64_t Size, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert a memmove between the specified pointers.
Definition: IRBuilder.h:494
Value * CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1772
ConstantInt * getInt16(uint16_t C)
Get a constant 16-bit value.
Definition: IRBuilder.h:302
Type * getVoidTy()
Fetch the type representing void.
Definition: IRBuilder.h:380
BasicBlock * BB
Definition: IRBuilder.h:93
AtomicOrdering
Atomic ordering for LLVM&#39;s memory model.
CatchReturnInst * CreateCatchRet(CatchPadInst *CatchPad, BasicBlock *BB)
Definition: IRBuilder.h:934
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition: IRBuilder.h:1333
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1636
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:1915
Class to represent function types.
Definition: DerivedTypes.h:103
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1641
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
Value * CreateSExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a SExt or Trunc from the integer value V to DestTy.
Definition: IRBuilder.h:1593
Value * CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1756
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:693
BasicBlock * GetInsertBlock() const
Definition: IRBuilder.h:121
void ClearInsertionPoint()
Clear the insertion point: created instructions will not be inserted into a block.
Definition: IRBuilder.h:116
void SetInstDebugLocation(Instruction *I) const
If this builder has a current debug location, set it on the specified instruction.
Definition: IRBuilder.h:158
This instruction compares its operands according to the predicate given to the constructor.
Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
Definition: IRBuilder.h:2088
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
ConstantFolder - Create constants with minimum, target independent, folding.
AtomicCmpXchgInst * CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, SyncScope::ID SSID=SyncScope::System)
Definition: IRBuilder.h:1372
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:991
Value * CreateSIToFP(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1618
An instruction for storing to memory.
Definition: Instructions.h:310
void SetCurrentDebugLocation(DebugLoc L)
Set location information used by debugging information.
Definition: IRBuilder.h:151
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition: Type.h:203
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1568
IRBuilder(LLVMContext &C, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=None)
Definition: IRBuilder.h:753
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
Definition: DerivedTypes.h:66
Value * CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1788
Value * CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1651
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:1021
static BinaryOperator * CreateAdd(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
Value * CreateXor(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition: IRBuilder.h:1165
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:467
Type * getHalfTy()
Fetch the type representing a 16-bit floating point value.
Definition: IRBuilder.h:365
CallInst * CreateMinNum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the minnum intrinsic.
Definition: IRBuilder.h:699
Value * CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1828
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1142
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:887
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1866
InsertPoint saveAndClearIP()
Returns the current insert point, clearing it in the process.
Definition: IRBuilder.h:193
LoadInst * CreateLoad(Value *Ptr, const char *Name)
Provided to resolve &#39;CreateLoad(Ptr, "...")&#39; correctly, instead of converting the string to &#39;bool&#39; fo...
Definition: IRBuilder.h:1317
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:742
Type * getDoubleTy()
Fetch the type representing a 64-bit floating point value.
Definition: IRBuilder.h:375
#define P(N)
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:169
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:178
The landingpad instruction holds all of the information necessary to generate correct exception handl...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
IntegerType * getInt128Ty()
Fetch the type representing a 128-bit integer.
Definition: IRBuilder.h:357
Value * CreateFMul(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition: IRBuilder.h:1207
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:308
Value * CreateAShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1104
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:769
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
ConstantInt * getTrue()
Get the constant value for i1 true.
Definition: IRBuilder.h:287
UnreachableInst * CreateUnreachable()
Definition: IRBuilder.h:938
Conditional or Unconditional Branch instruction.
static ExtractValueInst * Create(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
MDNode * getDefaultFPMathTag() const
Get the floating point math metadata being used.
Definition: IRBuilder.h:208
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
This function has undefined behavior.
ConstantInt * getInt1(bool V)
Get a constant value representing either true or false.
Definition: IRBuilder.h:282
Value * CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1049
This is an important base class in LLVM.
Definition: Constant.h:42
InsertPoint saveIP() const
Returns the current insert point.
Definition: IRBuilder.h:188
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:1072
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:1035
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition: IRBuilder.h:1913
Indirect Branch Instruction.
Value * CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1017
Value * CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1793
Value * CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition: IRBuilder.h:1513
Value * CreateFPToUI(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1606
CallInst * CreateMaxNum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the maxnum intrinsic.
Definition: IRBuilder.h:704
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const Twine &Name="")
Definition: IRBuilder.h:1325
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:161
CatchSwitchInst * CreateCatchSwitch(Value *ParentPad, BasicBlock *UnwindBB, unsigned NumHandlers, const Twine &Name="")
Definition: IRBuilder.h:916
Value * CreateFSubFMF(Value *L, Value *R, Instruction *FMFSource, const Twine &Name="")
Copy fast-math-flags from an instruction rather than using the builder&#39;s default FMF.
Definition: IRBuilder.h:1199
Value * CreateFDivFMF(Value *L, Value *R, Instruction *FMFSource, const Twine &Name="")
Copy fast-math-flags from an instruction rather than using the builder&#39;s default FMF.
Definition: IRBuilder.h:1233
VAArgInst * CreateVAArg(Value *List, Type *Ty, const Twine &Name="")
Definition: IRBuilder.h:1929
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1268
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:642
IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=None)
Definition: IRBuilder.h:757
Value * CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1776
A specialization of it&#39;s base class for read-write access to a gc.statepoint.
Definition: Statepoint.h:319
0 1 1 1 True if ordered (no nans)
Definition: InstrTypes.h:651
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
CallInst * CreateCall(Function *Callee, ArrayRef< Value *> Args, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1908
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1748
self_iterator getIterator()
Definition: ilist_node.h:82
Class to represent integer types.
Definition: DerivedTypes.h:40
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:1933
LoadInst * CreateAlignedLoad(Value *Ptr, unsigned Align, bool isVolatile, const Twine &Name="")
Definition: IRBuilder.h:1351
IRBuilderCallbackInserter(std::function< void(Instruction *)> Callback)
Definition: IRBuilder.h:77
void setAlignment(unsigned Align)
Constant * Insert(Constant *C, const Twine &="") const
No-op overload to handle constants.
Definition: IRBuilder.h:801
AtomicRMWInst * CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val, AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Definition: IRBuilder.h:1380
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...
static UndefValue * get(Type *T)
Static factory methods - Return an &#39;undef&#39; object of the specified type.
Definition: Constants.cpp:1415
Value * CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1094
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:790
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition: IRBuilder.h:1975
static CastInst * CreateZExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a ZExt or BitCast cast instruction.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:220
PointerType * getInt8PtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer to an 8-bit integer value.
Definition: IRBuilder.h:385
1 1 0 1 True if unordered, less than, or equal
Definition: InstrTypes.h:657
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1226
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1008
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE maxNum semantics.
Definition: APFloat.h:1238
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1564
static IndirectBrInst * Create(Value *Address, unsigned NumDests, Instruction *InsertBefore=nullptr)
static InvokeInst * Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value *> Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
Value * CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1099
Value * CreateSRem(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1058
signed greater than
Definition: InstrTypes.h:669
Value * CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1853
Value * CreateUIToFP(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1614
Value * CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1798
Value * CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition: IRBuilder.h:1494
This provides the default implementation of the IRBuilder &#39;InsertHelper&#39; method that is called whenev...
Definition: IRBuilder.h:62
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
Definition: IRBuilder.h:1878
Value * CreateGEP(Value *Ptr, ArrayRef< Value *> IdxList, const Twine &Name="")
Definition: IRBuilder.h:1386
Value * CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1803
0 0 1 0 True if ordered and greater than
Definition: InstrTypes.h:646
static BinaryOperator * CreateFNeg(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
static Type * getHalfTy(LLVMContext &C)
Definition: Type.cpp:163
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition: Type.h:227
const InstListType & getInstList() const
Return the underlying instruction list container.
Definition: BasicBlock.h:334
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.
This is the shared class of boolean and integer constants.
Definition: Constants.h:84
ResumeInst * CreateResume(Value *Exn)
Definition: IRBuilder.h:907
BlockVerifier::State From
InsertPoint - A saved insertion point.
Definition: IRBuilder.h:168
CallInst * CreateMinimum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the minimum intrinsic.
Definition: IRBuilder.h:709
static CleanupPadInst * Create(Value *ParentPad, ArrayRef< Value *> Args=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
iterator end()
Definition: BasicBlock.h:271
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:2002
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
Definition: Type.cpp:130
InvokeInst * CreateInvoke(Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value *> Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Definition: IRBuilder.h:899
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Definition: IRBuilder.h:1710
Value * CreateNUWNeg(Value *V, const Twine &Name="")
Definition: IRBuilder.h:1282
Value * CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1760
CallInst * CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val, uint64_t Size, unsigned Align, uint32_t ElementSize, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert an element unordered-atomic memset of the region of memory starting at the given po...
Definition: IRBuilder.h:423
1 1 0 0 True if unordered or less than
Definition: InstrTypes.h:656
Module.h This file contains the declarations for the Module class.
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:1946
AddressSpace
Definition: NVPTXBaseInfo.h:22
signed less than
Definition: InstrTypes.h:671
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:1818
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:1941
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition: Type.cpp:180
Value * CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1813
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
Definition: IRBuilder.h:1960
CallInst * CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign, uint64_t Size, 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:446
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:622
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
Value * CreateConstInBoundsGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition: IRBuilder.h:1503
Value * CreateURem(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1053
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:578
Value handle that asserts if the Value is deleted.
Definition: ValueHandle.h:238
Constant * 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:1551
ArrayRef< OperandBundleDef > DefaultOperandBundles
Definition: IRBuilder.h:100
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:164
Value * CreateFPCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1731
Value * CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition: IRBuilder.h:1138
signed less or equal
Definition: InstrTypes.h:672
Class for arbitrary precision integers.
Definition: APInt.h:70
BasicBlock::iterator getPoint() const
Definition: IRBuilder.h:184
CallInst * CreateMaximum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the maximum intrinsic.
Definition: IRBuilder.h:714
Value * CreateGEP(Value *Ptr, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:1425
Value * CreateSDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1039
Value * CreateUDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1025
Value * CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1021
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:1696
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:90
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:1063
Value * CreatePointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1687
Value * CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition: IRBuilder.h:1526
static CatchPadInst * Create(Value *CatchSwitch, ArrayRef< Value *> Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
amdgpu Simplify well known AMD library false Value Value * Arg
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:1345
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:1719
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:877
Value * CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1669
Value * CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1004
ReturnInst * CreateRetVoid()
Create a &#39;ret void&#39; instruction.
Definition: IRBuilder.h:824
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&#39;s ...
Value * CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1843
Value * CreateGEP(Type *Ty, Value *Ptr, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:1429
Value * CreateGEP(Type *Ty, Value *Ptr, ArrayRef< Value *> IdxList, const Twine &Name="")
Definition: IRBuilder.h:1391
Provides an &#39;InsertHelper&#39; that calls a user-provided callback after performing the default insertion...
Definition: IRBuilder.h:73
iterator insert(iterator where, pointer New)
Definition: ilist.h:228
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:311
FenceInst * CreateFence(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System, const Twine &Name="")
Definition: IRBuilder.h:1365
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:176
Value * CreateXor(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition: IRBuilder.h:1169
static CastInst * CreateTruncOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a Trunc or BitCast cast instruction.
CatchPadInst * CreateCatchPad(Value *ParentPad, ArrayRef< Value *> Args, const Twine &Name="")
Definition: IRBuilder.h:923
unsigned greater or equal
Definition: InstrTypes.h:666
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant *> IdxList)
Create an "inbounds" getelementptr.
Definition: Constants.h:1181
CleanupReturnInst * CreateCleanupRet(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB=nullptr)
Definition: IRBuilder.h:911
const NodeList & List
Definition: RDFGraph.cpp:210
#define I(x, y, z)
Definition: MD5.cpp:58
Value * CreateFSub(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition: IRBuilder.h:1190
#define N
Value * CreateInBoundsGEP(Type *Ty, Value *Ptr, ArrayRef< Value *> IdxList, const Twine &Name="")
Definition: IRBuilder.h:1410
0 1 1 0 True if ordered and operands are unequal
Definition: InstrTypes.h:650
Value * CreateStripInvariantGroup(Value *Ptr)
Create a strip.invariant.group intrinsic call.
Definition: IRBuilder.h:2061
Value * CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="")
Definition: IRBuilder.h:1481
Value * CreateFPToSI(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1610
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
Type * getValueType() const
Definition: GlobalValue.h:276
uint32_t Size
Definition: Profile.cpp:47
void setDefaultFPMathTag(MDNode *FPMathTag)
Set the floating point math metadata to be used.
Definition: IRBuilder.h:217
static BinaryOperator * CreateNeg(Value *S1, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
Type * getFloatTy()
Fetch the type representing a 32-bit floating point value.
Definition: IRBuilder.h:370
1 0 1 0 True if unordered or greater than
Definition: InstrTypes.h:654
Value * CreateFAdd(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition: IRBuilder.h:1173
void InsertHelper(Instruction *I, const Twine &Name, BasicBlock *BB, BasicBlock::iterator InsertPt) const
Definition: IRBuilder.h:81
LandingPadInst * CreateLandingPad(Type *Ty, unsigned NumClauses, const Twine &Name="")
Definition: IRBuilder.h:1992
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1124
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1631
Value * CreateFDiv(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition: IRBuilder.h:1224
InstTy * Insert(InstTy *I, const Twine &Name="") const
Insert and return the specified instruction.
Definition: IRBuilder.h:794
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw 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:1678
static CastInst * CreateSExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a SExt or BitCast cast instruction.
static GetElementPtrInst * CreateInBounds(Value *Ptr, ArrayRef< Value *> IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Create an "inbounds" getelementptr.
Definition: Instructions.h:903
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Value * CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition: IRBuilder.h:1134
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:840
Value * CreateFMulFMF(Value *L, Value *R, Instruction *FMFSource, const Twine &Name="")
Copy fast-math-flags from an instruction rather than using the builder&#39;s default FMF.
Definition: IRBuilder.h:1216
LoadInst * CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name)
Provided to resolve &#39;CreateAlignedLoad(Ptr, Align, "...")&#39; correctly, instead of converting the strin...
Definition: IRBuilder.h:1340
static CatchReturnInst * Create(Value *CatchPad, BasicBlock *BB, Instruction *InsertBefore=nullptr)
0 0 0 1 True if ordered and equal
Definition: InstrTypes.h:645
LLVM Value Representation.
Definition: Value.h:73
void setAlignment(unsigned Align)
1 0 1 1 True if unordered, greater than, or equal
Definition: InstrTypes.h:655
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
Definition: DataLayout.h:411
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, Instruction *MDSrc)
Create a conditional &#39;br Cond, TrueDest, FalseDest&#39; instruction.
Definition: IRBuilder.h:863
BranchInst * CreateBr(BasicBlock *Dest)
Create an unconditional &#39;br label X&#39; instruction.
Definition: IRBuilder.h:848
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:606
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
Synchronized with respect to all concurrently executing threads.
Definition: LLVMContext.h:59
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&#39;s largest value.
Definition: BitmaskEnum.h:81
void InsertHelper(Instruction *I, const Twine &Name, BasicBlock *BB, BasicBlock::iterator InsertPt) const
Definition: IRBuilder.h:64
void setFastMathFlags(FastMathFlags NewFMF)
Set the fast-math flags to be used with generated fp-math operators.
Definition: IRBuilder.h:220
BasicBlock::iterator GetInsertPoint() const
Definition: IRBuilder.h:122
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1084
Value * CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx, const Twine &Name="")
Definition: IRBuilder.h:1540
Invoke instruction.
ConstantInt * getInt8(uint8_t C)
Get a constant 8-bit value.
Definition: IRBuilder.h:297
print Print MemDeps of function
Convenience struct for specifying and reasoning about fast-math flags.
Definition: Operator.h:160
unsigned greater than
Definition: InstrTypes.h:665
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Value * CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1000
static bool isVolatile(Instruction *Inst)
CallInst * CreateElementUnorderedAtomicMemCpy(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign, uint64_t Size, uint32_t ElementSize, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert an element unordered-atomic memcpy between the specified pointers.
Definition: IRBuilder.h:472
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=None)
Definition: IRBuilder.h:782
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition: IRBuilder.h:1983
bool isBigEndian() const
Definition: DataLayout.h:222
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:2584
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:747
ConstantInt * getInt(const APInt &AI)
Get a constant integer value.
Definition: IRBuilder.h:323
static BinaryOperator * CreateMul(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
BasicBlock * getBlock() const
Definition: IRBuilder.h:183
InvokeInst * CreateInvoke(Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value *> Args=None, const Twine &Name="")
Create an invoke instruction.
Definition: IRBuilder.h:892
0 0 1 1 True if ordered and greater than or equal
Definition: InstrTypes.h:647
Value * CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1784
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:174
BasicBlock::iterator InsertPt
Definition: IRBuilder.h:94
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Value * CreateFNeg(Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1286
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
Definition: APFloat.h:1227
Value * CreateOr(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition: IRBuilder.h:1152
signed greater or equal
Definition: InstrTypes.h:670
const BasicBlock * getParent() const
Definition: Instruction.h:67
an instruction to allocate memory on the stack
Definition: Instructions.h:60
Value * CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1848
CallInst * CreateCall(Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1883
Value * CreateStructGEP(Value *Ptr, unsigned Idx, const Twine &Name="")
Definition: IRBuilder.h:1545