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
This commit is contained in:
Chris Lattner 2009-12-28 20:45:51 +00:00
parent 7d05c46d60
commit 0eb419800a
11 changed files with 59 additions and 108 deletions

View File

@ -197,32 +197,25 @@ public:
};
//===----------------------------------------------------------------------===//
/// MetadataContext -
/// MetadataContext handles uniquing and assignment of IDs for custom metadata
/// types. Custom metadata handler names do not contain spaces. And the name
/// must start with an alphabet. The regular expression used to check name
/// is [a-zA-Z$._][a-zA-Z$._0-9]*
/// MetadataContext - MetadataContext handles uniquing and assignment of IDs for
/// custom metadata types.
///
class MetadataContext {
// DO NOT IMPLEMENT
MetadataContext(MetadataContext&);
void operator=(MetadataContext&);
MetadataContext(MetadataContext&); // DO NOT IMPLEMENT
void operator=(MetadataContext&); // DO NOT IMPLEMENT
MetadataContextImpl *const pImpl;
public:
MetadataContext();
~MetadataContext();
/// 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;
/// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
unsigned getMDKindID(StringRef Name) const;
/// isValidName - Return true if Name is a valid custom metadata handler name.
static bool isValidName(StringRef Name);
#if 1
/// getMD - Get the metadata of given kind attached to an Instruction.
/// If the metadata is not found then return 0.
MDNode *getMD(unsigned Kind, const Instruction *Inst);
@ -239,6 +232,7 @@ public:
/// removeAllMetadata - Remove all metadata attached with an instruction.
void removeAllMetadata(Instruction *Inst);
#endif
/// copyMD - If metadata is attached with Instruction In1 then attach
/// the same metadata to In2.

View File

@ -137,9 +137,7 @@ public:
/// information.
void SetCurrentDebugLocation(MDNode *L) {
if (MDKind == 0)
MDKind = Context.getMetadata().getMDKind("dbg");
if (MDKind == 0)
MDKind = Context.getMetadata().registerMDKind("dbg");
MDKind = Context.getMetadata().getMDKindID("dbg");
CurDbgLocation = L;
}
@ -154,9 +152,7 @@ public:
/// SetDebugLocation - Set location information for the given instruction.
void SetDebugLocation(Instruction *I, MDNode *Loc) {
if (MDKind == 0)
MDKind = Context.getMetadata().getMDKind("dbg");
if (MDKind == 0)
MDKind = Context.getMetadata().registerMDKind("dbg");
MDKind = Context.getMetadata().getMDKindID("dbg");
Context.getMetadata().addMD(MDKind, Loc, I);
}

View File

@ -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");

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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());
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);
SDB->setCurDebugLoc(Loc);
if (FastIS)
FastIS->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);
}
// 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)) {

View File

@ -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;

View File

@ -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())

View File

@ -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;
}
/// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
unsigned MetadataContextImpl::getMDKindID(StringRef Name) {
unsigned &Entry = MDHandlerNames[Name];
/// 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;
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.