[llvm-commits] CVS: llvm/lib/CodeGen/AsmPrinter.cpp MachineFunction.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Feb 8 20:46:18 PST 2006



Changes in directory llvm/lib/CodeGen:

AsmPrinter.cpp updated: 1.51 -> 1.52
MachineFunction.cpp updated: 1.85 -> 1.86
---
Log message:

Adjust to MachineConstantPool interface change: instead of keeping a 
value/alignment pair for each constant, keep a value/offset pair.


---
Diffs of the changes:  (+37 -3)

 AsmPrinter.cpp      |    8 +++++++-
 MachineFunction.cpp |   32 ++++++++++++++++++++++++++++++--
 2 files changed, 37 insertions(+), 3 deletions(-)


Index: llvm/lib/CodeGen/AsmPrinter.cpp
diff -u llvm/lib/CodeGen/AsmPrinter.cpp:1.51 llvm/lib/CodeGen/AsmPrinter.cpp:1.52
--- llvm/lib/CodeGen/AsmPrinter.cpp:1.51	Wed Feb  8 22:22:52 2006
+++ llvm/lib/CodeGen/AsmPrinter.cpp	Wed Feb  8 22:46:04 2006
@@ -111,11 +111,17 @@
   const TargetData &TD = TM.getTargetData();
   
   SwitchSection(ConstantPoolSection, 0);
+  EmitAlignment(MCP->getConstantPoolAlignment());
   for (unsigned i = 0, e = CP.size(); i != e; ++i) {
-    EmitAlignment(CP[i].Alignment);
     O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << '_' << i
       << ":\t\t\t\t\t" << CommentString << *CP[i].Val << '\n';
     EmitGlobalConstant(CP[i].Val);
+    if (i != e-1) {
+      unsigned EntSize = TM.getTargetData().getTypeSize(CP[i].Val->getType());
+      unsigned ValEnd = CP[i].Offset + EntSize;
+      // Emit inter-object padding for alignment.
+      EmitZeros(CP[i+1].Offset-ValEnd);
+    }
   }
 }
 


Index: llvm/lib/CodeGen/MachineFunction.cpp
diff -u llvm/lib/CodeGen/MachineFunction.cpp:1.85 llvm/lib/CodeGen/MachineFunction.cpp:1.86
--- llvm/lib/CodeGen/MachineFunction.cpp:1.85	Wed Feb  8 22:22:52 2006
+++ llvm/lib/CodeGen/MachineFunction.cpp	Wed Feb  8 22:46:04 2006
@@ -112,7 +112,7 @@
   SSARegMapping = new SSARegMap();
   MFInfo = 0;
   FrameInfo = new MachineFrameInfo();
-  ConstantPool = new MachineConstantPool();
+  ConstantPool = new MachineConstantPool(TM.getTargetData());
   BasicBlocks.Parent = this;
 }
 
@@ -345,10 +345,38 @@
 //  MachineConstantPool implementation
 //===----------------------------------------------------------------------===//
 
+/// getConstantPoolIndex - Create a new entry in the constant pool or return
+/// an existing one.  User must specify an alignment in bytes for the object.
+///
+unsigned MachineConstantPool::getConstantPoolIndex(Constant *C, 
+                                                   unsigned Alignment) {
+  assert(Alignment && "Alignment must be specified!");
+  if (Alignment > PoolAlignment) PoolAlignment = Alignment;
+  
+  // Check to see if we already have this constant.
+  //
+  // FIXME, this could be made much more efficient for large constant pools.
+  unsigned AlignMask = (1 << Alignment)-1;
+  for (unsigned i = 0, e = Constants.size(); i != e; ++i)
+    if (Constants[i].Val == C && (Constants[i].Offset & AlignMask) == 0)
+      return i;
+  
+  unsigned Offset = 0;
+  if (!Constants.empty()) {
+    Offset = Constants.back().Offset;
+    Offset += TD.getTypeSize(Constants.back().Val->getType());
+    Offset = (Offset+AlignMask)&~AlignMask;
+  }
+  
+  Constants.push_back(MachineConstantPoolEntry(C, Offset));
+  return Constants.size()-1;
+}
+
+
 void MachineConstantPool::print(std::ostream &OS) const {
   for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
     OS << "  <cp #" << i << "> is" << *(Value*)Constants[i].Val;
-    OS << " , align=" << Constants[i].Alignment;
+    OS << " , offset=" << Constants[i].Offset;
     OS << "\n";
   }
 }






More information about the llvm-commits mailing list