@@ -386,23 +386,6 @@ transform::TransformState::replacePayloadOp(Operation *op,
386
386
dropMappingEntry (mappings.reverse , op, handle);
387
387
}
388
388
389
- #if LLVM_ENABLE_ABI_BREAKING_CHECKS
390
- if (options.getExpensiveChecksEnabled ()) {
391
- auto it = cachedNames.find (op);
392
- assert (it != cachedNames.end () && " entry not found" );
393
- assert (it->second == op->getName () && " operation name mismatch" );
394
- cachedNames.erase (it);
395
- if (replacement) {
396
- auto insertion =
397
- cachedNames.insert ({replacement, replacement->getName ()});
398
- if (!insertion.second ) {
399
- assert (insertion.first ->second == replacement->getName () &&
400
- " operation is already cached with a different name" );
401
- }
402
- }
403
- }
404
- #endif // LLVM_ENABLE_ABI_BREAKING_CHECKS
405
-
406
389
// Replace the pointed-to object of all handles with the replacement object.
407
390
// In case a payload op was erased (replacement object is nullptr), a nullptr
408
391
// is stored in the mapping. These nullptrs are removed after each transform.
@@ -494,10 +477,10 @@ void transform::TransformState::recordOpHandleInvalidationOne(
494
477
unsigned operandNo = consumingHandle.getOperandNumber ();
495
478
for (Operation *ancestor : potentialAncestors) {
496
479
// clang-format off
497
- DEBUG_WITH_TYPE (DEBUG_TYPE_FULL,
480
+ DEBUG_WITH_TYPE (DEBUG_TYPE_FULL,
498
481
{ (DBGS () << " ----handle one ancestor: " << *ancestor << " \n " ); });
499
- DEBUG_WITH_TYPE (DEBUG_TYPE_FULL,
500
- { (DBGS () << " ----of payload with name: "
482
+ DEBUG_WITH_TYPE (DEBUG_TYPE_FULL,
483
+ { (DBGS () << " ----of payload with name: "
501
484
<< payloadOp->getName ().getIdentifier () << " \n " ); });
502
485
DEBUG_WITH_TYPE (DEBUG_TYPE_FULL,
503
486
{ (DBGS () << " ----of payload: " << *payloadOp << " \n " ); });
@@ -872,29 +855,6 @@ transform::TransformState::applyTransform(TransformOpInterface transform) {
872
855
FULL_LDBG (" --not a TransformHandle -> SKIP AND DROP ON THE FLOOR\n " );
873
856
}
874
857
}
875
-
876
- #if LLVM_ENABLE_ABI_BREAKING_CHECKS
877
- // Cache Operation* -> OperationName mappings. These will be checked after
878
- // the transform has been applied to detect incorrect memory side effects
879
- // and missing op tracking.
880
- for (std::unique_ptr<Mappings> &mapping :
881
- llvm::make_second_range (mappings)) {
882
- for (Operation *op : llvm::make_first_range (mapping->reverse )) {
883
- auto insertion = cachedNames.insert ({op, op->getName ()});
884
- if (!insertion.second ) {
885
- if (insertion.first ->second != op->getName ()) {
886
- // Operation is already in the cache, but with a different name.
887
- DiagnosedDefiniteFailure diag =
888
- emitDefiniteFailure (transform->getLoc ())
889
- << " expensive checks failure: operation mismatch, expected "
890
- << insertion.first ->second ;
891
- diag.attachNote (op->getLoc ()) << " payload op: " << op->getName ();
892
- return diag;
893
- }
894
- }
895
- }
896
- }
897
- #endif // LLVM_ENABLE_ABI_BREAKING_CHECKS
898
858
}
899
859
900
860
// Find which operands are consumed.
@@ -908,22 +868,11 @@ transform::TransformState::applyTransform(TransformOpInterface transform) {
908
868
// IR after that.
909
869
SmallVector<Value> origOpFlatResults;
910
870
SmallVector<Operation *> origAssociatedOps;
911
- #if LLVM_ENABLE_ABI_BREAKING_CHECKS
912
- DenseSet<Operation *> consumedPayloadOps;
913
- #endif // LLVM_ENABLE_ABI_BREAKING_CHECKS
914
871
for (OpOperand *opOperand : consumedOperands) {
915
872
Value operand = opOperand->get ();
916
873
if (llvm::isa<TransformHandleTypeInterface>(operand.getType ())) {
917
874
for (Operation *payloadOp : getPayloadOps (operand)) {
918
875
llvm::append_range (origOpFlatResults, payloadOp->getResults ());
919
- #if LLVM_ENABLE_ABI_BREAKING_CHECKS
920
- if (options.getExpensiveChecksEnabled ()) {
921
- // Store all consumed payload ops (and their nested ops) in a set for
922
- // extra error checking.
923
- payloadOp->walk (
924
- [&](Operation *op) { consumedPayloadOps.insert (op); });
925
- }
926
- #endif // LLVM_ENABLE_ABI_BREAKING_CHECKS
927
876
}
928
877
continue ;
929
878
}
@@ -1004,63 +953,6 @@ transform::TransformState::applyTransform(TransformOpInterface transform) {
1004
953
}
1005
954
}
1006
955
1007
- #if LLVM_ENABLE_ABI_BREAKING_CHECKS
1008
- if (options.getExpensiveChecksEnabled ()) {
1009
- // Remove erased ops from the transform state.
1010
- for (Operation *op : consumedPayloadOps) {
1011
- // This payload op was consumed but it may still be mapped to one or
1012
- // multiple handles. Forget all handles that are mapped to the op, so that
1013
- // there are no dangling pointers in the transform dialect state. This is
1014
- // necessary so that the `cachedNames`-based checks work correctly.
1015
- //
1016
- // Note: Dangling pointers to erased payload ops are allowed if the
1017
- // corresponding handles are not used anymore. There is another
1018
- // "expensive-check" that looks for future uses of dangling payload op
1019
- // pointers (through arbitrary handles). Removing handles to erased ops
1020
- // does not interfere with the other expensive checks: handle invalidation
1021
- // happens earlier and keeps track of invalidated handles with
1022
- // pre-generated error messages, so we do not need the association to
1023
- // still be there when the invalidated handle is accessed.
1024
- SmallVector<Value> handles;
1025
- (void )getHandlesForPayloadOp (op, handles, /* includeOutOfScope=*/ true );
1026
- for (Value handle : handles)
1027
- forgetMapping (handle, /* origOpFlatResults=*/ ValueRange (),
1028
- /* allowOutOfScope=*/ true );
1029
- cachedNames.erase (op);
1030
- }
1031
-
1032
- // Check cached operation names.
1033
- for (std::unique_ptr<Mappings> &mapping :
1034
- llvm::make_second_range (mappings)) {
1035
- for (Operation *op : llvm::make_first_range (mapping->reverse )) {
1036
- // Make sure that the name of the op has not changed. If it has changed,
1037
- // the op was removed and a new op was allocated at the same memory
1038
- // location. This means that we are missing op tracking somewhere.
1039
- auto cacheIt = cachedNames.find (op);
1040
- if (cacheIt == cachedNames.end ()) {
1041
- DiagnosedDefiniteFailure diag =
1042
- emitDefiniteFailure (transform->getLoc ())
1043
- << " expensive checks failure: operation not found in cache" ;
1044
- diag.attachNote (op->getLoc ()) << " payload op" ;
1045
- return diag;
1046
- }
1047
- // If the `getName` call (or the above `attachNote`) is crashing, we
1048
- // have a dangling pointer. This usually means that an op was erased but
1049
- // the transform dialect was not made aware of that; e.g., missing
1050
- // "consumesHandle" or rewriter usage.
1051
- if (cacheIt->second != op->getName ()) {
1052
- DiagnosedDefiniteFailure diag =
1053
- emitDefiniteFailure (transform->getLoc ())
1054
- << " expensive checks failure: operation mismatch, expected "
1055
- << cacheIt->second ;
1056
- diag.attachNote (op->getLoc ()) << " payload op: " << op->getName ();
1057
- return diag;
1058
- }
1059
- }
1060
- }
1061
- }
1062
- #endif // LLVM_ENABLE_ABI_BREAKING_CHECKS
1063
-
1064
956
if (failed (updateStateFromResults (results, transform->getResults ())))
1065
957
return DiagnosedSilenceableFailure::definiteFailure ();
1066
958
@@ -1150,16 +1042,6 @@ transform::TransformState::RegionScope::~RegionScope() {
1150
1042
state.mappings .erase (region);
1151
1043
1152
1044
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
1153
- // If the last handle to a payload op has gone out of scope, we no longer
1154
- // need to store the cached name. Pointers may get reused, leading to
1155
- // incorrect associations in the cache.
1156
- for (Operation *op : referencedOps) {
1157
- SmallVector<Value> handles;
1158
- if (succeeded (state.getHandlesForPayloadOp (op, handles)))
1159
- continue ;
1160
- state.cachedNames .erase (op);
1161
- }
1162
-
1163
1045
state.regionStack .pop_back ();
1164
1046
#endif // LLVM_ENABLE_ABI_BREAKING_CHECKS
1165
1047
}
0 commit comments