[llvm-commits] [PATCH] Review request: MC access to target and subtarget machine info

Carter, Jack jcarter at mips.com
Mon Dec 3 11:48:50 PST 2012


SUMMARY:
This patch adds the <target>TargetMachine class
object to the creation of the <target>MCAsmBackend
class object.

PROBLEM:
The problem I have been having for some time is how
to get access to target specific information during
the direct object output phase. The current issue was
how to fill the ELF header's target specific E_FLAGS
bit field.

SOLUTION:
The information has already been collected and isolated
by the <target>TargetMachine class object. This patch
passes the const pointer to this class object to the
<target>MCAsmBackend class object which in turn passes
it to the <target>ELFObjectWriter class object which
updates the E_FLAGS.

This is the current creation routine for the backend:

MCAsmBackend *llvm::createMipsAsmBackendEB64(const Target &T, StringRef TT,
                                             StringRef CPU,
                                             const TargetMachine *TM) {
  return new MipsAsmBackend(T, Triple(TT).getOS(),
                            /*IsLittle*/false, /*Is64Bit*/true, TM);
}

I believe we could reduce this to the one parameter TM
and derive the rest of the information from it. I also
believe that TM could be used with the other MC classes
to reduce the need for future parameters there as well.

An alternative and maybe cleaner solution would to create
another class object, call it MCTarget for now, That would
be filled at about the same time as SubtargetInfo and filled
independently by the individual targets with just what they
want. This might be more acceptable to the llvm-mc folks. I'd
still want to load it with TM from a MCTarget method initially
because the info is there.

For now, TargetMachine/SubtargetInfo have already derived
all that I need, albeit with a load of stuff I don't need
as well.

CAVEAT:
llvm-mc and clang both create MCAsmBackend separate from
the general mechanism. In this patch I pass 0 (NULL) and
check for it before using the <target>TargetMachine object
pointer. That is also why I use a pointer instead of a reference.

This will be fixed in a later patch.

CONCLUSION:
* This patch does not affect the current behavior of other
  targets.
* Future E_FLAGS additions will be easy to implement at the
  individual target level.
* This change has changes in both the llvm and clang trees.
* it would be followed up with patches for llvm-mc and clang.

Contributer: Jack Carter

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121203/c4d7a2c1/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: elf_header.patch
Type: text/x-patch
Size: 25648 bytes
Desc: elf_header.patch
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121203/c4d7a2c1/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: elf_header_clang.patch
Type: text/x-patch
Size: 1712 bytes
Desc: elf_header_clang.patch
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121203/c4d7a2c1/attachment-0001.bin>


More information about the llvm-commits mailing list