MATLAB: “No traceability information” for blocks in subsystem after generating HDL Code

HDL Coder

When opening the Traceability Report section in our HDL Code Generation Report, I see the following warning message instead of relevant HDL Code being traced:
For '<subsystemName/blockName>', you cannot trace code from the model because there is no traceability information
In this case, I have multiple identical atomic subsystems in the model: Stage1, Stage2, and Stage3. Traceability works fine for Stage1, but Stage2 and Stage3 point to the error message listed above.

Best Answer

This is the expected behavior because the blocks in Stage2 & Stage3 have been optimized from the generated code due to code reuse. If you look in the "Eliminated/Virtual Blocks" section of the Traceability Report, you will see the blocks from Stage2 & Stage3 listed there.
In this case, the code was optimized because all three subsystems were atomic, so the generated HDL code includes one implementation of Stage1.vhd. This is re-instantiated twice for Stage2 and Stage3, as indicated in the image below. For this reason, traceability works for Stage1 because each block has dedicated lines of code to point to, but there are not unique lines of code to trace to for blocks under the Stage2 subsystem, so traceability is not available.
To enable traceability for Stage2, make its subsystem non-atomic and re-generate the HDL code. The generated code will now contain two implementations for Stage1.vhd and Stage2.vhd, and the instantiation of each stage will point to its own unique implementation. Traceability will now work in this case.