dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dotgnu-pnet-commits] pnet ChangeLog codegen/cg_lvalue.tc codegen/cg_...


From: Klaus Treichel
Subject: [dotgnu-pnet-commits] pnet ChangeLog codegen/cg_lvalue.tc codegen/cg_...
Date: Fri, 02 Jan 2009 14:33:07 +0000

CVSROOT:        /cvsroot/dotgnu-pnet
Module name:    pnet
Changes by:     Klaus Treichel <ktreichel>      09/01/02 14:33:07

Modified files:
        .              : ChangeLog 
        codegen        : cg_lvalue.tc cg_misc.tc cg_nodes.tc jv_misc.tc 
        cscc/c         : c_name.tc c_stubs.tc 
        cscc/csharp    : cs_oper.tc 

Log message:
        Optimize code generation of value type assignment from a new expression.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3598&r2=1.3599
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_lvalue.tc?cvsroot=dotgnu-pnet&r1=1.29&r2=1.30
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_misc.tc?cvsroot=dotgnu-pnet&r1=1.53&r2=1.54
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_nodes.tc?cvsroot=dotgnu-pnet&r1=1.95&r2=1.96
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/jv_misc.tc?cvsroot=dotgnu-pnet&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/c/c_name.tc?cvsroot=dotgnu-pnet&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/c/c_stubs.tc?cvsroot=dotgnu-pnet&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_oper.tc?cvsroot=dotgnu-pnet&r1=1.54&r2=1.55

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3598
retrieving revision 1.3599
diff -u -b -r1.3598 -r1.3599
--- ChangeLog   30 Dec 2008 14:41:54 -0000      1.3598
+++ ChangeLog   2 Jan 2009 14:33:05 -0000       1.3599
@@ -1,3 +1,32 @@
+2009-01-02  Klaus Treichel  <address@hidden>
+
+       * codegen/cg_lvalue.tc (ILNode_GenRef(ILNode_Deref)): Add code 
generation
+       for getting the address of of a dreferencing node.
+
+       * codegen/cg_misc.tc: Add support operations for the new node types
+       ILNode_RefInit and ILNode_RefValueTypeCreationExpression.
+
+       * codegen/cg_nodes.tc: Add node types ILNode_RefInit and
+       ILNode_RefValueTypeCreationExpression for optimizing initialization of
+       value types (structs) where the target is a node where a reference can 
be
+       computed.
+       Change parent of ILNode_Deref from ILNode_LValueNoRef to ILNode_LValue.
+
+       * codegen/jv_misc.tc: Stub out JavaGenValue operation for the new node
+       types ILNode_RefInit and ILNode_RefValueTypeCreationExpression.
+
+       * cscc/c/c_name.tc, cscc/c/c_stubs.tc: Stub out operations for the new
+       node types ILNode_RefInit and ILNode_RefValueTypeCreationExpression.
+
+       * cscc/csharp/cs_oper.tc (ILNode_SemAnalysis(ILNode_Assign)): Optimize
+       assignment to a value type from a new expression if a reference to the
+       target can be computed.
+       Stub out operations for the new node types ILNode_RefInit and
+       ILNode_RefValueTypeCreationExpression because they will never be
+       semanalyzed.
+       (ILNode_SemAnalysis(ILNode_AddressOf)): Add a check if the address of 
the
+       expression can be computed.
+
 2008-12-30  Klaus Treichel  <address@hidden>
 
        * codegen/cg_arith.tc (ReduceOperator): Add more basic optimizations and

