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 
17 namespace mcld {
18 
19 class Fragment;
20 class Module;
21 
22 /** \class BranchIslandFactory
23  *  \brief
24  *
25  */
26 class 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 - the group size to place stubs between sections
32   BranchIslandFactory(int64_t pMaxFwdBranchRange,
33                       int64_t pMaxBwdBranchRange,
34                       size_t pMaxIslandSize);
35 
36   ~BranchIslandFactory();
37 
38   /// group - group fragments and create islands when needed
39   /// @param pSectionData - the SectionData holds fragments need to be grouped
40   void group(Module& pModule);
41 
42   /// produce - produce a island for the given fragment
43   /// @param pFragment - the fragment needs a branch island
44   BranchIsland* produce(Fragment& pFragment);
45 
46   /// getIsland - find fwd and bwd islands for the fragment
47   /// @param pFragment - the fragment needs a branch island
48   /// @return - return the pair of <fwd island, bwd island>
49   std::pair<BranchIsland*, BranchIsland*> getIslands(const Fragment& pFragment);
50 
51  private:
52   int64_t m_MaxFwdBranchRange;
53   int64_t m_MaxBwdBranchRange;
54   size_t m_MaxIslandSize;
55 };
56 
57 }  // namespace mcld
58 
59 #endif  // MCLD_LD_BRANCHISLANDFACTORY_H_
60