LLVM 24.0.0git
SystemZAlignGlobals.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Try to increase the alignment of globals to at least 2, to avoid the need for
10// GOT indirection to load an unaligned address.
11//
12//===----------------------------------------------------------------------===//
13
14#include "SystemZ.h"
16#include "llvm/IR/Module.h"
17#include "llvm/Pass.h"
18
19using namespace llvm;
20
21namespace {
22
23class SystemZAlignGlobals : public ModulePass {
24public:
25 static char ID;
26
27 explicit SystemZAlignGlobals() : ModulePass(ID) {}
28
29 StringRef getPassName() const override { return "SystemZ Align Globals"; }
30
31 bool runOnModule(Module &M) override;
32};
33
34} // end anonymous namespace
35
36char SystemZAlignGlobals::ID = 0;
37
38INITIALIZE_PASS(SystemZAlignGlobals, "systemz-align-globals",
39 "Try aligning globals to 2 bytes", false, false)
40
42 return new SystemZAlignGlobals();
43}
44
45bool SystemZAlignGlobals::runOnModule(Module &M) {
46 bool Changed = false;
47
48 for (GlobalVariable &GV : M.globals()) {
49 MaybeAlign GVAlign = GV.getAlign();
50 if (!GVAlign || GVAlign.value() > 1)
51 continue;
52
53 if (!GV.canIncreaseAlignment())
54 continue;
55
56 GV.setAlignment(Align(2));
57 Changed = true;
58 }
59
60 return Changed;
61}
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition Pass.h:255
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
Changed
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
This is an optimization pass for GlobalISel generic memory operations.
ModulePass * createSystemZAlignGlobalsPass()