[llvm] r230245 - Rewrite the global merge pass to be subprogram agnostic for now.
Jim Grosbach
grosbach at apple.com
Mon Feb 23 12:03:40 PST 2015
Seems reasonable. Thanks.
-Jim
> On Feb 23, 2015, at 11:28 AM, Eric Christopher <echristo at gmail.com> wrote:
>
> Author: echristo
> Date: Mon Feb 23 13:28:45 2015
> New Revision: 230245
>
> URL: http://llvm.org/viewvc/llvm-project?rev=230245&view=rev
> Log:
> 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.
>
> Modified:
> llvm/trunk/include/llvm/Target/TargetLowering.h
> llvm/trunk/include/llvm/Transforms/Scalar.h
> llvm/trunk/lib/CodeGen/GlobalMerge.cpp
> llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp
> llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.h
> llvm/trunk/lib/Target/AArch64/AArch64TargetMachine.cpp
> llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp
> llvm/trunk/lib/Target/ARM/ARMISelLowering.h
> llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp
>
> Modified: llvm/trunk/include/llvm/Target/TargetLowering.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLowering.h?rev=230245&r1=230244&r2=230245&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Target/TargetLowering.h (original)
> +++ llvm/trunk/include/llvm/Target/TargetLowering.h Mon Feb 23 13:28:45 2015
> @@ -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;
>
> Modified: llvm/trunk/include/llvm/Transforms/Scalar.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Scalar.h?rev=230245&r1=230244&r2=230245&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Transforms/Scalar.h (original)
> +++ llvm/trunk/include/llvm/Transforms/Scalar.h Mon Feb 23 13:28:45 2015
> @@ -145,7 +145,7 @@ Pass *createLICMPass();
> //
> Pass *createLoopStrengthReducePass();
>
> -Pass *createGlobalMergePass(const TargetMachine *TM = nullptr);
> +Pass *createGlobalMergePass(const TargetMachine *TM, unsigned MaximalOffset);
>
> //===----------------------------------------------------------------------===//
> //
>
> Modified: llvm/trunk/lib/CodeGen/GlobalMerge.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalMerge.cpp?rev=230245&r1=230244&r2=230245&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/GlobalMerge.cpp (original)
> +++ llvm/trunk/lib/CodeGen/GlobalMerge.cpp Mon Feb 23 13:28:45 2015
> @@ -90,10 +90,16 @@ EnableGlobalMergeOnExternal("global-merg
> 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(Modul
>
> 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
> 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);
> }
>
> Modified: llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp?rev=230245&r1=230244&r2=230245&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp (original)
> +++ llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp Mon Feb 23 13:28:45 2015
> @@ -730,13 +730,6 @@ MVT AArch64TargetLowering::getScalarShif
> 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 {
>
> Modified: llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.h?rev=230245&r1=230244&r2=230245&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.h (original)
> +++ llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.h Mon Feb 23 13:28:45 2015
> @@ -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.
>
> Modified: llvm/trunk/lib/Target/AArch64/AArch64TargetMachine.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64TargetMachine.cpp?rev=230245&r1=230244&r2=230245&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/AArch64/AArch64TargetMachine.cpp (original)
> +++ llvm/trunk/lib/Target/AArch64/AArch64TargetMachine.cpp Mon Feb 23 13:28:45 2015
> @@ -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());
>
>
> Modified: llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp?rev=230245&r1=230244&r2=230245&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp (original)
> +++ llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp Mon Feb 23 13:28:45 2015
> @@ -1170,12 +1170,6 @@ ARMTargetLowering::createFastISel(Functi
> 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)
>
> Modified: llvm/trunk/lib/Target/ARM/ARMISelLowering.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMISelLowering.h?rev=230245&r1=230244&r2=230245&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/ARM/ARMISelLowering.h (original)
> +++ llvm/trunk/lib/Target/ARM/ARMISelLowering.h Mon Feb 23 13:28:45 2015
> @@ -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.
>
> Modified: llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp?rev=230245&r1=230244&r2=230245&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp (original)
> +++ llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp Mon Feb 23 13:28:45 2015
> @@ -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;
> }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list