[PATCH] D31417: [OpenMP] Add support for omp simd pragmas without runtime

2017-10-03 Thread Graham Hunter via Phabricator via cfe-commits
huntergr added a comment.

In https://reviews.llvm.org/D31417#886441, @hfinkel wrote:

> Is this still being worked on?


Hi, yes it is. Sorry for the delay in posting new changes but priorities 
shifted a bit and I had to work on something else for a while.

I do have a new version that's just about ready based on Alexey's idea. Simd 
constructs work, and non-simd constructs just pass the code straight through; 
combined constructs pose a bit of an issue, since they will have captured stmts 
from non-simd directives as well. Some additional work will be needed to handle 
that case. I'll post what I have after a bit of tidying for comments and 
suggestions; it's possible that the mixed case could be dealt with in another 
patch.


https://reviews.llvm.org/D31417



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


[PATCH] D53138: Scalable type size queries (clang)

2018-10-11 Thread Graham Hunter via Phabricator via cfe-commits
huntergr created this revision.

Initial changes for clang to use the scalable type size queries 
(https://reviews.llvm.org/D53137)

This isn't ready for inclusion yet, more discussion on the mailing list 
required.


https://reviews.llvm.org/D53138

Files:
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CGStmt.cpp
  lib/CodeGen/TargetInfo.cpp

Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -890,9 +890,10 @@
 /// IsX86_MMXType - Return true if this is an MMX type.
 bool IsX86_MMXType(llvm::Type *IRType) {
   // Return true if the type is an MMX type <2 x i32>, <4 x i16>, or <8 x i8>.
-  return IRType->isVectorTy() && IRType->getPrimitiveSizeInBits() == 64 &&
-cast(IRType)->getElementType()->isIntegerTy() &&
-IRType->getScalarSizeInBits() != 64;
+  auto Size = IRType->getScalableSizeInBits();
+  return IRType->isVectorTy() && Size.Scaled == 0 &&
+Size.Unscaled == 64 && IRType->getScalarSizeInBits() != 64 &&
+cast(IRType)->getElementType()->isIntegerTy();
 }
 
 static llvm::Type* X86AdjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
Index: lib/CodeGen/CGStmt.cpp
===
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -1985,7 +1985,7 @@
   // Update largest vector width for any vector types.
   if (auto *VT = dyn_cast(ResultRegTypes.back()))
 LargestVectorWidth = std::max(LargestVectorWidth,
-  VT->getPrimitiveSizeInBits());
+  VT->getScalableSizeInBits().Unscaled);
 } else {
   ArgTypes.push_back(Dest.getAddress().getType());
   Args.push_back(Dest.getPointer());
@@ -2010,7 +2010,7 @@
   // Update largest vector width for any vector types.
   if (auto *VT = dyn_cast(Arg->getType()))
 LargestVectorWidth = std::max(LargestVectorWidth,
-  VT->getPrimitiveSizeInBits());
+  VT->getScalableSizeInBits().Unscaled);
   if (Info.allowsRegister())
 InOutConstraints += llvm::utostr(i);
   else
@@ -2094,7 +2094,7 @@
 // Update largest vector width for any vector types.
 if (auto *VT = dyn_cast(Arg->getType()))
   LargestVectorWidth = std::max(LargestVectorWidth,
-VT->getPrimitiveSizeInBits());
+VT->getScalableSizeInBits().Unscaled);
 
 ArgTypes.push_back(Arg->getType());
 Args.push_back(Arg);
