to lower "write to argument pointer"

Drear there:

The problem I have is to lower an intrinsic function like this**”**
float @llvm.write.arg(flaot %src, float* %dst)

I am lowering it with INTRINSIC_W_CHAIN, so the return value and the value to write to dst are generated with some operations using src:

"
// it is the frame index node corresponding to input pointer
SDvalue frindex = Op.getoperand(3);

SDValue returnValue = DAG.getNode(myNode1, DL, VT….);

SDValue dstValue = DAG.getNode(myNode2, DL, VT….);

// to save the value to dst pointer, I think I need some call like
SDValue dstOut = DAG.getStore(chain, DL, dstValue, FrameIndex, MachinePointerInfo(), false, false, 0);


I have two questions here:
(1) should I return some merges values( returnValue, DstValue) ? or only return returnValue is right? ( the dag dumped out looks better if I return the merged values)
(2) How the FrameIndex should be computed? I use DAG.getFrameIndex((dyn_cast( frindex.getNode()))->getIndex(), i32), not confident it is correct, any good examples to understand to this?

Best

Kevin

Drear there:

The problem I have is to lower an intrinsic function like this

float @llvm.write.arg(flaot %src, float* %dst)

I am lowering it with INTRINSIC_W_CHAIN, so the return value and the value to write to dst are generated with some operations using src:

"
// it is the frame index node corresponding to input pointer
SDvalue frindex = Op.getoperand(3);

SDValue returnValue = DAG.getNode(myNode1, DL, VT….);

SDValue dstValue = DAG.getNode(myNode2, DL, VT….);

// to save the value to dst pointer, I think I need some call like
SDValue dstOut = DAG.getStore(chain, DL, dstValue, FrameIndex, MachinePointerInfo(), false, false, 0);


I have two questions here:
(1) should I return some merges values( returnValue, DstValue) ? or only return returnValue is right? ( the dag dumped out looks better if I return the merged values)

Since INTRINSIC_W_CHAIN has two values, whatever you lower it to should
have two: The result and the chain. You canuse MERGE_VALUES for that.

(2) How the FrameIndex should be computed? I use DAG.getFrameIndex((dyn_cast<FrameIndexSDnode>( frindex.getNode()))->getIndex(), i32), not confident it is correct, any good examples to understand to this?

Is the FrameIndex one of the inputs to the intrinsic, or are you trying
to create a new FrameIndex?

-Tom

Thanks Tom!

Drear there:

The problem I have is to lower an intrinsic function like this

float @llvm.write.arg(flaot %src, float* %dst)

I am lowering it with INTRINSIC_W_CHAIN, so the return value and the value to write to dst are generated with some operations using src:

"
// it is the frame index node corresponding to input pointer
SDvalue frindex = Op.getoperand(3);

SDValue returnValue = DAG.getNode(myNode1, DL, VT….);

SDValue dstValue = DAG.getNode(myNode2, DL, VT….);

// to save the value to dst pointer, I think I need some call like
SDValue dstOut = DAG.getStore(chain, DL, dstValue, FrameIndex, MachinePointerInfo(), false, false, 0);


I have two questions here:
(1) should I return some merges values( returnValue, DstValue) ? or only return returnValue is right? ( the dag dumped out looks better if I return the merged values)

Since INTRINSIC_W_CHAIN has two values, whatever you lower it to should
have two: The result and the chain. You canuse MERGE_VALUES for that.
  
I mean , since the dstValue is wrote to the pointer of dst via " SDValue dstOut = DAG.getStore(chain, DL, dstValue, FrameIndex, MachinePointerInfo(), false, false, 0);”,
Should I only return the "SDValue returnValue = DAG.getNode(myNode1, DL, VT….);” And the chain is only used by the dstOut to write out to pointer?

(2) How the FrameIndex should be computed? I use DAG.getFrameIndex((dyn_cast<FrameIndexSDnode>( frindex.getNode()))->getIndex(), i32), not confident it is correct, any good examples to understand to this?

Is the FrameIndex one of the inputs to the intrinsic, or are you trying
to create a new FrameIndex?

I think the FrameIndexSDNode is generated by DAGBuilder when it sees the input dst pointer in call " float @llvm.write.arg(flaot %src, float* %dst)”. should be the one you mentioned “frameIndex one of the inputs to the intrinsic”.
I don’t think I need to create new Frameindex.

Best

Kevin

Thanks Tom!

>> Drear there:
>>
>> The problem I have is to lower an intrinsic function like this
>> ”
>> float @llvm.write.arg(flaot %src, float* %dst)
>> “
>> I am lowering it with INTRINSIC_W_CHAIN, so the return value and the value to write to dst are generated with some operations using src:
>>
>> "
>> // it is the frame index node corresponding to input pointer
>> SDvalue frindex = Op.getoperand(3);
>> …
>> SDValue returnValue = DAG.getNode(myNode1, DL, VT….);
>>
>> SDValue dstValue = DAG.getNode(myNode2, DL, VT….);
>>
>> // to save the value to dst pointer, I think I need some call like
>> SDValue dstOut = DAG.getStore(chain, DL, dstValue, FrameIndex, MachinePointerInfo(), false, false, 0);
>>
>> “
>> I have two questions here:
>> (1) should I return some merges values( returnValue, DstValue) ? or only return returnValue is right? ( the dag dumped out looks better if I return the merged values)
>
> Since INTRINSIC_W_CHAIN has two values, whatever you lower it to should
> have two: The result and the chain. You canuse MERGE_VALUES for that.
  
I mean , since the dstValue is wrote to the pointer of dst via " SDValue dstOut = DAG.getStore(chain, DL, dstValue, FrameIndex, MachinePointerInfo(), false, false, 0);”,
Should I only return the "SDValue returnValue = DAG.getNode(myNode1, DL, VT….);” And the chain is only used by the dstOut to write out to pointer?

You need to return the chain too, because there may be loads or stores
after this intrinsic that rely on the chain to keep them in the correct
order.

>
>> (2) How the FrameIndex should be computed? I use DAG.getFrameIndex((dyn_cast<FrameIndexSDnode>( frindex.getNode()))->getIndex(), i32), not confident it is correct, any good examples to understand to this?
>>
>
> Is the FrameIndex one of the inputs to the intrinsic, or are you trying
> to create a new FrameIndex?
>
I think the FrameIndexSDNode is generated by DAGBuilder when it sees the input dst pointer in call " float @llvm.write.arg(flaot %src, float* %dst)”. should be the one you mentioned “frameIndex one of the inputs to the intrinsic”.
I don’t think I need to create new Frameindex.

You don't have to do anything special with the FrameIndex node. Just pass it
directly to DAG.getStore as the pointer argument. As far as the DAG is concerned
it is just a pointer value. The intrinsic does not need any special handling for it.

-Tom