Since some perennial weeds can regenerate from even tiny root fragments, they are not considered safe for composting unless you use the Berkeley method of hot composting, and measure the temperature to ensure that your compost temperature is within bounds as prescribed by that method.
Another way to treat perennial weeds is to dry them out to kill the roots and stems as some can regenerate from stem cuttings (eg. Tradescantia). I put them on a plastic tarpaulin and leave them in full sun until I'm sure that they are desiccated and dead.
If the weed has flowers eg. Scottish thistle, I remove the flowers and place in a bath of water and drown them for a month or so.
Dried weeds can then be used as a mulch to compost in-situ, or, added to the compost pile.