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