-bool LLVMContext::RemoveDeadMetadata() {
- std::vector<WeakVH> DeadMDNodes;
- bool Changed = false;
- while (1) {
-
- for (FoldingSet<MDNode>::iterator
- I = pImpl->MDNodeSet.begin(),
- E = pImpl->MDNodeSet.end(); I != E; ++I) {
- MDNode *N = &(*I);
- if (N->use_empty())
- DeadMDNodes.push_back(WeakVH(N));
- }
-
- if (DeadMDNodes.empty())
- return Changed;
-
- while (!DeadMDNodes.empty()) {
- Value *V = DeadMDNodes.back(); DeadMDNodes.pop_back();
- if (const MDNode *N = dyn_cast_or_null<MDNode>(V))
- if (N->use_empty())
- delete N;
- }
+void LLVMContext::emitError(const Twine &ErrorStr) {
+ emitError(0U, ErrorStr);
+}
+
+void LLVMContext::emitError(const Instruction *I, const Twine &ErrorStr) {
+ unsigned LocCookie = 0;
+ if (const MDNode *SrcLoc = I->getMetadata("srcloc")) {
+ if (SrcLoc->getNumOperands() != 0)
+ if (const ConstantInt *CI = dyn_cast<ConstantInt>(SrcLoc->getOperand(0)))
+ LocCookie = CI->getZExtValue();
+ }
+ return emitError(LocCookie, ErrorStr);
+}
+
+void LLVMContext::emitError(unsigned LocCookie, const Twine &ErrorStr) {
+ // If there is no error handler installed, just print the error and exit.
+ if (pImpl->InlineAsmDiagHandler == 0) {
+ errs() << "error: " << ErrorStr << "\n";
+ exit(1);
+ }
+
+ // If we do have an error handler, we can report the error and keep going.
+ SMDiagnostic Diag("", SourceMgr::DK_Error, ErrorStr.str());
+
+ pImpl->InlineAsmDiagHandler(Diag, pImpl->InlineAsmDiagContext, LocCookie);
+}
+
+//===----------------------------------------------------------------------===//
+// Metadata Kind Uniquing
+//===----------------------------------------------------------------------===//
+
+#ifndef NDEBUG
+/// isValidName - Return true if Name is a valid custom metadata handler name.
+static bool isValidName(StringRef MDName) {
+ if (MDName.empty())
+ return false;
+
+ if (!std::isalpha(MDName[0]))
+ return false;
+
+ for (StringRef::iterator I = MDName.begin() + 1, E = MDName.end(); I != E;
+ ++I) {
+ if (!std::isalnum(*I) && *I != '_' && *I != '-' && *I != '.')
+ return false;