summaryrefslogtreecommitdiff
path: root/unsorted/OptimizerHelpers.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--unsorted/OptimizerHelpers.c166
1 files changed, 166 insertions, 0 deletions
diff --git a/unsorted/OptimizerHelpers.c b/unsorted/OptimizerHelpers.c
new file mode 100644
index 0000000..8b4bf36
--- /dev/null
+++ b/unsorted/OptimizerHelpers.c
@@ -0,0 +1,166 @@
+#include "parser.h"
+
+Boolean setOldOptimizerOptions;
+
+typedef struct {
+ Boolean commonsubs;
+ Boolean loopinvariants;
+ Boolean propagation;
+ Boolean deadstore;
+ Boolean strengthreduction;
+ Boolean deadcode;
+ Boolean lifetimes;
+} PIROptimizer; // assumed name
+
+static PIROptimizer pIrOptimizer = {0};
+
+Pragma irPragmas[] = {
+ &pIrOptimizer.commonsubs, "opt_common_subs", 0,
+ &pIrOptimizer.loopinvariants, "opt_loop_invariants", 0,
+ &pIrOptimizer.propagation, "opt_propagation", 0,
+ &pIrOptimizer.deadstore, "opt_dead_assignments", 0,
+ &pIrOptimizer.deadcode, "opt_dead_code", 0,
+ &pIrOptimizer.strengthreduction, "opt_strength_reduction", 0,
+ &pIrOptimizer.lifetimes, "opt_lifetimes", 0,
+ 0, 0, 0
+};
+
+int SetPragmaOptimizationsToUnspecified(const char *opt, void *, const char *, int) {
+ if (setOldOptimizerOptions)
+ Option_Warning(CLPStr62);
+
+ memset(&pIrOptimizer, 0, sizeof(pIrOptimizer));
+ TargetSetPragmaOptimizationsToUnspecified();
+ return 1;
+}
+
+int SetOptFlags(const char *opt, void *str, const char *, int flags) {
+ // this is very similar to ToolHelper
+ // might also fail to match
+ unsigned char *ptr;
+ Boolean set;
+ Boolean no;
+ UInt16 flag;
+
+ ptr = (unsigned char *) str;
+ no = (Boolean) ((flags & PARAMPARSEFLAGS_8) >> 3);
+ set = (Boolean) (no ^ 1);
+
+ while (*ptr) {
+ if (*ptr == '+') {
+ set = !no;
+ } else if (*ptr == '-') {
+ set = no;
+ } else if (*ptr == '|') {
+ set = (Boolean) (no ^ 1);
+ } else {
+ flag = (ptr[0] << 8) | ptr[1];
+
+ if ((flag >= 'G0' && flag <= 'G4') || (flag == 'Gs') || (flag == 'Gp'))
+ SetPragmaOptimizationsToUnspecified(opt, NULL, NULL, 0);
+
+ switch (flag) {
+ case 'Cs':
+ pIrOptimizer.commonsubs = set ? 1 : 2;
+ setOldOptimizerOptions = 1;
+ break;
+ case 'Li':
+ pIrOptimizer.loopinvariants = set ? 1 : 2;
+ setOldOptimizerOptions = 1;
+ break;
+ case 'Pr':
+ pIrOptimizer.propagation = set ? 1 : 2;
+ setOldOptimizerOptions = 1;
+ break;
+ case 'Ds':
+ pIrOptimizer.deadstore = set ? 1 : 2;
+ setOldOptimizerOptions = 1;
+ break;
+ case 'Sr':
+ pIrOptimizer.strengthreduction = set ? 1 : 2;
+ setOldOptimizerOptions = 1;
+ break;
+ case 'Dc':
+ pIrOptimizer.deadcode = set ? 1 : 2;
+ setOldOptimizerOptions = 1;
+ break;
+ case 'Lt':
+ pIrOptimizer.lifetimes = set ? 1 : 2;
+ setOldOptimizerOptions = 1;
+ break;
+ case 'G0':
+ pGlobalOptimizer.optimizationlevel = set ? 0 : 0;
+ break;
+ case 'G1':
+ pGlobalOptimizer.optimizationlevel = set ? 1 : 0;
+ break;
+ case 'G2':
+ pGlobalOptimizer.optimizationlevel = set ? 2 : 0;
+ break;
+ case 'G3':
+ pGlobalOptimizer.optimizationlevel = set ? 3 : 0;
+ break;
+ case 'G4':
+ pGlobalOptimizer.optimizationlevel = set ? 4 : 0;
+ break;
+ case 'Gs':
+ pGlobalOptimizer.optfor = set ? 1 : 0;
+ break;
+ case 'Gp':
+ pGlobalOptimizer.optfor = set ? 0 : 1;
+ break;
+ default:
+ if (!TargetSetOptFlags(flag, set))
+ CLPFatalError("Bad optimizer settings in %s (%c%c)\n", str, ptr[0], ptr[1]);
+ }
+
+ ++ptr;
+ }
+
+ ++ptr;
+ }
+
+ return 1;
+}
+
+int DisplayOptimizationOptions() {
+ SInt32 oldsize;
+ Handle h;
+
+ h = NewHandle(0);
+ if (!h)
+ exit(-23);
+
+ HPrintF(h, "\t- global optimizer level %d\n", pGlobalOptimizer.optimizationlevel);
+ HPrintF(h, "\t- global optimize for %s\n", (pGlobalOptimizer.optfor == 0) ? "speed" : "size");
+
+ oldsize = GetHandleSize(h);
+ if (pIrOptimizer.commonsubs)
+ HPrintF(h, "\t- common subexpression elimination %s\n", (pIrOptimizer.commonsubs == 1) ? "on" : "off");
+ if (pIrOptimizer.loopinvariants)
+ HPrintF(h, "\t- loop invariants %s\n", (pIrOptimizer.loopinvariants == 1) ? "on" : "off");
+ if (pIrOptimizer.commonsubs)
+ HPrintF(h, "\t- constant propagation %s\n", (pIrOptimizer.propagation == 1) ? "on" : "off");
+ if (pIrOptimizer.deadstore)
+ HPrintF(h, "\t- dead store elimination %s\n", (pIrOptimizer.deadstore == 1) ? "on" : "off");
+ if (pIrOptimizer.deadcode)
+ HPrintF(h, "\t- dead code elimination %s\n", (pIrOptimizer.deadcode == 1) ? "on" : "off");
+ if (pIrOptimizer.strengthreduction)
+ HPrintF(h, "\t- strength reduction %s\n", (pIrOptimizer.strengthreduction == 1) ? "on" : "off");
+ if (pIrOptimizer.lifetimes)
+ HPrintF(h, "\t- variable lifetimes %s\n", (pIrOptimizer.lifetimes == 1) ? "on" : "off");
+
+ if (oldsize == GetHandleSize(h))
+ HPrintF(h, "\t- no extra global optimizations\n");
+
+ HPrintF(h, "Backend-specific optimizer options:\n");
+
+ oldsize = GetHandleSize(h);
+ TargetDisplayOptimizationOptions(h);
+ if (oldsize == GetHandleSize(h))
+ HPrintF(h, "\t- no extra backend-specific optimizations\n");
+
+ ShowTextHandle(NULL, h);
+ DisposeHandle(h);
+ return 1;
+}