Index: lib/CodeGen/CGExprScalar.cpp
===
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -1079,8 +1079,8 @@
 
   if (isa(SrcTy) || isa(DstTy)) {
 // Allow bitcast from vector to integer/fp of the same size.
-unsigned SrcSize = SrcTy->getPrimitiveSizeInBits();
-unsigned DstSize = DstTy->getPrimitiveSizeInBits();
+auto SrcSize = SrcTy->getScalableSizeInBits();
+auto DstSize = DstTy->getScalableSizeInBits();
 if (SrcSize == DstSize)
   return Builder.CreateBitCast(Src, DstTy, "conv");
 
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -4790,8 +4790,8 @@
   for (Function::const_arg_iterator ai = F->arg_begin(), ae = F->arg_end();
ai != ae; ++ai, ++j) {
 llvm::Type *ArgTy = ai->getType();
-if (Ops[j]->getType()->getPrimitiveSizeInBits() ==
- ArgTy->getPrimitiveSizeInBits())
+if (Ops[j]->getType()->getScalableSizeInBits() ==
+ ArgTy->getScalableSizeInBits())
   continue;
 
 assert(ArgTy->isVectorTy() && !Ops[j]->getType()->isVectorTy());
@@ -4805,8 +4805,8 @@
 
   Value *Result = CGF.EmitNeonCall(F, Ops, s);
   llvm::Type *ResultType = CGF.ConvertType(E->getType());
-  if (ResultType->getPrimitiveSizeInBits() <
-  Result->getType()->getPrimitiveSizeInBits())
+  if (ResultType->getScalableSizeInBits() <
+  Result->getType()->getScalableSizeInBits())
 return CGF.Builder.CreateExtractElement(Result, C0);
 
   return CGF.Builder.CreateBitCast(Result, ResultType, s);
@@ -5336,7 +5336,7 @@
   case NEON::BI__builtin_neon_vdot_v:
   case NEON::BI__builtin_neon_vdotq_v: {
 llvm::Type *InputTy =
-llvm::VectorType::get(Int8Ty, Ty->getPrimitiveSizeInBits() / 8);
+llvm::VectorType::get(Int8Ty, Ty->getScalableSizeInBits().Unscaled / 8);
 llvm::Type *Tys[2] = { Ty, InputTy };
 Int = Usgn ? LLVMIntrinsic : AltLLVMIntrinsic;
 return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vdot");
@@ -6735,7 +6735,7 @@
   case NEON::BI__builtin_neon_vcvts_s32_f32:
   case NEON::BI__builtin_neon_vcvtd_s64_f64: {
 Ops.push_back(EmitScalarExpr(E->getArg(0)));
-bool Is64 = Ops[0]->getType()->getPrimitiveSizeInBits() == 64;
+b

[PATCH] D53138: Scalable type size queries (clang)

2018-10-24 Thread Graham Hunter via Phabricator via cfe-commits
huntergr abandoned this revision.
huntergr added a comment.

Abandoning this. At the devmeeting it was agreed that 'getPrimitiveSizeInBits' 
should continue to work as-is for fixed-length vectors and only behave 
differently for scalable vectors.


https://reviews.llvm.org/D53138



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


[PATCH] D31417: [OpenMP] Add support for omp simd pragmas without runtime

2019-04-02 Thread Graham Hunter via Phabricator via cfe-commits
huntergr abandoned this revision.
huntergr added a comment.

In D31417#1450587 , @xtian wrote:

> LGTM.  This provides a consistent behavior same as GCC and ICC w/ 
> -fopenmp-simd option. To answer, Kelvin's question. it is not directly tied 
> with "target".


Thanks for the review Xinmin, but as Alexey notes in the previous comment 
-fopenmp-simd support has already been committed -- I missed that comment 
earlier, but should have closed it then.

Apologies for the delay in implementing it Alexey, I just had too many other 
things to take care of at the time, and thanks for getting a better 
implementation in.


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

https://reviews.llvm.org/D31417



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


[PATCH] D53137: Scalable vector core instruction support + size queries

2019-09-23 Thread Graham Hunter via Phabricator via cfe-commits
huntergr updated this revision to Diff 221283.
huntergr added a comment.
Herald added subscribers: cfe-commits, haicheng, eraman.
Herald added a project: clang.

- Changed existing interface to return ScalableSize objects and added a 
(mostly) transparent conversion, as per Sander's suggestion.
- Removed new interfaces for DataLayout and Type.
- Fixed cases where the transparent conversion doesn't quite work (e.g. 
std::max/min, where the types must be the same)

I suspect 'ScalableSize' is the wrong term now; 'TypeSize' may be better. 
Thoughts?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53137

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  llvm/include/llvm/IR/DataLayout.h
  llvm/include/llvm/IR/InstrTypes.h
  llvm/include/llvm/IR/Type.h
  llvm/include/llvm/Support/ScalableSize.h
  llvm/lib/Analysis/InlineCost.cpp
  llvm/lib/CodeGen/Analysis.cpp
  llvm/lib/IR/DataLayout.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/IR/Type.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Transforms/Scalar/SROA.cpp
  llvm/test/Other/scalable-vectors-core-ir.ll
  llvm/unittests/IR/VectorTypesTest.cpp

Index: llvm/unittests/IR/VectorTypesTest.cpp
===
--- llvm/unittests/IR/VectorTypesTest.cpp
+++ llvm/unittests/IR/VectorTypesTest.cpp
@@ -6,6 +6,7 @@
 //
 //===--===//
 
+#include "llvm/IR/DataLayout.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/Support/ScalableSize.h"
@@ -161,4 +162,117 @@
   ASSERT_TRUE(EltCnt.Scalable);
 }
 
+TEST(VectorTypesTest, FixedLenComparisons) {
+  LLVMContext Ctx;
+  DataLayout DL("");
+
+  Type *Int32Ty = Type::getInt32Ty(Ctx);
+  Type *Int64Ty = Type::getInt64Ty(Ctx);
+
+  VectorType *V2Int32Ty = VectorType::get(Int32Ty, 2);
+  VectorType *V4Int32Ty = VectorType::get(Int32Ty, 4);
+
+  VectorType *V2Int64Ty = VectorType::get(Int64Ty, 2);
+
+  ScalableSize V2I32Len = V2Int32Ty->getPrimitiveSizeInBits();
+  EXPECT_EQ(V2I32Len.getKnownMinSize(), 64U);
+  EXPECT_FALSE(V2I32Len.isScalable());
+
+  EXPECT_LT(V2Int32Ty->getPrimitiveSizeInBits(),
+V4Int32Ty->getPrimitiveSizeInBits());
+  EXPECT_GT(V2Int64Ty->getPrimitiveSizeInBits(),
+V2Int32Ty->getPrimitiveSizeInBits());
+  EXPECT_EQ(V4Int32Ty->getPrimitiveSizeInBits(),
+V2Int64Ty->getPrimitiveSizeInBits());
+  EXPECT_NE(V2Int32Ty->getPrimitiveSizeInBits(),
+V2Int64Ty->getPrimitiveSizeInBits());
+
+  // Check that a fixed-only comparison works for fixed size vectors.
+  EXPECT_EQ(V2Int64Ty->getPrimitiveSizeInBits().getFixedSize(),
+V4Int32Ty->getPrimitiveSizeInBits().getFixedSize());
+
+  // Check the DataLayout interfaces.
+  EXPECT_EQ(DL.getTypeSizeInBits(V2Int64Ty),
+DL.getTypeSizeInBits(V4Int32Ty));
+  EXPECT_EQ(DL.getTypeSizeInBits(V2Int32Ty), 64U);
+  EXPECT_EQ(DL.getTypeSizeInBits(V2Int64Ty), 128U);
+  EXPECT_EQ(DL.getTypeStoreSize(V2Int64Ty),
+DL.getTypeStoreSize(V4Int32Ty));
+  EXPECT_NE(DL.getTypeStoreSizeInBits(V2Int32Ty),
+DL.getTypeStoreSizeInBits(V2Int64Ty));
+  EXPECT_EQ(DL.getTypeStoreSizeInBits(V2Int32Ty), 64U);
+  EXPECT_EQ(DL.getTypeStoreSize(V2Int64Ty), 16U);
+  EXPECT_EQ(DL.getTypeAllocSize(V4Int32Ty),
+DL.getTypeAllocSize(V2Int64Ty));
+  EXPECT_NE(DL.getTypeAllocSizeInBits(V2Int32Ty),
+DL.getTypeAllocSizeInBits(V2Int64Ty));
+  EXPECT_EQ(DL.getTypeAllocSizeInBits(V4Int32Ty), 128U);
+  EXPECT_EQ(DL.getTypeAllocSize(V2Int32Ty), 8U);
+  ASSERT_TRUE(DL.typeSizeEqualsStoreSize(V4Int32Ty));
+}
+
+TEST(VectorTypesTest, ScalableComparisons) {
+  LLVMContext Ctx;
+  DataLayout DL("");
+
+  Type *Int32Ty = Type::getInt32Ty(Ctx);
+  Type *Int64Ty = Type::getInt64Ty(Ctx);
+
+  VectorType *ScV2Int32Ty = VectorType::get(Int32Ty, {2, true});
+  VectorType *ScV4Int32Ty = VectorType::get(Int32Ty, {4, true});
+
+  VectorType *ScV2Int64Ty = VectorType::get(Int64Ty, {2, true});
+
+  ScalableSize ScV2I32Len = ScV2Int32Ty->getPrimitiveSizeInBits();
+  EXPECT_EQ(ScV2I32Len.getKnownMinSize(), 64U);
+  EXPECT_TRUE(ScV2I32Len.isScalable());
+
+  EXPECT_LT(ScV2Int32Ty->getPrimitiveSizeInBits(),
+ScV4Int32Ty->getPrimitiveSizeInBits());
+  EXPECT_GT(ScV2Int64Ty->getPrimitiveSizeInBits(),
+ScV2Int32Ty->getPrimitiveSizeInBits());
+  EXPECT_EQ(ScV4Int32Ty->getPrimitiveSizeInBits(),
+ScV2Int64Ty->getPrimitiveSizeInBits());
+  EXPECT_NE(ScV2Int32Ty->getPrimitiveSizeInBits(),
+ScV2Int64Ty->getPrimitiveSizeInBits());
+
+  // Check the DataLayout interfaces.
+  EXPECT_EQ(DL.getTypeSizeInBits(ScV2Int64Ty),
+DL.getTypeSizeInBits(ScV4Int32Ty));
+  EXPECT_EQ(DL.getTypeSizeInBits(ScV2Int32Ty).getKnownMinSize(), 64U);
+  EXPECT_EQ(DL.getTypeStoreSize(ScV2Int64Ty

[PATCH] D53137: Scalable vector core instruction support + size queries

2019-10-01 Thread Graham Hunter via Phabricator via cfe-commits
huntergr added inline comments.



Comment at: llvm/include/llvm/IR/DataLayout.h:454
+auto BaseSize = getTypeSizeInBits(Ty);
+return { (BaseSize.getKnownMinSize() + 7) / 8, BaseSize.isScalable() };
   }

rovka wrote:
> We already overload operator /, why not overload + as well so we don't have 
> to change the body of this method?
Scaling a size with * or / has a clear meaning to me, since it's independent of 
vscale; getting a vector that's half the size or four times larger just works.

Using + (or -) on the other hand doesn't seem to be as clear; I wasn't sure if 
a standalone int should be automatically treated as being the same as the 
TypeSize, or always considered Fixed. If we try for the former I can imagine 
quite a few bugs arising.

I could add a roundBitsToNearestByteSize method to move the arithmetic 
elsewhere if that would be acceptable?



Comment at: llvm/include/llvm/IR/DataLayout.h:656
+ 
getTypeSizeInBits(VTy->getElementType()).getKnownMinSize();
+return ScalableSize(MinBits, EltCnt.Scalable);
   }

rovka wrote:
> Maybe just return VTy->getElementCount() * 
> getTypeSizeInBits(VTy->getElementType()).getFixedSize().
There's no support for generating a TypeSize from an ElementCount in that way; 
is that an interface you feel is useful?

(I'll certainly change the `getKnownMinSize` to `getFixedSize` though, since 
we're just referring to a scalar)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53137



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


[PATCH] D53137: Scalable vector core instruction support + size queries

2019-10-01 Thread Graham Hunter via Phabricator via cfe-commits
huntergr updated this revision to Diff 222593.
huntergr added a comment.
Herald added a subscriber: dexonsmith.

- Renamed `ScalableSize` to `TypeSize`, including header name.
- added `alignTo` function that takes and returns a `TypeSize`. I wasn't sure 
if this should be added to MathExtras.h where the other variants live, so just 
kept it in TypeSize.h for now


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53137

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  llvm/include/llvm/ADT/DenseMapInfo.h
  llvm/include/llvm/IR/DataLayout.h
  llvm/include/llvm/IR/DerivedTypes.h
  llvm/include/llvm/IR/InstrTypes.h
  llvm/include/llvm/IR/Type.h
  llvm/include/llvm/Support/MachineValueType.h
  llvm/include/llvm/Support/ScalableSize.h
  llvm/include/llvm/Support/TypeSize.h
  llvm/lib/Analysis/InlineCost.cpp
  llvm/lib/CodeGen/Analysis.cpp
  llvm/lib/IR/DataLayout.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/IR/Type.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Transforms/Scalar/SROA.cpp
  llvm/test/Other/scalable-vectors-core-ir.ll
  llvm/unittests/CodeGen/ScalableVectorMVTsTest.cpp
  llvm/unittests/IR/VectorTypesTest.cpp

Index: llvm/unittests/IR/VectorTypesTest.cpp
===
--- llvm/unittests/IR/VectorTypesTest.cpp
+++ llvm/unittests/IR/VectorTypesTest.cpp
@@ -6,9 +6,10 @@
 //
 //===--===//
 
+#include "llvm/IR/DataLayout.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/LLVMContext.h"
-#include "llvm/Support/ScalableSize.h"
+#include "llvm/Support/TypeSize.h"
 #include "gtest/gtest.h"
 using namespace llvm;
 
@@ -161,4 +162,117 @@
   ASSERT_TRUE(EltCnt.Scalable);
 }
 
+TEST(VectorTypesTest, FixedLenComparisons) {
+  LLVMContext Ctx;
+  DataLayout DL("");
+
+  Type *Int32Ty = Type::getInt32Ty(Ctx);
+  Type *Int64Ty = Type::getInt64Ty(Ctx);
+
+  VectorType *V2Int32Ty = VectorType::get(Int32Ty, 2);
+  VectorType *V4Int32Ty = VectorType::get(Int32Ty, 4);
+
+  VectorType *V2Int64Ty = VectorType::get(Int64Ty, 2);
+
+  TypeSize V2I32Len = V2Int32Ty->getPrimitiveSizeInBits();
+  EXPECT_EQ(V2I32Len.getKnownMinSize(), 64U);
+  EXPECT_FALSE(V2I32Len.isScalable());
+
+  EXPECT_LT(V2Int32Ty->getPrimitiveSizeInBits(),
+V4Int32Ty->getPrimitiveSizeInBits());
+  EXPECT_GT(V2Int64Ty->getPrimitiveSizeInBits(),
+V2Int32Ty->getPrimitiveSizeInBits());
+  EXPECT_EQ(V4Int32Ty->getPrimitiveSizeInBits(),
+V2Int64Ty->getPrimitiveSizeInBits());
+  EXPECT_NE(V2Int32Ty->getPrimitiveSizeInBits(),
+V2Int64Ty->getPrimitiveSizeInBits());
+
+  // Check that a fixed-only comparison works for fixed size vectors.
+  EXPECT_EQ(V2Int64Ty->getPrimitiveSizeInBits().getFixedSize(),
+V4Int32Ty->getPrimitiveSizeInBits().getFixedSize());
+
+  // Check the DataLayout interfaces.
+  EXPECT_EQ(DL.getTypeSizeInBits(V2Int64Ty),
+DL.getTypeSizeInBits(V4Int32Ty));
+  EXPECT_EQ(DL.getTypeSizeInBits(V2Int32Ty), 64U);
+  EXPECT_EQ(DL.getTypeSizeInBits(V2Int64Ty), 128U);
+  EXPECT_EQ(DL.getTypeStoreSize(V2Int64Ty),
+DL.getTypeStoreSize(V4Int32Ty));
+  EXPECT_NE(DL.getTypeStoreSizeInBits(V2Int32Ty),
+DL.getTypeStoreSizeInBits(V2Int64Ty));
+  EXPECT_EQ(DL.getTypeStoreSizeInBits(V2Int32Ty), 64U);
+  EXPECT_EQ(DL.getTypeStoreSize(V2Int64Ty), 16U);
+  EXPECT_EQ(DL.getTypeAllocSize(V4Int32Ty),
+DL.getTypeAllocSize(V2Int64Ty));
+  EXPECT_NE(DL.getTypeAllocSizeInBits(V2Int32Ty),
+DL.getTypeAllocSizeInBits(V2Int64Ty));
+  EXPECT_EQ(DL.getTypeAllocSizeInBits(V4Int32Ty), 128U);
+  EXPECT_EQ(DL.getTypeAllocSize(V2Int32Ty), 8U);
+  ASSERT_TRUE(DL.typeSizeEqualsStoreSize(V4Int32Ty));
+}
+
+TEST(VectorTypesTest, ScalableComparisons) {
+  LLVMContext Ctx;
+  DataLayout DL("");
+
+  Type *Int32Ty = Type::getInt32Ty(Ctx);
+  Type *Int64Ty = Type::getInt64Ty(Ctx);
+
+  VectorType *ScV2Int32Ty = VectorType::get(Int32Ty, {2, true});
+  VectorType *ScV4Int32Ty = VectorType::get(Int32Ty, {4, true});
+
+  VectorType *ScV2Int64Ty = VectorType::get(Int64Ty, {2, true});
+
+  TypeSize ScV2I32Len = ScV2Int32Ty->getPrimitiveSizeInBits();
+  EXPECT_EQ(ScV2I32Len.getKnownMinSize(), 64U);
+  EXPECT_TRUE(ScV2I32Len.isScalable());
+
+  EXPECT_LT(ScV2Int32Ty->getPrimitiveSizeInBits(),
+ScV4Int32Ty->getPrimitiveSizeInBits());
+  EXPECT_GT(ScV2Int64Ty->getPrimitiveSizeInBits(),
+ScV2Int32Ty->getPrimitiveSizeInBits());
+  EXPECT_EQ(ScV4Int32Ty->getPrimitiveSizeInBits(),
+ScV2Int64Ty->getPrimitiveSizeInBits());
+  EXPECT_NE(ScV2Int32Ty->getPrimitiveSizeInBits(),
+ScV2Int64Ty->getPrimitiveSizeInBits());
+
+  // Check the DataLayout interfaces.
+  EXPECT_EQ(DL.getTypeSizeInBits(ScV2Int64Ty),
+DL.getTypeSizeInBits(ScV4Int32Ty));
+  EXPECT

[PATCH] D53137: Scalable vector core instruction support + size queries

2019-10-08 Thread Graham Hunter via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb302561b763a: [SVE][IR] Scalable Vector size queries and IR 
instruction support (authored by huntergr).

Changed prior to commit:
  https://reviews.llvm.org/D53137?vs=222593&id=223835#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53137

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  llvm/include/llvm/ADT/DenseMapInfo.h
  llvm/include/llvm/IR/DataLayout.h
  llvm/include/llvm/IR/DerivedTypes.h
  llvm/include/llvm/IR/InstrTypes.h
  llvm/include/llvm/IR/Type.h
  llvm/include/llvm/Support/MachineValueType.h
  llvm/include/llvm/Support/ScalableSize.h
  llvm/include/llvm/Support/TypeSize.h
  llvm/lib/Analysis/InlineCost.cpp
  llvm/lib/CodeGen/Analysis.cpp
  llvm/lib/IR/DataLayout.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/IR/Type.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Transforms/Scalar/SROA.cpp
  llvm/test/Other/scalable-vectors-core-ir.ll
  llvm/unittests/CodeGen/ScalableVectorMVTsTest.cpp
  llvm/unittests/IR/VectorTypesTest.cpp

Index: llvm/unittests/IR/VectorTypesTest.cpp
===
--- llvm/unittests/IR/VectorTypesTest.cpp
+++ llvm/unittests/IR/VectorTypesTest.cpp
@@ -6,9 +6,10 @@
 //
 //===--===//
 
+#include "llvm/IR/DataLayout.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/LLVMContext.h"
-#include "llvm/Support/ScalableSize.h"
+#include "llvm/Support/TypeSize.h"
 #include "gtest/gtest.h"
 using namespace llvm;
 
@@ -161,4 +162,117 @@
   ASSERT_TRUE(EltCnt.Scalable);
 }
 
+TEST(VectorTypesTest, FixedLenComparisons) {
+  LLVMContext Ctx;
+  DataLayout DL("");
+
+  Type *Int32Ty = Type::getInt32Ty(Ctx);
+  Type *Int64Ty = Type::getInt64Ty(Ctx);
+
+  VectorType *V2Int32Ty = VectorType::get(Int32Ty, 2);
+  VectorType *V4Int32Ty = VectorType::get(Int32Ty, 4);
+
+  VectorType *V2Int64Ty = VectorType::get(Int64Ty, 2);
+
+  TypeSize V2I32Len = V2Int32Ty->getPrimitiveSizeInBits();
+  EXPECT_EQ(V2I32Len.getKnownMinSize(), 64U);
+  EXPECT_FALSE(V2I32Len.isScalable());
+
+  EXPECT_LT(V2Int32Ty->getPrimitiveSizeInBits(),
+V4Int32Ty->getPrimitiveSizeInBits());
+  EXPECT_GT(V2Int64Ty->getPrimitiveSizeInBits(),
+V2Int32Ty->getPrimitiveSizeInBits());
+  EXPECT_EQ(V4Int32Ty->getPrimitiveSizeInBits(),
+V2Int64Ty->getPrimitiveSizeInBits());
+  EXPECT_NE(V2Int32Ty->getPrimitiveSizeInBits(),
+V2Int64Ty->getPrimitiveSizeInBits());
+
+  // Check that a fixed-only comparison works for fixed size vectors.
+  EXPECT_EQ(V2Int64Ty->getPrimitiveSizeInBits().getFixedSize(),
+V4Int32Ty->getPrimitiveSizeInBits().getFixedSize());
+
+  // Check the DataLayout interfaces.
+  EXPECT_EQ(DL.getTypeSizeInBits(V2Int64Ty),
+DL.getTypeSizeInBits(V4Int32Ty));
+  EXPECT_EQ(DL.getTypeSizeInBits(V2Int32Ty), 64U);
+  EXPECT_EQ(DL.getTypeSizeInBits(V2Int64Ty), 128U);
+  EXPECT_EQ(DL.getTypeStoreSize(V2Int64Ty),
+DL.getTypeStoreSize(V4Int32Ty));
+  EXPECT_NE(DL.getTypeStoreSizeInBits(V2Int32Ty),
+DL.getTypeStoreSizeInBits(V2Int64Ty));
+  EXPECT_EQ(DL.getTypeStoreSizeInBits(V2Int32Ty), 64U);
+  EXPECT_EQ(DL.getTypeStoreSize(V2Int64Ty), 16U);
+  EXPECT_EQ(DL.getTypeAllocSize(V4Int32Ty),
+DL.getTypeAllocSize(V2Int64Ty));
+  EXPECT_NE(DL.getTypeAllocSizeInBits(V2Int32Ty),
+DL.getTypeAllocSizeInBits(V2Int64Ty));
+  EXPECT_EQ(DL.getTypeAllocSizeInBits(V4Int32Ty), 128U);
+  EXPECT_EQ(DL.getTypeAllocSize(V2Int32Ty), 8U);
+  ASSERT_TRUE(DL.typeSizeEqualsStoreSize(V4Int32Ty));
+}
+
+TEST(VectorTypesTest, ScalableComparisons) {
+  LLVMContext Ctx;
+  DataLayout DL("");
+
+  Type *Int32Ty = Type::getInt32Ty(Ctx);
+  Type *Int64Ty = Type::getInt64Ty(Ctx);
+
+  VectorType *ScV2Int32Ty = VectorType::get(Int32Ty, {2, true});
+  VectorType *ScV4Int32Ty = VectorType::get(Int32Ty, {4, true});
+
+  VectorType *ScV2Int64Ty = VectorType::get(Int64Ty, {2, true});
+
+  TypeSize ScV2I32Len = ScV2Int32Ty->getPrimitiveSizeInBits();
+  EXPECT_EQ(ScV2I32Len.getKnownMinSize(), 64U);
+  EXPECT_TRUE(ScV2I32Len.isScalable());
+
+  EXPECT_LT(ScV2Int32Ty->getPrimitiveSizeInBits(),
+ScV4Int32Ty->getPrimitiveSizeInBits());
+  EXPECT_GT(ScV2Int64Ty->getPrimitiveSizeInBits(),
+ScV2Int32Ty->getPrimitiveSizeInBits());
+  EXPECT_EQ(ScV4Int32Ty->getPrimitiveSizeInBits(),
+ScV2Int64Ty->getPrimitiveSizeInBits());
+  EXPECT_NE(ScV2Int32Ty->getPrimitiveSizeInBits(),
+ScV2Int64Ty->getPrimitiveSizeInBits());
+
+  // Check the DataLayout interfaces.
+  EXPECT_EQ(DL.getTypeSizeInBits(ScV2Int64Ty),
+DL.getTypeSizeInBits(ScV4Int32Ty));
+  EXPECT_EQ(DL.getTypeSizeInBits(ScV2Int32Ty).getKnownMinSize(), 64U);
+  EXPECT_EQ(DL.getTy

[PATCH] D53137: Scalable vector core instruction support + size queries

2019-10-08 Thread Graham Hunter via Phabricator via cfe-commits
huntergr added a comment.

Hmm, forgot to add the last round of minor fixes before committing. Sorry about 
that, will push them as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53137



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


[PATCH] D103793: [Clang][OpenMP] Monotonic does not apply to SIMD

2021-06-07 Thread Graham Hunter via Phabricator via cfe-commits
huntergr created this revision.
huntergr added reviewers: ABataev, kkwli0.
Herald added subscribers: guansong, yaxunl.
huntergr requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

The codegen for simd constructs was affected by the presence (or
absence) of the 'monotonic' schedule modifier for worksharing
loops. The modifier is only intended to apply to the scheduling of
chunks for a thread, not iterations of a loop inside a chunk.

In addition, the monotonic modifier was applied to worksharing loops
by default if no schedule clause was present; the referenced part of
the OpenMP 4.5 spec in the code (section 2.7.1) only applies if the
user specified a schedule clause with a static kind but no modifier.
Without a user-specified schedule clause we should default to
nonmonotonic scheduling.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103793

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/distribute_simd_codegen.cpp
  clang/test/OpenMP/for_simd_codegen.cpp
  clang/test/OpenMP/parallel_for_simd_codegen.cpp
  clang/test/OpenMP/schedule_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_if_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_dist_schedule_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_schedule_codegen.cpp
  clang/test/OpenMP/teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/teams_distribute_simd_dist_schedule_codegen.cpp

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


[PATCH] D103793: [Clang][OpenMP] Monotonic does not apply to SIMD

2021-06-07 Thread Graham Hunter via Phabricator via cfe-commits
huntergr added a comment.

Apologies for not including more of the diff for context, but the test files 
are large enough that the full diff exceeds the maximum upload size.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103793

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


[PATCH] D103793: [Clang][OpenMP] Monotonic does not apply to SIMD

2021-06-17 Thread Graham Hunter via Phabricator via cfe-commits
huntergr added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103793

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


[PATCH] D103793: [Clang][OpenMP] Monotonic does not apply to SIMD

2021-06-22 Thread Graham Hunter via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc6a91ee6: [Clang][OpenMP] Monotonic does not apply to 
SIMD (authored by huntergr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103793

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/distribute_simd_codegen.cpp
  clang/test/OpenMP/for_simd_codegen.cpp
  clang/test/OpenMP/parallel_for_simd_codegen.cpp
  clang/test/OpenMP/schedule_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_if_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_dist_schedule_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_schedule_codegen.cpp
  clang/test/OpenMP/teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/teams_distribute_simd_dist_schedule_codegen.cpp

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


[PATCH] D75350: [OpenMP] Allow const parameters in declare simd linear clause

2020-02-28 Thread Graham Hunter via Phabricator via cfe-commits
huntergr created this revision.
huntergr added reviewers: ABataev, kkwli0.
Herald added a subscriber: guansong.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

Section 2.19.3 (List Item Privatization) of the OpenMP 5.0 standard does not 
apply to declarative directives, only to constructs. As such it's legal for a 
const-qualified function parameter to be marked as linear in a declare simd 
directive. I have confirmed this with the language committee.

Suggestions on a better approach are welcome -- I tried using DSAStack, but it 
didn't have a valid current directive when the restriction was checked.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75350

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/declare_simd_codegen.cpp


Index: clang/test/OpenMP/declare_simd_codegen.cpp
===
--- clang/test/OpenMP/declare_simd_codegen.cpp
+++ clang/test/OpenMP/declare_simd_codegen.cpp
@@ -114,6 +114,9 @@
 #pragma omp declare simd notinbranch
 double foo(double x) { return 0; }
 
+#pragma omp declare simd notinbranch linear(i)
+double constlinear(const int i);
+
 // CHECK-DAG: define {{.+}}@_Z5add_1Pf(
 // CHECK-DAG: define {{.+}}@_Z1hIiEvPT_S1_S1_S1_(
 // CHECK-DAG: define {{.+}}@_Z1hIfEvPT_S1_S1_S1_(
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -5269,7 +5269,8 @@
   E->containsUnexpandedParameterPack())
 continue;
   (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind,
-  PVD->getOriginalType());
+  PVD->getOriginalType(),
+  /*IsDeclareSimd=*/true);
   continue;
 }
   }
@@ -5289,7 +5290,7 @@
   E->isInstantiationDependent() || 
E->containsUnexpandedParameterPack())
 continue;
   (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind,
-  E->getType());
+  E->getType(), /*IsDeclareSimd=*/true);
   continue;
 }
 Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause)
