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