OmniSciDB  95562058bd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AutomaticIRMetadataGuard Class Reference

#include <AutomaticIRMetadataGuard.h>

+ Collaboration diagram for AutomaticIRMetadataGuard:

Classes

struct  InstructionInfo
 

Public Member Functions

 AutomaticIRMetadataGuard (CgenState *cgen_state, const std::string &ppfile, const size_t ppline, const std::string &ppfunc)
 
 ~AutomaticIRMetadataGuard ()
 
void done () noexcept
 
void rememberPreexistingInstructions () noexcept
 
void rememberOurInstructions () noexcept
 
void markInstructions () noexcept
 

Private Types

using OurInstructions = std::unordered_map< llvm::Instruction *, InstructionInfo >
 

Private Member Functions

std::string makeBaseFilename ()
 
std::string makeQueryEngineFilename ()
 
std::string replacePunctuation (std::string text)
 

Private Attributes

CgenStatecgen_state_
 
const std::string ppfile_
 
const size_t ppline_
 
const std::string ppfunc_
 
std::unordered_set
< llvm::Instruction * > 
preexisting_instructions_
 
OurInstructionsour_instructions_
 
bool done_
 
bool this_is_root_
 

Static Private Attributes

static std::unordered_map
< CgenState *, OurInstructions
instructions_
 
static const std::string detailed_footnote_prefix_ {"Omnisci Debugging Info: "}
 

Detailed Description

Definition at line 29 of file AutomaticIRMetadataGuard.h.

Member Typedef Documentation

using AutomaticIRMetadataGuard::OurInstructions = std::unordered_map<llvm::Instruction*, InstructionInfo>
private

Definition at line 176 of file AutomaticIRMetadataGuard.h.

Constructor & Destructor Documentation

AutomaticIRMetadataGuard::AutomaticIRMetadataGuard ( CgenState cgen_state,
const std::string &  ppfile,
const size_t  ppline,
const std::string &  ppfunc 
)
inline

Definition at line 31 of file AutomaticIRMetadataGuard.h.

References cgen_state_, CHECK, instructions_, CgenState::module_, our_instructions_, and rememberPreexistingInstructions().

35  : cgen_state_(cgen_state)
36  , ppfile_(ppfile)
37  , ppline_(ppline)
38  , ppfunc_(ppfunc)
39  , our_instructions_(nullptr)
40  , done_(false)
46  }
void rememberPreexistingInstructions() noexcept
llvm::Module * module_
Definition: CgenState.h:330
static std::unordered_map< CgenState *, OurInstructions > instructions_
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the call graph for this function:

AutomaticIRMetadataGuard::~AutomaticIRMetadataGuard ( )
inline

Definition at line 48 of file AutomaticIRMetadataGuard.h.

References done().

48 { done(); }

+ Here is the call graph for this function:

Member Function Documentation

void AutomaticIRMetadataGuard::done ( )
inlinenoexcept

Definition at line 50 of file AutomaticIRMetadataGuard.h.

References cgen_state_, done_, instructions_, markInstructions(), rememberOurInstructions(), and this_is_root_.

Referenced by ~AutomaticIRMetadataGuard().

50  {
51  if (!done_) {
53  if (this_is_root_) {
56  }
57  done_ = true;
58  }
59  }
static std::unordered_map< CgenState *, OurInstructions > instructions_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string AutomaticIRMetadataGuard::makeBaseFilename ( )
inlineprivate

Definition at line 130 of file AutomaticIRMetadataGuard.h.

References ppfile_, and split().

Referenced by rememberOurInstructions().

130  {
131  std::vector<std::string> fnames = split(ppfile_, "/");
132  if (!fnames.empty()) {
133  return fnames.back();
134  }
135  return ppfile_;
136  }
std::vector< std::string > split(std::string_view str, std::string_view delim, std::optional< size_t > maxsplit)
split apart a string into a vector of substrings

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string AutomaticIRMetadataGuard::makeQueryEngineFilename ( )
inlineprivate

Definition at line 138 of file AutomaticIRMetadataGuard.h.

References ppfile_, and split().

Referenced by rememberOurInstructions().

138  {
139  std::vector<std::string> fnames = split(ppfile_, "/");
140  bool copying{false};
141  std::string f;
142  for (auto n : fnames) {
143  if (copying && !n.empty()) {
144  if (!f.empty()) {
145  f += "/";
146  }
147  f += n;
148  }
149  if (n == "QueryEngine") {
150  copying = true;
151  }
152  }
153  if (f.empty() && fnames.size() > 0) {
154  f = fnames.back();
155  } else if (f.empty()) {
156  f = ppfile_;
157  }
158  return f;
159  }
std::vector< std::string > split(std::string_view str, std::string_view delim, std::optional< size_t > maxsplit)
split apart a string into a vector of substrings

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AutomaticIRMetadataGuard::markInstructions ( )
inlinenoexcept

Definition at line 105 of file AutomaticIRMetadataGuard.h.

References cgen_state_, CgenState::context_, detailed_footnote_prefix_, CgenState::module_, and our_instructions_.

Referenced by done().

105  {
106  // iterate over all LLVM instructions in the module
107  for (auto func_it = cgen_state_->module_->begin();
108  func_it != cgen_state_->module_->end();
109  ++func_it) {
110  for (auto bb_it = func_it->begin(); bb_it != func_it->end(); ++bb_it) {
111  for (auto instr_it = bb_it->begin(); instr_it != bb_it->end(); ++instr_it) {
112  auto our_it = our_instructions_->find(&*instr_it);
113  if (our_it == our_instructions_->end()) {
114  continue;
115  }
116  unsigned kind_id =
117  cgen_state_->context_.getMDKindID(our_it->second.main_filename_);
118  auto value = llvm::MDNode::get(
120  llvm::MDString::get(
122  detailed_footnote_prefix_ + our_it->second.detailed_footnote_));
123  our_it->first->setMetadata(kind_id, value);
124  }
125  }
126  }
127  }
llvm::Module * module_
Definition: CgenState.h:330
llvm::LLVMContext & context_
Definition: CgenState.h:339
static const std::string detailed_footnote_prefix_

