Hi, Just to add to the list of suggestions...
I don't think there is a specific pass but, depending on your application, the following might work and is fairly simple. 1) Use a visitor to identify all variables whose address is taken. 2) Use a visitor to identify all variables which have precisely one assignment to them and, of those, which are of the form 'v1 = &v2'. This is the list of variables that are guaranteed to have precisely one 'pseudo-constant' value assigned to them. (You could generalise by looking for 'v = const_expression' too.) 3) Make a list of pairs [(v1,v2); ...] where v1 is not in list (1) and 'v1 = &v2' is in list (2). That is, we look for assignments 'v1 = &v2' where - the address of v1 is not taken - this is the only assignment to v1 4) Use a visitor to replace assignments of the form '*v1' with 'v2'. (Can probably replace all lvals of the form '*v1'??) This will give the correct result provided the variable is initialized before it is used. If the variable is used before it is initialized, it will give a better defined answer than the original program. Whether this is acceptable depends on whether you are optimizing code (acceptable) or trying to detect errors (unacceptable). -- Alastair Reid, Principal Engineer, R&D ARM Ltd, 110 Fulbourn Rd, Cambridge, CB1 9NJ. T: +44 1223 406 109 -----Original Message----- From: Benjamin Ylvisaker [mailto:benjam...@fastmail.fm] Sent: 09 September 2009 06:34 To: CIL Mailing List Subject: [CIL users] optimizations with pointers Does anyone know if there is any existing optimization in Cil that will do the translation of int a; int *b = &a; *b = 4; ... into int a; int *b = &a; a = 4; ... ? Thanks, Ben ------------------------------------------------------------------------ ------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ CIL-users mailing list CIL-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/cil-users -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ CIL-users mailing list CIL-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/cil-users