@@ -14548,7 +14549,7 @@
 
 bool Sema::CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc,
  OpenMPLinearClauseKind LinKind,
- QualType Type) {
+ QualType Type, bool IsDeclareSimd) {
   const auto *VD = dyn_cast_or_null(D);
   // A variable must not have an incomplete type or a reference type.
   if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type))
@@ -14564,8 +14565,10 @@
   // OpenMP 5.0 [2.19.3, List Item Privatization, Restrictions]
   // A variable that is privatized must not have a const-qualified type
   // unless it is of class type with a mutable member. This restriction does
-  // not apply to the firstprivate clause.
-  if (rejectConstNotMutableType(*this, D, Type, OMPC_linear, ELoc))
+  // not apply to the firstprivate clause, nor to the linear clause on
+  // declarative directives (like declare simd).
+  if (!IsDeclareSimd &&
+  rejectConstNotMutableType(*this, D, Type, OMPC_linear, ELoc))
 return true;
 
   // A list item must be of integral or pointer type.
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -10173,7 +10173,8 @@
   /// Checks that the specified declaration matches requirements for the linear
   /// decls.
   bool CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc,
- OpenMPLinearClauseKind LinKind, QualType Type);
+ OpenMPLinearClauseKind LinKind, QualType Type,
+ bool IsDeclareSimd = false);
 
   /// Called on well-formed '\#pragma omp declare simd' after parsing of
   /// the associated method/function.


