36 if (std::error_code EC = BufferOrErr.getError())
38 return std::move(BufferOrErr.get());
46 if (OutputFile.
empty())
53 Twine(
"failed to open instrumentor configuration file for writing: ") +
65 switch (BaseCO->Kind) {
67 J.
attribute(BaseCO->Name, BaseCO->getString());
70 J.
attribute(BaseCO->Name, BaseCO->getBool());
73 if (!BaseCO->Description.empty())
74 J.
attribute(std::string(BaseCO->Name) +
".description",
84 auto &KindChoices = IConf.
IChoices[Kind];
85 if (KindChoices.empty())
90 for (
auto &[Name, Choice] : KindChoices) {
96 "Static property filter to exclude instrumentation.");
97 for (
auto &ArgIt : Choice->IRTArgs) {
101 J.
attribute(std::string(ArgIt.Name) +
".replace",
true);
102 if (!ArgIt.Description.empty())
103 J.
attribute(std::string(ArgIt.Name) +
".description",
116template <
typename Map>
121 auto EditDist = Missing.edit_distance_insensitive(
Key,
true, MaxEdit);
122 if (EditDist < MaxEdit) {
132 if (InputFile.
empty())
136 if (
Error E = BufferOrErr.takeError()) {
138 Twine(
"failed to open instrumentor configuration file for reading: ") +
143 auto Buffer = std::move(BufferOrErr.get());
148 Twine(
"failed to parse instrumentor configuration file: ") +
153 auto *Config = Parsed->getAsObject();
156 "failed to parse instrumentor configuration file, expected an object "
164 BCOMap[BO->Name] = BO;
167 for (
auto &It : *Config) {
168 auto *Obj = It.second.getAsObject();
171 "malformed JSON configuration, expected an object",
DS_Warning));
174 if (It.first ==
"configuration") {
175 for (
auto &ObjIt : *Obj) {
176 if (
auto *BO = BCOMap.
lookup(ObjIt.first)) {
179 if (
auto V = ObjIt.second.getAsString()) {
180 BO->setString(IConf.
SS.
save(*V));
184 Twine(
"' expects a string, value ignored"),
189 if (
auto V = ObjIt.second.getAsBoolean())
194 Twine(
"' expects a boolean, value ignored"),
200 std::string Diag =
"configuration key '" + ObjIt.first.str() +
201 "' not found and ignored";
203 if (!Closest.
empty())
204 Diag +=
"; did you mean '" + Closest.
str() +
"'?";
213 for (
auto &ObjIt : *Obj) {
214 auto *InnerObj = ObjIt.second.getAsObject();
217 "malformed JSON configuration, expected an object",
DS_Warning));
220 auto *IO = IChoiceMap.lookup(ObjIt.first);
223 "malformed JSON configuration, expected an object matching "
224 "an instrumentor choice, got '" +
225 ObjIt.first.str() +
"'";
227 if (!Closest.
empty())
228 Diag +=
"; did you mean '" + Closest.
str() +
"'?";
238 for (
auto &IRArg : IO->IRTArgs)
239 IOOpts.
insert(IRArg.Name);
240 for (
auto &InnerObjIt : *InnerObj) {
242 if (Name ==
"filter") {
243 if (
auto V = InnerObjIt.second.getAsString())
244 FilterStr = IConf.
SS.
save(*V);
245 }
else if (Name.consume_back(
".replace")) {
246 ReplaceMap[Name] = InnerObjIt.second.getAsBoolean().value_or(
false);
248 ValueMap[Name] = InnerObjIt.second.getAsBoolean().value_or(
false);
251 std::string Diag =
"unrecognized JSON property '" + Name.str() +
252 "' in configuration for '" + IO->getName().str() +
255 if (!Closest.
empty())
256 Diag +=
"; did you mean '" + Closest.
str() +
"'?";
261 IO->Filter = FilterStr;
262 for (
auto &IRArg : IO->IRTArgs) {
263 IRArg.Enabled =
ValueMap[IRArg.Name];
265 IRArg.Flags &=
~IRTArg::REPLACABLE;
272 for (
auto &IChoiceMap : IConf.
IChoices)
273 for (
auto &It : IChoiceMap)
274 if (!SeenIOs.
count(It.second))
275 It.second->Enabled =
false;
282 if (InputFile.
empty())
286 if (
Error E = BufferOrErr.takeError()) {
288 Twine(
"failed to open instrumentor configuration paths file for "
297 auto Buffer = std::move(BufferOrErr.get());
301 auto [LHS, RHS] = Content.
split(EOL);
302 std::string ConfigPath = LHS.trim().str();
306 ConfigPath = InputFilePathStringVec.
c_str();
309 Content = RHS.
trim();
310 }
while (!Content.
empty());
This file defines the StringMap class.
static constexpr std::pair< StringLiteral, StringLiteral > ReplaceMap[]
This file supports working with JSON data.
static constexpr StringLiteral Filename
StringSet - A set-like wrapper for the StringMap.
Defines the virtual file system interface vfs::FileSystem.
Diagnostic information for IR instrumentation reporting.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
This is an important class for using LLVM in a threaded context.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getSTDIN()
Read all of stdin into a file buffer, and return it.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
std::string str() const
Get the contents as an std::string.
constexpr bool empty() const
Check if the string is empty.
StringRef detectEOL() const
Detect the line ending style of the string.
StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
StringRef save(const char *S)
StringSet - A wrapper for StringMap that provides set-like functionality.
bool contains(StringRef key) const
Check if the set contains the given key.
std::pair< typename Base::iterator, bool > insert(StringRef key)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void push_back(const DataType &value)
json::OStream allows writing well-formed JSON without materializing all structures as json::Value ahe...
LLVM_ABI void attributeBegin(llvm::StringRef Key)
void attribute(llvm::StringRef Key, const Value &Contents)
Emit an attribute whose value is self-contained (number, vector<int> etc).
LLVM_ABI void objectBegin()
LLVM_ABI void attributeEnd()
LLVM_ABI void objectEnd()
The root is the trivial Path to the root value.
A raw_ostream of a file for reading/writing/seeking.
The virtual file system interface.
LLVM_ABI void writeConfigToJSON(InstrumentationConfig &IConf, StringRef OutputFile, LLVMContext &Ctx)
Write the configuration in /p IConf to the file with path OutputFile.
static StringRef closestOption(const Map &Options, StringRef Missing)
LLVM_ABI bool readConfigPathsFile(StringRef InputFile, cl::list< std::string > &Configs, LLVMContext &Ctx, vfs::FileSystem &FS)
Read the configuration paths from the file with path InputFile into Configs.
LLVM_ABI bool readConfigFromJSON(InstrumentationConfig &IConf, StringRef InputFile, LLVMContext &Ctx, vfs::FileSystem &FS)
Read the configuration from the file with path InputFile into /p IConf.
LLVM_ABI llvm::Expected< Value > parse(llvm::StringRef JSON)
Parses the provided JSON source, or returns a ParseError.
LLVM_ABI StringRef parent_path(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get parent path.
LLVM_ABI bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
This is an optimization pass for GlobalISel generic memory operations.
static Expected< std::unique_ptr< MemoryBuffer > > setupMemoryBuffer(const Twine &Filename, vfs::FileSystem &FS)
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
unsigned Flags
The flags that describe the properties of the argument.
The class that contains the configuration for the instrumentor.
EnumeratedArray< MapVector< StringRef, InstrumentationOpportunity * >, InstrumentationLocation::KindTy > IChoices
The map registered instrumentation opportunities.
SmallVector< BaseConfigurationOption * > BaseConfigurationOptions
The list of enabled base configuration options.
static KindTy getKindFromStr(StringRef S)
Return the location kind described by a string.
static StringRef getKindStr(KindTy Kind)
Return the string representation given a location kind.
KindTy
The supported location kinds, which are composed of a opportunity type and position.