[llvm-dev] Getting TargetLowering in AsmPrinter / Lowering constant addrspacecast

Tom Stellard via llvm-dev llvm-dev at lists.llvm.org
Mon Dec 14 15:59:56 PST 2015


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


More information about the llvm-dev mailing list