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


C++ NamedMDNode类代码示例

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


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

示例1: buildCFICheck

/// buildCFICheck - emits __cfi_check for the current module.
void CrossDSOCFI::buildCFICheck() {
  // FIXME: verify that __cfi_check ends up near the end of the code section,
  // but before the jump slots created in LowerBitSets.
  llvm::DenseSet<uint64_t> BitSetIds;
  NamedMDNode *BitSetNM = M->getNamedMetadata("llvm.bitsets");

  if (BitSetNM)
    for (unsigned I = 0, E = BitSetNM->getNumOperands(); I != E; ++I)
      if (ConstantInt *TypeId = extractBitSetTypeId(BitSetNM->getOperand(I)))
        BitSetIds.insert(TypeId->getZExtValue());

  LLVMContext &Ctx = M->getContext();
  Constant *C = M->getOrInsertFunction(
      "__cfi_check",
      FunctionType::get(
          Type::getVoidTy(Ctx),
          {Type::getInt64Ty(Ctx), PointerType::getUnqual(Type::getInt8Ty(Ctx))},
          false));
  Function *F = dyn_cast<Function>(C);
  F->setAlignment(4096);
  auto args = F->arg_begin();
  Argument &CallSiteTypeId = *(args++);
  CallSiteTypeId.setName("CallSiteTypeId");
  Argument &Addr = *(args++);
  Addr.setName("Addr");
  assert(args == F->arg_end());

  BasicBlock *BB = BasicBlock::Create(Ctx, "entry", F);

  BasicBlock *TrapBB = BasicBlock::Create(Ctx, "trap", F);
  IRBuilder<> IRBTrap(TrapBB);
  Function *TrapFn = Intrinsic::getDeclaration(M, Intrinsic::trap);
  llvm::CallInst *TrapCall = IRBTrap.CreateCall(TrapFn);
  TrapCall->setDoesNotReturn();
  TrapCall->setDoesNotThrow();
  IRBTrap.CreateUnreachable();

  BasicBlock *ExitBB = BasicBlock::Create(Ctx, "exit", F);
  IRBuilder<> IRBExit(ExitBB);
  IRBExit.CreateRetVoid();

  IRBuilder<> IRB(BB);
  SwitchInst *SI = IRB.CreateSwitch(&CallSiteTypeId, TrapBB, BitSetIds.size());
  for (uint64_t TypeId : BitSetIds) {
    ConstantInt *CaseTypeId = ConstantInt::get(Type::getInt64Ty(Ctx), TypeId);
    BasicBlock *TestBB = BasicBlock::Create(Ctx, "test", F);
    IRBuilder<> IRBTest(TestBB);
    Function *BitsetTestFn =
        Intrinsic::getDeclaration(M, Intrinsic::bitset_test);

    Value *Test = IRBTest.CreateCall(
        BitsetTestFn, {&Addr, MetadataAsValue::get(
                                  Ctx, ConstantAsMetadata::get(CaseTypeId))});
    BranchInst *BI = IRBTest.CreateCondBr(Test, ExitBB, TrapBB);
    BI->setMetadata(LLVMContext::MD_prof, VeryLikelyWeights);

    SI->addCase(CaseTypeId, TestBB);
    ++TypeIds;
  }
}
开发者ID:2asoft,项目名称:freebsd,代码行数:61,代码来源:CrossDSOCFI.cpp

示例2: processDeclare

