当前位置: 首页>>代码示例>>C++>>正文


C++ GlobalValue类代码示例

本文整理汇总了C++中GlobalValue的典型用法代码示例。如果您正苦于以下问题:C++ GlobalValue类的具体用法?C++ GlobalValue怎么用?C++ GlobalValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了GlobalValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: isDeclaration

/// isDeclaration - Return 'true' if the global value is a declaration.
static bool isDeclaration(const GlobalValue &V) {
  if (V.hasAvailableExternallyLinkage())
    return true;

  if (V.isMaterializable())
    return false;

  return V.isDeclaration();
}
开发者ID:eerolanguage,项目名称:llvm,代码行数:10,代码来源:LTOModule.cpp

示例2: raiseVisibilityOnValue

static void raiseVisibilityOnValue(GlobalValue &V, GlobalRenamer &R) {
  if (V.hasLocalLinkage()) {
    if (R.needsRenaming(V))
      V.setName(R.getRename(V));
    V.setLinkage(GlobalValue::ExternalLinkage);
    V.setVisibility(GlobalValue::HiddenVisibility);
  }
  V.setUnnamedAddr(GlobalValue::UnnamedAddr::None);
  assert(!R.needsRenaming(V) && "Invalid global name.");
}
开发者ID:Lucretia,项目名称:llvm,代码行数:10,代码来源:IndirectionUtils.cpp

示例3: llvmutil_extractmodule

Module * llvmutil_extractmodule(Module * OrigMod, TargetMachine * TM, std::vector<llvm::GlobalValue*> * livevalues, std::vector<std::string> * symbolnames, bool internalizeandoptimize) {
        assert(symbolnames == NULL || livevalues->size() == symbolnames->size());
        ValueToValueMapTy VMap;
        #if LLVM_VERSION >= 34
        Module * M = llvmutil_extractmodulewithproperties(OrigMod->getModuleIdentifier(), OrigMod, (llvm::GlobalValue **)&(*livevalues)[0], livevalues->size(), AlwaysCopy, NULL, VMap);
        #else
        Module * M = CloneModule(OrigMod, VMap);
        internalizeandoptimize = true; //we need to do this regardless of the input because it is the only way we can extract just the needed functions from the module
        #endif

        //rename values to symbolsnames
        std::vector<const char *> names;
        for(size_t i = 0; i < livevalues->size(); i++) {
            GlobalValue * fn = cast<GlobalValue>(VMap[(*livevalues)[i]]);
            const std::string & name = (*symbolnames)[i];
            GlobalValue * gv = M->getNamedValue(name);
            if(gv) { //if there is already a symbol with this name, rename it
                gv->setName(Twine((*symbolnames)[i],"_renamed"));
            }
            fn->setName(name); //and set our function to this name
            assert(fn->getName() == name);
            names.push_back(name.c_str()); //internalize pass has weird interface, so we need to copy the names here
        }
        
        if (!internalizeandoptimize)
            return M;
    
        //at this point we run optimizations on the module
        //first internalize all functions not mentioned in "names" using an internalize pass and then perform 
        //standard optimizations
        PassManager MPM;
        llvmutil_addtargetspecificpasses(&MPM, TM);
    
        MPM.add(createVerifierPass()); //make sure we haven't messed stuff up yet
        MPM.add(createInternalizePass(names));
        MPM.add(createGlobalDCEPass()); //run this early since anything not in the table of exported functions is still in this module
                                         //this will remove dead functions
        
        PassManagerBuilder PMB;
        PMB.OptLevel = 3;
        PMB.SizeLevel = 0;
    
#if LLVM_VERSION >= 35
        PMB.LoopVectorize = true;
        PMB.SLPVectorize = true;
#endif

        PMB.populateModulePassManager(MPM);
    
        MPM.run(*M);
    

        return M;
}
开发者ID:0----0,项目名称:terra,代码行数:54,代码来源:tllvmutil.cpp

示例4: isNonRenamableLocal

bool FunctionImportGlobalProcessing::isNonRenamableLocal(
    const GlobalValue &GV) const {
  if (!GV.hasLocalLinkage())
    return false;
  // This needs to stay in sync with the logic in buildModuleSummaryIndex.
  if (GV.hasSection())
    return true;
  if (Used.count(const_cast<GlobalValue *>(&GV)))
    return true;
  return false;
}
开发者ID:bgabor666,项目名称:llvm,代码行数:11,代码来源:FunctionImportUtils.cpp