Index: clang/test/OpenMP/declare_simd_codegen.cpp
===
--- clang/test/OpenMP/declare_simd_codegen.cpp
+++ clang/test/OpenMP/declare_simd_codegen.cpp
@@ -114,6 +114,9 @@
 #pragma omp declare simd notinbranch
 double foo(double x) { return 0; }
 
+#pragma omp declare simd notinbranch linear(i)
+double constlinear(const int i);
+
 // CHECK-DAG: define {{.+}}@_Z5add_1Pf(
 // CHECK-DAG: define {{.+}}@_Z1hIiEvPT_S1_S1_S1_(
 // CHECK-DAG: define {{.+}}@_Z1hIfEvPT_S1_S1_S1_(
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -5269,7 +5269,8 @@
   E->containsUnexpandedParameterPack())
 continue;
   (void)Ch

[PATCH] D75350: [OpenMP] Allow const parameters in declare simd linear clause

2020-02-28 Thread Graham Hunter via Phabricator via cfe-commits
huntergr added inline comments.



Comment at: clang/test/OpenMP/declare_simd_codegen.cpp:118
+#pragma omp declare simd notinbranch linear(i)
+double constlinear(const int i);
+

fpetrogalli wrote:
> Shouldn't you check that the `_ZGV *` name is generated?
Ok, and I can take care of the formatting issue as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75350



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


