[llvm-branch-commits] [llvm] release/18.x: [AArch64] Only apply bool vector bitcast opt if result is scalar (#81256) (PR #81454)

2024-02-12 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/81454
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [AArch64] Only apply bool vector bitcast opt if result is scalar (#81256) (PR #81454)

2024-02-12 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/81454

Backport 92d79922051f732560acf3791b543df1e6580689

Requested by: @DianQK

>From c9f2f8538310d6602cfb1cfb0749ef0f0bcbde56 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Mon, 12 Feb 2024 10:00:34 +0100
Subject: [PATCH] [AArch64] Only apply bool vector bitcast opt if result is
 scalar (#81256)

This optimization tries to optimize bitcasts from `` to iN, but
currently also triggers for `` to `` bitcasts, if custom
lowering has been requested for these for an unrelated reason. Fix this
by explicitly checking that the result type is scalar.

Fixes https://github.com/llvm/llvm-project/issues/81216.

(cherry picked from commit 92d79922051f732560acf3791b543df1e6580689)
---
 .../Target/AArch64/AArch64ISelLowering.cpp|  3 +-
 .../AArch64/vec-combine-compare-to-bitmask.ll | 28 +++
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index e97f5e32201488..2d6b5bc983e739 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -24419,7 +24419,8 @@ void AArch64TargetLowering::ReplaceBITCASTResults(
 return;
   }
 
-  if (SrcVT.isVector() && SrcVT.getVectorElementType() == MVT::i1)
+  if (SrcVT.isVector() && SrcVT.getVectorElementType() == MVT::i1 &&
+  !VT.isVector())
 return replaceBoolVectorBitcast(N, Results, DAG);
 
   if (VT != MVT::i16 || (SrcVT != MVT::f16 && SrcVT != MVT::bf16))
diff --git a/llvm/test/CodeGen/AArch64/vec-combine-compare-to-bitmask.ll 
b/llvm/test/CodeGen/AArch64/vec-combine-compare-to-bitmask.ll
index 1b22e2f900ddb7..557aa010b3a7d9 100644
--- a/llvm/test/CodeGen/AArch64/vec-combine-compare-to-bitmask.ll
+++ b/llvm/test/CodeGen/AArch64/vec-combine-compare-to-bitmask.ll
@@ -489,3 +489,31 @@ define i6 @no_combine_illegal_num_elements(<6 x i32> %vec) 
{
   %bitmask = bitcast <6 x i1> %cmp_result to i6
   ret i6 %bitmask
 }
+
+; Only apply the combine when casting a vector to a scalar.
+define <2 x i8> @vector_to_vector_cast(<16 x i1> %arg) nounwind {
+; CHECK-LABEL: vector_to_vector_cast:
+; CHECK:   ; %bb.0:
+; CHECK-NEXT:sub sp, sp, #16
+; CHECK-NEXT:shl.16b v0, v0, #7
+; CHECK-NEXT:  Lloh36:
+; CHECK-NEXT:adrp x8, lCPI20_0@PAGE
+; CHECK-NEXT:  Lloh37:
+; CHECK-NEXT:ldr q1, [x8, lCPI20_0@PAGEOFF]
+; CHECK-NEXT:add x8, sp, #14
+; CHECK-NEXT:cmlt.16b v0, v0, #0
+; CHECK-NEXT:and.16b v0, v0, v1
+; CHECK-NEXT:ext.16b v1, v0, v0, #8
+; CHECK-NEXT:zip1.16b v0, v0, v1
+; CHECK-NEXT:addv.8h h0, v0
+; CHECK-NEXT:str h0, [sp, #14]
+; CHECK-NEXT:ld1.b { v0 }[0], [x8]
+; CHECK-NEXT:orr x8, x8, #0x1
+; CHECK-NEXT:ld1.b { v0 }[4], [x8]
+; CHECK-NEXT:; kill: def $d0 killed $d0 killed $q0
+; CHECK-NEXT:add sp, sp, #16
+; CHECK-NEXT:ret
+; CHECK-NEXT:.loh AdrpLdr Lloh36, Lloh37
+  %bc = bitcast <16 x i1> %arg to <2 x i8>
+  ret <2 x i8> %bc
+}

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


[llvm-branch-commits] [llvm] release/18.x: [AArch64] Only apply bool vector bitcast opt if result is scalar (#81256) (PR #81454)

2024-02-12 Thread via llvm-branch-commits

llvmbot wrote:

@lawben What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/81454
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [AArch64] Only apply bool vector bitcast opt if result is scalar (#81256) (PR #81454)

2024-02-12 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-aarch64

Author: None (llvmbot)


Changes

Backport 92d79922051f732560acf3791b543df1e6580689

Requested by: @DianQK

---
Full diff: https://github.com/llvm/llvm-project/pull/81454.diff


2 Files Affected:

- (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (+2-1) 
- (modified) llvm/test/CodeGen/AArch64/vec-combine-compare-to-bitmask.ll (+28) 


``diff
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index e97f5e32201488..2d6b5bc983e739 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -24419,7 +24419,8 @@ void AArch64TargetLowering::ReplaceBITCASTResults(
 return;
   }
 
-  if (SrcVT.isVector() && SrcVT.getVectorElementType() == MVT::i1)
+  if (SrcVT.isVector() && SrcVT.getVectorElementType() == MVT::i1 &&
+  !VT.isVector())
 return replaceBoolVectorBitcast(N, Results, DAG);
 
   if (VT != MVT::i16 || (SrcVT != MVT::f16 && SrcVT != MVT::bf16))
diff --git a/llvm/test/CodeGen/AArch64/vec-combine-compare-to-bitmask.ll 
b/llvm/test/CodeGen/AArch64/vec-combine-compare-to-bitmask.ll
index 1b22e2f900ddb7..557aa010b3a7d9 100644
--- a/llvm/test/CodeGen/AArch64/vec-combine-compare-to-bitmask.ll
+++ b/llvm/test/CodeGen/AArch64/vec-combine-compare-to-bitmask.ll
@@ -489,3 +489,31 @@ define i6 @no_combine_illegal_num_elements(<6 x i32> %vec) 
{
   %bitmask = bitcast <6 x i1> %cmp_result to i6
   ret i6 %bitmask
 }
+
+; Only apply the combine when casting a vector to a scalar.
+define <2 x i8> @vector_to_vector_cast(<16 x i1> %arg) nounwind {
+; CHECK-LABEL: vector_to_vector_cast:
+; CHECK:   ; %bb.0:
+; CHECK-NEXT:sub sp, sp, #16
+; CHECK-NEXT:shl.16b v0, v0, #7
+; CHECK-NEXT:  Lloh36:
+; CHECK-NEXT:adrp x8, lCPI20_0@PAGE
+; CHECK-NEXT:  Lloh37:
+; CHECK-NEXT:ldr q1, [x8, lCPI20_0@PAGEOFF]
+; CHECK-NEXT:add x8, sp, #14
+; CHECK-NEXT:cmlt.16b v0, v0, #0
+; CHECK-NEXT:and.16b v0, v0, v1
+; CHECK-NEXT:ext.16b v1, v0, v0, #8
+; CHECK-NEXT:zip1.16b v0, v0, v1
+; CHECK-NEXT:addv.8h h0, v0
+; CHECK-NEXT:str h0, [sp, #14]
+; CHECK-NEXT:ld1.b { v0 }[0], [x8]
+; CHECK-NEXT:orr x8, x8, #0x1
+; CHECK-NEXT:ld1.b { v0 }[4], [x8]
+; CHECK-NEXT:; kill: def $d0 killed $d0 killed $q0
+; CHECK-NEXT:add sp, sp, #16
+; CHECK-NEXT:ret
+; CHECK-NEXT:.loh AdrpLdr Lloh36, Lloh37
+  %bc = bitcast <16 x i1> %arg to <2 x i8>
+  ret <2 x i8> %bc
+}

``




https://github.com/llvm/llvm-project/pull/81454
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms] Support `moveOpBefore`/`After` in dialect conversion (PR #81240)

2024-02-12 Thread Matthias Springer via llvm-branch-commits

https://github.com/matthias-springer updated 
https://github.com/llvm/llvm-project/pull/81240

>From c60c43bcd2296715ceca83a3f9666433883ec303 Mon Sep 17 00:00:00 2001
From: Matthias Springer 
Date: Mon, 12 Feb 2024 09:05:50 +
Subject: [PATCH 1/2] [mlir][Transforms][WIP] RewriteAction

BEGIN_PUBLIC
No public commit message needed for presubmit.
END_PUBLIC
---
 .../Transforms/Utils/DialectConversion.cpp| 504 +++---
 1 file changed, 306 insertions(+), 198 deletions(-)

diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp 
b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index e41231d7cbd390..edca84e5a73f04 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -154,13 +154,12 @@ namespace {
 struct RewriterState {
   RewriterState(unsigned numCreatedOps, unsigned numUnresolvedMaterializations,
 unsigned numReplacements, unsigned numArgReplacements,
-unsigned numBlockActions, unsigned numIgnoredOperations,
+unsigned numRewrites, unsigned numIgnoredOperations,
 unsigned numRootUpdates)
   : numCreatedOps(numCreatedOps),
 numUnresolvedMaterializations(numUnresolvedMaterializations),
 numReplacements(numReplacements),
-numArgReplacements(numArgReplacements),
-numBlockActions(numBlockActions),
+numArgReplacements(numArgReplacements), numRewrites(numRewrites),
 numIgnoredOperations(numIgnoredOperations),
 numRootUpdates(numRootUpdates) {}
 
@@ -176,8 +175,8 @@ struct RewriterState {
   /// The current number of argument replacements queued.
   unsigned numArgReplacements;
 
-  /// The current number of block actions performed.
-  unsigned numBlockActions;
+  /// The current number of rewrites performed.
+  unsigned numRewrites;
 
   /// The current number of ignored operations.
   unsigned numIgnoredOperations;
@@ -235,86 +234,6 @@ struct OpReplacement {
   const TypeConverter *converter;
 };
 
-//===--===//
-// BlockAction
-
-/// The kind of the block action performed during the rewrite.  Actions can be
-/// undone if the conversion fails.
-enum class BlockActionKind {
-  Create,
-  Erase,
-  Inline,
-  Move,
-  Split,
-  TypeConversion
-};
-
-/// Original position of the given block in its parent region. During undo
-/// actions, the block needs to be placed before `insertBeforeBlock`.
-struct BlockPosition {
-  Region *region;
-  Block *insertBeforeBlock;
-};
-
-/// Information needed to undo inlining actions.
-/// - the source block
-/// - the first inlined operation (could be null if the source block was empty)
-/// - the last inlined operation (could be null if the source block was empty)
-struct InlineInfo {
-  Block *sourceBlock;
-  Operation *firstInlinedInst;
-  Operation *lastInlinedInst;
-};
-
-/// The storage class for an undoable block action (one of BlockActionKind),
-/// contains the information necessary to undo this action.
-struct BlockAction {
-  static BlockAction getCreate(Block *block) {
-return {BlockActionKind::Create, block, {}};
-  }
-  static BlockAction getErase(Block *block, BlockPosition originalPosition) {
-return {BlockActionKind::Erase, block, {originalPosition}};
-  }
-  static BlockAction getInline(Block *block, Block *srcBlock,
-   Block::iterator before) {
-BlockAction action{BlockActionKind::Inline, block, {}};
-action.inlineInfo = {srcBlock,
- srcBlock->empty() ? nullptr : &srcBlock->front(),
- srcBlock->empty() ? nullptr : &srcBlock->back()};
-return action;
-  }
-  static BlockAction getMove(Block *block, BlockPosition originalPosition) {
-return {BlockActionKind::Move, block, {originalPosition}};
-  }
-  static BlockAction getSplit(Block *block, Block *originalBlock) {
-BlockAction action{BlockActionKind::Split, block, {}};
-action.originalBlock = originalBlock;
-return action;
-  }
-  static BlockAction getTypeConversion(Block *block) {
-return BlockAction{BlockActionKind::TypeConversion, block, {}};
-  }
-
-  // The action kind.
-  BlockActionKind kind;
-
-  // A pointer to the block that was created by the action.
-  Block *block;
-
-  union {
-// In use if kind == BlockActionKind::Inline or BlockActionKind::Erase, and
-// contains a pointer to the region that originally contained the block as
-// well as the position of the block in that region.
-BlockPosition originalPosition;
-// In use if kind == BlockActionKind::Split and contains a pointer to the
-// block that was split into two parts.
-Block *originalBlock;
-// In use if kind == BlockActionKind::Inline, and contains the information
-// needed to undo the inlining.
-InlineInfo inlineInfo;
-  };
-};
-
 
//===--===/

[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Modularize block actions (PR #81237)

2024-02-12 Thread Matthias Springer via llvm-branch-commits

https://github.com/matthias-springer updated 
https://github.com/llvm/llvm-project/pull/81237

>From c60c43bcd2296715ceca83a3f9666433883ec303 Mon Sep 17 00:00:00 2001
From: Matthias Springer 
Date: Mon, 12 Feb 2024 09:05:50 +
Subject: [PATCH] [mlir][Transforms][WIP] RewriteAction

BEGIN_PUBLIC
No public commit message needed for presubmit.
END_PUBLIC
---
 .../Transforms/Utils/DialectConversion.cpp| 504 +++---
 1 file changed, 306 insertions(+), 198 deletions(-)

diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp 
b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index e41231d7cbd390..edca84e5a73f04 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -154,13 +154,12 @@ namespace {
 struct RewriterState {
   RewriterState(unsigned numCreatedOps, unsigned numUnresolvedMaterializations,
 unsigned numReplacements, unsigned numArgReplacements,
-unsigned numBlockActions, unsigned numIgnoredOperations,
+unsigned numRewrites, unsigned numIgnoredOperations,
 unsigned numRootUpdates)
   : numCreatedOps(numCreatedOps),
 numUnresolvedMaterializations(numUnresolvedMaterializations),
 numReplacements(numReplacements),
-numArgReplacements(numArgReplacements),
-numBlockActions(numBlockActions),
+numArgReplacements(numArgReplacements), numRewrites(numRewrites),
 numIgnoredOperations(numIgnoredOperations),
 numRootUpdates(numRootUpdates) {}
 
@@ -176,8 +175,8 @@ struct RewriterState {
   /// The current number of argument replacements queued.
   unsigned numArgReplacements;
 
-  /// The current number of block actions performed.
-  unsigned numBlockActions;
+  /// The current number of rewrites performed.
+  unsigned numRewrites;
 
   /// The current number of ignored operations.
   unsigned numIgnoredOperations;
@@ -235,86 +234,6 @@ struct OpReplacement {
   const TypeConverter *converter;
 };
 
-//===--===//
-// BlockAction
-
-/// The kind of the block action performed during the rewrite.  Actions can be
-/// undone if the conversion fails.
-enum class BlockActionKind {
-  Create,
-  Erase,
-  Inline,
-  Move,
-  Split,
-  TypeConversion
-};
-
-/// Original position of the given block in its parent region. During undo
-/// actions, the block needs to be placed before `insertBeforeBlock`.
-struct BlockPosition {
-  Region *region;
-  Block *insertBeforeBlock;
-};
-
-/// Information needed to undo inlining actions.
-/// - the source block
-/// - the first inlined operation (could be null if the source block was empty)
-/// - the last inlined operation (could be null if the source block was empty)
-struct InlineInfo {
-  Block *sourceBlock;
-  Operation *firstInlinedInst;
-  Operation *lastInlinedInst;
-};
-
-/// The storage class for an undoable block action (one of BlockActionKind),
-/// contains the information necessary to undo this action.
-struct BlockAction {
-  static BlockAction getCreate(Block *block) {
-return {BlockActionKind::Create, block, {}};
-  }
-  static BlockAction getErase(Block *block, BlockPosition originalPosition) {
-return {BlockActionKind::Erase, block, {originalPosition}};
-  }
-  static BlockAction getInline(Block *block, Block *srcBlock,
-   Block::iterator before) {
-BlockAction action{BlockActionKind::Inline, block, {}};
-action.inlineInfo = {srcBlock,
- srcBlock->empty() ? nullptr : &srcBlock->front(),
- srcBlock->empty() ? nullptr : &srcBlock->back()};
-return action;
-  }
-  static BlockAction getMove(Block *block, BlockPosition originalPosition) {
-return {BlockActionKind::Move, block, {originalPosition}};
-  }
-  static BlockAction getSplit(Block *block, Block *originalBlock) {
-BlockAction action{BlockActionKind::Split, block, {}};
-action.originalBlock = originalBlock;
-return action;
-  }
-  static BlockAction getTypeConversion(Block *block) {
-return BlockAction{BlockActionKind::TypeConversion, block, {}};
-  }
-
-  // The action kind.
-  BlockActionKind kind;
-
-  // A pointer to the block that was created by the action.
-  Block *block;
-
-  union {
-// In use if kind == BlockActionKind::Inline or BlockActionKind::Erase, and
-// contains a pointer to the region that originally contained the block as
-// well as the position of the block in that region.
-BlockPosition originalPosition;
-// In use if kind == BlockActionKind::Split and contains a pointer to the
-// block that was split into two parts.
-Block *originalBlock;
-// In use if kind == BlockActionKind::Inline, and contains the information
-// needed to undo the inlining.
-InlineInfo inlineInfo;
-  };
-};
-
 
//===--===//
 /

[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Turn in-place op modifications into `RewriteAction`s (PR #81245)

2024-02-12 Thread Matthias Springer via llvm-branch-commits

https://github.com/matthias-springer updated 
https://github.com/llvm/llvm-project/pull/81245

>From f7010ea9f363c011f4171a6329ad6de30880c3e7 Mon Sep 17 00:00:00 2001
From: Matthias Springer 
Date: Mon, 12 Feb 2024 09:11:47 +
Subject: [PATCH] [mlir][Transforms][NFC] Turn in-place op modifications into
 `RewriteAction`s

This commit simplifies the internal state of the dialect conversion. A separate 
field for the previous state of in-place op modifications is no longer needed.

BEGIN_PUBLIC
No public commit message needed for presubmit.
END_PUBLIC
---
 .../mlir/Transforms/DialectConversion.h   |   4 +-
 .../Transforms/Utils/DialectConversion.cpp| 123 --
 2 files changed, 56 insertions(+), 71 deletions(-)

diff --git a/mlir/include/mlir/Transforms/DialectConversion.h 
b/mlir/include/mlir/Transforms/DialectConversion.h
index b028d2b71b3762..c0c702a7d34821 100644
--- a/mlir/include/mlir/Transforms/DialectConversion.h
+++ b/mlir/include/mlir/Transforms/DialectConversion.h
@@ -721,8 +721,8 @@ class ConversionPatternRewriter final : public 
PatternRewriter {
 
   /// PatternRewriter hook for updating the given operation in-place.
   /// Note: These methods only track updates to the given operation itself,
-  /// and not nested regions. Updates to regions will still require
-  /// notification through other more specific hooks above.
+  /// and not nested regions. Updates to regions will still require 
notification
+  /// through other more specific hooks above.
   void startOpModification(Operation *op) override;
 
   /// PatternRewriter hook for updating the given operation in-place.
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp 
b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 85b67bb834de7c..489ccd0139c7f2 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -154,14 +154,12 @@ namespace {
 struct RewriterState {
   RewriterState(unsigned numCreatedOps, unsigned numUnresolvedMaterializations,
 unsigned numReplacements, unsigned numArgReplacements,
-unsigned numRewrites, unsigned numIgnoredOperations,
-unsigned numRootUpdates)
+unsigned numRewrites, unsigned numIgnoredOperations)
   : numCreatedOps(numCreatedOps),
 numUnresolvedMaterializations(numUnresolvedMaterializations),
 numReplacements(numReplacements),
 numArgReplacements(numArgReplacements), numRewrites(numRewrites),
-numIgnoredOperations(numIgnoredOperations),
-numRootUpdates(numRootUpdates) {}
+numIgnoredOperations(numIgnoredOperations) {}
 
   /// The current number of created operations.
   unsigned numCreatedOps;
@@ -180,44 +178,6 @@ struct RewriterState {
 
   /// The current number of ignored operations.
   unsigned numIgnoredOperations;
-
-  /// The current number of operations that were updated in place.
-  unsigned numRootUpdates;
-};
-
-//===--===//
-// OperationTransactionState
-
-/// The state of an operation that was updated by a pattern in-place. This
-/// contains all of the necessary information to reconstruct an operation that
-/// was updated in place.
-class OperationTransactionState {
-public:
-  OperationTransactionState() = default;
-  OperationTransactionState(Operation *op)
-  : op(op), loc(op->getLoc()), attrs(op->getAttrDictionary()),
-operands(op->operand_begin(), op->operand_end()),
-successors(op->successor_begin(), op->successor_end()) {}
-
-  /// Discard the transaction state and reset the state of the original
-  /// operation.
-  void resetOperation() const {
-op->setLoc(loc);
-op->setAttrs(attrs);
-op->setOperands(operands);
-for (const auto &it : llvm::enumerate(successors))
-  op->setSuccessor(it.value(), it.index());
-  }
-
-  /// Return the original operation of this state.
-  Operation *getOperation() const { return op; }
-
-private:
-  Operation *op;
-  LocationAttr loc;
-  DictionaryAttr attrs;
-  SmallVector operands;
-  SmallVector successors;
 };
 
 
//===--===//
@@ -761,7 +721,8 @@ class IRRewrite {
 MoveBlock,
 SplitBlock,
 BlockTypeConversion,
-MoveOperation
+MoveOperation,
+ModifyOperation
   };
 
   virtual ~IRRewrite() = default;
@@ -992,7 +953,7 @@ class OperationRewrite : public IRRewrite {
 
   static bool classof(const IRRewrite *rewrite) {
 return rewrite->getKind() >= Kind::MoveOperation &&
-   rewrite->getKind() <= Kind::MoveOperation;
+   rewrite->getKind() <= Kind::ModifyOperation;
   }
 
 protected:
@@ -1031,6 +992,34 @@ class MoveOperationRewrite : public OperationRewrite {
   // this operation was the only operation in the region.
   Operation *insertBeforeOp;
 };
+
+/// In-place modification of an op. This rewrite is immediately reflected in
+///

[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Modularize block actions (PR #81237)

2024-02-12 Thread Matthias Springer via llvm-branch-commits

https://github.com/matthias-springer edited 
https://github.com/llvm/llvm-project/pull/81237
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Modularize block actions (PR #81237)

2024-02-12 Thread Matthias Springer via llvm-branch-commits


@@ -820,6 +740,238 @@ void ArgConverter::insertConversion(Block *newBlock,
   conversionInfo.insert({newBlock, std::move(info)});
 }
 
+//===--===//
+// RewriteAction

matthias-springer wrote:

I renamed `RewriteAction` to `IRRewrite`.


https://github.com/llvm/llvm-project/pull/81237
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms] Support `moveOpBefore`/`After` in dialect conversion (PR #81240)

2024-02-12 Thread Matthias Springer via llvm-branch-commits

https://github.com/matthias-springer edited 
https://github.com/llvm/llvm-project/pull/81240
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms] Support `moveOpBefore`/`After` in dialect conversion (PR #81240)

2024-02-12 Thread Matthias Springer via llvm-branch-commits


@@ -970,6 +971,54 @@ class BlockTypeConversionAction : public BlockAction {
 
   void rollback() override;
 };
+
+/// An operation rewrite.

matthias-springer wrote:

I renamed the class to `OperationRewrite`. I added more documentation to the 
superclass `IRRewrite` in the dependent PR.


https://github.com/llvm/llvm-project/pull/81240
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Turn in-place op modification into `IRRewrite` (PR #81245)

2024-02-12 Thread Matthias Springer via llvm-branch-commits

https://github.com/matthias-springer edited 
https://github.com/llvm/llvm-project/pull/81245
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [TBAA] Use !tbaa for first accessed field, even if there are others. (PR #81313)

2024-02-12 Thread via llvm-branch-commits

https://github.com/dobbelaj-snps approved this pull request.

lgtm

Maybe rephrase the commit message to something like:

 [tbaa] Use !tbaa for first accessed field if it is an exact match in 
offset and size. 

https://github.com/llvm/llvm-project/pull/81313
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Simplify `ArgConverter` state (PR #81462)

2024-02-12 Thread Matthias Springer via llvm-branch-commits

https://github.com/matthias-springer created 
https://github.com/llvm/llvm-project/pull/81462

* When converting a block signature, `ArgConverter` creates a new block with 
the new signature and moves all operation from the old block to the new block. 
The new block is temporarily inserted into a region that is stored in 
`regionMapping`. The old block is not yet deleted, so that the conversion can 
be rolled back. `regionMapping` is not needed. Instead of moving the old block 
to a temporary region, it can just be unlinked. Block erasures are handles in 
the same way in the dialect conversion.
* `regionToConverter` is a mapping from regions to type converter. That field 
is never accessed within `ArgConverter`. It should be stored in 
`ConversionPatternRewriterImpl` instead.


>From 5af1476c5d439c14122ffb50d24923e522a61b32 Mon Sep 17 00:00:00 2001
From: Matthias Springer 
Date: Mon, 12 Feb 2024 10:53:59 +
Subject: [PATCH] [mlir][Transforms][NFC] Simplify `ArgConverter` state

* When converting a block signature, `ArgConverter` creates a new block with 
the new signature and moves all operation from the old block to the new block. 
The new block is temporarily inserted into a region that is stored in 
`regionMapping`. The old block is not yet deleted, so that the conversion can 
be rolled back. `regionMapping` is not needed. Instead of moving the old block 
to a temporary region, it can just be unlinked. Block erasures are handles in 
the same way in the dialect conversion.
* `regionToConverter` is a mapping from regions to type converter. That field 
is never accessed within `ArgConverter`. It should be stored in 
`ConversionPatternRewriterImpl` instead.
---
 .../Transforms/Utils/DialectConversion.cpp| 63 ++-
 1 file changed, 18 insertions(+), 45 deletions(-)

diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp 
b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 489ccd0139c7f..53717f632621d 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -348,18 +348,6 @@ struct ArgConverter {
 return conversionInfo.count(block) || convertedBlocks.count(block);
   }
 
-  /// Set the type converter to use for the given region.
-  void setConverter(Region *region, const TypeConverter *typeConverter) {
-assert(typeConverter && "expected valid type converter");
-regionToConverter[region] = typeConverter;
-  }
-
-  /// Return the type converter to use for the given region, or null if there
-  /// isn't one.
-  const TypeConverter *getConverter(Region *region) {
-return regionToConverter.lookup(region);
-  }
-
   
//======//
   // Rewrite Application
   
//======//
@@ -409,9 +397,6 @@ struct ArgConverter {
   ConversionValueMapping &mapping,
   SmallVectorImpl &argReplacements);
 
-  /// Insert a new conversion into the cache.
-  void insertConversion(Block *newBlock, ConvertedBlockInfo &&info);
-
   /// A collection of blocks that have had their arguments converted. This is a
   /// map from the new replacement block, back to the original block.
   llvm::MapVector conversionInfo;
@@ -419,14 +404,6 @@ struct ArgConverter {
   /// The set of original blocks that were converted.
   DenseSet convertedBlocks;
 
-  /// A mapping from valid regions, to those containing the original blocks of 
a
-  /// conversion.
-  DenseMap> regionMapping;
-
-  /// A mapping of regions to type converters that should be used when
-  /// converting the arguments of blocks within that region.
-  DenseMap regionToConverter;
-
   /// The pattern rewriter to use when materializing conversions.
   PatternRewriter &rewriter;
 
@@ -474,9 +451,10 @@ void ArgConverter::discardRewrites(Block *block) {
 block->getArgument(i).dropAllUses();
   block->replaceAllUsesWith(origBlock);
 
-  // Move the operations back the original block and the delete the new block.
+  // Move the operations back the original block, move the original block back
+  // into its original location and the delete the new block.
   origBlock->getOperations().splice(origBlock->end(), block->getOperations());
-  origBlock->moveBefore(block);
+  block->getParent()->getBlocks().insert(Region::iterator(block), origBlock);
   block->erase();
 
   convertedBlocks.erase(origBlock);
@@ -510,6 +488,9 @@ void ArgConverter::applyRewrites(ConversionValueMapping 
&mapping) {
 mapping.lookupOrDefault(castValue, origArg.getType()));
   }
 }
+
+delete origBlock;
+blockInfo.origBlock = nullptr;
   }
 }
 
@@ -603,6 +584,9 @@ Block *ArgConverter::applySignatureConversion(
   // signature.
   Block *newBlock = block->splitBlock(block->begin());
   block->replaceAllUsesWith(newBlock);
+  // Unlink the block, but do not erase it yet, so that the change can be 
rolled
+  // back.
+  block->getParent()->getBlocks().remo

[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Simplify `ArgConverter` state (PR #81462)

2024-02-12 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir-core

Author: Matthias Springer (matthias-springer)


Changes

* When converting a block signature, `ArgConverter` creates a new block with 
the new signature and moves all operation from the old block to the new block. 
The new block is temporarily inserted into a region that is stored in 
`regionMapping`. The old block is not yet deleted, so that the conversion can 
be rolled back. `regionMapping` is not needed. Instead of moving the old block 
to a temporary region, it can just be unlinked. Block erasures are handles in 
the same way in the dialect conversion.
* `regionToConverter` is a mapping from regions to type converter. That field 
is never accessed within `ArgConverter`. It should be stored in 
`ConversionPatternRewriterImpl` instead.


---
Full diff: https://github.com/llvm/llvm-project/pull/81462.diff


1 Files Affected:

- (modified) mlir/lib/Transforms/Utils/DialectConversion.cpp (+18-45) 


``diff
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp 
b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 489ccd0139c7f2..53717f632621dd 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -348,18 +348,6 @@ struct ArgConverter {
 return conversionInfo.count(block) || convertedBlocks.count(block);
   }
 
-  /// Set the type converter to use for the given region.
-  void setConverter(Region *region, const TypeConverter *typeConverter) {
-assert(typeConverter && "expected valid type converter");
-regionToConverter[region] = typeConverter;
-  }
-
-  /// Return the type converter to use for the given region, or null if there
-  /// isn't one.
-  const TypeConverter *getConverter(Region *region) {
-return regionToConverter.lookup(region);
-  }
-
   
//======//
   // Rewrite Application
   
//======//
@@ -409,9 +397,6 @@ struct ArgConverter {
   ConversionValueMapping &mapping,
   SmallVectorImpl &argReplacements);
 
-  /// Insert a new conversion into the cache.
-  void insertConversion(Block *newBlock, ConvertedBlockInfo &&info);
-
   /// A collection of blocks that have had their arguments converted. This is a
   /// map from the new replacement block, back to the original block.
   llvm::MapVector conversionInfo;
@@ -419,14 +404,6 @@ struct ArgConverter {
   /// The set of original blocks that were converted.
   DenseSet convertedBlocks;
 
-  /// A mapping from valid regions, to those containing the original blocks of 
a
-  /// conversion.
-  DenseMap> regionMapping;
-
-  /// A mapping of regions to type converters that should be used when
-  /// converting the arguments of blocks within that region.
-  DenseMap regionToConverter;
-
   /// The pattern rewriter to use when materializing conversions.
   PatternRewriter &rewriter;
 
@@ -474,9 +451,10 @@ void ArgConverter::discardRewrites(Block *block) {
 block->getArgument(i).dropAllUses();
   block->replaceAllUsesWith(origBlock);
 
-  // Move the operations back the original block and the delete the new block.
+  // Move the operations back the original block, move the original block back
+  // into its original location and the delete the new block.
   origBlock->getOperations().splice(origBlock->end(), block->getOperations());
-  origBlock->moveBefore(block);
+  block->getParent()->getBlocks().insert(Region::iterator(block), origBlock);
   block->erase();
 
   convertedBlocks.erase(origBlock);
@@ -510,6 +488,9 @@ void ArgConverter::applyRewrites(ConversionValueMapping 
&mapping) {
 mapping.lookupOrDefault(castValue, origArg.getType()));
   }
 }
+
+delete origBlock;
+blockInfo.origBlock = nullptr;
   }
 }
 
@@ -603,6 +584,9 @@ Block *ArgConverter::applySignatureConversion(
   // signature.
   Block *newBlock = block->splitBlock(block->begin());
   block->replaceAllUsesWith(newBlock);
+  // Unlink the block, but do not erase it yet, so that the change can be 
rolled
+  // back.
+  block->getParent()->getBlocks().remove(block);
 
   // Map all new arguments to the location of the argument they originate from.
   SmallVector newLocs(convertedTypes.size(),
@@ -679,24 +663,9 @@ Block *ArgConverter::applySignatureConversion(
 ConvertedArgInfo(inputMap->inputNo, inputMap->size, newArg);
   }
 
-  // Remove the original block from the region and return the new one.
-  insertConversion(newBlock, std::move(info));
-  return newBlock;
-}
-
-void ArgConverter::insertConversion(Block *newBlock,
-ConvertedBlockInfo &&info) {
-  // Get a region to insert the old block.
-  Region *region = newBlock->getParent();
-  std::unique_ptr &mappedRegion = regionMapping[region];
-  if (!mappedRegion)
-mappedRegion = std::make_unique(region->getParentOp());
-
-  // Move the original block to the mapped region and 

[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Simplify `ArgConverter` state (PR #81462)

2024-02-12 Thread Matthias Springer via llvm-branch-commits

https://github.com/matthias-springer updated 
https://github.com/llvm/llvm-project/pull/81462

>From ba1a8085ab576b56a7d1780d9a3f01cb6769df65 Mon Sep 17 00:00:00 2001
From: Matthias Springer 
Date: Mon, 12 Feb 2024 11:24:52 +
Subject: [PATCH] [mlir][Transforms][NFC] Simplify `ArgConverter` state

* When converting a block signature, `ArgConverter` creates a new block with 
the new signature and moves all operation from the old block to the new block. 
The new block is temporarily inserted into a region that is stored in 
`regionMapping`. The old block is not yet deleted, so that the conversion can 
be rolled back. `regionMapping` is not needed. Instead of moving the old block 
to a temporary region, it can just be unlinked. Block erasures are handles in 
the same way in the dialect conversion.
* `regionToConverter` is a mapping from regions to type converter. That field 
is never accessed within `ArgConverter`. It should be stored in 
`ConversionPatternRewriterImpl` instead.
---
 .../Transforms/Utils/DialectConversion.cpp| 79 ++-
 1 file changed, 22 insertions(+), 57 deletions(-)

diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp 
b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 489ccd0139c7f2..e1c838ea1e43a4 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -343,23 +343,6 @@ struct ArgConverter {
 const TypeConverter *converter;
   };
 
-  /// Return if the signature of the given block has already been converted.
-  bool hasBeenConverted(Block *block) const {
-return conversionInfo.count(block) || convertedBlocks.count(block);
-  }
-
-  /// Set the type converter to use for the given region.
-  void setConverter(Region *region, const TypeConverter *typeConverter) {
-assert(typeConverter && "expected valid type converter");
-regionToConverter[region] = typeConverter;
-  }
-
-  /// Return the type converter to use for the given region, or null if there
-  /// isn't one.
-  const TypeConverter *getConverter(Region *region) {
-return regionToConverter.lookup(region);
-  }
-
   
//======//
   // Rewrite Application
   
//======//
@@ -409,24 +392,10 @@ struct ArgConverter {
   ConversionValueMapping &mapping,
   SmallVectorImpl &argReplacements);
 
-  /// Insert a new conversion into the cache.
-  void insertConversion(Block *newBlock, ConvertedBlockInfo &&info);
-
   /// A collection of blocks that have had their arguments converted. This is a
   /// map from the new replacement block, back to the original block.
   llvm::MapVector conversionInfo;
 
-  /// The set of original blocks that were converted.
-  DenseSet convertedBlocks;
-
-  /// A mapping from valid regions, to those containing the original blocks of 
a
-  /// conversion.
-  DenseMap> regionMapping;
-
-  /// A mapping of regions to type converters that should be used when
-  /// converting the arguments of blocks within that region.
-  DenseMap regionToConverter;
-
   /// The pattern rewriter to use when materializing conversions.
   PatternRewriter &rewriter;
 
@@ -474,12 +443,12 @@ void ArgConverter::discardRewrites(Block *block) {
 block->getArgument(i).dropAllUses();
   block->replaceAllUsesWith(origBlock);
 
-  // Move the operations back the original block and the delete the new block.
+  // Move the operations back the original block, move the original block back
+  // into its original location and the delete the new block.
   origBlock->getOperations().splice(origBlock->end(), block->getOperations());
-  origBlock->moveBefore(block);
+  block->getParent()->getBlocks().insert(Region::iterator(block), origBlock);
   block->erase();
 
-  convertedBlocks.erase(origBlock);
   conversionInfo.erase(it);
 }
 
@@ -510,6 +479,9 @@ void ArgConverter::applyRewrites(ConversionValueMapping 
&mapping) {
 mapping.lookupOrDefault(castValue, origArg.getType()));
   }
 }
+
+delete origBlock;
+blockInfo.origBlock = nullptr;
   }
 }
 
@@ -572,9 +544,11 @@ FailureOr ArgConverter::convertSignature(
 Block *block, const TypeConverter *converter,
 ConversionValueMapping &mapping,
 SmallVectorImpl &argReplacements) {
-  // Check if the block was already converted. If the block is detached,
-  // conservatively assume it is going to be deleted.
-  if (hasBeenConverted(block) || !block->getParent())
+  // Check if the block was already converted.
+  // * If the block is mapped in `conversionInfo`, it is a converted block.
+  // * If the block is detached, conservatively assume that it is going to be
+  //   deleted; it is likely the old block (before it was converted).
+  if (conversionInfo.count(block) || !block->getParent())
 return block;
   // If a converter wasn't provided, and the block wasn't already converted,
   // there is nothing we can do

[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Simplify `ArgConverter` state (PR #81462)

2024-02-12 Thread Matthias Springer via llvm-branch-commits

https://github.com/matthias-springer edited 
https://github.com/llvm/llvm-project/pull/81462
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/18.x: [LLD] [test] Avoid printing timestamps past INT32_MAX with llvm-readobj (#81463) (PR #81468)

2024-02-12 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/81468
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [AArch64] Improve cost model for legal subvec insert/extract (PR #81135)

2024-02-12 Thread Graham Hunter via llvm-branch-commits

https://github.com/huntergr-arm edited 
https://github.com/llvm/llvm-project/pull/81135
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/18.x: [LLD] [test] Avoid printing timestamps past INT32_MAX with llvm-readobj (#81463) (PR #81468)

2024-02-12 Thread via llvm-branch-commits

https://github.com/llvmbot updated 
https://github.com/llvm/llvm-project/pull/81468

>From 996b6d7194c6bc6dc4b9aa87bcca3525dafcaa03 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= 
Date: Mon, 12 Feb 2024 13:22:45 +0200
Subject: [PATCH] [LLD] [test] Avoid printing timestamps past INT32_MAX with
 llvm-readobj (#81463)

If llvm-readobj is built with a 32 bit time_t, it can't print such
timestamps correctly.

(cherry picked from commit 0bf4ff29816c0eead99ba576a2df2e3c4d214b1f)
---
 lld/test/COFF/timestamp.test | 29 +++--
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/lld/test/COFF/timestamp.test b/lld/test/COFF/timestamp.test
index c0658d6109811b..cc73af13c38ca6 100644
--- a/lld/test/COFF/timestamp.test
+++ b/lld/test/COFF/timestamp.test
@@ -4,19 +4,28 @@ RUN: lld-link %t.obj /debug /Brepro /entry:main /nodefaultlib 
/out:%t.1.exe
 RUN: lld-link %t.obj /debug /Brepro /entry:main /nodefaultlib /out:%t.2.exe
 RUN: lld-link %t.obj /debug /timestamp:0 /entry:main /nodefaultlib 
/out:%t.3.exe
 RUN: env SOURCE_DATE_EPOCH=0 lld-link %t.obj /debug /entry:main /nodefaultlib 
/out:%t.4.exe
-RUN: lld-link %t.obj /debug /timestamp:4294967295 /entry:main /nodefaultlib 
/out:%t.5.exe
-RUN: env SOURCE_DATE_EPOCH=4294967295 lld-link %t.obj /debug /entry:main 
/nodefaultlib /out:%t.6.exe
+# Test timestamps corresponding to INT32_TMAX
+RUN: lld-link %t.obj /debug /timestamp:2147483647 /entry:main /nodefaultlib 
/out:%t.5.exe
+RUN: env SOURCE_DATE_EPOCH=2147483647 lld-link %t.obj /debug /entry:main 
/nodefaultlib /out:%t.6.exe
+# Test that the command line option /timestamp has precedence over 
SOURCE_DATE_EPOCH
 RUN: env SOURCE_DATE_EPOCH=12345 lld-link %t.obj /debug /timestamp:0 
/entry:main /nodefaultlib /out:%t.7.exe
-RUN: env LLD_IN_TEST=1 not lld-link %t.obj /debug /timestamp:4294967296 
/entry:main /nodefaultlib /out:%t.8.exe 2>&1 | FileCheck %s --check-prefix=ERROR
-RUN: env SOURCE_DATE_EPOCH=4294967296 env LLD_IN_TEST=1 not lld-link %t.obj 
/debug /entry:main /nodefaultlib /out:%t.9.exe 2>&1 | FileCheck %s 
--check-prefix=ERROR2
+# Test timestamps corresponding to UINT32_TMAX
+RUN: lld-link %t.obj /debug /timestamp:4294967295 /entry:main /nodefaultlib 
/out:%t.8.exe
+RUN: env SOURCE_DATE_EPOCH=4294967295 lld-link %t.obj /debug /entry:main 
/nodefaultlib /out:%t.9.exe
+# Test that setting UINT32_MAX+1 as timestamp fails.
+RUN: env LLD_IN_TEST=1 not lld-link %t.obj /debug /timestamp:4294967296 
/entry:main /nodefaultlib /out:%t.10.exe 2>&1 | FileCheck %s 
--check-prefix=ERROR
+RUN: env SOURCE_DATE_EPOCH=4294967296 env LLD_IN_TEST=1 not lld-link %t.obj 
/debug /entry:main /nodefaultlib /out:%t.11.exe 2>&1 | FileCheck %s 
--check-prefix=ERROR2
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.1.exe | FileCheck 
%s --check-prefix=HASH
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.2.exe | FileCheck 
%s --check-prefix=HASH
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.3.exe | FileCheck 
%s --check-prefix=ZERO
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.4.exe | FileCheck 
%s --check-prefix=ZERO
-RUN: llvm-readobj --file-headers --coff-debug-directory %t.5.exe | FileCheck 
%s --check-prefix=MAX
-RUN: llvm-readobj --file-headers --coff-debug-directory %t.6.exe | FileCheck 
%s --check-prefix=MAX
+RUN: llvm-readobj --file-headers --coff-debug-directory %t.5.exe | FileCheck 
%s --check-prefix=LARGE
+RUN: llvm-readobj --file-headers --coff-debug-directory %t.6.exe | FileCheck 
%s --check-prefix=LARGE
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.7.exe | FileCheck 
%s --check-prefix=ZERO
 
+# Not inspecting %t.8.exe and %t.9.exe; llvm-readobj with a 32 bit time_t 
fails to print dates
+# past INT32_MAX correctly.
+
 HASH: ImageFileHeader {
 HASH: TimeDateStamp: [[STAMP:.*]]
 HASH: DebugDirectory [
@@ -27,10 +36,10 @@ ZERO: TimeDateStamp: 1970-01-01 00:00:00 (0x0)
 ZERO: DebugDirectory [
 ZERO: TimeDateStamp: 1970-01-01 00:00:00 (0x0)
 
-MAX: ImageFileHeader {
-MAX: TimeDateStamp: 2106-02-07 06:28:15 (0x)
-MAX: DebugDirectory [
-MAX: TimeDateStamp: 2106-02-07 06:28:15 (0x)
+LARGE: ImageFileHeader {
+LARGE: TimeDateStamp: 2038-01-19 03:14:07 (0x7FFF)
+LARGE: DebugDirectory [
+LARGE: TimeDateStamp: 2038-01-19 03:14:07 (0x7FFF)
 
 ERROR: error: invalid timestamp: 4294967296.  Expected 32-bit integer
 ERROR2: error: invalid SOURCE_DATE_EPOCH timestamp: 4294967296.  Expected 
32-bit integer

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


[llvm-branch-commits] [lld] release/18.x: [LLD] [test] Avoid printing timestamps past INT32_MAX with llvm-readobj (#81463) (PR #81468)

2024-02-12 Thread via llvm-branch-commits

llvmbot wrote:

@DavidSpickett What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/81468
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/18.x: [LLD] [test] Avoid printing timestamps past INT32_MAX with llvm-readobj (#81463) (PR #81468)

2024-02-12 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-lld

Author: None (llvmbot)


Changes

Backport 0bf4ff29816c0eead99ba576a2df2e3c4d214b1f

Requested by: @mstorsjo

---
Full diff: https://github.com/llvm/llvm-project/pull/81468.diff


1 Files Affected:

- (modified) lld/test/COFF/timestamp.test (+19-10) 


``diff
diff --git a/lld/test/COFF/timestamp.test b/lld/test/COFF/timestamp.test
index c0658d6109811b..cc73af13c38ca6 100644
--- a/lld/test/COFF/timestamp.test
+++ b/lld/test/COFF/timestamp.test
@@ -4,19 +4,28 @@ RUN: lld-link %t.obj /debug /Brepro /entry:main /nodefaultlib 
/out:%t.1.exe
 RUN: lld-link %t.obj /debug /Brepro /entry:main /nodefaultlib /out:%t.2.exe
 RUN: lld-link %t.obj /debug /timestamp:0 /entry:main /nodefaultlib 
/out:%t.3.exe
 RUN: env SOURCE_DATE_EPOCH=0 lld-link %t.obj /debug /entry:main /nodefaultlib 
/out:%t.4.exe
-RUN: lld-link %t.obj /debug /timestamp:4294967295 /entry:main /nodefaultlib 
/out:%t.5.exe
-RUN: env SOURCE_DATE_EPOCH=4294967295 lld-link %t.obj /debug /entry:main 
/nodefaultlib /out:%t.6.exe
+# Test timestamps corresponding to INT32_TMAX
+RUN: lld-link %t.obj /debug /timestamp:2147483647 /entry:main /nodefaultlib 
/out:%t.5.exe
+RUN: env SOURCE_DATE_EPOCH=2147483647 lld-link %t.obj /debug /entry:main 
/nodefaultlib /out:%t.6.exe
+# Test that the command line option /timestamp has precedence over 
SOURCE_DATE_EPOCH
 RUN: env SOURCE_DATE_EPOCH=12345 lld-link %t.obj /debug /timestamp:0 
/entry:main /nodefaultlib /out:%t.7.exe
-RUN: env LLD_IN_TEST=1 not lld-link %t.obj /debug /timestamp:4294967296 
/entry:main /nodefaultlib /out:%t.8.exe 2>&1 | FileCheck %s --check-prefix=ERROR
-RUN: env SOURCE_DATE_EPOCH=4294967296 env LLD_IN_TEST=1 not lld-link %t.obj 
/debug /entry:main /nodefaultlib /out:%t.9.exe 2>&1 | FileCheck %s 
--check-prefix=ERROR2
+# Test timestamps corresponding to UINT32_TMAX
+RUN: lld-link %t.obj /debug /timestamp:4294967295 /entry:main /nodefaultlib 
/out:%t.8.exe
+RUN: env SOURCE_DATE_EPOCH=4294967295 lld-link %t.obj /debug /entry:main 
/nodefaultlib /out:%t.9.exe
+# Test that setting UINT32_MAX+1 as timestamp fails.
+RUN: env LLD_IN_TEST=1 not lld-link %t.obj /debug /timestamp:4294967296 
/entry:main /nodefaultlib /out:%t.10.exe 2>&1 | FileCheck %s 
--check-prefix=ERROR
+RUN: env SOURCE_DATE_EPOCH=4294967296 env LLD_IN_TEST=1 not lld-link %t.obj 
/debug /entry:main /nodefaultlib /out:%t.11.exe 2>&1 | FileCheck %s 
--check-prefix=ERROR2
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.1.exe | FileCheck 
%s --check-prefix=HASH
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.2.exe | FileCheck 
%s --check-prefix=HASH
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.3.exe | FileCheck 
%s --check-prefix=ZERO
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.4.exe | FileCheck 
%s --check-prefix=ZERO
-RUN: llvm-readobj --file-headers --coff-debug-directory %t.5.exe | FileCheck 
%s --check-prefix=MAX
-RUN: llvm-readobj --file-headers --coff-debug-directory %t.6.exe | FileCheck 
%s --check-prefix=MAX
+RUN: llvm-readobj --file-headers --coff-debug-directory %t.5.exe | FileCheck 
%s --check-prefix=LARGE
+RUN: llvm-readobj --file-headers --coff-debug-directory %t.6.exe | FileCheck 
%s --check-prefix=LARGE
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.7.exe | FileCheck 
%s --check-prefix=ZERO
 
+# Not inspecting %t.8.exe and %t.9.exe; llvm-readobj with a 32 bit time_t 
fails to print dates
+# past INT32_MAX correctly.
+
 HASH: ImageFileHeader {
 HASH: TimeDateStamp: [[STAMP:.*]]
 HASH: DebugDirectory [
@@ -27,10 +36,10 @@ ZERO: TimeDateStamp: 1970-01-01 00:00:00 (0x0)
 ZERO: DebugDirectory [
 ZERO: TimeDateStamp: 1970-01-01 00:00:00 (0x0)
 
-MAX: ImageFileHeader {
-MAX: TimeDateStamp: 2106-02-07 06:28:15 (0x)
-MAX: DebugDirectory [
-MAX: TimeDateStamp: 2106-02-07 06:28:15 (0x)
+LARGE: ImageFileHeader {
+LARGE: TimeDateStamp: 2038-01-19 03:14:07 (0x7FFF)
+LARGE: DebugDirectory [
+LARGE: TimeDateStamp: 2038-01-19 03:14:07 (0x7FFF)
 
 ERROR: error: invalid timestamp: 4294967296.  Expected 32-bit integer
 ERROR2: error: invalid SOURCE_DATE_EPOCH timestamp: 4294967296.  Expected 
32-bit integer

``




https://github.com/llvm/llvm-project/pull/81468
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/18.x: [LLD] [test] Avoid printing timestamps past INT32_MAX with llvm-readobj (#81463) (PR #81468)

2024-02-12 Thread David Spickett via llvm-branch-commits

DavidSpickett wrote:

I've confirmed locally that this fixes the test as claimed, let's merge it.

https://github.com/llvm/llvm-project/pull/81468
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/18.x: [LLD] [test] Avoid printing timestamps past INT32_MAX with llvm-readobj (#81463) (PR #81468)

2024-02-12 Thread David Spickett via llvm-branch-commits

https://github.com/DavidSpickett approved this pull request.


https://github.com/llvm/llvm-project/pull/81468
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [TBAA] Use !tbaa for first accessed field if it is an exact match in offset and size. (PR #81313)

2024-02-12 Thread Florian Hahn via llvm-branch-commits

https://github.com/fhahn edited https://github.com/llvm/llvm-project/pull/81313
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [TBAA] Use !tbaa for first accessed field if it is an exact match in offset and size. (PR #81313)

2024-02-12 Thread Florian Hahn via llvm-branch-commits

fhahn wrote:

> lgtm
> 
> Maybe rephrase the commit message to something like:
> 
> ```
>  [tbaa] Use !tbaa for first accessed field if it is an exact match in offset 
> and size. 
> ```

Updated, thanks! It would be great if you could take another look at 
https://github.com/llvm/llvm-project/pull/81289 in case you missed my response 
to your comment, as this PR depends on 
https://github.com/llvm/llvm-project/pull/81289

https://github.com/llvm/llvm-project/pull/81313
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [SROA] Use !tbaa instead of !tbaa.struct if op matches field. (PR #81289)

2024-02-12 Thread via llvm-branch-commits

dobbelaj-snps wrote:

> > Hmm. 10 changes + 1 new usage of setAAMetaData, But only 4 relevant changes 
> > in tests.. That part of SROA seems to lack some testing ?
> 
> Yes, will add the missing coverage, just wanted to make sure this makes sense 
> in general beforehand

I think it makes sense.

For this one to go through, I think we need at least a testcase that triggers 
the new 'PStore->setAAMetaData'... case. (line 4582)


https://github.com/llvm/llvm-project/pull/81289
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] release/18.x: [libc++][print] Moves is_terminal to the dylib. (#80464) (PR #81410)

2024-02-12 Thread Louis Dionne via llvm-branch-commits

ldionne wrote:

Approved.

https://github.com/llvm/llvm-project/pull/81410
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [NFC][CallPromotionUtils]Extract a helper function versionCallSiteWithCond from versionCallSite (PR #81181)

2024-02-12 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 ready_for_review 
https://github.com/llvm/llvm-project/pull/81181
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [NFC][CallPromotionUtils]Extract a helper function versionCallSiteWithCond from versionCallSite (PR #81181)

2024-02-12 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: Mingming Liu (minglotus-6)


Changes

The parent patch is https://github.com/llvm/llvm-project/pull/81051

---
Full diff: https://github.com/llvm/llvm-project/pull/81181.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/Utils/CallPromotionUtils.cpp (+21-15) 


``diff
diff --git a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp 
b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
index 4e84927f1cfc90..d0cf0792eface0 100644
--- a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
+++ b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
@@ -188,10 +188,9 @@ static void createRetBitCast(CallBase &CB, Type *RetTy, 
CastInst **RetBitCast) {
 /// Predicate and clone the given call site.
 ///
 /// This function creates an if-then-else structure at the location of the call
-/// site. The "if" condition compares the call site's called value to the given
-/// callee. The original call site is moved into the "else" block, and a clone
-/// of the call site is placed in the "then" block. The cloned instruction is
-/// returned.
+/// site. The "if" condition is specified by `Cond`.
+/// The original call site is moved into the "else" block, and a clone of the
+/// call site is placed in the "then" block. The cloned instruction is 
returned.
 ///
 /// For example, the call instruction below:
 ///
@@ -202,7 +201,6 @@ static void createRetBitCast(CallBase &CB, Type *RetTy, 
CastInst **RetBitCast) {
 /// Is replace by the following:
 ///
 ///   orig_bb:
-/// %cond = icmp eq i32 ()* %ptr, @func
 /// br i1 %cond, %then_bb, %else_bb
 ///
 ///   then_bb:
@@ -232,7 +230,6 @@ static void createRetBitCast(CallBase &CB, Type *RetTy, 
CastInst **RetBitCast) {
 /// Is replace by the following:
 ///
 ///   orig_bb:
-/// %cond = icmp eq i32 ()* %ptr, @func
 /// br i1 %cond, %then_bb, %else_bb
 ///
 ///   then_bb:
@@ -267,7 +264,6 @@ static void createRetBitCast(CallBase &CB, Type *RetTy, 
CastInst **RetBitCast) {
 /// Is replaced by the following:
 ///
 ///   cond_bb:
-/// %cond = icmp eq i32 ()* %ptr, @func
 /// br i1 %cond, %then_bb, %orig_bb
 ///
 ///   then_bb:
@@ -280,19 +276,13 @@ static void createRetBitCast(CallBase &CB, Type *RetTy, 
CastInst **RetBitCast) {
 /// ; The original call instruction stays in its original block.
 /// %t0 = musttail call i32 %ptr()
 /// ret %t0
-CallBase &llvm::versionCallSite(CallBase &CB, Value *Callee,
-MDNode *BranchWeights) {
+static CallBase &versionCallSiteWithCond(CallBase &CB, Value *Cond,
+ MDNode *BranchWeights) {
 
   IRBuilder<> Builder(&CB);
   CallBase *OrigInst = &CB;
   BasicBlock *OrigBlock = OrigInst->getParent();
 
-  // Create the compare. The called value and callee must have the same type to
-  // be compared.
-  if (CB.getCalledOperand()->getType() != Callee->getType())
-Callee = Builder.CreateBitCast(Callee, CB.getCalledOperand()->getType());
-  auto *Cond = Builder.CreateICmpEQ(CB.getCalledOperand(), Callee);
-
   if (OrigInst->isMustTailCall()) {
 // Create an if-then structure. The original instruction stays in its 
block,
 // and a clone of the original instruction is placed in the "then" block.
@@ -380,6 +370,22 @@ CallBase &llvm::versionCallSite(CallBase &CB, Value 
*Callee,
   return *NewInst;
 }
 
+// Predicate and clone the given call site usingc condition `CB.callee ==
+// Callee`. See the comment `versionCallSiteWithCond` for the transformation.
+CallBase &llvm::versionCallSite(CallBase &CB, Value *Callee,
+MDNode *BranchWeights) {
+
+  IRBuilder<> Builder(&CB);
+
+  // Create the compare. The called value and callee must have the same type to
+  // be compared.
+  if (CB.getCalledOperand()->getType() != Callee->getType())
+Callee = Builder.CreateBitCast(Callee, CB.getCalledOperand()->getType());
+  auto *Cond = Builder.CreateICmpEQ(CB.getCalledOperand(), Callee);
+
+  return versionCallSiteWithCond(CB, Cond, BranchWeights);
+}
+
 bool llvm::isLegalToPromote(const CallBase &CB, Function *Callee,
 const char **FailureReason) {
   assert(!CB.getCalledFunction() && "Only indirect call sites can be 
promoted");

``




https://github.com/llvm/llvm-project/pull/81181
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [NFC][CallPromotionUtils]Extract a helper function versionCallSiteWithCond from versionCallSite (PR #81181)

2024-02-12 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/81181
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [CallPromotionUtils]Implement conditional indirect call promotion with vtable-based comparison (PR #81378)

2024-02-12 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 updated 
https://github.com/llvm/llvm-project/pull/81378

>From ac5dc1bf77b67cbf0aa5e2c8fb6a7ce0080fb501 Mon Sep 17 00:00:00 2001
From: mingmingl 
Date: Sat, 10 Feb 2024 12:03:25 -0800
Subject: [PATCH 1/2] [CallPromotionUtils]Implement conditional indirect call
 promotion with vtable-based comparison

---
 .../Transforms/Utils/CallPromotionUtils.h |  50 ++-
 .../Transforms/Utils/CallPromotionUtils.cpp   |  64 -
 .../Utils/CallPromotionUtilsTest.cpp  | 127 ++
 3 files changed, 233 insertions(+), 8 deletions(-)

diff --git a/llvm/include/llvm/Transforms/Utils/CallPromotionUtils.h 
b/llvm/include/llvm/Transforms/Utils/CallPromotionUtils.h
index fcb384ec361339..5f3a71206876c6 100644
--- a/llvm/include/llvm/Transforms/Utils/CallPromotionUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/CallPromotionUtils.h
@@ -14,10 +14,17 @@
 #ifndef LLVM_TRANSFORMS_UTILS_CALLPROMOTIONUTILS_H
 #define LLVM_TRANSFORMS_UTILS_CALLPROMOTIONUTILS_H
 
+#include 
+
+#include "llvm/ADT/ArrayRef.h"
+
 namespace llvm {
+class Constant;
 class CallBase;
 class CastInst;
 class Function;
+class GlobalVariable;
+class Instruction;
 class MDNode;
 class Value;
 
@@ -41,7 +48,9 @@ bool isLegalToPromote(const CallBase &CB, Function *Callee,
 CallBase &promoteCall(CallBase &CB, Function *Callee,
   CastInst **RetBitCast = nullptr);
 
-/// Promote the given indirect call site to conditionally call \p Callee.
+/// Promote the given indirect call site to conditionally call \p Callee. The
+/// promoted direct call instruction is predicated on `CB.getCalledOperand() ==
+/// Callee`.
 ///
 /// This function creates an if-then-else structure at the location of the call
 /// site. The original call site is moved into the "else" block. A clone of the
@@ -51,6 +60,31 @@ CallBase &promoteCall(CallBase &CB, Function *Callee,
 CallBase &promoteCallWithIfThenElse(CallBase &CB, Function *Callee,
 MDNode *BranchWeights = nullptr);
 
+/// This is similar to `promoteCallWithIfThenElse` except that the condition to
+/// promote a virtual call is that \p VPtr is the same as any of \p
+/// AddressPoints.
+///
+/// This function is expected to be used on virtual calls (a subset of indirect
+/// calls). \p VPtr is the virtual table address stored in the objects, and
+/// \p AddressPoints contains address points of vtables to be compared with.
+///
+/// It's the responsibility of caller to guarantee the transformation
+/// correctness (by specifying \p VPtr and \p AddressPoints properly).
+///
+/// This function doesn't sink the address-calculation instructions of indirect
+/// callee to the indirect call fallback. The subsequent passes (e.g.
+/// inst-combine) should sink them if possible and handle the sink of debug
+/// intrinsics together.
+CallBase &promoteCallWithVTableCmp(CallBase &CB, Instruction *VPtr,
+   Function *Callee,
+   ArrayRef AddressPoints,
+   MDNode *BranchWeights);
+
+/// Returns a constant representing the vtable's address point specified by the
+/// offset. Caller should ensure \p AddressPointOffset is valid.
+Constant *getVTableAddressPointOffset(GlobalVariable *VTable,
+  uint32_t AddressPointOffset);
+
 /// Try to promote (devirtualize) a virtual call on an Alloca. Return true on
 /// success.
 ///
@@ -74,13 +108,17 @@ CallBase &promoteCallWithIfThenElse(CallBase &CB, Function 
*Callee,
 ///
 bool tryPromoteCall(CallBase &CB);
 
+/// Predicate and clone the given call site using the given condition.
+CallBase &versionCallSiteWithCond(CallBase &CB, Value *Cond,
+  MDNode *BranchWeights);
+
 /// Predicate and clone the given call site.
 ///
-/// This function creates an if-then-else structure at the location of the call
-/// site. The "if" condition compares the call site's called value to the given
-/// callee. The original call site is moved into the "else" block, and a clone
-/// of the call site is placed in the "then" block. The cloned instruction is
-/// returned.
+/// This function creates an if-then-else structure at the location of the
+/// call site. The "if" condition compares the call site's called value to
+/// the given callee. The original call site is moved into the "else" block,
+/// and a clone of the call site is placed in the "then" block. The cloned
+/// instruction is returned.
 CallBase &versionCallSite(CallBase &CB, Value *Callee, MDNode *BranchWeights);
 
 } // end namespace llvm
diff --git a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp 
b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
index d0cf0792eface0..ea855b9a4d8416 100644
--- a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
+++ b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
@@ -12,9 +12,11 @@
 
//===

[llvm-branch-commits] [llvm] [CallPromotionUtils]Implement conditional indirect call promotion with vtable-based comparison (PR #81378)

2024-02-12 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 updated 
https://github.com/llvm/llvm-project/pull/81378

>From ac5dc1bf77b67cbf0aa5e2c8fb6a7ce0080fb501 Mon Sep 17 00:00:00 2001
From: mingmingl 
Date: Sat, 10 Feb 2024 12:03:25 -0800
Subject: [PATCH 1/3] [CallPromotionUtils]Implement conditional indirect call
 promotion with vtable-based comparison

---
 .../Transforms/Utils/CallPromotionUtils.h |  50 ++-
 .../Transforms/Utils/CallPromotionUtils.cpp   |  64 -
 .../Utils/CallPromotionUtilsTest.cpp  | 127 ++
 3 files changed, 233 insertions(+), 8 deletions(-)

diff --git a/llvm/include/llvm/Transforms/Utils/CallPromotionUtils.h 
b/llvm/include/llvm/Transforms/Utils/CallPromotionUtils.h
index fcb384ec361339..5f3a71206876c6 100644
--- a/llvm/include/llvm/Transforms/Utils/CallPromotionUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/CallPromotionUtils.h
@@ -14,10 +14,17 @@
 #ifndef LLVM_TRANSFORMS_UTILS_CALLPROMOTIONUTILS_H
 #define LLVM_TRANSFORMS_UTILS_CALLPROMOTIONUTILS_H
 
+#include 
+
+#include "llvm/ADT/ArrayRef.h"
+
 namespace llvm {
+class Constant;
 class CallBase;
 class CastInst;
 class Function;
+class GlobalVariable;
+class Instruction;
 class MDNode;
 class Value;
 
@@ -41,7 +48,9 @@ bool isLegalToPromote(const CallBase &CB, Function *Callee,
 CallBase &promoteCall(CallBase &CB, Function *Callee,
   CastInst **RetBitCast = nullptr);
 
-/// Promote the given indirect call site to conditionally call \p Callee.
+/// Promote the given indirect call site to conditionally call \p Callee. The
+/// promoted direct call instruction is predicated on `CB.getCalledOperand() ==
+/// Callee`.
 ///
 /// This function creates an if-then-else structure at the location of the call
 /// site. The original call site is moved into the "else" block. A clone of the
@@ -51,6 +60,31 @@ CallBase &promoteCall(CallBase &CB, Function *Callee,
 CallBase &promoteCallWithIfThenElse(CallBase &CB, Function *Callee,
 MDNode *BranchWeights = nullptr);
 
+/// This is similar to `promoteCallWithIfThenElse` except that the condition to
+/// promote a virtual call is that \p VPtr is the same as any of \p
+/// AddressPoints.
+///
+/// This function is expected to be used on virtual calls (a subset of indirect
+/// calls). \p VPtr is the virtual table address stored in the objects, and
+/// \p AddressPoints contains address points of vtables to be compared with.
+///
+/// It's the responsibility of caller to guarantee the transformation
+/// correctness (by specifying \p VPtr and \p AddressPoints properly).
+///
+/// This function doesn't sink the address-calculation instructions of indirect
+/// callee to the indirect call fallback. The subsequent passes (e.g.
+/// inst-combine) should sink them if possible and handle the sink of debug
+/// intrinsics together.
+CallBase &promoteCallWithVTableCmp(CallBase &CB, Instruction *VPtr,
+   Function *Callee,
+   ArrayRef AddressPoints,
+   MDNode *BranchWeights);
+
+/// Returns a constant representing the vtable's address point specified by the
+/// offset. Caller should ensure \p AddressPointOffset is valid.
+Constant *getVTableAddressPointOffset(GlobalVariable *VTable,
+  uint32_t AddressPointOffset);
+
 /// Try to promote (devirtualize) a virtual call on an Alloca. Return true on
 /// success.
 ///
@@ -74,13 +108,17 @@ CallBase &promoteCallWithIfThenElse(CallBase &CB, Function 
*Callee,
 ///
 bool tryPromoteCall(CallBase &CB);
 
+/// Predicate and clone the given call site using the given condition.
+CallBase &versionCallSiteWithCond(CallBase &CB, Value *Cond,
+  MDNode *BranchWeights);
+
 /// Predicate and clone the given call site.
 ///
-/// This function creates an if-then-else structure at the location of the call
-/// site. The "if" condition compares the call site's called value to the given
-/// callee. The original call site is moved into the "else" block, and a clone
-/// of the call site is placed in the "then" block. The cloned instruction is
-/// returned.
+/// This function creates an if-then-else structure at the location of the
+/// call site. The "if" condition compares the call site's called value to
+/// the given callee. The original call site is moved into the "else" block,
+/// and a clone of the call site is placed in the "then" block. The cloned
+/// instruction is returned.
 CallBase &versionCallSite(CallBase &CB, Value *Callee, MDNode *BranchWeights);
 
 } // end namespace llvm
diff --git a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp 
b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
index d0cf0792eface0..ea855b9a4d8416 100644
--- a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
+++ b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
@@ -12,9 +12,11 @@
 
//===

[llvm-branch-commits] [llvm] [CallPromotionUtils]Implement conditional indirect call promotion with vtable-based comparison (PR #81378)

2024-02-12 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/81378
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [RISCV] Support select optimization (PR #80124)

2024-02-12 Thread Craig Topper via llvm-branch-commits


@@ -445,6 +450,9 @@ void RISCVPassConfig::addIRPasses() {
 if (EnableLoopDataPrefetch)
   addPass(createLoopDataPrefetchPass());
 
+if (EnableSelectOpt && getOptLevel() == CodeGenOptLevel::Aggressive)

topperc wrote:

Shoudl this be after addIRPasses like it is for AArch64?

https://github.com/llvm/llvm-project/pull/80124
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [RISCV] Support select optimization (PR #80124)

2024-02-12 Thread Craig Topper via llvm-branch-commits

https://github.com/topperc edited 
https://github.com/llvm/llvm-project/pull/80124
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [CallPromotionUtils]Implement conditional indirect call promotion with vtable-based comparison (PR #81378)

2024-02-12 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 ready_for_review 
https://github.com/llvm/llvm-project/pull/81378
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [CallPromotionUtils]Implement conditional indirect call promotion with vtable-based comparison (PR #81378)

2024-02-12 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: Mingming Liu (minglotus-6)


Changes

* Given the code sequence
   ```
   bb:
 %vtable = load ptr, ptr %d, !prof !8
 %vfn = getelementptr inbounds ptr, ptr %vtable, i64 1
 %1 = load ptr, ptr %vfn
 %call = tail call i32 %1(ptr %d), !prof !9
  ```
   The transformation looks like

   ```
   bb:
%vtable = load ptr, ptr %d, align 8
%vfn = getelementptr inbounds i8, ptr %vtable, i64 8  <-- Inst 1
%func-addr = load ptr, ptr %vfn, align 8  <-- Inst 2
# compare loaded pointers with address point of vtables
%1 = icmp eq ptr %vtable, getelementptr inbounds ({ [4 x ptr] }, ptr @_ZTV, i64 0, i32 0, i64 2)
br i1 %1, label %if.true.direct_targ, label %if.false.orig_indirect, !prof 
!18

  if.true.direct_targ:  ; preds = %entry
%2 = tail call i32 @(ptr nonnull %d)
br label %if.end.icp

  if.false.orig_indirect:   ; preds = %entry
%call = tail call i32 %func-addr(ptr nonnull %d)
br label %if.end.icp

  if.end.icp:   ; preds = 
%if.false.orig_indirect, %if.true.direct_targ
%4 = phi i32 [ %call, %if.false.orig_indirect ], [ %2, %if.true.direct_targ 
]

   ```
   It's intentional that `Inst 1` and `Inst2` remains in `bb` (not in 
`if.false.orig_indirect`). Subsequent pass (notably `instcombine` would sink 
them (and handles debug intrinsics properly) if possible.

* The parent patch is https://github.com/llvm/llvm-project/pull/81181

---
Full diff: https://github.com/llvm/llvm-project/pull/81378.diff


3 Files Affected:

- (modified) llvm/include/llvm/Transforms/Utils/CallPromotionUtils.h (+43-6) 
- (modified) llvm/lib/Transforms/Utils/CallPromotionUtils.cpp (+62-2) 
- (modified) llvm/unittests/Transforms/Utils/CallPromotionUtilsTest.cpp (+119) 


``diff
diff --git a/llvm/include/llvm/Transforms/Utils/CallPromotionUtils.h 
b/llvm/include/llvm/Transforms/Utils/CallPromotionUtils.h
index fcb384ec361339..32b252d132c04c 100644
--- a/llvm/include/llvm/Transforms/Utils/CallPromotionUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/CallPromotionUtils.h
@@ -14,10 +14,16 @@
 #ifndef LLVM_TRANSFORMS_UTILS_CALLPROMOTIONUTILS_H
 #define LLVM_TRANSFORMS_UTILS_CALLPROMOTIONUTILS_H
 
+#include 
+
 namespace llvm {
+template  class ArrayRef;
+class Constant;
 class CallBase;
 class CastInst;
 class Function;
+class GlobalVariable;
+class Instruction;
 class MDNode;
 class Value;
 
@@ -41,7 +47,9 @@ bool isLegalToPromote(const CallBase &CB, Function *Callee,
 CallBase &promoteCall(CallBase &CB, Function *Callee,
   CastInst **RetBitCast = nullptr);
 
-/// Promote the given indirect call site to conditionally call \p Callee.
+/// Promote the given indirect call site to conditionally call \p Callee. The
+/// promoted direct call instruction is predicated on `CB.getCalledOperand() ==
+/// Callee`.
 ///
 /// This function creates an if-then-else structure at the location of the call
 /// site. The original call site is moved into the "else" block. A clone of the
@@ -51,6 +59,31 @@ CallBase &promoteCall(CallBase &CB, Function *Callee,
 CallBase &promoteCallWithIfThenElse(CallBase &CB, Function *Callee,
 MDNode *BranchWeights = nullptr);
 
+/// This is similar to `promoteCallWithIfThenElse` except that the condition to
+/// promote a virtual call is that \p VPtr is the same as any of \p
+/// AddressPoints.
+///
+/// This function is expected to be used on virtual calls (a subset of indirect
+/// calls). \p VPtr is the virtual table address stored in the objects, and
+/// \p AddressPoints contains address points of vtables to be compared with.
+///
+/// It's the responsibility of caller to guarantee the transformation
+/// correctness (by specifying \p VPtr and \p AddressPoints properly).
+///
+/// This function doesn't sink the address-calculation instructions of indirect
+/// callee to the indirect call fallback. The subsequent passes (e.g.
+/// inst-combine) should sink them if possible and handle the sink of debug
+/// intrinsics together.
+CallBase &promoteCallWithVTableCmp(CallBase &CB, Instruction *VPtr,
+   Function *Callee,
+   ArrayRef AddressPoints,
+   MDNode *BranchWeights);
+
+/// Returns a constant representing the vtable's address point specified by the
+/// offset. Caller should ensure \p AddressPointOffset is valid.
+Constant *getVTableAddressPointOffset(GlobalVariable *VTable,
+  uint32_t AddressPointOffset);
+
 /// Try to promote (devirtualize) a virtual call on an Alloca. Return true on
 /// success.
 ///
@@ -74,13 +107,17 @@ CallBase &promoteCallWithIfThenElse(CallBase &CB, Function 
*Callee,
 ///
 bool tryPromoteCall(CallBase &CB);
 
+/// Predicate and clone the given call site using the given condition.

[llvm-branch-commits] [OpenMP][MLIR] Add new partial_map and members_index arguments to omp.map_info operations to help support record type mapping (PR #81509)

2024-02-12 Thread via llvm-branch-commits

https://github.com/agozillon created 
https://github.com/llvm/llvm-project/pull/81509

This PR adds two new fields to omp.map_info, one BoolAttr and one I64ArrayAttr.

The BoolAttr is named partial_map, and is a flag that indicates if the record 
type captured by
the map_info operation is a partial map, or if it is mapped in its entirety, 
this currently helps
the later lowering determine the type of map entries that need to be generated.

The I64ArrayAttr named members_index is intended to track the placement of each 
member
map_info operations (and by extension mapped member variable) placement in the 
parent
record type. This may need to be extended to an N-D array for nested member 
mapping.



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


[llvm-branch-commits] [OpenMP][MLIR] Extend explicit derived type member mapping support for OpenMP dialects lowering to LLVM-IR (PR #81510)

2024-02-12 Thread via llvm-branch-commits

https://github.com/agozillon created 
https://github.com/llvm/llvm-project/pull/81510

This patch seeks to refactor slightly and extend the current record type map
support that was put in place for Fortran's descriptor types to handle explicit
member mapping for record types at a single level of depth (the case of explicit
mapping of nested record types is currently unsupported).

This patch seeks to support this by extending the OpenMPToLLVMIRTranslation 
phase
to more generally support record types, building on the prior groundwork in the
Fortran allocatables/pointers patch. It now supports different kinds of record 
type
mapping, in this case full record type mapping and then explicit member mapping
in which there is a special case for certain types when mapped individually to 
not
require any parent map link in the kernel argument structure. To facilitate this
required:
   *  The movement of the setting of the map flag type "ptr_and_obj" to 
respective
 frontends, now supporting it as a possible flag that can be read and 
printed
 in mlir form. Some minor changes to declare target map type setting was
 neccesary for this.
   * The addition of a member index array operand, which tracks the position
   of the member in the parent, required for caclulating the appropriate 
size
   to offload to the target, alongside the parents offload pointer (always 
the
   first member currently being mapped).
   * A partial mapping attribute operand, to indicate if the entire record type 
is
   being mapped or just member components, aiding the ability to lower
   record types in the different manners that are possible.
   * Refactoring bounds calculation for record types and general arrays to one
   location (as well as load/store generation prior to assigning to the 
kernel
   argument structure), as a side affect enter/exit/update/data mapping
   should now be more correct and fully support bounds mapping, previously
   this would have only worked for target.



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


[llvm-branch-commits] [Flang][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-12 Thread via llvm-branch-commits

https://github.com/agozillon created 
https://github.com/llvm/llvm-project/pull/81511

This patch is one in a series of four patches that seeks to refactor
slightly and extend the current record type map support that was
put in place for Fortran's descriptor types to handle explicit
member mapping for record types at a single level of depth.

For example, the below case where two members of a Fortran
derived type are mapped explicitly:


  type :: scalar_and_array
real(4) :: real
integer(4) :: array(10)
integer(4) :: int
  end type scalar_and_array
  type(scalar_and_array) :: scalar_arr

  !$omp target map(tofrom: scalar_arr%int, scalar_arr%real)


Current cases of derived type mapping left for future work are:
  > explicit member mapping of nested members (e.g. two layers of
 record types where we explicitly map a member from the internal
 record type)
  > Fortran's automagical mapping of all elements and nested elements
 of a derived type
  > explicit member mapping of a derived type and then constituient members
 (redundant in Fortran due to former case but still legal as far as I am 
aware)
  > explicit member mapping of a record type (may be handled reasonably, just
 not fully tested in this iteration)
  > explicit member mapping for Fortran allocatable types (a variation of nested
 record types)

This patch seeks to support this by extending the Flang-new OpenMP lowering to
support generation of this newly required information, creating the neccessary
parent <-to-> member map_info links, calculating the member indices and
setting if it's a partial map.

The OMPDescriptorMapInfoGen pass has also been generalized into a map
finalization phase, now named OMPMapInfoFinalization. This pass was extended
to support the insertion of member maps into the BlockArg and MapOperands of
relevant map carrying operations. Similar to the method in which descriptor 
types
are expanded and constituient members inserted.



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


[llvm-branch-commits] [OpenMP][MLIR] Extend explicit derived type member mapping support for OpenMP dialects lowering to LLVM-IR (PR #81510)

2024-02-12 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-mlir-openmp

@llvm/pr-subscribers-mlir

Author: None (agozillon)


Changes

This patch seeks to refactor slightly and extend the current record type map
support that was put in place for Fortran's descriptor types to handle explicit
member mapping for record types at a single level of depth (the case of explicit
mapping of nested record types is currently unsupported).

This patch seeks to support this by extending the OpenMPToLLVMIRTranslation 
phase
to more generally support record types, building on the prior groundwork in the
Fortran allocatables/pointers patch. It now supports different kinds of record 
type
mapping, in this case full record type mapping and then explicit member mapping
in which there is a special case for certain types when mapped individually to 
not
require any parent map link in the kernel argument structure. To facilitate this
required:
   *  The movement of the setting of the map flag type "ptr_and_obj" to 
respective
 frontends, now supporting it as a possible flag that can be read and 
printed
 in mlir form. Some minor changes to declare target map type setting was
 neccesary for this.
   * The addition of a member index array operand, which tracks the position
   of the member in the parent, required for caclulating the appropriate 
size
   to offload to the target, alongside the parents offload pointer (always 
the
   first member currently being mapped).
   * A partial mapping attribute operand, to indicate if the entire record type 
is
   being mapped or just member components, aiding the ability to lower
   record types in the different manners that are possible.
   * Refactoring bounds calculation for record types and general arrays to one
   location (as well as load/store generation prior to assigning to the 
kernel
   argument structure), as a side affect enter/exit/update/data mapping
   should now be more correct and fully support bounds mapping, previously
   this would have only worked for target.


---

Patch is 49.34 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/81510.diff


4 Files Affected:

- (modified) 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+300-204) 
- (modified) 
mlir/test/Target/LLVMIR/omptarget-fortran-allocatable-types-host.mlir (+14-16) 
- (modified) mlir/test/Target/LLVMIR/omptarget-llvm.mlir (+27-22) 
- (added) mlir/test/Target/LLVMIR/omptarget-record-type-mapping-host.mlir (+63) 


``diff
diff --git 
a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp 
b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index 79956f82ed141a..1ba8099135c35f 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -1750,9 +1750,9 @@ void collectMapDataFromMapOperands(MapInfoData &mapData,
 
   mapData.BaseType.push_back(
   moduleTranslation.convertType(mapOp.getVarType()));
-  mapData.Sizes.push_back(getSizeInBytes(
-  dl, mapOp.getVarType(), mapOp, mapData.BasePointers.back(),
-  mapData.BaseType.back(), builder, moduleTranslation));
+  mapData.Sizes.push_back(
+  getSizeInBytes(dl, mapOp.getVarType(), mapOp, 
mapData.Pointers.back(),
+ mapData.BaseType.back(), builder, moduleTranslation));
   mapData.MapClause.push_back(mapOp.getOperation());
   mapData.Types.push_back(
   llvm::omp::OpenMPOffloadMappingFlags(mapOp.getMapType().value()));
@@ -1783,6 +1783,98 @@ void collectMapDataFromMapOperands(MapInfoData &mapData,
   }
 }
 
+static int getMapDataMemberIdx(MapInfoData &mapData,
+   mlir::omp::MapInfoOp memberOp) {
+  int memberDataIdx = -1;
+  for (size_t i = 0; i < mapData.MapClause.size(); ++i) {
+if (mapData.MapClause[i] == memberOp)
+  memberDataIdx = i;
+  }
+  return memberDataIdx;
+}
+
+static mlir::omp::MapInfoOp
+getFirstOrLastMappedMemberPtr(mlir::omp::MapInfoOp mapInfo, bool first) {
+  // Only 1 member has been mapped, we can return it.
+  if (mapInfo.getMembersIndex()->size() == 1)
+if (auto mapOp = mlir::dyn_cast(
+mapInfo.getMembers()[0].getDefiningOp()))
+  return mapOp;
+
+  int64_t curPos =
+  mapInfo.getMembersIndex()->begin()->cast().getInt();
+
+  int64_t idx = 1, curIdx = 0, memberPlacement = 0;
+  for (const auto *iter = std::next(mapInfo.getMembersIndex()->begin());
+   iter != mapInfo.getMembersIndex()->end(); iter++) {
+memberPlacement = iter->cast().getInt();
+if (first) {
+  if (memberPlacement < curPos) {
+curIdx = idx;
+curPos = memberPlacement;
+  }
+} else {
+  if (memberPlacement > curPos) {
+curIdx = idx;
+curPos = memberPlacement;
+  }
+}
+idx++;
+  }
+
+  if (auto mapOp = mlir::dyn_cast(
+  m

[llvm-branch-commits] [OpenMP][MLIR] Add new partial_map and members_index arguments to omp.map_info operations to help support record type mapping (PR #81509)

2024-02-12 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-mlir

Author: None (agozillon)


Changes

This PR adds two new fields to omp.map_info, one BoolAttr and one I64ArrayAttr.

The BoolAttr is named partial_map, and is a flag that indicates if the record 
type captured by
the map_info operation is a partial map, or if it is mapped in its entirety, 
this currently helps
the later lowering determine the type of map entries that need to be generated.

The I64ArrayAttr named members_index is intended to track the placement of each 
member
map_info operations (and by extension mapped member variable) placement in the 
parent
record type. This may need to be extended to an N-D array for nested member 
mapping.


---
Full diff: https://github.com/llvm/llvm-project/pull/81509.diff


3 Files Affected:

- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+12-4) 
- (modified) mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp (+7) 
- (modified) mlir/test/Dialect/OpenMP/ops.mlir (+22-6) 


``diff
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index ca36350548577..cdfe6a8f8edf4 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -1195,10 +1195,12 @@ def MapInfoOp : OpenMP_Op<"map_info", 
[AttrSizedOperandSegments]> {
TypeAttr:$var_type,
Optional:$var_ptr_ptr,
Variadic:$members,
+   OptionalAttr:$members_index,
Variadic:$bounds, /* rank-0 to 
rank-{n-1} */
OptionalAttr:$map_type,
OptionalAttr:$map_capture_type,
-   OptionalAttr:$name);
+   OptionalAttr:$name,
+   DefaultValuedAttr:$partial_map);
   let results = (outs OpenMP_PointerLikeType:$omp_ptr);
 
   let description = [{
@@ -1234,10 +1236,14 @@ def MapInfoOp : OpenMP_Op<"map_info", 
[AttrSizedOperandSegments]> {
 - `var_type`: The type of the variable to copy.
 - `var_ptr_ptr`: Used when the variable copied is a member of a class, 
structure
   or derived type and refers to the originating struct.
-- `members`:  Used to indicate mapped child members for the current 
MapInfoOp, 
+- `members`: Used to indicate mapped child members for the current 
MapInfoOp, 
represented as other MapInfoOp's, utilised in cases where a parent 
structure 
type and members of the structure type are being mapped at the same 
time. 
-   For example: map(to: parent, parent->member, parent->member2[:10])  
+   For example: map(to: parent, parent->member, parent->member2[:10])
+- `members_index`: Used to indicate the ordering of members within the 
containing 
+   parent (generally a record type such as a structure, class or derived 
type),
+   e.g. struct {int x, float y, double z}, x would be 0, y would be 1, and 
z 
+   would be 2. This aids the mapping 
 - `bounds`: Used when copying slices of array's, pointers or pointer 
members of
objects (e.g. derived types or classes), indicates the bounds to be 
copied
of the variable. When it's an array slice it is in rank order where 
rank 0
@@ -1248,6 +1254,8 @@ def MapInfoOp : OpenMP_Op<"map_info", 
[AttrSizedOperandSegments]> {
 - 'map_capture_type': Capture type for the variable e.g. this, byref, 
byvalue, byvla
this can affect how the variable is lowered.
 - `name`: Holds the name of variable as specified in user clause 
(including bounds).
+- `partial_map`: The record type being mapped will not be mapped in its 
entirety, 
+   it may be used however, in a mapping to bind it's mapped components 
together.
   }];
 
   let assemblyFormat = [{
@@ -1256,7 +1264,7 @@ def MapInfoOp : OpenMP_Op<"map_info", 
[AttrSizedOperandSegments]> {
 `var_ptr_ptr` `(` $var_ptr_ptr `:` type($var_ptr_ptr) `)`
   | `map_clauses` `(` custom($map_type) `)`
   | `capture` `(` custom($map_capture_type) `)`
-  | `members` `(` $members `:` type($members) `)`
+  | `members` `(` $members `:` type($members) `:` $members_index `)`
   | `bounds` `(` $bounds `)`
 ) `->` type($omp_ptr) attr-dict
   }];
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp 
b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 381f17d080419..7d166b1f78bff 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -709,6 +709,9 @@ static ParseResult parseMapClause(OpAsmParser &parser, 
IntegerAttr &mapType) {
 if (mapTypeMod == "delete")
   mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_DELETE;
 
+if (mapTypeMod == "ptr_and_obj")
+  mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_PTR_AND_OBJ;
+
 return success();
   };
 
@@ -745,6 +748,10 @@ static void printMapClause(OpAsmPrinter &p, Oper

[llvm-branch-commits] [Flang][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-12 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-fir-hlfir

Author: None (agozillon)


Changes

This patch is one in a series of four patches that seeks to refactor
slightly and extend the current record type map support that was
put in place for Fortran's descriptor types to handle explicit
member mapping for record types at a single level of depth.

For example, the below case where two members of a Fortran
derived type are mapped explicitly:


  type :: scalar_and_array
real(4) :: real
integer(4) :: array(10)
integer(4) :: int
  end type scalar_and_array
  type(scalar_and_array) :: scalar_arr

  !$omp target map(tofrom: scalar_arr%int, scalar_arr%real)


Current cases of derived type mapping left for future work are:
  > explicit member mapping of nested members (e.g. two layers of
 record types where we explicitly map a member from the internal
 record type)
  > Fortran's automagical mapping of all elements and nested elements
 of a derived type
  > explicit member mapping of a derived type and then constituient members
 (redundant in Fortran due to former case but still legal as far as I am 
aware)
  > explicit member mapping of a record type (may be handled reasonably, just
 not fully tested in this iteration)
  > explicit member mapping for Fortran allocatable types (a variation of 
nested
 record types)

This patch seeks to support this by extending the Flang-new OpenMP lowering to
support generation of this newly required information, creating the neccessary
parent <-to-> member map_info links, calculating the member indices and
setting if it's a partial map.

The OMPDescriptorMapInfoGen pass has also been generalized into a map
finalization phase, now named OMPMapInfoFinalization. This pass was extended
to support the insertion of member maps into the BlockArg and MapOperands of
relevant map carrying operations. Similar to the method in which descriptor 
types
are expanded and constituient members inserted.


---

Patch is 98.14 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/81511.diff


20 Files Affected:

- (modified) flang/docs/OpenMP-descriptor-management.md (+2-2) 
- (modified) flang/include/flang/Optimizer/Transforms/Passes.h (+1-1) 
- (modified) flang/include/flang/Optimizer/Transforms/Passes.td (+3-3) 
- (modified) flang/include/flang/Tools/CLOptions.inc (+1-1) 
- (modified) flang/lib/Lower/OpenMP.cpp (+210-25) 
- (modified) flang/lib/Optimizer/Transforms/CMakeLists.txt (+1-1) 
- (removed) flang/lib/Optimizer/Transforms/OMPDescriptorMapInfoGen.cpp (-168) 
- (added) flang/lib/Optimizer/Transforms/OMPMapInfoFinalization.cpp (+262) 
- (modified) flang/test/Fir/convert-to-llvm-openmp-and-fir.fir (+31-4) 
- (modified) flang/test/Integration/OpenMP/map-types-and-sizes.f90 (+153-1) 
- (modified) flang/test/Lower/OpenMP/FIR/array-bounds.f90 (+2-2) 
- (modified) flang/test/Lower/OpenMP/FIR/map-component-ref.f90 (+2-2) 
- (modified) flang/test/Lower/OpenMP/FIR/target.f90 (+2-2) 
- (modified) flang/test/Lower/OpenMP/allocatable-array-bounds.f90 (+6-6) 
- (modified) flang/test/Lower/OpenMP/allocatable-map.f90 (+4-4) 
- (modified) flang/test/Lower/OpenMP/array-bounds.f90 (+4-4) 
- (added) flang/test/Lower/OpenMP/derived-type-map.f90 (+105) 
- (modified) flang/test/Lower/OpenMP/map-component-ref.f90 (+1-1) 
- (modified) flang/test/Lower/OpenMP/target.f90 (+2-2) 
- (renamed) flang/test/Transforms/omp-map-info-finalization.fir (+29-5) 


``diff
diff --git a/flang/docs/OpenMP-descriptor-management.md 
b/flang/docs/OpenMP-descriptor-management.md
index 90a20282e05126..af02b3a99cb07d 100644
--- a/flang/docs/OpenMP-descriptor-management.md
+++ b/flang/docs/OpenMP-descriptor-management.md
@@ -44,7 +44,7 @@ Currently, Flang will lower these descriptor types in the 
OpenMP lowering (lower
 to all other map types, generating an omp.MapInfoOp containing relevant 
information required for lowering
 the OpenMP dialect to LLVM-IR during the final stages of the MLIR lowering. 
However, after 
 the lowering to FIR/HLFIR has been performed an OpenMP dialect specific pass 
for Fortran, 
-`OMPDescriptorMapInfoGenPass` (Optimizer/OMPDescriptorMapInfoGen.cpp) will 
expand the 
+`OMPMapInfoFinalizationPass` (Optimizer/OMPMapInfoFinalization.cpp) will 
expand the 
 `omp.MapInfoOp`'s containing descriptors (which currently will be a `BoxType` 
or `BoxAddrOp`) into multiple 
 mappings, with one extra per pointer member in the descriptor that is 
supported on top of the original
 descriptor map operation. These pointers members are linked to the parent 
descriptor by adding them to 
@@ -52,7 +52,7 @@ the member field of the original descriptor map operation, 
they are then inserte
 owning operation's (`omp.TargetOp`, `omp.DataOp` etc.) map operand list and in 
cases where the owning operation
 is `IsolatedFromAbove`, it also inserts them as `BlockArgs` to canonicalize 
the mappings and simplify lowering.
 
-An example transformation b

[llvm-branch-commits] [asan] isInterestingAlloca: remove the isAllocaPromotable condition (PR #77221)

2024-02-12 Thread Fangrui Song via llvm-branch-commits

MaskRay wrote:

Ping:)

https://github.com/llvm/llvm-project/pull/77221
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] release/18.x: [mlir] Skip invalid test on big endian platform (s390x) (#80246) (PR #81373)

2024-02-12 Thread Jacques Pienaar via llvm-branch-commits

https://github.com/jpienaar approved this pull request.


https://github.com/llvm/llvm-project/pull/81373
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [Flang][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-12 Thread via llvm-branch-commits

agozillon wrote:

I believe this is the top of the PR stack that should pass... however, it's my 
first time using SPR so we'll see how it goes. If there's anything odd with the 
PR (outside of the usual code review) please don't hesitate to mention it so I 
can address it!

I believe I fragmented the stack appropriately into:
   MLIR Dialect change
   Flang change
   MLIR -> LLVM IR changes
   Set of offload runtime tests

However, if you spot a test or file that isn't in the right stack, please do 
point it out and I can move it, there's a lot of tests across the patch series 
so there's a chance I've misplaced one or two. 

https://github.com/llvm/llvm-project/pull/81511
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT][NFC] Add BOLTError and return it from passes (1/n) (PR #81522)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov created 
https://github.com/llvm/llvm-project/pull/81522

Co-authored-by: Rafael Auler 

Test Plan: NFC



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


[llvm-branch-commits] [BOLT] Propagate BOLTErrors from Core, RewriteInstance, and passes (2/n) (PR #81523)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov created 
https://github.com/llvm/llvm-project/pull/81523



Test Plan:
NFC

Co-authored-by: Rafael Auler 



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


[llvm-branch-commits] [BOLT] Log through JournalingStreams (PR #81524)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov created 
https://github.com/llvm/llvm-project/pull/81524

Co-authored-by: Rafael Auler 

Test Plan: NFC



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


[llvm-branch-commits] [BOLT] Propagate BOLTErrors from Core, RewriteInstance, and passes (2/n) (PR #81523)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov converted_to_draft 
https://github.com/llvm/llvm-project/pull/81523
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Log through JournalingStreams (PR #81524)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov converted_to_draft 
https://github.com/llvm/llvm-project/pull/81524
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [CallPromotionUtils]Implement conditional indirect call promotion with vtable-based comparison (PR #81378)

2024-02-12 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/81378
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [CallPromotionUtils]Implement conditional indirect call promotion with vtable-based comparison (PR #81378)

2024-02-12 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/81378
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT][NFC] Add BOLTError and return it from passes (1/n) (PR #81529)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov created 
https://github.com/llvm/llvm-project/pull/81529

Co-authored-by: Rafael Auler 

Test Plan: NFC



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


[llvm-branch-commits] [BOLT] Propagate BOLTErrors from Core, RewriteInstance, and passes (2/n) (PR #81530)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov created 
https://github.com/llvm/llvm-project/pull/81530



Test Plan:
NFC

Co-authored-by: Rafael Auler 



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


[llvm-branch-commits] [BOLT] Log through JournalingStreams (PR #81531)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov created 
https://github.com/llvm/llvm-project/pull/81531

Co-authored-by: Rafael Auler 

Test Plan: NFC



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


[llvm-branch-commits] [llvm] [InstrProf] Add vtables with type metadata into symtab to look it up with GUID (PR #81051)

2024-02-12 Thread Teresa Johnson via llvm-branch-commits

teresajohnson wrote:

Can you pull out the part that does the refactoring into getCanonicalName and 
adds comments etc into a separate nfc patch, so that this one is just about 
adding vtables?

https://github.com/llvm/llvm-project/pull/81051
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Log through JournalingStreams (PR #81531)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov closed https://github.com/llvm/llvm-project/pull/81531
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Propagate BOLTErrors from Core, RewriteInstance, and passes (2/n) (PR #81530)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov closed https://github.com/llvm/llvm-project/pull/81530
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT][NFC] Add BOLTError and return it from passes (1/n) (PR #81529)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov closed https://github.com/llvm/llvm-project/pull/81529
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [BOLT] Propagate BOLTErrors from Core, RewriteInstance, and passes (2/n) (PR #81523)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/81523

>From 17ab8e592a01d4402e88de21c8f66742134b64f3 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Mon, 12 Feb 2024 12:42:25 -0800
Subject: [PATCH] Fix build

Created using spr 1.3.4
---
 bolt/lib/Rewrite/MachORewriteInstance.cpp |  4 ++--
 bolt/lib/Rewrite/RewriteInstance.cpp  | 11 ++-
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/bolt/lib/Rewrite/MachORewriteInstance.cpp 
b/bolt/lib/Rewrite/MachORewriteInstance.cpp
index 8be8257f15c1ce..c2a6c1f88ab070 100644
--- a/bolt/lib/Rewrite/MachORewriteInstance.cpp
+++ b/bolt/lib/Rewrite/MachORewriteInstance.cpp
@@ -337,7 +337,7 @@ void MachORewriteInstance::disassembleFunctions() {
 BinaryFunction &Function = BFI.second;
 if (!Function.isSimple())
   continue;
-Function.disassemble();
+cantFail(Function.disassemble());
 if (opts::PrintDisasm)
   Function.print(outs(), "after disassembly");
   }
@@ -387,7 +387,7 @@ void MachORewriteInstance::runOptimizationPasses() {
   Manager.registerPass(
   std::make_unique(opts::PrintFinalized));
 
-  Manager.runPasses();
+  cantFail(Manager.runPasses());
 }
 
 void MachORewriteInstance::mapInstrumentationSection(
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp 
b/bolt/lib/Rewrite/RewriteInstance.cpp
index cc994c213482d4..06aed246de0cf2 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1283,7 +1283,7 @@ void RewriteInstance::discoverFileObjects() {
/*UseMaxSize*/ true);
 if (BF) {
   assert(Rel.isRelative() && "Expected relative relocation for 
island");
-  BF->markIslandDynamicRelocationAtAddress(RelAddress);
+  cantFail(BF->markIslandDynamicRelocationAtAddress(RelAddress));
 }
   }
 }
@@ -2859,8 +2859,9 @@ void RewriteInstance::selectFunctionsToProcess() {
   StringSet<> ReorderFunctionsUserSet;
   StringSet<> ReorderFunctionsLTOCommonSet;
   if (opts::ReorderFunctions == ReorderFunctions::RT_USER) {
-for (const std::string &Function :
- ReorderFunctions::readFunctionOrderFile()) {
+std::vector FunctionNames;
+cantFail(ReorderFunctions::readFunctionOrderFile(FunctionNames));
+for (const std::string &Function : FunctionNames) {
   ReorderFunctionsUserSet.insert(Function);
   if (std::optional LTOCommonName = getLTOCommonName(Function))
 ReorderFunctionsLTOCommonSet.insert(*LTOCommonName);
@@ -3207,7 +3208,7 @@ void RewriteInstance::disassembleFunctions() {
   check_error(LSDASection.getError(), "failed to get LSDA section");
   ArrayRef LSDAData = ArrayRef(
   LSDASection->getData(), LSDASection->getContents().size());
-  Function.parseLSDA(LSDAData, LSDASection->getAddress());
+  cantFail(Function.parseLSDA(LSDAData, LSDASection->getAddress()));
 }
   }
 }
@@ -3298,7 +3299,7 @@ void RewriteInstance::postProcessFunctions() {
 void RewriteInstance::runOptimizationPasses() {
   NamedRegionTimer T("runOptimizationPasses", "run optimization passes",
  TimerGroupName, TimerGroupDesc, opts::TimeRewrite);
-  BinaryFunctionPassManager::runAllPasses(*BC);
+  cantFail(BinaryFunctionPassManager::runAllPasses(*BC));
 }
 
 void RewriteInstance::preregisterSections() {

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


[llvm-branch-commits] [BOLT] Log through JournalingStreams (PR #81524)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/81524


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


[llvm-branch-commits] [BOLT] Log through JournalingStreams (PR #81524)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/81524


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


[llvm-branch-commits] [llvm] [NFC][CallPromotionUtils]Extract a helper function versionCallSiteWithCond from versionCallSite (PR #81181)

2024-02-12 Thread Teresa Johnson via llvm-branch-commits

https://github.com/teresajohnson approved this pull request.

lgtm with a suggested change to the comments

https://github.com/llvm/llvm-project/pull/81181
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [NFC][CallPromotionUtils]Extract a helper function versionCallSiteWithCond from versionCallSite (PR #81181)

2024-02-12 Thread Teresa Johnson via llvm-branch-commits


@@ -267,7 +264,6 @@ static void createRetBitCast(CallBase &CB, Type *RetTy, 
CastInst **RetBitCast) {
 /// Is replaced by the following:
 ///
 ///   cond_bb:
-/// %cond = icmp eq i32 ()* %ptr, @func

teresajohnson wrote:

I'm not sure these conditions should be completely removed. Perhaps just show 
something like `%cond = Cond`.

https://github.com/llvm/llvm-project/pull/81181
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [NFC][CallPromotionUtils]Extract a helper function versionCallSiteWithCond from versionCallSite (PR #81181)

2024-02-12 Thread Teresa Johnson via llvm-branch-commits

https://github.com/teresajohnson edited 
https://github.com/llvm/llvm-project/pull/81181
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT][NFC] Add BOLTError and return it from passes (1/2) (PR #81522)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/81522
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [BOLT] Propagate BOLTErrors from Core, RewriteInstance, and passes (2/2) (PR #81523)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/81523
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [BOLT] Propagate BOLTErrors from Core, RewriteInstance, and passes (2/2) (PR #81523)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov ready_for_review 
https://github.com/llvm/llvm-project/pull/81523
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Log through JournalingStreams (PR #81524)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov ready_for_review 
https://github.com/llvm/llvm-project/pull/81524
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [InstrProf] Add vtables with type metadata into symtab to look it up with GUID (PR #81051)

2024-02-12 Thread Mingming Liu via llvm-branch-commits

minglotus-6 wrote:

> Can you pull out the part that does the refactoring into getCanonicalName and 
> adds comments etc into a separate nfc patch, so that this one is just about 
> adding vtables?

Sure! I'm thinking about doing the nfc patch into LLVM main branch given 
`getCanonicalName` simplifies `addFuncWithName` a little bit. But it should be 
a quick 
[click](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-base-branch-of-a-pull-request)
 to switch the base branch to merge a PR into at any time.

https://github.com/llvm/llvm-project/pull/81051
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [BOLT] Propagate BOLTErrors from Core, RewriteInstance, and passes (2/2) (PR #81523)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/81523

>From 17ab8e592a01d4402e88de21c8f66742134b64f3 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Mon, 12 Feb 2024 12:42:25 -0800
Subject: [PATCH 1/2] Fix build

Created using spr 1.3.4
---
 bolt/lib/Rewrite/MachORewriteInstance.cpp |  4 ++--
 bolt/lib/Rewrite/RewriteInstance.cpp  | 11 ++-
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/bolt/lib/Rewrite/MachORewriteInstance.cpp 
b/bolt/lib/Rewrite/MachORewriteInstance.cpp
index 8be8257f15c1ce..c2a6c1f88ab070 100644
--- a/bolt/lib/Rewrite/MachORewriteInstance.cpp
+++ b/bolt/lib/Rewrite/MachORewriteInstance.cpp
@@ -337,7 +337,7 @@ void MachORewriteInstance::disassembleFunctions() {
 BinaryFunction &Function = BFI.second;
 if (!Function.isSimple())
   continue;
-Function.disassemble();
+cantFail(Function.disassemble());
 if (opts::PrintDisasm)
   Function.print(outs(), "after disassembly");
   }
@@ -387,7 +387,7 @@ void MachORewriteInstance::runOptimizationPasses() {
   Manager.registerPass(
   std::make_unique(opts::PrintFinalized));
 
-  Manager.runPasses();
+  cantFail(Manager.runPasses());
 }
 
 void MachORewriteInstance::mapInstrumentationSection(
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp 
b/bolt/lib/Rewrite/RewriteInstance.cpp
index cc994c213482d4..06aed246de0cf2 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1283,7 +1283,7 @@ void RewriteInstance::discoverFileObjects() {
/*UseMaxSize*/ true);
 if (BF) {
   assert(Rel.isRelative() && "Expected relative relocation for 
island");
-  BF->markIslandDynamicRelocationAtAddress(RelAddress);
+  cantFail(BF->markIslandDynamicRelocationAtAddress(RelAddress));
 }
   }
 }
@@ -2859,8 +2859,9 @@ void RewriteInstance::selectFunctionsToProcess() {
   StringSet<> ReorderFunctionsUserSet;
   StringSet<> ReorderFunctionsLTOCommonSet;
   if (opts::ReorderFunctions == ReorderFunctions::RT_USER) {
-for (const std::string &Function :
- ReorderFunctions::readFunctionOrderFile()) {
+std::vector FunctionNames;
+cantFail(ReorderFunctions::readFunctionOrderFile(FunctionNames));
+for (const std::string &Function : FunctionNames) {
   ReorderFunctionsUserSet.insert(Function);
   if (std::optional LTOCommonName = getLTOCommonName(Function))
 ReorderFunctionsLTOCommonSet.insert(*LTOCommonName);
@@ -3207,7 +3208,7 @@ void RewriteInstance::disassembleFunctions() {
   check_error(LSDASection.getError(), "failed to get LSDA section");
   ArrayRef LSDAData = ArrayRef(
   LSDASection->getData(), LSDASection->getContents().size());
-  Function.parseLSDA(LSDAData, LSDASection->getAddress());
+  cantFail(Function.parseLSDA(LSDAData, LSDASection->getAddress()));
 }
   }
 }
@@ -3298,7 +3299,7 @@ void RewriteInstance::postProcessFunctions() {
 void RewriteInstance::runOptimizationPasses() {
   NamedRegionTimer T("runOptimizationPasses", "run optimization passes",
  TimerGroupName, TimerGroupDesc, opts::TimeRewrite);
-  BinaryFunctionPassManager::runAllPasses(*BC);
+  cantFail(BinaryFunctionPassManager::runAllPasses(*BC));
 }
 
 void RewriteInstance::preregisterSections() {

>From cb5a6939b09a88e1f1442d8ea761a04b2fcad332 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Mon, 12 Feb 2024 13:52:48 -0800
Subject: [PATCH 2/2] Handle BOLTErrors in runOptimizationPasses

Created using spr 1.3.4
---
 bolt/lib/Rewrite/RewriteInstance.cpp | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp 
b/bolt/lib/Rewrite/RewriteInstance.cpp
index 06aed246de0cf2..829568cefff01f 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -3299,7 +3299,11 @@ void RewriteInstance::postProcessFunctions() {
 void RewriteInstance::runOptimizationPasses() {
   NamedRegionTimer T("runOptimizationPasses", "run optimization passes",
  TimerGroupName, TimerGroupDesc, opts::TimeRewrite);
-  cantFail(BinaryFunctionPassManager::runAllPasses(*BC));
+  handleAllErrors(BinaryFunctionPassManager::runAllPasses(*BC),
+  [](const BOLTError &E) {
+E.log(errs());
+exit(1);
+  });
 }
 
 void RewriteInstance::preregisterSections() {

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


[llvm-branch-commits] [BOLT] Log through JournalingStreams (PR #81524)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/81524


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


[llvm-branch-commits] [BOLT] Log through JournalingStreams (PR #81524)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/81524


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


[llvm-branch-commits] [BOLT][NFC] Add BOLTError and return it from passes (1/2) (PR #81522)

2024-02-12 Thread Rafael Auler via llvm-branch-commits

https://github.com/rafaelauler approved this pull request.

Thanks, as commit message we can put something like:

As part of the effort to refactor old error handling code that
would directly call exit(1), in this patch we add a new class
BOLTError and auxiliary functions createFatalBOLTError() and
createNonFatalBOLTError() that allow BOLT code to bubble up the
problem to the caller by using the Error class as a return
type (or Expected). Also change passes to use these.

https://github.com/llvm/llvm-project/pull/81522
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT][NFC] Add BOLTError and return it from passes (1/2) (PR #81522)

2024-02-12 Thread Rafael Auler via llvm-branch-commits

https://github.com/rafaelauler edited 
https://github.com/llvm/llvm-project/pull/81522
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [BOLT] Propagate BOLTErrors from Core, RewriteInstance, and passes (2/2) (PR #81523)

2024-02-12 Thread Rafael Auler via llvm-branch-commits

https://github.com/rafaelauler approved this pull request.

Thanks, as commit message:

As part of the effort to refactor old error handling code that
would directly call exit(1), in this patch continue the migration
on libCore, libRewrite and libPasses to use the new BOLTError
class whenever a failure occurs.

https://github.com/llvm/llvm-project/pull/81523
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Log through JournalingStreams (PR #81524)

2024-02-12 Thread Rafael Auler via llvm-branch-commits

https://github.com/rafaelauler approved this pull request.

Thanks, here's what I think is a suitable commit message for this one:

Make core BOLT functionality more friendly to being used as a
library instead of in our standalone driver llvm-bolt. To
accomplish this, we augment BinaryContext with journaling streams
that are to be used by most BOLT code whenever something needs to
be logged to the screen. Users of the library can decide if logs
should be printed to a file, no file or to the screen, as
before. To illustrate this, this patch adds a new option
--log-file that allows the user to redirect BOLT logging to a
file on disk or completely hide it by using
--log-file=/dev/null. Future BOLT code should now use
BinaryContext::outs() for printing important messages instead of
llvm::outs(). A new test log.test enforces this by verifying that
no strings are print to screen once the --log-file option is
used.

In previous patches we also added a new BOLTError class to report
common and fatal errors, so code shouldn't call exit(1) now.  To
easily handle problems as before (by quitting with exit(1)),
callers can now use
BinaryContext::logBOLTErrorsAndQuitOnFatal(Error) whenever code
needs to deal with BOLT errors. To test this, we have fatal.s
that checks we are correctly quitting and printing a fatal error
to the screen.

Because this is a significant change by itself, not all code was
yet ported. Code from Profiler libs (DataAggregator and friends)
still print errors directly to screen.

https://github.com/llvm/llvm-project/pull/81524
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/18.x: [LLD] [test] Avoid printing timestamps past INT32_MAX with llvm-readobj (#81463) (PR #81468)

2024-02-12 Thread Fangrui Song via llvm-branch-commits

https://github.com/MaskRay approved this pull request.


https://github.com/llvm/llvm-project/pull/81468
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT][NFC] Add BOLTError and return it from passes (1/2) (PR #81522)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/81522
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [BOLT] Propagate BOLTErrors from Core, RewriteInstance, and passes (2/2) (PR #81523)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/81523

>From 17ab8e592a01d4402e88de21c8f66742134b64f3 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Mon, 12 Feb 2024 12:42:25 -0800
Subject: [PATCH 1/2] Fix build

Created using spr 1.3.4
---
 bolt/lib/Rewrite/MachORewriteInstance.cpp |  4 ++--
 bolt/lib/Rewrite/RewriteInstance.cpp  | 11 ++-
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/bolt/lib/Rewrite/MachORewriteInstance.cpp 
b/bolt/lib/Rewrite/MachORewriteInstance.cpp
index 8be8257f15c1ce..c2a6c1f88ab070 100644
--- a/bolt/lib/Rewrite/MachORewriteInstance.cpp
+++ b/bolt/lib/Rewrite/MachORewriteInstance.cpp
@@ -337,7 +337,7 @@ void MachORewriteInstance::disassembleFunctions() {
 BinaryFunction &Function = BFI.second;
 if (!Function.isSimple())
   continue;
-Function.disassemble();
+cantFail(Function.disassemble());
 if (opts::PrintDisasm)
   Function.print(outs(), "after disassembly");
   }
@@ -387,7 +387,7 @@ void MachORewriteInstance::runOptimizationPasses() {
   Manager.registerPass(
   std::make_unique(opts::PrintFinalized));
 
-  Manager.runPasses();
+  cantFail(Manager.runPasses());
 }
 
 void MachORewriteInstance::mapInstrumentationSection(
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp 
b/bolt/lib/Rewrite/RewriteInstance.cpp
index cc994c213482d4..06aed246de0cf2 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1283,7 +1283,7 @@ void RewriteInstance::discoverFileObjects() {
/*UseMaxSize*/ true);
 if (BF) {
   assert(Rel.isRelative() && "Expected relative relocation for 
island");
-  BF->markIslandDynamicRelocationAtAddress(RelAddress);
+  cantFail(BF->markIslandDynamicRelocationAtAddress(RelAddress));
 }
   }
 }
@@ -2859,8 +2859,9 @@ void RewriteInstance::selectFunctionsToProcess() {
   StringSet<> ReorderFunctionsUserSet;
   StringSet<> ReorderFunctionsLTOCommonSet;
   if (opts::ReorderFunctions == ReorderFunctions::RT_USER) {
-for (const std::string &Function :
- ReorderFunctions::readFunctionOrderFile()) {
+std::vector FunctionNames;
+cantFail(ReorderFunctions::readFunctionOrderFile(FunctionNames));
+for (const std::string &Function : FunctionNames) {
   ReorderFunctionsUserSet.insert(Function);
   if (std::optional LTOCommonName = getLTOCommonName(Function))
 ReorderFunctionsLTOCommonSet.insert(*LTOCommonName);
@@ -3207,7 +3208,7 @@ void RewriteInstance::disassembleFunctions() {
   check_error(LSDASection.getError(), "failed to get LSDA section");
   ArrayRef LSDAData = ArrayRef(
   LSDASection->getData(), LSDASection->getContents().size());
-  Function.parseLSDA(LSDAData, LSDASection->getAddress());
+  cantFail(Function.parseLSDA(LSDAData, LSDASection->getAddress()));
 }
   }
 }
@@ -3298,7 +3299,7 @@ void RewriteInstance::postProcessFunctions() {
 void RewriteInstance::runOptimizationPasses() {
   NamedRegionTimer T("runOptimizationPasses", "run optimization passes",
  TimerGroupName, TimerGroupDesc, opts::TimeRewrite);
-  BinaryFunctionPassManager::runAllPasses(*BC);
+  cantFail(BinaryFunctionPassManager::runAllPasses(*BC));
 }
 
 void RewriteInstance::preregisterSections() {

>From cb5a6939b09a88e1f1442d8ea761a04b2fcad332 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Mon, 12 Feb 2024 13:52:48 -0800
Subject: [PATCH 2/2] Handle BOLTErrors in runOptimizationPasses

Created using spr 1.3.4
---
 bolt/lib/Rewrite/RewriteInstance.cpp | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp 
b/bolt/lib/Rewrite/RewriteInstance.cpp
index 06aed246de0cf2..829568cefff01f 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -3299,7 +3299,11 @@ void RewriteInstance::postProcessFunctions() {
 void RewriteInstance::runOptimizationPasses() {
   NamedRegionTimer T("runOptimizationPasses", "run optimization passes",
  TimerGroupName, TimerGroupDesc, opts::TimeRewrite);
-  cantFail(BinaryFunctionPassManager::runAllPasses(*BC));
+  handleAllErrors(BinaryFunctionPassManager::runAllPasses(*BC),
+  [](const BOLTError &E) {
+E.log(errs());
+exit(1);
+  });
 }
 
 void RewriteInstance::preregisterSections() {

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


[llvm-branch-commits] [llvm] [BOLT] Propagate BOLTErrors from Core, RewriteInstance, and passes (2/2) (PR #81523)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/81523

>From 17ab8e592a01d4402e88de21c8f66742134b64f3 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Mon, 12 Feb 2024 12:42:25 -0800
Subject: [PATCH 1/2] Fix build

Created using spr 1.3.4
---
 bolt/lib/Rewrite/MachORewriteInstance.cpp |  4 ++--
 bolt/lib/Rewrite/RewriteInstance.cpp  | 11 ++-
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/bolt/lib/Rewrite/MachORewriteInstance.cpp 
b/bolt/lib/Rewrite/MachORewriteInstance.cpp
index 8be8257f15c1ce..c2a6c1f88ab070 100644
--- a/bolt/lib/Rewrite/MachORewriteInstance.cpp
+++ b/bolt/lib/Rewrite/MachORewriteInstance.cpp
@@ -337,7 +337,7 @@ void MachORewriteInstance::disassembleFunctions() {
 BinaryFunction &Function = BFI.second;
 if (!Function.isSimple())
   continue;
-Function.disassemble();
+cantFail(Function.disassemble());
 if (opts::PrintDisasm)
   Function.print(outs(), "after disassembly");
   }
@@ -387,7 +387,7 @@ void MachORewriteInstance::runOptimizationPasses() {
   Manager.registerPass(
   std::make_unique(opts::PrintFinalized));
 
-  Manager.runPasses();
+  cantFail(Manager.runPasses());
 }
 
 void MachORewriteInstance::mapInstrumentationSection(
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp 
b/bolt/lib/Rewrite/RewriteInstance.cpp
index cc994c213482d4..06aed246de0cf2 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1283,7 +1283,7 @@ void RewriteInstance::discoverFileObjects() {
/*UseMaxSize*/ true);
 if (BF) {
   assert(Rel.isRelative() && "Expected relative relocation for 
island");
-  BF->markIslandDynamicRelocationAtAddress(RelAddress);
+  cantFail(BF->markIslandDynamicRelocationAtAddress(RelAddress));
 }
   }
 }
@@ -2859,8 +2859,9 @@ void RewriteInstance::selectFunctionsToProcess() {
   StringSet<> ReorderFunctionsUserSet;
   StringSet<> ReorderFunctionsLTOCommonSet;
   if (opts::ReorderFunctions == ReorderFunctions::RT_USER) {
-for (const std::string &Function :
- ReorderFunctions::readFunctionOrderFile()) {
+std::vector FunctionNames;
+cantFail(ReorderFunctions::readFunctionOrderFile(FunctionNames));
+for (const std::string &Function : FunctionNames) {
   ReorderFunctionsUserSet.insert(Function);
   if (std::optional LTOCommonName = getLTOCommonName(Function))
 ReorderFunctionsLTOCommonSet.insert(*LTOCommonName);
@@ -3207,7 +3208,7 @@ void RewriteInstance::disassembleFunctions() {
   check_error(LSDASection.getError(), "failed to get LSDA section");
   ArrayRef LSDAData = ArrayRef(
   LSDASection->getData(), LSDASection->getContents().size());
-  Function.parseLSDA(LSDAData, LSDASection->getAddress());
+  cantFail(Function.parseLSDA(LSDAData, LSDASection->getAddress()));
 }
   }
 }
@@ -3298,7 +3299,7 @@ void RewriteInstance::postProcessFunctions() {
 void RewriteInstance::runOptimizationPasses() {
   NamedRegionTimer T("runOptimizationPasses", "run optimization passes",
  TimerGroupName, TimerGroupDesc, opts::TimeRewrite);
-  BinaryFunctionPassManager::runAllPasses(*BC);
+  cantFail(BinaryFunctionPassManager::runAllPasses(*BC));
 }
 
 void RewriteInstance::preregisterSections() {

>From cb5a6939b09a88e1f1442d8ea761a04b2fcad332 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Mon, 12 Feb 2024 13:52:48 -0800
Subject: [PATCH 2/2] Handle BOLTErrors in runOptimizationPasses

Created using spr 1.3.4
---
 bolt/lib/Rewrite/RewriteInstance.cpp | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp 
b/bolt/lib/Rewrite/RewriteInstance.cpp
index 06aed246de0cf2..829568cefff01f 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -3299,7 +3299,11 @@ void RewriteInstance::postProcessFunctions() {
 void RewriteInstance::runOptimizationPasses() {
   NamedRegionTimer T("runOptimizationPasses", "run optimization passes",
  TimerGroupName, TimerGroupDesc, opts::TimeRewrite);
-  cantFail(BinaryFunctionPassManager::runAllPasses(*BC));
+  handleAllErrors(BinaryFunctionPassManager::runAllPasses(*BC),
+  [](const BOLTError &E) {
+E.log(errs());
+exit(1);
+  });
 }
 
 void RewriteInstance::preregisterSections() {

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


[llvm-branch-commits] [BOLT] Log through JournalingStreams (PR #81524)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/81524


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


[llvm-branch-commits] [BOLT] Log through JournalingStreams (PR #81524)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/81524


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


[llvm-branch-commits] [llvm] [BOLT] Propagate BOLTErrors from Core, RewriteInstance, and passes (2/2) (PR #81523)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/81523
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [NFC][CallPromotionUtils]Extract a helper function versionCallSiteWithCond from versionCallSite (PR #81181)

2024-02-12 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 updated 
https://github.com/llvm/llvm-project/pull/81181

>From 7ebae253ab1808bca328453f68af2b595d07176e Mon Sep 17 00:00:00 2001
From: mingmingl 
Date: Thu, 8 Feb 2024 11:32:50 -0800
Subject: [PATCH 1/2] [NFC][CallPromotionUtils]Extract a helper function
 versionCallSiteWithCond from versionCallSite

---
 .../Transforms/Utils/CallPromotionUtils.cpp   | 36 +++
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp 
b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
index 4e84927f1cfc90..d0cf0792eface0 100644
--- a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
+++ b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
@@ -188,10 +188,9 @@ static void createRetBitCast(CallBase &CB, Type *RetTy, 
CastInst **RetBitCast) {
 /// Predicate and clone the given call site.
 ///
 /// This function creates an if-then-else structure at the location of the call
-/// site. The "if" condition compares the call site's called value to the given
-/// callee. The original call site is moved into the "else" block, and a clone
-/// of the call site is placed in the "then" block. The cloned instruction is
-/// returned.
+/// site. The "if" condition is specified by `Cond`.
+/// The original call site is moved into the "else" block, and a clone of the
+/// call site is placed in the "then" block. The cloned instruction is 
returned.
 ///
 /// For example, the call instruction below:
 ///
@@ -202,7 +201,6 @@ static void createRetBitCast(CallBase &CB, Type *RetTy, 
CastInst **RetBitCast) {
 /// Is replace by the following:
 ///
 ///   orig_bb:
-/// %cond = icmp eq i32 ()* %ptr, @func
 /// br i1 %cond, %then_bb, %else_bb
 ///
 ///   then_bb:
@@ -232,7 +230,6 @@ static void createRetBitCast(CallBase &CB, Type *RetTy, 
CastInst **RetBitCast) {
 /// Is replace by the following:
 ///
 ///   orig_bb:
-/// %cond = icmp eq i32 ()* %ptr, @func
 /// br i1 %cond, %then_bb, %else_bb
 ///
 ///   then_bb:
@@ -267,7 +264,6 @@ static void createRetBitCast(CallBase &CB, Type *RetTy, 
CastInst **RetBitCast) {
 /// Is replaced by the following:
 ///
 ///   cond_bb:
-/// %cond = icmp eq i32 ()* %ptr, @func
 /// br i1 %cond, %then_bb, %orig_bb
 ///
 ///   then_bb:
@@ -280,19 +276,13 @@ static void createRetBitCast(CallBase &CB, Type *RetTy, 
CastInst **RetBitCast) {
 /// ; The original call instruction stays in its original block.
 /// %t0 = musttail call i32 %ptr()
 /// ret %t0
-CallBase &llvm::versionCallSite(CallBase &CB, Value *Callee,
-MDNode *BranchWeights) {
+static CallBase &versionCallSiteWithCond(CallBase &CB, Value *Cond,
+ MDNode *BranchWeights) {
 
   IRBuilder<> Builder(&CB);
   CallBase *OrigInst = &CB;
   BasicBlock *OrigBlock = OrigInst->getParent();
 
-  // Create the compare. The called value and callee must have the same type to
-  // be compared.
-  if (CB.getCalledOperand()->getType() != Callee->getType())
-Callee = Builder.CreateBitCast(Callee, CB.getCalledOperand()->getType());
-  auto *Cond = Builder.CreateICmpEQ(CB.getCalledOperand(), Callee);
-
   if (OrigInst->isMustTailCall()) {
 // Create an if-then structure. The original instruction stays in its 
block,
 // and a clone of the original instruction is placed in the "then" block.
@@ -380,6 +370,22 @@ CallBase &llvm::versionCallSite(CallBase &CB, Value 
*Callee,
   return *NewInst;
 }
 
+// Predicate and clone the given call site usingc condition `CB.callee ==
+// Callee`. See the comment `versionCallSiteWithCond` for the transformation.
+CallBase &llvm::versionCallSite(CallBase &CB, Value *Callee,
+MDNode *BranchWeights) {
+
+  IRBuilder<> Builder(&CB);
+
+  // Create the compare. The called value and callee must have the same type to
+  // be compared.
+  if (CB.getCalledOperand()->getType() != Callee->getType())
+Callee = Builder.CreateBitCast(Callee, CB.getCalledOperand()->getType());
+  auto *Cond = Builder.CreateICmpEQ(CB.getCalledOperand(), Callee);
+
+  return versionCallSiteWithCond(CB, Cond, BranchWeights);
+}
+
 bool llvm::isLegalToPromote(const CallBase &CB, Function *Callee,
 const char **FailureReason) {
   assert(!CB.getCalledFunction() && "Only indirect call sites can be 
promoted");

>From e774f69e9e960966399aa5569664c254ff0040bd Mon Sep 17 00:00:00 2001
From: mingmingl 
Date: Mon, 12 Feb 2024 15:38:07 -0800
Subject: [PATCH 2/2] resolve review feedback

---
 llvm/lib/Transforms/Utils/CallPromotionUtils.cpp | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp 
b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
index d0cf0792eface0..47e6d299ae8607 100644
--- a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
+++ b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
@@ -188,9 +188,9 @@ static void createRetB

[llvm-branch-commits] [llvm] [NFC][CallPromotionUtils]Extract a helper function versionCallSiteWithCond from versionCallSite (PR #81181)

2024-02-12 Thread Mingming Liu via llvm-branch-commits


@@ -267,7 +264,6 @@ static void createRetBitCast(CallBase &CB, Type *RetTy, 
CastInst **RetBitCast) {
 /// Is replaced by the following:
 ///
 ///   cond_bb:
-/// %cond = icmp eq i32 ()* %ptr, @func

minglotus-6 wrote:

done.

https://github.com/llvm/llvm-project/pull/81181
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [BOLT] Add binary introspection/JIT manager (PR #81346)

2024-02-12 Thread Amir Ayupov via llvm-branch-commits


@@ -0,0 +1,99 @@
+#include "bolt/Rewrite/JITRewriteInstance.h"
+#include "bolt/Core/BinaryContext.h"
+#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/Support/TargetSelect.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace llvm::object;
+using namespace llvm::ELF;
+using namespace bolt;
+
+namespace {
+struct JITRewriteInstanceTester
+: public testing::TestWithParam {
+  void SetUp() override {
+initalizeLLVM();
+initializeBOLT();
+  }
+
+protected:
+  void initalizeLLVM() {
+llvm::InitializeAllTargetInfos();
+llvm::InitializeAllTargetMCs();
+llvm::InitializeAllAsmParsers();
+llvm::InitializeAllDisassemblers();
+llvm::InitializeAllTargets();
+llvm::InitializeAllAsmPrinters();
+  }
+
+  void initializeBOLT() {
+BOLTJIT = cantFail(bolt::JITRewriteInstance::createJITRewriteInstance(
+{llvm::outs(), llvm::errs()}, /*IsPIC*/ false));
+ASSERT_FALSE(!BOLTJIT);
+  }
+
+  std::unique_ptr BOLTJIT;
+};
+} // namespace
+
+#ifdef X86_AVAILABLE
+
+// clang-format off
+extern "C" __attribute((naked)) int fib(int n)
+{
+  __asm__ __volatile__(
+"pushq   %%r14\n"
+"pushq   %%rbx\n"
+"pushq   %%rax\n"
+"movl%%edi, %%r14d\n"
+"xorl%%ebx, %%ebx\n"
+"cmpl$0x2, %%edi\n"
+"jge .Ltmp0\n"
+"movl%%r14d, %%ecx\n"
+"jmp .Ltmp1\n"
+".Ltmp0:\n"
+"xorl%%ebx, %%ebx\n"
+"nopw%%cs:(%%rax,%%rax)\n"
+".Ltmp2:\n"
+"leal-0x1(%%r14), %%edi\n"
+"callq   fib\n"
+"leal-0x2(%%r14), %%ecx\n"
+"addl%%eax, %%ebx\n"
+"cmpl$0x3, %%r14d\n"
+"movl%%ecx, %%r14d\n"
+"ja  .Ltmp2\n"
+".Ltmp1:\n"
+"addl%%ecx, %%ebx\n"
+"movl%%ebx, %%eax\n"
+"addq$0x8, %%rsp\n"
+"popq%%rbx\n"
+"popq%%r14\n"
+"retq\n"
+:::);
+}
+// clang-format on
+
+INSTANTIATE_TEST_SUITE_P(X86, JITRewriteInstanceTester,
+ ::testing::Values(Triple::x86_64));
+
+TEST_P(JITRewriteInstanceTester, DisassembleFib) {
+  EXPECT_EQ(fib(7), 13);
+
+  // BOLT JIT test/example
+  // Analyze fib function in this binary
+  // Disassemble 63 bytes
+  uint64_t Address = reinterpret_cast(&fib);
+  StringRef Data = StringRef(reinterpret_cast(&fib), 63);

aaupov wrote:

Should JITRewriter expose symbol size so users use it directly?

https://github.com/llvm/llvm-project/pull/81346
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [BOLT] Add binary introspection/JIT manager (PR #81346)

2024-02-12 Thread Rafael Auler via llvm-branch-commits


@@ -0,0 +1,99 @@
+#include "bolt/Rewrite/JITRewriteInstance.h"
+#include "bolt/Core/BinaryContext.h"
+#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/Support/TargetSelect.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace llvm::object;
+using namespace llvm::ELF;
+using namespace bolt;
+
+namespace {
+struct JITRewriteInstanceTester
+: public testing::TestWithParam {
+  void SetUp() override {
+initalizeLLVM();
+initializeBOLT();
+  }
+
+protected:
+  void initalizeLLVM() {
+llvm::InitializeAllTargetInfos();
+llvm::InitializeAllTargetMCs();
+llvm::InitializeAllAsmParsers();
+llvm::InitializeAllDisassemblers();
+llvm::InitializeAllTargets();
+llvm::InitializeAllAsmPrinters();
+  }
+
+  void initializeBOLT() {
+BOLTJIT = cantFail(bolt::JITRewriteInstance::createJITRewriteInstance(
+{llvm::outs(), llvm::errs()}, /*IsPIC*/ false));
+ASSERT_FALSE(!BOLTJIT);
+  }
+
+  std::unique_ptr BOLTJIT;
+};
+} // namespace
+
+#ifdef X86_AVAILABLE
+
+// clang-format off
+extern "C" __attribute((naked)) int fib(int n)
+{
+  __asm__ __volatile__(
+"pushq   %%r14\n"
+"pushq   %%rbx\n"
+"pushq   %%rax\n"
+"movl%%edi, %%r14d\n"
+"xorl%%ebx, %%ebx\n"
+"cmpl$0x2, %%edi\n"
+"jge .Ltmp0\n"
+"movl%%r14d, %%ecx\n"
+"jmp .Ltmp1\n"
+".Ltmp0:\n"
+"xorl%%ebx, %%ebx\n"
+"nopw%%cs:(%%rax,%%rax)\n"
+".Ltmp2:\n"
+"leal-0x1(%%r14), %%edi\n"
+"callq   fib\n"
+"leal-0x2(%%r14), %%ecx\n"
+"addl%%eax, %%ebx\n"
+"cmpl$0x3, %%r14d\n"
+"movl%%ecx, %%r14d\n"
+"ja  .Ltmp2\n"
+".Ltmp1:\n"
+"addl%%ecx, %%ebx\n"
+"movl%%ebx, %%eax\n"
+"addq$0x8, %%rsp\n"
+"popq%%rbx\n"
+"popq%%r14\n"
+"retq\n"
+:::);
+}
+// clang-format on
+
+INSTANTIATE_TEST_SUITE_P(X86, JITRewriteInstanceTester,
+ ::testing::Values(Triple::x86_64));
+
+TEST_P(JITRewriteInstanceTester, DisassembleFib) {
+  EXPECT_EQ(fib(7), 13);
+
+  // BOLT JIT test/example
+  // Analyze fib function in this binary
+  // Disassemble 63 bytes
+  uint64_t Address = reinterpret_cast(&fib);
+  StringRef Data = StringRef(reinterpret_cast(&fib), 63);

rafaelauler wrote:

The rewriter object will only get knowledge about the symbol size after a call 
to to registerJITFunction. Not sure if I answered the question, but does it 
make sense to you? The user calling registerJITSection function will first make 
a section visible to the Rewriter, and then the user can partition this section 
in different functions using registerJITFunction, so the user passes the size 
down to the rewriter instead of the opposite.

https://github.com/llvm/llvm-project/pull/81346
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [ELF] Place .lbss/.lrodata/.ldata after .bss (PR #81224)

2024-02-12 Thread Fangrui Song via llvm-branch-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/81224


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


[llvm-branch-commits] [ELF] Place .lbss/.lrodata/.ldata after .bss (PR #81224)

2024-02-12 Thread Fangrui Song via llvm-branch-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/81224


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


[llvm-branch-commits] [ELF] Place .lbss/.lrodata/.ldata after .bss (PR #81224)

2024-02-12 Thread Fangrui Song via llvm-branch-commits

https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/81224
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [ELF] Place .lbss/.lrodata/.ldata after .bss (PR #81224)

2024-02-12 Thread James Y Knight via llvm-branch-commits

jyknight wrote:

ISTM that making the layout conditional in order to not regress the most-common 
case (PIE) would be worth a minor amount of code in lld, even though the 
benefit is also relatively small.

Do you think INSERT scripts are going to be a real-world issue there? It seems 
to me like it wouldn't much matter to someone doing INSERT BEFORE/AFTER 
.lrodata, if lrodata goes near the beginning or near the end?

https://github.com/llvm/llvm-project/pull/81224
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/18.x: [clang-format] Don't remove parentheses in macro definitions (#81444) (PR #81566)

2024-02-12 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/81566

Backport 4af24d4ab765

Requested by: @owenca

>From 0acacbbad0160dc697375ab657b4231012e4e4d0 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 12 Feb 2024 19:20:26 -0800
Subject: [PATCH] [clang-format] Don't remove parentheses in macro definitions
 (#81444)

Closes #81399.

(cherry picked from commit 4af24d4ab76539706bfbceec4b3923426fb1b9e7)
---
 clang/lib/Format/UnwrappedLineParser.cpp | 2 +-
 clang/unittests/Format/FormatTest.cpp| 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index b904e0e56d9eb3..57391979887078 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2515,7 +2515,7 @@ bool UnwrappedLineParser::parseParens(TokenType 
AmpAmpTokenType) {
 parseChildBlock();
   break;
 case tok::r_paren:
-  if (!MightBeStmtExpr &&
+  if (!MightBeStmtExpr && !Line->InMacroBody &&
   Style.RemoveParentheses > FormatStyle::RPS_Leave) {
 const auto *Prev = LeftParen->Previous;
 const auto *Next = Tokens->peekNextToken();
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index a471e36f8d6825..0beba12dda62ae 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26856,6 +26856,7 @@ TEST_F(FormatTest, RemoveParentheses) {
   EXPECT_EQ(Style.RemoveParentheses, FormatStyle::RPS_Leave);
 
   Style.RemoveParentheses = FormatStyle::RPS_MultipleParentheses;
+  verifyFormat("#define Foo(...) foo((__VA_ARGS__))", Style);
   verifyFormat("int x __attribute__((aligned(16))) = 0;", Style);
   verifyFormat("decltype((foo->bar)) baz;", Style);
   verifyFormat("class __declspec(dllimport) X {};",
@@ -26890,6 +26891,7 @@ TEST_F(FormatTest, RemoveParentheses) {
   verifyFormat("return (({ 0; }));", "return ((({ 0; })));", Style);
 
   Style.RemoveParentheses = FormatStyle::RPS_ReturnStatement;
+  verifyFormat("#define Return0 return (0);", Style);
   verifyFormat("return 0;", "return (0);", Style);
   verifyFormat("co_return 0;", "co_return ((0));", Style);
   verifyFormat("return 0;", "return (((0)));", Style);

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


[llvm-branch-commits] [clang] release/18.x: [clang-format] Don't remove parentheses in macro definitions (#81444) (PR #81566)

2024-02-12 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/81566
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/18.x: [clang-format] Don't remove parentheses in macro definitions (#81444) (PR #81566)

2024-02-12 Thread via llvm-branch-commits

llvmbot wrote:

@HazardyKnusperkeks What do you think about merging this PR to the release 
branch?

https://github.com/llvm/llvm-project/pull/81566
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/18.x: [clang-format] Don't remove parentheses in macro definitions (#81444) (PR #81566)

2024-02-12 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: None (llvmbot)


Changes

Backport 4af24d4ab765

Requested by: @owenca

---
Full diff: https://github.com/llvm/llvm-project/pull/81566.diff


2 Files Affected:

- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+1-1) 
- (modified) clang/unittests/Format/FormatTest.cpp (+2) 


``diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index b904e0e56d9eb3..57391979887078 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2515,7 +2515,7 @@ bool UnwrappedLineParser::parseParens(TokenType 
AmpAmpTokenType) {
 parseChildBlock();
   break;
 case tok::r_paren:
-  if (!MightBeStmtExpr &&
+  if (!MightBeStmtExpr && !Line->InMacroBody &&
   Style.RemoveParentheses > FormatStyle::RPS_Leave) {
 const auto *Prev = LeftParen->Previous;
 const auto *Next = Tokens->peekNextToken();
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index a471e36f8d6825..0beba12dda62ae 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26856,6 +26856,7 @@ TEST_F(FormatTest, RemoveParentheses) {
   EXPECT_EQ(Style.RemoveParentheses, FormatStyle::RPS_Leave);
 
   Style.RemoveParentheses = FormatStyle::RPS_MultipleParentheses;
+  verifyFormat("#define Foo(...) foo((__VA_ARGS__))", Style);
   verifyFormat("int x __attribute__((aligned(16))) = 0;", Style);
   verifyFormat("decltype((foo->bar)) baz;", Style);
   verifyFormat("class __declspec(dllimport) X {};",
@@ -26890,6 +26891,7 @@ TEST_F(FormatTest, RemoveParentheses) {
   verifyFormat("return (({ 0; }));", "return ((({ 0; })));", Style);
 
   Style.RemoveParentheses = FormatStyle::RPS_ReturnStatement;
+  verifyFormat("#define Return0 return (0);", Style);
   verifyFormat("return 0;", "return (0);", Style);
   verifyFormat("co_return 0;", "co_return ((0));", Style);
   verifyFormat("return 0;", "return (((0)));", Style);

``




https://github.com/llvm/llvm-project/pull/81566
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [ELF] Place .lbss/.lrodata/.ldata after .bss (PR #81224)

2024-02-12 Thread Fangrui Song via llvm-branch-commits

MaskRay wrote:

> ISTM that making the layout conditional in order to not regress the 
> most-common case (PIE) would be worth a minor amount of code in lld, even 
> though the benefit is also relatively small.
> 
> Do you think INSERT scripts are going to be a real-world issue there? It 
> seems to me like it wouldn't much matter to someone doing INSERT BEFORE/AFTER 
> .lrodata, if lrodata goes near the beginning or near the end?

This has been my objection to making this layout change at all.
If we consider `-no-pie` an uncommon case that has to be supported, ISTM we can 
require the user to use a linker script fragment

```
SECTIONS { .lrodata : { *(.lrodata .lrodata.*) } } INSERT AFTER .bss;
```

https://github.com/llvm/llvm-project/pull/81224
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [ELF] Place .lbss/.lrodata/.ldata after .bss (PR #81224)

2024-02-12 Thread James Y Knight via llvm-branch-commits

jyknight wrote:

I don't follow.

no-pie is _uncommon_ but not _unsupported_. Making users add a linker script 
when they wouldn't otherwise have one, in order to have a working no-pie build 
seems unjustified.

https://github.com/llvm/llvm-project/pull/81224
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


  1   2   >