Skip to content

obj2yaml: Introduce CovMap dump #127432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: users/chapuni/yaml/enc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion llvm/include/llvm/ObjectYAML/CovMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
//
// - llvm::covmap
//
// Provides YAML encoder for coverage map.
// Provides YAML encoder and decoder for coverage map.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be possible to do only the encoder or decoder first in this patch, and then in another patch, do the other one?

e.g.

  • patch 1: add ability to encode
  • patch 2: add ability to decode
  • patch 3: add support for covmap-raw
  • patch 4: add support for covmap-dloc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I split out "encoder" and "decoder detailed(--covmap)".

//
//===----------------------------------------------------------------------===//

#ifndef LLVM_OBJECTYAML_COVMAP_H
#define LLVM_OBJECTYAML_COVMAP_H

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ObjectYAML/ELFYAML.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/YAMLTraits.h"
#include <array>
#include <cstdint>
Expand All @@ -41,6 +43,8 @@ class raw_ostream;

namespace llvm::coverage::yaml {

struct DecoderContext;

/// Base Counter, corresponding to coverage::Counter.
struct CounterTy {
enum TagTy : uint8_t {
Expand All @@ -57,6 +61,14 @@ struct CounterTy {

virtual void mapping(llvm::yaml::IO &IO);

uint64_t getExtTagVal() const { return (Tag == Zero && Val != 0 ? Val : 0); }

/// Holds Val for extensions.
Error decodeOrTag(DecoderContext &Data);

/// Raise Error if Val isn't empty.
Error decode(DecoderContext &Data);

void encode(raw_ostream &OS) const;
};

Expand All @@ -77,6 +89,8 @@ struct DecisionTy {

void mapping(llvm::yaml::IO &IO);

Error decode(DecoderContext &Data);

void encode(raw_ostream &OS) const;
};

Expand Down Expand Up @@ -110,6 +124,8 @@ struct RecTy : CounterTy {

void mapping(llvm::yaml::IO &IO) override;

Error decode(DecoderContext &Data);

void encode(raw_ostream &OS) const;
};

Expand All @@ -131,6 +147,10 @@ struct CovFunTy {

void mapping(llvm::yaml::IO &IO);

/// Depends on CovMap and SymTab(IPSK_names)
Expected<uint64_t> decode(const ArrayRef<uint8_t> Content, uint64_t Offset,
endianness Endianness);

void encode(raw_ostream &OS, endianness Endianness) const;
};

Expand All @@ -147,6 +167,9 @@ struct CovMapTy {

void mapping(llvm::yaml::IO &IO);

Expected<uint64_t> decode(const ArrayRef<uint8_t> Content, uint64_t Offset,
endianness Endianness);

/// Encode Filenames. This is mostly used just to obtain FilenamesRef.
std::pair<uint64_t, std::string> encodeFilenames(bool Compress = false) const;

Expand Down Expand Up @@ -201,6 +224,31 @@ LLVM_COVERAGE_YAML_ELEM_MAPPING(CovMapTy)

namespace llvm::covmap {

class Decoder {
protected:
endianness Endianness;

public:
Decoder(endianness Endianness) : Endianness(Endianness) {}
virtual ~Decoder();

/// Returns DecoderImpl.
static std::unique_ptr<Decoder> get(endianness Endianness,
bool CovMapEnabled);

/// Called from the Sections loop in advance of the final dump.
/// Decoder predecodes CovMap for Version info.
virtual Error acquire(unsigned AddressAlign, StringRef Name,
ArrayRef<uint8_t> Content) = 0;

/// Make contents on ELFYAML object. CovMap is predecoded.
virtual Error make(ELFYAML::CovMapSectionBase *Base,
ArrayRef<uint8_t> Content) = 0;

/// Suppress emission of CovMap unless enabled.
static bool enabled;
};

/// Returns whether Name is interested.
bool nameMatches(StringRef Name);

Expand Down
6 changes: 6 additions & 0 deletions llvm/include/llvm/ProfileData/InstrProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,12 @@ class InstrProfSymtab {
/// This method is a wrapper to \c readAndDecodeStrings method.
Error create(StringRef NameStrings);

// PrfNames is nested array.
using PrfNamesTy = SmallVector<std::string>;
using PrfNamesChunksTy = SmallVector<PrfNamesTy, 1>;

Expected<PrfNamesChunksTy> createAndGetList(ArrayRef<uint8_t> Content);

/// Initialize symtab states with function names and vtable names. \c
/// FuncNameStrings is a string composed of one or more encoded function name
/// strings, and \c VTableNameStrings composes of one or more encoded vtable
Expand Down
Loading
Loading