Thank you for your help. I think I managed to create the instruction I wanted: // mov eax, 41 Chain = DAG.getCopyToReg(Chain, DAG.getRegister(X86::EAX, MVT::i32), DAG.getConstant(41, MVT::i32), InFlag); InFlag = Chain.getValue(1); I don't understand though what InFlag is for. As I read the code, it even remains uninitialized when first passed to some node creation method. Unfortunately I still don't manage to create more sophisticated error free instructions that actually appear in the assembly generated by llc. For example after the CopyToReg instruction, I want to increase eax by 1. In X86 'inc eax' would probably be the way to go, which I try to model by ISD 'addc eax, eax, 1' or something of that sort (it's probably rather 'addc eax, 1'). I've tried all sorts of combinations and ordering of operands I could come up with, but I seem to be missing the point. This is the most complete version: // inc eax Ops.push_back(Chain); Ops.push_back(DAG.getRegister(X86::EAX, MVT::i32)); // rather without target register? Ops.push_back(DAG.getRegister(X86::EAX, MVT::i32)); Ops.push_back(DAG.getConstant(1, MVT::i32)); Ops.push_back(InFlag); Chain = DAG.getNode(ISD::ADDC, DAG.getVTList(MVT::Other, MVT::Flag), &Ops[0], Ops.size()); InFlag = Chain.getValue(1); Usually, llc quits with the error message llc: SelectionDAG.cpp:4417: llvm::SDValue llvm::SelectionDAG::UpdateNodeOperands(llvm::SDValue, llvm::SDValue, llvm::SDValue): Assertion `N->getNumOperands() == 2 && "Update with wrong number of operands"' failed. Omiting the target register or switching operand order seems not to change anything. I'd really appreciate your help on this. Artjom -- View this message in context: http://www.nabble.com/Inserting-nodes-into-SelectionDAG-%28X86%29-tp24211066p24218876.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
On Jun 26, 2009, at 4:49 AM, Artjom K. wrote:> > Thank you for your help. > > I think I managed to create the instruction I wanted: > > // mov eax, 41 > Chain = DAG.getCopyToReg(Chain, DAG.getRegister(X86::EAX, MVT::i32), > DAG.getConstant(41, MVT::i32), InFlag); > InFlag = Chain.getValue(1); > > I don't understand though what InFlag is for. As I read the code, it > even > remains uninitialized when first passed to some node creation method.Flag operands in SelectionDAG are special. SelectionDAG currently requires Flag operands for copies to and from physical registers, though not for virtual registers.> > Unfortunately I still don't manage to create more sophisticated > error free > instructions that actually appear in the assembly generated by llc. > For > example after the CopyToReg instruction, I want to increase eax by > 1. In X86 > 'inc eax' would probably be the way to go, which I try to model by > ISD 'addc > eax, eax, 1' or something of that sort (it's probably rather 'addc > eax, 1').ADDC is add-with-carry. If you just want to add 1 to EAX and don't care about the carry result, ADD is easier. The result type of ADD is just MVT::i32 (assuming you're working with i32 operands). Dan
Sorry to ask again, but I still can't get it right. The following code compiles and runs, but produces no instructions: Ops.push_back(DAG.getRegister(X86::EAX, MVT::i32)); Ops.push_back(DAG.getConstant(1, MVT::i32)); DAG.getNode(ISD::ADD, DAG.getVTList(MVT::i32), &Ops[0], Ops.size()); I reckon that has something to do with the fact that I am not using the Chain object. But as soon as I try to chain that node, llc tells me that I have the wrong number of operands: Ops.push_back(Chain); Ops.push_back(DAG.getRegister(X86::EAX, MVT::i32)); Ops.push_back(DAG.getConstant(1, MVT::i32)); Chain = DAG.getNode(ISD::ADD, DAG.getVTList(MVT::Other, MVT::i32), &Ops[0], Ops.size()); Isn't that the way how it is supposed to work? Artjom -- View this message in context: http://www.nabble.com/Inserting-nodes-into-SelectionDAG-%28X86%29-tp24211066p24256897.html Sent from the LLVM - Dev mailing list archive at Nabble.com.