Exemplo n.º 1
0
void LinearScan::allocRegs(Trace* trace) {
  if (RuntimeOption::EvalHHIREnableCoalescing) {
    // <coalesce> doesn't need instruction numbering.
    coalesce(trace);
  }

  numberInstructions(trace);

  collectNatives(trace);
  computePreColoringHint();
  initFreeList();
  allocRegsToTraceAux(trace);
  // Renumber instructions, because we added spills and reloads.
  numberInstructions(trace);

  if (RuntimeOption::EvalHHIREnableRematerialization && m_slots.size() > 0) {
    // Don't bother rematerializing the trace if it has no Spill/Reload.
    if (RuntimeOption::EvalDumpIR > 5) {
      std::cout << "--------- HHIR before rematerialization ---------\n";
      trace->print(std::cout, false);
      std::cout << "-------------------------------------------------\n";
    }
    rematerialize(trace);
  }

  // assignSpillLoc needs next natives in order to decide whether we
  // can use MMX registers.
  collectNatives(trace);
  // Make sure rsp is 16-aligned.
  uint32 numSpillLocs = assignSpillLoc(trace);
  if (numSpillLocs % 2) {
    ++numSpillLocs;
  }
  assert(NumPreAllocatedSpillLocs % 2 == 0);
  if (numSpillLocs > 0) {
    preAllocSpillLoc(trace, numSpillLocs);
    if (numSpillLocs > (uint32)NumPreAllocatedSpillLocs) {
      /*
       * We only insert AllocSpill and FreeSpill when the pre-allocated
       * spill locations are not enough.
       *
       * AllocSpill and FreeSpill take the number of extra spill locations
       * besides the pre-allocated ones.
       *
       * TODO(#2044051) AllocSpill/FreeSpill are currently disabled
       * due to bugs.
       */
      PUNT(LinearScan_AllocSpill);
      insertAllocFreeSpill(trace, numSpillLocs - NumPreAllocatedSpillLocs);
    }
  }
  numberInstructions(trace);

  // record the live out register set at each instruction
  LinearScan::computeLiveOutRegs(trace);
}
Exemplo n.º 2
0
void LinearScan::rematerialize(Trace* trace) {
  rematerializeAux(trace,
                   NULL,
                   NULL,
                   std::vector<SSATmp*>());
  numberInstructions(trace);

  // We only replaced Reloads in <rematerializeAux>.
  // Here, we remove Spills that are never reloaded.
  removeUnusedSpills(trace);
  numberInstructions(trace);
}
Exemplo n.º 3
0
bool BoUpSLP::vectorizeStores(StoreList &Stores, int costThreshold) {
  ValueSet Heads, Tails;
  SmallDenseMap<Value*, Value*> ConsecutiveChain;
  bool Changed = false;

  // Do a quadratic search on all of the given stores and find
  // all of the pairs of loads that follow each other.
  for (unsigned i = 0, e = Stores.size(); i < e; ++i)
    for (unsigned j = 0; j < e; ++j) {
      if (i == j) continue;
      if (isConsecutiveAccess(Stores[i], Stores[j])) {
        Tails.insert(Stores[j]);
        Heads.insert(Stores[i]);
        ConsecutiveChain[Stores[i]] = Stores[j];
      }
    }

  // For stores that start but don't end a link in the chain:
  for (ValueSet::iterator it = Heads.begin(), e = Heads.end();it != e; ++it) {
    if (Tails.count(*it)) continue;

    // We found a store instr that starts a chain. Now follow the chain and try
    // to vectorize it.
    ValueList Operands;
    Value *I = *it;
    int MinCost = 0, MinVF = 0;
    while (Tails.count(I) || Heads.count(I)) {
      Operands.push_back(I);
      unsigned VF = Operands.size();
      if (isPowerOf2_32(VF) && VF > 1) {
        int cost = getTreeRollCost(Operands, 0);
        DEBUG(dbgs() << "Found cost=" << cost << " for VF=" << VF << "\n");
        if (cost < MinCost) { MinCost = cost; MinVF = VF; }
      }
      // Move to the next value in the chain.
      I = ConsecutiveChain[I];
    }

    if (MinCost <= costThreshold && MinVF > 1) {
      DEBUG(dbgs() << "Decided to vectorize cost=" << MinCost << "\n");
      vectorizeTree(Operands, MinVF);
      Stores.clear();
      // The current numbering is invalid because we added and removed instrs.
      numberInstructions();
      Changed = true;
    }
  }

  return Changed;
}
Exemplo n.º 4
0
BoUpSLP::BoUpSLP(BasicBlock *Bb, ScalarEvolution *S, DataLayout *Dl,
                             TargetTransformInfo *Tti, AliasAnalysis *Aa) :
                             BB(Bb), SE(S), DL(Dl), TTI(Tti), AA(Aa) {
  numberInstructions();
}