Skip to content

Commit

Permalink
[GT]: Use ArrayRef rather than SmallVector
Browse files Browse the repository at this point in the history
We don't need to copy the uses/defs. Instead, we use an llvm::ArrayRef.
  • Loading branch information
Quincunx271 committed May 18, 2020
1 parent 2f5a178 commit 6c7c0a8
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions lib/Scheduler/graph_trans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,20 @@ static llvm::SmallVector<const Register *, 10> possiblyLengthenedIfAfterOther(
return result;
}

// Converts a class type and a function signature into a pointer to member
// function.
// Usage: memfn_t<Cls, int(double) const> ==> int (Cls::*)(double) const
template <typename Cls, typename FnSig> using memfn_t = FnSig Cls::*;

// Gets the Uses or Defs for the given SchedInstruction.
template <std::size_t N,
memfn_t<SchedInstruction, int16_t(Register **&)> UsesOrDefsFn>
static llvm::SmallVector<const Register *, N> getSet(SchedInstruction *node) {
// Gets the Uses for the given SchedInstruction.
static llvm::ArrayRef<const Register *> getUses(SchedInstruction *node) {
Register **uses;
const int useCount = (node->*UsesOrDefsFn)(uses);
// Call the (Iter, Iter) constructor.
return {uses, uses + useCount};
const int useCount = node->GetUses(uses);
assert(useCount >= 0);
return {uses, static_cast<size_t>(useCount)};
}

// Gets the Defs for the given SchedInstruction.
static llvm::ArrayRef<const Register *> getDefs(SchedInstruction *node) {
Register **defs;
const int defCount = node->GetDefs(defs);
assert(defCount >= 0);
return {defs, static_cast<size_t>(defCount)};
}

GraphTrans::GraphTrans(DataDepGraph *dataDepGraph) {
Expand Down Expand Up @@ -241,15 +242,11 @@ bool StaticNodeSupTrans::NodeIsSuperior_(SchedInstruction *nodeA,
// registers.
const int regTypes = graph->GetRegTypeCnt();

const llvm::SmallVector<const Register *, 10> usesA =
::getSet<10, &SchedInstruction::GetUses>(nodeA);
const llvm::SmallVector<const Register *, 10> usesB =
::getSet<10, &SchedInstruction::GetUses>(nodeB);
const llvm::ArrayRef<const Register *> usesA = ::getUses(nodeA);
const llvm::ArrayRef<const Register *> usesB = ::getUses(nodeB);

const llvm::SmallVector<const Register *, 10> defsA =
::getSet<10, &SchedInstruction::GetDefs>(nodeA);
const llvm::SmallVector<const Register *, 10> defsB =
::getSet<10, &SchedInstruction::GetDefs>(nodeB);
const llvm::ArrayRef<const Register *> defsA = ::getDefs(nodeA);
const llvm::ArrayRef<const Register *> defsB = ::getDefs(nodeB);

// (# lengthened registers) - (# shortened registers)
// from scheduling B after A. Indexed by register type.
Expand Down

0 comments on commit 6c7c0a8

Please sign in to comment.