[llvm-branch-commits] [llvm] f17d60d - Inform pass manager when child loops are deleted

2021-09-09 Thread Tom Stellard via llvm-branch-commits

Author: Bjorn Pettersson
Date: 2021-09-09T09:04:59-07:00
New Revision: f17d60d620283b5d53286056ceeaeb8c27b6530a

URL: 
https://github.com/llvm/llvm-project/commit/f17d60d620283b5d53286056ceeaeb8c27b6530a
DIFF: 
https://github.com/llvm/llvm-project/commit/f17d60d620283b5d53286056ceeaeb8c27b6530a.diff

LOG: Inform pass manager when child loops are deleted

As part of the nontrivial unswitching we could end up removing child
loops. This patch add a notification to the pass manager when
that happens (using the markLoopAsDeleted callback).

Without this there could be stale LoopAccessAnalysis results cached
in the analysis manager. Those analysis results are cached based on
a Loop* as key. Since the BumpPtrAllocator used to allocate
Loop objects could be resetted between different runs of for
example the loop-distribute pass (running on different functions),
a new Loop object could be created using the same Loop pointer.
And then when requiring the LoopAccessAnalysis for the loop we
got the stale (corrupt) result from the destroyed loop.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D109257

(fixes PR51754)
(cherry-picked from commit 0f0344dd1e3b53387bb396070916e67f4c426da6)

Added: 

llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-markloopasdeleted.ll

Modified: 
llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp

Removed: 




diff  --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp 
b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
index b92af3090..b1c1052580278 100644
--- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
+++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
@@ -1587,10 +1587,12 @@ deleteDeadClonedBlocks(Loop &L, ArrayRef 
ExitBlocks,
 BB->eraseFromParent();
 }
 
-static void deleteDeadBlocksFromLoop(Loop &L,
- SmallVectorImpl &ExitBlocks,
- DominatorTree &DT, LoopInfo &LI,
- MemorySSAUpdater *MSSAU) {
+static void
+deleteDeadBlocksFromLoop(Loop &L,
+ SmallVectorImpl &ExitBlocks,
+ DominatorTree &DT, LoopInfo &LI,
+ MemorySSAUpdater *MSSAU,
+ function_ref DestroyLoopCB) {
   // Find all the dead blocks tied to this loop, and remove them from their
   // successors.
   SmallSetVector DeadBlockSet;
@@ -1640,6 +1642,7 @@ static void deleteDeadBlocksFromLoop(Loop &L,
 }) &&
"If the child loop header is dead all blocks in the child loop must 
"
"be dead as well!");
+DestroyLoopCB(*ChildL, ChildL->getName());
 LI.destroy(ChildL);
 return true;
   });
@@ -1980,6 +1983,8 @@ static bool rebuildLoopAfterUnswitch(Loop &L, 
ArrayRef ExitBlocks,
   ParentL->removeChildLoop(llvm::find(*ParentL, &L));
 else
   LI.removeLoop(llvm::find(LI, &L));
+// markLoopAsDeleted for L should be triggered by the caller (it is 
typically
+// done by using the UnswitchCB callback).
 LI.destroy(&L);
 return false;
   }
@@ -2019,7 +2024,8 @@ static void unswitchNontrivialInvariants(
 SmallVectorImpl &ExitBlocks, IVConditionInfo &PartialIVInfo,
 DominatorTree &DT, LoopInfo &LI, AssumptionCache &AC,
 function_ref)> UnswitchCB,
