[llvm-dev] Get constants of undefined types in IR

Iulia Stirb via llvm-dev llvm-dev at lists.llvm.org
Tue Sep 3 11:39:20 PDT 2019


Hi Tim,
My mistake not including the llvm-dev, excuse me. affinityElement.__bits[0] worked fine for me, thank you. I am new in using the API for Constants and I am facing the error "incomplete type is not allowed" on the last last of below code: Type * ET = IntegerType::getInt64Ty(I.getContext()); unsigned long size = cpuAffinityVector.size(); ArrayType * AT = ArrayType::get(ET,size);
Internet gives different solutions for this error but none of them was appropriate for this case.
Could you please help?
Regards,Iulia




 

    On Tuesday, September 3, 2019, 8:15:26 PM GMT+3, Tim Northover <t.p.northover at gmail.com> wrote:  
 
 Adding llvm-dev back.
On Tue, 3 Sep 2019 at 18:02, Iulia Stirb <iulia_s24 at yahoo.com> wrote:
Thank very much you for your answer. Following the indications in your mail, I obtained one of the 16th elements as below:
 static cpu_set_t getCpuAffinityElement(cpu_set_t affinity, int index) { cpu_set_t mask; CPU_ZERO(&mask); for(int i = index * sizeof(unsigned long); i < (index + 1) * sizeof(unsigned long); i++) { CPU_SET(i,&mask); } CPU_AND(&affinity, &affinity, &mask); return affinity; }

That looks like a weird function, but it’s just within the realms of plausible so I’ll assume you know what you’re doing. 



The problem is that the element is of type cpu_set_t and cannot be converted to unsigned long. So, when I try to get the ConstantInt object like below, I get an error saying that I cannot pass a cpu_set_t parameter as second parameter of get method.ConstantInt * elem = ConstantInt::get(Type::getInt64Ty(I.getContext()),affinityElement,false);

To use a real cpu_set_t from the host as part of a. ConstantInt like that you’ll have to look at its actual definition and access something like affinityElement.__bits[0]. The exact internals may vary with the header you’re using, but you’re fundamentally trying to do something ABI specific so you will have to get your hands dirty. 
What I need is to insert in IR a call that has a cpu_set_t parameter, and the parameter is already set (so I don't need to construct it).

An alternative might be to pass a pointer to the cpu_set_t you created above into the Module somehow (a global might work). It would sidestep the tricky annoying API for Constants in LLVM, and possibly even be a buffer against the structure changing in future. 
Cheers.
Tim.  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190903/9cce31e9/attachment.html>


More information about the llvm-dev mailing list