[PATCH] D75350: [OpenMP] Allow const parameters in declare simd linear clause

2020-02-28 Thread Graham Hunter via Phabricator via cfe-commits
huntergr updated this revision to Diff 247294.
huntergr added a comment.

- Added a function body to the test so that it would generate symbols
- Added check lines to ensure the mangled name is present
- Reformatted the params of Sema::CheckOpenMPLinearDecl to comply with coding 
style.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75350

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/declare_simd_codegen.cpp


Index: clang/test/OpenMP/declare_simd_codegen.cpp
===
--- clang/test/OpenMP/declare_simd_codegen.cpp
+++ clang/test/OpenMP/declare_simd_codegen.cpp
@@ -114,6 +114,9 @@
 #pragma omp declare simd notinbranch
 double foo(double x) { return 0; }
 
+#pragma omp declare simd notinbranch linear(i)
+double constlinear(const int i) { return 0.0; }
+
 // CHECK-DAG: define {{.+}}@_Z5add_1Pf(
 // CHECK-DAG: define {{.+}}@_Z1hIiEvPT_S1_S1_S1_(
 // CHECK-DAG: define {{.+}}@_Z1hIfEvPT_S1_S1_S1_(
@@ -131,6 +134,7 @@
 // CHECK-DAG: define {{.+}}@_Z3fooPffi(
 // CHECK-DAG: define {{.+}}@_Z3food(
 // CHECK-DAG: declare {{.+}}@_Z5add_2Pf(
+// CHECK-DAG: declare {{.+}}@_Z11constlineari()
 
 // CHECK-DAG: "_ZGVbM4l8__Z5add_1Pf"
 // CHECK-DAG: "_ZGVbN4l8__Z5add_1Pf"
@@ -320,6 +324,11 @@
 // CHECK-DAG: "_ZGVdN4v__Z3food"
 // CHECK-DAG: "_ZGVeN8v__Z3food"
 
+// CHECK-DAG: "_ZGVbN2l__Z11constlineari"
+// CHECK-DAG: "_ZGVcN4l__Z11constlineari"
+// CHECK-DAG: "_ZGVdN4l__Z11constlineari"
+// CHECK-DAG: "_ZGVeN8l__Z11constlineari"
+
 // CHECK-NOT: "_ZGV{{.+}}__Z1fRA_i
 
 #endif
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -5269,7 +5269,8 @@
   E->containsUnexpandedParameterPack())
 continue;
   (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind,
-  PVD->getOriginalType());
+  PVD->getOriginalType(),
+  /*IsDeclareSimd=*/true);
   continue;
 }
   }
@@ -5289,7 +5290,7 @@
   E->isInstantiationDependent() || 
E->containsUnexpandedParameterPack())
 continue;
   (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind,
-  E->getType());
+  E->getType(), /*IsDeclareSimd=*/true);
   continue;
 }
 Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause)
@@ -14547,8 +14548,8 @@
 }
 
 bool Sema::CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc,
- OpenMPLinearClauseKind LinKind,
- QualType Type) {
+ OpenMPLinearClauseKind LinKind, QualType Type,
+ bool IsDeclareSimd) {
   const auto *VD = dyn_cast_or_null(D);
   // A variable must not have an incomplete type or a reference type.
   if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type))
@@ -14564,8 +14565,10 @@
   // OpenMP 5.0 [2.19.3, List Item Privatization, Restrictions]
   // A variable that is privatized must not have a const-qualified type
   // unless it is of class type with a mutable member. This restriction does
-  // not apply to the firstprivate clause.
-  if (rejectConstNotMutableType(*this, D, Type, OMPC_linear, ELoc))
+  // not apply to the firstprivate clause, nor to the linear clause on
+  // declarative directives (like declare simd).
+  if (!IsDeclareSimd &&
+  rejectConstNotMutableType(*this, D, Type, OMPC_linear, ELoc))
 return true;
 
   // A list item must be of integral or pointer type.
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -10173,7 +10173,8 @@
   /// Checks that the specified declaration matches requirements for the linear
   /// decls.
   bool CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc,
- OpenMPLinearClauseKind LinKind, QualType Type);
+ OpenMPLinearClauseKind LinKind, QualType Type,
+ bool IsDeclareSimd = false);
 
   /// Called on well-formed '\#pragma omp declare simd' after parsing of
   /// the associated method/function.


Index: clang/test/OpenMP/declare_simd_codegen.cpp
===
--- clang/test/OpenMP/declare_simd_codegen.cpp
+++ clang/test/OpenMP/declare_simd_codegen.cpp
@@ -114,6 +114,9 @@
 #pragma omp declare simd notinbranch
 double foo(double x) { return 0; }
 
+#pragma omp declare simd notinbranch linear(i)
+double constlinear(const int i) { return 0.0; }
+
 // CHECK-DAG: define {{.+}}@_

[PATCH] D75350: [OpenMP] Allow const parameters in declare simd linear clause

2020-03-02 Thread Graham Hunter via Phabricator via cfe-commits
huntergr updated this revision to Diff 247614.
huntergr added a comment.

- Removed the ) my editor helpfully added to the CHECK line
- Added a test to declare_simd_aarch64.c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75350

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/declare_simd_aarch64.c
  clang/test/OpenMP/declare_simd_codegen.cpp

Index: clang/test/OpenMP/declare_simd_codegen.cpp
===
--- clang/test/OpenMP/declare_simd_codegen.cpp
+++ clang/test/OpenMP/declare_simd_codegen.cpp
@@ -114,6 +114,9 @@
 #pragma omp declare simd notinbranch
 double foo(double x) { return 0; }
 
+#pragma omp declare simd notinbranch linear(i)
+double constlinear(const int i) { return 0.0; }
+
 // CHECK-DAG: define {{.+}}@_Z5add_1Pf(
 // CHECK-DAG: define {{.+}}@_Z1hIiEvPT_S1_S1_S1_(
 // CHECK-DAG: define {{.+}}@_Z1hIfEvPT_S1_S1_S1_(
@@ -131,6 +134,7 @@
 // CHECK-DAG: define {{.+}}@_Z3fooPffi(
 // CHECK-DAG: define {{.+}}@_Z3food(
 // CHECK-DAG: declare {{.+}}@_Z5add_2Pf(
+// CHECK-DAG: define {{.+}}@_Z11constlineari(
 
 // CHECK-DAG: "_ZGVbM4l8__Z5add_1Pf"
 // CHECK-DAG: "_ZGVbN4l8__Z5add_1Pf"
@@ -320,6 +324,11 @@
 // CHECK-DAG: "_ZGVdN4v__Z3food"
 // CHECK-DAG: "_ZGVeN8v__Z3food"
 
