<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<br>
<br>
<div class="moz-cite-prefix">On 1/6/20 9:51 PM, Jie Zhou via cfe-dev
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:28F1A7CA-5808-48D8-AC5E-280CF6ABF2EA@cs.rochester.edu">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Dear All,
<div class=""><br class="">
</div>
<div class="">I’m working on a project that extends C. I’m adding
a new type of pointer</div>
<div class="">that is a fat pointer. It has some metadata about
the pointed object besides</div>
<div class="">the starting address of the object. Currently I
implemented this pointer as</div>
<div class="">an llvm:StructType. In llvm::Type generation
function</div>
<div class=""><i class="">llvm::Type
*CodeGenTypes::ConvertType(QualType T)</i></div>
<div class="">in the case for <i class="">clang::Type::Pointer</i>,
instead of creating an llvm::PointerType</div>
<div class="">I create an llvm::StructType type for this new type
of pointer. And I added some</div>
<div class="">helper code in llvm::StructType and in multiple
places I added code to trick</div>
<div class="">the compiler to believe sometimes a struct is
actually a pointer. Until now</div>
<div class="">it compile test programs fine with -O0 but I got
lots of assertion failures when</div>
<div class="">compiling with -O1 or -O2 majorly because of the
confusion of type mismatch.</div>
<div class=""><br class="">
</div>
<div class="">LLVM assumes that a PointerType is essentially an
Integer (32 or 64 bit depending</div>
<div class="">on the architecture), and since this is quite a
fundamental assumption, I started</div>
<div class="">to question whether my way of implementing the fat
pointer is feasible.</div>
<div class="">I thought about adding a new llvm type that inherits
both llvm:PointerType</div>
<div class="">and llvm:StructType; but I’m not sure if this is the
correct path. It looks like</div>
<div class="">this demands substantial changes to the compiler
including adding code</div>
<div class="">for bitcode generation. Can you give me some advice
on how to implement</div>
<div class="">a fat pointer in llvm?</div>
<div class=""><br class="">
</div>
<div class="">Thanks,</div>
<div class="">- Jie</div>
</blockquote>
Jie,<br>
<br>
I'm no expert but LLVM does do function pointers as a pointer type
with extra data in IR.<br>
I just checked and it's mentioned in Global Variables and Function
Addresses of the LLVM<br>
IR manual. Maybe exploring how that is implemented as it seems
similar would be a place<br>
to start. The data would be different i.e. no function arguments as
its a data object but the<br>
ideas should be similar in that its a pointer with more meta
information than a normal pointer.<br>
<br>
Maybe that helps,<br>
<br>
Nick<br>
<blockquote type="cite"
cite="mid:28F1A7CA-5808-48D8-AC5E-280CF6ABF2EA@cs.rochester.edu">
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
cfe-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a>
</pre>
</blockquote>
<br>
</body>
</html>