mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 20:32:21 +00:00
Rewrite the global merge pass to be subprogram agnostic for now.
It was previously using the subtarget to get values for the global offset without actually checking each function as it was generating code. Go ahead and solidify the current behavior and make the existing FIXMEs more prominent. As a note the ARM backend previously had a thumb1 and non-thumb1 set of defaults. Only the former was tested so I've changed the behavior to only use that for now. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230245 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6229219f7e
commit
308458a98b
@ -959,12 +959,6 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Returns the maximal possible offset which can be used for loads / stores
|
||||
/// from the global.
|
||||
virtual unsigned getMaximalGlobalOffset() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// Returns true if a cast between SrcAS and DestAS is a noop.
|
||||
virtual bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const {
|
||||
return false;
|
||||
|
@ -145,7 +145,7 @@ Pass *createLICMPass();
|
||||
//
|
||||
Pass *createLoopStrengthReducePass();
|
||||
|
||||
Pass *createGlobalMergePass(const TargetMachine *TM = nullptr);
|
||||
Pass *createGlobalMergePass(const TargetMachine *TM, unsigned MaximalOffset);
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
|
@ -90,10 +90,16 @@ EnableGlobalMergeOnExternal("global-merge-on-external", cl::Hidden,
|
||||
cl::desc("Enable global merge pass on external linkage"),
|
||||
cl::init(false));
|
||||
|
||||
STATISTIC(NumMerged , "Number of globals merged");
|
||||
STATISTIC(NumMerged, "Number of globals merged");
|
||||
namespace {
|
||||
class GlobalMerge : public FunctionPass {
|
||||
const TargetMachine *TM;
|
||||
const DataLayout *DL;
|
||||
// FIXME: Infer the maximum possible offset depending on the actual users
|
||||
// (these max offsets are different for the users inside Thumb or ARM
|
||||
// functions), see the code that passes in the offset in the ARM backend
|
||||
// for more information.
|
||||
unsigned MaxOffset;
|
||||
|
||||
bool doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
|
||||
Module &M, bool isConst, unsigned AddrSpace) const;
|
||||
@ -117,8 +123,10 @@ namespace {
|
||||
|
||||
public:
|
||||
static char ID; // Pass identification, replacement for typeid.
|
||||
explicit GlobalMerge(const TargetMachine *TM = nullptr)
|
||||
: FunctionPass(ID), TM(TM) {
|
||||
explicit GlobalMerge(const TargetMachine *TM = nullptr,
|
||||
unsigned MaximalOffset = 0)
|
||||
: FunctionPass(ID), TM(TM), DL(TM->getDataLayout()),
|
||||
MaxOffset(MaximalOffset) {
|
||||
initializeGlobalMergePass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
@ -138,22 +146,16 @@ namespace {
|
||||
} // end anonymous namespace
|
||||
|
||||
char GlobalMerge::ID = 0;
|
||||
INITIALIZE_TM_PASS(GlobalMerge, "global-merge", "Merge global variables",
|
||||
false, false)
|
||||
INITIALIZE_PASS_BEGIN(GlobalMerge, "global-merge", "Merge global variables",
|
||||
false, false)
|
||||
INITIALIZE_PASS_END(GlobalMerge, "global-merge", "Merge global variables",
|
||||
false, false)
|
||||
|
||||
bool GlobalMerge::doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
|
||||
Module &M, bool isConst, unsigned AddrSpace) const {
|
||||
const TargetLowering *TLI = TM->getSubtargetImpl()->getTargetLowering();
|
||||
const DataLayout *DL = TM->getDataLayout();
|
||||
|
||||
// FIXME: Infer the maximum possible offset depending on the actual users
|
||||
// (these max offsets are different for the users inside Thumb or ARM
|
||||
// functions)
|
||||
unsigned MaxOffset = TLI->getMaximalGlobalOffset();
|
||||
|
||||
// FIXME: Find better heuristics
|
||||
std::stable_sort(Globals.begin(), Globals.end(),
|
||||
[DL](const GlobalVariable *GV1, const GlobalVariable *GV2) {
|
||||
[this](const GlobalVariable *GV1, const GlobalVariable *GV2) {
|
||||
Type *Ty1 = cast<PointerType>(GV1->getType())->getElementType();
|
||||
Type *Ty2 = cast<PointerType>(GV2->getType())->getElementType();
|
||||
|
||||
@ -282,9 +284,6 @@ bool GlobalMerge::doInitialization(Module &M) {
|
||||
|
||||
DenseMap<unsigned, SmallVector<GlobalVariable*, 16> > Globals, ConstGlobals,
|
||||
BSSGlobals;
|
||||
const TargetLowering *TLI = TM->getSubtargetImpl()->getTargetLowering();
|
||||
const DataLayout *DL = TM->getDataLayout();
|
||||
unsigned MaxOffset = TLI->getMaximalGlobalOffset();
|
||||
bool Changed = false;
|
||||
setMustKeepGlobalVariables(M);
|
||||
|
||||
@ -357,6 +356,6 @@ bool GlobalMerge::doFinalization(Module &M) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Pass *llvm::createGlobalMergePass(const TargetMachine *TM) {
|
||||
return new GlobalMerge(TM);
|
||||
Pass *llvm::createGlobalMergePass(const TargetMachine *TM, unsigned Offset) {
|
||||
return new GlobalMerge(TM, Offset);
|
||||
}
|
||||
|
@ -730,13 +730,6 @@ MVT AArch64TargetLowering::getScalarShiftAmountTy(EVT LHSTy) const {
|
||||
return MVT::i64;
|
||||
}
|
||||
|
||||
unsigned AArch64TargetLowering::getMaximalGlobalOffset() const {
|
||||
// FIXME: On AArch64, this depends on the type.
|
||||
// Basically, the addressable offsets are up to 4095 * Ty.getSizeInBytes().
|
||||
// and the offset has to be a multiple of the related size in bytes.
|
||||
return 4095;
|
||||
}
|
||||
|
||||
FastISel *
|
||||
AArch64TargetLowering::createFastISel(FunctionLoweringInfo &funcInfo,
|
||||
const TargetLibraryInfo *libInfo) const {
|
||||
|
@ -246,10 +246,6 @@ public:
|
||||
/// getFunctionAlignment - Return the Log2 alignment of this function.
|
||||
unsigned getFunctionAlignment(const Function *F) const;
|
||||
|
||||
/// getMaximalGlobalOffset - Returns the maximal possible offset which can
|
||||
/// be used for loads / stores from the global.
|
||||
unsigned getMaximalGlobalOffset() const override;
|
||||
|
||||
/// Returns true if a cast between SrcAS and DestAS is a noop.
|
||||
bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override {
|
||||
// Addrspacecasts are always noops.
|
||||
|
@ -236,8 +236,11 @@ bool AArch64PassConfig::addPreISel() {
|
||||
// get a chance to be merged
|
||||
if (TM->getOptLevel() != CodeGenOpt::None && EnablePromoteConstant)
|
||||
addPass(createAArch64PromoteConstantPass());
|
||||
// FIXME: On AArch64, this depends on the type.
|
||||
// Basically, the addressable offsets are up to 4095 * Ty.getSizeInBytes().
|
||||
// and the offset has to be a multiple of the related size in bytes.
|
||||
if (TM->getOptLevel() != CodeGenOpt::None)
|
||||
addPass(createGlobalMergePass(TM));
|
||||
addPass(createGlobalMergePass(TM, 4095));
|
||||
if (TM->getOptLevel() != CodeGenOpt::None)
|
||||
addPass(createAArch64AddressTypePromotionPass());
|
||||
|
||||
|
@ -1170,12 +1170,6 @@ ARMTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo,
|
||||
return ARM::createFastISel(funcInfo, libInfo);
|
||||
}
|
||||
|
||||
/// getMaximalGlobalOffset - Returns the maximal possible offset which can
|
||||
/// be used for loads / stores from the global.
|
||||
unsigned ARMTargetLowering::getMaximalGlobalOffset() const {
|
||||
return (Subtarget->isThumb1Only() ? 127 : 4095);
|
||||
}
|
||||
|
||||
Sched::Preference ARMTargetLowering::getSchedulingPreference(SDNode *N) const {
|
||||
unsigned NumVals = N->getNumValues();
|
||||
if (!NumVals)
|
||||
|
@ -353,10 +353,6 @@ namespace llvm {
|
||||
/// specified value type.
|
||||
const TargetRegisterClass *getRegClassFor(MVT VT) const override;
|
||||
|
||||
/// getMaximalGlobalOffset - Returns the maximal possible offset which can
|
||||
/// be used for loads / stores from the global.
|
||||
unsigned getMaximalGlobalOffset() const override;
|
||||
|
||||
/// Returns true if a cast between SrcAS and DestAS is a noop.
|
||||
bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override {
|
||||
// Addrspacecasts are always noops.
|
||||
|
@ -326,7 +326,12 @@ void ARMPassConfig::addIRPasses() {
|
||||
|
||||
bool ARMPassConfig::addPreISel() {
|
||||
if (TM->getOptLevel() != CodeGenOpt::None)
|
||||
addPass(createGlobalMergePass(TM));
|
||||
// FIXME: This is using the thumb1 only constant value for
|
||||
// maximal global offset for merging globals. We may want
|
||||
// to look into using the old value for non-thumb1 code of
|
||||
// 4095 based on the TargetMachine, but this starts to become
|
||||
// tricky when doing code gen per function.
|
||||
addPass(createGlobalMergePass(TM, 127));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user