Iulia Stirb via llvm-dev
2019-Sep-03 18:39 UTC
[llvm-dev] Get constants of undefined types in IR
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>
Tim Northover via llvm-dev
2019-Sep-04 17:51 UTC
[llvm-dev] Get constants of undefined types in IR
Hi Iulia, On Tue, 3 Sep 2019 at 19:39, Iulia Stirb <iulia_s24 at yahoo.com> wrote:> 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?I take it that's a Clang error when compiling the code? I'm not entirely sure, but it's possible you don't have a full definition for llvm::ArrayType. It's not in the same header as IntegerType, so try #including DerivedTypes.h. Otherwise, does it give any indication about which type is incomplete? Cheers. Tim.
Iulia Stirb via llvm-dev
2019-Sep-05 17:38 UTC
[llvm-dev] Get constants of undefined types in IR
Hi Tim, Thank you for the answer. I found another solution so I didn't need to use ArrayType for what I intended to do. I did include the DerivedTypes.h from the first place, but the problem was still there and there was no indication about which type is incomplete (I assume ArrayType). Regards,Iulia On Wednesday, September 4, 2019, 8:51:40 PM GMT+3, Tim Northover <t.p.northover at gmail.com> wrote: Hi Iulia, On Tue, 3 Sep 2019 at 19:39, Iulia Stirb <iulia_s24 at yahoo.com> wrote:> 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?I take it that's a Clang error when compiling the code? I'm not entirely sure, but it's possible you don't have a full definition for llvm::ArrayType. It's not in the same header as IntegerType, so try #including DerivedTypes.h. Otherwise, does it give any indication about which type is incomplete? Cheers. Tim. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190905/a7a3057f/attachment.html>