[llvm-commits] CVS: llvm/lib/Target/Sparc/PreSelection.cpp

Misha Brukman brukman at cs.uiuc.edu
Fri Nov 7 11:32:01 PST 2003


Changes in directory llvm/lib/Target/Sparc:

PreSelection.cpp updated: 1.24 -> 1.25

---
Log message:

* Stop making a global for each constant that cannot live in an instruction;
  it will be converted to a MachineConstantPool index during instruction
  selection
* This is now eligible to become a FunctionPass since it does not have any side
  effects outside of the function it is processing.


---
Diffs of the changes:  (+14 -36)

Index: llvm/lib/Target/Sparc/PreSelection.cpp
diff -u llvm/lib/Target/Sparc/PreSelection.cpp:1.24 llvm/lib/Target/Sparc/PreSelection.cpp:1.25
--- llvm/lib/Target/Sparc/PreSelection.cpp:1.24	Tue Oct 21 23:51:36 2003
+++ llvm/lib/Target/Sparc/PreSelection.cpp	Fri Nov  7 11:31:22 2003
@@ -34,38 +34,16 @@
   //===--------------------------------------------------------------------===//
   // PreSelection Pass - Specialize LLVM code for the current target machine.
   // 
-  class PreSelection : public Pass, public InstVisitor<PreSelection> {
+  class PreSelection : public FunctionPass, public InstVisitor<PreSelection> {
     const TargetInstrInfo &instrInfo;
-    Module *TheModule;
-
-    std::map<const Constant*, GlobalVariable*> gvars;
-
-    GlobalVariable* getGlobalForConstant(Constant* CV) {
-      std::map<const Constant*, GlobalVariable*>::iterator I = gvars.find(CV);
-      if (I != gvars.end()) return I->second;    // global exists so return it
-
-      return I->second = new GlobalVariable(CV->getType(), true,
-                                            GlobalValue::InternalLinkage, CV,
-                                            "immcst", TheModule);
-    }
 
   public:
     PreSelection(const TargetMachine &T)
-      : instrInfo(T.getInstrInfo()), TheModule(0) {}
-
-    // run - apply this pass to the entire Module
-    bool run(Module &M) {
-      TheModule = &M;
-
-      // Build reverse map for pre-existing global constants so we can find them
-      for (Module::giterator I = M.gbegin(), E = M.gend(); I != E; ++I)
-        if (I->hasInitializer() && I->isConstant())
-          gvars[I->getInitializer()] = I;
-
-      for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
-        visit(*I);
+      : instrInfo(T.getInstrInfo()) {}
 
-      gvars.clear();
+    // runOnFunction - apply this pass to each Function
+    bool runOnFunction(Function &F) {
+      visit(F);
       return true;
     }
 
@@ -87,10 +65,12 @@
                          Instruction& insertBefore);
   };
 
+#if 0
   // Register the pass...
-  RegisterOpt<PreSelection> X("preselect",
-                              "Specialize LLVM code for a target machine",
-                              createPreSelectionPass);
+  RegisterPass<PreSelection> X("preselect",
+                               "Specialize LLVM code for a target machine"
+                               createPreselectionPass);
+#endif
 }  // end anonymous namespace
 
 
@@ -184,10 +164,8 @@
     I.setOperand(opNum, computeConst); // replace expr operand with result
   } else if (instrInfo.ConstantTypeMustBeLoaded(CV)) {
     // load address of constant into a register, then load the constant
-    GetElementPtrInst* gep = getGlobalAddr(getGlobalForConstant(CV),
-                                           insertBefore);
-    LoadInst* ldI = new LoadInst(gep, "loadConst", &insertBefore);
-    I.setOperand(opNum, ldI);        // replace operand with copy in v.reg.
+    // this is now done during instruction selection
+    // the constant will live in the MachineConstantPool later on
   } else if (instrInfo.ConstantMayNotFitInImmedField(CV, &I)) {
     // put the constant into a virtual register using a cast
     CastInst* castI = new CastInst(CV, CV->getType(), "copyConst",
@@ -263,6 +241,6 @@
 // createPreSelectionPass - Public entrypoint for pre-selection pass
 // and this file as a whole...
 //
-Pass* createPreSelectionPass(TargetMachine &T) {
-  return new PreSelection(T);
+FunctionPass* createPreSelectionPass(const TargetMachine &TM) {
+  return new PreSelection(TM);
 }





More information about the llvm-commits mailing list