/// processModule - Process entire module and collect debug info.
void DebugInfoFinder::processModule(Module &M) {

  MetadataContext &TheMetadata = M.getContext().getMetadata();
  unsigned MDDbgKind = TheMetadata.getMDKind("dbg");

  for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
    for (Function::iterator FI = (*I).begin(), FE = (*I).end(); FI != FE; ++FI)
      for (BasicBlock::iterator BI = (*FI).begin(), BE = (*FI).end(); BI != BE;
           ++BI) {
        if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(BI))
          processDeclare(DDI);
        else if (MDDbgKind) 
          if (MDNode *L = TheMetadata.getMD(MDDbgKind, BI)) 
            processLocation(DILocation(L));
      }

  NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.gv");
  if (!NMD)
    return;

  for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i) {
    DIGlobalVariable DIG(cast<MDNode>(NMD->getElement(i)));
    if (addGlobalVariable(DIG)) {
      addCompileUnit(DIG.getCompileUnit());
      processType(DIG.getType());
    }
  }
}
开发者ID:,项目名称:,代码行数:29,代码来源:

示例3: assert

DICompileUnit *DIBuilder::createCompileUnit(
    unsigned Lang, StringRef Filename, StringRef Directory, StringRef Producer,
    bool isOptimized, StringRef Flags, unsigned RunTimeVer, StringRef SplitName,
    DebugEmissionKind Kind, uint64_t DWOId, bool EmitDebugInfo) {

  assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) ||
          (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
         "Invalid Language tag");
  assert(!Filename.empty() &&
         "Unable to create compile unit without filename");

  assert(!CUNode && "Can only make one compile unit per DIBuilder instance");
  CUNode = DICompileUnit::getDistinct(
      VMContext, Lang, DIFile::get(VMContext, Filename, Directory), Producer,
      isOptimized, Flags, RunTimeVer, SplitName, Kind, nullptr,
      nullptr, nullptr, nullptr, nullptr, DWOId);

  // Create a named metadata so that it is easier to find cu in a module.
  // Note that we only generate this when the caller wants to actually
  // emit debug information. When we are only interested in tracking
  // source line locations throughout the backend, we prevent codegen from
  // emitting debug info in the final output by not generating llvm.dbg.cu.
  if (EmitDebugInfo) {
    NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
    NMD->addOperand(CUNode);
  }

  trackIfUnresolved(CUNode);
  return CUNode;
}
开发者ID:IanLee1521,项目名称:ares,代码行数:30,代码来源:DIBuilder.cpp

示例4: StripDebugInfo

bool llvm::StripDebugInfo(Module &M) {
  bool Changed = false;

  for (Module::named_metadata_iterator NMI = M.named_metadata_begin(),
         NME = M.named_metadata_end(); NMI != NME;) {
    NamedMDNode *NMD = &*NMI;
    ++NMI;

    // We're stripping debug info, and without them, coverage information
    // doesn't quite make sense.
    if (NMD->getName().startswith("llvm.dbg.") ||
        NMD->getName() == "llvm.gcov") {
      NMD->eraseFromParent();
      Changed = true;
    }
  }

  for (Function &F : M)
    Changed |= stripDebugInfo(F);

  for (auto &GV : M.globals()) {
    SmallVector<MDNode *, 1> MDs;
    GV.getMetadata(LLVMContext::MD_dbg, MDs);
    if (!MDs.empty()) {
      GV.eraseMetadata(LLVMContext::MD_dbg);
      Changed = true;
    }
  }

  if (GVMaterializer *Materializer = M.getMaterializer())
    Materializer->setStripDebugInfo();

  return Changed;
}
开发者ID:anupam128,项目名称:llvm,代码行数:34,代码来源:DebugInfo.cpp

示例5: parseType

map<string, Variable*>* IRParser::parseParameters(Module* module){
    map<string, Variable*>* parameters = new map<string, Variable*>();

    NamedMDNode* inputsMD =  module->getNamedMetadata(IRConstant::KEY_PARAMETERS);
    if (inputsMD != NULL){
        for (unsigned i = 0, e = inputsMD->getNumOperands(); i != e; ++i) {

            //Parse a parameter
            MDNode* parameterNode = cast<MDNode>(inputsMD->getOperand(i));
            MDNode* details = cast<MDNode>(parameterNode->getOperand(0));
            MDString* nameMD = cast<MDString>(details->getOperand(0));

            Type* type = parseType(cast<MDNode>(parameterNode->getOperand(1)));

            GlobalVariable* variable = cast<GlobalVariable>(parameterNode->getOperand(2));

            //Parse create parameter
            StateVar* parameter = new StateVar(type, nameMD->getString(), false, variable);

            parameters->insert(pair<string, Variable*>(nameMD->getString(), parameter));
        }

    }
    return parameters;
}
开发者ID:orcc,项目名称:jade,代码行数:25,代码来源:IRParser.cpp

