本文整理汇总了C++中NamedMDNode::getNumOperands方法的典型用法代码示例。如果您正苦于以下问题:C++ NamedMDNode::getNumOperands方法的具体用法?C++ NamedMDNode::getNumOperands怎么用?C++ NamedMDNode::getNumOperands使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NamedMDNode
的用法示例。
在下文中一共展示了NamedMDNode::getNumOperands方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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 */
}
示例2: 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;
}
}
示例3: 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;
}
示例4: assert
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();
}
示例5: DIG
/// Find the debug info descriptor corresponding to this global variable.
static Value *findDbgGlobalDeclare(GlobalVariable *V) {
const Module *M = V->getParent();
NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.gv");
if (!NMD)
return 0;
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
DIDescriptor DIG(cast<MDNode>(NMD->getOperand(i)));
if (!DIG.isGlobalVariable())
continue;
if (DIGlobalVariable(DIG).getGlobal() == V)
return DIG;
}
return 0;
}
示例6: convertMetadataToLibraryList
// @LOCALMOD-BEGIN
void Module::convertMetadataToLibraryList() {
LibraryList.clear();
// Get the DepLib node
NamedMDNode *Node = getNamedMetadata("DepLibs");
if (!Node)
return;
for (unsigned i = 0; i < Node->getNumOperands(); i++) {
MDString* Mds = dyn_cast_or_null<MDString>(
Node->getOperand(i)->getOperand(0));
assert(Mds && "Bad NamedMetadata operand");
LibraryList.push_back(Mds->getString());
}
// Clear the metadata so the linker won't try to merge it
Node->dropAllReferences();
}
示例7: parseAction
list<Action*>* IRParser::parseActions(string key, Module* module){
list<Action*>* actions = new list<Action*>();
NamedMDNode* inputsMD = module->getNamedMetadata(key);
if (inputsMD == NULL) {
return actions;
}
for (unsigned i = 0, e = inputsMD->getNumOperands(); i != e; ++i) {
Action* action = parseAction(inputsMD->getOperand(i));
actions->push_back(action);
}
return actions;
}
示例8: parseStateVar
map<string, StateVar*>* IRParser::parseStateVars(Module* module){
map<string, StateVar*>* stateVars = new map<string, StateVar*>();
NamedMDNode* stateVarsMD = module->getNamedMetadata(IRConstant::KEY_STATE_VARS);
if (stateVarsMD == NULL) {
return stateVars;
}
for (unsigned i = 0, e = stateVarsMD->getNumOperands(); i != e; ++i) {
StateVar* var = parseStateVar(stateVarsMD->getOperand(i));
stateVars->insert(pair<string, StateVar*>(var->getName(), var));
}
return stateVars;
}
示例9: printLocation
// Print the main compile unit's source filename,
// falls back to printing the module identifier.
static void printLocation(const llvm::Module *M)
{
NamedMDNode *ND = M->getNamedMetadata("llvm.dbg.gv");
if (ND) {
unsigned N = ND->getNumOperands();
// Try to find main compile unit
for (unsigned i=0;i<N;i++) {
DIGlobalVariable G(ND->getOperand(i));
DICompileUnit CU(G.getCompileUnit());
if (!CU.isMain())
continue;
errs() << /*CU.getDirectory() << "/" <<*/ CU.getFilename() << ": ";
return;
}
}
errs() << M->getModuleIdentifier() << ": ";
}
示例10: getNeededRecordFor
// Get the NeededRecord for SOName.
// Returns an empty NeededRecord if there was no metadata found.
static void getNeededRecordFor(const Module *M,
StringRef SOName,
Module::NeededRecord *NR) {
NR->DynFile = SOName;
NR->Symbols.clear();
std::string Key = NeededPrefix;
Key += SOName;
NamedMDNode *Node = M->getNamedMetadata(Key);
if (!Node)
return;
for (unsigned k = 0; k < Node->getNumOperands(); ++k) {
// Insert the symbol name.
const MDString *SymName =
dyn_cast<MDString>(Node->getOperand(k)->getOperand(0));
NR->Symbols.push_back(SymName->getString());
}
}
示例11: FindDynamicInitializers
void AddressSanitizer::FindDynamicInitializers(Module& M) {
// Clang generates metadata identifying all dynamically initialized globals.
NamedMDNode *DynamicGlobals =
M.getNamedMetadata("llvm.asan.dynamically_initialized_globals");
if (!DynamicGlobals)
return;
for (int i = 0, n = DynamicGlobals->getNumOperands(); i < n; ++i) {
MDNode *MDN = DynamicGlobals->getOperand(i);
assert(MDN->getNumOperands() == 1);
Value *VG = MDN->getOperand(0);
// The optimizer may optimize away a global entirely, in which case we
// cannot instrument access to it.
if (!VG)
continue;
GlobalVariable *G = cast<GlobalVariable>(VG);
DynamicallyInitializedGlobals.insert(G);
}
}
示例12: diCu
static std::unique_ptr<StructInfo> getCpuArchStructInfo(Module *module)
{
GlobalVariable *env = module->getGlobalVariable("cpuarchstruct_type_anchor", false);
assert(env);
assert(env->getType() && env->getType()->isPointerTy());
assert(env->getType()->getElementType() && env->getType()->getElementType()->isPointerTy());
PointerType *envDeref = dyn_cast<PointerType>(env->getType()->getElementType());
assert(envDeref && envDeref->getElementType() && envDeref->getElementType()->isStructTy());
StructType *structType = dyn_cast<StructType>(envDeref->getElementType());
assert(structType);
NamedMDNode *mdCuNodes = module->getNamedMetadata("llvm.dbg.cu");
if (!mdCuNodes) {
return nullptr;
}
std::shared_ptr<DITypeIdentifierMap> typeIdentifierMap(new DITypeIdentifierMap(generateDITypeIdentifierMap(mdCuNodes)));
DICompositeType *diStructType = nullptr;
for ( unsigned i = 0; i < mdCuNodes->getNumOperands() && !diStructType; ++i )
{
DICompileUnit diCu(mdCuNodes->getOperand(i));
for ( unsigned j = 0; j < diCu.getGlobalVariables().getNumElements(); ++j )
{
DIGlobalVariable diGlobalVar(diCu.getGlobalVariables().getElement(j));
if (diGlobalVar.getName() != "cpuarchstruct_type_anchor") {
continue;
}
assert(diGlobalVar.getType().isDerivedType());
DIDerivedType diEnvPtrType(diGlobalVar.getType());
assert(diEnvPtrType.getTypeDerivedFrom().resolve(*typeIdentifierMap).isCompositeType());
return std::unique_ptr<StructInfo>(new StructInfo(module, structType, new DICompositeType(diEnvPtrType.getTypeDerivedFrom().resolve(*typeIdentifierMap)), typeIdentifierMap));
}
}
llvm::errs() << "WARNING: Debug information for struct CPUArchState not found" << '\n';
return nullptr;
}
示例13: parseProc
map<string, Procedure*>* IRParser::parseProcs(Module* module){
map<string, Procedure*>* procedures = new map<string, Procedure*>();
NamedMDNode* inputsMD = module->getNamedMetadata(IRConstant::KEY_PROCEDURES);
if (inputsMD != NULL){
for (unsigned i = 0, e = inputsMD->getNumOperands(); i != e; ++i) {
//Parse a procedure
Procedure* proc= parseProc(inputsMD->getOperand(i));
if (proc != NULL){
// Insert procedure in case of success
procedures->insert(pair<string, Procedure*>(proc->getName(), proc));
}
}
}
return procedures;
}
示例14: parsePort
map<string, Port*>* IRParser::parsePorts(string key, Module* module){
map<string, Port*>* ports = new map<string, Port*>();
NamedMDNode* inputsMD = module->getNamedMetadata(key);
if (inputsMD == NULL) {
return ports;
}
for (unsigned i = 0, e = inputsMD->getNumOperands(); i != e; ++i) {
Port* port = parsePort(inputsMD->getOperand(i));
if(key == IRConstant::KEY_INPUTS){
port->setAccess(true, false);
}else {
port->setAccess(false, true);
}
ports->insert(pair<string,Port*>(port->getName(), port));
}
return ports;
}
示例15: buildBitSets
void DevirtModule::buildBitSets(
std::vector<VTableBits> &Bits,
DenseMap<Metadata *, std::set<BitSetInfo>> &BitSets) {
NamedMDNode *BitSetNM = M.getNamedMetadata("llvm.bitsets");
if (!BitSetNM)
return;
DenseMap<GlobalVariable *, VTableBits *> GVToBits;
Bits.reserve(BitSetNM->getNumOperands());
for (auto Op : BitSetNM->operands()) {
auto OpConstMD = dyn_cast_or_null<ConstantAsMetadata>(Op->getOperand(1));
if (!OpConstMD)
continue;
auto BitSetID = Op->getOperand(0).get();
Constant *OpConst = OpConstMD->getValue();
if (auto GA = dyn_cast<GlobalAlias>(OpConst))
OpConst = GA->getAliasee();
auto OpGlobal = dyn_cast<GlobalVariable>(OpConst);
if (!OpGlobal)
continue;
uint64_t Offset =
cast<ConstantInt>(
cast<ConstantAsMetadata>(Op->getOperand(2))->getValue())
->getZExtValue();
VTableBits *&BitsPtr = GVToBits[OpGlobal];
if (!BitsPtr) {
Bits.emplace_back();
Bits.back().GV = OpGlobal;
Bits.back().ObjectSize = M.getDataLayout().getTypeAllocSize(
OpGlobal->getInitializer()->getType());
BitsPtr = &Bits.back();
}
BitSets[BitSetID].insert({BitsPtr, Offset});
}
}