Module 3: Phases and Transactions | Lesson 22

Build Phase

Learn how UVM constructs the testbench hierarchy, creates reusable components, and retrieves configuration during build_phase().

Learning objectives

  • Explain the purpose of build_phase().
  • Understand when UVM components are created.
  • Use type_id::create() to construct components through the factory.
  • Understand why super.build_phase(phase) is normally called.
  • Retrieve configuration during the build phase.
  • Understand the top-down nature of UVM component construction.
  • Recognize common build-phase mistakes and debug them systematically.

Step 1: What is the build phase?

The build_phase() is one of the most important phases in UVM. It is where components construct the structure of the verification environment.

During build, components can:

  • Create child UVM components.
  • Retrieve configuration values.
  • Determine which optional components should exist.
  • Prepare objects needed by the component.

A typical environment might be constructed like this:

test


|
v
env
|
+-- agent
|    |
|    +-- driver
|    +-- monitor
|
+-- scoreboard

The important idea is that the component hierarchy is built before the testbench begins its main time-consuming simulation activity.

Key idea: build_phase() answers: "What components should exist in my verification environment?"

Step 2: The build phase is a function

The standard signature is:

function void build_phase(uvm_phase phase);

Because build_phase() is a function, it cannot consume simulation time.

Therefore, code such as this does not belong in build:

// Do not do this in build_phase


#10ns;
@(posedge clk);

Those operations consume simulation time and belong in a task phase, such as run_phase().

Remember: Build constructs the testbench. Run executes time-consuming behavior.

Step 3: Creating a component with the factory

UVM components are commonly created using the factory:

agent = bus_agent::type_id::create("agent", this);

The first argument is the instance name. The second argument is the parent component.

If this code is inside an environment:

agent = bus_agent::type_id::create("agent", this);

the resulting hierarchy contains:

env


└── agent

The parent-child relationship is important because UVM uses it to construct and manage the component hierarchy.

Step 4: Why use type_id::create() instead of new()?

You may wonder why UVM code does not simply use:

agent = new("agent", this);

The reason is the UVM factory.

Factory-based creation allows a test to replace an implementation without modifying the component that creates it.

Compare:

// Direct construction


agent = bus_agent::new("agent", this);

// Factory construction
agent = bus_agent::type_id::create("agent", this);

Factory creation makes the component more configurable and reusable. You learned the factory in Lessons 17 and 18; now you are using it as part of a real component hierarchy.

Practical rule: For UVM components, prefer type_id::create() so the factory can override the implementation later.

Step 5: Always understand super.build_phase()

A typical build phase begins with:

function void build_phase(uvm_phase phase);


super.build_phase(phase);

// Create child components here.
endfunction

Calling super.build_phase(phase) invokes the parent class implementation.

This is important because UVM base classes can perform their own required processing during the phase.

As a beginner, a safe and consistent pattern is:

function void build_phase(uvm_phase phase);


super.build_phase(phase);

// Your build code.
endfunction
Good habit: Unless you have a specific reason not to, call the parent implementation when overriding a UVM phase method.

Step 6: Building an environment

Let's build a small environment containing an agent and scoreboard.

class bus_env extends uvm_env;


`uvm_component_utils(bus_env)

bus_agent      agent;
bus_scoreboard scoreboard;

function new(
string name = "bus_env",
uvm_component parent = null
);
super.new(name, parent);
endfunction

function void build_phase(uvm_phase phase);
super.build_phase(phase);


agent = bus_agent::type_id::create("agent", this);

scoreboard =
  bus_scoreboard::type_id::create("scoreboard", this);


endfunction

endclass

After the environment is built, the hierarchy looks like:

env


├── agent
└── scoreboard

The environment owns these components because this was passed as their parent.

Step 7: Components build their own children

A powerful UVM design pattern is that each component is responsible for constructing its own children.

For example:

class bus_agent extends uvm_agent;


bus_driver  driver;
bus_monitor monitor;

function void build_phase(uvm_phase phase);
super.build_phase(phase);


driver  = bus_driver::type_id::create("driver", this);
monitor = bus_monitor::type_id::create("monitor", this);


endfunction

endclass

The environment does not need to know how the agent is internally constructed.

The resulting hierarchy becomes:

env


├── agent
│   ├── driver
│   └── monitor
└── scoreboard

This is one of the reasons UVM environments scale well. Each component owns the construction of its immediate children.

Design principle: A component should generally create its direct children. The environment should not reach inside an agent and construct the agent's driver itself.

Step 8: Build phase and configuration

The build phase is also commonly used to retrieve configuration.

For example, an agent might retrieve an is_active setting:

function void build_phase(uvm_phase phase);


super.build_phase(phase);

if (!uvm_config_db#(uvm_active_passive_enum)::get(
this,
"",
"is_active",
is_active
))
is_active = UVM_ACTIVE;

driver  = bus_driver::type_id::create("driver", this);
monitor = bus_monitor::type_id::create("monitor", this);
endfunction

Configuration can influence what gets constructed.

For example, an active agent normally needs a driver, while a passive agent may only need a monitor.

if (is_active == UVM_ACTIVE)


driver = bus_driver::type_id::create("driver", this);

monitor = bus_monitor::type_id::create("monitor", this);

This is a real example of why configuration and build belong together: configuration can determine the structure of the environment.

Step 9: Build happens top-down

UVM constructs the component hierarchy in a top-down manner.

Think about the hierarchy:

test


|
v
env
|
v
agent
|
+-- driver
+-- monitor

The test creates the environment. The environment creates the agent. The agent creates the driver and monitor.

This naturally produces a top-down construction pattern.

test.build_phase()
   |
   v


env.build_phase()
|
v
agent.build_phase()
|
+----> driver.build_phase()
|
+----> monitor.build_phase()
Important mental model: Parent components establish the structure that allows child components to exist. Each component then builds its own children.

Step 10: Build phase does not mean "start the test"

A common beginner mistake is to put actual stimulus inside build_phase().

For example, this is conceptually wrong:

function void build_phase(uvm_phase phase);


super.build_phase(phase);

// Do not start time-consuming stimulus here.
repeat (100) begin
#10ns;
send_transaction();
end
endfunction

Build should construct and configure the environment.

Stimulus belongs in sequences and run-time activity, for example:

task run_phase(uvm_phase phase);


phase.raise_objection(this);

sequence.start(agent.sequencer);

phase.drop_objection(this);
endtask

The distinction is fundamental:

Build phase Run phase
Create components Run stimulus
Retrieve configuration Wait for clock/events
Decide which components exist Drive and monitor activity
No simulation time Can consume simulation time

Step 11: A complete build example

Put everything together with a small environment:

class bus_env extends uvm_env;


`uvm_component_utils(bus_env)

