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
|
/* rtrVia.c.c -
*
* This file contains procedures that minimize vias and
* maximize metal.
*
* *********************************************************************
* * Copyright (C) 1985, 1990 Regents of the University of California. *
* * Permission to use, copy, modify, and distribute this *
* * software and its documentation for any purpose and without *
* * fee is hereby granted, provided that the above copyright *
* * notice appear in all copies. The University of California *
* * makes no representations about the suitability of this *
* * software for any purpose. It is provided "as is" without *
* * express or implied warranty. Export of this software outside *
* * of the United States of America may require an export license. *
* *********************************************************************
*/
#ifndef lint
static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-7.5/router/rtrVia.c,v 1.1.1.1 2006/04/10 22:03:14 tim Exp $";
#endif /* not lint */
#include <stdio.h>
#include "utils/magic.h"
#include "utils/geometry.h"
#include "tiles/tile.h"
#include "utils/hash.h"
#include "utils/heap.h"
#include "database/database.h"
#include "windows/windows.h"
#include "dbwind/dbwind.h"
#include "utils/main.h"
#include "netmenu/netmenu.h"
#include "textio/textio.h"
#include "utils/styles.h"
#include "utils/malloc.h"
#include "gcr/gcr.h"
#include "router/router.h"
#include "router/routerInt.h"
/*
* The following structures are used to hold information about
* areas to be erased/modified/painted during via minimization.
*/
struct arealist
{
Rect ap_erase; /* Area to be erased. */
Rect ap_paint; /* Area to be painted. */
int ap_oldtype; /* Type to be erased */
int ap_newtype; /* Type to be painted */
struct arealist *ap_next; /* Next item in list, or NULL for end. */
};
struct vialist
{
Rect vp_area; /* Via area to be examined. */
struct vialist *vp_next; /* Next item in list, or NULL for end. */
};
struct paintlist
{
Rect pl_area; /* Extension segment to paint */
struct paintlist *pl_next;/* Next extension to paint */
};
struct srinfo
{
Rect *si_area; /* Expanded area surrounding via */
Rect *si_varea; /* Exact area of via */
Rect si_extend; /* Extended stub within si_varea */
Tile *si_tile; /* Reference tile */
Plane *si_plane; /* Plane being searched */
TileTypeBitMask si_mask; /* Tile type mask */
};
struct vialist *rtrViaList; /* List of vias to be processed */
struct arealist *rtrAreaList; /* List of areas to be processed */
struct paintlist *rtrPaintList; /* List of extension segments to paint */
int rtrVias; /* Count of vias eliminated */
int rtrExamineStack(); /* Examines the tile stack for
replacement segments to be converted
to the target material */
/*
* ----------------------------------------------------------------------------
*
* rtrFollowLocFunc --
*
* This function is called once for each terminal location in
* a netlist. It invokes a procedure to follow all electrically
* connected paths from the terminal.
*
* Results:
* Always returns 0 to keep the search from aborting.
*
* Side effects:
*
* ----------------------------------------------------------------------------
*/
/* ARGSUSED */
int
rtrFollowLocFunc(rect, name, label, area)
Rect *rect; /* Area of the terminal, edit cell coords. */
char *name; /* Name of the terminal (ignored). */
Label *label; /* Pointer to the label, used to find out
* what layer the label's attached to.
*/
Rect *area; /* We GeoInclude into this all the areas of
* all the tiles we delete.
*/
{
CellDef *def = EditCellUse->cu_def;
Rect initialArea;
GEO_EXPAND(rect, 1, &initialArea);
(void) rtrSrTraverse(def, &initialArea,
&DBConnectTbl[label->lab_type], DBConnectTbl,
&TiPlaneRect, rtrExamineStack, 0);
return 0;
}
/*
* ----------------------------------------------------------------------------
*
* rtrFollowName --
*
* This function gets called during via minimization. It's invoked
* once for each terminal name in the netlist. It calls
* DBSrLabelLoc to invoke rtrFollowLocFunc for each terminal
* location associated with the name.
*
* Results:
* Always returns 0 to keep the search from aborting.
*
* Side effects:
* Nothing here, but a list of segments of poly are generated.
*
* ----------------------------------------------------------------------------
*/
/* ARGSUSED */
int
rtrFollowName(name, firstInNet, area)
char *name; /* Name of terminal. */
bool firstInNet; /* Ignored by this procedure. */
Rect *area; /* Passed through as ClientData to
* rtrFollowLocFunc.
*/
{
if ( firstInNet )
{
RtrMilestonePrint("#");
(void) DBSrLabelLoc(EditCellUse, name, rtrFollowLocFunc, (ClientData) area);
}
return 0;
}
/*
* ----------------------------------------------------------------------------
*
* rtrCheckTypes --
* Abort area search if both poly and metal are adjacent to via.
*
* Results:
* Returns 1 if poly and metal connect to via.
* Returns zero otherwise.
*
* Side effects:
* Type of connecting material returned in cdata parameter.
*
* ----------------------------------------------------------------------------
*/
int
rtrCheckTypes(tile, cdata)
Tile *tile;
ClientData cdata;
{
int type;
int lastType = * (int *) cdata;
type = TiGetType(tile);
if ( (type == RtrMetalType) || (type == RtrPolyType) )
{
if ( lastType )
{
if ( lastType != type )
return 1;
}
else
*(int *)cdata = type;
}
return 0;
}
/*
* ----------------------------------------------------------------------------
*
* rtrExtandStub --
* Generate an extension of a piece of routing material
* by extending into the area of the via.
*
* Results:
* None.
*
* Side effects:
* Extension segment returned in *stub*.
*
* ----------------------------------------------------------------------------
*/
void
rtrExtend(tile,area,stub)
Tile *tile; /* Tile adjacent to via */
Rect *area; /* Area occupied by via */
Rect *stub; /* Extension of routing material
into area of via */
{
if ( (TOP(tile) == area->r_ybot) || (BOTTOM(tile) == area->r_ytop) )
{
stub->r_xbot = MAX(area->r_xbot, LEFT(tile));
stub->r_xtop = MIN(area->r_xtop, RIGHT(tile));
stub->r_ybot = area->r_ybot;
stub->r_ytop = area->r_ytop;
}
else if ( (LEFT(tile) == area->r_xtop) || (RIGHT(tile) == area->r_xbot) )
{
stub->r_xbot = area->r_xbot;
stub->r_xtop = area->r_xtop;
stub->r_ybot = MAX(area->r_ybot, BOTTOM(tile));
stub->r_ytop = MIN(area->r_ytop, TOP(tile));
}
}
/*
* ----------------------------------------------------------------------------
*
* rtrStubGen --
* Generate an extension segment for a piece of routing material.
*
* Results:
* Return 0 to keep the search going.
*
* Side effects:
* Extension segment entry added to rtrPaintList list for later painting.
*
* ----------------------------------------------------------------------------
*/
int
rtrStubGen(tile, si)
Tile *tile;
struct srinfo *si;
{
Rect area;
struct paintlist *pl;
if ( tile != si->si_tile )
{
pl = (struct paintlist *) mallocMagic((unsigned) (sizeof(*pl)));
pl->pl_next = rtrPaintList;
rtrPaintList = pl;
/*
* Generate extension segment relative to reference segment.
*/
rtrExtend(tile, si->si_varea, &pl->pl_area);
GeoClip(&pl->pl_area, &si->si_extend);
TITORECT(tile, &area);
GeoClip(&area, si->si_area);
(void) GeoInclude(&area, &pl->pl_area);
}
return 0;
}
/*
* ----------------------------------------------------------------------------
*
* rtrReferenceTile --
* Store a reference tile and corresponding extension stub.
* Recursively call DBSrPaintArea to generate extension
* stubs intersecting the reference stub. Each tile
* adjacent to the via will in turn be a reference tile.
*
* Results:
* Always returns 0 to continue search.
*
* Side effects:
* Tile pointer and extension stub stored in *srinfo* structure.
*
* ----------------------------------------------------------------------------
*/
int
rtrReferenceTile(tile, si)
Tile *tile;
struct srinfo *si;
{
si->si_tile = tile;
rtrExtend(tile, si->si_varea, &si->si_extend);
(void) DBSrPaintArea(tile, si->si_plane, si->si_area,
&si->si_mask, rtrStubGen, (ClientData) si);
return 0;
}
/*
* ----------------------------------------------------------------------------
*
* rtrViaCheck --
* Check to see if a via is necessary.
* If only one routing layer connects to the via,
* delete the via and replace with extended segments of routing material.
*
* Results:
* None.
*
* Side effects:
* Via erased.
*
* ----------------------------------------------------------------------------
*/
void
rtrViaCheck(area, def)
Rect *area;
CellDef *def;
{
Rect r;
int type, plane;
struct paintlist *pl;
TileTypeBitMask mask;
/*
* Search around via for connecting pieces of metal or poly.
*/
GEO_EXPAND(area, 1, &r);
type = 0;
TTMaskZero(&mask);
TTMaskSetType(&mask, RtrPolyType);
TTMaskSetType(&mask, RtrMetalType);
for ( plane = PL_PAINTBASE; plane < DBNumPlanes; plane++ )
if ( DBPaintOnPlane(RtrPolyType, plane) ||
DBPaintOnPlane(RtrMetalType, plane) )
if ( DBSrPaintArea((Tile *)NULL, def->cd_planes[plane],
&r, &mask, rtrCheckTypes, (ClientData) &type) )
return;
/*
* No metal or poly connects to this via.
* Enumerate all connecting routing material
* and build a list if extension segments to replace the via.
*/
rtrPaintList = (struct paintlist *) NULL;
for ( plane = PL_PAINTBASE; plane < DBNumPlanes; plane++ )
if ( DBPaintOnPlane(type, plane) )
{
struct srinfo si;
si.si_area = &r;
si.si_varea = area;
si.si_plane = def->cd_planes[plane];
TTMaskZero(&si.si_mask);
TTMaskSetType(&si.si_mask, type);
(void) DBSrPaintArea((Tile *)NULL, si.si_plane,
&r, &mask, rtrReferenceTile, (ClientData) &si);
}
/*
* Erase via and paint extensions.
*/
DBErase(def, area, RtrContactType);
for ( pl = rtrPaintList; pl; pl = pl->pl_next)
{
DBPaint(def, &pl->pl_area, type);
freeMagic( (char *)pl );
}
rtrVias++;
return;
}
/*
* ----------------------------------------------------------------------------
*
* rtrListArea --
* Append an entry into a linked list
* of areas to be processed.
*
* Results:
* None.
*
* Side effects:
* rtrAreaList points to a new list entry
* which is linked into the existing list.
*
* ----------------------------------------------------------------------------
*/
void
rtrListArea(tile, oldType, newType, deltax, deltay)
Tile *tile;
int oldType;
int newType;
int deltax;
int deltay;
{
struct arealist *ap;
ap = (struct arealist *) mallocMagic((unsigned) (sizeof(*ap)));
TITORECT(tile, &ap->ap_erase);
TITORECT(tile, &ap->ap_paint);
/*
* Adjust size of paint to correspond to new layer.
*/
ap->ap_paint.r_xtop += deltax;
ap->ap_paint.r_ytop += deltay;
ap->ap_oldtype = oldType;
ap->ap_newtype = newType;
ap->ap_next = rtrAreaList;
rtrAreaList = ap;
}
/*
* ----------------------------------------------------------------------------
*
* rtrListVia --
* Append an entry into a linked list
* of areas to be processed.
*
* Results:
* Always return 0 to keep the search going.
*
* Side effects:
* rtrViaList points to new list entry
* which is linked in front of existing list.
* Always returns 0 to continue search if called from
* DBSrPaintArea.
*
* ----------------------------------------------------------------------------
*/
int
rtrListVia(tile)
Tile *tile;
{
struct vialist *vp;
vp = (struct vialist *) mallocMagic((unsigned)(sizeof(*vp)));
TITORECT(tile, &vp->vp_area);
vp->vp_next = rtrViaList;
rtrViaList = vp;
return 0;
}
/*
* ----------------------------------------------------------------------------
*
* RtrViaMinimize --
* Minimize vias and maximize metal.
*
* Results:
* Return number of vias elminiated.
*
* Side effects:
* On the first pass, segments of poly
* are replaced with metal and connecting vias are erased.
* On the second pass, segments of metal
* are replaced with poly and connecting vias are erased.
*
* ----------------------------------------------------------------------------
*/
int
RtrViaMinimize(def)
CellDef *def;
{
Rect area;
struct vialist *vp;
struct arealist *ap;
/*
* Pass 1 --
* Enumerate every terminal in the netlist
* to follow all electrically connected paths.
* Generate a list of segments of poly not overlapped by metal
* and terminated at each end by vias.
* These segments of poly are replaced with metal
* and the connecting via's are removed.
*/
rtrVias = 0;
rtrTarget = RtrMetalType;
rtrReplace = RtrPolyType;
rtrDelta = RtrMetalWidth - RtrPolyWidth;
area = GeoNullRect;
rtrViaList = (struct vialist *) NULL;
rtrAreaList = (struct arealist *) NULL;
(void) NMEnumNets(rtrFollowName, (ClientData) &area);
/*
* Replace poly with metal where appropriate.
*/
for ( ap = rtrAreaList; ap; ap = ap->ap_next)
{
DBErase(def, &ap->ap_erase, ap->ap_oldtype);
DBPaint(def, &ap->ap_paint, ap->ap_newtype);
freeMagic( (char *)ap);
}
/*
* Eliminate unnecessary vias.
*/
for ( vp = rtrViaList; vp; vp = vp->vp_next)
{
rtrViaCheck(&vp->vp_area, def);
freeMagic( (char *)vp);
}
/*
* Pass 2 --
* Repeat the entire process replacing metal with poly.
*/
rtrTarget = RtrPolyType;
rtrReplace = RtrMetalType;
rtrDelta = RtrPolyWidth - RtrMetalWidth;
area = GeoNullRect;
rtrViaList = (struct vialist *) NULL;
rtrAreaList = (struct arealist *) NULL;
(void) NMEnumNets(rtrFollowName, (ClientData) &area);
/*
* Erase poly and replace with metal.
*/
for ( ap = rtrAreaList; ap; ap = ap->ap_next)
{
DBErase(def, &ap->ap_erase, ap->ap_oldtype);
DBPaint(def, &ap->ap_paint, ap->ap_newtype);
freeMagic( (char *)ap);
}
/*
* Eliminate unnecessary vias.
*/
for ( vp = rtrViaList; vp; vp = vp->vp_next)
{
rtrViaCheck(&vp->vp_area, def);
freeMagic( (char *)vp);
}
return rtrVias;
}
|