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