From 40f20d77bac07a06edc7efa03240d86bfebb33b6 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Tue, 1 Sep 2009 20:15:08 +0000 Subject: [PATCH] old and nowaday useless tool stuff [r26460] --- ir/be/tools/instrument.cpp | 123 ------------------------------------- ir/be/tools/mkrandflags.c | 35 ----------- ir/be/tools/saveinstr.c | 23 ------- 3 files changed, 181 deletions(-) delete mode 100644 ir/be/tools/instrument.cpp delete mode 100644 ir/be/tools/mkrandflags.c delete mode 100644 ir/be/tools/saveinstr.c diff --git a/ir/be/tools/instrument.cpp b/ir/be/tools/instrument.cpp deleted file mode 100644 index 3a58e48da..000000000 --- a/ir/be/tools/instrument.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/** - * Simple naive instrumentation on (x86) assembler files - * @author Matthias Braun (warning this is a 30 minutes hack and no nice code!) - * - * Takes an assembler file and adds instrumentation code to some instructions. - * You have to link the output with saveinstr.c - * - * Example usage with a file queens.s: - * - * (adapt is_instr function here to your needs and compile instrument.cpp) - * instrument < queens.s > queensi.s - * gcc queensi.s saveinstr.c -o queensi - * ./queensi (run with you desired arguments and testdata) - * instrument -a < queens.s > queens_annotated.s - * You will get a list of the hottest spots in your file and an assembler - * will the instructions prefixed with their execution count - */ -#include -#include -#include -#include -#include -#include -#include - -/** checks if we have an instruction that should be instrumented */ -bool is_instr(const char* str) -{ - if(str[0] != '\t') - return false; - if(str[1] == '.') - return false; - if(isspace(str[1])) - return false; - if(str[1] == 'c' && str[2] == 'a' && str[3] == 'l') - return true; - if(str[1] == 'j') - return true; - if(str[1] == 'p') - return true; - - return false; -} - -struct place { - int line; - unsigned int count; - - bool operator <(const place& other) const - { - return count > other.count; - } -}; - -int main(int argc, char** argv) -{ - char linebuf[2048]; - int instrcount = 0; - bool annotate = false; - std::vector places; - int line = 0; - - FILE* file = stdin; - FILE* instr = NULL; - - // annotation mode? - if(argc == 2 && std::string(argv[1]) == "-a") { - annotate = true; - instr = fopen("instr.out", "r"); - assert(instr != NULL); - } - - while(!feof(file)) { - fgets(linebuf, sizeof(linebuf), file); - line++; - if(feof(file)) - break; - - if(is_instr(linebuf)) { - if(annotate) { - place p; - p.line = line; - assert(fread(&p.count, 4, 1, instr) == 1); - printf("/* %u */ ", p.count); - - places.push_back(p); - } else { - printf("\tpushf\n"); - printf("\tinc DWORD PTR[__instr + %d]\n", (instrcount++) * 4); - printf("\tpopf\n"); - } - } - - printf("%s", linebuf); - - if(!annotate) { - if(strcmp(linebuf, "main:\n") == 0) { - printf("\tsub %%esp, 4\n" - "\tmov DWORD PTR[%%esp], OFFSET FLAT:__saveinstr\n" - "\tcall atexit\n" - "\tadd %%esp, 4\n"); - } - } - } - - if(!annotate) { - printf("\n\t.section .bss\n" - ".global __instr\n" - "__instr:\n" - "\t.space %d\n" - ".global __instrend\n" - "__instrend:\n", instrcount * 4); - } else { - std::sort(places.begin(), places.end()); - - for(int i = 0; i < 20 && i < places.size(); ++i) { - const place &p = places[i]; - fprintf(stderr, "line %d: %u\n", p.line, p.count); - } - } - - fclose(file); -} diff --git a/ir/be/tools/mkrandflags.c b/ir/be/tools/mkrandflags.c deleted file mode 100644 index 44da48b6d..000000000 --- a/ir/be/tools/mkrandflags.c +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Outputs a random set of compiler flags - * @author Matthias Braun (warning: 10 minutes hack and no nice code!) - */ -#include -#include - -const char* flags[] = { - "-fif-conv", - "-finline", - "-fcse", - "-fcode-place", - "-fgvn-pre", - "-fopt-loop-unrolling", - "-fconfirm", - "-fopt-proc-clone", - "-fno-strength-red", - "-fno-reassociation" -}; - -int main() -{ - int i; - int flagcount = sizeof(flags) / sizeof(flags[0]); - srand(time(0)); - - for(i = 0; i < flagcount; ++i) { - if(rand() % 2) { - printf("%s ", flags[i]); - } - } - printf("\n"); - - return 0; -} diff --git a/ir/be/tools/saveinstr.c b/ir/be/tools/saveinstr.c deleted file mode 100644 index af496ea4a..000000000 --- a/ir/be/tools/saveinstr.c +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Helper code to output instrumentation result (see instrument.cpp) - * @author Matthias Braun - */ -#include -#include - -extern char __instr; -extern char __instrend; - -void __saveinstr() -{ - size_t len; - FILE* f; - - f = fopen("instr.out", "w"); - assert(f != NULL); - - len = (&__instrend) - (&__instr); - assert(fwrite(&__instr, len, 1, f) == 1); - - fclose(f); -} -- 2.20.1