LLVM API Documentation

llvm::Instruction Class Reference

#include <Instruction.h>

Inheritance diagram for llvm::Instruction:
[legend]
Collaboration diagram for llvm::Instruction:
[legend]

List of all members.

Public Types

enum  TermOps { FIRST_TERM_INST }
enum  BinaryOps { FIRST_BINARY_INST }
enum  MemoryOps { FIRST_MEMORY_INST }
enum  CastOps { FIRST_CAST_INST }
enum  OtherOps { FIRST_OTHER_INST }

Public Member Functions

 ~Instruction ()
virtual Instruction * clone (LLVMContext &Context) const =0
bool isIdenticalTo (const Instruction *I) const
bool isIdenticalToWhenDefined (const Instruction *I) const
bool isSameOperationAs (const Instruction *I) const
 Determine if one instruction is the same operation as another.
bool isUsedOutsideOfBlock (const BasicBlock *BB) const
Instruction * use_back ()
const Instruction * use_back () const
const BasicBlock * getParent () const
BasicBlock * getParent ()
void removeFromParent ()
void eraseFromParent ()
void insertBefore (Instruction *InsertPos)
void insertAfter (Instruction *InsertPos)
void moveBefore (Instruction *MovePos)
unsigned getOpcode () const
const char * getOpcodeName () const
bool isTerminator () const
bool isBinaryOp () const
bool isShift ()
bool isCast () const
bool isLogicalShift () const
bool isArithmeticShift () const
 isArithmeticShift - Return true if this is an arithmetic shift right.
bool isAssociative () const
bool isCommutative () const
bool mayWriteToMemory () const
bool mayReadFromMemory () const
bool mayThrow () const
bool mayHaveSideEffects () const
bool isSafeToSpeculativelyExecute () const

Static Public Member Functions

static const char * getOpcodeName (unsigned OpCode)
static bool isTerminator (unsigned OpCode)
static bool isBinaryOp (unsigned Opcode)
static bool isShift (unsigned Opcode)
 Determine if the Opcode is one of the shift instructions.
static bool isCast (unsigned OpCode)
 Determine if the OpCode is one of the CastInst instructions.
static bool isAssociative (unsigned op, const Type *Ty)
static bool isCommutative (unsigned op)
static bool classof (const Instruction *)
 Methods for support type inquiry through isa, cast, and dyn_cast:.
static bool classof (const Value *V)

Protected Member Functions

 Instruction (const Type *Ty, unsigned iType, Use *Ops, unsigned NumOps, Instruction *InsertBefore=0)
 Instruction (const Type *Ty, unsigned iType, Use *Ops, unsigned NumOps, BasicBlock *InsertAtEnd)

Friends

class SymbolTableListTraits< Instruction, BasicBlock >


Detailed Description

Definition at line 28 of file Instruction.h.


Member Enumeration Documentation

Enumerator:
FIRST_TERM_INST 

Definition at line 227 of file Instruction.h.

Enumerator:
FIRST_BINARY_INST 

Definition at line 430 of file Instruction.h.

Enumerator:
FIRST_MEMORY_INST 

Definition at line 633 of file Instruction.h.

Enumerator:
FIRST_CAST_INST 

Definition at line 836 of file Instruction.h.

Enumerator:
FIRST_OTHER_INST 

Definition at line 1039 of file Instruction.h.


Constructor & Destructor Documentation

Instruction::Instruction ( const Type *  Ty,
unsigned  iType,
Use *  Ops,
unsigned  NumOps,
Instruction *  InsertBefore = 0 
) [protected]

Instruction::Instruction ( const Type *  Ty,
unsigned  iType,
Use *  Ops,
unsigned  NumOps,
BasicBlock *  InsertAtEnd 
) [protected]

Instruction::~Instruction (  ) 

Definition at line 50 of file Instruction.cpp.


Member Function Documentation

virtual Instruction* llvm::Instruction::clone ( LLVMContext &  Context  )  const [pure virtual]

bool Instruction::isIdenticalTo ( const Instruction *  I  )  const

isIdenticalTo - Return true if the specified instruction is exactly identical to the current one. This means that all operands match and any extra information (e.g. load is volatile) agree.

isIdenticalTo - Return true if the specified instruction is exactly identical to the current one. This means that all operands match and any extra information (e.g. load is volatile) agree.

Definition at line 170 of file Instruction.cpp.

References isIdenticalToWhenDefined(), and llvm::Value::SubclassOptionalData.

Referenced by HasSameValue().

