Skip to content

Commit 012e24a

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merge upstream LLVM into amd-gfx12
2 parents 65e64d6 + c639475 commit 012e24a

File tree

6 files changed

+81
-24
lines changed

6 files changed

+81
-24
lines changed

clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,7 @@ void AggExprEmitter::visitCXXParenListOrInitListExpr(
438438
// Push a destructor if necessary.
439439
// FIXME: if we have an array of structures, all explicitly
440440
// initialized, we can end up pushing a linear number of cleanups.
441-
if (QualType::DestructionKind dtorKind =
442-
field->getType().isDestructedType()) {
441+
if (field->getType().isDestructedType()) {
443442
cgf.cgm.errorNYI(e->getSourceRange(),
444443
"visitCXXParenListOrInitListExpr destructor");
445444
return;

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -466,28 +466,27 @@ void VPlanTransforms::prepareForVectorization(
466466
VPDominatorTree VPDT;
467467
VPDT.recalculate(Plan);
468468

469-
VPBlockBase *HeaderVPB = Plan.getEntry()->getSingleSuccessor();
470-
canonicalHeaderAndLatch(HeaderVPB, VPDT);
471-
VPBlockBase *LatchVPB = HeaderVPB->getPredecessors()[1];
469+
auto *HeaderVPBB = cast<VPBasicBlock>(Plan.getEntry()->getSingleSuccessor());
470+
canonicalHeaderAndLatch(HeaderVPBB, VPDT);
471+
auto *LatchVPBB = cast<VPBasicBlock>(HeaderVPBB->getPredecessors()[1]);
472472

473473
VPBasicBlock *VecPreheader = Plan.createVPBasicBlock("vector.ph");
474474
VPBlockUtils::insertBlockAfter(VecPreheader, Plan.getEntry());
475475

476476
VPBasicBlock *MiddleVPBB = Plan.createVPBasicBlock("middle.block");
477-
// The canonical LatchVPB has the header block as last successor. If it has
477+
// The canonical LatchVPBB has the header block as last successor. If it has
478478
// another successor, this successor is an exit block - insert middle block on
479479
// its edge. Otherwise, add middle block as another successor retaining header
480480
// as last.
481-
if (LatchVPB->getNumSuccessors() == 2) {
482-
VPBlockBase *LatchExitVPB = LatchVPB->getSuccessors()[0];
483-
VPBlockUtils::insertOnEdge(LatchVPB, LatchExitVPB, MiddleVPBB);
481+
if (LatchVPBB->getNumSuccessors() == 2) {
482+
VPBlockBase *LatchExitVPB = LatchVPBB->getSuccessors()[0];
483+
VPBlockUtils::insertOnEdge(LatchVPBB, LatchExitVPB, MiddleVPBB);
484484
} else {
485-
VPBlockUtils::connectBlocks(LatchVPB, MiddleVPBB);
486-
LatchVPB->swapSuccessors();
485+
VPBlockUtils::connectBlocks(LatchVPBB, MiddleVPBB);
486+
LatchVPBB->swapSuccessors();
487487
}
488488

489-
addCanonicalIVRecipes(Plan, cast<VPBasicBlock>(HeaderVPB),
490-
cast<VPBasicBlock>(LatchVPB), InductionTy, IVDL);
489+
addCanonicalIVRecipes(Plan, HeaderVPBB, LatchVPBB, InductionTy, IVDL);
491490

492491
[[maybe_unused]] bool HandledUncountableEarlyExit = false;
493492
// Disconnect all early exits from the loop leaving it with a single exit from
@@ -503,8 +502,7 @@ void VPlanTransforms::prepareForVectorization(
503502
assert(!HandledUncountableEarlyExit &&
504503
"can handle exactly one uncountable early exit");
505504
handleUncountableEarlyExit(cast<VPBasicBlock>(Pred), EB, Plan,
506-
cast<VPBasicBlock>(HeaderVPB),
507-
cast<VPBasicBlock>(LatchVPB), Range);
505+
HeaderVPBB, LatchVPBB, Range);
508506
HandledUncountableEarlyExit = true;
509507
} else {
510508
for (VPRecipeBase &R : EB->phis())
@@ -568,7 +566,7 @@ void VPlanTransforms::prepareForVectorization(
568566
// the corresponding compare because they may have ended up with different
569567
// line numbers and we want to avoid awkward line stepping while debugging.
570568
// E.g., if the compare has got a line number inside the loop.
571-
DebugLoc LatchDL = TheLoop->getLoopLatch()->getTerminator()->getDebugLoc();
569+
DebugLoc LatchDL = LatchVPBB->getTerminator()->getDebugLoc();
572570
VPBuilder Builder(MiddleVPBB);
573571
VPValue *Cmp;
574572
if (!RequiresScalarEpilogueCheck)

mlir/include/mlir/IR/PatternMatch.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,11 @@ class RewriterBase : public OpBuilder {
525525
}
526526

527527
/// This method erases an operation that is known to have no uses.
528+
///
529+
/// If the current insertion point is before the erased operation, it is
530+
/// adjusted to the following operation (or the end of the block). If the
531+
/// current insertion point is within the erased operation, the insertion
532+
/// point is left in an invalid state.
528533
virtual void eraseOp(Operation *op);
529534

530535
/// This method erases all operations in a block.
@@ -539,6 +544,9 @@ class RewriterBase : public OpBuilder {
539544
/// somewhere in the middle (or beginning) of the dest block, the source block
540545
/// must have no successors. Otherwise, the resulting IR would have
541546
/// unreachable operations.
547+
///
548+
/// If the insertion point is within the source block, it is adjusted to the
549+
/// destination block.
542550
virtual void inlineBlockBefore(Block *source, Block *dest,
543551
Block::iterator before,
544552
ValueRange argValues = {});
@@ -549,6 +557,9 @@ class RewriterBase : public OpBuilder {
549557
///
550558
/// The source block must have no successors. Otherwise, the resulting IR
551559
/// would have unreachable operations.
560+
///
561+
/// If the insertion point is within the source block, it is adjusted to the
562+
/// destination block.
552563
void inlineBlockBefore(Block *source, Operation *op,
553564
ValueRange argValues = {});
554565

@@ -558,6 +569,9 @@ class RewriterBase : public OpBuilder {
558569
///
559570
/// The dest block must have no successors. Otherwise, the resulting IR would
560571
/// have unreachable operation.
572+
///
573+
/// If the insertion point is within the source block, it is adjusted to the
574+
/// destination block.
561575
void mergeBlocks(Block *source, Block *dest, ValueRange argValues = {});
562576

563577
/// Split the operations starting at "before" (inclusive) out of the given

mlir/lib/IR/PatternMatch.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ void RewriterBase::eraseOp(Operation *op) {
156156
assert(op->use_empty() && "expected 'op' to have no uses");
157157
auto *rewriteListener = dyn_cast_if_present<Listener>(listener);
158158

159+
// If the current insertion point is before the erased operation, we adjust
160+
// the insertion point to be after the operation.
161+
if (getInsertionPoint() == op->getIterator())
162+
setInsertionPointAfter(op);
163+
159164
// Fast path: If no listener is attached, the op can be dropped in one go.
160165
if (!rewriteListener) {
161166
op->erase();
@@ -320,6 +325,11 @@ void RewriterBase::inlineBlockBefore(Block *source, Block *dest,
320325
moveOpBefore(&source->front(), dest, before);
321326
}
322327

328+
// If the current insertion point is within the source block, adjust the
329+
// insertion point to the destination block.
330+
if (getInsertionBlock() == source)
331+
setInsertionPoint(dest, getInsertionPoint());
332+
323333
// Erase the source block.
324334
assert(source->empty() && "expected 'source' to be empty");
325335
eraseBlock(source);

mlir/lib/Transforms/Utils/DialectConversion.cpp

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "mlir/IR/Operation.h"
1818
#include "mlir/Interfaces/FunctionInterfaces.h"
1919
#include "mlir/Rewrite/PatternApplicator.h"
20+
#include "llvm/ADT/ScopeExit.h"
2021
#include "llvm/ADT/SmallPtrSet.h"
2122
#include "llvm/Support/Debug.h"
2223
#include "llvm/Support/FormatVariadic.h"
@@ -1759,6 +1760,12 @@ void ConversionPatternRewriter::replaceOp(Operation *op, ValueRange newValues) {
17591760
impl->logger.startLine()
17601761
<< "** Replace : '" << op->getName() << "'(" << op << ")\n";
17611762
});
1763+
1764+
// If the current insertion point is before the erased operation, we adjust
1765+
// the insertion point to be after the operation.
1766+
if (getInsertionPoint() == op->getIterator())
1767+
setInsertionPointAfter(op);
1768+
17621769
SmallVector<SmallVector<Value>> newVals =
17631770
llvm::map_to_vector(newValues, [](Value v) -> SmallVector<Value> {
17641771
return v ? SmallVector<Value>{v} : SmallVector<Value>();
@@ -1774,6 +1781,12 @@ void ConversionPatternRewriter::replaceOpWithMultiple(
17741781
impl->logger.startLine()
17751782
<< "** Replace : '" << op->getName() << "'(" << op << ")\n";
17761783
});
1784+
1785+
// If the current insertion point is before the erased operation, we adjust
1786+
// the insertion point to be after the operation.
1787+
if (getInsertionPoint() == op->getIterator())
1788+
setInsertionPointAfter(op);
1789+
17771790
impl->replaceOp(op, std::move(newValues));
17781791
}
17791792

@@ -1782,6 +1795,12 @@ void ConversionPatternRewriter::eraseOp(Operation *op) {
17821795
impl->logger.startLine()
17831796
<< "** Erase : '" << op->getName() << "'(" << op << ")\n";
17841797
});
1798+
1799+
// If the current insertion point is before the erased operation, we adjust
1800+
// the insertion point to be after the operation.
1801+
if (getInsertionPoint() == op->getIterator())
1802+
setInsertionPointAfter(op);
1803+
17851804
SmallVector<SmallVector<Value>> nullRepls(op->getNumResults(), {});
17861805
impl->replaceOp(op, std::move(nullRepls));
17871806
}
@@ -1888,6 +1907,11 @@ void ConversionPatternRewriter::inlineBlockBefore(Block *source, Block *dest,
18881907
moveOpBefore(&source->front(), dest, before);
18891908
}
18901909

1910+
// If the current insertion point is within the source block, adjust the
1911+
// insertion point to the destination block.
1912+
if (getInsertionBlock() == source)
1913+
setInsertionPoint(dest, getInsertionPoint());
1914+
18911915
// Erase the source block.
18921916
eraseBlock(source);
18931917
}
@@ -2217,23 +2241,39 @@ OperationLegalizer::legalizeWithFold(Operation *op,
22172241
rewriterImpl.logger.startLine() << "* Fold {\n";
22182242
rewriterImpl.logger.indent();
22192243
});
2220-
(void)rewriterImpl;
2244+
2245+
// Clear pattern state, so that the next pattern application starts with a
2246+
// clean slate. (The op/block sets are populated by listener notifications.)
2247+
auto cleanup = llvm::make_scope_exit([&]() {
2248+
rewriterImpl.patternNewOps.clear();
2249+
rewriterImpl.patternModifiedOps.clear();
2250+
rewriterImpl.patternInsertedBlocks.clear();
2251+
});
2252+
2253+
// Upon failure, undo all changes made by the folder.
2254+
RewriterState curState = rewriterImpl.getCurrentState();
22212255

22222256
// Try to fold the operation.
22232257
StringRef opName = op->getName().getStringRef();
22242258
SmallVector<Value, 2> replacementValues;
22252259
SmallVector<Operation *, 2> newOps;
22262260
rewriter.setInsertionPoint(op);
2261+
rewriter.startOpModification(op);
22272262
if (failed(rewriter.tryFold(op, replacementValues, &newOps))) {
22282263
LLVM_DEBUG(logFailure(rewriterImpl.logger, "unable to fold"));
2264+
rewriter.cancelOpModification(op);
22292265
return failure();
22302266
}
2267+
rewriter.finalizeOpModification(op);
22312268

22322269
// An empty list of replacement values indicates that the fold was in-place.
22332270
// As the operation changed, a new legalization needs to be attempted.
22342271
if (replacementValues.empty())
22352272
return legalize(op, rewriter);
22362273

2274+
// Insert a replacement for 'op' with the folded replacement values.
2275+
rewriter.replaceOp(op, replacementValues);
2276+
22372277
// Recursively legalize any new constant operations.
22382278
for (Operation *newOp : newOps) {
22392279
if (failed(legalize(newOp, rewriter))) {
@@ -2246,16 +2286,12 @@ OperationLegalizer::legalizeWithFold(Operation *op,
22462286
"op '" + opName +
22472287
"' folder rollback of IR modifications requested");
22482288
}
2249-
// Legalization failed: erase all materialized constants.
2250-
for (Operation *op : newOps)
2251-
rewriter.eraseOp(op);
2289+
rewriterImpl.resetState(
2290+
curState, std::string(op->getName().getStringRef()) + " folder");
22522291
return failure();
22532292
}
22542293
}
22552294

2256-
// Insert a replacement for 'op' with the folded replacement values.
2257-
rewriter.replaceOp(op, replacementValues);
2258-
22592295
LLVM_DEBUG(logSuccess(rewriterImpl.logger, ""));
22602296
return success();
22612297
}

mlir/test/Transforms/test-legalize-type-conversion.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ func.func @test_signature_conversion_no_converter() {
104104
"test.signature_conversion_no_converter"() ({
105105
// expected-error@below {{failed to legalize unresolved materialization from ('f64') to ('f32') that remained live after conversion}}
106106
^bb0(%arg0: f32):
107-
"test.type_consumer"(%arg0) : (f32) -> ()
108107
// expected-note@below{{see existing live user here}}
108+
"test.type_consumer"(%arg0) : (f32) -> ()
109109
"test.return"(%arg0) : (f32) -> ()
110110
}) : () -> ()
111111
return

0 commit comments

Comments
 (0)