LCOV - code coverage report
Current view: top level - lib/IR - Module.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 188 190 98.9 %
Date: 2018-06-17 00:07:59 Functions: 52 53 98.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- Module.cpp - Implement the Module class ----------------------------===//
       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 implements the Module class for the IR library.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "llvm/IR/Module.h"
      15             : #include "SymbolTableListTraitsImpl.h"
      16             : #include "llvm/ADT/SmallPtrSet.h"
      17             : #include "llvm/ADT/SmallString.h"
      18             : #include "llvm/ADT/SmallVector.h"
      19             : #include "llvm/ADT/StringMap.h"
      20             : #include "llvm/ADT/StringRef.h"
      21             : #include "llvm/ADT/Twine.h"
      22             : #include "llvm/IR/Attributes.h"
      23             : #include "llvm/IR/Comdat.h"
      24             : #include "llvm/IR/Constants.h"
      25             : #include "llvm/IR/DataLayout.h"
      26             : #include "llvm/IR/DebugInfoMetadata.h"
      27             : #include "llvm/IR/DerivedTypes.h"
      28             : #include "llvm/IR/Function.h"
      29             : #include "llvm/IR/GVMaterializer.h"
      30             : #include "llvm/IR/GlobalAlias.h"
      31             : #include "llvm/IR/GlobalIFunc.h"
      32             : #include "llvm/IR/GlobalValue.h"
      33             : #include "llvm/IR/GlobalVariable.h"
      34             : #include "llvm/IR/LLVMContext.h"
      35             : #include "llvm/IR/Metadata.h"
      36             : #include "llvm/IR/SymbolTableListTraits.h"
      37             : #include "llvm/IR/Type.h"
      38             : #include "llvm/IR/TypeFinder.h"
      39             : #include "llvm/IR/Value.h"
      40             : #include "llvm/IR/ValueSymbolTable.h"
      41             : #include "llvm/Pass.h"
      42             : #include "llvm/Support/Casting.h"
      43             : #include "llvm/Support/CodeGen.h"
      44             : #include "llvm/Support/Error.h"
      45             : #include "llvm/Support/MemoryBuffer.h"
      46             : #include "llvm/Support/Path.h"
      47             : #include "llvm/Support/RandomNumberGenerator.h"
      48             : #include <algorithm>
      49             : #include <cassert>
      50             : #include <cstdint>
      51             : #include <memory>
      52             : #include <utility>
      53             : #include <vector>
      54             : 
      55             : using namespace llvm;
      56             : 
      57             : //===----------------------------------------------------------------------===//
      58             : // Methods to implement the globals and functions lists.
      59             : //
      60             : 
      61             : // Explicit instantiations of SymbolTableListTraits since some of the methods
      62             : // are not in the public header file.
      63             : template class llvm::SymbolTableListTraits<Function>;
      64             : template class llvm::SymbolTableListTraits<GlobalVariable>;
      65             : template class llvm::SymbolTableListTraits<GlobalAlias>;
      66             : template class llvm::SymbolTableListTraits<GlobalIFunc>;
      67             : 
      68             : //===----------------------------------------------------------------------===//
      69             : // Primitive Module methods.
      70             : //
      71             : 
      72       48917 : Module::Module(StringRef MID, LLVMContext &C)
      73      146751 :     : Context(C), Materializer(), ModuleID(MID), SourceFileName(MID), DL("") {
      74       97834 :   ValSymTab = new ValueSymbolTable();
      75       97834 :   NamedMDSymTab = new StringMap<NamedMDNode *>();
      76       48917 :   Context.addModule(this);
      77       48917 : }
      78             : 
      79      183428 : Module::~Module() {
      80       45857 :   Context.removeModule(this);
      81       45857 :   dropAllReferences();
      82       45857 :   GlobalList.clear();
      83       45857 :   FunctionList.clear();
      84       45857 :   AliasList.clear();
      85       45857 :   IFuncList.clear();
      86             :   NamedMDList.clear();
      87       45857 :   delete ValSymTab;
      88       45857 :   delete static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab);
      89       45857 : }
      90             : 
      91           2 : std::unique_ptr<RandomNumberGenerator> Module::createRNG(const Pass* P) const {
      92           2 :   SmallString<32> Salt(P->getPassName());
      93             : 
      94             :   // This RNG is guaranteed to produce the same random stream only
      95             :   // when the Module ID and thus the input filename is the same. This
      96             :   // might be problematic if the input filename extension changes
      97             :   // (e.g. from .c to .bc or .ll).
      98             :   //
      99             :   // We could store this salt in NamedMetadata, but this would make
     100             :   // the parameter non-const. This would unfortunately make this
     101             :   // interface unusable by any Machine passes, since they only have a
     102             :   // const reference to their IR Module. Alternatively we can always
     103             :   // store salt metadata from the Module constructor.
     104           4 :   Salt += sys::path::filename(getModuleIdentifier());
     105             : 
     106           6 :   return std::unique_ptr<RandomNumberGenerator>(new RandomNumberGenerator(Salt));
     107             : }
     108             : 
     109             : /// getNamedValue - Return the first global value in the module with
     110             : /// the specified name, of arbitrary type.  This method returns null
     111             : /// if a global with the specified name is not found.
     112     7551441 : GlobalValue *Module::getNamedValue(StringRef Name) const {
     113    15102885 :   return cast_or_null<GlobalValue>(getValueSymbolTable().lookup(Name));
     114             : }
     115             : 
     116             : /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
     117             : /// This ID is uniqued across modules in the current LLVMContext.
     118      120014 : unsigned Module::getMDKindID(StringRef Name) const {
     119      120014 :   return Context.getMDKindID(Name);
     120             : }
     121             : 
     122             : /// getMDKindNames - Populate client supplied SmallVector with the name for
     123             : /// custom metadata IDs registered in this LLVMContext.   ID #0 is not used,
     124             : /// so it is filled in as an empty string.
     125        4481 : void Module::getMDKindNames(SmallVectorImpl<StringRef> &Result) const {
     126        4481 :   return Context.getMDKindNames(Result);
     127             : }
     128             : 
     129        4481 : void Module::getOperandBundleTags(SmallVectorImpl<StringRef> &Result) const {
     130        4481 :   return Context.getOperandBundleTags(Result);
     131             : }
     132             : 
     133             : //===----------------------------------------------------------------------===//
     134             : // Methods for easy access to the functions in the module.
     135             : //
     136             : 
     137             : // getOrInsertFunction - Look up the specified function in the module symbol
     138             : // table.  If it does not exist, add a prototype for the function and return
     139             : // it.  This is nice because it allows most passes to get away with not handling
     140             : // the symbol table directly for this common task.
     141             : //
     142      746537 : Constant *Module::getOrInsertFunction(StringRef Name, FunctionType *Ty,
     143             :                                       AttributeList AttributeList) {
     144             :   // See if we have a definition for the specified function already.
     145      746537 :   GlobalValue *F = getNamedValue(Name);
     146      746537 :   if (!F) {
     147             :     // Nope, add it
     148       72813 :     Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name);
     149       72813 :     if (!New->isIntrinsic())       // Intrinsics get attrs set on construction
     150             :       New->setAttributes(AttributeList);
     151       72813 :     FunctionList.push_back(New);
     152       72813 :     return New;                    // Return the new prototype.
     153             :   }
     154             : 
     155             :   // If the function exists but has the wrong type, return a bitcast to the
     156             :   // right type.
     157      673724 :   if (F->getType() != PointerType::getUnqual(Ty))
     158           9 :     return ConstantExpr::getBitCast(F, PointerType::getUnqual(Ty));
     159             : 
     160             :   // Otherwise, we just found the existing function or a prototype.
     161             :   return F;
     162             : }
     163             : 
     164      699511 : Constant *Module::getOrInsertFunction(StringRef Name,
     165             :                                       FunctionType *Ty) {
     166      699511 :   return getOrInsertFunction(Name, Ty, AttributeList());
     167             : }
     168             : 
     169             : // getFunction - Look up the specified function in the module symbol table.
     170             : // If it does not exist, return null.
     171             : //
     172     2888533 : Function *Module::getFunction(StringRef Name) const {
     173     5777067 :   return dyn_cast_or_null<Function>(getNamedValue(Name));
     174             : }
     175             : 
     176             : //===----------------------------------------------------------------------===//
     177             : // Methods for easy access to the global variables in the module.
     178             : //
     179             : 
     180             : /// getGlobalVariable - Look up the specified global variable in the module
     181             : /// symbol table.  If it does not exist, return null.  The type argument
     182             : /// should be the underlying type of the global, i.e., it should not have
     183             : /// the top-level PointerType, which represents the address of the global.
     184             : /// If AllowLocal is set to true, this function will return types that
     185             : /// have an local. By default, these types are not returned.
     186             : ///
     187       54402 : GlobalVariable *Module::getGlobalVariable(StringRef Name,
     188             :                                           bool AllowLocal) const {
     189             :   if (GlobalVariable *Result =
     190       54402 :       dyn_cast_or_null<GlobalVariable>(getNamedValue(Name)))
     191       10953 :     if (AllowLocal || !Result->hasLocalLinkage())
     192             :       return Result;
     193             :   return nullptr;
     194             : }
     195             : 
     196             : /// getOrInsertGlobal - Look up the specified global in the module symbol table.
     197             : ///   1. If it does not exist, add a declaration of the global and return it.
     198             : ///   2. Else, the global exists but has the wrong type: return the function
     199             : ///      with a constantexpr cast to the right type.
     200             : ///   3. Finally, if the existing global is the correct declaration, return the
     201             : ///      existing global.
     202        2758 : Constant *Module::getOrInsertGlobal(StringRef Name, Type *Ty) {
     203             :   // See if we have a definition for the specified global already.
     204        2758 :   GlobalVariable *GV = dyn_cast_or_null<GlobalVariable>(getNamedValue(Name));
     205             :   if (!GV) {
     206             :     // Nope, add it
     207             :     GlobalVariable *New =
     208             :       new GlobalVariable(*this, Ty, false, GlobalVariable::ExternalLinkage,
     209        1400 :                          nullptr, Name);
     210        1400 :      return New;                    // Return the new declaration.
     211             :   }
     212             : 
     213             :   // If the variable exists but has the wrong type, return a bitcast to the
     214             :   // right type.
     215             :   Type *GVTy = GV->getType();
     216        1358 :   PointerType *PTy = PointerType::get(Ty, GVTy->getPointerAddressSpace());
     217        1358 :   if (GVTy != PTy)
     218          76 :     return ConstantExpr::getBitCast(GV, PTy);
     219             : 
     220             :   // Otherwise, we just found the existing function or a prototype.
     221             :   return GV;
     222             : }
     223             : 
     224             : //===----------------------------------------------------------------------===//
     225             : // Methods for easy access to the global variables in the module.
     226             : //
     227             : 
     228             : // getNamedAlias - Look up the specified global in the module symbol table.
     229             : // If it does not exist, return null.
     230             : //
     231          19 : GlobalAlias *Module::getNamedAlias(StringRef Name) const {
     232          38 :   return dyn_cast_or_null<GlobalAlias>(getNamedValue(Name));
     233             : }
     234             : 
     235           0 : GlobalIFunc *Module::getNamedIFunc(StringRef Name) const {
     236           0 :   return dyn_cast_or_null<GlobalIFunc>(getNamedValue(Name));
     237             : }
     238             : 
     239             : /// getNamedMetadata - Return the first NamedMDNode in the module with the
     240             : /// specified name. This method returns null if a NamedMDNode with the
     241             : /// specified name is not found.
     242     2700481 : NamedMDNode *Module::getNamedMetadata(const Twine &Name) const {
     243             :   SmallString<256> NameData;
     244     2700481 :   StringRef NameRef = Name.toStringRef(NameData);
     245     5400964 :   return static_cast<StringMap<NamedMDNode*> *>(NamedMDSymTab)->lookup(NameRef);
     246             : }
     247             : 
     248             : /// getOrInsertNamedMetadata - Return the first named MDNode in the module
     249             : /// with the specified name. This method returns a new NamedMDNode if a
     250             : /// NamedMDNode with the specified name is not found.
     251       48371 : NamedMDNode *Module::getOrInsertNamedMetadata(StringRef Name) {
     252             :   NamedMDNode *&NMD =
     253       48371 :     (*static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab))[Name];
     254       48371 :   if (!NMD) {
     255       36261 :     NMD = new NamedMDNode(Name);
     256             :     NMD->setParent(this);
     257             :     NamedMDList.push_back(NMD);
     258             :   }
     259       48371 :   return NMD;
     260             : }
     261             : 
     262             : /// eraseNamedMetadata - Remove the given NamedMDNode from this module and
     263             : /// delete it.
     264        1358 : void Module::eraseNamedMetadata(NamedMDNode *NMD) {
     265        1358 :   static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab)->erase(NMD->getName());
     266        1358 :   NamedMDList.erase(NMD->getIterator());
     267        1358 : }
     268             : 
     269     5860372 : bool Module::isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB) {
     270             :   if (ConstantInt *Behavior = mdconst::dyn_extract_or_null<ConstantInt>(MD)) {
     271             :     uint64_t Val = Behavior->getLimitedValue();
     272     5860368 :     if (Val >= ModFlagBehaviorFirstVal && Val <= ModFlagBehaviorLastVal) {
     273     5860366 :       MFB = static_cast<ModFlagBehavior>(Val);
     274     5860366 :       return true;
     275             :     }
     276             :   }
     277             :   return false;
     278             : }
     279             : 
     280             : /// getModuleFlagsMetadata - Returns the module flags in the provided vector.
     281     2277315 : void Module::
     282             : getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const {
     283     2277315 :   const NamedMDNode *ModFlags = getModuleFlagsMetadata();
     284     2277316 :   if (!ModFlags) return;
     285             : 
     286     7210200 :   for (const MDNode *Flag : ModFlags->operands()) {
     287             :     ModFlagBehavior MFB;
     288    11660999 :     if (Flag->getNumOperands() >= 3 &&
     289    11660999 :         isValidModFlagBehavior(Flag->getOperand(0), MFB) &&
     290             :         dyn_cast_or_null<MDString>(Flag->getOperand(1))) {
     291             :       // Check the operands of the MDNode before accessing the operands.
     292             :       // The verifier will actually catch these failures.
     293             :       MDString *Key = cast<MDString>(Flag->getOperand(1));
     294             :       Metadata *Val = Flag->getOperand(2);
     295    11660988 :       Flags.push_back(ModuleFlagEntry(MFB, Key, Val));
     296             :     }
     297             :   }
     298             : }
     299             : 
     300             : /// Return the corresponding value if Key appears in module flags, otherwise
     301             : /// return null.
     302     2255277 : Metadata *Module::getModuleFlag(StringRef Key) const {
     303             :   SmallVector<Module::ModuleFlagEntry, 8> ModuleFlags;
     304     2255277 :   getModuleFlagsMetadata(ModuleFlags);
     305    13865604 :   for (const ModuleFlagEntry &MFE : ModuleFlags) {
     306     5812712 :     if (Key == MFE.Key->getString())
     307        7549 :       return MFE.Val;
     308             :   }
     309             :   return nullptr;
     310             : }
     311             : 
     312             : /// getModuleFlagsMetadata - Returns the NamedMDNode in the module that
     313             : /// represents module-level flags. This method returns null if there are no
     314             : /// module-level flags.
     315     2409628 : NamedMDNode *Module::getModuleFlagsMetadata() const {
     316     2409628 :   return getNamedMetadata("llvm.module.flags");
     317             : }
     318             : 
     319             : /// getOrInsertModuleFlagsMetadata - Returns the NamedMDNode in the module that
     320             : /// represents module-level flags. If module-level flags aren't found, it
     321             : /// creates the named metadata that contains them.
     322       22656 : NamedMDNode *Module::getOrInsertModuleFlagsMetadata() {
     323       22656 :   return getOrInsertNamedMetadata("llvm.module.flags");
     324             : }
     325             : 
     326             : /// addModuleFlag - Add a module-level flag to the module-level flags
     327             : /// metadata. It will create the module-level flags named metadata if it doesn't
     328             : /// already exist.
     329       22506 : void Module::addModuleFlag(ModFlagBehavior Behavior, StringRef Key,
     330             :                            Metadata *Val) {
     331       22506 :   Type *Int32Ty = Type::getInt32Ty(Context);
     332             :   Metadata *Ops[3] = {
     333       22506 :       ConstantAsMetadata::get(ConstantInt::get(Int32Ty, Behavior)),
     334       22506 :       MDString::get(Context, Key), Val};
     335       45012 :   getOrInsertModuleFlagsMetadata()->addOperand(MDNode::get(Context, Ops));
     336       22506 : }
     337       21637 : void Module::addModuleFlag(ModFlagBehavior Behavior, StringRef Key,
     338             :                            Constant *Val) {
     339       21637 :   addModuleFlag(Behavior, Key, ConstantAsMetadata::get(Val));
     340       21637 : }
     341       21637 : void Module::addModuleFlag(ModFlagBehavior Behavior, StringRef Key,
     342             :                            uint32_t Val) {
     343       21637 :   Type *Int32Ty = Type::getInt32Ty(Context);
     344       21637 :   addModuleFlag(Behavior, Key, ConstantInt::get(Int32Ty, Val));
     345       21637 : }
     346           1 : void Module::addModuleFlag(MDNode *Node) {
     347             :   assert(Node->getNumOperands() == 3 &&
     348             :          "Invalid number of operands for module flag!");
     349             :   assert(mdconst::hasa<ConstantInt>(Node->getOperand(0)) &&
     350             :          isa<MDString>(Node->getOperand(1)) &&
     351             :          "Invalid operand types for module flag!");
     352           1 :   getOrInsertModuleFlagsMetadata()->addOperand(Node);
     353           1 : }
     354             : 
     355        9483 : void Module::setDataLayout(StringRef Desc) {
     356        9483 :   DL.reset(Desc);
     357        9456 : }
     358             : 
     359       43314 : void Module::setDataLayout(const DataLayout &Other) { DL = Other; }
     360             : 
     361   117436407 : const DataLayout &Module::getDataLayout() const { return DL; }
     362             : 
     363        6639 : DICompileUnit *Module::debug_compile_units_iterator::operator*() const {
     364        6639 :   return cast<DICompileUnit>(CUs->getOperand(Idx));
     365             : }
     366       10026 : DICompileUnit *Module::debug_compile_units_iterator::operator->() const {
     367       10026 :   return cast<DICompileUnit>(CUs->getOperand(Idx));
     368             : }
     369             : 
     370      105387 : void Module::debug_compile_units_iterator::SkipNoDebugCUs() {
     371      115567 :   while (CUs && (Idx < CUs->getNumOperands()) &&
     372       10026 :          ((*this)->getEmissionKind() == DICompileUnit::NoDebug))
     373          77 :     ++Idx;
     374      105387 : }
     375             : 
     376             : //===----------------------------------------------------------------------===//
     377             : // Methods to control the materialization of GlobalValues in the Module.
     378             : //
     379        3321 : void Module::setMaterializer(GVMaterializer *GVM) {
     380             :   assert(!Materializer &&
     381             :          "Module already has a GVMaterializer.  Call materializeAll"
     382             :          " to clear it out before setting another one.");
     383             :   Materializer.reset(GVM);
     384        3321 : }
     385             : 
     386      180201 : Error Module::materialize(GlobalValue *GV) {
     387      180201 :   if (!Materializer)
     388             :     return Error::success();
     389             : 
     390        1033 :   return Materializer->materialize(GV);
     391             : }
     392             : 
     393        2737 : Error Module::materializeAll() {
     394        2737 :   if (!Materializer)
     395             :     return Error::success();
     396             :   std::unique_ptr<GVMaterializer> M = std::move(Materializer);
     397        2551 :   return M->materializeModule();
     398             : }
     399             : 
     400        1087 : Error Module::materializeMetadata() {
     401        1087 :   if (!Materializer)
     402             :     return Error::success();
     403         652 :   return Materializer->materializeMetadata();
     404             : }
     405             : 
     406             : //===----------------------------------------------------------------------===//
     407             : // Other module related stuff.
     408             : //
     409             : 
     410        1057 : std::vector<StructType *> Module::getIdentifiedStructTypes() const {
     411             :   // If we have a materializer, it is possible that some unread function
     412             :   // uses a type that is currently not visible to a TypeFinder, so ask
     413             :   // the materializer which types it created.
     414        1057 :   if (Materializer)
     415         659 :     return Materializer->getIdentifiedStructTypes();
     416             : 
     417             :   std::vector<StructType *> Ret;
     418         796 :   TypeFinder SrcStructTypes;
     419         398 :   SrcStructTypes.run(*this, true);
     420             :   Ret.assign(SrcStructTypes.begin(), SrcStructTypes.end());
     421             :   return Ret;
     422             : }
     423             : 
     424             : // dropAllReferences() - This function causes all the subelements to "let go"
     425             : // of all references that they are maintaining.  This allows one to 'delete' a
     426             : // whole module at a time, even though there may be circular references... first
     427             : // all references are dropped, and all use counts go to zero.  Then everything
     428             : // is deleted for real.  Note that no operations are valid on an object that
     429             : // has "dropped all references", except operator delete.
     430             : //
     431       45857 : void Module::dropAllReferences() {
     432      538781 :   for (Function &F : *this)
     433      492924 :     F.dropAllReferences();
     434             : 
     435      169119 :   for (GlobalVariable &GV : globals())
     436      123262 :     GV.dropAllReferences();
     437             : 
     438       48256 :   for (GlobalAlias &GA : aliases())
     439        2399 :     GA.dropAllReferences();
     440             : 
     441       45965 :   for (GlobalIFunc &GIF : ifuncs())
     442         108 :     GIF.dropAllReferences();
     443       45857 : }
     444             : 
     445         937 : unsigned Module::getNumberRegisterParameters() const {
     446             :   auto *Val =
     447        1493 :       cast_or_null<ConstantAsMetadata>(getModuleFlag("NumRegisterParameters"));
     448             :   if (!Val)
     449             :     return 0;
     450         381 :   return cast<ConstantInt>(Val->getValue())->getZExtValue();
     451             : }
     452             : 
     453       22419 : unsigned Module::getDwarfVersion() const {
     454       42185 :   auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("Dwarf Version"));
     455             :   if (!Val)
     456             :     return 0;
     457        2653 :   return cast<ConstantInt>(Val->getValue())->getZExtValue();
     458             : }
     459             : 
     460       24692 : unsigned Module::getCodeViewFlag() const {
     461       49032 :   auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("CodeView"));
     462             :   if (!Val)
     463             :     return 0;
     464         352 :   return cast<ConstantInt>(Val->getValue())->getZExtValue();
     465             : }
     466             : 
     467         294 : unsigned Module::getInstructionCount() {
     468             :   unsigned NumInstrs = 0;
     469        1348 :   for (Function &F : FunctionList)
     470        1054 :     NumInstrs += F.getInstructionCount();
     471         294 :   return NumInstrs;
     472             : }
     473             : 
     474       85634 : Comdat *Module::getOrInsertComdat(StringRef Name) {
     475      171268 :   auto &Entry = *ComdatSymTab.insert(std::make_pair(Name, Comdat())).first;
     476       85634 :   Entry.second.Name = &Entry;
     477       85634 :   return &Entry.second;
     478             : }
     479             : 
     480       74118 : PICLevel::Level Module::getPICLevel() const {
     481      147370 :   auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("PIC Level"));
     482             : 
     483             :   if (!Val)
     484             :     return PICLevel::NotPIC;
     485             : 
     486             :   return static_cast<PICLevel::Level>(
     487         866 :       cast<ConstantInt>(Val->getValue())->getZExtValue());
     488             : }
     489             : 
     490         283 : void Module::setPICLevel(PICLevel::Level PL) {
     491         283 :   addModuleFlag(ModFlagBehavior::Max, "PIC Level", PL);
     492         283 : }
     493             : 
     494       71941 : PIELevel::Level Module::getPIELevel() const {
     495      143610 :   auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("PIE Level"));
     496             : 
     497             :   if (!Val)
     498             :     return PIELevel::Default;
     499             : 
     500             :   return static_cast<PIELevel::Level>(
     501         272 :       cast<ConstantInt>(Val->getValue())->getZExtValue());
     502             : }
     503             : 
     504          17 : void Module::setPIELevel(PIELevel::Level PL) {
     505          17 :   addModuleFlag(ModFlagBehavior::Max, "PIE Level", PL);
     506          17 : }
     507             : 
     508         147 : void Module::setProfileSummary(Metadata *M) {
     509         147 :   addModuleFlag(ModFlagBehavior::Error, "ProfileSummary", M);
     510         147 : }
     511             : 
     512     1523908 : Metadata *Module::getProfileSummary() {
     513     1523908 :   return getModuleFlag("ProfileSummary");
     514             : }
     515             : 
     516         196 : void Module::setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB) {
     517             :   OwnedMemoryBuffer = std::move(MB);
     518         196 : }
     519             : 
     520      133416 : bool Module::getRtLibUseGOT() const {
     521      266815 :   auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("RtLibUseGOT"));
     522          17 :   return Val && (cast<ConstantInt>(Val->getValue())->getZExtValue() > 0);
     523             : }
     524             : 
     525           5 : void Module::setRtLibUseGOT() {
     526           5 :   addModuleFlag(ModFlagBehavior::Max, "RtLibUseGOT", 1);
     527           5 : }
     528             : 
     529       13763 : GlobalVariable *llvm::collectUsedGlobalVariables(
     530             :     const Module &M, SmallPtrSetImpl<GlobalValue *> &Set, bool CompilerUsed) {
     531       13763 :   const char *Name = CompilerUsed ? "llvm.compiler.used" : "llvm.used";
     532             :   GlobalVariable *GV = M.getGlobalVariable(Name);
     533       13931 :   if (!GV || !GV->hasInitializer())
     534             :     return GV;
     535             : 
     536             :   const ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
     537        1056 :   for (Value *Op : Init->operands()) {
     538             :     GlobalValue *G = cast<GlobalValue>(Op->stripPointerCastsNoFollowAliases());
     539         360 :     Set.insert(G);
     540             :   }
     541             :   return GV;
     542             : }

Generated by: LCOV version 1.13