summaryrefslogtreecommitdiff
path: root/lib/Transforms/Instrumentation/GCOVProfiling.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2013-03-07 08:28:49 +0000
committerNick Lewycky <nicholas@mxc.ca>2013-03-07 08:28:49 +0000
commitd9686a98b8145010516c44a3a5b9b96bf934b9ac (patch)
treefa706bcc832e554f6c0f530289b70b20cb158ca2 /lib/Transforms/Instrumentation/GCOVProfiling.cpp
parent4d895455fe1bcc0bbfe1a0f18c01246694f64a9c (diff)
downloadllvm-d9686a98b8145010516c44a3a5b9b96bf934b9ac.tar.gz
llvm-d9686a98b8145010516c44a3a5b9b96bf934b9ac.tar.bz2
llvm-d9686a98b8145010516c44a3a5b9b96bf934b9ac.tar.xz
Switch from a version 4.2/4.4 switch to a four-byte version string to be put
into the actual gcov file. Instead of using the bottom 4 bytes as the function identifier, use a counter. This makes the identifier numbers stable across multiple runs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@176616 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Instrumentation/GCOVProfiling.cpp')
-rw-r--r--lib/Transforms/Instrumentation/GCOVProfiling.cpp48
1 files changed, 25 insertions, 23 deletions
diff --git a/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/lib/Transforms/Instrumentation/GCOVProfiling.cpp
index 095b852d93..db1dd41283 100644
--- a/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ b/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -44,17 +44,19 @@ namespace {
public:
static char ID;
GCOVProfiler()
- : ModulePass(ID), EmitNotes(true), EmitData(true), Use402Format(false),
+ : ModulePass(ID), EmitNotes(true), EmitData(true),
UseExtraChecksum(false), NoRedZone(false),
NoFunctionNamesInData(false) {
+ memcpy(Version, DefaultGCovVersion, 4);
initializeGCOVProfilerPass(*PassRegistry::getPassRegistry());
}
- GCOVProfiler(bool EmitNotes, bool EmitData, bool Use402Format,
+ GCOVProfiler(bool EmitNotes, bool EmitData, const char (&Version)[4],
bool UseExtraChecksum, bool NoRedZone,
bool NoFunctionNamesInData)
: ModulePass(ID), EmitNotes(EmitNotes), EmitData(EmitData),
- Use402Format(Use402Format), UseExtraChecksum(UseExtraChecksum),
- NoRedZone(NoRedZone), NoFunctionNamesInData(NoFunctionNamesInData) {
+ UseExtraChecksum(UseExtraChecksum), NoRedZone(NoRedZone),
+ NoFunctionNamesInData(NoFunctionNamesInData) {
+ memcpy(this->Version, Version, 4);
assert((EmitNotes || EmitData) && "GCOVProfiler asked to do nothing?");
initializeGCOVProfilerPass(*PassRegistry::getPassRegistry());
}
@@ -99,7 +101,7 @@ namespace {
bool EmitNotes;
bool EmitData;
- bool Use402Format;
+ char Version[4];
bool UseExtraChecksum;
bool NoRedZone;
bool NoFunctionNamesInData;
@@ -114,11 +116,11 @@ INITIALIZE_PASS(GCOVProfiler, "insert-gcov-profiling",
"Insert instrumentation for GCOV profiling", false, false)
ModulePass *llvm::createGCOVProfilerPass(bool EmitNotes, bool EmitData,
- bool Use402Format,
+ const char (&Version)[4],
bool UseExtraChecksum,
bool NoRedZone,
bool NoFunctionNamesInData) {
- return new GCOVProfiler(EmitNotes, EmitData, Use402Format, UseExtraChecksum,
+ return new GCOVProfiler(EmitNotes, EmitData, Version, UseExtraChecksum,
NoRedZone, NoFunctionNamesInData);
}
@@ -257,8 +259,8 @@ namespace {
// object users can construct, the blocks and lines will be rooted here.
class GCOVFunction : public GCOVRecord {
public:
- GCOVFunction(DISubprogram SP, raw_ostream *os,
- bool Use402Format, bool UseExtraChecksum) {
+ GCOVFunction(DISubprogram SP, raw_ostream *os, uint32_t Ident,
+ bool UseExtraChecksum) {
this->os = os;
Function *F = SP.getFunction();
@@ -275,7 +277,6 @@ namespace {
if (UseExtraChecksum)
++BlockLen;
write(BlockLen);
- uint32_t Ident = reinterpret_cast<intptr_t>((MDNode*)SP);
write(Ident);
write(0); // lineno checksum
if (UseExtraChecksum)
@@ -380,10 +381,9 @@ void GCOVProfiler::emitGCNO() {
std::string ErrorInfo;
raw_fd_ostream out(mangleName(CU, "gcno").c_str(), ErrorInfo,
raw_fd_ostream::F_Binary);
- if (!Use402Format)
- out.write("oncg*404MVLL", 12);
- else
- out.write("oncg*204MVLL", 12);
+ out.write("oncg", 4);
+ out.write(Version, 4);
+ out.write("MVLL", 4);
DIArray SPs = CU.getSubprograms();
for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
@@ -392,7 +392,7 @@ void GCOVProfiler::emitGCNO() {
Function *F = SP.getFunction();
if (!F) continue;
- GCOVFunction Func(SP, &out, Use402Format, UseExtraChecksum);
+ GCOVFunction Func(SP, &out, i, UseExtraChecksum);
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
GCOVBlock &Block = Func.getBlock(BB);
@@ -581,8 +581,11 @@ GlobalVariable *GCOVProfiler::buildEdgeLookupTable(
}
Constant *GCOVProfiler::getStartFileFunc() {
- FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx),
- Type::getInt8PtrTy(*Ctx), false);
+ Type *Args[] = {
+ Type::getInt8PtrTy(*Ctx), // const char *orig_filename
+ Type::getInt8PtrTy(*Ctx), // const char version[4]
+ };
+ FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false);
return M->getOrInsertFunction("llvm_gcda_start_file", FTy);
}
@@ -611,8 +614,7 @@ Constant *GCOVProfiler::getEmitArcsFunc() {
Type::getInt32Ty(*Ctx), // uint32_t num_counters
Type::getInt64PtrTy(*Ctx), // uint64_t *counters
};
- FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx),
- Args, false);
+ FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false);
return M->getOrInsertFunction("llvm_gcda_emit_arcs", FTy);
}
@@ -659,15 +661,15 @@ void GCOVProfiler::insertCounterWriteout(
for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
DICompileUnit CU(CU_Nodes->getOperand(i));
std::string FilenameGcda = mangleName(CU, "gcda");
- Builder.CreateCall(StartFile,
- Builder.CreateGlobalStringPtr(FilenameGcda));
+ Builder.CreateCall2(StartFile,
+ Builder.CreateGlobalStringPtr(FilenameGcda),
+ Builder.CreateGlobalStringPtr(Version));
for (ArrayRef<std::pair<GlobalVariable *, MDNode *> >::iterator
I = CountersBySP.begin(), E = CountersBySP.end();
I != E; ++I) {
DISubprogram SP(I->second);
- intptr_t ident = reinterpret_cast<intptr_t>(I->second);
Builder.CreateCall2(EmitFunction,
- Builder.getInt32(ident),
+ Builder.getInt32(i),
NoFunctionNamesInData ?
Constant::getNullValue(Builder.getInt8PtrTy()) :
Builder.CreateGlobalStringPtr(SP.getName()));