示例5: errs

void Variables::changeGlobal(Change* change, Module &module) {

  GlobalValue* oldTarget = dyn_cast<GlobalValue>(change->getValue());
  Type* oldType = oldTarget->getType()->getElementType();
  Type* newType = change->getType()[0];
  errs() << "Changing the precision of variable \"" << oldTarget->getName() << "\" from " << *oldType << " to " << *newType << ".\n";

  if (diffTypes(oldType, newType)) {      
    Constant *initializer;
    GlobalVariable* newTarget;

    if (PointerType *newPointerType = dyn_cast<PointerType>(newType)) {
      initializer = ConstantPointerNull::get(newPointerType);
      newTarget = new GlobalVariable(module, newType, false, GlobalValue::CommonLinkage, initializer, "");
    }
    else if (ArrayType * atype = dyn_cast<ArrayType>(newType)) {

      // preparing initializer
      Type *temp = Type::getFloatTy(module.getContext());
      vector<Constant*> operands;
      operands.push_back(ConstantFP::get(temp, 0));
      ArrayRef<Constant*> *arrayRef = new ArrayRef<Constant*>(operands);
      initializer = ConstantArray::get(atype, *arrayRef);

      newTarget = new GlobalVariable(module, newType, false, GlobalValue::CommonLinkage, initializer, "");
    }
    else {
      initializer = ConstantFP::get(newType, 0);
      newTarget = new GlobalVariable(module, newType, false, GlobalValue::CommonLinkage, initializer, "");
    }

    /*
    GlobalVariable* newTarget = new GlobalVariable(module, newType, false, GlobalValue::CommonLinkage, initializer, "");
    */

    unsigned alignment = getAlignment(newType);
    newTarget->setAlignment(alignment);

    newTarget->takeName(oldTarget);
    
    // iterating through instructions using old AllocaInst
    Value::use_iterator it = oldTarget->use_begin();
    for(; it != oldTarget->use_end(); it++) {
      Transformer::transform(it, newTarget, oldTarget, newType, oldType, alignment);
    }	  
    //oldTarget->eraseFromParent();
  }
  else {
    errs() << "No changes required.\n";
  }
  return;
}
开发者ID:Sumith1896,项目名称:precimonious,代码行数:52,代码来源:Variables.cpp

示例6: llvm_mark_decl_weak

// llvm_mark_decl_weak - Used by varasm.c, called when a decl is found to be
// weak, but it already had an llvm object created for it. This marks the LLVM
// object weak as well.
void llvm_mark_decl_weak(tree decl) {
  assert(DECL_LLVM_SET_P(decl) && DECL_WEAK(decl) &&
         isa<GlobalValue>(DECL_LLVM(decl)) && "Decl isn't marked weak!");
  GlobalValue *GV = cast<GlobalValue>(DECL_LLVM(decl));

  // Do not mark something that is already known to be linkonce or internal.
  if (GV->hasExternalLinkage()) {
    if (GV->isDeclaration())
      GV->setLinkage(GlobalValue::ExternalWeakLinkage);
    else
      GV->setLinkage(GlobalValue::WeakLinkage);
  }
}
开发者ID:BackupTheBerlios,项目名称:iphone-binutils-svn,代码行数:16,代码来源:llvm-backend.cpp

示例7: DumpSymbolNameForGlobalValue

static void DumpSymbolNameForGlobalValue(GlobalValue &GV) {
  // Private linkage and available_externally linkage don't exist in symtab.
  if (GV.hasPrivateLinkage() || GV.hasLinkerPrivateLinkage() ||
      GV.hasLinkerPrivateWeakLinkage() || GV.hasAvailableExternallyLinkage())
    return;
  
  const std::string SymbolAddrStr = "        "; // Not used yet...
  char TypeChar = TypeCharForSymbol(GV);
  if ((TypeChar != 'U') && UndefinedOnly)
    return;
  if ((TypeChar == 'U') && DefinedOnly)
    return;
  if (GV.hasLocalLinkage () && ExternalOnly)
    return;
  if (OutputFormat == posix) {
    outs() << GV.getName () << " " << TypeCharForSymbol(GV) << " "
           << SymbolAddrStr << "\n";
  } else if (OutputFormat == bsd) {
    outs() << SymbolAddrStr << " " << TypeCharForSymbol(GV) << " "
           << GV.getName () << "\n";
  } else if (OutputFormat == sysv) {
    std::string PaddedName (GV.getName ());
    while (PaddedName.length () < 20)
      PaddedName += " ";
    outs() << PaddedName << "|" << SymbolAddrStr << "|   "
           << TypeCharForSymbol(GV)
           << "  |                  |      |     |\n";
  }
}
开发者ID:AHelper,项目名称:llvm-z80-target,代码行数:29,代码来源:llvm-nm.cpp

