~ubuntu-branches/ubuntu/natty/clamav/natty-security

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-12-02 21:04:10 UTC
  • mfrom: (0.35.17 sid)
  • Revision ID: james.westby@ubuntu.com-20101202210410-ppgyckmylngsfa8o
Tags: 0.96.5+dfsg-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop initial signature definitions from clamav-base
  - Drop build-dep on electric-fence (in Universe)
  - Add apparmor profiles for clamd and freshclam along with maintainer
    script changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
ScheduleDAGInstrs::ScheduleDAGInstrs(MachineFunction &mf,
33
33
                                     const MachineLoopInfo &mli,
34
34
                                     const MachineDominatorTree &mdt)
35
 
  : ScheduleDAG(mf), MLI(mli), MDT(mdt), LoopRegs(MLI, MDT) {
 
35
  : ScheduleDAG(mf), MLI(mli), MDT(mdt), Defs(TRI->getNumRegs()),
 
36
    Uses(TRI->getNumRegs()), LoopRegs(MLI, MDT) {
36
37
  MFI = mf.getFrameInfo();
 
38
  DbgValueVec.clear();
37
39
}
38
40
 
39
41
/// Run - perform scheduling.
157
159
  std::map<const Value *, SUnit *> AliasMemDefs, NonAliasMemDefs;
158
160
  std::map<const Value *, std::vector<SUnit *> > AliasMemUses, NonAliasMemUses;
159
161
 
 
162
  // Keep track of dangling debug references to registers.
 
163
  std::vector<std::pair<MachineInstr*, unsigned> >
 
164
    DanglingDebugValue(TRI->getNumRegs(),
 
165
    std::make_pair(static_cast<MachineInstr*>(0), 0));
 
166
 
160
167
  // Check to see if the scheduler cares about latencies.
161
168
  bool UnitLatencies = ForceUnitLatencies();
162
169
 
164
171
  const TargetSubtarget &ST = TM.getSubtarget<TargetSubtarget>();
165
172
  unsigned SpecialAddressLatency = ST.getSpecialAddressLatency();
166
173
 
 
174
  // Remove any stale debug info; sometimes BuildSchedGraph is called again
 
175
  // without emitting the info from the previous call.
 
176
  DbgValueVec.clear();
 
177
 
167
178
  // Walk the list of instructions, from bottom moving up.
168
179
  for (MachineBasicBlock::iterator MII = InsertPos, MIE = Begin;
169
180
       MII != MIE; --MII) {
170
181
    MachineInstr *MI = prior(MII);
 
182
    // DBG_VALUE does not have SUnit's built, so just remember these for later
 
183
    // reinsertion.
 
184
    if (MI->isDebugValue()) {
 
185
      if (MI->getNumOperands()==3 && MI->getOperand(0).isReg() &&
 
186
          MI->getOperand(0).getReg())
 
187
        DanglingDebugValue[MI->getOperand(0).getReg()] =
 
188
             std::make_pair(MI, DbgValueVec.size());
 
189
      DbgValueVec.push_back(MI);
 
190
      continue;
 
191
    }
171
192
    const TargetInstrDesc &TID = MI->getDesc();
172
193
    assert(!TID.isTerminator() && !MI->isLabel() &&
173
194
           "Cannot schedule terminators or labels!");
188
209
      if (Reg == 0) continue;
189
210
 
190
211
      assert(TRI->isPhysicalRegister(Reg) && "Virtual register encountered!");
 
212
 
 
213
      if (MO.isDef() && DanglingDebugValue[Reg].first!=0) {
 
214
        SU->DbgInstrList.push_back(DanglingDebugValue[Reg].first);
 
215
        DbgValueVec[DanglingDebugValue[Reg].second] = 0;
 
216
        DanglingDebugValue[Reg] = std::make_pair((MachineInstr*)0, 0);
 
217
      }
 
218
 
191
219
      std::vector<SUnit *> &UseList = Uses[Reg];
192
220
      std::vector<SUnit *> &DefList = Defs[Reg];
193
221
      // Optionally add output and anti dependencies. For anti
221
249
        unsigned DataLatency = SU->Latency;
222
250
        for (unsigned i = 0, e = UseList.size(); i != e; ++i) {
223
251
          SUnit *UseSU = UseList[i];
224
 
          if (UseSU != SU) {
225
 
            unsigned LDataLatency = DataLatency;
226
 
            // Optionally add in a special extra latency for nodes that
227
 
            // feed addresses.
228
 
            // TODO: Do this for register aliases too.
229
 
            // TODO: Perhaps we should get rid of
230
 
            // SpecialAddressLatency and just move this into
231
 
            // adjustSchedDependency for the targets that care about
232
 
            // it.
233
 
            if (SpecialAddressLatency != 0 && !UnitLatencies) {
234
 
              MachineInstr *UseMI = UseSU->getInstr();
235
 
              const TargetInstrDesc &UseTID = UseMI->getDesc();
236
 
              int RegUseIndex = UseMI->findRegisterUseOperandIdx(Reg);
237
 
              assert(RegUseIndex >= 0 && "UseMI doesn's use register!");
238
 
              if ((UseTID.mayLoad() || UseTID.mayStore()) &&
239
 
                  (unsigned)RegUseIndex < UseTID.getNumOperands() &&
240
 
                  UseTID.OpInfo[RegUseIndex].isLookupPtrRegClass())
241
 
                LDataLatency += SpecialAddressLatency;
242
 
            }
243
 
            // Adjust the dependence latency using operand def/use
244
 
            // information (if any), and then allow the target to
245
 
            // perform its own adjustments.
246
 
            const SDep& dep = SDep(SU, SDep::Data, LDataLatency, Reg);
247
 
            if (!UnitLatencies) {
248
 
              ComputeOperandLatency(SU, UseSU, (SDep &)dep);
249
 
              ST.adjustSchedDependency(SU, UseSU, (SDep &)dep);
250
 
            }
251
 
            UseSU->addPred(dep);
252
 
          }
 
252
          if (UseSU == SU)
 
253
            continue;
 
254
          unsigned LDataLatency = DataLatency;
 
255
          // Optionally add in a special extra latency for nodes that
 
256
          // feed addresses.
 
257
          // TODO: Do this for register aliases too.
 
258
          // TODO: Perhaps we should get rid of
 
259
          // SpecialAddressLatency and just move this into
 
260
          // adjustSchedDependency for the targets that care about it.
 
261
          if (SpecialAddressLatency != 0 && !UnitLatencies) {
 
262
            MachineInstr *UseMI = UseSU->getInstr();
 
263
            const TargetInstrDesc &UseTID = UseMI->getDesc();
 
264
            int RegUseIndex = UseMI->findRegisterUseOperandIdx(Reg);
 
265
            assert(RegUseIndex >= 0 && "UseMI doesn's use register!");
 
266
            if ((UseTID.mayLoad() || UseTID.mayStore()) &&
 
267
                (unsigned)RegUseIndex < UseTID.getNumOperands() &&
 
268
                UseTID.OpInfo[RegUseIndex].isLookupPtrRegClass())
 
269
              LDataLatency += SpecialAddressLatency;
 
270
          }
 
271
          // Adjust the dependence latency using operand def/use
 
272
          // information (if any), and then allow the target to
 
273
          // perform its own adjustments.
 
274
          const SDep& dep = SDep(SU, SDep::Data, LDataLatency, Reg);
 
275
          if (!UnitLatencies) {
 
276
            ComputeOperandLatency(SU, UseSU, const_cast<SDep &>(dep));
 
277
            ST.adjustSchedDependency(SU, UseSU, const_cast<SDep &>(dep));
 
278
          }
 
279
          UseSU->addPred(dep);
253
280
        }
254
281
        for (const unsigned *Alias = TRI->getAliasSet(Reg); *Alias; ++Alias) {
255
282
          std::vector<SUnit *> &UseList = Uses[*Alias];
256
283
          for (unsigned i = 0, e = UseList.size(); i != e; ++i) {
257
284
            SUnit *UseSU = UseList[i];
258
 
            if (UseSU != SU) {
259
 
              const SDep& dep = SDep(SU, SDep::Data, DataLatency, *Alias);
260
 
              if (!UnitLatencies) {
261
 
                ComputeOperandLatency(SU, UseSU, (SDep &)dep);
262
 
                ST.adjustSchedDependency(SU, UseSU, (SDep &)dep);
263
 
              }
264
 
              UseSU->addPred(dep);
 
285
            if (UseSU == SU)
 
286
              continue;
 
287
            const SDep& dep = SDep(SU, SDep::Data, DataLatency, *Alias);
 
288
            if (!UnitLatencies) {
 
289
              ComputeOperandLatency(SU, UseSU, const_cast<SDep &>(dep));
 
290
              ST.adjustSchedDependency(SU, UseSU, const_cast<SDep &>(dep));
265
291
            }
 
292
            UseSU->addPred(dep);
266
293
          }
267
294
        }
268
295
 
501
528
  MachineInstr *DefMI = Def->getInstr();
502
529
  int DefIdx = DefMI->findRegisterDefOperandIdx(Reg);
503
530
  if (DefIdx != -1) {
504
 
    int DefCycle = InstrItins.getOperandCycle(DefMI->getDesc().getSchedClass(), DefIdx);
 
531
    int DefCycle = InstrItins.getOperandCycle(DefMI->getDesc().getSchedClass(),
 
532
                                              DefIdx);
505
533
    if (DefCycle >= 0) {
506
534
      MachineInstr *UseMI = Use->getInstr();
507
535
      const unsigned UseClass = UseMI->getDesc().getSchedClass();
545
573
}
546
574
 
547
575
// EmitSchedule - Emit the machine code in scheduled order.
548
 
MachineBasicBlock *ScheduleDAGInstrs::
549
 
EmitSchedule(DenseMap<MachineBasicBlock*, MachineBasicBlock*> *EM) {
 
576
MachineBasicBlock *ScheduleDAGInstrs::EmitSchedule() {
550
577
  // For MachineInstr-based scheduling, we're rescheduling the instructions in
551
578
  // the block, so start by removing them from the block.
552
579
  while (Begin != InsertPos) {
555
582
    BB->remove(I);
556
583
  }
557
584
 
 
585
  // First reinsert any remaining debug_values; these are either constants,
 
586
  // or refer to live-in registers.  The beginning of the block is the right
 
587
  // place for the latter.  The former might reasonably be placed elsewhere
 
588
  // using some kind of ordering algorithm, but right now it doesn't matter.
 
589
  for (int i = DbgValueVec.size()-1; i>=0; --i)
 
590
    if (DbgValueVec[i])
 
591
      BB->insert(InsertPos, DbgValueVec[i]);
 
592
 
558
593
  // Then re-insert them according to the given schedule.
559
594
  for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
560
595
    SUnit *SU = Sequence[i];
565
600
    }
566
601
 
567
602
    BB->insert(InsertPos, SU->getInstr());
 
603
    for (unsigned i = 0, e = SU->DbgInstrList.size() ; i < e ; ++i)
 
604
      BB->insert(InsertPos, SU->DbgInstrList[i]);
568
605
  }
569
606
 
570
607
  // Update the Begin iterator, as the first instruction in the block
571
608
  // may have been scheduled later.
572
 
  if (!Sequence.empty())
 
609
  if (!DbgValueVec.empty()) {
 
610
    for (int i = DbgValueVec.size()-1; i>=0; --i)
 
611
      if (DbgValueVec[i]!=0) {
 
612
        Begin = DbgValueVec[DbgValueVec.size()-1];
 
613
        break;
 
614
      }
 
615
  } else if (!Sequence.empty())
573
616
    Begin = Sequence[0]->getInstr();
574
617
 
 
618
  DbgValueVec.clear();
575
619
  return BB;
576
620
}