示例6: GetTagConstant

/// createVariable - Create a new descriptor for the specified variable.
DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
                                          StringRef Name, DIFile File,
                                          unsigned LineNo, DIType Ty,
                                          bool AlwaysPreserve, unsigned Flags,
                                          unsigned ArgNo) {
  Value *Elts[] = {
    GetTagConstant(VMContext, Tag),
    getNonCompileUnitScope(Scope),
    MDString::get(VMContext, Name),
    File,
    ConstantInt::get(Type::getInt32Ty(VMContext), (LineNo | (ArgNo << 24))),
    Ty,
    ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
    Constant::getNullValue(Type::getInt32Ty(VMContext))
  };
  MDNode *Node = MDNode::get(VMContext, Elts);
  if (AlwaysPreserve) {
    // The optimizer may remove local variable. If there is an interest
    // to preserve variable info in such situation then stash it in a
    // named mdnode.
    DISubprogram Fn(getDISubprogram(Scope));
    NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, Fn);
    FnLocals->addOperand(Node);
  }
  return DIVariable(Node);
}
开发者ID:ebraheemk,项目名称:llvm-picoblaze,代码行数:27,代码来源:DIBuilder.cpp

示例7: parseActionScheduler

ActionScheduler* IRParser::parseActionScheduler(Module* module){
    NamedMDNode* inputsMD =  module->getNamedMetadata(IRConstant::KEY_ACTION_SCHED);

    MDNode* actionSchedulerMD = cast<MDNode>(inputsMD->getOperand(0));
    list<Action*>* actions = new list<Action*>();
    FSM* fsm = NULL;

    //Get actions outside fsm if present
    Value* actionsValue = actionSchedulerMD->getOperand(0);

    if (actionsValue != NULL){
        MDNode* actionsNode =  cast<MDNode>(actionsValue);
        for (unsigned i = 0, e = actionsNode->getNumOperands(); i != e; ++i) {
            actions->push_back(getAction(cast<MDNode>(actionsNode->getOperand(i))));
        }
    }

    //Get fsm if present
    Value* fsmValue = actionSchedulerMD->getOperand(1);

    if (fsmValue != NULL){
        fsm = parseFSM(cast<MDNode>(fsmValue));
    }

    return new ActionScheduler(actions, fsm);
}
开发者ID:orcc,项目名称:jade,代码行数:26,代码来源:IRParser.cpp

示例8: parseMoC

MoC* IRParser::parseMoC(Module* module){
    NamedMDNode* mocKeyMD =  module->getNamedMetadata(IRConstant::KEY_MOC);

    if (mocKeyMD == NULL) {
        return new DPNMoC(actor);
    }

    //Parse MoC type
    MDNode* node = mocKeyMD->getOperand(0);
    MDString* name = cast<MDString>(node->getOperand(0));
    StringRef nameStr = name->getString();

    if (nameStr == "SDF"){
        return parseCSDF(cast<MDNode>(node->getOperand(1)));
    }else if(nameStr == "CSDF"){
        return parseCSDF(cast<MDNode>(node->getOperand(1)));
    }else if(nameStr == "QuasiStatic"){
        return parseQSDF(node);
    }else if(nameStr == "KPN"){
        return new KPNMoC(actor);
    }else if(nameStr == "DPN"){
        return new DPNMoC(actor);
    }

    cerr << "Unsupported type of MoC" << endl;
    exit(1);
}
开发者ID:orcc,项目名称:jade,代码行数:27,代码来源:IRParser.cpp

