r329823 - bpf: accept all asm register names

Yonghong Song via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 11 09:08:00 PDT 2018


Author: yhs
Date: Wed Apr 11 09:08:00 2018
New Revision: 329823

URL: http://llvm.org/viewvc/llvm-project?rev=329823&view=rev
Log:
bpf: accept all asm register names

Sometimes when people compile bpf programs with
"clang ... -target bpf ...", the kernel header
files may contain host arch inline assembly codes
as in the patch https://patchwork.kernel.org/patch/10119683/
by Arnaldo Carvaldo de Melo.

The current workaround in the above patch
is to guard the inline assembly with "#ifndef __BPF__"
marco. So when __BPF__ is defined, these macros will
have no use.

Such a method is not extensible. As a matter of fact,
most of these inline assembly codes will be thrown away
at the end of clang compilation.

So for bpf target, this patch accepts all asm register
names in clang AST stage. The name will be checked
again during llc code generation if the inline assembly
code is indeed for bpf programs.

With this patch, the above "#ifndef __BPF__" is not needed
any more in https://patchwork.kernel.org/patch/10119683/.

Signed-off-by: Yonghong Song <yhs at fb.com>

Modified:
    cfe/trunk/include/clang/Basic/TargetInfo.h
    cfe/trunk/lib/Basic/Targets/BPF.h

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=329823&r1=329822&r2=329823&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Wed Apr 11 09:08:00 2018
@@ -619,7 +619,7 @@ public:
   /// according to GCC.
   ///
   /// This is used by Sema for inline asm statements.
-  bool isValidGCCRegisterName(StringRef Name) const;
+  virtual bool isValidGCCRegisterName(StringRef Name) const;
 
   /// \brief Returns the "normalized" GCC register name.
   ///

Modified: cfe/trunk/lib/Basic/Targets/BPF.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/BPF.h?rev=329823&r1=329822&r2=329823&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets/BPF.h (original)
+++ cfe/trunk/lib/Basic/Targets/BPF.h Wed Apr 11 09:08:00 2018
@@ -63,6 +63,7 @@ public:
     return TargetInfo::VoidPtrBuiltinVaList;
   }
 
+  bool isValidGCCRegisterName(StringRef Name) const override { return true; }
   ArrayRef<const char *> getGCCRegNames() const override { return None; }
 
   bool validateAsmConstraint(const char *&Name,




More information about the cfe-commits mailing list