lcm.c 22.3 KB
Newer Older
Jeffrey A Law committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799
/* Generic partial redundancy elimination with lazy code motion
   support.
   Copyright (C) 1998 Free Software Foundation, Inc.

This file is part of GNU CC.

GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING.  If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */

/* These routines are meant to be used by various optimization
   passes which can be modeled as lazy code motion problems. 
   Including, but not limited to:

	* Traditional partial redundancy elimination.

	* Placement of caller/caller register save/restores.

	* Load/store motion.

	* Copy motion.

	* Conversion of flat register files to a stacked register
	model.

	* Dead load/store elimination.

  These routines accept as input:

	* Basic block information (number of blocks, lists of
	predecessors and successors).  Note the granularity
	does not need to be basic block, they could be statements
	or functions.

	* Bitmaps of local properties (computed, transparent and
	anticipatable expressions).

  The output of these routines is bitmap of redundant computations
  and a bitmap of optimal placement points.  */


#include "config.h"
#include "system.h"

#include "rtl.h"
#include "regs.h"
#include "hard-reg-set.h"
#include "flags.h"
#include "real.h"
#include "insn-config.h"
#include "recog.h"
#include "basic-block.h"

static void compute_antinout 	PROTO ((int, int_list_ptr *, sbitmap *,
					sbitmap *, sbitmap *, sbitmap *));
static void compute_earlyinout	PROTO ((int, int, int_list_ptr *, sbitmap *,
					sbitmap *, sbitmap *, sbitmap *));
static void compute_delayinout  PROTO ((int, int, int_list_ptr *, sbitmap *,
					sbitmap *, sbitmap *,
					sbitmap *, sbitmap *));
static void compute_latein	PROTO ((int, int, int_list_ptr *, sbitmap *,
					sbitmap *, sbitmap *));
static void compute_isoinout	PROTO ((int, int_list_ptr *, sbitmap *,
					sbitmap *, sbitmap *, sbitmap *));
static void compute_optimal	PROTO ((int, sbitmap *,
					sbitmap *, sbitmap *));
static void compute_redundant	PROTO ((int, int, sbitmap *,
					sbitmap *, sbitmap *, sbitmap *));

/* Similarly, but for the reversed flowgraph.  */
static void compute_avinout 	PROTO ((int, int_list_ptr *, sbitmap *,
					sbitmap *, sbitmap *, sbitmap *));
static void compute_fartherinout	PROTO ((int, int, int_list_ptr *,
						sbitmap *, sbitmap *,
						sbitmap *, sbitmap *));
static void compute_earlierinout  PROTO ((int, int, int_list_ptr *, sbitmap *,
					  sbitmap *, sbitmap *,
					  sbitmap *, sbitmap *));
static void compute_firstout	PROTO ((int, int, int_list_ptr *, sbitmap *,
					sbitmap *, sbitmap *));
static void compute_rev_isoinout PROTO ((int, int_list_ptr *, sbitmap *,
					 sbitmap *, sbitmap *, sbitmap *));

/* Given local properties TRANSP, ANTLOC, return the redundant and optimal
   computation points for expressions.

   To reduce overall memory consumption, we allocate memory immediately
   before its needed and deallocate it as soon as possible.  */
