mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-03-15 22:32:35 +00:00
Rename isWeakForLinker to mayBeOverridden. Use it
instead of hasWeakLinkage in a bunch of optimization passes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56782 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
7ab5799f75
commit
5df3186f59
@ -111,9 +111,10 @@ public:
|
||||
void setLinkage(LinkageTypes LT) { Linkage = LT; }
|
||||
LinkageTypes getLinkage() const { return Linkage; }
|
||||
|
||||
/// isWeakForLinker - Determines if symbol is weak for linker having weak or
|
||||
/// linkonce or common or extweak LLVM linkage.
|
||||
bool isWeakForLinker() const {
|
||||
/// mayBeOverridden - Whether the definition of this global may be replaced
|
||||
/// at link time. For example, if a function has weak linkage then the code
|
||||
/// defining it may be replaced by different code.
|
||||
bool mayBeOverridden() const {
|
||||
return (Linkage == WeakLinkage ||
|
||||
Linkage == LinkOnceLinkage ||
|
||||
Linkage == CommonLinkage ||
|
||||
|
@ -477,7 +477,7 @@ static bool GetLinkageResult(GlobalValue *Dest, const GlobalValue *Src,
|
||||
"': can only link appending global with another appending global!");
|
||||
LinkFromSrc = true; // Special cased.
|
||||
LT = Src->getLinkage();
|
||||
} else if (Src->isWeakForLinker()) {
|
||||
} else if (Src->mayBeOverridden()) {
|
||||
// At this point we know that Dest has LinkOnce, External*, Weak, Common,
|
||||
// or DLL* linkage.
|
||||
if ((Dest->hasLinkOnceLinkage() &&
|
||||
@ -489,7 +489,7 @@ static bool GetLinkageResult(GlobalValue *Dest, const GlobalValue *Src,
|
||||
LinkFromSrc = false;
|
||||
LT = Dest->getLinkage();
|
||||
}
|
||||
} else if (Dest->isWeakForLinker()) {
|
||||
} else if (Dest->mayBeOverridden()) {
|
||||
// At this point we know that Src has External* or DLL* linkage.
|
||||
if (Src->hasExternalWeakLinkage()) {
|
||||
LinkFromSrc = false;
|
||||
@ -757,7 +757,7 @@ static bool LinkAlias(Module *Dest, const Module *Src,
|
||||
} else if (GlobalVariable *DGVar = dyn_cast_or_null<GlobalVariable>(DGV)) {
|
||||
// The only allowed way is to link alias with external declaration or weak
|
||||
// symbol..
|
||||
if (DGVar->isDeclaration() || DGVar->isWeakForLinker()) {
|
||||
if (DGVar->isDeclaration() || DGVar->mayBeOverridden()) {
|
||||
// But only if aliasee is global too...
|
||||
if (!isa<GlobalVariable>(DAliasee))
|
||||
return Error(Err, "Global-Alias Collision on '" + SGA->getName() +
|
||||
@ -786,7 +786,7 @@ static bool LinkAlias(Module *Dest, const Module *Src,
|
||||
} else if (Function *DF = dyn_cast_or_null<Function>(DGV)) {
|
||||
// The only allowed way is to link alias with external declaration or weak
|
||||
// symbol...
|
||||
if (DF->isDeclaration() || DF->isWeakForLinker()) {
|
||||
if (DF->isDeclaration() || DF->mayBeOverridden()) {
|
||||
// But only if aliasee is function too...
|
||||
if (!isa<Function>(DAliasee))
|
||||
return Error(Err, "Function-Alias Collision on '" + SGA->getName() +
|
||||
@ -862,10 +862,10 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src,
|
||||
if (DGV->getInitializer() != SInit)
|
||||
return Error(Err, "Global Variable Collision on '" + SGV->getName() +
|
||||
"': global variables have different initializers");
|
||||
} else if (DGV->isWeakForLinker()) {
|
||||
} else if (DGV->mayBeOverridden()) {
|
||||
// Nothing is required, mapped values will take the new global
|
||||
// automatically.
|
||||
} else if (SGV->isWeakForLinker()) {
|
||||
} else if (SGV->mayBeOverridden()) {
|
||||
// Nothing is required, mapped values will take the new global
|
||||
// automatically.
|
||||
} else if (DGV->hasAppendingLinkage()) {
|
||||
|
@ -871,7 +871,7 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
||||
}
|
||||
}
|
||||
|
||||
if (GVar->hasInternalLinkage() || GVar->isWeakForLinker()) {
|
||||
if (GVar->hasInternalLinkage() || GVar->mayBeOverridden()) {
|
||||
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
|
||||
|
||||
if (TAI->getLCOMMDirective() != NULL) {
|
||||
|
@ -73,7 +73,7 @@ DarwinTargetAsmInfo::emitUsedDirectiveFor(const GlobalValue* GV,
|
||||
const Section*
|
||||
DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
|
||||
SectionKind::Kind Kind = SectionKindForGlobal(GV);
|
||||
bool isWeak = GV->isWeakForLinker();
|
||||
bool isWeak = GV->mayBeOverridden();
|
||||
bool isNonStatic = (DTM->getRelocationModel() != Reloc::Static);
|
||||
|
||||
switch (Kind) {
|
||||
|
@ -55,7 +55,7 @@ ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
|
||||
return getNamedSection(Name.c_str(), Flags);
|
||||
}
|
||||
} else if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) {
|
||||
if (GVar->isWeakForLinker()) {
|
||||
if (GVar->mayBeOverridden()) {
|
||||
std::string Name = UniqueSectionForGlobal(GVar, Kind);
|
||||
unsigned Flags = SectionFlagsForGlobal(GVar, Name.c_str());
|
||||
return getNamedSection(Name.c_str(), Flags);
|
||||
|
@ -275,7 +275,7 @@ void IA64AsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
||||
|
||||
if (C->isNullValue() && !GVar->hasSection()) {
|
||||
if (!GVar->isThreadLocal() &&
|
||||
(GVar->hasInternalLinkage() || GVar->isWeakForLinker())) {
|
||||
(GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
|
||||
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
|
||||
|
||||
if (GVar->hasInternalLinkage()) {
|
||||
|
@ -504,7 +504,7 @@ printModuleLevelGV(const GlobalVariable* GVar) {
|
||||
|
||||
if (C->isNullValue() && !GVar->hasSection()) {
|
||||
if (!GVar->isThreadLocal() &&
|
||||
(GVar->hasInternalLinkage() || GVar->isWeakForLinker())) {
|
||||
(GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
|
||||
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
|
||||
|
||||
if (GVar->hasInternalLinkage())
|
||||
|
@ -85,7 +85,7 @@ SelectSectionForGlobal(const GlobalValue *GV) const {
|
||||
SectionKind::Kind K = SectionKindForGlobal(GV);
|
||||
const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);
|
||||
|
||||
if (GVA && (!GVA->isWeakForLinker()))
|
||||
if (GVA && (!GVA->mayBeOverridden()))
|
||||
switch (K) {
|
||||
case SectionKind::SmallData:
|
||||
return getSmallDataSection();
|
||||
|
@ -675,7 +675,7 @@ void PPCLinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
||||
if (C->isNullValue() && /* FIXME: Verify correct */
|
||||
!GVar->hasSection() &&
|
||||
(GVar->hasInternalLinkage() || GVar->hasExternalLinkage() ||
|
||||
GVar->isWeakForLinker())) {
|
||||
GVar->mayBeOverridden())) {
|
||||
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
|
||||
|
||||
if (GVar->hasExternalLinkage()) {
|
||||
@ -900,7 +900,7 @@ void PPCDarwinAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
||||
if (C->isNullValue() && /* FIXME: Verify correct */
|
||||
!GVar->hasSection() &&
|
||||
(GVar->hasInternalLinkage() || GVar->hasExternalLinkage() ||
|
||||
GVar->isWeakForLinker())) {
|
||||
GVar->mayBeOverridden())) {
|
||||
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
|
||||
|
||||
if (GVar->hasExternalLinkage()) {
|
||||
|
@ -253,7 +253,7 @@ void SparcAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
||||
|
||||
if (C->isNullValue() && !GVar->hasSection()) {
|
||||
if (!GVar->isThreadLocal() &&
|
||||
(GVar->hasInternalLinkage() || GVar->isWeakForLinker())) {
|
||||
(GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
|
||||
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
|
||||
|
||||
if (GVar->hasInternalLinkage())
|
||||
|
@ -240,7 +240,7 @@ TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
|
||||
assert(0 && "Unexpected section kind!");
|
||||
}
|
||||
|
||||
if (GV->isWeakForLinker())
|
||||
if (GV->mayBeOverridden())
|
||||
Flags |= SectionFlags::Linkonce;
|
||||
}
|
||||
|
||||
@ -291,7 +291,7 @@ const Section*
|
||||
TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
|
||||
SectionKind::Kind Kind = SectionKindForGlobal(GV);
|
||||
|
||||
if (GV->isWeakForLinker()) {
|
||||
if (GV->mayBeOverridden()) {
|
||||
std::string Name = UniqueSectionForGlobal(GV, Kind);
|
||||
unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
|
||||
return getNamedSection(Name.c_str(), Flags);
|
||||
|
@ -383,7 +383,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
|
||||
if (shouldPrintStub(TM, Subtarget)) {
|
||||
// Link-once, declaration, or Weakly-linked global variables need
|
||||
// non-lazily-resolved stubs
|
||||
if (GV->isDeclaration() || GV->isWeakForLinker()) {
|
||||
if (GV->isDeclaration() || GV->mayBeOverridden()) {
|
||||
// Dynamically-resolved functions need a stub for the function.
|
||||
if (isCallOp && isa<Function>(GV)) {
|
||||
// Function stubs are no longer needed for Mac OS X 10.5 and up.
|
||||
@ -790,7 +790,7 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
||||
}
|
||||
|
||||
if (!GVar->isThreadLocal() &&
|
||||
(GVar->hasInternalLinkage() || GVar->isWeakForLinker())) {
|
||||
(GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
|
||||
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
|
||||
|
||||
if (TAI->getLCOMMDirective() != NULL) {
|
||||
|
@ -63,7 +63,7 @@ bool AddReadAttrs::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
|
||||
|
||||
// Definitions with weak linkage may be overridden at linktime with
|
||||
// something that writes memory, so treat them like declarations.
|
||||
if (F->isDeclaration() || F->hasWeakLinkage()) {
|
||||
if (F->isDeclaration() || F->mayBeOverridden()) {
|
||||
if (!F->onlyReadsMemory())
|
||||
// May write memory.
|
||||
return false;
|
||||
|
@ -155,7 +155,7 @@ bool IPCP::PropagateConstantReturn(Function &F) {
|
||||
|
||||
// If this function could be overridden later in the link stage, we can't
|
||||
// propagate information about its results into callers.
|
||||
if (F.hasLinkOnceLinkage() || F.hasWeakLinkage())
|
||||
if (F.hasLinkOnceLinkage() || F.mayBeOverridden())
|
||||
return false;
|
||||
|
||||
// Check to see if this function returns a constant.
|
||||
|
@ -76,7 +76,7 @@ bool PruneEH::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
|
||||
if (F == 0) {
|
||||
SCCMightUnwind = true;
|
||||
SCCMightReturn = true;
|
||||
} else if (F->isDeclaration() || F->hasWeakLinkage()) {
|
||||
} else if (F->isDeclaration() || F->mayBeOverridden()) {
|
||||
SCCMightUnwind |= !F->doesNotThrow();
|
||||
SCCMightReturn |= !F->doesNotReturn();
|
||||
} else {
|
||||
|
@ -174,17 +174,21 @@ int InlineCostAnalyzer::getInlineCost(CallSite CS,
|
||||
Instruction *TheCall = CS.getInstruction();
|
||||
Function *Callee = CS.getCalledFunction();
|
||||
const Function *Caller = TheCall->getParent()->getParent();
|
||||
|
||||
|
||||
// Don't inline a directly recursive call.
|
||||
if (Caller == Callee ||
|
||||
// Don't inline functions which can be redefined at link-time to mean
|
||||
// something else. link-once linkage is ok though.
|
||||
Callee->hasWeakLinkage() ||
|
||||
|
||||
// something else.
|
||||
// FIXME: We allow link-once linkage since in practice all versions of
|
||||
// the function have the same body (C++ ODR) - but the LLVM definition
|
||||
// of LinkOnceLinkage doesn't require this.
|
||||
(Callee->mayBeOverridden() && !Callee->hasLinkOnceLinkage()
|
||||
) ||
|
||||
|
||||
// Don't inline functions marked noinline.
|
||||
NeverInline.count(Callee))
|
||||
return 2000000000;
|
||||
|
||||
|
||||
// InlineCost - This value measures how good of an inline candidate this call
|
||||
// site is to inline. A lower inline cost make is more likely for the call to
|
||||
// be inlined. This value may go negative.
|
||||
|
Loading…
x
Reference in New Issue
Block a user