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

Manuel Jacob via llvm-dev llvm-dev at lists.llvm.org
Mon Dec 14 15:41:57 PST 2015


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


More information about the llvm-dev mailing list