DwarfDebug: Remove some more redundant explicit constructions.
[oota-llvm.git] / lib / CodeGen / StackMaps.cpp
index ffe46288b9bef29aa4a4c6b612ff015bfbce57f5..0eeec83117b98903f44135b908815d5ceac80e2a 100644 (file)
@@ -15,6 +15,7 @@
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCExpr.h"
+#include "llvm/MC/MCObjectFileInfo.h"
 #include "llvm/MC/MCSectionMachO.h"
 #include "llvm/MC/MCStreamer.h"
 #include "llvm/Support/Debug.h"
@@ -29,7 +30,8 @@ using namespace llvm;
 
 void StackMaps::recordStackMap(const MachineInstr &MI, uint32_t ID,
                                MachineInstr::const_mop_iterator MOI,
-                               MachineInstr::const_mop_iterator MOE) {
+                               MachineInstr::const_mop_iterator MOE,
+                               bool recordResult) {
 
   MCContext &OutContext = AP.OutStreamer.getContext();
   MCSymbol *MILabel = OutContext.CreateTempSymbol();
@@ -37,9 +39,19 @@ void StackMaps::recordStackMap(const MachineInstr &MI, uint32_t ID,
 
   LocationVec CallsiteLocs;
 
+  if (recordResult) {
+    std::pair<Location, MachineInstr::const_mop_iterator> ParseResult =
+      OpParser(MI.operands_begin(), llvm::next(MI.operands_begin()), AP.TM);
+
+    Location &Loc = ParseResult.first;
+    assert(Loc.LocType == Location::Register &&
+           "Stackmap return location must be a register.");
+    CallsiteLocs.push_back(Loc);
+  }
+
   while (MOI != MOE) {
     std::pair<Location, MachineInstr::const_mop_iterator> ParseResult =
-      OpParser(MOI, MOE);
+      OpParser(MOI, MOE, AP.TM);
 
     Location &Loc = ParseResult.first;
 
@@ -74,7 +86,7 @@ void StackMaps::recordStackMap(const MachineInstr &MI, uint32_t ID,
 ///   uint16 : NumLocations
 ///   Location[NumLocations] {
 ///     uint8  : Register | Direct | Indirect | Constant | ConstantIndex
-///     uint8  : Reserved (location flags)
+///     uint8  : Size in Bytes
 ///     uint16 : Dwarf RegNum
 ///     int32  : Offset
 ///   }
@@ -97,8 +109,7 @@ void StackMaps::serializeToStackMapSection() {
 
   // Create the section.
   const MCSection *StackMapSection =
-    OutContext.getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
-                               SectionKind::getMetadata());
+    OutContext.getObjectFileInfo()->getStackMapSection();
   AP.OutStreamer.SwitchSection(StackMapSection);
 
   // Emit a dummy symbol to force section inclusion.
@@ -107,6 +118,7 @@ void StackMaps::serializeToStackMapSection() {
 
   // Serialize data.
   const char *WSMP = "Stack Maps: ";
+  (void)WSMP;
   const MCRegisterInfo &MCRI = *OutContext.getRegisterInfo();
 
   DEBUG(dbgs() << "********** Stack Map Output **********\n");
@@ -188,12 +200,22 @@ void StackMaps::serializeToStackMapSection() {
       );
 
       unsigned RegNo = 0;
+      int Offset = Loc.Offset;
       if(Loc.Reg) {
         RegNo = MCRI.getDwarfRegNum(Loc.Reg, false);
         for (MCSuperRegIterator SR(Loc.Reg, TRI);
              SR.isValid() && (int)RegNo < 0; ++SR) {
           RegNo = TRI->getDwarfRegNum(*SR, false);
         }
+        // If this is a register location, put the subregister byte offset in
+        // the location offset.
+        if (Loc.LocType == Location::Register) {
+          assert(!Loc.Offset && "Register location should have zero offset");
+          unsigned LLVMRegNo = MCRI.getLLVMRegNum(RegNo, false);
+          unsigned SubRegIdx = MCRI.getSubRegIndex(LLVMRegNo, Loc.Reg);
+          if (SubRegIdx)
+            Offset = MCRI.getSubRegIdxOffset(SubRegIdx);
+        }
       }
       else {
         assert((Loc.LocType != Location::Register
@@ -201,9 +223,9 @@ void StackMaps::serializeToStackMapSection() {
                "Missing location register");
       }
       AP.OutStreamer.EmitIntValue(Loc.LocType, 1);
-      AP.OutStreamer.EmitIntValue(0, 1); // Reserved location flags.
+      AP.OutStreamer.EmitIntValue(Loc.Size, 1);
       AP.OutStreamer.EmitIntValue(RegNo, 2);
-      AP.OutStreamer.EmitIntValue(Loc.Offset, 4);
+      AP.OutStreamer.EmitIntValue(Offset, 4);
     }
   }