+// CHECK-DAG: "_ZGVbN2l__Z11constlineari"
+// CHECK-DAG: "_ZGVcN4l__Z11constlineari"
+// CHECK-DAG: "_ZGVdN4l__Z11constlineari"
+// CHECK-DAG: "_ZGVeN8l__Z11constlineari"
+
 // CHECK-NOT: "_ZGV{{.+}}__Z1fRA_i
 
 #endif
Index: clang/test/OpenMP/declare_simd_aarch64.c
===
--- clang/test/OpenMP/declare_simd_aarch64.c
+++ clang/test/OpenMP/declare_simd_aarch64.c
@@ -116,6 +116,15 @@
 // AARCH64: "_ZGVnM16uv_c02" "_ZGVnM8uv_c02"
 // AARCH64-NOT: c02
 
+//
+/* Linear with a constant parameter */
+//
+
+#pragma omp declare simd notinbranch linear(i)
+double constlinear(const int i);
+// AARCH64: "_ZGVnN2l_constlinear" "_ZGVnN4l_constlinear"
+// AARCH64-NOT: constlinear
+
 /*/
 /* sincos-like signature */
 /*/
@@ -170,6 +179,7 @@
   D = b03(D);
   *I = c01(D, *S);
   *D = c02(D, *S);
+  constlinear(*I);
   sincos(*D, D, D);
   SinCos(*D, D, D);
   foo2(I, *I);
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -5269,7 +5269,8 @@
   E->containsUnexpandedParameterPack())
 continue;
   (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind,
-  PVD->getOriginalType());
+  PVD->getOriginalType(),
+  /*IsDeclareSimd=*/true);
   continue;
 }
   }
@@ -5289,7 +5290,7 @@
   E->isInstantiationDependent() || E->containsUnexpandedParameterPack())
 continue;
   (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind,
-  E->getType());
+  E->getType(), /*IsDeclareSimd=*/true);
   continue;
 }
 Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause)
@@ -14547,8 +14548,8 @@
 }
 
 bool Sema::CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc,
- OpenMPLinearClauseKind LinKind,
- QualType Type) {
+ OpenMPLinearClauseKind LinKind, QualType Type,
+ bool IsDeclareSimd) {
   const auto *VD = dyn_cast_or_null(D);
   // A variable must not have an incomplete type or a reference type.
   if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type))
@@ -14564,8 +14565,10 @@
   // OpenMP 5.0 [2.19.3, List Item Privatization, Restrictions]
   // A variable that is privatized must not have a const-qualified type
   // unless it is of class type with a mutable member. This restriction does
-  // not apply to the firstprivate clause.
-  if (rejectConstNotMutableType(*this, D, Type, OMPC_linear, ELoc))
+  // not apply to the firstprivate clause, nor to the linear clause on
+  // declarative directives (like declare simd).
+  if (!IsDeclareSimd &&
+  rejectConstNotMutableType(*this, D, Type, OMPC_linear, ELoc))
 return true;
 
   // A list item must be of integral or pointer type.
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -10173,7 +10173,8 @@
   /// Checks that the specified declaration matches requirements for the linear
   /// decls.
   bool CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc,
-   

[PATCH] D75350: [OpenMP] Allow const parameters in declare simd linear clause

2020-03-02 Thread Graham Hunter via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGad497658d25a: [OpenMP] Allow const parameters in declare 
simd linear clause (authored by huntergr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75350

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/declare_simd_aarch64.c
  clang/test/OpenMP/declare_simd_codegen.cpp

Index: clang/test/OpenMP/declare_simd_codegen.cpp
===
--- clang/test/OpenMP/declare_simd_codegen.cpp
+++ clang/test/OpenMP/declare_simd_codegen.cpp
@@ -114,6 +114,9 @@
 #pragma omp declare simd notinbranch
 double foo(double x) { return 0; }
 
+#pragma omp declare simd notinbranch linear(i)
+double constlinear(const int i) { return 0.0; }
+
 // CHECK-DAG: define {{.+}}@_Z5add_1Pf(
 // CHECK-DAG: define {{.+}}@_Z1hIiEvPT_S1_S1_S1_(
 // CHECK-DAG: define {{.+}}@_Z1hIfEvPT_S1_S1_S1_(
@@ -131,6 +134,7 @@
 // CHECK-DAG: define {{.+}}@_Z3fooPffi(
 // CHECK-DAG: define {{.+}}@_Z3food(
 // CHECK-DAG: declare {{.+}}@_Z5add_2Pf(
+// CHECK-DAG: define {{.+}}@_Z11constlineari(
 
 // CHECK-DAG: "_ZGVbM4l8__Z5add_1Pf"
 // CHECK-DAG: "_ZGVbN4l8__Z5add_1Pf"
@@ -320,6 +324,11 @@
 // CHECK-DAG: "_ZGVdN4v__Z3food"
 // CHECK-DAG: "_ZGVeN8v__Z3food"
 
+// CHECK-DAG: "_ZGVbN2l__Z11constlineari"
+// CHECK-DAG: "_ZGVcN4l__Z11constlineari"
+// CHECK-DAG: "_ZGVdN4l__Z11constlineari"
+// CHECK-DAG: "_ZGVeN8l__Z11constlineari"
+
 // CHECK-NOT: "_ZGV{{.+}}__Z1fRA_i
 
 #endif
Index: clang/test/OpenMP/declare_simd_aarch64.c
===
--- clang/test/OpenMP/declare_simd_aarch64.c
+++ clang/test/OpenMP/declare_simd_aarch64.c
@@ -116,6 +116,15 @@
 // AARCH64: "_ZGVnM16uv_c02" "_ZGVnM8uv_c02"
 // AARCH64-NOT: c02
 
+//
+/* Linear with a constant parameter */
+//
+
+#pragma omp declare simd notinbranch linear(i)
+double constlinear(const int i);
+// AARCH64: "_ZGVnN2l_constlinear" "_ZGVnN4l_constlinear"
+// AARCH64-NOT: constlinear
+
 /*/
 /* sincos-like signature */
 /*/
@@ -170,6 +179,7 @@
   D = b03(D);
   *I = c01(D, *S);
   *D = c02(D, *S);
+  constlinear(*I);
   sincos(*D, D, D);
   SinCos(*D, D, D);
   foo2(I, *I);
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -5269,7 +5269,8 @@
   E->containsUnexpandedParameterPack())
 continue;
   (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind,
-  PVD->getOriginalType());
+  PVD->getOriginalType(),
+  /*IsDeclareSimd=*/true);
   continue;
 }
   }
@@ -5289,7 +5290,7 @@
   E->isInstantiationDependent() || E->containsUnexpandedParameterPack())
 continue;
   (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind,
-  E->getType());
+  E->getType(), /*IsDeclareSimd=*/true);
   continue;
 }
 Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause)
@@ -14547,8 +14548,8 @@
 }
 
 bool Sema::CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc,
- OpenMPLinearClauseKind LinKind,
- QualType Type) {
+ OpenMPLinearClauseKind LinKind, QualType Type,
+ bool IsDeclareSimd) {
   const auto *VD = dyn_cast_or_null(D);
   // A variable must not have an incomplete type or a reference type.
   if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type))
@@ -14564,8 +14565,10 @@
   // OpenMP 5.0 [2.19.3, List Item Privatization, Restrictions]
   // A variable that is privatized must not have a const-qualified type
   // unless it is of class type with a mutable member. This restriction does
-  // not apply to the firstprivate clause.
-  if (rejectConstNotMutableType(*this, D, Type, OMPC_linear, ELoc))
+  // not apply to the firstprivate clause, nor to the linear clause on
+  // declarative directives (like declare simd).
+  if (!IsDeclareSimd &&
+  rejectConstNotMutableType(*this, D, Type, OMPC_linear, ELoc))
 return true;
 
   // A list item must be of integral or pointer type.
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -10173,7 +10173,8 @@
   /// Checks that the specified declaration matches requirements for the linear
   /// decls.
   bool CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation 

[PATCH] D31417: [OpenMP] Add support for omp simd pragmas without runtime

2017-03-28 Thread Graham Hunter via Phabricator via cfe-commits
huntergr created this revision.
Herald added a subscriber: rengolin.

Adds a new flag ('-fopenmp-simd') to clang which enables processing
of 'simd' and 'declare simd' pragmas without supporting the rest
of OpenMP.

The pragma handler will filter out directives and clauses which
aren't related to simd, and the driver will not add lib(g)omp to
the list of libraries to link.

Documentation updated to describe the new flag.


https://reviews.llvm.org/D31417

Files:
  docs/ClangCommandLineReference.rst
  docs/UsersManual.rst
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParsePragma.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOpenMP.cpp
  test/OpenMP/linking.c
  test/OpenMP/simd_only.c