bus_agent      agent;
bus_scoreboard scoreboard;

function new(
string name = "bus_env",
uvm_component parent = null
);
super.new(name, parent);
endfunction

function void build_phase(uvm_phase phase);
super.build_phase(phase);


agent =
  bus_agent::type_id::create("agent", this);

scoreboard =
  bus_scoreboard::type_id::create("scoreboard", this);

`uvm_info(
  "BUILD",
  "Environment components created",
  UVM_LOW
)


endfunction

endclass

If this environment is created by a test:

class bus_test extends uvm_test;


`uvm_component_utils(bus_test)

bus_env env;

function new(
string name = "bus_test",
uvm_component parent = null
);
super.new(name, parent);
endfunction

function void build_phase(uvm_phase phase);
super.build_phase(phase);


env = bus_env::type_id::create("env", this);


endfunction

endclass

The resulting hierarchy is:

uvm_test_top


└── env
├── agent
│   ├── driver
│   └── monitor
└── scoreboard

Notice that no component manually constructs its grandchildren. Each level creates its immediate children.

Step 12: Common build-phase mistakes

Mistake 1: Forgetting to create a component

bus_driver driver;


// driver is never created

If another phase later tries to use driver, it may be null.

Mistake 2: Using the wrong parent

driver = bus_driver::type_id::create("driver", this);

The parent should normally be the component that owns the child. Passing the wrong parent creates an unexpected hierarchy.

Mistake 3: Using new() instead of the factory

driver = new("driver", this);

Direct construction bypasses the normal factory creation mechanism. Prefer type_id::create() for UVM components.

Mistake 4: Forgetting super.build_phase()

Omitting the parent implementation can interfere with inherited behavior. Use the standard pattern unless there is a deliberate reason not to.

Mistake 5: Starting stimulus during build

Build is for construction and configuration. Put time-consuming activity in run_phase() or sequences.

Mistake 6: Expecting TLM connections to exist during build

Components are created in build. TLM connections are normally established later in connect_phase().

Debugging rule: If a component is null, first inspect build_phase(). If a port is not connected, inspect connect_phase().

Step 13: Build phase debugging

When debugging a UVM environment, it is useful to verify that the expected hierarchy was actually constructed.

You can print the UVM topology:

uvm_root::get().print_topology();

A topology dump might show:

uvm_test_top


env
agent
driver
monitor
scoreboard

If the driver is missing from the topology, do not start debugging transactions yet. First fix the construction problem.

Verification mindset: Debug from the outside in: hierarchy → configuration → connections → stimulus → checking.

Try it yourself

Build the following UVM hierarchy:

test


└── env
└── agent
├── driver
└── monitor
  1. Create all four UVM components.
  2. Use type_id::create() for every component.
  3. Pass the correct parent using this.
  4. Call super.build_phase(phase) in each build phase.
  5. Print the topology after construction.
  6. Confirm that the hierarchy matches your design.
Challenge: Add an is_active configuration setting. If the agent is active, create the driver. If it is passive, create only the monitor. Then print the topology for both configurations.

Key takeaways

  • build_phase() constructs the UVM component hierarchy.
  • UVM components should normally be created with type_id::create().
  • The second argument to create() establishes the parent-child relationship.
  • Each component should normally create its own immediate children.
  • Configuration can be retrieved during build and can influence which components are created.
  • build_phase() is a function and cannot consume simulation time.
  • Stimulus and other time-consuming behavior belong in run-time phases and sequences.
  • Build creates the structure; connect establishes communication; run performs simulation activity.
  • When debugging UVM, verify the topology before debugging transactions.