45 static bool NeedsDefaultLoweringPass(
const GCStrategy &
C);
46 static bool NeedsCustomLoweringPass(
const GCStrategy &
C);
49 static bool InsertRootInitializers(
Function &
F,
56 const char *getPassName()
const;
59 bool doInitialization(
Module &M);
85 GCMachineCodeAnalysis();
97 CustomReadBarriers(
false),
98 CustomWriteBarriers(
false),
100 CustomSafePoints(
false),
115 dbgs() <<
"gc " <<
getName() <<
" must override performCustomLowering.\n";
121 dbgs() <<
"gc " <<
getName() <<
" must override findCustomSafePoints.\n";
128 Functions.push_back(FI);
140 return new LowerIntrinsics();
145 LowerIntrinsics::LowerIntrinsics()
150 const char *LowerIntrinsics::getPassName()
const {
151 return "Lower Garbage Collection Instructions";
154 void LowerIntrinsics::getAnalysisUsage(
AnalysisUsage &AU)
const {
155 FunctionPass::getAnalysisUsage(AU);
161 bool LowerIntrinsics::doInitialization(
Module &M) {
167 assert(MI &&
"LowerIntrinsics didn't require GCModuleInfo!?");
169 if (!
I->isDeclaration() &&
I->hasGC())
172 bool MadeChange =
false;
174 if (NeedsCustomLoweringPass(**
I))
175 if ((*I)->initializeCustomLowering(M))
185 while (isa<AllocaInst>(IP)) ++IP;
189 for (; !CouldBecomeSafePoint(IP); ++IP)
190 if (
StoreInst *SI = dyn_cast<StoreInst>(IP))
192 dyn_cast<AllocaInst>(SI->getOperand(1)->stripPointerCasts()))
196 bool MadeChange =
false;
198 for (
AllocaInst **
I = Roots, **E = Roots + Count;
I != E; ++
I)
199 if (!InitedRoots.
count(*
I)) {
201 cast<PointerType>((*I)->getType())->getElementType())),
210 bool LowerIntrinsics::NeedsDefaultLoweringPass(
const GCStrategy &
C) {
218 bool LowerIntrinsics::NeedsCustomLoweringPass(
const GCStrategy &C) {
227 bool LowerIntrinsics::CouldBecomeSafePoint(
Instruction *
I) {
239 if (isa<AllocaInst>(I) || isa<GetElementPtrInst>(I) ||
240 isa<StoreInst>(I) || isa<LoadInst>(I))
244 if (
CallInst *CI = dyn_cast<CallInst>(I))
245 if (
Function *F = CI->getCalledFunction())
255 bool LowerIntrinsics::runOnFunction(
Function &F) {
260 GCFunctionInfo &FI = getAnalysis<GCModuleInfo>().getFunctionInfo(F);
263 bool MadeChange =
false;
265 if (NeedsDefaultLoweringPass(S))
266 MadeChange |= PerformDefaultLowering(F, S);
268 bool UseCustomLoweringPass = NeedsCustomLoweringPass(S);
269 if (UseCustomLoweringPass)
273 if (UseCustomLoweringPass) {
274 if (
DominatorTree *DT = getAnalysisIfAvailable<DominatorTree>())
275 DT->DT->recalculate(F);
288 bool MadeChange =
false;
292 Function *F = CI->getCalledFunction();
298 CI->getArgOperand(2), CI);
300 CI->eraseFromParent();
308 CI->replaceAllUsesWith(Ld);
309 CI->eraseFromParent();
317 CI->getArgOperand(0)->stripPointerCasts()));
330 MadeChange |= InsertRootInitializers(F, Roots.
begin(), Roots.
size());
341 "Analyze Machine Code For Garbage Collection",
false,
false)
343 GCMachineCodeAnalysis::GCMachineCodeAnalysis()
346 void GCMachineCodeAnalysis::getAnalysisUsage(
AnalysisUsage &AU)
const {
347 MachineFunctionPass::getAnalysisUsage(AU);
368 MCSymbol* Label = InsertLabel(*CI->getParent(), CI, CI->getDebugLoc());
373 MCSymbol* Label = InsertLabel(*CI->getParent(), RAI, CI->getDebugLoc());
380 BBE = MF.
end(); BBI != BBE; ++BBI)
382 ME = BBI->end(); MI != ME; ++
MI)
389 assert(TFI &&
"TargetRegisterInfo not available!");
403 bool GCMachineCodeAnalysis::runOnMachineFunction(
MachineFunction &MF) {
408 FI = &getAnalysis<GCModuleInfo>().getFunctionInfo(*MF.
getFunction());
413 MMI = &getAnalysis<MachineModuleInfo>();
414 TII =
TM->getInstrInfo();
427 FindStackOffsets(MF);
void push_back(const T &Elt)
const MachineFunction * getParent() const
AnalysisUsage & addPreserved()
virtual bool performCustomLowering(Function &F)
The main container class for the LLVM Intermediate Representation.
virtual bool findCustomSafePoints(GCFunctionInfo &FI, MachineFunction &MF)
const Function * getFunction() const
uint64_t getStackSize() const
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
INITIALIZE_PASS_BEGIN(LowerIntrinsics,"gc-lowering","GC Lowering", false, false) FunctionPass *llvm
MCSymbol * CreateTempSymbol()
const HexagonInstrInfo * TII
FunctionPass * createGCLoweringPass()
#define llvm_unreachable(msg)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
GCFunctionInfo & getFunctionInfo(const Function &F)
void initializeLowerIntrinsicsPass(PassRegistry &)
ID
LLVM Calling Convention Representation.
bool count(PtrType Ptr) const
count - Return true if the specified pointer is in the set.
list_type::const_iterator iterator
const std::string & getName() const
INITIALIZE_PASS(GCMachineCodeAnalysis,"gc-analysis","Analyze Machine Code For Garbage Collection", false, false) GCMachineCodeAnalysis
void replaceAllUsesWith(Value *V)
MCContext & getContext() const
bool customReadBarrier() const
bundle_iterator< MachineInstr, instr_iterator > iterator
roots_iterator roots_end()
unsigned getIntrinsicID() const LLVM_READONLY
bool initializeRoots() const
initializeRoots - If set, gcroot intrinsics should initialize their
Instr is the return address of a call.
roots_iterator removeStackRoot(roots_iterator position)
removeStackRoot - Removes a root.
GCStrategy & getStrategy()
list_type::iterator iterator
bool needsSafePoint(GC::PointKind Kind) const
needsSafePoint(Kind) - True if the given kind of safe point is
MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL, const MCInstrDesc &MCID)
bool needsSafePoints() const
needsSafePoitns - True if safe points of any kind are required. By
roots_iterator roots_begin()
bool isDeadObjectIndex(int ObjectIdx) const
virtual int getFrameIndexOffset(const MachineFunction &MF, int FI) const
MachineFrameInfo * getFrameInfo()
const BasicBlock & getEntryBlock() const
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
char & GCMachineCodeAnalysisID
void insertAfter(Instruction *InsertPos)
bool customWriteBarrier() const
const TargetMachine & getTarget() const
Instr is a call instruction.
GCFunctionInfo * insertFunctionInfo(const Function &F)
void setFrameSize(uint64_t S)
bool customSafePoints() const
LLVM Value Representation.
BasicBlockListType::iterator iterator
void addSafePoint(GC::PointKind Kind, MCSymbol *Label, DebugLoc DL)
std::vector< GCRoot >::iterator roots_iterator
virtual bool initializeCustomLowering(Module &F)