void
pre_lcm (n_blocks, n_exprs, s_preds, s_succs, transp,
	 antloc, redundant, optimal)
     int n_blocks;
     int n_exprs;
     int_list_ptr *s_preds;
     int_list_ptr *s_succs;
     sbitmap *transp;
     sbitmap *antloc;
     sbitmap *redundant;
     sbitmap *optimal;
{
  sbitmap *antin, *antout, *earlyin, *earlyout, *delayin, *delayout;
  sbitmap *latein, *isoin, *isoout;

  /* Compute global anticipatability.  ANTOUT is not needed except to
     compute ANTIN, so free its memory as soon as we return from
     compute_antinout.  */
  antin = sbitmap_vector_alloc (n_blocks, n_exprs);
  antout = sbitmap_vector_alloc (n_blocks, n_exprs);
  compute_antinout (n_blocks, s_succs, antloc,
		    transp, antin, antout);
  free (antout);
  antout = NULL;

  /* Compute earliestness.  EARLYOUT is not needed except to compute
     EARLYIN, so free its memory as soon as we return from
     compute_earlyinout.  */
  earlyin = sbitmap_vector_alloc (n_blocks, n_exprs);
  earlyout = sbitmap_vector_alloc (n_blocks, n_exprs);
  compute_earlyinout (n_blocks, n_exprs, s_preds, transp, antin,
		      earlyin, earlyout);
  free (earlyout);
  earlyout = NULL;

  /* Compute delayedness.  DELAYOUT is not needed except to compute
     DELAYIN, so free its memory as soon as we return from
     compute_delayinout.  We also no longer need ANTIN and EARLYIN.  */
  delayin = sbitmap_vector_alloc (n_blocks, n_exprs);
  delayout = sbitmap_vector_alloc (n_blocks, n_exprs);
  compute_delayinout (n_blocks, n_exprs, s_preds, antloc,
		      antin, earlyin, delayin, delayout);
  free (delayout);
  delayout = NULL;
  free (antin);
  antin = NULL;
  free (earlyin);
  earlyin = NULL;

  /* Compute latestness.  We no longer need DELAYIN after we compute
     LATEIN.  */
  latein = sbitmap_vector_alloc (n_blocks, n_exprs);
  compute_latein (n_blocks, n_exprs, s_succs, antloc, delayin, latein);
  free (delayin);
  delayin = NULL;

  /* Compute isolatedness.  ISOIN is not needed except to compute
     ISOOUT, so free its memory as soon as we return from
     compute_isoinout.  */
  isoin = sbitmap_vector_alloc (n_blocks, n_exprs);
  isoout = sbitmap_vector_alloc (n_blocks, n_exprs);
  compute_isoinout (n_blocks, s_succs, antloc, latein, isoin, isoout);
  free (isoin);
  isoin = NULL;

  /* Now compute optimal placement points and the redundant expressions.  */
  compute_optimal (n_blocks, latein, isoout, optimal);
  compute_redundant (n_blocks, n_exprs, antloc, latein, isoout, redundant);
  free (latein);
  latein = NULL;
  free (isoout);
  isoout = NULL;
}

/* Given local properties TRANSP, AVLOC, return the redundant and optimal
   computation points for expressions on the reverse flowgraph.

   To reduce overall memory consumption, we allocate memory immediately
   before its needed and deallocate it as soon as possible.  */

void
pre_rev_lcm (n_blocks, n_exprs, s_preds, s_succs, transp,
	     avloc, redundant, optimal)
     int n_blocks;
     int n_exprs;
     int_list_ptr *s_preds;
     int_list_ptr *s_succs;
     sbitmap *transp;
     sbitmap *avloc;
     sbitmap *redundant;
     sbitmap *optimal;
{
  sbitmap *avin, *avout, *fartherin, *fartherout, *earlierin, *earlierout;
  sbitmap *firstout, *rev_isoin, *rev_isoout;

  /* Compute global availability.  AVIN is not needed except to
     compute AVOUT, so free its memory as soon as we return from
     compute_avinout.  */
  avin = sbitmap_vector_alloc (n_blocks, n_exprs);
  avout = sbitmap_vector_alloc (n_blocks, n_exprs);
  compute_avinout (n_blocks, s_preds, avloc, transp, avin, avout);
  free (avin);
  avin = NULL;

  /* Compute fartherness.  FARTHERIN is not needed except to compute
     FARTHEROUT, so free its memory as soon as we return from
     compute_earlyinout.  */
  fartherin = sbitmap_vector_alloc (n_blocks, n_exprs);
  fartherout = sbitmap_vector_alloc (n_blocks, n_exprs);
  compute_fartherinout (n_blocks, n_exprs, s_succs, transp,
			avout, fartherin, fartherout);
  free (fartherin);
  fartherin = NULL;

  /* Compute earlierness.  EARLIERIN is not needed except to compute
     EARLIEROUT, so free its memory as soon as we return from
     compute_delayinout.  We also no longer need AVOUT and FARTHEROUT.  */
  earlierin = sbitmap_vector_alloc (n_blocks, n_exprs);
  earlierout = sbitmap_vector_alloc (n_blocks, n_exprs);
  compute_earlierinout (n_blocks, n_exprs, s_succs, avloc,
		        avout, fartherout, earlierin, earlierout);
  free (earlierin);
  earlierin = NULL;
  free (avout);
  avout = NULL;
  free (fartherout);
  fartherout = NULL;

  /* Compute firstness.  We no longer need EARLIEROUT after we compute
     FIRSTOUT.  */
  firstout = sbitmap_vector_alloc (n_blocks, n_exprs);
  compute_firstout (n_blocks, n_exprs, s_preds, avloc, earlierout, firstout);
  free (earlierout);
  earlierout = NULL;

  /* Compute rev_isolatedness.  ISOIN is not needed except to compute
     ISOOUT, so free its memory as soon as we return from
     compute_isoinout.  */
  rev_isoin = sbitmap_vector_alloc (n_blocks, n_exprs);
  rev_isoout = sbitmap_vector_alloc (n_blocks, n_exprs);
  compute_rev_isoinout (n_blocks, s_preds, avloc, firstout,
			rev_isoin, rev_isoout);
  free (rev_isoout);
  rev_isoout = NULL;

  /* Now compute optimal placement points and the redundant expressions.  */
  compute_optimal (n_blocks, firstout, rev_isoin, optimal);
  compute_redundant (n_blocks, n_exprs, avloc, firstout, rev_isoin, redundant);
  free (firstout);
  firstout = NULL;
  free (rev_isoin);
  rev_isoin = NULL;
}

