Convert a few loops to use ranges.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209628 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2014-05-26 13:38:51 +00:00
parent 7aac65de51
commit 1322e998c1

View File

@ -476,8 +476,8 @@ static void WriteTypeTable(const ValueEnumerator &VE, BitstreamWriter &Stream) {
Stream.ExitBlock(); Stream.ExitBlock();
} }
static unsigned getEncodedLinkage(const GlobalValue *GV) { static unsigned getEncodedLinkage(const GlobalValue &GV) {
switch (GV->getLinkage()) { switch (GV.getLinkage()) {
case GlobalValue::ExternalLinkage: return 0; case GlobalValue::ExternalLinkage: return 0;
case GlobalValue::WeakAnyLinkage: return 1; case GlobalValue::WeakAnyLinkage: return 1;
case GlobalValue::AppendingLinkage: return 2; case GlobalValue::AppendingLinkage: return 2;
@ -493,8 +493,8 @@ static unsigned getEncodedLinkage(const GlobalValue *GV) {
llvm_unreachable("Invalid linkage"); llvm_unreachable("Invalid linkage");
} }
static unsigned getEncodedVisibility(const GlobalValue *GV) { static unsigned getEncodedVisibility(const GlobalValue &GV) {
switch (GV->getVisibility()) { switch (GV.getVisibility()) {
case GlobalValue::DefaultVisibility: return 0; case GlobalValue::DefaultVisibility: return 0;
case GlobalValue::HiddenVisibility: return 1; case GlobalValue::HiddenVisibility: return 1;
case GlobalValue::ProtectedVisibility: return 2; case GlobalValue::ProtectedVisibility: return 2;
@ -502,8 +502,8 @@ static unsigned getEncodedVisibility(const GlobalValue *GV) {
llvm_unreachable("Invalid visibility"); llvm_unreachable("Invalid visibility");
} }
static unsigned getEncodedDLLStorageClass(const GlobalValue *GV) { static unsigned getEncodedDLLStorageClass(const GlobalValue &GV) {
switch (GV->getDLLStorageClass()) { switch (GV.getDLLStorageClass()) {
case GlobalValue::DefaultStorageClass: return 0; case GlobalValue::DefaultStorageClass: return 0;
case GlobalValue::DLLImportStorageClass: return 1; case GlobalValue::DLLImportStorageClass: return 1;
case GlobalValue::DLLExportStorageClass: return 2; case GlobalValue::DLLExportStorageClass: return 2;
@ -511,8 +511,8 @@ static unsigned getEncodedDLLStorageClass(const GlobalValue *GV) {
llvm_unreachable("Invalid DLL storage class"); llvm_unreachable("Invalid DLL storage class");
} }
static unsigned getEncodedThreadLocalMode(const GlobalVariable *GV) { static unsigned getEncodedThreadLocalMode(const GlobalVariable &GV) {
switch (GV->getThreadLocalMode()) { switch (GV.getThreadLocalMode()) {
case GlobalVariable::NotThreadLocal: return 0; case GlobalVariable::NotThreadLocal: return 0;
case GlobalVariable::GeneralDynamicTLSModel: return 1; case GlobalVariable::GeneralDynamicTLSModel: return 1;
case GlobalVariable::LocalDynamicTLSModel: return 2; case GlobalVariable::LocalDynamicTLSModel: return 2;
@ -543,36 +543,35 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
std::map<std::string, unsigned> GCMap; std::map<std::string, unsigned> GCMap;
unsigned MaxAlignment = 0; unsigned MaxAlignment = 0;
unsigned MaxGlobalType = 0; unsigned MaxGlobalType = 0;
for (Module::const_global_iterator GV = M->global_begin(),E = M->global_end(); for (const GlobalValue &GV : M->globals()) {
GV != E; ++GV) { MaxAlignment = std::max(MaxAlignment, GV.getAlignment());
MaxAlignment = std::max(MaxAlignment, GV->getAlignment()); MaxGlobalType = std::max(MaxGlobalType, VE.getTypeID(GV.getType()));
MaxGlobalType = std::max(MaxGlobalType, VE.getTypeID(GV->getType())); if (GV.hasSection()) {
if (GV->hasSection()) {
// Give section names unique ID's. // Give section names unique ID's.
unsigned &Entry = SectionMap[GV->getSection()]; unsigned &Entry = SectionMap[GV.getSection()];
if (!Entry) { if (!Entry) {
WriteStringRecord(bitc::MODULE_CODE_SECTIONNAME, GV->getSection(), WriteStringRecord(bitc::MODULE_CODE_SECTIONNAME, GV.getSection(),
0/*TODO*/, Stream); 0/*TODO*/, Stream);
Entry = SectionMap.size(); Entry = SectionMap.size();
} }
} }
} }
for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) { for (const Function &F : *M) {
MaxAlignment = std::max(MaxAlignment, F->getAlignment()); MaxAlignment = std::max(MaxAlignment, F.getAlignment());
if (F->hasSection()) { if (F.hasSection()) {
// Give section names unique ID's. // Give section names unique ID's.
unsigned &Entry = SectionMap[F->getSection()]; unsigned &Entry = SectionMap[F.getSection()];
if (!Entry) { if (!Entry) {
WriteStringRecord(bitc::MODULE_CODE_SECTIONNAME, F->getSection(), WriteStringRecord(bitc::MODULE_CODE_SECTIONNAME, F.getSection(),
0/*TODO*/, Stream); 0/*TODO*/, Stream);
Entry = SectionMap.size(); Entry = SectionMap.size();
} }
} }
if (F->hasGC()) { if (F.hasGC()) {
// Same for GC names. // Same for GC names.
unsigned &Entry = GCMap[F->getGC()]; unsigned &Entry = GCMap[F.getGC()];
if (!Entry) { if (!Entry) {
WriteStringRecord(bitc::MODULE_CODE_GCNAME, F->getGC(), WriteStringRecord(bitc::MODULE_CODE_GCNAME, F.getGC(),
0/*TODO*/, Stream); 0/*TODO*/, Stream);
Entry = GCMap.size(); Entry = GCMap.size();
} }
@ -608,28 +607,27 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
// Emit the global variable information. // Emit the global variable information.
SmallVector<unsigned, 64> Vals; SmallVector<unsigned, 64> Vals;
for (Module::const_global_iterator GV = M->global_begin(),E = M->global_end(); for (const GlobalVariable &GV : M->globals()) {
GV != E; ++GV) {
unsigned AbbrevToUse = 0; unsigned AbbrevToUse = 0;
// GLOBALVAR: [type, isconst, initid, // GLOBALVAR: [type, isconst, initid,
// linkage, alignment, section, visibility, threadlocal, // linkage, alignment, section, visibility, threadlocal,
// unnamed_addr, externally_initialized, dllstorageclass] // unnamed_addr, externally_initialized, dllstorageclass]
Vals.push_back(VE.getTypeID(GV->getType())); Vals.push_back(VE.getTypeID(GV.getType()));
Vals.push_back(GV->isConstant()); Vals.push_back(GV.isConstant());
Vals.push_back(GV->isDeclaration() ? 0 : Vals.push_back(GV.isDeclaration() ? 0 :
(VE.getValueID(GV->getInitializer()) + 1)); (VE.getValueID(GV.getInitializer()) + 1));
Vals.push_back(getEncodedLinkage(GV)); Vals.push_back(getEncodedLinkage(GV));
Vals.push_back(Log2_32(GV->getAlignment())+1); Vals.push_back(Log2_32(GV.getAlignment())+1);
Vals.push_back(GV->hasSection() ? SectionMap[GV->getSection()] : 0); Vals.push_back(GV.hasSection() ? SectionMap[GV.getSection()] : 0);
if (GV->isThreadLocal() || if (GV.isThreadLocal() ||
GV->getVisibility() != GlobalValue::DefaultVisibility || GV.getVisibility() != GlobalValue::DefaultVisibility ||
GV->hasUnnamedAddr() || GV->isExternallyInitialized() || GV.hasUnnamedAddr() || GV.isExternallyInitialized() ||
GV->getDLLStorageClass() != GlobalValue::DefaultStorageClass) { GV.getDLLStorageClass() != GlobalValue::DefaultStorageClass) {
Vals.push_back(getEncodedVisibility(GV)); Vals.push_back(getEncodedVisibility(GV));
Vals.push_back(getEncodedThreadLocalMode(GV)); Vals.push_back(getEncodedThreadLocalMode(GV));
Vals.push_back(GV->hasUnnamedAddr()); Vals.push_back(GV.hasUnnamedAddr());
Vals.push_back(GV->isExternallyInitialized()); Vals.push_back(GV.isExternallyInitialized());
Vals.push_back(getEncodedDLLStorageClass(GV)); Vals.push_back(getEncodedDLLStorageClass(GV));
} else { } else {
AbbrevToUse = SimpleGVarAbbrev; AbbrevToUse = SimpleGVarAbbrev;
@ -640,20 +638,20 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
} }
// Emit the function proto information. // Emit the function proto information.
for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) { for (const Function &F : *M) {
// FUNCTION: [type, callingconv, isproto, linkage, paramattrs, alignment, // FUNCTION: [type, callingconv, isproto, linkage, paramattrs, alignment,
// section, visibility, gc, unnamed_addr, prefix] // section, visibility, gc, unnamed_addr, prefix]
Vals.push_back(VE.getTypeID(F->getType())); Vals.push_back(VE.getTypeID(F.getType()));
Vals.push_back(F->getCallingConv()); Vals.push_back(F.getCallingConv());
Vals.push_back(F->isDeclaration()); Vals.push_back(F.isDeclaration());
Vals.push_back(getEncodedLinkage(F)); Vals.push_back(getEncodedLinkage(F));
Vals.push_back(VE.getAttributeID(F->getAttributes())); Vals.push_back(VE.getAttributeID(F.getAttributes()));
Vals.push_back(Log2_32(F->getAlignment())+1); Vals.push_back(Log2_32(F.getAlignment())+1);
Vals.push_back(F->hasSection() ? SectionMap[F->getSection()] : 0); Vals.push_back(F.hasSection() ? SectionMap[F.getSection()] : 0);
Vals.push_back(getEncodedVisibility(F)); Vals.push_back(getEncodedVisibility(F));
Vals.push_back(F->hasGC() ? GCMap[F->getGC()] : 0); Vals.push_back(F.hasGC() ? GCMap[F.getGC()] : 0);
Vals.push_back(F->hasUnnamedAddr()); Vals.push_back(F.hasUnnamedAddr());
Vals.push_back(F->hasPrefixData() ? (VE.getValueID(F->getPrefixData()) + 1) Vals.push_back(F.hasPrefixData() ? (VE.getValueID(F.getPrefixData()) + 1)
: 0); : 0);
Vals.push_back(getEncodedDLLStorageClass(F)); Vals.push_back(getEncodedDLLStorageClass(F));
@ -663,14 +661,13 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
} }
// Emit the alias information. // Emit the alias information.
for (Module::const_alias_iterator AI = M->alias_begin(), E = M->alias_end(); for (const GlobalAlias &A : M->aliases()) {
AI != E; ++AI) {
// ALIAS: [alias type, aliasee val#, linkage, visibility] // ALIAS: [alias type, aliasee val#, linkage, visibility]
Vals.push_back(VE.getTypeID(AI->getType())); Vals.push_back(VE.getTypeID(A.getType()));
Vals.push_back(VE.getValueID(AI->getAliasee())); Vals.push_back(VE.getValueID(A.getAliasee()));
Vals.push_back(getEncodedLinkage(AI)); Vals.push_back(getEncodedLinkage(A));
Vals.push_back(getEncodedVisibility(AI)); Vals.push_back(getEncodedVisibility(A));
Vals.push_back(getEncodedDLLStorageClass(AI)); Vals.push_back(getEncodedDLLStorageClass(A));
unsigned AbbrevToUse = 0; unsigned AbbrevToUse = 0;
Stream.EmitRecord(bitc::MODULE_CODE_ALIAS, Vals, AbbrevToUse); Stream.EmitRecord(bitc::MODULE_CODE_ALIAS, Vals, AbbrevToUse);
Vals.clear(); Vals.clear();