comparison lib/CodeGen/GlobalMerge.cpp @ 134:3a76565eade5 LLVM5.0.1

update 5.0.1
author mir3636
date Sat, 17 Feb 2018 09:57:20 +0900
parents 803732b1fca8
children c2174574ed3a
comparison
equal deleted inserted replaced
133:c60214abe0e8 134:3a76565eade5
68 #include "llvm/ADT/Statistic.h" 68 #include "llvm/ADT/Statistic.h"
69 #include "llvm/ADT/StringRef.h" 69 #include "llvm/ADT/StringRef.h"
70 #include "llvm/ADT/Triple.h" 70 #include "llvm/ADT/Triple.h"
71 #include "llvm/ADT/Twine.h" 71 #include "llvm/ADT/Twine.h"
72 #include "llvm/CodeGen/Passes.h" 72 #include "llvm/CodeGen/Passes.h"
73 #include "llvm/CodeGen/TargetLoweringObjectFile.h"
73 #include "llvm/IR/BasicBlock.h" 74 #include "llvm/IR/BasicBlock.h"
74 #include "llvm/IR/Constants.h" 75 #include "llvm/IR/Constants.h"
75 #include "llvm/IR/DataLayout.h" 76 #include "llvm/IR/DataLayout.h"
76 #include "llvm/IR/DerivedTypes.h" 77 #include "llvm/IR/DerivedTypes.h"
77 #include "llvm/IR/Function.h" 78 #include "llvm/IR/Function.h"
86 #include "llvm/Pass.h" 87 #include "llvm/Pass.h"
87 #include "llvm/Support/Casting.h" 88 #include "llvm/Support/Casting.h"
88 #include "llvm/Support/CommandLine.h" 89 #include "llvm/Support/CommandLine.h"
89 #include "llvm/Support/Debug.h" 90 #include "llvm/Support/Debug.h"
90 #include "llvm/Support/raw_ostream.h" 91 #include "llvm/Support/raw_ostream.h"
91 #include "llvm/Target/TargetLoweringObjectFile.h"
92 #include "llvm/Target/TargetMachine.h" 92 #include "llvm/Target/TargetMachine.h"
93 #include <algorithm> 93 #include <algorithm>
94 #include <cassert> 94 #include <cassert>
95 #include <cstddef>
95 #include <cstdint> 96 #include <cstdint>
96 #include <cstddef>
97 #include <string> 97 #include <string>
98 #include <vector> 98 #include <vector>
99 99
100 using namespace llvm; 100 using namespace llvm;
101 101
384 // the number of times we encountered the sets (i.e., the number of blocks 384 // the number of times we encountered the sets (i.e., the number of blocks
385 // that use that exact set of globals). 385 // that use that exact set of globals).
386 // 386 //
387 // Multiply that by the size of the set to give us a crude profitability 387 // Multiply that by the size of the set to give us a crude profitability
388 // metric. 388 // metric.
389 std::sort(UsedGlobalSets.begin(), UsedGlobalSets.end(), 389 std::stable_sort(UsedGlobalSets.begin(), UsedGlobalSets.end(),
390 [](const UsedGlobalSet &UGS1, const UsedGlobalSet &UGS2) { 390 [](const UsedGlobalSet &UGS1, const UsedGlobalSet &UGS2) {
391 return UGS1.Globals.count() * UGS1.UsageCount < 391 return UGS1.Globals.count() * UGS1.UsageCount <
392 UGS2.Globals.count() * UGS2.UsageCount; 392 UGS2.Globals.count() * UGS2.UsageCount;
393 }); 393 });
394 394
495 const StructLayout *MergedLayout = DL.getStructLayout(MergedTy); 495 const StructLayout *MergedLayout = DL.getStructLayout(MergedTy);
496 496
497 for (ssize_t k = i, idx = 0; k != j; k = GlobalSet.find_next(k), ++idx) { 497 for (ssize_t k = i, idx = 0; k != j; k = GlobalSet.find_next(k), ++idx) {
498 GlobalValue::LinkageTypes Linkage = Globals[k]->getLinkage(); 498 GlobalValue::LinkageTypes Linkage = Globals[k]->getLinkage();
499 std::string Name = Globals[k]->getName(); 499 std::string Name = Globals[k]->getName();
500 GlobalValue::DLLStorageClassTypes DLLStorage =
501 Globals[k]->getDLLStorageClass();
500 502
501 // Copy metadata while adjusting any debug info metadata by the original 503 // Copy metadata while adjusting any debug info metadata by the original
502 // global's offset within the merged global. 504 // global's offset within the merged global.
503 MergedGV->copyMetadata(Globals[k], MergedLayout->getElementOffset(idx)); 505 MergedGV->copyMetadata(Globals[k], MergedLayout->getElementOffset(idx));
504 506
515 // variable name as it may be accessed from another object. On non-Mach-O 517 // variable name as it may be accessed from another object. On non-Mach-O
516 // we can also emit an alias for internal linkage as it's safe to do so. 518 // we can also emit an alias for internal linkage as it's safe to do so.
517 // It's not safe on Mach-O as the alias (and thus the portion of the 519 // It's not safe on Mach-O as the alias (and thus the portion of the
518 // MergedGlobals variable) may be dead stripped at link time. 520 // MergedGlobals variable) may be dead stripped at link time.
519 if (Linkage != GlobalValue::InternalLinkage || !IsMachO) { 521 if (Linkage != GlobalValue::InternalLinkage || !IsMachO) {
520 GlobalAlias::create(Tys[idx], AddrSpace, Linkage, Name, GEP, &M); 522 GlobalAlias *GA =
523 GlobalAlias::create(Tys[idx], AddrSpace, Linkage, Name, GEP, &M);
524 GA->setDLLStorageClass(DLLStorage);
521 } 525 }
522 526
523 NumMerged++; 527 NumMerged++;
524 } 528 }
525 i = j; 529 i = j;