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());
154 Twine(
"failed to parse instrumentor configuration file: ") +
159 auto *Config = Parsed->getAsObject();
162 "failed to parse instrumentor configuration file, expected an object "
170 BCOMap[BO->Name] = BO;
173 for (
auto &It : *Config) {
174 auto *Obj = It.second.getAsObject();
177 "malformed JSON configuration, expected an object",
DS_Warning));
180 if (It.first ==
"configuration") {
181 for (
auto &ObjIt : *Obj) {
182 if (
auto *BO = BCOMap.
lookup(ObjIt.first)) {
185 if (
auto V = ObjIt.second.getAsString()) {
186 BO->setString(IConf.
SS.
save(*V));
190 Twine(
"' expects a string, value ignored"),
195 if (
auto V = ObjIt.second.getAsBoolean())
200 Twine(
"' expects a boolean, value ignored"),
205 auto *
Values = ObjIt.second.getAsArray();
209 Twine(
"' expects an array of strings, value ignored"),
215 bool AllStrings =
true;
225 BO->setStringList(Strings);
229 Twine(
"' expects an array of strings, value ignored"),
235 std::string Diag =
"configuration key '" + ObjIt.first.str() +
236 "' not found and ignored";
238 if (!Closest.
empty())
239 Diag +=
"; did you mean '" + Closest.
str() +
"'?";
248 for (
auto &ObjIt : *Obj) {
249 auto *InnerObj = ObjIt.second.getAsObject();
252 "malformed JSON configuration, expected an object",
DS_Warning));
255 auto *IO = IChoiceMap.lookup(ObjIt.first);
258 "malformed JSON configuration, expected an object matching "
259 "an instrumentor choice, got '" +
260 ObjIt.first.str() +
"'";
262 if (!Closest.
empty())
263 Diag +=
"; did you mean '" + Closest.
str() +
"'?";
273 for (
auto &IRArg : IO->IRTArgs)
274 IOOpts.
insert(IRArg.Name);
275 for (
auto &InnerObjIt : *InnerObj) {
277 if (Name ==
"filter") {
278 if (
auto V = InnerObjIt.second.getAsString())
279 FilterStr = IConf.
SS.
save(*V);
280 }
else if (Name.consume_back(
".replace")) {
281 ReplaceMap[Name] = InnerObjIt.second.getAsBoolean().value_or(
false);
283 ValueMap[Name] = InnerObjIt.second.getAsBoolean().value_or(
false);
286 std::string Diag =
"unrecognized JSON property '" + Name.str() +
287 "' in configuration for '" + IO->getName().str() +
290 if (!Closest.
empty())
291 Diag +=
"; did you mean '" + Closest.
str() +
"'?";
296 IO->Filter = FilterStr;
297 for (
auto &IRArg : IO->IRTArgs) {
298 IRArg.Enabled =
ValueMap[IRArg.Name];
300 IRArg.Flags &=
~IRTArg::REPLACABLE;
307 for (
auto &IChoiceMap : IConf.
IChoices)
308 for (
auto &It : IChoiceMap)
309 if (!SeenIOs.
count(It.second))
310 It.second->Enabled =
false;
317 if (InputFile.
empty())
321 if (
Error E = BufferOrErr.takeError()) {
323 Twine(
"failed to open instrumentor configuration paths file for "
332 auto Buffer = std::move(BufferOrErr.get());
336 auto [LHS, RHS] = Content.
split(EOL);
337 std::string ConfigPath = LHS.trim().str();
341 ConfigPath = InputFilePathStringVec.
c_str();
344 Content = RHS.
trim();
345 }
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()
The root is the trivial Path to the root value.
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.