1 //===-- llvm/Instruction.h - Instruction class definition -------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file contains the declaration of the Instruction class, which is the
10 // base class for all of the LLVM instructions.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_IR_INSTRUCTION_H
15 #define LLVM_IR_INSTRUCTION_H
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/None.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/ADT/ilist_node.h"
21 #include "llvm/IR/DebugLoc.h"
22 #include "llvm/IR/SymbolTableListTraits.h"
23 #include "llvm/IR/User.h"
24 #include "llvm/IR/Value.h"
25 #include "llvm/Support/Casting.h"
39 template <> struct ilist_alloc_traits
<Instruction
> {
40 static inline void deleteNode(Instruction
*V
);
43 class Instruction
: public User
,
44 public ilist_node_with_parent
<Instruction
, BasicBlock
> {
46 DebugLoc DbgLoc
; // 'dbg' Metadata cache.
49 /// This is a bit stored in the SubClassData field which indicates whether
50 /// this instruction has metadata attached to it or not.
51 HasMetadataBit
= 1 << 15
55 ~Instruction(); // Use deleteValue() to delete a generic Instruction.
58 Instruction(const Instruction
&) = delete;
59 Instruction
&operator=(const Instruction
&) = delete;
61 /// Specialize the methods defined in Value, as we know that an instruction
62 /// can only be used by other instructions.
63 Instruction
*user_back() { return cast
<Instruction
>(*user_begin());}
64 const Instruction
*user_back() const { return cast
<Instruction
>(*user_begin());}
66 inline const BasicBlock
*getParent() const { return Parent
; }
67 inline BasicBlock
*getParent() { return Parent
; }
69 /// Return the module owning the function this instruction belongs to
70 /// or nullptr it the function does not have a module.
72 /// Note: this is undefined behavior if the instruction does not have a
73 /// parent, or the parent basic block does not have a parent function.
74 const Module
*getModule() const;
76 return const_cast<Module
*>(
77 static_cast<const Instruction
*>(this)->getModule());
80 /// Return the function this instruction belongs to.
82 /// Note: it is undefined behavior to call this on an instruction not
83 /// currently inserted into a function.
84 const Function
*getFunction() const;
85 Function
*getFunction() {
86 return const_cast<Function
*>(
87 static_cast<const Instruction
*>(this)->getFunction());
90 /// This method unlinks 'this' from the containing basic block, but does not
92 void removeFromParent();
94 /// This method unlinks 'this' from the containing basic block and deletes it.
96 /// \returns an iterator pointing to the element after the erased one
97 SymbolTableList
<Instruction
>::iterator
eraseFromParent();
99 /// Insert an unlinked instruction into a basic block immediately before
100 /// the specified instruction.
101 void insertBefore(Instruction
*InsertPos
);
103 /// Insert an unlinked instruction into a basic block immediately after the
104 /// specified instruction.
105 void insertAfter(Instruction
*InsertPos
);
107 /// Unlink this instruction from its current basic block and insert it into
108 /// the basic block that MovePos lives in, right before MovePos.
109 void moveBefore(Instruction
*MovePos
);
111 /// Unlink this instruction and insert into BB before I.
113 /// \pre I is a valid iterator into BB.
114 void moveBefore(BasicBlock
&BB
, SymbolTableList
<Instruction
>::iterator I
);
116 /// Unlink this instruction from its current basic block and insert it into
117 /// the basic block that MovePos lives in, right after MovePos.
118 void moveAfter(Instruction
*MovePos
);
120 //===--------------------------------------------------------------------===//
121 // Subclass classification.
122 //===--------------------------------------------------------------------===//
124 /// Returns a member of one of the enums like Instruction::Add.
125 unsigned getOpcode() const { return getValueID() - InstructionVal
; }
127 const char *getOpcodeName() const { return getOpcodeName(getOpcode()); }
128 bool isTerminator() const { return isTerminator(getOpcode()); }
129 bool isUnaryOp() const { return isUnaryOp(getOpcode()); }
130 bool isBinaryOp() const { return isBinaryOp(getOpcode()); }
131 bool isIntDivRem() const { return isIntDivRem(getOpcode()); }
132 bool isShift() { return isShift(getOpcode()); }
133 bool isCast() const { return isCast(getOpcode()); }
134 bool isFuncletPad() const { return isFuncletPad(getOpcode()); }
135 bool isExceptionalTerminator() const {
136 return isExceptionalTerminator(getOpcode());
138 bool isIndirectTerminator() const {
139 return isIndirectTerminator(getOpcode());
142 static const char* getOpcodeName(unsigned OpCode
);
144 static inline bool isTerminator(unsigned OpCode
) {
145 return OpCode
>= TermOpsBegin
&& OpCode
< TermOpsEnd
;
148 static inline bool isUnaryOp(unsigned Opcode
) {
149 return Opcode
>= UnaryOpsBegin
&& Opcode
< UnaryOpsEnd
;
151 static inline bool isBinaryOp(unsigned Opcode
) {
152 return Opcode
>= BinaryOpsBegin
&& Opcode
< BinaryOpsEnd
;
155 static inline bool isIntDivRem(unsigned Opcode
) {
156 return Opcode
== UDiv
|| Opcode
== SDiv
|| Opcode
== URem
|| Opcode
== SRem
;
159 /// Determine if the Opcode is one of the shift instructions.
160 static inline bool isShift(unsigned Opcode
) {
161 return Opcode
>= Shl
&& Opcode
<= AShr
;
164 /// Return true if this is a logical shift left or a logical shift right.
165 inline bool isLogicalShift() const {
166 return getOpcode() == Shl
|| getOpcode() == LShr
;
169 /// Return true if this is an arithmetic shift right.
170 inline bool isArithmeticShift() const {
171 return getOpcode() == AShr
;
174 /// Determine if the Opcode is and/or/xor.
175 static inline bool isBitwiseLogicOp(unsigned Opcode
) {
176 return Opcode
== And
|| Opcode
== Or
|| Opcode
== Xor
;
179 /// Return true if this is and/or/xor.
180 inline bool isBitwiseLogicOp() const {
181 return isBitwiseLogicOp(getOpcode());
184 /// Determine if the OpCode is one of the CastInst instructions.
185 static inline bool isCast(unsigned OpCode
) {
186 return OpCode
>= CastOpsBegin
&& OpCode
< CastOpsEnd
;
189 /// Determine if the OpCode is one of the FuncletPadInst instructions.
190 static inline bool isFuncletPad(unsigned OpCode
) {
191 return OpCode
>= FuncletPadOpsBegin
&& OpCode
< FuncletPadOpsEnd
;
194 /// Returns true if the OpCode is a terminator related to exception handling.
195 static inline bool isExceptionalTerminator(unsigned OpCode
) {
197 case Instruction::CatchSwitch
:
198 case Instruction::CatchRet
:
199 case Instruction::CleanupRet
:
200 case Instruction::Invoke
:
201 case Instruction::Resume
:
208 /// Returns true if the OpCode is a terminator with indirect targets.
209 static inline bool isIndirectTerminator(unsigned OpCode
) {
211 case Instruction::IndirectBr
:
212 case Instruction::CallBr
:
219 //===--------------------------------------------------------------------===//
220 // Metadata manipulation.
221 //===--------------------------------------------------------------------===//
223 /// Return true if this instruction has any metadata attached to it.
224 bool hasMetadata() const { return DbgLoc
|| hasMetadataHashEntry(); }
226 /// Return true if this instruction has metadata attached to it other than a
228 bool hasMetadataOtherThanDebugLoc() const {
229 return hasMetadataHashEntry();
232 /// Get the metadata of given kind attached to this Instruction.
233 /// If the metadata is not found then return null.
234 MDNode
*getMetadata(unsigned KindID
) const {
235 if (!hasMetadata()) return nullptr;
236 return getMetadataImpl(KindID
);
239 /// Get the metadata of given kind attached to this Instruction.
240 /// If the metadata is not found then return null.
241 MDNode
*getMetadata(StringRef Kind
) const {
242 if (!hasMetadata()) return nullptr;
243 return getMetadataImpl(Kind
);
246 /// Get all metadata attached to this Instruction. The first element of each
247 /// pair returned is the KindID, the second element is the metadata value.
248 /// This list is returned sorted by the KindID.
250 getAllMetadata(SmallVectorImpl
<std::pair
<unsigned, MDNode
*>> &MDs
) const {
252 getAllMetadataImpl(MDs
);
255 /// This does the same thing as getAllMetadata, except that it filters out the
257 void getAllMetadataOtherThanDebugLoc(
258 SmallVectorImpl
<std::pair
<unsigned, MDNode
*>> &MDs
) const {
259 if (hasMetadataOtherThanDebugLoc())
260 getAllMetadataOtherThanDebugLocImpl(MDs
);
263 /// Fills the AAMDNodes structure with AA metadata from this instruction.
264 /// When Merge is true, the existing AA metadata is merged with that from this
265 /// instruction providing the most-general result.
266 void getAAMetadata(AAMDNodes
&N
, bool Merge
= false) const;
268 /// Set the metadata of the specified kind to the specified node. This updates
269 /// or replaces metadata if already present, or removes it if Node is null.
270 void setMetadata(unsigned KindID
, MDNode
*Node
);
271 void setMetadata(StringRef Kind
, MDNode
*Node
);
273 /// Copy metadata from \p SrcInst to this instruction. \p WL, if not empty,
274 /// specifies the list of meta data that needs to be copied. If \p WL is
275 /// empty, all meta data will be copied.
276 void copyMetadata(const Instruction
&SrcInst
,
277 ArrayRef
<unsigned> WL
= ArrayRef
<unsigned>());
279 /// If the instruction has "branch_weights" MD_prof metadata and the MDNode
280 /// has three operands (including name string), swap the order of the
282 void swapProfMetadata();
284 /// Drop all unknown metadata except for debug locations.
286 /// Passes are required to drop metadata they don't understand. This is a
287 /// convenience method for passes to do so.
288 void dropUnknownNonDebugMetadata(ArrayRef
<unsigned> KnownIDs
);
289 void dropUnknownNonDebugMetadata() {
290 return dropUnknownNonDebugMetadata(None
);
292 void dropUnknownNonDebugMetadata(unsigned ID1
) {
293 return dropUnknownNonDebugMetadata(makeArrayRef(ID1
));
295 void dropUnknownNonDebugMetadata(unsigned ID1
, unsigned ID2
) {
296 unsigned IDs
[] = {ID1
, ID2
};
297 return dropUnknownNonDebugMetadata(IDs
);
301 /// Sets the metadata on this instruction from the AAMDNodes structure.
302 void setAAMetadata(const AAMDNodes
&N
);
304 /// Retrieve the raw weight values of a conditional branch or select.
305 /// Returns true on success with profile weights filled in.
306 /// Returns false if no metadata or invalid metadata was found.
307 bool extractProfMetadata(uint64_t &TrueVal
, uint64_t &FalseVal
) const;
309 /// Retrieve total raw weight values of a branch.
310 /// Returns true on success with profile total weights filled in.
311 /// Returns false if no metadata was found.
312 bool extractProfTotalWeight(uint64_t &TotalVal
) const;
314 /// Updates branch_weights metadata by scaling it by \p S / \p T.
315 void updateProfWeight(uint64_t S
, uint64_t T
);
317 /// Sets the branch_weights metadata to \p W for CallInst.
318 void setProfWeight(uint64_t W
);
320 /// Set the debug location information for this instruction.
321 void setDebugLoc(DebugLoc Loc
) { DbgLoc
= std::move(Loc
); }
323 /// Return the debug location for this node as a DebugLoc.
324 const DebugLoc
&getDebugLoc() const { return DbgLoc
; }
326 /// Set or clear the nuw flag on this instruction, which must be an operator
327 /// which supports this flag. See LangRef.html for the meaning of this flag.
328 void setHasNoUnsignedWrap(bool b
= true);
330 /// Set or clear the nsw flag on this instruction, which must be an operator
331 /// which supports this flag. See LangRef.html for the meaning of this flag.
332 void setHasNoSignedWrap(bool b
= true);
334 /// Set or clear the exact flag on this instruction, which must be an operator
335 /// which supports this flag. See LangRef.html for the meaning of this flag.
336 void setIsExact(bool b
= true);
338 /// Determine whether the no unsigned wrap flag is set.
339 bool hasNoUnsignedWrap() const;
341 /// Determine whether the no signed wrap flag is set.
342 bool hasNoSignedWrap() const;
344 /// Drops flags that may cause this instruction to evaluate to poison despite
345 /// having non-poison inputs.
346 void dropPoisonGeneratingFlags();
348 /// Determine whether the exact flag is set.
349 bool isExact() const;
351 /// Set or clear all fast-math-flags on this instruction, which must be an
352 /// operator which supports this flag. See LangRef.html for the meaning of
354 void setFast(bool B
);
356 /// Set or clear the reassociation flag on this instruction, which must be
357 /// an operator which supports this flag. See LangRef.html for the meaning of
359 void setHasAllowReassoc(bool B
);
361 /// Set or clear the no-nans flag on this instruction, which must be an
362 /// operator which supports this flag. See LangRef.html for the meaning of
364 void setHasNoNaNs(bool B
);
366 /// Set or clear the no-infs flag on this instruction, which must be an
367 /// operator which supports this flag. See LangRef.html for the meaning of
369 void setHasNoInfs(bool B
);
371 /// Set or clear the no-signed-zeros flag on this instruction, which must be
372 /// an operator which supports this flag. See LangRef.html for the meaning of
374 void setHasNoSignedZeros(bool B
);
376 /// Set or clear the allow-reciprocal flag on this instruction, which must be
377 /// an operator which supports this flag. See LangRef.html for the meaning of
379 void setHasAllowReciprocal(bool B
);
381 /// Set or clear the approximate-math-functions flag on this instruction,
382 /// which must be an operator which supports this flag. See LangRef.html for
383 /// the meaning of this flag.
384 void setHasApproxFunc(bool B
);
386 /// Convenience function for setting multiple fast-math flags on this
387 /// instruction, which must be an operator which supports these flags. See
388 /// LangRef.html for the meaning of these flags.
389 void setFastMathFlags(FastMathFlags FMF
);
391 /// Convenience function for transferring all fast-math flag values to this
392 /// instruction, which must be an operator which supports these flags. See
393 /// LangRef.html for the meaning of these flags.
394 void copyFastMathFlags(FastMathFlags FMF
);
396 /// Determine whether all fast-math-flags are set.
399 /// Determine whether the allow-reassociation flag is set.
400 bool hasAllowReassoc() const;
402 /// Determine whether the no-NaNs flag is set.
403 bool hasNoNaNs() const;
405 /// Determine whether the no-infs flag is set.
406 bool hasNoInfs() const;
408 /// Determine whether the no-signed-zeros flag is set.
409 bool hasNoSignedZeros() const;
411 /// Determine whether the allow-reciprocal flag is set.
412 bool hasAllowReciprocal() const;
414 /// Determine whether the allow-contract flag is set.
415 bool hasAllowContract() const;
417 /// Determine whether the approximate-math-functions flag is set.
418 bool hasApproxFunc() const;
420 /// Convenience function for getting all the fast-math flags, which must be an
421 /// operator which supports these flags. See LangRef.html for the meaning of
423 FastMathFlags
getFastMathFlags() const;
425 /// Copy I's fast-math flags
426 void copyFastMathFlags(const Instruction
*I
);
428 /// Convenience method to copy supported exact, fast-math, and (optionally)
429 /// wrapping flags from V to this instruction.
430 void copyIRFlags(const Value
*V
, bool IncludeWrapFlags
= true);
432 /// Logical 'and' of any supported wrapping, exact, and fast-math flags of
433 /// V and this instruction.
434 void andIRFlags(const Value
*V
);
436 /// Merge 2 debug locations and apply it to the Instruction. If the
437 /// instruction is a CallIns, we need to traverse the inline chain to find
438 /// the common scope. This is not efficient for N-way merging as each time
439 /// you merge 2 iterations, you need to rebuild the hashmap to find the
440 /// common scope. However, we still choose this API because:
441 /// 1) Simplicity: it takes 2 locations instead of a list of locations.
442 /// 2) In worst case, it increases the complexity from O(N*I) to
443 /// O(2*N*I), where N is # of Instructions to merge, and I is the
444 /// maximum level of inline stack. So it is still linear.
445 /// 3) Merging of call instructions should be extremely rare in real
446 /// applications, thus the N-way merging should be in code path.
447 /// The DebugLoc attached to this instruction will be overwritten by the
449 void applyMergedLocation(const DILocation
*LocA
, const DILocation
*LocB
);
452 /// Return true if we have an entry in the on-the-side metadata hash.
453 bool hasMetadataHashEntry() const {
454 return (getSubclassDataFromValue() & HasMetadataBit
) != 0;
457 // These are all implemented in Metadata.cpp.
458 MDNode
*getMetadataImpl(unsigned KindID
) const;
459 MDNode
*getMetadataImpl(StringRef Kind
) const;
461 getAllMetadataImpl(SmallVectorImpl
<std::pair
<unsigned, MDNode
*>> &) const;
462 void getAllMetadataOtherThanDebugLocImpl(
463 SmallVectorImpl
<std::pair
<unsigned, MDNode
*>> &) const;
464 /// Clear all hashtable-based metadata from this instruction.
465 void clearMetadataHashEntries();
468 //===--------------------------------------------------------------------===//
469 // Predicates and helper methods.
470 //===--------------------------------------------------------------------===//
472 /// Return true if the instruction is associative:
474 /// Associative operators satisfy: x op (y op z) === (x op y) op z
476 /// In LLVM, the Add, Mul, And, Or, and Xor operators are associative.
478 bool isAssociative() const LLVM_READONLY
;
479 static bool isAssociative(unsigned Opcode
) {
480 return Opcode
== And
|| Opcode
== Or
|| Opcode
== Xor
||
481 Opcode
== Add
|| Opcode
== Mul
;
484 /// Return true if the instruction is commutative:
486 /// Commutative operators satisfy: (x op y) === (y op x)
488 /// In LLVM, these are the commutative operators, plus SetEQ and SetNE, when
489 /// applied to any type.
491 bool isCommutative() const { return isCommutative(getOpcode()); }
492 static bool isCommutative(unsigned Opcode
) {
496 case And
: case Or
: case Xor
:
503 /// Return true if the instruction is idempotent:
505 /// Idempotent operators satisfy: x op x === x
507 /// In LLVM, the And and Or operators are idempotent.
509 bool isIdempotent() const { return isIdempotent(getOpcode()); }
510 static bool isIdempotent(unsigned Opcode
) {
511 return Opcode
== And
|| Opcode
== Or
;
514 /// Return true if the instruction is nilpotent:
516 /// Nilpotent operators satisfy: x op x === Id,
518 /// where Id is the identity for the operator, i.e. a constant such that
519 /// x op Id === x and Id op x === x for all x.
521 /// In LLVM, the Xor operator is nilpotent.
523 bool isNilpotent() const { return isNilpotent(getOpcode()); }
524 static bool isNilpotent(unsigned Opcode
) {
525 return Opcode
== Xor
;
528 /// Return true if this instruction may modify memory.
529 bool mayWriteToMemory() const;
531 /// Return true if this instruction may read memory.
532 bool mayReadFromMemory() const;
534 /// Return true if this instruction may read or write memory.
535 bool mayReadOrWriteMemory() const {
536 return mayReadFromMemory() || mayWriteToMemory();
539 /// Return true if this instruction has an AtomicOrdering of unordered or
541 bool isAtomic() const;
543 /// Return true if this atomic instruction loads from memory.
544 bool hasAtomicLoad() const;
546 /// Return true if this atomic instruction stores to memory.
547 bool hasAtomicStore() const;
549 /// Return true if this instruction may throw an exception.
550 bool mayThrow() const;
552 /// Return true if this instruction behaves like a memory fence: it can load
553 /// or store to memory location without being given a memory location.
554 bool isFenceLike() const {
555 switch (getOpcode()) {
558 // This list should be kept in sync with the list in mayWriteToMemory for
559 // all opcodes which don't have a memory location.
560 case Instruction::Fence
:
561 case Instruction::CatchPad
:
562 case Instruction::CatchRet
:
563 case Instruction::Call
:
564 case Instruction::Invoke
:
569 /// Return true if the instruction may have side effects.
571 /// Note that this does not consider malloc and alloca to have side
572 /// effects because the newly allocated memory is completely invisible to
573 /// instructions which don't use the returned value. For cases where this
574 /// matters, isSafeToSpeculativelyExecute may be more appropriate.
575 bool mayHaveSideEffects() const { return mayWriteToMemory() || mayThrow(); }
577 /// Return true if the instruction can be removed if the result is unused.
579 /// When constant folding some instructions cannot be removed even if their
580 /// results are unused. Specifically terminator instructions and calls that
581 /// may have side effects cannot be removed without semantically changing the
582 /// generated program.
583 bool isSafeToRemove() const;
585 /// Return true if the instruction is a variety of EH-block.
586 bool isEHPad() const {
587 switch (getOpcode()) {
588 case Instruction::CatchSwitch
:
589 case Instruction::CatchPad
:
590 case Instruction::CleanupPad
:
591 case Instruction::LandingPad
:
598 /// Return true if the instruction is a llvm.lifetime.start or
599 /// llvm.lifetime.end marker.
600 bool isLifetimeStartOrEnd() const;
602 /// Return a pointer to the next non-debug instruction in the same basic
603 /// block as 'this', or nullptr if no such instruction exists.
604 const Instruction
*getNextNonDebugInstruction() const;
605 Instruction
*getNextNonDebugInstruction() {
606 return const_cast<Instruction
*>(
607 static_cast<const Instruction
*>(this)->getNextNonDebugInstruction());
610 /// Return a pointer to the previous non-debug instruction in the same basic
611 /// block as 'this', or nullptr if no such instruction exists.
612 const Instruction
*getPrevNonDebugInstruction() const;
613 Instruction
*getPrevNonDebugInstruction() {
614 return const_cast<Instruction
*>(
615 static_cast<const Instruction
*>(this)->getPrevNonDebugInstruction());
618 /// Create a copy of 'this' instruction that is identical in all ways except
620 /// * The instruction has no parent
621 /// * The instruction has no name
623 Instruction
*clone() const;
625 /// Return true if the specified instruction is exactly identical to the
626 /// current one. This means that all operands match and any extra information
627 /// (e.g. load is volatile) agree.
628 bool isIdenticalTo(const Instruction
*I
) const;
630 /// This is like isIdenticalTo, except that it ignores the
631 /// SubclassOptionalData flags, which may specify conditions under which the
632 /// instruction's result is undefined.
633 bool isIdenticalToWhenDefined(const Instruction
*I
) const;
635 /// When checking for operation equivalence (using isSameOperationAs) it is
636 /// sometimes useful to ignore certain attributes.
637 enum OperationEquivalenceFlags
{
638 /// Check for equivalence ignoring load/store alignment.
639 CompareIgnoringAlignment
= 1<<0,
640 /// Check for equivalence treating a type and a vector of that type
642 CompareUsingScalarTypes
= 1<<1
645 /// This function determines if the specified instruction executes the same
646 /// operation as the current one. This means that the opcodes, type, operand
647 /// types and any other factors affecting the operation must be the same. This
648 /// is similar to isIdenticalTo except the operands themselves don't have to
650 /// @returns true if the specified instruction is the same operation as
652 /// Determine if one instruction is the same operation as another.
653 bool isSameOperationAs(const Instruction
*I
, unsigned flags
= 0) const;
655 /// Return true if there are any uses of this instruction in blocks other than
656 /// the specified block. Note that PHI nodes are considered to evaluate their
657 /// operands in the corresponding predecessor block.
658 bool isUsedOutsideOfBlock(const BasicBlock
*BB
) const;
660 /// Return the number of successors that this instruction has. The instruction
661 /// must be a terminator.
662 unsigned getNumSuccessors() const;
664 /// Return the specified successor. This instruction must be a terminator.
665 BasicBlock
*getSuccessor(unsigned Idx
) const;
667 /// Update the specified successor to point at the provided block. This
668 /// instruction must be a terminator.
669 void setSuccessor(unsigned Idx
, BasicBlock
*BB
);
671 /// Methods for support type inquiry through isa, cast, and dyn_cast:
672 static bool classof(const Value
*V
) {
673 return V
->getValueID() >= Value::InstructionVal
;
676 //----------------------------------------------------------------------
677 // Exported enumerations.
679 enum TermOps
{ // These terminate basic blocks
680 #define FIRST_TERM_INST(N) TermOpsBegin = N,
681 #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
682 #define LAST_TERM_INST(N) TermOpsEnd = N+1
683 #include "llvm/IR/Instruction.def"
687 #define FIRST_UNARY_INST(N) UnaryOpsBegin = N,
688 #define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N,
689 #define LAST_UNARY_INST(N) UnaryOpsEnd = N+1
690 #include "llvm/IR/Instruction.def"
694 #define FIRST_BINARY_INST(N) BinaryOpsBegin = N,
695 #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
696 #define LAST_BINARY_INST(N) BinaryOpsEnd = N+1
697 #include "llvm/IR/Instruction.def"
701 #define FIRST_MEMORY_INST(N) MemoryOpsBegin = N,
702 #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
703 #define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1
704 #include "llvm/IR/Instruction.def"
708 #define FIRST_CAST_INST(N) CastOpsBegin = N,
709 #define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N,
710 #define LAST_CAST_INST(N) CastOpsEnd = N+1
711 #include "llvm/IR/Instruction.def"
715 #define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N,
716 #define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N,
717 #define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1
718 #include "llvm/IR/Instruction.def"
722 #define FIRST_OTHER_INST(N) OtherOpsBegin = N,
723 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
724 #define LAST_OTHER_INST(N) OtherOpsEnd = N+1
725 #include "llvm/IR/Instruction.def"
729 friend class SymbolTableListTraits
<Instruction
>;
731 // Shadow Value::setValueSubclassData with a private forwarding method so that
732 // subclasses cannot accidentally use it.
733 void setValueSubclassData(unsigned short D
) {
734 Value::setValueSubclassData(D
);
737 unsigned short getSubclassDataFromValue() const {
738 return Value::getSubclassDataFromValue();
741 void setHasMetadataHashEntry(bool V
) {
742 setValueSubclassData((getSubclassDataFromValue() & ~HasMetadataBit
) |
743 (V
? HasMetadataBit
: 0));
746 void setParent(BasicBlock
*P
);
749 // Instruction subclasses can stick up to 15 bits of stuff into the
750 // SubclassData field of instruction with these members.
752 // Verify that only the low 15 bits are used.
753 void setInstructionSubclassData(unsigned short D
) {
754 assert((D
& HasMetadataBit
) == 0 && "Out of range value put into field");
755 setValueSubclassData((getSubclassDataFromValue() & HasMetadataBit
) | D
);
758 unsigned getSubclassDataFromInstruction() const {
759 return getSubclassDataFromValue() & ~HasMetadataBit
;
762 Instruction(Type
*Ty
, unsigned iType
, Use
*Ops
, unsigned NumOps
,
763 Instruction
*InsertBefore
= nullptr);
764 Instruction(Type
*Ty
, unsigned iType
, Use
*Ops
, unsigned NumOps
,
765 BasicBlock
*InsertAtEnd
);
768 /// Create a copy of this instruction.
769 Instruction
*cloneImpl() const;
772 inline void ilist_alloc_traits
<Instruction
>::deleteNode(Instruction
*V
) {
776 } // end namespace llvm
778 #endif // LLVM_IR_INSTRUCTION_H