26 #define DEBUG_TYPE "loweremutls"
39 bool runOnModule(
Module &M)
override;
42 static void copyLinkageVisibility(
Module &M,
58 "Add __emutls_[vt]. variables for emultated TLS model",
62 return new LowerEmuTLS(TM);
65 bool LowerEmuTLS::runOnModule(
Module &M) {
69 if (!
TM || !
TM->Options.EmulatedTLS)
75 if (
G.isThreadLocal())
78 for (
const auto G : TlsVars)
79 Changed |= addEmuTlsVar(M,
G);
87 std::string EmuTlsVarName = (
"__emutls_v." + GV->
getName()).str();
93 Constant *NullPtr = ConstantPointerNull::get(VoidPtrType);
102 if (isa<ConstantAggregateZero>(InitValue) ||
103 (InitIntValue && InitIntValue->
isZero()))
115 PointerType::getUnqual(InitValue->
getType()) : VoidPtrType;
116 Type *ElementTypes[4] = {WordType, WordType, VoidPtrType, InitPtrType};
118 StructType *EmuTlsVarType = StructType::create(ElementTypeArray);
119 EmuTlsVar = cast<GlobalVariable>(
121 copyLinkageVisibility(M, GV, EmuTlsVar);
138 std::string EmuTlsTmplName = (
"__emutls_t." + GV->
getName()).str();
139 EmuTlsTmplVar = dyn_cast_or_null<GlobalVariable>(
141 assert(EmuTlsTmplVar &&
"Failed to create emualted TLS initializer");
145 copyLinkageVisibility(M, GV, EmuTlsTmplVar);
151 ConstantInt::get(WordType, GVAlignment),
152 NullPtr, EmuTlsTmplVar ? EmuTlsTmplVar : NullPtr
156 ConstantStruct::get(EmuTlsVarType, ElementValueArray));
157 unsigned MaxAlignment = std::max(
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
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 ...
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)...
INITIALIZE_PASS(LowerEmuTLS,"loweremutls","Add __emutls_[vt]. variables for emultated TLS model", false, false) ModulePass *llvm
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)
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
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.
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.
GlobalVariable * getNamedGlobal(StringRef Name)
Return the global variable in the module with the specified name, of arbitrary type.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
void setLinkage(LinkageTypes LT)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
bool hasInitializer() const
Definitions have initializers, declarations don't.
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)
ModulePass * createLowerEmuTLSPass(const TargetMachine *TM)
LowerEmuTLS - This pass generates __emutls_[vt].xyz variables for all TLS variables for the emulated ...
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.