48 const char *getPassName()
const override;
51 bool doInitialization(
Module &M)
override;
74 GCMachineCodeAnalysis();
96 const char *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;
170 for (
AllocaInst **
I = Roots, **E = Roots + Count;
I != E; ++
I)
171 if (!InitedRoots.
count(*
I)) {
173 ConstantPointerNull::get(cast<PointerType>(
174 cast<PointerType>((*I)->getType())->getElementType())),
185 bool LowerIntrinsics::runOnFunction(
Function &
F) {
190 GCFunctionInfo &FI = getAnalysis<GCModuleInfo>().getFunctionInfo(F);
193 bool MadeChange =
false;
196 MadeChange |= PerformDefaultLowering(F, S);
208 bool MadeChange =
false;
212 Function *F = CI->getCalledFunction();
214 case Intrinsic::gcwrite:
218 new StoreInst(CI->getArgOperand(0), CI->getArgOperand(2), CI);
220 CI->eraseFromParent();
223 case Intrinsic::gcread:
228 CI->replaceAllUsesWith(Ld);
229 CI->eraseFromParent();
232 case Intrinsic::gcroot:
237 cast<AllocaInst>(CI->getArgOperand(0)->stripPointerCasts()));
261 "Analyze Machine Code For Garbage Collection",
false,
false)
265 void GCMachineCodeAnalysis::getAnalysisUsage(
AnalysisUsage &AU)
const {
266 MachineFunctionPass::getAnalysisUsage(AU);
287 MCSymbol *Label = InsertLabel(*CI->getParent(), CI, CI->getDebugLoc());
292 MCSymbol *Label = InsertLabel(*CI->getParent(), RAI, CI->getDebugLoc());
307 if (MI->isTerminator())
315 assert(TFI &&
"TargetRegisterInfo not available!");
329 bool GCMachineCodeAnalysis::runOnMachineFunction(
MachineFunction &MF) {
334 FI = &getAnalysis<GCModuleInfo>().getFunctionInfo(*MF.
getFunction());
335 MMI = &getAnalysis<MachineModuleInfo>();
351 FindStackOffsets(MF);
void push_back(const T &Elt)
const MachineFunction * getParent() const
getParent - 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. ...
CallInst - 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
LoadInst - 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.
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.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
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...
An analysis pass which caches information about the entire Module.
StoreInst - 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.
TargetInstrInfo - Interface to description of machine instruction set.
bundle_iterator< MachineInstr, instr_iterator > iterator
roots_iterator roots_end()
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
virtual bool needsStackRealignment(const MachineFunction &MF) const
needsStackRealignment - true if storage within the function requires the stack pointer to be aligned ...
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.
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.
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
MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL, const MCInstrDesc &MCID)
BuildMI - Builder interface.
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
virtual int getFrameIndexOffset(const MachineFunction &MF, int FI) const
getFrameIndexOffset - Returns the displacement from the frame register to the stack frame of the spec...
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.
MachineFrameInfo * getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
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 bool NeedsDefaultLoweringPass(const GCStrategy &C)
void setPreservesAll()
Set by analyses that do not transform their input at all.
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
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.
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)
virtual const TargetInstrInfo * getInstrInfo() const
LLVM Value Representation.
BasicBlockListType::iterator iterator
C - The default llvm calling convention, compatible with C.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
Garbage collection metadata for a single function.
Legacy analysis pass which computes a DominatorTree.
void addSafePoint(GC::PointKind Kind, MCSymbol *Label, DebugLoc DL)
addSafePoint - Notes the existence of a safe point.
std::vector< GCRoot >::iterator roots_iterator
IntrinsicInst - A useful wrapper class for inspecting calls to intrinsic functions.
MachineModuleInfo - This class contains meta information specific to a module.
AllocaInst - an instruction to allocate memory on the stack.