Remove a call to TargetMachine::getSubtarget from the inline
authorEric Christopher <echristo@gmail.com>
Thu, 19 Feb 2015 21:24:23 +0000 (21:24 +0000)
committerEric Christopher <echristo@gmail.com>
Thu, 19 Feb 2015 21:24:23 +0000 (21:24 +0000)
asm support in the asm printer. If we can get a subtarget from
the machine function then we should do so, otherwise we can
go ahead and create a default one since we're at the module
level.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229916 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp

index 4dd41ca678e25ed36e1705648a84a9f960e98e1e..a8b00561fe7ab68a6152e3dd07d0d31b88ccea2c 100644 (file)
@@ -92,7 +92,17 @@ void AsmPrinter::EmitInlineAsm(StringRef Str, const MDNode *LocMDNode,
       !OutStreamer.isIntegratedAssemblerRequired()) {
     emitInlineAsmStart();
     OutStreamer.EmitRawText(Str);
-    emitInlineAsmEnd(TM.getSubtarget<MCSubtargetInfo>(), nullptr);
+    // If we have a machine function then grab the MCSubtarget off of that,
+    // otherwise we're at the module level and want to construct one from
+    // the default CPU and target triple.
+    if (MF) {
+      emitInlineAsmEnd(MF->getSubtarget<MCSubtargetInfo>(), nullptr);
+    } else {
+      std::unique_ptr<MCSubtargetInfo> STI(TM.getTarget().createMCSubtargetInfo(
+          TM.getTargetTriple(), TM.getTargetCPU(),
+          TM.getTargetFeatureString()));
+      emitInlineAsmEnd(*STI, nullptr);
+    }
     return;
   }