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