]> granicus.if.org Git - llvm/commitdiff
[Stackmap] Added callsite counts to emitted function information.
authorSanjoy Das <sanjoy@playingwithpointers.com>
Wed, 14 Sep 2016 20:22:03 +0000 (20:22 +0000)
committerSanjoy Das <sanjoy@playingwithpointers.com>
Wed, 14 Sep 2016 20:22:03 +0000 (20:22 +0000)
Summary:
It was previously not possible for tools to use solely the stackmap
information emitted to reconstruct the return addresses of callsites in
the map, which is necessary to use the information to walk a stack. This
patch adds per-function callsite counts when emitting the stackmap
section in order to resolve the problem. Note that this slightly alters
the stackmap format, so external tools parsing these maps will need to
be updated.

**Problem Details:**
Records only store their offset from the beginning of the function they
belong to. While these records and the functions are output in program
order, it is not possible to determine where the end of one function's
records are without the callsite count when processing the records to
compute return addresses.

Patch by Kavon Farvardin!

Reviewers: atrick, ributzka, sanjoy

Subscribers: nemanjai

Differential Revision: https://reviews.llvm.org/D23487

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

23 files changed:
docs/StackMaps.rst
include/llvm/CodeGen/StackMaps.h
include/llvm/Object/StackMapParser.h
lib/CodeGen/StackMaps.cpp
test/CodeGen/AArch64/arm64-anyregcc.ll
test/CodeGen/AArch64/arm64-stackmap.ll
test/CodeGen/AArch64/stackmap-liveness.ll
test/CodeGen/PowerPC/ppc64-anyregcc.ll
test/CodeGen/PowerPC/ppc64-stackmap.ll
test/CodeGen/X86/anyregcc.ll
test/CodeGen/X86/patchpoint-invoke.ll
test/CodeGen/X86/stackmap-fast-isel.ll
test/CodeGen/X86/stackmap-large-constants.ll
test/CodeGen/X86/stackmap-liveness.ll
test/CodeGen/X86/stackmap.ll
test/CodeGen/X86/statepoint-allocas.ll
test/CodeGen/X86/statepoint-stackmap-format.ll
test/Object/Inputs/stackmap-test.macho-x86-64
test/Object/stackmap-dump.test
tools/llvm-readobj/COFFDumper.cpp
tools/llvm-readobj/ELFDumper.cpp
tools/llvm-readobj/MachODumper.cpp
tools/llvm-readobj/StackMapPrinter.h

index 5bdae38b699dfbb40c8a7f1d79d9761b4ea95192..a78fde16c2be983b326defd23987fc603a56481b 100644 (file)
@@ -319,7 +319,7 @@ format of this section follows:
 .. code-block:: none
 
   Header {
-    uint8  : Stack Map Version (current version is 1)
+    uint8  : Stack Map Version (current version is 2)
     uint8  : Reserved (expected to be 0)
     uint16 : Reserved (expected to be 0)
   }
