Manuel Jacob via llvm-dev
2015-Dec-14 23:41 UTC
[llvm-dev] Getting TargetLowering in AsmPrinter / Lowering constant addrspacecast
Hi, I'd like to add support for addrspacecast in initializers of global variables, at least for the trivial case. The trivial case is if TargetLowering::isNoopAddrSpaceCast(SrcAS, DestAS) returns true. In this case the MCExpr for the addrspacecast is the MCExpr of its first operand. It seems hard to obtain an instance of TargetLowering in AsmPrinter::lowerConstant(). Other methods in this class obtain it by calling `MF->getSubtarget().getTargetLowering()`. However, because MF is nullptr when lowering initializers of global variables, it won't work. My impression is that this is not possible because every function has its own TargetLowering instance. Is that correct? NVPTX solves the problem by having a method on it's NVPTXAsmPrinter class, which is mostly a copy of AsmPrinter::lowerConstant() and knows how to handle addrspacecasts. However, this probably isn't a solution for e.g. X86. Suggestions are highly welcome. -Manuel
Justin Holewinski via llvm-dev
2015-Dec-14 23:46 UTC
[llvm-dev] Getting TargetLowering in AsmPrinter / Lowering constant addrspacecast
Yeah, NVPTX is funny and requires some extra handling; especially in regards to how such casts are emitted in the assembly. It’s certainly not ideal. We actually wrap such casts in a custom MCExpr sub-class. On 12/14/15, 6:41 PM, "Manuel Jacob" <me at manueljacob.de> wrote:>Hi, > >I'd like to add support for addrspacecast in initializers of global >variables, at least for the trivial case. The trivial case is if >TargetLowering::isNoopAddrSpaceCast(SrcAS, DestAS) returns true. In >this case the MCExpr for the addrspacecast is the MCExpr of its first >operand. > >It seems hard to obtain an instance of TargetLowering in >AsmPrinter::lowerConstant(). Other methods in this class obtain it by >calling `MF->getSubtarget().getTargetLowering()`. However, because MF >is nullptr when lowering initializers of global variables, it won't >work. My impression is that this is not possible because every function >has its own TargetLowering instance. Is that correct? > >NVPTX solves the problem by having a method on it's NVPTXAsmPrinter >class, which is mostly a copy of AsmPrinter::lowerConstant() and knows >how to handle addrspacecasts. However, this probably isn't a solution >for e.g. X86. > >Suggestions are highly welcome. > >-Manuel----------------------------------------------------------------------------------- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. -----------------------------------------------------------------------------------
Tom Stellard via llvm-dev
2015-Dec-14 23:59 UTC
[llvm-dev] Getting TargetLowering in AsmPrinter / Lowering constant addrspacecast
On Tue, Dec 15, 2015 at 12:41:57AM +0100, Manuel Jacob via llvm-dev wrote:> Hi, > > I'd like to add support for addrspacecast in initializers of global > variables, at least for the trivial case. The trivial case is if > TargetLowering::isNoopAddrSpaceCast(SrcAS, DestAS) returns true. In > this case the MCExpr for the addrspacecast is the MCExpr of its first > operand. >You could create a Util directory and put the implementation of isNoopAddrSpaceCast in there. We do this in AMDGPU when we want to share code between the MC and non-MC parts of the compiler. -Tom> It seems hard to obtain an instance of TargetLowering in > AsmPrinter::lowerConstant(). Other methods in this class obtain it by > calling `MF->getSubtarget().getTargetLowering()`. However, because MF > is nullptr when lowering initializers of global variables, it won't > work. My impression is that this is not possible because every function > has its own TargetLowering instance. Is that correct? > > NVPTX solves the problem by having a method on it's NVPTXAsmPrinter > class, which is mostly a copy of AsmPrinter::lowerConstant() and knows > how to handle addrspacecasts. However, this probably isn't a solution > for e.g. X86. > > Suggestions are highly welcome. > > -Manuel > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Manuel Jacob via llvm-dev
2015-Dec-15 17:19 UTC
[llvm-dev] Getting TargetLowering in AsmPrinter / Lowering constant addrspacecast
On 2015-12-15 00:59, Tom Stellard wrote:> On Tue, Dec 15, 2015 at 12:41:57AM +0100, Manuel Jacob via llvm-dev > wrote: >> Hi, >> >> I'd like to add support for addrspacecast in initializers of global >> variables, at least for the trivial case. The trivial case is if >> TargetLowering::isNoopAddrSpaceCast(SrcAS, DestAS) returns true. In >> this case the MCExpr for the addrspacecast is the MCExpr of its first >> operand. >> > > You could create a Util directory and put the implementation of > isNoopAddrSpaceCast in there. We do this in AMDGPU when we want > to share code between the MC and non-MC parts of the compiler.Your suggestion is very helpful to avoid code duplication for a single target. However, it still requires every target to implement an additional target hook, instead of using the existing one. -Manuel> > -Tom > >> It seems hard to obtain an instance of TargetLowering in >> AsmPrinter::lowerConstant(). Other methods in this class obtain it by >> calling `MF->getSubtarget().getTargetLowering()`. However, because MF >> is nullptr when lowering initializers of global variables, it won't >> work. My impression is that this is not possible because every >> function >> has its own TargetLowering instance. Is that correct? >> >> NVPTX solves the problem by having a method on it's NVPTXAsmPrinter >> class, which is mostly a copy of AsmPrinter::lowerConstant() and knows >> how to handle addrspacecasts. However, this probably isn't a solution >> for e.g. X86. >> >> Suggestions are highly welcome. >> >> -Manuel >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev