00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef DELTA_COMPILER
00025
00026
00027
00028 class PRegClosure: public PrintableResourceObj {
00029 public:
00030 virtual void preg_do(PReg* preg) {}
00031 };
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 class PRegMapping: public PrintableResourceObj {
00045 private:
00046 MacroAssembler* _assm;
00047 bool _NLRinProgress;
00048 Locations* _locs;
00049 GrowableArray<PReg*>* _pregs;
00050 GrowableArray<int>* _regLocs;
00051 GrowableArray<int>* _stkLocs;
00052 GrowableArray<int>* _tmpLocs;
00053
00054
00055
00056 int size() const { return _pregs->length(); }
00057 bool used(int i) const { return _pregs->at(i) != NULL; }
00058 int regLoc(int i) const { return _regLocs->at(i); }
00059 int stkLoc(int i) const { return _stkLocs->at(i); }
00060 bool hasRegLoc(int i) const { return _locs->isLocation(regLoc(i)); }
00061 bool hasStkLoc(int i) const { return _locs->isLocation(stkLoc(i)); }
00062 int location(int i) const { int rloc = regLoc(i); return rloc >= 0 ? rloc : stkLoc(i); }
00063 void set_entry(int i, PReg* preg, int rloc, int sloc);
00064 int index(PReg* preg);
00065 int freeSlot();
00066 void print(int i);
00067 void destroy();
00068
00069
00070 int spillablePRegIndex();
00071 void ensureOneFreeRegister();
00072 void spillRegister(int loc);
00073 void saveRegister(int loc);
00074
00075
00076 int allocateTemporary(Register hint = noreg);
00077 void releaseTemporary(int regLoc);
00078 void releaseAllTemporaries();
00079
00080
00081 void old_makeConformant(PRegMapping* with);
00082 void new_makeConformant(PRegMapping* with);
00083
00084 public:
00085
00086 PRegMapping(MacroAssembler* assm, int nofArgs, int nofRegs, int nofTemps);
00087 PRegMapping(PRegMapping* m);
00088
00089 MacroAssembler* assembler() const { return _assm; }
00090
00091
00092 bool isInjective();
00093 bool isConformant(PRegMapping* with);
00094 bool isDefined(PReg* preg) { return index(preg) >= 0; }
00095 bool inRegister(PReg* preg) { int i = index(preg); return used(i) && hasRegLoc(i); }
00096 bool onStack(PReg* preg) { int i = index(preg); return used(i) && hasStkLoc(i); }
00097
00098
00099 void mapToArgument(PReg* preg, int argNo);
00100 void mapToRegister(PReg* preg, Register reg);
00101 void mapToTemporary(PReg* preg, int tempNo);
00102
00103 void kill(PReg* preg);
00104 void killDeadsAt(Node* node, PReg* exception = NULL);
00105 void killAll(PReg* exception = NULL);
00106 void cleanupContextReferences();
00107
00108
00109 Register def(PReg* preg, Register hint = noreg);
00110 Register use(PReg* preg, Register hint);
00111 Register use(PReg* preg);
00112
00113
00114 void move(PReg* dst, PReg* src);
00115
00116
00117 void saveRegisters(PReg* exception = NULL);
00118 void killRegisters(PReg* exception = NULL);
00119 void killRegister (PReg* preg);
00120
00121
00122 bool NLRinProgress() const { return _NLRinProgress; }
00123 void acquireNLRRegisters();
00124 void releaseNLRRegisters();
00125
00126
00127 void makeInjective();
00128 void makeConformant(PRegMapping* with);
00129
00130
00131 void iterate(PRegClosure* closure);
00132 Location locationFor(PReg* preg);
00133
00134
00135 int nofPRegs();
00136 int maxNofStackTmps();
00137
00138
00139 void my_print();
00140 void print();
00141 void verify();
00142
00143 friend class Temporary;
00144 };
00145
00146
00147
00148
00149
00150
00151
00152 class PRegLocker: StackObj {
00153 private:
00154 static PRegLocker* _top;
00155 PRegLocker* _prev;
00156 PReg* _pregs[3];
00157
00158 void lock(PReg* r0, PReg* r1, PReg* r2) { _prev = _top; _top = this; _pregs[0] = r0; _pregs[1] = r1; _pregs[2] = r2; }
00159 bool holds(PReg* preg) const;
00160
00161 public:
00162 PRegLocker(PReg* r0);
00163 PRegLocker(PReg* r0, PReg* r1);
00164 PRegLocker(PReg* r0, PReg* r1, PReg* r2);
00165 ~PRegLocker() { _top = _prev; }
00166
00167
00168 static bool locks(PReg* preg);
00169 static void initialize() { _top = NULL; }
00170 friend class PRegMapping;
00171 };
00172
00173
00174
00175
00176
00177 class Temporary: StackObj {
00178 private:
00179 PRegMapping* _mapping;
00180 int _regLoc;
00181
00182 public:
00183 Temporary(PRegMapping* mapping, Register hint = noreg);
00184 Temporary(PRegMapping* mapping, PReg* preg);
00185 ~Temporary();
00186
00187 Register reg() const { return _mapping->_locs->locationAsRegister(_regLoc); }
00188 };
00189
00190
00191 #endif