[llvm-commits] [parallel] CVS: llvm/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.h BBLiveVar.cpp BBLiveVar.h FunctionLiveVarInfo.cpp Makefile

Misha Brukman brukman at cs.uiuc.edu
Mon Mar 1 18:02:39 PST 2004


Changes in directory llvm/lib/Target/SparcV9/LiveVar:

FunctionLiveVarInfo.h added (r1.1.2.1)
BBLiveVar.cpp updated: 1.41 -> 1.41.2.1
BBLiveVar.h updated: 1.25 -> 1.25.4.1
FunctionLiveVarInfo.cpp updated: 1.51 -> 1.51.2.1
Makefile updated: 1.4 -> 1.4.2.1

---
Log message:

Merge from trunk

---
Diffs of the changes:  (+128 -15)

Index: llvm/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.h
diff -c /dev/null llvm/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.h:1.1.2.1
*** /dev/null	Mon Mar  1 17:58:27 2004
--- llvm/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.h	Mon Mar  1 17:58:15 2004
***************
*** 0 ****
--- 1,111 ----
+ //===-- CodeGen/FunctionLiveVarInfo.h - LiveVar Analysis --------*- C++ -*-===//
+ // 
+ //                     The LLVM Compiler Infrastructure
+ //
+ // This file was developed by the LLVM research group and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ // 
+ //===----------------------------------------------------------------------===//
+ //
+ // This is the interface for live variable info of a function that is required 
+ // by any other part of the compiler
+ //
+ // After the analysis, getInSetOfBB or getOutSetofBB can be called to get 
+ // live var info of a BB.
+ //
+ // The live var set before an instruction can be obtained in 2 ways:
+ //
+ // 1. Use the method getLiveVarSetAfterInst(Instruction *) to get the LV Info 
+ //    just after an instruction. (also exists getLiveVarSetBeforeInst(..))
+ //
+ //    This function caluclates the LV info for a BB only once and caches that 
+ //    info. If the cache does not contain the LV info of the instruction, it 
+ //    calculates the LV info for the whole BB and caches them.
+ //
+ //    Getting liveVar info this way uses more memory since, LV info should be 
+ //    cached. However, if you need LV info of nearly all the instructions of a
+ //    BB, this is the best and simplest interfrace.
+ //
+ // 2. Use the OutSet and applyTranferFuncForInst(const Instruction *const Inst) 
+ //    declared in LiveVarSet and  traverse the instructions of a basic block in 
+ //    reverse (using const_reverse_iterator in the BB class). 
+ //
+ //===----------------------------------------------------------------------===//
+ 
+ #ifndef FUNCTION_LIVE_VAR_INFO_H
+ #define FUNCTION_LIVE_VAR_INFO_H
+ 
+ #include "Support/hash_map"
+ #include "llvm/Pass.h"
+ #include "llvm/CodeGen/ValueSet.h"
+ 
+ namespace llvm {
+ 
+ class BBLiveVar;
+ class MachineInstr;
+ 
+ class FunctionLiveVarInfo : public FunctionPass {
+   // Machine Instr to LiveVarSet Map for providing LVset BEFORE each inst
+   // These sets are owned by this map and will be freed in releaseMemory().
+   hash_map<const MachineInstr *, ValueSet *> MInst2LVSetBI; 
+ 
+   // Machine Instr to LiveVarSet Map for providing LVset AFTER each inst.
+   // These sets are just pointers to sets in MInst2LVSetBI or BBLiveVar.
+   hash_map<const MachineInstr *, ValueSet *> MInst2LVSetAI;
+ 
+   hash_map<const BasicBlock*, BBLiveVar*> BBLiveVarInfo;
+ 
+   // Stored Function that the data is computed with respect to
+   const Function *M;
+ 
+   // --------- private methods -----------------------------------------
+ 
+   // constructs BBLiveVars and init Def and In sets
+   void constructBBs(const Function *F);
+     
+   // do one backward pass over the CFG
+   bool doSingleBackwardPass(const Function *F, unsigned int iter); 
+ 
+   // calculates live var sets for instructions in a BB
+   void calcLiveVarSetsForBB(const BasicBlock *BB);
+   
+ public:
+   // --------- Implement the FunctionPass interface ----------------------
+ 
+   // runOnFunction - Perform analysis, update internal data structures.
+   virtual bool runOnFunction(Function &F);
+ 
+   // releaseMemory - After LiveVariable analysis has been used, forget!
+   virtual void releaseMemory();
+ 
+   // getAnalysisUsage - Provide self!
+   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+     AU.setPreservesAll();
+   }
+ 
+   // --------- Functions to access analysis results -------------------
+ 
+   // get OutSet of a BB
+   const ValueSet &getOutSetOfBB(const BasicBlock *BB) const;
+         ValueSet &getOutSetOfBB(const BasicBlock *BB)      ;
+ 
+   // get InSet of a BB
+   const ValueSet &getInSetOfBB(const BasicBlock *BB) const;
+         ValueSet &getInSetOfBB(const BasicBlock *BB)      ;
+ 
+   // gets the Live var set BEFORE an instruction.
+   // if BB is specified and the live var set has not yet been computed,
+   // it will be computed on demand.
+   const ValueSet &getLiveVarSetBeforeMInst(const MachineInstr *MI,
+                                            const BasicBlock *BB = 0);
+ 
+   // gets the Live var set AFTER an instruction
+   // if BB is specified and the live var set has not yet been computed,
+   // it will be computed on demand.
+   const ValueSet &getLiveVarSetAfterMInst(const MachineInstr *MI,
+                                           const BasicBlock *BB = 0);
+ };
+ 
+ } // End llvm namespace
+ 
+ #endif


