aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-12-28 20:45:51 +0000
committerChris Lattner <sabre@nondot.org>2009-12-28 20:45:51 +0000
commit0eb419800ae51d6e0e00a656ede0627483755361 (patch)
tree11dc009d755eda2b02147fc4be338d0912bce39c /lib
parent7d05c46d601cbb52be605019548c34286c02e3a3 (diff)
downloadexternal_llvm-0eb419800ae51d6e0e00a656ede0627483755361.zip
external_llvm-0eb419800ae51d6e0e00a656ede0627483755361.tar.gz
external_llvm-0eb419800ae51d6e0e00a656ede0627483755361.tar.bz2
rename getMDKind -> getMDKindID, make it autoinsert if an MD Kind
doesn't exist already, eliminate registerMDKind. Tidy up a bunch of random stuff. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92225 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Analysis/DebugInfo.cpp7
-rw-r--r--lib/AsmParser/LLParser.cpp5
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp15
-rw-r--r--lib/CodeGen/SelectionDAG/FastISel.cpp6
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp6
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp52
-rw-r--r--lib/Transforms/IPO/StripSymbols.cpp4
-rw-r--r--lib/Transforms/Utils/CloneFunction.cpp2
-rw-r--r--lib/VMCore/Metadata.cpp44
9 files changed, 51 insertions, 90 deletions
diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp
index c8cb60f..3732818 100644
--- a/lib/Analysis/DebugInfo.cpp
+++ b/lib/Analysis/DebugInfo.cpp
@@ -1119,7 +1119,7 @@ Instruction *DIFactory::InsertDbgValueIntrinsic(Value *V, Value *Offset,
void DebugInfoFinder::processModule(Module &M) {
MetadataContext &TheMetadata = M.getContext().getMetadata();
- unsigned MDDbgKind = TheMetadata.getMDKind("dbg");
+ unsigned MDDbgKind = TheMetadata.getMDKindID("dbg");
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
for (Function::iterator FI = (*I).begin(), FE = (*I).end(); FI != FE; ++FI)
@@ -1127,9 +1127,8 @@ void DebugInfoFinder::processModule(Module &M) {
++BI) {
if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(BI))
processDeclare(DDI);
- else if (MDDbgKind)
- if (MDNode *L = TheMetadata.getMD(MDDbgKind, BI))
- processLocation(DILocation(L));
+ else if (MDNode *L = TheMetadata.getMD(MDDbgKind, BI))
+ processLocation(DILocation(L));
}
NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.gv");
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp
index 48b6e87..a84336d 100644
--- a/lib/AsmParser/LLParser.cpp
+++ b/lib/AsmParser/LLParser.cpp
@@ -1123,11 +1123,8 @@ bool LLParser::ParseOptionalCustomMetadata() {
if (ParseMDNode(Node)) return true;
MetadataContext &TheMetadata = M->getContext().getMetadata();
- unsigned MDK = TheMetadata.getMDKind(Name.c_str());
- if (!MDK)
- MDK = TheMetadata.registerMDKind(Name.c_str());
+ unsigned MDK = TheMetadata.getMDKindID(Name.c_str());
MDsOnInst.push_back(std::make_pair(MDK, cast<MDNode>(Node)));
-
return false;
}
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index 9916388..0bda03e 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -840,17 +840,10 @@ bool BitcodeReader::ParseMetadata() {
(void) Kind;
for (unsigned i = 1; i != RecordLength; ++i)
Name[i-1] = Record[i];
- MetadataContext &TheMetadata = Context.getMetadata();
- unsigned ExistingKind = TheMetadata.getMDKind(Name.str());
- if (ExistingKind == 0) {
- unsigned NewKind = TheMetadata.registerMDKind(Name.str());
- (void) NewKind;
- assert (Kind == NewKind
- && "Unable to handle custom metadata mismatch!");
- } else {
- assert (ExistingKind == Kind
- && "Unable to handle custom metadata mismatch!");
- }
+
+ unsigned NewKind = Context.getMetadata().getMDKindID(Name.str());
+ assert(Kind == NewKind &&
+ "FIXME: Unable to handle custom metadata mismatch!");(void)NewKind;
break;
}
}
diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp
index 9e182ef..24a5b0d 100644
--- a/lib/CodeGen/SelectionDAG/FastISel.cpp
+++ b/lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -351,9 +351,9 @@ bool FastISel::SelectCall(User *I) {
if (MMI) {
MetadataContext &TheMetadata =
DI->getParent()->getContext().getMetadata();
- unsigned MDDbgKind = TheMetadata.getMDKind("dbg");
- MDNode *Dbg = TheMetadata.getMD(MDDbgKind, DI);
- MMI->setVariableDbgInfo(DI->getVariable(), FI, Dbg);
+ unsigned MDDbgKind = TheMetadata.getMDKindID("dbg");
+ if (MDNode *Dbg = TheMetadata.getMD(MDDbgKind, DI))
+ MMI->setVariableDbgInfo(DI->getVariable(), FI, Dbg);
}
return true;
}
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 8fe7c45..266cb64 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -4383,9 +4383,9 @@ SelectionDAGBuilder::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
if (MMI) {
MetadataContext &TheMetadata =
DI.getParent()->getContext().getMetadata();
- unsigned MDDbgKind = TheMetadata.getMDKind("dbg");
- MDNode *Dbg = TheMetadata.getMD(MDDbgKind, &DI);
- MMI->setVariableDbgInfo(Variable, FI, Dbg);
+ unsigned MDDbgKind = TheMetadata.getMDKindID("dbg");
+ if (MDNode *Dbg = TheMetadata.getMD(MDDbgKind, &DI))
+ MMI->setVariableDbgInfo(Variable, FI, Dbg);
}
return 0;
}
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index 667be90..7efd480 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -362,27 +362,25 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
/// SetDebugLoc - Update MF's and SDB's DebugLocs if debug information is
/// attached with this instruction.
-static void SetDebugLoc(unsigned MDDbgKind,
- MetadataContext &TheMetadata,
- Instruction *I,
- SelectionDAGBuilder *SDB,
- FastISel *FastIS,
- MachineFunction *MF) {
- if (!isa<DbgInfoIntrinsic>(I))
- if (MDNode *Dbg = TheMetadata.getMD(MDDbgKind, I)) {
- DILocation DILoc(Dbg);
- DebugLoc Loc = ExtractDebugLocation(DILoc, MF->getDebugLocInfo());
-
- SDB->setCurDebugLoc(Loc);
-
- if (FastIS)
- FastIS->setCurDebugLoc(Loc);
-
- // If the function doesn't have a default debug location yet, set
- // it. This is kind of a hack.
- if (MF->getDefaultDebugLoc().isUnknown())
- MF->setDefaultDebugLoc(Loc);
- }
+static void SetDebugLoc(unsigned MDDbgKind, MetadataContext &TheMetadata,
+ Instruction *I, SelectionDAGBuilder *SDB,
+ FastISel *FastIS, MachineFunction *MF) {
+ if (isa<DbgInfoIntrinsic>(I)) return;
+
+ if (MDNode *Dbg = TheMetadata.getMD(MDDbgKind, I)) {
+ DILocation DILoc(Dbg);
+ DebugLoc Loc = ExtractDebugLocation(DILoc, MF->getDebugLocInfo());
+
+ SDB->setCurDebugLoc(Loc);
+
+ if (FastIS)
+ FastIS->setCurDebugLoc(Loc);
+
+ // If the function doesn't have a default debug location yet, set
+ // it. This is kind of a hack.
+ if (MF->getDefaultDebugLoc().isUnknown())
+ MF->setDefaultDebugLoc(Loc);
+ }
}
/// ResetDebugLoc - Set MF's and SDB's DebugLocs to Unknown.
@@ -398,14 +396,13 @@ void SelectionDAGISel::SelectBasicBlock(BasicBlock *LLVMBB,
BasicBlock::iterator End,
bool &HadTailCall) {
SDB->setCurrentBasicBlock(BB);
- MetadataContext &TheMetadata = LLVMBB->getParent()->getContext().getMetadata();
- unsigned MDDbgKind = TheMetadata.getMDKind("dbg");
+ MetadataContext &TheMetadata =LLVMBB->getParent()->getContext().getMetadata();
+ unsigned MDDbgKind = TheMetadata.getMDKindID("dbg");
// Lower all of the non-terminator instructions. If a call is emitted
// as a tail call, cease emitting nodes for this block.
for (BasicBlock::iterator I = Begin; I != End && !SDB->HasTailCall; ++I) {
- if (MDDbgKind)
- SetDebugLoc(MDDbgKind, TheMetadata, I, SDB, 0, MF);
+ SetDebugLoc(MDDbgKind, TheMetadata, I, SDB, 0, MF);
if (!isa<TerminatorInst>(I)) {
SDB->visit(*I);
@@ -681,7 +678,7 @@ void SelectionDAGISel::SelectAllBasicBlocks(Function &Fn,
);
MetadataContext &TheMetadata = Fn.getContext().getMetadata();
- unsigned MDDbgKind = TheMetadata.getMDKind("dbg");
+ unsigned MDDbgKind = TheMetadata.getMDKindID("dbg");
// Iterate over all basic blocks in the function.
for (Function::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) {
@@ -779,8 +776,7 @@ void SelectionDAGISel::SelectAllBasicBlocks(Function &Fn,
break;
}
- if (MDDbgKind)
- SetDebugLoc(MDDbgKind, TheMetadata, BI, SDB, FastIS, &MF);
+ SetDebugLoc(MDDbgKind, TheMetadata, BI, SDB, FastIS, &MF);
// First try normal tablegen-generated "fast" selection.
if (FastIS->SelectInstruction(BI)) {
diff --git a/lib/Transforms/IPO/StripSymbols.cpp b/lib/Transforms/IPO/StripSymbols.cpp
index 0b5e007..b213b01 100644
--- a/lib/Transforms/IPO/StripSymbols.cpp
+++ b/lib/Transforms/IPO/StripSymbols.cpp
@@ -221,9 +221,7 @@ static bool StripDebugInfo(Module &M) {
NMD->eraseFromParent();
}
MetadataContext &TheMetadata = M.getContext().getMetadata();
- unsigned MDDbgKind = TheMetadata.getMDKind("dbg");
- if (!MDDbgKind)
- return Changed;
+ unsigned MDDbgKind = TheMetadata.getMDKindID("dbg");
for (Module::iterator MI = M.begin(), ME = M.end(); MI != ME; ++MI)
for (Function::iterator FI = MI->begin(), FE = MI->end(); FI != FE;
diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp
index 162d7b3..2f94ee1 100644
--- a/lib/Transforms/Utils/CloneFunction.cpp
+++ b/lib/Transforms/Utils/CloneFunction.cpp
@@ -422,7 +422,7 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
BasicBlock::iterator I = NewBB->begin();
LLVMContext &Context = OldFunc->getContext();
- unsigned DbgKind = Context.getMetadata().getMDKind("dbg");
+ unsigned DbgKind = Context.getMetadata().getMDKindID("dbg");
MDNode *TheCallMD = NULL;
SmallVector<Value *, 4> MDVs;
if (TheCall && TheCall->hasMetadata())
diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp
index 31e737f..a516d7b 100644
--- a/lib/VMCore/Metadata.cpp
+++ b/lib/VMCore/Metadata.cpp
@@ -261,13 +261,7 @@ private:
StringMap<unsigned> MDHandlerNames;
public:
- /// registerMDKind - Register a new metadata kind and return its ID.
- /// A metadata kind can be registered only once.
- unsigned registerMDKind(StringRef Name);
-
- /// getMDKind - Return metadata kind. If the requested metadata kind
- /// is not registered then return 0.
- unsigned getMDKind(StringRef Name) const;
+ unsigned getMDKindID(StringRef Name);
/// getMD - Get the metadata of given kind attached to an Instruction.
/// If the metadata is not found then return 0.
@@ -308,22 +302,14 @@ public:
};
}
-/// registerMDKind - Register a new metadata kind and return its ID.
-/// A metadata kind can be registered only once.
-unsigned MetadataContextImpl::registerMDKind(StringRef Name) {
- unsigned Count = MDHandlerNames.size();
- assert(MDHandlerNames.count(Name) == 0 && "Already registered MDKind!");
- return MDHandlerNames[Name] = Count + 1;
-}
-
-/// getMDKind - Return metadata kind. If the requested metadata kind
-/// is not registered then return 0.
-unsigned MetadataContextImpl::getMDKind(StringRef Name) const {
- StringMap<unsigned>::const_iterator I = MDHandlerNames.find(Name);
- if (I == MDHandlerNames.end())
- return 0;
+/// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
+unsigned MetadataContextImpl::getMDKindID(StringRef Name) {
+ unsigned &Entry = MDHandlerNames[Name];
- return I->getValue();
+ // If this is new, assign it its ID.
+ if (Entry == 0) Entry = MDHandlerNames.size();
+
+ return Entry;
}
/// addMD - Attach the metadata of given kind to an Instruction.
@@ -472,17 +458,9 @@ bool MetadataContext::isValidName(StringRef MDName) {
return true;
}
-/// registerMDKind - Register a new metadata kind and return its ID.
-/// A metadata kind can be registered only once.
-unsigned MetadataContext::registerMDKind(StringRef Name) {
- assert(isValidName(Name) && "Invalid custome metadata name!");
- return pImpl->registerMDKind(Name);
-}
-
-/// getMDKind - Return metadata kind. If the requested metadata kind
-/// is not registered then return 0.
-unsigned MetadataContext::getMDKind(StringRef Name) const {
- return pImpl->getMDKind(Name);
+/// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
+unsigned MetadataContext::getMDKindID(StringRef Name) const {
+ return pImpl->getMDKindID(Name);
}
/// getMD - Get the metadata of given kind attached to an Instruction.