[LLVMdev] How does the memory of MachineInstr objects are managed?

Tzu-Chien Chiu tzuchien.chiu at gmail.com
Tue Sep 27 06:29:06 PDT 2005

A question about how the memory of object in LLVM are managed.

I dived in some source files but still don't have any idea how the
memory of MachineInstr object are managed. It doesn't look like
reference counting.

I'm writing an instruction scheudling code, the new order of
MachineInstr* in a MachineBasicBlock is stored in a "schedule".  All
MachineInstr* in MachineBasicBlock are first removed, and
MachineInstr* are inserted back MachineBasicBlock in the scheduled

The question is: isn't the memory of MachineInstr* "released/freed"
when it's removed from the MachineBasicBlock?

vector<MachineInstr*> S; // the schedule;

// reference implementation: SparcV9/InstrSched/InstructionScheduling.cpp
void recordSchedule(MachineBasicBlock &MBB) {
  while (I != MBB.end())
    MBB.remove(I++); // **** Q: Doesn't it invalidate the pointers in
'S' ?? ****

  vector<MachineInstr*>::iterator I = S.begin(); S.end() != I; ++ I) {

Tzu-Chien Chiu - XGI Technology, Inc.
URL: http://www.csie.nctu.edu.tw/~jwchiu/

More information about the llvm-dev mailing list