bool Instruction::isIdenticalToWhenDefined ( const Instruction *  I  )  const

isIdenticalToWhenDefined - This is like isIdenticalTo, except that it ignores the SubclassOptionalData flags, which specify conditions under which the instruction's result is undefined.

isIdenticalToWhenDefined - This is like isIdenticalTo, except that it ignores the SubclassOptionalData flags, which specify conditions under which the instruction's result is undefined.

Definition at line 178 of file Instruction.cpp.

References llvm::Intrinsic::getAttributes(), llvm::User::getNumOperands(), getOpcode(), llvm::User::getOperand(), getPredicate(), llvm::AttrListPtr::getRawPointer(), llvm::Value::getType(), and LI.

Referenced by HoistThenElseCodeToIf(), and isIdenticalTo().

bool Instruction::isSameOperationAs ( const Instruction *  I  )  const

Determine if one instruction is the same operation as another.

This function determines if the specified instruction executes the same operation as the current one. This means that the opcodes, type, operand types and any other factors affecting the operation must be the same. This is similar to isIdenticalTo except the operands themselves don't have to be identical.

Returns:
true if the specified instruction is the same operation as the current one.

Definition at line 231 of file Instruction.cpp.

References llvm::Intrinsic::getAttributes(), llvm::User::getNumOperands(), getOpcode(), llvm::User::getOperand(), getPredicate(), llvm::AttrListPtr::getRawPointer(), llvm::Value::getType(), and LI.

bool Instruction::isUsedOutsideOfBlock ( const BasicBlock *  BB  )  const

isUsedOutsideOfBlock - Return true if there are any uses of this instruction in blocks other than the specified block. Note that PHI nodes are considered to evaluate their operands in the corresponding predecessor block.

isUsedOutsideOfBlock - Return true if there are any uses of I outside of the specified block. Note that PHI nodes are considered to evaluate their operands in the corresponding predecessor block.

Definition at line 284 of file Instruction.cpp.

References llvm::dyn_cast(), E, llvm::PHINode::getIncomingBlock(), llvm::Value::use_begin(), and llvm::Value::use_end().

Instruction* llvm::Instruction::use_back (  )  [inline]

use_back - Specialize the methods defined in Value, as we know that an instruction can only be used by other instructions.

Reimplemented from llvm::Value.

Definition at line 81 of file Instruction.h.

References llvm::Value::use_begin().

Referenced by ConvertShiftToMul(), DeadPHICycle(), llvm::DemoteRegToStack(), and ShouldBreakUpSubtract().

const Instruction* llvm::Instruction::use_back (  )  const [inline]

Reimplemented from llvm::Value.

Definition at line 82 of file Instruction.h.

References llvm::Value::use_begin().

const BasicBlock* llvm::Instruction::getParent (  )  const [inline]

Definition at line 86 of file Instruction.h.

Referenced by llvm::IVUsers::AddUsersIfInteresting(), BlockIsSimpleEnoughToThreadThrough(), llvm::AliasAnalysis::canInstructionRangeModify(), ChangeToCall(), ChangeToUnreachable(), llvm::CloneAndPruneFunctionInto(), llvm::CopyPrecedingStopPoint(), llvm::DemotePHIToStack(), llvm::DemoteRegToStack(), llvm::DominatorTree::dominates(), DominatesMergePoint(), llvm::Value::DoPHITranslation(), eraseFromParent(), EvaluateExpression(), llvm::SCEVExpander::expandCodeFor(), FindIVIncInsertPt(), llvm::SelectionDAGLowering::FindMergedConditions(), llvm::findStopPoint(), llvm::FoldBranchToCommonDest(), FoldCondBranchOnPHI(), FoldTwoEntryPHINode(), FoldValueComparisonIntoPredecessors(), llvm::CallSite::getCaller(), getCommonReturnValue(), getConstantEvolvingPHI(), llvm::MemoryDependenceAnalysis::getDependency(), llvm::InlineCostAnalyzer::getInlineCost(), llvm::MemoryDependenceAnalysis::getNonLocalCallDependency(), llvm::IVUsers::getReplacementExpr(), llvm::ScalarEvolution::getSCEVAtScope(), HandleInlinedInvoke(), HoistThenElseCodeToIf(), InBlock(), llvm::InlineFunction(), llvm::BasicInlinerImpl::inlineFunctions(), insertAfter(), insertBefore(), Instruction(), isDynamicConstant(), isInTailCallPosition(), llvm::Loop::isLoopInvariant(), isSafeAndProfitableToSinkLoad(), llvm::isSafeToLoadUnconditionally(), llvm::AllocaInst::isStaticAlloca(), llvm::Value::isUsedInBasicBlock(), isUsedOutsideOfDefiningBlock(), IVUseShouldUsePostIncValue(), LLVMGetNextInstruction(), LLVMGetPreviousInstruction(), LLVMPositionBuilderBefore(), LowerBSWAP(), LowerCTLZ(), LowerCTPOP(), llvm::IntrinsicLowering::LowerIntrinsicCall(), LowerToBSwap(), moveBefore(), OptimizeCmpExpression(), OptimizeNoopCopyExpression(), llvm::Value::print(), llvm::MSILWriter::printBranchInstruction(), llvm::MSILWriter::printInvokeInstruction(), llvm::MSILWriter::printSwitchInstruction(), llvm::RemapInstruction(), removeFromParent(), llvm::RemoveSuccessor(), ReplaceCallWith(), llvm::ReplaceInstWithInst(), SafeToMergeTerminators(), SimplifyCondBranchToCondBranch(), SimplifyCondBranchToTwoReturns(), SimplifyEqualityComparisonWithOnlyPredecessor(), llvm::SparseSolver::Solve(), SpeculativelyExecuteBB(), llvm::SplitCriticalEdge(), SplitEdgeNicely(), TryToSinkInstruction(), llvm::UnrollLoop(), UpdateCallGraphAfterInlining(), and llvm::Interpreter::visitCallSite().

