BranchIslandFactory.h revision 37b74a387bb3993387029859c2d9d051c41c724e
1//===- BranchIslandFactory.h ----------------------------------------------===//
2//
3//                     The MCLinker Project
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9#ifndef MCLD_LD_BRANCHISLANDFACTORY_H_
10#define MCLD_LD_BRANCHISLANDFACTORY_H_
11
12#include "mcld/LD/BranchIsland.h"
13#include "mcld/Support/GCFactory.h"
14
15#include <llvm/Support/DataTypes.h>
16
17namespace mcld {
18
19class Fragment;
20class Module;
21
22/** \class BranchIslandFactory
23 *  \brief
24 *
25 */
26class BranchIslandFactory : public GCFactory<BranchIsland, 0> {
27 public:
28  /// ctor
29  /// @param pMaxFwdBranchRange - the max forward branch range of the target
30  /// @param pMaxBwdBranchRange - the max backward branch range of the target
31  /// @param pMaxIslandSize - a predifned value (64KB here) to decide the max
32  ///                         size of the island
33  BranchIslandFactory(int64_t pMaxFwdBranchRange,
34                      int64_t pMaxBwdBranchRange,
35                      size_t pMaxIslandSize = 65536U);
36
37  ~BranchIslandFactory();
38
39  /// group - group fragments and create islands when needed
40  /// @param pSectionData - the SectionData holds fragments need to be grouped
41  void group(Module& pModule);
42
43  /// produce - produce a island for the given fragment
44  /// @param pFragment - the fragment needs a branch island
45  BranchIsland* produce(Fragment& pFragment);
46
47  /// getIsland - find fwd and bwd islands for the fragment
48  /// @param pFragment - the fragment needs a branch island
49  /// @return - return the pair of <fwd island, bwd island>
50  std::pair<BranchIsland*, BranchIsland*> getIslands(const Fragment& pFragment);
51
52 private:
53  int64_t m_MaxFwdBranchRange;
54  int64_t m_MaxBwdBranchRange;
55  size_t m_MaxIslandSize;
56};
57
58}  // namespace mcld
59
60#endif  // MCLD_LD_BRANCHISLANDFACTORY_H_
61