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 18fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman#include "llvm/ADT/ilist_node.h" 190b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/User.h" 2061336ae001e07c6d68454b1494e45954d373fb51Chris Lattner#include "llvm/Support/DebugLoc.h" 217a73b80b9052136c8cd2234eb3433a07df7cf38eJohn Criswell 22d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm { 23d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 241638b839090a35adcd5a4b4cc0a649352276e703Michael Ilsemanclass FastMathFlags; 2512ddd409535b52a7fa5157ded9a4cedd161fedb6Benjamin Kramerclass LLVMContext; 263990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattnerclass MDNode; 27333c40096561218bc3597cf153c0a3895274414cOwen Anderson 2817fcdd5e1b78b829068ca657c97357a39d6e768bChris Lattnertemplate<typename ValueSubClass, typename ItemParentClass> 2917fcdd5e1b78b829068ca657c97357a39d6e768bChris Lattner class SymbolTableListTraits; 30009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 31fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass Instruction : public User, public ilist_node<Instruction> { 32f630e49efc7bf3f1716b6daab3c2cc11a908754aCraig Topper void operator=(const Instruction &) LLVM_DELETED_FUNCTION; 33f630e49efc7bf3f1716b6daab3c2cc11a908754aCraig Topper Instruction(const Instruction &) LLVM_DELETED_FUNCTION; 34c5f24a2c2a16681f7816ac053c8f46a2692a3b7aJeff Cohen 35009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner BasicBlock *Parent; 3684e679beea11ac55ed7871eec4deaccdf393de3eChris Lattner DebugLoc DbgLoc; // 'dbg' Metadata cache. 37407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 38b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner enum { 39b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner /// HasMetadataBit - This is a bit stored in the SubClassData field which 40b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner /// indicates whether this instruction has metadata attached to it or not. 41b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner HasMetadataBit = 1 << 15 42b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner }; 43009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic: 44afba8fe662d65b25b4baf46bb26cc18e1f9cc0a5Gordon Henriksen // Out of line virtual method, so the vtable, etc has a home. 45afba8fe662d65b25b4baf46bb26cc18e1f9cc0a5Gordon Henriksen ~Instruction(); 46407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 47cb4f10b4d5e9ba2e37e70424b290dd1187ca6ea7Chris Lattner /// use_back - Specialize the methods defined in Value, as we know that an 48cb4f10b4d5e9ba2e37e70424b290dd1187ca6ea7Chris Lattner /// instruction can only be used by other instructions. 49cb4f10b4d5e9ba2e37e70424b290dd1187ca6ea7Chris Lattner Instruction *use_back() { return cast<Instruction>(*use_begin());} 50cb4f10b4d5e9ba2e37e70424b290dd1187ca6ea7Chris Lattner const Instruction *use_back() const { return cast<Instruction>(*use_begin());} 51407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 52009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner inline const BasicBlock *getParent() const { return Parent; } 53009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner inline BasicBlock *getParent() { return Parent; } 5418961504fc2b299578dba817900a0696cf3ccc4dChris Lattner 55b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner /// removeFromParent - This method unlinks 'this' from the containing basic 56b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner /// block, but does not delete it. 57f0a93ed9c59d706494496c6fe4e8354864d24aa7Chris Lattner /// 58b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner void removeFromParent(); 59b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner 60b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner /// eraseFromParent - This method unlinks 'this' from the containing basic 61b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner /// block and deletes it. 62b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner /// 63b92f50fe6091a7a12f54f9884529b1127b1a14e5Chris Lattner void eraseFromParent(); 64cfad5df977f257299063309fa34f3c24831093c4Chris Lattner 6526bb50ab48c561adfd32d129e0eff0cbf0a04625Owen Anderson /// insertBefore - Insert an unlinked instructions into a basic block 6626bb50ab48c561adfd32d129e0eff0cbf0a04625Owen Anderson /// immediately before the specified instruction. 6726bb50ab48c561adfd32d129e0eff0cbf0a04625Owen Anderson void insertBefore(Instruction *InsertPos); 6826bb50ab48c561adfd32d129e0eff0cbf0a04625Owen Anderson 693ff704fa2b67d6c857142218c5aca3058b6239fcChris Lattner /// insertAfter - Insert an unlinked instructions into a basic block 703ff704fa2b67d6c857142218c5aca3058b6239fcChris Lattner /// immediately after the specified instruction. 713ff704fa2b67d6c857142218c5aca3058b6239fcChris Lattner void insertAfter(Instruction *InsertPos); 723ff704fa2b67d6c857142218c5aca3058b6239fcChris Lattner 73287921d1889e101cb7f5cfa031a34ebe53a9a4a0Chris Lattner /// moveBefore - Unlink this instruction from its current basic block and 74287921d1889e101cb7f5cfa031a34ebe53a9a4a0Chris Lattner /// insert it into the basic block that MovePos lives in, right before 75287921d1889e101cb7f5cfa031a34ebe53a9a4a0Chris Lattner /// MovePos. 76287921d1889e101cb7f5cfa031a34ebe53a9a4a0Chris Lattner void moveBefore(Instruction *MovePos); 77287921d1889e101cb7f5cfa031a34ebe53a9a4a0Chris Lattner 783990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner //===--------------------------------------------------------------------===// 793990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner // Subclass classification. 803990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner //===--------------------------------------------------------------------===// 81407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 823990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// getOpcode() returns a member of one of the enums like Instruction::Add. 83a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman unsigned getOpcode() const { return getValueID() - InstructionVal; } 84407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 85555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner const char *getOpcodeName() const { return getOpcodeName(getOpcode()); } 86555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner bool isTerminator() const { return isTerminator(getOpcode()); } 87555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner bool isBinaryOp() const { return isBinaryOp(getOpcode()); } 88555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner bool isShift() { return isShift(getOpcode()); } 89555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner bool isCast() const { return isCast(getOpcode()); } 90407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 915814008f4b77774c8563578e1562c9c24a6750c2Vikram S. Adve static const char* getOpcodeName(unsigned OpCode); 92009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 93dac69c83c22a00d3f8de3bb4d62b9dbeb0a20cafReid Spencer static inline bool isTerminator(unsigned OpCode) { 94dac69c83c22a00d3f8de3bb4d62b9dbeb0a20cafReid Spencer return OpCode >= TermOpsBegin && OpCode < TermOpsEnd; 95dac69c83c22a00d3f8de3bb4d62b9dbeb0a20cafReid Spencer } 96dac69c83c22a00d3f8de3bb4d62b9dbeb0a20cafReid Spencer 97555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner static inline bool isBinaryOp(unsigned Opcode) { 98555c729a2f604027840b96d8e05f7d07d1f51053Chris Lattner return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd; 99009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner } 100009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 101832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer /// @brief Determine if the Opcode is one of the shift instructions. 102832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer static inline bool isShift(unsigned Opcode) { 103832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer return Opcode >= Shl && Opcode <= AShr; 104832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer } 105832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer 106832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer /// isLogicalShift - Return true if this is a logical shift left or a logical 107832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer /// shift right. 108cedbacffd67939d8e8f42e5506d458ddc187e575Dan Gohman inline bool isLogicalShift() const { 109832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer return getOpcode() == Shl || getOpcode() == LShr; 110832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer } 111832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer 112031b7481c818b7ad6f43ba942ed33663aef7f1b8Misha Brukman /// isArithmeticShift - Return true if this is an arithmetic shift right. 113cedbacffd67939d8e8f42e5506d458ddc187e575Dan Gohman inline bool isArithmeticShift() const { 114832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer return getOpcode() == AShr; 115832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer } 116832254e1c2387c0cbeb0a820b8315fbe85cb003aReid Spencer 1173da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer /// @brief Determine if the OpCode is one of the CastInst instructions. 1183da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer static inline bool isCast(unsigned OpCode) { 1193da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer return OpCode >= CastOpsBegin && OpCode < CastOpsEnd; 1203da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer } 1213da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer 1223990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner //===--------------------------------------------------------------------===// 1233990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner // Metadata manipulation. 1243990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner //===--------------------------------------------------------------------===// 125407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 1263990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// hasMetadata() - Return true if this instruction has any metadata attached 1273990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// to it. 1283990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner bool hasMetadata() const { 12961336ae001e07c6d68454b1494e45954d373fb51Chris Lattner return !DbgLoc.isUnknown() || hasMetadataHashEntry(); 13061336ae001e07c6d68454b1494e45954d373fb51Chris Lattner } 131407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 13261336ae001e07c6d68454b1494e45954d373fb51Chris Lattner /// hasMetadataOtherThanDebugLoc - Return true if this instruction has 13361336ae001e07c6d68454b1494e45954d373fb51Chris Lattner /// metadata attached to it other than a debug location. 13461336ae001e07c6d68454b1494e45954d373fb51Chris Lattner bool hasMetadataOtherThanDebugLoc() const { 13561336ae001e07c6d68454b1494e45954d373fb51Chris Lattner return hasMetadataHashEntry(); 1363990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner } 137407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 1383990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// getMetadata - Get the metadata of given kind attached to this Instruction. 1393990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// If the metadata is not found then return null. 1403990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner MDNode *getMetadata(unsigned KindID) const { 1413990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner if (!hasMetadata()) return 0; 1423990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner return getMetadataImpl(KindID); 1433990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner } 144407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 1453990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// getMetadata - Get the metadata of given kind attached to this Instruction. 1463990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// If the metadata is not found then return null. 14785dadecbd664f60f0c7e4fbb44f083d43d01cfb7Benjamin Kramer MDNode *getMetadata(StringRef Kind) const { 1483990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner if (!hasMetadata()) return 0; 1493990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner return getMetadataImpl(Kind); 1503990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner } 151407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 1523990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// getAllMetadata - Get all metadata attached to this Instruction. The first 1533990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// element of each pair returned is the KindID, the second element is the 1543990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// metadata value. This list is returned sorted by the KindID. 1553990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner void getAllMetadata(SmallVectorImpl<std::pair<unsigned, MDNode*> > &MDs)const{ 1563990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner if (hasMetadata()) 1573990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner getAllMetadataImpl(MDs); 1583990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner } 159407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 16061336ae001e07c6d68454b1494e45954d373fb51Chris Lattner /// getAllMetadataOtherThanDebugLoc - This does the same thing as 16161336ae001e07c6d68454b1494e45954d373fb51Chris Lattner /// getAllMetadata, except that it filters out the debug location. 16261336ae001e07c6d68454b1494e45954d373fb51Chris Lattner void getAllMetadataOtherThanDebugLoc(SmallVectorImpl<std::pair<unsigned, 16361336ae001e07c6d68454b1494e45954d373fb51Chris Lattner MDNode*> > &MDs) const { 16461336ae001e07c6d68454b1494e45954d373fb51Chris Lattner if (hasMetadataOtherThanDebugLoc()) 16561336ae001e07c6d68454b1494e45954d373fb51Chris Lattner getAllMetadataOtherThanDebugLocImpl(MDs); 16661336ae001e07c6d68454b1494e45954d373fb51Chris Lattner } 167407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 168f451cb870efcf9e0302d25ed05f4cac6bb494e42Dan Gohman /// setMetadata - Set the metadata of the specified kind to the specified 1693990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// node. This updates/replaces metadata if already present, or removes it if 1703990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner /// Node is null. 1713990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner void setMetadata(unsigned KindID, MDNode *Node); 17285dadecbd664f60f0c7e4fbb44f083d43d01cfb7Benjamin Kramer void setMetadata(StringRef Kind, MDNode *Node); 1733990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner 17461336ae001e07c6d68454b1494e45954d373fb51Chris Lattner /// setDebugLoc - Set the debug location information for this instruction. 17584e679beea11ac55ed7871eec4deaccdf393de3eChris Lattner void setDebugLoc(const DebugLoc &Loc) { DbgLoc = Loc; } 176407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 17761336ae001e07c6d68454b1494e45954d373fb51Chris Lattner /// getDebugLoc - Return the debug location for this node as a DebugLoc. 17884e679beea11ac55ed7871eec4deaccdf393de3eChris Lattner const DebugLoc &getDebugLoc() const { return DbgLoc; } 179407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 180125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Set or clear the unsafe-algebra flag on this instruction, which must be an 181125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// operator which supports this flag. See LangRef.html for the meaning of 182125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// this flag. 183125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman void setHasUnsafeAlgebra(bool B); 184125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 185125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Set or clear the no-nans flag on this instruction, which must be an 186125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// operator which supports this flag. See LangRef.html for the meaning of 187125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// this flag. 188125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman void setHasNoNaNs(bool B); 189125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 190125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Set or clear the no-infs flag on this instruction, which must be an 191125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// operator which supports this flag. See LangRef.html for the meaning of 192125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// this flag. 193125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman void setHasNoInfs(bool B); 194125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 195125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Set or clear the no-signed-zeros flag on this instruction, which must be 196125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// an operator which supports this flag. See LangRef.html for the meaning of 197125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// this flag. 198125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman void setHasNoSignedZeros(bool B); 199125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 200125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Set or clear the allow-reciprocal flag on this instruction, which must be 201125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// an operator which supports this flag. See LangRef.html for the meaning of 202125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// this flag. 203125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman void setHasAllowReciprocal(bool B); 204125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 205125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Convenience function for setting all the fast-math flags on this 206125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// instruction, which must be an operator which supports these flags. See 207125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// LangRef.html for the meaning of these flats. 208125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman void setFastMathFlags(FastMathFlags FMF); 209125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 210125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Determine whether the unsafe-algebra flag is set. 211125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman bool hasUnsafeAlgebra() const; 212125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 213125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Determine whether the no-NaNs flag is set. 214125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman bool hasNoNaNs() const; 215125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 216125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Determine whether the no-infs flag is set. 217125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman bool hasNoInfs() const; 218125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 219125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Determine whether the no-signed-zeros flag is set. 220125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman bool hasNoSignedZeros() const; 221125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 222125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Determine whether the allow-reciprocal flag is set. 223125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman bool hasAllowReciprocal() const; 224125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 225125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// Convenience function for getting all the fast-math flags, which must be an 226125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// operator which supports these flags. See LangRef.html for the meaning of 227125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman /// these flats. 228125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman FastMathFlags getFastMathFlags() const; 229125fc7fefd4a198dd210cb43f5d8f1ba2c1e2dcfMichael Ilseman 2304b896dd613b1d85ee1b261ee470cb72fab24c282Michael Ilseman /// Copy I's fast-math flags 2314b896dd613b1d85ee1b261ee470cb72fab24c282Michael Ilseman void copyFastMathFlags(const Instruction *I); 2324b896dd613b1d85ee1b261ee470cb72fab24c282Michael Ilseman 2333990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattnerprivate: 234ec39f095f5abaf1ec90d7c6c46454032cda36e1cChris Lattner /// hasMetadataHashEntry - Return true if we have an entry in the on-the-side 235ec39f095f5abaf1ec90d7c6c46454032cda36e1cChris Lattner /// metadata hash. 236ec39f095f5abaf1ec90d7c6c46454032cda36e1cChris Lattner bool hasMetadataHashEntry() const { 237ec39f095f5abaf1ec90d7c6c46454032cda36e1cChris Lattner return (getSubclassDataFromValue() & HasMetadataBit) != 0; 238ec39f095f5abaf1ec90d7c6c46454032cda36e1cChris Lattner } 239407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 2403990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner // These are all implemented in Metadata.cpp. 2413990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner MDNode *getMetadataImpl(unsigned KindID) const; 24285dadecbd664f60f0c7e4fbb44f083d43d01cfb7Benjamin Kramer MDNode *getMetadataImpl(StringRef Kind) const; 2433990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner void getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned,MDNode*> > &)const; 24461336ae001e07c6d68454b1494e45954d373fb51Chris Lattner void getAllMetadataOtherThanDebugLocImpl(SmallVectorImpl<std::pair<unsigned, 24561336ae001e07c6d68454b1494e45954d373fb51Chris Lattner MDNode*> > &) const; 2464f1be4abba762f8a7b77d7622abaf1ed1a87b48bDan Gohman void clearMetadataHashEntries(); 2473990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattnerpublic: 2483990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner //===--------------------------------------------------------------------===// 2493990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner // Predicates and helper methods. 2503990b121cf4a0b280ed3e54cf13870cbf4259e78Chris Lattner //===--------------------------------------------------------------------===// 251407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 252407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 253f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// isAssociative - Return true if the instruction is associative: 254f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// 255686e65fb65f97176e000c4d4cae82fc7b404ef9dMisha Brukman /// Associative operators satisfy: x op (y op z) === (x op y) op z 256f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// 2570d7ce5ffa4aa853b75e1015c62e27bd9f23ef73bDuncan Sands /// In LLVM, the Add, Mul, And, Or, and Xor operators are associative. 258f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// 2599b7f6f2de89a321f7eae5e942c8668cb50acfd1dShuxin Yang bool isAssociative() const; 2600d7ce5ffa4aa853b75e1015c62e27bd9f23ef73bDuncan Sands static bool isAssociative(unsigned op); 261f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner 262f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// isCommutative - Return true if the instruction is commutative: 263f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// 264686e65fb65f97176e000c4d4cae82fc7b404ef9dMisha Brukman /// Commutative operators satisfy: (x op y) === (y op x) 265f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// 266f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// In LLVM, these are the associative operators, plus SetEQ and SetNE, when 267f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// applied to any type. 268f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner /// 269f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner bool isCommutative() const { return isCommutative(getOpcode()); } 270f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner static bool isCommutative(unsigned op); 271f2da7241f590aaae128ecce7732c6094084df2b6Chris Lattner 272c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// isIdempotent - Return true if the instruction is idempotent: 273c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// 274c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// Idempotent operators satisfy: x op x === x 275c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// 276c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// In LLVM, the And and Or operators are idempotent. 277c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// 278c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands bool isIdempotent() const { return isIdempotent(getOpcode()); } 279c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands static bool isIdempotent(unsigned op); 280c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands 281c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// isNilpotent - Return true if the instruction is nilpotent: 282c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// 283c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// Nilpotent operators satisfy: x op x === Id, 284c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// 285c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// where Id is the identity for the operator, i.e. a constant such that 286c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// x op Id === x and Id op x === x for all x. 287c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// 288c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// In LLVM, the Xor operator is nilpotent. 289c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// 290c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands bool isNilpotent() const { return isNilpotent(getOpcode()); } 291c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands static bool isNilpotent(unsigned op); 292c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands 2937af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands /// mayWriteToMemory - Return true if this instruction may modify memory. 2947af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands /// 2957af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands bool mayWriteToMemory() const; 2967af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands 2977af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands /// mayReadFromMemory - Return true if this instruction may read memory. 2987af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands /// 2997af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands bool mayReadFromMemory() const; 3007af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands 3016f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman /// mayReadOrWriteMemory - Return true if this instruction may read or 3026f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman /// write memory. 3036f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman /// 3046f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman bool mayReadOrWriteMemory() const { 3056f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman return mayReadFromMemory() || mayWriteToMemory(); 3066f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman } 3076f3ba37ebb06de206c74d73c7c2b422cca28a16dEli Friedman 3087af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands /// mayThrow - Return true if this instruction may throw an exception. 3097af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands /// 3107af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands bool mayThrow() const; 3117af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands 31203544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem /// mayReturn - Return true if this is a function that may return. 31303544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem /// this is true for all normal instructions. The only exception 31403544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem /// is functions that are marked with the 'noreturn' attribute. 31503544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem /// 31603544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem bool mayReturn() const; 31703544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem 3187af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands /// mayHaveSideEffects - Return true if the instruction may have side effects. 3197af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands /// 3208b7d706c80afa7ad40acaab08f7406093a2851ffEli Friedman /// Note that this does not consider malloc and alloca to have side 3218b7d706c80afa7ad40acaab08f7406093a2851ffEli Friedman /// effects because the newly allocated memory is completely invisible to 3228b7d706c80afa7ad40acaab08f7406093a2851ffEli Friedman /// instructions which don't used the returned value. For cases where this 3238b7d706c80afa7ad40acaab08f7406093a2851ffEli Friedman /// matters, isSafeToSpeculativelyExecute may be more appropriate. 3247af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands bool mayHaveSideEffects() const { 32503544ec2a43fab162d25cf44627d1d08430bcccdNadav Rotem return mayWriteToMemory() || mayThrow() || !mayReturn(); 3267af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands } 3277af1c78b98d2df7d0ab9154461ca3d835706716eDuncan Sands 328f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// clone() - Create a copy of 'this' instruction that is identical in all 329f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// ways except the following: 330f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// * The instruction has no parent 331f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// * The instruction has no name 332f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// 333f309880ad86114cda05037538c46123f6cda1a7eChris Lattner Instruction *clone() const; 334407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 335f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// isIdenticalTo - Return true if the specified instruction is exactly 336f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// identical to the current one. This means that all operands match and any 337f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// extra information (e.g. load is volatile) agree. 338f309880ad86114cda05037538c46123f6cda1a7eChris Lattner bool isIdenticalTo(const Instruction *I) const; 339407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 340f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// isIdenticalToWhenDefined - This is like isIdenticalTo, except that it 341f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// ignores the SubclassOptionalData flags, which specify conditions 342f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// under which the instruction's result is undefined. 343f309880ad86114cda05037538c46123f6cda1a7eChris Lattner bool isIdenticalToWhenDefined(const Instruction *I) const; 344ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel 345ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel /// When checking for operation equivalence (using isSameOperationAs) it is 346ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel /// sometimes useful to ignore certain attributes. 347ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel enum OperationEquivalenceFlags { 348ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel /// Check for equivalence ignoring load/store alignment. 349ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel CompareIgnoringAlignment = 1<<0, 350ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel /// Check for equivalence treating a type and a vector of that type 351ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel /// as equivalent. 352ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel CompareUsingScalarTypes = 1<<1 353ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel }; 354407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 355f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// This function determines if the specified instruction executes the same 356f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// operation as the current one. This means that the opcodes, type, operand 357f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// types and any other factors affecting the operation must be the same. This 358f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// is similar to isIdenticalTo except the operands themselves don't have to 359f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// be identical. 360f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// @returns true if the specified instruction is the same operation as 361f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// the current one. 362f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// @brief Determine if one instruction is the same operation as another. 363ec4e85e3364f50802f2007e4b1e23661d4610366Hal Finkel bool isSameOperationAs(const Instruction *I, unsigned flags = 0) const; 364407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 365f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// isUsedOutsideOfBlock - Return true if there are any uses of this 366f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// instruction in blocks other than the specified block. Note that PHI nodes 367f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// are considered to evaluate their operands in the corresponding predecessor 368f309880ad86114cda05037538c46123f6cda1a7eChris Lattner /// block. 369f309880ad86114cda05037538c46123f6cda1a7eChris Lattner bool isUsedOutsideOfBlock(const BasicBlock *BB) const; 370407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 371407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 37226199059268a05739c84ebf465fcdbf7ded861dfChris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 373b00c582b6d40e6b9ff2d1ed4f5eaf7930e792aceChris Lattner static inline bool classof(const Value *V) { 374a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() >= Value::InstructionVal; 3757295eb4ea3e3a81e697600cbca681674e4b35a20Chris Lattner } 3769769ab22265b313171d201b5928688524a01bd87Misha Brukman 377009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner //---------------------------------------------------------------------- 378f309880ad86114cda05037538c46123f6cda1a7eChris Lattner // Exported enumerations. 379009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner // 380009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner enum TermOps { // These terminate basic blocks 3810b16ae209a1d0876a7ea6800bb567d925443cba3Chris Lattner#define FIRST_TERM_INST(N) TermOpsBegin = N, 382f96315e985880178562ba43b51efbc0efc8f6c8aChris Lattner#define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N, 38382870e0b733fa72c759271c1c62cb5f07be2c4dbChris Lattner#define LAST_TERM_INST(N) TermOpsEnd = N+1 3840b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instruction.def" 385009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner }; 386009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 387009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner enum BinaryOps { 3880b16ae209a1d0876a7ea6800bb567d925443cba3Chris Lattner#define FIRST_BINARY_INST(N) BinaryOpsBegin = N, 389f96315e985880178562ba43b51efbc0efc8f6c8aChris Lattner#define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N, 39082870e0b733fa72c759271c1c62cb5f07be2c4dbChris Lattner#define LAST_BINARY_INST(N) BinaryOpsEnd = N+1 3910b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instruction.def" 392009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner }; 393009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 394009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner enum MemoryOps { 3950b16ae209a1d0876a7ea6800bb567d925443cba3Chris Lattner#define FIRST_MEMORY_INST(N) MemoryOpsBegin = N, 396f96315e985880178562ba43b51efbc0efc8f6c8aChris Lattner#define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N, 39782870e0b733fa72c759271c1c62cb5f07be2c4dbChris Lattner#define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1 3980b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instruction.def" 399009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner }; 400009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 4013da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer enum CastOps { 4023da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer#define FIRST_CAST_INST(N) CastOpsBegin = N, 4033da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer#define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N, 4043da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer#define LAST_CAST_INST(N) CastOpsEnd = N+1 4050b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instruction.def" 4063da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer }; 4073da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer 408009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner enum OtherOps { 4090b16ae209a1d0876a7ea6800bb567d925443cba3Chris Lattner#define FIRST_OTHER_INST(N) OtherOpsBegin = N, 410f96315e985880178562ba43b51efbc0efc8f6c8aChris Lattner#define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N, 41182870e0b733fa72c759271c1c62cb5f07be2c4dbChris Lattner#define LAST_OTHER_INST(N) OtherOpsEnd = N+1 4120b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instruction.def" 413009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner }; 414b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattnerprivate: 415b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner // Shadow Value::setValueSubclassData with a private forwarding method so that 416b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner // subclasses cannot accidentally use it. 417b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner void setValueSubclassData(unsigned short D) { 418b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner Value::setValueSubclassData(D); 419b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner } 420b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner unsigned short getSubclassDataFromValue() const { 421b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner return Value::getSubclassDataFromValue(); 422b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner } 423407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 424ec39f095f5abaf1ec90d7c6c46454032cda36e1cChris Lattner void setHasMetadataHashEntry(bool V) { 425b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner setValueSubclassData((getSubclassDataFromValue() & ~HasMetadataBit) | 426b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner (V ? HasMetadataBit : 0)); 427b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner } 428407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 429b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner friend class SymbolTableListTraits<Instruction, BasicBlock>; 430b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner void setParent(BasicBlock *P); 431b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattnerprotected: 432b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner // Instruction subclasses can stick up to 15 bits of stuff into the 433b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner // SubclassData field of instruction with these members. 434407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 435b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner // Verify that only the low 15 bits are used. 436b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner void setInstructionSubclassData(unsigned short D) { 437b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner assert((D & HasMetadataBit) == 0 && "Out of range value put into field"); 438b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner setValueSubclassData((getSubclassDataFromValue() & HasMetadataBit) | D); 439b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner } 440407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 441b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner unsigned getSubclassDataFromInstruction() const { 442b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner return getSubclassDataFromValue() & ~HasMetadataBit; 443b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner } 444407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 445db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps, 446b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner Instruction *InsertBefore = 0); 447db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps, 448b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner BasicBlock *InsertAtEnd); 449b2406d9895314cbc61183c2fb712cd1a2ddfe7e0Chris Lattner virtual Instruction *clone_impl() const = 0; 450407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 451009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner}; 452009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 453e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner// Instruction* is only 4-byte aligned. 454e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattnertemplate<> 455e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattnerclass PointerLikeTypeTraits<Instruction*> { 456e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner typedef Instruction* PT; 457e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattnerpublic: 458e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner static inline void *getAsVoidPointer(PT P) { return P; } 459e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner static inline PT getFromVoidPointer(void *P) { 460e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner return static_cast<PT>(P); 461e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner } 462e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner enum { NumLowBitsAvailable = 2 }; 463e30173ac3396510bd0bb26a66fd615ff9083436dChris Lattner}; 464407a6169b729c72c3a7ddb01b8454ab0b4f6897cMichael Ilseman 465d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace 466d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 467009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner#endif 468