mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 04:30:23 +00:00
Simplify code that chooses when to enumerate function-local metadata operands
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93446 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3cd7c3db99
commit
d7e6457c3f
@ -91,8 +91,13 @@ ValueEnumerator::ValueEnumerator(const Module *M) {
|
||||
for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
|
||||
for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E;++I){
|
||||
for (User::const_op_iterator OI = I->op_begin(), E = I->op_end();
|
||||
OI != E; ++OI)
|
||||
EnumerateOperandType(*OI, true);
|
||||
OI != E; ++OI) {
|
||||
if (MDNode *MD = dyn_cast<MDNode>(*OI))
|
||||
if (MD->isFunctionLocal())
|
||||
// These will get enumerated during function-incorporation.
|
||||
continue;
|
||||
EnumerateOperandType(*OI);
|
||||
}
|
||||
EnumerateType(I->getType());
|
||||
if (const CallInst *CI = dyn_cast<CallInst>(I))
|
||||
EnumerateAttributes(CI->getAttributes());
|
||||
@ -103,7 +108,7 @@ ValueEnumerator::ValueEnumerator(const Module *M) {
|
||||
MDs.clear();
|
||||
I->getAllMetadata(MDs);
|
||||
for (unsigned i = 0, e = MDs.size(); i != e; ++i)
|
||||
EnumerateMetadata(MDs[i].second, true);
|
||||
EnumerateMetadata(MDs[i].second);
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,7 +229,7 @@ void ValueEnumerator::EnumerateNamedMDNode(const NamedMDNode *MD) {
|
||||
MDValueMap[MD] = Values.size();
|
||||
}
|
||||
|
||||
void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD, bool isGlobal) {
|
||||
void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD) {
|
||||
// Check to see if it's already in!
|
||||
unsigned &MDValueID = MDValueMap[MD];
|
||||
if (MDValueID) {
|
||||
@ -237,16 +242,14 @@ void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD, bool isGlobal) {
|
||||
EnumerateType(MD->getType());
|
||||
|
||||
if (const MDNode *N = dyn_cast<MDNode>(MD)) {
|
||||
if ((isGlobal && !N->isFunctionLocal()) ||
|
||||
(!isGlobal && N->isFunctionLocal())) {
|
||||
MDValues.push_back(std::make_pair(MD, 1U));
|
||||
MDValueMap[MD] = MDValues.size();
|
||||
MDValueID = MDValues.size();
|
||||
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
|
||||
if (Value *V = N->getOperand(i))
|
||||
EnumerateValue(V);
|
||||
else
|
||||
EnumerateType(Type::getVoidTy(MD->getContext()));
|
||||
MDValues.push_back(std::make_pair(MD, 1U));
|
||||
MDValueMap[MD] = MDValues.size();
|
||||
MDValueID = MDValues.size();
|
||||
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
|
||||
if (Value *V = N->getOperand(i))
|
||||
EnumerateValue(V);
|
||||
else
|
||||
EnumerateType(Type::getVoidTy(MD->getContext()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -257,10 +260,10 @@ void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD, bool isGlobal) {
|
||||
MDValueID = MDValues.size();
|
||||
}
|
||||
|
||||
void ValueEnumerator::EnumerateValue(const Value *V, bool isGlobal) {
|
||||
void ValueEnumerator::EnumerateValue(const Value *V) {
|
||||
assert(!V->getType()->isVoidTy() && "Can't insert void values!");
|
||||
if (const MetadataBase *MB = dyn_cast<MetadataBase>(V))
|
||||
return EnumerateMetadata(MB, isGlobal);
|
||||
return EnumerateMetadata(MB);
|
||||
else if (const NamedMDNode *NMD = dyn_cast<NamedMDNode>(V))
|
||||
return EnumerateNamedMDNode(NMD);
|
||||
|
||||
@ -294,7 +297,7 @@ void ValueEnumerator::EnumerateValue(const Value *V, bool isGlobal) {
|
||||
for (User::const_op_iterator I = C->op_begin(), E = C->op_end();
|
||||
I != E; ++I)
|
||||
if (!isa<BasicBlock>(*I)) // Don't enumerate BB operand to BlockAddress.
|
||||
EnumerateValue(*I, isGlobal);
|
||||
EnumerateValue(*I);
|
||||
|
||||
// Finally, add the value. Doing this could make the ValueID reference be
|
||||
// dangling, don't reuse it.
|
||||
@ -331,14 +334,9 @@ void ValueEnumerator::EnumerateType(const Type *Ty) {
|
||||
|
||||
// Enumerate the types for the specified value. If the value is a constant,
|
||||
// walk through it, enumerating the types of the constant.
|
||||
void ValueEnumerator::EnumerateOperandType(const Value *V, bool isGlobal) {
|
||||
void ValueEnumerator::EnumerateOperandType(const Value *V) {
|
||||
EnumerateType(V->getType());
|
||||
|
||||
// During function-incorporation, only enumerate metadata operands.
|
||||
if (!isGlobal)
|
||||
if (const MetadataBase *MB = dyn_cast<MetadataBase>(V))
|
||||
return EnumerateMetadata(MB, isGlobal);
|
||||
|
||||
if (const Constant *C = dyn_cast<Constant>(V)) {
|
||||
// If this constant is already enumerated, ignore it, we know its type must
|
||||
// be enumerated.
|
||||
@ -353,13 +351,13 @@ void ValueEnumerator::EnumerateOperandType(const Value *V, bool isGlobal) {
|
||||
// blockaddress.
|
||||
if (isa<BasicBlock>(Op)) continue;
|
||||
|
||||
EnumerateOperandType(cast<Constant>(Op), isGlobal);
|
||||
EnumerateOperandType(cast<Constant>(Op));
|
||||
}
|
||||
|
||||
if (const MDNode *N = dyn_cast<MDNode>(V)) {
|
||||
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
|
||||
if (Value *Elem = N->getOperand(i))
|
||||
EnumerateOperandType(Elem, isGlobal);
|
||||
EnumerateOperandType(Elem);
|
||||
}
|
||||
} else if (isa<MDString>(V) || isa<MDNode>(V))
|
||||
EnumerateValue(V);
|
||||
@ -414,7 +412,11 @@ void ValueEnumerator::incorporateFunction(const Function &F) {
|
||||
for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) {
|
||||
for (User::const_op_iterator OI = I->op_begin(), E = I->op_end();
|
||||
OI != E; ++OI) {
|
||||
EnumerateOperandType(*OI, false);
|
||||
if (MDNode *MD = dyn_cast<MDNode>(*OI))
|
||||
if (!MD->isFunctionLocal())
|
||||
// These were already enumerated during ValueEnumerator creation.
|
||||
continue;
|
||||
EnumerateOperandType(*OI);
|
||||
}
|
||||
if (!I->getType()->isVoidTy())
|
||||
EnumerateValue(I);
|
||||
|
@ -127,11 +127,11 @@ public:
|
||||
private:
|
||||
void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
|
||||
|
||||
void EnumerateMetadata(const MetadataBase *MD, bool isGlobal);
|
||||
void EnumerateMetadata(const MetadataBase *MD);
|
||||
void EnumerateNamedMDNode(const NamedMDNode *NMD);
|
||||
void EnumerateValue(const Value *V, bool isGlobal = true);
|
||||
void EnumerateValue(const Value *V);
|
||||
void EnumerateType(const Type *T);
|
||||
void EnumerateOperandType(const Value *V, bool isGlobal);
|
||||
void EnumerateOperandType(const Value *V);
|
||||
void EnumerateAttributes(const AttrListPtr &PAL);
|
||||
|
||||
void EnumerateTypeSymbolTable(const TypeSymbolTable &ST);
|
||||
|
Loading…
Reference in New Issue
Block a user