Index: include/llvm/CodeGen/TargetPassConfig.h =================================================================== --- include/llvm/CodeGen/TargetPassConfig.h +++ include/llvm/CodeGen/TargetPassConfig.h @@ -16,10 +16,12 @@ #include "llvm/Pass.h" #include "llvm/Support/CodeGen.h" +#include "llvm/Support/CommandLine.h" #include -namespace llvm { +extern llvm::cl::opt UseIPRA; +namespace llvm { class PassConfigImpl; class ScheduleDAGInstrs; class TargetMachine; @@ -372,5 +374,4 @@ }; } // end namespace llvm - #endif Index: lib/CodeGen/TargetFrameLoweringImpl.cpp =================================================================== --- lib/CodeGen/TargetFrameLoweringImpl.cpp +++ lib/CodeGen/TargetFrameLoweringImpl.cpp @@ -12,13 +12,14 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/BitVector.h" -#include "llvm/Target/TargetFrameLowering.h" #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/MachineRegisterInfo.h" +#include "llvm/CodeGen/TargetPassConfig.h" #include "llvm/IR/CallingConv.h" #include "llvm/IR/Function.h" +#include "llvm/Target/TargetFrameLowering.h" #include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Target/TargetSubtargetInfo.h" #include @@ -59,6 +60,14 @@ void TargetFrameLowering::determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const { + // When interprocedural register allocation is enabled caller saved registers + // are preferred over callee saved registers. + if (UseIPRA) { + Function *F = const_cast(MF.getFunction()); + if (F->hasLocalLinkage() && !F->hasAddressTaken()) + return; + } + // Get the callee saved register list... const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo(); const MCPhysReg *CSRegs = TRI.getCalleeSavedRegs(&MF); Index: lib/CodeGen/TargetPassConfig.cpp =================================================================== --- lib/CodeGen/TargetPassConfig.cpp +++ lib/CodeGen/TargetPassConfig.cpp @@ -27,7 +27,6 @@ #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Verifier.h" #include "llvm/MC/MCAsmInfo.h" -#include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" Index: test/CodeGen/X86/ipra-local-linkage.ll =================================================================== --- /dev/null +++ test/CodeGen/X86/ipra-local-linkage.ll @@ -0,0 +1,22 @@ +; RUN: llc < %s | FileCheck %s -check-prefix=NOIPRA +; RUN: llc -enable-ipra < %s | FileCheck %s + +target triple = "x86_64--" + +define void @bar() { + call void @foo() + ret void +} + +define internal void @foo() { +; When IPRA is not enabled R15 will be saved by foo as it is callee saved reg. +; NOIPRA-LABEL: foo: +; NOIPRA: pushq %r15 +; When IPRA is enabled none register should be saved as foo() is local function +; so we optimize it to save no registers. +; CHECK: foo: +; CHECK-NOT: pushq %r15 + call void asm sideeffect "", "~{eax},~{ecx},~{edi},~{r15}"() + ret void +} +