Instruction.h revision 4c5e43da7792f75567b693105cc53e3f1992ad98
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 574c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar /// \brief Return the module owning the function this instruction belongs to 584c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar /// or nullptr it the function does not have a module. 594c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar /// 604c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar /// Note: this is undefined behavior if the instruction does not have a 614c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar /// parent, or the parent basic block does not have a parent function. 624c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar const Module *getModule() const; 6336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 64b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner /// removeFromParent - This method unlinks 'this' from the containing basic 65b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner /// block, but does not delete it. 66f0a93ed9c59d706494496c6fe4e8354864d24aa7Chris Lattner /// 67b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner void removeFromParent(); 68b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner 69b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner /// eraseFromParent - This method unlinks 'this' from the containing basic 70b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner /// block and deletes it. 71b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner /// 72b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner void eraseFromParent(); 73cfad5df977f257299063309fa34f3c24831093c4Chris Lattner 7426bb50ab48c561adfd32d129e0eff0cbf0a04625Owen Anderson /// insertBefore - Insert an unlinked instructions into a basic block 7526bb50ab48c561adfd32d129e0eff0cbf0a04625Owen Anderson /// immediately before the specified instruction. 7626bb50ab48c561adfd32d129e0eff0cbf0a04625Owen Anderson void insertBefore(Instruction *InsertPos); 7726bb50ab48c561adfd32d129e0eff0cbf0a04625Owen Anderson 783ff704fa2b67d6c857142218c5aca3058b6239fcChris Lattner /// insertAfter - Insert an unlinked instructions into a basic block 793ff704fa2b67d6c857142218c5aca3058b6239fcChris Lattner /// immediately after the specified instruction. 803ff704fa2b67d6c857142218c5aca3058b6239fcChris Lattner void insertAfter(Instruction *InsertPos); 813ff704fa2b67d6c857142218c5aca3058b6239fcChris Lattner 82287921d1889e101cb7f5cfa031a34ebe53a9a4a0Chris Lattner /// moveBefore - Unlink this instruction from its current basic block and 83287921d1889e101cb7f5cfa031a34ebe53a9a4a0Chris Lattner /// insert it into the basic block that MovePos lives in, right before 84287921d1889e101cb7f5cfa031a34ebe53a9a4a0Chris Lattner /// MovePos. 85287921d1889e101cb7f5cfa031a34ebe53a9a4a0Chris Lattner void moveBefore(Instruction *MovePos); 86287921d1889e101cb7f5cfa031a34ebe53a9a4a0Chris Lattner 873990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner //===--------------------------------------------------------------------===// 883990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner // Subclass classification. 893990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner //===--------------------------------------------------------------------===// 90407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 913990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// getOpcode() returns a member of one of the enums like Instruction::Add. 92a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman unsigned getOpcode() const { return getValueID() - InstructionVal; } 93407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 94555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner const char *getOpcodeName() const { return getOpcodeName(getOpcode()); } 95555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner bool isTerminator() const { return isTerminator(getOpcode()); } 96555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner bool isBinaryOp() const { return isBinaryOp(getOpcode()); } 97555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner bool isShift() { return isShift(getOpcode()); } 98555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner bool isCast() const { return isCast(getOpcode()); } 99407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 1005814008f4b77774c8563578e1562c9c24a6750c2Vikram S. Adve static const char* getOpcodeName(unsigned OpCode); 101009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 102dac69c83c22a00d3f8de3bb4d62b9dbeb0a20cafReid Spencer static inline bool isTerminator(unsigned OpCode) { 103dac69c83c22a00d3f8de3bb4d62b9dbeb0a20cafReid Spencer return OpCode >= TermOpsBegin && OpCode < TermOpsEnd; 104dac69c83c22a00d3f8de3bb4d62b9dbeb0a20cafReid Spencer } 105dac69c83c22a00d3f8de3bb4d62b9dbeb0a20cafReid Spencer 106555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner static inline bool isBinaryOp(unsigned Opcode) { 107555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd; 108009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner } 109009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 110832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer /// @brief Determine if the Opcode is one of the shift instructions. 111832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer static inline bool isShift(unsigned Opcode) { 112832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer return Opcode >= Shl && Opcode <= AShr; 113832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer } 114832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer 115832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer /// isLogicalShift - Return true if this is a logical shift left or a logical 116832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer /// shift right. 117cedbacffd67939d8e8f42e5506d458ddc187e575Dan Gohman inline bool isLogicalShift() const { 118832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer return getOpcode() == Shl || getOpcode() == LShr; 119832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer } 120832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer 121031b7481c818b7ad6f43ba942ed33663aef7f1b8Misha Brukman /// isArithmeticShift - Return true if this is an arithmetic shift right. 122cedbacffd67939d8e8f42e5506d458ddc187e575Dan Gohman inline bool isArithmeticShift() const { 123832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer return getOpcode() == AShr; 124832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer } 125832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer 1263da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer /// @brief Determine if the OpCode is one of the CastInst instructions. 1273da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer static inline bool isCast(unsigned OpCode) { 1283da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer return OpCode >= CastOpsBegin && OpCode < CastOpsEnd; 1293da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer } 1303da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer 1313990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner //===--------------------------------------------------------------------===// 1323990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner // Metadata manipulation. 1333990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner //===--------------------------------------------------------------------===// 134407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 1353990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// hasMetadata() - Return true if this instruction has any metadata attached 1363990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// to it. 1373990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner bool hasMetadata() const { 13861336ae001e07c6d68454b1494e45954d373fb51Chris Lattner return !DbgLoc.isUnknown() || hasMetadataHashEntry(); 13961336ae001e07c6d68454b1494e45954d373fb51Chris Lattner } 140407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 14161336ae001e07c6d68454b1494e45954d373fb51Chris Lattner /// hasMetadataOtherThanDebugLoc - Return true if this instruction has 14261336ae001e07c6d68454b1494e45954d373fb51Chris Lattner /// metadata attached to it other than a debug location. 14361336ae001e07c6d68454b1494e45954d373fb51Chris Lattner bool hasMetadataOtherThanDebugLoc() const { 14461336ae001e07c6d68454b1494e45954d373fb51Chris Lattner return hasMetadataHashEntry(); 1453990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner } 146407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 1473990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// getMetadata - Get the metadata of given kind attached to this Instruction. 1483990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// If the metadata is not found then return null. 1493990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner MDNode *getMetadata(unsigned KindID) const { 150dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines if (!hasMetadata()) return nullptr; 1513990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner return getMetadataImpl(KindID); 1523990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner } 153407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 1543990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// getMetadata - Get the metadata of given kind attached to this Instruction. 1553990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// If the metadata is not found then return null. 15685dadecbd664f60f0c7e4fbb44f083d43d01cfb7Benjamin Kramer MDNode *getMetadata(StringRef Kind) const { 157dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines if (!hasMetadata()) return nullptr; 1583990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner return getMetadataImpl(Kind); 1593990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner } 160407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 1613990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// getAllMetadata - Get all metadata attached to this Instruction. The first 1623990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// element of each pair returned is the KindID, the second element is the 1633990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// metadata value. This list is returned sorted by the KindID. 16437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines void 16537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines getAllMetadata(SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs) const { 1663990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner if (hasMetadata()) 1673990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner getAllMetadataImpl(MDs); 1683990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner } 169407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 17061336ae001e07c6d68454b1494e45954d373fb51Chris Lattner /// getAllMetadataOtherThanDebugLoc - This does the same thing as 17161336ae001e07c6d68454b1494e45954d373fb51Chris Lattner /// getAllMetadata, except that it filters out the debug location. 17237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines void getAllMetadataOtherThanDebugLoc( 17337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs) const { 17461336ae001e07c6d68454b1494e45954d373fb51Chris Lattner if (hasMetadataOtherThanDebugLoc()) 17561336ae001e07c6d68454b1494e45954d373fb51Chris Lattner getAllMetadataOtherThanDebugLocImpl(MDs); 17661336ae001e07c6d68454b1494e45954d373fb51Chris Lattner } 177407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 17837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// getAAMetadata - Fills the AAMDNodes structure with AA metadata from 17937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// this instruction. When Merge is true, the existing AA metadata is 18037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// merged with that from this instruction providing the most-general result. 18137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines void getAAMetadata(AAMDNodes &N, bool Merge = false) const; 18237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines 183f451cb870efcf9e0302d25ed05f4cac6bb494e42Dan Gohman /// setMetadata - Set the metadata of the specified kind to the specified 1843990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// node. This updates/replaces metadata if already present, or removes it if 1853990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// Node is null. 1863990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner void setMetadata(unsigned KindID, MDNode *Node); 18785dadecbd664f60f0c7e4fbb44f083d43d01cfb7Benjamin Kramer void setMetadata(StringRef Kind, MDNode *Node); 1883990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner 18936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// \brief Drop unknown metadata. 19036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// Passes are required to drop metadata they don't understand. This is a 19136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// convenience method for passes to do so. 19236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines void dropUnknownMetadata(ArrayRef<unsigned> KnownIDs); 19336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines void dropUnknownMetadata() { 19437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines return dropUnknownMetadata(None); 19536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines } 19636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines void dropUnknownMetadata(unsigned ID1) { 19736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return dropUnknownMetadata(makeArrayRef(ID1)); 19836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines } 19936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines void dropUnknownMetadata(unsigned ID1, unsigned ID2) { 20036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines unsigned IDs[] = {ID1, ID2}; 20136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return dropUnknownMetadata(IDs); 20236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines } 20336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 20437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// setAAMetadata - Sets the metadata on this instruction from the 20537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// AAMDNodes structure. 20637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines void setAAMetadata(const AAMDNodes &N); 20737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines 20861336ae001e07c6d68454b1494e45954d373fb51Chris Lattner /// setDebugLoc - Set the debug location information for this instruction. 209ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines void setDebugLoc(DebugLoc Loc) { DbgLoc = std::move(Loc); } 210407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 21161336ae001e07c6d68454b1494e45954d373fb51Chris Lattner /// getDebugLoc - Return the debug location for this node as a DebugLoc. 21284e679beea11ac55ed7871eec4deaccdf393de3eChris Lattner const DebugLoc &getDebugLoc() const { return DbgLoc; } 213407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 214125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Set or clear the unsafe-algebra 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 setHasUnsafeAlgebra(bool B); 218125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 219125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Set or clear the no-nans 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 setHasNoNaNs(bool B); 223125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 224125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Set or clear the no-infs flag on this instruction, which must be an 225125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// operator which supports this flag. See LangRef.html for the meaning of 226125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// this flag. 227125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman void setHasNoInfs(bool B); 228125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 229125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Set or clear the no-signed-zeros 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 setHasNoSignedZeros(bool B); 233125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 234125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Set or clear the allow-reciprocal flag on this instruction, which must be 235125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// an operator which supports this flag. See LangRef.html for the meaning of 236125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// this flag. 237125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman void setHasAllowReciprocal(bool B); 238125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 23937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// Convenience function for setting multiple fast-math flags on this 240125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// instruction, which must be an operator which supports these flags. See 24137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// LangRef.html for the meaning of these flags. 242125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman void setFastMathFlags(FastMathFlags FMF); 243125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 24437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// Convenience function for transferring all fast-math flag values to this 24537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// instruction, which must be an operator which supports these flags. See 24637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// LangRef.html for the meaning of these flags. 24737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines void copyFastMathFlags(FastMathFlags FMF); 24837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines 249125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Determine whether the unsafe-algebra flag is set. 250125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman bool hasUnsafeAlgebra() const; 251125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 252125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Determine whether the no-NaNs flag is set. 253125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman bool hasNoNaNs() const; 254125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 255125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Determine whether the no-infs flag is set. 256125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman bool hasNoInfs() const; 257125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 258125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Determine whether the no-signed-zeros flag is set. 259125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman bool hasNoSignedZeros() const; 260125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 261125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Determine whether the allow-reciprocal flag is set. 262125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman bool hasAllowReciprocal() const; 263125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 264125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Convenience function for getting all the fast-math flags, which must be an 265125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// operator which supports these flags. See LangRef.html for the meaning of 26637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// these flags. 267125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman FastMathFlags getFastMathFlags() const; 268125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 2694b896dd613b1d85ee1b261ee470cb72fab24c282Michael Ilseman /// Copy I's fast-math flags 2704b896dd613b1d85ee1b261ee470cb72fab24c282Michael Ilseman void copyFastMathFlags(const Instruction *I); 2714b896dd613b1d85ee1b261ee470cb72fab24c282Michael Ilseman 2723990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattnerprivate: 273ec39f095f5abaf1ec90d7c6c46454032cda36e1cChris Lattner /// hasMetadataHashEntry - Return true if we have an entry in the on-the-side 274ec39f095f5abaf1ec90d7c6c46454032cda36e1cChris Lattner /// metadata hash. 275ec39f095f5abaf1ec90d7c6c46454032cda36e1cChris Lattner bool hasMetadataHashEntry() const { 276ec39f095f5abaf1ec90d7c6c46454032cda36e1cChris Lattner return (getSubclassDataFromValue() & HasMetadataBit) != 0; 277ec39f095f5abaf1ec90d7c6c46454032cda36e1cChris Lattner } 278407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 2793990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner // These are all implemented in Metadata.cpp. 2803990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner MDNode *getMetadataImpl(unsigned KindID) const; 28185dadecbd664f60f0c7e4fbb44f083d43d01cfb7Benjamin Kramer MDNode *getMetadataImpl(StringRef Kind) const; 28237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines void 28337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned, MDNode *>> &) const; 28437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines void getAllMetadataOtherThanDebugLocImpl( 28537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines SmallVectorImpl<std::pair<unsigned, MDNode *>> &) const; 2864f1be4abba762f8a7b77d7622abaf1ed1a87b48bDan Gohman void clearMetadataHashEntries(); 2873990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattnerpublic: 2883990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner //===--------------------------------------------------------------------===// 2893990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner // Predicates and helper methods. 2903990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner //===--------------------------------------------------------------------===// 291407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 292407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 293f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// isAssociative - Return true if the instruction is associative: 294f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// 295686e65fb65f97176e000c4d4cae82fc7b404ef9dMisha Brukman /// Associative operators satisfy: x op (y op z) === (x op y) op z 296f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// 2970d7ce5ffa4aa853b75e1015c62e27bd9f23ef73bDuncan Sands /// In LLVM, the Add, Mul, And, Or, and Xor operators are associative. 298f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// 2999b7f6f2de89a321f7eae5e942c8668cb50acfd1dShuxin Yang bool isAssociative() const; 3000d7ce5ffa4aa853b75e1015c62e27bd9f23ef73bDuncan Sands static bool isAssociative(unsigned op); 301f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner 302f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// isCommutative - Return true if the instruction is commutative: 303f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// 304686e65fb65f97176e000c4d4cae82fc7b404ef9dMisha Brukman /// Commutative operators satisfy: (x op y) === (y op x) 305f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// 306f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// In LLVM, these are the associative operators, plus SetEQ and SetNE, when 307f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// applied to any type. 308f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// 309f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner bool isCommutative() const { return isCommutative(getOpcode()); } 310f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner static bool isCommutative(unsigned op); 311f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner 312c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// isIdempotent - Return true if the instruction is idempotent: 313c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// 314c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// Idempotent operators satisfy: x op x === x 315c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// 316c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// In LLVM, the And and Or operators are idempotent. 317c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// 318c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands bool isIdempotent() const { return isIdempotent(getOpcode()); } 319c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands static bool isIdempotent(unsigned op); 320c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands 321c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// isNilpotent - Return true if the instruction is nilpotent: 322c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// 323c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// Nilpotent operators satisfy: x op x === Id, 324c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// 325c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// where Id is the identity for the operator, i.e. a constant such that 326c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// x op Id === x and Id op x === x for all x. 327c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// 328c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// In LLVM, the Xor operator is nilpotent. 329c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// 330c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands bool isNilpotent() const { return isNilpotent(getOpcode()); } 331c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands static bool isNilpotent(unsigned op); 332c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands 3337af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands /// mayWriteToMemory - Return true if this instruction may modify memory. 3347af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands /// 3357af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands bool mayWriteToMemory() const; 3367af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands 3377af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands /// mayReadFromMemory - Return true if this instruction may read memory. 3387af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands /// 3397af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands bool mayReadFromMemory() const; 3407af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands 3416f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman /// mayReadOrWriteMemory - Return true if this instruction may read or 3426f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman /// write memory. 3436f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman /// 3446f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman bool mayReadOrWriteMemory() const { 3456f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman return mayReadFromMemory() || mayWriteToMemory(); 3466f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman } 3476f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman 34837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// isAtomic - Return true if this instruction has an 34937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// AtomicOrdering of unordered or higher. 35037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// 35137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines bool isAtomic() const; 35237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines 3537af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands /// mayThrow - Return true if this instruction may throw an exception. 3547af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands /// 3557af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands bool mayThrow() const; 3567af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands 35703544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem /// mayReturn - Return true if this is a function that may return. 35803544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem /// this is true for all normal instructions. The only exception 35903544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem /// is functions that are marked with the 'noreturn' attribute. 36003544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem /// 36103544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem bool mayReturn() const; 36203544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem 3637af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands /// mayHaveSideEffects - Return true if the instruction may have side effects. 3647af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands /// 3658b7d706c80afa7ad40acaab08f7406093a2851ffEli Friedman /// Note that this does not consider malloc and alloca to have side 3668b7d706c80afa7ad40acaab08f7406093a2851ffEli Friedman /// effects because the newly allocated memory is completely invisible to 3678b7d706c80afa7ad40acaab08f7406093a2851ffEli Friedman /// instructions which don't used the returned value. For cases where this 3688b7d706c80afa7ad40acaab08f7406093a2851ffEli Friedman /// matters, isSafeToSpeculativelyExecute may be more appropriate. 3697af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands bool mayHaveSideEffects() const { 37003544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem return mayWriteToMemory() || mayThrow() || !mayReturn(); 3717af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands } 3727af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands 373f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// clone() - Create a copy of 'this' instruction that is identical in all 374f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// ways except the following: 375f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// * The instruction has no parent 376f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// * The instruction has no name 377f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// 378f309880ad86114cda05037538c46123f6cda1a7eChris Lattner Instruction *clone() const; 379407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 380f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// isIdenticalTo - Return true if the specified instruction is exactly 381f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// identical to the current one. This means that all operands match and any 382f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// extra information (e.g. load is volatile) agree. 383f309880ad86114cda05037538c46123f6cda1a7eChris Lattner bool isIdenticalTo(const Instruction *I) const; 384407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 385f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// isIdenticalToWhenDefined - This is like isIdenticalTo, except that it 386f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// ignores the SubclassOptionalData flags, which specify conditions 387f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// under which the instruction's result is undefined. 388f309880ad86114cda05037538c46123f6cda1a7eChris Lattner bool isIdenticalToWhenDefined(const Instruction *I) const; 389ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel 390ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel /// When checking for operation equivalence (using isSameOperationAs) it is 391ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel /// sometimes useful to ignore certain attributes. 392ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel enum OperationEquivalenceFlags { 393ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel /// Check for equivalence ignoring load/store alignment. 394ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel CompareIgnoringAlignment = 1<<0, 395ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel /// Check for equivalence treating a type and a vector of that type 396ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel /// as equivalent. 397ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel CompareUsingScalarTypes = 1<<1 398ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel }; 399407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 400f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// This function determines if the specified instruction executes the same 401f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// operation as the current one. This means that the opcodes, type, operand 402f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// types and any other factors affecting the operation must be the same. This 403f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// is similar to isIdenticalTo except the operands themselves don't have to 404f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// be identical. 405f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// @returns true if the specified instruction is the same operation as 406f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// the current one. 407f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// @brief Determine if one instruction is the same operation as another. 408ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel bool isSameOperationAs(const Instruction *I, unsigned flags = 0) const; 409407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 410f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// isUsedOutsideOfBlock - Return true if there are any uses of this 411f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// instruction in blocks other than the specified block. Note that PHI nodes 412f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// are considered to evaluate their operands in the corresponding predecessor 413f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// block. 414f309880ad86114cda05037538c46123f6cda1a7eChris Lattner bool isUsedOutsideOfBlock(const BasicBlock *BB) const; 415407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 416407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 41726199059268a05739c84ebf465fcdbf7ded861dfChris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 418b00c582b6d40e6b9ff2d1ed4f5eaf7930e792aceChris Lattner static inline bool classof(const Value *V) { 419a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() >= Value::InstructionVal; 4207295eb4ea3e3a81e697600cbca681674e4b35a20Chris Lattner } 4219769ab22265b313171d201b5928688524a01bd87Misha Brukman 422009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner //---------------------------------------------------------------------- 423f309880ad86114cda05037538c46123f6cda1a7eChris Lattner // Exported enumerations. 424009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner // 425009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner enum TermOps { // These terminate basic blocks 4260b16ae209a1d0876a7ea6800bb567d925443cba3Chris Lattner#define FIRST_TERM_INST(N) TermOpsBegin = N, 427f96315e985880178562ba43b51efbc0efc8f6c8aChris Lattner#define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N, 42882870e0b733fa72c759271c1c62cb5f07be2c4dbChris Lattner#define LAST_TERM_INST(N) TermOpsEnd = N+1 4290b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instruction.def" 430009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner }; 431009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 432009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner enum BinaryOps { 4330b16ae209a1d0876a7ea6800bb567d925443cba3Chris Lattner#define FIRST_BINARY_INST(N) BinaryOpsBegin = N, 434f96315e985880178562ba43b51efbc0efc8f6c8aChris Lattner#define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N, 43582870e0b733fa72c759271c1c62cb5f07be2c4dbChris Lattner#define LAST_BINARY_INST(N) BinaryOpsEnd = N+1 4360b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instruction.def" 437009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner }; 438009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 439009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner enum MemoryOps { 4400b16ae209a1d0876a7ea6800bb567d925443cba3Chris Lattner#define FIRST_MEMORY_INST(N) MemoryOpsBegin = N, 441f96315e985880178562ba43b51efbc0efc8f6c8aChris Lattner#define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N, 44282870e0b733fa72c759271c1c62cb5f07be2c4dbChris Lattner#define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1 4430b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instruction.def" 444009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner }; 445009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 4463da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer enum CastOps { 4473da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer#define FIRST_CAST_INST(N) CastOpsBegin = N, 4483da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer#define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N, 4493da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer#define LAST_CAST_INST(N) CastOpsEnd = N+1 4500b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instruction.def" 4513da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer }; 4523da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer 453009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner enum OtherOps { 4540b16ae209a1d0876a7ea6800bb567d925443cba3Chris Lattner#define FIRST_OTHER_INST(N) OtherOpsBegin = N, 455f96315e985880178562ba43b51efbc0efc8f6c8aChris Lattner#define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N, 45682870e0b733fa72c759271c1c62cb5f07be2c4dbChris Lattner#define LAST_OTHER_INST(N) OtherOpsEnd = N+1 4570b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instruction.def" 458009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner }; 459b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattnerprivate: 460b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner // Shadow Value::setValueSubclassData with a private forwarding method so that 461b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner // subclasses cannot accidentally use it. 462b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner void setValueSubclassData(unsigned short D) { 463b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner Value::setValueSubclassData(D); 464b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner } 465b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner unsigned short getSubclassDataFromValue() const { 466b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner return Value::getSubclassDataFromValue(); 467b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner } 468407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 469ec39f095f5abaf1ec90d7c6c46454032cda36e1cChris Lattner void setHasMetadataHashEntry(bool V) { 470b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner setValueSubclassData((getSubclassDataFromValue() & ~HasMetadataBit) | 471b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner (V ? HasMetadataBit : 0)); 472b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner } 473407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 474b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner friend class SymbolTableListTraits<Instruction, BasicBlock>; 475b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner void setParent(BasicBlock *P); 476b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattnerprotected: 477b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner // Instruction subclasses can stick up to 15 bits of stuff into the 478b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner // SubclassData field of instruction with these members. 479407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 480b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner // Verify that only the low 15 bits are used. 481b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner void setInstructionSubclassData(unsigned short D) { 482b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner assert((D & HasMetadataBit) == 0 && "Out of range value put into field"); 483b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner setValueSubclassData((getSubclassDataFromValue() & HasMetadataBit) | D); 484b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner } 485407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 486b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner unsigned getSubclassDataFromInstruction() const { 487b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner return getSubclassDataFromValue() & ~HasMetadataBit; 488b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner } 489407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 490db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps, 491dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Instruction *InsertBefore = nullptr); 492db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps, 493b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner BasicBlock *InsertAtEnd); 494b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner virtual Instruction *clone_impl() const = 0; 495407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 496009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner}; 497009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 498e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner// Instruction* is only 4-byte aligned. 499e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattnertemplate<> 500e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattnerclass PointerLikeTypeTraits<Instruction*> { 501e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner typedef Instruction* PT; 502e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattnerpublic: 503e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner static inline void *getAsVoidPointer(PT P) { return P; } 504e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner static inline PT getFromVoidPointer(void *P) { 505e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner return static_cast<PT>(P); 506e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner } 507e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner enum { NumLowBitsAvailable = 2 }; 508e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner}; 509407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 510d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace 511d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 512009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner#endif 513