2018-09-22 22:32:36 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
KLayout Layout Viewer
|
|
|
|
|
Copyright (C) 2006-2018 Matthias Koefferlein
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program 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 this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "dbHierProcessor.h"
|
|
|
|
|
#include "dbBoxScanner.h"
|
|
|
|
|
#include "dbRecursiveShapeIterator.h"
|
|
|
|
|
#include "dbBoxConvert.h"
|
|
|
|
|
#include "dbEdgeProcessor.h"
|
|
|
|
|
#include "dbPolygonGenerators.h"
|
|
|
|
|
#include "tlLog.h"
|
2018-09-23 17:49:10 +02:00
|
|
|
#include "tlTimer.h"
|
|
|
|
|
#include "tlInternational.h"
|
2018-09-22 22:32:36 +02:00
|
|
|
|
|
|
|
|
namespace db
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------
|
2018-10-06 23:59:47 +02:00
|
|
|
// Shape reference translator
|
2018-09-22 22:32:36 +02:00
|
|
|
|
2018-10-06 23:59:47 +02:00
|
|
|
template <class Ref>
|
|
|
|
|
class shape_reference_translator
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2018-10-06 23:59:47 +02:00
|
|
|
typedef typename Ref::shape_type shape_type;
|
2018-09-22 22:32:36 +02:00
|
|
|
|
2018-10-06 23:59:47 +02:00
|
|
|
shape_reference_translator (db::Layout *target_layout)
|
|
|
|
|
: mp_layout (target_layout)
|
|
|
|
|
{
|
|
|
|
|
// .. nothing yet ..
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
2018-10-06 01:40:01 +02:00
|
|
|
|
2018-10-06 23:59:47 +02:00
|
|
|
Ref operator() (const Ref &ref) const
|
|
|
|
|
{
|
|
|
|
|
shape_type sh = ref.obj ().transformed (ref.trans ());
|
|
|
|
|
return Ref (sh, mp_layout->shape_repository ());
|
2018-10-06 01:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-06 23:59:47 +02:00
|
|
|
template <class Trans>
|
|
|
|
|
Ref operator() (const Ref &ref, const Trans &tr) const
|
|
|
|
|
{
|
|
|
|
|
shape_type sh = ref.obj ().transformed (tr * Trans (ref.trans ()));
|
|
|
|
|
return Ref (sh, mp_layout->shape_repository ());
|
2018-10-06 01:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-06 23:59:47 +02:00
|
|
|
private:
|
|
|
|
|
db::Layout *mp_layout;
|
|
|
|
|
};
|
2018-10-06 01:40:01 +02:00
|
|
|
|
2018-09-22 22:32:36 +02:00
|
|
|
// ---------------------------------------------------------------------------------------------
|
|
|
|
|
// LocalProcessorCellContext implementation
|
|
|
|
|
|
|
|
|
|
LocalProcessorCellContext::LocalProcessorCellContext ()
|
|
|
|
|
{
|
|
|
|
|
// .. nothing yet ..
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
LocalProcessorCellContext::add (db::LocalProcessorCellContext *parent_context, db::Cell *parent, const db::ICplxTrans &cell_inst)
|
|
|
|
|
{
|
|
|
|
|
m_drops.push_back (LocalProcessorCellDrop (parent_context, parent, cell_inst));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
LocalProcessorCellContext::propagate (const std::set<db::PolygonRef> &res)
|
|
|
|
|
{
|
|
|
|
|
if (res.empty ()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (std::vector<LocalProcessorCellDrop>::const_iterator d = m_drops.begin (); d != m_drops.end (); ++d) {
|
|
|
|
|
|
|
|
|
|
tl_assert (d->parent_context != 0);
|
|
|
|
|
tl_assert (d->parent != 0);
|
|
|
|
|
|
2018-10-01 22:45:46 +02:00
|
|
|
db::Layout *subject_layout = d->parent->layout ();
|
2018-10-06 23:59:47 +02:00
|
|
|
shape_reference_translator<db::PolygonRef> rt (subject_layout);
|
2018-09-22 22:32:36 +02:00
|
|
|
for (std::set<db::PolygonRef>::const_iterator r = res.begin (); r != res.end (); ++r) {
|
2018-10-06 23:59:47 +02:00
|
|
|
d->parent_context->propagated ().insert (rt (*r, d->cell_inst));
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------
|
|
|
|
|
// LocalProcessorCellContexts implementation
|
|
|
|
|
|
|
|
|
|
LocalProcessorCellContexts::LocalProcessorCellContexts ()
|
2018-10-01 22:45:46 +02:00
|
|
|
: mp_intruder_cell (0)
|
|
|
|
|
{
|
|
|
|
|
// .. nothing yet ..
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LocalProcessorCellContexts::LocalProcessorCellContexts (const db::Cell *intruder_cell)
|
|
|
|
|
: mp_intruder_cell (intruder_cell)
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
|
|
|
|
// .. nothing yet ..
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db::LocalProcessorCellContext *
|
|
|
|
|
LocalProcessorCellContexts::find_context (const key_type &intruders)
|
|
|
|
|
{
|
|
|
|
|
std::map<key_type, db::LocalProcessorCellContext>::iterator c = m_contexts.find (intruders);
|
|
|
|
|
return c != m_contexts.end () ? &c->second : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db::LocalProcessorCellContext *
|
|
|
|
|
LocalProcessorCellContexts::create (const key_type &intruders)
|
|
|
|
|
{
|
|
|
|
|
return &m_contexts[intruders];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2018-09-25 22:25:40 +02:00
|
|
|
LocalProcessorCellContexts::compute_results (LocalProcessorContexts &contexts, db::Cell *cell, const LocalOperation *op, unsigned int output_layer, LocalProcessor *proc)
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
|
|
|
|
bool first = true;
|
|
|
|
|
std::set<db::PolygonRef> common;
|
|
|
|
|
|
2018-09-23 17:49:10 +02:00
|
|
|
int index = 0;
|
|
|
|
|
int total = int (m_contexts.size ());
|
2018-09-22 22:32:36 +02:00
|
|
|
for (std::map<key_type, db::LocalProcessorCellContext>::iterator c = m_contexts.begin (); c != m_contexts.end (); ++c) {
|
|
|
|
|
|
2018-09-23 17:49:10 +02:00
|
|
|
++index;
|
|
|
|
|
|
|
|
|
|
if (tl::verbosity () >= 30) {
|
|
|
|
|
tl::log << tr ("Computing local results for ") << cell->layout ()->cell_name (cell->cell_index ()) << " (context " << index << "/" << total << ")";
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-22 22:32:36 +02:00
|
|
|
if (first) {
|
|
|
|
|
|
|
|
|
|
common = c->second.propagated ();
|
2018-10-01 22:45:46 +02:00
|
|
|
proc->compute_local_cell (contexts, cell, mp_intruder_cell, op, c->first, common);
|
2018-09-22 22:32:36 +02:00
|
|
|
first = false;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
std::set<db::PolygonRef> res = c->second.propagated ();
|
2018-10-01 22:45:46 +02:00
|
|
|
proc->compute_local_cell (contexts, cell, mp_intruder_cell, op, c->first, res);
|
2018-09-22 22:32:36 +02:00
|
|
|
|
|
|
|
|
if (common.empty ()) {
|
|
|
|
|
|
|
|
|
|
c->second.propagate (res);
|
|
|
|
|
|
|
|
|
|
} else if (res != common) {
|
|
|
|
|
|
|
|
|
|
std::set<db::PolygonRef> lost;
|
|
|
|
|
std::set_difference (common.begin (), common.end (), res.begin (), res.end (), std::inserter (lost, lost.end ()));
|
|
|
|
|
|
|
|
|
|
if (! lost.empty ()) {
|
|
|
|
|
|
|
|
|
|
std::set<db::PolygonRef> new_common;
|
|
|
|
|
std::set_intersection (common.begin (), common.end (), res.begin (), res.end (), std::inserter (new_common, new_common.end ()));
|
|
|
|
|
common.swap (new_common);
|
|
|
|
|
|
|
|
|
|
for (std::map<key_type, db::LocalProcessorCellContext>::iterator cc = m_contexts.begin (); cc != c; ++cc) {
|
|
|
|
|
cc->second.propagate (lost);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::set<db::PolygonRef> gained;
|
|
|
|
|
std::set_difference (res.begin (), res.end (), common.begin (), common.end (), std::inserter (gained, gained.end ()));
|
|
|
|
|
c->second.propagate (gained);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 22:25:40 +02:00
|
|
|
proc->push_results (cell, output_layer, common);
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-06 01:40:01 +02:00
|
|
|
// ---------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
ShapeInteractions::ShapeInteractions ()
|
|
|
|
|
: m_id (0)
|
|
|
|
|
{
|
|
|
|
|
// .. nothing yet ..
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
ShapeInteractions::has_shape_id (unsigned int id) const
|
|
|
|
|
{
|
|
|
|
|
return m_shapes.find (id) != m_shapes.end ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ShapeInteractions::add_shape (unsigned int id, const db::PolygonRef &shape)
|
|
|
|
|
{
|
|
|
|
|
m_shapes [id] = shape;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ShapeInteractions::add_subject (unsigned int id, const db::PolygonRef &shape)
|
|
|
|
|
{
|
|
|
|
|
add_shape (id, shape);
|
|
|
|
|
m_interactions.insert (std::make_pair (id, container::value_type::second_type ()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ShapeInteractions::add_interaction (unsigned int subject_id, unsigned int intruder_id)
|
|
|
|
|
{
|
|
|
|
|
m_interactions [subject_id].push_back (intruder_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::vector<unsigned int> &
|
|
|
|
|
ShapeInteractions::intruders_for (unsigned int subject_id) const
|
|
|
|
|
{
|
|
|
|
|
iterator i = m_interactions.find (subject_id);
|
|
|
|
|
if (i == m_interactions.end ()) {
|
|
|
|
|
static std::vector<unsigned int> empty;
|
|
|
|
|
return empty;
|
|
|
|
|
} else {
|
|
|
|
|
return i->second;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const db::PolygonRef &
|
|
|
|
|
ShapeInteractions::shape (unsigned int id) const
|
|
|
|
|
{
|
|
|
|
|
std::map<unsigned int, db::PolygonRef>::const_iterator i = m_shapes.find (id);
|
|
|
|
|
if (i == m_shapes.end ()) {
|
|
|
|
|
static db::PolygonRef s;
|
|
|
|
|
return s;
|
|
|
|
|
} else {
|
|
|
|
|
return i->second;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-22 22:32:36 +02:00
|
|
|
// ---------------------------------------------------------------------------------------------
|
|
|
|
|
// Helper classes for the LocalProcessor
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
inline unsigned int polygon_ref_flags ()
|
|
|
|
|
{
|
|
|
|
|
return 1 << db::ShapeIterator::PolygonRef;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct InteractionRegistrationShape2Shape
|
2018-10-06 01:40:01 +02:00
|
|
|
: db::box_scanner_receiver2<db::PolygonRef, unsigned int, db::PolygonRef, unsigned int>
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2018-10-06 01:40:01 +02:00
|
|
|
InteractionRegistrationShape2Shape (db::Layout *layout, ShapeInteractions *result)
|
2018-10-01 22:45:46 +02:00
|
|
|
: mp_result (result), mp_layout (layout)
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
|
|
|
|
// nothing yet ..
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-06 01:40:01 +02:00
|
|
|
void add (const db::PolygonRef *ref1, unsigned int id1, const db::PolygonRef *ref2, unsigned int id2)
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
2018-10-06 01:40:01 +02:00
|
|
|
mp_result->add_shape (id1, *ref1);
|
|
|
|
|
|
2018-10-01 22:45:46 +02:00
|
|
|
if (mp_layout) {
|
|
|
|
|
// In order to guarantee the refs come from the subject layout, we'd need to
|
|
|
|
|
// rewrite them to the subject layout if required.
|
2018-10-06 01:40:01 +02:00
|
|
|
if (!mp_result->has_shape_id (id2)) {
|
2018-10-06 23:59:47 +02:00
|
|
|
db::shape_reference_translator<db::PolygonRef> rt (mp_layout);
|
|
|
|
|
mp_result->add_shape (id2, rt (*ref2));
|
2018-10-06 01:40:01 +02:00
|
|
|
}
|
2018-10-01 22:45:46 +02:00
|
|
|
} else {
|
2018-10-06 01:40:01 +02:00
|
|
|
mp_result->add_shape (id2, *ref2);
|
2018-10-01 22:45:46 +02:00
|
|
|
}
|
2018-10-06 21:56:13 +02:00
|
|
|
|
2018-10-06 01:40:01 +02:00
|
|
|
mp_result->add_interaction (id1, id2);
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2018-10-06 01:40:01 +02:00
|
|
|
ShapeInteractions *mp_result;
|
2018-10-01 22:45:46 +02:00
|
|
|
db::Layout *mp_layout;
|
2018-09-22 22:32:36 +02:00
|
|
|
};
|
|
|
|
|
|
2018-10-06 01:40:01 +02:00
|
|
|
struct InteractionRegistrationShape1
|
|
|
|
|
: db::box_scanner_receiver<db::PolygonRef, unsigned int>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
InteractionRegistrationShape1 (ShapeInteractions *result)
|
|
|
|
|
: mp_result (result)
|
|
|
|
|
{
|
|
|
|
|
// nothing yet ..
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void add (const db::PolygonRef *ref1, unsigned int id1, const db::PolygonRef *ref2, unsigned int id2)
|
|
|
|
|
{
|
|
|
|
|
mp_result->add_shape (id1, *ref1);
|
|
|
|
|
mp_result->add_shape (id2, *ref2);
|
|
|
|
|
mp_result->add_interaction (id1, id2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ShapeInteractions *mp_result;
|
|
|
|
|
};
|
|
|
|
|
|
2018-09-22 22:32:36 +02:00
|
|
|
struct InteractionRegistrationShape2Inst
|
2018-10-06 01:40:01 +02:00
|
|
|
: db::box_scanner_receiver2<db::PolygonRef, unsigned int, db::CellInstArray, unsigned int>
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2018-10-06 01:40:01 +02:00
|
|
|
InteractionRegistrationShape2Inst (db::Layout *subject_layout, const db::Layout *intruder_layout, unsigned int intruder_layer, db::Coord dist, ShapeInteractions *result)
|
2018-10-01 22:45:46 +02:00
|
|
|
: mp_subject_layout (subject_layout), mp_intruder_layout (intruder_layout), m_intruder_layer (intruder_layer), m_dist (dist), mp_result (result)
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
|
|
|
|
// nothing yet ..
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-06 01:40:01 +02:00
|
|
|
void add (const db::PolygonRef *ref, unsigned int id1, const db::CellInstArray *inst, unsigned int inst_id)
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
2018-10-01 22:45:46 +02:00
|
|
|
const db::Cell &intruder_cell = mp_intruder_layout->cell (inst->object ().cell_index ());
|
|
|
|
|
db::box_convert <db::CellInst, true> inst_bc (*mp_intruder_layout, m_intruder_layer);
|
2018-10-06 01:40:01 +02:00
|
|
|
mp_result->add_shape (id1, *ref);
|
2018-09-22 22:32:36 +02:00
|
|
|
|
2018-10-06 23:59:47 +02:00
|
|
|
// Find all instance array members that potentially interact with the shape and use
|
|
|
|
|
// add_shapes_from_intruder_inst on them
|
2018-09-25 23:26:18 +02:00
|
|
|
for (db::CellInstArray::iterator n = inst->begin_touching (ref->box ().enlarged (db::Vector (m_dist - 1, m_dist - 1)), inst_bc); !n.at_end (); ++n) {
|
2018-09-22 23:37:23 +02:00
|
|
|
db::ICplxTrans tn = inst->complex_trans (*n);
|
2018-09-25 23:26:18 +02:00
|
|
|
db::Box region = ref->box ().transformed (tn.inverted ()).enlarged (db::Vector (m_dist, m_dist)) & intruder_cell.bbox (m_intruder_layer).enlarged (db::Vector (m_dist, m_dist));
|
2018-09-22 23:37:23 +02:00
|
|
|
if (! region.empty ()) {
|
2018-10-06 23:59:47 +02:00
|
|
|
add_shapes_from_intruder_inst (id1, intruder_cell, tn, inst_id, region);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-22 23:37:23 +02:00
|
|
|
|
2018-10-06 23:59:47 +02:00
|
|
|
private:
|
|
|
|
|
db::Layout *mp_subject_layout;
|
|
|
|
|
const db::Layout *mp_intruder_layout;
|
|
|
|
|
unsigned int m_intruder_layer;
|
|
|
|
|
db::Coord m_dist;
|
|
|
|
|
ShapeInteractions *mp_result;
|
|
|
|
|
std::map<std::pair<unsigned int, const db::PolygonRef *>, unsigned int> m_inst_shape_ids;
|
2018-09-22 23:37:23 +02:00
|
|
|
|
2018-10-06 23:59:47 +02:00
|
|
|
void add_shapes_from_intruder_inst (unsigned int id1, const db::Cell &intruder_cell, const db::ICplxTrans &tn, unsigned int inst_id, const db::Box ®ion)
|
|
|
|
|
{
|
|
|
|
|
db::shape_reference_translator<db::PolygonRef> rt (mp_subject_layout);
|
2018-10-06 01:40:01 +02:00
|
|
|
|
2018-10-06 23:59:47 +02:00
|
|
|
// Look up all shapes from the intruder instance which interact with the subject shape
|
|
|
|
|
// (given through region)
|
2018-10-07 16:56:14 +02:00
|
|
|
// TODO: should be lighter, cache, handle arrays ..
|
2018-10-06 23:59:47 +02:00
|
|
|
db::RecursiveShapeIterator si (*mp_intruder_layout, intruder_cell, m_intruder_layer, region);
|
|
|
|
|
si.shape_flags (polygon_ref_flags ());
|
|
|
|
|
while (! si.at_end ()) {
|
2018-10-06 01:40:01 +02:00
|
|
|
|
2018-10-06 23:59:47 +02:00
|
|
|
const db::PolygonRef *ref2 = si.shape ().basic_ptr (db::PolygonRef::tag ());
|
2018-10-06 01:40:01 +02:00
|
|
|
|
2018-10-06 23:59:47 +02:00
|
|
|
// reuse the same id for shapes from the same instance -> this avoid duplicates with different IDs on
|
|
|
|
|
// the intruder side.
|
|
|
|
|
std::map<std::pair<unsigned int, const db::PolygonRef *>, unsigned int>::const_iterator k = m_inst_shape_ids.find (std::make_pair (inst_id, ref2));
|
|
|
|
|
if (k == m_inst_shape_ids.end ()) {
|
2018-10-06 01:40:01 +02:00
|
|
|
|
2018-10-06 23:59:47 +02:00
|
|
|
k = m_inst_shape_ids.insert (std::make_pair (std::make_pair (inst_id, ref2), mp_result->next_id ())).first;
|
2018-10-06 01:40:01 +02:00
|
|
|
|
2018-10-06 23:59:47 +02:00
|
|
|
// NOTE: we intentionally rewrite to the *subject* layout - this way polygon refs in the context come from the
|
|
|
|
|
// subject, not from the intruder.
|
|
|
|
|
mp_result->add_shape (k->second, rt (*ref2, tn * si.trans ()));
|
2018-09-22 23:37:23 +02:00
|
|
|
|
2018-10-06 23:59:47 +02:00
|
|
|
}
|
2018-09-22 23:37:23 +02:00
|
|
|
|
2018-10-06 23:59:47 +02:00
|
|
|
mp_result->add_interaction (id1, k->second);
|
2018-09-22 22:32:36 +02:00
|
|
|
|
2018-10-06 23:59:47 +02:00
|
|
|
++si;
|
2018-09-22 22:32:36 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-09-23 16:57:49 +02:00
|
|
|
static bool
|
2018-09-25 23:26:18 +02:00
|
|
|
instances_interact (const db::Layout *layout1, const db::CellInstArray *inst1, unsigned int layer1, const db::Layout *layout2, const db::CellInstArray *inst2, unsigned int layer2, db::Coord dist)
|
2018-09-23 16:57:49 +02:00
|
|
|
{
|
2018-09-23 22:34:50 +02:00
|
|
|
// TODO: this algorithm is not in particular effective for identical arrays
|
|
|
|
|
|
2018-09-23 16:57:49 +02:00
|
|
|
const db::Cell &cell1 = layout1->cell (inst1->object ().cell_index ());
|
|
|
|
|
const db::Cell &cell2 = layout2->cell (inst2->object ().cell_index ());
|
|
|
|
|
db::box_convert <db::CellInst, true> inst2_bc (*layout2, layer2);
|
|
|
|
|
|
|
|
|
|
std::set<db::ICplxTrans> relative_trans_seen;
|
|
|
|
|
|
|
|
|
|
for (db::CellInstArray::iterator n = inst1->begin (); ! n.at_end (); ++n) {
|
|
|
|
|
|
|
|
|
|
db::ICplxTrans tn1 = inst1->complex_trans (*n);
|
|
|
|
|
db::ICplxTrans tni1 = tn1.inverted ();
|
2018-09-25 23:26:18 +02:00
|
|
|
db::Box ibox1 = tn1 * cell1.bbox (layer1).enlarged (db::Vector (dist, dist));
|
2018-09-23 16:57:49 +02:00
|
|
|
|
|
|
|
|
if (! ibox1.empty ()) {
|
|
|
|
|
|
2018-10-07 16:56:14 +02:00
|
|
|
// TODO: in some cases, it may be possible to optimize this for arrays
|
2018-09-23 16:57:49 +02:00
|
|
|
|
|
|
|
|
for (db::CellInstArray::iterator k = inst2->begin_touching (ibox1.enlarged (db::Vector (-1, -1)), inst2_bc); ! k.at_end (); ++k) {
|
|
|
|
|
|
2018-09-23 22:34:50 +02:00
|
|
|
if (inst1 == inst2 && *n == *k) {
|
|
|
|
|
// skip self-interactions - this is handled inside the cell
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-23 16:57:49 +02:00
|
|
|
db::ICplxTrans tn2 = inst2->complex_trans (*k);
|
2018-09-25 23:26:18 +02:00
|
|
|
|
|
|
|
|
// NOTE: we need to enlarge both subject *and* intruder boxes - either ubject comes close to intruder or the other way around
|
|
|
|
|
db::Box ibox2 = tn2 * cell2.bbox (layer2).enlarged (db::Vector (dist, dist));
|
2018-09-23 16:57:49 +02:00
|
|
|
|
|
|
|
|
db::ICplxTrans tn21 = tni1 * tn2;
|
|
|
|
|
if (! relative_trans_seen.insert (tn21).second) {
|
|
|
|
|
// this relative transformation was already seen
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db::Box cbox = ibox1 & ibox2;
|
|
|
|
|
if (! cbox.empty ()) {
|
|
|
|
|
|
|
|
|
|
db::ICplxTrans tni2 = tn2.inverted ();
|
|
|
|
|
|
|
|
|
|
// not very strong, but already useful: the cells interact if there is a layer1 in cell1
|
|
|
|
|
// in the common box and a layer2 in the cell2 in the common box
|
|
|
|
|
if (! db::RecursiveShapeIterator (*layout1, cell1, layer1, tni1 * cbox, true).at_end () &&
|
|
|
|
|
! db::RecursiveShapeIterator (*layout2, cell2, layer2, tni2 * cbox, true).at_end ()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-22 22:32:36 +02:00
|
|
|
struct InteractionRegistrationInst2Inst
|
2018-10-06 01:40:01 +02:00
|
|
|
: db::box_scanner_receiver2<db::CellInstArray, unsigned int, db::CellInstArray, unsigned int>
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2018-10-01 22:45:46 +02:00
|
|
|
typedef std::pair<std::set<const db::CellInstArray *>, std::set<db::PolygonRef> > interaction_value_type;
|
|
|
|
|
|
|
|
|
|
InteractionRegistrationInst2Inst (const db::Layout *subject_layout, unsigned int subject_layer, const db::Layout *intruder_layout, unsigned int intruder_layer, db::Coord dist, std::map<const db::CellInstArray *, interaction_value_type> *result)
|
2018-09-25 23:26:18 +02:00
|
|
|
: mp_subject_layout (subject_layout), mp_intruder_layout (intruder_layout), m_subject_layer (subject_layer), m_intruder_layer (intruder_layer), m_dist (dist), mp_result (result)
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
|
|
|
|
// nothing yet ..
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-06 01:40:01 +02:00
|
|
|
void add (const db::CellInstArray *inst1, unsigned int id1, const db::CellInstArray *inst2, unsigned int id2)
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
2018-09-23 22:34:50 +02:00
|
|
|
// NOTE: self-interactions are possible for arrays: different elements of the
|
|
|
|
|
// array may interact which is a cell-external interaction.
|
2018-10-06 01:40:01 +02:00
|
|
|
if (mp_subject_layout != mp_intruder_layout || id1 != id2 || inst1->size () > 1) {
|
|
|
|
|
|
|
|
|
|
bool ignore = false;
|
|
|
|
|
if (mp_subject_layout == mp_intruder_layout && m_subject_layer == m_intruder_layer) {
|
|
|
|
|
if (m_interactions.find (std::make_pair (id2, id1)) != m_interactions.end ()) {
|
|
|
|
|
// for self interactions ignore the reverse interactions
|
|
|
|
|
ignore = true;
|
|
|
|
|
} else {
|
|
|
|
|
m_interactions.insert (std::make_pair (id1, id2));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! ignore && instances_interact (mp_subject_layout, inst1, m_subject_layer, mp_intruder_layout, inst2, m_intruder_layer, m_dist)) {
|
|
|
|
|
(*mp_result) [inst1].first.insert (inst2);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-23 16:08:00 +02:00
|
|
|
}
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2018-09-23 16:57:49 +02:00
|
|
|
const db::Layout *mp_subject_layout, *mp_intruder_layout;
|
|
|
|
|
unsigned int m_subject_layer, m_intruder_layer;
|
2018-09-25 23:26:18 +02:00
|
|
|
db::Coord m_dist;
|
2018-09-22 22:32:36 +02:00
|
|
|
std::map<const db::CellInstArray *, std::pair<std::set<const db::CellInstArray *>, std::set<db::PolygonRef> > > *mp_result;
|
2018-10-06 01:40:01 +02:00
|
|
|
std::set<std::pair<unsigned int, unsigned int> > m_interactions;
|
2018-09-22 22:32:36 +02:00
|
|
|
};
|
|
|
|
|
|
2018-09-23 16:57:49 +02:00
|
|
|
static bool
|
2018-09-25 23:26:18 +02:00
|
|
|
instance_shape_interacts (const db::Layout *layout, const db::CellInstArray *inst, unsigned int layer, const db::PolygonRef &ref, db::Coord dist)
|
2018-09-23 16:57:49 +02:00
|
|
|
{
|
|
|
|
|
const db::Cell &cell = layout->cell (inst->object ().cell_index ());
|
|
|
|
|
db::box_convert <db::CellInst, true> inst_bc (*layout, layer);
|
|
|
|
|
db::Box rbox = ref.box ();
|
|
|
|
|
|
2018-09-25 23:26:18 +02:00
|
|
|
for (db::CellInstArray::iterator n = inst->begin_touching (rbox.enlarged (db::Vector (dist - 1, dist - 1)), inst_bc); ! n.at_end (); ++n) {
|
2018-09-23 16:57:49 +02:00
|
|
|
|
|
|
|
|
db::ICplxTrans tn = inst->complex_trans (*n);
|
2018-09-25 23:26:18 +02:00
|
|
|
db::Box cbox = (tn * cell.bbox (layer)).enlarged (db::Vector (dist, dist)) & rbox.enlarged (db::Vector (dist, dist));
|
2018-09-23 16:57:49 +02:00
|
|
|
|
|
|
|
|
if (! cbox.empty ()) {
|
|
|
|
|
|
|
|
|
|
db::ICplxTrans tni = tn.inverted ();
|
|
|
|
|
|
|
|
|
|
// not very strong, but already useful: the cells interact if there is a layer in cell
|
|
|
|
|
// in the common box
|
|
|
|
|
if (! db::RecursiveShapeIterator (*layout, cell, layer, tni * cbox, true).at_end ()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-22 22:32:36 +02:00
|
|
|
struct InteractionRegistrationInst2Shape
|
2018-10-06 01:40:01 +02:00
|
|
|
: db::box_scanner_receiver2<db::CellInstArray, unsigned int, db::PolygonRef, unsigned int>
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2018-09-25 23:26:18 +02:00
|
|
|
InteractionRegistrationInst2Shape (const db::Layout *subject_layout, unsigned int subject_layer, db::Coord dist, std::map<const db::CellInstArray *, std::pair<std::set<const db::CellInstArray *>, std::set<db::PolygonRef> > > *result)
|
|
|
|
|
: mp_subject_layout (subject_layout), m_subject_layer (subject_layer), m_dist (dist), mp_result (result)
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
|
|
|
|
// nothing yet ..
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-06 01:40:01 +02:00
|
|
|
void add (const db::CellInstArray *inst, unsigned int, const db::PolygonRef *ref, unsigned int)
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
2018-09-25 23:26:18 +02:00
|
|
|
if (instance_shape_interacts (mp_subject_layout, inst, m_subject_layer, *ref, m_dist)) {
|
2018-09-23 16:57:49 +02:00
|
|
|
(*mp_result) [inst].second.insert (*ref);
|
|
|
|
|
}
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2018-09-23 16:57:49 +02:00
|
|
|
const db::Layout *mp_subject_layout;
|
|
|
|
|
unsigned int m_subject_layer;
|
2018-09-25 23:26:18 +02:00
|
|
|
db::Coord m_dist;
|
2018-09-22 22:32:36 +02:00
|
|
|
std::map<const db::CellInstArray *, std::pair<std::set<const db::CellInstArray *>, std::set<db::PolygonRef> > > *mp_result;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------
|
|
|
|
|
// LocalProcessor implementation
|
|
|
|
|
|
2018-09-25 22:25:40 +02:00
|
|
|
LocalProcessor::LocalProcessor (db::Layout *layout, db::Cell *top)
|
2018-10-01 22:45:46 +02:00
|
|
|
: mp_subject_layout (layout), mp_intruder_layout (layout), mp_subject_top (top), mp_intruder_top (top)
|
|
|
|
|
{
|
|
|
|
|
// .. nothing yet ..
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LocalProcessor::LocalProcessor (db::Layout *subject_layout, db::Cell *subject_top, const db::Layout *intruder_layout, const db::Cell *intruder_top)
|
|
|
|
|
: mp_subject_layout (subject_layout), mp_intruder_layout (intruder_layout), mp_subject_top (subject_top), mp_intruder_top (intruder_top)
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
2018-09-25 22:25:40 +02:00
|
|
|
// .. nothing yet ..
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
2018-09-25 23:26:18 +02:00
|
|
|
void LocalProcessor::run (LocalOperation *op, unsigned int subject_layer, unsigned int intruder_layer, unsigned int output_layer)
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
2018-09-25 22:25:40 +02:00
|
|
|
LocalProcessorContexts contexts;
|
2018-09-25 23:26:18 +02:00
|
|
|
compute_contexts (contexts, op, subject_layer, intruder_layer);
|
2018-09-25 22:25:40 +02:00
|
|
|
compute_results (contexts, op, output_layer);
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
2018-09-25 22:25:40 +02:00
|
|
|
void LocalProcessor::push_results (db::Cell *cell, unsigned int output_layer, const std::set<db::PolygonRef> &result) const
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
|
|
|
|
if (! result.empty ()) {
|
2018-09-25 22:25:40 +02:00
|
|
|
cell->shapes (output_layer).insert (result.begin (), result.end ());
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 23:26:18 +02:00
|
|
|
void LocalProcessor::compute_contexts (LocalProcessorContexts &contexts, const LocalOperation *op, unsigned int subject_layer, unsigned int intruder_layer)
|
2018-09-23 16:08:00 +02:00
|
|
|
{
|
2018-09-23 17:49:10 +02:00
|
|
|
tl::SelfTimer timer (tl::verbosity () >= 21, tl::to_string (tr ("Computing contexts for ")) + description ());
|
|
|
|
|
|
2018-09-25 22:25:40 +02:00
|
|
|
contexts.clear ();
|
|
|
|
|
contexts.set_intruder_layer (intruder_layer);
|
|
|
|
|
contexts.set_subject_layer (subject_layer);
|
|
|
|
|
contexts.set_description (op->description ());
|
2018-09-23 16:08:00 +02:00
|
|
|
|
|
|
|
|
std::pair<std::set<db::CellInstArray>, std::set<db::PolygonRef> > intruders;
|
2018-10-01 22:45:46 +02:00
|
|
|
compute_contexts (contexts, 0, 0, mp_subject_top, db::ICplxTrans (), mp_intruder_top, intruders, op->dist ());
|
2018-09-23 16:08:00 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-01 22:45:46 +02:00
|
|
|
void LocalProcessor::compute_contexts (LocalProcessorContexts &contexts,
|
|
|
|
|
db::LocalProcessorCellContext *parent_context,
|
|
|
|
|
db::Cell *subject_parent,
|
|
|
|
|
db::Cell *subject_cell,
|
|
|
|
|
const db::ICplxTrans &subject_cell_inst,
|
|
|
|
|
const db::Cell *intruder_cell,
|
|
|
|
|
const std::pair<std::set<CellInstArray>, std::set<PolygonRef> > &intruders,
|
|
|
|
|
db::Coord dist)
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
2018-09-23 17:49:10 +02:00
|
|
|
if (tl::verbosity () >= 30) {
|
2018-10-01 22:45:46 +02:00
|
|
|
if (! subject_parent) {
|
|
|
|
|
tl::log << tr ("Computing context for top cell ") << mp_subject_layout->cell_name (subject_cell->cell_index ());
|
2018-09-23 17:49:10 +02:00
|
|
|
} else {
|
2018-10-01 22:45:46 +02:00
|
|
|
tl::log << tr ("Computing context for ") << mp_subject_layout->cell_name (subject_parent->cell_index ()) << " -> " << mp_subject_layout->cell_name (subject_cell->cell_index ()) << " @" << subject_cell_inst.to_string ();
|
2018-09-23 17:49:10 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-01 22:45:46 +02:00
|
|
|
db::LocalProcessorCellContexts &cell_contexts = contexts.contexts_per_cell (subject_cell, intruder_cell);
|
2018-09-22 22:32:36 +02:00
|
|
|
|
2018-09-25 22:25:40 +02:00
|
|
|
db::LocalProcessorCellContext *context = cell_contexts.find_context (intruders);
|
2018-09-22 22:32:36 +02:00
|
|
|
if (context) {
|
2018-10-01 22:45:46 +02:00
|
|
|
context->add (parent_context, subject_parent, subject_cell_inst);
|
2018-09-22 22:32:36 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 22:25:40 +02:00
|
|
|
context = cell_contexts.create (intruders);
|
2018-10-01 22:45:46 +02:00
|
|
|
context->add (parent_context, subject_parent, subject_cell_inst);
|
2018-09-22 22:32:36 +02:00
|
|
|
|
2018-10-01 22:45:46 +02:00
|
|
|
const db::Shapes *intruder_shapes = 0;
|
|
|
|
|
if (intruder_cell) {
|
|
|
|
|
intruder_shapes = &intruder_cell->shapes (contexts.intruder_layer ());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db::box_convert <db::CellInstArray, true> inst_bcs (*mp_subject_layout, contexts.subject_layer ());
|
|
|
|
|
db::box_convert <db::CellInstArray, true> inst_bci (*mp_intruder_layout, contexts.intruder_layer ());
|
|
|
|
|
db::box_convert <db::CellInst, true> inst_bcii (*mp_intruder_layout, contexts.intruder_layer ());
|
2018-09-22 22:32:36 +02:00
|
|
|
|
2018-10-01 22:45:46 +02:00
|
|
|
// handle top-down interactions (subject instances interacting with intruder shapes)
|
|
|
|
|
// and sibling interactions
|
2018-09-22 22:32:36 +02:00
|
|
|
|
2018-10-01 22:45:46 +02:00
|
|
|
if (! subject_cell->begin ().at_end ()) {
|
2018-09-22 22:32:36 +02:00
|
|
|
|
|
|
|
|
typedef std::pair<std::set<const db::CellInstArray *>, std::set<db::PolygonRef> > interaction_value_type;
|
|
|
|
|
|
|
|
|
|
std::map<const db::CellInstArray *, interaction_value_type> interactions;
|
|
|
|
|
|
2018-09-23 17:22:08 +02:00
|
|
|
// insert dummy interactions to handle at least the child cell vs. itself
|
2018-10-01 22:45:46 +02:00
|
|
|
// - this is important so we will always handle the instances unless they are
|
|
|
|
|
// entirely empty in the subject layer
|
|
|
|
|
for (db::Cell::const_iterator i = subject_cell->begin (); !i.at_end (); ++i) {
|
|
|
|
|
if (! inst_bcs (i->cell_inst ()).empty ()) {
|
|
|
|
|
interactions.insert (std::make_pair (&i->cell_inst (), interaction_value_type ()));
|
|
|
|
|
}
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
db::box_scanner2<db::CellInstArray, int, db::CellInstArray, int> scanner;
|
2018-10-01 22:45:46 +02:00
|
|
|
InteractionRegistrationInst2Inst rec (mp_subject_layout, contexts.subject_layer (), mp_intruder_layout, contexts.intruder_layer (), dist, &interactions);
|
2018-09-22 22:32:36 +02:00
|
|
|
|
2018-10-06 01:40:01 +02:00
|
|
|
unsigned int id = 0;
|
|
|
|
|
|
|
|
|
|
if (subject_cell == intruder_cell) {
|
2018-10-01 22:45:46 +02:00
|
|
|
|
2018-10-06 01:40:01 +02:00
|
|
|
// Use the same id's for same instances - this way we can easily detect same instances
|
|
|
|
|
// and don't make the self-interacting
|
|
|
|
|
|
|
|
|
|
for (db::Cell::const_iterator i = subject_cell->begin (); !i.at_end (); ++i) {
|
|
|
|
|
unsigned int iid = ++id;
|
|
|
|
|
if (! inst_bcs (i->cell_inst ()).empty ()) {
|
|
|
|
|
scanner.insert1 (&i->cell_inst (), iid);
|
|
|
|
|
}
|
2018-10-01 22:45:46 +02:00
|
|
|
if (! inst_bci (i->cell_inst ()).empty ()) {
|
2018-10-06 01:40:01 +02:00
|
|
|
scanner.insert2 (&i->cell_inst (), iid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
for (db::Cell::const_iterator i = subject_cell->begin (); !i.at_end (); ++i) {
|
|
|
|
|
if (! inst_bcs (i->cell_inst ()).empty ()) {
|
|
|
|
|
scanner.insert1 (&i->cell_inst (), ++id);
|
2018-10-01 22:45:46 +02:00
|
|
|
}
|
2018-09-23 20:06:27 +02:00
|
|
|
}
|
2018-10-06 01:40:01 +02:00
|
|
|
|
|
|
|
|
if (intruder_cell) {
|
|
|
|
|
for (db::Cell::const_iterator i = intruder_cell->begin (); !i.at_end (); ++i) {
|
|
|
|
|
if (! inst_bci (i->cell_inst ()).empty ()) {
|
|
|
|
|
scanner.insert2 (&i->cell_inst (), ++id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (std::set<db::CellInstArray>::const_iterator i = intruders.first.begin (); i != intruders.first.end (); ++i) {
|
2018-09-23 20:06:27 +02:00
|
|
|
if (! inst_bci (*i).empty ()) {
|
2018-10-06 01:40:01 +02:00
|
|
|
scanner.insert2 (i.operator-> (), ++id);
|
2018-09-23 20:06:27 +02:00
|
|
|
}
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
2018-09-25 23:26:18 +02:00
|
|
|
scanner.process (rec, dist, inst_bcs, inst_bci);
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
db::box_scanner2<db::CellInstArray, int, db::PolygonRef, int> scanner;
|
2018-10-01 22:45:46 +02:00
|
|
|
InteractionRegistrationInst2Shape rec (mp_subject_layout, contexts.subject_layer (), dist, &interactions);
|
2018-09-22 22:32:36 +02:00
|
|
|
|
2018-10-01 22:45:46 +02:00
|
|
|
for (db::Cell::const_iterator i = subject_cell->begin (); !i.at_end (); ++i) {
|
2018-09-23 20:06:27 +02:00
|
|
|
if (! inst_bcs (i->cell_inst ()).empty ()) {
|
|
|
|
|
scanner.insert1 (&i->cell_inst (), 0);
|
|
|
|
|
}
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (std::set<db::PolygonRef>::const_iterator i = intruders.second.begin (); i != intruders.second.end (); ++i) {
|
|
|
|
|
scanner.insert2 (i.operator-> (), 0);
|
|
|
|
|
}
|
2018-10-01 22:45:46 +02:00
|
|
|
|
|
|
|
|
if (intruder_shapes) {
|
|
|
|
|
for (db::Shapes::shape_iterator i = intruder_shapes->begin (polygon_ref_flags ()); !i.at_end (); ++i) {
|
|
|
|
|
scanner.insert2 (i->basic_ptr (db::PolygonRef::tag ()), 0);
|
|
|
|
|
}
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
2018-09-25 23:26:18 +02:00
|
|
|
scanner.process (rec, dist, inst_bcs, db::box_convert<db::PolygonRef> ());
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-01 22:45:46 +02:00
|
|
|
for (std::map<const db::CellInstArray *, interaction_value_type>::const_iterator i = interactions.begin (); i != interactions.end (); ++i) {
|
2018-09-22 22:32:36 +02:00
|
|
|
|
2018-10-01 22:45:46 +02:00
|
|
|
db::Cell &subject_child_cell = mp_subject_layout->cell (i->first->object ().cell_index ());
|
2018-10-06 23:59:47 +02:00
|
|
|
db::shape_reference_translator<db::PolygonRef> rt (mp_subject_layout);
|
2018-09-22 22:32:36 +02:00
|
|
|
|
|
|
|
|
for (db::CellInstArray::iterator n = i->first->begin (); ! n.at_end (); ++n) {
|
|
|
|
|
|
|
|
|
|
db::ICplxTrans tn = i->first->complex_trans (*n);
|
|
|
|
|
db::ICplxTrans tni = tn.inverted ();
|
2018-10-01 22:45:46 +02:00
|
|
|
db::Box nbox = tn * subject_child_cell.bbox (contexts.subject_layer ()).enlarged (db::Vector (dist, dist));
|
2018-09-22 22:32:36 +02:00
|
|
|
|
|
|
|
|
if (! nbox.empty ()) {
|
|
|
|
|
|
2018-09-22 23:37:23 +02:00
|
|
|
std::pair<std::set<db::CellInstArray>, std::set<db::PolygonRef> > intruders_below;
|
|
|
|
|
|
|
|
|
|
for (std::set<db::PolygonRef>::const_iterator p = i->second.second.begin (); p != i->second.second.end (); ++p) {
|
|
|
|
|
if (nbox.overlaps (p->box ())) {
|
2018-10-06 23:59:47 +02:00
|
|
|
intruders_below.second.insert (rt (*p, tni));
|
2018-09-22 23:37:23 +02:00
|
|
|
}
|
|
|
|
|
}
|
2018-09-22 22:32:36 +02:00
|
|
|
|
2018-10-07 16:56:14 +02:00
|
|
|
// TODO: in some cases, it may be possible to optimize this for arrays
|
2018-09-22 22:32:36 +02:00
|
|
|
|
|
|
|
|
for (std::set<const db::CellInstArray *>::const_iterator j = i->second.first.begin (); j != i->second.first.end (); ++j) {
|
|
|
|
|
for (db::CellInstArray::iterator k = (*j)->begin_touching (nbox.enlarged (db::Vector (-1, -1)), inst_bcii); ! k.at_end (); ++k) {
|
2018-10-06 21:56:13 +02:00
|
|
|
db::ICplxTrans tk = (*j)->complex_trans (*k);
|
|
|
|
|
// NOTE: no self-interactions
|
|
|
|
|
if (i->first != *j || tn != tk) {
|
|
|
|
|
intruders_below.first.insert (db::CellInstArray (db::CellInst ((*j)->object ().cell_index ()), tni * tk));
|
|
|
|
|
}
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-01 22:45:46 +02:00
|
|
|
db::Cell *intruder_child_cell = (subject_cell == intruder_cell ? &subject_child_cell : 0);
|
|
|
|
|
compute_contexts (contexts, context, subject_cell, &subject_child_cell, tn, intruder_child_cell, intruders_below, dist);
|
2018-09-22 22:32:36 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2018-09-25 22:25:40 +02:00
|
|
|
LocalProcessor::compute_results (LocalProcessorContexts &contexts, const LocalOperation *op, unsigned int output_layer)
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
2018-09-23 17:49:10 +02:00
|
|
|
tl::SelfTimer timer (tl::verbosity () >= 21, tl::to_string (tr ("Computing results for ")) + description ());
|
|
|
|
|
|
|
|
|
|
// avoids updates while we work on the layout
|
2018-10-01 22:45:46 +02:00
|
|
|
mp_subject_layout->update ();
|
|
|
|
|
db::LayoutLocker locker (mp_subject_layout);
|
2018-09-23 17:49:10 +02:00
|
|
|
|
2018-10-01 22:45:46 +02:00
|
|
|
for (db::Layout::bottom_up_const_iterator bu = mp_subject_layout->begin_bottom_up (); bu != mp_subject_layout->end_bottom_up (); ++bu) {
|
2018-09-22 22:32:36 +02:00
|
|
|
|
2018-10-01 22:45:46 +02:00
|
|
|
LocalProcessorContexts::iterator cpc = contexts.context_map ().find (&mp_subject_layout->cell (*bu));
|
2018-09-25 22:25:40 +02:00
|
|
|
if (cpc != contexts.context_map ().end ()) {
|
|
|
|
|
cpc->second.compute_results (contexts, cpc->first, op, output_layer, this);
|
|
|
|
|
contexts.context_map ().erase (cpc);
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2018-10-01 22:45:46 +02:00
|
|
|
LocalProcessor::compute_local_cell (LocalProcessorContexts &contexts, db::Cell *subject_cell, const db::Cell *intruder_cell, const db::LocalOperation *op, const std::pair<std::set<CellInstArray>, std::set<db::PolygonRef> > &intruders, std::set<db::PolygonRef> &result)
|
2018-09-22 22:32:36 +02:00
|
|
|
{
|
2018-10-01 22:45:46 +02:00
|
|
|
const db::Shapes *subject_shapes = &subject_cell->shapes (contexts.subject_layer ());
|
|
|
|
|
|
|
|
|
|
const db::Shapes *intruder_shapes = 0;
|
|
|
|
|
if (intruder_cell) {
|
|
|
|
|
intruder_shapes = &intruder_cell->shapes (contexts.intruder_layer ());
|
|
|
|
|
if (intruder_shapes->empty ()) {
|
|
|
|
|
intruder_shapes = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-22 22:32:36 +02:00
|
|
|
|
|
|
|
|
// local shapes vs. child cell
|
|
|
|
|
|
2018-10-06 01:40:01 +02:00
|
|
|
ShapeInteractions interactions;
|
2018-10-01 22:45:46 +02:00
|
|
|
db::box_convert <db::CellInstArray, true> inst_bci (*mp_intruder_layout, contexts.intruder_layer ());
|
2018-09-22 22:32:36 +02:00
|
|
|
|
2018-10-06 01:40:01 +02:00
|
|
|
// insert dummy interactions to accommodate subject vs. nothing and assign an ID
|
|
|
|
|
// range for the subject shapes.
|
|
|
|
|
unsigned int subject_id0 = 0;
|
|
|
|
|
for (db::Shapes::shape_iterator i = subject_shapes->begin (polygon_ref_flags ()); !i.at_end (); ++i) {
|
|
|
|
|
|
|
|
|
|
unsigned int id = interactions.next_id ();
|
|
|
|
|
if (subject_id0 == 0) {
|
|
|
|
|
subject_id0 = id;
|
2018-09-23 17:22:08 +02:00
|
|
|
}
|
2018-10-06 01:40:01 +02:00
|
|
|
|
|
|
|
|
if (op->on_empty_intruder_hint () != LocalOperation::Drop) {
|
|
|
|
|
const db::PolygonRef *ref = i->basic_ptr (db::PolygonRef::tag ());
|
|
|
|
|
interactions.add_subject (id, *ref);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-01 22:45:46 +02:00
|
|
|
if (! subject_shapes->empty () && (intruder_shapes || ! intruders.second.empty ())) {
|
2018-09-22 22:32:36 +02:00
|
|
|
|
2018-10-06 01:40:01 +02:00
|
|
|
if (subject_cell == intruder_cell && contexts.subject_layer () == contexts.intruder_layer ()) {
|
2018-09-22 22:32:36 +02:00
|
|
|
|
2018-10-06 01:40:01 +02:00
|
|
|
db::box_scanner<db::PolygonRef, int> scanner;
|
|
|
|
|
InteractionRegistrationShape1 rec (&interactions);
|
2018-09-22 22:32:36 +02:00
|
|
|
|
2018-10-06 01:40:01 +02:00
|
|
|
unsigned int id = subject_id0;
|
|
|
|
|
for (db::Shapes::shape_iterator i = subject_shapes->begin (polygon_ref_flags ()); !i.at_end (); ++i) {
|
|
|
|
|
const db::PolygonRef *ref = i->basic_ptr (db::PolygonRef::tag ());
|
|
|
|
|
scanner.insert (ref, id++);
|
|
|
|
|
}
|
2018-10-01 22:45:46 +02:00
|
|
|
|
2018-10-06 01:40:01 +02:00
|
|
|
for (std::set<db::PolygonRef>::const_iterator i = intruders.second.begin (); i != intruders.second.end (); ++i) {
|
|
|
|
|
scanner.insert (i.operator-> (), interactions.next_id ());
|
2018-10-01 22:45:46 +02:00
|
|
|
}
|
2018-09-22 22:32:36 +02:00
|
|
|
|
2018-10-06 01:40:01 +02:00
|
|
|
scanner.process (rec, op->dist (), db::box_convert<db::PolygonRef> ());
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
db::box_scanner2<db::PolygonRef, int, db::PolygonRef, int> scanner;
|
|
|
|
|
InteractionRegistrationShape2Shape rec (mp_subject_layout == mp_intruder_layout ? 0 : mp_subject_layout, &interactions);
|
|
|
|
|
|
|
|
|
|
unsigned int id = subject_id0;
|
|
|
|
|
for (db::Shapes::shape_iterator i = subject_shapes->begin (polygon_ref_flags ()); !i.at_end (); ++i) {
|
|
|
|
|
const db::PolygonRef *ref = i->basic_ptr (db::PolygonRef::tag ());
|
|
|
|
|
scanner.insert1 (ref, id++);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (std::set<db::PolygonRef>::const_iterator i = intruders.second.begin (); i != intruders.second.end (); ++i) {
|
|
|
|
|
scanner.insert2 (i.operator-> (), interactions.next_id ());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (intruder_shapes) {
|
|
|
|
|
for (db::Shapes::shape_iterator i = intruder_shapes->begin (polygon_ref_flags ()); !i.at_end (); ++i) {
|
|
|
|
|
scanner.insert2 (i->basic_ptr (db::PolygonRef::tag ()), interactions.next_id ());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scanner.process (rec, op->dist (), db::box_convert<db::PolygonRef> (), db::box_convert<db::PolygonRef> ());
|
|
|
|
|
|
|
|
|
|
}
|
2018-09-22 22:32:36 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-01 22:45:46 +02:00
|
|
|
if (! subject_shapes->empty () && ! ((! intruder_cell || intruder_cell->begin ().at_end ()) && intruders.first.empty ())) {
|
2018-09-22 22:32:36 +02:00
|
|
|
|
|
|
|
|
db::box_scanner2<db::PolygonRef, int, db::CellInstArray, int> scanner;
|
2018-10-01 22:45:46 +02:00
|
|
|
InteractionRegistrationShape2Inst rec (mp_subject_layout, mp_intruder_layout, contexts.intruder_layer (), op->dist (), &interactions);
|
2018-09-22 22:32:36 +02:00
|
|
|
|
2018-10-06 01:40:01 +02:00
|
|
|
unsigned int id = subject_id0;
|
2018-10-01 22:45:46 +02:00
|
|
|
for (db::Shapes::shape_iterator i = subject_shapes->begin (polygon_ref_flags ()); !i.at_end (); ++i) {
|
2018-10-06 01:40:01 +02:00
|
|
|
scanner.insert1 (i->basic_ptr (db::PolygonRef::tag ()), id++);
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-06 01:40:01 +02:00
|
|
|
unsigned int inst_id = 0;
|
|
|
|
|
|
|
|
|
|
if (subject_cell == intruder_cell && contexts.subject_layer () == contexts.intruder_layer ()) {
|
|
|
|
|
|
|
|
|
|
// Same cell, same layer -> no shape to child instance interactions because this will be taken care of
|
|
|
|
|
// by the instances themselves (and their intruders). This also means, we prefer to deal with
|
|
|
|
|
// interactions low in the hierarchy.
|
|
|
|
|
|
|
|
|
|
} else if (intruder_cell) {
|
2018-10-01 22:45:46 +02:00
|
|
|
for (db::Cell::const_iterator i = intruder_cell->begin (); !i.at_end (); ++i) {
|
|
|
|
|
if (! inst_bci (i->cell_inst ()).empty ()) {
|
2018-10-06 01:40:01 +02:00
|
|
|
scanner.insert2 (&i->cell_inst (), ++inst_id);
|
2018-10-01 22:45:46 +02:00
|
|
|
}
|
2018-09-23 20:06:27 +02:00
|
|
|
}
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
2018-10-01 22:45:46 +02:00
|
|
|
|
2018-09-22 22:32:36 +02:00
|
|
|
for (std::set<db::CellInstArray>::const_iterator i = intruders.first.begin (); i != intruders.first.end (); ++i) {
|
2018-09-23 20:06:27 +02:00
|
|
|
if (! inst_bci (*i).empty ()) {
|
2018-10-06 01:40:01 +02:00
|
|
|
scanner.insert2 (i.operator-> (), ++inst_id);
|
2018-09-23 20:06:27 +02:00
|
|
|
}
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
2018-09-25 23:26:18 +02:00
|
|
|
scanner.process (rec, op->dist (), db::box_convert<db::PolygonRef> (), inst_bci);
|
2018-09-22 22:32:36 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-01 22:45:46 +02:00
|
|
|
op->compute_local (mp_subject_layout, interactions, result);
|
2018-09-22 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|