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