//===-- llvm/Target/TargetAsmInfo.h - Asm 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 contains a class to be used as the basis for target specific
// asm writers. This class primarily takes care of global printing constants,
// which are used in very similar ways across all targets.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TARGET_ASM_INFO_H
#define LLVM_TARGET_ASM_INFO_H
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/DataTypes.h"
#include <string>
namespace llvm {
// DWARF encoding query type
namespace DwarfEncoding {
enum Target {
Data = 0,
CodeLabels = 1,
Functions = 2
};
}
namespace SectionKind {
enum Kind {
Unknown = 0, ///< Custom section
Text, ///< Text section
Data, ///< Data section
BSS, ///< BSS section
ROData, ///< Readonly data section
RODataMergeStr, ///< Readonly data section (mergeable strings)
RODataMergeConst, ///< Readonly data section (mergeable constants)
SmallData, ///< Small data section
SmallBSS, ///< Small bss section
SmallROData, ///< Small readonly section
ThreadData, ///< Initialized TLS data objects
ThreadBSS ///< Uninitialized TLS data objects
};
static inline bool isReadOnly(Kind K) {
return (K == SectionKind::ROData ||
K == SectionKind::RODataMergeConst ||
K == SectionKind::RODataMergeStr ||
K == SectionKind::SmallROData);
}
static inline bool isBSS(Kind K) {
return (K == SectionKind::BSS ||
K == SectionKind::SmallBSS);
}
}
namespace SectionFlags {
const unsigned Invalid = -1U;
const unsigned None = 0;
const unsigned Code = 1 << 0; ///< Section contains code
const unsigned Writeable = 1 << 1; ///< Section is writeable
const unsigned BSS = 1 << 2; ///< Section contains only zeroes
const unsigned Mergeable = 1 << 3; ///< Section contains mergeable data
const unsigned Strings = 1 << 4; ///< Section contains C-type strings
const unsigned TLS = 1 << 5; ///< Section contains thread-local data
const unsigned Debug = 1 << 6; ///< Section contains debug data
const unsigned Linkonce = 1 << 7; ///< Section is linkonce
const unsigned Small = 1 << 8; ///< Section is small
const unsigned TypeFlags = 0xFF;
// Some gap for future flags
const unsigned Named = 1 << 23; ///< Section is named
const unsigned EntitySize = 0xFF << 24; ///< Entity size for mergeable stuff
static inline unsigned getEntitySize(unsigned Flags) {
return (Flags >> 24) & 0xFF;
}
static inline unsigned setEntitySize(unsigned Flags, unsigned Size) {
return ((Flags & ~EntitySize) | ((Size & 0xFF) << 24));
}
struct KeyInfo {
static inline unsigned getEmptyKey() { return Invalid; }
static inline unsigned getTombstoneKey() { return Invalid - 1; }
static unsigned getHashValue(const unsigned &Key) { return Key; }
static bool isEqual(unsigned LHS, unsigned RHS) { return LHS == RHS; }
static bool isPod() { return true; }
};
typedef DenseMap<unsigned, std::string, KeyInfo> FlagsStringsMapType;
}
class TargetMachine;
class CallInst;
class GlobalValue;
class Type;
class Mangler;
class Section {
friend class TargetAsmInfo;
friend class StringMapEntry<Section>;
friend class StringMap<Section>;
std::string Name;
unsigned Flags;
explicit Section(unsigned F = SectionFlags::Invalid):Flags(F) { }
public:
bool isNamed() const { return Flags & SectionFlags::Named; }
unsigned getEntitySize() const { return (Flags >> 24) & 0xFF; }
const std::string& getName() const { return Name; }
unsigned getFlags() const { return Flags; }
};
/// TargetAsmInfo - This class is intended to be used as a base class for asm
/// properties and features specific to the target.
class TargetAsmInfo {
private:
mutable StringMap<Section> Sections;
mutable SectionFlags::FlagsStringsMapType FlagsStrings;
void fillDefaultValues();
protected:
/// TM - The current TargetMachine.
const TargetMachine &TM;