[llvm-dev] [RFC][LLVM] New Constant type for representing function PLT entries
Chris Lattner via llvm-dev
llvm-dev at lists.llvm.org
Fri Aug 21 17:19:30 PDT 2020
Sure, I also don’t like unnecessary complexity. Let me try to motivate this along two different points: expressivity, and simplicity.
On Expressivity, LLVM IR *in general* provides an abstract representation that allows frontends to generate target independent(ish!) IR, instead of having to understand all of the target details, e.g. you shouldn’t have to know the target to get an integer add. However, the model is really that we provide *both* a target independent model and a target-specific model. You can see this in calling conventions, you can see this in target-specific intrinsics, you can see this in inline assembly. In my opinion these are all good examples of LLVM providing target-independent abstractions, while still allowing frontends to get to the full capability of the hardware/architecture/target. Making addressing modes for relocations consistent with that seems like a good thing.
On simplicity, I’ve mentioned before that the right thing is to redesign ConstantExpr entirely, eliminating most of the operations. “Trapping” constants (like divide) is a huge bug in the representation, and is only there for historical reasons. When you get beyond the fundamental integer and FP constants, the only reason we have aggregates (ConstantArray) and ConstantExpr is to enable global variable initializers that contain relocations. Things like constants (and particularly constant exprs) in PHI nodes are persistent problems at the LLVM IR level that would be better defined away. As such, a reasonable design for constants would be “fundamental constants within function bodies; possibly using an MLIR like representation to define away even these” and “global variable initializers”. Note that there is no specific reason that “global variable initializers” be Value*’s.
In any case, I think the first thing is motivation alone. Doing so would be a stepping stone to get rid of all the crazy backend logic that tries to match "gv-gv+cst” etc, instead allowing this to be done on the IR level.
> On Aug 20, 2020, at 8:35 PM, Eric Christopher <echristo at gmail.com> wrote:
> I do have concerns about the amount of object level modeling that we want to do in the IR though. While it isn't the highest level IR we've managed to mostly avoid these kinds of features/complications in the past. I'm definitely interested in hearing some alternate implementations here and there rather than a full set of constants for relocations. Keeping the IR abstract enough over the object file level other than in generalizable cases still feels like a win.
> On Thu, Aug 20, 2020 at 8:44 PM Chris Lattner via llvm-dev <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote:
> Hi Leonard,
> I haven’t looked at your patch in detail, but I think that this is a step in the right direction. I would like to see new “Constant*”’s that directly map onto the relocations that various object formats use (for example, macho has a relocation for “&g1-&g2+cst”). This would get us to a more principled lowering in many cases as well as make the backend modeling more specific.
>> On Aug 20, 2020, at 11:29 AM, Leonard Chan via llvm-dev <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote:
>> Hi all,
>> We would like to propose a new Constant type in LLVM for representing entries in the Procedure Linkage Table (PLT).
>> The PLT is a data structure used for dispatching position-independent function calls to appropriate functions where the address of the function is not known statically. Right now, if a call is made to a function, it may be lowered to a direct call to the function itself or the PLT entry for that function. LLVM has checks that dictate if the function call should be a direct reference or PLT entry, but we don’t have a way in IR to semantically represent that the PLT entry should be used.
>> The proposed constant would be analogous to BlockAddress, but instead represent the PLT entry for functions. The usage could look something like:
>> and would always have the same type as the function. A pltentry would operate exactly like a function, but the main difference is that it’s lowered to the PLT entry (function at plt) on targets that support PLT relocations. The linker can then decide if it should be relaxed into a direct reference or remain a PLT entry.
>> I have a very rough WIP implementation at https://reviews.llvm.org/D77248 <https://reviews.llvm.org/D77248>.
>> Thoughts and opinions?
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev <https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev>
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev <https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev