35 if (std::error_code EC = BufferOrErr.getError())
37 return std::move(BufferOrErr.get());
45 if (OutputFile.
empty())
52 Twine(
"failed to open instrumentor configuration file for writing: ") +
64 switch (BaseCO->Kind) {
66 J.
attribute(BaseCO->Name, BaseCO->getString());
69 J.
attribute(BaseCO->Name, BaseCO->getBool());
72 if (!BaseCO->Description.empty())
73 J.
attribute(std::string(BaseCO->Name) +
".description",
83 auto &KindChoices = IConf.
IChoices[Kind];
84 if (KindChoices.empty())
89 for (
auto &ChoiceIt : KindChoices) {
92 J.
attribute(
"enabled", ChoiceIt.second->Enabled);
93 J.
attribute(
"filter", ChoiceIt.second->Filter);
95 "Static property filter to exclude instrumentation.");
96 for (
auto &ArgIt : ChoiceIt.second->IRTArgs) {
100 J.
attribute(std::string(ArgIt.Name) +
".replace",
true);
101 if (!ArgIt.Description.empty())
102 J.
attribute(std::string(ArgIt.Name) +
".description",
117 if (InputFile.
empty())
121 if (
Error E = BufferOrErr.takeError()) {
123 Twine(
"failed to open instrumentor configuration file for reading: ") +
128 auto Buffer = std::move(BufferOrErr.get());
133 Twine(
"failed to parse instrumentor configuration file: ") +
138 auto *Config = Parsed->getAsObject();
141 "failed to parse instrumentor configuration file, expected an object "
149 BCOMap[BO->Name] = BO;
152 for (
auto &It : *Config) {
153 auto *Obj = It.second.getAsObject();
156 "malformed JSON configuration, expected an object",
DS_Warning));
159 if (It.first ==
"configuration") {
160 for (
auto &ObjIt : *Obj) {
161 if (
auto *BO = BCOMap.
lookup(ObjIt.first)) {
164 if (
auto V = ObjIt.second.getAsString()) {
165 BO->setString(IConf.
SS.
save(*V));
168 Twine(
"configuration key '") + ObjIt.first.
str() +
169 Twine(
"' expects a string, value ignored"),
174 if (
auto V = ObjIt.second.getAsBoolean())
178 Twine(
"configuration key '") + ObjIt.first.
str() +
179 Twine(
"' expects a boolean, value ignored"),
186 Twine(
"configuration key '") + ObjIt.first.
str() +
187 Twine(
"' not found and ignored"),
196 for (
auto &ObjIt : *Obj) {
197 auto *InnerObj = ObjIt.second.getAsObject();
200 "malformed JSON configuration, expected an object",
DS_Warning));
203 auto *IO = IChoiceMap.lookup(ObjIt.first);
206 Twine(
"malformed JSON configuration, expected an object matching "
207 "an instrumentor choice, got ") +
215 for (
auto &InnerObjIt : *InnerObj) {
217 if (Name ==
"filter") {
218 if (
auto V = InnerObjIt.second.getAsString())
219 FilterStr = IConf.
SS.
save(*V);
220 }
else if (Name.consume_back(
".replace")) {
221 ReplaceMap[Name] = InnerObjIt.second.getAsBoolean().value_or(
false);
223 ValueMap[Name] = InnerObjIt.second.getAsBoolean().value_or(
false);
227 IO->Filter = FilterStr;
228 for (
auto &IRArg : IO->IRTArgs) {
229 IRArg.Enabled =
ValueMap[IRArg.Name];
231 IRArg.Flags &=
~IRTArg::REPLACABLE;
238 for (
auto &IChoiceMap : IConf.
IChoices)
239 for (
auto &It : IChoiceMap)
240 if (!SeenIOs.
count(It.second))
241 It.second->Enabled =
false;
248 if (InputFile.
empty())
252 if (
Error E = BufferOrErr.takeError()) {
254 Twine(
"failed to open instrumentor configuration paths file for "
263 auto Buffer = std::move(BufferOrErr.get());
267 auto [LHS, RHS] = Content.
split(EOL);
268 std::string ConfigPath = LHS.trim().str();
272 ConfigPath = InputFilePathStringVec.
c_str();
275 Content = RHS.
trim();
276 }
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
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.
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)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
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.
void writeConfigToJSON(InstrumentationConfig &IConf, StringRef OutputFile, LLVMContext &Ctx)
Write the configuration in /p IConf to the file with path OutputFile.
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.
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)
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.
SmallVector< BaseConfigurationOption * > BaseConfigurationOptions
The list of enabled base configuration options.
EnumeratedArray< StringMap< InstrumentationOpportunity * >, InstrumentationLocation::KindTy > IChoices
The map registered instrumentation opportunities.
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.