// Important things that make up a function!
BasicBlockListType BasicBlocks; ///< The basic blocks
mutable ArgumentListType ArgumentList; ///< The formal arguments
- ValueSymbolTable *SymTab; ///< Symbol table of args/instructions
+ std::unique_ptr<ValueSymbolTable>
+ SymTab; ///< Symbol table of args/instructions
AttributeSet AttributeSets; ///< Parameter attributes
/*
//===--------------------------------------------------------------------===//
// Symbol Table Accessing functions...
- /// getSymbolTable() - Return the symbol table...
+ /// getSymbolTable() - Return the symbol table if any, otherwise nullptr.
///
- inline ValueSymbolTable &getValueSymbolTable() { return *SymTab; }
- inline const ValueSymbolTable &getValueSymbolTable() const { return *SymTab; }
+ inline ValueSymbolTable *getValueSymbolTable() { return SymTab.get(); }
+ inline const ValueSymbolTable *getValueSymbolTable() const {
+ return SymTab.get();
+ }
//===--------------------------------------------------------------------===//
// BasicBlock iterator forwarding functions
Value *LLParser::PerFunctionState::GetVal(const std::string &Name, Type *Ty,
LocTy Loc) {
// Look this name up in the normal function symbol table.
- Value *Val = F.getValueSymbolTable().lookup(Name);
+ Value *Val = F.getValueSymbolTable()->lookup(Name);
// If this is a forward reference for the value, see if we already created a
// forward ref record.
return Error(Label.Loc, "cannot take address of numeric label after "
"the function is defined");
BB = dyn_cast_or_null<BasicBlock>(
- F->getValueSymbolTable().lookup(Label.StrVal));
+ F->getValueSymbolTable()->lookup(Label.StrVal));
if (!BB)
return Error(Label.Loc, "referenced value is not a basic block");
}
return Error(Label.Loc, "invalid numeric label in uselistorder_bb");
if (Label.Kind != ValID::t_LocalName)
return Error(Label.Loc, "expected basic block name in uselistorder_bb");
- Value *V = F->getValueSymbolTable().lookup(Label.StrVal);
+ Value *V = F->getValueSymbolTable()->lookup(Label.StrVal);
if (!V)
return Error(Label.Loc, "invalid basic block in uselistorder_bb");
if (!isa<BasicBlock>(V))
}
// Emit names for all the instructions etc.
- writeValueSymbolTable(F.getValueSymbolTable());
+ if (auto *Symtab = F.getValueSymbolTable())
+ writeValueSymbolTable(*Symtab);
if (NeedsMetadataAttachment)
writeFunctionMetadataAttachment(F);
if (!Name.empty()) {
BB = dyn_cast_or_null<BasicBlock>(
- MF.getFunction()->getValueSymbolTable().lookup(Name));
+ MF.getFunction()->getValueSymbolTable()->lookup(Name));
if (!BB)
return error(Loc, Twine("basic block '") + Name +
"' is not defined in the function '" +
switch (Token.kind()) {
case MIToken::NamedIRBlock: {
BB = dyn_cast_or_null<BasicBlock>(
- F.getValueSymbolTable().lookup(Token.stringValue()));
+ F.getValueSymbolTable()->lookup(Token.stringValue()));
if (!BB)
return error(Twine("use of undefined IR block '") + Token.range() + "'");
break;
bool MIParser::parseIRValue(const Value *&V) {
switch (Token.kind()) {
case MIToken::NamedIRValue: {
- V = MF.getFunction()->getValueSymbolTable().lookup(Token.stringValue());
+ V = MF.getFunction()->getValueSymbolTable()->lookup(Token.stringValue());
break;
}
case MIToken::IRValue: {
const yaml::StringValue &Name = Object.Name;
if (!Name.Value.empty()) {
Alloca = dyn_cast_or_null<AllocaInst>(
- F.getValueSymbolTable().lookup(Name.Value));
+ F.getValueSymbolTable()->lookup(Name.Value));
if (!Alloca)
return error(Name.SourceRange.Start,
"alloca instruction named '" + Name.Value +
ValueSymbolTable *BasicBlock::getValueSymbolTable() {
if (Function *F = getParent())
- return &F->getValueSymbolTable();
+ return F->getValueSymbolTable();
return nullptr;
}
assert(FunctionType::isValidReturnType(getReturnType()) &&
"invalid return type");
setGlobalObjectSubClassData(0);
- SymTab = new ValueSymbolTable();
+
+ // We only need a symbol table for a function if the context keeps value names
+ if (!getContext().shouldDiscardValueNames())
+ SymTab = make_unique<ValueSymbolTable>();
// If the function has arguments, mark them as lazily built.
if (Ty->getNumParams())
// Delete all of the method arguments and unlink from symbol table...
ArgumentList.clear();
- delete SymTab;
// Remove the function from the on-the-side GC table.
clearGC();
if (Instruction *I = dyn_cast<Instruction>(V)) {
if (BasicBlock *P = I->getParent())
if (Function *PP = P->getParent())
- ST = &PP->getValueSymbolTable();
+ ST = PP->getValueSymbolTable();
} else if (BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
if (Function *P = BB->getParent())
- ST = &P->getValueSymbolTable();
+ ST = P->getValueSymbolTable();
} else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
if (Module *P = GV->getParent())
ST = &P->getValueSymbolTable();
} else if (Argument *A = dyn_cast<Argument>(V)) {
if (Function *P = A->getParent())
- ST = &P->getValueSymbolTable();
+ ST = P->getValueSymbolTable();
} else {
assert(isa<Constant>(V) && "Unknown value type!");
return true; // no name is setable for this.
if (I.hasLocalLinkage() && llvmUsedValues.count(&I) == 0)
if (!PreserveDbgInfo || !I.getName().startswith("llvm.dbg"))
I.setName(""); // Internal symbols can't participate in linkage
- StripSymtab(I.getValueSymbolTable(), PreserveDbgInfo);
+ if (auto *Symtab = I.getValueSymbolTable())
+ StripSymtab(*Symtab, PreserveDbgInfo);
}
// Remove all names from types.
const ValueSymbolTable &GST = M->getValueSymbolTable();
for (unsigned i = 0, e = BlockInfo.size(); i != e; ++i) {
Function *F = cast<Function>(GST.lookup(BlockInfo[i].first));
- ValueSymbolTable &ST = F->getValueSymbolTable();
- Value *V = ST.lookup(BlockInfo[i].second);
+ Value *V = F->getValueSymbolTable()->lookup(BlockInfo[i].second);
if (V && V->getType() == Type::getLabelTy(V->getContext()))
BBs.push_back(cast<BasicBlock>(V));
}
const ValueSymbolTable &GST = M->getValueSymbolTable();
for (auto &BI : BlockInfo) {
auto *F = cast<Function>(GST.lookup(BI.first));
- ValueSymbolTable &ST = F->getValueSymbolTable();
- Value *V = ST.lookup(BI.second);
+ Value *V = F->getValueSymbolTable()->lookup(BI.second);
if (V && V->getType() == Type::getLabelTy(V->getContext()))
BBs.push_back(cast<BasicBlock>(V));
}
const ValueSymbolTable &GST = M->getValueSymbolTable();
for (auto &BI : BlockInfo) {
auto *F = cast<Function>(GST.lookup(BI.first));
- ValueSymbolTable &ST = F->getValueSymbolTable();
- Value *V = ST.lookup(BI.second);
+ Value *V = F->getValueSymbolTable()->lookup(BI.second);
if (V && V->getType() == Type::getLabelTy(V->getContext()))
BBs.push_back(cast<BasicBlock>(V));
}