OmniSciDB  ba1bac9284
 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_
 
bool enabled_
 

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 31 of file AutomaticIRMetadataGuard.h.

Member Typedef Documentation

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

Definition at line 181 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 33 of file AutomaticIRMetadataGuard.h.

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

37  : cgen_state_(cgen_state)
38  , ppfile_(ppfile)
39  , ppline_(ppline)
40  , ppfunc_(ppfunc)
41  , our_instructions_(nullptr)
42  , done_(false)
45  if (enabled_) {
50  }
51  }
void rememberPreexistingInstructions() noexcept
llvm::Module * module_
Definition: CgenState.h:324
static std::unordered_map< CgenState *, OurInstructions > instructions_
bool g_enable_automatic_ir_metadata
Definition: Execute.cpp:139
#define CHECK(condition)
Definition: Logger.h:206

+ Here is the call graph for this function:

AutomaticIRMetadataGuard::~AutomaticIRMetadataGuard ( )
inline

Definition at line 53 of file AutomaticIRMetadataGuard.h.

References done().

53 { done(); }

+ Here is the call graph for this function:

Member Function Documentation

void AutomaticIRMetadataGuard::done ( )
inlinenoexcept

Definition at line 55 of file AutomaticIRMetadataGuard.h.

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

Referenced by ~AutomaticIRMetadataGuard().

55  {
56  if (enabled_ && !done_) {
58  if (this_is_root_) {
61  }
62  done_ = true;
63  }
64  }
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 135 of file AutomaticIRMetadataGuard.h.

References ppfile_, and split().

Referenced by rememberOurInstructions().

135  {
136  std::vector<std::string> fnames = split(ppfile_, "/");
137  if (!fnames.empty()) {
138  return fnames.back();
139  }
140  return ppfile_;
141  }
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 143 of file AutomaticIRMetadataGuard.h.

References f, ppfile_, and split().

Referenced by rememberOurInstructions().

143  {
144  std::vector<std::string> fnames = split(ppfile_, "/");
145  bool copying{false};
146  std::string f;
147  for (auto n : fnames) {
148  if (copying && !n.empty()) {
149  if (!f.empty()) {
150  f += "/";
151  }
152  f += n;
153  }
154  if (n == "QueryEngine") {
155  copying = true;
156  }
157  }
158  if (f.empty() && fnames.size() > 0) {
159  f = fnames.back();
160  } else if (f.empty()) {
161  f = ppfile_;
162  }
163  return f;
164  }
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
char * f

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AutomaticIRMetadataGuard::markInstructions ( )
inlinenoexcept

Definition at line 110 of file AutomaticIRMetadataGuard.h.

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

Referenced by done().

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

+ Here is the caller graph for this function:

void AutomaticIRMetadataGuard::rememberOurInstructions ( )
inlinenoexcept

Definition at line 82 of file AutomaticIRMetadataGuard.h.

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

Referenced by done().

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

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

Referenced by AutomaticIRMetadataGuard().

66  {
67  // iterate over all LLVM instructions in the module
68  for (auto func_it = cgen_state_->module_->begin();
69  func_it != cgen_state_->module_->end();
70  ++func_it) {
71  for (auto bb_it = func_it->begin(); bb_it != func_it->end(); ++bb_it) {
72  for (auto instr_it = bb_it->begin(); instr_it != bb_it->end(); ++instr_it) {
73  // remember all the instructions that already existed
74  // before this guard object was constructed
75  CHECK_EQ(preexisting_instructions_.count(&*instr_it), 0U);
76  preexisting_instructions_.insert(&*instr_it);
77  }
78  }
79  }
80  }
#define CHECK_EQ(x, y)
Definition: Logger.h:214
llvm::Module * module_
Definition: CgenState.h:324
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 166 of file AutomaticIRMetadataGuard.h.

Referenced by rememberOurInstructions().

166  {
167  static const std::unordered_set<std::string::value_type> allowed_punct{'_', '.'};
168  for (auto& ch : text) {
169  if (std::ispunct(ch) && !allowed_punct.count(ch)) {
170  ch = '_';
171  }
172  }
173  return text;
174  }

+ 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 198 of file AutomaticIRMetadataGuard.h.

Referenced by markInstructions().

bool AutomaticIRMetadataGuard::done_
private

Definition at line 192 of file AutomaticIRMetadataGuard.h.

Referenced by done().

bool AutomaticIRMetadataGuard::enabled_
private

Definition at line 194 of file AutomaticIRMetadataGuard.h.

Referenced by AutomaticIRMetadataGuard(), and done().

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

Definition at line 196 of file AutomaticIRMetadataGuard.h.

Referenced by AutomaticIRMetadataGuard(), and done().

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

Definition at line 185 of file AutomaticIRMetadataGuard.h.

Referenced by makeBaseFilename(), and makeQueryEngineFilename().

const std::string AutomaticIRMetadataGuard::ppfunc_
private

Definition at line 187 of file AutomaticIRMetadataGuard.h.

Referenced by rememberOurInstructions().

const size_t AutomaticIRMetadataGuard::ppline_
private

Definition at line 186 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 193 of file AutomaticIRMetadataGuard.h.

Referenced by done().


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