<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"><base href="x-msg://32740/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Jack,<div><br></div><div>TargetMachine is deliberately not available in any MC layer code, as it's part of the CodeGen layer.</div><div><br></div><div>You probably want something along the lines of the features bit mask in MCSubtargetInfo. The ARM assembler has some examples of using that for related things.</div><div><br></div><div>-Jim</div><div><br></div><div><div><div>On Dec 3, 2012, at 11:48 AM, "Carter, Jack" <<a href="mailto:jcarter@mips.com">jcarter@mips.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div ocsi="0" fpstyle="1" style="font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="direction: ltr; font-family: Tahoma; font-size: 10pt; ">SUMMARY:<br>This patch adds the <target>TargetMachine class<span class="Apple-converted-space"> </span><br>object to the creation of the <target>MCAsmBackend<br>class object.<br><br>PROBLEM:<br>The problem I have been having for some time is how<br>to get access to target specific information during<br>the direct object output phase. The current issue was<br>how to fill the ELF header's target specific E_FLAGS<br>bit field.<br><br>SOLUTION:<br>The information has already been collected and isolated<br>by the <target>TargetMachine class object. This patch<br>passes the const pointer to this class object to the<span class="Apple-converted-space"> </span><br><target>MCAsmBackend class object which in turn passes<span class="Apple-converted-space"> </span><br>it to the <target>ELFObjectWriter class object which<br>updates the E_FLAGS.<br><br>This is the current creation routine for the backend:<br><br>MCAsmBackend *llvm::createMipsAsmBackendEB64(const Target &T, StringRef TT,<br>                                             StringRef CPU,<br>                                             const TargetMachine *TM) {<br>  return new MipsAsmBackend(T, Triple(TT).getOS(),<br>                            /*IsLittle*/false, /*Is64Bit*/true, TM);<br>}<br><br>I believe we could reduce this to the one parameter TM<span class="Apple-converted-space"> </span><br>and derive the rest of the information from it. I also<br>believe that TM could be used with the other MC classes<br>to reduce the need for future parameters there as well.<br><br>An alternative and maybe cleaner solution would to create<br>another class object, call it MCTarget for now, That would<br>be filled at about the same time as SubtargetInfo and filled<br>independently by the individual targets with just what they<br>want. This might be more acceptable to the llvm-mc folks. I'd<br>still want to load it with TM from a MCTarget method initially<br>because the info is there.<br><br>For now, TargetMachine/SubtargetInfo have already derived<span class="Apple-converted-space"> </span><br>all that I need, albeit with a load of stuff I don't need<br>as well.<br><br>CAVEAT:<br>llvm-mc and clang both create MCAsmBackend separate from<br>the general mechanism. In this patch I pass 0 (NULL) and<span class="Apple-converted-space"> </span><br>check for it before using the <target>TargetMachine object<br>pointer. That is also why I use a pointer instead of a reference.<br><br>This will be fixed in a later patch.<br><br>CONCLUSION:<br>* This patch does not affect the current behavior of other<br>  targets.<br>* Future E_FLAGS additions will be easy to implement at the<br>  individual target level.<br>* This change has changes in both the llvm and clang trees.<br>* it would be followed up with patches for llvm-mc and clang.<br><br>Contributer: Jack Carter<br><br></div><span><elf_header.patch></span><span><elf_header_clang.patch></span></div></blockquote></div><br></div></body></html>