home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / compiler / 1289 < prev    next >
Encoding:
Text File  |  1992-07-30  |  2.6 KB  |  67 lines

  1. Newsgroups: comp.compilers
  2. Path: sparky!uunet!think.com!spdcc!iecc!compilers-sender
  3. From: moss@cs.umass.edu (Eliot Moss)
  4. Subject: Re: Pros and cons of high-level intermediate languages
  5. Reply-To: moss@cs.umass.edu (Eliot Moss)
  6. Organization: Dept of Comp and Info Sci, Univ of Mass (Amherst)
  7. Date: Thu, 30 Jul 1992 00:08:32 GMT
  8. Approved: compilers@iecc.cambridge.ma.us
  9. Message-ID: <92-07-110@comp.compilers>
  10. Keywords: C, storage
  11. References: <92-07-064@comp.compilers> <92-07-089@comp.compilers>
  12. Sender: compilers-sender@iecc.cambridge.ma.us
  13. Lines: 52
  14.  
  15. graham@maths.su.oz.au (Graham Matthews) said:
  16.  
  17. > (Hans Boehm) writes:
  18. >>a) (the one I'd personally most like to see fixed) The treatment of 
  19. >>source languages that require garbage collection is tricky.
  20.  
  21. > I am not sure I understand what you are talking about here Hans.  As
  22. > far as I can see if the C code you produce is not safe in the presence
  23. > of garbage collection then you are generating incorrect C code. There
  24. > is nothing in C that makes it "garbage collection unsafe" even with a
  25. > non-conservative garbage collection.
  26.  
  27. Suppose we have something like the following code:
  28.  
  29.     int *p, *q;
  30.     int i;
  31.     for (i = 0; i < 100; i++)
  32.        p[i] = q[i];
  33.  
  34. Since C compilers are generally written assuming that allocated things do
  35. not move during execution, we might get code like this for a machine
  36. supporting two index registers in an addressing mode:
  37.  
  38.     ld rp,p        ; rp <- p
  39.     addi rl,rp,400    ; rl <- p + 100 * 4  (4 byte integers)
  40.     ld rq,q        ; rq <- q
  41.     sub rq,rq,rp    ; rq <- rq - rp
  42. label:    ld rx,0(rp,0)    ; rx <- p[i]
  43.     st rx,0(rp,rq)    ; q[i] <- rx
  44.     addi rp,rp,4    ; rp <- rp + 4
  45.     blt rp,rl,label    ; loop if rp < rl (rl = the limit)
  46.  
  47. This appears to be perfectly legal code, yet it is possible that no
  48. pointer to q exists, and we might gc (you might argue not in this case,
  49. but I can add a call in the loop or something and fix that, or we can say
  50. there are multiple threads and another thread causes gc).
  51.  
  52. This is the kind of subtle transformation that Hans was referring to. Note
  53. that the transformation here improves performance by reducing the number
  54. of items that need to be kept in registers from 3 (i, p, q) to 2 (p and
  55. q-p) and requires only one increment around the loop. Strength reduction
  56. and induction variable elimination definitely head this way.
  57. --
  58.         J. Eliot B. Moss, Associate Professor
  59.         Department of Computer Science
  60.         Lederle Graduate Research Center
  61.         University of Massachusetts
  62.         Amherst, MA  01003
  63.         (413) 545-4206, 545-1249 (fax); Moss@cs.umass.edu
  64. -- 
  65. Send compilers articles to compilers@iecc.cambridge.ma.us or
  66. {ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
  67.