Skip to content
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
12 changes: 5 additions & 7 deletions llvm/lib/IR/Assumptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@

using namespace llvm;

namespace {
bool hasAssumption(const Attribute &A,
const KnownAssumptionString &AssumptionStr) {
static bool hasAssumption(const Attribute &A,
const KnownAssumptionString &AssumptionStr) {
if (!A.isValid())
return false;
assert(A.isStringAttribute() && "Expected a string attribute!");
Expand All @@ -33,7 +32,7 @@ bool hasAssumption(const Attribute &A,
return llvm::is_contained(Strings, AssumptionStr);
}

DenseSet<StringRef> getAssumptions(const Attribute &A) {
static DenseSet<StringRef> getAssumptions(const Attribute &A) {
if (!A.isValid())
return DenseSet<StringRef>();
assert(A.isStringAttribute() && "Expected a string attribute!");
Expand All @@ -47,8 +46,8 @@ DenseSet<StringRef> getAssumptions(const Attribute &A) {
}

template <typename AttrSite>
bool addAssumptionsImpl(AttrSite &Site,
const DenseSet<StringRef> &Assumptions) {
static bool addAssumptionsImpl(AttrSite &Site,
const DenseSet<StringRef> &Assumptions) {
if (Assumptions.empty())
return false;

Expand All @@ -64,7 +63,6 @@ bool addAssumptionsImpl(AttrSite &Site,

return true;
}
} // namespace

bool llvm::hasAssumption(const Function &F,
const KnownAssumptionString &AssumptionStr) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/IR/DiagnosticHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct PassRemarksOpt {
}
}
};
} // namespace

static PassRemarksOpt PassRemarksPassedOptLoc;
static PassRemarksOpt PassRemarksMissedOptLoc;
Expand Down Expand Up @@ -66,7 +67,6 @@ static cl::opt<PassRemarksOpt, true, cl::parser<std::string>>
"Enable optimization analysis remarks from passes whose name match "
"the given regular expression"),
cl::Hidden, cl::location(PassRemarksAnalysisOptLoc), cl::ValueRequired);
}

bool DiagnosticHandler::isAnalysisRemarkEnabled(StringRef PassName) const {
return (PassRemarksAnalysisOptLoc.Pattern &&
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/IR/ModuleSummaryIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ struct Edge {
GlobalValue::GUID Src;
GlobalValue::GUID Dst;
};
}
} // namespace

