I want to have some functions that create machine instructions, not specifying which machine function or basic block or iterator they are part of. And then I want to use that result when adding that instruction to a basic block. I'm pretty sure you can do this but we have not done this in the Mips port so far. We just use instruction builder. Anyone know how to do this best, or can point me to some code where this is done? Tia. Reed
Jakob Stoklund Olesen
2013-Feb-15 23:07 UTC
[LLVMdev] build a machine instruction by itself
On Feb 15, 2013, at 1:21 PM, Reed Kotler <rkotler at mips.com> wrote:> I want to have some functions that create machine instructions, not specifying which machine function or basic block or iterator they are part of.All machine instructions must be created by a machine function. It provides the context for memory allocation etc.> And then I want to use that result when adding that instruction to a basic block. > > I'm pretty sure you can do this but we have not done this in the Mips port so far. We just use instruction builder. > > Anyone know how to do this best, or can point me to some code where this is done?Did you look at BuildMI? /jakob
On 02/15/2013 03:07 PM, Jakob Stoklund Olesen wrote:> On Feb 15, 2013, at 1:21 PM, Reed Kotler <rkotler at mips.com> wrote: > >> I want to have some functions that create machine instructions, not specifying which machine function or basic block or iterator they are part of. > All machine instructions must be created by a machine function. It provides the context for memory allocation etc. > >> And then I want to use that result when adding that instruction to a basic block. >> >> I'm pretty sure you can do this but we have not done this in the Mips port so far. We just use instruction builder. >> >> Anyone know how to do this best, or can point me to some code where this is done? > Did you look at BuildMI?For example, what I did already was create the folllowing: void BuildAddiuSpImm(MachineBasicBlock &MBB, MachineBasicBlock::iterator II, DebugLoc DL, int64_t Imm) const; this will insert one of two Addiu SP, Immediate instruction forms at the point of the iterator, based on the value of the Immediate field. It does this by using BuildMI. Probably I should have returned a MachineInstructionBuilder. I would like to use the function I create in various contexts but just have one base function, that is used to build a proper Addiu Sp, Immediate field. There are various BuildMi forms. To me, creating a MachineInstr is not related this context of how you are placing it. So I guess I could use: /// CreateMachineInstr - Allocate a new MachineInstr. Use this instead /// of `new MachineInstr'. /// MachineInstr *CreateMachineInstr(const MCInstrDesc &MCID, DebugLoc DL, bool NoImp = false); so my creator function needs to at least have a parameter of type MachineFunction I can get the MachineFunction from any MachineBasicBlock using getParent MachineInstr BuildAddiuSpImm(MachineFunction &MF, int64_t Imm) const; I did not want to have to pass any more arguments than Imm.> /jakob >
Reasonably Related Threads
- [LLVMdev] build a machine instruction by itself
- [LLVMdev] build a machine instruction by itself
- [LLVMdev] build a machine instruction by itself
- [LLVMdev] What does this error mean: psuedo instructions should be removed before code emission?
- [LLVMdev] What does this error mean: psuedo instructions should be removed before code emission?