本文整理汇总了C++中basicblock::iterator::getMetadata方法的典型用法代码示例。如果您正苦于以下问题:C++ iterator::getMetadata方法的具体用法?C++ iterator::getMetadata怎么用?C++ iterator::getMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类basicblock::iterator
的用法示例。
在下文中一共展示了iterator::getMetadata方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addIRInstructions
void DebugDatabase::addIRInstructions(GenerateRTL *hw) {
Function *F = hw->getFunction();
int instr_count = 0;
for (Function::iterator b = F->begin(), be = F->end(); b != be; b++) {
for (BasicBlock::iterator i = b->begin(), ie = b->end(); i != ie; i++) {
instr_count++;
bool isDummyDbgCall = false;
if (isa<DbgDeclareInst>(i) || isa<DbgValueInst>(i))
isDummyDbgCall = true;
if (i->hasMetadata()) {
MDNode *n = i->getMetadata("dbg");
DILocation loc(n);
int lineNumber = loc.getLineNumber();
int columnNumber = loc.getColumnNumber();
std::string filePath =
loc.getDirectory().str() + "/" + loc.getFilename().str();
addIRInstruction(hw, i, instr_count, isDummyDbgCall, filePath,
lineNumber, columnNumber);
} else {
addIRInstruction(hw, i, instr_count, isDummyDbgCall, "", 0, 0);
}
}
}
}
示例2: hasSIMDLoopMetadata
bool LowerSIMDLoop::hasSIMDLoopMetadata(Loop *L) const
{
// Note: If a loop has 0 or multiple latch blocks, it's probably not a simd_loop anyway.
if (BasicBlock* latch = L->getLoopLatch())
for (BasicBlock::iterator II = latch->begin(), EE = latch->end(); II!=EE; ++II)
if (II->getMetadata(simd_loop_mdkind))
return true;
return false;
}
示例3: getSourceFileName
string getSourceFileName(Function *f){
for(Function::iterator bb = f->begin(); bb != f->end(); bb++)
for(BasicBlock::iterator i = bb->begin(); i != bb->end(); i++){
if (MDNode *N = i->getMetadata("dbg")) { // this if is never executed
DILocation Loc(N);
string dir = Loc.getDirectory().str();
string name = Loc.getFilename().str();
stringstream fileName;
fileName<<dir<<name;
errs() << fileName.str() << "\n";
return fileName.str();
//return ConstantInt::get(Type::getInt32Ty(I->getContext()), Line);
}
}
return "";
}
示例4: isAnnotatedParallel
bool Loop::isAnnotatedParallel() const {
MDNode *desiredLoopIdMetadata = getLoopID();
if (!desiredLoopIdMetadata)
return false;
// The loop branch contains the parallel loop metadata. In order to ensure
// that any parallel-loop-unaware optimization pass hasn't added loop-carried
// dependencies (thus converted the loop back to a sequential loop), check
// that all the memory instructions in the loop contain parallelism metadata
// that point to the same unique "loop id metadata" the loop branch does.
for (block_iterator BB = block_begin(), BE = block_end(); BB != BE; ++BB) {
for (BasicBlock::iterator II = (*BB)->begin(), EE = (*BB)->end();
II != EE; II++) {
if (!II->mayReadOrWriteMemory())
continue;
// The memory instruction can refer to the loop identifier metadata
// directly or indirectly through another list metadata (in case of
// nested parallel loops). The loop identifier metadata refers to
// itself so we can check both cases with the same routine.
MDNode *loopIdMD =
II->getMetadata(LLVMContext::MD_mem_parallel_loop_access);
if (!loopIdMD)
return false;
bool loopIdMDFound = false;
for (unsigned i = 0, e = loopIdMD->getNumOperands(); i < e; ++i) {
if (loopIdMD->getOperand(i) == desiredLoopIdMetadata) {
loopIdMDFound = true;
break;
}
}
if (!loopIdMDFound)
return false;
}
}
return true;
}
示例5: print
void InterPro::print(raw_ostream &O, Module *M)
{
char pPath[100];
for(Module::iterator F = M->begin(); F != M->end(); F ++)
{
if(!F->getName().startswith("test"))
{
continue;
}
O << F->getName() << ":\n";
for(Function::iterator BB = F->begin(); BB != F->end(); ++ BB)
{
for(BasicBlock::iterator I = BB->begin(); I != BB->end(); I ++)
{
I->dump();
if( MDNode *N = I->getMetadata("dbg") )
{
DILocation Loc(N);
string sFileNameForInstruction = Loc.getDirectory().str() + "/" + Loc.getFilename().str();
realpath( sFileNameForInstruction.c_str() , pPath);
sFileNameForInstruction = string(pPath);
unsigned int uLineNoForInstruction = Loc.getLineNumber();
O << sFileNameForInstruction << ": " << uLineNoForInstruction << ": ";
}
O << this->InstBeforeSetMapping[I].size() << " ";
O << this->InstAfterSetMapping[I].size() << "\n";
}
}
O << "*********************************************\n";
}
}
示例6: runOnModule
/*
* Main args are always input
* Functions currently considered as input functions:
* scanf
* fscanf
* gets
* fgets
* fread
* fgetc
* getc
* getchar
* recv
* recvmsg
* read
* recvfrom
* fread
*/
bool InputDep::runOnModule(Module &M) {
// DEBUG (errs() << "Function " << F.getName() << "\n";);
NumInputValues = 0;
bool inserted;
Function* main = M.getFunction("main");
if (main) {
MDNode *mdn = main->begin()->begin()->getMetadata("dbg");
for (Function::arg_iterator Arg = main->arg_begin(), aEnd =
main->arg_end(); Arg != aEnd; Arg++) {
inputDepValues.insert(Arg);
NumInputValues++;
if (mdn) {
DILocation Loc(mdn);
unsigned Line = Loc.getLineNumber();
lineNo[Arg] = Line-1; //educated guess (can only get line numbers from insts, suppose main is declared one line before 1st inst
}
}
}
for (Module::iterator F = M.begin(), eM = M.end(); F != eM; ++F) {
for (Function::iterator BB = F->begin(), e = F->end(); BB != e; ++BB) {
for (BasicBlock::iterator I = BB->begin(), ee = BB->end(); I != ee; ++I) {
if (CallInst *CI = dyn_cast<CallInst>(I)) {
Function *Callee = CI->getCalledFunction();
if (Callee) {
Value* V;
inserted = false;
StringRef Name = Callee->getName();
if (Name.equals("main")) {
errs() << "main\n";
V = CI->getArgOperand(1); //char* argv[]
inputDepValues.insert(V);
inserted = true;
//errs() << "Input " << *V << "\n";
}
if (Name.equals("__isoc99_scanf") || Name.equals(
"scanf")) {
for (unsigned i = 1, eee = CI->getNumArgOperands(); i
!= eee; ++i) { // skip format string (i=1)
V = CI->getArgOperand(i);
if (V->getType()->isPointerTy()) {
inputDepValues.insert(V);
inserted = true;
//errs() << "Input " << *V << "\n";
}
}
} else if (Name.equals("__isoc99_fscanf")
|| Name.equals("fscanf")) {
for (unsigned i = 2, eee = CI->getNumArgOperands(); i
!= eee; ++i) { // skip file pointer and format string (i=1)
V = CI->getArgOperand(i);
if (V->getType()->isPointerTy()) {
inputDepValues.insert(V);
inserted = true;
//errs() << "Input " << *V << "\n";
}
}
} else if ((Name.equals("gets") || Name.equals("fgets")
|| Name.equals("fread"))
|| Name.equals("getwd")
|| Name.equals("getcwd")) {
V = CI->getArgOperand(0); //the first argument receives the input for these functions
if (V->getType()->isPointerTy()) {
inputDepValues.insert(V);
inserted = true;
//errs() << "Input " << *V << "\n";
}
} else if ((Name.equals("fgetc") || Name.equals("getc")
|| Name.equals("getchar"))) {
inputDepValues.insert(CI);
inserted = true;
//errs() << "Input " << *CI << "\n";
} else if (Name.equals("recv")
|| Name.equals("recvmsg")
|| Name.equals("read")) {
Value* V = CI->getArgOperand(1);
if (V->getType()->isPointerTy()) {
inputDepValues.insert(V);
inserted = true;
//errs() << "Input " << *V << "\n";
}
} else if (Name.equals("recvfrom")) {
//.........这里部分代码省略.........
示例7: CloneAndPruneFunctionInto
/// CloneAndPruneFunctionInto - This works exactly like CloneFunctionInto,
/// except that it does some simple constant prop and DCE on the fly. The
/// effect of this is to copy significantly less code in cases where (for
/// example) a function call with constant arguments is inlined, and those
/// constant arguments cause a significant amount of code in the callee to be
/// dead. Since this doesn't produce an exact copy of the input, it can't be
/// used for things like CloneFunction or CloneModule.
void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
ValueToValueMapTy &VMap,
SmallVectorImpl<ReturnInst*> &Returns,
const char *NameSuffix,
ClonedCodeInfo *CodeInfo,
const TargetData *TD,
Instruction *TheCall) {
assert(NameSuffix && "NameSuffix cannot be null!");
#ifndef NDEBUG
for (Function::const_arg_iterator II = OldFunc->arg_begin(),
E = OldFunc->arg_end(); II != E; ++II)
assert(VMap.count(II) && "No mapping from source argument specified!");
#endif
PruningFunctionCloner PFC(NewFunc, OldFunc, VMap, Returns,
NameSuffix, CodeInfo, TD);
// Clone the entry block, and anything recursively reachable from it.
std::vector<const BasicBlock*> CloneWorklist;
CloneWorklist.push_back(&OldFunc->getEntryBlock());
while (!CloneWorklist.empty()) {
const BasicBlock *BB = CloneWorklist.back();
CloneWorklist.pop_back();
PFC.CloneBlock(BB, CloneWorklist);
}
// Loop over all of the basic blocks in the old function. If the block was
// reachable, we have cloned it and the old block is now in the value map:
// insert it into the new function in the right order. If not, ignore it.
//
// Defer PHI resolution until rest of function is resolved.
SmallVector<const PHINode*, 16> PHIToResolve;
for (Function::const_iterator BI = OldFunc->begin(), BE = OldFunc->end();
BI != BE; ++BI) {
BasicBlock *NewBB = cast_or_null<BasicBlock>(VMap[BI]);
if (NewBB == 0) continue; // Dead block.
// Add the new block to the new function.
NewFunc->getBasicBlockList().push_back(NewBB);
// Loop over all of the instructions in the block, fixing up operand
// references as we go. This uses VMap to do all the hard work.
//
BasicBlock::iterator I = NewBB->begin();
unsigned DbgKind = OldFunc->getContext().getMDKindID("dbg");
MDNode *TheCallMD = NULL;
if (TheCall && TheCall->hasMetadata())
TheCallMD = TheCall->getMetadata(DbgKind);
// Handle PHI nodes specially, as we have to remove references to dead
// blocks.
if (PHINode *PN = dyn_cast<PHINode>(I)) {
// Skip over all PHI nodes, remembering them for later.
BasicBlock::const_iterator OldI = BI->begin();
for (; (PN = dyn_cast<PHINode>(I)); ++I, ++OldI) {
if (I->hasMetadata()) {
if (TheCallMD) {
if (MDNode *IMD = I->getMetadata(DbgKind)) {
MDNode *NewMD = UpdateInlinedAtInfo(IMD, TheCallMD);
I->setMetadata(DbgKind, NewMD);
}
} else {
// The cloned instruction has dbg info but the call instruction
// does not have dbg info. Remove dbg info from cloned instruction.
I->setMetadata(DbgKind, 0);
}
}
PHIToResolve.push_back(cast<PHINode>(OldI));
}
}
// FIXME:
// FIXME:
// FIXME: Unclone all this metadata stuff.
// FIXME:
// FIXME:
// Otherwise, remap the rest of the instructions normally.
for (; I != NewBB->end(); ++I) {
if (I->hasMetadata()) {
if (TheCallMD) {
if (MDNode *IMD = I->getMetadata(DbgKind)) {
MDNode *NewMD = UpdateInlinedAtInfo(IMD, TheCallMD);
I->setMetadata(DbgKind, NewMD);
}
} else {
// The cloned instruction has dbg info but the call instruction
// does not have dbg info. Remove dbg info from cloned instruction.
I->setMetadata(DbgKind, 0);
}
}
//.........这里部分代码省略.........
示例8: runOnModule
bool ClamBCTrace::runOnModule(Module &M) {
if (!InsertTracing)
return false;
unsigned MDDbgKind = M.getContext().getMDKindID("dbg");
DenseMap<MDNode*, unsigned> scopeIDs;
unsigned scopeid = 0;
IRBuilder<> builder(M.getContext());
const Type *I32Ty = Type::getInt32Ty(M.getContext());
std::vector<const Type*> args;
args.push_back(PointerType::getUnqual(Type::getInt8Ty(M.getContext())));
args.push_back(I32Ty);
const FunctionType *FTy = FunctionType::get(I32Ty, args, false);
Constant *trace_directory = M.getOrInsertFunction("trace_directory", FTy);
Constant *trace_scope = M.getOrInsertFunction("trace_scope", FTy);
Constant *trace_source = M.getOrInsertFunction("trace_source", FTy);
Constant *trace_op = M.getOrInsertFunction("trace_op", FTy);
Constant *trace_value = M.getOrInsertFunction("trace_value", FTy);
Constant *trace_ptr = M.getOrInsertFunction("trace_ptr", FTy);
assert (trace_scope && trace_source && trace_op && trace_value &&
trace_directory && trace_ptr);
if (!trace_directory->use_empty() || !trace_scope->use_empty()
|| !trace_source->use_empty() || !trace_op->use_empty() ||
!trace_value->use_empty() || !trace_ptr->use_empty())
ClamBCModule::stop("Tracing API can only be used by compiler!\n", &M);
for (Module::iterator I=M.begin(),E=M.end(); I != E; ++I) {
Function &F = *I;
if (F.isDeclaration())
continue;
bool first = true;
for (Function::iterator J=I->begin(),JE=I->end(); J != JE; ++J) {
MDNode *Scope = 0;
StringRef directory;
Value *LastFile = 0;
unsigned SrcLine = 0;
BasicBlock::iterator BBIt = J->begin();
while (BBIt != J->end()) {
while (isa<AllocaInst>(BBIt) || isa<PHINode>(BBIt)) ++BBIt;
MDNode *Dbg = BBIt->getMetadata(MDDbgKind);
if (!Dbg) {
++BBIt;
continue;
}
builder.SetInsertPoint(&*J, BBIt);
Instruction *II = BBIt;
++BBIt;
DILocation Loc(Dbg);
StringRef file = Loc.getFilename();
Value *File = builder.CreateGlobalStringPtr(file.str().c_str());
MDNode *NewScope = Loc.getScope().getNode();
if (NewScope != Scope) {
Scope = NewScope;
unsigned sid = scopeIDs[NewScope];
if (!sid) {
sid = ++scopeid;
scopeIDs[NewScope] = sid;
}
DIScope scope(Loc.getScope());
while (scope.isLexicalBlock()) {
DILexicalBlock lex(scope.getNode());
scope = lex.getContext();
}
Value *Scope = 0;
if (scope.isSubprogram()) {
DISubprogram sub(scope.getNode());
StringRef name = sub.getDisplayName();
if (name.empty()) name = sub.getName();
Scope = builder.CreateGlobalStringPtr(name.str().c_str());
} else {
assert(scope.isCompileUnit());
DICompileUnit unit(scope.getNode());
Scope =
builder.CreateGlobalStringPtr(unit.getFilename().str().c_str());
}
builder.CreateCall2(trace_scope, Scope,
ConstantInt::get(Type::getInt32Ty(M.getContext()), sid));
}
unsigned newLine = Loc.getLineNumber();
if (File != LastFile || newLine != SrcLine) {
LastFile = File;
SrcLine = newLine;
if (Loc.getDirectory() != directory) {
directory = Loc.getDirectory();
builder.CreateCall2(trace_directory,
builder.CreateGlobalStringPtr(directory.str().c_str()),
ConstantInt::get(Type::getInt32Ty(M.getContext()), 0));
}
builder.CreateCall2(trace_source, File,
ConstantInt::get(Type::getInt32Ty(M.getContext()), newLine));
}
if (first) {
first = false;
for (Function::arg_iterator AI=I->arg_begin(),AE=I->arg_end();
AI != AE; ++AI) {
if (isa<IntegerType>(AI->getType())) {
#if 0
Value *V = builder.CreateIntCast(AI, Type::getInt32Ty(M.getContext()), false);
Value *ValueName = builder.CreateGlobalStringPtr(AI->getName().data());
//.........这里部分代码省略.........