void Attributes::add(const Twine &Name, const Twine &Value,
const Twine &Comment) {
Expand Down
7 changes: 3 additions & 4 deletions llvm/lib/IR/PassInstrumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/PassManager.h"

namespace llvm {
using namespace llvm;

template struct LLVM_EXPORT_TEMPLATE Any::TypeId<const Module *>;
template struct LLVM_EXPORT_TEMPLATE Any::TypeId<const Function *>;
Expand All @@ -42,13 +42,12 @@ PassInstrumentationCallbacks::getPassNameForClassName(StringRef ClassName) {

AnalysisKey PassInstrumentationAnalysis::Key;

bool isSpecialPass(StringRef PassID, const std::vector<StringRef> &Specials) {
bool llvm::isSpecialPass(StringRef PassID,
const std::vector<StringRef> &Specials) {
size_t Pos = PassID.find('<');
StringRef Prefix = PassID;
if (Pos != StringRef::npos)
Prefix = PassID.substr(0, Pos);
return any_of(Specials,
[Prefix](StringRef S) { return Prefix.ends_with(S); });
}

} // namespace llvm
99 changes: 49 additions & 50 deletions llvm/lib/IR/ProfDataUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

using namespace llvm;

namespace {

// MD_prof nodes have the following layout
//
// In general:
Expand All @@ -41,14 +39,15 @@ namespace {
// correctly, and can change the behavior in the future if the layout changes

// the minimum number of operands for MD_prof nodes with branch weights
constexpr unsigned MinBWOps = 3;
static constexpr unsigned MinBWOps = 3;

// the minimum number of operands for MD_prof nodes with value profiles
constexpr unsigned MinVPOps = 5;
static constexpr unsigned MinVPOps = 5;

// We may want to add support for other MD_prof types, so provide an abstraction
// for checking the metadata type.
bool isTargetMD(const MDNode *ProfData, const char *Name, unsigned MinOps) {
static bool isTargetMD(const MDNode *ProfData, const char *Name,
unsigned MinOps) {
// TODO: This routine may be simplified if MD_prof used an enum instead of a
// string to differentiate the types of MD_prof nodes.
if (!ProfData || !Name || MinOps < 2)
Expand Down Expand Up @@ -101,14 +100,11 @@ static SmallVector<uint32_t> fitWeights(ArrayRef<uint64_t> Weights) {
return Ret;
}

} // namespace

namespace llvm {
cl::opt<bool> ElideAllZeroBranchWeights("elide-all-zero-branch-weights",
static cl::opt<bool> ElideAllZeroBranchWeights("elide-all-zero-branch-weights",
#if defined(LLVM_ENABLE_PROFCHECK)
cl::init(false)
cl::init(false)
#else
cl::init(true)
cl::init(true)
#endif
);
const char *MDProfLabels::BranchWeights = "branch_weights";
Expand All @@ -118,21 +114,21 @@ const char *MDProfLabels::FunctionEntryCount = "function_entry_count";
const char *MDProfLabels::SyntheticFunctionEntryCount =
"synthetic_function_entry_count";
const char *MDProfLabels::UnknownBranchWeightsMarker = "unknown";
const char *LLVMLoopEstimatedTripCount = "llvm.loop.estimated_trip_count";
const char *llvm::LLVMLoopEstimatedTripCount = "llvm.loop.estimated_trip_count";

bool hasProfMD(const Instruction &I) {
bool llvm::hasProfMD(const Instruction &I) {
return I.hasMetadata(LLVMContext::MD_prof);
}

bool isBranchWeightMD(const MDNode *ProfileData) {
bool llvm::isBranchWeightMD(const MDNode *ProfileData) {
return isTargetMD(ProfileData, MDProfLabels::BranchWeights, MinBWOps);
}

bool isValueProfileMD(const MDNode *ProfileData) {
bool llvm::isValueProfileMD(const MDNode *ProfileData) {
return isTargetMD(ProfileData, MDProfLabels::ValueProfile, MinVPOps);
}

bool hasBranchWeightMD(const Instruction &I) {
bool llvm::hasBranchWeightMD(const Instruction &I) {
auto *ProfileData = I.getMetadata(LLVMContext::MD_prof);
return isBranchWeightMD(ProfileData);
}
Expand All @@ -147,16 +143,16 @@ static bool hasCountTypeMD(const Instruction &I) {
return isa<CallBase>(I) && !isBranchWeightMD(ProfileData);
}

bool hasValidBranchWeightMD(const Instruction &I) {
bool llvm::hasValidBranchWeightMD(const Instruction &I) {
return getValidBranchWeightMDNode(I);
}

bool hasBranchWeightOrigin(const Instruction &I) {
bool llvm::hasBranchWeightOrigin(const Instruction &I) {
auto *ProfileData = I.getMetadata(LLVMContext::MD_prof);
return hasBranchWeightOrigin(ProfileData);
}

bool hasBranchWeightOrigin(const MDNode *ProfileData) {
bool llvm::hasBranchWeightOrigin(const MDNode *ProfileData) {
if (!isBranchWeightMD(ProfileData))
return false;
auto *ProfDataName = dyn_cast<MDString>(ProfileData->getOperand(1));
Expand All @@ -168,54 +164,54 @@ bool hasBranchWeightOrigin(const MDNode *ProfileData) {
return ProfDataName != nullptr;
}

unsigned getBranchWeightOffset(const MDNode *ProfileData) {
unsigned llvm::getBranchWeightOffset(const MDNode *ProfileData) {
return hasBranchWeightOrigin(ProfileData) ? 2 : 1;
}

unsigned getNumBranchWeights(const MDNode &ProfileData) {
unsigned llvm::getNumBranchWeights(const MDNode &ProfileData) {
return ProfileData.getNumOperands() - getBranchWeightOffset(&ProfileData);
}

MDNode *getBranchWeightMDNode(const Instruction &I) {
MDNode *llvm::getBranchWeightMDNode(const Instruction &I) {
auto *ProfileData = I.getMetadata(LLVMContext::MD_prof);
if (!isBranchWeightMD(ProfileData))
return nullptr;
return ProfileData;
}

MDNode *getValidBranchWeightMDNode(const Instruction &I) {
MDNode *llvm::getValidBranchWeightMDNode(const Instruction &I) {
auto *ProfileData = getBranchWeightMDNode(I);
if (ProfileData && getNumBranchWeights(*ProfileData) == I.getNumSuccessors())
return ProfileData;
return nullptr;
}

void extractFromBranchWeightMD32(const MDNode *ProfileData,
SmallVectorImpl<uint32_t> &Weights) {
void llvm::extractFromBranchWeightMD32(const MDNode *ProfileData,
SmallVectorImpl<uint32_t> &Weights) {
extractFromBranchWeightMD(ProfileData, Weights);
}

void extractFromBranchWeightMD64(const MDNode *ProfileData,
SmallVectorImpl<uint64_t> &Weights) {
void llvm::extractFromBranchWeightMD64(const MDNode *ProfileData,
SmallVectorImpl<uint64_t> &Weights) {
extractFromBranchWeightMD(ProfileData, Weights);
}

bool extractBranchWeights(const MDNode *ProfileData,
SmallVectorImpl<uint32_t> &Weights) {
bool llvm::extractBranchWeights(const MDNode *ProfileData,
SmallVectorImpl<uint32_t> &Weights) {
if (!isBranchWeightMD(ProfileData))
return false;
extractFromBranchWeightMD(ProfileData, Weights);
return true;
}

bool extractBranchWeights(const Instruction &I,
SmallVectorImpl<uint32_t> &Weights) {
bool llvm::extractBranchWeights(const Instruction &I,
SmallVectorImpl<uint32_t> &Weights) {
auto *ProfileData = I.getMetadata(LLVMContext::MD_prof);
return extractBranchWeights(ProfileData, Weights);
}

bool extractBranchWeights(const Instruction &I, uint64_t &TrueVal,
uint64_t &FalseVal) {
bool llvm::extractBranchWeights(const Instruction &I, uint64_t &TrueVal,
uint64_t &FalseVal) {
assert((I.getOpcode() == Instruction::Br ||
I.getOpcode() == Instruction::Select) &&
"Looking for branch weights on something besides branch, select, or "
Expand All @@ -234,7 +230,8 @@ bool extractBranchWeights(const Instruction &I, uint64_t &TrueVal,
return true;
}

bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalVal) {
bool llvm::extractProfTotalWeight(const MDNode *ProfileData,
uint64_t &TotalVal) {
TotalVal = 0;
if (!ProfileData)
return false;
Expand Down Expand Up @@ -262,11 +259,12 @@ bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalVal) {
return false;
}

bool extractProfTotalWeight(const Instruction &I, uint64_t &TotalVal) {
bool llvm::extractProfTotalWeight(const Instruction &I, uint64_t &TotalVal) {
return extractProfTotalWeight(I.getMetadata(LLVMContext::MD_prof), TotalVal);
}

void setExplicitlyUnknownBranchWeights(Instruction &I, StringRef PassName) {
void llvm::setExplicitlyUnknownBranchWeights(Instruction &I,
StringRef PassName) {
MDBuilder MDB(I.getContext());
I.setMetadata(
LLVMContext::MD_prof,
Expand All @@ -275,14 +273,16 @@ void setExplicitlyUnknownBranchWeights(Instruction &I, StringRef PassName) {
MDB.createString(PassName)}));
}

void setExplicitlyUnknownBranchWeightsIfProfiled(Instruction &I, Function &F,
StringRef PassName) {
void llvm::setExplicitlyUnknownBranchWeightsIfProfiled(Instruction &I,
Function &F,
StringRef PassName) {
if (std::optional<Function::ProfileCount> EC = F.getEntryCount();
EC && EC->getCount() > 0)
setExplicitlyUnknownBranchWeights(I, PassName);
}

void setExplicitlyUnknownFunctionEntryCount(Function &F, StringRef PassName) {
void llvm::setExplicitlyUnknownFunctionEntryCount(Function &F,
StringRef PassName) {
MDBuilder MDB(F.getContext());
F.setMetadata(
LLVMContext::MD_prof,
Expand All @@ -291,21 +291,21 @@ void setExplicitlyUnknownFunctionEntryCount(Function &F, StringRef PassName) {
MDB.createString(PassName)}));
}

bool isExplicitlyUnknownProfileMetadata(const MDNode &MD) {
bool llvm::isExplicitlyUnknownProfileMetadata(const MDNode &MD) {
if (MD.getNumOperands() != 2)
return false;
return MD.getOperand(0).equalsStr(MDProfLabels::UnknownBranchWeightsMarker);
}

bool hasExplicitlyUnknownBranchWeights(const Instruction &I) {
bool llvm::hasExplicitlyUnknownBranchWeights(const Instruction &I) {
auto *MD = I.getMetadata(LLVMContext::MD_prof);
if (!MD)
return false;
return isExplicitlyUnknownProfileMetadata(*MD);
}

void setBranchWeights(Instruction &I, ArrayRef<uint32_t> Weights,
bool IsExpected, bool ElideAllZero) {
void llvm::setBranchWeights(Instruction &I, ArrayRef<uint32_t> Weights,
bool IsExpected, bool ElideAllZero) {
if ((ElideAllZeroBranchWeights && ElideAllZero) &&
llvm::all_of(Weights, [](uint32_t V) { return V == 0; })) {
I.setMetadata(LLVMContext::MD_prof, nullptr);
Expand All @@ -317,13 +317,14 @@ void setBranchWeights(Instruction &I, ArrayRef<uint32_t> Weights,
I.setMetadata(LLVMContext::MD_prof, BranchWeights);
}

void setFittedBranchWeights(Instruction &I, ArrayRef<uint64_t> Weights,
bool IsExpected, bool ElideAllZero) {
void llvm::setFittedBranchWeights(Instruction &I, ArrayRef<uint64_t> Weights,
bool IsExpected, bool ElideAllZero) {
setBranchWeights(I, fitWeights(Weights), IsExpected, ElideAllZero);
}

SmallVector<uint32_t> downscaleWeights(ArrayRef<uint64_t> Weights,
std::optional<uint64_t> KnownMaxCount) {
SmallVector<uint32_t>
llvm::downscaleWeights(ArrayRef<uint64_t> Weights,
std::optional<uint64_t> KnownMaxCount) {
uint64_t MaxCount = KnownMaxCount.has_value() ? KnownMaxCount.value()
: *llvm::max_element(Weights);
assert(MaxCount > 0 && "Bad max count");
Expand All @@ -334,7 +335,7 @@ SmallVector<uint32_t> downscaleWeights(ArrayRef<uint64_t> Weights,
return DownscaledWeights;
}

void scaleProfData(Instruction &I, uint64_t S, uint64_t T) {
void llvm::scaleProfData(Instruction &I, uint64_t S, uint64_t T) {
assert(T != 0 && "Caller should guarantee");
auto *ProfileData = I.getMetadata(LLVMContext::MD_prof);
if (ProfileData == nullptr)
Expand Down Expand Up @@ -387,5 +388,3 @@ void scaleProfData(Instruction &I, uint64_t S, uint64_t T) {
}
I.setMetadata(LLVMContext::MD_prof, MDNode::get(C, Vals));
}

} // namespace llvm
2 changes: 0 additions & 2 deletions llvm/lib/IR/SafepointIRVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ class CFGDeadness {
static void Verify(const Function &F, const DominatorTree &DT,
const CFGDeadness &CD);

namespace llvm {
PreservedAnalyses SafepointIRVerifierPass::run(Function &F,
FunctionAnalysisManager &AM) {
const auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
Expand All @@ -205,7 +204,6 @@ PreservedAnalyses SafepointIRVerifierPass::run(Function &F,
Verify(F, DT, CD);
return PreservedAnalyses::all();
}
} // namespace llvm

namespace {

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/IR/VFABIDemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ using namespace llvm;

#define DEBUG_TYPE "vfabi-demangler"

namespace {
/// Utilities for the Vector Function ABI name parser.

namespace {
/// Return types for the parser functions.
enum class ParseRet {
OK, // Found.
None, // Not found.
Error // Syntax error.
};
} // namespace

/// Extracts the `<isa>` information from the mangled string, and
/// sets the `ISA` accordingly. If successful, the <isa> token is removed
Expand Down Expand Up @@ -372,7 +373,6 @@ getScalableECFromSignature(const FunctionType *Signature, const VFISAKind ISA,

return std::nullopt;
}
} // namespace

// Format of the ABI name:
// _ZGV<isa><mask><vlen><parameters>_<scalarname>[(<redirection>)]
Expand Down
Loading