[llvm-dev] [MachineScheduler]: SchedBoundary trivially copiable, but "HazardRec" is raw pointer: a design issue?

Lorenzo Casalino via llvm-dev llvm-dev at lists.llvm.org
Fri Oct 4 02:01:48 PDT 2019


Hi to everyone,

while working with the machine scheduler for a personal project, I came
up with the necessity of
inserting a backup boundary in the MachineSchedulerStrategy -- specifically,
the PostGenericScheduler -- to hold a copy the scheduler's state, in
order to implement a really
trivial (and really inefficient) backtracking mechanism.

This approach leads to a subtle "segmentation fault", when the pass ends
and invokes the deleter.

The reason of the fault is due to the custom deleter of SchedBoundary,
which explicitly deletes
the scoreboard object. Follows that, since both the boundary objects,
the original and the copy, hold
 a pointer to the same object, a double "delete" is performed.

I think this is an issue deriving from the design: if SchedBoundary is
designed to be copiable, then
solutions may be:

    1. The pointer should be wrapped around a smart_ptr (a shared_ptr,
since we want to hold a copy)

    2.  Define a custom copy-constructor and assign-operator, such that
the ScoreBoard object, and not
       the pointer, is copied.

If SchedBoundary was not designed to be copiable, then default
copy-costructor/assign-operator should
be marked as "deleted".


Let me know what do you think about it, and if there's actually the need
to submit a patch.


Best regards,

Lorenzo Casalino




More information about the llvm-dev mailing list