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());
74 for (StringRef Value : BaseCO->getStringList())
79 if (!BaseCO->Description.empty())
80 J.
attribute(std::string(BaseCO->Name) +
".description",
90 auto &KindChoices = IConf.
IChoices[Kind];
91 if (KindChoices.empty())
96 for (
auto &[Name, Choice] : KindChoices) {
102 "Static property filter to exclude instrumentation.");
103 for (
auto &ArgIt : Choice->IRTArgs) {
107 J.
attribute(std::string(ArgIt.Name) +
".replace",
true);
108 if (!ArgIt.Description.empty())
109 J.
attribute(std::string(ArgIt.Name) +
".description",
122template <
typename Map>
127 auto EditDist = Missing.edit_distance_insensitive(
Key,
true, MaxEdit);
128 if (EditDist < MaxEdit) {
138 if (InputFile.
empty())
142 if (
Error E = BufferOrErr.takeError()) {
144 Twine(
"failed to open instrumentor configuration file for reading: ") +
149 auto Buffer = std::move(BufferOrErr.get());
153 Twine(
"failed to parse instrumentor configuration file: ") +
158 auto *Config = Parsed->getAsObject();
161 "failed to parse instrumentor configuration file, expected an object "
169 BCOMap[BO->Name] = BO;
172 for (
auto &It : *Config) {
173 auto *Obj = It.second.getAsObject();
176 "malformed JSON configuration, expected an object",
DS_Warning));
179 if (It.first ==
"configuration") {
180 for (
auto &ObjIt : *Obj) {
181 if (
auto *BO = BCOMap.
lookup(ObjIt.first)) {
184 if (
auto V = ObjIt.second.getAsString()) {
185 BO->setString(IConf.
SS.
save(*V));
189 Twine(
"' expects a string, value ignored"),
194 if (
auto V = ObjIt.second.getAsBoolean())
199 Twine(
"' expects a boolean, value ignored"),
204 auto *
Values = ObjIt.second.getAsArray();
208 Twine(
"' expects an array of strings, value ignored"),
214 bool AllStrings =
true;
224 BO->setStringList(Strings);
228 Twine(
"' expects an array of strings, value ignored"),
234 std::string Diag =
"configuration key '" + ObjIt.first.str() +
235 "' not found and ignored";
237 if (!Closest.
empty())
238 Diag +=
"; did you mean '" + Closest.
str() +
"'?";
247 for (
auto &ObjIt : *Obj) {
248 auto *InnerObj = ObjIt.second.getAsObject();
251 "malformed JSON configuration, expected an object",
DS_Warning));
254 auto *IO = IChoiceMap.lookup(ObjIt.first);
257 "malformed JSON configuration, expected an object matching "
258 "an instrumentor choice, got '" +
259 ObjIt.first.str() +
"'";
261 if (!Closest.
empty())
262 Diag +=
"; did you mean '" + Closest.
str() +
"'?";
272 for (
auto &IRArg : IO->IRTArgs)
273 IOOpts.
insert(IRArg.Name);
274 for (
auto &InnerObjIt : *InnerObj) {
276 if (Name ==
"filter") {
277 if (
auto V = InnerObjIt.second.getAsString())
278 FilterStr = IConf.
SS.
save(*V);
279 }
else if (Name.consume_back(
".replace")) {
280 ReplaceMap[Name] = InnerObjIt.second.getAsBoolean().value_or(
false);
282 ValueMap[Name] = InnerObjIt.second.getAsBoolean().value_or(
false);
284 if (!IOOpts.
contains(Name) && !Name.ends_with(
".description")) {
285 std::string Diag =
"unrecognized JSON property '" + Name.str() +
286 "' in configuration for '" + IO->getName().str() +
289 if (!Closest.
empty())
290 Diag +=
"; did you mean '" + Closest.
str() +
"'?";
295 IO->Filter = FilterStr;
296 for (
auto &IRArg : IO->IRTArgs) {
297 IRArg.Enabled =
ValueMap[IRArg.Name];
299 IRArg.Flags &=
~IRTArg::REPLACABLE;
306 for (
auto &IChoiceMap : IConf.
IChoices)
307 for (
auto &It : IChoiceMap)
308 if (!SeenIOs.
count(It.second))
309 It.second->Enabled =
false;
316 if (InputFile.
empty())
320 if (
Error E = BufferOrErr.takeError()) {
322 Twine(
"failed to open instrumentor configuration paths file for "
331 auto Buffer = std::move(BufferOrErr.get());
335 auto [LHS, RHS] = Content.
split(EOL);
336 std::string ConfigPath = LHS.trim().str();
340 ConfigPath = InputFilePathStringVec.
c_str();
343 Content = RHS.
trim();
344 }
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...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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...
LLVM Value Representation.
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()
void attributeArray(llvm::StringRef Key, Block Contents)
Emit an attribute whose value is an array with elements from the Block.
LLVM_ABI void attributeEnd()
LLVM_ABI void objectEnd()
A Value is an JSON value of unknown type.
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)
RelativeUniformCounterPtr Values
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.