示例8: makeVisible

/// Make sure GV is visible from both modules. Delete is true if it is
/// being deleted from this module.
/// This also makes sure GV cannot be dropped so that references from
/// the split module remain valid.
static void makeVisible(GlobalValue &GV, bool Delete, bool IsDeletePass) {
  bool Local = GV.hasLocalLinkage();
  if (Local || Delete) {
    // This changes members from private -> hidden -> causes linker errors when using llvm-link
    if (!IsDeletePass)
      GV.setLinkage(GlobalValue::ExternalLinkage);
    if (Local)
      GV.setVisibility(GlobalValue::HiddenVisibility);
    return;
  }

  if (!GV.hasLinkOnceLinkage()) {
    assert(!GV.isDiscardableIfUnused());
    return;
  }

  // Map linkonce* to weak* so that llvm doesn't drop this GV.
  switch(GV.getLinkage()) {
  default:
    llvm_unreachable("Unexpected linkage");
  case GlobalValue::LinkOnceAnyLinkage:
    GV.setLinkage(GlobalValue::WeakAnyLinkage);
    return;
  case GlobalValue::LinkOnceODRLinkage:
    GV.setLinkage(GlobalValue::WeakODRLinkage);
    return;
  }
}
开发者ID:,项目名称:,代码行数:32,代码来源:

示例9: makeVisible

/// Make sure GV is visible from both modules. Delete is true if it is
/// being deleted from this module.
/// This also makes sure GV cannot be dropped so that references from
/// the split module remain valid.
static void makeVisible(GlobalValue &GV, bool Delete) {
  bool Local = GV.hasLocalLinkage();
  if (Local)
    GV.setVisibility(GlobalValue::HiddenVisibility);

  if (Local || Delete) {
    GV.setLinkage(GlobalValue::ExternalLinkage);
    return;
  }

  if (!GV.hasLinkOnceLinkage()) {
    assert(!GV.isDiscardableIfUnused());
    return;
  }

  // Map linkonce* to weak* so that llvm doesn't drop this GV.
  switch(GV.getLinkage()) {
  default:
    llvm_unreachable("Unexpected linkage");
  case GlobalValue::LinkOnceAnyLinkage:
    GV.setLinkage(GlobalValue::WeakAnyLinkage);
    return;
  case GlobalValue::LinkOnceODRLinkage:
    GV.setLinkage(GlobalValue::WeakODRLinkage);
    return;
  }
}
开发者ID:christinaa,项目名称:LLVM-VideoCore4,代码行数:31,代码来源:ExtractGV.cpp

示例10: wrapSymName

void
Module::wrapSymbol(StringRef symName) {
  std::string wrapSymName("__wrap_");
  wrapSymName += symName;

  std::string realSymName("__real_");
  realSymName += symName;

  GlobalValue *SymGV = getNamedValue(symName);
  GlobalValue *WrapGV = getNamedValue(wrapSymName);
  GlobalValue *RealGV = getNamedValue(realSymName);

  // Replace uses of "sym" with __wrap_sym.
  if (SymGV) {
    if (!WrapGV)
      WrapGV = cast<GlobalValue>(getOrInsertGlobal(wrapSymName,
                                                   SymGV->getType()));
    SymGV->replaceAllUsesWith(ConstantExpr::getBitCast(WrapGV,
                                                       SymGV->getType()));
  }

  // Replace uses of "__real_sym" with "sym".
  if (RealGV) {
    if (!SymGV)
      SymGV = cast<GlobalValue>(getOrInsertGlobal(symName, RealGV->getType()));
    RealGV->replaceAllUsesWith(ConstantExpr::getBitCast(SymGV,
                                                        RealGV->getType()));
  }
}
开发者ID:8l,项目名称:emscripten-fastcomp,代码行数:29,代码来源:Module.cpp

示例11: applyRestriction

