diff options
author | Anton Korobeynikov <asl@math.spbu.ru> | 2007-01-17 10:33:08 +0000 |
---|---|---|
committer | Anton Korobeynikov <asl@math.spbu.ru> | 2007-01-17 10:33:08 +0000 |
commit | 5032e5a61381437174e035de2a7dd728978f7bd5 (patch) | |
tree | d3490b98b33a202ee2b2a399692d9c7b169ac1c8 /lib | |
parent | e911615c4769d793588087b5321d303ecb9661c7 (diff) | |
download | external_llvm-5032e5a61381437174e035de2a7dd728978f7bd5.zip external_llvm-5032e5a61381437174e035de2a7dd728978f7bd5.tar.gz external_llvm-5032e5a61381437174e035de2a7dd728978f7bd5.tar.bz2 |
* Fix one more bug in PIC codegen: extra load is needed for *all*
non-statics.
* Introduce new option to output zero-initialized data to .bss section.
This can reduce size of binaries. Enable it by default for ELF &
Cygwin/Mingw targets. Probably, Darwin should be also added.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33299 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Target/TargetAsmInfo.cpp | 1 | ||||
-rw-r--r-- | lib/Target/TargetMachine.cpp | 6 | ||||
-rwxr-xr-x | lib/Target/X86/X86ATTAsmPrinter.cpp | 23 | ||||
-rw-r--r-- | lib/Target/X86/X86AsmPrinter.cpp | 11 | ||||
-rw-r--r-- | lib/Target/X86/X86Subtarget.cpp | 6 |
5 files changed, 31 insertions, 16 deletions
diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp index b184500..b90eaa1 100644 --- a/lib/Target/TargetAsmInfo.cpp +++ b/lib/Target/TargetAsmInfo.cpp @@ -19,6 +19,7 @@ using namespace llvm; TargetAsmInfo::TargetAsmInfo() : TextSection(".text"), DataSection(".data"), + BSSSection(".bss"), AddressSize(4), NeedsSet(false), MaxInstLength(4), diff --git a/lib/Target/TargetMachine.cpp b/lib/Target/TargetMachine.cpp index 7547614..f6b3fd0 100644 --- a/lib/Target/TargetMachine.cpp +++ b/lib/Target/TargetMachine.cpp @@ -28,6 +28,7 @@ namespace llvm { bool UnsafeFPMath; bool FiniteOnlyFPMathOption; bool UseSoftFloat; + bool NoZerosInBSS; Reloc::Model RelocationModel; CodeModel::Model CMModel; } @@ -61,6 +62,11 @@ namespace { cl::desc("Generate software floating point library calls"), cl::location(UseSoftFloat), cl::init(false)); + cl::opt<bool, true> + DontPlaceZerosInBSS("nozero-initialized-in-bss", + cl::desc("Don't place zero-initialized symbols into bss section"), + cl::location(NoZerosInBSS), + cl::init(false)); cl::opt<llvm::Reloc::Model, true> DefRelocationModel( diff --git a/lib/Target/X86/X86ATTAsmPrinter.cpp b/lib/Target/X86/X86ATTAsmPrinter.cpp index 02faf7c..1dd53c7 100755 --- a/lib/Target/X86/X86ATTAsmPrinter.cpp +++ b/lib/Target/X86/X86ATTAsmPrinter.cpp @@ -323,22 +323,19 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo, O << Offset; if (isMemOp) { - if (isExt) { - if (Subtarget->isPICStyleGOT()) { + if (Subtarget->isPICStyleGOT()) { + if (Subtarget->GVRequiresExtraLoad(GV, TM, false)) O << "@GOT"; - } else if (Subtarget->isPICStyleRIPRel()) { + else + O << "@GOTOFF"; + } else + if (isExt && Subtarget->isPICStyleRIPRel()) O << "@GOTPCREL(%rip)"; - } else if (Subtarget->is64Bit() && !NotRIPRel) - // Use rip when possible to reduce code size, except when - // index or base register are also part of the address. e.g. - // foo(%rip)(%rcx,%rax,4) is not legal - O << "(%rip)"; - } else { - if (Subtarget->is64Bit() && !NotRIPRel) + else if (Subtarget->is64Bit() && !NotRIPRel) + // Use rip when possible to reduce code size, except when + // index or base register are also part of the address. e.g. + // foo(%rip)(%rcx,%rax,4) is not legal O << "(%rip)"; - else if (Subtarget->isPICStyleGOT()) - O << "@GOTOFF"; - } } return; diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/X86AsmPrinter.cpp index 767ab23..bea3914 100644 --- a/lib/Target/X86/X86AsmPrinter.cpp +++ b/lib/Target/X86/X86AsmPrinter.cpp @@ -28,6 +28,7 @@ #include "llvm/Assembly/Writer.h" #include "llvm/Support/Mangler.h" #include "llvm/Target/TargetAsmInfo.h" +#include "llvm/Target/TargetOptions.h" using namespace llvm; static X86FunctionInfo calculateFunctionInfo(const Function *F, @@ -149,7 +150,10 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) { O << "\t.zerofill __DATA__, __common, " << name << ", " << Size << ", " << Align; } else { - SwitchToDataSection(TAI->getDataSection(), I); + if (!NoZerosInBSS && TAI->getBSSSection()) + SwitchToDataSection(TAI->getBSSSection(), I); + else + SwitchToDataSection(TAI->getDataSection(), I); if (TAI->getLCOMMDirective() != NULL) { if (I->hasInternalLinkage()) { O << TAI->getLCOMMDirective() << name << "," << Size; @@ -224,7 +228,10 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) { SwitchToDataSection(SectionName.c_str()); } else { - SwitchToDataSection(TAI->getDataSection(), I); + if (C->isNullValue() && !NoZerosInBSS && TAI->getBSSSection()) + SwitchToDataSection(TAI->getBSSSection(), I); + else + SwitchToDataSection(TAI->getDataSection(), I); } break; diff --git a/lib/Target/X86/X86Subtarget.cpp b/lib/Target/X86/X86Subtarget.cpp index 5f2342f..be5c64d 100644 --- a/lib/Target/X86/X86Subtarget.cpp +++ b/lib/Target/X86/X86Subtarget.cpp @@ -36,10 +36,14 @@ bool X86Subtarget::GVRequiresExtraLoad(const GlobalValue* GV, bool isDirectCall) const { if (TM.getRelocationModel() != Reloc::Static) - if (isTargetDarwin() || isPICStyleGOT()) { + if (isTargetDarwin()) { return (!isDirectCall && (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() || (GV->isExternal() && !GV->hasNotBeenReadFromBytecode()))); + } else if (isPICStyleGOT()) { + // Extra load is needed for all non-statics. + return (!isDirectCall && + (GV->isExternal() || !GV->hasInternalLinkage())); } else if (isTargetCygMing() || isTargetWindows()) { return (GV->hasDLLImportLinkage()); } |