[PATCH] D75298: [Clang][SVE] Parse builtin type string for scalable vectors

2020-03-15 Thread Sander de Smalen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5087ace65197: [Clang][SVE] Parse builtin type string for 
scalable vectors (authored by sdesmalen).

Changed prior to commit:
  https://reviews.llvm.org/D75298?vs=249966=250421#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75298/new/

https://reviews.llvm.org/D75298

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/AArch64SVEACLETypes.def
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/BuiltinsAArch64.def
  clang/include/clang/Basic/arm_sve.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/module.modulemap
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1.c
  clang/utils/TableGen/CMakeLists.txt
  clang/utils/TableGen/SveEmitter.cpp
  clang/utils/TableGen/TableGen.cpp
  clang/utils/TableGen/TableGenBackends.h

Index: clang/utils/TableGen/TableGenBackends.h
===
--- clang/utils/TableGen/TableGenBackends.h
+++ clang/utils/TableGen/TableGenBackends.h
@@ -91,6 +91,8 @@
 void EmitNeonSema2(llvm::RecordKeeper , llvm::raw_ostream );
 void EmitNeonTest2(llvm::RecordKeeper , llvm::raw_ostream );
 
+void EmitSveHeader(llvm::RecordKeeper , llvm::raw_ostream );
+
 void EmitMveHeader(llvm::RecordKeeper , llvm::raw_ostream );
 void EmitMveBuiltinDef(llvm::RecordKeeper , llvm::raw_ostream );
 void EmitMveBuiltinSema(llvm::RecordKeeper , llvm::raw_ostream );
Index: clang/utils/TableGen/TableGen.cpp
===
--- clang/utils/TableGen/TableGen.cpp
+++ clang/utils/TableGen/TableGen.cpp
@@ -70,6 +70,7 @@
   GenArmMveBuiltinSema,
   GenArmMveBuiltinCG,
   GenArmMveBuiltinAliases,
+  GenArmSveHeader,
   GenArmCdeHeader,
   GenArmCdeBuiltinDef,
   GenArmCdeBuiltinSema,
