Skip to content

[TRANSFORMS][SUPPORT] Added const reference for params with size >= 16 bytes #125085

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions llvm/include/llvm/Support/BinaryStreamWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ class BinaryStreamWriter {
///
/// \returns a success error code if the data was successfully written,
/// otherwise returns an appropriate error code.
Error writeStreamRef(BinaryStreamRef Ref);
Error writeStreamRef(const BinaryStreamRef &Ref);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Ref seems to indicate this was intended to be passed by value. I assume this is 16-size? I would expect the minimum threshold to be at least > 16, not >= 16


/// Efficiently reads \p Size bytes from \p Ref, and writes it to this stream.
/// This operation will not invoke any copies of the source data, regardless
/// of the source stream's implementation.
///
/// \returns a success error code if the data was successfully written,
/// otherwise returns an appropriate error code.
Error writeStreamRef(BinaryStreamRef Ref, uint64_t Size);
Error writeStreamRef(const BinaryStreamRef &Ref, uint64_t Size);

/// Writes the object \p Obj to the underlying stream, as if by using memcpy.
/// It is up to the caller to ensure that type of \p Obj can be safely copied
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Support/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ Expected<T> handleExpected(Expected<T> ValOrErr, RecoveryFtor &&RecoveryPath,
/// This is useful in the base level of your program to allow clean termination
/// (allowing clean deallocation of resources, etc.), while reporting error
/// information to the user.
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner = {});
void logAllUnhandledErrors(Error E, raw_ostream &OS, const Twine &ErrorBanner = {});

/// Write all error messages (if any) in E to a string. The newline character
/// is used to separate error messages.
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Transforms/Scalar/Float2Int.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Float2IntPass : public PassInfoMixin<Float2IntPass> {
void seen(Instruction *I, ConstantRange R);
ConstantRange badRange();
ConstantRange unknownRange();
ConstantRange validateRange(ConstantRange R);
ConstantRange validateRange(const ConstantRange &R);
std::optional<ConstantRange> calcRange(Instruction *I);
void walkBackwards();
void walkForwards();
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Transforms/Scalar/GVN.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class GVNPass : public PassInfoMixin<GVNPass> {
/// Given a local dependency (Def or Clobber) determine if a value is
/// available for the load.
std::optional<gvn::AvailableValue>
AnalyzeLoadAvailability(LoadInst *Load, MemDepResult DepInfo, Value *Address);
AnalyzeLoadAvailability(LoadInst *Load, const MemDepResult &DepInfo, Value *Address);

/// Given a list of non-local dependencies, determine if a value is
/// available for the load in each specified block. If it is, add it to
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Transforms/Utils/FunctionImportUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class FunctionImportGlobalProcessing {
DenseMap<const Comdat *, Comdat *> RenamedComdats;

/// Check if we should promote the given local value to global scope.
bool shouldPromoteLocalToGlobal(const GlobalValue *SGV, ValueInfo VI);
bool shouldPromoteLocalToGlobal(const GlobalValue *SGV, const ValueInfo &VI);

#ifndef NDEBUG
/// Check if the given value is a local that can't be renamed (promoted).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DependencyGraph;
/// While OpIt points to a Value that is not an Instruction keep incrementing
/// it. \Returns the first iterator that points to an Instruction, or end.
[[nodiscard]] static User::op_iterator skipNonInstr(User::op_iterator OpIt,
User::op_iterator OpItE) {
const User::op_iterator &OpItE) {
while (OpIt != OpItE && !isa<Instruction>((*OpIt).get()))
++OpIt;
return OpIt;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Support/AMDGPUMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ std::error_code fromString(StringRef String, Metadata &HSAMetadata) {
return YamlInput.error();
}

std::error_code toString(Metadata HSAMetadata, std::string &String) {
std::error_code toString(Metadata &HSAMetadata, std::string &String) {
raw_string_ostream YamlStream(String);
yaml::Output YamlOutput(YamlStream, nullptr, std::numeric_limits<int>::max());
YamlOutput << HSAMetadata;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Support/BinaryStreamWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ Error BinaryStreamWriter::writeFixedString(StringRef Str) {
return writeBytes(arrayRefFromStringRef(Str));
}

Error BinaryStreamWriter::writeStreamRef(BinaryStreamRef Ref) {
Error BinaryStreamWriter::writeStreamRef(const BinaryStreamRef &Ref) {
return writeStreamRef(Ref, Ref.getLength());
}

Error BinaryStreamWriter::writeStreamRef(BinaryStreamRef Ref, uint64_t Length) {
Error BinaryStreamWriter::writeStreamRef(const BinaryStreamRef &Ref, uint64_t Length) {
BinaryStreamReader SrcReader(Ref.slice(0, Length));
// This is a bit tricky. If we just call readBytes, we are requiring that it
// return us the entire stream as a contiguous buffer. There is no guarantee
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Support/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ char ECError::ID = 0;
char StringError::ID = 0;
char FileError::ID = 0;

void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner) {
void logAllUnhandledErrors(Error E, raw_ostream &OS, const Twine &ErrorBanner) {
if (!E)
return;
OS << ErrorBanner;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ MachineTypes getEmulation(StringRef S) {
.Default(IMAGE_FILE_MACHINE_UNKNOWN);
}

MachineTypes getMachine(Triple T) {
MachineTypes getMachine(const Triple &T) {
switch (T.getArch()) {
case Triple::x86:
return COFF::IMAGE_FILE_MACHINE_I386;
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7536,7 +7536,7 @@ struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl {
/// Extract values from \p Base according to the type \p PrivType at the
/// call position \p ACS. The values are appended to \p ReplacementValues.
void createReplacementValues(Align Alignment, Type *PrivType,
AbstractCallSite ACS, Value *Base,
const AbstractCallSite &ACS, Value *Base,
SmallVectorImpl<Value *> &ReplacementValues) {
assert(Base && "Expected base value!");
assert(PrivType && "Expected privatizable type!");
Expand Down Expand Up @@ -11156,7 +11156,7 @@ struct AAPotentialValuesFloating : AAPotentialValuesImpl {
return true;
}

bool handleLoadInst(Attributor &A, LoadInst &LI, ItemInfo II,
bool handleLoadInst(Attributor &A, LoadInst &LI, const ItemInfo &II,
SmallVectorImpl<ItemInfo> &Worklist) {
SmallSetVector<Value *, 4> PotentialCopies;
SmallSetVector<Instruction *, 4> PotentialValueOrigins;
Expand Down Expand Up @@ -11280,7 +11280,7 @@ struct AAPotentialValuesFloating : AAPotentialValuesImpl {
/// Use the generic, non-optimistic InstSimplfy functionality if we managed to
/// simplify any operand of the instruction \p I. Return true if successful,
/// in that case Worklist will be updated.
bool handleGenericInst(Attributor &A, Instruction &I, ItemInfo II,
bool handleGenericInst(Attributor &A, Instruction &I, const ItemInfo &II,
SmallVectorImpl<ItemInfo> &Worklist) {
bool SomeSimplified = false;
bool UsedAssumedInformation = false;
Expand Down Expand Up @@ -11330,7 +11330,7 @@ struct AAPotentialValuesFloating : AAPotentialValuesImpl {
}

bool simplifyInstruction(
Attributor &A, Instruction &I, ItemInfo II,
Attributor &A, Instruction &I, const ItemInfo &II,
SmallVectorImpl<ItemInfo> &Worklist,
SmallMapVector<const Function *, LivenessInfo, 4> &LivenessAAs) {
if (auto *CI = dyn_cast<CmpInst>(&I))
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/IPO/CalledValuePropagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class CVPLatticeFunc
}

/// Print the given CVPLatticeVal to the specified stream.
void PrintLatticeVal(CVPLatticeVal LV, raw_ostream &OS) override {
void PrintLatticeVal(const CVPLatticeVal &LV, raw_ostream &OS) override {
if (LV == getUndefVal())
OS << "Undefined ";
else if (LV == getOverdefinedVal())
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/IPO/FunctionAttrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ static void addMemoryAttrs(const SCCNodeSet &SCCNodes, AARGetterT &&AARGetter,
// Compute definitive function attributes for a function taking into account
// prevailing definitions and linkage types
static FunctionSummary *calculatePrevailingSummary(
ValueInfo VI,
const ValueInfo &VI,
DenseMap<ValueInfo, FunctionSummary *> &CachedPrevailingSummary,
function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
IsPrevailing) {
Expand Down Expand Up @@ -1714,7 +1714,7 @@ class AttributeInferer {
SmallVector<InferenceDescriptor, 4> InferenceDescriptors;

public:
void registerAttrInference(InferenceDescriptor AttrInference) {
void registerAttrInference(const InferenceDescriptor &AttrInference) {
InferenceDescriptors.push_back(AttrInference);
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/IPO/FunctionImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ void ModuleImportsManager::computeImportForModule(
}

#ifndef NDEBUG
static bool isGlobalVarSummary(const ModuleSummaryIndex &Index, ValueInfo VI) {
static bool isGlobalVarSummary(const ModuleSummaryIndex &Index, const ValueInfo &VI) {
auto SL = VI.getSummaryList();
return SL.empty()
? false
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ struct FactOrCheck {

static FactOrCheck getConditionFact(DomTreeNode *DTN, CmpPredicate Pred,
Value *Op0, Value *Op1,
ConditionTy Precond = {}) {
const ConditionTy &Precond = {}) {
return FactOrCheck(DTN, Pred, Op0, Op1, Precond);
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/Float2Int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ ConstantRange Float2IntPass::badRange() {
ConstantRange Float2IntPass::unknownRange() {
return ConstantRange::getEmpty(MaxIntegerBW + 1);
}
ConstantRange Float2IntPass::validateRange(ConstantRange R) {
ConstantRange Float2IntPass::validateRange(const ConstantRange &R) {
if (R.getBitWidth() > MaxIntegerBW + 1)
return badRange();
return R;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Scalar/GVN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ static bool liesBetween(const Instruction *From, Instruction *Between,

/// Try to locate the three instruction involved in a missed
/// load-elimination case that is due to an intervening store.
static void reportMayClobberedLoad(LoadInst *Load, MemDepResult DepInfo,
static void reportMayClobberedLoad(LoadInst *Load, const MemDepResult &DepInfo,
DominatorTree *DT,
OptimizationRemarkEmitter *ORE) {
using namespace ore;
Expand Down Expand Up @@ -1254,7 +1254,7 @@ static Value *findDominatingValue(const MemoryLocation &Loc, Type *LoadTy,
}

std::optional<AvailableValue>
GVNPass::AnalyzeLoadAvailability(LoadInst *Load, MemDepResult DepInfo,
GVNPass::AnalyzeLoadAvailability(LoadInst *Load, const MemDepResult &DepInfo,
Value *Address) {
assert(Load->isUnordered() && "rules below are incorrect for ordered access");
assert(DepInfo.isLocal() && "expected a local dependence");
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ struct AssumeBuilderState {
AssumptionCache *AC = nullptr, DominatorTree *DT = nullptr)
: M(M), InstBeingModified(I), AC(AC), DT(DT) {}

bool tryToPreserveWithoutAddingAssume(RetainedKnowledge RK) {
bool tryToPreserveWithoutAddingAssume(const RetainedKnowledge &RK) const {
if (!InstBeingModified || !RK.WasOn)
return false;
bool HasBeenPreserved = false;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Utils/CodeLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ struct ChainEdge {
return Src == SrcChain ? CachedGainForward : CachedGainBackward;
}

void setCachedMergeGain(ChainT *Src, ChainT *Dst, MergeGainT MergeGain) {
void setCachedMergeGain(ChainT *Src, ChainT *Dst, const MergeGainT &MergeGain) {
if (Src == SrcChain) {
CachedGainForward = MergeGain;
CacheValidForward = true;
Expand All @@ -422,7 +422,7 @@ struct ChainEdge {
CacheValidBackward = false;
}

void setMergeGain(MergeGainT Gain) { CachedGain = Gain; }
void setMergeGain(const MergeGainT &Gain) { CachedGain = Gain; }

MergeGainT getMergeGain() const { return CachedGain; }

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bool FunctionImportGlobalProcessing::doImportAsDefinition(
}

bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(
const GlobalValue *SGV, ValueInfo VI) {
const GlobalValue *SGV, const ValueInfo &VI) {
assert(SGV->hasLocalLinkage());

// Ifuncs and ifunc alias does not have summary.
Expand Down