1f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===- llvm/Function.h - Class to represent a single function ---*- C++ -*-===// 2f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// 3f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// The LLVM Compiler Infrastructure 4f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// 5f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// This file is distributed under the University of Illinois Open Source 6f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// License. See LICENSE.TXT for details. 7f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// 8f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===----------------------------------------------------------------------===// 9f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// 10f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// This file contains the declaration of the Function class, which represents a 11f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// single function/procedure in LLVM. 12f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// 13f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// A function basically consists of a list of basic blocks, a list of arguments, 14f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// and a symbol table. 15f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// 16f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===----------------------------------------------------------------------===// 17f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 18f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#ifndef LLVM_IR_FUNCTION_H 19f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#define LLVM_IR_FUNCTION_H 20f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 21f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/ADT/DenseSet.h" 22f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/ADT/StringRef.h" 23f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/ADT/Twine.h" 24f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/ADT/ilist_node.h" 25f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/ADT/iterator_range.h" 26f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/IR/Argument.h" 27f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/IR/Attributes.h" 28f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/IR/BasicBlock.h" 29f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/IR/CallingConv.h" 30f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/IR/DerivedTypes.h" 31f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/IR/GlobalObject.h" 32f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/IR/GlobalValue.h" 33f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/IR/OperandTraits.h" 34f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/IR/SymbolTableListTraits.h" 35f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/IR/Value.h" 36f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/Support/Casting.h" 37f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/Support/Compiler.h" 38f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include <cassert> 39f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include <cstddef> 40f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include <cstdint> 41f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include <memory> 42f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include <string> 43f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 44f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotnamespace llvm { 45f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 46f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotnamespace Intrinsic { 47f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotenum ID : unsigned; 48f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot} 49f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 50f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass AssemblyAnnotationWriter; 51f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass Constant; 52f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass DISubprogram; 53f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass LLVMContext; 54f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass Module; 55f3014761c955345d6e05491608e73228d014afbandroid-build-team Robottemplate <typename T> class Optional; 56f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass raw_ostream; 57f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass Type; 58f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass User; 59f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 60f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass Function : public GlobalObject, public ilist_node<Function> { 61f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic: 62f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot using BasicBlockListType = SymbolTableList<BasicBlock>; 63f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 64f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // BasicBlock iterators... 65f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot using iterator = BasicBlockListType::iterator; 66f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot using const_iterator = BasicBlockListType::const_iterator; 67f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 68f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot using arg_iterator = Argument *; 69f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot using const_arg_iterator = const Argument *; 70f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 71f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate: 72f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // Important things that make up a function! 73f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot BasicBlockListType BasicBlocks; ///< The basic blocks 74f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot mutable Argument *Arguments = nullptr; ///< The formal arguments 75f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot size_t NumArgs; 76f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot std::unique_ptr<ValueSymbolTable> 77f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot SymTab; ///< Symbol table of args/instructions 78f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot AttributeList AttributeSets; ///< Parameter attributes 79f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 80f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /* 81f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot * Value::SubclassData 82f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot * 83f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot * bit 0 : HasLazyArguments 84f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot * bit 1 : HasPrefixData 85f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot * bit 2 : HasPrologueData 86f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot * bit 3 : HasPersonalityFn 87f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot * bits 4-13 : CallingConvention 88f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot * bits 14 : HasGC 89f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot * bits 15 : [reserved] 90f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot */ 91f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 92f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Bits from GlobalObject::GlobalObjectSubclassData. 93f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot enum { 94f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Whether this function is materializable. 95f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot IsMaterializableBit = 0, 96f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot }; 97f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 98f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot friend class SymbolTableListTraits<Function>; 99f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 100f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// hasLazyArguments/CheckLazyArguments - The argument list of a function is 101f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// built on demand, so that the list isn't allocated until the first client 102f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// needs it. The hasLazyArguments predicate returns true if the arg list 103f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// hasn't been set up yet. 104f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic: 105f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool hasLazyArguments() const { 106f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return getSubclassDataFromValue() & (1<<0); 107f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 108f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 109f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate: 110f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void CheckLazyArguments() const { 111f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot if (hasLazyArguments()) 112f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot BuildLazyArguments(); 113f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 114f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 115f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void BuildLazyArguments() const; 116f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 117f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void clearArguments(); 118f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 119f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Function ctor - If the (optional) Module argument is specified, the 120f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// function is automatically inserted into the end of the function list for 121f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// the module. 122f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 123f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Function(FunctionType *Ty, LinkageTypes Linkage, 124f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot const Twine &N = "", Module *M = nullptr); 125f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 126f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic: 127f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Function(const Function&) = delete; 128f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void operator=(const Function&) = delete; 129f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot ~Function(); 130f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 131f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // This is here to help easily convert from FunctionT * (Function * or 132f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // MachineFunction *) in BlockFrequencyInfoImpl to Function * by calling 133f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // FunctionT->getFunction(). 134f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot const Function *getFunction() const { return this; } 135f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 136f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot static Function *Create(FunctionType *Ty, LinkageTypes Linkage, 137f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot const Twine &N = "", Module *M = nullptr) { 138f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return new Function(Ty, Linkage, N, M); 139f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 140f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 141f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // Provide fast operand accessors. 142f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 143f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 144f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Returns the FunctionType for me. 145f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot FunctionType *getFunctionType() const { 146f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return cast<FunctionType>(getValueType()); 147f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 148f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 149f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Returns the type of the ret val. 150f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Type *getReturnType() const { return getFunctionType()->getReturnType(); } 151f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 152f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// getContext - Return a reference to the LLVMContext associated with this 153f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// function. 154f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot LLVMContext &getContext() const; 155f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 156f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// isVarArg - Return true if this function takes a variable number of 157f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// arguments. 158f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool isVarArg() const { return getFunctionType()->isVarArg(); } 159f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 160f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool isMaterializable() const { 161f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return getGlobalObjectSubClassData() & (1 << IsMaterializableBit); 162f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 163f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setIsMaterializable(bool V) { 164f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot unsigned Mask = 1 << IsMaterializableBit; 165f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot setGlobalObjectSubClassData((~Mask & getGlobalObjectSubClassData()) | 166f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot (V ? Mask : 0u)); 167f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 168f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 169f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// getIntrinsicID - This method returns the ID number of the specified 170f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// function, or Intrinsic::not_intrinsic if the function is not an 171f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// intrinsic, or if the pointer is null. This value is always defined to be 172f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// zero to allow easy checking for whether a function is intrinsic or not. 173f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// The particular intrinsic functions which correspond to this value are 174f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// defined in llvm/Intrinsics.h. 175f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Intrinsic::ID getIntrinsicID() const LLVM_READONLY { return IntID; } 176f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 177f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// isIntrinsic - Returns true if the function's name starts with "llvm.". 178f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// It's possible for this function to return true while getIntrinsicID() 179f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// returns Intrinsic::not_intrinsic! 180f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool isIntrinsic() const { return HasLLVMReservedName; } 181f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 182f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot static Intrinsic::ID lookupIntrinsicID(StringRef Name); 183f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 184f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// \brief Recalculate the ID for this function if it is an Intrinsic defined 185f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// in llvm/Intrinsics.h. Sets the intrinsic ID to Intrinsic::not_intrinsic 186f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// if the name of this function does not match an intrinsic in that header. 187f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Note, this method does not need to be called directly, as it is called 188f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// from Value::setName() whenever the name of this function changes. 189f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void recalculateIntrinsicID(); 190f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 191f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// getCallingConv()/setCallingConv(CC) - These method get and set the 192f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// calling convention of this function. The enum values for the known 193f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// calling conventions are defined in CallingConv.h. 194f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot CallingConv::ID getCallingConv() const { 195f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return static_cast<CallingConv::ID>((getSubclassDataFromValue() >> 4) & 196f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot CallingConv::MaxID); 197f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 198f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setCallingConv(CallingConv::ID CC) { 199f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot auto ID = static_cast<unsigned>(CC); 200f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention"); 201f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot setValueSubclassData((getSubclassDataFromValue() & 0xc00f) | (ID << 4)); 202f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 203f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 204f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Return the attribute list for this Function. 205f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot AttributeList getAttributes() const { return AttributeSets; } 206f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 207f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Set the attribute list for this Function. 208f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setAttributes(AttributeList Attrs) { AttributeSets = Attrs; } 209f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 210f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Add function attributes to this function. 211f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void addFnAttr(Attribute::AttrKind Kind) { 212f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot addAttribute(AttributeList::FunctionIndex, Kind); 213f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 214f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 215f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Add function attributes to this function. 216f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void addFnAttr(StringRef Kind, StringRef Val = StringRef()) { 217f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot addAttribute(AttributeList::FunctionIndex, 218f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Attribute::get(getContext(), Kind, Val)); 219f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 220f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 221f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void addFnAttr(Attribute Attr) { 222f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot addAttribute(AttributeList::FunctionIndex, Attr); 223f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 224f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 225f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Remove function attributes from this function. 226f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void removeFnAttr(Attribute::AttrKind Kind) { 227f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot removeAttribute(AttributeList::FunctionIndex, Kind); 228f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 229f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 230f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Remove function attribute from this function. 231f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void removeFnAttr(StringRef Kind) { 232f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot setAttributes(getAttributes().removeAttribute( 233f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot getContext(), AttributeList::FunctionIndex, Kind)); 234f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 235f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 236f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// \brief Set the entry count for this function. 237f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 238f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Entry count is the number of times this function was executed based on 239f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// pgo data. \p Imports points to a set of GUIDs that needs to be imported 240f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// by the function for sample PGO, to enable the same inlines as the 241f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// profiled optimized binary. 242f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setEntryCount(uint64_t Count, 243f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot const DenseSet<GlobalValue::GUID> *Imports = nullptr); 244f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 245f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// \brief Get the entry count for this function. 246f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 247f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Entry count is the number of times the function was executed based on 248f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// pgo data. 249f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Optional<uint64_t> getEntryCount() const; 250f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 251f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Returns the set of GUIDs that needs to be imported to the function for 252f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// sample PGO, to enable the same inlines as the profiled optimized binary. 253f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot DenseSet<GlobalValue::GUID> getImportGUIDs() const; 254f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 255f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Set the section prefix for this function. 256f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setSectionPrefix(StringRef Prefix); 257f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 258f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Get the section prefix for this function. 259f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Optional<StringRef> getSectionPrefix() const; 260f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 261f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Return true if the function has the attribute. 262f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool hasFnAttribute(Attribute::AttrKind Kind) const { 263f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return AttributeSets.hasFnAttribute(Kind); 264f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 265f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool hasFnAttribute(StringRef Kind) const { 266f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return AttributeSets.hasFnAttribute(Kind); 267f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 268f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 269f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Return the attribute for the given attribute kind. 270f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Attribute getFnAttribute(Attribute::AttrKind Kind) const { 271f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return getAttribute(AttributeList::FunctionIndex, Kind); 272f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 273f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Attribute getFnAttribute(StringRef Kind) const { 274f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return getAttribute(AttributeList::FunctionIndex, Kind); 275f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 276f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 277f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// \brief Return the stack alignment for the function. 278f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot unsigned getFnStackAlignment() const { 279f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot if (!hasFnAttribute(Attribute::StackAlignment)) 280f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return 0; 281f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return AttributeSets.getStackAlignment(AttributeList::FunctionIndex); 282f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 283f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 284f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm 285f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// to use during code generation. 286f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool hasGC() const { 287f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return getSubclassDataFromValue() & (1<<14); 288f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 289f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot const std::string &getGC() const; 290f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setGC(std::string Str); 291f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void clearGC(); 292f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 293f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief adds the attribute to the list of attributes. 294f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void addAttribute(unsigned i, Attribute::AttrKind Kind); 295f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 296f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief adds the attribute to the list of attributes. 297f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void addAttribute(unsigned i, Attribute Attr); 298f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 299f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief adds the attributes to the list of attributes. 300f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void addAttributes(unsigned i, const AttrBuilder &Attrs); 301f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 302f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief adds the attribute to the list of attributes for the given arg. 303f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind); 304f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 305f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief adds the attribute to the list of attributes for the given arg. 306f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void addParamAttr(unsigned ArgNo, Attribute Attr); 307f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 308f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief adds the attributes to the list of attributes for the given arg. 309f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs); 310f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 311f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief removes the attribute from the list of attributes. 312f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void removeAttribute(unsigned i, Attribute::AttrKind Kind); 313f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 314f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief removes the attribute from the list of attributes. 315f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void removeAttribute(unsigned i, StringRef Kind); 316f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 317f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief removes the attributes from the list of attributes. 318f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void removeAttributes(unsigned i, const AttrBuilder &Attrs); 319f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 320f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief removes the attribute from the list of attributes. 321f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind); 322f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 323f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief removes the attribute from the list of attributes. 324f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void removeParamAttr(unsigned ArgNo, StringRef Kind); 325f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 326f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief removes the attribute from the list of attributes. 327f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void removeParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs); 328f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 329f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief check if an attributes is in the list of attributes. 330f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool hasAttribute(unsigned i, Attribute::AttrKind Kind) const { 331f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return getAttributes().hasAttribute(i, Kind); 332f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 333f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 334f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief check if an attributes is in the list of attributes. 335f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const { 336f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return getAttributes().hasParamAttribute(ArgNo, Kind); 337f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 338f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 339f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const { 340f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return AttributeSets.getAttribute(i, Kind); 341f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 342f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 343f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Attribute getAttribute(unsigned i, StringRef Kind) const { 344f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return AttributeSets.getAttribute(i, Kind); 345f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 346f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 347f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief adds the dereferenceable attribute to the list of attributes. 348f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void addDereferenceableAttr(unsigned i, uint64_t Bytes); 349f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 350f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief adds the dereferenceable attribute to the list of attributes for 351f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// the given arg. 352f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes); 353f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 354f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief adds the dereferenceable_or_null attribute to the list of 355f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// attributes. 356f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes); 357f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 358f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief adds the dereferenceable_or_null attribute to the list of 359f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// attributes for the given arg. 360f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void addDereferenceableOrNullParamAttr(unsigned ArgNo, uint64_t Bytes); 361f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 362f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Extract the alignment for a call or parameter (0=unknown). 363f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot unsigned getParamAlignment(unsigned ArgNo) const { 364f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return AttributeSets.getParamAlignment(ArgNo); 365f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 366f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 367f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Extract the number of dereferenceable bytes for a call or 368f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// parameter (0=unknown). 369f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @param i AttributeList index, referring to a return value or argument. 370f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot uint64_t getDereferenceableBytes(unsigned i) const { 371f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return AttributeSets.getDereferenceableBytes(i); 372f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 373f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 374f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Extract the number of dereferenceable bytes for a parameter. 375f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @param ArgNo Index of an argument, with 0 being the first function arg. 376f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot uint64_t getParamDereferenceableBytes(unsigned ArgNo) const { 377f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return AttributeSets.getParamDereferenceableBytes(ArgNo); 378f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 379f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 380f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Extract the number of dereferenceable_or_null bytes for a call or 381f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// parameter (0=unknown). 382f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @param i AttributeList index, referring to a return value or argument. 383f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot uint64_t getDereferenceableOrNullBytes(unsigned i) const { 384f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return AttributeSets.getDereferenceableOrNullBytes(i); 385f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 386f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 387f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Extract the number of dereferenceable_or_null bytes for a 388f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// parameter. 389f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @param ArgNo AttributeList ArgNo, referring to an argument. 390f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const { 391f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return AttributeSets.getParamDereferenceableOrNullBytes(ArgNo); 392f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 393f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 394f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Determine if the function does not access memory. 395f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool doesNotAccessMemory() const { 396f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return hasFnAttribute(Attribute::ReadNone); 397f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 398f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setDoesNotAccessMemory() { 399f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot addFnAttr(Attribute::ReadNone); 400f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 401f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 402f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Determine if the function does not access or only reads memory. 403f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool onlyReadsMemory() const { 404f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return doesNotAccessMemory() || hasFnAttribute(Attribute::ReadOnly); 405f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 406f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setOnlyReadsMemory() { 407f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot addFnAttr(Attribute::ReadOnly); 408f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 409f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 410f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Determine if the function does not access or only writes memory. 411f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool doesNotReadMemory() const { 412f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return doesNotAccessMemory() || hasFnAttribute(Attribute::WriteOnly); 413f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 414f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setDoesNotReadMemory() { 415f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot addFnAttr(Attribute::WriteOnly); 416f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 417f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 418f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Determine if the call can access memmory only using pointers based 419f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// on its arguments. 420f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool onlyAccessesArgMemory() const { 421f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return hasFnAttribute(Attribute::ArgMemOnly); 422f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 423f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setOnlyAccessesArgMemory() { addFnAttr(Attribute::ArgMemOnly); } 424f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 425f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Determine if the function may only access memory that is 426f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// inaccessible from the IR. 427f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool onlyAccessesInaccessibleMemory() const { 428f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return hasFnAttribute(Attribute::InaccessibleMemOnly); 429f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 430f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setOnlyAccessesInaccessibleMemory() { 431f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot addFnAttr(Attribute::InaccessibleMemOnly); 432f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 433f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 434f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Determine if the function may only access memory that is 435f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// either inaccessible from the IR or pointed to by its arguments. 436f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool onlyAccessesInaccessibleMemOrArgMem() const { 437f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly); 438f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 439f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setOnlyAccessesInaccessibleMemOrArgMem() { 440f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot addFnAttr(Attribute::InaccessibleMemOrArgMemOnly); 441f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 442f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 443f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Determine if the function cannot return. 444f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool doesNotReturn() const { 445f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return hasFnAttribute(Attribute::NoReturn); 446f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 447f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setDoesNotReturn() { 448f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot addFnAttr(Attribute::NoReturn); 449f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 450f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 451f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Determine if the function cannot unwind. 452f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool doesNotThrow() const { 453f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return hasFnAttribute(Attribute::NoUnwind); 454f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 455f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setDoesNotThrow() { 456f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot addFnAttr(Attribute::NoUnwind); 457f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 458f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 459f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Determine if the call cannot be duplicated. 460f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool cannotDuplicate() const { 461f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return hasFnAttribute(Attribute::NoDuplicate); 462f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 463f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setCannotDuplicate() { 464f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot addFnAttr(Attribute::NoDuplicate); 465f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 466f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 467f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Determine if the call is convergent. 468f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool isConvergent() const { 469f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return hasFnAttribute(Attribute::Convergent); 470f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 471f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setConvergent() { 472f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot addFnAttr(Attribute::Convergent); 473f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 474f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setNotConvergent() { 475f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot removeFnAttr(Attribute::Convergent); 476f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 477f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 478f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Determine if the call has sideeffects. 479f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool isSpeculatable() const { 480f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return hasFnAttribute(Attribute::Speculatable); 481f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 482f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setSpeculatable() { 483f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot addFnAttr(Attribute::Speculatable); 484f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 485f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 486f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Determine if the function is known not to recurse, directly or 487f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// indirectly. 488f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool doesNotRecurse() const { 489f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return hasFnAttribute(Attribute::NoRecurse); 490f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 491f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setDoesNotRecurse() { 492f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot addFnAttr(Attribute::NoRecurse); 493f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 494f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 495f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief True if the ABI mandates (or the user requested) that this 496f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// function be in a unwind table. 497f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool hasUWTable() const { 498f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return hasFnAttribute(Attribute::UWTable); 499f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 500f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setHasUWTable() { 501f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot addFnAttr(Attribute::UWTable); 502f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 503f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 504f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief True if this function needs an unwind table. 505f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool needsUnwindTableEntry() const { 506f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return hasUWTable() || !doesNotThrow(); 507f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 508f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 509f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Determine if the function returns a structure through first 510f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// or second pointer argument. 511f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool hasStructRetAttr() const { 512f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return AttributeSets.hasParamAttribute(0, Attribute::StructRet) || 513f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot AttributeSets.hasParamAttribute(1, Attribute::StructRet); 514f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 515f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 516f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// @brief Determine if the parameter or return value is marked with NoAlias 517f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// attribute. 518f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool returnDoesNotAlias() const { 519f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return AttributeSets.hasAttribute(AttributeList::ReturnIndex, 520f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Attribute::NoAlias); 521f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 522f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setReturnDoesNotAlias() { 523f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot addAttribute(AttributeList::ReturnIndex, Attribute::NoAlias); 524f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 525f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 526f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Optimize this function for minimum size (-Oz). 527f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool optForMinSize() const { return hasFnAttribute(Attribute::MinSize); } 528f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 529f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Optimize this function for size (-Os) or minimum size (-Oz). 530f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool optForSize() const { 531f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return hasFnAttribute(Attribute::OptimizeForSize) || optForMinSize(); 532f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 533f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 534f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// copyAttributesFrom - copy all additional attributes (those not needed to 535f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// create a Function) from the Function Src to this one. 536f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void copyAttributesFrom(const Function *Src); 537f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 538f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// deleteBody - This method deletes the body of the function, and converts 539f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// the linkage to external. 540f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 541f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void deleteBody() { 542f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot dropAllReferences(); 543f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot setLinkage(ExternalLinkage); 544f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 545f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 546f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// removeFromParent - This method unlinks 'this' from the containing module, 547f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// but does not delete it. 548f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 549f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void removeFromParent(); 550f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 551f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// eraseFromParent - This method unlinks 'this' from the containing module 552f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// and deletes it. 553f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 554f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void eraseFromParent(); 555f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 556f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Steal arguments from another function. 557f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 558f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Drop this function's arguments and splice in the ones from \c Src. 559f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Requires that this has no function body. 560f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void stealArgumentListFrom(Function &Src); 561f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 562f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Get the underlying elements of the Function... the basic block list is 563f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// empty for external functions. 564f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 565f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; } 566f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot BasicBlockListType &getBasicBlockList() { return BasicBlocks; } 567f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 568f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot static BasicBlockListType Function::*getSublistAccess(BasicBlock*) { 569f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return &Function::BasicBlocks; 570f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 571f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 572f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot const BasicBlock &getEntryBlock() const { return front(); } 573f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot BasicBlock &getEntryBlock() { return front(); } 574f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 575f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot //===--------------------------------------------------------------------===// 576f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // Symbol Table Accessing functions... 577f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 578f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// getSymbolTable() - Return the symbol table if any, otherwise nullptr. 579f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 580f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot inline ValueSymbolTable *getValueSymbolTable() { return SymTab.get(); } 581f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot inline const ValueSymbolTable *getValueSymbolTable() const { 582f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return SymTab.get(); 583f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 584f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 585f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot //===--------------------------------------------------------------------===// 586f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // BasicBlock iterator forwarding functions 587f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // 588f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot iterator begin() { return BasicBlocks.begin(); } 589f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot const_iterator begin() const { return BasicBlocks.begin(); } 590f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot iterator end () { return BasicBlocks.end(); } 591f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot const_iterator end () const { return BasicBlocks.end(); } 592f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 593f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot size_t size() const { return BasicBlocks.size(); } 594f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool empty() const { return BasicBlocks.empty(); } 595f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot const BasicBlock &front() const { return BasicBlocks.front(); } 596f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot BasicBlock &front() { return BasicBlocks.front(); } 597f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot const BasicBlock &back() const { return BasicBlocks.back(); } 598f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot BasicBlock &back() { return BasicBlocks.back(); } 599f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 600f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// @name Function Argument Iteration 601f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// @{ 602f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 603f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot arg_iterator arg_begin() { 604f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot CheckLazyArguments(); 605f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return Arguments; 606f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 607f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot const_arg_iterator arg_begin() const { 608f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot CheckLazyArguments(); 609f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return Arguments; 610f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 611f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 612f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot arg_iterator arg_end() { 613f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot CheckLazyArguments(); 614f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return Arguments + NumArgs; 615f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 616f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot const_arg_iterator arg_end() const { 617f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot CheckLazyArguments(); 618f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return Arguments + NumArgs; 619f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 620f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 621f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot iterator_range<arg_iterator> args() { 622f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return make_range(arg_begin(), arg_end()); 623f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 624f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot iterator_range<const_arg_iterator> args() const { 625f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return make_range(arg_begin(), arg_end()); 626f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 627f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 628f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// @} 629f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 630f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot size_t arg_size() const { return NumArgs; } 631f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool arg_empty() const { return arg_size() == 0; } 632f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 633f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// \brief Check whether this function has a personality function. 634f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool hasPersonalityFn() const { 635f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return getSubclassDataFromValue() & (1<<3); 636f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 637f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 638f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// \brief Get the personality function associated with this function. 639f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Constant *getPersonalityFn() const; 640f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setPersonalityFn(Constant *Fn); 641f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 642f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// \brief Check whether this function has prefix data. 643f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool hasPrefixData() const { 644f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return getSubclassDataFromValue() & (1<<1); 645f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 646f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 647f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// \brief Get the prefix data associated with this function. 648f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Constant *getPrefixData() const; 649f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setPrefixData(Constant *PrefixData); 650f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 651f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// \brief Check whether this function has prologue data. 652f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool hasPrologueData() const { 653f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return getSubclassDataFromValue() & (1<<2); 654f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 655f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 656f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// \brief Get the prologue data associated with this function. 657f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Constant *getPrologueData() const; 658f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setPrologueData(Constant *PrologueData); 659f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 660f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Print the function to an output stream with an optional 661f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// AssemblyAnnotationWriter. 662f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW = nullptr, 663f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool ShouldPreserveUseListOrder = false, 664f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool IsForDebug = false) const; 665f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 666f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// viewCFG - This function is meant for use from the debugger. You can just 667f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// say 'call F->viewCFG()' and a ghostview window should pop up from the 668f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// program, displaying the CFG of the current function with the code for each 669f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// basic block inside. This depends on there being a 'dot' and 'gv' program 670f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// in your path. 671f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 672f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void viewCFG() const; 673f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 674f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// viewCFGOnly - This function is meant for use from the debugger. It works 675f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// just like viewCFG, but it does not include the contents of basic blocks 676f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// into the nodes, just the label. If you are only interested in the CFG 677f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// this can make the graph smaller. 678f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 679f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void viewCFGOnly() const; 680f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 681f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Methods for support type inquiry through isa, cast, and dyn_cast: 682f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot static bool classof(const Value *V) { 683f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return V->getValueID() == Value::FunctionVal; 684f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 685f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 686f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// dropAllReferences() - This method causes all the subinstructions to "let 687f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// go" of all references that they are maintaining. This allows one to 688f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 'delete' a whole module at a time, even though there may be circular 689f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// references... first all references are dropped, and all use counts go to 690f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// zero. Then everything is deleted for real. Note that no operations are 691f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// valid on an object that has "dropped all references", except operator 692f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// delete. 693f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 694f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Since no other object in the module can have references into the body of a 695f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// function, dropping all references deletes the entire body of the function, 696f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// including any contained basic blocks. 697f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 698f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void dropAllReferences(); 699f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 700f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// hasAddressTaken - returns true if there are any uses of this function 701f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// other than direct calls or invokes to it, or blockaddress expressions. 702f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Optionally passes back an offending user for diagnostic purposes. 703f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 704f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool hasAddressTaken(const User** = nullptr) const; 705f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 706f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// isDefTriviallyDead - Return true if it is trivially safe to remove 707f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// this function definition from the module (because it isn't externally 708f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// visible, does not have its address taken, and has no callers). To make 709f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// this more accurate, call removeDeadConstantUsers first. 710f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool isDefTriviallyDead() const; 711f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 712f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// callsFunctionThatReturnsTwice - Return true if the function has a call to 713f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// setjmp or other function that gcc recognizes as "returning twice". 714f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool callsFunctionThatReturnsTwice() const; 715f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 716f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// \brief Set the attached subprogram. 717f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 718f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Calls \a setMetadata() with \a LLVMContext::MD_dbg. 719f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setSubprogram(DISubprogram *SP); 720f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 721f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// \brief Get the attached subprogram. 722f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 723f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Calls \a getMetadata() with \a LLVMContext::MD_dbg and casts the result 724f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// to \a DISubprogram. 725f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot DISubprogram *getSubprogram() const; 726f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 727f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Returns true if we should emit debug info for profiling. 728f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool isDebugInfoForProfiling() const; 729f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 730f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate: 731f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void allocHungoffUselist(); 732f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot template<int Idx> void setHungoffOperand(Constant *C); 733f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 734f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Shadow Value::setValueSubclassData with a private forwarding method so 735f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// that subclasses cannot accidentally use it. 736f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setValueSubclassData(unsigned short D) { 737f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Value::setValueSubclassData(D); 738f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 739f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setValueSubclassDataBit(unsigned Bit, bool On); 740f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}; 741f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 742f3014761c955345d6e05491608e73228d014afbandroid-build-team Robottemplate <> 743f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct OperandTraits<Function> : public HungoffOperandTraits<3> {}; 744f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 745f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotDEFINE_TRANSPARENT_OPERAND_ACCESSORS(Function, Value) 746f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 747f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot} // end namespace llvm 748f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 749f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#endif // LLVM_IR_FUNCTION_H 750