+ Here is the caller graph for this function:

void AutomaticIRMetadataGuard::rememberOurInstructions ( )
inlinenoexcept

Definition at line 77 of file AutomaticIRMetadataGuard.h.

References cgen_state_, makeBaseFilename(), makeQueryEngineFilename(), CgenState::module_, our_instructions_, ppfunc_, ppline_, preexisting_instructions_, replacePunctuation(), and to_string().

Referenced by done().

77  {
78  // iterate over all LLVM instructions in the module
79  for (auto func_it = cgen_state_->module_->begin();
80  func_it != cgen_state_->module_->end();
81  ++func_it) {
82  for (auto bb_it = func_it->begin(); bb_it != func_it->end(); ++bb_it) {
83  for (auto instr_it = bb_it->begin(); instr_it != bb_it->end(); ++instr_it) {
84  // remember any new instructions as ours, skipping
85  // instructions already remembered as preexisting
86  llvm::Instruction* i = &*instr_it;
87  if (!preexisting_instructions_.count(i)) {
88  std::string qefile = makeQueryEngineFilename();
89  std::string footnote =
90  ppfunc_ + " near " + qefile + " line #" + std::to_string(ppline_);
91  auto it = our_instructions_->find(i);
92  if (it == our_instructions_->end()) {
93  std::string bfile = replacePunctuation(makeBaseFilename());
94  our_instructions_->emplace(i, InstructionInfo{bfile, footnote});
95  } else {
96  it->second.detailed_footnote_ =
97  footnote + ", " + it->second.detailed_footnote_;
98  }
99  }
100  }
101  }
102  }
103  }
std::string to_string(char const *&&v)
llvm::Module * module_
Definition: CgenState.h:330
std::unordered_set< llvm::Instruction * > preexisting_instructions_
std::string replacePunctuation(std::string text)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AutomaticIRMetadataGuard::rememberPreexistingInstructions ( )
inlinenoexcept

Definition at line 61 of file AutomaticIRMetadataGuard.h.

References cgen_state_, CHECK_EQ, CgenState::module_, and preexisting_instructions_.

Referenced by AutomaticIRMetadataGuard().

61  {
62  // iterate over all LLVM instructions in the module
63  for (auto func_it = cgen_state_->module_->begin();
64  func_it != cgen_state_->module_->end();
65  ++func_it) {
66  for (auto bb_it = func_it->begin(); bb_it != func_it->end(); ++bb_it) {
67  for (auto instr_it = bb_it->begin(); instr_it != bb_it->end(); ++instr_it) {
68  // remember all the instructions that already existed
69  // before this guard object was constructed
70  CHECK_EQ(preexisting_instructions_.count(&*instr_it), 0U);
71  preexisting_instructions_.insert(&*instr_it);
72  }
73  }
74  }
75  }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
llvm::Module * module_
Definition: CgenState.h:330
std::unordered_set< llvm::Instruction * > preexisting_instructions_

+ Here is the caller graph for this function:

std::string AutomaticIRMetadataGuard::replacePunctuation ( std::string  text)
inlineprivate

Definition at line 161 of file AutomaticIRMetadataGuard.h.

Referenced by rememberOurInstructions().

161  {
162  static const std::unordered_set<std::string::value_type> allowed_punct{'_', '.'};
163  for (auto& ch : text) {
164  if (std::ispunct(ch) && !allowed_punct.count(ch)) {
165  ch = '_';
166  }
167  }
168  return text;
169  }

+ Here is the caller graph for this function:

Member Data Documentation

CgenState* AutomaticIRMetadataGuard::cgen_state_
private
const std::string AutomaticIRMetadataGuard::detailed_footnote_prefix_ {"Omnisci Debugging Info: "}
inlinestaticprivate

Definition at line 192 of file AutomaticIRMetadataGuard.h.

Referenced by markInstructions().

bool AutomaticIRMetadataGuard::done_
private

Definition at line 187 of file AutomaticIRMetadataGuard.h.

Referenced by done().

std::unordered_map<CgenState*, OurInstructions> AutomaticIRMetadataGuard::instructions_
inlinestaticprivate

Definition at line 190 of file AutomaticIRMetadataGuard.h.

Referenced by AutomaticIRMetadataGuard(), and done().

OurInstructions* AutomaticIRMetadataGuard::our_instructions_
private
const std::string AutomaticIRMetadataGuard::ppfile_
private

Definition at line 180 of file AutomaticIRMetadataGuard.h.

Referenced by makeBaseFilename(), and makeQueryEngineFilename().

const std::string AutomaticIRMetadataGuard::ppfunc_
private

Definition at line 182 of file AutomaticIRMetadataGuard.h.

Referenced by rememberOurInstructions().

const size_t AutomaticIRMetadataGuard::ppline_
private

Definition at line 181 of file AutomaticIRMetadataGuard.h.

Referenced by rememberOurInstructions().

std::unordered_set<llvm::Instruction*> AutomaticIRMetadataGuard::preexisting_instructions_
private
bool AutomaticIRMetadataGuard::this_is_root_
private

Definition at line 188 of file AutomaticIRMetadataGuard.h.

Referenced by done().


The documentation for this class was generated from the following file: