Create constant expression casts instead of constant instructions if possible
[oota-llvm.git] / lib / CodeGen / MachineFunction.cpp
index 79886176ccc31510bb0d3d508a38b815425ff14e..57b34fae1f528b74dbf5db800611c3fa6171095c 100644 (file)
 #include "llvm/CodeGen/SSARegMap.h"
 #include "llvm/CodeGen/MachineFunctionInfo.h"
 #include "llvm/CodeGen/MachineFrameInfo.h"
+#include "llvm/CodeGen/MachineConstantPool.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetFrameInfo.h"
-#include "llvm/Target/MachineCacheInfo.h"
+#include "llvm/Target/TargetCacheInfo.h"
 #include "llvm/Function.h"
 #include "llvm/iOther.h"
 #include "llvm/Pass.h"
@@ -102,12 +103,14 @@ MachineFunction::MachineFunction(const Function *F,
   SSARegMapping = new SSARegMap();
   MFInfo = new MachineFunctionInfo(*this);
   FrameInfo = new MachineFrameInfo();
+  ConstantPool = new MachineConstantPool();
 }
 
 MachineFunction::~MachineFunction() { 
   delete SSARegMapping;
   delete MFInfo;
   delete FrameInfo;
+  delete ConstantPool;
 }
 
 void MachineFunction::dump() const { print(std::cerr); }
@@ -117,7 +120,10 @@ void MachineFunction::print(std::ostream &OS) const {
      << "\"\n";
 
   // Print Frame Information
-  getFrameInfo()->print(OS);
+  getFrameInfo()->print(*this, OS);
+
+  // Print Constant Pool
+  getConstantPool()->print(OS);
   
   for (const_iterator BB = begin(); BB != end(); ++BB) {
     BasicBlock *LBB = BB->getBasicBlock();
@@ -171,10 +177,23 @@ void MachineFunction::clearSSARegMap() {
 //  MachineFrameInfo implementation
 //===----------------------------------------------------------------------===//
 
-void MachineFrameInfo::print(std::ostream &OS) const {
+/// CreateStackObject - Create a stack object for a value of the specified type.
+///
+int MachineFrameInfo::CreateStackObject(const Type *Ty, const TargetData &TD) {
+  return CreateStackObject(TD.getTypeSize(Ty), TD.getTypeAlignment(Ty));
+}
+
+int MachineFrameInfo::CreateStackObject(const TargetRegisterClass *RC) {
+  return CreateStackObject(RC->getSize(), RC->getAlignment());
+}
+
+
+void MachineFrameInfo::print(const MachineFunction &MF, std::ostream &OS) const{
+  int ValOffset = MF.getTarget().getFrameInfo().getOffsetOfLocalArea();
+
   for (unsigned i = 0, e = Objects.size(); i != e; ++i) {
     const StackObject &SO = Objects[i];
-    OS << "  <fi" << (int)(i-NumFixedObjects) << "> is ";
+    OS << "  <fi #" << (int)(i-NumFixedObjects) << "> is ";
     if (SO.Size == 0)
       OS << "variable sized";
     else
@@ -183,11 +202,12 @@ void MachineFrameInfo::print(std::ostream &OS) const {
     if (i < NumFixedObjects)
       OS << " fixed";
     if (i < NumFixedObjects || SO.SPOffset != -1) {
+      int Off = SO.SPOffset + ValOffset;
       OS << " at location [SP";
-      if (SO.SPOffset > 0)
-       OS << "+" << SO.SPOffset;
-      else if (SO.SPOffset < 0)
-       OS << SO.SPOffset;
+      if (Off > 0)
+       OS << "+" << Off;
+      else if (Off < 0)
+       OS << Off;
       OS << "]";
     }
     OS << "\n";
@@ -197,8 +217,21 @@ void MachineFrameInfo::print(std::ostream &OS) const {
     OS << "  Stack frame contains variable sized objects\n";
 }
 
-void MachineFrameInfo::dump() const { print(std::cerr); }
+void MachineFrameInfo::dump(const MachineFunction &MF) const {
+  print(MF, std::cerr);
+}
+
+
+//===----------------------------------------------------------------------===//
+//  MachineConstantPool implementation
+//===----------------------------------------------------------------------===//
+
+void MachineConstantPool::print(std::ostream &OS) const {
+  for (unsigned i = 0, e = Constants.size(); i != e; ++i)
+    OS << "  <cp #" << i << "> is" << *(Value*)Constants[i] << "\n";
+}
 
+void MachineConstantPool::dump() const { print(std::cerr); }
 
 //===----------------------------------------------------------------------===//
 //  MachineFunctionInfo implementation
@@ -214,7 +247,7 @@ ComputeMaxOptionalArgsSize(const TargetMachine& target, const Function *F,
   
   for (Function::const_iterator BB = F->begin(), BBE = F->end(); BB !=BBE; ++BB)
     for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I)
-      if (const CallInst *callInst = dyn_cast<CallInst>(&*I))
+      if (const CallInst *callInst = dyn_cast<CallInst>(I))
         {
           unsigned numOperands = callInst->getNumOperands() - 1;
           int numExtra = (int)numOperands-frameInfo.getNumFixedOutgoingArgs();