1) Build a function type, using LLVMFunctionType.
2) Build a function value, passing the result of 1) to LLVMAddFunction
3) Go through the formal parameters of 2), using LLVMGet[First|Next]Param,
which give me a value for each formal
4) For the desired formal, pass it to LLVMAddAttribute.
This results in compiled code that passes my parameter in the same way as gcc,
giving the interoperability I need.
For an indirect call, i.e., on a function whose address is runtime variable,
I can't find any place/way to attach this attribute. LLVMAddAttribute
won't take a type.
I don't see a way to construct a function value with a runtime variable
address, that I could do 3) & 4) on. (I already have an i8* pointer to
the function code.)
The comment on LLVMAddAttribute says " Add an attribute to a function argument",
which, to me, "argument" means an actual parameter. But When I try that, I get
an assertion failure, which I am having trouble interpreting:
m3llvm: /home/rodney/proj/llvm/llvm-3.6.1/llvm-3.6.1.src/include/llvm/Support/Casting.h:237: typename cast_retty<X, Y *>::ret_type llvm::cast(Y *) [X = llvm::Argument, Y = llvm::Value]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
My actual parameter is a load instruction, which I would expect to be a value.
Its llvm type is i8*, but I don't think that is relevant.
Here are some relevant debugger lines:
(m3gdb) frame 7
#7 0x00000000004264fd in M3CG_LLVM__InnerCallIndirect (self=16_0000000001b30830, proc=16_0000000001a7e388, t=Void,
cc=16_0000000001b07928, Nested=TRUE) at ../src/M3CG_LLVM.m3:4750
4750 LLVM.LLVMAddAttribute(actual.lVal, LLVM.NestAttribute);
Current language: auto; currently Modula-3
(m3gdb) p M3CG_LLVM__DumpLvVal(actual.lVal)
%load_ind13 = load i8** %load_ind_toptr12
$1 = <void>
(m3gdb) p M3CG_LLVM__LvType(actual.lVal)
$2 = 16_0000000001a78620
(m3gdb) p M3CG_LLVM__DumpLvType($2)
i8*
$3 = <void>
(m3gdb)
--
Rodney Bates
rodney....@acm.org
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
In the C++ API you'd add the attribute to the CallInst. I've not used
any of the wrappers, but I think you might get what you want via
LLVMAddCallSiteAttribute.
Cheers.
Tim.
On 08/24/2017 09:40 AM, Tim Northover wrote:
> On 17 August 2017 at 15:15, Rodney M. Bates via llvm-dev
> <llvm...@lists.llvm.org> wrote:
>> For an indirect call, i.e., on a function whose address is runtime variable,
>> I can't find any place/way to attach this attribute. LLVMAddAttribute
>> won't take a type.
>
> In the C++ API you'd add the attribute to the CallInst. I've not used
> any of the wrappers, but I think you might get what you want via
> LLVMAddCallSiteAttribute.
I don't find LLVMAddCallSiteAttribute or anything similar in include/llvm. (I am using 3.6.1)
I do see llvm::CallInst::addAttribute
/// addAttribute - adds the attribute to the list of attributes.
void addAttribute(unsigned i, Attribute::AttrKind attr);
Is 'i' the number of the parameter that gets the attribute? This matters for 'nest'.
Is it zero-origin numbering, left-to-right?
I have an out-of-tree binding already for a small set of things not in Core.h,
and it's not hard to add things in ones & twos.
>
> Cheers.
>
> Tim.
>
--
Rodney Bates
rodney....@acm.org
It may have been added since then, it definitely exists in trunk.
> /// addAttribute - adds the attribute to the list of attributes.
> void addAttribute(unsigned i, Attribute::AttrKind attr);
>
> Is 'i' the number of the parameter that gets the attribute? This matters
> for 'nest'. Is it zero-origin numbering, left-to-right?
I believe 0 is the return and args start at 1 (see
include/llvm/IR/Attributes.h, especially the AttrIndex enum).
> I have an out-of-tree binding already for a small set of things not in
> Core.h, and it's not hard to add things in ones & twos.
Oh good, that'll make using a slightly older version less of a
disaster and more an inconvenience.
Cheers.
Tim.
On 08/24/2017 03:48 PM, Tim Northover wrote:
> On 24 August 2017 at 13:43, Rodney M. Bates <rodney...@lcwb.coop> wrote:
>> I don't find LLVMAddCallSiteAttribute or anything similar in include/llvm.
>> (I am using 3.6.1)
>
> It may have been added since then, it definitely exists in trunk.
>
Looking to see how to write a binding for CallInst::addAttr, I came across
LLVMAddInstrAttribute. Tried it out and it did want I want. It's
a little surprising, because it unwraps its operand to an Instruction,
a superclass of CallInstr. But I'm happy to let that go uninvestigated.
Thanks for the help. Putting it on starting from the CallInstr instead of
directly on a parameter was the breakout info for me.
>> /// addAttribute - adds the attribute to the list of attributes.
>> void addAttribute(unsigned i, Attribute::AttrKind attr);
>>
>> Is 'i' the number of the parameter that gets the attribute? This matters
>> for 'nest'. Is it zero-origin numbering, left-to-right?
>
> I believe 0 is the return and args start at 1 (see
> include/llvm/IR/Attributes.h, especially the AttrIndex enum).
>
>> I have an out-of-tree binding already for a small set of things not in
>> Core.h, and it's not hard to add things in ones & twos.
>
> Oh good, that'll make using a slightly older version less of a
> disaster and more an inconvenience.
>
> Cheers.
>
> Tim.
>
--
Rodney Bates
rodney....@acm.org