File size: 5,104 Bytes
5cdf637
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2026, The OpenROAD Authors

#include <memory>
#include <string>
#include <vector>

#include "MplTest.h"
#include "gtest/gtest.h"
#include "mpl/rtl_mp.h"
#include "odb/db.h"
#include "odb/dbTypes.h"
#include "odb/geom.h"

namespace mpl {
namespace {

class TestBlockMacroChannels : public MplTest
{
 protected:
  void SetUp() override
  {
    MplTest::SetUp();

    macro_placer_ = std::make_unique<MacroPlacer>(db_.get(),
                                                  /*sta=*/nullptr,
                                                  &logger_,
                                                  /*tritonpart=*/nullptr);

    odb::dbLib* library = db_->findLib("lib");

    macro_master_ = odb::dbMaster::create(library, "block_master");
    macro_master_->setType(odb::dbMasterType::BLOCK);
    macro_master_->setWidth(master_width_);
    macro_master_->setHeight(master_height_);
    macro_master_->setFrozen();
  }

  odb::dbInst* createFixedMacro(const std::string& name,
                                const int origin_x,
                                const int origin_y)
  {
    odb::dbInst* instance = odb::dbInst::create(
        db_->getChip()->getBlock(), macro_master_, name.c_str());
    instance->setLocation(origin_x, origin_y);
    instance->setPlacementStatus(odb::dbPlacementStatus::FIRM);
    return instance;
  }

  std::vector<odb::Rect> getBlockages() const
  {
    std::vector<odb::Rect> rectangles;
    for (odb::dbBlockage* blockage :
         db_->getChip()->getBlock()->getBlockages()) {
      rectangles.push_back(blockage->getBBox()->getBox());
    }
    return rectangles;
  }

  const int master_width_ = 100000;
  const int master_height_ = 100000;
  const int macro_x_ = 50000;
  const int macro_y_ = 50000;
  std::unique_ptr<MacroPlacer> macro_placer_;
  odb::dbMaster* macro_master_ = nullptr;
};

// DEF halo only: blockage equals master bbox expanded by the DEF halo.
TEST_F(TestBlockMacroChannels, DefHaloOnly)
{
  odb::dbInst* instance = createFixedMacro("macro", macro_x_, macro_y_);
  instance->setHalo(5000, 5000, 5000, 5000, /*is_soft=*/false);

  macro_placer_->blockMacroChannels();

  const std::vector<odb::Rect> blockages = getBlockages();
  ASSERT_EQ(blockages.size(), 1);
  EXPECT_EQ(blockages[0], odb::Rect(45000, 45000, 155000, 155000));
}

// Base halo is floored by the DEF halo per side: the larger of the two wins.
TEST_F(TestBlockMacroChannels, BaseHaloFloorsDefHalo)
{
  odb::dbInst* instance = createFixedMacro("macro", macro_x_, macro_y_);
  instance->setHalo(5000, 5000, 5000, 5000, /*is_soft=*/false);
  macro_placer_->setBaseHalo(10000, 1000, 10000, 1000);

  macro_placer_->blockMacroChannels();

  const std::vector<odb::Rect> blockages = getBlockages();
  ASSERT_EQ(blockages.size(), 1);
  // Horizontal: base 10000 > DEF 5000. Vertical: DEF 5000 > base 1000.
  EXPECT_EQ(blockages[0], odb::Rect(40000, 45000, 160000, 155000));
}

// Per-macro halo has top priority over both the base halo and the DEF halo.
TEST_F(TestBlockMacroChannels, PerMacroHaloOverrides)
{
  odb::dbInst* instance = createFixedMacro("macro", macro_x_, macro_y_);
  instance->setHalo(5000, 5000, 5000, 5000, /*is_soft=*/false);
  macro_placer_->setBaseHalo(10000, 10000, 10000, 10000);
  macro_placer_->setMacroHalo(instance, 20000, 20000, 20000, 20000);

  macro_placer_->blockMacroChannels();

  const std::vector<odb::Rect> blockages = getBlockages();
  ASSERT_EQ(blockages.size(), 1);
  EXPECT_EQ(blockages[0], odb::Rect(30000, 30000, 170000, 170000));
}

// Macros with a soft DEF halo are skipped even when a base halo is set.
TEST_F(TestBlockMacroChannels, SoftDefHaloSkipped)
{
  odb::dbInst* instance = createFixedMacro("macro", macro_x_, macro_y_);
  instance->setHalo(5000, 5000, 5000, 5000, /*is_soft=*/true);
  macro_placer_->setBaseHalo(10000, 10000, 10000, 10000);

  macro_placer_->blockMacroChannels();

  EXPECT_TRUE(getBlockages().empty());
}

// When the macro has no DEF halo, the base halo alone defines the blockage.
TEST_F(TestBlockMacroChannels, BaseHaloOnly)
{
  createFixedMacro("macro", macro_x_, macro_y_);
  macro_placer_->setBaseHalo(8000, 4000, 6000, 2000);

  macro_placer_->blockMacroChannels();

  const std::vector<odb::Rect> blockages = getBlockages();
  ASSERT_EQ(blockages.size(), 1);
  EXPECT_EQ(blockages[0], odb::Rect(42000, 46000, 156000, 152000));
}

// Unplaced macros are ignored.
TEST_F(TestBlockMacroChannels, UnplacedMacroSkipped)
{
  odb::dbInst::create(db_->getChip()->getBlock(), macro_master_, "macro");

  macro_placer_->blockMacroChannels();

  EXPECT_TRUE(getBlockages().empty());
}

// Placed macros are ignored: MPL can still move them as they're not fixed.
TEST_F(TestBlockMacroChannels, PlacedMacroSkipped)
{
  odb::dbInst* instance
      = odb::dbInst::create(db_->getChip()->getBlock(), macro_master_, "macro");
  instance->setLocation(macro_x_, macro_y_);
  instance->setPlacementStatus(odb::dbPlacementStatus::PLACED);

  macro_placer_->blockMacroChannels();

  EXPECT_TRUE(getBlockages().empty());
}

}  // namespace
}  // namespace mpl