示例9: GetTagConstant

/// CreateGlobalVariable - Create a new descriptor for the specified global.
DIGlobalVariable
DIFactory::CreateGlobalVariable(DIDescriptor Context, const char * Name,
                                const char * DisplayName,
                                const char * LinkageName,
                                DICompileUnit CompileUnit,
                                unsigned LineNo, DIType Type,bool isLocalToUnit,
                                bool isDefinition, llvm::GlobalVariable *Val) {
  Value *Elts[] = {
    GetTagConstant(dwarf::DW_TAG_variable),
    llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
    Context.getNode(),
    MDString::get(VMContext, Name),
    MDString::get(VMContext, DisplayName),
    MDString::get(VMContext, LinkageName),
    CompileUnit.getNode(),
    ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
    Type.getNode(),
    ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
    ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
    Val
  };

  Value *const *Vs = &Elts[0];
  MDNode *Node = MDNode::get(VMContext,Vs, 12);

  // Create a named metadata so that we do not lose this mdnode.
  NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.gv");
  NMD->addElement(Node);

  return DIGlobalVariable(Node);
}
开发者ID:,项目名称:,代码行数:32,代码来源:

示例10: LLVMAddNamedMetadataOperand2

void LLVMAddNamedMetadataOperand2(LLVMModuleRef M, const char *name,
                                  LLVMMetadataRef Val) {
  NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(name);
  if (!N)
    return;
  if (!Val)
    return;
  N->addOperand(unwrap<MDNode>(Val));
}
开发者ID:Aj0Ay,项目名称:llvm,代码行数:9,代码来源:IRBindings.cpp

示例11: ModuleMetaSet

static void
ModuleMetaSet(Module *module, StringRef MetaName, StringRef ValueStr) {
  NamedMDNode *node = module->getNamedMetadata(MetaName);
  if (node)
    module->eraseNamedMetadata(node);
  node = module->getOrInsertNamedMetadata(MetaName);
  MDString *value = MDString::get(module->getContext(), ValueStr);
  node->addOperand(MDNode::get(module->getContext(),
                   makeArrayRef(static_cast<Value*>(value))));
}
开发者ID:8l,项目名称:emscripten-fastcomp,代码行数:10,代码来源:Module.cpp

示例12: assert

  void
  SpecializationTable::initialize(Module* m)
  {
    assert(this->module == NULL);
    this->module = m;
#ifdef RECORD_IN_METADATA
    // Parse the module metadata to populate the table
    NamedMDNode* specs = m->getNamedMetadata("previrt::specializations");
    if (specs == NULL)
    return;

    errs() << "Specialization Count: " << specs->getNumOperands() << "\n";

    for (unsigned int i = 0; i < specs->getNumOperands(); ++i) {
      MDNode* funNode = specs->getOperand(i);
      if (funNode == NULL) {
        continue;
      }
      assert (funNode->getNumOperands() > 2);
      MDString* prinName = dyn_cast_or_null<MDString>(funNode->getOperand(0));
      MDString* specName = dyn_cast_or_null<MDString>(funNode->getOperand(1));
      if (prinName == NULL || specName == NULL) {
        errs() << "must skip " << (prinName == NULL ? "?" : prinName->getString()) << "\n";
        continue;
      }
      Function* prin = m->getFunction(prinName->getString());
      Function* spec = m->getFunction(specName->getString());
      if (prin == NULL || spec == NULL) {
        errs() << "must skip " << (prin == NULL ? "?" : prin->getName()) << "\n";
        continue;
      }

      const unsigned int arg_count = prin->getArgumentList().size();
      if (funNode->getNumOperands() != 2 + arg_count) {
        continue;
      }

      SpecScheme scheme = new Value*[arg_count];
      for (unsigned int i = 0; i < arg_count; i++) {
        Value* opr = funNode->getOperand(2 + i);
        if (opr == NULL) {
          scheme[i] = NULL;
        } else {
          assert (dyn_cast<Constant>(opr) != NULL);
          scheme[i] = opr;
        }
      }

      this->addSpecialization(prin, scheme, spec, false);
      errs() << "recording specialization of '" << prin->getName() << "' to '" << spec->getName() << "'\n";
    }
#endif /* RECORD_IN_METADATA */
  }
