LLVM 19.0.0git
Instruction.h
Go to the documentation of this file.
1//===-- llvm/Instruction.h - Instruction class definition -------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the declaration of the Instruction class, which is the
10// base class for all of the LLVM instructions.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_IR_INSTRUCTION_H
15#define LLVM_IR_INSTRUCTION_H
16
17#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/Bitfields.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/ADT/ilist_node.h"
21#include "llvm/IR/DebugLoc.h"
23#include "llvm/IR/User.h"
24#include "llvm/IR/Value.h"
26#include <cstdint>
27#include <utility>
28
29namespace llvm {
30
31class BasicBlock;
32class DbgMarker;
33class FastMathFlags;
34class MDNode;
35class Module;
36struct AAMDNodes;
37class DbgMarker;
38class DbgRecord;
39
40template <> struct ilist_alloc_traits<Instruction> {
41 static inline void deleteNode(Instruction *V);
42};
43
46
47class Instruction : public User,
48 public ilist_node_with_parent<Instruction, BasicBlock,
49 ilist_iterator_bits<true>,
50 ilist_parent<BasicBlock>> {
51public:
54
55private:
56 DebugLoc DbgLoc; // 'dbg' Metadata cache.
57
58 /// Relative order of this instruction in its parent basic block. Used for
59 /// O(1) local dominance checks between instructions.
60 mutable unsigned Order = 0;
61
62public:
63 /// Optional marker recording the position for debugging information that
64 /// takes effect immediately before this instruction. Null unless there is
65 /// debugging information present.
67
68 /// Clone any debug-info attached to \p From onto this instruction. Used to
69 /// copy debugging information from one block to another, when copying entire
70 /// blocks. \see DebugProgramInstruction.h , because the ordering of
71 /// DbgRecords is still important, fine grain control of which instructions
72 /// are moved and where they go is necessary.
73 /// \p From The instruction to clone debug-info from.
74 /// \p from_here Optional iterator to limit DbgRecords cloned to be a range
75 /// from
76 /// from_here to end().
77 /// \p InsertAtHead Whether the cloned DbgRecords should be placed at the end
78 /// or the beginning of existing DbgRecords attached to this.
79 /// \returns A range over the newly cloned DbgRecords.
81 const Instruction *From,
82 std::optional<simple_ilist<DbgRecord>::iterator> FromHere = std::nullopt,
83 bool InsertAtHead = false);
84
85 /// Return a range over the DbgRecords attached to this instruction.
88 }
89
90 /// Return an iterator to the position of the "Next" DbgRecord after this
91 /// instruction, or std::nullopt. This is the position to pass to
92 /// BasicBlock::reinsertInstInDbgRecords when re-inserting an instruction.
93 std::optional<simple_ilist<DbgRecord>::iterator> getDbgReinsertionPosition();
94
95 /// Returns true if any DbgRecords are attached to this instruction.
96 bool hasDbgRecords() const;
97
98 /// Transfer any DbgRecords on the position \p It onto this instruction,
99 /// by simply adopting the sequence of DbgRecords (which is efficient) if
100 /// possible, by merging two sequences otherwise.
102 bool InsertAtHead);
103
104 /// Erase any DbgRecords attached to this instruction.
105 void dropDbgRecords();
106
107 /// Erase a single DbgRecord \p I that is attached to this instruction.
109
110 /// Handle the debug-info implications of this instruction being removed. Any
111 /// attached DbgRecords need to "fall" down onto the next instruction.
112 void handleMarkerRemoval();
113
114protected:
115 // The 15 first bits of `Value::SubclassData` are available for subclasses of
116 // `Instruction` to use.
118
119 // Template alias so that all Instruction storing alignment use the same
120 // definiton.
121 // Valid alignments are powers of two from 2^0 to 2^MaxAlignmentExponent =
122 // 2^32. We store them as Log2(Alignment), so we need 6 bits to encode the 33
123 // possible values.
124 template <unsigned Offset>
126 typename Bitfield::Element<unsigned, Offset, 6,
128
129 template <unsigned Offset>
131
132 template <unsigned Offset>
136
137private:
138 // The last bit is used to store whether the instruction has metadata attached
139 // or not.
141
142protected:
143 ~Instruction(); // Use deleteValue() to delete a generic Instruction.
144
145public:
146 Instruction(const Instruction &) = delete;
148
149 /// Specialize the methods defined in Value, as we know that an instruction
150 /// can only be used by other instructions.
151 Instruction *user_back() { return cast<Instruction>(*user_begin());}
152 const Instruction *user_back() const { return cast<Instruction>(*user_begin());}
153
154 /// Return the module owning the function this instruction belongs to
155 /// or nullptr it the function does not have a module.
156 ///
157 /// Note: this is undefined behavior if the instruction does not have a
158 /// parent, or the parent basic block does not have a parent function.
159 const Module *getModule() const;
161 return const_cast<Module *>(
162 static_cast<const Instruction *>(this)->getModule());
163 }
164
165 /// Return the function this instruction belongs to.
166 ///
167 /// Note: it is undefined behavior to call this on an instruction not
168 /// currently inserted into a function.
169 const Function *getFunction() const;
171 return const_cast<Function *>(
172 static_cast<const Instruction *>(this)->getFunction());
173 }
174
175 /// This method unlinks 'this' from the containing basic block, but does not
176 /// delete it.
177 void removeFromParent();
178
179 /// This method unlinks 'this' from the containing basic block and deletes it.
180 ///
181 /// \returns an iterator pointing to the element after the erased one
183
184 /// Insert an unlinked instruction into a basic block immediately before
185 /// the specified instruction.
186 void insertBefore(Instruction *InsertPos);
187 void insertBefore(InstListType::iterator InsertPos);
188
189 /// Insert an unlinked instruction into a basic block immediately after the
190 /// specified instruction.
191 void insertAfter(Instruction *InsertPos);
192
193 /// Inserts an unlinked instruction into \p ParentBB at position \p It and
194 /// returns the iterator of the inserted instruction.
197
199
200 /// Unlink this instruction from its current basic block and insert it into
201 /// the basic block that MovePos lives in, right before MovePos.
202 void moveBefore(Instruction *MovePos);
203
204 /// Perform a \ref moveBefore operation, while signalling that the caller
205 /// intends to preserve the original ordering of instructions. This implicitly
206 /// means that any adjacent debug-info should move with this instruction.
207 /// This method is currently a no-op placeholder, but it will become meaningful
208 /// when the "RemoveDIs" project is enabled.
209 void moveBeforePreserving(Instruction *MovePos);
210
211private:
212 /// RemoveDIs project: all other moves implemented with this method,
213 /// centralising debug-info updates into one place.
214 void moveBeforeImpl(BasicBlock &BB, InstListType::iterator I, bool Preserve);
215
216public:
217 /// Unlink this instruction and insert into BB before I.
218 ///
219 /// \pre I is a valid iterator into BB.
221
222 /// (See other overload for moveBeforePreserving).
224
225 /// Unlink this instruction from its current basic block and insert it into
226 /// the basic block that MovePos lives in, right after MovePos.
227 void moveAfter(Instruction *MovePos);
228
229 /// See \ref moveBeforePreserving .
230 void moveAfterPreserving(Instruction *MovePos);
231
232 /// Given an instruction Other in the same basic block as this instruction,
233 /// return true if this instruction comes before Other. In this worst case,
234 /// this takes linear time in the number of instructions in the block. The
235 /// results are cached, so in common cases when the block remains unmodified,
236 /// it takes constant time.
237 bool comesBefore(const Instruction *Other) const;
238
239 /// Get the first insertion point at which the result of this instruction
240 /// is defined. This is *not* the directly following instruction in a number
241 /// of cases, e.g. phi nodes or terminators that return values. This function
242 /// may return null if the insertion after the definition is not possible,
243 /// e.g. due to a catchswitch terminator.
244 std::optional<InstListType::iterator> getInsertionPointAfterDef();
245
246 //===--------------------------------------------------------------------===//
247 // Subclass classification.
248 //===--------------------------------------------------------------------===//
249
250 /// Returns a member of one of the enums like Instruction::Add.
251 unsigned getOpcode() const { return getValueID() - InstructionVal; }
252
253 const char *getOpcodeName() const { return getOpcodeName(getOpcode()); }
254 bool isTerminator() const { return isTerminator(getOpcode()); }
255 bool isUnaryOp() const { return isUnaryOp(getOpcode()); }
256 bool isBinaryOp() const { return isBinaryOp(getOpcode()); }
257 bool isIntDivRem() const { return isIntDivRem(getOpcode()); }
258 bool isShift() const { return isShift(getOpcode()); }
259 bool isCast() const { return isCast(getOpcode()); }
260 bool isFuncletPad() const { return isFuncletPad(getOpcode()); }
262
263 /// It checks if this instruction is the only user of at least one of
264 /// its operands.
266
267 static const char *getOpcodeName(unsigned Opcode);
268
269 static inline bool isTerminator(unsigned Opcode) {
270 return Opcode >= TermOpsBegin && Opcode < TermOpsEnd;
271 }
272
273 static inline bool isUnaryOp(unsigned Opcode) {
274 return Opcode >= UnaryOpsBegin && Opcode < UnaryOpsEnd;
275 }
276 static inline bool isBinaryOp(unsigned Opcode) {
277 return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd;
278 }
279
280 static inline bool isIntDivRem(unsigned Opcode) {
281 return Opcode == UDiv || Opcode == SDiv || Opcode == URem || Opcode == SRem;
282 }
283
284 /// Determine if the Opcode is one of the shift instructions.
285 static inline bool isShift(unsigned Opcode) {
286 return Opcode >= Shl && Opcode <= AShr;
287 }
288
289 /// Return true if this is a logical shift left or a logical shift right.
290 inline bool isLogicalShift() const {
291 return getOpcode() == Shl || getOpcode() == LShr;
292 }
293
294 /// Return true if this is an arithmetic shift right.
295 inline bool isArithmeticShift() const {
296 return getOpcode() == AShr;
297 }
298
299 /// Determine if the Opcode is and/or/xor.
300 static inline bool isBitwiseLogicOp(unsigned Opcode) {
301 return Opcode == And || Opcode == Or || Opcode == Xor;
302 }
303
304 /// Return true if this is and/or/xor.
305 inline bool isBitwiseLogicOp() const {
306 return isBitwiseLogicOp(getOpcode());
307 }
308
309 /// Determine if the Opcode is one of the CastInst instructions.
310 static inline bool isCast(unsigned Opcode) {
311 return Opcode >= CastOpsBegin && Opcode < CastOpsEnd;
312 }
313
314 /// Determine if the Opcode is one of the FuncletPadInst instructions.
315 static inline bool isFuncletPad(unsigned Opcode) {
316 return Opcode >= FuncletPadOpsBegin && Opcode < FuncletPadOpsEnd;
317 }
318
319 /// Returns true if the Opcode is a "special" terminator that does more than
320 /// branch to a successor (e.g. have a side effect or return a value).
321 static inline bool isSpecialTerminator(unsigned Opcode) {
322 switch (Opcode) {
323 case Instruction::CatchSwitch:
324 case Instruction::CatchRet:
325 case Instruction::CleanupRet:
326 case Instruction::Invoke:
327 case Instruction::Resume:
328 case Instruction::CallBr:
329 return true;
330 default:
331 return false;
332 }
333 }
334
335 //===--------------------------------------------------------------------===//
336 // Metadata manipulation.
337 //===--------------------------------------------------------------------===//
338
339 /// Return true if this instruction has any metadata attached to it.
340 bool hasMetadata() const { return DbgLoc || Value::hasMetadata(); }
341
342 /// Return true if this instruction has metadata attached to it other than a
343 /// debug location.
345
346 /// Return true if this instruction has the given type of metadata attached.
347 bool hasMetadata(unsigned KindID) const {
348 return getMetadata(KindID) != nullptr;
349 }
350
351 /// Return true if this instruction has the given type of metadata attached.
352 bool hasMetadata(StringRef Kind) const {
353 return getMetadata(Kind) != nullptr;
354 }
355
356 /// Get the metadata of given kind attached to this Instruction.
357 /// If the metadata is not found then return null.
358 MDNode *getMetadata(unsigned KindID) const {
359 // Handle 'dbg' as a special case since it is not stored in the hash table.
360 if (KindID == LLVMContext::MD_dbg)
361 return DbgLoc.getAsMDNode();
362 return Value::getMetadata(KindID);
363 }
364
365 /// Get the metadata of given kind attached to this Instruction.
366 /// If the metadata is not found then return null.
368 if (!hasMetadata()) return nullptr;
369 return getMetadataImpl(Kind);
370 }
371
372 /// Get all metadata attached to this Instruction. The first element of each
373 /// pair returned is the KindID, the second element is the metadata value.
374 /// This list is returned sorted by the KindID.
375 void
376 getAllMetadata(SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs) const {
377 if (hasMetadata())
378 getAllMetadataImpl(MDs);
379 }
380
381 /// This does the same thing as getAllMetadata, except that it filters out the
382 /// debug location.
384 SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs) const {
386 }
387
388 /// Set the metadata of the specified kind to the specified node. This updates
389 /// or replaces metadata if already present, or removes it if Node is null.
390 void setMetadata(unsigned KindID, MDNode *Node);
391 void setMetadata(StringRef Kind, MDNode *Node);
392
393 /// Copy metadata from \p SrcInst to this instruction. \p WL, if not empty,
394 /// specifies the list of meta data that needs to be copied. If \p WL is
395 /// empty, all meta data will be copied.
396 void copyMetadata(const Instruction &SrcInst,
398
399 /// Erase all metadata that matches the predicate.
400 void eraseMetadataIf(function_ref<bool(unsigned, MDNode *)> Pred);
401
402 /// If the instruction has "branch_weights" MD_prof metadata and the MDNode
403 /// has three operands (including name string), swap the order of the
404 /// metadata.
405 void swapProfMetadata();
406
407 /// Drop all unknown metadata except for debug locations.
408 /// @{
409 /// Passes are required to drop metadata they don't understand. This is a
410 /// convenience method for passes to do so.
411 /// dropUBImplyingAttrsAndUnknownMetadata should be used instead of
412 /// this API if the Instruction being modified is a call.
415 return dropUnknownNonDebugMetadata(std::nullopt);
416 }
417 void dropUnknownNonDebugMetadata(unsigned ID1) {
419 }
420 void dropUnknownNonDebugMetadata(unsigned ID1, unsigned ID2) {
421 unsigned IDs[] = {ID1, ID2};
422 return dropUnknownNonDebugMetadata(IDs);
423 }
424 /// @}
425
426 /// Adds an !annotation metadata node with \p Annotation to this instruction.
427 /// If this instruction already has !annotation metadata, append \p Annotation
428 /// to the existing node.
429 void addAnnotationMetadata(StringRef Annotation);
430 /// Adds an !annotation metadata node with an array of \p Annotations
431 /// as a tuple to this instruction. If this instruction already has
432 /// !annotation metadata, append the tuple to
433 /// the existing node.
435 /// Returns the AA metadata for this instruction.
436 AAMDNodes getAAMetadata() const;
437
438 /// Sets the AA metadata on this instruction from the AAMDNodes structure.
439 void setAAMetadata(const AAMDNodes &N);
440
441 /// Sets the nosanitize metadata on this instruction.
443
444 /// Retrieve total raw weight values of a branch.
445 /// Returns true on success with profile total weights filled in.
446 /// Returns false if no metadata was found.
447 bool extractProfTotalWeight(uint64_t &TotalVal) const;
448
449 /// Set the debug location information for this instruction.
450 void setDebugLoc(DebugLoc Loc) { DbgLoc = std::move(Loc); }
451
452 /// Return the debug location for this node as a DebugLoc.
453 const DebugLoc &getDebugLoc() const { return DbgLoc; }
454
455 /// Fetch the debug location for this node, unless this is a debug intrinsic,
456 /// in which case fetch the debug location of the next non-debug node.
457 const DebugLoc &getStableDebugLoc() const;
458
459 /// Set or clear the nuw flag on this instruction, which must be an operator
460 /// which supports this flag. See LangRef.html for the meaning of this flag.
461 void setHasNoUnsignedWrap(bool b = true);
462
463 /// Set or clear the nsw flag on this instruction, which must be an operator
464 /// which supports this flag. See LangRef.html for the meaning of this flag.
465 void setHasNoSignedWrap(bool b = true);
466
467 /// Set or clear the exact flag on this instruction, which must be an operator
468 /// which supports this flag. See LangRef.html for the meaning of this flag.
469 void setIsExact(bool b = true);
470
471 /// Set or clear the nneg flag on this instruction, which must be a zext
472 /// instruction.
473 void setNonNeg(bool b = true);
474
475 /// Determine whether the no unsigned wrap flag is set.
477
478 /// Determine whether the no signed wrap flag is set.
480
481 /// Determine whether the the nneg flag is set.
483
484 /// Return true if this operator has flags which may cause this instruction
485 /// to evaluate to poison despite having non-poison inputs.
487
488 /// Drops flags that may cause this instruction to evaluate to poison despite
489 /// having non-poison inputs.
491
492 /// Return true if this instruction has poison-generating metadata.
494
495 /// Drops metadata that may generate poison.
497
498 /// Return true if this instruction has poison-generating attribute.
500
501 /// Drops return attributes that may generate poison.
503
504 /// Return true if this instruction has poison-generating flags,
505 /// return attributes or metadata.
507 return hasPoisonGeneratingFlags() ||
510 }
511
512 /// Drops flags, return attributes and metadata that may generate poison.
517 }
518
519 /// This function drops non-debug unknown metadata (through
520 /// dropUnknownNonDebugMetadata). For calls, it also drops parameter and
521 /// return attributes that can cause undefined behaviour. Both of these should
522 /// be done by passes which move instructions in IR.
524
525 /// Drop any attributes or metadata that can cause immediate undefined
526 /// behavior. Retain other attributes/metadata on a best-effort basis.
527 /// This should be used when speculating instructions.
529
530 /// Determine whether the exact flag is set.
532
533 /// Set or clear all fast-math-flags on this instruction, which must be an
534 /// operator which supports this flag. See LangRef.html for the meaning of
535 /// this flag.
536 void setFast(bool B);
537
538 /// Set or clear the reassociation flag on this instruction, which must be
539 /// an operator which supports this flag. See LangRef.html for the meaning of
540 /// this flag.
541 void setHasAllowReassoc(bool B);
542
543 /// Set or clear the no-nans flag on this instruction, which must be an
544 /// operator which supports this flag. See LangRef.html for the meaning of
545 /// this flag.
546 void setHasNoNaNs(bool B);
547
548 /// Set or clear the no-infs flag on this instruction, which must be an
549 /// operator which supports this flag. See LangRef.html for the meaning of
550 /// this flag.
551 void setHasNoInfs(bool B);
552
553 /// Set or clear the no-signed-zeros flag on this instruction, which must be
554 /// an operator which supports this flag. See LangRef.html for the meaning of
555 /// this flag.
556 void setHasNoSignedZeros(bool B);
557
558 /// Set or clear the allow-reciprocal flag on this instruction, which must be
559 /// an operator which supports this flag. See LangRef.html for the meaning of
560 /// this flag.
561 void setHasAllowReciprocal(bool B);
562
563 /// Set or clear the allow-contract flag on this instruction, which must be
564 /// an operator which supports this flag. See LangRef.html for the meaning of
565 /// this flag.
566 void setHasAllowContract(bool B);
567
568 /// Set or clear the approximate-math-functions flag on this instruction,
569 /// which must be an operator which supports this flag. See LangRef.html for
570 /// the meaning of this flag.
571 void setHasApproxFunc(bool B);
572
573 /// Convenience function for setting multiple fast-math flags on this
574 /// instruction, which must be an operator which supports these flags. See
575 /// LangRef.html for the meaning of these flags.
576 void setFastMathFlags(FastMathFlags FMF);
577
578 /// Convenience function for transferring all fast-math flag values to this
579 /// instruction, which must be an operator which supports these flags. See
580 /// LangRef.html for the meaning of these flags.
581 void copyFastMathFlags(FastMathFlags FMF);
582
583 /// Determine whether all fast-math-flags are set.
585
586 /// Determine whether the allow-reassociation flag is set.
588
589 /// Determine whether the no-NaNs flag is set.
591
592 /// Determine whether the no-infs flag is set.
594
595 /// Determine whether the no-signed-zeros flag is set.
597
598 /// Determine whether the allow-reciprocal flag is set.
600
601 /// Determine whether the allow-contract flag is set.
603
604 /// Determine whether the approximate-math-functions flag is set.
606
607 /// Convenience function for getting all the fast-math flags, which must be an
608 /// operator which supports these flags. See LangRef.html for the meaning of
609 /// these flags.
610 FastMathFlags getFastMathFlags() const LLVM_READONLY;
611
612 /// Copy I's fast-math flags
613 void copyFastMathFlags(const Instruction *I);
614
615 /// Convenience method to copy supported exact, fast-math, and (optionally)
616 /// wrapping flags from V to this instruction.
617 void copyIRFlags(const Value *V, bool IncludeWrapFlags = true);
618
619 /// Logical 'and' of any supported wrapping, exact, and fast-math flags of
620 /// V and this instruction.
621 void andIRFlags(const Value *V);
622
623 /// Merge 2 debug locations and apply it to the Instruction. If the
624 /// instruction is a CallIns, we need to traverse the inline chain to find
625 /// the common scope. This is not efficient for N-way merging as each time
626 /// you merge 2 iterations, you need to rebuild the hashmap to find the
627 /// common scope. However, we still choose this API because:
628 /// 1) Simplicity: it takes 2 locations instead of a list of locations.
629 /// 2) In worst case, it increases the complexity from O(N*I) to
630 /// O(2*N*I), where N is # of Instructions to merge, and I is the
631 /// maximum level of inline stack. So it is still linear.
632 /// 3) Merging of call instructions should be extremely rare in real
633 /// applications, thus the N-way merging should be in code path.
634 /// The DebugLoc attached to this instruction will be overwritten by the
635 /// merged DebugLoc.
636 void applyMergedLocation(DILocation *LocA, DILocation *LocB);
637
638 /// Updates the debug location given that the instruction has been hoisted
639 /// from a block to a predecessor of that block.
640 /// Note: it is undefined behavior to call this on an instruction not
641 /// currently inserted into a function.
643
644 /// Drop the instruction's debug location. This does not guarantee removal
645 /// of the !dbg source location attachment, as it must set a line 0 location
646 /// with scope information attached on call instructions. To guarantee
647 /// removal of the !dbg attachment, use the \ref setDebugLoc() API.
648 /// Note: it is undefined behavior to call this on an instruction not
649 /// currently inserted into a function.
650 void dropLocation();
651
652 /// Merge the DIAssignID metadata from this instruction and those attached to
653 /// instructions in \p SourceInstructions. This process performs a RAUW on
654 /// the MetadataAsValue uses of the merged DIAssignID nodes. Not every
655 /// instruction in \p SourceInstructions needs to have DIAssignID
656 /// metadata. If none of them do then nothing happens. If this instruction
657 /// does not have a DIAssignID attachment but at least one in \p
658 /// SourceInstructions does then the merged one will be attached to
659 /// it. However, instructions without attachments in \p SourceInstructions
660 /// are not modified.
661 void mergeDIAssignID(ArrayRef<const Instruction *> SourceInstructions);
662
663private:
664 // These are all implemented in Metadata.cpp.
665 MDNode *getMetadataImpl(StringRef Kind) const;
666 void
667 getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned, MDNode *>> &) const;
668
669 /// Update the LLVMContext ID-to-Instruction(s) mapping. If \p ID is nullptr
670 /// then clear the mapping for this instruction.
671 void updateDIAssignIDMapping(DIAssignID *ID);
672
673public:
674 //===--------------------------------------------------------------------===//
675 // Predicates and helper methods.
676 //===--------------------------------------------------------------------===//
677
678 /// Return true if the instruction is associative:
679 ///
680 /// Associative operators satisfy: x op (y op z) === (x op y) op z
681 ///
682 /// In LLVM, the Add, Mul, And, Or, and Xor operators are associative.
683 ///
685 static bool isAssociative(unsigned Opcode) {
686 return Opcode == And || Opcode == Or || Opcode == Xor ||
687 Opcode == Add || Opcode == Mul;
688 }
689
690 /// Return true if the instruction is commutative:
691 ///
692 /// Commutative operators satisfy: (x op y) === (y op x)
693 ///
694 /// In LLVM, these are the commutative operators, plus SetEQ and SetNE, when
695 /// applied to any type.
696 ///
698 static bool isCommutative(unsigned Opcode) {
699 switch (Opcode) {
700 case Add: case FAdd:
701 case Mul: case FMul:
702 case And: case Or: case Xor:
703 return true;
704 default:
705 return false;
706 }
707 }
708
709 /// Return true if the instruction is idempotent:
710 ///
711 /// Idempotent operators satisfy: x op x === x
712 ///
713 /// In LLVM, the And and Or operators are idempotent.
714 ///
715 bool isIdempotent() const { return isIdempotent(getOpcode()); }
716 static bool isIdempotent(unsigned Opcode) {
717 return Opcode == And || Opcode == Or;
718 }
719
720 /// Return true if the instruction is nilpotent:
721 ///
722 /// Nilpotent operators satisfy: x op x === Id,
723 ///
724 /// where Id is the identity for the operator, i.e. a constant such that
725 /// x op Id === x and Id op x === x for all x.
726 ///
727 /// In LLVM, the Xor operator is nilpotent.
728 ///
729 bool isNilpotent() const { return isNilpotent(getOpcode()); }
730 static bool isNilpotent(unsigned Opcode) {
731 return Opcode == Xor;
732 }
733
734 /// Return true if this instruction may modify memory.
736
737 /// Return true if this instruction may read memory.
739
740 /// Return true if this instruction may read or write memory.
741 bool mayReadOrWriteMemory() const {
743 }
744
745 /// Return true if this instruction has an AtomicOrdering of unordered or
746 /// higher.
748
749 /// Return true if this atomic instruction loads from memory.
751
752 /// Return true if this atomic instruction stores to memory.
754
755 /// Return true if this instruction has a volatile memory access.
757
758 /// Return the type this instruction accesses in memory, if any.
760
761 /// Return true if this instruction may throw an exception.
762 ///
763 /// If IncludePhaseOneUnwind is set, this will also include cases where
764 /// phase one unwinding may unwind past this frame due to skipping of
765 /// cleanup landingpads.
766 bool mayThrow(bool IncludePhaseOneUnwind = false) const LLVM_READONLY;
767
768 /// Return true if this instruction behaves like a memory fence: it can load
769 /// or store to memory location without being given a memory location.
770 bool isFenceLike() const {
771 switch (getOpcode()) {
772 default:
773 return false;
774 // This list should be kept in sync with the list in mayWriteToMemory for
775 // all opcodes which don't have a memory location.
776 case Instruction::Fence:
777 case Instruction::CatchPad:
778 case Instruction::CatchRet:
779 case Instruction::Call:
780 case Instruction::Invoke:
781 return true;
782 }
783 }
784
785 /// Return true if the instruction may have side effects.
786 ///
787 /// Side effects are:
788 /// * Writing to memory.
789 /// * Unwinding.
790 /// * Not returning (e.g. an infinite loop).
791 ///
792 /// Note that this does not consider malloc and alloca to have side
793 /// effects because the newly allocated memory is completely invisible to
794 /// instructions which don't use the returned value. For cases where this
795 /// matters, isSafeToSpeculativelyExecute may be more appropriate.
797
798 /// Return true if the instruction can be removed if the result is unused.
799 ///
800 /// When constant folding some instructions cannot be removed even if their
801 /// results are unused. Specifically terminator instructions and calls that
802 /// may have side effects cannot be removed without semantically changing the
803 /// generated program.
805
806 /// Return true if the instruction will return (unwinding is considered as
807 /// a form of returning control flow here).
809
810 /// Return true if the instruction is a variety of EH-block.
811 bool isEHPad() const {
812 switch (getOpcode()) {
813 case Instruction::CatchSwitch:
814 case Instruction::CatchPad:
815 case Instruction::CleanupPad:
816 case Instruction::LandingPad:
817 return true;
818 default:
819 return false;
820 }
821 }
822
823 /// Return true if the instruction is a llvm.lifetime.start or
824 /// llvm.lifetime.end marker.
826
827 /// Return true if the instruction is a llvm.launder.invariant.group or
828 /// llvm.strip.invariant.group.
830
831 /// Return true if the instruction is a DbgInfoIntrinsic or PseudoProbeInst.
833
834 /// Return a pointer to the next non-debug instruction in the same basic
835 /// block as 'this', or nullptr if no such instruction exists. Skip any pseudo
836 /// operations if \c SkipPseudoOp is true.
838 getNextNonDebugInstruction(bool SkipPseudoOp = false) const;
840 return const_cast<Instruction *>(
841 static_cast<const Instruction *>(this)->getNextNonDebugInstruction(
842 SkipPseudoOp));
843 }
844
845 /// Return a pointer to the previous non-debug instruction in the same basic
846 /// block as 'this', or nullptr if no such instruction exists. Skip any pseudo
847 /// operations if \c SkipPseudoOp is true.
848 const Instruction *
849 getPrevNonDebugInstruction(bool SkipPseudoOp = false) const;
850 Instruction *getPrevNonDebugInstruction(bool SkipPseudoOp = false) {
851 return const_cast<Instruction *>(
852 static_cast<const Instruction *>(this)->getPrevNonDebugInstruction(
853 SkipPseudoOp));
854 }
855
856 /// Create a copy of 'this' instruction that is identical in all ways except
857 /// the following:
858 /// * The instruction has no parent
859 /// * The instruction has no name
860 ///
861 Instruction *clone() const;
862
863 /// Return true if the specified instruction is exactly identical to the
864 /// current one. This means that all operands match and any extra information
865 /// (e.g. load is volatile) agree.
866 bool isIdenticalTo(const Instruction *I) const LLVM_READONLY;
867
868 /// This is like isIdenticalTo, except that it ignores the
869 /// SubclassOptionalData flags, which may specify conditions under which the
870 /// instruction's result is undefined.
872
873 /// When checking for operation equivalence (using isSameOperationAs) it is
874 /// sometimes useful to ignore certain attributes.
876 /// Check for equivalence ignoring load/store alignment.
878 /// Check for equivalence treating a type and a vector of that type
879 /// as equivalent.
881 };
882
883 /// This function determines if the specified instruction executes the same
884 /// operation as the current one. This means that the opcodes, type, operand
885 /// types and any other factors affecting the operation must be the same. This
886 /// is similar to isIdenticalTo except the operands themselves don't have to
887 /// be identical.
888 /// @returns true if the specified instruction is the same operation as
889 /// the current one.
890 /// Determine if one instruction is the same operation as another.
891 bool isSameOperationAs(const Instruction *I, unsigned flags = 0) const LLVM_READONLY;
892
893 /// This function determines if the speficied instruction has the same
894 /// "special" characteristics as the current one. This means that opcode
895 /// specific details are the same. As a common example, if we are comparing
896 /// loads, then hasSameSpecialState would compare the alignments (among
897 /// other things).
898 /// @returns true if the specific instruction has the same opcde specific
899 /// characteristics as the current one. Determine if one instruction has the
900 /// same state as another.
902 bool IgnoreAlignment = false) const LLVM_READONLY;
903
904 /// Return true if there are any uses of this instruction in blocks other than
905 /// the specified block. Note that PHI nodes are considered to evaluate their
906 /// operands in the corresponding predecessor block.
908
909 /// Return the number of successors that this instruction has. The instruction
910 /// must be a terminator.
912
913 /// Return the specified successor. This instruction must be a terminator.
915
916 /// Update the specified successor to point at the provided block. This
917 /// instruction must be a terminator.
918 void setSuccessor(unsigned Idx, BasicBlock *BB);
919
920 /// Replace specified successor OldBB to point at the provided block.
921 /// This instruction must be a terminator.
922 void replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB);
923
924 /// Methods for support type inquiry through isa, cast, and dyn_cast:
925 static bool classof(const Value *V) {
926 return V->getValueID() >= Value::InstructionVal;
927 }
928
929 //----------------------------------------------------------------------
930 // Exported enumerations.
931 //
932 enum TermOps { // These terminate basic blocks
933#define FIRST_TERM_INST(N) TermOpsBegin = N,
934#define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
935#define LAST_TERM_INST(N) TermOpsEnd = N+1
936#include "llvm/IR/Instruction.def"
937 };
938
939 enum UnaryOps {
940#define FIRST_UNARY_INST(N) UnaryOpsBegin = N,
941#define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N,
942#define LAST_UNARY_INST(N) UnaryOpsEnd = N+1
943#include "llvm/IR/Instruction.def"
944 };
945
947#define FIRST_BINARY_INST(N) BinaryOpsBegin = N,
948#define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
949#define LAST_BINARY_INST(N) BinaryOpsEnd = N+1
950#include "llvm/IR/Instruction.def"
951 };
952
954#define FIRST_MEMORY_INST(N) MemoryOpsBegin = N,
955#define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
956#define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1
957#include "llvm/IR/Instruction.def"
958 };
959
960 enum CastOps {
961#define FIRST_CAST_INST(N) CastOpsBegin = N,
962#define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N,
963#define LAST_CAST_INST(N) CastOpsEnd = N+1
964#include "llvm/IR/Instruction.def"
965 };
966
968#define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N,
969#define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N,
970#define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1
971#include "llvm/IR/Instruction.def"
972 };
973
974 enum OtherOps {
975#define FIRST_OTHER_INST(N) OtherOpsBegin = N,
976#define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
977#define LAST_OTHER_INST(N) OtherOpsEnd = N+1
978#include "llvm/IR/Instruction.def"
979 };
980
981private:
982 friend class SymbolTableListTraits<Instruction, ilist_iterator_bits<true>,
983 ilist_parent<BasicBlock>>;
984 friend class BasicBlock; // For renumbering.
985
986 // Shadow Value::setValueSubclassData with a private forwarding method so that
987 // subclasses cannot accidentally use it.
988 void setValueSubclassData(unsigned short D) {
990 }
991
992 unsigned short getSubclassDataFromValue() const {
994 }
995
996protected:
997 // Instruction subclasses can stick up to 15 bits of stuff into the
998 // SubclassData field of instruction with these members.
999
1000 template <typename BitfieldElement>
1001 typename BitfieldElement::Type getSubclassData() const {
1002 static_assert(
1003 std::is_same<BitfieldElement, HasMetadataField>::value ||
1004 !Bitfield::isOverlapping<BitfieldElement, HasMetadataField>(),
1005 "Must not overlap with the metadata bit");
1006 return Bitfield::get<BitfieldElement>(getSubclassDataFromValue());
1007 }
1008
1009 template <typename BitfieldElement>
1010 void setSubclassData(typename BitfieldElement::Type Value) {
1011 static_assert(
1012 std::is_same<BitfieldElement, HasMetadataField>::value ||
1013 !Bitfield::isOverlapping<BitfieldElement, HasMetadataField>(),
1014 "Must not overlap with the metadata bit");
1015 auto Storage = getSubclassDataFromValue();
1016 Bitfield::set<BitfieldElement>(Storage, Value);
1017 setValueSubclassData(Storage);
1018 }
1019
1020 Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps,
1021 InstListType::iterator InsertBefore);
1022 Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps,
1023 Instruction *InsertBefore = nullptr);
1024 Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps,
1025 BasicBlock *InsertAtEnd);
1026
1027private:
1028 /// Create a copy of this instruction.
1029 Instruction *cloneImpl() const;
1030};
1031
1033 V->deleteValue();
1034}
1035
1036} // end namespace llvm
1037
1038#endif // LLVM_IR_INSTRUCTION_H
aarch64 promote const
Atomic ordering constants.
basic Basic Alias true
This file implements methods to test, set and extract typed bits from packed unsigned integers.
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_READONLY
Definition: Compiler.h:227
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
#define I(x, y, z)
Definition: MD5.cpp:58
Machine Check Debug Module
Annotations lets you mark points and ranges inside source code, for tests:
Definition: Annotations.h:53
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
Per-instruction record of debug-info.
Base class for non-instruction debug metadata records that have positions within IR.
A debug info location.
Definition: DebugLoc.h:33
MDNode * getAsMDNode() const
Return this as a bar MDNode.
Definition: DebugLoc.h:106
const DebugLoc & getStableDebugLoc() const
Fetch the debug location for this node, unless this is a debug intrinsic, in which case fetch the deb...
DbgMarker * DebugMarker
Optional marker recording the position for debugging information that takes effect immediately before...
Definition: Instruction.h:66
BitfieldElement::Type getSubclassData() const
Definition: Instruction.h:1001
bool mayThrow(bool IncludePhaseOneUnwind=false) const LLVM_READONLY
Return true if this instruction may throw an exception.
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following:
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
bool hasNoNaNs() const LLVM_READONLY
Determine whether the no-NaNs flag is set.
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
Definition: Instruction.cpp:85
bool hasNoUnsignedWrap() const LLVM_READONLY
Determine whether the no unsigned wrap flag is set.
bool hasNoInfs() const LLVM_READONLY
Determine whether the no-infs flag is set.
bool isLifetimeStartOrEnd() const LLVM_READONLY
Return true if the instruction is a llvm.lifetime.start or llvm.lifetime.end marker.
bool hasMetadata(unsigned KindID) const
Return true if this instruction has the given type of metadata attached.
Definition: Instruction.h:347
static bool isBinaryOp(unsigned Opcode)
Definition: Instruction.h:276
bool isArithmeticShift() const
Return true if this is an arithmetic shift right.
Definition: Instruction.h:295
bool hasMetadata(StringRef Kind) const
Return true if this instruction has the given type of metadata attached.
Definition: Instruction.h:352
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction,...
bool isSameOperationAs(const Instruction *I, unsigned flags=0) const LLVM_READONLY
This function determines if the specified instruction executes the same operation as the current one.
void mergeDIAssignID(ArrayRef< const Instruction * > SourceInstructions)
Merge the DIAssignID metadata from this instruction and those attached to instructions in SourceInstr...
Definition: DebugInfo.cpp:936
bool isCast() const
Definition: Instruction.h:259
void setHasNoSignedZeros(bool B)
Set or clear the no-signed-zeros flag on this instruction, which must be an operator which supports t...
void moveBeforePreserving(Instruction *MovePos)
Perform a moveBefore operation, while signalling that the caller intends to preserve the original ord...
bool hasNoSignedZeros() const LLVM_READONLY
Determine whether the no-signed-zeros flag is set.
iterator_range< simple_ilist< DbgRecord >::iterator > cloneDebugInfoFrom(const Instruction *From, std::optional< simple_ilist< DbgRecord >::iterator > FromHere=std::nullopt, bool InsertAtHead=false)
Clone any debug-info attached to From onto this instruction.
static bool isBitwiseLogicOp(unsigned Opcode)
Determine if the Opcode is and/or/xor.
Definition: Instruction.h:300
bool mayReadOrWriteMemory() const
Return true if this instruction may read or write memory.
Definition: Instruction.h:741
bool hasPoisonGeneratingReturnAttributes() const LLVM_READONLY
Return true if this instruction has poison-generating attribute.
bool isDebugOrPseudoInst() const LLVM_READONLY
Return true if the instruction is a DbgInfoIntrinsic or PseudoProbeInst.
unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
static bool isShift(unsigned Opcode)
Determine if the Opcode is one of the shift instructions.
Definition: Instruction.h:285
bool hasNoSignedWrap() const LLVM_READONLY
Determine whether the no signed wrap flag is set.
Function * getFunction()
Definition: Instruction.h:170
bool mayWriteToMemory() const LLVM_READONLY
Return true if this instruction may modify memory.
static bool isSpecialTerminator(unsigned Opcode)
Returns true if the Opcode is a "special" terminator that does more than branch to a successor (e....
Definition: Instruction.h:321
void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
void setHasAllowContract(bool B)
Set or clear the allow-contract flag on this instruction, which must be an operator which supports th...
bool hasAtomicStore() const LLVM_READONLY
Return true if this atomic instruction stores to memory.
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
typename Bitfield::Element< AtomicOrdering, Offset, 3, AtomicOrdering::LAST > AtomicOrderingBitfieldElementT
Definition: Instruction.h:135
bool isOnlyUserOfAnyOperand()
It checks if this instruction is the only user of at least one of its operands.
iterator_range< simple_ilist< DbgRecord >::iterator > getDbgRecordRange() const
Return a range over the DbgRecords attached to this instruction.
Definition: Instruction.h:86
void dropLocation()
Drop the instruction's debug location.
Definition: DebugInfo.cpp:967
static bool isCast(unsigned Opcode)
Determine if the Opcode is one of the CastInst instructions.
Definition: Instruction.h:310
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:453
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:77
void setAAMetadata(const AAMDNodes &N)
Sets the AA metadata on this instruction from the AAMDNodes structure.
Definition: Metadata.cpp:1720
void andIRFlags(const Value *V)
Logical 'and' of any supported wrapping, exact, and fast-math flags of V and this instruction.
void setHasNoNaNs(bool B)
Set or clear the no-nans flag on this instruction, which must be an operator which supports this flag...
bool isAssociative() const LLVM_READONLY
Return true if the instruction is associative:
const Instruction * getPrevNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the previous non-debug instruction in the same basic block as 'this',...
bool extractProfTotalWeight(uint64_t &TotalVal) const
Retrieve total raw weight values of a branch.
Definition: Metadata.cpp:1744
Instruction & operator=(const Instruction &)=delete
void setHasApproxFunc(bool B)
Set or clear the approximate-math-functions flag on this instruction, which must be an operator which...
void moveAfter(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
bool hasMetadataOtherThanDebugLoc() const
Return true if this instruction has metadata attached to it other than a debug location.
Definition: Instruction.h:344
bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
typename Bitfield::Element< bool, Offset, 1 > BoolBitfieldElementT
Definition: Instruction.h:130
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
Definition: Instruction.h:340
Module * getModule()
Definition: Instruction.h:160
bool isAtomic() const LLVM_READONLY
Return true if this instruction has an AtomicOrdering of unordered or higher.
void setHasAllowReassoc(bool B)
Set or clear the reassociation flag on this instruction, which must be an operator which supports thi...
bool isBinaryOp() const
Definition: Instruction.h:256
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
Definition: Instruction.h:811
void dropPoisonGeneratingReturnAttributes()
Drops return attributes that may generate poison.
InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:99
bool isFast() const LLVM_READONLY
Determine whether all fast-math-flags are set.
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Instruction.h:925
void replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB)
Replace specified successor OldBB to point at the provided block.
Instruction * user_back()
Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...
Definition: Instruction.h:151
static bool isIdempotent(unsigned Opcode)
Definition: Instruction.h:716
void addAnnotationMetadata(StringRef Annotation)
Adds an !annotation metadata node with Annotation to this instruction.
Definition: Metadata.cpp:1688
bool isExact() const LLVM_READONLY
Determine whether the exact flag is set.
bool isIdenticalToWhenDefined(const Instruction *I) const LLVM_READONLY
This is like isIdenticalTo, except that it ignores the SubclassOptionalData flags,...
const Function * getFunction() const
Return the function this instruction belongs to.
Definition: Instruction.cpp:81
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:358
void swapProfMetadata()
If the instruction has "branch_weights" MD_prof metadata and the MDNode has three operands (including...
BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY
Return the specified successor. This instruction must be a terminator.
bool mayHaveSideEffects() const LLVM_READONLY
Return true if the instruction may have side effects.
bool isFuncletPad() const
Definition: Instruction.h:260
void dropOneDbgRecord(DbgRecord *I)
Erase a single DbgRecord I that is attached to this instruction.
void setNonNeg(bool b=true)
Set or clear the nneg flag on this instruction, which must be a zext instruction.
bool isTerminator() const
Definition: Instruction.h:254
Type * getAccessType() const LLVM_READONLY
Return the type this instruction accesses in memory, if any.
bool hasSameSpecialState(const Instruction *I2, bool IgnoreAlignment=false) const LLVM_READONLY
This function determines if the speficied instruction has the same "special" characteristics as the c...
bool hasAllowReciprocal() const LLVM_READONLY
Determine whether the allow-reciprocal flag is set.
bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
void dropUBImplyingAttrsAndMetadata()
Drop any attributes or metadata that can cause immediate undefined behavior.
typename Bitfield::Element< unsigned, Offset, 6, Value::MaxAlignmentExponent > AlignmentBitfieldElementT
Definition: Instruction.h:127
bool hasPoisonGeneratingAnnotations() const
Return true if this instruction has poison-generating flags, return attributes or metadata.
Definition: Instruction.h:506
bool hasNonNeg() const LLVM_READONLY
Determine whether the the nneg flag is set.
void dropUnknownNonDebugMetadata(unsigned ID1, unsigned ID2)
Definition: Instruction.h:420
Instruction * getPrevNonDebugInstruction(bool SkipPseudoOp=false)
Definition: Instruction.h:850
bool hasPoisonGeneratingFlags() const LLVM_READONLY
Return true if this operator has flags which may cause this instruction to evaluate to poison despite...
bool isNilpotent() const
Return true if the instruction is nilpotent:
Definition: Instruction.h:729
bool mayReadFromMemory() const LLVM_READONLY
Return true if this instruction may read memory.
const Instruction * getNextNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the next non-debug instruction in the same basic block as 'this',...
bool isUsedOutsideOfBlock(const BasicBlock *BB) const LLVM_READONLY
Return true if there are any uses of this instruction in blocks other than the specified block.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1635
bool isVolatile() const LLVM_READONLY
Return true if this instruction has a volatile memory access.
void setHasNoInfs(bool B)
Set or clear the no-infs flag on this instruction, which must be an operator which supports this flag...
void setNoSanitizeMetadata()
Sets the nosanitize metadata on this instruction.
Definition: Metadata.cpp:1727
void dropPoisonGeneratingAnnotations()
Drops flags, return attributes and metadata that may generate poison.
Definition: Instruction.h:513
void adoptDbgRecords(BasicBlock *BB, InstListType::iterator It, bool InsertAtHead)
Transfer any DbgRecords on the position It onto this instruction, by simply adopting the sequence of ...
FastMathFlags getFastMathFlags() const LLVM_READONLY
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
const char * getOpcodeName() const
Definition: Instruction.h:253
const Instruction * user_back() const
Definition: Instruction.h:152
bool willReturn() const LLVM_READONLY
Return true if the instruction will return (unwinding is considered as a form of returning control fl...
bool hasApproxFunc() const LLVM_READONLY
Determine whether the approximate-math-functions flag is set.
OperationEquivalenceFlags
When checking for operation equivalence (using isSameOperationAs) it is sometimes useful to ignore ce...
Definition: Instruction.h:875
@ CompareIgnoringAlignment
Check for equivalence ignoring load/store alignment.
Definition: Instruction.h:877
@ CompareUsingScalarTypes
Check for equivalence treating a type and a vector of that type as equivalent.
Definition: Instruction.h:880
MDNode * getMetadata(StringRef Kind) const
Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:367
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Get all metadata attached to this Instruction.
Definition: Instruction.h:376
bool isLogicalShift() const
Return true if this is a logical shift left or a logical shift right.
Definition: Instruction.h:290
AAMDNodes getAAMetadata() const
Returns the AA metadata for this instruction.
Definition: Metadata.cpp:1706
void getAllMetadataOtherThanDebugLoc(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
This does the same thing as getAllMetadata, except that it filters out the debug location.
Definition: Instruction.h:383
static bool isFuncletPad(unsigned Opcode)
Determine if the Opcode is one of the FuncletPadInst instructions.
Definition: Instruction.h:315
void moveAfterPreserving(Instruction *MovePos)
See moveBeforePreserving .
static bool isUnaryOp(unsigned Opcode)
Definition: Instruction.h:273
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:251
bool hasAtomicLoad() const LLVM_READONLY
Return true if this atomic instruction loads from memory.
static bool isNilpotent(unsigned Opcode)
Definition: Instruction.h:730
void dropUnknownNonDebugMetadata()
Definition: Instruction.h:414
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
void dropPoisonGeneratingMetadata()
Drops metadata that may generate poison.
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
Definition: Instruction.h:305
bool isShift() const
Definition: Instruction.h:258
static bool isTerminator(unsigned Opcode)
Definition: Instruction.h:269
void setHasAllowReciprocal(bool B)
Set or clear the allow-reciprocal flag on this instruction, which must be an operator which supports ...
bool isFenceLike() const
Return true if this instruction behaves like a memory fence: it can load or store to memory location ...
Definition: Instruction.h:770
void handleMarkerRemoval()
Handle the debug-info implications of this instruction being removed.
Definition: Instruction.cpp:92
std::optional< InstListType::iterator > getInsertionPointAfterDef()
Get the first insertion point at which the result of this instruction is defined.
void dropPoisonGeneratingFlags()
Drops flags that may cause this instruction to evaluate to poison despite having non-poison inputs.
void dropUBImplyingAttrsAndUnknownMetadata(ArrayRef< unsigned > KnownIDs={})
This function drops non-debug unknown metadata (through dropUnknownNonDebugMetadata).
bool isIdenticalTo(const Instruction *I) const LLVM_READONLY
Return true if the specified instruction is exactly identical to the current one.
std::optional< simple_ilist< DbgRecord >::iterator > getDbgReinsertionPosition()
Return an iterator to the position of the "Next" DbgRecord after this instruction,...
bool isLaunderOrStripInvariantGroup() const LLVM_READONLY
Return true if the instruction is a llvm.launder.invariant.group or llvm.strip.invariant....
bool hasAllowContract() const LLVM_READONLY
Determine whether the allow-contract flag is set.
void updateLocationAfterHoist()
Updates the debug location given that the instruction has been hoisted from a block to a predecessor ...
Definition: DebugInfo.cpp:965
bool hasPoisonGeneratingMetadata() const LLVM_READONLY
Return true if this instruction has poison-generating metadata.
bool isUnaryOp() const
Definition: Instruction.h:255
void dropUnknownNonDebugMetadata(unsigned ID1)
Definition: Instruction.h:417
Instruction(const Instruction &)=delete
void applyMergedLocation(DILocation *LocA, DILocation *LocB)
Merge 2 debug locations and apply it to the Instruction.
Definition: DebugInfo.cpp:932
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:450
void setSuccessor(unsigned Idx, BasicBlock *BB)
Update the specified successor to point at the provided block.
static bool isIntDivRem(unsigned Opcode)
Definition: Instruction.h:280
bool isIdempotent() const
Return true if the instruction is idempotent:
Definition: Instruction.h:715
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
void setFast(bool B)
Set or clear all fast-math-flags on this instruction, which must be an operator which supports this f...
bool hasAllowReassoc() const LLVM_READONLY
Determine whether the allow-reassociation flag is set.
void dropDbgRecords()
Erase any DbgRecords attached to this instruction.
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction.
friend class BasicBlock
Various leaf nodes.
Definition: Instruction.h:984
void eraseMetadataIf(function_ref< bool(unsigned, MDNode *)> Pred)
Erase all metadata that matches the predicate.
Definition: Metadata.cpp:1582
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
bool isSafeToRemove() const LLVM_READONLY
Return true if the instruction can be removed if the result is unused.
bool isIntDivRem() const
Definition: Instruction.h:257
void setSubclassData(typename BitfieldElement::Type Value)
Definition: Instruction.h:1010
bool isSpecialTerminator() const
Definition: Instruction.h:261
InstListType::iterator insertInto(BasicBlock *ParentBB, InstListType::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
bool hasDbgRecords() const
Returns true if any DbgRecords are attached to this instruction.
Metadata node.
Definition: Metadata.h:1067
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
LLVM Value Representation.
Definition: Value.h:74
unsigned short getSubclassDataFromValue() const
Definition: Value.h:866
user_iterator user_begin()
Definition: Value.h:397
bool hasMetadata() const
Return true if this value has any metadata attached to it.
Definition: Value.h:589
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
Definition: Metadata.cpp:1477
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:532
void setValueSubclassData(unsigned short D)
Definition: Value.h:867
static constexpr unsigned MaxAlignmentExponent
The maximum alignment for instructions.
Definition: Value.h:806
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
Definition: Value.h:565
An efficient, type-erasing, non-owning reference to a callable.
An ilist node that can access its parent list.
Definition: ilist_node.h:321
base_list_type::iterator iterator
Definition: ilist.h:121
A range adaptor for a pair of iterators.
typename ilist_select_iterator_type< OptionsT::has_iterator_bits, OptionsT, false, false >::type iterator
Definition: simple_ilist.h:97
This file defines the ilist_node class template, which is a convenient base class for creating classe...
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:456
iterator_range< simple_ilist< DbgRecord >::iterator > getDbgRecordRange(DbgMarker *DebugMarker)
Inline helper to return a range of DbgRecords attached to a marker.
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ Other
Any other memory.
@ Or
Bitwise or logical OR of integers.
@ Mul
Product of integers.
@ Xor
Bitwise or logical XOR of integers.
@ FMul
Product of floats.
@ And
Bitwise or logical AND of integers.
@ Add
Sum of integers.
@ FAdd
Sum of floats.
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
#define N
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition: Metadata.h:760
Describes an element of a Bitfield.
Definition: Bitfields.h:223
Use delete by default for iplist and ilist.
Definition: ilist.h:41
static void deleteNode(NodeTy *V)
Definition: ilist.h:42
Option to add a pointer to this list's owner in every node.