本文整理汇总了C++中DILocation::getFilename方法的典型用法代码示例。如果您正苦于以下问题:C++ DILocation::getFilename方法的具体用法?C++ DILocation::getFilename怎么用?C++ DILocation::getFilename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DILocation
的用法示例。
在下文中一共展示了DILocation::getFilename方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ci
void
CallGraphPass::handleInstruction(llvm::CallSite cs, callgraphs::FunctionInfo *fun, llvm::Module &m){
// Check whether the instruction is actually a call
if (!cs.getInstruction()) {
return;
}
// Check whether the called function is directly invoked
auto called = dyn_cast<Function>(cs.getCalledValue()->stripPointerCasts());
if (!called) {
for(auto &f : m){
if(f.hasAddressTaken()){
bool match = true;
std::vector< Type* > argslist;
for (Use &U : cs.getInstruction()->operands()) {
Value *v = U.get();
argslist.push_back( v->getType() );
}
llvm::Function::ArgumentListType &alt = f.getArgumentList();
int j = 0;
for( auto &a : alt){
if( a.getType() != argslist[j++]){
match = false;
}
}
if( argslist.size() > (j+1) && !f.isVarArg() ){
match = false;
}
if(match){
DILocation *Loc = cs.getInstruction()->getDebugLoc();
callgraphs::CallInfo ci( &f, Loc->getLine() , Loc->getFilename(),
funcs.find( fun->getFunction() )->second.callCount);
funcs.find( &f )->second.weight++;
funcs.find( fun->getFunction() )->second.directCalls.push_back( ci );
}
}
}
funcs.find( fun->getFunction() )->second.callCount++;
return;
}
if(called->getName() == "llvm.dbg.declare")
return;
// Direct Calls heres
DILocation *Loc = cs.getInstruction()->getDebugLoc();
callgraphs::CallInfo ci(called, Loc->getLine() , Loc->getFilename(),
funcs.find( fun->getFunction() )->second.callCount );
funcs.find( called )->second.weight++;
funcs.find( fun->getFunction() )->second.directCalls.push_back( ci );
funcs.find( fun->getFunction() )->second.callCount++;
}
示例2: emitInstructionAnnot
void LineNumberAnnotatedWriter::emitInstructionAnnot(
const Instruction *I, formatted_raw_ostream &Out)
{
DILocation *NewInstrLoc = I->getDebugLoc();
if (!NewInstrLoc) {
auto Loc = DebugLoc.find(I);
if (Loc != DebugLoc.end())
NewInstrLoc = Loc->second;
}
if (!NewInstrLoc || NewInstrLoc == InstrLoc)
return;
InstrLoc = NewInstrLoc;
std::vector<DILineInfo> DIvec;
do {
DIvec.emplace_back();
DILineInfo &DI = DIvec.back();
DIScope *scope = NewInstrLoc->getScope();
if (scope)
DI.FunctionName = scope->getName();
DI.FileName = NewInstrLoc->getFilename();
DI.Line = NewInstrLoc->getLine();
NewInstrLoc = NewInstrLoc->getInlinedAt();
} while (NewInstrLoc);
LinePrinter.emit_lineinfo(Out, DIvec);
}
示例3: getLocation
void DiagnosticInfoOptimizationBase::getLocation(StringRef *Filename,
unsigned *Line,
unsigned *Column) const {
DILocation *L = getDebugLoc();
assert(L != nullptr && "debug location is invalid");
*Filename = L->getFilename();
*Line = L->getLine();
*Column = L->getColumn();
}
示例4: getDSPIPath
static std::string getDSPIPath(DILocation Loc) {
std::string dir = Loc.getDirectory();
std::string file = Loc.getFilename();
if (dir.empty()) {
return file;
} else if (*dir.rbegin() == '/') {
return dir + file;
} else {
return dir + "/" + file;
}
}
示例5: Loc
//
// Function: printSourceInfo()
//
// Description:
// Print source file and line number information about the instruction to
// standard output.
//
static void
printSourceInfo (std::string errorType, Instruction * I) {
//
// Print out where the fault will be inserted in the source code.
// If we can't find the source line information, use a dummy line number and
// the function name by default.
//
std::string fname = I->getParent()->getParent()->getNameStr();
std::string funcname = fname;
uint64_t lineno = 0;
unsigned dbgKind = I->getContext().getMDKindID("dbg");
if (MDNode *Dbg = I->getMetadata(dbgKind)) {
DILocation Loc (Dbg);
fname = Loc.getDirectory().str() + Loc.getFilename().str();
lineno = Loc.getLineNumber();
}
std::cout << "Inject: " << errorType << ": "
<< funcname << ": " << fname << ": " << lineno << "\n";
return;
}
示例6: runOnFunction
/// \brief Assign DWARF discriminators.
///
/// To assign discriminators, we examine the boundaries of every
/// basic block and its successors. Suppose there is a basic block B1
/// with successor B2. The last instruction I1 in B1 and the first
/// instruction I2 in B2 are located at the same file and line number.
/// This situation is illustrated in the following code snippet:
///
/// if (i < 10) x = i;
///
/// entry:
/// br i1 %cmp, label %if.then, label %if.end, !dbg !10
/// if.then:
/// %1 = load i32* %i.addr, align 4, !dbg !10
/// store i32 %1, i32* %x, align 4, !dbg !10
/// br label %if.end, !dbg !10
/// if.end:
/// ret void, !dbg !12
///
/// Notice how the branch instruction in block 'entry' and all the
/// instructions in block 'if.then' have the exact same debug location
/// information (!dbg !10).
///
/// To distinguish instructions in block 'entry' from instructions in
/// block 'if.then', we generate a new lexical block for all the
/// instruction in block 'if.then' that share the same file and line
/// location with the last instruction of block 'entry'.
///
/// This new lexical block will have the same location information as
/// the previous one, but with a new DWARF discriminator value.
///
/// One of the main uses of this discriminator value is in runtime
/// sample profilers. It allows the profiler to distinguish instructions
/// at location !dbg !10 that execute on different basic blocks. This is
/// important because while the predicate 'if (x < 10)' may have been
/// executed millions of times, the assignment 'x = i' may have only
/// executed a handful of times (meaning that the entry->if.then edge is
/// seldom taken).
///
/// If we did not have discriminator information, the profiler would
/// assign the same weight to both blocks 'entry' and 'if.then', which
/// in turn will make it conclude that the entry->if.then edge is very
/// hot.
///
/// To decide where to create new discriminator values, this function
/// traverses the CFG and examines instruction at basic block boundaries.
/// If the last instruction I1 of a block B1 is at the same file and line
/// location as instruction I2 of successor B2, then it creates a new
/// lexical block for I2 and all the instruction in B2 that share the same
/// file and line location as I2. This new lexical block will have a
/// different discriminator number than I1.
bool AddDiscriminators::runOnFunction(Function &F) {
// If the function has debug information, but the user has disabled
// discriminators, do nothing.
// Simlarly, if the function has no debug info, do nothing.
// Finally, if this module is built with dwarf versions earlier than 4,
// do nothing (discriminator support is a DWARF 4 feature).
if (NoDiscriminators || !hasDebugInfo(F) ||
F.getParent()->getDwarfVersion() < 4)
return false;
bool Changed = false;
Module *M = F.getParent();
LLVMContext &Ctx = M->getContext();
DIBuilder Builder(*M, /*AllowUnresolved*/ false);
typedef std::pair<StringRef, unsigned> Location;
typedef DenseMap<const BasicBlock *, Metadata *> BBScopeMap;
typedef DenseMap<Location, BBScopeMap> LocationBBMap;
typedef DenseMap<Location, unsigned> LocationDiscriminatorMap;
LocationBBMap LBM;
LocationDiscriminatorMap LDM;
// Traverse all instructions in the function. If the source line location
// of the instruction appears in other basic block, assign a new
// discriminator for this instruction.
for (BasicBlock &B : F) {
for (auto &I : B.getInstList()) {
if (isa<DbgInfoIntrinsic>(&I))
continue;
const DILocation *DIL = I.getDebugLoc();
if (!DIL)
continue;
Location L = std::make_pair(DIL->getFilename(), DIL->getLine());
auto &BBMap = LBM[L];
auto R = BBMap.insert(std::make_pair(&B, (Metadata *)nullptr));
if (BBMap.size() == 1)
continue;
bool InsertSuccess = R.second;
Metadata *&NewScope = R.first->second;
// If we could insert a different block in the same location, a
// discriminator is needed to distinguish both instructions.
if (InsertSuccess) {
auto *Scope = DIL->getScope();
auto *File =
Builder.createFile(DIL->getFilename(), Scope->getDirectory());
NewScope = Builder.createLexicalBlockFile(Scope, File, ++LDM[L]);
}
I.setDebugLoc(DILocation::get(Ctx, DIL->getLine(), DIL->getColumn(),
//.........这里部分代码省略.........
示例7: runOnFunction
/// \brief Assign DWARF discriminators.
///
/// To assign discriminators, we examine the boundaries of every
/// basic block and its successors. Suppose there is a basic block B1
/// with successor B2. The last instruction I1 in B1 and the first
/// instruction I2 in B2 are located at the same file and line number.
/// This situation is illustrated in the following code snippet:
///
/// if (i < 10) x = i;
///
/// entry:
/// br i1 %cmp, label %if.then, label %if.end, !dbg !10
/// if.then:
/// %1 = load i32* %i.addr, align 4, !dbg !10
/// store i32 %1, i32* %x, align 4, !dbg !10
/// br label %if.end, !dbg !10
/// if.end:
/// ret void, !dbg !12
///
/// Notice how the branch instruction in block 'entry' and all the
/// instructions in block 'if.then' have the exact same debug location
/// information (!dbg !10).
///
/// To distinguish instructions in block 'entry' from instructions in
/// block 'if.then', we generate a new lexical block for all the
/// instruction in block 'if.then' that share the same file and line
/// location with the last instruction of block 'entry'.
///
/// This new lexical block will have the same location information as
/// the previous one, but with a new DWARF discriminator value.
///
/// One of the main uses of this discriminator value is in runtime
/// sample profilers. It allows the profiler to distinguish instructions
/// at location !dbg !10 that execute on different basic blocks. This is
/// important because while the predicate 'if (x < 10)' may have been
/// executed millions of times, the assignment 'x = i' may have only
/// executed a handful of times (meaning that the entry->if.then edge is
/// seldom taken).
///
/// If we did not have discriminator information, the profiler would
/// assign the same weight to both blocks 'entry' and 'if.then', which
/// in turn will make it conclude that the entry->if.then edge is very
/// hot.
///
/// To decide where to create new discriminator values, this function
/// traverses the CFG and examines instruction at basic block boundaries.
/// If the last instruction I1 of a block B1 is at the same file and line
/// location as instruction I2 of successor B2, then it creates a new
/// lexical block for I2 and all the instruction in B2 that share the same
/// file and line location as I2. This new lexical block will have a
/// different discriminator number than I1.
bool AddDiscriminators::runOnFunction(Function &F) {
// If the function has debug information, but the user has disabled
// discriminators, do nothing.
// Simlarly, if the function has no debug info, do nothing.
// Finally, if this module is built with dwarf versions earlier than 4,
// do nothing (discriminator support is a DWARF 4 feature).
if (NoDiscriminators ||
!hasDebugInfo(F) ||
F.getParent()->getDwarfVersion() < 4)
return false;
bool Changed = false;
Module *M = F.getParent();
LLVMContext &Ctx = M->getContext();
DIBuilder Builder(*M, /*AllowUnresolved*/ false);
// Traverse all the blocks looking for instructions in different
// blocks that are at the same file:line location.
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
BasicBlock *B = I;
TerminatorInst *Last = B->getTerminator();
DILocation LastDIL = Last->getDebugLoc().get();
if (!LastDIL)
continue;
for (unsigned I = 0; I < Last->getNumSuccessors(); ++I) {
BasicBlock *Succ = Last->getSuccessor(I);
Instruction *First = Succ->getFirstNonPHIOrDbgOrLifetime();
DILocation FirstDIL = First->getDebugLoc().get();
if (!FirstDIL)
continue;
// If the first instruction (First) of Succ is at the same file
// location as B's last instruction (Last), add a new
// discriminator for First's location and all the instructions
// in Succ that share the same location with First.
if (!FirstDIL->canDiscriminate(*LastDIL)) {
// Create a new lexical scope and compute a new discriminator
// number for it.
StringRef Filename = FirstDIL->getFilename();
auto *Scope = FirstDIL->getScope();
auto *File = Builder.createFile(Filename, Scope->getDirectory());
// FIXME: Calculate the discriminator here, based on local information,
// and delete MDLocation::computeNewDiscriminator(). The current
// solution gives different results depending on other modules in the
// same context. All we really need is to discriminate between
// FirstDIL and LastDIL -- a local map would suffice.
unsigned Discriminator = FirstDIL->computeNewDiscriminator();
//.........这里部分代码省略.........