[LLVMdev] Inserting nodes into SelectionDAG (X86)

Artjom K. artjom.kochtchi at googlemail.com
Thu Jun 25 14:05:36 PDT 2009


I am rather new to LLVM, so please excuse my limited knowledge about it.

Currently I am trying to modify the X86TargetLowering::LowerCALL method by
inserting additional instructions before the call.
As far as I understand, nodes are created by calling the getNode method on
the DAG. If, for example, I insert the following code

  Chain = DAG.getNode(ISD::TRAP, DAG.getVTList(MVT::Other), &Ops[0],

then an X86 instruction (namely ud2) appears in the output files compiled by
So, is my understanding correct that
1) the Chain determines the ordering of the nodes?
2) the second parameter is a set of return types, i. e. in my example,
MVT::Other says that a Chain object will be returned?

Now, as soon as I try to generate more complex instructions, I get lost.
Say, I want to insert the following instruction

  mov   eax, 42

then the best I can come up with is

  Ops.push_back(DAG.getRegister(X86::EAX, MVT::i32));
  Ops.push_back(DAG.getConstant(42, MVT::i32));
  Chain = DAG.getNode(X86::MOV32ri, DAG.getVTList(MVT::Other), &Ops[0],

But there are a few problems:
3) It seems I am not allowed to use concrete X86 instructions here (at least
that's what I think llc's error message "cannot yet select" could mean). Is
there an appropriate instruction in ISD? I can't find it...
4) Do I get the parameter passing right? Fooling around with other
expressions suggests that I get it wrong.
5) What exactly is the meaning of further result types? If I get the new
Chain object back, are the other results inside?

Could you help me out?

Artjom Kochtchi
View this message in context: http://www.nabble.com/Inserting-nodes-into-SelectionDAG-%28X86%29-tp24211066p24211066.html
Sent from the LLVM - Dev mailing list archive at Nabble.com.

More information about the llvm-dev mailing list