Introduce a new technique for merging BasicBlock with Instruction sentinel by superpo...
[oota-llvm.git] / lib / CodeGen / MachineFunction.cpp
index 0d442af7eda233dd2f1147ff3b1cca1baa0fbe8c..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,31 +379,29 @@ MachineFunction& MachineFunction::get(const Function *F)
   return *mc;
 }
 
-/// lookUpDebugLocId - Look up the DebugLocTuple index with the given
-/// filename, line, and column. It may add a new filename and / or
-/// a new DebugLocTuple.
-unsigned MachineFunction::lookUpDebugLocId(const char *Filename, unsigned Line,
-                                           unsigned Col) {
-  unsigned FileId;
-  StringMap<unsigned>::iterator I =
-    DebugLocInfo.DebugFilenamesMap.find(Filename);
-  if (I != DebugLocInfo.DebugFilenamesMap.end())
-    FileId = I->second;
-  else {
-    // Add a new filename.
-    FileId = DebugLocInfo.NumFilenames++;
-    DebugLocInfo.DebugFilenames.push_back(Filename);
-    DebugLocInfo.DebugFilenamesMap[Filename] = FileId;
-  }
-
-  struct DebugLocTuple Tuple(FileId, Line, Col);
-  DebugIdMapType::iterator II = DebugLocInfo.DebugIdMap.find(Tuple);
+/// 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] = DebugLocInfo.NumDebugLocations;
-  return DebugLocInfo.NumDebugLocations++;
+  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];
 }
 
 //===----------------------------------------------------------------------===//