/* Compute expression anticipatability at entrance and exit of each block.  */

static void
compute_antinout (n_blocks, s_succs, antloc, transp, antin, antout)
     int n_blocks;
     int_list_ptr *s_succs;
     sbitmap *antloc;
     sbitmap *transp;
     sbitmap *antin;
     sbitmap *antout;
{
  int bb, changed, passes;
  sbitmap old_changed, new_changed;

  sbitmap_zero (antout[n_blocks - 1]);
  sbitmap_vector_ones (antin, n_blocks);

  old_changed = sbitmap_alloc (n_blocks);
  new_changed = sbitmap_alloc (n_blocks);
  sbitmap_ones (old_changed);

  passes = 0;
  changed = 1;
  while (changed)
    {
      changed = 0;
      sbitmap_zero (new_changed);
      /* We scan the blocks in the reverse order to speed up
	 the convergence.  */
      for (bb = n_blocks - 1; bb >= 0; bb--)
	{
	  int_list_ptr ps;

	  /* If none of the successors of this block have changed,
	     then this block is not going to change.  */
	  for (ps = s_succs[bb] ; ps; ps = ps->next)
	    {
	      if (INT_LIST_VAL (ps) == EXIT_BLOCK
		  || INT_LIST_VAL (ps) == ENTRY_BLOCK)
		break;

	      if (TEST_BIT (old_changed, INT_LIST_VAL (ps))
		  || TEST_BIT (new_changed, INT_LIST_VAL (ps)))
		break;
	    }

	  if (!ps)
	    continue;

	  if (bb != n_blocks - 1)
	    sbitmap_intersect_of_successors (antout[bb], antin,
					     bb, s_succs);
 	  if (sbitmap_a_or_b_and_c (antin[bb], antloc[bb],
				    transp[bb], antout[bb]))
	    {
	      changed = 1;
	      SET_BIT (new_changed, bb);
	    }
	}
      sbitmap_copy (old_changed, new_changed);
      passes++;
    }
  free (old_changed);
  free (new_changed);
}

/* Compute expression earliestness at entrance and exit of each block.

   From Advanced Compiler Design and Implementation pp411.

   An expression is earliest at the entrance to basic block BB if no
   block from entry to block BB both evaluates the expression and
   produces the same value as evaluating it at the entry to block BB
   does.  Similarly for earlistness at basic block BB exit.  */

static void
compute_earlyinout (n_blocks, n_exprs, s_preds, transp, antin,
		    earlyin, earlyout)
     int n_blocks;
     int n_exprs;
     int_list_ptr *s_preds;
     sbitmap *transp;
     sbitmap *antin;
     sbitmap *earlyin;
     sbitmap *earlyout;
{
  int bb, changed, passes;
  sbitmap temp_bitmap;
  sbitmap old_changed, new_changed;

  temp_bitmap = sbitmap_alloc (n_exprs);

  sbitmap_vector_zero (earlyout, n_blocks);
  sbitmap_ones (earlyin[0]);

  old_changed = sbitmap_alloc (n_blocks);
  new_changed = sbitmap_alloc (n_blocks);
  sbitmap_ones (old_changed);

  passes = 0;
  changed = 1;
  while (changed)
    {
      changed = 0;
      sbitmap_zero (new_changed);
      for (bb = 0; bb < n_blocks; bb++)
	{
	  int_list_ptr ps;

	  /* If none of the predecessors of this block have changed,
	     then this block is not going to change.  */
	  for (ps = s_preds[bb] ; ps; ps = ps->next)
	    {
	      if (INT_LIST_VAL (ps) == EXIT_BLOCK
		  || INT_LIST_VAL (ps) == ENTRY_BLOCK)
		break;

	      if (TEST_BIT (old_changed, INT_LIST_VAL (ps))
		  || TEST_BIT (new_changed, INT_LIST_VAL (ps)))
		break;
	    }

	  if (!ps)
	    continue;

	  if (bb != 0)
	    sbitmap_union_of_predecessors (earlyin[bb], earlyout,
					   bb, s_preds);
	  sbitmap_not (temp_bitmap, transp[bb]);
	  if (sbitmap_union_of_diff (earlyout[bb], temp_bitmap,
				     earlyin[bb], antin[bb]))
	    {
	      changed = 1;
	      SET_BIT (new_changed, bb);
	    }
	}
      sbitmap_copy (old_changed, new_changed);
      passes++;
    }
  free (old_changed);
  free (new_changed);
  free (temp_bitmap);
}

