Skip to content

Commit cc869e1

Browse files
Apply reviews
1 parent 3753bc0 commit cc869e1

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
@@ -17,12 +17,13 @@
1717
#include "clang/CIR/Dialect/IR/CIRTypes.h"
1818
#include "clang/CIR/Interfaces/CIRLoopOpInterface.h"
1919
#include "clang/CIR/MissingFeatures.h"
20+
#include "llvm/ADT/SetOperations.h"
21+
#include "llvm/ADT/SmallSet.h"
2022
#include "llvm/ADT/TypeSwitch.h"
2123
#include "llvm/Support/ErrorHandling.h"
2224
#include "llvm/Support/LogicalResult.h"
2325
#include <numeric>
2426
#include <optional>
25-
#include <set>
2627

2728
#include "mlir/Dialect/Func/IR/FuncOps.h"
2829
#include "mlir/Dialect/LLVMIR/LLVMTypes.h"
@@ -2886,38 +2887,41 @@ LogicalResult cir::FuncOp::verify() {
28862887
<< "' must have empty body";
28872888
}
28882889

2889-
std::set<llvm::StringRef> labels;
2890-
std::set<llvm::StringRef> gotos;
2891-
std::set<llvm::StringRef> blockAddresses;
2890+
llvm::SmallSet<llvm::StringRef, 16> labels;
2891+
llvm::SmallSet<llvm::StringRef, 16> gotos;
2892+
llvm::SmallSet<llvm::StringRef, 16> blockAddresses;
28922893
bool invalidBlockAddress = false;
28932894
getOperation()->walk([&](mlir::Operation *op) {
28942895
if (auto lab = dyn_cast<cir::LabelOp>(op)) {
2895-
labels.emplace(lab.getLabel());
2896+
labels.insert(lab.getLabel());
28962897
} else if (auto goTo = dyn_cast<cir::GotoOp>(op)) {
2897-
gotos.emplace(goTo.getLabel());
2898+
gotos.insert(goTo.getLabel());
28982899
} else if (auto blkAdd = dyn_cast<cir::BlockAddressOp>(op)) {
2899-
if (blkAdd.getFunc() != getSymName())
2900+
if (blkAdd.getFunc() != getSymName()) {
2901+
// Stop the walk early, no need to continue
29002902
invalidBlockAddress = true;
2901-
blockAddresses.emplace(blkAdd.getLabel());
2903+
return mlir::WalkResult::interrupt();
2904+
}
2905+
blockAddresses.insert(blkAdd.getLabel());
29022906
}
2907+
return mlir::WalkResult::advance();
29032908
});
29042909

29052910
if (invalidBlockAddress)
29062911
return emitOpError() << "blockaddress references a different function";
29072912

2908-
{
2909-
std::vector<llvm::StringRef> mismatched;
2910-
std::set_difference(gotos.begin(), gotos.end(), labels.begin(),
2911-
labels.end(), std::back_inserter(mismatched));
2913+
llvm::SmallSet<llvm::StringRef, 16> mismatched;
2914+
if (!labels.empty() || !gotos.empty()) {
2915+
mismatched = llvm::set_difference(gotos, labels);
29122916

29132917
if (!mismatched.empty())
29142918
return emitOpError() << "goto/label mismatch";
29152919
}
2916-
{
2917-
std::vector<llvm::StringRef> mismatched;
2918-
std::set_difference(blockAddresses.begin(), blockAddresses.end(),
2919-
labels.begin(), labels.end(),
2920-
std::back_inserter(mismatched));
2920+
2921+
mismatched.clear();
2922+
2923+
if (!labels.empty() || !blockAddresses.empty()) {
2924+
mismatched = llvm::set_difference(blockAddresses, labels);
29212925

29222926
if (!mismatched.empty())
29232927
return emitOpError()

0 commit comments

Comments
 (0)