//===- llvm/Instructions.h - Instruction subclass definitions ---*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file exposes the class definitions of all of the subclasses of the // Instruction class. This is meant to be an easy way to get access to all // instruction subclasses. // //===----------------------------------------------------------------------===// #ifndef LLVM_IR_INSTRUCTIONS_H #define LLVM_IR_INSTRUCTIONS_H #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Bitfields.h" #include "llvm/ADT/MapVector.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Twine.h" #include "llvm/ADT/iterator.h" #include "llvm/ADT/iterator_range.h" #include "llvm/IR/CFG.h" #include "llvm/IR/Constant.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/GEPNoWrapFlags.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/OperandTraits.h" #include "llvm/IR/Use.h" #include "llvm/IR/User.h" #include "llvm/Support/AtomicOrdering.h" #include "llvm/Support/ErrorHandling.h" #include <cassert> #include <cstddef> #include <cstdint> #include <iterator> #include <optional> namespace llvm { class APFloat; class APInt; class BasicBlock; class ConstantInt; class DataLayout; class StringRef; class Type; class Value; class UnreachableInst; //===----------------------------------------------------------------------===// // AllocaInst Class //===----------------------------------------------------------------------===// /// an instruction to allocate memory on the stack class AllocaInst : public UnaryInstruction { … }; //===----------------------------------------------------------------------===// // LoadInst Class //===----------------------------------------------------------------------===// /// An instruction for reading from memory. This uses the SubclassData field in /// Value to store whether or not the load is volatile. class LoadInst : public UnaryInstruction { … }; //===----------------------------------------------------------------------===// // StoreInst Class //===----------------------------------------------------------------------===// /// An instruction for storing to memory. class StoreInst : public Instruction { … }; template <> struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> { … }; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(…) //===----------------------------------------------------------------------===// // FenceInst Class //===----------------------------------------------------------------------===// /// An instruction for ordering other memory operations. class FenceInst : public Instruction { … }; //===----------------------------------------------------------------------===// // AtomicCmpXchgInst Class //===----------------------------------------------------------------------===// /// An instruction that atomically checks whether a /// specified value is in a memory location, and, if it is, stores a new value /// there. The value returned by this instruction is a pair containing the /// original value as first element, and an i1 indicating success (true) or /// failure (false) as second element. /// class AtomicCmpXchgInst : public Instruction { … }; template <> struct OperandTraits<AtomicCmpXchgInst> : public FixedNumOperandTraits<AtomicCmpXchgInst, 3> { … }; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(…) //===----------------------------------------------------------------------===// // AtomicRMWInst Class //===----------------------------------------------------------------------===// /// an instruction that atomically reads a memory location, /// combines it with another value, and then stores the result back. Returns /// the old value. /// class AtomicRMWInst : public Instruction { … }; template <> struct OperandTraits<AtomicRMWInst> : public FixedNumOperandTraits<AtomicRMWInst,2> { … }; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(…) //===----------------------------------------------------------------------===// // GetElementPtrInst Class //===----------------------------------------------------------------------===// // checkGEPType - Simple wrapper function to give a better assertion failure // message on bad indexes for a gep instruction. // inline Type *checkGEPType(Type *Ty) { … } /// an instruction for type-safe pointer arithmetic to /// access elements of arrays and structs /// class GetElementPtrInst : public Instruction { … }; template <> struct OperandTraits<GetElementPtrInst> : public VariadicOperandTraits<GetElementPtrInst> { … }; GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr, ArrayRef<Value *> IdxList, AllocInfo AllocInfo, const Twine &NameStr, InsertPosition InsertBefore) : … { … } DEFINE_TRANSPARENT_OPERAND_ACCESSORS(…) //===----------------------------------------------------------------------===// // ICmpInst Class //===----------------------------------------------------------------------===// /// This instruction compares its operands according to the predicate given /// to the constructor. It only operates on integers or pointers. The operands /// must be identical types. /// Represent an integer comparison operator. class ICmpInst: public CmpInst { … }; //===----------------------------------------------------------------------===// // FCmpInst Class //===----------------------------------------------------------------------===// /// This instruction compares its operands according to the predicate given /// to the constructor. It only operates on floating point values or packed /// vectors of floating point values. The operands must be identical types. /// Represents a floating point comparison operator. class FCmpInst: public CmpInst { … }; //===----------------------------------------------------------------------===// /// This class represents a function call, abstracting a target /// machine's calling convention. This class uses low bit of the SubClassData /// field to indicate whether or not this is a tail call. The rest of the bits /// hold the calling convention of the call. /// class CallInst : public CallBase { … }; CallInst::CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr, AllocInfo AllocInfo, InsertPosition InsertBefore) : … { … } //===----------------------------------------------------------------------===// // SelectInst Class //===----------------------------------------------------------------------===// /// This class represents the LLVM 'select' instruction. /// class SelectInst : public Instruction { … }; template <> struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> { … }; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(…) //===----------------------------------------------------------------------===// // VAArgInst Class //===----------------------------------------------------------------------===// /// This class represents the va_arg llvm instruction, which returns /// an argument of the specified type given a va_list and increments that list /// class VAArgInst : public UnaryInstruction { … }; //===----------------------------------------------------------------------===// // ExtractElementInst Class //===----------------------------------------------------------------------===// /// This instruction extracts a single (scalar) /// element from a VectorType value /// class ExtractElementInst : public Instruction { … }; template <> struct OperandTraits<ExtractElementInst> : public FixedNumOperandTraits<ExtractElementInst, 2> { … }; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(…) //===----------------------------------------------------------------------===// // InsertElementInst Class //===----------------------------------------------------------------------===// /// This instruction inserts a single (scalar) /// element into a VectorType value /// class InsertElementInst : public Instruction { … }; template <> struct OperandTraits<InsertElementInst> : public FixedNumOperandTraits<InsertElementInst, 3> { … }; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(…) //===----------------------------------------------------------------------===// // ShuffleVectorInst Class //===----------------------------------------------------------------------===// constexpr int PoisonMaskElem = …; /// This instruction constructs a fixed permutation of two /// input vectors. /// /// For each element of the result vector, the shuffle mask selects an element /// from one of the input vectors to copy to the result. Non-negative elements /// in the mask represent an index into the concatenated pair of input vectors. /// PoisonMaskElem (-1) specifies that the result element is poison. /// /// For scalable vectors, all the elements of the mask must be 0 or -1. This /// requirement may be relaxed in the future. class ShuffleVectorInst : public Instruction { … }; template <> struct OperandTraits<ShuffleVectorInst> : public FixedNumOperandTraits<ShuffleVectorInst, 2> { … }; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(…) //===----------------------------------------------------------------------===// // ExtractValueInst Class //===----------------------------------------------------------------------===// /// This instruction extracts a struct member or array /// element value from an aggregate value. /// class ExtractValueInst : public UnaryInstruction { … }; ExtractValueInst::ExtractValueInst(Value *Agg, ArrayRef<unsigned> Idxs, const Twine &NameStr, InsertPosition InsertBefore) : … { … } //===----------------------------------------------------------------------===// // InsertValueInst Class //===----------------------------------------------------------------------===// /// This instruction inserts a struct field of array element /// value into an aggregate value. /// class InsertValueInst : public Instruction { … }; template <> struct OperandTraits<InsertValueInst> : public FixedNumOperandTraits<InsertValueInst, 2> { … }; InsertValueInst::InsertValueInst(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs, const Twine &NameStr, InsertPosition InsertBefore) : … { … } DEFINE_TRANSPARENT_OPERAND_ACCESSORS(…) //===----------------------------------------------------------------------===// // PHINode Class //===----------------------------------------------------------------------===// // PHINode - The PHINode class is used to represent the magical mystical PHI // node, that can not exist in nature, but can be synthesized in a computer // scientist's overactive imagination. // class PHINode : public Instruction { … }; template <> struct OperandTraits<PHINode> : public HungoffOperandTraits { … }; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(…) //===----------------------------------------------------------------------===// // LandingPadInst Class //===----------------------------------------------------------------------===// //===--------------------------------------------------------------------------- /// The landingpad instruction holds all of the information /// necessary to generate correct exception handling. The landingpad instruction /// cannot be moved from the top of a landing pad block, which itself is /// accessible only from the 'unwind' edge of an invoke. This uses the /// SubclassData field in Value to store whether or not the landingpad is a /// cleanup. /// class LandingPadInst : public Instruction { … }; template <> struct OperandTraits<LandingPadInst> : public HungoffOperandTraits { … }; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(…) //===----------------------------------------------------------------------===// // ReturnInst Class //===----------------------------------------------------------------------===// //===--------------------------------------------------------------------------- /// Return a value (possibly void), from a function. Execution /// does not continue in this function any longer. /// class ReturnInst : public Instruction { … }; template <> struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> { … }; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(…) //===----------------------------------------------------------------------===// // BranchInst Class //===----------------------------------------------------------------------===// //===--------------------------------------------------------------------------- /// Conditional or Unconditional Branch instruction. /// class BranchInst : public Instruction { … }; template <> struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst> { … }; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(…) //===----------------------------------------------------------------------===// // SwitchInst Class //===----------------------------------------------------------------------===// //===--------------------------------------------------------------------------- /// Multiway switch /// class SwitchInst : public Instruction { … }; /// A wrapper class to simplify modification of SwitchInst cases along with /// their prof branch_weights metadata. class SwitchInstProfUpdateWrapper { … }; template <> struct OperandTraits<SwitchInst> : public HungoffOperandTraits { … }; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(…) //===----------------------------------------------------------------------===// // IndirectBrInst Class //===----------------------------------------------------------------------===// //===--------------------------------------------------------------------------- /// Indirect Branch Instruction. /// class IndirectBrInst : public Instruction { … }; template <> struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits { … }; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(…) //===----------------------------------------------------------------------===// // InvokeInst Class //===----------------------------------------------------------------------===// /// Invoke instruction. The SubclassData field is used to hold the /// calling convention of the call. /// class InvokeInst : public CallBase { … }; InvokeInst::InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles, AllocInfo AllocInfo, const Twine &NameStr, InsertPosition InsertBefore) : … { … } //===----------------------------------------------------------------------===// // CallBrInst Class //===----------------------------------------------------------------------===// /// CallBr instruction, tracking function calls that may not return control but /// instead transfer it to a third location. The SubclassData field is used to /// hold the calling convention of the call. /// class CallBrInst : public CallBase { … }; CallBrInst::CallBrInst(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest, ArrayRef<BasicBlock *> IndirectDests, ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles, AllocInfo AllocInfo, const Twine &NameStr, InsertPosition InsertBefore) : … { … } //===----------------------------------------------------------------------===// // ResumeInst Class //===----------------------------------------------------------------------===// //===--------------------------------------------------------------------------- /// Resume the propagation of an exception. /// class ResumeInst : public Instruction { … }; template <> struct OperandTraits<ResumeInst> : public FixedNumOperandTraits<ResumeInst, 1> { … }; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(…) //===----------------------------------------------------------------------===// // CatchSwitchInst Class //===----------------------------------------------------------------------===// class CatchSwitchInst : public Instruction { … }; template <> struct OperandTraits<CatchSwitchInst> : public HungoffOperandTraits { … }; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(…) //===----------------------------------------------------------------------===// // CleanupPadInst Class //===----------------------------------------------------------------------===// class CleanupPadInst : public FuncletPadInst { … }; //===----------------------------------------------------------------------===// // CatchPadInst Class //===----------------------------------------------------------------------===// class CatchPadInst : public FuncletPadInst { … }; //===----------------------------------------------------------------------===// // CatchReturnInst Class //===----------------------------------------------------------------------===// class CatchReturnInst : public Instruction { … }; template <> struct OperandTraits<CatchReturnInst> : public FixedNumOperandTraits<CatchReturnInst, 2> { … }; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(…) //===----------------------------------------------------------------------===// // CleanupReturnInst Class //===----------------------------------------------------------------------===// class CleanupReturnInst : public Instruction { … }; template <> struct OperandTraits<CleanupReturnInst> : public VariadicOperandTraits<CleanupReturnInst> { … }; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(…) //===----------------------------------------------------------------------===// // UnreachableInst Class //===----------------------------------------------------------------------===// //===--------------------------------------------------------------------------- /// This function has undefined behavior. In particular, the /// presence of this instruction indicates some higher level knowledge that the /// end of the block cannot be reached. /// class UnreachableInst : public Instruction { … }; //===----------------------------------------------------------------------===// // TruncInst Class //===----------------------------------------------------------------------===// /// This class represents a truncation of integer types. class TruncInst : public CastInst { … }; //===----------------------------------------------------------------------===// // ZExtInst Class //===----------------------------------------------------------------------===// /// This class represents zero extension of integer types. class ZExtInst : public CastInst { … }; //===----------------------------------------------------------------------===// // SExtInst Class //===----------------------------------------------------------------------===// /// This class represents a sign extension of integer types. class SExtInst : public CastInst { … }; //===----------------------------------------------------------------------===// // FPTruncInst Class //===----------------------------------------------------------------------===// /// This class represents a truncation of floating point types. class FPTruncInst : public CastInst { … }; //===----------------------------------------------------------------------===// // FPExtInst Class //===----------------------------------------------------------------------===// /// This class represents an extension of floating point types. class FPExtInst : public CastInst { … }; //===----------------------------------------------------------------------===// // UIToFPInst Class //===----------------------------------------------------------------------===// /// This class represents a cast unsigned integer to floating point. class UIToFPInst : public CastInst { … }; //===----------------------------------------------------------------------===// // SIToFPInst Class //===----------------------------------------------------------------------===// /// This class represents a cast from signed integer to floating point. class SIToFPInst : public CastInst { … }; //===----------------------------------------------------------------------===// // FPToUIInst Class //===----------------------------------------------------------------------===// /// This class represents a cast from floating point to unsigned integer class FPToUIInst : public CastInst { … }; //===----------------------------------------------------------------------===// // FPToSIInst Class //===----------------------------------------------------------------------===// /// This class represents a cast from floating point to signed integer. class FPToSIInst : public CastInst { … }; //===----------------------------------------------------------------------===// // IntToPtrInst Class //===----------------------------------------------------------------------===// /// This class represents a cast from an integer to a pointer. class IntToPtrInst : public CastInst { … }; //===----------------------------------------------------------------------===// // PtrToIntInst Class //===----------------------------------------------------------------------===// /// This class represents a cast from a pointer to an integer. class PtrToIntInst : public CastInst { … }; //===----------------------------------------------------------------------===// // BitCastInst Class //===----------------------------------------------------------------------===// /// This class represents a no-op cast from one type to another. class BitCastInst : public CastInst { … }; //===----------------------------------------------------------------------===// // AddrSpaceCastInst Class //===----------------------------------------------------------------------===// /// This class represents a conversion between pointers from one address space /// to another. class AddrSpaceCastInst : public CastInst { … }; //===----------------------------------------------------------------------===// // Helper functions //===----------------------------------------------------------------------===// /// A helper function that returns the pointer operand of a load or store /// instruction. Returns nullptr if not load or store. inline const Value *getLoadStorePointerOperand(const Value *V) { … } inline Value *getLoadStorePointerOperand(Value *V) { … } /// A helper function that returns the pointer operand of a load, store /// or GEP instruction. Returns nullptr if not load, store, or GEP. inline const Value *getPointerOperand(const Value *V) { … } inline Value *getPointerOperand(Value *V) { … } /// A helper function that returns the alignment of load or store instruction. inline Align getLoadStoreAlignment(const Value *I) { … } /// A helper function that returns the address space of the pointer operand of /// load or store instruction. inline unsigned getLoadStoreAddressSpace(const Value *I) { … } /// A helper function that returns the type of a load or store instruction. inline Type *getLoadStoreType(const Value *I) { … } /// A helper function that returns an atomic operation's sync scope; returns /// std::nullopt if it is not an atomic operation. inline std::optional<SyncScope::ID> getAtomicSyncScopeID(const Instruction *I) { … } /// A helper function that sets an atomic operation's sync scope. inline void setAtomicSyncScopeID(Instruction *I, SyncScope::ID SSID) { … } //===----------------------------------------------------------------------===// // FreezeInst Class //===----------------------------------------------------------------------===// /// This class represents a freeze function that returns random concrete /// value if an operand is either a poison value or an undef value class FreezeInst : public UnaryInstruction { … }; } // end namespace llvm #endif // LLVM_IR_INSTRUCTIONS_H