#include "LLVMContextImpl.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/Attributes.h"
+#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Module.h"
-#include "llvm/PassSupport.h"
-#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/Regex.h"
#include <algorithm>
using namespace llvm;
-/// Notify that we finished running a pass.
-void LLVMContextImpl::notifyPassRun(LLVMContext *C, Pass *P, Module *M,
- Function *F, BasicBlock *BB) {
- for (auto const &L : RunListeners)
- L->passRun(C, P, M, F, BB);
-}
-/// Register the given PassRunListener to receive notifyPassRun()
-/// callbacks whenever a pass ran.
-void LLVMContextImpl::addRunListener(PassRunListener *L) {
- RunListeners.push_back(L);
-}
-/// Unregister a PassRunListener so that it no longer receives
-/// notifyPassRun() callbacks.
-void LLVMContextImpl::removeRunListener(PassRunListener *L) {
- auto I = std::find(RunListeners.begin(), RunListeners.end(), L);
- assert(I != RunListeners.end() && "RunListener not registered!");
- delete *I;
- RunListeners.erase(I);
-}
-
LLVMContextImpl::LLVMContextImpl(LLVMContext &C)
: TheTrueVal(nullptr), TheFalseVal(nullptr),
VoidTy(C, Type::VoidTyID),
InlineAsmDiagContext = nullptr;
DiagnosticHandler = nullptr;
DiagnosticContext = nullptr;
+ RespectDiagnosticFilters = false;
+ YieldCallback = nullptr;
+ YieldOpaqueHandle = nullptr;
NamedStructTypesUniqueID = 0;
}
-namespace {
-
-/// \brief Regular expression corresponding to the value given in the
-/// command line flag -pass-remarks. Passes whose name matches this
-/// regexp will emit a diagnostic when calling
-/// LLVMContext::emitOptimizationRemark.
-static Regex *OptimizationRemarkPattern = nullptr;
-
-struct PassRemarksOpt {
- void operator=(const std::string &Val) const {
- // Create a regexp object to match pass names for emitOptimizationRemark.
- if (!Val.empty()) {
- delete OptimizationRemarkPattern;
- OptimizationRemarkPattern = new Regex(Val);
- std::string RegexError;
- if (!OptimizationRemarkPattern->isValid(RegexError))
- report_fatal_error("Invalid regular expression '" + Val +
- "' in -pass-remarks: " + RegexError,
- false);
- }
- };
-};
-
-static PassRemarksOpt PassRemarksOptLoc;
-
-// -pass-remarks
-// Command line flag to enable LLVMContext::emitOptimizationRemark()
-// and LLVMContext::emitOptimizationNote() calls.
-static cl::opt<PassRemarksOpt, true, cl::parser<std::string>>
-PassRemarks("pass-remarks", cl::value_desc("pattern"),
- cl::desc("Enable optimization remarks from passes whose name match "
- "the given regular expression"),
- cl::Hidden, cl::location(PassRemarksOptLoc), cl::ValueRequired,
- cl::ZeroOrMore);
-}
-
-bool
-LLVMContextImpl::optimizationRemarksEnabledFor(const char *PassName) const {
- return OptimizationRemarkPattern &&
- OptimizationRemarkPattern->match(PassName);
-}
-
-
namespace {
struct DropReferences {
// Takes the value_type of a ConstantUniqueMap's internal map, whose 'second'
// is a Constant*.
- template<typename PairT>
- void operator()(const PairT &P) {
+ template <typename PairT> void operator()(const PairT &P) {
P.second->dropAllReferences();
}
};
// Free the constants. This is important to do here to ensure that they are
// freed before the LeakDetector is torn down.
std::for_each(ExprConstants.map_begin(), ExprConstants.map_end(),
- DropReferences());
+ DropFirst());
std::for_each(ArrayConstants.map_begin(), ArrayConstants.map_end(),
DropFirst());
std::for_each(StructConstants.map_begin(), StructConstants.map_end(),
// Destroy MDStrings.
DeleteContainerSeconds(MDStringCache);
-
- // Destroy all run listeners.
- for (auto &L : RunListeners)
- delete L;
- RunListeners.clear();
}
// ConstantsContext anchors