Computer Laboratory

instrument.cpp File Reference
#include "Assertion.h"
#include "Callee.h"
#include "Caller.h"
#include "Debug.h"
#include "FieldReference.h"
#include "Manifest.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/CodeGen/CommandFlags.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Assembly/PrintModulePass.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Target/TargetLibraryInfo.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/SystemUtils.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/PassManager.h"
+ Include dependency graph for instrument.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 85 of file instrument.cpp.

References tesla::Manifest::load(), and tesla::panic().

85  {
86  llvm::PrettyStackTraceProgram X(argc, argv);
87 
88  llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
89  LLVMContext &Context = getGlobalContext();
90 
91  cl::ParseCommandLineOptions(argc, argv, "TESLA bitcode instrumenter\n");
92 
93  SMDiagnostic Err;
94 
95  // Load TESLA manifest file.
96  OwningPtr<tesla::Manifest> Manifest(tesla::Manifest::load(llvm::errs()));
97  if (!Manifest)
98  tesla::panic("unable to load TESLA manifest");
99 
100  // Load the input module...
101  std::auto_ptr<Module> M;
102  M.reset(ParseIRFile(InputFilename, Err, Context));
103 
104  if (M.get() == 0) {
105  Err.print(argv[0], errs());
106  return 1;
107  }
108 
109  // Output stream...
110  OwningPtr<tool_output_file> Out;
111  if (OutputFilename.empty())
112  OutputFilename = "-";
113 
114  std::string ErrorInfo;
115  Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
116  raw_fd_ostream::F_Binary));
117  if (!ErrorInfo.empty()) {
118  errs() << ErrorInfo << '\n';
119  return 1;
120  }
121 
122  // If the output is set to be emitted to standard out, and standard out is a
123  // console, print out a warning message and refuse to do it. We don't
124  // impress anyone by spewing tons of binary goo to a terminal.
125  bool NoOutput = false;
126  if (!Force && !OutputAssembly)
127  if (CheckBitcodeOutputToConsole(Out->os(), true))
128  NoOutput = true;
129 
130  // Create a PassManager to hold and optimize the collection of passes we are
131  // about to build.
132  //
133  PassManager Passes;
134 
135  // Add an appropriate TargetLibraryInfo pass for the module's triple.
136  TargetLibraryInfo *TLI = new TargetLibraryInfo(Triple(M->getTargetTriple()));
137  Passes.add(TLI);
138 
139  // Add an appropriate DataLayout instance for this module.
140  DataLayout *TD = 0;
141  const std::string &ModuleDataLayout = M.get()->getDataLayout();
142  if (!ModuleDataLayout.empty())
143  TD = new DataLayout(ModuleDataLayout);
144 
145  if (TD)
146  Passes.add(TD);
147 
148  // Just add TESLA instrumentation passes.
149  addPass(Passes, new tesla::AssertionSiteInstrumenter(*Manifest, SuppressDI));
150  addPass(Passes, new tesla::FnCalleeInstrumenter(*Manifest, SuppressDI));
151  addPass(Passes, new tesla::FnCallerInstrumenter(*Manifest, SuppressDI));
152  addPass(Passes, new tesla::FieldReferenceInstrumenter(*Manifest, SuppressDI));
153 
154  // Write bitcode or assembly to the output as the last step...
155  if (!NoOutput) {
156  if (OutputAssembly)
157  Passes.add(createPrintModulePass(&Out->os()));
158  else
159  Passes.add(createBitcodeWriterPass(Out->os()));
160  }
161 
162  // Before executing passes, print the final values of the LLVM options.
163  cl::PrintOptionValues();
164 
165  // Now that we have all of the passes ready, run them.
166  Passes.run(*M.get());
167 
168  // Declare success.
169  if (!NoOutput)
170  Out->keep();
171 
172  return 0;
173 }

+ Here is the call graph for this function: