2009-07-28 05:13:23 +02:00
|
|
|
//===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements classes used to handle lowerings specific to common
|
|
|
|
// object file formats.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
|
|
|
|
#define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
|
|
|
|
|
2012-12-03 18:02:12 +01:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/Module.h"
|
2011-07-20 07:58:47 +02:00
|
|
|
#include "llvm/MC/MCObjectFileInfo.h"
|
2009-08-01 23:30:49 +02:00
|
|
|
#include "llvm/MC/SectionKind.h"
|
2009-07-28 05:13:23 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
2009-09-17 20:49:52 +02:00
|
|
|
class MachineModuleInfo;
|
2009-08-13 01:34:27 +02:00
|
|
|
class Mangler;
|
2010-03-11 20:41:58 +01:00
|
|
|
class MCContext;
|
2009-09-17 20:49:52 +02:00
|
|
|
class MCExpr;
|
2009-07-31 20:48:30 +02:00
|
|
|
class MCSection;
|
2010-02-15 23:35:59 +01:00
|
|
|
class MCSymbol;
|
2012-11-14 02:47:00 +01:00
|
|
|
class MCSymbolRefExpr;
|
2010-03-11 20:41:58 +01:00
|
|
|
class MCStreamer;
|
2015-03-06 14:49:05 +01:00
|
|
|
class MCValue;
|
2014-01-15 10:16:42 +01:00
|
|
|
class ConstantExpr;
|
2009-07-31 20:48:30 +02:00
|
|
|
class GlobalValue;
|
|
|
|
class TargetMachine;
|
2014-02-07 23:33:56 +01:00
|
|
|
|
2011-07-20 07:58:47 +02:00
|
|
|
class TargetLoweringObjectFile : public MCObjectFileInfo {
|
2009-07-31 20:48:30 +02:00
|
|
|
MCContext *Ctx;
|
2012-09-17 08:59:23 +02:00
|
|
|
|
|
|
|
TargetLoweringObjectFile(
|
2015-02-15 23:54:22 +01:00
|
|
|
const TargetLoweringObjectFile&) = delete;
|
|
|
|
void operator=(const TargetLoweringObjectFile&) = delete;
|
2012-09-17 08:59:23 +02:00
|
|
|
|
2015-02-23 22:26:18 +01:00
|
|
|
protected:
|
|
|
|
bool SupportIndirectSymViaGOTPCRel;
|
2015-03-06 14:48:45 +01:00
|
|
|
bool SupportGOTPCRelWithOffset;
|
2015-02-23 22:26:18 +01:00
|
|
|
|
2009-07-28 05:13:23 +02:00
|
|
|
public:
|
2009-08-08 22:14:13 +02:00
|
|
|
MCContext &getContext() const { return *Ctx; }
|
2011-07-20 07:58:47 +02:00
|
|
|
|
2015-07-16 08:04:17 +02:00
|
|
|
TargetLoweringObjectFile()
|
|
|
|
: MCObjectFileInfo(), Ctx(nullptr), SupportIndirectSymViaGOTPCRel(false),
|
|
|
|
SupportGOTPCRelWithOffset(true) {}
|
2014-02-07 23:33:56 +01:00
|
|
|
|
2009-07-28 05:13:23 +02:00
|
|
|
virtual ~TargetLoweringObjectFile();
|
2014-02-07 23:33:56 +01:00
|
|
|
|
2014-02-07 23:39:17 +01:00
|
|
|
/// This method must be called before any actual lowering is done. This
|
|
|
|
/// specifies the current context for codegen, and gives the lowering
|
|
|
|
/// implementations a chance to set up their default sections.
|
2011-07-20 07:58:47 +02:00
|
|
|
virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
|
2014-02-07 23:33:56 +01:00
|
|
|
|
2015-07-16 08:04:17 +02:00
|
|
|
virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
|
2011-04-16 05:51:21 +02:00
|
|
|
const MCSymbol *Sym) const;
|
2012-02-14 22:28:13 +01:00
|
|
|
|
2014-02-07 23:39:17 +01:00
|
|
|
/// Emit the module flags that the platform cares about.
|
2014-02-08 15:53:28 +01:00
|
|
|
virtual void emitModuleFlags(MCStreamer &Streamer,
|
|
|
|
ArrayRef<Module::ModuleFlagEntry> Flags,
|
|
|
|
Mangler &Mang, const TargetMachine &TM) const {}
|
2012-02-14 22:28:13 +01:00
|
|
|
|
2014-02-07 23:39:17 +01:00
|
|
|
/// Given a constant with the SectionKind, return a section that it should be
|
|
|
|
/// placed in.
|
2015-07-16 08:04:17 +02:00
|
|
|
virtual MCSection *getSectionForConstant(const DataLayout &DL,
|
|
|
|
SectionKind Kind,
|
2015-05-21 21:20:38 +02:00
|
|
|
const Constant *C) const;
|
2014-02-07 23:33:56 +01:00
|
|
|
|
2014-02-07 23:39:17 +01:00
|
|
|
/// Classify the specified global variable into a set of target independent
|
|
|
|
/// categories embodied in SectionKind.
|
2009-08-05 06:25:40 +02:00
|
|
|
static SectionKind getKindForGlobal(const GlobalValue *GV,
|
|
|
|
const TargetMachine &TM);
|
2014-02-07 23:33:56 +01:00
|
|
|
|
2014-02-07 23:39:17 +01:00
|
|
|
/// This method computes the appropriate section to emit the specified global
|
|
|
|
/// variable or function definition. This should not be passed external (or
|
|
|
|
/// available externally) globals.
|
2015-05-21 21:20:38 +02:00
|
|
|
MCSection *SectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
|
|
|
Mangler &Mang, const TargetMachine &TM) const;
|
2014-02-07 23:33:56 +01:00
|
|
|
|
2014-02-07 23:39:17 +01:00
|
|
|
/// This method computes the appropriate section to emit the specified global
|
|
|
|
/// variable or function definition. This should not be passed external (or
|
|
|
|
/// available externally) globals.
|
2015-05-21 21:20:38 +02:00
|
|
|
MCSection *SectionForGlobal(const GlobalValue *GV, Mangler &Mang,
|
|
|
|
const TargetMachine &TM) const {
|
2009-08-05 06:25:40 +02:00
|
|
|
return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
|
|
|
|
}
|
2012-02-14 22:28:13 +01:00
|
|
|
|
2015-03-18 00:54:51 +01:00
|
|
|
virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
|
2015-11-04 00:40:03 +01:00
|
|
|
const GlobalValue *GV, Mangler &Mang,
|
2015-03-18 00:54:51 +01:00
|
|
|
const TargetMachine &TM) const;
|
|
|
|
|
2015-05-21 21:20:38 +02:00
|
|
|
virtual MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
|
|
|
|
const TargetMachine &TM) const;
|
2015-02-12 18:16:46 +01:00
|
|
|
|
2015-02-18 00:34:51 +01:00
|
|
|
virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
|
|
|
|
const Function &F) const;
|
|
|
|
|
2014-02-07 23:39:17 +01:00
|
|
|
/// Targets should implement this method to assign a section to globals with
|
|
|
|
/// an explicit section specfied. The implementation of this method can
|
|
|
|
/// assume that GV->hasSection() is true.
|
2015-05-21 21:20:38 +02:00
|
|
|
virtual MCSection *
|
2014-02-07 23:33:56 +01:00
|
|
|
getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
|
2014-02-08 15:53:28 +01:00
|
|
|
Mangler &Mang, const TargetMachine &TM) const = 0;
|
2014-02-07 23:33:56 +01:00
|
|
|
|
2014-02-07 23:39:17 +01:00
|
|
|
/// Allow the target to completely override section assignment of a global.
|
2014-02-09 15:50:44 +01:00
|
|
|
virtual const MCSection *getSpecialCasedSectionGlobals(const GlobalValue *GV,
|
|
|
|
SectionKind Kind,
|
|
|
|
Mangler &Mang) const {
|
2014-04-14 02:51:57 +02:00
|
|
|
return nullptr;
|
2009-07-28 05:13:23 +02:00
|
|
|
}
|
2014-02-07 23:33:56 +01:00
|
|
|
|
2014-02-07 23:39:17 +01:00
|
|
|
/// Return an MCExpr to use for a reference to the specified global variable
|
|
|
|
/// from exception handling information.
|
2014-02-19 18:23:20 +01:00
|
|
|
virtual const MCExpr *
|
|
|
|
getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
|
|
|
|
Mangler &Mang, const TargetMachine &TM,
|
|
|
|
MachineModuleInfo *MMI, MCStreamer &Streamer) const;
|
2013-10-29 18:28:26 +01:00
|
|
|
|
2013-12-02 17:25:47 +01:00
|
|
|
/// Return the MCSymbol for a private symbol with global value name as its
|
|
|
|
/// base, with the specified suffix.
|
2014-02-09 15:50:44 +01:00
|
|
|
MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
|
2014-02-19 18:23:20 +01:00
|
|
|
StringRef Suffix, Mangler &Mang,
|
|
|
|
const TargetMachine &TM) const;
|
2013-12-02 17:25:47 +01:00
|
|
|
|
2014-02-07 23:39:17 +01:00
|
|
|
// The symbol that gets passed to .cfi_personality.
|
2014-02-19 18:23:20 +01:00
|
|
|
virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
|
|
|
|
Mangler &Mang,
|
|
|
|
const TargetMachine &TM,
|
|
|
|
MachineModuleInfo *MMI) const;
|
2011-04-28 01:08:15 +02:00
|
|
|
|
2010-03-11 20:41:58 +01:00
|
|
|
const MCExpr *
|
2012-11-14 02:47:00 +01:00
|
|
|
getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
|
|
|
|
MCStreamer &Streamer) const;
|
2012-01-25 23:24:19 +01:00
|
|
|
|
2015-05-21 21:20:38 +02:00
|
|
|
virtual MCSection *getStaticCtorSection(unsigned Priority,
|
|
|
|
const MCSymbol *KeySym) const {
|
2012-01-25 23:24:19 +01:00
|
|
|
return StaticCtorSection;
|
|
|
|
}
|
2014-05-16 22:39:27 +02:00
|
|
|
|
2015-05-21 21:20:38 +02:00
|
|
|
virtual MCSection *getStaticDtorSection(unsigned Priority,
|
|
|
|
const MCSymbol *KeySym) const {
|
2012-01-25 23:24:19 +01:00
|
|
|
return StaticDtorSection;
|
|
|
|
}
|
|
|
|
|
2013-06-28 22:05:11 +02:00
|
|
|
/// \brief Create a symbol reference to describe the given TLS variable when
|
|
|
|
/// emitting the address in debug info.
|
2013-07-02 20:47:09 +02:00
|
|
|
virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
|
2013-06-28 22:05:11 +02:00
|
|
|
|
2014-01-15 10:16:42 +01:00
|
|
|
virtual const MCExpr *
|
2014-02-19 18:23:20 +01:00
|
|
|
getExecutableRelativeSymbol(const ConstantExpr *CE, Mangler &Mang,
|
|
|
|
const TargetMachine &TM) const {
|
2014-04-14 02:51:57 +02:00
|
|
|
return nullptr;
|
2014-01-15 10:16:42 +01:00
|
|
|
}
|
|
|
|
|
2015-02-23 22:26:18 +01:00
|
|
|
/// \brief Target supports replacing a data "PC"-relative access to a symbol
|
|
|
|
/// through another symbol, by accessing the later via a GOT entry instead?
|
|
|
|
bool supportIndirectSymViaGOTPCRel() const {
|
|
|
|
return SupportIndirectSymViaGOTPCRel;
|
|
|
|
}
|
|
|
|
|
2015-03-06 14:48:45 +01:00
|
|
|
/// \brief Target GOT "PC"-relative relocation supports encoding an additional
|
|
|
|
/// binary expression with an offset?
|
|
|
|
bool supportGOTPCRelWithOffset() const {
|
|
|
|
return SupportGOTPCRelWithOffset;
|
|
|
|
}
|
|
|
|
|
2015-02-23 22:26:18 +01:00
|
|
|
/// \brief Get the target specific PC relative GOT entry relocation
|
|
|
|
virtual const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
|
2015-03-06 14:49:05 +01:00
|
|
|
const MCValue &MV,
|
2015-03-06 14:48:45 +01:00
|
|
|
int64_t Offset,
|
2015-03-06 14:49:05 +01:00
|
|
|
MachineModuleInfo *MMI,
|
2015-03-06 14:48:45 +01:00
|
|
|
MCStreamer &Streamer) const {
|
2015-02-23 22:26:18 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-06-30 00:04:09 +02:00
|
|
|
virtual void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV,
|
|
|
|
const Mangler &Mang) const {}
|
|
|
|
|
2009-07-28 05:13:23 +02:00
|
|
|
protected:
|
2015-05-21 21:20:38 +02:00
|
|
|
virtual MCSection *SelectSectionForGlobal(const GlobalValue *GV,
|
|
|
|
SectionKind Kind, Mangler &Mang,
|
|
|
|
const TargetMachine &TM) const = 0;
|
2009-07-28 05:13:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|