BasicBlock* llvm::Instruction::getParent (  )  [inline]

Definition at line 87 of file Instruction.h.

void Instruction::removeFromParent (  ) 

removeFromParent - This method unlinks 'this' from the containing basic block, but does not delete it.

Definition at line 65 of file Instruction.cpp.

References llvm::BasicBlock::getInstList(), and getParent().

void Instruction::eraseFromParent (  ) 

void Instruction::insertBefore ( Instruction *  InsertPos  ) 

insertBefore - Insert an unlinked instructions into a basic block immediately before the specified instruction.

insertBefore - Insert an unlinked instructions into a basic block immediately before the specified instruction.

Definition at line 75 of file Instruction.cpp.

References llvm::BasicBlock::getInstList(), and getParent().

Referenced by llvm::CopyPrecedingStopPoint().

void Instruction::insertAfter ( Instruction *  InsertPos  ) 

insertAfter - Insert an unlinked instructions into a basic block immediately after the specified instruction.

insertAfter - Insert an unlinked instructions into a basic block immediately after the specified instruction.

Definition at line 81 of file Instruction.cpp.

References llvm::BasicBlock::getInstList(), and getParent().

void Instruction::moveBefore ( Instruction *  MovePos  ) 

moveBefore - Unlink this instruction from its current basic block and insert it into the basic block that MovePos lives in, right before MovePos.

moveBefore - Unlink this instruction from its current basic block and insert it into the basic block that MovePos lives in, right before MovePos.

Definition at line 88 of file Instruction.cpp.

References llvm::BasicBlock::getInstList(), and getParent().

Referenced by AssociativeOpt(), llvm::Loop::makeLoopInvariant(), and TryToSinkInstruction().

unsigned llvm::Instruction::getOpcode (  )  const [inline]

Subclass classification... getOpcode() returns a member of one of the enums that is coming soon (down below)...

Reimplemented in llvm::BinaryOperator, llvm::CastInst, llvm::CmpInst, and llvm::SelectInst.

Definition at line 116 of file Instruction.h.

References llvm::Value::getValueID(), and llvm::Value::InstructionVal.

