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