int32_t TR_ReachingBlocks::perform() { // Allocate the block info before setting the stack mark - it will be used by // the caller // initializeBlockInfo(); { TR::StackMemoryRegion stackMemoryRegion(*trMemory()); TR_Structure *rootStructure = comp()->getFlowGraph()->getStructure(); performAnalysis(rootStructure, false); } // scope of the stack memory region return 10; // actual cost }
TR_RegisterAnticipatability::TR_RegisterAnticipatability(TR::Compilation *comp, TR::Optimizer *optimizer, TR_Structure *rootStructure, TR_BitVector **regUsageInfo, bool trace) : TR_BackwardIntersectionBitVectorAnalysis(comp, comp->getFlowGraph(), optimizer, trace) { if (comp->getOption(TR_TraceShrinkWrapping)) traceMsg(comp, "Starting RegisterAnticipatability\n"); _registerUsageInfo = regUsageInfo; // Will be copied in initializeRegisterUsageInfo performAnalysis(rootStructure, false); // copy the solution from the first block of the CFG // into the dummy entry -- this is because the dummy entry // dominates every block // int32_t entryNum = comp->getStartTree()->getEnclosingBlock()->getNumber(); // dummy entry block int32_t dummyNum = comp->getFlowGraph()->getStart()->getNumber(); *_blockAnalysisInfo[dummyNum] |= *_blockAnalysisInfo[entryNum]; *_outSetInfo[dummyNum] |= *_blockAnalysisInfo[entryNum]; if (comp->getOption(TR_TraceShrinkWrapping)) { for (int32_t i = 0; i < _numberOfNodes; i++) { traceMsg(comp, "Block number : %d has solution : ", i); _blockAnalysisInfo[i]->print(comp); traceMsg(comp, "\n"); } for (int32_t i = 0; i < _numberOfNodes; i++) { traceMsg(comp, "Block number : %d has outSet : ", i); _outSetInfo[i]->print(comp); traceMsg(comp, "\n"); } traceMsg(comp, "Ending RegisterAnticipatability\n"); } }
int32_t TR_ReachingDefinitions::perform() { LexicalTimer tlex("reachingDefs_perform", comp()->phaseTimer()); if (traceRD()) traceMsg(comp(), "Starting ReachingDefinitions\n"); // Allocate the block info, allowing the bit vectors to be allocated on the fly // initializeBlockInfo(false); { TR::StackMemoryRegion stackMemoryRegion(*trMemory()); TR_Structure *rootStructure = _cfg->getStructure(); performAnalysis(rootStructure, false); if (traceRD()) traceMsg(comp(), "\nEnding ReachingDefinitions\n"); } // scope of the stack memory region return 10; // actual cost }
int main (int argc, char *argv[]) { printf("Start: %s\n", getTime()); //================================================== // define arguments and usage char *optv[MAX_ARGS] = { "-i", "-o", "-s", "-r", "-v", "-l", "-z", "-t", "-f", "-c", "-a" }; char *optd[MAX_ARGS] = {"efm file (tab separated like: 0.4\t0\t-0.24)", "output file [default: ltcs.out]", "stoichiometric matrix file [optional, needed to find internal loops]", "reaction file [optional, but necessary if option -a is set]", "reversibility file [optional, but saves memory!]", "loops output [only if stoichiometric matrix is given, default: loops.out]", "zero threshold [default: 1e-10]", "number of threads [default: 1]", "full output [yes/no; default: yes] if set to no only summary is printed and ltcs are not saved", "print ltcs in csv format [yes/no; default: yes] if set to no ltcs output will be e.g. 10011 instead of 1,0,0,1,1", "analysis output file - needs option -r"}; char *optr[MAX_ARGS]; char *description = "Calculate largest thermodynamically consistent sets of " "EFMs\nbased only on the reversibility of the reactions"; char *usg = "\n calcLtcs -i efms.txt -o ltcs.out\n calcLtcs -i efms.txt -o ltcs.out -s sfile -v rvfile -z 1e-6 -t 8 -a yes -r rfile"; // end define arguments and usage //================================================== //================================================== // read arguments readArgs(argc, argv, MAX_ARGS, optv, optr); if ( !optr[ARG_INPUT] ) { usage(description, usg, MAX_ARGS, optv, optd); quitError("Missing argument\n", ERROR_ARGS); } char* ltcsout = optr[ARG_LTCS_OUT] ? optr[ARG_LTCS_OUT] : "ltcs.out"; char* arg_rvfile = optr[ARG_RVFILE] ? optr[ARG_RVFILE] : "not available"; char* arg_sfile = optr[ARG_SFILE] ? optr[ARG_SFILE] : "not available"; char* arg_rfile = optr[ARG_RFILE] ? optr[ARG_RFILE] : "not available"; char* loopout = optr[ARG_SFILE] ? (optr[ARG_LOOPS] ? optr[ARG_LOOPS] : "loops.out") : "not available"; double threshold = optr[ARG_ZERO] ? atof(optr[ARG_ZERO]) : 1e-10; int threads = optr[ARG_THREADS] ? atoi(optr[ARG_THREADS]) : 1; int full_out = optr[ARG_FULL_OUT] ? (!strcmp(optr[ARG_FULL_OUT], "no") ? 0 : 1) : 1; int csv_out = optr[ARG_CSV_OUT] ? (!strcmp(optr[ARG_CSV_OUT], "no") ? 0 : 1) : 1; int arg_analysis = optr[ARG_ANALYSIS] ? (optr[ARG_RFILE] ? 1 : 0) : 0; char* arg_analysisfile = optr[ARG_ANALYSIS] ? optr[ARG_ANALYSIS] : "not available"; // end read arguments //================================================== //================================================== // print arguments summary printf("\n"); printf("Input: %s\n", optr[ARG_INPUT]); printf("Output: %s\n", ltcsout); printf("sfile: %s\n", arg_sfile); printf("rvfile: %s\n", arg_rvfile); printf("rfile: %s\n", arg_rfile); printf("Zero threshold: %.2e\n", threshold); printf("Threads: %d\n", threads); printf("Loops output: %s\n", full_out > 0 ? loopout : "no"); printf("Full output: %s\n", full_out > 0 ? "yes" : "no"); if (full_out > 0) { printf("csv output: %s\n", csv_out > 0 ? "yes (1,0,1,1)" : "no (1011)"); } printf("Perform analysis: %s\n", arg_analysis > 0 ? "yes" : "no"); if (arg_analysis > 0) { printf("analysis file: %s\n", arg_analysisfile); } printf("\n"); // end print arguments summary //================================================== //================================================== // check files FILE *file = fopen(optr[ARG_INPUT], "r"); FILE *fileout = NULL; FILE *fileloops = NULL; FILE *fileanalysis = NULL; if (!file) { quitError("Error in opening input file\n", ERROR_FILE); } if (full_out > 0) { fileout = fopen(ltcsout, "w"); if (!fileout) { quitError("Error in opening output file\n", ERROR_FILE); } if (optr[ARG_SFILE]) { fileloops = fopen(loopout, "w"); if (!fileloops) { quitError("Error in opening loop outputfile\n", ERROR_FILE); } } } if (arg_analysis > 0) { fileanalysis = fopen(arg_analysisfile, "w"); if (!fileanalysis) { quitError("Error in opening analysis file\n", ERROR_FILE); } } // end check files //================================================== //================================================== // read number of reactions int rx_count = getRxCount(file); fclose(file); if (rx_count < 1) { quitError("Error in EFM file format; number of reactions < 1\n", ERROR_FILE); } // end read number of reactions //================================================== //================================================== // define exchange reactions char* exchange_reaction = NULL; int s_cols = 0; if (optr[ARG_SFILE]) { defineExchangeReactions(&s_cols, &exchange_reaction, threshold, optr[ARG_SFILE]); if (s_cols != rx_count) { quitError("Error in EFM of stoichiometric file format. Number of reactions is not equal\n", ERROR_FILE); } } // end define exchange reactions //================================================== //================================================== // define reversible reactions unsigned int rev_rx_count = 0; unsigned long rev_rx_bitsize = getBitsize(rx_count); char* reversible_reactions = calloc(1, rev_rx_bitsize); int i; for (i = 0; i < rx_count; i++) { BITSET(reversible_reactions, i); } if (optr[ARG_RVFILE]) { readReversibleFile(optr[ARG_RVFILE], reversible_reactions, rx_count); } else { for (i = 0; i < rx_count; i++) { BITSET(reversible_reactions, i); } } // end define reversible reactions //================================================== //================================================== // read reaction names char** reaction_names = NULL; if (arg_analysis > 0) { readReactions(optr[ARG_RFILE], &reaction_names, rx_count); } // //================================================== //================================================== // read efm matrix char* loops = NULL; char** initial_mat = NULL; char** full_mat = NULL; unsigned long efm_count = 0; int checkLoops = optr[ARG_SFILE] ? 1 : 0; readInitialMatrix(rx_count, &efm_count, reversible_reactions, &rev_rx_count, &initial_mat, &full_mat, arg_analysis, exchange_reaction, &loops, checkLoops, 1e-8, optr[ARG_INPUT]); // end read efm matrix //================================================== //================================================== // find ltcs unsigned long ltcs_count = 0; char** ltcs = NULL; findLtcs(rev_rx_count, efm_count, initial_mat, loops, <cs, <cs_count, threads); // end find ltcs //================================================== //================================================== // filter ltcs to remove subsets printf("%s filter LTCS to remove subsets\n", getTime()); char* notAnLtcs = NULL; filterLtcs(ltcs, ¬AnLtcs, ltcs_count, efm_count); // end filter ltcs to remove subsets //================================================== //================================================== // print ltcs to file if (full_out > 0) { printf("%s save ltcs\n", getTime()); } unsigned long li; unsigned long ul; unsigned long result_ltcs_count = 0; int makeSep = 0; for (li = 0; li < ltcs_count; li++) { if (!BITTEST(notAnLtcs, li)) { makeSep = 0; result_ltcs_count++; if (full_out > 0) { for (ul = 0; ul < efm_count; ul++) { if (makeSep > 0 && csv_out > 0) { fprintf(fileout, ","); } makeSep = 1; if (BITTEST(ltcs[li],ul)) { fprintf(fileout, "1"); } else { fprintf(fileout, "0"); } } fprintf(fileout, "\n"); } } } if (full_out > 0) { fclose(fileout); } // end print ltcs to file //================================================== //================================================== // perform analysis if (arg_analysis > 0) { printf("%s perform and save analysis of LTCS\n", getTime()); double** analysis_values = NULL; performAnalysis(&analysis_values, ltcs, full_mat, reaction_names, ltcs_count, efm_count, rx_count); unsigned long lj; for (li = 0; li < rx_count; li++) { fprintf(fileanalysis, "%s", reaction_names[li]); for (lj = 0; lj < ltcs_count; lj++) { fprintf(fileanalysis, ",%.2f", analysis_values[li][lj]); } fprintf(fileanalysis, "\n"); } fclose(fileanalysis); for (li = 0; li < rx_count; li++) { free(analysis_values[li]); free(reaction_names[li]); } free(analysis_values); free(reaction_names); } // end perform analysis //================================================== //================================================== // set initial_mat memory free for (li=0; li<efm_count; li++) { if (!BITTEST(loops, li)) { free(initial_mat[li]); } } free(initial_mat); initial_mat = NULL; if (arg_analysis > 0) { for (li=0; li<efm_count; li++) { if (!BITTEST(loops, li)) { free(full_mat[li]); } } free(full_mat); full_mat = NULL; } // end set initial_mat memory free //================================================== //================================================== // count and print loops to file unsigned long loop_count = 0; if (optr[ARG_SFILE]) { if (full_out > 0) { printf("%s save internal loops\n", getTime()); for (ul = 0; ul < efm_count; ul++) { if (ul > 0 && csv_out > 0) { fprintf(fileloops, ","); } if (BITTEST(loops, ul)) { fprintf(fileloops, "1"); loop_count++; } else { fprintf(fileloops, "0"); } } fclose(fileloops); } else { for (ul = 0; ul < efm_count; ul++) { if (BITTEST(loops, ul)) { loop_count++; } } } } // end count and print loops to file //================================================== //================================================== // print summary printf("\n"); printf("Nr of EFMS: %lu\n", efm_count); printf("Nr of LTCS: %lu\n", result_ltcs_count); if (optr[ARG_SFILE]) { printf("Nr of internal loops: %lu\n", loop_count); } printf("\nSizes of LTCS:\n"); for (li = 0; li < ltcs_count; li++) { if (!BITTEST(notAnLtcs, li)) { if (li > 0) { printf(","); } printf("%lu", getLtcsCardinality(ltcs[li], efm_count)); } } printf("\n\n"); printf("End: %s\n", getTime()); // end print summary //================================================== //================================================== // set memory free free(loops); free(exchange_reaction); loops = NULL; for (li = 0; li < ltcs_count; li++) { if (!BITTEST(notAnLtcs, li)) { free(ltcs[li]); } } free(ltcs); free(notAnLtcs); ltcs = NULL; free(reversible_reactions); reversible_reactions = NULL; // end set memory free //================================================== return EXIT_SUCCESS; }