/* Compute expression delayedness at entrance and exit of each block.

   From Advanced Compiler Design and Implementation pp411.

   An expression is delayed at the entrance to BB if it is anticipatable
   and earliest at that point and if all subsequent computations of
   the expression are in block BB.   */

static void
compute_delayinout (n_blocks, n_exprs, s_preds, antloc,
		    antin, earlyin, delayin, delayout)
     int n_blocks;
     int n_exprs;
     int_list_ptr *s_preds;
     sbitmap *antloc;
     sbitmap *antin;
     sbitmap *earlyin;
     sbitmap *delayin;
     sbitmap *delayout;
{
  int bb, changed, passes;
  sbitmap *anti_and_early;
  sbitmap temp_bitmap;

  temp_bitmap = sbitmap_alloc (n_exprs);

  /* This is constant throughout the flow equations below, so compute
     it once to save time.  */
  anti_and_early = sbitmap_vector_alloc (n_blocks, n_exprs);
  for (bb = 0; bb < n_blocks; bb++)
    sbitmap_a_and_b (anti_and_early[bb], antin[bb], earlyin[bb]);
  
  sbitmap_vector_zero (delayout, n_blocks);
  sbitmap_copy (delayin[0], anti_and_early[0]);

  passes = 0;
  changed = 1;
  while (changed)
    {
      changed = 0;
      for (bb = 0; bb < n_blocks; bb++)
	{
	  if (bb != 0)
	    {
	      sbitmap_intersect_of_predecessors (temp_bitmap, delayout,
						 bb, s_preds);
	      changed |= sbitmap_a_or_b (delayin[bb],
					 anti_and_early[bb],
					 temp_bitmap);
	    }
	  sbitmap_not (temp_bitmap, antloc[bb]);
	  changed |= sbitmap_a_and_b (delayout[bb],
				      temp_bitmap,
				      delayin[bb]);
	}
      passes++;
    }

  /* We're done with this, so go ahead and free it's memory now instead
     of waiting until the end of pre.  */
  free (anti_and_early);
  free (temp_bitmap);
}

/* Compute latestness.

   From Advanced Compiler Design and Implementation pp412.

   An expression is latest at the entrance to block BB if that is an optimal
   point for computing the expression and if on every path from block BB's
   entrance to the exit block, any optimal computation point for the 
   expression occurs after one of the points at which the expression was
   computed in the original flowgraph.  */

static void
compute_latein (n_blocks, n_exprs, s_succs, antloc, delayin, latein)
     int n_blocks;
     int n_exprs;
     int_list_ptr *s_succs;
     sbitmap *antloc;
     sbitmap *delayin;
     sbitmap *latein;
{
  int bb;
  sbitmap temp_bitmap;

  temp_bitmap = sbitmap_alloc (n_exprs);

  for (bb = 0; bb < n_blocks; bb++)
    {
      /* The last block is succeeded only by the exit block; therefore,
	 temp_bitmap will not be set by the following call!  */
      if (bb == n_blocks - 1)
	{
          sbitmap_intersect_of_successors (temp_bitmap, delayin,
				           bb, s_succs);
	  sbitmap_not (temp_bitmap, temp_bitmap);
	}
      else
	sbitmap_ones (temp_bitmap);
      sbitmap_a_and_b_or_c (latein[bb], delayin[bb],
			    antloc[bb], temp_bitmap);
    }
  free (temp_bitmap);
}

