27#define DEBUG_TYPE "loweremutls"
41 static void copyLinkageVisibility(
Module &M,
55char LowerEmuTLS::ID = 0;
58 "Add __emutls_[vt]. variables for emultated TLS model",
false,
63bool LowerEmuTLS::runOnModule(
Module &M) {
67 auto *TPC = getAnalysisIfAvailable<TargetPassConfig>();
72 if (!
TM.useEmulatedTLS())
77 for (
const auto &
G :
M.globals()) {
78 if (
G.isThreadLocal())
81 for (
const auto *
const G : TlsVars)
82 Changed |= addEmuTlsVar(M,
G);
90 std::string EmuTlsVarName = (
"__emutls_v." + GV->
getName()).str();
102 const ConstantInt *InitIntValue = dyn_cast<ConstantInt>(InitValue);
105 if (isa<ConstantAggregateZero>(InitValue) ||
106 (InitIntValue && InitIntValue->
isZero()))
118 PointerType::getUnqual(InitValue->
getType()) : VoidPtrType;
119 Type *ElementTypes[4] = {WordType, WordType, VoidPtrType, InitPtrType};
122 EmuTlsVar = cast<GlobalVariable>(
123 M.getOrInsertGlobal(EmuTlsVarName, EmuTlsVarType));
124 copyLinkageVisibility(M, GV, EmuTlsVar);
131 Align GVAlignment =
DL.getValueOrABITypeAlignment(GV->
getAlign(), GVType);
136 std::string EmuTlsTmplName = (
"__emutls_t." + GV->
getName()).str();
137 EmuTlsTmplVar = dyn_cast_or_null<GlobalVariable>(
138 M.getOrInsertGlobal(EmuTlsTmplName, GVType));
139 assert(EmuTlsTmplVar &&
"Failed to create emualted TLS initializer");
143 copyLinkageVisibility(M, GV, EmuTlsTmplVar);
150 EmuTlsTmplVar ? EmuTlsTmplVar : NullPtr};
155 std::max(
DL.getABITypeAlign(WordType),
DL.getABITypeAlign(VoidPtrType));
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
const char LLVMTargetMachineRef TM
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
Target-Independent Code Generator Pass Configuration Options pass.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
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 Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
static 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.
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
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.
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.
void setConstant(bool Val)
Class to represent integer types.
This is an important class for using LLVM in a threaded context.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
A Module instance is used to store all the information related to an LLVM module.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Class to represent struct types.
static 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.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Type * getType() const
All values are typed, get the type of this value.
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.
ModulePass * createLowerEmuTLSPass()
LowerEmuTLS - This pass generates __emutls_[vt].xyz variables for all TLS variables for the emulated ...
void initializeLowerEmuTLSPass(PassRegistry &)
This struct is a compact representation of a valid (non-zero power of two) alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.