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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 class PReg: public PrintableResourceObj {
00040 protected:
00041 int16 _id;
00042 int16 _nuses, _ndefs;
00043
00044
00045 int16 _nsoftUses;
00046 LogicalAddress* _logicalAddress;
00047 static const int AvgBBIndexLen;
00048 public:
00049 static int currentNo;
00050 GrowableArray<PRegBBIndex*> dus;
00051 InlinedScope* _scope;
00052 Location loc;
00053 CPInfo* cpInfo;
00054 GrowableArray<PReg*>* cpRegs;
00055 int regClass;
00056 PReg* regClassLink;
00057 int weight;
00058
00059 GrowableArray<BlockPReg*>* _uplevelR;
00060 GrowableArray<BlockPReg*>* _uplevelW;
00061 bool debug;
00062 int _map_index_cash;
00063
00064 protected:
00065 void initialize() {
00066 _id = currentNo++;
00067 _uplevelR = _uplevelW = NULL; debug = false;
00068 _nuses = _ndefs = _nsoftUses = weight = 0;
00069 _logicalAddress = NULL;
00070 cpInfo = NULL; regClass = 0;
00071 regClassLink = 0; cpRegs = NULL;
00072 _map_index_cash = 0;
00073 }
00074 static const int VeryNegative;
00075
00076 public:
00077 PReg(InlinedScope* s) : dus(AvgBBIndexLen) {
00078 assert(s, "must have a scope");
00079 initialize(); _scope = s; loc = unAllocated;
00080 }
00081
00082 PReg(InlinedScope* s, Location l, bool incU, bool incD) : dus(AvgBBIndexLen){
00083 assert(s, "must have a scope");
00084 assert(!l.equals(illegalLocation), "illegal location");
00085 initialize(); _scope = s; loc = l;
00086 if (incU) _nuses = VeryNegative;
00087 if (incD) _ndefs = VeryNegative;
00088 }
00089
00090 int id() const { return _id; }
00091 InlinedScope* scope() const { return _scope; }
00092 virtual bool isSAPReg() const { return false; }
00093 virtual bool isArgSAPReg() const { return false; }
00094 virtual bool isSplitPReg() const { return false; }
00095 virtual bool isTempPReg() const { return false; }
00096 virtual bool isNoPReg() const { return false; }
00097 virtual bool isBlockPReg() const { return false; }
00098 virtual bool isConstPReg() const { return false; }
00099 virtual bool isMemoized() const { return false; }
00100
00101 bool uplevelR() const { return _uplevelR != NULL; }
00102 bool uplevelW() const { return _uplevelW != NULL; }
00103 void addUplevelAccessor(BlockPReg* blk, bool read, bool write);
00104 void removeUplevelAccessor(BlockPReg* blk);
00105 void removeAllUplevelAccessors();
00106
00107 virtual int begBCI() const { return PrologueBCI; }
00108 virtual int endBCI() const { return EpilogueBCI; }
00109
00110 virtual bool canCopyPropagate() const;
00111 bool incorrectDU() const { return _nuses < 0 || _ndefs < 0; }
00112 bool incorrectD() const { return _ndefs < 0; }
00113 bool incorrectU() const { return _nuses < 0; }
00114 void makeIncorrectDU(bool incU, bool incD);
00115
00116 protected:
00117
00118
00119
00120 int nuses() const { return _nuses; }
00121 int hardUses() const { return _nuses - _nsoftUses; }
00122 int ndefs() const { return _ndefs; }
00123 friend class RegisterAllocator;
00124 public:
00125 int nsoftUses() const { return _nsoftUses; }
00126 bool isUsed() const { return _ndefs || _nuses; }
00127 bool isUnused() const { return !isUsed(); }
00128 bool hasNoUses() const { return _nuses == 0; }
00129
00130
00131 virtual bool isSinglyAssigned() const { return _ndefs == 1; }
00132 bool isSinglyUsed() const { return _nuses == 1; }
00133 bool isOnlySoftUsed() const { return hardUses() == 0; }
00134
00135 void incUses(Use* use);
00136 void decUses(Use* use);
00137 void incDefs(Def* def);
00138 void decDefs(Def* def);
00139
00140
00141 Use* addUse(DUInfo* info, NonTrivialNode* n);
00142 Use* addUse(BB* bb, NonTrivialNode* n);
00143 void removeUse(DUInfo* info, Use* u);
00144 void removeUse(BB* bb, Use* u);
00145 Def* addDef(DUInfo* info, NonTrivialNode* n);
00146 Def* addDef(BB* bb, NonTrivialNode* n);
00147 void removeDef(DUInfo* info, Def* d);
00148 void removeDef(BB* bb, Def* d);
00149 virtual bool extendLiveRange(Node* n);
00150 virtual bool extendLiveRange(InlinedScope* s, int bci);
00151 void forAllDefsDo(Closure<Def*>* c);
00152 void forAllUsesDo(Closure<Use*>* c);
00153
00154 bool isLocalTo(BB* bb) const;
00155 void makeSameRegClass(PReg* other, GrowableArray<RegisterEqClass*>* classes);
00156 virtual void allocateTo(Location r);
00157
00158 virtual bool canBeEliminated(bool withUses = false) const;
00159 virtual void eliminate(bool withUses = false);
00160 bool isCPEquivalent(PReg* r) const;
00161 bool checkEquivalentDefs() const;
00162 bool slow_isLiveAt(Node* n) const;
00163 virtual bool isLiveAt(Node* n) const;
00164 protected:
00165 void addDUHelper(Node* n, SList<DefUse*>* l, DefUse* el);
00166 virtual NameNode* locNameNode(bool mustBeLegal) const;
00167 void eliminateUses(DUInfo* info, BB* bb);
00168 void eliminateDefs(DUInfo* info, BB* bb, bool removing);
00169 void updateCPInfo(NonTrivialNode* n);
00170
00171 public:
00172 virtual void print();
00173 virtual void print_short() { lprintf("%s\n", name()); }
00174 virtual char* name() const;
00175 char* safeName() const;
00176 virtual char* prefix() const { return "P"; }
00177 virtual bool verify() const;
00178 virtual NameNode* nameNode(bool mustBeLegal = true) const;
00179 LogicalAddress* createLogicalAddress();
00180 LogicalAddress* logicalAddress() const { return _logicalAddress; }
00181 PReg* cpReg() const;
00182
00183 friend InlinedScope* findAncestor(InlinedScope* s1, int& bci1,
00184 InlinedScope* s2, int& bci2);
00185
00186
00187
00188
00189 static void initPRegs();
00190 };
00191
00192
00193
00194 class TempPReg : public PReg {
00195 public:
00196 TempPReg(InlinedScope* s) : PReg(s) {}
00197 TempPReg(InlinedScope* s, Location l, bool incU, bool incD): PReg(s, l, incU, incD) {}
00198 bool isTempPReg() const { return true; }
00199 bool isLiveAt(Node* n) const { Unused(n); return false; }
00200 bool canCopyPropagate() const { return false; }
00201 char* prefix() const { return "TempP"; }
00202 };
00203
00204
00205
00206
00207 class SAPReg : public PReg {
00208 protected:
00209 InlinedScope* _creationScope;
00210 int creationStartBCI;
00211 int _begBCI, _endBCI;
00212
00213 const bool _isInContext;
00214 public:
00215 SAPReg(InlinedScope* s, int st = IllegalBCI, int en = IllegalBCI, bool inContext = false);
00216 SAPReg(InlinedScope* s, Location l, bool incU, bool incD,
00217 int st, int en) : PReg((InlinedScope*)s, l, incU, incD), _isInContext(false) {
00218 _begBCI = creationStartBCI = st; _endBCI = en; _creationScope = s;
00219 }
00220
00221 int begBCI() const { return _begBCI; }
00222 int endBCI() const { return _endBCI; }
00223 bool isInContext() const { return _isInContext; }
00224 InlinedScope* creationScope() const { return _creationScope; }
00225
00226 bool isSinglyAssigned() const { return true; }
00227 bool extendLiveRange(Node* n);
00228 bool extendLiveRange(InlinedScope* s, int bci);
00229 bool isLiveAt(Node* n) const;
00230 bool isSAPReg() const { return true; }
00231 char* prefix() const { return "SAP"; }
00232 bool verify() const;
00233 protected:
00234 bool basic_isLiveAt(InlinedScope* s, int bci) const;
00235 friend class ExprStack;
00236 };
00237
00238
00239 class BlockPReg : public SAPReg {
00240 protected:
00241 CompileTimeClosure* _closure;
00242 bool _memoized;
00243 bool _escapes;
00244 GrowableArray<Node*>* _escapeNodes;
00245 GrowableArray<PReg*>* _uplevelRead;
00246 GrowableArray<PReg*>* _uplevelWritten;
00247 GrowableArray<Location*>* _contextCopies;
00248 static int _numBlocks;
00249
00250 public:
00251 BlockPReg(InlinedScope* scope, CompileTimeClosure* closure, int beg, int end);
00252
00253 bool isBlockPReg() const { return true; }
00254 virtual NameNode* locNameNode(bool mustBeLegal) const;
00255 InlinedScope* scope() const { return (InlinedScope*)_scope; }
00256 InlinedScope* parent() const;
00257 CompileTimeClosure* closure() const { return _closure; }
00258 methodOop method() const { return _closure->method(); }
00259 static int numBlocks() { return _numBlocks; }
00260 void memoize();
00261 void markEscaped(Node* n);
00262 void markEscaped();
00263 bool isMemoized() const { return _memoized; }
00264 bool escapes() const { return _escapes; }
00265 bool canBeEliminated(bool withUses = false) const;
00266 void eliminate(bool withUses = false);
00267 void computeUplevelAccesses();
00268 GrowableArray<PReg*>* uplevelRead() const { return _uplevelRead; }
00269 GrowableArray<PReg*>* uplevelWritten() const { return _uplevelWritten; }
00270 GrowableArray<Location*>* contextCopies() const { return _contextCopies; }
00271 void addContextCopy(Location* l);
00272 char* prefix() const { return "BlkP"; }
00273 char* name() const;
00274 bool verify() const;
00275 void print();
00276
00277 friend InlinedScope* scopeFromBlockKlass(klassOop blockKlass);
00278 friend class PReg;
00279 };
00280
00281
00282 class NoPReg : public PReg {
00283 public:
00284 NoPReg(InlinedScope* scope) : PReg(scope) { loc = noRegister; initialize(); }
00285 virtual bool isNoPReg() const { return true; }
00286 bool canCopyPropagate() const { return false; }
00287 NameNode* nameNode(bool mustBeLegal) const;
00288 char* name() const { return "nil"; }
00289 bool verify() const;
00290 };
00291
00292
00293 class ConstPReg : public PReg {
00294
00295
00296
00297
00298 public:
00299 oop constant;
00300 protected:
00301 ConstPReg(InlinedScope* s, oop c) : PReg(s) {
00302 constant = c;
00303 assert(!c->is_mem() || c->is_old(), "constant must be tenured");
00304 }
00305 public:
00306 friend ConstPReg* new_ConstPReg(InlinedScope* s, oop c);
00307 friend ConstPReg* findConstPReg(Node* n, oop c);
00308 bool isConstPReg() const { return true; }
00309 void allocateTo(Location r);
00310 void extendLiveRange(InlinedScope* s);
00311 bool extendLiveRange(Node* n);
00312 bool covers(Node* n) const;
00313 bool needsRegister() const;
00314 NameNode* nameNode(bool mustBeLegal = true) const;
00315 char* prefix() const { return "ConstP"; }
00316 char* name() const;
00317 bool verify() const;
00318 };
00319
00320
00321
00322 #ifdef not_yet_used
00323
00324
00325
00326 class SplitPReg : public SAPReg {
00327 public:
00328 SplitSig* sig;
00329
00330 SplitPReg(InlinedScope* s, int st, int en, SplitSig* signature) : SAPReg(s, st, en) {
00331 sig = signature;
00332 }
00333
00334 bool isSinglyAssigned() const { return true; }
00335 bool extendLiveRange(Node* n);
00336 bool isLiveAt(Node* n) const;
00337 bool isSplitPReg() const { return true; }
00338 char* prefix() const { return "SplitP"; }
00339 char* name() const;
00340 };
00341 #endif
00342
00343
00344 # endif
00345