@@ -329,6 +329,7 @@ format of this section follows:
   StkSizeRecord[NumFunctions] {
     uint64 : Function Address
     uint64 : Stack Size
+    uint64 : Record Count
   }
   Constants[NumConstants] {
     uint64 : LargeConstant
@@ -434,7 +435,7 @@ precisely determine the location of values at a specific position in
 the code. LLVM does not maintain any mapping between those values and
 any higher-level entity. The runtime must be able to interpret the
 stack map record given only the ID, offset, and the order of the
-locations, which LLVM preserves.
+locations, records, and functions, which LLVM preserves.
 
 Note that this is quite different from the goal of debug information,
 which is a best-effort attempt to track the location of named
@@ -508,4 +509,3 @@ Support for StackMap generation and the related intrinsics requires
 some code for each backend.  Today, only a subset of LLVM's backends 
 are supported.  The currently supported architectures are X86_64, 
 PowerPC, and Aarch64.
-
index 2e50689bb57bcde8d520c75e4725c5d31444842f..7b55b796863583f07f033e85f2bf24c9db50bb15 100644 (file)
@@ -219,7 +219,7 @@ public:
   void reset() {
     CSInfos.clear();
     ConstPool.clear();
-    FnStackSize.clear();
+    FnInfos.clear();
   }
 
   /// \brief Generate a stackmap record for a stackmap instruction.
@@ -243,7 +243,13 @@ private:
   typedef SmallVector<Location, 8> LocationVec;
   typedef SmallVector<LiveOutReg, 8> LiveOutVec;
   typedef MapVector<uint64_t, uint64_t> ConstantPool;
-  typedef MapVector<const MCSymbol *, uint64_t> FnStackSizeMap;
+
+  struct FunctionInfo {
+    uint64_t StackSize;
+    uint64_t RecordCount;
+    FunctionInfo() : StackSize(0), RecordCount(1) {}
+    explicit FunctionInfo(uint64_t StackSize) : StackSize(StackSize), RecordCount(1) {}
+  };
 
   struct CallsiteInfo {
     const MCExpr *CSOffsetExpr;
@@ -257,12 +263,13 @@ private:
           LiveOuts(std::move(LiveOuts)) {}
   };
 
+  typedef MapVector<const MCSymbol *, FunctionInfo> FnInfoMap;
   typedef std::vector<CallsiteInfo> CallsiteInfoList;
 
   AsmPrinter &AP;
   CallsiteInfoList CSInfos;
   ConstantPool ConstPool;
-  FnStackSizeMap FnStackSize;
+  FnInfoMap FnInfos;
 
   MachineInstr::const_mop_iterator
   parseOperand(MachineInstr::const_mop_iterator MOI,
index e58162de1501eeab7425b2a9b9a4ce18199b4f72..efea62bb3cb3c1ddf4156d513d147ad5c98a5e61 100644 (file)
@@ -17,7 +17,7 @@
 namespace llvm {
 
 template <support::endianness Endianness>
-class StackMapV1Parser {
+class StackMapV2Parser {
 public:
 
   template <typename AccessorT>
@@ -47,7 +47,7 @@ public:
 
   /// Accessor for function records.
   class FunctionAccessor {
-    friend class StackMapV1Parser;
+    friend class StackMapV2Parser;
   public:
 
     /// Get the function address.
@@ -56,14 +56,19 @@ public:
     }
 
     /// Get the function's stack size.
-    uint32_t getStackSize() const {
+    uint64_t getStackSize() const {
       return read<uint64_t>(P + sizeof(uint64_t));
     }
+    
+    /// Get the number of callsite records.
+    uint64_t getRecordCount() const {
+      return read<uint64_t>(P + (2 * sizeof(uint64_t)));
+    }
 
   private:
     FunctionAccessor(const uint8_t *P) : P(P) {}
 
-    const static int FunctionAccessorSize = 2 * sizeof(uint64_t);
+    const static int FunctionAccessorSize = 3 * sizeof(uint64_t);
 
     FunctionAccessor next() const {
       return FunctionAccessor(P + FunctionAccessorSize);
@@ -74,7 +79,7 @@ public:
 
   /// Accessor for constants.
   class ConstantAccessor {
-    friend class StackMapV1Parser;
+    friend class StackMapV2Parser;
   public:
 
     /// Return the value of this constant.
@@ -103,7 +108,7 @@ public:
 
   /// Accessor for location records.
   class LocationAccessor {
-    friend class StackMapV1Parser;
+    friend class StackMapV2Parser;
     friend class RecordAccessor;
   public:
 
@@ -156,7 +161,7 @@ public:
 
   /// Accessor for stackmap live-out fields.
   class LiveOutAccessor {
-    friend class StackMapV1Parser;
+    friend class StackMapV2Parser;
     friend class RecordAccessor;
   public:
 
@@ -188,7 +193,7 @@ public:
 
   /// Accessor for stackmap records.
   class RecordAccessor {
-    friend class StackMapV1Parser;
+    friend class StackMapV2Parser;
   public:
 
     typedef AccessorIterator<LocationAccessor> location_iterator;
@@ -292,14 +297,14 @@ public:
     const uint8_t *P;
   };
 
-  /// Construct a parser for a version-1 stackmap. StackMap data will be read
+  /// Construct a parser for a version-2 stackmap. StackMap data will be read
   /// from the given array.
-  StackMapV1Parser(ArrayRef<uint8_t> StackMapSection)
+  StackMapV2Parser(ArrayRef<uint8_t> StackMapSection)
       : StackMapSection(StackMapSection) {
     ConstantsListOffset = FunctionListOffset + getNumFunctions() * FunctionSize;
 
-    assert(StackMapSection[0] == 1 &&
-           "StackMapV1Parser can only parse version 1 stackmaps");
+    assert(StackMapSection[0] == 2 &&
+           "StackMapV2Parser can only parse version 2 stackmaps");
 
     unsigned CurrentRecordOffset =
       ConstantsListOffset + getNumConstants() * ConstantSize;
@@ -315,8 +320,8 @@ public:
   typedef AccessorIterator<ConstantAccessor> constant_iterator;
   typedef AccessorIterator<RecordAccessor> record_iterator;
 
-  /// Get the version number of this stackmap. (Always returns 1).
-  unsigned getVersion() const { return 1; }
+  /// Get the version number of this stackmap. (Always returns 2).
+  unsigned getVersion() const { return 2; }
 
   /// Get the number of functions in the stack map.
   uint32_t getNumFunctions() const {
@@ -420,7 +425,7 @@ private:
   static const unsigned NumRecordsOffset = NumConstantsOffset + sizeof(uint32_t);
   static const unsigned FunctionListOffset = NumRecordsOffset + sizeof(uint32_t);
 
-  static const unsigned FunctionSize = 2 * sizeof(uint64_t);
+  static const unsigned FunctionSize = 3 * sizeof(uint64_t);
   static const unsigned ConstantSize = sizeof(uint64_t);
 
   std::size_t getFunctionOffset(unsigned FunctionIndex) const {
index 9e6fc3e094b1109a066663a41c4415d239c31490..9b7dd400fc92e540929453ab8cfc3527d644ecd1 100644 (file)
@@ -30,8 +30,8 @@ using namespace llvm;
 #define DEBUG_TYPE "stackmaps"
 
 static cl::opt<int> StackMapVersion(
-    "stackmap-version", cl::init(1),
-    cl::desc("Specify the stackmap encoding version (default = 1)"));
+    "stackmap-version", cl::init(2),
+    cl::desc("Specify the stackmap encoding version (default = 2)"));
 
 const char *StackMaps::WSMP = "Stack Maps: ";
 
@@ -74,7 +74,7 @@ unsigned PatchPointOpers::getNextScratchIdx(unsigned StartIdx) const {
 }
 
 StackMaps::StackMaps(AsmPrinter &AP) : AP(AP) {
-  if (StackMapVersion != 1)
+  if (StackMapVersion != 2)
     llvm_unreachable("Unsupported stackmap version!");
 }
 
@@ -335,13 +335,18 @@ void StackMaps::recordStackMapOpers(const MachineInstr &MI, uint64_t ID,
   CSInfos.emplace_back(CSOffsetExpr, ID, std::move(Locations),
                        std::move(LiveOuts));
 
-  // Record the stack size of the current function.
+  // Record the stack size of the current function and update callsite count.
   const MachineFrameInfo &MFI = AP.MF->getFrameInfo();
   const TargetRegisterInfo *RegInfo = AP.MF->getSubtarget().getRegisterInfo();
   bool HasDynamicFrameSize =
       MFI.hasVarSizedObjects() || RegInfo->needsStackRealignment(*(AP.MF));
-  FnStackSize[AP.CurrentFnSym] =
-      HasDynamicFrameSize ? UINT64_MAX : MFI.getStackSize();
+  uint64_t FrameSize = HasDynamicFrameSize ? UINT64_MAX : MFI.getStackSize();
+
+  auto CurrentIt = FnInfos.find(AP.CurrentFnSym);
+  if (CurrentIt != FnInfos.end())
+    CurrentIt->second.RecordCount++;
+  else
+    FnInfos.insert(std::make_pair(AP.CurrentFnSym, FunctionInfo(FrameSize)));
 }
 
 void StackMaps::recordStackMap(const MachineInstr &MI) {
@@ -387,7 +392,7 @@ void StackMaps::recordStatepoint(const MachineInstr &MI) {
 /// Emit the stackmap header.
 ///
 /// Header {
-///   uint8  : Stack Map Version (currently 1)
+///   uint8  : Stack Map Version (currently 2)
 ///   uint8  : Reserved (expected to be 0)
 ///   uint16 : Reserved (expected to be 0)
 /// }
@@ -401,8 +406,8 @@ void StackMaps::emitStackmapHeader(MCStreamer &OS) {
   OS.EmitIntValue(0, 2);               // Reserved.
 
   // Num functions.
-  DEBUG(dbgs() << WSMP << "#functions = " << FnStackSize.size() << '\n');
-  OS.EmitIntValue(FnStackSize.size(), 4);
+  DEBUG(dbgs() << WSMP << "#functions = " << FnInfos.size() << '\n');
+  OS.EmitIntValue(FnInfos.size(), 4);
   // Num constants.
   DEBUG(dbgs() << WSMP << "#constants = " << ConstPool.size() << '\n');
   OS.EmitIntValue(ConstPool.size(), 4);
@@ -416,15 +421,18 @@ void StackMaps::emitStackmapHeader(MCStreamer &OS) {
 /// StkSizeRecord[NumFunctions] {
 ///   uint64 : Function Address
 ///   uint64 : Stack Size
+///   uint64 : Record Count
 /// }
 void StackMaps::emitFunctionFrameRecords(MCStreamer &OS) {
   // Function Frame records.
   DEBUG(dbgs() << WSMP << "functions:\n");
-  for (auto const &FR : FnStackSize) {
+  for (auto const &FR : FnInfos) {
     DEBUG(dbgs() << WSMP << "function addr: " << FR.first
-                 << " frame size: " << FR.second);
+                 << " frame size: " << FR.second.StackSize
+                 << " callsite count: " << FR.second.RecordCount << '\n');
     OS.EmitSymbolValue(FR.first, 8);
-    OS.EmitIntValue(FR.second, 8);
+    OS.EmitIntValue(FR.second.StackSize, 8);
+    OS.EmitIntValue(FR.second.RecordCount, 8);
   }
 }
 
@@ -525,7 +533,7 @@ void StackMaps::serializeToStackMapSection() {
   // Bail out if there's no stack map data.
   assert((!CSInfos.empty() || ConstPool.empty()) &&
          "Expected empty constant pool too!");
-  assert((!CSInfos.empty() || FnStackSize.empty()) &&
+  assert((!CSInfos.empty() || FnInfos.empty()) &&
          "Expected empty function record too!");
   if (CSInfos.empty())
     return;
index 2a2f45196046544e0d0837ce4ee585c59413ee9f..1af3103832432eff169c3ceb12a1977cf4c12e18 100644 (file)
@@ -4,7 +4,7 @@
 ; CHECK-LABEL: .section        __LLVM_STACKMAPS,__llvm_stackmaps
 ; CHECK-NEXT:  __LLVM_StackMaps:
 ; Header
-; CHECK-NEXT:   .byte 1
+; CHECK-NEXT:   .byte 2
 ; CHECK-NEXT:   .byte 0
 ; CHECK-NEXT:   .short 0
 ; Num Functions
 ; Functions and stack size
 ; CHECK-NEXT:   .quad _test
 ; CHECK-NEXT:   .quad 16
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _property_access1
 ; CHECK-NEXT:   .quad 16
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _property_access2
 ; CHECK-NEXT:   .quad 32
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _property_access3
 ; CHECK-NEXT:   .quad 32
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _anyreg_test1
 ; CHECK-NEXT:   .quad 16
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _anyreg_test2
 ; CHECK-NEXT:   .quad 16
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _patchpoint_spilldef
 ; CHECK-NEXT:   .quad 112
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _patchpoint_spillargs
 ; CHECK-NEXT:   .quad 128
+; CHECK-NEXT:   .quad 1
 
 
 ; test
index 3eb1d275300124bdc5e639e220edefac854ca324..0b2e9776263dc0a0ae407df6d737bf7b5de558e3 100644 (file)
@@ -10,7 +10,7 @@ target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
 ; CHECK-LABEL:  .section  __LLVM_STACKMAPS,__llvm_stackmaps
 ; CHECK-NEXT:  __LLVM_StackMaps:
 ; Header
-; CHECK-NEXT:   .byte 1
+; CHECK-NEXT:   .byte 2
 ; CHECK-NEXT:   .byte 0
 ; CHECK-NEXT:   .short 0
 ; Num Functions
@@ -23,26 +23,37 @@ target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
 ; Functions and stack size
 ; CHECK-NEXT:   .quad _constantargs
 ; CHECK-NEXT:   .quad 16
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _osrinline
 ; CHECK-NEXT:   .quad 32
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _osrcold
 ; CHECK-NEXT:   .quad 16
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _propertyRead
 ; CHECK-NEXT:   .quad 16
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _propertyWrite
 ; CHECK-NEXT:   .quad 16
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _jsVoidCall
 ; CHECK-NEXT:   .quad 16
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _jsIntCall
 ; CHECK-NEXT:   .quad 16
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _spilledValue
 ; CHECK-NEXT:   .quad 160
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _spilledStackMapValue
 ; CHECK-NEXT:   .quad 128
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _liveConstant
 ; CHECK-NEXT:   .quad 16
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _clobberLR
 ; CHECK-NEXT:   .quad 112
+; CHECK-NEXT:   .quad 1
 
 ; Num LargeConstants
 ; CHECK-NEXT:   .quad   4294967295
index 224a9c41852658e64247d3386781843392886456..4b04276ac226ba3608f29a35512a6a45f940c307 100644 (file)
@@ -5,7 +5,7 @@ target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
 ; CHECK-LABEL:  .section  __LLVM_STACKMAPS,__llvm_stackmaps
 ; CHECK-NEXT:   __LLVM_StackMaps:
 ; Header
-; CHECK-NEXT:   .byte 1
+; CHECK-NEXT:   .byte 2
 ; CHECK-NEXT:   .byte 0
 ; CHECK-NEXT:   .short 0
 ; Num Functions
@@ -44,4 +44,3 @@ define i64 @stackmap_liveness(i1 %c) {
 }
 
 declare void @llvm.experimental.patchpoint.void(i64, i32, i8*, i32, ...)
-
index ff0768ff47edb0ecfda2fc6a5ccc85c27ffd933f..4af118b567b22c13b8744c7339317cb447e0d509 100644 (file)
@@ -31,7 +31,7 @@ target triple = "powerpc64-unknown-linux-gnu"
 ; CHECK-LABEL: .section        .llvm_stackmaps
 ; CHECK-NEXT:  __LLVM_StackMaps:
 ; Header
-; CHECK-NEXT:   .byte 1
+; CHECK-NEXT:   .byte 2
 ; CHECK-NEXT:   .byte 0
 ; CHECK-NEXT:   .short 0
 ; Num Functions
@@ -44,20 +44,28 @@ target triple = "powerpc64-unknown-linux-gnu"
 ; Functions and stack size
 ; CHECK-NEXT:   .quad test
 ; CHECK-NEXT:   .quad 128
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad property_access1
 ; CHECK-NEXT:   .quad 128
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad property_access2
 ; CHECK-NEXT:   .quad 128
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad property_access3
 ; CHECK-NEXT:   .quad 128
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad anyreg_test1
 ; CHECK-NEXT:   .quad 144
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad anyreg_test2
 ; CHECK-NEXT:   .quad 144
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad patchpoint_spilldef
 ; CHECK-NEXT:   .quad 256
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad patchpoint_spillargs
 ; CHECK-NEXT:   .quad 288
+; CHECK-NEXT:   .quad 1
 
 
 ; test
index a77339f8e4759235b12095d9b2c2bc1efba0c5a0..854cee22c3420077487c9eb7e2f47289eea9191d 100644 (file)
@@ -44,7 +44,7 @@ target triple = "powerpc64-unknown-linux-gnu"
 ; CHECK-LABEL:  .section  .llvm_stackmaps
 ; CHECK-NEXT:  __LLVM_StackMaps:
 ; Header
-; CHECK-NEXT:   .byte 1
+; CHECK-NEXT:   .byte 2
 ; CHECK-NEXT:   .byte 0
 ; CHECK-NEXT:   .short 0
 ; Num Functions
@@ -57,26 +57,37 @@ target triple = "powerpc64-unknown-linux-gnu"
 ; Functions and stack size
 ; CHECK-NEXT:   .quad constantargs
 ; CHECK-NEXT:   .quad 128
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad osrinline
 ; CHECK-NEXT:   .quad 144
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad osrcold
 ; CHECK-NEXT:   .quad 128
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad propertyRead
 ; CHECK-NEXT:   .quad 128
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad propertyWrite
 ; CHECK-NEXT:   .quad 128
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad jsVoidCall
 ; CHECK-NEXT:   .quad 128
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad jsIntCall
 ; CHECK-NEXT:   .quad 128
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad spilledValue
 ; CHECK-NEXT:   .quad 304
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad spilledStackMapValue
 ; CHECK-NEXT:   .quad 224
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad liveConstant
 ; CHECK-NEXT:   .quad 64
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad clobberLR
 ; CHECK-NEXT:   .quad 208
+; CHECK-NEXT:   .quad 1
 
 ; Num LargeConstants
 ; CHECK-NEXT:   .quad   4294967295
index 129aadfae88d29c61cb29386e9919f0fd53a1cce..018a92a52f79063163189d878351562202bb78bc 100644 (file)
@@ -7,7 +7,7 @@
 ; CHECK-LABEL:  .section __LLVM_STACKMAPS,__llvm_stackmaps
 ; CHECK-NEXT:   __LLVM_StackMaps:
 ; Header
-; CHECK-NEXT:   .byte 1
+; CHECK-NEXT:   .byte 2
 ; CHECK-NEXT:   .byte 0
 ; CHECK-NEXT:   .short 0
 ; Num Functions
 ; Functions and stack size
 ; CHECK-NEXT:   .quad _test
 ; CHECK-NEXT:   .quad 8
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _property_access1
 ; CHECK-NEXT:   .quad 8
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _property_access2
 ; CHECK-NEXT:   .quad 24
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _property_access3
 ; CHECK-NEXT:   .quad 24
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _anyreg_test1
 ; CHECK-NEXT:   .quad 56
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _anyreg_test2
 ; CHECK-NEXT:   .quad 56
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _patchpoint_spilldef
 ; CHECK-NEXT:   .quad 56
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _patchpoint_spillargs
 ; CHECK-NEXT:   .quad 88
+; CHECK-NEXT:   .quad 1
 
 ; No constants
 
index b7f198d960a61abcd13f4f2296920b7dc76c955e..c6dff3b78f16de0c9576e2b6dbdda5d682d8cef7 100644 (file)
@@ -45,7 +45,7 @@ threw:
 ; Verify that the stackmap section got emitted:
 ; CHECK-LABEL: __LLVM_StackMaps:
 ; Header
-; CHECK-NEXT:   .byte 1
+; CHECK-NEXT:   .byte 2
 ; CHECK-NEXT:   .byte 0
 ; CHECK-NEXT:   .short 0
 ; Num Functions
index 1392e5bd87c149fd7de4e0298ff683da4b602e73..7afe966b77aa3efc4cadeb6f15e73da4dd68c7d9 100644 (file)
@@ -4,7 +4,7 @@
 ; CHECK-LABEL:  .section  __LLVM_STACKMAPS,__llvm_stackmaps
 ; CHECK-NEXT:  __LLVM_StackMaps:
 ; Header
-; CHECK-NEXT:   .byte 1
+; CHECK-NEXT:   .byte 2
 ; CHECK-NEXT:   .byte 0
 ; CHECK-NEXT:   .short 0
 ; Num Functions
 ; Functions and stack size
 ; CHECK-NEXT:   .quad _constantargs
 ; CHECK-NEXT:   .quad 8
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _liveConstant
 ; CHECK-NEXT:   .quad 8
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _directFrameIdx
 ; CHECK-NEXT:   .quad 40
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _longid
 ; CHECK-NEXT:   .quad 8
+; CHECK-NEXT:   .quad 4
 
 ; Large Constants
 ; CHECK-NEXT:   .quad   2147483648
index 0143a4e0fbc8364c1729030f83849c036e7b8c3c..99a2c11828e08486392e77020d7b4609a2bddc9c 100644 (file)
@@ -3,7 +3,7 @@
 ; CHECK-LABEL: .section        __LLVM_STACKMAPS,__llvm_stackmaps
 ; CHECK-NEXT: __LLVM_StackMaps:
 ; version
-; CHECK-NEXT:  .byte   1
+; CHECK-NEXT:  .byte   2
 ; reserved
 ; CHECK-NEXT:  .byte   0
 ; reserved
 ; function address & stack size
 ; CHECK-NEXT:  .quad   _foo
 ; CHECK-NEXT:  .quad   8
+; CHECK-NEXT:   .quad  1
 ; function address & stack size
 ; CHECK-NEXT:  .quad   _bar
 ; CHECK-NEXT:  .quad   8
+; CHECK-NEXT:   .quad  1
 
 ; Constants Array:
 ; CHECK-NEXT:  .quad   9223372036854775807
index d2dd263a6174c484b9334fa84685c283b5f0cabd..a5809ace795b464f5eb7c3ff8f299c9c1bf3c98f 100644 (file)
@@ -6,7 +6,7 @@
 ; CHECK-LABEL:  .section  __LLVM_STACKMAPS,__llvm_stackmaps
 ; CHECK-NEXT:   __LLVM_StackMaps:
 ; Header
-; CHECK-NEXT:   .byte 1
+; CHECK-NEXT:   .byte 2
 ; CHECK-NEXT:   .byte 0
 ; CHECK-NEXT:   .short 0
 ; Num Functions
 ; Functions and stack size
 ; CHECK-NEXT:   .quad _stackmap_liveness
 ; CHECK-NEXT:   .quad 8
+; CHECK-NEXT:   .quad 3
 ; CHECK-NEXT:   .quad _mixed_liveness
 ; CHECK-NEXT:   .quad 8
+; CHECK-NEXT:   .quad 2
 
 define void @stackmap_liveness() {
 entry:
index 0805e814704406c52d66dc14d51c3ce6c41ac40b..fe3846254be427b6e40a30b43ada59abc5ce33e8 100644 (file)
@@ -5,7 +5,7 @@
 ; CHECK-LABEL:  .section  __LLVM_STACKMAPS,__llvm_stackmaps
 ; CHECK-NEXT:  __LLVM_StackMaps:
 ; Header
-; CHECK-NEXT:   .byte 1
+; CHECK-NEXT:   .byte 2
 ; CHECK-NEXT:   .byte 0
 ; CHECK-NEXT:   .short 0
 ; Num Functions
 ; Functions and stack size
 ; CHECK-NEXT:   .quad _constantargs
 ; CHECK-NEXT:   .quad 8
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _osrinline
 ; CHECK-NEXT:   .quad 24
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _osrcold
 ; CHECK-NEXT:   .quad 8
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _propertyRead
 ; CHECK-NEXT:   .quad 8
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _propertyWrite
 ; CHECK-NEXT:   .quad 8
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _jsVoidCall
 ; CHECK-NEXT:   .quad 8
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _jsIntCall
 ; CHECK-NEXT:   .quad 8
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _spilledValue
 ; CHECK-NEXT:   .quad 56
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _spilledStackMapValue
 ; CHECK-NEXT:   .quad 56
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _spillSubReg
 ; CHECK-NEXT:   .quad 56
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _subRegOffset
 ; CHECK-NEXT:   .quad 56
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _liveConstant
 ; CHECK-NEXT:   .quad 8
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _directFrameIdx
 ; CHECK-NEXT:   .quad 56
+; CHECK-NEXT:   .quad 2
 ; CHECK-NEXT:   .quad _longid
 ; CHECK-NEXT:   .quad 8
+; CHECK-NEXT:   .quad 4
 ; CHECK-NEXT:   .quad _clobberScratch
 ; CHECK-NEXT:   .quad 56
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad _needsStackRealignment
 ; CHECK-NEXT:   .quad -1
+; CHECK-NEXT:   .quad 1
 
 ; Large Constants
 ; CHECK-NEXT:   .quad   2147483648
index 040ab614d0a8537ad6e7eacb6367aaffa09c26dc..e33af61ebc62d19cfc883cbaebeccd31bf5d8207 100644 (file)
@@ -48,7 +48,7 @@ declare token @llvm.experimental.gc.statepoint.p0f_i1f(i64, i32, i1 ()*, i32, i3
 ; CHECK-LABEL: .section .llvm_stackmaps
 ; CHECK-NEXT:  __LLVM_StackMaps:
 ; Header
-; CHECK-NEXT:   .byte 1
+; CHECK-NEXT:   .byte 2
 ; CHECK-NEXT:   .byte 0
 ; CHECK-NEXT:   .short 0
 ; Num Functions
@@ -61,8 +61,10 @@ declare token @llvm.experimental.gc.statepoint.p0f_i1f(i64, i32, i1 ()*, i32, i3
 ; Functions and stack size
 ; CHECK-NEXT:   .quad test
 ; CHECK-NEXT:   .quad 8
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad test2
 ; CHECK-NEXT:   .quad 8
+; CHECK-NEXT:   .quad 1
 
 ; Large Constants
 ; Statepoint ID only
@@ -127,4 +129,3 @@ declare token @llvm.experimental.gc.statepoint.p0f_i1f(i64, i32, i1 ()*, i32, i3
 ; CHECK: .short        0
 ; CHECK: .short        0
 ; CHECK: .p2align      3
-
index 2b1357a1179ab940cc59ec87f14e03c028644a71..ea05993c4785622164d94af64105beecc1e60d62 100644 (file)
@@ -79,7 +79,7 @@ declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token, i32, i32)
 ; CHECK-LABEL: .section .llvm_stackmaps
 ; CHECK-NEXT:  __LLVM_StackMaps:
 ; Header
-; CHECK-NEXT:   .byte 1
+; CHECK-NEXT:   .byte 2
 ; CHECK-NEXT:   .byte 0
 ; CHECK-NEXT:   .short 0
 ; Num Functions
@@ -92,10 +92,13 @@ declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token, i32, i32)
 ; Functions and stack size
 ; CHECK-NEXT:   .quad test
 ; CHECK-NEXT:   .quad 40
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad test_derived_arg
 ; CHECK-NEXT:   .quad 40
+; CHECK-NEXT:   .quad 1
 ; CHECK-NEXT:   .quad test_id
 ; CHECK-NEXT:   .quad 8
+; CHECK-NEXT:   .quad 1
 
 ;
 ; test
@@ -276,4 +279,3 @@ declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token, i32, i32)
 ; CHECK: .short        0
 ; CHECK: .short        0
 ; CHECK: .p2align      3
-
index 588c5aa6685b93fe87361d9c40282d08e57b1ad5..438f5e77a4401b5f13739c6c9568a33a99352091 100644 (file)
Binary files a/test/Object/Inputs/stackmap-test.macho-x86-64 and b/test/Object/Inputs/stackmap-test.macho-x86-64 differ
index 71710fb6194db4a30ecf644e079ce869b09c7e0f..5d7d8ccbb677e90499404c009e55b4f047307992 100644 (file)
 RUN: llvm-readobj -stackmap %p/Inputs/stackmap-test.macho-x86-64 | FileCheck %s
 
-CHECK:      LLVM StackMap Version: 1
-CHECK-NEXT: Num Functions: 1
-CHECK-NEXT:   Function address: 0, stack size: 16
-CHECK-NEXT: Num Constants: 1
-CHECK-NEXT:   #1: 10000000000
-CHECK-NEXT: Num Records: 1
-CHECK-NEXT:   Record ID: 2, instruction offset: 1
-CHECK-NEXT:     5 locations:
+; Note: the macho object file in this test was generated in the following way:
+; llc -mtriple=x86_64-apple-darwin %p/test/CodeGen/X86/stackmap.ll -o stackmap.s
+; clang -c stackmap.s -o %p/test/Object/Inputs/stackmap-test.macho-x86-64
+
+CHECK: LLVM StackMap Version: 2
+CHECK-NEXT: Num Functions: 16
+CHECK-NEXT:   Function address: 0, stack size: 8, callsite record count: 1
+CHECK-NEXT:   Function address: 0, stack size: 24, callsite record count: 1
+CHECK-NEXT:   Function address: 0, stack size: 8, callsite record count: 1
+CHECK-NEXT:   Function address: 0, stack size: 8, callsite record count: 1
+CHECK-NEXT:   Function address: 0, stack size: 8, callsite record count: 1
+CHECK-NEXT:   Function address: 0, stack size: 8, callsite record count: 1
+CHECK-NEXT:   Function address: 0, stack size: 8, callsite record count: 1
+CHECK-NEXT:   Function address: 0, stack size: 56, callsite record count: 1
+CHECK-NEXT:   Function address: 0, stack size: 56, callsite record count: 1
+CHECK-NEXT:   Function address: 0, stack size: 56, callsite record count: 1
+CHECK-NEXT:   Function address: 0, stack size: 56, callsite record count: 1
+CHECK-NEXT:   Function address: 0, stack size: 8, callsite record count: 1
+CHECK-NEXT:   Function address: 0, stack size: 56, callsite record count: 2
+CHECK-NEXT:   Function address: 0, stack size: 8, callsite record count: 4
+CHECK-NEXT:   Function address: 0, stack size: 56, callsite record count: 1
+CHECK-NEXT:   Function address: 0, stack size: 18446744073709551615, callsite record count: 1
+CHECK-NEXT: Num Constants: 3
+CHECK-NEXT:   #1: 2147483648
+CHECK-NEXT:   #2: 4294967295
+CHECK-NEXT:   #3: 4294967296
+CHECK-NEXT: Num Records: 20
+CHECK-NEXT:   Record ID: 1, instruction offset: 4
+CHECK-NEXT:     12 locations:
+CHECK-NEXT:       #1: Constant 4294967295
+CHECK-NEXT:       #2: Constant 4294967295
+CHECK-NEXT:       #3: Constant 65536
+CHECK-NEXT:       #4: Constant 2000000000
+CHECK-NEXT:       #5: Constant 2147483647
+CHECK-NEXT:       #6: Constant 4294967295
+CHECK-NEXT:       #7: Constant 4294967295
+CHECK-NEXT:       #8: Constant 0
+CHECK-NEXT:       #9: ConstantIndex #0 (2147483648)
+CHECK-NEXT:       #10: ConstantIndex #1 (4294967295)
+CHECK-NEXT:       #11: ConstantIndex #2 (4294967296)
+CHECK-NEXT:       #12: Constant 4294967295
+CHECK-NEXT:     1 live-outs: [ R#7 (8-bytes) ]
+
+CHECK:        Record ID: 3, instruction offset: 22
+CHECK-NEXT:     2 locations:
+CHECK-NEXT:       #1: Register R#3
+CHECK-NEXT:       #2: Register R#14
+CHECK-NEXT:     0 live-outs: [ ]
+
+CHECK:        Record ID: 4, instruction offset: 10
+CHECK-NEXT:     2 locations:
 CHECK-NEXT:       #1: Register R#5
-CHECK-NEXT:       #2: Constant 10
-CHECK-NEXT:       #3: ConstantIndex #0 (10000000000)
-CHECK-NEXT:       #4: Direct R#4 + -8
-CHECK-NEXT:       #5: Indirect [R#6 + -16]
+CHECK-NEXT:       #2: Register R#4
+CHECK-NEXT:     0 live-outs: [ ]
+
+CHECK:        Record ID: 5, instruction offset: 4
+CHECK-NEXT:     2 locations:
+CHECK-NEXT:       #1: Register R#0
+CHECK-NEXT:       #2: Register R#5
+CHECK-NEXT:     2 live-outs: [ R#0 (8-bytes) R#7 (8-bytes) ]
+
+CHECK:        Record ID: 6, instruction offset: 4
+CHECK-NEXT:     2 locations:
+CHECK-NEXT:       #1: Register R#4
+CHECK-NEXT:       #2: Register R#2
 CHECK-NEXT:     1 live-outs: [ R#7 (8-bytes) ]
+
+CHECK:        Record ID: 7, instruction offset: 10
+CHECK-NEXT:     2 locations:
+CHECK-NEXT:       #1: Register R#2
+CHECK-NEXT:       #2: Register R#8
+CHECK-NEXT:     1 live-outs: [ R#7 (8-bytes) ]
+
+CHECK:        Record ID: 8, instruction offset: 10
+CHECK-NEXT:     2 locations:
+CHECK-NEXT:       #1: Register R#2
+CHECK-NEXT:       #2: Register R#8
+CHECK-NEXT:     2 live-outs: [ R#0 (8-bytes) R#7 (8-bytes) ]
+
+CHECK:        Record ID: 11, instruction offset: 42
+CHECK-NEXT:     17 locations:
+CHECK-NEXT:       #1: Register R#9
+CHECK-NEXT:       #2: Register R#14
+CHECK-NEXT:       #3: Register R#10
+CHECK-NEXT:       #4: Register R#3
+CHECK-NEXT:       #5: Register R#0
+CHECK-NEXT:       #6: Register R#13
+CHECK-NEXT:       #7: Register R#12
+CHECK-NEXT:       #8: Register R#15
+CHECK-NEXT:       #9: Indirect [R#6 + 72]
+CHECK-NEXT:       #10: Indirect [R#6 + 80]
+CHECK-NEXT:       #11: Indirect [R#6 + 88]
+CHECK-NEXT:       #12: Indirect [R#6 + 96]
+CHECK-NEXT:       #13: Indirect [R#6 + 104]
+CHECK-NEXT:       #14: Indirect [R#6 + 112]
+CHECK-NEXT:       #15: Indirect [R#6 + 120]
+CHECK-NEXT:       #16: Indirect [R#6 + 128]
+CHECK-NEXT:       #17: Indirect [R#6 + 136]
+CHECK-NEXT:     1 live-outs: [ R#7 (8-bytes) ]
+
+CHECK:        Record ID: 12, instruction offset: 62
+CHECK-NEXT:     17 locations:
+CHECK-NEXT:       #1: Register R#0
+CHECK-NEXT:       #2: Register R#14
+CHECK-NEXT:       #3: Register R#10
+CHECK-NEXT:       #4: Register R#9
+CHECK-NEXT:       #5: Register R#8
+CHECK-NEXT:       #6: Register R#4
+CHECK-NEXT:       #7: Register R#1
+CHECK-NEXT:       #8: Register R#2
+CHECK-NEXT:       #9: Register R#5
+CHECK-NEXT:       #10: Register R#3
+CHECK-NEXT:       #11: Register R#13
+CHECK-NEXT:       #12: Register R#12
+CHECK-NEXT:       #13: Register R#15
+CHECK-NEXT:       #14: Indirect [R#6 + 112]
+CHECK-NEXT:       #15: Indirect [R#6 + 120]
+CHECK-NEXT:       #16: Indirect [R#6 + 128]
+CHECK-NEXT:       #17: Indirect [R#6 + 136]
+CHECK-NEXT:     0 live-outs: [ ]
+
+CHECK:        Record ID: 13, instruction offset: 50
+CHECK-NEXT:     1 locations:
+CHECK-NEXT:       #1: Indirect [R#6 + -48]
+CHECK-NEXT:     0 live-outs: [ ]
+
+CHECK:        Record ID: 14, instruction offset: 24
+CHECK-NEXT:     2 locations:
+CHECK-NEXT:       #1: Register R#0
+CHECK-NEXT:       #2: Register R#3
+CHECK-NEXT:     0 live-outs: [ ]
+
+CHECK:        Record ID: 15, instruction offset: 4
+CHECK-NEXT:     1 locations:
+CHECK-NEXT:       #1: Constant 33
+CHECK-NEXT:     0 live-outs: [ ]
+
+CHECK:        Record ID: 16, instruction offset: 32
+CHECK-NEXT:     1 locations:
+CHECK-NEXT:       #1: Direct R#6 + -32
+CHECK-NEXT:     0 live-outs: [ ]
+
+CHECK:        Record ID: 17, instruction offset: 32
+CHECK-NEXT:     2 locations:
+CHECK-NEXT:       #1: Direct R#6 + -8
+CHECK-NEXT:       #2: Direct R#6 + -40
+CHECK-NEXT:     1 live-outs: [ R#7 (8-bytes) ]
+
+CHECK:        Record ID: 4294967295, instruction offset: 4
+CHECK-NEXT:     0 locations:
+CHECK-NEXT:     0 live-outs: [ ]
+
+CHECK:        Record ID: 4294967296, instruction offset: 4
+CHECK-NEXT:     0 locations:
+CHECK-NEXT:     0 live-outs: [ ]
+
+CHECK:        Record ID: 9223372036854775807, instruction offset: 4
+CHECK-NEXT:     0 locations:
+CHECK-NEXT:     0 live-outs: [ ]
+
+CHECK:        Record ID: 18446744073709551615, instruction offset: 4
+CHECK-NEXT:     0 locations:
+CHECK-NEXT:     1 live-outs: [ R#7 (8-bytes) ]
+
+CHECK:        Record ID: 16, instruction offset: 18
+CHECK-NEXT:     1 locations:
+CHECK-NEXT:       #1: Indirect [R#6 + -44]
+CHECK-NEXT:     0 live-outs: [ ]
+
+CHECK:        Record ID: 0, instruction offset: 26
+CHECK-NEXT:     0 locations:
+CHECK-NEXT:     0 live-outs: [ ]
index 529ebabaaf7bfda0d713b13773e2b657ade0cf65..bf6a103fb793fb224678ab5958fe1790f1e9e99d 100644 (file)
@@ -1527,10 +1527,10 @@ void COFFDumper::printStackMap() const {
   if (Obj->isLittleEndian())
     prettyPrintStackMap(
                       llvm::outs(),
-                      StackMapV1Parser<support::little>(StackMapContentsArray));
+                      StackMapV2Parser<support::little>(StackMapContentsArray));
   else
     prettyPrintStackMap(llvm::outs(),
-                        StackMapV1Parser<support::big>(StackMapContentsArray));
+                        StackMapV2Parser<support::big>(StackMapContentsArray));
 }
 
 void llvm::dumpCodeViewMergedTypes(
index 1c1b69aa31b72a743dee4f056ffbf76459164651..05c5ab34991a5f7aa48734c0b8e5d4ce8e134305 100644 (file)
@@ -2366,7 +2366,7 @@ template <class ELFT> void ELFDumper<ELFT>::printStackMap() const {
   ArrayRef<uint8_t> StackMapContentsArray =
       unwrapOrError(Obj->getSectionContents(StackMapSection));
 
-  prettyPrintStackMap(llvm::outs(), StackMapV1Parser<ELFT::TargetEndianness>(
+  prettyPrintStackMap(llvm::outs(), StackMapV2Parser<ELFT::TargetEndianness>(
                                         StackMapContentsArray));
 }
 
index 3773df250578e95567df9b98d722f02ee2197cf5..01b074170ba53fa7edf01983b37a5791484375b2 100644 (file)
@@ -669,10 +669,10 @@ void MachODumper::printStackMap() const {
   if (Obj->isLittleEndian())
      prettyPrintStackMap(
                       llvm::outs(),
-                      StackMapV1Parser<support::little>(StackMapContentsArray));
+                      StackMapV2Parser<support::little>(StackMapContentsArray));
   else
      prettyPrintStackMap(llvm::outs(),
-                         StackMapV1Parser<support::big>(StackMapContentsArray));
+                         StackMapV2Parser<support::big>(StackMapContentsArray));
 }
 
 void MachODumper::printMachODataInCode() {
index 92645bcf9172fb5784c8633b2edba8a61c0dca8e..f4ed68e92d786ebe04a91f7c7250ff95f0bf35ec 100644 (file)
@@ -24,7 +24,8 @@ void prettyPrintStackMap(OStreamT &OS, const StackMapParserT &SMP) {
   // Functions:
   for (const auto &F : SMP.functions())
     OS << "\n  Function address: " << F.getFunctionAddress()
-       << ", stack size: " << F.getStackSize();
+       << ", stack size: " << F.getStackSize()
+       << ", callsite record count: " << F.getRecordCount();
 
   // Constants:
   OS << "\nNum Constants: " << SMP.getNumConstants();