Index: codegen/cg_lvalue.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_lvalue.tc,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- codegen/cg_lvalue.tc        18 Nov 2008 20:06:03 -0000      1.29
+++ codegen/cg_lvalue.tc        2 Jan 2009 14:33:06 -0000       1.30
@@ -4,7 +4,7 @@
 /*
  * cg_lvalue.tc - Identifier and l-value nodes.
  *
- * Copyright (C) 2001, 2008  Southern Storm Software, Pty Ltd.
+ * Copyright (C) 2001, 2008, 2009  Southern Storm Software, Pty Ltd.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -1541,6 +1541,16 @@
 }
 
 /*
+ * Generate reference code for a dereference expression.
+ */
+ILNode_GenRef(ILNode_Deref)
+{
+       /* Evaluate the pointer expression */
+       ILGenCast(info, ILNode_GenValue(node->expr, info),
+                         ILMachineType_UnmanagedPtr);
+}
+
+/*
  * Declare operations that can be used to manage identifiers.
  */
 %decls %end %{

Index: codegen/cg_misc.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_misc.tc,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -b -r1.53 -r1.54
--- codegen/cg_misc.tc  14 Dec 2008 13:03:34 -0000      1.53
+++ codegen/cg_misc.tc  2 Jan 2009 14:33:06 -0000       1.54
@@ -4,7 +4,7 @@
 /*
  * cg_misc.tc - Miscellaneous operator nodes.
  *
- * Copyright (C) 2001  Southern Storm Software, Pty Ltd.
+ * Copyright (C) 2001, 2009  Southern Storm Software, Pty Ltd.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -159,6 +159,23 @@
 }
 
 /*
+ * Get the type of a value type initialization
+ */
+ILNode_GetType(ILNode_RefInit)
+{
+       return ILTypeToMachineType(node->type);
+}
+
+/*
+ * Get the type of a value type constructor call with the reference passed
+ * as argument 1 and emitted like a normal method call.
+ */
+ILNode_GetType(ILNode_RefValueTypeCreationExpression)
+{
+       return ILTypeToMachineType(node->type);
+}
+
+/*
  * Get the type of a method invocation.
  */
 ILNode_GetType(ILNode_InvocationExpression)
@@ -597,6 +614,49 @@
 }
 
 /*
+ * Generate the discard code for a reference initialization.
+ */
+ILNode_GenDiscard(ILNode_RefInit)
+{
+       ILNode_GenRef(node->expr, info);
+       ILGenTypeToken(info, IL_PREFIX_OP_INITOBJ + IL_OP_PREFIX,
+                                  node->type);
+       ILGenAdjust(info, -1);
+}
+
+/*
+ * Generate the discard code for a value type constructor call with the
+ * reference passed as argument 1 and emitted like a normal method call.
+ */
+ILNode_GenDiscard(ILNode_RefValueTypeCreationExpression)
+{
+       long saveStack;
+
+       /* Save the current stack height, so we know where to
+          unwind to when popping the arguments */
+       saveStack = info->stackHeight;
+
+       /* Push a reference to the value to be initialized on the stack */
+       ILNode_GenRef(node->expr, info);
+
+       /* Push the argument expressions */
+       if(node->argList)
+       {
+               ILNode_GenValue(node->argList, info);
+       }
+
+       /* Invoke the constructor */
+       ILGenCallByMethodSig(info, node->methodInfo, node->callSiteSig);
+
+       /* Re-adjust the stack to remove the arguments and push the result */
+       info->stackHeight = saveStack;
+       if(info->stackHeight > info->maxStackHeight)
+       {
+               info->maxStackHeight = info->stackHeight;
+       }
+}
+
+/*
  * Generate value code for a comma expression.
  */
 ILNode_GenValue(ILNode_Comma)
@@ -1394,6 +1454,64 @@
        return type;
 }
 