-ScalarEvolution *SE, MemorySSAUpdater *MSSAU) {
+ScalarEvolution *SE, MemorySSAUpdater *MSSAU,
+function_ref DestroyLoopCB) {
   auto *ParentBB = TI.getParent();
   BranchInst *BI = dyn_cast(&TI);
   SwitchInst *SI = BI ? nullptr : cast(&TI);
@@ -2319,7 +2325,7 @@ static void unswitchNontrivialInvariants(
   // Now that our cloned loops have been built, we can update the original 
loop.
   // First we delete the dead blocks from it and then we rebuild the loop
   // structure taking these deletions into account.
-  deleteDeadBlocksFromLoop(L, ExitBlocks, DT, LI, MSSAU);
+  deleteDeadBlocksFromLoop(L, ExitBlocks, DT, LI, MSSAU, DestroyLoopCB);
 
   if (MSSAU && VerifyMemorySSA)
 MSSAU->getMemorySSA()->verifyMemorySSA();
@@ -2670,7 +2676,8 @@ static bool unswitchBestCondition(
 Loop &L, DominatorTree &DT, LoopInfo &LI, AssumptionCache &AC,
 AAResults &AA, TargetTransformInfo &TTI,
 function_ref)> UnswitchCB,
-ScalarEvolution *SE, MemorySSAUpdater *MSSAU) {
+ScalarEvolution *SE, MemorySSAUpdater *MSSAU,
+function_ref DestroyLoopCB) {
   // Collect all invariant conditions within this loop (as opposed to an inner
   // loop which would be handled when visiting that inner loop).
   SmallVector>, 4>
@@ -2958,7 +2965,7 @@ static bool unswitchBestCondition(
 << "\n");
   unswitchNontrivialInvariants(L, *BestUnswitchTI, BestUnswitchInvariants,
ExitBlocks, PartialIVInfo, DT, LI, AC,
-   UnswitchCB, SE, MSSAU);
+   Unswit

[llvm-branch-commits] [llvm] 0c2f859 - Workaround incorrect types when lowering fixed length gather/scatter

2021-09-09 Thread Tom Stellard via llvm-branch-commits

Author: Bradley Smith
Date: 2021-09-09T09:05:58-07:00
New Revision: 0c2f8599a9cc42014b41aadf7c308b4889d2397f

URL: 
https://github.com/llvm/llvm-project/commit/0c2f8599a9cc42014b41aadf7c308b4889d2397f
DIFF: 
https://github.com/llvm/llvm-project/commit/0c2f8599a9cc42014b41aadf7c308b4889d2397f.diff

LOG: Workaround incorrect types when lowering fixed length gather/scatter

When lowering a fixed length gather/scatter the index type is assumed to
be the same as the memory type, this is incorrect in cases where the
extension of the index has been folded into the addressing mode.

For now add a temporary workaround to fix the codegen faults caused by
this by preventing the removal of this extension. At a later date the
lowering for SVE gather/scatters will be redesigned to improve the way
addressing modes are handled.

As a short term side effect of this change, the addressing modes
generated for fixed length gather/scatters will not be optimal.

Differential Revision: https://reviews.llvm.org/D109145

(cherry picked from commit 14e1a4a6eef2fb95ec852c9ddfc597f80bba3226)

Added: 


Modified: 
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/test/CodeGen/AArch64/sve-fixed-length-masked-gather.ll
llvm/test/CodeGen/AArch64/sve-fixed-length-masked-scatter.ll

Removed: 




diff  --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 60c00f47859b0..494554ae7b331 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -4161,7 +4161,8 @@ bool AArch64TargetLowering::shouldExtendGSIndex(EVT VT, 
EVT &EltTy) const {
 
 bool AArch64TargetLowering::shouldRemoveExtendFromGSIndex(EVT VT) const {
   if (VT.getVectorElementType() == MVT::i32 &&
-  VT.getVectorElementCount().getKnownMinValue() >= 4)
+  VT.getVectorElementCount().getKnownMinValue() >= 4 &&
+  !VT.isFixedLengthVector())
 return true;
 
   return false;

diff  --git a/llvm/test/CodeGen/AArch64/sve-fixed-length-masked-gather.ll 
b/llvm/test/CodeGen/AArch64/sve-fixed-length-masked-gather.ll
index ee64e6db65689..a52d3e91fac38 100644
--- a/llvm/test/CodeGen/AArch64/sve-fixed-length-masked-gather.ll
+++ b/llvm/test/CodeGen/AArch64/sve-fixed-length-masked-gather.ll
@@ -917,6 +917,7 @@ define void @masked_gather_v32f64(<32 x double>* %a, <32 x 
double*>* %b) #0 {
 ; The above tests test the types, the below tests check that the addressing
 ; modes still function
 
+; NOTE: This produces an non-optimal addressing mode due to a temporary 
workaround
 define void @masked_gather_32b_scaled_sext_f16(<32 x half>* %a, <32 x i32>* 
%b, half* %base) #0 {
 ; CHECK-LABEL: masked_gather_32b_scaled_sext_f16:
 ; VBITS_GE_2048: ptrue [[PG0:p[0-9]+]].h, vl32
@@ -925,11 +926,15 @@ define void @masked_gather_32b_scaled_sext_f16(<32 x 
half>* %a, <32 x i32>* %b,
 ; VBITS_GE_2048-NEXT: ld1w { [[PTRS:z[0-9]+]].s }, [[PG1]]/z, [x1]
 ; VBITS_GE_2048-NEXT: fcmeq [[CMP:p[0-9]+]].h, [[PG0]]/z, [[VALS]].h, #0.0
 ; VBITS_GE_2048-NEXT: mov [[MONE:z[0-9]+]].h, [[CMP]]/z, #-1
-; VBITS_GE_2048-NEXT: uunpklo [[UPK:z[0-9]+]].s, [[MONE]].h
-; VBITS_GE_2048-NEXT: cmpne [[MASK:p[0-9]+]].s, [[PG1]]/z, [[UPK]].s, #0
-; VBITS_GE_2048-NEXT: ld1h { [[RES:z[0-9]+]].s }, [[MASK]]/z, [x2, [[PTRS]].s, 
sxtw #1]
-; VBITS_GE_2048-NEXT: uzp1 [[UZP:z[0-9]+]].h, [[RES]].h, [[RES]].h
-; VBITS_GE_2048-NEXT: st1h { [[UZP]].h }, [[PG0]], [x0]
+; VBITS_GE_2048-NEXT: uunpklo [[UPK1:z[0-9]+]].s, [[MONE]].h
+; VBITS_GE_2048-NEXT: uunpklo [[UPK2:z[0-9]+]].d, [[UPK1]].s
+; VBITS_GE_2048-NEXT: ptrue [[PG2:p[0-9]+]].d, vl32
+; VBITS_GE_2048-NEXT: sunpklo [[SEXT:z[0-9]+]].d, [[PTRS]].s
+; VBITS_GE_2048-NEXT: cmpne [[MASK:p[0-9]+]].d, [[PG2]]/z, [[UPK2]].d, #0
+; VBITS_GE_2048-NEXT: ld1h { [[RES:z[0-9]+]].d }, [[MASK]]/z, [x2, [[SEXT]].d, 
lsl #1]
+; VBITS_GE_2048-NEXT: uzp1 [[UZP1:z[0-9]+]].s, [[RES]].s, [[RES]].s
+; VBITS_GE_2048-NEXT: uzp1 [[UZP2:z[0-9]+]].h, [[UZP1]].h, [[UZP1]].h
+; VBITS_GE_2048-NEXT: st1h { [[UZP2]].h }, [[PG0]], [x0]
 ; VBITS_GE_2048-NEXT: ret
   %cvals = load <32 x half>, <32 x half>* %a
   %idxs = load <32 x i32>, <32 x i32>* %b
@@ -941,14 +946,21 @@ define void @masked_gather_32b_scaled_sext_f16(<32 x 
half>* %a, <32 x i32>* %b,
   ret void
 }
 
+; NOTE: This produces an non-optimal addressing mode due to a temporary 
workaround
 define void @masked_gather_32b_scaled_sext_f32(<32 x float>* %a, <32 x i32>* 
%b, float* %base) #0 {
 ; CHECK-LABEL: masked_gather_32b_scaled_sext_f32:
-; VBITS_GE_2048: ptrue [[PG:p[0-9]+]].s, vl32
-; VBITS_GE_2048-NEXT: ld1w { [[VALS:z[0-9]+]].s }, [[PG]]/z, [x0]
-; VBITS_GE_2048-NEXT: ld1w { [[PTRS:z[0-9]+]].s }, [[PG]]/z, [x1]
-; VBITS_GE_2048-NEXT: fcmeq [[MASK:p[0-9]+]].s, [[PG]]/z, [[VALS]].s, #0.0
-; VBITS_GE_2048-NEXT: ld1w { [[RES:z[0-9]+]].s }, [[MASK]]/z, [x2, [[PTRS]].s, 
sxtw #2]
-; VBITS_GE_2048-NEXT: st1w { [[RES]].s }, [[PG]], [x0

[llvm-branch-commits] [clang] 718280c - [AMDGPU][OpenMP] Use complex definitions from complex_cmath.h

2021-09-09 Thread Tom Stellard via llvm-branch-commits

Author: Pushpinder Singh
Date: 2021-09-09T16:20:23-07:00
New Revision: 718280c8a2d1beec1ec4c130f96648ab3e41f38c

URL: 
https://github.com/llvm/llvm-project/commit/718280c8a2d1beec1ec4c130f96648ab3e41f38c
DIFF: 
https://github.com/llvm/llvm-project/commit/718280c8a2d1beec1ec4c130f96648ab3e41f38c.diff

LOG: [AMDGPU][OpenMP] Use complex definitions from complex_cmath.h

Following nvptx approach, this patch uses complex function
definitions from complex_cmath.h. With this patch, ovo passes
23/34 complex mathematical test cases.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D109344

(cherry picked from commit 12dcbf913c49db839b3669db0dcacd5de25facde)

Added: 
clang/test/Headers/amdgcn-openmp-device-math-complex.cpp

Modified: 
clang/lib/Headers/openmp_wrappers/complex

Removed: 




diff  --git a/clang/lib/Headers/openmp_wrappers/complex 
b/clang/lib/Headers/openmp_wrappers/complex
index dfd6193c97cbd..eb1ead207d582 100644
--- a/clang/lib/Headers/openmp_wrappers/complex
+++ b/clang/lib/Headers/openmp_wrappers/complex
@@ -36,7 +36,7 @@
 #ifndef _LIBCPP_STD_VER
 
 #pragma omp begin declare variant match(   
\
-device = {arch(nvptx, nvptx64)},   
\
+device = {arch(amdgcn, nvptx, nvptx64)},   
\
 implementation = {extension(match_any, allow_templates)})
 
 #include 

diff  --git a/clang/test/Headers/amdgcn-openmp-device-math-complex.cpp 
b/clang/test/Headers/amdgcn-openmp-device-math-complex.cpp
new file mode 100644
index 0..d1a2cf31fabae
--- /dev/null
+++ b/clang/test/Headers/amdgcn-openmp-device-math-complex.cpp
@@ -0,0 +1,85 @@
+// RUN: %clang_cc1 -verify -internal-isystem %S/Inputs/include -fopenmp -x c++ 
-triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc 
%s -o %t-x86-host.bc
+// RUN: %clang_cc1 -verify -internal-isystem 
%S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h 
-internal-isystem %S/Inputs/include -fopenmp -x c++ -triple amdgcn-amd-amdhsa 
-fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device 
-fopenmp-host-ir-file-path %t-x86-host.bc -aux-triple x86_64-unknown-unknown -o 
- | FileCheck %s
+// expected-no-diagnostics
+
+#include 
+#include 
+
+// CHECK: define weak {{.*}} @__muldc3
+// CHECK-DAG: call i32 @__ocml_isnan_f64(
+// CHECK-DAG: call i32 @__ocml_isinf_f64(
+
+// CHECK: define weak {{.*}} @__mulsc3
+// CHECK-DAG: call i32 @__ocml_isnan_f32(
+// CHECK-DAG: call i32 @__ocml_isinf_f32(
+// CHECK-DAG: call float @__ocml_copysign_f32(
+
+// CHECK: define weak {{.*}} @__divdc3
+// CHECK-DAG: call i32 @__ocml_isnan_f64(
+// CHECK-DAG: call i32 @__ocml_isinf_f64(
+// CHECK-DAG: call i32 @__ocml_isfinite_f64(
+// CHECK-DAG: call double @__ocml_copysign_f64(
+// CHECK-DAG: call double @__ocml_scalbn_f64(
+// CHECK-DAG: call double @__ocml_fabs_f64(
+// CHECK-DAG: call double @__ocml_logb_f64(
+
+// CHECK: define weak {{.*}} @__divsc3
+// CHECK-DAG: call i32 @__ocml_isnan_f32(
+// CHECK-DAG: call i32 @__ocml_isinf_f32(
+// CHECK-DAG: call i32 @__ocml_isfinite_f32(
+// CHECK-DAG: call float @__ocml_copysign_f32(
+// CHECK-DAG: call float @__ocml_scalbn_f32(
+// CHECK-DAG: call float @__ocml_fabs_f32(
+// CHECK-DAG: call float @__ocml_logb_f32(
+
+// We actually check that there are no declarations of non-OpenMP functions.
+// That is, as long as we don't call an unkown function with a name that
+// doesn't start with '__' we are good :)
+
+// CHECK-NOT: declare.*@[^_]
+
+void test_scmplx(std::complex a) {
+#pragma omp target
+  {
+(void)(a * (a / a));
+  }
+}
+
+void test_dcmplx(std::complex a) {
+#pragma omp target
+  {
+(void)(a * (a / a));
+  }
+}
+
+template 
+std::complex test_template_math_calls(std::complex a) {
+  decltype(a) r = a;
+#pragma omp target
+  {
+r = std::sin(r);
+r = std::cos(r);
+r = std::exp(r);
+r = std::atan(r);
+r = std::acos(r);
+  }
+  return r;
+}
+
+std::complex test_scall(std::complex a) {
+  decltype(a) r;
+#pragma omp target
+  {
+r = std::sin(a);
+  }
+  return test_template_math_calls(r);
+}
+
+std::complex test_dcall(std::complex a) {
+  decltype(a) r;
+#pragma omp target
+  {
+r = std::exp(a);
+  }
+  return test_template_math_calls(r);
+}



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] e3ec905 - [MemCpyOpt] Fix a variety of scalable-type crashes

2021-09-09 Thread Tom Stellard via llvm-branch-commits

Author: Fraser Cormack
Date: 2021-09-09T16:21:27-07:00
New Revision: e3ec9058aae5cf3175a1709d8f0b470439584e0d

URL: 
https://github.com/llvm/llvm-project/commit/e3ec9058aae5cf3175a1709d8f0b470439584e0d
DIFF: 
https://github.com/llvm/llvm-project/commit/e3ec9058aae5cf3175a1709d8f0b470439584e0d.diff

LOG: [MemCpyOpt] Fix a variety of scalable-type crashes

This patch fixes a variety of crashes resulting from the `MemCpyOptPass`
casting `TypeSize` to a constant integer, whether implicitly or
explicitly.

Since the `MemsetRanges` requires a constant size to work, all but one
of the fixes in this patch simply involve skipping the various
optimizations for scalable types as cleanly as possible.

The optimization of `byval` parameters, however, has been updated to
work on scalable types in theory. In practice, this optimization is only
valid when the length of the `memcpy` is known to be larger than the
scalable type size, which is currently never the case. This could
perhaps be done in the future using the `vscale_range` attribute.

Some implicit casts have been left as they were, under the knowledge
they are only called on aggregate types. These should never be
scalably-sized.

Reviewed By: nikic, tra

Differential Revision: https://reviews.llvm.org/D109329

(cherry-picked from commit 7fb66d4)

Added: 
llvm/test/Transforms/MemCpyOpt/vscale-crashes.ll

Modified: 
llvm/include/llvm/Transforms/Scalar/MemCpyOptimizer.h
llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp

Removed: 




diff  --git a/llvm/include/llvm/Transforms/Scalar/MemCpyOptimizer.h 
b/llvm/include/llvm/Transforms/Scalar/MemCpyOptimizer.h
index 635b706d0bef5..6203f37ebb012 100644
--- a/llvm/include/llvm/Transforms/Scalar/MemCpyOptimizer.h
+++ b/llvm/include/llvm/Transforms/Scalar/MemCpyOptimizer.h
@@ -65,7 +65,7 @@ class MemCpyOptPass : public PassInfoMixin {
   bool processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI);
   bool processMemMove(MemMoveInst *M);
   bool performCallSlotOptzn(Instruction *cpyLoad, Instruction *cpyStore,
-Value *cpyDst, Value *cpySrc, uint64_t cpyLen,
+Value *cpyDst, Value *cpySrc, TypeSize cpyLen,
 Align cpyAlign, CallInst *C);
   bool processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep);
   bool processMemSetMemCpyDependence(MemCpyInst *MemCpy, MemSetInst *MemSet);

diff  --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp 
b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index 2e36c50b75fc0..9afbe0e9a2a54 100644
--- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -178,9 +178,9 @@ class MemsetRanges {
   }
 
   void addStore(int64_t OffsetFromFirst, StoreInst *SI) {
-int64_t StoreSize = DL.getTypeStoreSize(SI->getOperand(0)->getType());
-
-addRange(OffsetFromFirst, StoreSize, SI->getPointerOperand(),
+TypeSize StoreSize = DL.getTypeStoreSize(SI->getOperand(0)->getType());
+assert(!StoreSize.isScalable() && "Can't track scalable-typed stores");
+addRange(OffsetFromFirst, StoreSize.getFixedSize(), 
SI->getPointerOperand(),
  SI->getAlign().value(), SI);
   }
 
@@ -371,6 +371,11 @@ Instruction 
*MemCpyOptPass::tryMergingIntoMemset(Instruction *StartInst,
  Value *ByteVal) {
   const DataLayout &DL = StartInst->getModule()->getDataLayout();
 
+  // We can't track scalable types
+  if (StoreInst *SI = dyn_cast(StartInst))
+if (DL.getTypeStoreSize(SI->getOperand(0)->getType()).isScalable())
+  return nullptr;
+
   // Okay, so we now have a single store that can be splatable.  Scan to find
   // all subsequent stores of the same value to offset from the same pointer.
   // Join these together into ranges, so we can decide whether contiguous 
blocks
@@ -426,6 +431,10 @@ Instruction 
*MemCpyOptPass::tryMergingIntoMemset(Instruction *StartInst,
   if (DL.isNonIntegralPointerType(StoredVal->getType()->getScalarType()))
 break;
 
+  // We can't track ranges involving scalable types.
+  if (DL.getTypeStoreSize(StoredVal->getType()).isScalable())
+break;
+
   // Check to see if this stored value is of the same byte-splattable 
value.
   Value *StoredByte = isBytewiseValue(StoredVal, DL);
   if (isa(ByteVal) && StoredByte)
@@ -859,7 +868,7 @@ bool MemCpyOptPass::processMemSet(MemSetInst *MSI, 
BasicBlock::iterator &BBI) {
 /// the call write its result directly into the destination of the memcpy.
 bool MemCpyOptPass::performCallSlotOptzn(Instruction *cpyLoad,
  Instruction *cpyStore, Value *cpyDest,
- Value *cpySrc, uint64_t cpyLen,
+ Value *cpySrc, TypeSize cpySize,
  Align cpyAlign, CallInst *C) {
   //

[llvm-branch-commits] [clang] b685e13 - [clan-format] detect function definitions more conservatively

2021-09-09 Thread Tom Stellard via llvm-branch-commits

Author: Krasimir Georgiev
Date: 2021-09-09T20:00:23-07:00
New Revision: b685e13d1130a969dd58fb917a61eef5a33c0552

URL: 
https://github.com/llvm/llvm-project/commit/b685e13d1130a969dd58fb917a61eef5a33c0552
DIFF: 
https://github.com/llvm/llvm-project/commit/b685e13d1130a969dd58fb917a61eef5a33c0552.diff

LOG: [clan-format] detect function definitions more conservatively

https://reviews.llvm.org/D105964 updated the detection of function
definitions. It had the unfortunate effect to start marking object
definitions with attribute-like macros as function definitions.

This addresses this issue.

Reviewed By: owenpan

Differential Revision: https://reviews.llvm.org/D107269

(cherry picked from commit f6bc614546e169bb1b17a29c422ebace038e6c62)

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 54e6c7d38e7de..de3dabcfc639b 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2482,7 +2482,7 @@ static bool isFunctionDeclarationName(const FormatToken 
&Current,
   // return i + 1;
   //   }
   if (Next->Next && Next->Next->is(tok::identifier) &&
-  !(Next->MatchingParen->Next && Next->MatchingParen->Next->is(tok::semi)))
+  Line.Last->isNot(tok::semi))
 return true;
   for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
Tok = Tok->Next) {

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index de00864143f7b..67064d02c01a5 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8216,7 +8216,12 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
"f(i)\n"
"{\n"
"  return i + 1;\n"
-   "}",
+   "}\n"
+   "int\n" // Break here.
+   "f(i)\n"
+   "{\n"
+   "  return i + 1;\n"
+   "};",
Style);
   verifyFormat("int f(a, b, c);\n" // No break here.
"int\n" // Break here.
@@ -8225,8 +8230,20 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
"float c;\n"
"{\n"
"  return a + b < c;\n"
-   "}",
+   "}\n"
+   "int\n"// Break here.
+   "f(a, b, c)\n" // Break here.
+   "short a, b;\n"
+   "float c;\n"
+   "{\n"
+   "  return a + b < c;\n"
+   "};",
Style);
+  // The return breaking style doesn't affect object definitions with
+  // attribute-like macros.
+  verifyFormat("Tttt ppp\n"
+   "ABSL_GUARDED_BY(mutex) = {};",
+   getGoogleStyleWithColumns(40));
 
   Style = getGNUStyle();
 



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] ffd90ed - [clang-format] handle trailing comments in function definition detection

2021-09-09 Thread Tom Stellard via llvm-branch-commits

Author: Krasimir Georgiev
Date: 2021-09-09T20:01:12-07:00
New Revision: ffd90ed19988658fcf1add9c7b9c19153e19cb74

URL: 
https://github.com/llvm/llvm-project/commit/ffd90ed19988658fcf1add9c7b9c19153e19cb74
DIFF: 
https://github.com/llvm/llvm-project/commit/ffd90ed19988658fcf1add9c7b9c19153e19cb74.diff

LOG: [clang-format] handle trailing comments in function definition detection

A follow-up to
https://github.com/llvm/llvm-project/commit/f6bc614546e169bb1b17a29c422ebace038e6c62
where we handle the case where the semicolon is followed by a trailing
comment.

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D107907

(cherry picked from commit 0fc27ef19670676689d3317948c81eb171bb25f8)

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index de3dabcfc639b..703eced09d446 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2482,7 +2482,7 @@ static bool isFunctionDeclarationName(const FormatToken 
&Current,
   // return i + 1;
   //   }
   if (Next->Next && Next->Next->is(tok::identifier) &&
-  Line.Last->isNot(tok::semi))
+  !Line.endsWith(tok::semi))
 return true;
   for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
Tok = Tok->Next) {

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 67064d02c01a5..38b5aa45cc0ea 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8244,6 +8244,9 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
   verifyFormat("Tttt ppp\n"
"ABSL_GUARDED_BY(mutex) = {};",
getGoogleStyleWithColumns(40));
+  verifyFormat("Tttt ppp\n"
+   "ABSL_GUARDED_BY(mutex);  // comment",
+   getGoogleStyleWithColumns(40));
 
   Style = getGNUStyle();
 



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 748f09f - [clang-format] improve distinction of K&R function definitions vs attributes

2021-09-09 Thread Tom Stellard via llvm-branch-commits

Author: Krasimir Georgiev
Date: 2021-09-09T20:02:05-07:00
New Revision: 748f09fdd5d61e64e485a7125d56bc217b5ba491

URL: 
https://github.com/llvm/llvm-project/commit/748f09fdd5d61e64e485a7125d56bc217b5ba491
DIFF: 
https://github.com/llvm/llvm-project/commit/748f09fdd5d61e64e485a7125d56bc217b5ba491.diff

LOG: [clang-format] improve distinction of K&R function definitions vs 
attributes

After
https://github.com/llvm/llvm-project/commit/9da70ab3d43c79116f80fc06aa7cf517374ce42c
we saw a few regressions around trailing attribute definitions and in
typedefs (examples in the added test cases). There's some tension
distinguishing K&R definitions from attributes at the parser level,
where we have to decide if we need to put the type of the K&R definition
on a new unwrapped line before we have access to the rest of the line,
so we're scanning backwards and looking for a pattern like f(a, b). But
this type of pattern could also be an attribute macro, or the whole
declaration could be a typedef itself. I updated the code to check for a
typedef at the beginning of the line and to not consider raw identifiers
as possible first K&R declaration (but treated as an attribute macro
instead). This is not 100% correct heuristic, but I think it should be
reasonably good in practice, where we'll:
  * likely be in some very C-ish code when using K&R style (e.g., stuff
that uses `struct name a;` instead of `name a;`
  * likely be in some very C++-ish code when using attributes
  * unlikely mix up the two in the same declaration.

Ideally, we should only decide to add the unwrapped line before the K&R
declaration after we've scanned the rest of the line an noticed the
variable declarations and the semicolon, but the way the parser is
organized I don't see a good way to do this in the current parser, which
only has good context for the previously visited tokens. I also tried
not emitting an unwrapped line there and trying to resolve the situation
later in the token annotator and the continuation indenter, and that
approach seems promising, but I couldn't make it to work without
messing up a bunch of other cases in unit tests.

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D107950

(cherry picked from commit 45934922fa88b7542c8bcd86889d062fb78efdda)

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 103e3559b1208..14ab1860a0ab6 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -14,6 +14,7 @@
 
 #include "UnwrappedLineParser.h"
 #include "FormatToken.h"
+#include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
@@ -1007,7 +1008,7 @@ static bool isC78ParameterDecl(const FormatToken *Tok) {
 
   if (!Tok->isOneOf(tok::kw_int, tok::kw_char, tok::kw_float, tok::kw_double,
 tok::kw_struct, tok::kw_union, tok::kw_long, tok::kw_short,
-tok::kw_unsigned, tok::kw_register, tok::identifier))
+tok::kw_unsigned, tok::kw_register))
 return false;
 
   Tok = Tok->Previous;
@@ -1378,7 +1379,8 @@ void UnwrappedLineParser::parseStructuralElement(bool 
IsTopLevel) {
 break;
   if (Previous->Previous && Previous->Previous->is(tok::at))
 break;
-  if (isC78ParameterDecl(FormatTok)) {
+  if (!Line->Tokens.begin()->Tok->is(tok::kw_typedef) &&
+  isC78ParameterDecl(FormatTok)) {
 addUnwrappedLine();
 return;
   }

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 38b5aa45cc0ea..b86d30c1872c7 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8239,14 +8239,25 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
"  return a + b < c;\n"
"};",
Style);
-  // The return breaking style doesn't affect object definitions with
-  // attribute-like macros.
+
+  // The return breaking style doesn't affect:
+  // * function and object definitions with attribute-like macros
   verifyFormat("Tttt ppp\n"
"ABSL_GUARDED_BY(mutex) = {};",
getGoogleStyleWithColumns(40));
   verifyFormat("Tttt ppp\n"
"ABSL_GUARDED_BY(mutex);  // comment",
getGoogleStyleWithColumns(40));
+  verifyFormat("Tttt ppp\n"
+   "ABSL_GUARDED_BY(mutex1)\n"
+   "ABSL_GUARDED_BY(mutex2);",
+   getGoogleStyleWithColumns(40));
+  verifyFormat("Tt f(int a, int b)\n"
+   "ABSL_GUARDED_BY(mutex

[llvm-branch-commits] [clang] 4ab7fe9 - [clang-format] Distinguish K&R C function definition and attribute

2021-09-09 Thread Tom Stellard via llvm-branch-commits

Author: Owen
Date: 2021-09-09T20:02:29-07:00
New Revision: 4ab7fe9228dbc7dc521d9cd4afeff7eac3b43c32

URL: 
https://github.com/llvm/llvm-project/commit/4ab7fe9228dbc7dc521d9cd4afeff7eac3b43c32
DIFF: 
https://github.com/llvm/llvm-project/commit/4ab7fe9228dbc7dc521d9cd4afeff7eac3b43c32.diff

LOG: [clang-format] Distinguish K&R C function definition and attribute

This is a follow-up to https://reviews.llvm.org/D107950 which
missed user-defined types in K&R C.

Differential Revision: https://reviews.llvm.org/D107961

(cherry picked from commit f6928cf45516503deb48f8175a982becc579dc8c)

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 14ab1860a0ab6..49a5b4b6dc3e8 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -14,7 +14,6 @@
 
 #include "UnwrappedLineParser.h"
 #include "FormatToken.h"
-#include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
@@ -995,6 +994,13 @@ static bool isJSDeclOrStmt(const AdditionalKeywords 
&Keywords,
   Keywords.kw_import, tok::kw_export);
 }
 
+// Checks whether a token is a type in K&R C (aka C78).
+static bool isC78Type(const FormatToken &Tok) {
+  return Tok.isOneOf(tok::kw_char, tok::kw_short, tok::kw_int, tok::kw_long,
+ tok::kw_unsigned, tok::kw_float, tok::kw_double,
+ tok::identifier);
+}
+
 // This function checks whether a token starts the first parameter declaration
 // in a K&R C (aka C78) function definition, e.g.:
 //   int f(a, b)
@@ -1006,9 +1012,8 @@ static bool isC78ParameterDecl(const FormatToken *Tok) {
   if (!Tok)
 return false;
 
-  if (!Tok->isOneOf(tok::kw_int, tok::kw_char, tok::kw_float, tok::kw_double,
-tok::kw_struct, tok::kw_union, tok::kw_long, tok::kw_short,
-tok::kw_unsigned, tok::kw_register))
+  if (!isC78Type(*Tok) &&
+  !Tok->isOneOf(tok::kw_register, tok::kw_struct, tok::kw_union))
 return false;
 
   Tok = Tok->Previous;
@@ -1369,7 +1374,7 @@ void UnwrappedLineParser::parseStructuralElement(bool 
IsTopLevel) {
 case tok::r_brace:
   addUnwrappedLine();
   return;
-case tok::l_paren:
+case tok::l_paren: {
   parseParens();
   // Break the unwrapped line if a K&R C function definition has a 
parameter
   // declaration.
@@ -1377,14 +1382,22 @@ void UnwrappedLineParser::parseStructuralElement(bool 
IsTopLevel) {
 break;
   if (!Previous || Previous->isNot(tok::identifier))
 break;
-  if (Previous->Previous && Previous->Previous->is(tok::at))
+  const FormatToken *PrevPrev = Previous->Previous;
+  if (!PrevPrev || (!isC78Type(*PrevPrev) && PrevPrev->isNot(tok::star)))
 break;
-  if (!Line->Tokens.begin()->Tok->is(tok::kw_typedef) &&
-  isC78ParameterDecl(FormatTok)) {
+  const unsigned Position = Tokens->getPosition() + 1;
+  if (Position == AllTokens.size())
+break;
+  assert(Position < AllTokens.size());
+  const FormatToken *Next = AllTokens[Position];
+  if (Next && Next->isOneOf(tok::l_paren, tok::semi))
+break;
+  if (isC78ParameterDecl(FormatTok)) {
 addUnwrappedLine();
 return;
   }
   break;
+}
 case tok::kw_operator:
   nextToken();
   if (FormatTok->isBinaryOperator())

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index b86d30c1872c7..623d2163ec364 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8239,6 +8239,20 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
"  return a + b < c;\n"
"};",
Style);
+  verifyFormat("byte *\n" // Break here.
+   "f(a)\n"   // Break here.
+   "byte a[];\n"
+   "{\n"
+   "  return a;\n"
+   "}",
+   Style);
+  verifyFormat("bool f(int a, int) override;\n"
+   "Bar g(int a, Bar) final;\n"
+   "Bar h(a, Bar) final;",
+   Style);
+  verifyFormat("int\n"
+   "f(a)",
+   Style);
 
   // The return breaking style doesn't affect:
   // * function and object definitions with attribute-like macros



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] c8d8248 - [clang-format] Improve detection of parameter declarations in K&R C

2021-09-09 Thread Tom Stellard via llvm-branch-commits

Author: owenca
Date: 2021-09-09T20:02:55-07:00
New Revision: c8d8248488a387d8e948ddfcbef0f1efa8c30f65

URL: 
https://github.com/llvm/llvm-project/commit/c8d8248488a387d8e948ddfcbef0f1efa8c30f65
DIFF: 
https://github.com/llvm/llvm-project/commit/c8d8248488a387d8e948ddfcbef0f1efa8c30f65.diff

LOG: [clang-format] Improve detection of parameter declarations in K&R C

Clean up the detection of parameter declarations in K&R C function
definitions. Also make it more precise by requiring the second
token after the r_paren to be either a star or keyword/identifier.

Differential Revision: https://reviews.llvm.org/D108094

(cherry picked from commmit 643f2be7b6afd91d9f0d6df89cd3391835763112)

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 49a5b4b6dc3e8..673986d16af2f 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1008,14 +1008,26 @@ static bool isC78Type(const FormatToken &Tok) {
 //   {
 //  return a + b;
 //   }
-static bool isC78ParameterDecl(const FormatToken *Tok) {
-  if (!Tok)
+static bool isC78ParameterDecl(const FormatToken *Tok, const FormatToken *Next,
+   const FormatToken *FuncName) {
+  assert(Tok);
+  assert(Next);
+  assert(FuncName);
+
+  if (FuncName->isNot(tok::identifier))
+return false;
+
+  const FormatToken *Prev = FuncName->Previous;
+  if (!Prev || (Prev->isNot(tok::star) && !isC78Type(*Prev)))
 return false;
 
   if (!isC78Type(*Tok) &&
   !Tok->isOneOf(tok::kw_register, tok::kw_struct, tok::kw_union))
 return false;
 
+  if (Next->isNot(tok::star) && !Next->Tok.getIdentifierInfo())
+return false;
+
   Tok = Tok->Previous;
   if (!Tok || Tok->isNot(tok::r_paren))
 return false;
@@ -1378,21 +1390,11 @@ void UnwrappedLineParser::parseStructuralElement(bool 
IsTopLevel) {
   parseParens();
   // Break the unwrapped line if a K&R C function definition has a 
parameter
   // declaration.
-  if (!IsTopLevel || !Style.isCpp())
-break;
-  if (!Previous || Previous->isNot(tok::identifier))
-break;
-  const FormatToken *PrevPrev = Previous->Previous;
-  if (!PrevPrev || (!isC78Type(*PrevPrev) && PrevPrev->isNot(tok::star)))
+  if (!IsTopLevel || !Style.isCpp() || !Previous || 
FormatTok->is(tok::eof))
 break;
   const unsigned Position = Tokens->getPosition() + 1;
-  if (Position == AllTokens.size())
-break;
   assert(Position < AllTokens.size());
-  const FormatToken *Next = AllTokens[Position];
-  if (Next && Next->isOneOf(tok::l_paren, tok::semi))
-break;
-  if (isC78ParameterDecl(FormatTok)) {
+  if (isC78ParameterDecl(FormatTok, AllTokens[Position], Previous)) {
 addUnwrappedLine();
 return;
   }



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] f536522 - scudo: Only add no-omit-frame-pointer flags when the compiler supports them

2021-09-09 Thread Tom Stellard via llvm-branch-commits

Author: Tom Stellard
Date: 2021-09-09T20:42:27-07:00
New Revision: f53652203e4974eac67d2e409650c3f22909d7e2

URL: 
https://github.com/llvm/llvm-project/commit/f53652203e4974eac67d2e409650c3f22909d7e2
DIFF: 
https://github.com/llvm/llvm-project/commit/f53652203e4974eac67d2e409650c3f22909d7e2.diff

LOG: scudo: Only add no-omit-frame-pointer flags when the compiler supports them

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D109196

(cherry picked from commit 9ee64c374605683ae80b9641d5312a72c2a67336)

Added: 


Modified: 
compiler-rt/lib/scudo/standalone/CMakeLists.txt

Removed: 




diff  --git a/compiler-rt/lib/scudo/standalone/CMakeLists.txt 
b/compiler-rt/lib/scudo/standalone/CMakeLists.txt
index 8c3708d3a45f..d6ffa448d7e0 100644
--- a/compiler-rt/lib/scudo/standalone/CMakeLists.txt
+++ b/compiler-rt/lib/scudo/standalone/CMakeLists.txt
@@ -124,8 +124,11 @@ if (COMPILER_RT_HAS_GWP_ASAN)
RTGwpAsan RTGwpAsanBacktraceLibc RTGwpAsanSegvHandler
RTGwpAsanOptionsParser)
 
-  list(APPEND SCUDO_CFLAGS -DGWP_ASAN_HOOKS -fno-omit-frame-pointer
-   -mno-omit-leaf-frame-pointer)
+  append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG 
-fno-omit-frame-pointer
+ 
-mno-omit-leaf-frame-pointer
+ SCUDO_CFLAGS)
+  list(APPEND SCUDO_CFLAGS -DGWP_ASAN_HOOKS)
+
 endif()
 
 set(SCUDO_LINK_LIBS)



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits