Rodney M. Bates via llvm-dev
2017-Aug-17 22:15 UTC
[llvm-dev] How do set 'nest' addribute in an indirect call?
I need to set the 'next' attribute on a parameter. If the function is to be directly called, i.e., a function constant, I am getting what I want as follows (using the C 'Core.h' binding) 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.m.bates at acm.org
Rodney M. Bates via llvm-dev
2017-Aug-24 14:32 UTC
[llvm-dev] How do set 'nest' addribute in an indirect call?
Ping. On 08/17/2017 05:15 PM, Rodney M. Bates via llvm-dev wrote:> I need to set the 'next' attribute on a parameter. If the function is to be > directly called, i.e., a function constant, I am getting what I want as follows > (using the C 'Core.h' binding) > > 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.m.bates at acm.org
Tim Northover via llvm-dev
2017-Aug-24 14:40 UTC
[llvm-dev] How do set 'nest' addribute in an indirect call?
On 17 August 2017 at 15:15, Rodney M. Bates via llvm-dev <llvm-dev at 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. Cheers. Tim.
Rodney M. Bates via llvm-dev
2017-Aug-24 20:43 UTC
[llvm-dev] How do set 'nest' addribute in an indirect call?
On 08/24/2017 09:40 AM, Tim Northover wrote:> On 17 August 2017 at 15:15, Rodney M. Bates via llvm-dev > <llvm-dev at 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.m.bates at acm.org
Reasonably Related Threads
- How do set 'nest' addribute in an indirect call?
- [LLVMdev] Question about changes to llvm::Argument::addAttr(AttributeSet AS) API
- [LLVMdev] Question about changes to llvm::Argument::addAttr(AttributeSet AS) API
- [4.0 Release] Schedule and call for testers
- Samba Beta 3 + LDAP: user in mapped group "Domain Admins" isn't a domain admin when he logs on