X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FCodeGen%2FRenderMachineFunction.h;h=85719923c0c664b876cfe5f08606be604f7cd44e;hb=7332e6ee25378e19c0f621c80c32b283b07f428a;hp=743938d9edbb94e90b46f6958e44c20c1cd913d3;hpb=c4bcc778a8dcc385b129852c9aa1c712d042ad63;p=oota-llvm.git diff --git a/lib/CodeGen/RenderMachineFunction.h b/lib/CodeGen/RenderMachineFunction.h index 743938d9edb..85719923c0c 100644 --- a/lib/CodeGen/RenderMachineFunction.h +++ b/lib/CodeGen/RenderMachineFunction.h @@ -28,75 +28,11 @@ namespace llvm { class LiveIntervals; class MachineInstr; class MachineRegisterInfo; + class RenderMachineFunction; class TargetRegisterClass; class TargetRegisterInfo; class VirtRegMap; - - /// \brief Provide extra information about the physical and virtual registers - /// in the function being compiled. - class TargetRegisterExtraInfo { - public: - TargetRegisterExtraInfo(); - - /// \brief Set up TargetRegisterExtraInfo with pointers to necessary - /// sources of information. - void setup(MachineFunction *mf, MachineRegisterInfo *mri, - const TargetRegisterInfo *tri, LiveIntervals *lis); - - /// \brief Recompute tables for changed function. - void reset(); - - /// \brief Free all tables in TargetRegisterExtraInfo. - void clear(); - - /// \brief Maximum number of registers from trc which alias reg. - unsigned getWorst(unsigned reg, const TargetRegisterClass *trc) const; - - /// \brief Returns the number of allocable registers in trc. - unsigned getCapacity(const TargetRegisterClass *trc) const; - - /// \brief Return the number of registers of class trc that may be - /// needed at slot i. - unsigned getPressureAtSlot(const TargetRegisterClass *trc, - SlotIndex i) const; - - /// \brief Return true if the number of registers of type trc that may be - /// needed at slot i is greater than the capacity of trc. - bool classOverCapacityAtSlot(const TargetRegisterClass *trc, - SlotIndex i) const; - - private: - - MachineFunction *mf; - MachineRegisterInfo *mri; - const TargetRegisterInfo *tri; - LiveIntervals *lis; - - typedef std::map WorstMapLine; - typedef std::map VRWorstMap; - VRWorstMap vrWorst; - - typedef std::map PRWorstMap; - PRWorstMap prWorst; - - typedef std::map CapacityMap; - CapacityMap capacityMap; - - typedef std::map PressureMapLine; - typedef std::map PressureMap; - PressureMap pressureMap; - - bool mapsPopulated; - - /// \brief Initialise the 'worst' table. - void initWorst(); - - /// \brief Initialise the 'capacity' table. - void initCapacity(); - - /// \brief Initialise/Reset the 'pressure' and live states tables. - void resetPressureAndLiveStates(); - }; + class raw_ostream; /// \brief Helper class to process rendering options. Tries to be as lazy as /// possible. @@ -124,7 +60,7 @@ namespace llvm { /// Initialise the rendering options. void setup(MachineFunction *mf, const TargetRegisterInfo *tri, - LiveIntervals *lis); + LiveIntervals *lis, const RenderMachineFunction *rmf); /// Clear translations of options to the current function. void clear(); @@ -159,9 +95,11 @@ namespace llvm { static std::set > intervalNumsToRender; typedef enum { ExplicitOnly = 0, - VirtPlusExplicit = 1, - PhysPlusExplicit = 2, - All = 3 } + AllPhys = 1, + VirtNoSpills = 2, + VirtSpills = 4, + AllVirt = 6, + All = 7 } IntervalTypesToRender; static unsigned intervalTypesToRender; @@ -179,6 +117,7 @@ namespace llvm { MachineFunction *mf; const TargetRegisterInfo *tri; LiveIntervals *lis; + const RenderMachineFunction *rmf; mutable bool regClassesTranslatedToCurrentFunction; mutable RegClassSet regClassSet; @@ -191,13 +130,81 @@ namespace llvm { void translateIntervalNumbersToCurrentFunction() const; }; + /// \brief Provide extra information about the physical and virtual registers + /// in the function being compiled. + class TargetRegisterExtraInfo { + public: + TargetRegisterExtraInfo(); + + /// \brief Set up TargetRegisterExtraInfo with pointers to necessary + /// sources of information. + void setup(MachineFunction *mf, MachineRegisterInfo *mri, + const TargetRegisterInfo *tri, LiveIntervals *lis); + + /// \brief Recompute tables for changed function. + void reset(); + + /// \brief Free all tables in TargetRegisterExtraInfo. + void clear(); + + /// \brief Maximum number of registers from trc which alias reg. + unsigned getWorst(unsigned reg, const TargetRegisterClass *trc) const; + + /// \brief Returns the number of allocable registers in trc. + unsigned getCapacity(const TargetRegisterClass *trc) const; + + /// \brief Return the number of registers of class trc that may be + /// needed at slot i. + unsigned getPressureAtSlot(const TargetRegisterClass *trc, + SlotIndex i) const; + + /// \brief Return true if the number of registers of type trc that may be + /// needed at slot i is greater than the capacity of trc. + bool classOverCapacityAtSlot(const TargetRegisterClass *trc, + SlotIndex i) const; + + private: + + MachineFunction *mf; + MachineRegisterInfo *mri; + const TargetRegisterInfo *tri; + LiveIntervals *lis; + + typedef std::map WorstMapLine; + typedef std::map VRWorstMap; + VRWorstMap vrWorst; + + typedef std::map PRWorstMap; + PRWorstMap prWorst; + + typedef std::map CapacityMap; + CapacityMap capacityMap; + + typedef std::map PressureMapLine; + typedef std::map PressureMap; + PressureMap pressureMap; + + bool mapsPopulated; + + /// \brief Initialise the 'worst' table. + void initWorst(); + + /// \brief Initialise the 'capacity' table. + void initCapacity(); + + /// \brief Initialise/Reset the 'pressure' and live states tables. + void resetPressureAndLiveStates(); + }; + /// \brief Render MachineFunction objects and related information to a HTML /// page. class RenderMachineFunction : public MachineFunctionPass { public: static char ID; - RenderMachineFunction() : MachineFunctionPass(&ID) {} + RenderMachineFunction() : MachineFunctionPass(ID) { + initializeRenderMachineFunctionPass(*PassRegistry::getPassRegistry()); + } virtual void getAnalysisUsage(AnalysisUsage &au) const; @@ -205,6 +212,13 @@ namespace llvm { virtual void releaseMemory(); + void rememberUseDefs(const LiveInterval *li); + + void rememberSpills(const LiveInterval *li, + const std::vector &spills); + + bool isSpill(const LiveInterval *li) const; + /// \brief Render this machine function to HTML. /// /// @param renderContextStr This parameter will be included in the top of @@ -223,6 +237,8 @@ namespace llvm { const char *renderSuffix = 0); private: + class Spacer; + friend raw_ostream& operator<<(raw_ostream &os, const Spacer &s); std::string fqn; @@ -236,60 +252,83 @@ namespace llvm { TargetRegisterExtraInfo trei; MFRenderingOptions ro; + + // Utilities. typedef enum { Dead, Defined, Used, AliveReg, AliveStack } LiveState; - LiveState getLiveStateAt(const LiveInterval *li, SlotIndex i) const; + typedef enum { Zero, Low, High } PressureState; + PressureState getPressureStateAt(const TargetRegisterClass *trc, + SlotIndex i) const; + + typedef std::map > + SpillIntervals; + SpillIntervals spillIntervals; + + typedef std::map SpillForMap; + SpillForMap spillFor; + + typedef std::set SlotSet; + typedef std::map UseDefs; + UseDefs useDefs; + // ---------- Rendering methods ---------- + /// For inserting spaces when pretty printing. + class Spacer { + public: + explicit Spacer(unsigned numSpaces) : ns(numSpaces) {} + Spacer operator+(const Spacer &o) const { return Spacer(ns + o.ns); } + void print(raw_ostream &os) const; + private: + unsigned ns; + }; + + Spacer s(unsigned ns) const; + template std::string escapeChars(Iterator sBegin, Iterator sEnd) const; /// \brief Render a machine instruction. - template - void renderMachineInstr(OStream &os, + void renderMachineInstr(raw_ostream &os, const MachineInstr *mi) const; /// \brief Render vertical text. - template - void renderVertical(const std::string &indent, - OStream &os, + template + void renderVertical(const Spacer &indent, + raw_ostream &os, const T &t) const; /// \brief Insert CSS layout info. - template - void insertCSS(const std::string &indent, - OStream &os) const; + void insertCSS(const Spacer &indent, + raw_ostream &os) const; /// \brief Render a brief summary of the function (including rendering /// context). - template - void renderFunctionSummary(const std::string &indent, - OStream &os, + void renderFunctionSummary(const Spacer &indent, + raw_ostream &os, const char * const renderContextStr) const; /// \brief Render a legend for the pressure table. - template - void renderPressureTableLegend(const std::string &indent, - OStream &os) const; + void renderPressureTableLegend(const Spacer &indent, + raw_ostream &os) const; + + /// \brief Render a consecutive set of HTML cells of the same class using + /// the colspan attribute for run-length encoding. + template + void renderCellsWithRLE( + const Spacer &indent, raw_ostream &os, + const std::pair &rleAccumulator, + const std::map &cellTypeStrs) const; /// \brief Render code listing, potentially with register pressure /// and live intervals shown alongside. - template - void renderCodeTablePlusPI(const std::string &indent, - OStream &os) const; - - /// \brief Render warnings about the machine function, or weird rendering - /// parameter combinations (e.g. rendering specified live intervals - /// over more than one machine function). - template - void renderWarnings(const std::string &indent, - OStream &os) const; + void renderCodeTablePlusPI(const Spacer &indent, + raw_ostream &os) const; /// \brief Render the HTML page representing the MachineFunction. - template - void renderFunctionPage(OStream &os, + void renderFunctionPage(raw_ostream &os, const char * const renderContextStr) const; std::string escapeChars(const std::string &s) const;