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