/* Compute isolated.

   From Advanced Compiler Design and Implementation pp413.

   A computationally optimal placement for the evaluation of an expression
   is defined to be isolated if and only if on every path from a successor
   of the block in which it is computed to the exit block, every original
   computation of the expression is preceded by the optimal placement point.  */

static void
compute_isoinout (n_blocks, s_succs, antloc, latein, isoin, isoout)
     int n_blocks;
     int_list_ptr *s_succs;
     sbitmap *antloc;
     sbitmap *latein;
     sbitmap *isoin;
     sbitmap *isoout;
{
  int bb, changed, passes;

  sbitmap_vector_zero (isoin, n_blocks);
  sbitmap_zero (isoout[n_blocks - 1]);

  passes = 0;
  changed = 1;
  while (changed)
    {
      changed = 0;
      for (bb = n_blocks - 1; bb >= 0; bb--)
	{
	  if (bb != n_blocks - 1)
	    sbitmap_intersect_of_successors (isoout[bb], isoin,
					     bb, s_succs);
	  changed |= sbitmap_union_of_diff (isoin[bb], latein[bb],
					    isoout[bb], antloc[bb]);
	}
      passes++;
    }
}

/* Compute the set of expressions which have optimal computational points
   in each basic block.  This is the set of expressions that are latest, but
   that are not isolated in the block.  */

static void
compute_optimal (n_blocks, latein, isoout, optimal)
     int n_blocks;
     sbitmap *latein;
     sbitmap *isoout;
     sbitmap *optimal;
{
  int bb;

  for (bb = 0; bb < n_blocks; bb++)
    sbitmap_difference (optimal[bb], latein[bb], isoout[bb]);
}

/* Compute the set of expressions that are redundant in a block.  They are
   the expressions that are used in the block and that are neither isolated
   or latest.  */

static void
compute_redundant (n_blocks, n_exprs, antloc, latein, isoout, redundant)
     int n_blocks;
     int n_exprs;
     sbitmap *antloc;
     sbitmap *latein;
     sbitmap *isoout;
     sbitmap *redundant;
{
  int bb;
  sbitmap temp_bitmap;

  temp_bitmap = sbitmap_alloc (n_exprs);

  for (bb = 0; bb < n_blocks; bb++)
    {
      sbitmap_a_or_b (temp_bitmap, latein[bb], isoout[bb]);
      sbitmap_difference (redundant[bb], antloc[bb], temp_bitmap);
    }
  free (temp_bitmap);
}

/* Compute expression availability at entrance and exit of each block.  */

static void
compute_avinout (n_blocks, s_preds, avloc, transp, avin, avout)
     int n_blocks;
     int_list_ptr *s_preds;
     sbitmap *avloc;
     sbitmap *transp;
     sbitmap *avin;
     sbitmap *avout;
{
  int bb, changed, passes;

  sbitmap_zero (avin[0]);
  sbitmap_vector_ones (avout, n_blocks);

  passes = 0;
  changed = 1;
  while (changed)
    {
      changed = 0;
      for (bb = 0; bb < n_blocks; bb++)
	{
	  if (bb != 0)
	    sbitmap_intersect_of_predecessors (avin[bb], avout,
					       bb, s_preds);
	  changed |= sbitmap_a_or_b_and_c (avout[bb], avloc[bb],
					   transp[bb], avin[bb]);
	}
      passes++;
    }
}

/* Compute expression latestness.

   This is effectively the same as earliestness computed on the reverse
   flow graph.  */

static void
compute_fartherinout (n_blocks, n_exprs, s_succs,
		      transp, avout, fartherin, fartherout)
     int n_blocks;
     int n_exprs;
     int_list_ptr *s_succs;
     sbitmap *transp;
     sbitmap *avout;
     sbitmap *fartherin;
     sbitmap *fartherout;
{
  int bb, changed, passes;
  sbitmap temp_bitmap;

  temp_bitmap = sbitmap_alloc (n_exprs);

  sbitmap_vector_zero (fartherin, n_blocks);
  sbitmap_ones (fartherout[n_blocks - 1]);

  passes = 0;
  changed = 1;
  while (changed)
    {
      changed = 0;
      for (bb = n_blocks - 1; bb >= 0; bb--)
	{
	  if (bb != n_blocks - 1)
	    sbitmap_union_of_successors (fartherout[bb], fartherin,
					 bb, s_succs);
	  sbitmap_not (temp_bitmap, transp[bb]);
	  changed |= sbitmap_union_of_diff (fartherin[bb], temp_bitmap,
					    fartherout[bb], avout[bb]);
	}
      passes++;
    }

  free (temp_bitmap);
}