Referenced by AssociativeOpt(), CheapToScalarize(), llvm::GEPOperator::classof(), llvm::SDivOperator::classof(), llvm::MulOperator::classof(), llvm::SubOperator::classof(), llvm::AddOperator::classof(), llvm::OverflowingBinaryOperator::classof(), llvm::BitCastInst::classof(), llvm::PtrToIntInst::classof(), llvm::IntToPtrInst::classof(), llvm::FPToSIInst::classof(), llvm::FPToUIInst::classof(), llvm::SIToFPInst::classof(), llvm::UIToFPInst::classof(), llvm::FPExtInst::classof(), llvm::FPTruncInst::classof(), llvm::SExtInst::classof(), llvm::ZExtInst::classof(), llvm::TruncInst::classof(), llvm::UnreachableInst::classof(), llvm::UnwindInst::classof(), llvm::InvokeInst::classof(), llvm::SwitchInst::classof(), llvm::BranchInst::classof(), llvm::ReturnInst::classof(), llvm::PHINode::classof(), llvm::InsertValueInst::classof(), llvm::ExtractValueInst::classof(), llvm::ShuffleVectorInst::classof(), llvm::InsertElementInst::classof(), llvm::ExtractElementInst::classof(), llvm::VAArgInst::classof(), llvm::SelectInst::classof(), llvm::CallInst::classof(), llvm::FCmpInst::classof(), llvm::ICmpInst::classof(), llvm::GetElementPtrInst::classof(), llvm::StoreInst::classof(), llvm::LoadInst::classof(), llvm::FreeInst::classof(), llvm::AllocaInst::classof(), llvm::MallocInst::classof(), llvm::AllocationInst::classof(), llvm::UnaryInstruction::classof(), llvm::ConstantFoldInstruction(), DominatesMergePoint(), EvaluateExpression(), llvm::SelectionDAGLowering::FindMergedConditions(), FoldOperationIntoSelectOperand(), GatherConstantSetEQs(), GatherConstantSetNEs(), GatherValueComparisons(), llvm::AliasAnalysis::getModRefInfo(), llvm::SelectInst::getOpcode(), getOpcodeName(), GetSelectFoldableConstant(), GetSelectFoldableOperands(), HoistThenElseCodeToIf(), llvm::InlineFunction(), isArithmeticShift(), isAssociative(), isBinaryOp(), isCast(), isCommutative(), isEquivalentOperation(), isIdenticalToWhenDefined(), isLogicalShift(), isSafeToSpeculativelyExecute(), isSameOperationAs(), isShift(), isTerminator(), isUnmovableInstruction(), mayReadFromMemory(), mayWriteToMemory(), MightBeFoldableInst(), llvm::PointerMayBeCaptured(), llvm::MSILWriter::printBasicBlock(), llvm::MSILWriter::printInstruction(), llvm::RemoveSuccessor(), llvm::FastISel::SelectInstruction(), SpeculativelyExecuteBB(), llvm::SelectionDAGLowering::visit(), llvm::Interpreter::visitAllocationInst(), and WriteInstruction().

const char* llvm::Instruction::getOpcodeName (  )  const [inline]

Definition at line 117 of file Instruction.h.

References getOpcode().

Referenced by llvm::ConstantExpr::getOpcodeName().

bool llvm::Instruction::isTerminator (  )  const [inline]

bool llvm::Instruction::isBinaryOp (  )  const [inline]

Definition at line 119 of file Instruction.h.

References getOpcode().

Referenced by llvm::ConstantFoldInstOperands().

bool llvm::Instruction::isShift (  )  [inline]

Definition at line 120 of file Instruction.h.

References getOpcode().

bool llvm::Instruction::isCast (  )  const [inline]

const char * Instruction::getOpcodeName ( unsigned  OpCode  )  [static]

static bool llvm::Instruction::isTerminator ( unsigned  OpCode  )  [inline, static]

Definition at line 127 of file Instruction.h.

static bool llvm::Instruction::isBinaryOp ( unsigned  Opcode  )  [inline, static]

Definition at line 131 of file Instruction.h.

static bool llvm::Instruction::isShift ( unsigned  Opcode  )  [inline, static]

Determine if the Opcode is one of the shift instructions.

Definition at line 136 of file Instruction.h.

bool llvm::Instruction::isLogicalShift (  )  const [inline]

isLogicalShift - Return true if this is a logical shift left or a logical shift right.

Definition at line 142 of file Instruction.h.

References getOpcode(), and llvm::LShr.

Referenced by CollectBSwapParts().

bool llvm::Instruction::isArithmeticShift (  )  const [inline]

isArithmeticShift - Return true if this is an arithmetic shift right.

Definition at line 147 of file Instruction.h.

References getOpcode().

static bool llvm::Instruction::isCast ( unsigned  OpCode  )  [inline, static]

Determine if the OpCode is one of the CastInst instructions.

Definition at line 152 of file Instruction.h.

bool llvm::Instruction::isAssociative (  )  const [inline]

isAssociative - Return true if the instruction is associative:

Associative operators satisfy: x op (y op z) === (x op y) op z

In LLVM, the Add, Mul, And, Or, and Xor operators are associative, when not applied to floating point types.

Definition at line 163 of file Instruction.h.

References getOpcode(), and llvm::Value::getType().

bool Instruction::isAssociative ( unsigned  Opcode,
const Type *  Ty 
) [static]

isAssociative - Return true if the instruction is associative:

