31 if (OutputFile.
empty())
38 Twine(
"failed to open instrumentor configuration file for writing: ") +
50 switch (BaseCO->Kind) {
52 J.
attribute(BaseCO->Name, BaseCO->getString());
55 J.
attribute(BaseCO->Name, BaseCO->getBool());
58 if (!BaseCO->Description.empty())
59 J.
attribute(std::string(BaseCO->Name) +
".description",
69 auto &KindChoices = IConf.
IChoices[Kind];
70 if (KindChoices.empty())
75 for (
auto &ChoiceIt : KindChoices) {
78 J.
attribute(
"enabled", ChoiceIt.second->Enabled);
79 for (
auto &ArgIt : ChoiceIt.second->IRTArgs) {
83 J.
attribute(std::string(ArgIt.Name) +
".replace",
true);
84 if (!ArgIt.Description.empty())
85 J.
attribute(std::string(ArgIt.Name) +
".description",
100 if (InputFile.
empty())
105 if (std::error_code EC = BufferOrErr.getError()) {
107 Twine(
"failed to open instrumentor configuration file for reading: ") +
112 auto Buffer = std::move(BufferOrErr.get());
117 Twine(
"failed to parse instrumentor configuration file: ") +
122 auto *Config = Parsed->getAsObject();
125 "failed to parse instrumentor configuration file, expected an object "
133 BCOMap[BO->Name] = BO;
136 for (
auto &It : *Config) {
137 auto *Obj = It.second.getAsObject();
140 "malformed JSON configuration, expected an object",
DS_Warning));
143 if (It.first ==
"configuration") {
144 for (
auto &ObjIt : *Obj) {
145 if (
auto *BO = BCOMap.
lookup(ObjIt.first)) {
148 if (
auto V = ObjIt.second.getAsString()) {
149 BO->setString(IConf.
SS.
save(*V));
152 Twine(
"configuration key '") + ObjIt.first.
str() +
153 Twine(
"' expects a string, value ignored"),
158 if (
auto V = ObjIt.second.getAsBoolean())
162 Twine(
"configuration key '") + ObjIt.first.
str() +
163 Twine(
"' expects a boolean, value ignored"),
170 Twine(
"configuration key '") + ObjIt.first.
str() +
171 Twine(
"' not found and ignored"),
180 for (
auto &ObjIt : *Obj) {
181 auto *InnerObj = ObjIt.second.getAsObject();
184 "malformed JSON configuration, expected an object",
DS_Warning));
187 auto *IO = IChoiceMap.lookup(ObjIt.first);
190 Twine(
"malformed JSON configuration, expected an object matching "
191 "an instrumentor choice, got ") +
198 for (
auto &InnerObjIt : *InnerObj) {
200 if (Name.consume_back(
".replace"))
201 ReplaceMap[Name] = InnerObjIt.second.getAsBoolean().value_or(
false);
203 ValueMap[Name] = InnerObjIt.second.getAsBoolean().value_or(
false);
206 for (
auto &IRArg : IO->IRTArgs) {
207 IRArg.Enabled =
ValueMap[IRArg.Name];
209 IRArg.Flags &=
~IRTArg::REPLACABLE;
216 for (
auto &IChoiceMap : IConf.
IChoices)
217 for (
auto &It : IChoiceMap)
218 if (!SeenIOs.
count(It.second))
219 It.second->Enabled =
false;
This file defines the StringMap class.
static constexpr std::pair< StringLiteral, StringLiteral > ReplaceMap[]
This file supports working with JSON data.
Diagnostic information for IR instrumentation reporting.
This is an important class for using LLVM in a threaded context.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
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.
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.
constexpr bool empty() const
Check if the string is empty.
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.
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.
bool readConfigFromJSON(InstrumentationConfig &IConf, StringRef InputFile, LLVMContext &Ctx)
Read the configuration from the file with path InputFile into /p IConf.
void writeConfigToJSON(InstrumentationConfig &IConf, StringRef OutputFile, LLVMContext &Ctx)
Write the configuration in /p IConf to the file with path OutputFile.
LLVM_ABI llvm::Expected< Value > parse(llvm::StringRef JSON)
Parses the provided JSON source, or returns a ParseError.
This is an optimization pass for GlobalISel generic memory operations.
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
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.