[llvm-commits] CVS: llvm/lib/Target/PowerPC/PPC32AsmPrinter.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Aug 16 16:25:34 PDT 2004



Changes in directory llvm/lib/Target/PowerPC:

PPC32AsmPrinter.cpp updated: 1.41 -> 1.42
---
Log message:

Finegrainify namespacification
Start using the AsmPrinter base class to factor out a bunch of code


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

Index: llvm/lib/Target/PowerPC/PPC32AsmPrinter.cpp
diff -u llvm/lib/Target/PowerPC/PPC32AsmPrinter.cpp:1.41 llvm/lib/Target/PowerPC/PPC32AsmPrinter.cpp:1.42
--- llvm/lib/Target/PowerPC/PPC32AsmPrinter.cpp:1.41	Sun Aug 15 00:48:47 2004
+++ llvm/lib/Target/PowerPC/PPC32AsmPrinter.cpp	Mon Aug 16 18:25:21 2004
@@ -24,6 +24,7 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
 #include "llvm/Assembly/Writer.h"
+#include "llvm/CodeGen/AsmPrinter.h"
 #include "llvm/CodeGen/MachineConstantPool.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/MachineInstr.h"
@@ -35,36 +36,17 @@
 #include "Support/Statistic.h"
 #include "Support/StringExtras.h"
 #include <set>
