Instruction.h revision ebe69fe11e48d322045d5949c83283927a0d790b
13a8b0f00e6d23ae57fee93f7f2c18fe8e6b45c3cChris Lattner//===-- llvm/Instruction.h - Instruction class definition -------*- C++ -*-===//
29769ab22265b313171d201b5928688524a01bd87Misha Brukman//
36fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//                     The LLVM Compiler Infrastructure
46fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//
57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source
67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details.
79769ab22265b313171d201b5928688524a01bd87Misha Brukman//
86fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//===----------------------------------------------------------------------===//
9009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner//
10009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner// This file contains the declaration of the Instruction class, which is the
11fab8c796f6754962f5732145248303e3a1f7b96bChris Lattner// base class for all of the LLVM instructions.
12009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner//
13009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner//===----------------------------------------------------------------------===//
14009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
15674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#ifndef LLVM_IR_INSTRUCTION_H
16674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#define LLVM_IR_INSTRUCTION_H
17009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
1836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/ADT/ArrayRef.h"
19fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman#include "llvm/ADT/ilist_node.h"
2036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/IR/DebugLoc.h"
210b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/User.h"
227a73b80b9052136c8cd2234eb3433a07df7cf38eJohn Criswell
23d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm {
24d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
251638b839090a35adcd5a4b4cc0a649352276e703Michael Ilsemanclass FastMathFlags;
2612ddd409535b52a7fa5157ded9a4cedd161fedb6Benjamin Kramerclass LLVMContext;
273990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattnerclass MDNode;
2837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hinesstruct AAMDNodes;
29333c40096561218bc3597cf153c0a3895274414cOwen Anderson
3017fcdd5e1b78b829068ca657c97357a39d6e768bChris Lattnertemplate<typename ValueSubClass, typename ItemParentClass>
3117fcdd5e1b78b829068ca657c97357a39d6e768bChris Lattner  class SymbolTableListTraits;
32009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
33fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass Instruction : public User, public ilist_node<Instruction> {
34ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  void operator=(const Instruction &) = delete;
35ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  Instruction(const Instruction &) = delete;
36c5f24a2c2a16681f7816ac053c8f46a2692a3b7aJeff Cohen
37009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  BasicBlock *Parent;
3884e679beea11ac55ed7871eec4deaccdf393de3eChris Lattner  DebugLoc DbgLoc;                         // 'dbg' Metadata cache.
39407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
40b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner  enum {
41b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner    /// HasMetadataBit - This is a bit stored in the SubClassData field which
42b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner    /// indicates whether this instruction has metadata attached to it or not.
43b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner    HasMetadataBit = 1 << 15
44b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner  };
45009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic:
46afba8fe662d65b25b4baf46bb26cc18e1f9cc0a5Gordon Henriksen  // Out of line virtual method, so the vtable, etc has a home.
47afba8fe662d65b25b4baf46bb26cc18e1f9cc0a5Gordon Henriksen  ~Instruction();
48407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
4936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// user_back - Specialize the methods defined in Value, as we know that an
50cb4f10b4d5e9ba2e37e70424b290dd1187ca6ea7Chris Lattner  /// instruction can only be used by other instructions.
5136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Instruction       *user_back()       { return cast<Instruction>(*user_begin());}
5236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  const Instruction *user_back() const { return cast<Instruction>(*user_begin());}
53407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
54009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  inline const BasicBlock *getParent() const { return Parent; }
55009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  inline       BasicBlock *getParent()       { return Parent; }
5618961504fc2b299578dba817900a0696cf3ccc4dChris Lattner
5736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  const DataLayout *getDataLayout() const;
5836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
59b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner  /// removeFromParent - This method unlinks 'this' from the containing basic
60b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner  /// block, but does not delete it.
61f0a93ed9c59d706494496c6fe4e8354864d24aa7Chris Lattner  ///
62b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner  void removeFromParent();
63b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner
64b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner  /// eraseFromParent - This method unlinks 'this' from the containing basic
65b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner  /// block and deletes it.
66b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner  ///
67b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner  void eraseFromParent();
68cfad5df977f257299063309fa34f3c24831093c4Chris Lattner
6926bb50ab48c561adfd32d129e0eff0cbf0a04625Owen Anderson  /// insertBefore - Insert an unlinked instructions into a basic block
7026bb50ab48c561adfd32d129e0eff0cbf0a04625Owen Anderson  /// immediately before the specified instruction.
7126bb50ab48c561adfd32d129e0eff0cbf0a04625Owen Anderson  void insertBefore(Instruction *InsertPos);
7226bb50ab48c561adfd32d129e0eff0cbf0a04625Owen Anderson
733ff704fa2b67d6c857142218c5aca3058b6239fcChris Lattner  /// insertAfter - Insert an unlinked instructions into a basic block
743ff704fa2b67d6c857142218c5aca3058b6239fcChris Lattner  /// immediately after the specified instruction.
753ff704fa2b67d6c857142218c5aca3058b6239fcChris Lattner  void insertAfter(Instruction *InsertPos);
763ff704fa2b67d6c857142218c5aca3058b6239fcChris Lattner
77287921d1889e101cb7f5cfa031a34ebe53a9a4a0Chris Lattner  /// moveBefore - Unlink this instruction from its current basic block and
78287921d1889e101cb7f5cfa031a34ebe53a9a4a0Chris Lattner  /// insert it into the basic block that MovePos lives in, right before
79287921d1889e101cb7f5cfa031a34ebe53a9a4a0Chris Lattner  /// MovePos.
80287921d1889e101cb7f5cfa031a34ebe53a9a4a0Chris Lattner  void moveBefore(Instruction *MovePos);
81287921d1889e101cb7f5cfa031a34ebe53a9a4a0Chris Lattner
823990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  //===--------------------------------------------------------------------===//
833990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  // Subclass classification.
843990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  //===--------------------------------------------------------------------===//
85407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
863990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  /// getOpcode() returns a member of one of the enums like Instruction::Add.
87a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman  unsigned getOpcode() const { return getValueID() - InstructionVal; }
88407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
89555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner  const char *getOpcodeName() const { return getOpcodeName(getOpcode()); }
90555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner  bool isTerminator() const { return isTerminator(getOpcode()); }
91555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner  bool isBinaryOp() const { return isBinaryOp(getOpcode()); }
92555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner  bool isShift() { return isShift(getOpcode()); }
93555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner  bool isCast() const { return isCast(getOpcode()); }
94407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
955814008f4b77774c8563578e1562c9c24a6750c2Vikram S. Adve  static const char* getOpcodeName(unsigned OpCode);
96009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
97dac69c83c22a00d3f8de3bb4d62b9dbeb0a20cafReid Spencer  static inline bool isTerminator(unsigned OpCode) {
98dac69c83c22a00d3f8de3bb4d62b9dbeb0a20cafReid Spencer    return OpCode >= TermOpsBegin && OpCode < TermOpsEnd;
99dac69c83c22a00d3f8de3bb4d62b9dbeb0a20cafReid Spencer  }
100dac69c83c22a00d3f8de3bb4d62b9dbeb0a20cafReid Spencer
101555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner  static inline bool isBinaryOp(unsigned Opcode) {
102555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner    return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd;
103009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  }
104009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
105832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer  /// @brief Determine if the Opcode is one of the shift instructions.
106832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer  static inline bool isShift(unsigned Opcode) {
107832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer    return Opcode >= Shl && Opcode <= AShr;
108832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer  }
109832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer
110832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer  /// isLogicalShift - Return true if this is a logical shift left or a logical
111832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer  /// shift right.
112cedbacffd67939d8e8f42e5506d458ddc187e575Dan Gohman  inline bool isLogicalShift() const {
113832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer    return getOpcode() == Shl || getOpcode() == LShr;
114832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer  }
115832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer
116031b7481c818b7ad6f43ba942ed33663aef7f1b8Misha Brukman  /// isArithmeticShift - Return true if this is an arithmetic shift right.
117cedbacffd67939d8e8f42e5506d458ddc187e575Dan Gohman  inline bool isArithmeticShift() const {
118832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer    return getOpcode() == AShr;
119832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer  }
120832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer
1213da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer  /// @brief Determine if the OpCode is one of the CastInst instructions.
1223da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer  static inline bool isCast(unsigned OpCode) {
1233da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer    return OpCode >= CastOpsBegin && OpCode < CastOpsEnd;
1243da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer  }
1253da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer
1263990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  //===--------------------------------------------------------------------===//
1273990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  // Metadata manipulation.
1283990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  //===--------------------------------------------------------------------===//
129407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
1303990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  /// hasMetadata() - Return true if this instruction has any metadata attached
1313990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  /// to it.
1323990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  bool hasMetadata() const {
13361336ae001e07c6d68454b1494e45954d373fb51Chris Lattner    return !DbgLoc.isUnknown() || hasMetadataHashEntry();
13461336ae001e07c6d68454b1494e45954d373fb51Chris Lattner  }
135407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
13661336ae001e07c6d68454b1494e45954d373fb51Chris Lattner  /// hasMetadataOtherThanDebugLoc - Return true if this instruction has
13761336ae001e07c6d68454b1494e45954d373fb51Chris Lattner  /// metadata attached to it other than a debug location.
13861336ae001e07c6d68454b1494e45954d373fb51Chris Lattner  bool hasMetadataOtherThanDebugLoc() const {
13961336ae001e07c6d68454b1494e45954d373fb51Chris Lattner    return hasMetadataHashEntry();
1403990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  }
141407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
1423990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  /// getMetadata - Get the metadata of given kind attached to this Instruction.
1433990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  /// If the metadata is not found then return null.
1443990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  MDNode *getMetadata(unsigned KindID) const {
145dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    if (!hasMetadata()) return nullptr;
1463990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner    return getMetadataImpl(KindID);
1473990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  }
148407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
1493990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  /// getMetadata - Get the metadata of given kind attached to this Instruction.
1503990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  /// If the metadata is not found then return null.
15185dadecbd664f60f0c7e4fbb44f083d43d01cfb7Benjamin Kramer  MDNode *getMetadata(StringRef Kind) const {
152dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    if (!hasMetadata()) return nullptr;
1533990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner    return getMetadataImpl(Kind);
1543990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  }
155407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
1563990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  /// getAllMetadata - Get all metadata attached to this Instruction.  The first
1573990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  /// element of each pair returned is the KindID, the second element is the
1583990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  /// metadata value.  This list is returned sorted by the KindID.
15937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void
16037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  getAllMetadata(SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs) const {
1613990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner    if (hasMetadata())
1623990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner      getAllMetadataImpl(MDs);
1633990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  }
164407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
16561336ae001e07c6d68454b1494e45954d373fb51Chris Lattner  /// getAllMetadataOtherThanDebugLoc - This does the same thing as
16661336ae001e07c6d68454b1494e45954d373fb51Chris Lattner  /// getAllMetadata, except that it filters out the debug location.
16737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void getAllMetadataOtherThanDebugLoc(
16837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines      SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs) const {
16961336ae001e07c6d68454b1494e45954d373fb51Chris Lattner    if (hasMetadataOtherThanDebugLoc())
17061336ae001e07c6d68454b1494e45954d373fb51Chris Lattner      getAllMetadataOtherThanDebugLocImpl(MDs);
17161336ae001e07c6d68454b1494e45954d373fb51Chris Lattner  }
172407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
17337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// getAAMetadata - Fills the AAMDNodes structure with AA metadata from
17437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// this instruction. When Merge is true, the existing AA metadata is
17537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// merged with that from this instruction providing the most-general result.
17637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void getAAMetadata(AAMDNodes &N, bool Merge = false) const;
17737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
178f451cb870efcf9e0302d25ed05f4cac6bb494e42Dan Gohman  /// setMetadata - Set the metadata of the specified kind to the specified
1793990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  /// node.  This updates/replaces metadata if already present, or removes it if
1803990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  /// Node is null.
1813990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  void setMetadata(unsigned KindID, MDNode *Node);
18285dadecbd664f60f0c7e4fbb44f083d43d01cfb7Benjamin Kramer  void setMetadata(StringRef Kind, MDNode *Node);
1833990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner
18436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// \brief Drop unknown metadata.
18536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// Passes are required to drop metadata they don't understand. This is a
18636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// convenience method for passes to do so.
18736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  void dropUnknownMetadata(ArrayRef<unsigned> KnownIDs);
18836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  void dropUnknownMetadata() {
18937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines    return dropUnknownMetadata(None);
19036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
19136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  void dropUnknownMetadata(unsigned ID1) {
19236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return dropUnknownMetadata(makeArrayRef(ID1));
19336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
19436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  void dropUnknownMetadata(unsigned ID1, unsigned ID2) {
19536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    unsigned IDs[] = {ID1, ID2};
19636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return dropUnknownMetadata(IDs);
19736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
19836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
19937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// setAAMetadata - Sets the metadata on this instruction from the
20037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// AAMDNodes structure.
20137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void setAAMetadata(const AAMDNodes &N);
20237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
20361336ae001e07c6d68454b1494e45954d373fb51Chris Lattner  /// setDebugLoc - Set the debug location information for this instruction.
204ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  void setDebugLoc(DebugLoc Loc) { DbgLoc = std::move(Loc); }
205407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
20661336ae001e07c6d68454b1494e45954d373fb51Chris Lattner  /// getDebugLoc - Return the debug location for this node as a DebugLoc.
20784e679beea11ac55ed7871eec4deaccdf393de3eChris Lattner  const DebugLoc &getDebugLoc() const { return DbgLoc; }
208407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
209125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// Set or clear the unsafe-algebra flag on this instruction, which must be an
210125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// operator which supports this flag. See LangRef.html for the meaning of
211125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// this flag.
212125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  void setHasUnsafeAlgebra(bool B);
213125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman
214125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// Set or clear the no-nans flag on this instruction, which must be an
215125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// operator which supports this flag. See LangRef.html for the meaning of
216125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// this flag.
217125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  void setHasNoNaNs(bool B);
218125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman
219125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// Set or clear the no-infs flag on this instruction, which must be an
220125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// operator which supports this flag. See LangRef.html for the meaning of
221125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// this flag.
222125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  void setHasNoInfs(bool B);
223125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman
224125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// Set or clear the no-signed-zeros flag on this instruction, which must be
225125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// an operator which supports this flag. See LangRef.html for the meaning of
226125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// this flag.
227125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  void setHasNoSignedZeros(bool B);
228125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman
229125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// Set or clear the allow-reciprocal flag on this instruction, which must be
230125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// an operator which supports this flag. See LangRef.html for the meaning of
231125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// this flag.
232125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  void setHasAllowReciprocal(bool B);
233125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman
23437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// Convenience function for setting multiple fast-math flags on this
235125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// instruction, which must be an operator which supports these flags. See
23637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// LangRef.html for the meaning of these flags.
237125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  void setFastMathFlags(FastMathFlags FMF);
238125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman
23937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// Convenience function for transferring all fast-math flag values to this
24037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// instruction, which must be an operator which supports these flags. See
24137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// LangRef.html for the meaning of these flags.
24237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void copyFastMathFlags(FastMathFlags FMF);
24337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
244125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// Determine whether the unsafe-algebra flag is set.
245125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  bool hasUnsafeAlgebra() const;
246125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman
247125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// Determine whether the no-NaNs flag is set.
248125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  bool hasNoNaNs() const;
249125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman
250125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// Determine whether the no-infs flag is set.
251125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  bool hasNoInfs() const;
252125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman
253125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// Determine whether the no-signed-zeros flag is set.
254125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  bool hasNoSignedZeros() const;
255125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman
256125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// Determine whether the allow-reciprocal flag is set.
257125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  bool hasAllowReciprocal() const;
258125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman
259125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// Convenience function for getting all the fast-math flags, which must be an
260125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  /// operator which supports these flags. See LangRef.html for the meaning of
26137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// these flags.
262125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman  FastMathFlags getFastMathFlags() const;
263125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman
2644b896dd613b1d85ee1b261ee470cb72fab24c282Michael Ilseman  /// Copy I's fast-math flags
2654b896dd613b1d85ee1b261ee470cb72fab24c282Michael Ilseman  void copyFastMathFlags(const Instruction *I);
2664b896dd613b1d85ee1b261ee470cb72fab24c282Michael Ilseman
2673990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattnerprivate:
268ec39f095f5abaf1ec90d7c6c46454032cda36e1cChris Lattner  /// hasMetadataHashEntry - Return true if we have an entry in the on-the-side
269ec39f095f5abaf1ec90d7c6c46454032cda36e1cChris Lattner  /// metadata hash.
270ec39f095f5abaf1ec90d7c6c46454032cda36e1cChris Lattner  bool hasMetadataHashEntry() const {
271ec39f095f5abaf1ec90d7c6c46454032cda36e1cChris Lattner    return (getSubclassDataFromValue() & HasMetadataBit) != 0;
272ec39f095f5abaf1ec90d7c6c46454032cda36e1cChris Lattner  }
273407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
2743990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  // These are all implemented in Metadata.cpp.
2753990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  MDNode *getMetadataImpl(unsigned KindID) const;
27685dadecbd664f60f0c7e4fbb44f083d43d01cfb7Benjamin Kramer  MDNode *getMetadataImpl(StringRef Kind) const;
27737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void
27837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned, MDNode *>> &) const;
27937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void getAllMetadataOtherThanDebugLocImpl(
28037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines      SmallVectorImpl<std::pair<unsigned, MDNode *>> &) const;
2814f1be4abba762f8a7b77d7622abaf1ed1a87b48bDan Gohman  void clearMetadataHashEntries();
2823990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattnerpublic:
2833990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  //===--------------------------------------------------------------------===//
2843990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  // Predicates and helper methods.
2853990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner  //===--------------------------------------------------------------------===//
286407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
287407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
288f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner  /// isAssociative - Return true if the instruction is associative:
289f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner  ///
290686e65fb65f97176e000c4d4cae82fc7b404ef9dMisha Brukman  ///   Associative operators satisfy:  x op (y op z) === (x op y) op z
291f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner  ///
2920d7ce5ffa4aa853b75e1015c62e27bd9f23ef73bDuncan Sands  /// In LLVM, the Add, Mul, And, Or, and Xor operators are associative.
293f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner  ///
2949b7f6f2de89a321f7eae5e942c8668cb50acfd1dShuxin Yang  bool isAssociative() const;
2950d7ce5ffa4aa853b75e1015c62e27bd9f23ef73bDuncan Sands  static bool isAssociative(unsigned op);
296f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner
297f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner  /// isCommutative - Return true if the instruction is commutative:
298f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner  ///
299686e65fb65f97176e000c4d4cae82fc7b404ef9dMisha Brukman  ///   Commutative operators satisfy: (x op y) === (y op x)
300f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner  ///
301f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner  /// In LLVM, these are the associative operators, plus SetEQ and SetNE, when
302f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner  /// applied to any type.
303f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner  ///
304f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner  bool isCommutative() const { return isCommutative(getOpcode()); }
305f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner  static bool isCommutative(unsigned op);
306f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner
307c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands  /// isIdempotent - Return true if the instruction is idempotent:
308c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands  ///
309c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands  ///   Idempotent operators satisfy:  x op x === x
310c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands  ///
311c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands  /// In LLVM, the And and Or operators are idempotent.
312c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands  ///
313c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands  bool isIdempotent() const { return isIdempotent(getOpcode()); }
314c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands  static bool isIdempotent(unsigned op);
315c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands
316c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands  /// isNilpotent - Return true if the instruction is nilpotent:
317c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands  ///
318c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands  ///   Nilpotent operators satisfy:  x op x === Id,
319c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands  ///
320c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands  ///   where Id is the identity for the operator, i.e. a constant such that
321c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands  ///     x op Id === x and Id op x === x for all x.
322c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands  ///
323c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands  /// In LLVM, the Xor operator is nilpotent.
324c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands  ///
325c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands  bool isNilpotent() const { return isNilpotent(getOpcode()); }
326c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands  static bool isNilpotent(unsigned op);
327c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands
3287af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands  /// mayWriteToMemory - Return true if this instruction may modify memory.
3297af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands  ///
3307af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands  bool mayWriteToMemory() const;
3317af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands
3327af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands  /// mayReadFromMemory - Return true if this instruction may read memory.
3337af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands  ///
3347af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands  bool mayReadFromMemory() const;
3357af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands
3366f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman  /// mayReadOrWriteMemory - Return true if this instruction may read or
3376f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman  /// write memory.
3386f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman  ///
3396f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman  bool mayReadOrWriteMemory() const {
3406f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman    return mayReadFromMemory() || mayWriteToMemory();
3416f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman  }
3426f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman
34337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// isAtomic - Return true if this instruction has an
34437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// AtomicOrdering of unordered or higher.
34537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  ///
34637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  bool isAtomic() const;
34737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
3487af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands  /// mayThrow - Return true if this instruction may throw an exception.
3497af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands  ///
3507af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands  bool mayThrow() const;
3517af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands
35203544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem  /// mayReturn - Return true if this is a function that may return.
35303544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem  /// this is true for all normal instructions. The only exception
35403544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem  /// is functions that are marked with the 'noreturn' attribute.
35503544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem  ///
35603544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem  bool mayReturn() const;
35703544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem
3587af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands  /// mayHaveSideEffects - Return true if the instruction may have side effects.
3597af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands  ///
3608b7d706c80afa7ad40acaab08f7406093a2851ffEli Friedman  /// Note that this does not consider malloc and alloca to have side
3618b7d706c80afa7ad40acaab08f7406093a2851ffEli Friedman  /// effects because the newly allocated memory is completely invisible to
3628b7d706c80afa7ad40acaab08f7406093a2851ffEli Friedman  /// instructions which don't used the returned value.  For cases where this
3638b7d706c80afa7ad40acaab08f7406093a2851ffEli Friedman  /// matters, isSafeToSpeculativelyExecute may be more appropriate.
3647af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands  bool mayHaveSideEffects() const {
36503544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem    return mayWriteToMemory() || mayThrow() || !mayReturn();
3667af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands  }
3677af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands
368f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// clone() - Create a copy of 'this' instruction that is identical in all
369f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// ways except the following:
370f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  ///   * The instruction has no parent
371f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  ///   * The instruction has no name
372f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  ///
373f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  Instruction *clone() const;
374407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
375f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// isIdenticalTo - Return true if the specified instruction is exactly
376f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// identical to the current one.  This means that all operands match and any
377f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// extra information (e.g. load is volatile) agree.
378f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  bool isIdenticalTo(const Instruction *I) const;
379407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
380f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// isIdenticalToWhenDefined - This is like isIdenticalTo, except that it
381f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// ignores the SubclassOptionalData flags, which specify conditions
382f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// under which the instruction's result is undefined.
383f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  bool isIdenticalToWhenDefined(const Instruction *I) const;
384ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel
385ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel  /// When checking for operation equivalence (using isSameOperationAs) it is
386ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel  /// sometimes useful to ignore certain attributes.
387ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel  enum OperationEquivalenceFlags {
388ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel    /// Check for equivalence ignoring load/store alignment.
389ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel    CompareIgnoringAlignment = 1<<0,
390ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel    /// Check for equivalence treating a type and a vector of that type
391ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel    /// as equivalent.
392ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel    CompareUsingScalarTypes = 1<<1
393ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel  };
394407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
395f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// This function determines if the specified instruction executes the same
396f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// operation as the current one. This means that the opcodes, type, operand
397f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// types and any other factors affecting the operation must be the same. This
398f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// is similar to isIdenticalTo except the operands themselves don't have to
399f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// be identical.
400f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// @returns true if the specified instruction is the same operation as
401f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// the current one.
402f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// @brief Determine if one instruction is the same operation as another.
403ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel  bool isSameOperationAs(const Instruction *I, unsigned flags = 0) const;
404407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
405f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// isUsedOutsideOfBlock - Return true if there are any uses of this
406f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// instruction in blocks other than the specified block.  Note that PHI nodes
407f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// are considered to evaluate their operands in the corresponding predecessor
408f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  /// block.
409f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  bool isUsedOutsideOfBlock(const BasicBlock *BB) const;
410407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
411407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
41226199059268a05739c84ebf465fcdbf7ded861dfChris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
413b00c582b6d40e6b9ff2d1ed4f5eaf7930e792aceChris Lattner  static inline bool classof(const Value *V) {
414a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman    return V->getValueID() >= Value::InstructionVal;
4157295eb4ea3e3a81e697600cbca681674e4b35a20Chris Lattner  }
4169769ab22265b313171d201b5928688524a01bd87Misha Brukman
417009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  //----------------------------------------------------------------------
418f309880ad86114cda05037538c46123f6cda1a7eChris Lattner  // Exported enumerations.
419009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  //
420009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  enum TermOps {       // These terminate basic blocks
4210b16ae209a1d0876a7ea6800bb567d925443cba3Chris Lattner#define  FIRST_TERM_INST(N)             TermOpsBegin = N,
422f96315e985880178562ba43b51efbc0efc8f6c8aChris Lattner#define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
42382870e0b733fa72c759271c1c62cb5f07be2c4dbChris Lattner#define   LAST_TERM_INST(N)             TermOpsEnd = N+1
4240b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instruction.def"
425009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  };
426009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
427009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  enum BinaryOps {
4280b16ae209a1d0876a7ea6800bb567d925443cba3Chris Lattner#define  FIRST_BINARY_INST(N)             BinaryOpsBegin = N,
429f96315e985880178562ba43b51efbc0efc8f6c8aChris Lattner#define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
43082870e0b733fa72c759271c1c62cb5f07be2c4dbChris Lattner#define   LAST_BINARY_INST(N)             BinaryOpsEnd = N+1
4310b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instruction.def"
432009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  };
433009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
434009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  enum MemoryOps {
4350b16ae209a1d0876a7ea6800bb567d925443cba3Chris Lattner#define  FIRST_MEMORY_INST(N)             MemoryOpsBegin = N,
436f96315e985880178562ba43b51efbc0efc8f6c8aChris Lattner#define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
43782870e0b733fa72c759271c1c62cb5f07be2c4dbChris Lattner#define   LAST_MEMORY_INST(N)             MemoryOpsEnd = N+1
4380b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instruction.def"
439009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  };
440009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
4413da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer  enum CastOps {
4423da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer#define  FIRST_CAST_INST(N)             CastOpsBegin = N,
4433da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer#define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N,
4443da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer#define   LAST_CAST_INST(N)             CastOpsEnd = N+1
4450b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instruction.def"
4463da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer  };
4473da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer
448009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  enum OtherOps {
4490b16ae209a1d0876a7ea6800bb567d925443cba3Chris Lattner#define  FIRST_OTHER_INST(N)             OtherOpsBegin = N,
450f96315e985880178562ba43b51efbc0efc8f6c8aChris Lattner#define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
45182870e0b733fa72c759271c1c62cb5f07be2c4dbChris Lattner#define   LAST_OTHER_INST(N)             OtherOpsEnd = N+1
4520b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instruction.def"
453009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  };
454b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattnerprivate:
455b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner  // Shadow Value::setValueSubclassData with a private forwarding method so that
456b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner  // subclasses cannot accidentally use it.
457b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner  void setValueSubclassData(unsigned short D) {
458b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner    Value::setValueSubclassData(D);
459b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner  }
460b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner  unsigned short getSubclassDataFromValue() const {
461b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner    return Value::getSubclassDataFromValue();
462b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner  }
463407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
464ec39f095f5abaf1ec90d7c6c46454032cda36e1cChris Lattner  void setHasMetadataHashEntry(bool V) {
465b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner    setValueSubclassData((getSubclassDataFromValue() & ~HasMetadataBit) |
466b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner                         (V ? HasMetadataBit : 0));
467b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner  }
468407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
469b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner  friend class SymbolTableListTraits<Instruction, BasicBlock>;
470b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner  void setParent(BasicBlock *P);
471b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattnerprotected:
472b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner  // Instruction subclasses can stick up to 15 bits of stuff into the
473b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner  // SubclassData field of instruction with these members.
474407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
475b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner  // Verify that only the low 15 bits are used.
476b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner  void setInstructionSubclassData(unsigned short D) {
477b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner    assert((D & HasMetadataBit) == 0 && "Out of range value put into field");
478b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner    setValueSubclassData((getSubclassDataFromValue() & HasMetadataBit) | D);
479b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner  }
480407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
481b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner  unsigned getSubclassDataFromInstruction() const {
482b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner    return getSubclassDataFromValue() & ~HasMetadataBit;
483b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner  }
484407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
485db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner  Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps,
486dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines              Instruction *InsertBefore = nullptr);
487db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner  Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps,
488b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner              BasicBlock *InsertAtEnd);
489b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner  virtual Instruction *clone_impl() const = 0;
490407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
491009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner};
492009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
493e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner// Instruction* is only 4-byte aligned.
494e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattnertemplate<>
495e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattnerclass PointerLikeTypeTraits<Instruction*> {
496e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner  typedef Instruction* PT;
497e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattnerpublic:
498e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner  static inline void *getAsVoidPointer(PT P) { return P; }
499e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner  static inline PT getFromVoidPointer(void *P) {
500e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner    return static_cast<PT>(P);
501e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner  }
502e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner  enum { NumLowBitsAvailable = 2 };
503e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner};
504407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman
505d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace
506d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
507009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner#endif
508