[LLVMdev] Folding instructions

Bil isanbard at gmail.com
Mon Aug 14 00:45:55 PDT 2006


On Aug 13, 2006, at 11:16 PM, Fernando Magno Quintao Pereira wrote:

>
> Dear LLVMers,
>
>     I am trying to fold memory operands in the way that is done in
> RegAllocLocal.cpp, or in LiveIntervalAnalysis.cpp, but I am getting  
> errors
> that
> I don't know how to fix. Could someone tell me which steps should I  
> take
> in order
> to correctly fold memory operands? The code that I am using is:
>
> const TargetMachine & target_machine =
> this->machine_function->getTarget();
> const MRegisterInfo *ri = target_machine.getRegisterInfo();
> MachineInstr * fmi = ri->foldMemoryOperand(mi, u, slot);
> if(fmi) {
>    numFolded++;
>    MachineBasicBlock * mbb = mi->getParent();
>    this->vrm->virtFolded(v_reg, mi, u, fmi);
>    //std::cerr << "Folding " << NeatPrint::mi2string(*mi,
> *this->machine_function) << "\n";
>    // TODO: see if it is not necessary to iterate
>    // again on the instruction.
>    return mbb->insert(mbb->erase(mi), fmi);
> }
>
> With this code, my register allocator passes many tests, but  
> crashes in
> some.
> Curiously, if I uncomment the printing line, it passes some more  
> tests.
> gdb gives me
> the error trace below. Could someone point me directions? I am not
> deleting fmi
> before the spiller runs, so, maybe I am not calling some methods  
> from LLVM
> to
> indicate the folding.
>
Hi Fernando,

It's hard to say exactly what's happening because I don't know your  
code (though, from the stack trace, it seems like there's some sort  
of memory debacle), but looking at the comment in the  
LiveVariableAnalysis.cpp file where it's folding memory operands, it  
might explain somethings better:

             // Folding the load/store can completely change the  
instruction in
             // unpredictable ways, rescan it from the beginning.

It's after this that it re-analyzes the operands of the machine  
instruction. Are you doing this?

-bw






More information about the llvm-dev mailing list