Associative operators satisfy: x op (y op z) === (x op y) op z

In LLVM, the Add, Mul, And, Or, and Xor operators are associative.

Definition at line 351 of file Instruction.cpp.

References llvm::APIntOps::And(), llvm::APIntOps::Or(), and llvm::APIntOps::Xor().

bool llvm::Instruction::isCommutative (  )  const [inline]

isCommutative - Return true if the instruction is commutative:

Commutative operators satisfy: (x op y) === (y op x)

In LLVM, these are the associative operators, plus SetEQ and SetNE, when applied to any type.

Reimplemented in llvm::ICmpInst, and llvm::FCmpInst.

Definition at line 173 of file Instruction.h.

References getOpcode().

Referenced by llvm::BinaryOperator::swapOperands().

bool Instruction::isCommutative ( unsigned  op  )  [static]

isCommutative - Return true if the instruction is commutative:

Commutative operators satisfy: (x op y) === (y op x)

In LLVM, these are the associative operators, plus SetEQ and SetNE, when applied to any type.

Definition at line 363 of file Instruction.cpp.

References llvm::APIntOps::And(), llvm::APIntOps::Or(), and llvm::APIntOps::Xor().

bool Instruction::mayWriteToMemory (  )  const

mayWriteToMemory - Return true if this instruction may modify memory.

Definition at line 321 of file Instruction.cpp.

References Call, getOpcode(), Load, llvm::SPII::Store, and VAArg.

Referenced by llvm::FindAvailableLoadedValue(), IsMemRefInstr(), and mayHaveSideEffects().

bool Instruction::mayReadFromMemory (  )  const

mayReadFromMemory - Return true if this instruction may read memory.

Definition at line 303 of file Instruction.cpp.

References Call, getOpcode(), Load, llvm::SPII::Store, and VAArg.

Referenced by isInTailCallPosition(), IsMemRefInstr(), llvm::Loop::makeLoopInvariant(), and TryToSinkInstruction().

bool Instruction::mayThrow (  )  const

mayThrow - Return true if this instruction may throw an exception.

Definition at line 339 of file Instruction.cpp.

Referenced by mayHaveSideEffects().

bool llvm::Instruction::mayHaveSideEffects (  )  const [inline]

mayHaveSideEffects - Return true if the instruction may have side effects.

Note that this does not consider malloc and alloca to have side effects because the newly allocated memory is completely invisible to instructions which don't used the returned value. For cases where this matters, isSafeToSpeculativelyExecute may be more appropriate.

Definition at line 194 of file Instruction.h.

References mayThrow(), and mayWriteToMemory().

Referenced by llvm::isInstructionTriviallyDead(), isInTailCallPosition(), and TryToSinkInstruction().

bool Instruction::isSafeToSpeculativelyExecute (  )  const

isSafeToSpeculativelyExecute - Return true if the instruction does not have any effects besides calculating the result and does not have undefined behavior.

This method never returns true for an instruction that returns true for mayHaveSideEffects; however, this method also does some other checks in addition. It checks for undefined behavior, like dividing by zero or loading from an invalid pointer (but not for undefined results, like a shift with a shift amount larger than the width of the result). It checks for malloc and alloca because speculatively executing them might cause a memory leak. It also returns false for instructions related to control flow, specifically terminators and PHI nodes.

This method only looks at the instruction itself and its operands, so if this method returns true, it is safe to move the instruction as long as the correct dominance relationships for the operands and users hold. However, this method can return true for instructions that read memory; for such instructions, moving them may change the resulting value.

Definition at line 378 of file Instruction.cpp.

References llvm::CallingConv::C, llvm::Call, llvm::dyn_cast(), llvm::User::getNumOperands(), getOpcode(), llvm::User::getOperand(), GV, llvm::GlobalValue::hasExternalWeakLinkage(), llvm::ConstantInt::isAllOnesValue(), llvm::ConstantInt::isNullValue(), llvm::Load, llvm::Malloc, llvm::User::Op(), PHI, llvm::MipsISD::Ret, llvm::SPII::Store, and llvm::VAArg.

Referenced by DominatesMergePoint(), isInTailCallPosition(), and llvm::Loop::makeLoopInvariant().

static bool llvm::Instruction::classof ( const Instruction *   )  [inline, static]

static bool llvm::Instruction::classof ( const Value *  V  )  [inline, static]


Friends And Related Function Documentation

friend class SymbolTableListTraits< Instruction, BasicBlock > [friend]

Definition at line 34 of file Instruction.h.


The documentation for this class was generated from the following files: