<div dir="ltr">There is no test case as this commit alone doesn't fix the problem explained in the commit message. The constructor of MachineFunction has to be fixed to get the per-function subtarget. See the following link for the discussion that prompted this commit.<div><br></div><div><a href="http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20150309/265459.html">http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20150309/265459.html</a><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 16, 2015 at 11:02 AM, Akira Hatanaka <span dir="ltr"><<a href="mailto:ahatanaka@apple.com" target="_blank">ahatanaka@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: ahatanak<br>
Date: Mon Mar 16 13:02:16 2015<br>
New Revision: 232392<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=232392&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=232392&view=rev</a><br>
Log:<br>
[AsmPrinter] Use the per-function subtarget to emit inline asm instructions that<br>
are not at the file level.<br>
<br>
Previously, the default subtarget created from the target triple was used to<br>
emit inline asm instructions. Compilation would fail in cases where the feature<br>
bits necessary to assemble an inline asm instruction in a function weren't set.<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/CodeGen/AsmPrinter.h<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=232392&r1=232391&r2=232392&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=232392&r1=232391&r2=232392&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)<br>
+++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Mon Mar 16 13:02:16 2015<br>
@@ -504,7 +504,8 @@ private:<br>
<br>
   /// Emit a blob of inline asm to the output streamer.<br>
   void<br>