+/*
+ * Generate the value code for a reference initialization.
+ */
+ILNode_GenValue(ILNode_RefInit)
+{
+       ILNode_GenRef(node->expr, info);
+       ILGenSimple(info, IL_OP_DUP);
+       ILGenAdjust(info, 1);
+       ILGenTypeToken(info, IL_PREFIX_OP_INITOBJ + IL_OP_PREFIX,
+                                  node->type);
+       ILGenAdjust(info, -1);
+       ILGenTypeToken(info, IL_OP_LDOBJ, node->type);
+
+       return ILTypeToMachineType(node->type);
+}
+
+/*
+ * Generate value code for a value type constructor call with the reference
+ * passed as argument 1 and emitted like a normal method call.
+ */
+ILNode_GenValue(ILNode_RefValueTypeCreationExpression)
+{
+       long saveStack;
+
+       /* Save the current stack height, so we know where to
+          unwind to when popping the arguments */
+       saveStack = info->stackHeight;
+
+       /* Push a reference to the value to be initialized on the stack */
+       ILNode_GenRef(node->expr, info);
+
+       /* Duplicate the reference which will be used by the call */
+       ILGenSimple(info, IL_OP_DUP);
+       ILGenAdjust(info, 1);
+
+       /* Push the argument expressions */
+       if(node->argList)
+       {
+               ILNode_GenValue(node->argList, info);
+       }
+
+       /* Invoke the constructor */
+       ILGenCallByMethodSig(info, node->methodInfo, node->callSiteSig);
+
+       /* Re-adjust the stack to remove the arguments and push the result */
+       info->stackHeight = saveStack + 1;
+       if(info->stackHeight > info->maxStackHeight)
+       {
+               info->maxStackHeight = info->stackHeight;
+       }
+
+       /* The first reference is now on the stack */
+       /* Load the value just initialized */
+       ILGenLoadManaged(info, ILTypeToMachineType(node->type), node->type);
+
+       return ILMachineType_ManagedValue;
+}
+
 %decls %end %{
 
 /*

Index: codegen/cg_nodes.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_nodes.tc,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -b -r1.95 -r1.96
--- codegen/cg_nodes.tc 25 Dec 2008 13:14:16 -0000      1.95
+++ codegen/cg_nodes.tc 2 Jan 2009 14:33:06 -0000       1.96
@@ -5,7 +5,7 @@
 /*
  * cg_nodes.tc - Declare common nodes and operations.
  *
- * Copyright (C) 2001  Southern Storm Software, Pty Ltd.
+ * Copyright (C) 2001, 2009  Southern Storm Software, Pty Ltd.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -413,7 +413,7 @@
        ILType *arrayType;
 }
 %node ILNode_Conditional ILNode_TernaryExpression
-%node ILNode_Deref ILNode_LValueNoRef =
+%node ILNode_Deref ILNode_LValue =
 {
        ILNode *expr;
        ILType *elemType;
@@ -500,6 +500,19 @@
        ILType     *type;
        int                     useCtorMethod;
 }
+%node ILNode_RefInit ILNode_Expression =
+{
+       ILNode     *expr;
+       ILType     *type;
+}
+%node ILNode_RefValueTypeCreationExpression ILNode_Expression =
+{
+       ILNode     *expr;
+       ILType     *type;
+       %nocreate ILNode   *argList = {0};
+       %nocreate ILMethod *methodInfo = {0};
+       %nocreate ILType   *callSiteSig = {0};
+}
 
 /*
  * Method invocation expressions.

Index: codegen/jv_misc.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/jv_misc.tc,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- codegen/jv_misc.tc  14 Dec 2008 13:03:35 -0000      1.33
+++ codegen/jv_misc.tc  2 Jan 2009 14:33:06 -0000       1.34
@@ -1,7 +1,7 @@
 /*
  * jv_misc.tc - Miscellaneous operator nodes.
  *
- * Copyright (C) 2001  Southern Storm Software, Pty Ltd.
+ * Copyright (C) 2001, 2009  Southern Storm Software, Pty Ltd.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -1571,6 +1571,25 @@
        return type;
 }
 
+/*
+ * Generate the value code for a reference initialization.
+ */
+JavaGenValue(ILNode_RefInit)
+{
+       /* Reference initialization is not yet supported in Java */
+       return ILTypeToMachineType(node->type);
+}
+
+/*
+ * Generate value code for a value type constructor call with the reference
+ * passed as argument 1 and emitted like a normal method call.
+ */
+JavaGenValue(ILNode_RefValueTypeCreationExpression)
+{
+       /* Invoking constructors this way is not yet supported in Java */
+       return ILTypeToMachineType(node->type);
+}
+
 %decls %end %{
 
 /*

Index: cscc/c/c_name.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_name.tc,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- cscc/c/c_name.tc    14 Dec 2008 13:03:35 -0000      1.4
+++ cscc/c/c_name.tc    2 Jan 2009 14:33:06 -0000       1.5
@@ -2,7 +2,7 @@
  * c_name.tc - Convert expressions into names suitable for embedding
  *             in array types.
  *
- * Copyright (C) 2004  Southern Storm Software, Pty Ltd.
+ * Copyright (C) 2004, 2009  Southern Storm Software, Pty Ltd.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -226,6 +226,8 @@
 ILNode_CName(ILNode_ObjectCreationExpression),
 ILNode_CName(ILNode_DelegateCreationExpression),
 ILNode_CName(ILNode_DefaultConstructor),
+ILNode_CName(ILNode_RefInit),
+ILNode_CName(ILNode_RefValueTypeCreationExpression),
 ILNode_CName(ILNode_InvocationExpression),
 ILNode_CName(ILNode_CSharpInvocation),
 ILNode_CName(ILNode_BaseInit),

Index: cscc/c/c_stubs.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_stubs.tc,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- cscc/c/c_stubs.tc   1 Mar 2004 04:29:23 -0000       1.17
+++ cscc/c/c_stubs.tc   2 Jan 2009 14:33:06 -0000       1.18
@@ -1,7 +1,7 @@
 /*
  * c_stubs.tc - Stub out codegen nodes that we don't require.
  *
- * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
+ * Copyright (C) 2002, 2009  Southern Storm Software, Pty Ltd.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -80,6 +80,8 @@
 ILNode_CSemAnalysis(ILNode_ObjectCreationExpression),
 ILNode_CSemAnalysis(ILNode_DelegateCreationExpression),
 ILNode_CSemAnalysis(ILNode_DefaultConstructor),
+ILNode_CSemAnalysis(ILNode_RefInit),
+ILNode_CSemAnalysis(ILNode_RefValueTypeCreationExpression),
 ILNode_CSemAnalysis(ILNode_BaseInit),
 ILNode_CSemAnalysis(ILNode_ThisInit),
 ILNode_CSemAnalysis(ILNode_NonStaticInit),
@@ -126,6 +128,7 @@
 ILNode_CGenAddress(ILNode_MemberField),
 ILNode_CGenAddress(ILNode_ArrayAccess),
 ILNode_CGenAddress(ILNode_DerefField),
+ILNode_CGenAddress(ILNode_Deref),
 ILNode_CGenAddress(ILNode_MemberAccess),
 ILNode_CGenAddress(ILNode_This)
 {

Index: cscc/csharp/cs_oper.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_oper.tc,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -b -r1.54 -r1.55
--- cscc/csharp/cs_oper.tc      30 Dec 2008 14:41:55 -0000      1.54
+++ cscc/csharp/cs_oper.tc      2 Jan 2009 14:33:06 -0000       1.55
@@ -1,7 +1,7 @@
 /*
  * cs_oper.tc - Semantic analysis for C# operators.
  *
- * Copyright (C) 2001, 2002  Southern Storm Software, Pty Ltd.
+ * Copyright (C) 2001, 2002, 2009  Southern Storm Software, Pty Ltd.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -1062,11 +1062,72 @@
        ILCoerce(info, node->expr2, &(node->expr2),
                         CSSemGetType(value2), CSSemGetType(value1),1);
 
+       /* Check if this is an assignment to a value type (struct) */
+       if(!info->outputIsJava && ILType_IsValueType(CSSemGetType(value1)) &&
+          !ILTypeIsEnum(CSSemGetType(value1)))
+       {
+               ILNode *expr = 0;
+
+               /* Check if we can get a reference to the assignment target */
+               if(yyisa(node->expr1, ILNode_LValue) &&
+                  !yyisa(node->expr1, ILNode_LValueNoRef))
+               {
+                       expr = node->expr1;
+               }
+               if(expr)
+               {
+                       if(yyisa(node->expr2, ILNode_DefaultConstructor))
+                       {
+                               *parent = ILNode_RefInit_create(expr, 
CSSemGetType(value1));
+                       }
+                       else if(yyisa(node->expr2, 
ILNode_ObjectCreationExpression))
+                       {
+                               ILNode_RefValueTypeCreationExpression *newNode;
+                               ILNode_ObjectCreationExpression *createExpr;
+
+                               createExpr = (ILNode_ObjectCreationExpression 
*)(node->expr2);
+                               newNode = 
(ILNode_RefValueTypeCreationExpression *)
+                                                       
ILNode_RefValueTypeCreationExpression_create
+                                                               (expr, 
CSSemGetType(value1));
+                               newNode->argList = createExpr->argList;
+                               newNode->methodInfo = createExpr->methodInfo;
+                               newNode->callSiteSig = createExpr->callSiteSig;
+
+                               *parent = (ILNode *)newNode;
+                       }
+               }
+       }
+
        /* Convert value1 into an rvalue and return its type */
        CSSemSetRValue(value1, CSSemGetType(value1));
        return value1;
 }
 
+/*
+ * semantic analysis for a reference initialization.
+ */
+ILNode_SemAnalysis(ILNode_RefInit)
+{
+       /*
+        * This node is created during semanalyzing an assignment.
+        * So it will never be semanalyzed directly.
+        */
+       return CSSemValueDefault;
+}
+
+/*
+ * semantic analysis for a value type constructor call with the reference
+ * passed as argument 1 and emitted like a normal method call.
+ */
+ILNode_SemAnalysis(ILNode_RefValueTypeCreationExpression)
+{
+       /*
+        * This node is created during semanalyzing an assignment.
+        * So it will never be semanalyzed directly.
+        */
+       return CSSemValueDefault;
+}
+
 %{
 
 /*
@@ -2304,6 +2365,12 @@
                   extra layer and use the pointer directly as the address */
                *parent = ((ILNode_Deref *)(node->expr))->expr;
        }
+       else if(!yyisa(node->expr, ILNode_LValue) ||
+                       yyisa(node->expr, ILNode_LValueNoRef))
+       {
+               
CCErrorOnLine(yygetfilename(node->expr),yygetlinenum(node->expr),
+                                         "cannot get address of expression");
+       }
        CSSemSetRValue(value,ILTypeCreateRef(info->context,
                                                        IL_TYPE_COMPLEX_PTR,
                                                        CSSemGetType(value)));




reply via email to

[Prev in Thread] Current Thread [Next in Thread]