27 #define DEBUG_TYPE "loweremutls"
38 bool runOnModule(
Module &M)
override;
41 static void copyLinkageVisibility(
Module &M,
57 "Add __emutls_[vt]. variables for emultated TLS model",
false,
62 bool LowerEmuTLS::runOnModule(
Module &M) {
66 auto *
TPC = getAnalysisIfAvailable<TargetPassConfig>();
71 if (!
TM.Options.EmulatedTLS)
77 if (
G.isThreadLocal())
80 for (
const auto G : TlsVars)
81 Changed |= addEmuTlsVar(M,
G);
89 std::string EmuTlsVarName = (
"__emutls_v." + GV->
getName()).str();
95 Constant *NullPtr = ConstantPointerNull::get(VoidPtrType);
104 if (isa<ConstantAggregateZero>(InitValue) ||
105 (InitIntValue && InitIntValue->
isZero()))
117 PointerType::getUnqual(InitValue->
getType()) : VoidPtrType;
118 Type *ElementTypes[4] = {WordType, WordType, VoidPtrType, InitPtrType};
120 StructType *EmuTlsVarType = StructType::create(ElementTypeArray);
121 EmuTlsVar = cast<GlobalVariable>(
123 copyLinkageVisibility(M, GV, EmuTlsVar);
140 std::string EmuTlsTmplName = (
"__emutls_t." + GV->
getName()).str();
141 EmuTlsTmplVar = dyn_cast_or_null<GlobalVariable>(
143 assert(EmuTlsTmplVar &&
"Failed to create emualted TLS initializer");
147 copyLinkageVisibility(M, GV, EmuTlsTmplVar);
153 ConstantInt::get(WordType, GVAlignment),
154 NullPtr, EmuTlsTmplVar ? EmuTlsTmplVar : NullPtr
158 ConstantStruct::get(EmuTlsVarType, ElementValueArray));
void setVisibility(VisibilityTypes V)
A parsed version of the target data layout string in and methods for querying it. ...
LinkageTypes getLinkage() const
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
VisibilityTypes getVisibility() const
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
INITIALIZE_PASS(LowerEmuTLS, DEBUG_TYPE,"Add __emutls_[vt]. variables for emultated TLS model", false, false) ModulePass *llvm
A Module instance is used to store all the information related to an LLVM module. ...
Type * getValueType() const
void initializeLowerEmuTLSPass(PassRegistry &)
void setAlignment(unsigned Align)
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
StringRef getName() const
Return a constant reference to the value's name.
void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
const GlobalVariable * getNamedGlobal(StringRef Name) const
Return the global variable in the module with the specified name, of arbitrary type.
Class to represent struct types.
unsigned getAlignment() const
void setComdat(Comdat *C)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Class to represent pointers.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
Constant * getOrInsertGlobal(StringRef Name, Type *Ty)
Look up the specified global in the module symbol table.
const Comdat * getComdat() const
This is an important base class in LLVM.
SelectionKind getSelectionKind() const
Class to represent integer types.
void setConstant(bool Val)
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
ModulePass * createLowerEmuTLSPass()
LowerEmuTLS - This pass generates __emutls_[vt].xyz variables for all TLS variables for the emulated ...
This is the shared class of boolean and integer constants.
void setSelectionKind(SelectionKind Val)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
void setLinkage(LinkageTypes LT)
bool hasInitializer() const
Definitions have initializers, declarations don't.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Primary interface to the complete machine description for the target machine.
iterator_range< global_iterator > globals()
LLVMContext & getContext() const
Get the global data context.
This file describes how to lower LLVM code to machine code.