Index: test/OpenMP/simd_only.c
===
--- /dev/null
+++ test/OpenMP/simd_only.c
@@ -0,0 +1,157 @@
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c -triple aarch64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK-LABEL: @simd_plain
+// CHECK-LABEL: omp.inner.for.body:
+// CHECK: load float, float* %arrayidx{{.*}} !llvm.mem.parallel_loop_access
+// CHECK: load float, float* %arrayidx{{.*}} !llvm.mem.parallel_loop_access
+// CHECK: store float %{{.*}}, float* %arrayidx{{.*}} !llvm.mem.parallel_loop_access
+// CHECK: ret void
+void simd_plain(float *a, float *b, float *c, int N) {
+  #pragma omp simd
+  for (int i = 0; i < N; i += 2)
+a[i] = b[i] * c[i];
+}
+
+// CHECK-LABEL: @simd_safelen_clause
+// CHECK-NOT: !llvm.mem.parallel_loop_access
+// CHECK-LABEL: omp.inner.for.inc:
+// CHECK: br label %omp.inner.for.cond, !llvm.loop
+// CHECK: ret void
+void simd_safelen_clause(float *a, float *b, float *c, int N) {
+  #pragma omp simd safelen(4)
+  for (int i = 0; i < N; i += 2)
+a[i] = b[i] * c[i];
+}
+
+extern long long initial_val();
+
+// CHECK-LABEL: @simd_simdlen_and_linear_clause
+// CHECK: omp.inner.for.body:
+// CHECK: !llvm.mem.parallel_loop_access
+// CHECK: ret void
+void simd_simdlen_and_linear_clause(float *a, float *b, float *c, int N) {
+  long long lv = initial_val();
+  #pragma omp simd simdlen(2) linear(lv: 4)
+  for (int i = 0; i < N; ++i) {
+a[lv] = b[lv] * c[lv];
+lv += 4;
+  }
+}
+
+extern float gfloat;
+
+// CHECK-LABEL: @simd_aligned_and_private_clause
+// CHECK-LABEL: entry:
+// CHECK: %gfloat = alloca float, align 4
+// CHECK: store float 1.00e+00, float* @gfloat, align 4
+// CHECK-LABEL: omp.inner.for.body:
+// CHECK-NOT: @gfloat
+// CHECK: load{{.*}}!llvm.mem.parallel_loop_access
+// CHECK: store float {{.*}}, float* %gfloat, align 4, !llvm.mem.parallel_loop_access
+// CHECK: %[[FADD:add[0-9]+]] = fadd float %{{[0-9]+}}, 2.00e+00
+// CHECK: store float %[[FADD]], float* {{.*}}, align 4, !llvm.mem.parallel_loop_access
+// CHECK: ret void
+void simd_aligned_and_private_clause(float *a, float *b, float *c, int N) {
+  gfloat = 1.0f;
+  #pragma omp simd aligned(a:4) private(gfloat)
+  for (int i = 0; i < N; i += 2) {
+gfloat = b[i] * c[i];
+a[i] = gfloat + 2.0f;
+  }
+}
+
+// CHECK-LABEL: @simd_lastprivate_and_reduction_clause
+// CHECK-LABEL: entry:
+// CHECK: %[[SUMVAR:sum[0-9]+]] = alloca float, align 4
+// CHECK: store float 0.00e+00, float* %[[SUMVAR]], align 4
+// CHECK-LABEL: omp.inner.for.body
+// CHECK: %[[LOAD:[0-9]+]] = load float, float* %[[SUMVAR]], align 4, !llvm.mem.parallel_loop_access
+// CHECK: %[[FADD:add[0-9]+]] = fadd float %[[LOAD]], %mul{{.*}}
+// CHECK: store float %[[FADD]], float* %[[SUMVAR]], align 4, !llvm.mem.parallel_loop_access
+// CHECK: store i32{{.*}}, i32* %[[IDXVAR:idx[0-9]+]]
+// CHECK-LABEL: omp.inner.for.end:
+// CHECK-DAG: %[[TMP1:[0-9]+]] = load i32, i32* %[[IDXVAR]], align 4
+// CHECK-DAG: store i32 %[[TMP1]], i32* %idx, align 4
+// CHECK-DAG: %[[INITVAL:[0-9]+]] = load float, float* %sum, align 4
+// CHECK-DAG: %[[TMP2:[0-9]+]] = load float, float* %[[SUMVAR]], align 4
+// CHECK-DAG: %[[SUMMED:add[0-9]+]] = fadd float %[[INITVAL]], %[[TMP2]]
+// CHECK-DAG: store float %[[SUMMED]], float* %sum, align 4
+// CHECK-LABEL: simd.if.end:
+// CHECK: %[[OUTVAL:[0-9]+]] = load float, float* %sum, align 4
+// CHECK: %[[OUTADDR:[0-9]+]] = load float*, float** %a.addr, align 8
+// CHECK: store float %[[OUTVAL]], float* %[[OUTADDR]], align 4
+// CHECK: %[[RETIDX:[0-9]+]] = load i32, i32* %idx, align 4
+// CHECK: ret i32 %[[RETIDX]]
+int simd_lastprivate_and_reduction_clause(float *a, float *b, float *c, int N) {
+  float sum = 0.0f;
+  int idx;
+  #pragma omp simd lastprivate(idx) reduction(+:sum)
+  for (int i = 0; i < N; ++i) {
+sum += b[i] * c[i];
+idx = i * 2;
+  }
+
+  *a = sum;
+  return idx;
+}
+
+// CHECK-LABEL: @simd_collapse_clause
+// CHECK: omp.inner.for.body:
+// CHECK-NOT: for.body

[PATCH] D31417: [OpenMP] Add support for omp simd pragmas without runtime

2017-03-28 Thread Graham Hunter via Phabricator via cfe-commits
huntergr added a comment.

In https://reviews.llvm.org/D31417#712008, @fpetrogalli wrote:

> Hi Graham,
>
> thank you for working on this. I understand that you are gonna take care of 
> the CodeGen side of things for the new `-fopenmp-simd` option in a separate 
> patch?


CodeGen for 'simd' pragmas works fine with this patch. 'declare simd' doesn't 
quite work yet, but yes, I was planning to do that in a separate patch.

> I am asking because I expect that the tests in `test/OpenMP/declare_simd_*` 
> will give the same results when invoking clang with the new flag instead of 
> `-fopenmp`.

So 'isAllowedClauseForDirective' needs to be updated; at present, it just bails 
out immediately if the directive kind passed in is OMPD_declare_simd. The 
clauses for a 'declare simd' are handled a little differently in 
ParseOpenMP.cpp, and I need to look into why.

I mainly wanted feedback on the approach at this point, since the patch is 
pretty small and changes won't be too cumbersome.


https://reviews.llvm.org/D31417



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


[PATCH] D31417: [OpenMP] Add support for omp simd pragmas without runtime

2017-03-29 Thread Graham Hunter via Phabricator via cfe-commits
huntergr added a comment.

Hi Renato,

In https://reviews.llvm.org/D31417#713162, @rengolin wrote:

> I don't know much about Clang's machinery, but would it be possible to have 
> `-fopenmp-simd` generate the same handler, but with restrictions? I fear this 
> slight duplication could get considerably worse as we support more and more 
> "non-RT" OMP pragmas.


Sure, I can combine the handlers and switch behaviour within that if that's 
preferable. The other alternative I thought of was to perform the filtering in 
ParseOpenMP.cpp instead, but I need to figure out how to delete or skip tokens 
there without cluttering up the rest of the OpenMP parsing.

I'll come up with a new version with the combined handler tomorrow.

