[PATCH] MC: provide the ability to disable assembly parsing

Saleem Abdulrasool compnerd at compnerd.org
Thu Feb 20 00:19:57 PST 2014


Hi rengolin, dwmw2,

This provides an interface for the frontend to disable assembly parsing.  This
is needed in the case where inline assembly is being processed to an assembly
output (.s).  In this case, it is preferable to not parse the assembly for
correctness.  The Linux kernel, for example, takes advantage of this to
use the compiler as a preprocessor to generate a specially crafted "assembly"
file to be post-processed.

This change is pretty simple in implementation, but, I feel that it is something that should be discussed pre-commit (mostly for the clang perspective which is/will be sent out as a separate change).  The motivation behind this change is to support compiling the Linux kernel with clang and the integrated assembler (on ARM).  However, there is nothing ARM specific in this change.

http://llvm-reviews.chandlerc.com/D2839

Files:
  include/llvm/MC/MCAsmInfo.h
  include/llvm/Target/TargetOptions.h
  lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
  lib/CodeGen/LLVMTargetMachine.cpp

Index: include/llvm/MC/MCAsmInfo.h
===================================================================
--- include/llvm/MC/MCAsmInfo.h
+++ include/llvm/MC/MCAsmInfo.h
@@ -307,6 +307,12 @@
     /// construction (see LLVMTargetMachine::initAsmInfo()).
     bool UseIntegratedAssembler;
 
+    /// Should we parse inline assembly?
+    /// The integrated assembler will usually parse inline assembly.  However,
+    /// when simply generating an object file, it can be useful to prevent this
+    /// (e.g. the Linux kernel uses it as a fancy preprocessor).
+    bool ValidateInlineASMSyntax;
+
   public:
     explicit MCAsmInfo();
     virtual ~MCAsmInfo();
@@ -542,6 +548,13 @@
     void setUseIntegratedAssembler(bool Value) {
       UseIntegratedAssembler = Value;
     }
+
+    void SetValidateInlineAssembly(bool Value) {
+      ValidateInlineASMSyntax = Value;
+    }
+    bool ValidateInlineAssembly() const {
+      return ValidateInlineASMSyntax;
+    }
   };
 }
 
Index: include/llvm/Target/TargetOptions.h
===================================================================
--- include/llvm/Target/TargetOptions.h
+++ include/llvm/Target/TargetOptions.h
@@ -50,7 +50,8 @@
           GuaranteedTailCallOpt(false), DisableTailCalls(false),
           StackAlignmentOverride(0),
           EnableFastISel(false), PositionIndependentExecutable(false),
-          EnableSegmentedStacks(false), UseInitArray(false), TrapFuncName(""),
+          EnableSegmentedStacks(false), UseInitArray(false),
+          ValidateInlineASMSyntax(true), TrapFuncName(""),
           FloatABIType(FloatABI::Default), AllowFPOpFusion(FPOpFusion::Standard)
     {}
 
@@ -158,6 +159,9 @@
     /// constructors.
     unsigned UseInitArray : 1;
 
+    /// ValidateInlineASMSyntax - Validate inline assembly syntax.
+    unsigned ValidateInlineASMSyntax : 1;
+
     /// getTrapFunctionName - If this returns a non-empty string, this means
     /// isel should lower Intrinsic::trap to a call to the specified function
     /// name instead of an ISD::TRAP node.
@@ -213,6 +217,7 @@
     ARE_EQUAL(PositionIndependentExecutable) &&
     ARE_EQUAL(EnableSegmentedStacks) &&
     ARE_EQUAL(UseInitArray) &&
+    ARE_EQUAL(ValidateInlineASMSyntax) &&
     ARE_EQUAL(TrapFuncName) &&
     ARE_EQUAL(FloatABIType) &&
     ARE_EQUAL(AllowFPOpFusion);
Index: lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
+++ lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
@@ -86,8 +86,9 @@
   // system assembler does.
   const MCAsmInfo *MCAI = TM.getMCAsmInfo();
   assert(MCAI && "No MCAsmInfo");
-  if (!MCAI->useIntegratedAssembler() &&
-      !OutStreamer.isIntegratedAssemblerRequired()) {
+  if ((!MCAI->useIntegratedAssembler() &&
+       !OutStreamer.isIntegratedAssemblerRequired()) ||
+      !MCAI->ValidateInlineAssembly()) {
     OutStreamer.EmitRawText(Str);
     emitInlineAsmEnd(TM.getSubtarget<MCSubtargetInfo>(), 0);
     return;
Index: lib/CodeGen/LLVMTargetMachine.cpp
===================================================================
--- lib/CodeGen/LLVMTargetMachine.cpp
+++ lib/CodeGen/LLVMTargetMachine.cpp
@@ -79,6 +79,7 @@
 
   if (NoIntegratedAssembler)
     TmpAsmInfo->setUseIntegratedAssembler(false);
+  TmpAsmInfo->SetValidateInlineAssembly(Options.ValidateInlineASMSyntax);
 
   AsmInfo = TmpAsmInfo;
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2839.1.patch
Type: text/x-patch
Size: 3417 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140220/c4d6ef00/attachment.bin>


More information about the llvm-commits mailing list