From 932e1c392426b692d72c71a849ca94a0a20f9cb7 Mon Sep 17 00:00:00 2001 From: Jiangning Liu Date: Thu, 15 May 2014 23:45:42 +0000 Subject: Implement global merge optimization for global variables. This commit implements two command line switches -global-merge-on-external and -global-merge-aligned, and both of them are false by default, so this optimization is disabled by default for all targets. For ARM64, some back-end behaviors need to be tuned to get this optimization further enabled. llvm-svn: 208934 --- llvm/lib/Target/ARM64/ARM64ISelLowering.cpp | 14 ++++++++++++++ llvm/lib/Target/ARM64/ARM64ISelLowering.h | 4 ++++ 2 files changed, 18 insertions(+) (limited to 'llvm/lib/Target/ARM64') diff --git a/llvm/lib/Target/ARM64/ARM64ISelLowering.cpp b/llvm/lib/Target/ARM64/ARM64ISelLowering.cpp index 118007fa70c..880df0c1a81 100644 --- a/llvm/lib/Target/ARM64/ARM64ISelLowering.cpp +++ b/llvm/lib/Target/ARM64/ARM64ISelLowering.cpp @@ -630,6 +630,20 @@ unsigned ARM64TargetLowering::getMaximalGlobalOffset() const { return 4095; } +/// getGlobalMergeAlignment - Set alignment to be the max size of merged +/// global variable data structure, and make it aligned up to power of 2. +/// This way, we could guarantee the merged global variable data structure +/// doesn't cross page boundary, because usually OS always allocates page at +/// 4096-byte aligned boundary. +unsigned ARM64TargetLowering::getGlobalMergeAlignment( + StructType *MergedTy) const { + unsigned Align = getDataLayout()->getTypeAllocSize(MergedTy); + if (Align & (Align - 1)) + Align = llvm::NextPowerOf2(Align); + + return Align; +} + FastISel * ARM64TargetLowering::createFastISel(FunctionLoweringInfo &funcInfo, const TargetLibraryInfo *libInfo) const { diff --git a/llvm/lib/Target/ARM64/ARM64ISelLowering.h b/llvm/lib/Target/ARM64/ARM64ISelLowering.h index 55792317dba..00b2710a35c 100644 --- a/llvm/lib/Target/ARM64/ARM64ISelLowering.h +++ b/llvm/lib/Target/ARM64/ARM64ISelLowering.h @@ -236,6 +236,10 @@ public: /// be used for loads / stores from the global. unsigned getMaximalGlobalOffset() const override; + /// getGlobalMergeAlignment - Set alignment to be the max size of merged + /// global variable data structure, and make it aligned up to power of 2. + unsigned getGlobalMergeAlignment(StructType *MergedTy) 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. -- cgit v1.2.3