@@ -185,6 +186,8 @@
"Generate ARM NEON sema support for clang"),
 clEnumValN(GenArmNeonTest, "gen-arm-neon-test",
"Generate ARM NEON tests for clang"),
+clEnumValN(GenArmSveHeader, "gen-arm-sve-header",
+   "Generate arm_sve.h for clang"),
 clEnumValN(GenArmMveHeader, "gen-arm-mve-header",
"Generate arm_mve.h for clang"),
 clEnumValN(GenArmMveBuiltinDef, "gen-arm-mve-builtin-def",
@@ -366,6 +369,9 @@
   case GenArmMveBuiltinAliases:
 EmitMveBuiltinAliases(Records, OS);
 break;
+  case GenArmSveHeader:
+EmitSveHeader(Records, OS);
+break;
   case GenArmCdeHeader:
 EmitCdeHeader(Records, OS);
 break;
Index: clang/utils/TableGen/SveEmitter.cpp
===
--- /dev/null
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -0,0 +1,128 @@
+//===- SveEmitter.cpp - Generate arm_sve.h for use with clang -*- C++ -*-===//
+//
+//  Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+//  See https://llvm.org/LICENSE.txt for license information.
+//  SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This tablegen backend is responsible for emitting arm_sve.h, which includes
+// a declaration and definition of each function specified by the ARM C/C++
+// Language Extensions (ACLE).
+//
+// For details, visit:
+//  https://developer.arm.com/architectures/system-architectures/software-standards/acle
+//
+// Each SVE instruction is implemented in terms of 1 or more functions which
+// are suffixed with the element type of the input vectors.  Functions may be
+// implemented in terms of generic vector operations such as +, *, -, etc. or
+// by calling a __builtin_-prefixed function which will be handled by clang's
+// CodeGen library.
+//
+// See also the documentation in include/clang/Basic/arm_sve.td.
+//
+//===--===//
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/TableGen/Record.h"
+#include "llvm/TableGen/Error.h"
+#include 
+#include 
+#include 
+#include 
+
+using namespace llvm;
+
+//===--===//
+// SVEEmitter
+//===--===//
+
+namespace {
+
+class SVEEmitter {
+private:
+  RecordKeeper 
+
+public:
+  SVEEmitter(RecordKeeper ) : Records(R) {}
+
+  // run - Emit arm_sve.h
+  void run(raw_ostream );
+};
+
+} // end anonymous namespace
+
+
+//===--===//
+// SVEEmitter implementation

[PATCH] D75298: [Clang][SVE] Parse builtin type string for scalable vectors

2020-03-13 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/utils/TableGen/SveEmitter.cpp:86
+  OS << "#ifndef  __cplusplus\n";
+  OS << "#include \n";
+  OS << "#endif\n\n";

sdesmalen wrote:
> efriedma wrote:
> > I'd prefer to avoid depending on stdbool if it isn't necessary.
> Section 3.3 of the ACLE actually mentions this explicitly:
> ```arm_sve.h includes stdint.h and so provides standard types such as 
> uint32_t. When included from C code the header also includes stdbool.h and so 
> provides the bool type.```
Oh, sorry, I was accidentally looking at an old version of the ACLE spec.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75298/new/

https://reviews.llvm.org/D75298



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75298: [Clang][SVE] Parse builtin type string for scalable vectors

2020-03-13 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen marked 2 inline comments as done.
sdesmalen added inline comments.



Comment at: clang/utils/TableGen/SveEmitter.cpp:86
+  OS << "#ifndef  __cplusplus\n";
+  OS << "#include \n";
+  OS << "#endif\n\n";

efriedma wrote:
> I'd prefer to avoid depending on stdbool if it isn't necessary.
Section 3.3 of the ACLE actually mentions this explicitly:
```arm_sve.h includes stdint.h and so provides standard types such as uint32_t. 
When included from C code the header also includes stdbool.h and so provides 
the bool type.```



Comment at: clang/utils/TableGen/SveEmitter.cpp:92
+  OS << "typedef double float64_t;\n";
+  OS << "typedef bool bool_t;\n\n";
+

efriedma wrote:
> The ACLE documentation doesn't say anything about float16_t etc.?
In that same section, it says:
```In addition, the header file defines the following scalar data types:
  float16_t equivalent to __fp16```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75298/new/

https://reviews.llvm.org/D75298



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75298: [Clang][SVE] Parse builtin type string for scalable vectors

2020-03-12 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/utils/TableGen/SveEmitter.cpp:86
+  OS << "#ifndef  __cplusplus\n";
+  OS << "#include \n";
+  OS << "#endif\n\n";

I'd prefer to avoid depending on stdbool if it isn't necessary.



Comment at: clang/utils/TableGen/SveEmitter.cpp:92
+  OS << "typedef double float64_t;\n";
+  OS << "typedef bool bool_t;\n\n";
+

The ACLE documentation doesn't say anything about float16_t etc.?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75298/new/

https://reviews.llvm.org/D75298



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75298: [Clang][SVE] Parse builtin type string for scalable vectors

2020-03-12 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen updated this revision to Diff 249966.
sdesmalen added a comment.

- Updated license header for the arm_sve.h file to use the LLVM license instead 
of MIT.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75298/new/

https://reviews.llvm.org/D75298

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/AArch64SVEACLETypes.def
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/BuiltinsAArch64.def
  clang/include/clang/Basic/arm_sve.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/module.modulemap
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1.c
  clang/utils/TableGen/CMakeLists.txt
  clang/utils/TableGen/SveEmitter.cpp
  clang/utils/TableGen/TableGen.cpp
  clang/utils/TableGen/TableGenBackends.h

Index: clang/utils/TableGen/TableGenBackends.h
===
--- clang/utils/TableGen/TableGenBackends.h
+++ clang/utils/TableGen/TableGenBackends.h
@@ -91,6 +91,8 @@
 void EmitNeonSema2(llvm::RecordKeeper , llvm::raw_ostream );
 void EmitNeonTest2(llvm::RecordKeeper , llvm::raw_ostream );
 
+void EmitSveHeader(llvm::RecordKeeper , llvm::raw_ostream );
+
 void EmitMveHeader(llvm::RecordKeeper , llvm::raw_ostream );
 void EmitMveBuiltinDef(llvm::RecordKeeper , llvm::raw_ostream );
 void EmitMveBuiltinSema(llvm::RecordKeeper , llvm::raw_ostream );
Index: clang/utils/TableGen/TableGen.cpp
===
--- clang/utils/TableGen/TableGen.cpp
+++ clang/utils/TableGen/TableGen.cpp
@@ -70,6 +70,7 @@
   GenArmMveBuiltinSema,
   GenArmMveBuiltinCG,
   GenArmMveBuiltinAliases,
+  GenArmSveHeader,
   GenAttrDocs,
   GenDiagDocs,
   GenOptDocs,
@@ -180,6 +181,8 @@
"Generate ARM NEON sema support for clang"),
 clEnumValN(GenArmNeonTest, "gen-arm-neon-test",
"Generate ARM NEON tests for clang"),
+clEnumValN(GenArmSveHeader, "gen-arm-sve-header",
+   "Generate arm_sve.h for clang"),
 clEnumValN(GenArmMveHeader, "gen-arm-mve-header",
"Generate arm_mve.h for clang"),
 clEnumValN(GenArmMveBuiltinDef, "gen-arm-mve-builtin-def",
@@ -351,6 +354,9 @@
   case GenArmMveBuiltinAliases:
 EmitMveBuiltinAliases(Records, OS);
 break;
+  case GenArmSveHeader:
+EmitSveHeader(Records, OS);
+break;
   case GenAttrDocs:
 EmitClangAttrDocs(Records, OS);
 break;
Index: clang/utils/TableGen/SveEmitter.cpp
===
--- /dev/null
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -0,0 +1,128 @@
+//===- SveEmitter.cpp - Generate arm_sve.h for use with clang -*- C++ -*-===//
+//
+//  Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+//  See https://llvm.org/LICENSE.txt for license information.
+//  SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This tablegen backend is responsible for emitting arm_sve.h, which includes
+// a declaration and definition of each function specified by the ARM C/C++
+// Language Extensions (ACLE).
+//
+// For details, visit:
+//  https://developer.arm.com/architectures/system-architectures/software-standards/acle
+//
+// Each SVE instruction is implemented in terms of 1 or more functions which
+// are suffixed with the element type of the input vectors.  Functions may be
+// implemented in terms of generic vector operations such as +, *, -, etc. or
+// by calling a __builtin_-prefixed function which will be handled by clang's
+// CodeGen library.
+//
+// See also the documentation in include/clang/Basic/arm_sve.td.
+//
+//===--===//
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/TableGen/Record.h"
+#include "llvm/TableGen/Error.h"
+#include 
+#include 
+#include 
+#include 
+
+using namespace llvm;
+
+//===--===//
+// SVEEmitter
+//===--===//
+
+namespace {
+
+class SVEEmitter {
+private:
+  RecordKeeper 
+
+public:
+  SVEEmitter(RecordKeeper ) : Records(R) {}
+
+  // run - Emit arm_sve.h
+  void run(raw_ostream );
+};
+
+} // end anonymous namespace
+
+
+//===--===//
+// SVEEmitter implementation
+//===--===//
+
+void SVEEmitter::run(raw_ostream ) {
+  OS << "/*=== arm_sve.h - ARM SVE intrinsics "
+"---===\n"
+" 

[PATCH] D75298: [Clang][SVE] Parse builtin type string for scalable vectors

2020-03-12 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added a comment.

In D75298#1918489 , @efriedma wrote:

> Changing the way we expose the builtins isn't going to affect most of the 
> code related to the SVE intrinsics.  I'm fine sticking with a known working 
> approach, and trying to address that issue later.


Okay, thanks! In that case, are you happy with the patch as it is now?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75298/new/

https://reviews.llvm.org/D75298



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75298: [Clang][SVE] Parse builtin type string for scalable vectors

2020-03-11 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Changing the way we expose the builtins isn't going to affect most of the code 
related to the SVE intrinsics.  I'm fine sticking with a known working 
approach, and trying to address that issue later.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75298/new/

https://reviews.llvm.org/D75298



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75298: [Clang][SVE] Parse builtin type string for scalable vectors

2020-03-06 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added a subscriber: simon_tatham.
sdesmalen added a comment.
Herald added a subscriber: danielkiss.

In D75298#1904561 , @efriedma wrote:

> > Do you happen to know which method in Sema does this? I had a look before, 
> > but couldn't find where we could do something like this.
>
> See Sema::LazilyCreateBuiltin, and its caller Sema::LookupBuiltin.


Thanks for those pointers! I spoke with @simon_tatham today, who is also very 
interested in this in order to simplify the MVE header file.

I would like to suggest first trying to land the current implementation (using 
the header file with all the declarations), so that we can use the regression 
tests added as part of this effort to test a different implementation that does 
not rely as much on the header file. What do you think?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75298/new/

https://reviews.llvm.org/D75298



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75298: [Clang][SVE] Parse builtin type string for scalable vectors

2020-03-03 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

> This is because many of the builtins are protected by an architecture guard 
> like `#ifdef __ARM_FEATURE_SVE` or `#ifdef __ARM_FEATURE_SVE2`.

I think TARGET_HEADER_BUILTIN has support for requiring target features.  
Granted, we don't use it much at the moment, so there might be some non-obvious 
issue with this.

> Do you happen to know which method in Sema does this? I had a look before, 
> but couldn't find where we could do something like this.

See Sema::LazilyCreateBuiltin, and its caller Sema::LookupBuiltin.

> The reason for using #defines for the non-overloaded intrinsics was mainly 
> performance, the preprocessor was much faster than having to parse all 
> declarations, with the only downside being the redirection in the diagnostics.

Oh, that makes sense.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75298/new/

https://reviews.llvm.org/D75298



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75298: [Clang][SVE] Parse builtin type string for scalable vectors

2020-03-03 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added a comment.

In D75298#1901578 , @efriedma wrote:

> How are you planning to handle them with your current approach?


Each prototype will get a `arm_sve_alias` attribute that specifies which 
builtin it relates to. For example:

  __attribute__((__clang_arm_sve_alias(__builtin_sve_svld1_u8)))
  svuint8_t svld1(svbool_t, uint8_t const *);
  
  __attribute__((__clang_arm_sve_alias(__builtin_sve_svld1_u32)))
  svuint32_t svld1(svbool_t, uint32_t const *);

This is similar to how this was done for MVE.

> Anyway, that isn't really relevant to the question of why we need to `#define 
> svld1_u8(...) __builtin_sve_svld1_u8(__VA_ARGS__)`, as opposed to just making 
> svld1_u8 an intrinsic.

This is because many of the builtins are protected by an architecture guard 
like `#ifdef __ARM_FEATURE_SVE` or `#ifdef __ARM_FEATURE_SVE2`.

>> I wouldn't know of a way to create overloaded intrinsics without having to 
>> manually do the usual arithmetic conversions similar to how this is 
>> currently done for some overloaded builtins like SemaBuiltinAtomicOverloaded 
>> in SemaChecking.cpp.
> 
> The current Builtins.def infrastructure isn't really designed around it, but 
> it would be possible to add overloaded intrinsics.  Currently, when a builtin 
> name is looked up, we create one FunctionDecl.  But we could change it to 
> make/return a list of FunctionDecls, instead, and pass them to standard 
> overload resolution.

Do you happen to know which method in Sema does this? I had a look before, but 
couldn't find where we could do something like this.

> Sort of?  I mean, yes, loading a precompiled module is somewhat cheaper than 
> parsing C.  But it still isn't free, it doesn't really change the fact that 
> the indirection isn't doing anything useful, and we're still making 
> preprocessing/diagnostics more complicated by using defines.

The reason for using `#define`s for the non-overloaded intrinsics was mainly 
performance, the preprocessor was much faster than having to parse all 
declarations, with the only downside being the redirection in the diagnostics.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75298/new/

https://reviews.llvm.org/D75298



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75298: [Clang][SVE] Parse builtin type string for scalable vectors

2020-03-02 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

> The main reason we couldn't remove the header file is because of the 
> short-forms/overloaded intrinsics

How are you planning to handle them with your current approach?

Anyway, that isn't really relevant to the question of why we need to `#define 
svld1_u8(...) __builtin_sve_svld1_u8(__VA_ARGS__)`, as opposed to just making 
svld1_u8 an intrinsic.

> I wouldn't know of a way to create overloaded intrinsics without having to 
> manually do the usual arithmetic conversions similar to how this is currently 
> done for some overloaded builtins like SemaBuiltinAtomicOverloaded in 
> SemaChecking.cpp.

The current Builtins.def infrastructure isn't really designed around it, but it 
would be possible to add overloaded intrinsics.  Currently, when a builtin name 
is looked up, we create one FunctionDecl.  But we could change it to 
make/return a list of FunctionDecls, instead, and pass them to standard 
overload resolution.

> I also wonder if this problem isn't better solved using pre-compiled modules 
> at some point?

Sort of?  I mean, yes, loading a precompiled module is somewhat cheaper than 
parsing C.  But it still isn't free, it doesn't really change the fact that the 
indirection isn't doing anything useful, and we're still making 
preprocessing/diagnostics more complicated by using defines.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75298/new/

https://reviews.llvm.org/D75298



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75298: [Clang][SVE] Parse builtin type string for scalable vectors

2020-03-02 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen updated this revision to Diff 247659.
sdesmalen marked an inline comment as done.
sdesmalen added a comment.

- Added comment describing `q` for scalable vectors to Builtins.def
- Use `getKnownMinSize()` for calculating `LargestVectorWidth`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75298/new/

https://reviews.llvm.org/D75298

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/AArch64SVEACLETypes.def
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/BuiltinsAArch64.def
  clang/include/clang/Basic/arm_sve.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/module.modulemap
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1.c
  clang/utils/TableGen/CMakeLists.txt
  clang/utils/TableGen/SveEmitter.cpp
  clang/utils/TableGen/TableGen.cpp
  clang/utils/TableGen/TableGenBackends.h

Index: clang/utils/TableGen/TableGenBackends.h
===
--- clang/utils/TableGen/TableGenBackends.h
+++ clang/utils/TableGen/TableGenBackends.h
@@ -91,6 +91,8 @@
 void EmitNeonSema2(llvm::RecordKeeper , llvm::raw_ostream );
 void EmitNeonTest2(llvm::RecordKeeper , llvm::raw_ostream );
 
+void EmitSveHeader(llvm::RecordKeeper , llvm::raw_ostream );
+
 void EmitMveHeader(llvm::RecordKeeper , llvm::raw_ostream );
 void EmitMveBuiltinDef(llvm::RecordKeeper , llvm::raw_ostream );
 void EmitMveBuiltinSema(llvm::RecordKeeper , llvm::raw_ostream );
Index: clang/utils/TableGen/TableGen.cpp
===
--- clang/utils/TableGen/TableGen.cpp
+++ clang/utils/TableGen/TableGen.cpp
@@ -70,6 +70,7 @@
   GenArmMveBuiltinSema,
   GenArmMveBuiltinCG,
   GenArmMveBuiltinAliases,
+  GenArmSveHeader,
   GenAttrDocs,
   GenDiagDocs,
   GenOptDocs,
@@ -180,6 +181,8 @@
"Generate ARM NEON sema support for clang"),
 clEnumValN(GenArmNeonTest, "gen-arm-neon-test",
"Generate ARM NEON tests for clang"),
+clEnumValN(GenArmSveHeader, "gen-arm-sve-header",
+   "Generate arm_sve.h for clang"),
 clEnumValN(GenArmMveHeader, "gen-arm-mve-header",
"Generate arm_mve.h for clang"),
 clEnumValN(GenArmMveBuiltinDef, "gen-arm-mve-builtin-def",
@@ -351,6 +354,9 @@
   case GenArmMveBuiltinAliases:
 EmitMveBuiltinAliases(Records, OS);
 break;
+  case GenArmSveHeader:
+EmitSveHeader(Records, OS);
+break;
   case GenAttrDocs:
 EmitClangAttrDocs(Records, OS);
 break;
Index: clang/utils/TableGen/SveEmitter.cpp
===
--- /dev/null
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -0,0 +1,157 @@
+//===- SveEmitter.cpp - Generate arm_sve.h for use with clang -*- C++ -*-===//
+//
+//  Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+//  See https://llvm.org/LICENSE.txt for license information.
+//  SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This tablegen backend is responsible for emitting arm_sve.h, which includes
+// a declaration and definition of each function specified by the ARM C/C++
+// Language Extensions (ACLE).
+//
+// For details, visit:
+//  https://developer.arm.com/architectures/system-architectures/software-standards/acle
+//
+// Each SVE instruction is implemented in terms of 1 or more functions which
+// are suffixed with the element type of the input vectors.  Functions may be
+// implemented in terms of generic vector operations such as +, *, -, etc. or
+// by calling a __builtin_-prefixed function which will be handled by clang's
+// CodeGen library.
+//
+// See also the documentation in include/clang/Basic/arm_sve.td.
+//
+//===--===//
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/TableGen/Record.h"
+#include "llvm/TableGen/Error.h"
+#include 
+#include 
+#include 
+#include 
+
+using namespace llvm;
+
+//===--===//
+// SVEEmitter
+//===--===//
+
+namespace {
+
+class SVEEmitter {
+private:
+  RecordKeeper 
+
+public:
+  SVEEmitter(RecordKeeper ) : Records(R) {}
+
+  // run - Emit arm_sve.h
+  void run(raw_ostream );
+};
+
+} // end anonymous namespace
+
+
+//===--===//
+// SVEEmitter implementation
+//===--===//
+
+void SVEEmitter::run(raw_ostream ) {
+  OS << "/*=== arm_sve.h 

[PATCH] D75298: [Clang][SVE] Parse builtin type string for scalable vectors

2020-03-02 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added a comment.

In D75298#1898770 , @efriedma wrote:

> Can we avoid a gigantic, expensive to parse arm_sve.h somehow?  Given that 
> the compiler has to know the signatures for all these buitins anyway, can we 
> just make including arm_sve.h set some flag in the compiler to make it 
> recognize all the SVE intrinsics?  This is different from the way we handle 
> intrinsics on other targets, but SVE seems like a good opportunity to try a 
> new approach.


We actually tried this and already simplified the header file as much as 
possible. The header file now only contains preprocessor macros and function 
declarations, but no definitions, so should be relatively easy to parse. All 
code-gen itself is handled in CGBuiltin.
The main reason we couldn't remove the header file is because of the 
short-forms/overloaded intrinsics. I wouldn't know of a way to create 
overloaded intrinsics without having to manually do the usual arithmetic 
conversions similar to how this is currently done for some overloaded builtins 
like `SemaBuiltinAtomicOverloaded` in SemaChecking.cpp.

I also wonder if this problem isn't better solved using pre-compiled modules at 
some point?

> Please update the documentation comment at the top of Builtins.def .

Good spot, fixed it!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75298/new/

https://reviews.llvm.org/D75298



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75298: [Clang][SVE] Parse builtin type string for scalable vectors

2020-02-28 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Please update the documentation comment at the top of Builtins.def .

Can we avoid a gigantic, expensive to parse arm_sve.h somehow?  Given that the 
compiler has to know the signatures for all these buitins anyway, can we just 
make including arm_sve.h set some flag in the compiler to make it recognize all 
the SVE intrinsics?  This is different from the way we handle intrinsics on 
other targets, but SVE seems like a good opportunity to try a new approach.




Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:508
+  std::max((uint64_t)LargestVectorWidth,
+   VT->getPrimitiveSizeInBits().getFixedSize());
 

I'm not sure that we'll ever want to take advantage of min-legal-vector-width 
on targets with scalable vectors... but if we did, we'd probably want to use 
`getKnownMinSize()` here


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75298/new/

https://reviews.llvm.org/D75298



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75298: [Clang][SVE] Parse builtin type string for scalable vectors

2020-02-27 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen created this revision.
sdesmalen added reviewers: efriedma, rjmccall, rovka, rsandifo-arm.
Herald added subscribers: psnobl, rkruppe, kristof.beyls, tschuett, mgorny.
Herald added a reviewer: rengolin.
Herald added a project: clang.

This patch adds 'q' to mean 'scalable vector' in the builtin
type string, and for SVE will return the matching builtin
type as defined in the C/C++ language extensions for SVE.

This patch also adds some scaffolding to generate the arm_sve.h
header file, and some builtin definitions (+CodeGen) to be able
to implement some simple masked load intrinsics that use the
ACLE types, such as:

svint8_t test_svld1_s8(svbool_t pg, const int8_t *base) {

  return svld1_s8(pg, base);

}


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75298

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/AArch64SVEACLETypes.def
  clang/include/clang/Basic/BuiltinsAArch64.def
  clang/include/clang/Basic/arm_sve.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/module.modulemap
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1.c
  clang/utils/TableGen/CMakeLists.txt
  clang/utils/TableGen/SveEmitter.cpp
  clang/utils/TableGen/TableGen.cpp
  clang/utils/TableGen/TableGenBackends.h

Index: clang/utils/TableGen/TableGenBackends.h
===
--- clang/utils/TableGen/TableGenBackends.h
+++ clang/utils/TableGen/TableGenBackends.h
@@ -91,6 +91,8 @@
 void EmitNeonSema2(llvm::RecordKeeper , llvm::raw_ostream );
 void EmitNeonTest2(llvm::RecordKeeper , llvm::raw_ostream );
 
+void EmitSveHeader(llvm::RecordKeeper , llvm::raw_ostream );
+
 void EmitMveHeader(llvm::RecordKeeper , llvm::raw_ostream );
 void EmitMveBuiltinDef(llvm::RecordKeeper , llvm::raw_ostream );
 void EmitMveBuiltinSema(llvm::RecordKeeper , llvm::raw_ostream );
Index: clang/utils/TableGen/TableGen.cpp
===
--- clang/utils/TableGen/TableGen.cpp
+++ clang/utils/TableGen/TableGen.cpp
@@ -70,6 +70,7 @@
   GenArmMveBuiltinSema,
   GenArmMveBuiltinCG,
   GenArmMveBuiltinAliases,
+  GenArmSveHeader,
   GenAttrDocs,
   GenDiagDocs,
   GenOptDocs,
@@ -180,6 +181,8 @@
"Generate ARM NEON sema support for clang"),
 clEnumValN(GenArmNeonTest, "gen-arm-neon-test",
"Generate ARM NEON tests for clang"),
+clEnumValN(GenArmSveHeader, "gen-arm-sve-header",
+   "Generate arm_sve.h for clang"),
 clEnumValN(GenArmMveHeader, "gen-arm-mve-header",
"Generate arm_mve.h for clang"),
 clEnumValN(GenArmMveBuiltinDef, "gen-arm-mve-builtin-def",
@@ -351,6 +354,9 @@
   case GenArmMveBuiltinAliases:
 EmitMveBuiltinAliases(Records, OS);
 break;
+  case GenArmSveHeader:
+EmitSveHeader(Records, OS);
+break;
   case GenAttrDocs:
 EmitClangAttrDocs(Records, OS);
 break;
Index: clang/utils/TableGen/SveEmitter.cpp
===
--- /dev/null
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -0,0 +1,157 @@
+//===- SveEmitter.cpp - Generate arm_sve.h for use with clang -*- C++ -*-===//
+//
+//  Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+//  See https://llvm.org/LICENSE.txt for license information.
+//  SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This tablegen backend is responsible for emitting arm_sve.h, which includes
+// a declaration and definition of each function specified by the ARM C/C++
+// Language Extensions (ACLE).
+//
+// For details, visit:
+//  https://developer.arm.com/architectures/system-architectures/software-standards/acle
+//
+// Each SVE instruction is implemented in terms of 1 or more functions which
+// are suffixed with the element type of the input vectors.  Functions may be
+// implemented in terms of generic vector operations such as +, *, -, etc. or
+// by calling a __builtin_-prefixed function which will be handled by clang's
+// CodeGen library.
+//
+// See also the documentation in include/clang/Basic/arm_sve.td.
+//
+//===--===//
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/TableGen/Record.h"
+#include "llvm/TableGen/Error.h"
+#include 
+#include 
+#include 
+#include 
+
+using namespace llvm;
+
+//===--===//
+// SVEEmitter
+//===--===//
+
+namespace {
+
+class SVEEmitter {
+private:
+  RecordKeeper 
+
+public: