xref: /freebsd/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVTargetObjectFile.h (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1 //===-- RISCVTargetObjectFile.h - RISC-V Object Info ------------*- C++ -*-===//
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 #ifndef LLVM_LIB_TARGET_RISCV_RISCVTARGETOBJECTFILE_H
10 #define LLVM_LIB_TARGET_RISCV_RISCVTARGETOBJECTFILE_H
11 
12 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
13 
14 namespace llvm {
15 
16 /// This implementation is used for RISC-V ELF targets.
17 class RISCVELFTargetObjectFile : public TargetLoweringObjectFileELF {
18   MCSection *SmallDataSection;
19   MCSection *SmallRODataSection;
20   MCSection *SmallROData4Section;
21   MCSection *SmallROData8Section;
22   MCSection *SmallROData16Section;
23   MCSection *SmallROData32Section;
24   MCSection *SmallBSSSection;
25   unsigned SSThreshold = 8;
26 
27 public:
28   unsigned getTextSectionAlignment() const override;
29 
30   void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
31 
32   /// Return true if this global address should be placed into small data/bss
33   /// section.
34   bool isGlobalInSmallSection(const GlobalObject *GO,
35                               const TargetMachine &TM) const;
36 
37   MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
38                                     const TargetMachine &TM) const override;
39 
40   /// Return true if this constant should be placed into small data section.
41   bool isConstantInSmallSection(const DataLayout &DL, const Constant *CN) const;
42 
43   MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
44                                    const Constant *C,
45                                    Align &Alignment) const override;
46 
47   void getModuleMetadata(Module &M) override;
48 
49   bool isInSmallSection(uint64_t Size) const;
50 
51   const MCExpr *getIndirectSymViaGOTPCRel(const GlobalValue *GV,
52                                           const MCSymbol *Sym,
53                                           const MCValue &MV, int64_t Offset,
54                                           MachineModuleInfo *MMI,
55                                           MCStreamer &Streamer) const override;
56 };
57 
58 } // end namespace llvm
59 
60 #endif
61