If compile unit's language is not set then don't crash while dump'ing compile unit.
[oota-llvm.git] / lib / CodeGen / MachineFunction.cpp
index 1ba4be8478c3a111b00a9cc2f4119b0ca6f1d7fc..cf7f39140b8663e25daf837a8973b3001d2b7384 100644 (file)
@@ -192,9 +192,10 @@ void MachineFunction::RenumberBlocks(MachineBasicBlock *MBB) {
 /// of `new MachineInstr'.
 ///
 MachineInstr *
-MachineFunction::CreateMachineInstr(const TargetInstrDesc &TID, bool NoImp) {
+MachineFunction::CreateMachineInstr(const TargetInstrDesc &TID,
+                                    DebugLoc DL, bool NoImp) {
   return new (InstructionRecycler.Allocate<MachineInstr>(Allocator))
-             MachineInstr(TID, NoImp);
+    MachineInstr(TID, DL, NoImp);
 }
 
 /// CloneMachineInstr - Create a new MachineInstr which is a copy of the
@@ -378,6 +379,31 @@ MachineFunction& MachineFunction::get(const Function *F)
   return *mc;
 }
 
+/// getOrCreateDebugLocID - Look up the DebugLocTuple index with the given
+/// source file, line, and column. If none currently exists, create a new
+/// DebugLocTuple, and insert it into the DebugIdMap.
+unsigned MachineFunction::getOrCreateDebugLocID(unsigned Src, unsigned Line,
+                                                unsigned Col) {
+  DebugLocTuple Tuple(Src, Line, Col);
+  DenseMap<DebugLocTuple, unsigned>::iterator II
+    = DebugLocInfo.DebugIdMap.find(Tuple);
+  if (II != DebugLocInfo.DebugIdMap.end())
+    return II->second;
+  // Add a new tuple.
+  unsigned Id = DebugLocInfo.DebugLocations.size();
+  DebugLocInfo.DebugLocations.push_back(Tuple);
+  DebugLocInfo.DebugIdMap[Tuple] = Id;
+  return Id;
+}
+
+/// getDebugLocTuple - Get the DebugLocTuple for a given DebugLoc object.
+DebugLocTuple MachineFunction::getDebugLocTuple(DebugLoc DL) const {
+  unsigned Idx = DL.getIndex();
+  assert(Idx < DebugLocInfo.DebugLocations.size() &&
+         "Invalid index into debug locations!");
+  return DebugLocInfo.DebugLocations[Idx];
+}
+
 //===----------------------------------------------------------------------===//
 //  MachineFrameInfo implementation
 //===----------------------------------------------------------------------===//
@@ -396,11 +422,12 @@ int MachineFrameInfo::CreateFixedObject(uint64_t Size, int64_t SPOffset,
 
 
 void MachineFrameInfo::print(const MachineFunction &MF, std::ostream &OS) const{
-  int ValOffset = MF.getTarget().getFrameInfo()->getOffsetOfLocalArea();
+  const TargetFrameInfo *FI = MF.getTarget().getFrameInfo();
+  int ValOffset = (FI ? FI->getOffsetOfLocalArea() : 0);
 
   for (unsigned i = 0, e = Objects.size(); i != e; ++i) {
     const StackObject &SO = Objects[i];
-    OS << "  <fi #" << (int)(i-NumFixedObjects) << ">: ";
+    OS << "  <fi#" << (int)(i-NumFixedObjects) << ">: ";
     if (SO.Size == ~0ULL) {
       OS << "dead\n";
       continue;
@@ -458,7 +485,7 @@ void MachineJumpTableInfo::print(std::ostream &OS) const {
   // FIXME: this is lame, maybe we could print out the MBB numbers or something
   // like {1, 2, 4, 5, 3, 0}
   for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) {
-    OS << "  <jt #" << i << "> has " << JumpTables[i].MBBs.size() 
+    OS << "  <jt#" << i << "> has " << JumpTables[i].MBBs.size() 
        << " entries\n";
   }
 }
@@ -502,7 +529,7 @@ unsigned MachineConstantPool::getConstantPoolIndex(Constant *C,
   unsigned Offset = 0;
   if (!Constants.empty()) {
     Offset = Constants.back().getOffset();
-    Offset += TD->getABITypeSize(Constants.back().getType());
+    Offset += TD->getTypePaddedSize(Constants.back().getType());
     Offset = (Offset+AlignMask)&~AlignMask;
   }
   
@@ -526,7 +553,7 @@ unsigned MachineConstantPool::getConstantPoolIndex(MachineConstantPoolValue *V,
   unsigned Offset = 0;
   if (!Constants.empty()) {
     Offset = Constants.back().getOffset();
-    Offset += TD->getABITypeSize(Constants.back().getType());
+    Offset += TD->getTypePaddedSize(Constants.back().getType());
     Offset = (Offset+AlignMask)&~AlignMask;
   }
   
@@ -536,7 +563,7 @@ unsigned MachineConstantPool::getConstantPoolIndex(MachineConstantPoolValue *V,
 
 void MachineConstantPool::print(raw_ostream &OS) const {
   for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
-    OS << "  <cp #" << i << "> is";
+    OS << "  <cp#" << i << "> is";
     if (Constants[i].isMachineConstantPoolEntry())
       Constants[i].Val.MachineCPVal->print(OS);
     else