51 bool doInitialization(
Module &M)
override;
74 GCMachineCodeAnalysis();
96 StringRef LowerIntrinsics::getPassName()
const {
97 return "Lower Garbage Collection Instructions";
100 void LowerIntrinsics::getAnalysisUsage(
AnalysisUsage &AU)
const {
101 FunctionPass::getAnalysisUsage(AU);
114 bool LowerIntrinsics::doInitialization(
Module &M) {
116 assert(MI &&
"LowerIntrinsics didn't require GCModuleInfo!?");
118 if (!
I->isDeclaration() &&
I->hasGC())
138 if (isa<AllocaInst>(I) || isa<GetElementPtrInst>(I) || isa<StoreInst>(I) ||
143 if (
CallInst *CI = dyn_cast<CallInst>(I))
144 if (
Function *
F = CI->getCalledFunction())
146 if (IID == Intrinsic::gcroot)
156 while (isa<AllocaInst>(IP))
164 dyn_cast<AllocaInst>(
SI->getOperand(1)->stripPointerCasts()))
168 bool MadeChange =
false;
171 if (!InitedRoots.
count(*
I)) {
173 ConstantPointerNull::get(cast<PointerType>((*I)->getAllocatedType())),
184 bool LowerIntrinsics::runOnFunction(
Function &
F) {
189 GCFunctionInfo &FI = getAnalysis<GCModuleInfo>().getFunctionInfo(F);
192 bool MadeChange =
false;
195 MadeChange |= PerformDefaultLowering(F, S);
207 bool MadeChange =
false;
211 Function *F = CI->getCalledFunction();
213 case Intrinsic::gcwrite:
217 new StoreInst(CI->getArgOperand(0), CI->getArgOperand(2), CI);
219 CI->eraseFromParent();
222 case Intrinsic::gcread:
227 CI->replaceAllUsesWith(Ld);
228 CI->eraseFromParent();
231 case Intrinsic::gcroot:
236 cast<AllocaInst>(CI->getArgOperand(0)->stripPointerCasts()));
260 "Analyze Machine Code For Garbage Collection",
false,
false)
264 void GCMachineCodeAnalysis::getAnalysisUsage(
AnalysisUsage &AU)
const {
265 MachineFunctionPass::getAnalysisUsage(AU);
275 BuildMI(MBB, MI, DL,
TII->get(TargetOpcode::GC_LABEL)).addSym(Label);
286 MCSymbol *Label = InsertLabel(*CI->getParent(), CI, CI->getDebugLoc());
291 MCSymbol *Label = InsertLabel(*CI->getParent(), RAI, CI->getDebugLoc());
306 if (MI->isTerminator())
314 assert(TFI &&
"TargetRegisterInfo not available!");
330 bool GCMachineCodeAnalysis::runOnMachineFunction(
MachineFunction &MF) {
335 FI = &getAnalysis<GCModuleInfo>().getFunctionInfo(*MF.
getFunction());
336 MMI = &getAnalysis<MachineModuleInfo>();
352 FindStackOffsets(MF);
void push_back(const T &Elt)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
A Module instance is used to store all the information related to an LLVM module. ...
This class represents a function call, abstracting a target machine's calling convention.
size_type count(PtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
INITIALIZE_PASS(GCMachineCodeAnalysis,"gc-analysis","Analyze Machine Code For Garbage Collection", false, false) GCMachineCodeAnalysis
static bool CouldBecomeSafePoint(Instruction *I)
CouldBecomeSafePoint - Predicate to conservatively determine whether the instruction could introduce ...
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
An instruction for reading from memory.
iterator begin()
Instruction iterator methods.
INITIALIZE_PASS_BEGIN(LowerIntrinsics,"gc-lowering","GC Lowering", false, false) FunctionPass *llvm
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
FunctionPass * createGCLoweringPass()
GCLowering Pass - Used by gc.root to perform its default lowering operations.
GCFunctionInfo & getFunctionInfo(const Function &F)
get - Look up function metadata.
void initializeLowerIntrinsicsPass(PassRegistry &)
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
void addSafePoint(GC::PointKind Kind, MCSymbol *Label, const DebugLoc &DL)
addSafePoint - Notes the existence of a safe point.
An analysis pass which caches information about the entire Module.
Function Alias Analysis false
An instruction for storing to memory.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
MCContext & getContext() const
void takeName(Value *V)
Transfer the name from V to this value.
bool customReadBarrier() const
By default, read barriers are replaced with simple load instructions.
virtual int getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const
getFrameIndexReference - This method should return the base register and offset used to reference a f...
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
TargetInstrInfo - Interface to description of machine instruction set.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
roots_iterator roots_end()
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
bool initializeRoots() const
If set, gcroot intrinsics should initialize their allocas to null before the first use...
Instr is the return address of a call.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
roots_iterator removeStackRoot(roots_iterator position)
removeStackRoot - Removes a root.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
GCStrategy & getStrategy()
getStrategy - Return the GC strategy for the function.
Represent the analysis usage information of a pass.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
FunctionPass class - This class is used to implement most global optimizations.
bool needsSafePoint(GC::PointKind Kind) const
True if the given kind of safe point is required.
rewrite statepoints for gc
bool needsSafePoints() const
True if safe points of any kind are required.
roots_iterator roots_begin()
roots_begin/roots_end - Iterators for all roots in the function.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
virtual const TargetFrameLowering * getFrameLowering() const
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
shadow stack gc Shadow Stack GC Lowering
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.
Information about stack frame layout on the target.
const BasicBlock & getEntryBlock() const
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
static bool NeedsDefaultLoweringPass(const GCStrategy &C)
void setPreservesAll()
Set by analyses that do not transform their input at all.
static bool InsertRootInitializers(Function &F, AllocaInst **Roots, unsigned Count)
GCStrategy describes a garbage collector algorithm's code generation requirements, and provides overridable hooks for those needs which cannot be abstractly described.
char & GCMachineCodeAnalysisID
GCMachineCodeAnalysis - Target-independent pass to mark safe points in machine code.
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction...
bool customWriteBarrier() const
By default, write barriers are replaced with simple store instructions.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Instr is a call instruction.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
void setFrameSize(uint64_t S)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual const TargetInstrInfo * getInstrInfo() const
LLVM Value Representation.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
StringRef - Represent a constant reference to a string, i.e.
Garbage collection metadata for a single function.
bool needsStackRealignment(const MachineFunction &MF) const
True if storage within the function requires the stack pointer to be aligned more than the normal cal...
Legacy analysis pass which computes a DominatorTree.
std::vector< GCRoot >::iterator roots_iterator
A wrapper class for inspecting calls to intrinsic functions.
This class contains meta information specific to a module.
an instruction to allocate memory on the stack