[LLVMdev] Two labels around one instruction in Codegen

Nicolas Geoffray nicolas.geoffray at lip6.fr
Mon Nov 5 11:52:18 PST 2007


Hi everyone,

In order to have exceptions for non-call instructions (such as sdiv,
load or stores), I'm modifying codegen so that it generates a BeginLabel
and an EndLabel between the "may throwing" instruction. This is what the
codegen of an InvokeInst does.

However, when generating native code, only BeginLabel is generated, and
it is generated after the instruction. I'm not familiar with DAGs in the
codegen library, so here are my 2-cents thoughts why:

1) BeginLabel and EndLabel are generated with:
  DAG.setRoot(DAG.getNode(ISD::LABEL, MVT::Other, getRoot(),
                            DAG.getConstant({Begin|End}Label, MVT::i32)));

This seems to work with InvokeInst instructions, because the root of the
DAG is modified by the instruction. With instructions such as sdiv, the
root is not modified: the instruction only lowers itself to:
DAG.getNode(OpCode, Op1.getValueType(), Op1, Op2)

Which probably makes the codegen think EndLabel and BeginLabel are in
the same place

2) Since there is no ordering between the node for the sdiv instruction
and the labels, the sdiv instruction can be generated anywhere.

These assumptions may be wrong, but it's the best I could come up with ;-).

If someone could correct me and help me found how to correctly generate
two labels between one instruction, that would be great! :)

Thanks,
Nicolas




More information about the llvm-dev mailing list