Skip to content

Commit 6c7a3f8

Browse files
authored
Fix LLVM_ENABLE_ABI_BREAKING_CHECKS macro check: use #if instead of #ifdef (#110938)
This macros is always defined: either 0 or 1. The correct pattern is to use #if. Re-apply #110185 with more fixes for debug build with the ABI breaking checks disabled.
1 parent e3686f1 commit 6c7a3f8

File tree

18 files changed

+41
-39
lines changed

18 files changed

+41
-39
lines changed

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ class SelectionDAG {
584584
return Root;
585585
}
586586

587-
#ifndef NDEBUG
587+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
588588
void VerifyDAGDivergence();
589589
#endif
590590

llvm/include/llvm/Passes/StandardInstrumentations.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class PreservedCFGCheckerInstrumentation {
171171
FunctionAnalysisManager::Invalidator &);
172172
};
173173

174-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
174+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
175175
SmallVector<StringRef, 8> PassStack;
176176
#endif
177177

llvm/include/llvm/Support/GenericDomTreeConstruction.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ struct SemiNCAInfo {
640640
Bucket;
641641
SmallDenseSet<TreeNodePtr, 8> Visited;
642642
SmallVector<TreeNodePtr, 8> Affected;
643-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
643+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
644644
SmallVector<TreeNodePtr, 8> VisitedUnaffected;
645645
#endif
646646
};
@@ -815,7 +815,7 @@ struct SemiNCAInfo {
815815
LLVM_DEBUG(dbgs() << "\t\tMarking visited not affected "
816816
<< BlockNamePrinter(Succ) << "\n");
817817
UnaffectedOnCurrentLevel.push_back(SuccTN);
818-
#ifndef NDEBUG
818+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
819819
II.VisitedUnaffected.push_back(SuccTN);
820820
#endif
821821
} else {
@@ -849,7 +849,7 @@ struct SemiNCAInfo {
849849
TN->setIDom(NCD);
850850
}
851851

852-
#if defined(LLVM_ENABLE_ABI_BREAKING_CHECKS) && !defined(NDEBUG)
852+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS && !defined(NDEBUG)
853853
for (const TreeNodePtr TN : II.VisitedUnaffected)
854854
assert(TN->getLevel() == TN->getIDom()->getLevel() + 1 &&
855855
"TN should have been updated by an affected ancestor");
@@ -915,7 +915,7 @@ struct SemiNCAInfo {
915915
LLVM_DEBUG(dbgs() << "Deleting edge " << BlockNamePrinter(From) << " -> "
916916
<< BlockNamePrinter(To) << "\n");
917917

918-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
918+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
919919
// Ensure that the edge was in fact deleted from the CFG before informing
920920
// the DomTree about it.
921921
// The check is O(N), so run it only in debug configuration.

llvm/include/llvm/Transforms/Scalar/JumpThreading.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ class JumpThreadingPass : public PassInfoMixin<JumpThreadingPass> {
8989
bool ChangedSinceLastAnalysisUpdate = false;
9090
bool HasGuards = false;
9191
#ifndef LLVM_ENABLE_ABI_BREAKING_CHECKS
92-
SmallPtrSet<const BasicBlock *, 16> LoopHeaders;
93-
#else
9492
SmallSet<AssertingVH<const BasicBlock>, 16> LoopHeaders;
93+
#else
94+
SmallPtrSet<const BasicBlock *, 16> LoopHeaders;
9595
#endif
9696

9797
unsigned BBDupThreshold;

llvm/include/llvm/Transforms/Scalar/LoopPassManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class LPMUpdater {
256256
}
257257

258258
void setParentLoop(Loop *L) {
259-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
259+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
260260
ParentL = L;
261261
#endif
262262
}
@@ -295,7 +295,7 @@ class LPMUpdater {
295295
/// loops within them will be visited in postorder as usual for the loop pass
296296
/// manager.
297297
void addSiblingLoops(ArrayRef<Loop *> NewSibLoops) {
298-
#if defined(LLVM_ENABLE_ABI_BREAKING_CHECKS) && !defined(NDEBUG)
298+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS && !defined(NDEBUG)
299299
for (Loop *NewL : NewSibLoops)
300300
assert(NewL->getParentLoop() == ParentL &&
301301
"All of the new loops must be siblings of the current loop!");
@@ -347,7 +347,7 @@ class LPMUpdater {
347347
const bool LoopNestMode;
348348
bool LoopNestChanged;
349349

350-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
350+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
351351
// In debug builds we also track the parent loop to implement asserts even in
352352
// the face of loop deletion.
353353
Loop *ParentL;

llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class SCEVExpander : public SCEVVisitor<SCEVExpander, Value *> {
168168
/// consistent when instructions are moved.
169169
SmallVector<SCEVInsertPointGuard *, 8> InsertPointGuards;
170170

171-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
171+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
172172
const char *DebugType;
173173
#endif
174174

@@ -184,7 +184,7 @@ class SCEVExpander : public SCEVVisitor<SCEVExpander, Value *> {
184184
Builder(se.getContext(), InstSimplifyFolder(DL),
185185
IRBuilderCallbackInserter(
186186
[this](Instruction *I) { rememberInstruction(I); })) {
187-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
187+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
188188
DebugType = "";
189189
#endif
190190
}
@@ -194,7 +194,7 @@ class SCEVExpander : public SCEVVisitor<SCEVExpander, Value *> {
194194
assert(InsertPointGuards.empty());
195195
}
196196

197-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
197+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
198198
void setDebugType(const char *s) { DebugType = s; }
199199
#endif
200200

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11725,7 +11725,7 @@ void SelectionDAG::CreateTopologicalOrder(std::vector<SDNode *> &Order) {
1172511725
}
1172611726
}
1172711727

11728-
#ifndef NDEBUG
11728+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
1172911729
void SelectionDAG::VerifyDAGDivergence() {
1173011730
std::vector<SDNode *> TopoOrder;
1173111731
CreateTopologicalOrder(TopoOrder);

llvm/lib/Passes/StandardInstrumentations.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ void PreservedCFGCheckerInstrumentation::registerCallbacks(
13581358
bool Registered = false;
13591359
PIC.registerBeforeNonSkippedPassCallback([this, &MAM, Registered](
13601360
StringRef P, Any IR) mutable {
1361-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
1361+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
13621362
assert(&PassStack.emplace_back(P));
13631363
#endif
13641364
(void)this;
@@ -1387,7 +1387,7 @@ void PreservedCFGCheckerInstrumentation::registerCallbacks(
13871387

13881388
PIC.registerAfterPassInvalidatedCallback(
13891389
[this](StringRef P, const PreservedAnalyses &PassPA) {
1390-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
1390+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
13911391
assert(PassStack.pop_back_val() == P &&
13921392
"Before and After callbacks must correspond");
13931393
#endif
@@ -1396,7 +1396,7 @@ void PreservedCFGCheckerInstrumentation::registerCallbacks(
13961396

13971397
PIC.registerAfterPassCallback([this, &MAM](StringRef P, Any IR,
13981398
const PreservedAnalyses &PassPA) {
1399-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
1399+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
14001400
assert(PassStack.pop_back_val() == P &&
14011401
"Before and After callbacks must correspond");
14021402
#endif

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1920,7 +1920,7 @@ bool IndVarSimplify::run(Loop *L) {
19201920

19211921
// Create a rewriter object which we'll use to transform the code with.
19221922
SCEVExpander Rewriter(*SE, DL, "indvars");
1923-
#ifndef NDEBUG
1923+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
19241924
Rewriter.setDebugType(DEBUG_TYPE);
19251925
#endif
19261926

llvm/lib/Transforms/Scalar/LoopPassManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ PreservedAnalyses FunctionToLoopPassAdaptor::run(Function &F,
293293
Updater.CurrentL = L;
294294
Updater.SkipCurrentLoop = false;
295295

296-
#ifndef NDEBUG
296+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
297297
// Save a parent loop pointer for asserts.
298298
Updater.ParentL = L->getParentLoop();
299299
#endif

llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6188,7 +6188,7 @@ LSRInstance::LSRInstance(Loop *L, IVUsers &IU, ScalarEvolution &SE,
61886188

61896189
// Configure SCEVExpander already now, so the correct mode is used for
61906190
// isSafeToExpand() checks.
6191-
#ifndef NDEBUG
6191+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
61926192
Rewriter.setDebugType(DEBUG_TYPE);
61936193
#endif
61946194
Rewriter.disableCanonicalMode();
@@ -7084,7 +7084,7 @@ static bool ReduceLoopStrength(Loop *L, IVUsers &IU, ScalarEvolution &SE,
70847084
SmallVector<WeakTrackingVH, 16> DeadInsts;
70857085
const DataLayout &DL = L->getHeader()->getDataLayout();
70867086
SCEVExpander Rewriter(SE, DL, "lsr", false);
7087-
#ifndef NDEBUG
7087+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
70887088
Rewriter.setDebugType(DEBUG_TYPE);
70897089
#endif
70907090
unsigned numFolded = Rewriter.replaceCongruentIVs(L, &DT, DeadInsts, &TTI);

llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "llvm/Support/raw_ostream.h"
2929
#include "llvm/Transforms/Utils/LoopUtils.h"
3030

31-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
31+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
3232
#define SCEV_DEBUG_WITH_TYPE(TYPE, X) DEBUG_WITH_TYPE(TYPE, X)
3333
#else
3434
#define SCEV_DEBUG_WITH_TYPE(TYPE, X)

llvm/lib/Transforms/Utils/SimplifyIndVar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ bool simplifyLoopIVs(Loop *L, ScalarEvolution *SE, DominatorTree *DT,
10241024
LoopInfo *LI, const TargetTransformInfo *TTI,
10251025
SmallVectorImpl<WeakTrackingVH> &Dead) {
10261026
SCEVExpander Rewriter(*SE, SE->getDataLayout(), "indvars");
1027-
#ifndef NDEBUG
1027+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
10281028
Rewriter.setDebugType(DEBUG_TYPE);
10291029
#endif
10301030
bool Changed = false;

mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Identifier {
7575
template <typename T>
7676
explicit Identifier(T value)
7777
: value(llvm::PointerLikeTypeTraits<T>::getAsVoidPointer(value)) {
78-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
78+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
7979
idType = llvm::getTypeName<T>();
8080
#endif
8181
}
@@ -84,7 +84,7 @@ class Identifier {
8484
/// the type of the identifier used to create it.
8585
template <typename T>
8686
T getValue() const {
87-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
87+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
8888
assert(llvm::getTypeName<T>() == idType &&
8989
"Identifier was initialized with a different type than the one used "
9090
"to retrieve it.");
@@ -108,7 +108,7 @@ class Identifier {
108108
/// The value of the identifier.
109109
void *value = nullptr;
110110

111-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
111+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
112112
/// TypeID of the identifiers in space. This should be used in asserts only.
113113
llvm::StringRef idType;
114114
#endif

mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class TransformState {
196196
/// should be emitted when the value is used.
197197
using InvalidatedHandleMap = DenseMap<Value, std::function<void(Location)>>;
198198

199-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
199+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
200200
/// Debug only: A timestamp is associated with each transform IR value, so
201201
/// that invalid iterator usage can be detected more reliably.
202202
using TransformIRTimestampMapping = DenseMap<Value, int64_t>;
@@ -211,7 +211,7 @@ class TransformState {
211211
ValueMapping values;
212212
ValueMapping reverseValues;
213213

214-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
214+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
215215
TransformIRTimestampMapping timestamps;
216216
void incrementTimestamp(Value value) { ++timestamps[value]; }
217217
#endif // LLVM_ENABLE_ABI_BREAKING_CHECKS
@@ -248,7 +248,7 @@ class TransformState {
248248
auto getPayloadOps(Value value) const {
249249
ArrayRef<Operation *> view = getPayloadOpsView(value);
250250

251-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
251+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
252252
// Memorize the current timestamp and make sure that it has not changed
253253
// when incrementing or dereferencing the iterator returned by this
254254
// function. The timestamp is incremented when the "direct" mapping is
@@ -259,7 +259,7 @@ class TransformState {
259259
// When ops are replaced/erased, they are replaced with nullptr (until
260260
// the data structure is compacted). Do not enumerate these ops.
261261
return llvm::make_filter_range(view, [=](Operation *op) {
262-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
262+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
263263
[[maybe_unused]] bool sameTimestamp =
264264
currentTimestamp == this->getMapping(value).timestamps.lookup(value);
265265
assert(sameTimestamp && "iterator was invalidated during iteration");
@@ -277,7 +277,7 @@ class TransformState {
277277
auto getPayloadValues(Value handleValue) const {
278278
ArrayRef<Value> view = getPayloadValuesView(handleValue);
279279

280-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
280+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
281281
// Memorize the current timestamp and make sure that it has not changed
282282
// when incrementing or dereferencing the iterator returned by this
283283
// function. The timestamp is incremented when the "values" mapping is

mlir/include/mlir/IR/PDLPatternMatch.h.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ template <typename PDLFnT, std::size_t... I>
625625
void assertArgs(PatternRewriter &rewriter, ArrayRef<PDLValue> values,
626626
std::index_sequence<I...>) {
627627
// We only want to do verification in debug builds, same as with `assert`.
628-
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
628+
#ifndef NDEBUG
629629
using FnTraitsT = llvm::function_traits<PDLFnT>;
630630
auto errorFn = [&](const Twine &msg) -> LogicalResult {
631631
llvm::report_fatal_error(msg);

mlir/lib/Analysis/Presburger/PresburgerSpace.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ using namespace presburger;
1818
bool Identifier::isEqual(const Identifier &other) const {
1919
if (value == nullptr || other.value == nullptr)
2020
return false;
21+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
2122
assert(value != other.value ||
2223
(value == other.value && idType == other.idType &&
2324
"Values of Identifiers are equal but their types do not match."));
25+
#endif
2426
return value == other.value;
2527
}
2628

mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ void transform::TransformState::forgetMapping(Value opHandle,
330330
for (Operation *op : mappings.direct[opHandle])
331331
dropMappingEntry(mappings.reverse, op, opHandle);
332332
mappings.direct.erase(opHandle);
333-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
333+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
334334
// Payload IR is removed from the mapping. This invalidates the respective
335335
// iterators.
336336
mappings.incrementTimestamp(opHandle);
@@ -342,7 +342,7 @@ void transform::TransformState::forgetMapping(Value opHandle,
342342
for (Value resultHandle : resultHandles) {
343343
Mappings &localMappings = getMapping(resultHandle);
344344
dropMappingEntry(localMappings.values, resultHandle, opResult);
345-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
345+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
346346
// Payload IR is removed from the mapping. This invalidates the respective
347347
// iterators.
348348
mappings.incrementTimestamp(resultHandle);
@@ -358,7 +358,7 @@ void transform::TransformState::forgetValueMapping(
358358
for (Value payloadValue : mappings.reverseValues[valueHandle])
359359
dropMappingEntry(mappings.reverseValues, payloadValue, valueHandle);
360360
mappings.values.erase(valueHandle);
361-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
361+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
362362
// Payload IR is removed from the mapping. This invalidates the respective
363363
// iterators.
364364
mappings.incrementTimestamp(valueHandle);
@@ -372,7 +372,7 @@ void transform::TransformState::forgetValueMapping(
372372
dropMappingEntry(localMappings.direct, opHandle, payloadOp);
373373
dropMappingEntry(localMappings.reverse, payloadOp, opHandle);
374374

375-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
375+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
376376
// Payload IR is removed from the mapping. This invalidates the respective
377377
// iterators.
378378
localMappings.incrementTimestamp(opHandle);
@@ -452,7 +452,7 @@ transform::TransformState::replacePayloadValue(Value value, Value replacement) {
452452
// between the handles and the IR objects
453453
if (!replacement) {
454454
dropMappingEntry(mappings.values, handle, value);
455-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
455+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
456456
// Payload IR is removed from the mapping. This invalidates the respective
457457
// iterators.
458458
mappings.incrementTimestamp(handle);
@@ -804,7 +804,7 @@ checkRepeatedConsumptionInOperand(ArrayRef<T> payload,
804804
void transform::TransformState::compactOpHandles() {
805805
for (Value handle : opHandlesToCompact) {
806806
Mappings &mappings = getMapping(handle, /*allowOutOfScope=*/true);
807-
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
807+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
808808
if (llvm::find(mappings.direct[handle], nullptr) !=
809809
mappings.direct[handle].end())
810810
// Payload IR is removed from the mapping. This invalidates the respective

0 commit comments

Comments
 (0)