summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2016-06-22 20:29:42 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2016-06-22 20:29:42 +0000
commit6d88fde3afcddbc7093e657eae23fdf23437b1db (patch)
treec94289078301e2e2194b6c843ac77d388d8be575 /llvm/lib
parent4a07bf63727fedea6441d5ccca8dbe26071a7c0e (diff)
downloadbcm5719-llvm-6d88fde3afcddbc7093e657eae23fdf23437b1db.tar.gz
bcm5719-llvm-6d88fde3afcddbc7093e657eae23fdf23437b1db.zip
IR: Introduce Module::global_objects().
This is a convenience iterator that allows clients to enumerate the GlobalObjects within a Module. Also start using it in a few places where it is obviously the right thing to use. Differential Revision: http://reviews.llvm.org/D21580 llvm-svn: 273470
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp14
-rw-r--r--llvm/lib/ExecutionEngine/ExecutionEngine.cpp6
-rw-r--r--llvm/lib/IR/AsmWriter.cpp7
-rw-r--r--llvm/lib/Transforms/IPO/GlobalDCE.cpp19
4 files changed, 14 insertions, 32 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index ad2f216f504..3f2ef090b86 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1173,17 +1173,11 @@ bool AsmPrinter::doFinalization(Module &M) {
// to notice uses in operands (due to constant exprs etc). This should
// happen with the MC stuff eventually.
- // Print out module-level global variables here.
- for (const auto &G : M.globals()) {
- if (!G.hasExternalWeakLinkage())
+ // Print out module-level global objects here.
+ for (const auto &GO : M.global_objects()) {
+ if (!GO.hasExternalWeakLinkage())
continue;
- OutStreamer->EmitSymbolAttribute(getSymbol(&G), MCSA_WeakReference);
- }
-
- for (const auto &F : M) {
- if (!F.hasExternalWeakLinkage())
- continue;
- OutStreamer->EmitSymbolAttribute(getSymbol(&F), MCSA_WeakReference);
+ OutStreamer->EmitSymbolAttribute(getSymbol(&GO), MCSA_WeakReference);
}
}
diff --git a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
index de3d647438b..a8e68bf49ab 100644
--- a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -235,10 +235,8 @@ void ExecutionEngine::clearAllGlobalMappings() {
void ExecutionEngine::clearGlobalMappingsFromModule(Module *M) {
MutexGuard locked(lock);
- for (Function &FI : *M)
- EEState.RemoveMapping(getMangledName(&FI));
- for (GlobalVariable &GI : M->globals())
- EEState.RemoveMapping(getMangledName(&GI));
+ for (GlobalObject &GO : M->global_objects())
+ EEState.RemoveMapping(getMangledName(&GO));
}
uint64_t ExecutionEngine::updateGlobalMapping(const GlobalValue *GV,
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 17b622458c4..0aa0b8014f0 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -2126,11 +2126,8 @@ AssemblyWriter::AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
if (!TheModule)
return;
TypePrinter.incorporateTypes(*TheModule);
- for (const Function &F : *TheModule)
- if (const Comdat *C = F.getComdat())
- Comdats.insert(C);
- for (const GlobalVariable &GV : TheModule->globals())
- if (const Comdat *C = GV.getComdat())
+ for (const GlobalObject &GO : TheModule->global_objects())
+ if (const Comdat *C = GO.getComdat())
Comdats.insert(C);
}
diff --git a/llvm/lib/Transforms/IPO/GlobalDCE.cpp b/llvm/lib/Transforms/IPO/GlobalDCE.cpp
index f30e69ccbcd..4c74698a1b6 100644
--- a/llvm/lib/Transforms/IPO/GlobalDCE.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalDCE.cpp
@@ -96,21 +96,14 @@ PreservedAnalyses GlobalDCEPass::run(Module &M, ModuleAnalysisManager &) {
ComdatMembers.insert(std::make_pair(C, &GA));
// Loop over the module, adding globals which are obviously necessary.
- for (Function &F : M) {
- Changed |= RemoveUnusedGlobalValue(F);
- // Functions with external linkage are needed if they have a body
- if (!F.isDeclaration() && !F.hasAvailableExternallyLinkage())
- if (!F.isDiscardableIfUnused())
- GlobalIsNeeded(&F);
- }
-
- for (GlobalVariable &GV : M.globals()) {
- Changed |= RemoveUnusedGlobalValue(GV);
+ for (GlobalObject &GO : M.global_objects()) {
+ Changed |= RemoveUnusedGlobalValue(GO);
+ // Functions with external linkage are needed if they have a body.
// Externally visible & appending globals are needed, if they have an
// initializer.
- if (!GV.isDeclaration() && !GV.hasAvailableExternallyLinkage())
- if (!GV.isDiscardableIfUnused())
- GlobalIsNeeded(&GV);
+ if (!GO.isDeclaration() && !GO.hasAvailableExternallyLinkage())
+ if (!GO.isDiscardableIfUnused())
+ GlobalIsNeeded(&GO);
}
for (GlobalAlias &GA : M.aliases()) {
OpenPOWER on IntegriCloud