开发者ID:ishaq,项目名称:OCCAM,代码行数:53,代码来源:SpecializationTable.cpp

示例13: linkNamedMDNodes

/// Insert all of the named MDNodes in Src into the Dest module.
void IRLinker::linkNamedMDNodes() {
  const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
  for (const NamedMDNode &NMD : SrcM->named_metadata()) {
    // Don't link module flags here. Do them separately.
    if (&NMD == SrcModFlags)
      continue;
    NamedMDNode *DestNMD = DstM.getOrInsertNamedMetadata(NMD.getName());
    // Add Src elements into Dest node.
    for (const MDNode *Op : NMD.operands())
      DestNMD->addOperand(Mapper.mapMDNode(*Op));
  }
}
开发者ID:yxsamliu,项目名称:llvm,代码行数:13,代码来源:IRMover.cpp

示例14: ModuleMetaGet

static std::string
ModuleMetaGet(const Module *module, StringRef MetaName) {
  NamedMDNode *node = module->getNamedMetadata(MetaName);
  if (node == NULL)
    return "";
  assert(node->getNumOperands() == 1);
  MDNode *subnode = node->getOperand(0);
  assert(subnode->getNumOperands() == 1);
  MDString *value = dyn_cast<MDString>(subnode->getOperand(0));
  assert(value != NULL);
  return value->getString();
}
开发者ID:8l,项目名称:emscripten-fastcomp,代码行数:12,代码来源:Module.cpp

示例15: exit

Actor* IRParser::parseActor(string classz){
    //Get file and package of the actor
    string file = PackageMng::getSimpleName(classz);
    string packageName = PackageMng::getPackagesName(classz);
    Package* package = PackageMng::getPackage(packageName);

    //Parse the bitcode
    Module* module = parser->loadModule(package, file);

    if (module == 0){
        //Module not found
        cerr << "Error when parsing bytecode";
        exit(1);
    }

    //Empty action list
    actions.clear();
    untaggedActions.clear();

    // Parse name
    NamedMDNode* nameNMD =  module->getNamedMetadata(IRConstant::KEY_NAME);
    MDNode* nameMD = cast<MDNode>(nameNMD->getOperand(0));
    MDString* name = cast<MDString>(nameMD->getOperand(0));

    // Create the new actor
    actor = new Actor(name->getString(), module, classz);

    // Parse actor elements
    inputs = parsePorts(IRConstant::KEY_INPUTS, module);
    outputs = parsePorts(IRConstant::KEY_OUTPUTS, module);
    map<string, Variable*>* parameters =  parseParameters(module);
    map<string, StateVar*>* stateVars = parseStateVars(module);
    map<string, Procedure*>* procs = parseProcs(module);
    list<Action*>* initializes = parseActions(IRConstant::KEY_INITIALIZES, module);
    list<Action*>* actions = parseActions(IRConstant::KEY_ACTIONS, module);
    ActionScheduler* actionScheduler = parseActionScheduler(module);
    MoC* moc = parseMoC(module);

    //Set parameters of the actor
    actor->setInputs(inputs);
    actor->setOutputs(outputs);
    actor->setParameters(parameters);
    actor->setActions(actions);
    actor->setStateVars(stateVars);
    actor->setProcs(procs);
    actor->setActions(actions);
    actor->setInitializes(initializes);
    actor->setActionScheduler(actionScheduler);
    actor->setMoC(moc);

    return actor;
}
开发者ID:orcc,项目名称:jade,代码行数:52,代码来源:IRParser.cpp


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