void LTOCodeGenerator::
applyRestriction(GlobalValue &GV,
                 std::vector<const char*> &mustPreserveList,
                 SmallPtrSet<GlobalValue*, 8> &asmUsed,
                 Mangler &mangler) {
  SmallString<64> Buffer;
  mangler.getNameWithPrefix(Buffer, &GV, false);

  if (GV.isDeclaration())
    return;
  if (_mustPreserveSymbols.count(Buffer))
    mustPreserveList.push_back(GV.getName().data());
  if (_asmUndefinedRefs.count(Buffer))
    asmUsed.insert(&GV);
}
开发者ID:otinn,项目名称:safecode,代码行数:15,代码来源:LTOCodeGenerator.cpp

示例12: convertAliasToDeclaration

bool EliminateAvailableExternally::runOnModule(Module &M) {
  bool Changed = false;

  // Convert any aliases that alias with an available externally
  // value (which will be turned into declarations later on in this routine)
  // into declarations themselves. All aliases must be definitions, and
  // must alias with a definition. So this involves creating a declaration
  // equivalent to the alias's base object.
  for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end(); I != E;) {
    // Increment the iterator first since we may delete the current alias.
    GlobalAlias &GA = *(I++);
    GlobalValue *GVal = GA.getBaseObject();
    if (!GVal->hasAvailableExternallyLinkage())
      continue;
    convertAliasToDeclaration(GA, M);
    Changed = true;
  }

  // Drop initializers of available externally global variables.
  for (GlobalVariable &GV : M.globals()) {
    if (!GV.hasAvailableExternallyLinkage())
      continue;
    if (GV.hasInitializer()) {
      Constant *Init = GV.getInitializer();
      GV.setInitializer(nullptr);
      if (isSafeToDestroyConstant(Init))
        Init->destroyConstant();
    }
    GV.removeDeadConstantUsers();
    GV.setLinkage(GlobalValue::ExternalLinkage);
    NumVariables++;
    Changed = true;
  }

  // Drop the bodies of available externally functions.
  for (Function &F : M) {
    if (!F.hasAvailableExternallyLinkage())
      continue;
    if (!F.isDeclaration())
      // This will set the linkage to external
      F.deleteBody();
    F.removeDeadConstantUsers();
    NumFunctions++;
    Changed = true;
  }

  return Changed;
}
开发者ID:alessandrostone,项目名称:metashell,代码行数:48,代码来源:ElimAvailExtern.cpp

示例13: getSymbolNMTypeChar

static char getSymbolNMTypeChar(const GlobalValue &GV) {
  if (GV.getType()->getElementType()->isFunctionTy())
    return 't';
  // FIXME: should we print 'b'? At the IR level we cannot be sure if this
  // will be in bss or not, but we could approximate.
  return 'd';
}
开发者ID:JuliaLang,项目名称:llvm,代码行数:7,代码来源:llvm-nm.cpp

示例14: recursivelyVisitUsers

void AMDGPUAlwaysInline::recursivelyVisitUsers(
  GlobalValue &GV,
  SmallPtrSetImpl<Function *> &FuncsToAlwaysInline) {
  SmallVector<User *, 16> Stack;

  SmallPtrSet<const Value *, 8> Visited;

  for (User *U : GV.users())
    Stack.push_back(U);

  while (!Stack.empty()) {
    User *U = Stack.pop_back_val();
    if (!Visited.insert(U).second)
      continue;

    if (Instruction *I = dyn_cast<Instruction>(U)) {
      Function *F = I->getParent()->getParent();
      if (!AMDGPU::isEntryFunctionCC(F->getCallingConv())) {
        FuncsToAlwaysInline.insert(F);
        Stack.push_back(F);
      }

      // No need to look at further users, but we do need to inline any callers.
      continue;
    }

    for (User *UU : U->users())
      Stack.push_back(UU);
  }
}
开发者ID:bkaradzic,项目名称:SwiftShader,代码行数:30,代码来源:AMDGPUAlwaysInlinePass.cpp

示例15: useExistingDest

static bool useExistingDest(GlobalValue &SGV, GlobalValue *DGV,
                            bool ShouldLink) {
  if (!DGV)
    return false;

  if (SGV.isDeclaration())
    return true;

  if (DGV->isDeclarationForLinker() && !SGV.isDeclarationForLinker())
    return false;

  if (ShouldLink)
    return false;

  return true;
}
开发者ID:jhayworth,项目名称:llvm,代码行数:16,代码来源:IRMover.cpp


注:本文中的GlobalValue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。