codeGenerator.hpp

Go to the documentation of this file.
00001 /* Copyright 1994 - 1996 LongView Technologies L.L.C. $Revision: 1.39 $ */
00002 /* Copyright (c) 2006, Sun Microsystems, Inc.
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 
00006 following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 
00010           disclaimer in the documentation and/or other materials provided with the distribution.
00011     * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 
00012           from this software without specific prior written permission.
00013 
00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 
00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
00020 
00021 
00022 */
00023 
00024 #ifdef DELTA_COMPILER
00025 
00026 class Stub;
00027 class DebugInfoWriter;
00028 
00029 class CodeGenerator: public NodeVisitor {
00030  private:
00031   MacroAssembler*       _masm;                  // the low-level assembler
00032   PRegMapping*          _currentMapping;        // currently used mapping of PRegs
00033   GrowableArray<Stub*>  _mergeStubs;            // a stack of yet to generate merge stubs
00034   DebugInfoWriter*      _debugInfoWriter;       // keeps track of PReg location changes and updates debug info
00035   int                   _maxNofStackTmps;       // the maximum number of stack allocated variables so far
00036   Node*                 _previousNode;          // the previous node in the same basic block or NULL
00037   // info used to patch temporary initialization
00038   Register              _nilReg;                // the register holding nilObj used to initialize the stack frame
00039   CodeBuffer*           _pushCode;              // the code area that can be patched with push instructions
00040 
00041  private:
00042   // Helper routines for mapping
00043   Register      def(PReg* preg) const;
00044   Register      use(PReg* preg) const           { return _currentMapping->use(preg); }
00045  
00046   void  setMapping(PRegMapping* mapping);
00047   int   maxNofStackTmps();
00048   bool  isLiveRangeBoundary(Node* a, Node* b) const;
00049   void  jmp(Node* from, Node* to, bool to_maybe_nontrivial = false);
00050   void  jcc(Assembler::Condition cc, Node* from, Node* to, bool to_maybe_nontrivial = false);
00051   void  bindLabel(Node* node);
00052   void  inlineCache(Node* call, MergeNode* nlrTestPoint, int flags = 0);
00053   void  updateDebuggingInfo(Node* node);
00054 
00055   // Helper routines for code generation
00056   char* nmethodAddress() const;
00057   void  incrementInvocationCounter();
00058   int   byteOffset(int offset);
00059   void  zapContext(PReg* context);
00060   void  storeCheck(Register obj);
00061   void  assign(PReg* dst, PReg* src, bool needsStoreCheck = true);
00062   void  uplevelBase(PReg* startContext, int nofLevels, Register base);
00063   void  moveConstant(ArithOpCode op, PReg*& x, PReg*& y, bool& x_attr, bool& y_attr);
00064   void  arithRROp(ArithOpCode op, Register x, Register y);
00065   void  arithRCOp(ArithOpCode op, Register x, int y);
00066   void  arithROOp(ArithOpCode op, Register x, oop y);
00067   void  arithRXOp(ArithOpCode op, Register x, oop y);
00068   bool  producesResult(ArithOpCode op);
00069   Register targetRegister(ArithOpCode op, PReg* z, PReg* x);
00070   Assembler::Condition mapToCC(BranchOpCode op);
00071   void  generateMergeStubs();
00072   void  copyIntoContexts(BlockCreateNode* node);
00073   void  materializeBlock(BlockCreateNode* node);
00074   void  jcc_error(Assembler::Condition cc, AbstractBranchNode* node, Label& label);
00075   void  testForSingleKlass(Register obj, klassOop klass, Register klassReg, Label& success, Label& failure);
00076   void  generateTypeTests(LoopHeaderNode* node, Label& failure);
00077   void  generateIntegerLoopTest(PReg* preg, LoopHeaderNode* node, Label& failure);
00078   void  generateIntegerLoopTests(LoopHeaderNode* node, Label& failure);
00079   void  generateArrayLoopTests(LoopHeaderNode* node, Label& failure);
00080 
00081   // Debugging
00082   static void  indent();
00083   static char* nmethodName();
00084 
00085   static void  verifyObj(oop obj);
00086   static void  verifyContext(oop obj);
00087   static void  verifyArguments(oop recv, oop* ebp, int nofArgs);
00088   static void  verifyReturn(oop result);
00089   static void  verifyNLR(char* fp, char* nlrFrame, int nlrScopeID, oop result);
00090 
00091   void callVerifyObj(Register obj);
00092   void callVerifyContext(Register context);
00093   void callVerifyArguments(Register recv, int nofArgs);
00094   void callVerifyReturn();
00095   void callVerifyNLR();
00096 
00097  public:
00098   CodeGenerator(MacroAssembler* masm, PRegMapping* mapping);
00099   Assembler* assembler() const                  { return _masm; }
00100   void initialize(InlinedScope* scope);         // call this before code generation
00101   void finalize(InlinedScope* scope);           // call this at end of code generation
00102 
00103  public:
00104   void beginOfBasicBlock(Node* node);
00105   void endOfBasicBlock(Node* node);
00106   
00107  public:
00108   void beginOfNode(Node* node);
00109   void endOfNode(Node* node);
00110   
00111  public:
00112   void aPrologueNode(PrologueNode* node);
00113 
00114   void aLoadIntNode(LoadIntNode* node);
00115   void aLoadOffsetNode(LoadOffsetNode* node);
00116   void aLoadUplevelNode(LoadUplevelNode* node);
00117 
00118   void anAssignNode(AssignNode* node);
00119   void aStoreOffsetNode(StoreOffsetNode* node);
00120   void aStoreUplevelNode(StoreUplevelNode* node);
00121   
00122   void anArithRRNode(ArithRRNode* node);
00123   void anArithRCNode(ArithRCNode* node);
00124   void aTArithRRNode(TArithRRNode* node);
00125   void aFloatArithRRNode(FloatArithRRNode* node);
00126   void aFloatUnaryArithNode(FloatUnaryArithNode* node);
00127 
00128   void aContextCreateNode(ContextCreateNode* node);
00129   void aContextInitNode(ContextInitNode* node);
00130   void aContextZapNode(ContextZapNode* node);
00131 
00132   void aBlockCreateNode(BlockCreateNode* node);
00133   void aBlockMaterializeNode(BlockMaterializeNode* node);
00134   
00135   void aSendNode(SendNode* node);
00136   void aPrimNode(PrimNode* node);
00137   void aDLLNode(DLLNode* node);
00138 
00139   void aLoopHeaderNode(LoopHeaderNode* node);
00140 
00141   void aReturnNode(ReturnNode* node);
00142   void aNLRSetupNode(NLRSetupNode* node);
00143   void anInlinedReturnNode(InlinedReturnNode* node);
00144   void aNLRContinuationNode(NLRContinuationNode* node);
00145   
00146   void aBranchNode(BranchNode* node);
00147   void aTypeTestNode(TypeTestNode* node);
00148   void aNLRTestNode(NLRTestNode* node);
00149   void aMergeNode(MergeNode* node);
00150   
00151   void anArrayAtNode(ArrayAtNode* node);
00152   void anArrayAtPutNode(ArrayAtPutNode* node);
00153 
00154   void anInlinedPrimitiveNode(InlinedPrimitiveNode* node);
00155   void anUncommonNode(UncommonNode* node);
00156   void aFixedCodeNode(FixedCodeNode* node);
00157 
00158   void aNopNode(NopNode* node) {}
00159   void aCommentNode(CommentNode* node) {}
00160 };
00161 
00162 #endif

Generated on Mon Oct 9 13:37:07 2006 for Strongtalk VM by  doxygen 1.4.7