mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-27 15:29:51 +00:00
This change enables tracking i1 values in the PowerPC backend using the condition register bits. These bits can be treated on PowerPC as separate registers; individual bit operations (and, or, xor, etc.) are supported. Tracking booleans in CR bits has several advantages: - Reduction in register pressure (because we no longer need GPRs to store boolean values). - Logical operations on booleans can be handled more efficiently; we used to have to move all results from comparisons into GPRs, perform promoted logical operations in GPRs, and then move the result back into condition register bits to be used by conditional branches. This can be very inefficient, because the throughput of these CR <-> GPR moves have high latency and low throughput (especially when other associated instructions are accounted for). - On the POWER7 and similar cores, we can increase total throughput by using the CR bits. CR bit operations have a dedicated functional unit. Most of this is more-or-less mechanical: Adjustments were needed in the calling-convention code, support was added for spilling/restoring individual condition-register bits, and conditional branch instruction definitions taking specific CR bits were added (plus patterns and code for generating bit-level operations). This is enabled by default when running at -O2 and higher. For -O0 and -O1, where the ability to debug is more important, this feature is disabled by default. Individual CR bits do not have assigned DWARF register numbers, and storing values in CR bits makes them invisible to the debugger. It is critical, however, that we don't move i1 values that have been promoted to larger values (such as those passed as function arguments) into bit registers only to quickly turn around and move the values back into GPRs (such as happens when values are returned by functions). A pair of target-specific DAG combines are added to remove the trunc/extends in: trunc(binary-ops(binary-ops(zext(x), zext(y)), ...) and: zext(binary-ops(binary-ops(trunc(x), trunc(y)), ...) In short, we only want to use CR bits where some of the i1 values come from comparisons or are used by conditional branches or selects. To put it another way, if we can do the entire i1 computation in GPRs, then we probably should (on the POWER7, the GPR-operation throughput is higher, and for all cores, the CR <-> GPR moves are expensive). POWER7 test-suite performance results (from 10 runs in each configuration): SingleSource/Benchmarks/Misc/mandel-2: 35% speedup MultiSource/Benchmarks/Prolangs-C++/city/city: 21% speedup MultiSource/Benchmarks/MiBench/automotive-susan: 23% speedup SingleSource/Benchmarks/CoyoteBench/huffbench: 13% speedup SingleSource/Benchmarks/Misc-C++/Large/sphereflake: 13% speedup SingleSource/Benchmarks/Misc-C++/mandel-text: 10% speedup SingleSource/Benchmarks/Misc-C++-EH/spirit: 10% slowdown MultiSource/Applications/lemon/lemon: 8% slowdown git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202451 91177308-0d34-0410-b5e6-96231b3b80d8
234 lines
7.3 KiB
C++
234 lines
7.3 KiB
C++
//===-- PowerPCSubtarget.cpp - PPC Subtarget Information ------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements the PPC specific subclass of TargetSubtargetInfo.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "PPCSubtarget.h"
|
|
#include "PPC.h"
|
|
#include "PPCRegisterInfo.h"
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
#include "llvm/CodeGen/MachineScheduler.h"
|
|
#include "llvm/IR/Attributes.h"
|
|
#include "llvm/IR/Function.h"
|
|
#include "llvm/IR/GlobalValue.h"
|
|
#include "llvm/Support/Host.h"
|
|
#include "llvm/Support/TargetRegistry.h"
|
|
#include "llvm/Target/TargetMachine.h"
|
|
#include <cstdlib>
|
|
|
|
#define GET_SUBTARGETINFO_TARGET_DESC
|
|
#define GET_SUBTARGETINFO_CTOR
|
|
#include "PPCGenSubtargetInfo.inc"
|
|
|
|
using namespace llvm;
|
|
|
|
PPCSubtarget::PPCSubtarget(const std::string &TT, const std::string &CPU,
|
|
const std::string &FS, bool is64Bit,
|
|
CodeGenOpt::Level OptLevel)
|
|
: PPCGenSubtargetInfo(TT, CPU, FS)
|
|
, IsPPC64(is64Bit)
|
|
, TargetTriple(TT) {
|
|
initializeEnvironment();
|
|
|
|
std::string FullFS = FS;
|
|
|
|
// At -O2 and above, track CR bits as individual registers.
|
|
if (OptLevel >= CodeGenOpt::Default) {
|
|
if (!FullFS.empty())
|
|
FullFS = "+crbits," + FullFS;
|
|
else
|
|
FullFS = "+crbits";
|
|
}
|
|
|
|
resetSubtargetFeatures(CPU, FullFS);
|
|
}
|
|
|
|
/// SetJITMode - This is called to inform the subtarget info that we are
|
|
/// producing code for the JIT.
|
|
void PPCSubtarget::SetJITMode() {
|
|
// JIT mode doesn't want lazy resolver stubs, it knows exactly where
|
|
// everything is. This matters for PPC64, which codegens in PIC mode without
|
|
// stubs.
|
|
HasLazyResolverStubs = false;
|
|
|
|
// Calls to external functions need to use indirect calls
|
|
IsJITCodeModel = true;
|
|
}
|
|
|
|
void PPCSubtarget::resetSubtargetFeatures(const MachineFunction *MF) {
|
|
AttributeSet FnAttrs = MF->getFunction()->getAttributes();
|
|
Attribute CPUAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
|
|
"target-cpu");
|
|
Attribute FSAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
|
|
"target-features");
|
|
std::string CPU =
|
|
!CPUAttr.hasAttribute(Attribute::None) ? CPUAttr.getValueAsString() : "";
|
|
std::string FS =
|
|
!FSAttr.hasAttribute(Attribute::None) ? FSAttr.getValueAsString() : "";
|
|
if (!FS.empty()) {
|
|
initializeEnvironment();
|
|
resetSubtargetFeatures(CPU, FS);
|
|
}
|
|
}
|
|
|
|
void PPCSubtarget::initializeEnvironment() {
|
|
StackAlignment = 16;
|
|
DarwinDirective = PPC::DIR_NONE;
|
|
HasMFOCRF = false;
|
|
Has64BitSupport = false;
|
|
Use64BitRegs = false;
|
|
UseCRBits = false;
|
|
HasAltivec = false;
|
|
HasQPX = false;
|
|
HasFCPSGN = false;
|
|
HasFSQRT = false;
|
|
HasFRE = false;
|
|
HasFRES = false;
|
|
HasFRSQRTE = false;
|
|
HasFRSQRTES = false;
|
|
HasRecipPrec = false;
|
|
HasSTFIWX = false;
|
|
HasLFIWAX = false;
|
|
HasFPRND = false;
|
|
HasFPCVT = false;
|
|
HasISEL = false;
|
|
HasPOPCNTD = false;
|
|
HasLDBRX = false;
|
|
IsBookE = false;
|
|
DeprecatedMFTB = false;
|
|
DeprecatedDST = false;
|
|
HasLazyResolverStubs = false;
|
|
IsJITCodeModel = false;
|
|
}
|
|
|
|
void PPCSubtarget::resetSubtargetFeatures(StringRef CPU, StringRef FS) {
|
|
// Determine default and user specified characteristics
|
|
std::string CPUName = CPU;
|
|
if (CPUName.empty())
|
|
CPUName = "generic";
|
|
#if (defined(__APPLE__) || defined(__linux__)) && \
|
|
(defined(__ppc__) || defined(__powerpc__))
|
|
if (CPUName == "generic")
|
|
CPUName = sys::getHostCPUName();
|
|
#endif
|
|
|
|
// Initialize scheduling itinerary for the specified CPU.
|
|
InstrItins = getInstrItineraryForCPU(CPUName);
|
|
|
|
// Make sure 64-bit features are available when CPUname is generic
|
|
std::string FullFS = FS;
|
|
|
|
// If we are generating code for ppc64, verify that options make sense.
|
|
if (IsPPC64) {
|
|
Has64BitSupport = true;
|
|
// Silently force 64-bit register use on ppc64.
|
|
Use64BitRegs = true;
|
|
if (!FullFS.empty())
|
|
FullFS = "+64bit," + FullFS;
|
|
else
|
|
FullFS = "+64bit";
|
|
}
|
|
|
|
// Parse features string.
|
|
ParseSubtargetFeatures(CPUName, FullFS);
|
|
|
|
// If the user requested use of 64-bit regs, but the cpu selected doesn't
|
|
// support it, ignore.
|
|
if (use64BitRegs() && !has64BitSupport())
|
|
Use64BitRegs = false;
|
|
|
|
// Set up darwin-specific properties.
|
|
if (isDarwin())
|
|
HasLazyResolverStubs = true;
|
|
|
|
// QPX requires a 32-byte aligned stack. Note that we need to do this if
|
|
// we're compiling for a BG/Q system regardless of whether or not QPX
|
|
// is enabled because external functions will assume this alignment.
|
|
if (hasQPX() || isBGQ())
|
|
StackAlignment = 32;
|
|
|
|
// Determine endianness.
|
|
IsLittleEndian = (TargetTriple.getArch() == Triple::ppc64le);
|
|
}
|
|
|
|
/// hasLazyResolverStub - Return true if accesses to the specified global have
|
|
/// to go through a dyld lazy resolution stub. This means that an extra load
|
|
/// is required to get the address of the global.
|
|
bool PPCSubtarget::hasLazyResolverStub(const GlobalValue *GV,
|
|
const TargetMachine &TM) const {
|
|
// We never have stubs if HasLazyResolverStubs=false or if in static mode.
|
|
if (!HasLazyResolverStubs || TM.getRelocationModel() == Reloc::Static)
|
|
return false;
|
|
// If symbol visibility is hidden, the extra load is not needed if
|
|
// the symbol is definitely defined in the current translation unit.
|
|
bool isDecl = GV->isDeclaration() && !GV->isMaterializable();
|
|
if (GV->hasHiddenVisibility() && !isDecl && !GV->hasCommonLinkage())
|
|
return false;
|
|
return GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
|
|
GV->hasCommonLinkage() || isDecl;
|
|
}
|
|
|
|
bool PPCSubtarget::enablePostRAScheduler(
|
|
CodeGenOpt::Level OptLevel,
|
|
TargetSubtargetInfo::AntiDepBreakMode& Mode,
|
|
RegClassVector& CriticalPathRCs) const {
|
|
Mode = TargetSubtargetInfo::ANTIDEP_ALL;
|
|
|
|
CriticalPathRCs.clear();
|
|
|
|
if (isPPC64())
|
|
CriticalPathRCs.push_back(&PPC::G8RCRegClass);
|
|
else
|
|
CriticalPathRCs.push_back(&PPC::GPRCRegClass);
|
|
|
|
return OptLevel >= CodeGenOpt::Default;
|
|
}
|
|
|
|
// Embedded cores need aggressive scheduling (and some others also benefit).
|
|
static bool needsAggressiveScheduling(unsigned Directive) {
|
|
switch (Directive) {
|
|
default: return false;
|
|
case PPC::DIR_440:
|
|
case PPC::DIR_A2:
|
|
case PPC::DIR_E500mc:
|
|
case PPC::DIR_E5500:
|
|
case PPC::DIR_PWR7:
|
|
return true;
|
|
}
|
|
}
|
|
|
|
bool PPCSubtarget::enableMachineScheduler() const {
|
|
// Enable MI scheduling for the embedded cores.
|
|
// FIXME: Enable this for all cores (some additional modeling
|
|
// may be necessary).
|
|
return needsAggressiveScheduling(DarwinDirective);
|
|
}
|
|
|
|
void PPCSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
|
|
MachineInstr *begin,
|
|
MachineInstr *end,
|
|
unsigned NumRegionInstrs) const {
|
|
if (needsAggressiveScheduling(DarwinDirective)) {
|
|
Policy.OnlyTopDown = false;
|
|
Policy.OnlyBottomUp = false;
|
|
}
|
|
|
|
// Spilling is generally expensive on all PPC cores, so always enable
|
|
// register-pressure tracking.
|
|
Policy.ShouldTrackPressure = true;
|
|
}
|
|
|
|
bool PPCSubtarget::useAA() const {
|
|
// Use AA during code generation for the embedded cores.
|
|
return needsAggressiveScheduling(DarwinDirective);
|
|
}
|
|
|