how to define INTRINSIC_W_CHAIN

Hi guys,

I am working on an intrinsic function, which will write to a pointer argument.
So I am lowering it and think I need to catch it in lowerINTRINSIC_W_CHAIN, but somehow it always fall into INTRINSIC_WO_CHAIN category.

I put [IntrReadwriteArgMem] into my Intrinsic class definition, it did not help.
tried put [SDNPHasChain] into intrinsic class definition, cause errors” Element type mismatch for list”.

wondering how to flag it to INTRINSIC_W_CHAIN?

best

Kevin

Does it have chain in the initial DAG?

-Krzysztof

From: "kewuzhang" <kewu.zhang@amd.com>
To: llvmdev@cs.uiuc.edu
Sent: Friday, July 18, 2014 2:00:07 PM
Subject: [LLVMdev] how to define INTRINSIC_W_CHAIN

Hi guys,

I am working on an intrinsic function, which will write to a pointer
argument.
So I am lowering it and think I need to catch it in
lowerINTRINSIC_W_CHAIN, but somehow it always fall into
INTRINSIC_WO_CHAIN category.

I put [IntrReadwriteArgMem] into my Intrinsic class definition, it
did not help.
tried put [SDNPHasChain] into intrinsic class definition, cause
errors” Element type mismatch for list”.

wondering how to flag it to INTRINSIC_W_CHAIN?

Does your intrinsic return a value? If not, it will be a INTRINSIC_VOID (which also has a chain).

-Hal

en!

my test is : %r1 = call<float> @test.adddiv( <float> %r0, <float>* %p0).
since

  but somehow it always fall into INTRINSIC_WO_CHAIN category.

(caught it in lowering..)

I think it doesn’t have chain in initial DAG.

unfortunately the intrinsic “test.adddiv” is defined by me for now. not sure how to make it has a chain.

kevin

en!

my test is : %r1 = call<float> @test.adddiv( <float> %r0, <float>* %p0).
since

Can you show us the code from your .td file where you define the intrinsic?

-Tom

sure!

class TEST_INTINSIC_FM< string asmstr> : Intrinsic
<llvm_i32_ty], [llvm_i32_ty, llvm_ptr_ty],
[IntrReadWriteArgMem],
!strconcat(“llvm.test”, asmstr),”.float”)

;

tks

sure!

class TEST_INTINSIC_FM< string asmstr> : Intrinsic
   <llvm_i32_ty], [llvm_i32_ty, llvm_ptr_ty],
  [IntrReadWriteArgMem],
  !strconcat(“llvm.test”, asmstr),”.float”)
  >;

Have a look at the SelectionDAGBuilder::visitTargetIntrinsic()
function in lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp. That is
where intrinsics are lowered to SelectionDAG nodes, so you can start
your debugging there to try to figure out why it is INSTRINSIC_WO_CHAIN.

-Tom

Tks Tom,

That is my confusing part. How can I make it to "access memory” so it will HasChain?

Is there any flag set like in typeProfile, Node, instructions? myLoad, mayStore, SDNPHasChain?

-kevin

I mean,
"
SelectionDAGBuilder::visitTargetIntrinsic()"

called
" bool HasChain = !I.doesNotAccessMemory();"
first.

So I think I must did not set up the "access memory kind flag" earlier.
But what can I do to set it up?
thought should be in Intrinsic definition, instruction definition..... but failed to make it right.

X86 has it... did not quite understand ...

any simple example out there ?

many many tks!

Kevin

I mean,
"
SelectionDAGBuilder::visitTargetIntrinsic()"

called
" bool HasChain = !I.doesNotAccessMemory();"
first.

So I think I must did not set up the "access memory kind flag" earlier.
But what can I do to set it up?
thought should be in Intrinsic definition, instruction definition..... but failed to make it right.

X86 has it... did not quite understand ...

any simple example out there ?

You will have to look at the code to see what it does, but I think that
value of I.doesNotAccessMemory() depends on how the intrinsic was
defined in LLVM IR and not how it was defined in TableGen. Can you
provide the LLVM IR you are trying to compile.

-Tom