LLVM  8.0.1
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.
893  BasicBlock *NormalDest, BasicBlock *UnwindDest,
895  ArrayRef<OperandBundleDef> OpBundles,
896  const Twine &Name = "") {
897  return Insert(
898  InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args, OpBundles),
899  Name);
900  }
902  BasicBlock *NormalDest, BasicBlock *UnwindDest,
904  const Twine &Name = "") {
905  return Insert(InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args),
906  Name);
907  }
908 
910  BasicBlock *UnwindDest, ArrayRef<Value *> Args,
911  ArrayRef<OperandBundleDef> OpBundles,
912  const Twine &Name = "") {
913  return CreateInvoke(Callee->getFunctionType(), Callee, NormalDest,
914  UnwindDest, Args, OpBundles, Name);
915  }
916 
918  BasicBlock *UnwindDest,
920  const Twine &Name = "") {
921  return CreateInvoke(Callee->getFunctionType(), Callee, NormalDest,
922  UnwindDest, Args, Name);
923  }
924 
925  // Deprecated [opaque pointer types]
926  InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
927  BasicBlock *UnwindDest, ArrayRef<Value *> Args,
928  ArrayRef<OperandBundleDef> OpBundles,
929  const Twine &Name = "") {
930  return CreateInvoke(
931  cast<FunctionType>(
932  cast<PointerType>(Callee->getType())->getElementType()),
933  Callee, NormalDest, UnwindDest, Args, OpBundles, Name);
934  }
935 
936  // Deprecated [opaque pointer types]
937  InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
938  BasicBlock *UnwindDest,
940  const Twine &Name = "") {
941  return CreateInvoke(
942  cast<FunctionType>(
943  cast<PointerType>(Callee->getType())->getElementType()),
944  Callee, NormalDest, UnwindDest, Args, Name);
945  }
946 
948  return Insert(ResumeInst::Create(Exn));
949  }
950 
952  BasicBlock *UnwindBB = nullptr) {
953  return Insert(CleanupReturnInst::Create(CleanupPad, UnwindBB));
954  }
955 
957  unsigned NumHandlers,
958  const Twine &Name = "") {
959  return Insert(CatchSwitchInst::Create(ParentPad, UnwindBB, NumHandlers),
960  Name);
961  }
962 
964  const Twine &Name = "") {
965  return Insert(CatchPadInst::Create(ParentPad, Args), Name);
966  }
967 
970  const Twine &Name = "") {
971  return Insert(CleanupPadInst::Create(ParentPad, Args), Name);
972  }
973 
975  return Insert(CatchReturnInst::Create(CatchPad, BB));
976  }
977 
979  return Insert(new UnreachableInst(Context));
980  }
981 
982  //===--------------------------------------------------------------------===//
983  // Instruction creation methods: Binary Operators
984  //===--------------------------------------------------------------------===//
985 private:
986  BinaryOperator *CreateInsertNUWNSWBinOp(BinaryOperator::BinaryOps Opc,
987  Value *LHS, Value *RHS,
988  const Twine &Name,
989  bool HasNUW, bool HasNSW) {
990  BinaryOperator *BO = Insert(BinaryOperator::Create(Opc, LHS, RHS), Name);
991  if (HasNUW) BO->setHasNoUnsignedWrap();
992  if (HasNSW) BO->setHasNoSignedWrap();
993  return BO;
994  }
995 
996  Instruction *setFPAttrs(Instruction *I, MDNode *FPMD,
997  FastMathFlags FMF) const {
998  if (!FPMD)
999  FPMD = DefaultFPMathTag;
1000  if (FPMD)
1002  I->setFastMathFlags(FMF);
1003  return I;
1004  }
1005 
1006  Value *foldConstant(Instruction::BinaryOps Opc, Value *L,
1007  Value *R, const Twine &Name = nullptr) const {
1008  auto *LC = dyn_cast<Constant>(L);
1009  auto *RC = dyn_cast<Constant>(R);
1010  return (LC && RC) ? Insert(Folder.CreateBinOp(Opc, LC, RC), Name) : nullptr;
1011  }
1012 
1013 public:
1014  Value *CreateAdd(Value *LHS, Value *RHS, const Twine &Name = "",
1015  bool HasNUW = false, bool HasNSW = false) {
1016  if (auto *LC = dyn_cast<Constant>(LHS))
1017  if (auto *RC = dyn_cast<Constant>(RHS))
1018  return Insert(Folder.CreateAdd(LC, RC, HasNUW, HasNSW), Name);
1019  return CreateInsertNUWNSWBinOp(Instruction::Add, LHS, RHS, Name,
1020  HasNUW, HasNSW);
1021  }
1022 
1023  Value *CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
1024  return CreateAdd(LHS, RHS, Name, false, true);
1025  }
1026 
1027  Value *CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
1028  return CreateAdd(LHS, RHS, Name, true, false);
1029  }
1030 
1031  Value *CreateSub(Value *LHS, Value *RHS, const Twine &Name = "",
1032  bool HasNUW = false, bool HasNSW = false) {
1033  if (auto *LC = dyn_cast<Constant>(LHS))
1034  if (auto *RC = dyn_cast<Constant>(RHS))
1035  return Insert(Folder.CreateSub(LC, RC, HasNUW, HasNSW), Name);
1036  return CreateInsertNUWNSWBinOp(Instruction::Sub, LHS, RHS, Name,
1037  HasNUW, HasNSW);
1038  }
1039 
1040  Value *CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
1041  return CreateSub(LHS, RHS, Name, false, true);
1042  }
1043 
1044  Value *CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
1045  return CreateSub(LHS, RHS, Name, true, false);
1046  }
1047 
1048  Value *CreateMul(Value *LHS, Value *RHS, const Twine &Name = "",
1049  bool HasNUW = false, bool HasNSW = false) {
1050  if (auto *LC = dyn_cast<Constant>(LHS))
1051  if (auto *RC = dyn_cast<Constant>(RHS))
1052  return Insert(Folder.CreateMul(LC, RC, HasNUW, HasNSW), Name);
1053  return CreateInsertNUWNSWBinOp(Instruction::Mul, LHS, RHS, Name,
1054  HasNUW, HasNSW);
1055  }
1056 
1057  Value *CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
1058  return CreateMul(LHS, RHS, Name, false, true);
1059  }
1060 
1061  Value *CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
1062  return CreateMul(LHS, RHS, Name, true, false);
1063  }
1064 
1065  Value *CreateUDiv(Value *LHS, Value *RHS, const Twine &Name = "",
1066  bool isExact = false) {
1067  if (auto *LC = dyn_cast<Constant>(LHS))
1068  if (auto *RC = dyn_cast<Constant>(RHS))
1069  return Insert(Folder.CreateUDiv(LC, RC, isExact), Name);
1070  if (!isExact)
1071  return Insert(BinaryOperator::CreateUDiv(LHS, RHS), Name);
1072  return Insert(BinaryOperator::CreateExactUDiv(LHS, RHS), Name);
1073  }
1074 
1075  Value *CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
1076  return CreateUDiv(LHS, RHS, Name, true);
1077  }
1078 
1079  Value *CreateSDiv(Value *LHS, Value *RHS, const Twine &Name = "",
1080  bool isExact = false) {
1081  if (auto *LC = dyn_cast<Constant>(LHS))
1082  if (auto *RC = dyn_cast<Constant>(RHS))
1083  return Insert(Folder.CreateSDiv(LC, RC, isExact), Name);
1084  if (!isExact)
1085  return Insert(BinaryOperator::CreateSDiv(LHS, RHS), Name);
1086  return Insert(BinaryOperator::CreateExactSDiv(LHS, RHS), Name);
1087  }
1088 
1089  Value *CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
1090  return CreateSDiv(LHS, RHS, Name, true);
1091  }
1092 
1093  Value *CreateURem(Value *LHS, Value *RHS, const Twine &Name = "") {
1094  if (Value *V = foldConstant(Instruction::URem, LHS, RHS, Name)) return V;
1095  return Insert(BinaryOperator::CreateURem(LHS, RHS), Name);
1096  }
1097 
1098  Value *CreateSRem(Value *LHS, Value *RHS, const Twine &Name = "") {
1099  if (Value *V = foldConstant(Instruction::SRem, LHS, RHS, Name)) return V;
1100  return Insert(BinaryOperator::CreateSRem(LHS, RHS), Name);
1101  }
1102 
1103  Value *CreateShl(Value *LHS, Value *RHS, const Twine &Name = "",
1104  bool HasNUW = false, bool HasNSW = false) {
1105  if (auto *LC = dyn_cast<Constant>(LHS))
1106  if (auto *RC = dyn_cast<Constant>(RHS))
1107  return Insert(Folder.CreateShl(LC, RC, HasNUW, HasNSW), Name);
1108  return CreateInsertNUWNSWBinOp(Instruction::Shl, LHS, RHS, Name,
1109  HasNUW, HasNSW);
1110  }
1111 
1112  Value *CreateShl(Value *LHS, const APInt &RHS, const Twine &Name = "",
1113  bool HasNUW = false, bool HasNSW = false) {
1114  return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1115  HasNUW, HasNSW);
1116  }
1117 
1118  Value *CreateShl(Value *LHS, uint64_t RHS, const Twine &Name = "",
1119  bool HasNUW = false, bool HasNSW = false) {
1120  return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1121  HasNUW, HasNSW);
1122  }
1123 
1124  Value *CreateLShr(Value *LHS, Value *RHS, const Twine &Name = "",
1125  bool isExact = false) {
1126  if (auto *LC = dyn_cast<Constant>(LHS))
1127  if (auto *RC = dyn_cast<Constant>(RHS))
1128  return Insert(Folder.CreateLShr(LC, RC, isExact), Name);
1129  if (!isExact)
1130  return Insert(BinaryOperator::CreateLShr(LHS, RHS), Name);
1131  return Insert(BinaryOperator::CreateExactLShr(LHS, RHS), Name);
1132  }
1133 
1134  Value *CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1135  bool isExact = false) {
1136  return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1137  }
1138 
1139  Value *CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name = "",
1140  bool isExact = false) {
1141  return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1142  }
1143 
1144  Value *CreateAShr(Value *LHS, Value *RHS, const Twine &Name = "",
1145  bool isExact = false) {
1146  if (auto *LC = dyn_cast<Constant>(LHS))
1147  if (auto *RC = dyn_cast<Constant>(RHS))
1148  return Insert(Folder.CreateAShr(LC, RC, isExact), Name);
1149  if (!isExact)
1150  return Insert(BinaryOperator::CreateAShr(LHS, RHS), Name);
1151  return Insert(BinaryOperator::CreateExactAShr(LHS, RHS), Name);
1152  }
1153 
1154  Value *CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1155  bool isExact = false) {
1156  return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1157  }
1158 
1159  Value *CreateAShr(Value *LHS, uint64_t RHS, const Twine &Name = "",
1160  bool isExact = false) {
1161  return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1162  }
1163 
1164  Value *CreateAnd(Value *LHS, Value *RHS, const Twine &Name = "") {
1165  if (auto *RC = dyn_cast<Constant>(RHS)) {
1166  if (isa<ConstantInt>(RC) && cast<ConstantInt>(RC)->isMinusOne())
1167  return LHS; // LHS & -1 -> LHS
1168  if (auto *LC = dyn_cast<Constant>(LHS))
1169  return Insert(Folder.CreateAnd(LC, RC), Name);
1170  }
1171  return Insert(BinaryOperator::CreateAnd(LHS, RHS), Name);
1172  }
1173 
1174  Value *CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1175  return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1176  }
1177 
1178  Value *CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1179  return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1180  }
1181 
1182  Value *CreateOr(Value *LHS, Value *RHS, const Twine &Name = "") {
1183  if (auto *RC = dyn_cast<Constant>(RHS)) {
1184  if (RC->isNullValue())
1185  return LHS; // LHS | 0 -> LHS
1186  if (auto *LC = dyn_cast<Constant>(LHS))
1187  return Insert(Folder.CreateOr(LC, RC), Name);
1188  }
1189  return Insert(BinaryOperator::CreateOr(LHS, RHS), Name);
1190  }
1191 
1192  Value *CreateOr(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1193  return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1194  }
1195 
1196  Value *CreateOr(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1197  return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1198  }
1199 
1200  Value *CreateXor(Value *LHS, Value *RHS, const Twine &Name = "") {
1201  if (Value *V = foldConstant(Instruction::Xor, LHS, RHS, Name)) return V;
1202  return Insert(BinaryOperator::CreateXor(LHS, RHS), Name);
1203  }
1204 
1205  Value *CreateXor(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1206  return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1207  }
1208 
1209  Value *CreateXor(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1210  return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1211  }
1212 
1213  Value *CreateFAdd(Value *L, Value *R, const Twine &Name = "",
1214  MDNode *FPMD = nullptr) {
1215  if (Value *V = foldConstant(Instruction::FAdd, L, R, Name)) return V;
1216  Instruction *I = setFPAttrs(BinaryOperator::CreateFAdd(L, R), FPMD, FMF);
1217  return Insert(I, Name);
1218  }
1219 
1220  /// Copy fast-math-flags from an instruction rather than using the builder's
1221  /// default FMF.
1223  const Twine &Name = "") {
1224  if (Value *V = foldConstant(Instruction::FAdd, L, R, Name)) return V;
1225  Instruction *I = setFPAttrs(BinaryOperator::CreateFAdd(L, R), nullptr,
1226  FMFSource->getFastMathFlags());
1227  return Insert(I, Name);
1228  }
1229 
1230  Value *CreateFSub(Value *L, Value *R, const Twine &Name = "",
1231  MDNode *FPMD = nullptr) {
1232  if (Value *V = foldConstant(Instruction::FSub, L, R, Name)) return V;
1233  Instruction *I = setFPAttrs(BinaryOperator::CreateFSub(L, R), FPMD, FMF);
1234  return Insert(I, Name);
1235  }
1236 
1237  /// Copy fast-math-flags from an instruction rather than using the builder's
1238  /// default FMF.
1240  const Twine &Name = "") {
1241  if (Value *V = foldConstant(Instruction::FSub, L, R, Name)) return V;
1242  Instruction *I = setFPAttrs(BinaryOperator::CreateFSub(L, R), nullptr,
1243  FMFSource->getFastMathFlags());
1244  return Insert(I, Name);
1245  }
1246 
1247  Value *CreateFMul(Value *L, Value *R, const Twine &Name = "",
1248  MDNode *FPMD = nullptr) {
1249  if (Value *V = foldConstant(Instruction::FMul, L, R, Name)) return V;
1250  Instruction *I = setFPAttrs(BinaryOperator::CreateFMul(L, R), FPMD, FMF);
1251  return Insert(I, Name);
1252  }
1253 
1254  /// Copy fast-math-flags from an instruction rather than using the builder's
1255  /// default FMF.
1257  const Twine &Name = "") {
1258  if (Value *V = foldConstant(Instruction::FMul, L, R, Name)) return V;
1259  Instruction *I = setFPAttrs(BinaryOperator::CreateFMul(L, R), nullptr,
1260  FMFSource->getFastMathFlags());
1261  return Insert(I, Name);
1262  }
1263 
1264  Value *CreateFDiv(Value *L, Value *R, const Twine &Name = "",
1265  MDNode *FPMD = nullptr) {
1266  if (Value *V = foldConstant(Instruction::FDiv, L, R, Name)) return V;
1267  Instruction *I = setFPAttrs(BinaryOperator::CreateFDiv(L, R), FPMD, FMF);
1268  return Insert(I, Name);
1269  }
1270 
1271  /// Copy fast-math-flags from an instruction rather than using the builder's
1272  /// default FMF.
1274  const Twine &Name = "") {
1275  if (Value *V = foldConstant(Instruction::FDiv, L, R, Name)) return V;
1276  Instruction *I = setFPAttrs(BinaryOperator::CreateFDiv(L, R), nullptr,
1277  FMFSource->getFastMathFlags());
1278  return Insert(I, Name);
1279  }
1280 
1281  Value *CreateFRem(Value *L, Value *R, const Twine &Name = "",
1282  MDNode *FPMD = nullptr) {
1283  if (Value *V = foldConstant(Instruction::FRem, L, R, Name)) return V;
1284  Instruction *I = setFPAttrs(BinaryOperator::CreateFRem(L, R), FPMD, FMF);
1285  return Insert(I, Name);
1286  }
1287 
1288  /// Copy fast-math-flags from an instruction rather than using the builder's
1289  /// default FMF.
1291  const Twine &Name = "") {
1292  if (Value *V = foldConstant(Instruction::FRem, L, R, Name)) return V;
1293  Instruction *I = setFPAttrs(BinaryOperator::CreateFRem(L, R), nullptr,
1294  FMFSource->getFastMathFlags());
1295  return Insert(I, Name);
1296  }
1297 
1299  Value *LHS, Value *RHS, const Twine &Name = "",
1300  MDNode *FPMathTag = nullptr) {
1301  if (Value *V = foldConstant(Opc, LHS, RHS, Name)) return V;
1302  Instruction *BinOp = BinaryOperator::Create(Opc, LHS, RHS);
1303  if (isa<FPMathOperator>(BinOp))
1304  BinOp = setFPAttrs(BinOp, FPMathTag, FMF);
1305  return Insert(BinOp, Name);
1306  }
1307 
1308  Value *CreateNeg(Value *V, const Twine &Name = "",
1309  bool HasNUW = false, bool HasNSW = false) {
1310  if (auto *VC = dyn_cast<Constant>(V))
1311  return Insert(Folder.CreateNeg(VC, HasNUW, HasNSW), Name);
1312  BinaryOperator *BO = Insert(BinaryOperator::CreateNeg(V), Name);
1313  if (HasNUW) BO->setHasNoUnsignedWrap();
1314  if (HasNSW) BO->setHasNoSignedWrap();
1315  return BO;
1316  }
1317 
1318  Value *CreateNSWNeg(Value *V, const Twine &Name = "") {
1319  return CreateNeg(V, Name, false, true);
1320  }
1321 
1322  Value *CreateNUWNeg(Value *V, const Twine &Name = "") {
1323  return CreateNeg(V, Name, true, false);
1324  }
1325 
1326  Value *CreateFNeg(Value *V, const Twine &Name = "",
1327  MDNode *FPMathTag = nullptr) {
1328  if (auto *VC = dyn_cast<Constant>(V))
1329  return Insert(Folder.CreateFNeg(VC), Name);
1330  return Insert(setFPAttrs(BinaryOperator::CreateFNeg(V), FPMathTag, FMF),
1331  Name);
1332  }
1333 
1334  Value *CreateNot(Value *V, const Twine &Name = "") {
1335  if (auto *VC = dyn_cast<Constant>(V))
1336  return Insert(Folder.CreateNot(VC), Name);
1337  return Insert(BinaryOperator::CreateNot(V), Name);
1338  }
1339 
1340  //===--------------------------------------------------------------------===//
1341  // Instruction creation methods: Memory Instructions
1342  //===--------------------------------------------------------------------===//
1343 
1344  AllocaInst *CreateAlloca(Type *Ty, unsigned AddrSpace,
1345  Value *ArraySize = nullptr, const Twine &Name = "") {
1346  return Insert(new AllocaInst(Ty, AddrSpace, ArraySize), Name);
1347  }
1348 
1349  AllocaInst *CreateAlloca(Type *Ty, Value *ArraySize = nullptr,
1350  const Twine &Name = "") {
1351  const DataLayout &DL = BB->getParent()->getParent()->getDataLayout();
1352  return Insert(new AllocaInst(Ty, DL.getAllocaAddrSpace(), ArraySize), Name);
1353  }
1354 
1355  /// Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of
1356  /// converting the string to 'bool' for the isVolatile parameter.
1357  LoadInst *CreateLoad(Type *Ty, Value *Ptr, const char *Name) {
1358  return Insert(new LoadInst(Ty, Ptr), Name);
1359  }
1360 
1361  LoadInst *CreateLoad(Type *Ty, Value *Ptr, const Twine &Name = "") {
1362  return Insert(new LoadInst(Ty, Ptr), Name);
1363  }
1364 
1366  const Twine &Name = "") {
1367  return Insert(new LoadInst(Ty, Ptr, Twine(), isVolatile), Name);
1368  }
1369 
1370  // Deprecated [opaque pointer types]
1371  LoadInst *CreateLoad(Value *Ptr, const char *Name) {
1372  return CreateLoad(Ptr->getType()->getPointerElementType(), Ptr, Name);
1373  }
1374 
1375  // Deprecated [opaque pointer types]
1376  LoadInst *CreateLoad(Value *Ptr, const Twine &Name = "") {
1377  return CreateLoad(Ptr->getType()->getPointerElementType(), Ptr, Name);
1378  }
1379 
1380  // Deprecated [opaque pointer types]
1381  LoadInst *CreateLoad(Value *Ptr, bool isVolatile, const Twine &Name = "") {
1382  return CreateLoad(Ptr->getType()->getPointerElementType(), Ptr, isVolatile,
1383  Name);
1384  }
1385 
1386  StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) {
1387  return Insert(new StoreInst(Val, Ptr, isVolatile));
1388  }
1389 
1390  /// Provided to resolve 'CreateAlignedLoad(Ptr, Align, "...")'
1391  /// correctly, instead of converting the string to 'bool' for the isVolatile
1392  /// parameter.
1394  const char *Name) {
1395  LoadInst *LI = CreateLoad(Ty, Ptr, Name);
1396  LI->setAlignment(Align);
1397  return LI;
1398  }
1400  const Twine &Name = "") {
1401  LoadInst *LI = CreateLoad(Ty, Ptr, Name);
1402  LI->setAlignment(Align);
1403  return LI;
1404  }
1406  bool isVolatile, const Twine &Name = "") {
1407  LoadInst *LI = CreateLoad(Ty, Ptr, isVolatile, Name);
1408  LI->setAlignment(Align);
1409  return LI;
1410  }
1411 
1412  // Deprecated [opaque pointer types]
1413  LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name) {
1414  return CreateAlignedLoad(Ptr->getType()->getPointerElementType(), Ptr,
1415  Align, Name);
1416  }
1417  // Deprecated [opaque pointer types]
1419  const Twine &Name = "") {
1420  return CreateAlignedLoad(Ptr->getType()->getPointerElementType(), Ptr,
1421  Align, Name);
1422  }
1423  // Deprecated [opaque pointer types]
1425  const Twine &Name = "") {
1426  return CreateAlignedLoad(Ptr->getType()->getPointerElementType(), Ptr,
1427  Align, isVolatile, Name);
1428  }
1429 
1431  bool isVolatile = false) {
1432  StoreInst *SI = CreateStore(Val, Ptr, isVolatile);
1433  SI->setAlignment(Align);
1434  return SI;
1435  }
1436 
1439  const Twine &Name = "") {
1440  return Insert(new FenceInst(Context, Ordering, SSID), Name);
1441  }
1442 
1445  AtomicOrdering SuccessOrdering,
1446  AtomicOrdering FailureOrdering,
1448  return Insert(new AtomicCmpXchgInst(Ptr, Cmp, New, SuccessOrdering,
1449  FailureOrdering, SSID));
1450  }
1451 
1453  AtomicOrdering Ordering,
1455  return Insert(new AtomicRMWInst(Op, Ptr, Val, Ordering, SSID));
1456  }
1457 
1459  const Twine &Name = "") {
1460  return CreateGEP(nullptr, Ptr, IdxList, Name);
1461  }
1462 
1464  const Twine &Name = "") {
1465  if (auto *PC = dyn_cast<Constant>(Ptr)) {
1466  // Every index must be constant.
1467  size_t i, e;
1468  for (i = 0, e = IdxList.size(); i != e; ++i)
1469  if (!isa<Constant>(IdxList[i]))
1470  break;
1471  if (i == e)
1472  return Insert(Folder.CreateGetElementPtr(Ty, PC, IdxList), Name);
1473  }
1474  return Insert(GetElementPtrInst::Create(Ty, Ptr, IdxList), Name);
1475  }
1476 
1478  const Twine &Name = "") {
1479  return CreateInBoundsGEP(nullptr, Ptr, IdxList, Name);
1480  }
1481 
1483  const Twine &Name = "") {
1484  if (auto *PC = dyn_cast<Constant>(Ptr)) {
1485  // Every index must be constant.
1486  size_t i, e;
1487  for (i = 0, e = IdxList.size(); i != e; ++i)
1488  if (!isa<Constant>(IdxList[i]))
1489  break;
1490  if (i == e)
1491  return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, IdxList),
1492  Name);
1493  }
1494  return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, IdxList), Name);
1495  }
1496 
1497  Value *CreateGEP(Value *Ptr, Value *Idx, const Twine &Name = "") {
1498  return CreateGEP(nullptr, Ptr, Idx, Name);
1499  }
1500 
1501  Value *CreateGEP(Type *Ty, Value *Ptr, Value *Idx, const Twine &Name = "") {
1502  if (auto *PC = dyn_cast<Constant>(Ptr))
1503  if (auto *IC = dyn_cast<Constant>(Idx))
1504  return Insert(Folder.CreateGetElementPtr(Ty, PC, IC), Name);
1505  return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
1506  }
1507 
1509  const Twine &Name = "") {
1510  if (auto *PC = dyn_cast<Constant>(Ptr))
1511  if (auto *IC = dyn_cast<Constant>(Idx))
1512  return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, IC), Name);
1513  return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
1514  }
1515 
1516  Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name = "") {
1517  return CreateConstGEP1_32(nullptr, Ptr, Idx0, Name);
1518  }
1519 
1520  Value *CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
1521  const Twine &Name = "") {
1523 
1524  if (auto *PC = dyn_cast<Constant>(Ptr))
1525  return Insert(Folder.CreateGetElementPtr(Ty, PC, Idx), Name);
1526 
1527  return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
1528  }
1529 
1530  Value *CreateConstInBoundsGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
1531  const Twine &Name = "") {
1533 
1534  if (auto *PC = dyn_cast<Constant>(Ptr))
1535  return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idx), Name);
1536 
1537  return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
1538  }
1539 
1540  Value *CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1,
1541  const Twine &Name = "") {
1542  Value *Idxs[] = {
1545  };
1546 
1547  if (auto *PC = dyn_cast<Constant>(Ptr))
1548  return Insert(Folder.CreateGetElementPtr(Ty, PC, Idxs), Name);
1549 
1550  return Insert(GetElementPtrInst::Create(Ty, Ptr, Idxs), Name);
1551  }
1552 
1553  Value *CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0,
1554  unsigned Idx1, const Twine &Name = "") {
1555  Value *Idxs[] = {
1558  };
1559 
1560  if (auto *PC = dyn_cast<Constant>(Ptr))
1561  return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idxs), Name);
1562 
1563  return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idxs), Name);
1564  }
1565 
1566  Value *CreateConstGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0,
1567  const Twine &Name = "") {
1569 
1570  if (auto *PC = dyn_cast<Constant>(Ptr))
1571  return Insert(Folder.CreateGetElementPtr(Ty, PC, Idx), Name);
1572 
1573  return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
1574  }
1575 
1576  Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name = "") {
1577  return CreateConstGEP1_64(nullptr, Ptr, Idx0, Name);
1578  }
1579 
1580  Value *CreateConstInBoundsGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0,
1581  const Twine &Name = "") {
1583 
1584  if (auto *PC = dyn_cast<Constant>(Ptr))
1585  return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idx), Name);
1586 
1587  return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
1588  }
1589 
1591  const Twine &Name = "") {
1592  return CreateConstInBoundsGEP1_64(nullptr, Ptr, Idx0, Name);
1593  }
1594 
1595  Value *CreateConstGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1596  const Twine &Name = "") {
1597  Value *Idxs[] = {
1600  };
1601 
1602  if (auto *PC = dyn_cast<Constant>(Ptr))
1603  return Insert(Folder.CreateGetElementPtr(Ty, PC, Idxs), Name);
1604 
1605  return Insert(GetElementPtrInst::Create(Ty, Ptr, Idxs), Name);
1606  }
1607 
1608  Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1609  const Twine &Name = "") {
1610  return CreateConstGEP2_64(nullptr, Ptr, Idx0, Idx1, Name);
1611  }
1612 
1613  Value *CreateConstInBoundsGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0,
1614  uint64_t Idx1, const Twine &Name = "") {
1615  Value *Idxs[] = {
1618  };
1619 
1620  if (auto *PC = dyn_cast<Constant>(Ptr))
1621  return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idxs), Name);
1622 
1623  return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idxs), Name);
1624  }
1625 
1626  Value *CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1627  const Twine &Name = "") {
1628  return CreateConstInBoundsGEP2_64(nullptr, Ptr, Idx0, Idx1, Name);
1629  }
1630 
1631  Value *CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx,
1632  const Twine &Name = "") {
1633  return CreateConstInBoundsGEP2_32(Ty, Ptr, 0, Idx, Name);
1634  }
1635 
1636  Value *CreateStructGEP(Value *Ptr, unsigned Idx, const Twine &Name = "") {
1637  return CreateConstInBoundsGEP2_32(nullptr, Ptr, 0, Idx, Name);
1638  }
1639 
1640  /// Same as CreateGlobalString, but return a pointer with "i8*" type
1641  /// instead of a pointer to array of i8.
1643  unsigned AddressSpace = 0) {
1644  GlobalVariable *GV = CreateGlobalString(Str, Name, AddressSpace);
1646  Constant *Indices[] = {Zero, Zero};
1648  Indices);
1649  }
1650 
1651  //===--------------------------------------------------------------------===//
1652  // Instruction creation methods: Cast/Conversion Operators
1653  //===--------------------------------------------------------------------===//
1654 
1655  Value *CreateTrunc(Value *V, Type *DestTy, const Twine &Name = "") {
1656  return CreateCast(Instruction::Trunc, V, DestTy, Name);
1657  }
1658 
1659  Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "") {
1660  return CreateCast(Instruction::ZExt, V, DestTy, Name);
1661  }
1662 
1663  Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") {
1664  return CreateCast(Instruction::SExt, V, DestTy, Name);
1665  }
1666 
1667  /// Create a ZExt or Trunc from the integer value V to DestTy. Return
1668  /// the value untouched if the type of V is already DestTy.
1670  const Twine &Name = "") {
1671  assert(V->getType()->isIntOrIntVectorTy() &&
1672  DestTy->isIntOrIntVectorTy() &&
1673  "Can only zero extend/truncate integers!");
1674  Type *VTy = V->getType();
1675  if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
1676  return CreateZExt(V, DestTy, Name);
1677  if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
1678  return CreateTrunc(V, DestTy, Name);
1679  return V;
1680  }
1681 
1682  /// Create a SExt or Trunc from the integer value V to DestTy. Return
1683  /// the value untouched if the type of V is already DestTy.
1685  const Twine &Name = "") {
1686  assert(V->getType()->isIntOrIntVectorTy() &&
1687  DestTy->isIntOrIntVectorTy() &&
1688  "Can only sign extend/truncate integers!");
1689  Type *VTy = V->getType();
1690  if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
1691  return CreateSExt(V, DestTy, Name);
1692  if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
1693  return CreateTrunc(V, DestTy, Name);
1694  return V;
1695  }
1696 
1697  Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = ""){
1698  return CreateCast(Instruction::FPToUI, V, DestTy, Name);
1699  }
1700 
1701  Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = ""){
1702  return CreateCast(Instruction::FPToSI, V, DestTy, Name);
1703  }
1704 
1705  Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
1706  return CreateCast(Instruction::UIToFP, V, DestTy, Name);
1707  }
1708 
1709  Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
1710  return CreateCast(Instruction::SIToFP, V, DestTy, Name);
1711  }
1712 
1714  const Twine &Name = "") {
1715  return CreateCast(Instruction::FPTrunc, V, DestTy, Name);
1716  }
1717 
1718  Value *CreateFPExt(Value *V, Type *DestTy, const Twine &Name = "") {
1719  return CreateCast(Instruction::FPExt, V, DestTy, Name);
1720  }
1721 
1723  const Twine &Name = "") {
1724  return CreateCast(Instruction::PtrToInt, V, DestTy, Name);
1725  }
1726 
1728  const Twine &Name = "") {
1729  return CreateCast(Instruction::IntToPtr, V, DestTy, Name);
1730  }
1731 
1733  const Twine &Name = "") {
1734  return CreateCast(Instruction::BitCast, V, DestTy, Name);
1735  }
1736 
1738  const Twine &Name = "") {
1739  return CreateCast(Instruction::AddrSpaceCast, V, DestTy, Name);
1740  }
1741 
1743  const Twine &Name = "") {
1744  if (V->getType() == DestTy)
1745  return V;
1746  if (auto *VC = dyn_cast<Constant>(V))
1747  return Insert(Folder.CreateZExtOrBitCast(VC, DestTy), Name);
1748  return Insert(CastInst::CreateZExtOrBitCast(V, DestTy), Name);
1749  }
1750 
1752  const Twine &Name = "") {
1753  if (V->getType() == DestTy)
1754  return V;
1755  if (auto *VC = dyn_cast<Constant>(V))
1756  return Insert(Folder.CreateSExtOrBitCast(VC, DestTy), Name);
1757  return Insert(CastInst::CreateSExtOrBitCast(V, DestTy), Name);
1758  }
1759 
1761  const Twine &Name = "") {
1762  if (V->getType() == DestTy)
1763  return V;
1764  if (auto *VC = dyn_cast<Constant>(V))
1765  return Insert(Folder.CreateTruncOrBitCast(VC, DestTy), Name);
1766  return Insert(CastInst::CreateTruncOrBitCast(V, DestTy), Name);
1767  }
1768 
1770  const Twine &Name = "") {
1771  if (V->getType() == DestTy)
1772  return V;
1773  if (auto *VC = dyn_cast<Constant>(V))
1774  return Insert(Folder.CreateCast(Op, VC, DestTy), Name);
1775  return Insert(CastInst::Create(Op, V, DestTy), Name);
1776  }
1777 
1779  const Twine &Name = "") {
1780  if (V->getType() == DestTy)
1781  return V;
1782  if (auto *VC = dyn_cast<Constant>(V))
1783  return Insert(Folder.CreatePointerCast(VC, DestTy), Name);
1784  return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
1785  }
1786 
1788  const Twine &Name = "") {
1789  if (V->getType() == DestTy)
1790  return V;
1791 
1792  if (auto *VC = dyn_cast<Constant>(V)) {
1793  return Insert(Folder.CreatePointerBitCastOrAddrSpaceCast(VC, DestTy),
1794  Name);
1795  }
1796 
1797  return Insert(CastInst::CreatePointerBitCastOrAddrSpaceCast(V, DestTy),
1798  Name);
1799  }
1800 
1801  Value *CreateIntCast(Value *V, Type *DestTy, bool isSigned,
1802  const Twine &Name = "") {
1803  if (V->getType() == DestTy)
1804  return V;
1805  if (auto *VC = dyn_cast<Constant>(V))
1806  return Insert(Folder.CreateIntCast(VC, DestTy, isSigned), Name);
1807  return Insert(CastInst::CreateIntegerCast(V, DestTy, isSigned), Name);
1808  }
1809 
1811  const Twine &Name = "") {
1812  if (V->getType() == DestTy)
1813  return V;
1814  if (V->getType()->isPtrOrPtrVectorTy() && DestTy->isIntOrIntVectorTy())
1815  return CreatePtrToInt(V, DestTy, Name);
1816  if (V->getType()->isIntOrIntVectorTy() && DestTy->isPtrOrPtrVectorTy())
1817  return CreateIntToPtr(V, DestTy, Name);
1818 
1819  return CreateBitCast(V, DestTy, Name);
1820  }
1821 
1822  Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "") {
1823  if (V->getType() == DestTy)
1824  return V;
1825  if (auto *VC = dyn_cast<Constant>(V))
1826  return Insert(Folder.CreateFPCast(VC, DestTy), Name);
1827  return Insert(CastInst::CreateFPCast(V, DestTy), Name);
1828  }
1829 
1830  // Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a
1831  // compile time error, instead of converting the string to bool for the
1832  // isSigned parameter.
1833  Value *CreateIntCast(Value *, Type *, const char *) = delete;
1834 
1835  //===--------------------------------------------------------------------===//
1836  // Instruction creation methods: Compare Instructions
1837  //===--------------------------------------------------------------------===//
1838 
1839  Value *CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
1840  return CreateICmp(ICmpInst::ICMP_EQ, LHS, RHS, Name);
1841  }
1842 
1843  Value *CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name = "") {
1844  return CreateICmp(ICmpInst::ICMP_NE, LHS, RHS, Name);
1845  }
1846 
1847  Value *CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name = "") {
1848  return CreateICmp(ICmpInst::ICMP_UGT, LHS, RHS, Name);
1849  }
1850 
1851  Value *CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name = "") {
1852  return CreateICmp(ICmpInst::ICMP_UGE, LHS, RHS, Name);
1853  }
1854 
1855  Value *CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name = "") {
1856  return CreateICmp(ICmpInst::ICMP_ULT, LHS, RHS, Name);
1857  }
1858 
1859  Value *CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name = "") {
1860  return CreateICmp(ICmpInst::ICMP_ULE, LHS, RHS, Name);
1861  }
1862 
1863  Value *CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name = "") {
1864  return CreateICmp(ICmpInst::ICMP_SGT, LHS, RHS, Name);
1865  }
1866 
1867  Value *CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name = "") {
1868  return CreateICmp(ICmpInst::ICMP_SGE, LHS, RHS, Name);
1869  }
1870 
1871  Value *CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name = "") {
1872  return CreateICmp(ICmpInst::ICMP_SLT, LHS, RHS, Name);
1873  }
1874 
1875  Value *CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name = "") {
1876  return CreateICmp(ICmpInst::ICMP_SLE, LHS, RHS, Name);
1877  }
1878 
1879  Value *CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name = "",
1880  MDNode *FPMathTag = nullptr) {
1881  return CreateFCmp(FCmpInst::FCMP_OEQ, LHS, RHS, Name, FPMathTag);
1882  }
1883 
1884  Value *CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name = "",
1885  MDNode *FPMathTag = nullptr) {
1886  return CreateFCmp(FCmpInst::FCMP_OGT, LHS, RHS, Name, FPMathTag);
1887  }
1888 
1889  Value *CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name = "",
1890  MDNode *FPMathTag = nullptr) {
1891  return CreateFCmp(FCmpInst::FCMP_OGE, LHS, RHS, Name, FPMathTag);
1892  }
1893 
1894  Value *CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name = "",
1895  MDNode *FPMathTag = nullptr) {
1896  return CreateFCmp(FCmpInst::FCMP_OLT, LHS, RHS, Name, FPMathTag);
1897  }
1898 
1899  Value *CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name = "",
1900  MDNode *FPMathTag = nullptr) {
1901  return CreateFCmp(FCmpInst::FCMP_OLE, LHS, RHS, Name, FPMathTag);
1902  }
1903 
1904  Value *CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name = "",
1905  MDNode *FPMathTag = nullptr) {
1906  return CreateFCmp(FCmpInst::FCMP_ONE, LHS, RHS, Name, FPMathTag);
1907  }
1908 
1909  Value *CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name = "",
1910  MDNode *FPMathTag = nullptr) {
1911  return CreateFCmp(FCmpInst::FCMP_ORD, LHS, RHS, Name, FPMathTag);
1912  }
1913 
1914  Value *CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name = "",
1915  MDNode *FPMathTag = nullptr) {
1916  return CreateFCmp(FCmpInst::FCMP_UNO, LHS, RHS, Name, FPMathTag);
1917  }
1918 
1919  Value *CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name = "",
1920  MDNode *FPMathTag = nullptr) {
1921  return CreateFCmp(FCmpInst::FCMP_UEQ, LHS, RHS, Name, FPMathTag);
1922  }
1923 
1924  Value *CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name = "",
1925  MDNode *FPMathTag = nullptr) {
1926  return CreateFCmp(FCmpInst::FCMP_UGT, LHS, RHS, Name, FPMathTag);
1927  }
1928 
1929  Value *CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name = "",
1930  MDNode *FPMathTag = nullptr) {
1931  return CreateFCmp(FCmpInst::FCMP_UGE, LHS, RHS, Name, FPMathTag);
1932  }
1933 
1934  Value *CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name = "",
1935  MDNode *FPMathTag = nullptr) {
1936  return CreateFCmp(FCmpInst::FCMP_ULT, LHS, RHS, Name, FPMathTag);
1937  }
1938 
1939  Value *CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name = "",
1940  MDNode *FPMathTag = nullptr) {
1941  return CreateFCmp(FCmpInst::FCMP_ULE, LHS, RHS, Name, FPMathTag);
1942  }
1943 
1944  Value *CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name = "",
1945  MDNode *FPMathTag = nullptr) {
1946  return CreateFCmp(FCmpInst::FCMP_UNE, LHS, RHS, Name, FPMathTag);
1947  }
1948 
1950  const Twine &Name = "") {
1951  if (auto *LC = dyn_cast<Constant>(LHS))
1952  if (auto *RC = dyn_cast<Constant>(RHS))
1953  return Insert(Folder.CreateICmp(P, LC, RC), Name);
1954  return Insert(new ICmpInst(P, LHS, RHS), Name);
1955  }
1956 
1958  const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1959  if (auto *LC = dyn_cast<Constant>(LHS))
1960  if (auto *RC = dyn_cast<Constant>(RHS))
1961  return Insert(Folder.CreateFCmp(P, LC, RC), Name);
1962  return Insert(setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMF), Name);
1963  }
1964 
1965  //===--------------------------------------------------------------------===//
1966  // Instruction creation methods: Other Instructions
1967  //===--------------------------------------------------------------------===//
1968 
1969  PHINode *CreatePHI(Type *Ty, unsigned NumReservedValues,
1970  const Twine &Name = "") {
1971  return Insert(PHINode::Create(Ty, NumReservedValues), Name);
1972  }
1973 
1975  ArrayRef<Value *> Args = None, const Twine &Name = "",
1976  MDNode *FPMathTag = nullptr) {
1977  CallInst *CI = CallInst::Create(FTy, Callee, Args, DefaultOperandBundles);
1978  if (isa<FPMathOperator>(CI))
1979  CI = cast<CallInst>(setFPAttrs(CI, FPMathTag, FMF));
1980  return Insert(CI, Name);
1981  }
1982 
1984  ArrayRef<OperandBundleDef> OpBundles,
1985  const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1986  CallInst *CI = CallInst::Create(FTy, Callee, Args, OpBundles);
1987  if (isa<FPMathOperator>(CI))
1988  CI = cast<CallInst>(setFPAttrs(CI, FPMathTag, FMF));
1989  return Insert(CI, Name);
1990  }
1991 
1993  const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1994  return CreateCall(Callee->getFunctionType(), Callee, Args, Name, FPMathTag);
1995  }
1996 
1998  ArrayRef<OperandBundleDef> OpBundles,
1999  const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2000  return CreateCall(Callee->getFunctionType(), Callee, Args, OpBundles, Name,
2001  FPMathTag);
2002  }
2003 
2004  // Deprecated [opaque pointer types]
2006  const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2007  return CreateCall(
2008  cast<FunctionType>(Callee->getType()->getPointerElementType()), Callee,
2009  Args, Name, FPMathTag);
2010  }
2011 
2012  // Deprecated [opaque pointer types]
2014  ArrayRef<OperandBundleDef> OpBundles,
2015  const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2016  return CreateCall(
2017  cast<FunctionType>(Callee->getType()->getPointerElementType()), Callee,
2018  Args, OpBundles, Name, FPMathTag);
2019  }
2020 
2021  Value *CreateSelect(Value *C, Value *True, Value *False,
2022  const Twine &Name = "", Instruction *MDFrom = nullptr) {
2023  if (auto *CC = dyn_cast<Constant>(C))
2024  if (auto *TC = dyn_cast<Constant>(True))
2025  if (auto *FC = dyn_cast<Constant>(False))
2026  return Insert(Folder.CreateSelect(CC, TC, FC), Name);
2027 
2028  SelectInst *Sel = SelectInst::Create(C, True, False);
2029  if (MDFrom) {
2030  MDNode *Prof = MDFrom->getMetadata(LLVMContext::MD_prof);
2031  MDNode *Unpred = MDFrom->getMetadata(LLVMContext::MD_unpredictable);
2032  Sel = addBranchMetadata(Sel, Prof, Unpred);
2033  }
2034  return Insert(Sel, Name);
2035  }
2036 
2037  VAArgInst *CreateVAArg(Value *List, Type *Ty, const Twine &Name = "") {
2038  return Insert(new VAArgInst(List, Ty), Name);
2039  }
2040 
2042  const Twine &Name = "") {
2043  if (auto *VC = dyn_cast<Constant>(Vec))
2044  if (auto *IC = dyn_cast<Constant>(Idx))
2045  return Insert(Folder.CreateExtractElement(VC, IC), Name);
2046  return Insert(ExtractElementInst::Create(Vec, Idx), Name);
2047  }
2048 
2049  Value *CreateExtractElement(Value *Vec, uint64_t Idx,
2050  const Twine &Name = "") {
2051  return CreateExtractElement(Vec, getInt64(Idx), Name);
2052  }
2053 
2055  const Twine &Name = "") {
2056  if (auto *VC = dyn_cast<Constant>(Vec))
2057  if (auto *NC = dyn_cast<Constant>(NewElt))
2058  if (auto *IC = dyn_cast<Constant>(Idx))
2059  return Insert(Folder.CreateInsertElement(VC, NC, IC), Name);
2060  return Insert(InsertElementInst::Create(Vec, NewElt, Idx), Name);
2061  }
2062 
2063  Value *CreateInsertElement(Value *Vec, Value *NewElt, uint64_t Idx,
2064  const Twine &Name = "") {
2065  return CreateInsertElement(Vec, NewElt, getInt64(Idx), Name);
2066  }
2067 
2069  const Twine &Name = "") {
2070  if (auto *V1C = dyn_cast<Constant>(V1))
2071  if (auto *V2C = dyn_cast<Constant>(V2))
2072  if (auto *MC = dyn_cast<Constant>(Mask))
2073  return Insert(Folder.CreateShuffleVector(V1C, V2C, MC), Name);
2074  return Insert(new ShuffleVectorInst(V1, V2, Mask), Name);
2075  }
2076 
2078  const Twine &Name = "") {
2080  return CreateShuffleVector(V1, V2, Mask, Name);
2081  }
2082 
2084  ArrayRef<unsigned> Idxs,
2085  const Twine &Name = "") {
2086  if (auto *AggC = dyn_cast<Constant>(Agg))
2087  return Insert(Folder.CreateExtractValue(AggC, Idxs), Name);
2088  return Insert(ExtractValueInst::Create(Agg, Idxs), Name);
2089  }
2090 
2092  ArrayRef<unsigned> Idxs,
2093  const Twine &Name = "") {
2094  if (auto *AggC = dyn_cast<Constant>(Agg))
2095  if (auto *ValC = dyn_cast<Constant>(Val))
2096  return Insert(Folder.CreateInsertValue(AggC, ValC, Idxs), Name);
2097  return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name);
2098  }
2099 
2100  LandingPadInst *CreateLandingPad(Type *Ty, unsigned NumClauses,
2101  const Twine &Name = "") {
2102  return Insert(LandingPadInst::Create(Ty, NumClauses), Name);
2103  }
2104 
2105  //===--------------------------------------------------------------------===//
2106  // Utility creation methods
2107  //===--------------------------------------------------------------------===//
2108 
2109  /// Return an i1 value testing if \p Arg is null.
2110  Value *CreateIsNull(Value *Arg, const Twine &Name = "") {
2111  return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()),
2112  Name);
2113  }
2114 
2115  /// Return an i1 value testing if \p Arg is not null.
2116  Value *CreateIsNotNull(Value *Arg, const Twine &Name = "") {
2117  return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()),
2118  Name);
2119  }
2120 
2121  /// Return the i64 difference between two pointer values, dividing out
2122  /// the size of the pointed-to objects.
2123  ///
2124  /// This is intended to implement C-style pointer subtraction. As such, the
2125  /// pointers must be appropriately aligned for their element types and
2126  /// pointing into the same object.
2127  Value *CreatePtrDiff(Value *LHS, Value *RHS, const Twine &Name = "") {
2128  assert(LHS->getType() == RHS->getType() &&
2129  "Pointer subtraction operand types must match!");
2130  auto *ArgType = cast<PointerType>(LHS->getType());
2131  Value *LHS_int = CreatePtrToInt(LHS, Type::getInt64Ty(Context));
2132  Value *RHS_int = CreatePtrToInt(RHS, Type::getInt64Ty(Context));
2133  Value *Difference = CreateSub(LHS_int, RHS_int);
2134  return CreateExactSDiv(Difference,
2135  ConstantExpr::getSizeOf(ArgType->getElementType()),
2136  Name);
2137  }
2138 
2139  /// Create a launder.invariant.group intrinsic call. If Ptr type is
2140  /// different from pointer to i8, it's casted to pointer to i8 in the same
2141  /// address space before call and casted back to Ptr type after call.
2143  assert(isa<PointerType>(Ptr->getType()) &&
2144  "launder.invariant.group only applies to pointers.");
2145  // FIXME: we could potentially avoid casts to/from i8*.
2146  auto *PtrType = Ptr->getType();
2147  auto *Int8PtrTy = getInt8PtrTy(PtrType->getPointerAddressSpace());
2148  if (PtrType != Int8PtrTy)
2149  Ptr = CreateBitCast(Ptr, Int8PtrTy);
2150  Module *M = BB->getParent()->getParent();
2151  Function *FnLaunderInvariantGroup = Intrinsic::getDeclaration(
2152  M, Intrinsic::launder_invariant_group, {Int8PtrTy});
2153 
2154  assert(FnLaunderInvariantGroup->getReturnType() == Int8PtrTy &&
2155  FnLaunderInvariantGroup->getFunctionType()->getParamType(0) ==
2156  Int8PtrTy &&
2157  "LaunderInvariantGroup should take and return the same type");
2158 
2159  CallInst *Fn = CreateCall(FnLaunderInvariantGroup, {Ptr});
2160 
2161  if (PtrType != Int8PtrTy)
2162  return CreateBitCast(Fn, PtrType);
2163  return Fn;
2164  }
2165 
2166  /// \brief Create a strip.invariant.group intrinsic call. If Ptr type is
2167  /// different from pointer to i8, it's casted to pointer to i8 in the same
2168  /// address space before call and casted back to Ptr type after call.
2170  assert(isa<PointerType>(Ptr->getType()) &&
2171  "strip.invariant.group only applies to pointers.");
2172 
2173  // FIXME: we could potentially avoid casts to/from i8*.
2174  auto *PtrType = Ptr->getType();
2175  auto *Int8PtrTy = getInt8PtrTy(PtrType->getPointerAddressSpace());
2176  if (PtrType != Int8PtrTy)
2177  Ptr = CreateBitCast(Ptr, Int8PtrTy);
2178  Module *M = BB->getParent()->getParent();
2179  Function *FnStripInvariantGroup = Intrinsic::getDeclaration(
2180  M, Intrinsic::strip_invariant_group, {Int8PtrTy});
2181 
2182  assert(FnStripInvariantGroup->getReturnType() == Int8PtrTy &&
2183  FnStripInvariantGroup->getFunctionType()->getParamType(0) ==
2184  Int8PtrTy &&
2185  "StripInvariantGroup should take and return the same type");
2186 
2187  CallInst *Fn = CreateCall(FnStripInvariantGroup, {Ptr});
2188 
2189  if (PtrType != Int8PtrTy)
2190  return CreateBitCast(Fn, PtrType);
2191  return Fn;
2192  }
2193 
2194  /// Return a vector value that contains \arg V broadcasted to \p
2195  /// NumElts elements.
2196  Value *CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name = "") {
2197  assert(NumElts > 0 && "Cannot splat to an empty vector!");
2198 
2199  // First insert it into an undef vector so we can shuffle it.
2200  Type *I32Ty = getInt32Ty();
2201  Value *Undef = UndefValue::get(VectorType::get(V->getType(), NumElts));
2202  V = CreateInsertElement(Undef, V, ConstantInt::get(I32Ty, 0),
2203  Name + ".splatinsert");
2204 
2205  // Shuffle the value across the desired number of elements.
2206  Value *Zeros = ConstantAggregateZero::get(VectorType::get(I32Ty, NumElts));
2207  return CreateShuffleVector(V, Undef, Zeros, Name + ".splat");
2208  }
2209 
2210  /// Return a value that has been extracted from a larger integer type.
2212  IntegerType *ExtractedTy, uint64_t Offset,
2213  const Twine &Name) {
2214  auto *IntTy = cast<IntegerType>(From->getType());
2215  assert(DL.getTypeStoreSize(ExtractedTy) + Offset <=
2216  DL.getTypeStoreSize(IntTy) &&
2217  "Element extends past full value");
2218  uint64_t ShAmt = 8 * Offset;
2219  Value *V = From;
2220  if (DL.isBigEndian())
2221  ShAmt = 8 * (DL.getTypeStoreSize(IntTy) -
2222  DL.getTypeStoreSize(ExtractedTy) - Offset);
2223  if (ShAmt) {
2224  V = CreateLShr(V, ShAmt, Name + ".shift");
2225  }
2226  assert(ExtractedTy->getBitWidth() <= IntTy->getBitWidth() &&
2227  "Cannot extract to a larger integer!");
2228  if (ExtractedTy != IntTy) {
2229  V = CreateTrunc(V, ExtractedTy, Name + ".trunc");
2230  }
2231  return V;
2232  }
2233 
2234 private:
2235  /// Helper function that creates an assume intrinsic call that
2236  /// represents an alignment assumption on the provided Ptr, Mask, Type
2237  /// and Offset. It may be sometimes useful to do some other logic
2238  /// based on this alignment check, thus it can be stored into 'TheCheck'.
2239  CallInst *CreateAlignmentAssumptionHelper(const DataLayout &DL,
2240  Value *PtrValue, Value *Mask,
2241  Type *IntPtrTy, Value *OffsetValue,
2242  Value **TheCheck) {
2243  Value *PtrIntValue = CreatePtrToInt(PtrValue, IntPtrTy, "ptrint");
2244 
2245  if (OffsetValue) {
2246  bool IsOffsetZero = false;
2247  if (const auto *CI = dyn_cast<ConstantInt>(OffsetValue))
2248  IsOffsetZero = CI->isZero();
2249 
2250  if (!IsOffsetZero) {
2251  if (OffsetValue->getType() != IntPtrTy)
2252  OffsetValue = CreateIntCast(OffsetValue, IntPtrTy, /*isSigned*/ true,
2253  "offsetcast");
2254  PtrIntValue = CreateSub(PtrIntValue, OffsetValue, "offsetptr");
2255  }
2256  }
2257 
2258  Value *Zero = ConstantInt::get(IntPtrTy, 0);
2259  Value *MaskedPtr = CreateAnd(PtrIntValue, Mask, "maskedptr");
2260  Value *InvCond = CreateICmpEQ(MaskedPtr, Zero, "maskcond");
2261  if (TheCheck)
2262  *TheCheck = InvCond;
2263 
2264  return CreateAssumption(InvCond);
2265  }
2266 
2267 public:
2268  /// Create an assume intrinsic call that represents an alignment
2269  /// assumption on the provided pointer.
2270  ///
2271  /// An optional offset can be provided, and if it is provided, the offset
2272  /// must be subtracted from the provided pointer to get the pointer with the
2273  /// specified alignment.
2274  ///
2275  /// It may be sometimes useful to do some other logic
2276  /// based on this alignment check, thus it can be stored into 'TheCheck'.
2278  unsigned Alignment,
2279  Value *OffsetValue = nullptr,
2280  Value **TheCheck = nullptr) {
2281  assert(isa<PointerType>(PtrValue->getType()) &&
2282  "trying to create an alignment assumption on a non-pointer?");
2283  auto *PtrTy = cast<PointerType>(PtrValue->getType());
2284  Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
2285 
2286  Value *Mask = ConstantInt::get(IntPtrTy, Alignment > 0 ? Alignment - 1 : 0);
2287  return CreateAlignmentAssumptionHelper(DL, PtrValue, Mask, IntPtrTy,
2288  OffsetValue, TheCheck);
2289  }
2290 
2291  /// Create an assume intrinsic call that represents an alignment
2292  /// assumption on the provided pointer.
2293  ///
2294  /// An optional offset can be provided, and if it is provided, the offset
2295  /// must be subtracted from the provided pointer to get the pointer with the
2296  /// specified alignment.
2297  ///
2298  /// It may be sometimes useful to do some other logic
2299  /// based on this alignment check, thus it can be stored into 'TheCheck'.
2300  ///
2301  /// This overload handles the condition where the Alignment is dependent
2302  /// on an existing value rather than a static value.
2304  Value *Alignment,
2305  Value *OffsetValue = nullptr,
2306  Value **TheCheck = nullptr) {
2307  assert(isa<PointerType>(PtrValue->getType()) &&
2308  "trying to create an alignment assumption on a non-pointer?");
2309  auto *PtrTy = cast<PointerType>(PtrValue->getType());
2310  Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
2311 
2312  if (Alignment->getType() != IntPtrTy)
2313  Alignment = CreateIntCast(Alignment, IntPtrTy, /*isSigned*/ true,
2314  "alignmentcast");
2315  Value *IsPositive =
2316  CreateICmp(CmpInst::ICMP_SGT, Alignment,
2317  ConstantInt::get(Alignment->getType(), 0), "ispositive");
2318  Value *PositiveMask =
2319  CreateSub(Alignment, ConstantInt::get(IntPtrTy, 1), "positivemask");
2320  Value *Mask = CreateSelect(IsPositive, PositiveMask,
2321  ConstantInt::get(IntPtrTy, 0), "mask");
2322 
2323  return CreateAlignmentAssumptionHelper(DL, PtrValue, Mask, IntPtrTy,
2324  OffsetValue, TheCheck);
2325  }
2326 };
2327 
2328 // Create wrappers for C Binding types (see CBindingWrapping.h).
2330 
2331 } // end namespace llvm
2332 
2333 #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:2063
Value * CreateNSWNeg(Value *V, const Twine &Name="")
Definition: IRBuilder.h:1318
Value * CreateConstInBoundsGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0, const Twine &Name="")
Definition: IRBuilder.h:1530
Value * CreateInBoundsGEP(Value *Ptr, ArrayRef< Value *> IdxList, const Twine &Name="")
Definition: IRBuilder.h:1477
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:89
CallInst * CreateCall(Function *Callee, ArrayRef< Value *> Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1997
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:1154
Value * CreateInBoundsGEP(Type *Ty, Value *Ptr, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:1508
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
Value * CreateConstGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition: IRBuilder.h:1566
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:1949
Value * CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name="")
Definition: IRBuilder.h:1516
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:1298
Value * CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0, const Twine &Name="")
Definition: IRBuilder.h:1520
FastMathFlags getFastMathFlags() const
Get the flags to be applied to created floating point ops.
Definition: IRBuilder.h:211
InvokeInst * CreateInvoke(Function *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value *> Args=None, const Twine &Name="")
Definition: IRBuilder.h:917
LLVMContext & Context
LLVMContext & getContext() const
Definition: IRBuilder.h:123
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
Definition: IRBuilder.h:1344
static BinaryOperator * CreateNot(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1843
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return an i1 value testing if Arg is not null.
Definition: IRBuilder.h:2116
Atomic ordering constants.
Value * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1737
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
Definition: IRBuilder.h:1669
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Value * CreateFPTrunc(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1713
Type * getParamType(unsigned i) const
Parameter type accessors.
Definition: DerivedTypes.h:135
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1855
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve &#39;CreateLoad(Ty, Ptr, "...")&#39; correctly, instead of converting the string to &#39;bool...
Definition: IRBuilder.h:1357
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1200
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, unsigned Align, const char *Name)
Provided to resolve &#39;CreateAlignedLoad(Ptr, Align, "...")&#39; correctly, instead of converting the strin...
Definition: IRBuilder.h:1393
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:2013
An instruction for ordering other memory operations.
Definition: Instructions.h:455
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:529
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
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
FastMathFlags FMF
Definition: IRBuilder.h:98
Value * CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1899
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:1381
Value * CreateShl(Value *LHS, uint64_t RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1118
static ConstantAggregateZero * get(Type *Ty)
Definition: Constants.cpp:1332
Value * CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1027
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:2211
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value *> IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:880
Value * CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1871
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:1540
unsigned less or equal
Definition: InstrTypes.h:672
unsigned less than
Definition: InstrTypes.h:671
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:652
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:662
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:1290
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:1663
A debug info location.
Definition: DebugLoc.h:34
Metadata node.
Definition: Metadata.h:864
F(f)
Value * CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1929
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:1914
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:692
Value * CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1859
Value * CreateShuffleVector(Value *V1, Value *V2, ArrayRef< uint32_t > IntMask, const Twine &Name="")
Definition: IRBuilder.h:2077
static IntegerType * getInt16Ty(LLVMContext &C)
Definition: Type.cpp:175
InvokeInst * CreateInvoke(Function *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value *> Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Definition: IRBuilder.h:909
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:2142
Value * CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1023
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:1430
Value * CreateNot(Value *V, const Twine &Name="")
Definition: IRBuilder.h:1334
LLVMContext & Context
Definition: IRBuilder.h:95
Value * CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1924
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:657
Value * CreateOr(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition: IRBuilder.h:1196
AllocaInst * CreateAlloca(Type *Ty, Value *ArraySize=nullptr, const Twine &Name="")
Definition: IRBuilder.h:1349
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:656
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:1281
Value * CreateFPExt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1718
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
This class represents the LLVM &#39;select&#39; instruction.
Type * getPointerElementType() const
Definition: Type.h:376
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:2127
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:1159
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:1376
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:968
Value * CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1751
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:653
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:1222
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:1014
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:285
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:1863
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:974
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition: IRBuilder.h:1386
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1727
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:1732
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:1684
Value * CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1847
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:704
BasicBlock * GetInsertBlock() const
Definition: IRBuilder.h:121
CallInst * CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue, unsigned Alignment, Value *OffsetValue=nullptr, Value **TheCheck=nullptr)
Create an assume intrinsic call that represents an alignment assumption on the provided pointer...
Definition: IRBuilder.h:2277
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value *> Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1983
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:2196
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:1444
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1031
Value * CreateSIToFP(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1709
An instruction for storing to memory.
Definition: Instructions.h:321
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:1659
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:1879
Value * CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1742
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:1020
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:1205
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:1919
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1182
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:1957
InsertPoint saveAndClearIP()
Returns the current insert point, clearing it in the process.
Definition: IRBuilder.h:193
LoadInst * CreateLoad(Type *Ty, Value *Ptr, bool isVolatile, const Twine &Name="")
Definition: IRBuilder.h:1365
LoadInst * CreateLoad(Value *Ptr, const char *Name)
Definition: IRBuilder.h:1371
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:750
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...
CallInst * CreateCall(Function *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1992
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:1247
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:1144
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
Value * CreateConstInBoundsGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition: IRBuilder.h:1580
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:978
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:1089
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:1112
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:1075
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition: IRBuilder.h:2021
Indirect Branch Instruction.
Value * CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1057
Value * CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1884
Value * CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition: IRBuilder.h:1608
Value * CreateFPToUI(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1697
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:1361
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:161
CatchSwitchInst * CreateCatchSwitch(Value *ParentPad, BasicBlock *UnwindBB, unsigned NumHandlers, const Twine &Name="")
Definition: IRBuilder.h:956
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:1239
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:1273
VAArgInst * CreateVAArg(Value *List, Type *Ty, const Twine &Name="")
Definition: IRBuilder.h:2037
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1308
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:646
IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=None)
Definition: IRBuilder.h:757
CallInst * CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue, Value *Alignment, Value *OffsetValue=nullptr, Value **TheCheck=nullptr)
Create an assume intrinsic call that represents an alignment assumption on the provided pointer...
Definition: IRBuilder.h:2303
Value * CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1867
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:655
static CastInst * CreatePointerBitCastOrAddrSpaceCast(Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
Create a BitCast or an AddrSpaceCast cast instruction.
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, unsigned Align, const Twine &Name="")
Definition: IRBuilder.h:1399
void clearFastMathFlags()
Clear the fast-math flags.
Definition: IRBuilder.h:214
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1839
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, unsigned Align, bool isVolatile, const Twine &Name="")
Definition: IRBuilder.h:1405
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:2041
LoadInst * CreateAlignedLoad(Value *Ptr, unsigned Align, bool isVolatile, const Twine &Name="")
Definition: IRBuilder.h:1424
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:1452
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:1134
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:2083
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:661
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:1048
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1655
static IndirectBrInst * Create(Value *Address, unsigned NumDests, Instruction *InsertBefore=nullptr)
Value * CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1139
Value * CreateSRem(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1098
signed greater than
Definition: InstrTypes.h:673
Value * CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1944
Value * CreateUIToFP(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1705
Value * CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1889
Value * CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition: IRBuilder.h:1576
InvokeInst * CreateInvoke(FunctionType *Ty, Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value *> Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Create an invoke instruction.
Definition: IRBuilder.h:892
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:1969
Value * CreateGEP(Value *Ptr, ArrayRef< Value *> IdxList, const Twine &Name="")
Definition: IRBuilder.h:1458
Value * CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1894
0 0 1 0 True if ordered and greater than
Definition: InstrTypes.h:650
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:947
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:2110
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:926
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Definition: IRBuilder.h:1801
Value * CreateNUWNeg(Value *V, const Twine &Name="")
Definition: IRBuilder.h:1322
Value * CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1851
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:660
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:2054
AddressSpace
Definition: NVPTXBaseInfo.h:22
signed less than
Definition: InstrTypes.h:675
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:1909
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:2049
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:1904
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
Definition: IRBuilder.h:2068
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:1590
Value * CreateURem(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1093
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:1642
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:1822
Value * CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition: IRBuilder.h:1178
signed less or equal
Definition: InstrTypes.h:676
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:1497
Value * CreateSDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1079
Value * CreateUDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1065
Value * CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1061
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:1787
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:1103
Value * CreatePointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1778
Value * CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition: IRBuilder.h:1626
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:1418
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:1810
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:1760
Value * CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1044
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:1934
Value * CreateGEP(Type *Ty, Value *Ptr, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:1501
Value * CreateGEP(Type *Ty, Value *Ptr, ArrayRef< Value *> IdxList, const Twine &Name="")
Definition: IRBuilder.h:1463
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:1437
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:176
Value * CreateXor(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition: IRBuilder.h:1209
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:963
unsigned greater or equal
Definition: InstrTypes.h:670
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value *> Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
Value * CreateConstGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition: IRBuilder.h:1595
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:951
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:1230
#define N
Value * CreateInBoundsGEP(Type *Ty, Value *Ptr, ArrayRef< Value *> IdxList, const Twine &Name="")
Definition: IRBuilder.h:1482
0 1 1 0 True if ordered and operands are unequal
Definition: InstrTypes.h:654
Value * CreateStripInvariantGroup(Value *Ptr)
Create a strip.invariant.group intrinsic call.
Definition: IRBuilder.h:2169
Value * CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="")
Definition: IRBuilder.h:1553
Value * CreateFPToSI(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1701
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)
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1974
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:658
Value * CreateFAdd(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition: IRBuilder.h:1213
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:2100
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1164
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1722
Value * CreateFDiv(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition: IRBuilder.h:1264
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:1769
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:914
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Value * CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition: IRBuilder.h:1174
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:1256
LoadInst * CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name)
Definition: IRBuilder.h:1413
static CatchReturnInst * Create(Value *CatchPad, BasicBlock *BB, Instruction *InsertBefore=nullptr)
0 0 0 1 True if ordered and equal
Definition: InstrTypes.h:649
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:659
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
Definition: DataLayout.h:419
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:1124
Value * CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx, const Twine &Name="")
Definition: IRBuilder.h:1631
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:669
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:1040
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:2091
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:2583
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="")
Definition: IRBuilder.h:937
0 0 1 1 True if ordered and greater than or equal
Definition: InstrTypes.h:651
InvokeInst * CreateInvoke(FunctionType *Ty, Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value *> Args=None, const Twine &Name="")
Definition: IRBuilder.h:901
Value * CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1875
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:1326
Value * CreateOr(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition: IRBuilder.h:1192
signed greater or equal
Definition: InstrTypes.h:674
Value * CreateConstInBoundsGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition: IRBuilder.h:1613
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:1939
CallInst * CreateCall(Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2005
Value * CreateStructGEP(Value *Ptr, unsigned Idx, const Twine &Name="")
Definition: IRBuilder.h:1636