Index: llvm/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp
diff -u llvm/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp:1.41 llvm/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp:1.41.2.1
--- llvm/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp:1.41	Fri Jan  9 12:15:24 2004
+++ llvm/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp	Mon Mar  1 17:58:15 2004
@@ -12,16 +12,18 @@
 //===----------------------------------------------------------------------===//
 
 #include "BBLiveVar.h"
-#include "llvm/CodeGen/FunctionLiveVarInfo.h"
+#include "FunctionLiveVarInfo.h"
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/CodeGen/MachineBasicBlock.h"
 #include "llvm/Support/CFG.h"
 #include "Support/SetOperations.h"
-#include "../SparcInternals.h"
+#include "../SparcV9Internals.h"
 
 namespace llvm {
 
-BBLiveVar::BBLiveVar(const BasicBlock &bb, MachineBasicBlock &mbb, unsigned id)
+BBLiveVar::BBLiveVar(const BasicBlock &bb,
+                     const MachineBasicBlock &mbb,
+                     unsigned id)
   : BB(bb), MBB(mbb), POID(id) {
   InSetChanged = OutSetChanged = false;
 
@@ -39,7 +41,7 @@
   // iterate over all the machine instructions in BB
   for (MachineBasicBlock::const_reverse_iterator MII = MBB.rbegin(),
          MIE = MBB.rend(); MII != MIE; ++MII) {
-    const MachineInstr *MI = *MII;
+    const MachineInstr *MI = &*MII;
     
     if (DEBUG_LV >= LV_DEBUG_Verbose) {
       std::cerr << " *Iterating over machine instr ";
@@ -76,7 +78,7 @@
         // Put Phi operands in UseSet for the incoming edge, not node.
         // They must not "hide" later defs, and must be handled specially
         // during set propagation over the CFG.
-	if (MI->getOpCode() == V9::PHI) {         // for a phi node
+	if (MI->getOpcode() == V9::PHI) {         // for a phi node
           const Value *ArgVal = Op;
 	  const BasicBlock *PredBB = cast<BasicBlock>(*++OpI); // next ptr is BB
 	  
@@ -95,7 +97,7 @@
 
     // do for implicit operands as well
     for (unsigned i = 0; i < MI->getNumImplicitRefs(); ++i) {
-      assert(MI->getOpCode() != V9::PHI && "Phi cannot have implicit operands");
+      assert(MI->getOpcode() != V9::PHI && "Phi cannot have implicit operands");
       const Value *Op = MI->getImplicitRef(i);
 
       if (Op->getType() == Type::LabelTy)             // don't process labels


Index: llvm/lib/Target/SparcV9/LiveVar/BBLiveVar.h
diff -u llvm/lib/Target/SparcV9/LiveVar/BBLiveVar.h:1.25 llvm/lib/Target/SparcV9/LiveVar/BBLiveVar.h:1.25.4.1
--- llvm/lib/Target/SparcV9/LiveVar/BBLiveVar.h:1.25	Tue Nov 11 16:41:32 2003
+++ llvm/lib/Target/SparcV9/LiveVar/BBLiveVar.h	Mon Mar  1 17:58:15 2004
@@ -35,7 +35,7 @@
 
 class BBLiveVar {
   const BasicBlock &BB;         // pointer to BasicBlock
-  MachineBasicBlock &MBB;       // Pointer to MachineBasicBlock
+  const MachineBasicBlock &MBB; // Pointer to MachineBasicBlock
   unsigned POID;                // Post-Order ID
 
   ValueSet DefSet;           // Def set (with no preceding uses) for LV analysis
@@ -61,12 +61,12 @@
   void calcDefUseSets();         // calculates the Def & Use sets for this BB
 public:
 
-  BBLiveVar(const BasicBlock &BB, MachineBasicBlock &MBB, unsigned POID);
+  BBLiveVar(const BasicBlock &BB, const MachineBasicBlock &MBB, unsigned POID);
 
   inline bool isInSetChanged() const  { return InSetChanged; }    
   inline bool isOutSetChanged() const { return OutSetChanged; }
 
-  MachineBasicBlock &getMachineBasicBlock() const { return MBB; }
+  const MachineBasicBlock &getMachineBasicBlock() const { return MBB; }
 
   inline unsigned getPOId() const { return POID; }
 


Index: llvm/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp
diff -u llvm/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp:1.51 llvm/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp:1.51.2.1
--- llvm/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp:1.51	Sun Dec 14 07:24:17 2003
+++ llvm/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp	Mon Mar  1 17:58:15 2004
@@ -12,7 +12,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/CodeGen/FunctionLiveVarInfo.h"
+#include "FunctionLiveVarInfo.h"
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/Target/TargetMachine.h"
@@ -283,7 +283,7 @@
   for (MachineBasicBlock::const_reverse_iterator MII = MIVec.rbegin(),
          MIE = MIVec.rend(); MII != MIE; ++MII) {  
     // MI is cur machine inst
-    const MachineInstr *MI = *MII;  
+    const MachineInstr *MI = &*MII;  
 
     MInst2LVSetAI[MI] = SetAI;                 // record in After Inst map
 
@@ -295,12 +295,12 @@
     // If the current machine instruction has delay slots, mark values
     // used by this instruction as live before and after each delay slot
     // instruction (After(MI) is the same as Before(MI+1) except for last MI).
-    if (unsigned DS = TM.getInstrInfo().getNumDelaySlots(MI->getOpCode())) {
+    if (unsigned DS = TM.getInstrInfo().getNumDelaySlots(MI->getOpcode())) {
       MachineBasicBlock::const_iterator fwdMII = MII.base(); // ptr to *next* MI
       for (unsigned i = 0; i < DS; ++i, ++fwdMII) {
         assert(fwdMII != MIVec.end() && "Missing instruction in delay slot?");
-        MachineInstr* DelaySlotMI = *fwdMII;
-        if (! TM.getInstrInfo().isNop(DelaySlotMI->getOpCode())) {
+        const MachineInstr* DelaySlotMI = fwdMII;
+        if (! TM.getInstrInfo().isNop(DelaySlotMI->getOpcode())) {
           set_union(*MInst2LVSetBI[DelaySlotMI], *NewSet);
           if (i+1 == DS)
             set_union(*MInst2LVSetAI[DelaySlotMI], *NewSet);


Index: llvm/lib/Target/SparcV9/LiveVar/Makefile
diff -u llvm/lib/Target/SparcV9/LiveVar/Makefile:1.4 llvm/lib/Target/SparcV9/LiveVar/Makefile:1.4.2.1
--- llvm/lib/Target/SparcV9/LiveVar/Makefile:1.4	Fri Jan  9 12:15:24 2004
+++ llvm/lib/Target/SparcV9/LiveVar/Makefile	Mon Mar  1 17:58:15 2004
@@ -8,7 +8,7 @@
 ##===----------------------------------------------------------------------===##
 
 LEVEL = ../../../..
-LIBRARYNAME = livevar
+LIBRARYNAME = sparcv9livevar
 
 include $(LEVEL)/Makefile.common
 





More information about the llvm-commits mailing list