aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNate Begeman <natebegeman@mac.com>2004-11-25 07:09:01 +0000
committerNate Begeman <natebegeman@mac.com>2004-11-25 07:09:01 +0000
commitd4c8bea47fd3403ff1f3786b99ff11e6e1b5fc09 (patch)
tree0bd0479bbffbc234a8a950f3d81bca407c4212a9
parent4f7ac4c76c55325f657a6f051ff22c19f2d86171 (diff)
Enable optimization suggested by Chris Lattner to not emit reloc stubs for
static global variables whose addresses are taken. This allows us to convert the following code for taking the address of a static function foo addis r2, r30, ha16(Ll1__2E_foo_2$non_lazy_ptr-"L00001$pb") lwz r3, lo16(Ll1__2E_foo_2$non_lazy_ptr-"L00001$pb")(r2) which also includes linker stub code emitted at the end of the .s file not shown here, and replace it with this: addis r2, r30, ha16(l1__2E_foo_2-"L00001$pb") la r3, lo16(l1__2E_foo_2-"L00001$pb")(r2) which in addition to not needing linker help, also has no load instruction. For those not up on PowerPC mnemonics, la is shorthand for add immediate. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18239 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/PowerPC/PPC32ISelSimple.cpp2
-rw-r--r--lib/Target/PowerPC/PPCAsmPrinter.cpp31
-rw-r--r--lib/Target/PowerPC/PPCCodeEmitter.cpp6
3 files changed, 18 insertions, 21 deletions
diff --git a/lib/Target/PowerPC/PPC32ISelSimple.cpp b/lib/Target/PowerPC/PPC32ISelSimple.cpp
index 465f560266..f2fc563957 100644
--- a/lib/Target/PowerPC/PPC32ISelSimple.cpp
+++ b/lib/Target/PowerPC/PPC32ISelSimple.cpp
@@ -703,7 +703,7 @@ void PPC32ISel::copyConstantToRegister(MachineBasicBlock *MBB,
BuildMI(*MBB, IP, PPC::LOADHiAddr, 2, TmpReg)
.addReg(getGlobalBaseReg(MBB, IP)).addGlobalAddress(GV);
- if (GV->hasWeakLinkage() || GV->isExternal() || isa<Function>(GV)) {
+ if (GV->hasWeakLinkage() || GV->isExternal()) {
BuildMI(*MBB, IP, PPC::LWZ, 2, R).addGlobalAddress(GV).addReg(TmpReg);
} else {
BuildMI(*MBB, IP, PPC::LA, 2, R).addReg(TmpReg).addGlobalAddress(GV);
diff --git a/lib/Target/PowerPC/PPCAsmPrinter.cpp b/lib/Target/PowerPC/PPCAsmPrinter.cpp
index 4316abc613..f4e36bab2e 100644
--- a/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -33,6 +33,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Target/MRegisterInfo.h"
+#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
#include <set>
@@ -67,7 +68,7 @@ namespace {
bool printInstruction(const MachineInstr *MI);
void printMachineInstruction(const MachineInstr *MI);
- void printOp(const MachineOperand &MO, bool LoadAddrOp = false);
+ void printOp(const MachineOperand &MO, bool IsCallOp = false);
void printOperand(const MachineInstr *MI, unsigned OpNo, MVT::ValueType VT){
const MachineOperand &MO = MI->getOperand(OpNo);
@@ -108,7 +109,8 @@ namespace {
if (MI->getOperand(OpNo).isImmediate()) {
O << "$+" << MI->getOperand(OpNo).getImmedValue() << '\n';
} else {
- printOp(MI->getOperand(OpNo));
+ printOp(MI->getOperand(OpNo),
+ TM.getInstrInfo()->isCall(MI->getOpcode()));
}
}
void printPICLabel(const MachineInstr *MI, unsigned OpNo,
@@ -120,7 +122,7 @@ namespace {
void printSymbolHi(const MachineInstr *MI, unsigned OpNo,
MVT::ValueType VT) {
O << "ha16(";
- printOp(MI->getOperand(OpNo), true /* LoadAddrOp */);
+ printOp(MI->getOperand(OpNo));
O << "-\"L0000" << LabelNumber << "$pb\")";
}
void printSymbolLo(const MachineInstr *MI, unsigned OpNo,
@@ -132,7 +134,7 @@ namespace {
O << (short)MI->getOperand(OpNo).getImmedValue();
} else {
O << "lo16(";
- printOp(MI->getOperand(OpNo), true /* LoadAddrOp */);
+ printOp(MI->getOperand(OpNo));
O << "-\"L0000" << LabelNumber << "$pb\")";
}
}
@@ -307,8 +309,7 @@ FunctionPass *llvm::createAIXAsmPrinter(std::ostream &o, TargetMachine &tm) {
// Include the auto-generated portion of the assembly writer
#include "PowerPCGenAsmWriter.inc"
-void PowerPCAsmPrinter::printOp(const MachineOperand &MO,
- bool LoadAddrOp /* = false */) {
+void PowerPCAsmPrinter::printOp(const MachineOperand &MO, bool IsCallOp) {
const MRegisterInfo &RI = *TM.getRegisterInfo();
int new_symbol;
@@ -359,27 +360,23 @@ void PowerPCAsmPrinter::printOp(const MachineOperand &MO,
// wary however not to output $stub for external functions whose addresses
// are taken. Those should be emitted as $non_lazy_ptr below.
Function *F = dyn_cast<Function>(GV);
- if (F && F->isExternal() && !LoadAddrOp &&
- getTM().CalledFunctions.count(F)) {
+ if (F && F->isExternal() && IsCallOp && getTM().CalledFunctions.count(F)) {
FnStubs.insert(Name);
O << "L" << Name << "$stub";
return;
}
// External or weakly linked global variables need non-lazily-resolved stubs
- if ((GV->isExternal() || GV->hasWeakLinkage() || GV->hasLinkOnceLinkage())
+ if ((GV->isExternal() || GV->hasWeakLinkage() || GV->hasLinkOnceLinkage())
&& getTM().AddressTaken.count(GV)) {
- GVStubs.insert(Name);
+ if (GV->hasLinkOnceLinkage())
+ LinkOnceStubs.insert(Name);
+ else
+ GVStubs.insert(Name);
O << "L" << Name << "$non_lazy_ptr";
return;
}
-
- if (F && LoadAddrOp && getTM().AddressTaken.count(GV)) {
- LinkOnceStubs.insert(Name);
- O << "L" << Name << "$non_lazy_ptr";
- return;
- }
-
+
O << Mang->getValueName(GV);
return;
}
diff --git a/lib/Target/PowerPC/PPCCodeEmitter.cpp b/lib/Target/PowerPC/PPCCodeEmitter.cpp
index e46d0ea4c3..2f9c8c23b3 100644
--- a/lib/Target/PowerPC/PPCCodeEmitter.cpp
+++ b/lib/Target/PowerPC/PPCCodeEmitter.cpp
@@ -199,20 +199,20 @@ int PPC32CodeEmitter::getMachineOpValue(MachineInstr &MI, MachineOperand &MO) {
Offset = -((intptr_t)MovePCtoLROffset+4);
if (MI.getOpcode() == PPC::LOADHiAddr) {
- if (GV->hasWeakLinkage() || GV->isExternal() || isa<Function>(GV))
+ if (GV->hasWeakLinkage() || GV->isExternal())
Reloc = PPC::reloc_absolute_ptr_high; // Pointer to stub
else
Reloc = PPC::reloc_absolute_high; // Pointer to symbol
} else if (MI.getOpcode() == PPC::LA) {
- assert(!(GV->hasWeakLinkage() || GV->isExternal() || isa<Function>(GV))
+ assert(!(GV->hasWeakLinkage() || GV->isExternal())
&& "Something in the ISEL changed\n");
Reloc = PPC::reloc_absolute_low;
} else if (MI.getOpcode() == PPC::LWZ) {
Reloc = PPC::reloc_absolute_ptr_low;
- assert((GV->hasWeakLinkage() || GV->isExternal() || isa<Function>(GV))&&
+ assert((GV->hasWeakLinkage() || GV->isExternal()) &&
"Something in the ISEL changed\n");
} else {
// These don't show up for global value references AFAIK, only for