-
-namespace llvm {
+using namespace llvm;
 
 namespace {
   Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
 
-  struct PowerPCAsmPrinter : public MachineFunctionPass {
-    /// Output stream on which we're printing assembly code.
-    ///
-    std::ostream &O;
-
-    /// Target machine description which we query for reg. names, data
-    /// layout, etc.
-    ///
-    PowerPCTargetMachine &TM;
-
-    /// Name-mangler for global names.
-    ///
-    Mangler *Mang;
+  struct PowerPCAsmPrinter : public AsmPrinter {
     std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
     std::set<std::string> Strings;
 
-    PowerPCAsmPrinter(std::ostream &o, TargetMachine &tm) : O(o),
-      TM(reinterpret_cast<PowerPCTargetMachine&>(tm)), LabelNumber(0) {}
-
-    /// Cache of mangled name for current function. This is
-    /// recalculated at the beginning of each call to
-    /// runOnMachineFunction().
-    ///
-    std::string CurrentFnName;
+    PowerPCAsmPrinter(std::ostream &O, TargetMachine &TM)
+      : AsmPrinter(O, TM), LabelNumber(0) {}
 
     /// Unique incrementer for label values for referencing Global values.
     ///
@@ -74,6 +56,10 @@
       return "PowerPC Assembly Printer";
     }
 
+    PowerPCTargetMachine &getTM() {
+      return static_cast<PowerPCTargetMachine&>(TM);
+    }
+
     /// printInstruction - This method is automatically generated by tablegen
     /// from the instruction set description.  This method returns true if the
     /// machine instruction was sufficiently described to print it, otherwise it
@@ -103,10 +89,8 @@
 
     void printConstantPool(MachineConstantPool *MCP);
     bool runOnMachineFunction(MachineFunction &F);    
-    bool doInitialization(Module &M);
     bool doFinalization(Module &M);
     void emitGlobalConstant(const Constant* CV);
-    void emitConstantValueOnly(const Constant *CV);
   };
 } // end of anonymous namespace
 
@@ -115,7 +99,7 @@
 /// using the given target machine description.  This should work
 /// regardless of whether the function is in SSA form or not.
 ///
-FunctionPass *createPPCAsmPrinter(std::ostream &o,TargetMachine &tm) {
+FunctionPass *llvm::createPPCAsmPrinter(std::ostream &o,TargetMachine &tm) {
   return new PowerPCAsmPrinter(o, tm);
 }
 
@@ -178,76 +162,6 @@
   O << "\"";
 }
 
-// Print out the specified constant, without a storage class.  Only the
-// constants valid in constant expressions can occur here.
-void PowerPCAsmPrinter::emitConstantValueOnly(const Constant *CV) {
-  if (CV->isNullValue())
-    O << "0";
-  else if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) {
-    assert(CB == ConstantBool::True);
-    O << "1";
-  } else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV))
-    O << CI->getValue();
-  else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV))
-    O << CI->getValue();
-  else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV))
-    // This is a constant address for a global variable or function.  Use the
-    // name of the variable or function as the address value.
-    O << Mang->getValueName(GV);
-  else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
-    const TargetData &TD = TM.getTargetData();
-    switch (CE->getOpcode()) {
-    case Instruction::GetElementPtr: {
-      // generate a symbolic expression for the byte address
-      const Constant *ptrVal = CE->getOperand(0);
-      std::vector<Value*> idxVec(CE->op_begin()+1, CE->op_end());
-      if (unsigned Offset = TD.getIndexedOffset(ptrVal->getType(), idxVec)) {
-        O << "(";
-        emitConstantValueOnly(ptrVal);
-        O << ") + " << Offset;
-      } else {
-        emitConstantValueOnly(ptrVal);
-      }
-      break;
-    }
-    case Instruction::Cast: {
-      // Support only non-converting or widening casts for now, that is, ones
-      // that do not involve a change in value.  This assertion is really gross,
-      // and may not even be a complete check.
-      Constant *Op = CE->getOperand(0);
-      const Type *OpTy = Op->getType(), *Ty = CE->getType();
-
-      // Remember, kids, pointers on x86 can be losslessly converted back and
-      // forth into 32-bit or wider integers, regardless of signedness. :-P
-      assert(((isa<PointerType>(OpTy)
-               && (Ty == Type::LongTy || Ty == Type::ULongTy
-                   || Ty == Type::IntTy || Ty == Type::UIntTy))
-              || (isa<PointerType>(Ty)
-                  && (OpTy == Type::LongTy || OpTy == Type::ULongTy
-                      || OpTy == Type::IntTy || OpTy == Type::UIntTy))
-              || (((TD.getTypeSize(Ty) >= TD.getTypeSize(OpTy))
-                   && OpTy->isLosslesslyConvertibleTo(Ty))))
-             && "FIXME: Don't yet support this kind of constant cast expr");
-      O << "(";
-      emitConstantValueOnly(Op);
-      O << ")";
-      break;
-    }
-    case Instruction::Add:
-      O << "(";
-      emitConstantValueOnly(CE->getOperand(0));
-      O << ") + (";
-      emitConstantValueOnly(CE->getOperand(1));
-      O << ")";
-      break;
-    default:
-      assert(0 && "Unsupported operator!");
-    }
-  } else {
-    assert(0 && "Unknown constant value!");
-  }
-}
-
 // Print a constant value or values, with the appropriate storage class as a
 // prefix.
 void PowerPCAsmPrinter::emitGlobalConstant(const Constant *CV) {  
@@ -382,9 +296,8 @@
 /// method to print assembly for each instruction.
 ///
 bool PowerPCAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
+  setupMachineFunction(MF);
   O << "\n\n";
-  // What's my mangled name?
-  CurrentFnName = Mang->getValueName(MF.getFunction());
 
   // Print out constants referenced by the function
   printConstantPool(MF.getConstantPool());
@@ -467,20 +380,20 @@
     // are taken.  Those should be emitted as $non_lazy_ptr below.
     Function *F = dyn_cast<Function>(GV);
     if (F && F->isExternal() && !LoadAddrOp &&
-        TM.CalledFunctions.find(F) != TM.CalledFunctions.end()) {
+        getTM().CalledFunctions.count(F)) {
       FnStubs.insert(Name);
       O << "L" << Name << "$stub";
       return;
     }
     
     // External global variables need a non-lazily-resolved stub
-    if (GV->isExternal() && TM.AddressTaken.find(GV) != TM.AddressTaken.end()) {
+    if (GV->isExternal() && getTM().AddressTaken.count(GV)) {
       GVStubs.insert(Name);
       O << "L" << Name << "$non_lazy_ptr";
       return;
     }
     
-    if (F && LoadAddrOp && TM.AddressTaken.find(GV) != TM.AddressTaken.end()) {
+    if (F && LoadAddrOp && getTM().AddressTaken.count(GV)) {
       LinkOnceStubs.insert(Name);
       O << "L" << Name << "$non_lazy_ptr";
       return;
@@ -626,11 +539,6 @@
   return;
 }
 
-bool PowerPCAsmPrinter::doInitialization(Module &M) {
-  Mang = new Mangler(M, true);
-  return false; // success
-}
-
 // SwitchSection - Switch to the specified section of the executable if we are
 // not already in it!
 //
@@ -750,8 +658,6 @@
       << "\t.long\t" << *i << '\n';
   }
   
-  delete Mang;
+  AsmPrinter::doFinalization(M);
   return false; // success
 }
-
-} // End llvm namespace






More information about the llvm-commits mailing list