diff options
Diffstat (limited to 'include/llvm/CodeGen')
| -rw-r--r-- | include/llvm/CodeGen/DFAPacketizer.h | 44 | ||||
| -rw-r--r-- | include/llvm/CodeGen/Passes.h | 2 | ||||
| -rw-r--r-- | include/llvm/CodeGen/ScheduleDAGInstrs.h | 7 | ||||
| -rw-r--r-- | include/llvm/CodeGen/SlotIndexes.h | 211 | 
4 files changed, 88 insertions, 176 deletions
| diff --git a/include/llvm/CodeGen/DFAPacketizer.h b/include/llvm/CodeGen/DFAPacketizer.h index 2d2db78144a45..ee1ed0779be47 100644 --- a/include/llvm/CodeGen/DFAPacketizer.h +++ b/include/llvm/CodeGen/DFAPacketizer.h @@ -28,7 +28,6 @@  #include "llvm/CodeGen/MachineBasicBlock.h"  #include "llvm/ADT/DenseMap.h" -#include <map>  namespace llvm { @@ -37,7 +36,7 @@ class MachineInstr;  class MachineLoopInfo;  class MachineDominatorTree;  class InstrItineraryData; -class DefaultVLIWScheduler; +class ScheduleDAGInstrs;  class SUnit;  class DFAPacketizer { @@ -78,8 +77,6 @@ public:    // reserveResources - Reserve the resources occupied by a machine    // instruction and change the current state to reflect that change.    void reserveResources(llvm::MachineInstr *MI); - -  const InstrItineraryData *getInstrItins() const { return InstrItins; }  };  // VLIWPacketizerList - Implements a simple VLIW packetizer using DFA. The @@ -90,21 +87,20 @@ public:  // and machine resource is marked as taken. If any dependency is found, a target  // API call is made to prune the dependence.  class VLIWPacketizerList { -protected:    const TargetMachine &TM;    const MachineFunction &MF;    const TargetInstrInfo *TII; -  // The VLIW Scheduler. -  DefaultVLIWScheduler *VLIWScheduler; +  // Encapsulate data types not exposed to the target interface. +  ScheduleDAGInstrs *SchedulerImpl; +protected:    // Vector of instructions assigned to the current packet.    std::vector<MachineInstr*> CurrentPacketMIs;    // DFA resource tracker.    DFAPacketizer *ResourceTracker; - -  // Generate MI -> SU map. -  std::map<MachineInstr*, SUnit*> MIToSUnit; +  // Scheduling units. +  std::vector<SUnit> SUnits;  public:    VLIWPacketizerList( @@ -122,32 +118,17 @@ public:    DFAPacketizer *getResourceTracker() {return ResourceTracker;}    // addToPacket - Add MI to the current packet. -  virtual MachineBasicBlock::iterator addToPacket(MachineInstr *MI) { -    MachineBasicBlock::iterator MII = MI; -    CurrentPacketMIs.push_back(MI); -    ResourceTracker->reserveResources(MI); -    return MII; -  } +  void addToPacket(MachineInstr *MI);    // endPacket - End the current packet. -  void endPacket(MachineBasicBlock *MBB, MachineInstr *MI); - -  // initPacketizerState - perform initialization before packetizing -  // an instruction. This function is supposed to be overrided by -  // the target dependent packetizer. -  virtual void initPacketizerState(void) { return; } +  void endPacket(MachineBasicBlock *MBB, MachineInstr *I);    // ignorePseudoInstruction - Ignore bundling of pseudo instructions. -  virtual bool ignorePseudoInstruction(MachineInstr *I, -                                       MachineBasicBlock *MBB) { -    return false; -  } +  bool ignorePseudoInstruction(MachineInstr *I, MachineBasicBlock *MBB); -  // isSoloInstruction - return true if instruction MI can not be packetized -  // with any other instruction, which means that MI itself is a packet. -  virtual bool isSoloInstruction(MachineInstr *MI) { -    return true; -  } +  // isSoloInstruction - return true if instruction I must end previous +  // packet. +  bool isSoloInstruction(MachineInstr *I);    // isLegalToPacketizeTogether - Is it legal to packetize SUI and SUJ    // together. @@ -160,7 +141,6 @@ public:    virtual bool isLegalToPruneDependencies(SUnit *SUI, SUnit *SUJ) {      return false;    } -  };  } diff --git a/include/llvm/CodeGen/Passes.h b/include/llvm/CodeGen/Passes.h index 3b3819985880a..e76fe99257219 100644 --- a/include/llvm/CodeGen/Passes.h +++ b/include/llvm/CodeGen/Passes.h @@ -56,7 +56,7 @@ public:  protected:    TargetMachine *TM; -  PassManagerBase &PM; +  PassManagerBase *PM;    PassConfigImpl *Impl; // Internal data structures    bool Initialized;     // Flagged after all passes are configured. diff --git a/include/llvm/CodeGen/ScheduleDAGInstrs.h b/include/llvm/CodeGen/ScheduleDAGInstrs.h index c8de7bc8f8922..4fee108cd2be0 100644 --- a/include/llvm/CodeGen/ScheduleDAGInstrs.h +++ b/include/llvm/CodeGen/ScheduleDAGInstrs.h @@ -181,6 +181,13 @@ namespace llvm {      /// the def-side latency only.      bool UnitLatencies; +    /// The standard DAG builder does not normally include terminators as DAG +    /// nodes because it does not create the necessary dependencies to prevent +    /// reordering. A specialized scheduler can overide +    /// TargetInstrInfo::isSchedulingBoundary then enable this flag to indicate +    /// it has taken responsibility for scheduling the terminator correctly. +    bool CanHandleTerminators; +      /// State specific to the current scheduling region.      /// ------------------------------------------------ diff --git a/include/llvm/CodeGen/SlotIndexes.h b/include/llvm/CodeGen/SlotIndexes.h index d868cb8dade86..0457e43e6b7b0 100644 --- a/include/llvm/CodeGen/SlotIndexes.h +++ b/include/llvm/CodeGen/SlotIndexes.h @@ -23,6 +23,7 @@  #include "llvm/CodeGen/MachineFunction.h"  #include "llvm/CodeGen/MachineFunctionPass.h"  #include "llvm/ADT/PointerIntPair.h" +#include "llvm/ADT/ilist.h"  #include "llvm/ADT/SmallVector.h"  #include "llvm/ADT/DenseMap.h"  #include "llvm/Support/Allocator.h" @@ -33,8 +34,7 @@ namespace llvm {    /// SlotIndexes pass. It should not be used directly. See the    /// SlotIndex & SlotIndexes classes for the public interface to this    /// information. -  class IndexListEntry { -    IndexListEntry *next, *prev; +  class IndexListEntry : public ilist_node<IndexListEntry> {      MachineInstr *mi;      unsigned index; @@ -51,31 +51,26 @@ namespace llvm {      void setIndex(unsigned index) {        this->index = index;      } -     -    IndexListEntry* getNext() { return next; } -    const IndexListEntry* getNext() const { return next; } -    void setNext(IndexListEntry *next) { -      this->next = next; -    } -    IndexListEntry* getPrev() { return prev; } -    const IndexListEntry* getPrev() const { return prev; } -    void setPrev(IndexListEntry *prev) { -      this->prev = prev; -    }    }; -  // Specialize PointerLikeTypeTraits for IndexListEntry.    template <> -  class PointerLikeTypeTraits<IndexListEntry*> {  +  struct ilist_traits<IndexListEntry> : public ilist_default_traits<IndexListEntry> { +  private: +    mutable ilist_half_node<IndexListEntry> Sentinel;    public: -    static inline void* getAsVoidPointer(IndexListEntry *p) { -      return p; +    IndexListEntry *createSentinel() const { +      return static_cast<IndexListEntry*>(&Sentinel);      } -    static inline IndexListEntry* getFromVoidPointer(void *p) { -      return static_cast<IndexListEntry*>(p); -    } -    enum { NumLowBitsAvailable = 3 }; +    void destroySentinel(IndexListEntry *) const {} + +    IndexListEntry *provideInitialHead() const { return createSentinel(); } +    IndexListEntry *ensureHead(IndexListEntry*) const { return createSentinel(); } +    static void noteHead(IndexListEntry*, IndexListEntry*) {} +    void deleteNode(IndexListEntry *N) {} + +  private: +    void createNode(const IndexListEntry &);    };    /// SlotIndex - An opaque wrapper around machine indexes. @@ -112,13 +107,13 @@ namespace llvm {      SlotIndex(IndexListEntry *entry, unsigned slot)        : lie(entry, slot) {} -    IndexListEntry& entry() const { +    IndexListEntry* listEntry() const {        assert(isValid() && "Attempt to compare reserved index."); -      return *lie.getPointer(); +      return lie.getPointer();      }      int getIndex() const { -      return entry().getIndex() | getSlot(); +      return listEntry()->getIndex() | getSlot();      }      /// Returns the slot for this SlotIndex. @@ -150,8 +145,7 @@ namespace llvm {      SlotIndex() : lie(0, 0) {}      // Construct a new slot index from the given one, and set the slot. -    SlotIndex(const SlotIndex &li, Slot s) -      : lie(&li.entry(), unsigned(s)) { +    SlotIndex(const SlotIndex &li, Slot s) : lie(li.listEntry(), unsigned(s)) {        assert(lie.getPointer() != 0 &&               "Attempt to construct index with 0 pointer.");      } @@ -179,7 +173,7 @@ namespace llvm {      bool operator!=(SlotIndex other) const {        return lie != other.lie;      } -    +      /// Compare two SlotIndex objects. Return true if the first index      /// is strictly lower than the second.      bool operator<(SlotIndex other) const { @@ -211,7 +205,7 @@ namespace llvm {      /// isEarlierInstr - Return true if A refers to an instruction earlier than      /// B. This is equivalent to A < B && !isSameInstr(A, B).      static bool isEarlierInstr(SlotIndex A, SlotIndex B) { -      return A.entry().getIndex() < B.entry().getIndex(); +      return A.listEntry()->getIndex() < B.listEntry()->getIndex();      }      /// Return the distance from this index to the given one. @@ -236,25 +230,25 @@ namespace llvm {      /// is the one associated with the Slot_Block slot for the instruction      /// pointed to by this index.      SlotIndex getBaseIndex() const { -      return SlotIndex(&entry(), Slot_Block); +      return SlotIndex(listEntry(), Slot_Block);      }      /// Returns the boundary index for associated with this index. The boundary      /// index is the one associated with the Slot_Block slot for the instruction      /// pointed to by this index.      SlotIndex getBoundaryIndex() const { -      return SlotIndex(&entry(), Slot_Dead); +      return SlotIndex(listEntry(), Slot_Dead);      }      /// Returns the register use/def slot in the current instruction for a      /// normal or early-clobber def.      SlotIndex getRegSlot(bool EC = false) const { -      return SlotIndex(&entry(), EC ? Slot_EarlyClobber : Slot_Register); +      return SlotIndex(listEntry(), EC ? Slot_EarlyClobber : Slot_Register);      }      /// Returns the dead def kill slot for the current instruction.      SlotIndex getDeadSlot() const { -      return SlotIndex(&entry(), Slot_Dead); +      return SlotIndex(listEntry(), Slot_Dead);      }      /// Returns the next slot in the index list. This could be either the @@ -266,15 +260,15 @@ namespace llvm {      SlotIndex getNextSlot() const {        Slot s = getSlot();        if (s == Slot_Dead) { -        return SlotIndex(entry().getNext(), Slot_Block); +        return SlotIndex(listEntry()->getNextNode(), Slot_Block);        } -      return SlotIndex(&entry(), s + 1); +      return SlotIndex(listEntry(), s + 1);      }      /// Returns the next index. This is the index corresponding to the this      /// index's slot, but for the next instruction.      SlotIndex getNextIndex() const { -      return SlotIndex(entry().getNext(), getSlot()); +      return SlotIndex(listEntry()->getNextNode(), getSlot());      }      /// Returns the previous slot in the index list. This could be either the @@ -286,15 +280,15 @@ namespace llvm {      SlotIndex getPrevSlot() const {        Slot s = getSlot();        if (s == Slot_Block) { -        return SlotIndex(entry().getPrev(), Slot_Dead); +        return SlotIndex(listEntry()->getPrevNode(), Slot_Dead);        } -      return SlotIndex(&entry(), s - 1); +      return SlotIndex(listEntry(), s - 1);      }      /// Returns the previous index. This is the index corresponding to this      /// index's slot, but for the previous instruction.      SlotIndex getPrevIndex() const { -      return SlotIndex(entry().getPrev(), getSlot()); +      return SlotIndex(listEntry()->getPrevNode(), getSlot());      }    }; @@ -315,7 +309,7 @@ namespace llvm {        return (LHS == RHS);      }    }; -   +    template <> struct isPodLike<SlotIndex> { static const bool value = true; }; @@ -346,8 +340,10 @@ namespace llvm {    class SlotIndexes : public MachineFunctionPass {    private: +    typedef ilist<IndexListEntry> IndexList; +    IndexList indexList; +      MachineFunction *mf; -    IndexListEntry *indexListHead;      unsigned functionSize;      typedef DenseMap<const MachineInstr*, SlotIndex> Mi2IndexMap; @@ -374,84 +370,18 @@ namespace llvm {        return entry;      } -    void initList() { -      assert(indexListHead == 0 && "Zero entry non-null at initialisation."); -      indexListHead = createEntry(0, ~0U); -      indexListHead->setNext(0); -      indexListHead->setPrev(indexListHead); -    } - -    void clearList() { -      indexListHead = 0; -      ileAllocator.Reset(); -    } - -    IndexListEntry* getTail() { -      assert(indexListHead != 0 && "Call to getTail on uninitialized list."); -      return indexListHead->getPrev(); -    } - -    const IndexListEntry* getTail() const { -      assert(indexListHead != 0 && "Call to getTail on uninitialized list."); -      return indexListHead->getPrev(); -    } - -    // Returns true if the index list is empty. -    bool empty() const { return (indexListHead == getTail()); } - -    IndexListEntry* front() { -      assert(!empty() && "front() called on empty index list."); -      return indexListHead; -    } - -    const IndexListEntry* front() const { -      assert(!empty() && "front() called on empty index list."); -      return indexListHead; -    } - -    IndexListEntry* back() { -      assert(!empty() && "back() called on empty index list."); -      return getTail()->getPrev(); -    } - -    const IndexListEntry* back() const { -      assert(!empty() && "back() called on empty index list."); -      return getTail()->getPrev(); -    } - -    /// Insert a new entry before itr. -    void insert(IndexListEntry *itr, IndexListEntry *val) { -      assert(itr != 0 && "itr should not be null."); -      IndexListEntry *prev = itr->getPrev(); -      val->setNext(itr); -      val->setPrev(prev); -       -      if (itr != indexListHead) { -        prev->setNext(val); -      } -      else { -        indexListHead = val; -      } -      itr->setPrev(val); -    } - -    /// Push a new entry on to the end of the list. -    void push_back(IndexListEntry *val) { -      insert(getTail(), val); -    } - -    /// Renumber locally after inserting newEntry. -    void renumberIndexes(IndexListEntry *newEntry); +    /// Renumber locally after inserting curItr. +    void renumberIndexes(IndexList::iterator curItr);    public:      static char ID; -    SlotIndexes() : MachineFunctionPass(ID), indexListHead(0) { +    SlotIndexes() : MachineFunctionPass(ID) {        initializeSlotIndexesPass(*PassRegistry::getPassRegistry());      }      virtual void getAnalysisUsage(AnalysisUsage &au) const; -    virtual void releaseMemory();  +    virtual void releaseMemory();      virtual bool runOnMachineFunction(MachineFunction &fn); @@ -463,22 +393,21 @@ namespace llvm {      /// Returns the zero index for this analysis.      SlotIndex getZeroIndex() { -      assert(front()->getIndex() == 0 && "First index is not 0?"); -      return SlotIndex(front(), 0); +      assert(indexList.front().getIndex() == 0 && "First index is not 0?"); +      return SlotIndex(&indexList.front(), 0);      }      /// Returns the base index of the last slot in this analysis.      SlotIndex getLastIndex() { -      return SlotIndex(back(), 0); +      return SlotIndex(&indexList.back(), 0);      }      /// Returns the distance between the highest and lowest indexes allocated      /// so far.      unsigned getIndexesLength() const { -      assert(front()->getIndex() == 0 && +      assert(indexList.front().getIndex() == 0 &&               "Initial index isn't zero?"); - -      return back()->getIndex(); +      return indexList.back().getIndex();      }      /// Returns the number of instructions in the function. @@ -503,19 +432,15 @@ namespace llvm {      /// Returns the instruction for the given index, or null if the given      /// index has no instruction associated with it.      MachineInstr* getInstructionFromIndex(SlotIndex index) const { -      return index.isValid() ? index.entry().getInstr() : 0; +      return index.isValid() ? index.listEntry()->getInstr() : 0;      }      /// Returns the next non-null index.      SlotIndex getNextNonNullIndex(SlotIndex index) { -      SlotIndex nextNonNull = index.getNextIndex(); - -      while (&nextNonNull.entry() != getTail() && -             getInstructionFromIndex(nextNonNull) == 0) { -        nextNonNull = nextNonNull.getNextIndex(); -      } - -      return nextNonNull; +      IndexList::iterator itr(index.listEntry()); +      ++itr; +      while (itr != indexList.end() && itr->getInstr() == 0) { ++itr; } +      return SlotIndex(itr, index.getSlot());      }      /// getIndexBefore - Returns the index of the last indexed instruction @@ -659,31 +584,31 @@ namespace llvm {        assert(mi->getParent() != 0 && "Instr must be added to function.");        // Get the entries where mi should be inserted. -      IndexListEntry *prevEntry, *nextEntry; +      IndexList::iterator prevItr, nextItr;        if (Late) {          // Insert mi's index immediately before the following instruction. -        nextEntry = &getIndexAfter(mi).entry(); -        prevEntry = nextEntry->getPrev(); +        nextItr = getIndexAfter(mi).listEntry(); +        prevItr = prior(nextItr);        } else {          // Insert mi's index immediately after the preceeding instruction. -        prevEntry = &getIndexBefore(mi).entry(); -        nextEntry = prevEntry->getNext(); +        prevItr = getIndexBefore(mi).listEntry(); +        nextItr = llvm::next(prevItr);        }        // Get a number for the new instr, or 0 if there's no room currently.        // In the latter case we'll force a renumber later. -      unsigned dist = ((nextEntry->getIndex() - prevEntry->getIndex())/2) & ~3u; -      unsigned newNumber = prevEntry->getIndex() + dist; +      unsigned dist = ((nextItr->getIndex() - prevItr->getIndex())/2) & ~3u; +      unsigned newNumber = prevItr->getIndex() + dist;        // Insert a new list entry for mi. -      IndexListEntry *newEntry = createEntry(mi, newNumber); -      insert(nextEntry, newEntry); +      IndexList::iterator newItr = +        indexList.insert(nextItr, createEntry(mi, newNumber));        // Renumber locally if we need to.        if (dist == 0) -        renumberIndexes(newEntry); +        renumberIndexes(newItr); -      SlotIndex newIndex(newEntry, SlotIndex::Slot_Block); +      SlotIndex newIndex(&*newItr, SlotIndex::Slot_Block);        mi2iMap.insert(std::make_pair(mi, newIndex));        return newIndex;      } @@ -694,7 +619,7 @@ namespace llvm {        // MachineInstr -> index mappings        Mi2IndexMap::iterator mi2iItr = mi2iMap.find(mi);        if (mi2iItr != mi2iMap.end()) { -        IndexListEntry *miEntry(&mi2iItr->second.entry());         +        IndexListEntry *miEntry(mi2iItr->second.listEntry());          assert(miEntry->getInstr() == mi && "Instruction indexes broken.");          // FIXME: Eventually we want to actually delete these indexes.          miEntry->setInstr(0); @@ -709,7 +634,7 @@ namespace llvm {        if (mi2iItr == mi2iMap.end())          return;        SlotIndex replaceBaseIndex = mi2iItr->second; -      IndexListEntry *miEntry(&replaceBaseIndex.entry()); +      IndexListEntry *miEntry(replaceBaseIndex.listEntry());        assert(miEntry->getInstr() == mi &&               "Mismatched instruction in index tables.");        miEntry->setInstr(newMI); @@ -726,13 +651,13 @@ namespace llvm {        IndexListEntry *nextEntry = 0;        if (nextMBB == mbb->getParent()->end()) { -        nextEntry = getTail(); +        nextEntry = indexList.end();        } else { -        nextEntry = &getMBBStartIdx(nextMBB).entry(); +        nextEntry = getMBBStartIdx(nextMBB).listEntry();        } -      insert(nextEntry, startEntry); -      insert(nextEntry, stopEntry); +      indexList.insert(nextEntry, startEntry); +      indexList.insert(nextEntry, stopEntry);        SlotIndex startIdx(startEntry, SlotIndex::Slot_Block);        SlotIndex endIdx(nextEntry, SlotIndex::Slot_Block); @@ -766,4 +691,4 @@ namespace llvm {  } -#endif // LLVM_CODEGEN_LIVEINDEX_H  +#endif // LLVM_CODEGEN_SLOTINDEXES_H | 
