Skip to content

Commit

Permalink
Move from llvm::makeArrayRef to ArrayRef deduction guides - llvm/ part
Browse files Browse the repository at this point in the history
Use deduction guides instead of helper functions.

The only non-automatic changes have been:

1. ArrayRef(some_uint8_pointer, 0) needs to be changed into ArrayRef(some_uint8_pointer, (size_t)0) to avoid an ambiguous call with ArrayRef((uint8_t*), (uint8_t*))
2. CVSymbol sym(makeArrayRef(symStorage)); needed to be rewritten as CVSymbol sym{ArrayRef(symStorage)}; otherwise the compiler is confused and thinks we have a (bad) function prototype. There was a few similar situation across the codebase.
3. ADL doesn't seem to work the same for deduction-guides and functions, so at some point the llvm namespace must be explicitly stated.
4. The "reference mode" of makeArrayRef(ArrayRef<T> &) that acts as no-op is not supported (a constructor cannot achieve that).

Per reviewers' comment, some useless makeArrayRef have been removed in the process.

This is a follow-up to https://reviews.llvm.org/D140896 that introduced
the deduction guides.

Differential Revision: https://reviews.llvm.org/D140955
  • Loading branch information
serge-sans-paille committed Jan 5, 2023
1 parent 11be5cc commit 38818b6
Show file tree
Hide file tree
Showing 270 changed files with 981 additions and 1,044 deletions.
6 changes: 3 additions & 3 deletions llvm/docs/TableGen/BackEnds.rst
Expand Up @@ -776,7 +776,7 @@ is guarded by ``GET_ATable_DECL``, while the definitions are guarded by
uint16_t Val2;
};
KeyType Key = { Val1, Val2 };
auto Table = makeArrayRef(ATable);
auto Table = ArrayRef(ATable);
auto Idx = std::lower_bound(Table.begin(), Table.end(), Key,
[](const AEntry &LHS, const KeyType &RHS) {
if (LHS.Val1 < RHS.Val1)
Expand Down Expand Up @@ -850,7 +850,7 @@ Here is the generated C++ code.
uint16_t Encoding;
};
KeyType Key = { Encoding };
auto Table = makeArrayRef(CTable);
auto Table = ArrayRef(CTable);
auto Idx = std::lower_bound(Table.begin(), Table.end(), Key,
[](const CEntry &LHS, const KeyType &RHS) {
if (LHS.Encoding < RHS.Encoding)
Expand Down Expand Up @@ -948,7 +948,7 @@ This use of ``SearchIndex`` generates the following additional C++ code.
unsigned Kind;
};
KeyType Key = { Name.upper(), Kind };
auto Table = makeArrayRef(Index);
auto Table = ArrayRef(Index);
auto Idx = std::lower_bound(Table.begin(), Table.end(), Key,
[](const IndexType &LHS, const KeyType &RHS) {
int CmpName = StringRef(LHS.Name).compare(RHS.Name);
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/ADT/SmallBitVector.h
Expand Up @@ -687,7 +687,7 @@ class SmallBitVector {
if (!isSmall())
return getPointer()->getData();
Store = getSmallBits();
return makeArrayRef(Store);
return Store;
}

private:
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Analysis/ConstraintSystem.h
Expand Up @@ -40,7 +40,7 @@ class ConstraintSystem {
assert(Constraints.empty() || R.size() == Constraints.back().size());
// If all variable coefficients are 0, the constraint does not provide any
// usable information.
if (all_of(makeArrayRef(R).drop_front(1), [](int64_t C) { return C == 0; }))
if (all_of(ArrayRef(R).drop_front(1), [](int64_t C) { return C == 0; }))
return false;

for (const auto &C : R) {
Expand All @@ -55,7 +55,7 @@ class ConstraintSystem {
bool addVariableRowFill(ArrayRef<int64_t> R) {
// If all variable coefficients are 0, the constraint does not provide any
// usable information.
if (all_of(makeArrayRef(R).drop_front(1), [](int64_t C) { return C == 0; }))
if (all_of(ArrayRef(R).drop_front(1), [](int64_t C) { return C == 0; }))
return false;

for (auto &CR : Constraints) {
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h
Expand Up @@ -187,7 +187,7 @@ class SCEVNAryExpr : public SCEV {

SCEVNAryExpr(const FoldingSetNodeIDRef ID, enum SCEVTypes T,
const SCEV *const *O, size_t N)
: SCEV(ID, T, computeExpressionSize(makeArrayRef(O, N))), Operands(O),
: SCEV(ID, T, computeExpressionSize(ArrayRef(O, N))), Operands(O),
NumOperands(N) {}

public:
Expand All @@ -199,7 +199,7 @@ class SCEVNAryExpr : public SCEV {
}

ArrayRef<const SCEV *> operands() const {
return makeArrayRef(Operands, NumOperands);
return ArrayRef(Operands, NumOperands);
}

NoWrapFlags getNoWrapFlags(NoWrapFlags Mask = NoWrapMask) const {
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Bitcode/BitcodeConvenience.h
Expand Up @@ -429,7 +429,7 @@ template <typename IDField, typename... Fields> class BCGenericRecordLayout {
/// in the buffer and should be handled separately by the caller.
template <typename BufferTy, typename... Data>
static void readRecord(BufferTy &buffer, Data &&...data) {
return readRecord(llvm::makeArrayRef(buffer), std::forward<Data>(data)...);
return readRecord(llvm::ArrayRef(buffer), std::forward<Data>(data)...);
}
};

Expand Down
20 changes: 9 additions & 11 deletions llvm/include/llvm/Bitstream/BitstreamWriter.h
Expand Up @@ -474,7 +474,7 @@ class BitstreamWriter {
Out.push_back(0);
}
void emitBlob(StringRef Bytes, bool ShouldEmitSize = true) {
emitBlob(makeArrayRef((const uint8_t *)Bytes.data(), Bytes.size()),
emitBlob(ArrayRef((const uint8_t *)Bytes.data(), Bytes.size()),
ShouldEmitSize);
}

Expand All @@ -485,7 +485,7 @@ class BitstreamWriter {
if (!Abbrev) {
// If we don't have an abbrev to use, emit this in its fully unabbreviated
// form.
auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
auto Count = static_cast<uint32_t>(ArrayRef(Vals).size());
EmitCode(bitc::UNABBREV_RECORD);
EmitVBR(Code, 6);
EmitVBR(Count, 6);
Expand All @@ -494,16 +494,15 @@ class BitstreamWriter {
return;
}

EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
EmitRecordWithAbbrevImpl(Abbrev, ArrayRef(Vals), StringRef(), Code);
}

/// EmitRecordWithAbbrev - Emit a record with the specified abbreviation.
/// Unlike EmitRecord, the code for the record should be included in Vals as
/// the first entry.
template <typename Container>
void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals) {
EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(),
std::nullopt);
EmitRecordWithAbbrevImpl(Abbrev, ArrayRef(Vals), StringRef(), std::nullopt);
}

/// EmitRecordWithBlob - Emit the specified record to the stream, using an
Expand All @@ -514,12 +513,12 @@ class BitstreamWriter {
template <typename Container>
void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals,
StringRef Blob) {
EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, std::nullopt);
EmitRecordWithAbbrevImpl(Abbrev, ArrayRef(Vals), Blob, std::nullopt);
}
template <typename Container>
void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals,
const char *BlobData, unsigned BlobLen) {
return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
return EmitRecordWithAbbrevImpl(Abbrev, ArrayRef(Vals),
StringRef(BlobData, BlobLen), std::nullopt);
}

Expand All @@ -528,14 +527,13 @@ class BitstreamWriter {
template <typename Container>
void EmitRecordWithArray(unsigned Abbrev, const Container &Vals,
StringRef Array) {
EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Array, std::nullopt);
EmitRecordWithAbbrevImpl(Abbrev, ArrayRef(Vals), Array, std::nullopt);
}
template <typename Container>
void EmitRecordWithArray(unsigned Abbrev, const Container &Vals,
const char *ArrayData, unsigned ArrayLen) {
return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
StringRef(ArrayData, ArrayLen),
std::nullopt);
return EmitRecordWithAbbrevImpl(
Abbrev, ArrayRef(Vals), StringRef(ArrayData, ArrayLen), std::nullopt);
}

//===--------------------------------------------------------------------===//
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/CodeGen/CostTable.h
Expand Up @@ -47,7 +47,7 @@ template <size_t N, class CostType>
inline const CostTblEntryT<CostType> *
CostTableLookup(const CostTblEntryT<CostType> (&Table)[N], int ISD, MVT Ty) {
// Wrapper to fix template argument deduction failures.
return CostTableLookup<CostType>(makeArrayRef(Table), ISD, Ty);
return CostTableLookup<CostType>(Table, ISD, Ty);
}

/// Type Conversion Cost Table
Expand Down Expand Up @@ -81,7 +81,7 @@ inline const TypeConversionCostTblEntryT<CostType> *
ConvertCostTableLookup(const TypeConversionCostTblEntryT<CostType> (&Table)[N],
int ISD, MVT Dst, MVT Src) {
// Wrapper to fix template argument deduction failures.
return ConvertCostTableLookup<CostType>(makeArrayRef(Table), ISD, Dst, Src);
return ConvertCostTableLookup<CostType>(Table, ISD, Dst, Src);
}

} // namespace llvm
Expand Down
4 changes: 1 addition & 3 deletions llvm/include/llvm/CodeGen/LiveRangeEdit.h
Expand Up @@ -163,9 +163,7 @@ class LiveRangeEdit : private MachineRegisterInfo::Delegate {
/// we want to drop it from the NewRegs set.
void pop_back() { NewRegs.pop_back(); }

ArrayRef<Register> regs() const {
return makeArrayRef(NewRegs).slice(FirstNew);
}
ArrayRef<Register> regs() const { return ArrayRef(NewRegs).slice(FirstNew); }

/// createFrom - Create a new virtual register based on OldReg.
Register createFrom(Register OldReg);
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/CodeGen/MachineInstr.h
Expand Up @@ -188,7 +188,7 @@ class MachineInstr
}

ArrayRef<MachineMemOperand *> getMMOs() const {
return makeArrayRef(getTrailingObjects<MachineMemOperand *>(), NumMMOs);
return ArrayRef(getTrailingObjects<MachineMemOperand *>(), NumMMOs);
}

MCSymbol *getPreInstrSymbol() const {
Expand Down Expand Up @@ -715,7 +715,7 @@ class MachineInstr
return {};

if (Info.is<EIIK_MMO>())
return makeArrayRef(Info.getAddrOfZeroTagPointer(), 1);
return ArrayRef(Info.getAddrOfZeroTagPointer(), 1);

if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
return EI->getMMOs();
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/RegisterClassInfo.h
Expand Up @@ -38,7 +38,7 @@ class RegisterClassInfo {
RCInfo() = default;

operator ArrayRef<MCPhysReg>() const {
return makeArrayRef(Order.get(), NumRegs);
return ArrayRef(Order.get(), NumRegs);
}
};

Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/CodeGen/SelectionDAG.h
Expand Up @@ -783,7 +783,7 @@ class SelectionDAG {
SDVTList VTs = getVTList(MVT::Other, MVT::Glue);
SDValue Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Glue };
return getNode(ISD::CopyToReg, dl, VTs,
makeArrayRef(Ops, Glue.getNode() ? 4 : 3));
ArrayRef(Ops, Glue.getNode() ? 4 : 3));
}

// Similar to last getCopyToReg() except parameter Reg is a SDValue
Expand All @@ -792,7 +792,7 @@ class SelectionDAG {
SDVTList VTs = getVTList(MVT::Other, MVT::Glue);
SDValue Ops[] = { Chain, Reg, N, Glue };
return getNode(ISD::CopyToReg, dl, VTs,
makeArrayRef(Ops, Glue.getNode() ? 4 : 3));
ArrayRef(Ops, Glue.getNode() ? 4 : 3));
}

SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, unsigned Reg, EVT VT) {
Expand All @@ -809,7 +809,7 @@ class SelectionDAG {
SDVTList VTs = getVTList(VT, MVT::Other, MVT::Glue);
SDValue Ops[] = { Chain, getRegister(Reg, VT), Glue };
return getNode(ISD::CopyFromReg, dl, VTs,
makeArrayRef(Ops, Glue.getNode() ? 3 : 2));
ArrayRef(Ops, Glue.getNode() ? 3 : 2));
}

SDValue getCondCode(ISD::CondCode Cond);
Expand Down
8 changes: 4 additions & 4 deletions llvm/include/llvm/CodeGen/SelectionDAGNodes.h
Expand Up @@ -927,7 +927,7 @@ END_TWO_BYTE_PACK()

op_iterator op_begin() const { return OperandList; }
op_iterator op_end() const { return OperandList+NumOperands; }
ArrayRef<SDUse> ops() const { return makeArrayRef(op_begin(), op_end()); }
ArrayRef<SDUse> ops() const { return ArrayRef(op_begin(), op_end()); }

/// Iterator for directly iterating over the operand SDValue's.
struct value_op_iterator
Expand Down Expand Up @@ -1535,7 +1535,7 @@ class ShuffleVectorSDNode : public SDNode {
public:
ArrayRef<int> getMask() const {
EVT VT = getValueType(0);
return makeArrayRef(Mask, VT.getVectorNumElements());
return ArrayRef(Mask, VT.getVectorNumElements());
}

int getMaskElt(unsigned Idx) const {
Expand Down Expand Up @@ -2931,10 +2931,10 @@ class MachineSDNode : public SDNode {
if (NumMemRefs == 0)
return {};
if (NumMemRefs == 1)
return makeArrayRef(MemRefs.getAddrOfPtr1(), 1);
return ArrayRef(MemRefs.getAddrOfPtr1(), 1);

// Otherwise we have an actual array.
return makeArrayRef(MemRefs.get<MachineMemOperand **>(), NumMemRefs);
return ArrayRef(MemRefs.get<MachineMemOperand **>(), NumMemRefs);
}
mmo_iterator memoperands_begin() const { return memoperands().begin(); }
mmo_iterator memoperands_end() const { return memoperands().end(); }
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/CodeGen/TargetRegisterInfo.h
Expand Up @@ -200,7 +200,7 @@ class TargetRegisterClass {
///
/// By default, this method returns all registers in the class.
ArrayRef<MCPhysReg> getRawAllocationOrder(const MachineFunction &MF) const {
return OrderFunc ? OrderFunc(MF) : makeArrayRef(begin(), getNumRegs());
return OrderFunc ? OrderFunc(MF) : ArrayRef(begin(), getNumRegs());
}

/// Returns the combination of all lane masks of register in this class.
Expand Down Expand Up @@ -357,7 +357,7 @@ class TargetRegisterInfo : public MCRegisterInfo {
unsigned NumRegs = getNumRegs();
assert(Idx < InfoDesc->NumCosts && "CostPerUse index out of bounds");

return makeArrayRef(&InfoDesc->CostPerUse[Idx * NumRegs], NumRegs);
return ArrayRef(&InfoDesc->CostPerUse[Idx * NumRegs], NumRegs);
}

/// Return true if the register is in the allocation of any register class.
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/DebugInfo/CodeView/TypeRecord.h
Expand Up @@ -704,10 +704,10 @@ class VFTableRecord : public TypeRecord {
TypeIndex getCompleteClass() const { return CompleteClass; }
TypeIndex getOverriddenVTable() const { return OverriddenVFTable; }
uint32_t getVFPtrOffset() const { return VFPtrOffset; }
StringRef getName() const { return makeArrayRef(MethodNames).front(); }
StringRef getName() const { return ArrayRef(MethodNames).front(); }

ArrayRef<StringRef> getMethodNames() const {
return makeArrayRef(MethodNames).drop_front();
return ArrayRef(MethodNames).drop_front();
}

TypeIndex CompleteClass;
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h
Expand Up @@ -164,11 +164,11 @@ class DWARFUnitIndex {
const Entry *getFromHash(uint64_t Offset) const;

ArrayRef<DWARFSectionKind> getColumnKinds() const {
return makeArrayRef(ColumnKinds.get(), Header.NumColumns);
return ArrayRef(ColumnKinds.get(), Header.NumColumns);
}

ArrayRef<Entry> getRows() const {
return makeArrayRef(Rows.get(), Header.NumBuckets);
return ArrayRef(Rows.get(), Header.NumBuckets);
}
};

Expand Down
Expand Up @@ -108,9 +108,7 @@ class DbiModuleDescriptorBuilder {

unsigned getModuleIndex() const { return Layout.Mod; }

ArrayRef<std::string> source_files() const {
return makeArrayRef(SourceFiles);
}
ArrayRef<std::string> source_files() const { return SourceFiles; }

uint32_t calculateSerializedLength() const;

Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/IR/Constants.h
Expand Up @@ -698,7 +698,7 @@ class ConstantDataArray final : public ConstantDataSequential {
/// ArrayRef<ElementTy>. Calls get(LLVMContext, ArrayRef<ElementTy>).
template <typename ArrayTy>
static Constant *get(LLVMContext &Context, ArrayTy &Elts) {
return ConstantDataArray::get(Context, makeArrayRef(Elts));
return ConstantDataArray::get(Context, ArrayRef(Elts));
}

/// getRaw() constructor - Return a constant with array type with an element
Expand Down Expand Up @@ -1247,7 +1247,7 @@ class ConstantExpr : public Constant {
std::optional<unsigned> InRangeIndex = std::nullopt,
Type *OnlyIfReducedTy = nullptr) {
return getGetElementPtr(
Ty, C, makeArrayRef((Value *const *)IdxList.data(), IdxList.size()),
Ty, C, ArrayRef((Value *const *)IdxList.data(), IdxList.size()),
InBounds, InRangeIndex, OnlyIfReducedTy);
}
static Constant *
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/IR/DataLayout.h
Expand Up @@ -646,7 +646,7 @@ class StructLayout final : public TrailingObjects<StructLayout, uint64_t> {
}

ArrayRef<uint64_t> getMemberOffsets() const {
return llvm::makeArrayRef(getTrailingObjects<uint64_t>(), NumElements);
return llvm::ArrayRef(getTrailingObjects<uint64_t>(), NumElements);
}

uint64_t getElementOffset(unsigned Idx) const {
Expand Down
8 changes: 4 additions & 4 deletions llvm/include/llvm/IR/DerivedTypes.h
Expand Up @@ -128,7 +128,7 @@ class FunctionType : public Type {
param_iterator param_begin() const { return ContainedTys + 1; }
param_iterator param_end() const { return &ContainedTys[NumContainedTys]; }
ArrayRef<Type *> params() const {
return makeArrayRef(param_begin(), param_end());
return ArrayRef(param_begin(), param_end());
}

/// Parameter type accessors.
Expand Down Expand Up @@ -317,7 +317,7 @@ class StructType : public Type {
element_iterator element_begin() const { return ContainedTys; }
element_iterator element_end() const { return &ContainedTys[NumContainedTys];}
ArrayRef<Type *> elements() const {
return makeArrayRef(element_begin(), element_end());
return ArrayRef(element_begin(), element_end());
}

/// Return true if this is layout identical to the specified struct.
Expand Down Expand Up @@ -761,7 +761,7 @@ class TargetExtType : public Type {
/// Return the type parameters for this particular target extension type. If
/// there are no parameters, an empty array is returned.
ArrayRef<Type *> type_params() const {
return makeArrayRef(type_param_begin(), type_param_end());
return ArrayRef(type_param_begin(), type_param_end());
}

using type_param_iterator = Type::subtype_iterator;
Expand All @@ -776,7 +776,7 @@ class TargetExtType : public Type {
/// Return the integer parameters for this particular target extension type.
/// If there are no parameters, an empty array is returned.
ArrayRef<unsigned> int_params() const {
return makeArrayRef(IntParams, getNumIntParameters());
return ArrayRef(IntParams, getNumIntParameters());
}

unsigned getIntParameter(unsigned i) const { return IntParams[i]; }
Expand Down

0 comments on commit 38818b6

Please sign in to comment.