LLVM: lib/CodeGen/LowerEmuTLS.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

28

29using namespace llvm;

30

31#define DEBUG_TYPE "lower-emutls"

32

33namespace {

34

35class LowerEmuTLS : public ModulePass {

36public:

37 static char ID;

40 }

41

42 bool runOnModule(Module &M) override;

43};

44}

45

47

58

62 for (const auto &G : M.globals()) {

63 if (G.isThreadLocal())

65 }

66 for (const auto *G : TlsVars)

68

75 return PA;

76}

77

78char LowerEmuTLS::ID = 0;

79

81 "Add __emutls_[vt]. variables for emultated TLS model", false,

82 false)

83

85

86bool LowerEmuTLS::runOnModule(Module &M) {

87 if (skipModule(M))

88 return false;

89

90 auto *TPC = getAnalysisIfAvailable();

91 if (!TPC)

92 return false;

93

95 if (!TM.useEmulatedTLS())

96 return false;

97

100 for (const auto &G : M.globals()) {

101 if (G.isThreadLocal())

103 }

104 for (const auto *const G : TlsVars)

107}

108

112

113 std::string EmuTlsVarName = ("__emutls_v." + GV->getName()).str();

114 GlobalVariable *EmuTlsVar = M.getNamedGlobal(EmuTlsVarName);

115 if (EmuTlsVar)

116 return false;

117

120

121

122 const Constant *InitValue = nullptr;

126

127

129 (InitIntValue && InitIntValue->isZero()))

130 InitValue = nullptr;

131 }

132

133

134

135

136

137

138

141 Type *ElementTypes[4] = {WordType, WordType, VoidPtrType, InitPtrType};

143 EmuTlsVar = M.getOrInsertGlobal(EmuTlsVarName, EmuTlsVarType);

145

146

148 return true;

149

151 Align GVAlignment = DL.getValueOrABITypeAlignment(GV->getAlign(), GVType);

152

153

155 if (InitValue) {

156 std::string EmuTlsTmplName = ("__emutls_t." + GV->getName()).str();

157 EmuTlsTmplVar = M.getOrInsertGlobal(EmuTlsTmplName, GVType);

158 assert(EmuTlsTmplVar && "Failed to create emualted TLS initializer");

163 }

164

165

166 Constant *ElementValues[4] = {

167 ConstantInt::get(WordType, DL.getTypeStoreSize(GVType)),

168 ConstantInt::get(WordType, GVAlignment.value()), NullPtr,

169 EmuTlsTmplVar ? EmuTlsTmplVar : NullPtr};

171 Align MaxAlignment =

172 std::max(DL.getABITypeAlign(WordType), DL.getABITypeAlign(VoidPtrType));

174 return true;

175}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

This file contains the declarations for the subclasses of Constant, which represent the different fla...

This is the interface for a simple mod/ref and alias analysis over globals.

Module.h This file contains the declarations for the Module class.

static void copyLinkageVisibility(Module &M, const GlobalVariable *from, GlobalVariable *to)

Definition LowerEmuTLS.cpp:48

static bool addEmuTlsVar(Module &M, const GlobalVariable *GV)

Definition LowerEmuTLS.cpp:109

This is the interface to build a ModuleSummaryIndex for a module.

ModuleAnalysisManager MAM

#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)

This file defines the SmallVector class.

Target-Independent Code Generator Pass Configuration Options pass.

void setSelectionKind(SelectionKind Val)

SelectionKind getSelectionKind() const

This is the shared class of boolean and integer constants.

bool isZero() const

This is just a convenience method to make client code smaller for a common code.

static LLVM_ABI ConstantPointerNull * get(PointerType *T)

Static factory methods - Return objects of the specified value.

static LLVM_ABI Constant * get(StructType *T, ArrayRef< Constant * > V)

This is an important base class in LLVM.

A parsed version of the target data layout string in and methods for querying it.

LLVM_ABI void setComdat(Comdat *C)

const Comdat * getComdat() const

VisibilityTypes getVisibility() const

LinkageTypes getLinkage() const

void setLinkage(LinkageTypes LT)

void setDSOLocal(bool Local)

void setVisibility(VisibilityTypes V)

Type * getValueType() const

const Constant * getInitializer() const

getInitializer - Return the initializer for this global variable.

LLVM_ABI void setInitializer(Constant *InitVal)

setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...

bool hasInitializer() const

Definitions have initializers, declarations don't.

MaybeAlign getAlign() const

Returns the alignment of the given variable.

void setConstant(bool Val)

void setAlignment(Align Align)

Sets the alignment attribute of the GlobalVariable.

Analysis pass providing a never-invalidated alias analysis result.

Class to represent integer types.

This is an important class for using LLVM in a threaded context.

PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)

Definition LowerEmuTLS.cpp:59

ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...

Analysis pass to provide the ModuleSummaryIndex object.

A Module instance is used to store all the information related to an LLVM module.

static LLVM_ABI PassRegistry * getPassRegistry()

getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...

static PointerType * getUnqual(Type *ElementType)

This constructs a pointer to an object of the specified type in the default address space (address sp...

A set of analyses that are preserved following a run of a transformation pass.

static PreservedAnalyses all()

Construct a special preserved set that preserves all passes.

PreservedAnalyses & abandon()

Mark an analysis as abandoned.

void append(ItTy in_start, ItTy in_end)

Add the specified range to the end of the SmallVector.

void push_back(const T &Elt)

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

This pass performs the global (interprocedural) stack safety analysis (new pass manager).

Class to represent struct types.

static LLVM_ABI StructType * create(LLVMContext &Context, StringRef Name)

This creates an identified struct.

Primary interface to the complete machine description for the target machine.

The instances of the Type class are immutable: once they are created, they are never changed.

LLVM_ABI StringRef getName() const

Return a constant reference to the value's name.

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

@ C

The default llvm calling convention, compatible with C.

This is an optimization pass for GlobalISel generic memory operations.

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

LLVM_ABI void initializeLowerEmuTLSPass(PassRegistry &)

bool isa(const From &Val)

isa - Return true if the parameter to the template is an instance of one of the template type argu...

LLVM_ABI ModulePass * createLowerEmuTLSPass()

LowerEmuTLS - This pass generates __emutls_[vt].xyz variables for all TLS variables for the emulated ...

AnalysisManager< Module > ModuleAnalysisManager

Convenience typedef for the Module analysis manager.

This struct is a compact representation of a valid (non-zero power of two) alignment.

constexpr uint64_t value() const

This is a hole in the type system and should not be abused.