llvm.org GIT mirror llvm / 7a2ba2f
Only read *predecessor once so as to fix a theoretical issue where it changes between two reads (threading). Fix an off-by-one in the indirect counter table that I meant to revert after an earlier experiment. Whoops! Implement GCOV_PREFIX. Doesn't handle GCOV_PREFIX_STRIP yet. Fix an off-by-one in string emission. Extra whoops! Tolerate DISubprograms that have null Function*'s attached to them. I don't yet understand what this means, but it happens when you have a global static with a non-trivial constructor/destructor. Fix a crash on switch statements with a single successor (default-only). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130443 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Lewycky 8 years ago
2 changed file(s) with 41 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
145145 writeBytes(s.data(), s.size());
146146
147147 // Write 1 to 4 bytes of NUL padding.
148 assert((unsigned)(5 - ((s.size() + 1) % 4)) > 0);
149 assert((unsigned)(5 - ((s.size() + 1) % 4)) <= 4);
150 writeBytes("\0\0\0\0", 5 - ((s.size() + 1) % 4));
148 assert((unsigned)(4 - (s.size() % 4)) > 0);
149 assert((unsigned)(4 - (s.size() % 4)) <= 4);
150 writeBytes("\0\0\0\0", 4 - (s.size() % 4));
151151 }
152152
153153 raw_ostream *os;
262262 write(BlockLen);
263263 uint32_t Ident = reinterpret_cast((MDNode*)SP);
264264 write(Ident);
265 write(0); // checksum
265 write(0); // checksum
266266 writeGCOVString(SP.getName());
267267 writeGCOVString(SP.getFilename());
268268 write(SP.getLineNumber());
355355 DISubprogram SP(*SPI);
356356 raw_fd_ostream *&os = GcnoFiles[SP.getCompileUnit()];
357357
358 Function *F = SP.getFunction();
359 if (!F) continue;
358360 GCOVFunction Func(SP, os);
359 Function *F = SP.getFunction();
361
360362 for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
361363 GCOVBlock &Block = Func.getBlock(BB);
362364 TerminatorInst *TI = BB->getTerminator();
401403 SPE = DIF.subprogram_end(); SPI != SPE; ++SPI) {
402404 DISubprogram SP(*SPI);
403405 Function *F = SP.getFunction();
406 if (!F) continue;
404407
405408 unsigned Edges = 0;
406409 for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
470473 const Type *Int32Ty = Type::getInt32Ty(*Ctx);
471474 for (int i = 0, e = ComplexEdgePreds.size(); i != e; ++i) {
472475 IRBuilder<> Builder(ComplexEdgePreds[i+1]->getTerminator());
473 Builder.CreateStore(ConstantInt::get(Int32Ty, i+1), EdgeState);
476 Builder.CreateStore(ConstantInt::get(Int32Ty, i), EdgeState);
474477 }
475478 for (int i = 0, e = ComplexEdgeSuccs.size(); i != e; ++i) {
476479 // call runtime to perform increment
516519 for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
517520 TerminatorInst *TI = BB->getTerminator();
518521 int Successors = isa(TI) ? 1 : TI->getNumSuccessors();
519 if (Successors && !isa(TI) && !isa(TI)) {
522 if (Successors > 1 && !isa(TI) && !isa(TI)) {
520523 for (int i = 0; i != Successors; ++i) {
521524 BasicBlock *Succ = TI->getSuccessor(i);
522525 IRBuilder<> builder(Succ);
4545 write_int32(hi);
4646 }
4747
48 static char *mangle_filename(const char *orig_filename) {
49 /* TODO: handle GCOV_PREFIX_STRIP */
50 const char *prefix;
51 char *filename = 0;
52
53 prefix = getenv("GCOV_PREFIX");
54
55 if (!prefix)
56 return strdup(filename);
57
58 filename = malloc(strlen(prefix) + 1 + strlen(orig_filename) + 1);
59 strcpy(filename, prefix);
60 strcat(filename, "/");
61 strcat(filename, orig_filename);
62
63 return filename;
64 }
65
4866 /*
4967 * --- LLVM line counter API ---
5068 */
5371 * profiling enabled will emit to a different file. Only one file may be
5472 * started at a time.
5573 */
56 void llvm_gcda_start_file(const char *filename) {
57 output_file = fopen(filename, "w+");
74 void llvm_gcda_start_file(const char *orig_filename) {
75 char *filename;
76 filename = mangle_filename(orig_filename);
77 output_file = fopen(filename, "wb");
5878
5979 /* gcda file, version 404*, stamp LLVM. */
6080 fwrite("adcg*404MVLL", 12, 1, output_file);
6181
6282 #ifdef DEBUG_GCDAPROFILING
63 printf("llvmgcda: [%s]\n", filename);
83 printf("llvmgcda: [%s]\n", orig_filename);
6484 #endif
85
86 free(filename);
6587 }
6688
6789 /* Given an array of pointers to counters (counters), increment the n-th one,
7092 void llvm_gcda_increment_indirect_counter(uint32_t *predecessor,
7193 uint64_t **counters) {
7294 uint64_t *counter;
73 if (*predecessor == 0xffffffff)
95 uint32_t pred;
96
97 pred = *predecessor;
98 if (pred == 0xffffffff)
7499 return;
100 counter = counters[pred];
75101
76102 /* Don't crash if the pred# is out of sync. This can happen due to threads,
77103 or because of a TODO in GCOVProfiling.cpp buildEdgeLookupTable(). */
78 if ((counter = counters[*predecessor]))
104 if (counter)
79105 ++*counter;
80106 #ifdef DEBUG_GCDAPROFILING
81107 else