> Alternatively, if this is for testing purposes, we have another pragma which 
> does exactly the same thing as `omp simd`, which are the Clang vectorizer 
> pragmas (http://llvm.org/docs/Vectorizers.html#pragma-loop-hint-directives).

This feature comes from user requests, and basically matches the functionality 
of other compilers (e.g. gcc).

Thanks for the comments.

-Graham


https://reviews.llvm.org/D31417



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


[PATCH] D31417: [OpenMP] Add support for omp simd pragmas without runtime

2017-04-03 Thread Graham Hunter via Phabricator via cfe-commits
huntergr updated this revision to Diff 93841.
huntergr added a reviewer: kkwli0.
huntergr added a comment.

Changed to transform combined constructs to simd in ParseOpenMP.cpp instead of 
creating a new pragma handler. This also made it easier to add support for 
'declare simd': only needed the addition of a check for the option when code 
generating functions to enable it, so I've added a RUN line to test it in the 
'declare simd' codegen tests.


https://reviews.llvm.org/D31417

Files:
  docs/ClangCommandLineReference.rst
  docs/UsersManual.rst
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParseOpenMP.cpp
  lib/Parse/ParsePragma.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOpenMP.cpp
  test/OpenMP/declare_simd_codegen.cpp
  test/OpenMP/linking.c
  test/OpenMP/simd_only.c

Index: test/OpenMP/simd_only.c
===
--- /dev/null
+++ test/OpenMP/simd_only.c
@@ -0,0 +1,157 @@
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c -triple aarch64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK-LABEL: @simd_plain
+// CHECK-LABEL: omp.inner.for.body:
+// CHECK: load float, float* %arrayidx{{.*}} !llvm.mem.parallel_loop_access
+// CHECK: load float, float* %arrayidx{{.*}} !llvm.mem.parallel_loop_access
+// CHECK: store float %{{.*}}, float* %arrayidx{{.*}} !llvm.mem.parallel_loop_access
+// CHECK: ret void
+void simd_plain(float *a, float *b, float *c, int N) {
+  #pragma omp simd
+  for (int i = 0; i < N; i += 2)
+a[i] = b[i] * c[i];
+}
+
+// CHECK-LABEL: @simd_safelen_clause
+// CHECK-NOT: !llvm.mem.parallel_loop_access
+// CHECK-LABEL: omp.inner.for.inc:
+// CHECK: br label %omp.inner.for.cond, !llvm.loop
+// CHECK: ret void
+void simd_safelen_clause(float *a, float *b, float *c, int N) {
+  #pragma omp simd safelen(4)
+  for (int i = 0; i < N; i += 2)
+a[i] = b[i] * c[i];
+}
+
+extern long long initial_val();
+
+// CHECK-LABEL: @simd_simdlen_and_linear_clause
+// CHECK: omp.inner.for.body:
+// CHECK: !llvm.mem.parallel_loop_access
+// CHECK: ret void
+void simd_simdlen_and_linear_clause(float *a, float *b, float *c, int N) {
+  long long lv = initial_val();
+  #pragma omp simd simdlen(2) linear(lv: 4)
+  for (int i = 0; i < N; ++i) {
+a[lv] = b[lv] * c[lv];
+lv += 4;
+  }
+}
+
+extern float gfloat;
+
+// CHECK-LABEL: @simd_aligned_and_private_clause
+// CHECK-LABEL: entry:
+// CHECK: %gfloat = alloca float, align 4
+// CHECK: store float 1.00e+00, float* @gfloat, align 4
+// CHECK-LABEL: omp.inner.for.body:
+// CHECK-NOT: @gfloat
+// CHECK: load{{.*}}!llvm.mem.parallel_loop_access
+// CHECK: store float {{.*}}, float* %gfloat, align 4, !llvm.mem.parallel_loop_access
+// CHECK: %[[FADD:add[0-9]+]] = fadd float %{{[0-9]+}}, 2.00e+00
+// CHECK: store float %[[FADD]], float* {{.*}}, align 4, !llvm.mem.parallel_loop_access
+// CHECK: ret void
+void simd_aligned_and_private_clause(float *a, float *b, float *c, int N) {
+  gfloat = 1.0f;
+  #pragma omp simd aligned(a:4) private(gfloat)
+  for (int i = 0; i < N; i += 2) {
+gfloat = b[i] * c[i];
+a[i] = gfloat + 2.0f;
+  }
+}
+
+// CHECK-LABEL: @simd_lastprivate_and_reduction_clause
+// CHECK-LABEL: entry:
+// CHECK: %[[SUMVAR:sum[0-9]+]] = alloca float, align 4
+// CHECK: store float 0.00e+00, float* %[[SUMVAR]], align 4
+// CHECK-LABEL: omp.inner.for.body
+// CHECK: %[[LOAD:[0-9]+]] = load float, float* %[[SUMVAR]], align 4, !llvm.mem.parallel_loop_access
+// CHECK: %[[FADD:add[0-9]+]] = fadd float %[[LOAD]], %mul{{.*}}
+// CHECK: store float %[[FADD]], float* %[[SUMVAR]], align 4, !llvm.mem.parallel_loop_access
+// CHECK: store i32{{.*}}, i32* %[[IDXVAR:idx[0-9]+]]
+// CHECK-LABEL: omp.inner.for.end:
+// CHECK-DAG: %[[TMP1:[0-9]+]] = load i32, i32* %[[IDXVAR]], align 4
+// CHECK-DAG: store i32 %[[TMP1]], i32* %idx, align 4
+// CHECK-DAG: %[[INITVAL:[0-9]+]] = load float, float* %sum, align 4
+// CHECK-DAG: %[[TMP2:[0-9]+]] = load float, float* %[[SUMVAR]], align 4
+// CHECK-DAG: %[[SUMMED:add[0-9]+]] = fadd float %[[INITVAL]], %[[TMP2]]
+// CHECK-DAG: store float %[[SUMMED]], float* %sum, align 4
+// CHECK-LABEL: simd.if.end:
+// CHECK: %[[OUTVAL:[0-9]+]] = load float, float* %sum, align 4
+// CHECK: %[[OUTADDR:[0-9]+]] = load float*, float** %a.addr, align 8
+// CHECK: store float %[[OUTVAL]], float* %[[OUTADDR]], align 4
+// CHECK: %[[RETIDX:[0-9]+]] = load i32, i32* %idx, align 4
+// CHECK: ret i32 %[[RETIDX]]
+int simd_lastprivate_and_reduction_clause(float *a, float *b, float *c, int N) {
+  float sum = 0.0f;
+  int idx;
+  #pragma omp simd lastprivate(idx) reduction(+:sum)
+  for (int i = 0; i < N; ++i) {
+sum += b[i] * c[i];
+idx = i * 2;
+  }

[PATCH] D31417: [OpenMP] Add support for omp simd pragmas without runtime

2017-04-03 Thread Graham Hunter via Phabricator via cfe-commits
huntergr added inline comments.



Comment at: lib/Parse/ParseOpenMP.cpp:174
+  case OMPD_target_teams_distribute_simd:
+DKind = OMPD_simd;
+break;

rengolin wrote:
> I'd like @ABataev to confirm this is the right semantics.
Yes, would be good. I don't think there's a formal spec for this feature, but 
it's possible that directives intended for a different target than the cpu 
shouldn't apply with this flag.



Comment at: lib/Parse/ParseOpenMP.cpp:1047
+// as the filter function will have switched the kind.
+if (!getLangOpts().OpenMPSimd)
+  Diag(Tok, diag::err_omp_unknown_directive);

rengolin wrote:
> What if it's really unknown, even to `-fopenmp-simd`?
I did wonder about handling this case; I defaulted to ignoring it, since we are 
already filtering out other non-simd constructs.

If we do want to catch it, then I can think of two options: creating the 
diagnostic right before the filter switch (possibly messy), or adding a new 
enum value of OMPD_non_simd_construct (or a similar name) to represent 
constructs we recognize but don't want to handle and differentiate against a 
true unknown. I think the latter would be preferable.


https://reviews.llvm.org/D31417



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


[PATCH] D31417: [OpenMP] Add support for omp simd pragmas without runtime

2017-04-11 Thread Graham Hunter via Phabricator via cfe-commits
huntergr added inline comments.



Comment at: lib/Parse/ParseOpenMP.cpp:174
+  case OMPD_target_teams_distribute_simd:
+DKind = OMPD_simd;
+break;

ABataev wrote:
> huntergr wrote:
> > rengolin wrote:
> > > I'd like @ABataev to confirm this is the right semantics.
> > Yes, would be good. I don't think there's a formal spec for this feature, 
> > but it's possible that directives intended for a different target than the 
> > cpu shouldn't apply with this flag.
> I don't think you need it here. Instead, you should keep an existing logic in 
> Sema/Parsing code, but you need to create your own OpenMPRuntime support 
> class, that supports only emission of simd part of the constructs.
Thanks for taking a look.

I tried this method first, but came to the conclusion it was too invasive. I've 
now tried it a second time and came to the same conclusion.

The problem isn't in generating 'simd' or 'declare simd' from a custom runtime 
class, but in generating everything else. Take a 'parallel for' directive -- I 
have to generate something close to unmodified code, but 
'emitCommonOMPParallelDirective' in CGStmtOpenMP.cpp will only pass the loop 
codegen lambda through to the runtime class's 'emitParallelOutlinedFunction', 
which doesn't take the current CodeGenFunction as an argument (as it's expected 
to create a new one). There doesn't seem to be a good way to look up the CGF 
that the call will be made from.

You also won't get unmodified code in that instance anyway, as the loop is 
generated by CodeGenFunction::EmitWorkSharingLoop, and a cancellation region 
may be created; very little of this is under the control of the runtime class, 
so it would need extensive modification to work.

So I'll switch to using a simd-only 'runtime' class, but I still think we need 
to filter out non-simd directives before we get to codegen. Will post updated 
patch soon.


https://reviews.llvm.org/D31417



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