Adjust to MachineConstantPool interface change: instead of keeping a
authorChris Lattner <sabre@nondot.org>
Thu, 9 Feb 2006 04:46:04 +0000 (04:46 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 9 Feb 2006 04:46:04 +0000 (04:46 +0000)
value/alignment pair for each constant, keep a value/offset pair.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26078 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter.cpp
lib/CodeGen/MachineFunction.cpp
lib/ExecutionEngine/JIT/JITEmitter.cpp
lib/Target/Sparc/SparcISelDAGToDAG.cpp
lib/Target/SparcV9/SparcV9AsmPrinter.cpp

index bd12c775e899be24c44455aea4b035a211ebeb42..af5346cb53362e8f4031aa46af1d4ee4aedbda5a 100644 (file)
@@ -111,11 +111,17 @@ void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
   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 94d87159886af089c8fbb90f2ddde9b6d32d2af0..6fdd03847ef9055905a37ed18e63b036e1a9e7b8 100644 (file)
@@ -112,7 +112,7 @@ MachineFunction::MachineFunction(const Function *F,
   SSARegMapping = new SSARegMap();
   MFInfo = 0;
   FrameInfo = new MachineFrameInfo();
-  ConstantPool = new MachineConstantPool();
+  ConstantPool = new MachineConstantPool(TM.getTargetData());
   BasicBlocks.Parent = this;
 }
 
@@ -345,10 +345,38 @@ void MachineFrameInfo::dump(const MachineFunction &MF) const {
 //  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";
   }
 }
index 5309692ec0f36dc0e549bfc4d690e02a174e43d8..3f41222b742673edceb3e4852f6fa6ccee778c12 100644 (file)
@@ -569,14 +569,17 @@ void JITEmitter::emitConstantPool(MachineConstantPool *MCP) {
   const std::vector<MachineConstantPoolEntry> &Constants = MCP->getConstants();
   if (Constants.empty()) return;
 
-  for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
-    const Type *Ty = Constants[i].Val->getType();
-    unsigned Size      = (unsigned)TheJIT->getTargetData().getTypeSize(Ty);
-    unsigned Alignment = Constants[i].Alignment;
+  unsigned Size = Constants.back().Offset;
+  Size += TheJIT->getTargetData().getTypeSize(Constants.back().Val->getType());
+
+  void *Addr = MemMgr.allocateConstant(Size, 
+                                       1 << MCP->getConstantPoolAlignment());
 
-    void *Addr = MemMgr.allocateConstant(Size, Alignment);
-    TheJIT->InitializeMemory(Constants[i].Val, Addr);
-    ConstantPoolAddresses.push_back(Addr);
+  // FIXME: Can eliminate ConstantPoolAddresses!
+  for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
+    void *CAddr = (char*)Addr+Constants[i].Offset;
+    TheJIT->InitializeMemory(Constants[i].Val, CAddr);
+    ConstantPoolAddresses.push_back(CAddr);
   }
 }
 
index ecfbe917fb77a36dafe552a01b568b09ecfe69a6..2924e7e62b39b1f292cb27f9a78e72e86c12ff21 100644 (file)
@@ -968,7 +968,7 @@ void SparcDAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
 }
 
 bool SparcDAGToDAGISel::SelectADDRri(SDOperand Addr, SDOperand &Base,
-                                       SDOperand &Offset) {
+                                     SDOperand &Offset) {
   if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
     Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i32);
     Offset = CurDAG->getTargetConstant(0, MVT::i32);
index 69f68094d57baa01b66efda22080fc1ee64f9752..62a31c26640619b007ed8f0dfbc62e40a07d47de 100644 (file)
@@ -216,7 +216,8 @@ namespace {
 
       if (Alignment == 0)
         Alignment = ConstantToAlignment(CV, TM);
-      O << "\t.align\t" << Alignment << "\n";
+      if (Alignment != 1)
+        O << "\t.align\t" << Alignment << "\n";
 
       // Print .size and .type only if it is not a string.
       if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV))
@@ -727,9 +728,18 @@ void SparcV9AsmPrinter::emitFunction(const Function &F) {
   const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
 
   enterSection(ReadOnlyData);
+  O << "\t.align\t" << (1 << MCP->getConstantPoolAlignment()) << "\n";
   for (unsigned i = 0, e = CP.size(); i != e; ++i) {
     std::string cpiName = ".CPI_" + CurrentFnName + "_" + utostr(i);
-    printConstant(CP[i].Val, CP[i].Alignment, cpiName);
+    printConstant(CP[i].Val, 1, cpiName);
+    
+    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.
+      for (unsigned NumZeros = CP[i+1].Offset-ValEnd; NumZeros; --NumZeros)
+        O << "\t.byte 0\n";
+    }
   }
 
   enterSection(Text);