blob: 545173df0090d99f0ef40bfcd11b07dba94f774c [file] [log] [blame]
Shih-wei Liao22add6f2012-12-15 17:21:00 -08001//===- 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//===----------------------------------------------------------------------===//
Stephen Hines37b74a32014-11-26 18:48:20 -08009#ifndef MCLD_LD_BRANCHISLANDFACTORY_H_
10#define MCLD_LD_BRANCHISLANDFACTORY_H_
11
12#include "mcld/LD/BranchIsland.h"
13#include "mcld/Support/GCFactory.h"
Shih-wei Liao22add6f2012-12-15 17:21:00 -080014
15#include <llvm/Support/DataTypes.h>
Shih-wei Liao22add6f2012-12-15 17:21:00 -080016
Stephen Hines37b74a32014-11-26 18:48:20 -080017namespace mcld {
Shih-wei Liao22add6f2012-12-15 17:21:00 -080018
19class Fragment;
Stephen Hines87f34652014-02-14 18:00:16 -080020class Module;
Shih-wei Liao22add6f2012-12-15 17:21:00 -080021
22/** \class BranchIslandFactory
23 * \brief
24 *
25 */
Stephen Hines37b74a32014-11-26 18:48:20 -080026class BranchIslandFactory : public GCFactory<BranchIsland, 0> {
27 public:
Shih-wei Liao22add6f2012-12-15 17:21:00 -080028 /// ctor
Stephen Hines0dea6bc2014-07-15 18:33:32 -070029 /// @param pMaxFwdBranchRange - the max forward branch range of the target
30 /// @param pMaxBwdBranchRange - the max backward branch range of the target
Stephen Hinescfcb2242016-03-08 00:18:09 -080031 /// @param pMaxIslandSize - the group size to place stubs between sections
Stephen Hines0dea6bc2014-07-15 18:33:32 -070032 BranchIslandFactory(int64_t pMaxFwdBranchRange,
33 int64_t pMaxBwdBranchRange,
Stephen Hinescfcb2242016-03-08 00:18:09 -080034 size_t pMaxIslandSize);
Shih-wei Liao22add6f2012-12-15 17:21:00 -080035
36 ~BranchIslandFactory();
37
Stephen Hines87f34652014-02-14 18:00:16 -080038 /// 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
Shih-wei Liao22add6f2012-12-15 17:21:00 -080042 /// produce - produce a island for the given fragment
43 /// @param pFragment - the fragment needs a branch island
44 BranchIsland* produce(Fragment& pFragment);
45
Stephen Hines0dea6bc2014-07-15 18:33:32 -070046 /// 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);
Shih-wei Liao22add6f2012-12-15 17:21:00 -080050
Stephen Hines37b74a32014-11-26 18:48:20 -080051 private:
Stephen Hines0dea6bc2014-07-15 18:33:32 -070052 int64_t m_MaxFwdBranchRange;
53 int64_t m_MaxBwdBranchRange;
54 size_t m_MaxIslandSize;
Shih-wei Liao22add6f2012-12-15 17:21:00 -080055};
56
Stephen Hines37b74a32014-11-26 18:48:20 -080057} // namespace mcld
Shih-wei Liao22add6f2012-12-15 17:21:00 -080058
Stephen Hines37b74a32014-11-26 18:48:20 -080059#endif // MCLD_LD_BRANCHISLANDFACTORY_H_