/* Compute expression earlierness at entrance and exit of each block.

   This is effectively the same as delayedness computed on the reverse
   flow graph.  */

static void
compute_earlierinout (n_blocks, n_exprs, s_succs, avloc,
		      avout, fartherout, earlierin, earlierout)
     int n_blocks;
     int n_exprs;
     int_list_ptr *s_succs;
     sbitmap *avloc;
     sbitmap *avout;
     sbitmap *fartherout;
     sbitmap *earlierin;
     sbitmap *earlierout;
{
  int bb, changed, passes;
  sbitmap *av_and_farther;
  sbitmap temp_bitmap;

  temp_bitmap = sbitmap_alloc (n_exprs);

  /* This is constant throughout the flow equations below, so compute
     it once to save time.  */
  av_and_farther = sbitmap_vector_alloc (n_blocks, n_exprs);
  for (bb = 0; bb < n_blocks; bb++)
    sbitmap_a_and_b (av_and_farther[bb], avout[bb], fartherout[bb]);
  
  sbitmap_vector_zero (earlierin, n_blocks);
  sbitmap_copy (earlierout[n_blocks - 1], av_and_farther[n_blocks - 1]);

  passes = 0;
  changed = 1;
  while (changed)
    {
      changed = 0;
      for (bb = n_blocks - 1; bb >= 0; bb--)
	{
	  if (bb != n_blocks - 1)
	    {
	      sbitmap_intersect_of_successors (temp_bitmap, earlierin,
					       bb, s_succs);
	      changed |= sbitmap_a_or_b (earlierout[bb],
					 av_and_farther[bb],
					 temp_bitmap);
	    }
	  sbitmap_not (temp_bitmap, avloc[bb]);
	  changed |= sbitmap_a_and_b (earlierin[bb],
				      temp_bitmap,
				      earlierout[bb]);
	}
      passes++;
    }

  /* We're done with this, so go ahead and free it's memory now instead
     of waiting until the end of pre.  */
  free (av_and_farther);
  free (temp_bitmap);
}

/* Compute firstness. 

   This is effectively the same as latestness computed on the reverse
   flow graph.  */

static void
compute_firstout (n_blocks, n_exprs, s_preds, avloc, earlierout, firstout)
     int n_blocks;
     int n_exprs;
     int_list_ptr *s_preds;
     sbitmap *avloc;
     sbitmap *earlierout;
     sbitmap *firstout;
{
  int bb;
  sbitmap temp_bitmap;

  temp_bitmap = sbitmap_alloc (n_exprs);

  for (bb = 0; bb < n_blocks; bb++)
    {
      /* The first block is preceded only by the entry block; therefore,
	 temp_bitmap will not be set by the following call!  */
      if (bb != 0)
	{
	  sbitmap_intersect_of_predecessors (temp_bitmap, earlierout,
					     bb, s_preds);
	  sbitmap_not (temp_bitmap, temp_bitmap);
	}
      else
	{
	  sbitmap_ones (temp_bitmap);
	}
      sbitmap_a_and_b_or_c (firstout[bb], earlierout[bb],
			    avloc[bb], temp_bitmap);
    }
  free (temp_bitmap);
}

/* Compute reverse isolated.

   This is effectively the same as isolatedness computed on the reverse
   flow graph.  */

static void
compute_rev_isoinout (n_blocks, s_preds, avloc, firstout,
		      rev_isoin, rev_isoout)
     int n_blocks;
     int_list_ptr *s_preds;
     sbitmap *avloc;
     sbitmap *firstout;
     sbitmap *rev_isoin;
     sbitmap *rev_isoout;
{
  int bb, changed, passes;

  sbitmap_vector_zero (rev_isoout, n_blocks);
  sbitmap_zero (rev_isoin[0]);

  passes = 0;
  changed = 1;
  while (changed)
    {
      changed = 0;
      for (bb = 0; bb < n_blocks; bb++)
	{
	  if (bb != 0)
	    sbitmap_intersect_of_predecessors (rev_isoin[bb], rev_isoout,
					       bb, s_preds);
	  changed |= sbitmap_union_of_diff (rev_isoout[bb], firstout[bb],
					    rev_isoin[bb], avloc[bb]);
	}
      passes++;
    }
}