bpf: accept all asm register names
authorYonghong Song <yhs@fb.com>
Wed, 11 Apr 2018 16:08:00 +0000 (16:08 +0000)
committerYonghong Song <yhs@fb.com>
Wed, 11 Apr 2018 16:08:00 +0000 (16:08 +0000)
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@fb.com>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@329823 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/TargetInfo.h
lib/Basic/Targets/BPF.h

index 26f72a1814df9f0065c249b49af19e0de6aee0b4..8fbda351ff39bc71c41f56e1813d6a6540548bf2 100644 (file)
@@ -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.
   ///
index 36d2da4dbf308027d7c9e8577601be4a5b8e0cad..61a7ddae9c99f644454c0192e24c923a07f2ac87 100644 (file)
@@ -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,