LLVM  5.0.0
Instruction.h
Go to the documentation of this file.
1 //===-- llvm/Instruction.h - Instruction class definition -------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the declaration of the Instruction class, which is the
11 // base class for all of the LLVM instructions.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_IR_INSTRUCTION_H
16 #define LLVM_IR_INSTRUCTION_H
17 
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/None.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/ADT/ilist_node.h"
22 #include "llvm/IR/DebugLoc.h"
24 #include "llvm/IR/User.h"
25 #include "llvm/IR/Value.h"
26 #include "llvm/Support/Casting.h"
27 #include <algorithm>
28 #include <cassert>
29 #include <cstdint>
30 #include <utility>
31 
32 namespace llvm {
33 
34 class BasicBlock;
35 class FastMathFlags;
36 class MDNode;
37 struct AAMDNodes;
38 
39 template <> struct ilist_alloc_traits<Instruction> {
40  static inline void deleteNode(Instruction *V);
41 };
42 
43 class Instruction : public User,
44  public ilist_node_with_parent<Instruction, BasicBlock> {
45  BasicBlock *Parent;
46  DebugLoc DbgLoc; // 'dbg' Metadata cache.
47 
48  enum {
49  /// This is a bit stored in the SubClassData field which indicates whether
50  /// this instruction has metadata attached to it or not.
51  HasMetadataBit = 1 << 15
52  };
53 
54 protected:
55  ~Instruction(); // Use deleteValue() to delete a generic Instruction.
56 
57 public:
58  Instruction(const Instruction &) = delete;
59  Instruction &operator=(const Instruction &) = delete;
60 
61  /// Specialize the methods defined in Value, as we know that an instruction
62  /// can only be used by other instructions.
63  Instruction *user_back() { return cast<Instruction>(*user_begin());}
64  const Instruction *user_back() const { return cast<Instruction>(*user_begin());}
65 
66  inline const BasicBlock *getParent() const { return Parent; }
67  inline BasicBlock *getParent() { return Parent; }
68 
69  /// Return the module owning the function this instruction belongs to
70  /// or nullptr it the function does not have a module.
71  ///
72  /// Note: this is undefined behavior if the instruction does not have a
73  /// parent, or the parent basic block does not have a parent function.
74  const Module *getModule() const;
76  return const_cast<Module *>(
77  static_cast<const Instruction *>(this)->getModule());
78  }
79 
80  /// Return the function this instruction belongs to.
81  ///
82  /// Note: it is undefined behavior to call this on an instruction not
83  /// currently inserted into a function.
84  const Function *getFunction() const;
86  return const_cast<Function *>(
87  static_cast<const Instruction *>(this)->getFunction());
88  }
89 
90  /// This method unlinks 'this' from the containing basic block, but does not
91  /// delete it.
92  void removeFromParent();
93 
94  /// This method unlinks 'this' from the containing basic block and deletes it.
95  ///
96  /// \returns an iterator pointing to the element after the erased one
98 
99  /// Insert an unlinked instruction into a basic block immediately before
100  /// the specified instruction.
101  void insertBefore(Instruction *InsertPos);
102 
103  /// Insert an unlinked instruction into a basic block immediately after the
104  /// specified instruction.
105  void insertAfter(Instruction *InsertPos);
106 
107  /// Unlink this instruction from its current basic block and insert it into
108  /// the basic block that MovePos lives in, right before MovePos.
109  void moveBefore(Instruction *MovePos);
110 
111  /// Unlink this instruction and insert into BB before I.
112  ///
113  /// \pre I is a valid iterator into BB.
115 
116  //===--------------------------------------------------------------------===//
117  // Subclass classification.
118  //===--------------------------------------------------------------------===//
119 
120  /// Returns a member of one of the enums like Instruction::Add.
121  unsigned getOpcode() const { return getValueID() - InstructionVal; }
122 
123  const char *getOpcodeName() const { return getOpcodeName(getOpcode()); }
124  bool isTerminator() const { return isTerminator(getOpcode()); }
125  bool isBinaryOp() const { return isBinaryOp(getOpcode()); }
126  bool isShift() { return isShift(getOpcode()); }
127  bool isCast() const { return isCast(getOpcode()); }
128  bool isFuncletPad() const { return isFuncletPad(getOpcode()); }
129 
130  static const char* getOpcodeName(unsigned OpCode);
131 
132  static inline bool isTerminator(unsigned OpCode) {
133  return OpCode >= TermOpsBegin && OpCode < TermOpsEnd;
134  }
135 
136  static inline bool isBinaryOp(unsigned Opcode) {
137  return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd;
138  }
139 
140  /// Determine if the Opcode is one of the shift instructions.
141  static inline bool isShift(unsigned Opcode) {
142  return Opcode >= Shl && Opcode <= AShr;
143  }
144 
145  /// Return true if this is a logical shift left or a logical shift right.
146  inline bool isLogicalShift() const {
147  return getOpcode() == Shl || getOpcode() == LShr;
148  }
149 
150  /// Return true if this is an arithmetic shift right.
151  inline bool isArithmeticShift() const {
152  return getOpcode() == AShr;
153  }
154 
155  /// Determine if the Opcode is and/or/xor.
156  static inline bool isBitwiseLogicOp(unsigned Opcode) {
157  return Opcode == And || Opcode == Or || Opcode == Xor;
158  }
159 
160  /// Return true if this is and/or/xor.
161  inline bool isBitwiseLogicOp() const {
162  return isBitwiseLogicOp(getOpcode());
163  }
164 
165  /// Determine if the OpCode is one of the CastInst instructions.
166  static inline bool isCast(unsigned OpCode) {
167  return OpCode >= CastOpsBegin && OpCode < CastOpsEnd;
168  }
169 
170  /// Determine if the OpCode is one of the FuncletPadInst instructions.
171  static inline bool isFuncletPad(unsigned OpCode) {
172  return OpCode >= FuncletPadOpsBegin && OpCode < FuncletPadOpsEnd;
173  }
174 
175  //===--------------------------------------------------------------------===//
176  // Metadata manipulation.
177  //===--------------------------------------------------------------------===//
178 
179  /// Return true if this instruction has any metadata attached to it.
180  bool hasMetadata() const { return DbgLoc || hasMetadataHashEntry(); }
181 
182  /// Return true if this instruction has metadata attached to it other than a
183  /// debug location.
185  return hasMetadataHashEntry();
186  }
187 
188  /// Get the metadata of given kind attached to this Instruction.
189  /// If the metadata is not found then return null.
190  MDNode *getMetadata(unsigned KindID) const {
191  if (!hasMetadata()) return nullptr;
192  return getMetadataImpl(KindID);
193  }
194 
195  /// Get the metadata of given kind attached to this Instruction.
196  /// If the metadata is not found then return null.
198  if (!hasMetadata()) return nullptr;
199  return getMetadataImpl(Kind);
200  }
201 
202  /// Get all metadata attached to this Instruction. The first element of each
203  /// pair returned is the KindID, the second element is the metadata value.
204  /// This list is returned sorted by the KindID.
205  void
206  getAllMetadata(SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs) const {
207  if (hasMetadata())
208  getAllMetadataImpl(MDs);
209  }
210 
211  /// This does the same thing as getAllMetadata, except that it filters out the
212  /// debug location.
214  SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs) const {
216  getAllMetadataOtherThanDebugLocImpl(MDs);
217  }
218 
219  /// Fills the AAMDNodes structure with AA metadata from this instruction.
220  /// When Merge is true, the existing AA metadata is merged with that from this
221  /// instruction providing the most-general result.
222  void getAAMetadata(AAMDNodes &N, bool Merge = false) const;
223 
224  /// Set the metadata of the specified kind to the specified node. This updates
225  /// or replaces metadata if already present, or removes it if Node is null.
226  void setMetadata(unsigned KindID, MDNode *Node);
227  void setMetadata(StringRef Kind, MDNode *Node);
228 
229  /// Copy metadata from \p SrcInst to this instruction. \p WL, if not empty,
230  /// specifies the list of meta data that needs to be copied. If \p WL is
231  /// empty, all meta data will be copied.
232  void copyMetadata(const Instruction &SrcInst,
234 
235  /// If the instruction has "branch_weights" MD_prof metadata and the MDNode
236  /// has three operands (including name string), swap the order of the
237  /// metadata.
238  void swapProfMetadata();
239 
240  /// Drop all unknown metadata except for debug locations.
241  /// @{
242  /// Passes are required to drop metadata they don't understand. This is a
243  /// convenience method for passes to do so.
247  }
248  void dropUnknownNonDebugMetadata(unsigned ID1) {
250  }
251  void dropUnknownNonDebugMetadata(unsigned ID1, unsigned ID2) {
252  unsigned IDs[] = {ID1, ID2};
253  return dropUnknownNonDebugMetadata(IDs);
254  }
255  /// @}
256 
257  /// Sets the metadata on this instruction from the AAMDNodes structure.
258  void setAAMetadata(const AAMDNodes &N);
259 
260  /// Retrieve the raw weight values of a conditional branch or select.
261  /// Returns true on success with profile weights filled in.
262  /// Returns false if no metadata or invalid metadata was found.
263  bool extractProfMetadata(uint64_t &TrueVal, uint64_t &FalseVal) const;
264 
265  /// Retrieve total raw weight values of a branch.
266  /// Returns true on success with profile total weights filled in.
267  /// Returns false if no metadata was found.
268  bool extractProfTotalWeight(uint64_t &TotalVal) const;
269 
270  /// Updates branch_weights metadata by scaling it by \p S / \p T.
271  void updateProfWeight(uint64_t S, uint64_t T);
272 
273  /// Sets the branch_weights metadata to \p W for CallInst.
274  void setProfWeight(uint64_t W);
275 
276  /// Set the debug location information for this instruction.
277  void setDebugLoc(DebugLoc Loc) { DbgLoc = std::move(Loc); }
278 
279  /// Return the debug location for this node as a DebugLoc.
280  const DebugLoc &getDebugLoc() const { return DbgLoc; }
281 
282  /// Set or clear the nsw flag on this instruction, which must be an operator
283  /// which supports this flag. See LangRef.html for the meaning of this flag.
284  void setHasNoUnsignedWrap(bool b = true);
285 
286  /// Set or clear the nsw flag on this instruction, which must be an operator
287  /// which supports this flag. See LangRef.html for the meaning of this flag.
288  void setHasNoSignedWrap(bool b = true);
289 
290  /// Set or clear the exact flag on this instruction, which must be an operator
291  /// which supports this flag. See LangRef.html for the meaning of this flag.
292  void setIsExact(bool b = true);
293 
294  /// Determine whether the no unsigned wrap flag is set.
295  bool hasNoUnsignedWrap() const;
296 
297  /// Determine whether the no signed wrap flag is set.
298  bool hasNoSignedWrap() const;
299 
300  /// Drops flags that may cause this instruction to evaluate to poison despite
301  /// having non-poison inputs.
303 
304  /// Determine whether the exact flag is set.
305  bool isExact() const;
306 
307  /// Set or clear the unsafe-algebra flag on this instruction, which must be an
308  /// operator which supports this flag. See LangRef.html for the meaning of
309  /// this flag.
310  void setHasUnsafeAlgebra(bool B);
311 
312  /// Set or clear the no-nans flag on this instruction, which must be an
313  /// operator which supports this flag. See LangRef.html for the meaning of
314  /// this flag.
315  void setHasNoNaNs(bool B);
316 
317  /// Set or clear the no-infs flag on this instruction, which must be an
318  /// operator which supports this flag. See LangRef.html for the meaning of
319  /// this flag.
320  void setHasNoInfs(bool B);
321 
322  /// Set or clear the no-signed-zeros flag on this instruction, which must be
323  /// an operator which supports this flag. See LangRef.html for the meaning of
324  /// this flag.
325  void setHasNoSignedZeros(bool B);
326 
327  /// Set or clear the allow-reciprocal flag on this instruction, which must be
328  /// an operator which supports this flag. See LangRef.html for the meaning of
329  /// this flag.
330  void setHasAllowReciprocal(bool B);
331 
332  /// Convenience function for setting multiple fast-math flags on this
333  /// instruction, which must be an operator which supports these flags. See
334  /// LangRef.html for the meaning of these flags.
336 
337  /// Convenience function for transferring all fast-math flag values to this
338  /// instruction, which must be an operator which supports these flags. See
339  /// LangRef.html for the meaning of these flags.
341 
342  /// Determine whether the unsafe-algebra flag is set.
343  bool hasUnsafeAlgebra() const;
344 
345  /// Determine whether the no-NaNs flag is set.
346  bool hasNoNaNs() const;
347 
348  /// Determine whether the no-infs flag is set.
349  bool hasNoInfs() const;
350 
351  /// Determine whether the no-signed-zeros flag is set.
352  bool hasNoSignedZeros() const;
353 
354  /// Determine whether the allow-reciprocal flag is set.
355  bool hasAllowReciprocal() const;
356 
357  /// Determine whether the allow-contract flag is set.
358  bool hasAllowContract() const;
359 
360  /// Convenience function for getting all the fast-math flags, which must be an
361  /// operator which supports these flags. See LangRef.html for the meaning of
362  /// these flags.
364 
365  /// Copy I's fast-math flags
366  void copyFastMathFlags(const Instruction *I);
367 
368  /// Convenience method to copy supported exact, fast-math, and (optionally)
369  /// wrapping flags from V to this instruction.
370  void copyIRFlags(const Value *V, bool IncludeWrapFlags = true);
371 
372  /// Logical 'and' of any supported wrapping, exact, and fast-math flags of
373  /// V and this instruction.
374  void andIRFlags(const Value *V);
375 
376 private:
377  /// Return true if we have an entry in the on-the-side metadata hash.
378  bool hasMetadataHashEntry() const {
379  return (getSubclassDataFromValue() & HasMetadataBit) != 0;
380  }
381 
382  // These are all implemented in Metadata.cpp.
383  MDNode *getMetadataImpl(unsigned KindID) const;
384  MDNode *getMetadataImpl(StringRef Kind) const;
385  void
386  getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned, MDNode *>> &) const;
387  void getAllMetadataOtherThanDebugLocImpl(
388  SmallVectorImpl<std::pair<unsigned, MDNode *>> &) const;
389  /// Clear all hashtable-based metadata from this instruction.
390  void clearMetadataHashEntries();
391 
392 public:
393  //===--------------------------------------------------------------------===//
394  // Predicates and helper methods.
395  //===--------------------------------------------------------------------===//
396 
397  /// Return true if the instruction is associative:
398  ///
399  /// Associative operators satisfy: x op (y op z) === (x op y) op z
400  ///
401  /// In LLVM, the Add, Mul, And, Or, and Xor operators are associative.
402  ///
404  static bool isAssociative(unsigned Opcode) {
405  return Opcode == And || Opcode == Or || Opcode == Xor ||
406  Opcode == Add || Opcode == Mul;
407  }
408 
409  /// Return true if the instruction is commutative:
410  ///
411  /// Commutative operators satisfy: (x op y) === (y op x)
412  ///
413  /// In LLVM, these are the commutative operators, plus SetEQ and SetNE, when
414  /// applied to any type.
415  ///
416  bool isCommutative() const { return isCommutative(getOpcode()); }
417  static bool isCommutative(unsigned Opcode) {
418  switch (Opcode) {
419  case Add: case FAdd:
420  case Mul: case FMul:
421  case And: case Or: case Xor:
422  return true;
423  default:
424  return false;
425  }
426  }
427 
428  /// Return true if the instruction is idempotent:
429  ///
430  /// Idempotent operators satisfy: x op x === x
431  ///
432  /// In LLVM, the And and Or operators are idempotent.
433  ///
434  bool isIdempotent() const { return isIdempotent(getOpcode()); }
435  static bool isIdempotent(unsigned Opcode) {
436  return Opcode == And || Opcode == Or;
437  }
438 
439  /// Return true if the instruction is nilpotent:
440  ///
441  /// Nilpotent operators satisfy: x op x === Id,
442  ///
443  /// where Id is the identity for the operator, i.e. a constant such that
444  /// x op Id === x and Id op x === x for all x.
445  ///
446  /// In LLVM, the Xor operator is nilpotent.
447  ///
448  bool isNilpotent() const { return isNilpotent(getOpcode()); }
449  static bool isNilpotent(unsigned Opcode) {
450  return Opcode == Xor;
451  }
452 
453  /// Return true if this instruction may modify memory.
454  bool mayWriteToMemory() const;
455 
456  /// Return true if this instruction may read memory.
457  bool mayReadFromMemory() const;
458 
459  /// Return true if this instruction may read or write memory.
460  bool mayReadOrWriteMemory() const {
461  return mayReadFromMemory() || mayWriteToMemory();
462  }
463 
464  /// Return true if this instruction has an AtomicOrdering of unordered or
465  /// higher.
466  bool isAtomic() const;
467 
468  /// Return true if this atomic instruction loads from memory.
469  bool hasAtomicLoad() const;
470 
471  /// Return true if this atomic instruction stores to memory.
472  bool hasAtomicStore() const;
473 
474  /// Return true if this instruction may throw an exception.
475  bool mayThrow() const;
476 
477  /// Return true if this instruction behaves like a memory fence: it can load
478  /// or store to memory location without being given a memory location.
479  bool isFenceLike() const {
480  switch (getOpcode()) {
481  default:
482  return false;
483  // This list should be kept in sync with the list in mayWriteToMemory for
484  // all opcodes which don't have a memory location.
485  case Instruction::Fence:
486  case Instruction::CatchPad:
487  case Instruction::CatchRet:
488  case Instruction::Call:
489  case Instruction::Invoke:
490  return true;
491  }
492  }
493 
494  /// Return true if the instruction may have side effects.
495  ///
496  /// Note that this does not consider malloc and alloca to have side
497  /// effects because the newly allocated memory is completely invisible to
498  /// instructions which don't use the returned value. For cases where this
499  /// matters, isSafeToSpeculativelyExecute may be more appropriate.
500  bool mayHaveSideEffects() const { return mayWriteToMemory() || mayThrow(); }
501 
502  /// Return true if the instruction is a variety of EH-block.
503  bool isEHPad() const {
504  switch (getOpcode()) {
505  case Instruction::CatchSwitch:
506  case Instruction::CatchPad:
507  case Instruction::CleanupPad:
508  case Instruction::LandingPad:
509  return true;
510  default:
511  return false;
512  }
513  }
514 
515  /// Create a copy of 'this' instruction that is identical in all ways except
516  /// the following:
517  /// * The instruction has no parent
518  /// * The instruction has no name
519  ///
520  Instruction *clone() const;
521 
522  /// Return true if the specified instruction is exactly identical to the
523  /// current one. This means that all operands match and any extra information
524  /// (e.g. load is volatile) agree.
525  bool isIdenticalTo(const Instruction *I) const;
526 
527  /// This is like isIdenticalTo, except that it ignores the
528  /// SubclassOptionalData flags, which may specify conditions under which the
529  /// instruction's result is undefined.
530  bool isIdenticalToWhenDefined(const Instruction *I) const;
531 
532  /// When checking for operation equivalence (using isSameOperationAs) it is
533  /// sometimes useful to ignore certain attributes.
535  /// Check for equivalence ignoring load/store alignment.
537  /// Check for equivalence treating a type and a vector of that type
538  /// as equivalent.
540  };
541 
542  /// This function determines if the specified instruction executes the same
543  /// operation as the current one. This means that the opcodes, type, operand
544  /// types and any other factors affecting the operation must be the same. This
545  /// is similar to isIdenticalTo except the operands themselves don't have to
546  /// be identical.
547  /// @returns true if the specified instruction is the same operation as
548  /// the current one.
549  /// @brief Determine if one instruction is the same operation as another.
550  bool isSameOperationAs(const Instruction *I, unsigned flags = 0) const;
551 
552  /// Return true if there are any uses of this instruction in blocks other than
553  /// the specified block. Note that PHI nodes are considered to evaluate their
554  /// operands in the corresponding predecessor block.
555  bool isUsedOutsideOfBlock(const BasicBlock *BB) const;
556 
557 
558  /// Methods for support type inquiry through isa, cast, and dyn_cast:
559  static bool classof(const Value *V) {
560  return V->getValueID() >= Value::InstructionVal;
561  }
562 
563  //----------------------------------------------------------------------
564  // Exported enumerations.
565  //
566  enum TermOps { // These terminate basic blocks
567 #define FIRST_TERM_INST(N) TermOpsBegin = N,
568 #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
569 #define LAST_TERM_INST(N) TermOpsEnd = N+1
570 #include "llvm/IR/Instruction.def"
571  };
572 
573  enum BinaryOps {
574 #define FIRST_BINARY_INST(N) BinaryOpsBegin = N,
575 #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
576 #define LAST_BINARY_INST(N) BinaryOpsEnd = N+1
577 #include "llvm/IR/Instruction.def"
578  };
579 
580  enum MemoryOps {
581 #define FIRST_MEMORY_INST(N) MemoryOpsBegin = N,
582 #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
583 #define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1
584 #include "llvm/IR/Instruction.def"
585  };
586 
587  enum CastOps {
588 #define FIRST_CAST_INST(N) CastOpsBegin = N,
589 #define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N,
590 #define LAST_CAST_INST(N) CastOpsEnd = N+1
591 #include "llvm/IR/Instruction.def"
592  };
593 
595 #define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N,
596 #define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N,
597 #define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1
598 #include "llvm/IR/Instruction.def"
599  };
600 
601  enum OtherOps {
602 #define FIRST_OTHER_INST(N) OtherOpsBegin = N,
603 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
604 #define LAST_OTHER_INST(N) OtherOpsEnd = N+1
605 #include "llvm/IR/Instruction.def"
606  };
607 
608 private:
610 
611  // Shadow Value::setValueSubclassData with a private forwarding method so that
612  // subclasses cannot accidentally use it.
613  void setValueSubclassData(unsigned short D) {
615  }
616 
617  unsigned short getSubclassDataFromValue() const {
619  }
620 
621  void setHasMetadataHashEntry(bool V) {
622  setValueSubclassData((getSubclassDataFromValue() & ~HasMetadataBit) |
623  (V ? HasMetadataBit : 0));
624  }
625 
626  void setParent(BasicBlock *P);
627 
628 protected:
629  // Instruction subclasses can stick up to 15 bits of stuff into the
630  // SubclassData field of instruction with these members.
631 
632  // Verify that only the low 15 bits are used.
633  void setInstructionSubclassData(unsigned short D) {
634  assert((D & HasMetadataBit) == 0 && "Out of range value put into field");
635  setValueSubclassData((getSubclassDataFromValue() & HasMetadataBit) | D);
636  }
637 
639  return getSubclassDataFromValue() & ~HasMetadataBit;
640  }
641 
642  Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps,
643  Instruction *InsertBefore = nullptr);
644  Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps,
645  BasicBlock *InsertAtEnd);
646 
647 private:
648  /// Create a copy of this instruction.
649  Instruction *cloneImpl() const;
650 };
651 
653  V->deleteValue();
654 }
655 
656 } // end namespace llvm
657 
658 #endif // LLVM_IR_INSTRUCTION_H
bool isArithmeticShift() const
Return true if this is an arithmetic shift right.
Definition: Instruction.h:151
Function * getFunction()
Definition: Instruction.h:85
bool isNilpotent() const
Return true if the instruction is nilpotent:
Definition: Instruction.h:448
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:69
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction, which must be an operator which supports these flags.
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
bool isFenceLike() const
Return true if this instruction behaves like a memory fence: it can load or store to memory location ...
Definition: Instruction.h:479
Various leaf nodes.
Definition: ISDOpcodes.h:60
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
void setProfWeight(uint64_t W)
Sets the branch_weights metadata to W for CallInst.
void setHasNoNaNs(bool B)
Set or clear the no-nans flag on this instruction, which must be an operator which supports this flag...
bool isUsedOutsideOfBlock(const BasicBlock *BB) const
Return true if there are any uses of this instruction in blocks other than the specified block...
bool mayHaveSideEffects() const
Return true if the instruction may have side effects.
Definition: Instruction.h:500
void deleteValue()
Delete a pointer to a generic Value.
Definition: Value.cpp:93
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
A debug info location.
Definition: DebugLoc.h:34
Metadata node.
Definition: Metadata.h:862
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
Get all metadata attached to this Instruction.
Definition: Instruction.h:206
void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
static bool isBitwiseLogicOp(unsigned Opcode)
Determine if the Opcode is and/or/xor.
Definition: Instruction.h:156
bool isCast() const
Definition: Instruction.h:127
bool hasNoNaNs() const
Determine whether the no-NaNs flag is set.
static bool isShift(unsigned Opcode)
Determine if the Opcode is one of the shift instructions.
Definition: Instruction.h:141
unsigned getSubclassDataFromInstruction() const
Definition: Instruction.h:638
bool isIdenticalTo(const Instruction *I) const
Return true if the specified instruction is exactly identical to the current one. ...
static bool isCommutative(unsigned Opcode)
Definition: Instruction.h:417
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:451
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
void dropPoisonGeneratingFlags()
Drops flags that may cause this instruction to evaluate to poison despite having non-poison inputs...
bool hasAllowReciprocal() const
Determine whether the allow-reciprocal flag is set.
Check for equivalence ignoring load/store alignment.
Definition: Instruction.h:536
void dropUnknownNonDebugMetadata(unsigned ID1)
Definition: Instruction.h:248
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following: ...
OperationEquivalenceFlags
When checking for operation equivalence (using isSameOperationAs) it is sometimes useful to ignore ce...
Definition: Instruction.h:534
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag...
Check for equivalence treating a type and a vector of that type as equivalent.
Definition: Instruction.h:539
bool mayReadFromMemory() const
Return true if this instruction may read memory.
void dropUnknownNonDebugMetadata()
Definition: Instruction.h:245
bool hasAllowContract() const
Determine whether the allow-contract flag is set.
bool hasAtomicLoad() const
Return true if this atomic instruction loads from memory.
void andIRFlags(const Value *V)
Logical 'and' of any supported wrapping, exact, and fast-math flags of V and this instruction...
void setHasUnsafeAlgebra(bool B)
Set or clear the unsafe-algebra flag on this instruction, which must be an operator which supports th...
bool hasUnsafeAlgebra() const
Determine whether the unsafe-algebra flag is set.
static bool isBinaryOp(unsigned Opcode)
Definition: Instruction.h:136
bool isLogicalShift() const
Return true if this is a logical shift left or a logical shift right.
Definition: Instruction.h:146
void setInstructionSubclassData(unsigned short D)
Definition: Instruction.h:633
const Function * getFunction() const
Return the function this instruction belongs to.
Definition: Instruction.cpp:61
const char * getOpcodeName() const
Definition: Instruction.h:123
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
BasicBlock * getParent()
Definition: Instruction.h:67
bool mayReadOrWriteMemory() const
Return true if this instruction may read or write memory.
Definition: Instruction.h:460
static bool isTerminator(unsigned OpCode)
Definition: Instruction.h:132
Use delete by default for iplist and ilist.
Definition: ilist.h:41
#define P(N)
An ilist node that can access its parent list.
Definition: ilist_node.h:257
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:277
bool isIdenticalToWhenDefined(const Instruction *I) const
This is like isIdenticalTo, except that it ignores the SubclassOptionalData flags, which may specify conditions under which the instruction's result is undefined.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction...
Definition: Instruction.cpp:75
void setAAMetadata(const AAMDNodes &N)
Sets the metadata on this instruction from the AAMDNodes structure.
Definition: Metadata.cpp:1253
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
bool isExact() const
Determine whether the exact flag is set.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
void getAllMetadataOtherThanDebugLoc(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
This does the same thing as getAllMetadata, except that it filters out the debug location.
Definition: Instruction.h:213
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
Definition: Instruction.h:180
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:280
bool extractProfMetadata(uint64_t &TrueVal, uint64_t &FalseVal) const
Retrieve the raw weight values of a conditional branch or select.
Definition: Metadata.cpp:1303
bool isAssociative() const LLVM_READONLY
Return true if the instruction is associative:
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Instruction.h:559
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:459
bool isCommutative() const
Return true if the instruction is commutative:
Definition: Instruction.h:416
void setHasNoInfs(bool B)
Set or clear the no-infs flag on this instruction, which must be an operator which supports this flag...
void swapProfMetadata()
If the instruction has "branch_weights" MD_prof metadata and the MDNode has three operands (including...
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1214
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
bool isTerminator() const
Definition: Instruction.h:124
bool extractProfTotalWeight(uint64_t &TotalVal) const
Retrieve total raw weight values of a branch.
Definition: Metadata.cpp:1328
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
static void Merge(const std::string &Input, const std::vector< std::string > Result, size_t NumNewFeatures)
#define B
Definition: LargeTest.cpp:24
bool hasNoUnsignedWrap() const
Determine whether the no unsigned wrap flag is set.
MDNode * getMetadata(StringRef Kind) const
Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:197
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:57
Module * getModule()
Definition: Instruction.h:75
Instruction * user_back()
Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...
Definition: Instruction.h:63
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:190
const Instruction * user_back() const
Definition: Instruction.h:64
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition: Metadata.h:642
static bool isCast(unsigned OpCode)
Determine if the OpCode is one of the CastInst instructions.
Definition: Instruction.h:166
const size_t N
void dropUnknownNonDebugMetadata(unsigned ID1, unsigned ID2)
Definition: Instruction.h:251
static void deleteNode(NodeTy *V)
Definition: ilist.h:42
void setValueSubclassData(unsigned short D)
Definition: Value.h:656
bool hasAtomicStore() const
Return true if this atomic instruction stores to memory.
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
Definition: Instruction.cpp:65
bool mayThrow() const
Return true if this instruction may throw an exception.
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
Definition: Instruction.h:503
bool isFuncletPad() const
Definition: Instruction.h:128
List that automatically updates parent links and symbol tables.
void updateProfWeight(uint64_t S, uint64_t T)
Updates branch_weights metadata by scaling it by S / T.
unsigned short getSubclassDataFromValue() const
Definition: Value.h:655
static bool isNilpotent(unsigned Opcode)
Definition: Instruction.h:449
void getAAMetadata(AAMDNodes &N, bool Merge=false) const
Fills the AAMDNodes structure with AA metadata from this instruction.
bool isBinaryOp() const
Definition: Instruction.h:125
bool isIdempotent() const
Return true if the instruction is idempotent:
Definition: Instruction.h:434
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction...
Definition: Instruction.cpp:81
#define I(x, y, z)
Definition: MD5.cpp:58
bool hasNoInfs() const
Determine whether the no-infs flag is set.
bool hasNoSignedZeros() const
Determine whether the no-signed-zeros flag is set.
Instruction & operator=(const Instruction &)=delete
#define LLVM_READONLY
Definition: Compiler.h:168
static bool isFuncletPad(unsigned OpCode)
Determine if the OpCode is one of the FuncletPadInst instructions.
Definition: Instruction.h:171
Instruction(const Instruction &)=delete
const unsigned Kind
bool hasMetadataOtherThanDebugLoc() const
Return true if this instruction has metadata attached to it other than a debug location.
Definition: Instruction.h:184
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
Definition: Instruction.cpp:98
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
Definition: Value.h:371
aarch64 promote const
LLVM Value Representation.
Definition: Value.h:73
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:121
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
Definition: Instruction.cpp:88
Convenience struct for specifying and reasoning about fast-math flags.
Definition: Operator.h:160
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
static bool isIdempotent(unsigned Opcode)
Definition: Instruction.h:435
bool isSameOperationAs(const Instruction *I, unsigned flags=0) const
This function determines if the specified instruction executes the same operation as the current one...
void setHasNoSignedZeros(bool B)
Set or clear the no-signed-zeros flag on this instruction, which must be an operator which supports t...
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
Definition: Instruction.h:161
void setHasAllowReciprocal(bool B)
Set or clear the allow-reciprocal flag on this instruction, which must be an operator which supports ...
const BasicBlock * getParent() const
Definition: Instruction.h:66
#define D
Definition: LargeTest.cpp:26