LCOV - code coverage report
Current view: top level - lib/IR - Module.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 201 203 99.0 %
Date: 2017-09-14 15:23:50 Functions: 49 50 98.0 %
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       37912 : Module::Module(StringRef MID, LLVMContext &C)
      73      530768 :     : Context(C), Materializer(), ModuleID(MID), SourceFileName(MID), DL("") {
      74       75823 :   ValSymTab = new ValueSymbolTable();
      75       75824 :   NamedMDSymTab = new StringMap<NamedMDNode *>();
      76       37912 :   Context.addModule(this);
      77       37912 : }
      78             : 
      79      482014 : Module::~Module() {
      80       37078 :   Context.removeModule(this);
      81       37078 :   dropAllReferences();
      82       74154 :   GlobalList.clear();
      83       74154 :   FunctionList.clear();
      84       74155 :   AliasList.clear();
      85       74156 :   IFuncList.clear();
      86       74156 :   NamedMDList.clear();
      87       37078 :   delete ValSymTab;
      88       37078 :   delete static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab);
      89       37078 : }
      90             : 
      91           2 : std::unique_ptr<RandomNumberGenerator> Module::createRNG(const Pass* P) const {
      92           6 :   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           6 :   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     5267748 : GlobalValue *Module::getNamedValue(StringRef Name) const {
     113    15803244 :   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       96361 : unsigned Module::getMDKindID(StringRef Name) const {
     119       96361 :   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        3629 : void Module::getMDKindNames(SmallVectorImpl<StringRef> &Result) const {
     126        3629 :   return Context.getMDKindNames(Result);
     127             : }
     128             : 
     129        3629 : void Module::getOperandBundleTags(SmallVectorImpl<StringRef> &Result) const {
     130        3629 :   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      558468 : Constant *Module::getOrInsertFunction(StringRef Name, FunctionType *Ty,
     143             :                                       AttributeList AttributeList) {
     144             :   // See if we have a definition for the specified function already.
     145      558468 :   GlobalValue *F = getNamedValue(Name);
     146      558468 :   if (!F) {
     147             :     // Nope, add it
     148      107046 :     Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name);
     149       53523 :     if (!New->isIntrinsic())       // Intrinsics get attrs set on construction
     150             :       New->setAttributes(AttributeList);
     151      107046 :     FunctionList.push_back(New);
     152       53523 :     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     1009890 :   if (F->getType() != PointerType::getUnqual(Ty))
     158           5 :     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      515484 : Constant *Module::getOrInsertFunction(StringRef Name,
     165             :                                       FunctionType *Ty) {
     166      515484 :   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     2608804 : Function *Module::getFunction(StringRef Name) const {
     173     5217608 :   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       40165 : GlobalVariable *Module::getGlobalVariable(StringRef Name,
     188             :                                           bool AllowLocal) const {
     189             :   if (GlobalVariable *Result =
     190       49924 :       dyn_cast_or_null<GlobalVariable>(getNamedValue(Name)))
     191        9759 :     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        2243 : Constant *Module::getOrInsertGlobal(StringRef Name, Type *Ty) {
     203             :   // See if we have a definition for the specified global already.
     204        3476 :   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        2020 :                          nullptr, Name);
     210        1010 :      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        2466 :   Type *GVTy = GV->getType();
     216        1233 :   PointerType *PTy = PointerType::get(Ty, GVTy->getPointerAddressSpace());
     217        1233 :   if (GVTy != PTy)
     218          74 :     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           5 : GlobalAlias *Module::getNamedAlias(StringRef Name) const {
     232          10 :   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     1786189 : NamedMDNode *Module::getNamedMetadata(const Twine &Name) const {
     243     3572379 :   SmallString<256> NameData;
     244     1786189 :   StringRef NameRef = Name.toStringRef(NameData);
     245     3572380 :   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       24623 : NamedMDNode *Module::getOrInsertNamedMetadata(StringRef Name) {
     252             :   NamedMDNode *&NMD =
     253       49246 :     (*static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab))[Name];
     254       24623 :   if (!NMD) {
     255       18765 :     NMD = new NamedMDNode(Name);
     256       37530 :     NMD->setParent(this);
     257       18765 :     NamedMDList.push_back(NMD);
     258             :   }
     259       24623 :   return NMD;
     260             : }
     261             : 
     262             : /// eraseNamedMetadata - Remove the given NamedMDNode from this module and
     263             : /// delete it.
     264         139 : void Module::eraseNamedMetadata(NamedMDNode *NMD) {
     265         139 :   static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab)->erase(NMD->getName());
     266         278 :   NamedMDList.erase(NMD->getIterator());
     267         139 : }
     268             : 
     269     4491076 : bool Module::isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB) {
     270     8982148 :   if (ConstantInt *Behavior = mdconst::dyn_extract_or_null<ConstantInt>(MD)) {
     271     4491072 :     uint64_t Val = Behavior->getLimitedValue();
     272     4491072 :     if (Val >= ModFlagBehaviorFirstVal && Val <= ModFlagBehaviorLastVal) {
     273     4491070 :       MFB = static_cast<ModFlagBehavior>(Val);
     274     4491070 :       return true;
     275             :     }
     276             :   }
     277             :   return false;
     278             : }
     279             : 
     280             : /// getModuleFlagsMetadata - Returns the module flags in the provided vector.
     281     1448451 : void Module::
     282             : getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const {
     283     1448451 :   const NamedMDNode *ModFlags = getModuleFlagsMetadata();
     284     1448452 :   if (!ModFlags) return;
     285             : 
     286     5502740 :   for (const MDNode *Flag : ModFlags->operands()) {
     287             :     ModFlagBehavior MFB;
     288     4472855 :     if (Flag->getNumOperands() >= 3 &&
     289    13418566 :         isValidModFlagBehavior(Flag->getOperand(0), MFB) &&
     290     8945702 :         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     8945700 :       MDString *Key = cast<MDString>(Flag->getOperand(1));
     294     8945700 :       Metadata *Val = Flag->getOperand(2);
     295     8945700 :       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     1431915 : Metadata *Module::getModuleFlag(StringRef Key) const {
     303     2863830 :   SmallVector<Module::ModuleFlagEntry, 8> ModuleFlags;
     304     1431915 :   getModuleFlagsMetadata(ModuleFlags);
     305     8759695 :   for (const ModuleFlagEntry &MFE : ModuleFlags) {
     306     4467446 :     if (Key == MFE.Key->getString())
     307        3496 :       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     1557035 : NamedMDNode *Module::getModuleFlagsMetadata() const {
     316     1557035 :   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       11094 : NamedMDNode *Module::getOrInsertModuleFlagsMetadata() {
     323       11094 :   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       10959 : void Module::addModuleFlag(ModFlagBehavior Behavior, StringRef Key,
     330             :                            Metadata *Val) {
     331       10959 :   Type *Int32Ty = Type::getInt32Ty(Context);
     332             :   Metadata *Ops[3] = {
     333       21918 :       ConstantAsMetadata::get(ConstantInt::get(Int32Ty, Behavior)),
     334       10959 :       MDString::get(Context, Key), Val};
     335       21918 :   getOrInsertModuleFlagsMetadata()->addOperand(MDNode::get(Context, Ops));
     336       10959 : }
     337       10197 : void Module::addModuleFlag(ModFlagBehavior Behavior, StringRef Key,
     338             :                            Constant *Val) {
     339       10197 :   addModuleFlag(Behavior, Key, ConstantAsMetadata::get(Val));
     340       10197 : }
     341       10197 : void Module::addModuleFlag(ModFlagBehavior Behavior, StringRef Key,
     342             :                            uint32_t Val) {
     343       10197 :   Type *Int32Ty = Type::getInt32Ty(Context);
     344       10197 :   addModuleFlag(Behavior, Key, ConstantInt::get(Int32Ty, Val));
     345       10197 : }
     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        8379 : void Module::setDataLayout(StringRef Desc) {
     356        8379 :   DL.reset(Desc);
     357        8353 : }
     358             : 
     359       28752 : void Module::setDataLayout(const DataLayout &Other) { DL = Other; }
     360             : 
     361   104221023 : const DataLayout &Module::getDataLayout() const { return DL; }
     362             : 
     363        1567 : DICompileUnit *Module::debug_compile_units_iterator::operator*() const {
     364        3134 :   return cast<DICompileUnit>(CUs->getOperand(Idx));
     365             : }
     366        2402 : DICompileUnit *Module::debug_compile_units_iterator::operator->() const {
     367        4804 :   return cast<DICompileUnit>(CUs->getOperand(Idx));
     368             : }
     369             : 
     370       70176 : void Module::debug_compile_units_iterator::SkipNoDebugCUs() {
     371       72700 :   while (CUs && (Idx < CUs->getNumOperands()) &&
     372        2402 :          ((*this)->getEmissionKind() == DICompileUnit::NoDebug))
     373          61 :     ++Idx;
     374       70176 : }
     375             : 
     376             : //===----------------------------------------------------------------------===//
     377             : // Methods to control the materialization of GlobalValues in the Module.
     378             : //
     379        2879 : 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        5758 :   Materializer.reset(GVM);
     384        2879 : }
     385             : 
     386      105893 : Error Module::materialize(GlobalValue *GV) {
     387      211786 :   if (!Materializer)
     388      315126 :     return Error::success();
     389             : 
     390        1702 :   return Materializer->materialize(GV);
     391             : }
     392             : 
     393        2232 : Error Module::materializeAll() {
     394        4464 :   if (!Materializer)
     395         117 :     return Error::success();
     396        4386 :   std::unique_ptr<GVMaterializer> M = std::move(Materializer);
     397        2193 :   return M->materializeModule();
     398             : }
     399             : 
     400         992 : Error Module::materializeMetadata() {
     401        1984 :   if (!Materializer)
     402        1242 :     return Error::success();
     403        1156 :   return Materializer->materializeMetadata();
     404             : }
     405             : 
     406             : //===----------------------------------------------------------------------===//
     407             : // Other module related stuff.
     408             : //
     409             : 
     410         981 : 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        1962 :   if (Materializer)
     415        1172 :     return Materializer->getIdentifiedStructTypes();
     416             : 
     417         395 :   std::vector<StructType *> Ret;
     418         790 :   TypeFinder SrcStructTypes;
     419         395 :   SrcStructTypes.run(*this, true);
     420        1185 :   Ret.assign(SrcStructTypes.begin(), SrcStructTypes.end());
     421         395 :   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       37079 : void Module::dropAllReferences() {
     432      476383 :   for (Function &F : *this)
     433      365146 :     F.dropAllReferences();
     434             : 
     435      118525 :   for (GlobalVariable &GV : globals())
     436       81447 :     GV.dropAllReferences();
     437             : 
     438       39192 :   for (GlobalAlias &GA : aliases())
     439        2114 :     GA.dropAllReferences();
     440             : 
     441       37155 :   for (GlobalIFunc &GIF : ifuncs())
     442          77 :     GIF.dropAllReferences();
     443       37078 : }
     444             : 
     445        1037 : unsigned Module::getNumberRegisterParameters() const {
     446             :   auto *Val =
     447        2074 :       cast_or_null<ConstantAsMetadata>(getModuleFlag("NumRegisterParameters"));
     448             :   if (!Val)
     449             :     return 0;
     450        1080 :   return cast<ConstantInt>(Val->getValue())->getZExtValue();
     451             : }
     452             : 
     453       16529 : unsigned Module::getDwarfVersion() const {
     454       33059 :   auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("Dwarf Version"));
     455             :   if (!Val)
     456             :     return 0;
     457        1518 :   return cast<ConstantInt>(Val->getValue())->getZExtValue();
     458             : }
     459             : 
     460       16570 : unsigned Module::getCodeViewFlag() const {
     461       33140 :   auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("CodeView"));
     462             :   if (!Val)
     463             :     return 0;
     464         288 :   return cast<ConstantInt>(Val->getValue())->getZExtValue();
     465             : }
     466             : 
     467       35701 : Comdat *Module::getOrInsertComdat(StringRef Name) {
     468      142804 :   auto &Entry = *ComdatSymTab.insert(std::make_pair(Name, Comdat())).first;
     469       35701 :   Entry.second.Name = &Entry;
     470       35701 :   return &Entry.second;
     471             : }
     472             : 
     473       64972 : PICLevel::Level Module::getPICLevel() const {
     474      129944 :   auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("PIC Level"));
     475             : 
     476             :   if (!Val)
     477             :     return PICLevel::NotPIC;
     478             : 
     479             :   return static_cast<PICLevel::Level>(
     480        1362 :       cast<ConstantInt>(Val->getValue())->getZExtValue());
     481             : }
     482             : 
     483         124 : void Module::setPICLevel(PICLevel::Level PL) {
     484         124 :   addModuleFlag(ModFlagBehavior::Max, "PIC Level", PL);
     485         124 : }
     486             : 
     487      107546 : PIELevel::Level Module::getPIELevel() const {
     488      215092 :   auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("PIE Level"));
     489             : 
     490             :   if (!Val)
     491             :     return PIELevel::Default;
     492             : 
     493             :   return static_cast<PIELevel::Level>(
     494         459 :       cast<ConstantInt>(Val->getValue())->getZExtValue());
     495             : }
     496             : 
     497          13 : void Module::setPIELevel(PIELevel::Level PL) {
     498          13 :   addModuleFlag(ModFlagBehavior::Max, "PIE Level", PL);
     499          13 : }
     500             : 
     501         133 : void Module::setProfileSummary(Metadata *M) {
     502         133 :   addModuleFlag(ModFlagBehavior::Error, "ProfileSummary", M);
     503         133 : }
     504             : 
     505     1179234 : Metadata *Module::getProfileSummary() {
     506     1179234 :   return getModuleFlag("ProfileSummary");
     507             : }
     508             : 
     509         959 : void Module::setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB) {
     510        1918 :   OwnedMemoryBuffer = std::move(MB);
     511         959 : }
     512             : 
     513        8681 : GlobalVariable *llvm::collectUsedGlobalVariables(
     514             :     const Module &M, SmallPtrSetImpl<GlobalValue *> &Set, bool CompilerUsed) {
     515        8681 :   const char *Name = CompilerUsed ? "llvm.compiler.used" : "llvm.used";
     516       17362 :   GlobalVariable *GV = M.getGlobalVariable(Name);
     517        8812 :   if (!GV || !GV->hasInitializer())
     518             :     return GV;
     519             : 
     520         262 :   const ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
     521         524 :   for (Value *Op : Init->operands()) {
     522         524 :     GlobalValue *G = cast<GlobalValue>(Op->stripPointerCastsNoFollowAliases());
     523         262 :     Set.insert(G);
     524             :   }
     525             :   return GV;
     526             : }

Generated by: LCOV version 1.13