Skip to content

Commit 8c51d1e

Browse files
Apply reviews
1 parent 68108e6 commit 8c51d1e

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
#include "clang/CIR/Interfaces/CIRLoopOpInterface.h"
1919
#include "clang/CIR/MissingFeatures.h"
2020
#include "llvm/ADT/StringExtras.h"
21+
#include "llvm/ADT/SetOperations.h"
22+
#include "llvm/ADT/SmallSet.h"
2123
#include "llvm/ADT/TypeSwitch.h"
2224
#include "llvm/Support/ErrorHandling.h"
2325
#include "llvm/Support/LogicalResult.h"
2426
#include <numeric>
2527
#include <optional>
26-
#include <set>
2728

2829
#include "mlir/Dialect/Func/IR/FuncOps.h"
2930
#include "mlir/Dialect/LLVMIR/LLVMTypes.h"
@@ -2928,38 +2929,41 @@ LogicalResult cir::FuncOp::verify() {
29282929
<< "' must have empty body";
29292930
}
29302931

2931-
std::set<llvm::StringRef> labels;
2932-
std::set<llvm::StringRef> gotos;
2933-
std::set<llvm::StringRef> blockAddresses;
2932+
llvm::SmallSet<llvm::StringRef, 16> labels;
2933+
llvm::SmallSet<llvm::StringRef, 16> gotos;
2934+
llvm::SmallSet<llvm::StringRef, 16> blockAddresses;
29342935
bool invalidBlockAddress = false;
29352936
getOperation()->walk([&](mlir::Operation *op) {
29362937
if (auto lab = dyn_cast<cir::LabelOp>(op)) {
2937-
labels.emplace(lab.getLabel());
2938+
labels.insert(lab.getLabel());
29382939
} else if (auto goTo = dyn_cast<cir::GotoOp>(op)) {
2939-
gotos.emplace(goTo.getLabel());
2940+
gotos.insert(goTo.getLabel());
29402941
} else if (auto blkAdd = dyn_cast<cir::BlockAddressOp>(op)) {
2941-
if (blkAdd.getFunc() != getSymName())
2942+
if (blkAdd.getFunc() != getSymName()) {
2943+
// Stop the walk early, no need to continue
29422944
invalidBlockAddress = true;
2943-
blockAddresses.emplace(blkAdd.getLabel());
2945+
return mlir::WalkResult::interrupt();
2946+
}
2947+
blockAddresses.insert(blkAdd.getLabel());
29442948
}
2949+
return mlir::WalkResult::advance();
29452950
});
29462951

29472952
if (invalidBlockAddress)
29482953
return emitOpError() << "blockaddress references a different function";
29492954

2950-
{
2951-
std::vector<llvm::StringRef> mismatched;
2952-
std::set_difference(gotos.begin(), gotos.end(), labels.begin(),
2953-
labels.end(), std::back_inserter(mismatched));
2955+
llvm::SmallSet<llvm::StringRef, 16> mismatched;
2956+
if (!labels.empty() || !gotos.empty()) {
2957+
mismatched = llvm::set_difference(gotos, labels);
29542958

29552959
if (!mismatched.empty())
29562960
return emitOpError() << "goto/label mismatch";
29572961
}
2958-
{
2959-
std::vector<llvm::StringRef> mismatched;
2960-
std::set_difference(blockAddresses.begin(), blockAddresses.end(),
2961-
labels.begin(), labels.end(),
2962-
std::back_inserter(mismatched));
2962+
2963+
mismatched.clear();
2964+
2965+
if (!labels.empty() || !blockAddresses.empty()) {
2966+
mismatched = llvm::set_difference(blockAddresses, labels);
29632967

29642968
if (!mismatched.empty())
29652969
return emitOpError()

0 commit comments

Comments
 (0)