Skip to content

[NFC] Split UniqueBBID definition to a separate file. #148043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/UniqueBBID.h"
#include "llvm/Target/TargetMachine.h"

namespace llvm {

// This struct represents the cluster information for a machine basic block,
// which is specifed by a unique ID (`MachineBasicBlock::BBID`).
// which is specifed by a unique basic block ID.
struct BBClusterInfo {
// Basic block ID.
UniqueBBID BBID;
Expand All @@ -52,27 +52,6 @@ struct FunctionPathAndClusterInfo {
SmallVector<SmallVector<unsigned>> ClonePaths;
};

// Provides DenseMapInfo for UniqueBBID.
template <> struct DenseMapInfo<UniqueBBID> {
static inline UniqueBBID getEmptyKey() {
unsigned EmptyKey = DenseMapInfo<unsigned>::getEmptyKey();
return UniqueBBID{EmptyKey, EmptyKey};
}
static inline UniqueBBID getTombstoneKey() {
unsigned TombstoneKey = DenseMapInfo<unsigned>::getTombstoneKey();
return UniqueBBID{TombstoneKey, TombstoneKey};
}
static unsigned getHashValue(const UniqueBBID &Val) {
std::pair<unsigned, unsigned> PairVal =
std::make_pair(Val.BaseID, Val.CloneID);
return DenseMapInfo<std::pair<unsigned, unsigned>>::getHashValue(PairVal);
}
static bool isEqual(const UniqueBBID &LHS, const UniqueBBID &RHS) {
return DenseMapInfo<unsigned>::isEqual(LHS.BaseID, RHS.BaseID) &&
DenseMapInfo<unsigned>::isEqual(LHS.CloneID, RHS.CloneID);
}
};

class BasicBlockSectionsProfileReader {
public:
friend class BasicBlockSectionsProfileReaderWrapperPass;
Expand Down
8 changes: 1 addition & 7 deletions llvm/include/llvm/CodeGen/MachineBasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "llvm/MC/LaneBitmask.h"
#include "llvm/Support/BranchProbability.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/UniqueBBID.h"
#include <cassert>
#include <cstdint>
#include <iterator>
Expand Down Expand Up @@ -99,13 +100,6 @@ template <> struct DenseMapInfo<MBBSectionID> {
}
};

// This structure represents the information for a basic block pertaining to
// the basic block sections profile.
struct UniqueBBID {
unsigned BaseID;
unsigned CloneID;
};

template <> struct ilist_traits<MachineInstr> {
private:
friend class MachineBasicBlock; // Set by the owning MachineBasicBlock.
Expand Down
50 changes: 50 additions & 0 deletions llvm/include/llvm/Support/UniqueBBID.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//===- llvm/Support/UniqueBBID.h --------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Unique fixed ID assigned to basic blocks upon their creation.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_SUPPORT_UNIQUEBBID_H
#define LLVM_SUPPORT_UNIQUEBBID_H

#include "llvm/ADT/DenseMapInfo.h"

namespace llvm {

// This structure represents the information for a basic block pertaining to
// the basic block sections profile.
struct UniqueBBID {
unsigned BaseID;
unsigned CloneID;
};

// Provides DenseMapInfo for UniqueBBID.
template <> struct DenseMapInfo<UniqueBBID> {
static inline UniqueBBID getEmptyKey() {
unsigned EmptyKey = DenseMapInfo<unsigned>::getEmptyKey();
return UniqueBBID{EmptyKey, EmptyKey};
}
static inline UniqueBBID getTombstoneKey() {
unsigned TombstoneKey = DenseMapInfo<unsigned>::getTombstoneKey();
return UniqueBBID{TombstoneKey, TombstoneKey};
}
static unsigned getHashValue(const UniqueBBID &Val) {
std::pair<unsigned, unsigned> PairVal =
std::make_pair(Val.BaseID, Val.CloneID);
return DenseMapInfo<std::pair<unsigned, unsigned>>::getHashValue(PairVal);
}
static bool isEqual(const UniqueBBID &LHS, const UniqueBBID &RHS) {
return DenseMapInfo<unsigned>::isEqual(LHS.BaseID, RHS.BaseID) &&
DenseMapInfo<unsigned>::isEqual(LHS.CloneID, RHS.CloneID);
}
};

} // end namespace llvm

#endif // LLVM_SUPPORT_UNIQUEBBID_H
1 change: 1 addition & 0 deletions llvm/lib/CodeGen/BasicBlockPathCloning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/InitializePasses.h"
#include "llvm/Support/UniqueBBID.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Target/TargetMachine.h"

Expand Down
1 change: 1 addition & 0 deletions llvm/lib/CodeGen/BasicBlockSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/InitializePasses.h"
#include "llvm/Support/UniqueBBID.h"
#include "llvm/Target/TargetMachine.h"
#include <optional>

Expand Down
1 change: 1 addition & 0 deletions llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/UniqueBBID.h"
#include <llvm/ADT/STLExtras.h>

using namespace llvm;
Expand Down
Loading