[AArch64] Enable global merge pass.
authorJiangning Liu <jiangning.liu@arm.com>
Tue, 22 Apr 2014 03:33:26 +0000 (03:33 +0000)
committerJiangning Liu <jiangning.liu@arm.com>
Tue, 22 Apr 2014 03:33:26 +0000 (03:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206861 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/AArch64/AArch64ISelLowering.cpp
lib/Target/AArch64/AArch64ISelLowering.h
lib/Target/AArch64/AArch64TargetMachine.cpp
test/CodeGen/AArch64/global_merge_1.ll [new file with mode: 0644]

index 18ac2da24837a4d5a1f2a269802950653745ab0a..3e40f76bd2b66ce1e3450eea5241fa8918d8088e 100644 (file)
@@ -5538,3 +5538,10 @@ int AArch64TargetLowering::getScalingFactorCost(const AddrMode &AM,
     return AM.Scale != 0 && AM.Scale != 1;
   return -1;
 }
+
+/// getMaximalGlobalOffset - Returns the maximal possible offset which can
+/// be used for loads / stores from the global.
+unsigned AArch64TargetLowering::getMaximalGlobalOffset() const {
+  return 4095;
+}
+
index 154c1d7673733f25c8670c9d1cb63e20a5555669..5e7716664a13996a6accc7e2b293cffd7f178796 100644 (file)
@@ -376,6 +376,10 @@ public:
   virtual bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
                                   unsigned Intrinsic) const override;
 
+  /// getMaximalGlobalOffset - Returns the maximal possible offset which can
+  /// be used for loads / stores from the global.
+  unsigned getMaximalGlobalOffset() const override;
+
 protected:
   std::pair<const TargetRegisterClass*, uint8_t>
   findRepresentativeClass(MVT VT) const;
index d9c990d7d5602bac1524f25001428e46ac4aa224..844e8ab2195067c14f821c532e66dbc5c84a6dd1 100644 (file)
@@ -19,6 +19,7 @@
 #include "llvm/CodeGen/Passes.h"
 #include "llvm/PassManager.h"
 #include "llvm/Support/TargetRegistry.h"
+#include "llvm/Transforms/Scalar.h"
 
 using namespace llvm;
 
@@ -86,11 +87,19 @@ public:
     return *getAArch64TargetMachine().getSubtargetImpl();
   }
 
+  bool addPreISel() override;
   virtual bool addInstSelector();
   virtual bool addPreEmitPass();
 };
 } // namespace
 
+bool AArch64PassConfig::addPreISel() {
+  if (TM->getOptLevel() != CodeGenOpt::None)
+    addPass(createGlobalMergePass(TM));
+
+  return false;
+}
+
 TargetPassConfig *AArch64TargetMachine::createPassConfig(PassManagerBase &PM) {
   return new AArch64PassConfig(this, PM);
 }
diff --git a/test/CodeGen/AArch64/global_merge_1.ll b/test/CodeGen/AArch64/global_merge_1.ll
new file mode 100644 (file)
index 0000000..e0587d6
--- /dev/null
@@ -0,0 +1,17 @@
+; RUN: llc < %s -mtriple=aarch64-none-linux-gnu | FileCheck %s
+
+@m = internal global i32 0, align 4
+@n = internal global i32 0, align 4
+
+define void @f1(i32 %a1, i32 %a2) {
+; CHECK-LABEL: f1:
+; CHECK: adrp x{{[0-9]+}}, _MergedGlobals
+; CHECK-NOT: adrp
+  store i32 %a1, i32* @m, align 4
+  store i32 %a2, i32* @n, align 4
+  ret void
+}
+
+; CHECK:        .local _MergedGlobals
+; CHECK:        .comm  _MergedGlobals,8,8
+