31#define DEBUG_TYPE "lower-emutls"
62 for (
const auto &
G : M.globals()) {
63 if (
G.isThreadLocal())
66 for (
const auto *
G : TlsVars)
78char LowerEmuTLS::ID = 0;
81 "Add __emutls_[vt]. variables for emultated TLS model",
false,
86bool LowerEmuTLS::runOnModule(
Module &M) {
90 auto *TPC = getAnalysisIfAvailable<TargetPassConfig>();
95 if (!
TM.useEmulatedTLS())
100 for (
const auto &
G :
M.globals()) {
101 if (
G.isThreadLocal())
104 for (
const auto *
const G : TlsVars)
113 std::string EmuTlsVarName = (
"__emutls_v." + GV->
getName()).str();
122 const Constant *InitValue =
nullptr;
125 const ConstantInt *InitIntValue = dyn_cast<ConstantInt>(InitValue);
128 if (isa<ConstantAggregateZero>(InitValue) ||
129 (InitIntValue && InitIntValue->
isZero()))
141 Type *ElementTypes[4] = {WordType, WordType, VoidPtrType, InitPtrType};
143 EmuTlsVar = cast<GlobalVariable>(
144 M.getOrInsertGlobal(EmuTlsVarName, EmuTlsVarType));
152 Align GVAlignment =
DL.getValueOrABITypeAlignment(GV->
getAlign(), GVType);
157 std::string EmuTlsTmplName = (
"__emutls_t." + GV->
getName()).str();
158 EmuTlsTmplVar = dyn_cast_or_null<GlobalVariable>(
159 M.getOrInsertGlobal(EmuTlsTmplName, GVType));
160 assert(EmuTlsTmplVar &&
"Failed to create emualted TLS initializer");
169 ConstantInt::get(WordType,
DL.getTypeStoreSize(GVType)),
170 ConstantInt::get(WordType, GVAlignment.
value()), NullPtr,
171 EmuTlsTmplVar ? EmuTlsTmplVar : NullPtr};
174 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...
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)
static bool addEmuTlsVar(Module &M, const GlobalVariable *GV)
This is the interface to build a ModuleSummaryIndex for a module.
ModuleAnalysisManager MAM
#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.
A container for analyses that lazily runs them and caches their results.
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 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)
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)
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.
Analysis pass to provide the ModuleSummaryIndex object.
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...
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.
void 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 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.
StringRef getName() const
Return a constant reference to the value's name.
@ C
The default llvm calling convention, compatible with C.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
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.