Home | History | Annotate | Download | only in CodeGen
      1 //===-- llvm/CodeGen/MachineModuleInfoImpls.h -------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file defines object-file format specific implementations of
     11 // MachineModuleInfoImpl.
     12 //
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef LLVM_CODEGEN_MACHINEMODULEINFOIMPLS_H
     16 #define LLVM_CODEGEN_MACHINEMODULEINFOIMPLS_H
     17 
     18 #include "llvm/CodeGen/ValueTypes.h"
     19 #include "llvm/CodeGen/MachineModuleInfo.h"
     20 #include "llvm/Support/Wasm.h"
     21 
     22 namespace llvm {
     23 class MCSymbol;
     24 
     25 /// MachineModuleInfoMachO - This is a MachineModuleInfoImpl implementation
     26 /// for MachO targets.
     27 class MachineModuleInfoMachO : public MachineModuleInfoImpl {
     28   /// GVStubs - Darwin '$non_lazy_ptr' stubs.  The key is something like
     29   /// "Lfoo$non_lazy_ptr", the value is something like "_foo". The extra bit
     30   /// is true if this GV is external.
     31   DenseMap<MCSymbol *, StubValueTy> GVStubs;
     32 
     33   /// ThreadLocalGVStubs - Darwin '$non_lazy_ptr' stubs.  The key is something
     34   /// like "Lfoo$non_lazy_ptr", the value is something like "_foo". The extra
     35   /// bit is true if this GV is external.
     36   DenseMap<MCSymbol *, StubValueTy> ThreadLocalGVStubs;
     37 
     38   virtual void anchor(); // Out of line virtual method.
     39 public:
     40   MachineModuleInfoMachO(const MachineModuleInfo &) {}
     41 
     42   StubValueTy &getGVStubEntry(MCSymbol *Sym) {
     43     assert(Sym && "Key cannot be null");
     44     return GVStubs[Sym];
     45   }
     46 
     47   StubValueTy &getThreadLocalGVStubEntry(MCSymbol *Sym) {
     48     assert(Sym && "Key cannot be null");
     49     return ThreadLocalGVStubs[Sym];
     50   }
     51 
     52   /// Accessor methods to return the set of stubs in sorted order.
     53   SymbolListTy GetGVStubList() { return getSortedStubs(GVStubs); }
     54   SymbolListTy GetThreadLocalGVStubList() {
     55     return getSortedStubs(ThreadLocalGVStubs);
     56   }
     57 };
     58 
     59 /// MachineModuleInfoELF - This is a MachineModuleInfoImpl implementation
     60 /// for ELF targets.
     61 class MachineModuleInfoELF : public MachineModuleInfoImpl {
     62   /// GVStubs - These stubs are used to materialize global addresses in PIC
     63   /// mode.
     64   DenseMap<MCSymbol *, StubValueTy> GVStubs;
     65 
     66   virtual void anchor(); // Out of line virtual method.
     67 public:
     68   MachineModuleInfoELF(const MachineModuleInfo &) {}
     69 
     70   StubValueTy &getGVStubEntry(MCSymbol *Sym) {
     71     assert(Sym && "Key cannot be null");
     72     return GVStubs[Sym];
     73   }
     74 
     75   /// Accessor methods to return the set of stubs in sorted order.
     76 
     77   SymbolListTy GetGVStubList() { return getSortedStubs(GVStubs); }
     78 };
     79 
     80 /// MachineModuleInfoWasm - This is a MachineModuleInfoImpl implementation
     81 /// for Wasm targets.
     82 class MachineModuleInfoWasm : public MachineModuleInfoImpl {
     83   /// WebAssembly global variables defined by CodeGen.
     84   std::vector<wasm::Global> Globals;
     85 
     86   /// The WebAssembly global variable which is the stack pointer.
     87   unsigned StackPointerGlobal;
     88 
     89   virtual void anchor(); // Out of line virtual method.
     90 public:
     91   MachineModuleInfoWasm(const MachineModuleInfo &)
     92     : StackPointerGlobal(-1U) {}
     93 
     94   void addGlobal(const wasm::Global &G) { Globals.push_back(G); }
     95   const std::vector<wasm::Global> &getGlobals() const { return Globals; }
     96 
     97   bool hasStackPointerGlobal() const {
     98     return StackPointerGlobal != -1U;
     99   }
    100   unsigned getStackPointerGlobal() const {
    101     assert(hasStackPointerGlobal() && "Stack ptr global hasn't been set");
    102     return StackPointerGlobal;
    103   }
    104   void setStackPointerGlobal(unsigned Global) { StackPointerGlobal = Global; }
    105 };
    106 
    107 } // end namespace llvm
    108 
    109 #endif
    110