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