-  EmitInlineAsm(StringRef Str, const MDNode *LocMDNode = nullptr,<br>
+  EmitInlineAsm(StringRef Str, const MCSubtargetInfo &STI,<br>
+                const MDNode *LocMDNode = nullptr,<br>
                 InlineAsm::AsmDialect AsmDialect = InlineAsm::AD_ATT) const;<br>
<br>
   /// This method formats and emits the specified machine instruction that is an<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=232392&r1=232391&r2=232392&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=232392&r1=232391&r2=232392&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Mon Mar 16 13:02:16 2015<br>
@@ -221,9 +221,13 @@ bool AsmPrinter::doInitialization(Module<br>
<br>
   // Emit module-level inline asm if it exists.<br>
   if (!M.getModuleInlineAsm().empty()) {<br>
+    // We're at the module level. Construct MCSubtarget from the default CPU<br>
+    // and target triple.<br>
+    std::unique_ptr<MCSubtargetInfo> STI(TM.getTarget().createMCSubtargetInfo(<br>
+        TM.getTargetTriple(), TM.getTargetCPU(), TM.getTargetFeatureString()));<br>
     OutStreamer.AddComment("Start of file scope inline assembly");<br>
     OutStreamer.AddBlankLine();<br>
-    EmitInlineAsm(M.getModuleInlineAsm()+"\n");<br>
+    EmitInlineAsm(M.getModuleInlineAsm()+"\n", *STI);<br>
     OutStreamer.AddComment("End of file scope inline assembly");<br>
     OutStreamer.AddBlankLine();<br>
   }<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp?rev=232392&r1=232391&r2=232392&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp?rev=232392&r1=232391&r2=232392&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp Mon Mar 16 13:02:16 2015<br>
@@ -73,7 +73,8 @@ static void srcMgrDiagHandler(const SMDi<br>
 }<br>
<br>
 /// EmitInlineAsm - Emit a blob of inline asm to the output streamer.<br>
-void AsmPrinter::EmitInlineAsm(StringRef Str, const MDNode *LocMDNode,<br>
+void AsmPrinter::EmitInlineAsm(StringRef Str, const MCSubtargetInfo &STI,<br>
+                               const MDNode *LocMDNode,<br>
                                InlineAsm::AsmDialect Dialect) const {<br>
   assert(!Str.empty() && "Can't emit empty inline asm block");<br>
<br>
@@ -93,17 +94,7 @@ void AsmPrinter::EmitInlineAsm(StringRef<br>
       !OutStreamer.isIntegratedAssemblerRequired()) {<br>
     emitInlineAsmStart();<br>
     OutStreamer.EmitRawText(Str);<br>
-    // If we have a machine function then grab the MCSubtarget off of that,<br>
-    // otherwise we're at the module level and want to construct one from<br>
-    // the default CPU and target triple.<br>
-    if (MF) {<br>
-      emitInlineAsmEnd(MF->getSubtarget<MCSubtargetInfo>(), nullptr);<br>
-    } else {<br>
-      std::unique_ptr<MCSubtargetInfo> STI(TM.getTarget().createMCSubtargetInfo(<br>
-          TM.getTargetTriple(), TM.getTargetCPU(),<br>
-          TM.getTargetFeatureString()));<br>
-      emitInlineAsmEnd(*STI, nullptr);<br>
-    }<br>
+    emitInlineAsmEnd(STI, nullptr);<br>
     return;<br>
   }<br>
<br>
@@ -135,19 +126,11 @@ void AsmPrinter::EmitInlineAsm(StringRef<br>
   std::unique_ptr<MCAsmParser> Parser(<br>
       createMCAsmParser(SrcMgr, OutContext, OutStreamer, *MAI));<br>
<br>
-  // Initialize the parser with a fresh subtarget info. It is better to use a<br>
-  // new STI here because the parser may modify it and we do not want those<br>
-  // modifications to persist after parsing the inlineasm. The modifications<br>
-  // made by the parser will be seen by the code emitters because it passes<br>
-  // the current STI down to the EncodeInstruction() method.<br>
-  std::unique_ptr<MCSubtargetInfo> STI(TM.getTarget().createMCSubtargetInfo(<br>
-      TM.getTargetTriple(), TM.getTargetCPU(), TM.getTargetFeatureString()));<br>
-<br>
-  // Preserve a copy of the original STI because the parser may modify it.  For<br>
-  // example, when switching between arm and thumb mode. If the target needs to<br>
-  // emit code to return to the original state it can do so in<br>
+  // Create a temporary copy of the original STI because the parser may modify<br>
+  // it. For example, when switching between arm and thumb mode. If the target<br>
+  // needs to emit code to return to the original state it can do so in<br>
   // emitInlineAsmEnd().<br>
-  MCSubtargetInfo STIOrig = *STI;<br>
+  MCSubtargetInfo TmpSTI = STI;<br>
<br>
   // We create a new MCInstrInfo here since we might be at the module level<br>
   // and not have a MachineFunction to initialize the TargetInstrInfo from and<br>
@@ -155,7 +138,7 @@ void AsmPrinter::EmitInlineAsm(StringRef<br>
   // because it's not subtarget dependent.<br>
   std::unique_ptr<MCInstrInfo> MII(TM.getTarget().createMCInstrInfo());<br>
   std::unique_ptr<MCTargetAsmParser> TAP(TM.getTarget().createMCAsmParser(<br>
-      *STI, *Parser, *MII, TM.Options.MCOptions));<br>
+      TmpSTI, *Parser, *MII, TM.Options.MCOptions));<br>
   if (!TAP)<br>
     report_fatal_error("Inline asm not supported by this streamer because"<br>
                        " we don't have an asm parser for this target\n");<br>
@@ -170,7 +153,7 @@ void AsmPrinter::EmitInlineAsm(StringRef<br>
   // Don't implicitly switch to the text section before the asm.<br>
   int Res = Parser->Run(/*NoInitialTextSection*/ true,<br>
                         /*NoFinalize*/ true);<br>
-  emitInlineAsmEnd(STIOrig, STI.get());<br>
+  emitInlineAsmEnd(STI, &TmpSTI);<br>
   if (Res && !HasDiagHandler)<br>
     report_fatal_error("Error parsing inline asm\n");<br>
 }<br>
@@ -505,7 +488,7 @@ void AsmPrinter::EmitInlineAsm(const Mac<br>
   else<br>
     EmitMSInlineAsmStr(AsmStr, MI, MMI, InlineAsmVariant, AP, LocCookie, OS);<br>
<br>
-  EmitInlineAsm(OS.str(), LocMD, MI->getInlineAsmDialect());<br>
+  EmitInlineAsm(OS.str(), getSubtargetInfo(), LocMD, MI->getInlineAsmDialect());<br>
<br>
   // Emit the #NOAPP end marker.  This has to happen even if verbose-asm isn't<br>
   // enabled, so we use emitRawComment.<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div></div>