mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 05:24:01 +00:00
clang-format GCStrategy.cpp & GCRootLowering.cpp (NFC)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226196 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -42,8 +42,8 @@ namespace {
|
|||||||
static bool NeedsCustomLoweringPass(const GCStrategy &C);
|
static bool NeedsCustomLoweringPass(const GCStrategy &C);
|
||||||
static bool CouldBecomeSafePoint(Instruction *I);
|
static bool CouldBecomeSafePoint(Instruction *I);
|
||||||
bool PerformDefaultLowering(Function &F, GCStrategy &Coll);
|
bool PerformDefaultLowering(Function &F, GCStrategy &Coll);
|
||||||
static bool InsertRootInitializers(Function &F,
|
static bool InsertRootInitializers(Function &F, AllocaInst **Roots,
|
||||||
AllocaInst **Roots, unsigned Count);
|
unsigned Count);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static char ID;
|
static char ID;
|
||||||
@ -56,7 +56,6 @@ namespace {
|
|||||||
bool runOnFunction(Function &F) override;
|
bool runOnFunction(Function &F) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// GCMachineCodeAnalysis - This is a target-independent pass over the machine
|
/// GCMachineCodeAnalysis - This is a target-independent pass over the machine
|
||||||
/// function representation to identify safe points for the garbage collector
|
/// function representation to identify safe points for the garbage collector
|
||||||
/// in the machine code. It inserts labels at safe points and populates a
|
/// in the machine code. It inserts labels at safe points and populates a
|
||||||
@ -69,8 +68,7 @@ namespace {
|
|||||||
|
|
||||||
void FindSafePoints(MachineFunction &MF);
|
void FindSafePoints(MachineFunction &MF);
|
||||||
void VisitCallPoint(MachineBasicBlock::iterator MI);
|
void VisitCallPoint(MachineBasicBlock::iterator MI);
|
||||||
MCSymbol *InsertLabel(MachineBasicBlock &MBB,
|
MCSymbol *InsertLabel(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
|
||||||
MachineBasicBlock::iterator MI,
|
|
||||||
DebugLoc DL) const;
|
DebugLoc DL) const;
|
||||||
|
|
||||||
void FindStackOffsets(MachineFunction &MF);
|
void FindStackOffsets(MachineFunction &MF);
|
||||||
@ -83,24 +81,20 @@ namespace {
|
|||||||
|
|
||||||
bool runOnMachineFunction(MachineFunction &MF) override;
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
INITIALIZE_PASS_BEGIN(LowerIntrinsics, "gc-lowering", "GC Lowering",
|
INITIALIZE_PASS_BEGIN(LowerIntrinsics, "gc-lowering", "GC Lowering", false,
|
||||||
false, false)
|
false)
|
||||||
INITIALIZE_PASS_DEPENDENCY(GCModuleInfo)
|
INITIALIZE_PASS_DEPENDENCY(GCModuleInfo)
|
||||||
INITIALIZE_PASS_END(LowerIntrinsics, "gc-lowering", "GC Lowering", false, false)
|
INITIALIZE_PASS_END(LowerIntrinsics, "gc-lowering", "GC Lowering", false, false)
|
||||||
|
|
||||||
FunctionPass *llvm::createGCLoweringPass() {
|
FunctionPass *llvm::createGCLoweringPass() { return new LowerIntrinsics(); }
|
||||||
return new LowerIntrinsics();
|
|
||||||
}
|
|
||||||
|
|
||||||
char LowerIntrinsics::ID = 0;
|
char LowerIntrinsics::ID = 0;
|
||||||
|
|
||||||
LowerIntrinsics::LowerIntrinsics()
|
LowerIntrinsics::LowerIntrinsics() : FunctionPass(ID) {
|
||||||
: FunctionPass(ID) {
|
|
||||||
initializeLowerIntrinsicsPass(*PassRegistry::getPassRegistry());
|
initializeLowerIntrinsicsPass(*PassRegistry::getPassRegistry());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +133,8 @@ bool LowerIntrinsics::InsertRootInitializers(Function &F, AllocaInst **Roots,
|
|||||||
unsigned Count) {
|
unsigned Count) {
|
||||||
// Scroll past alloca instructions.
|
// Scroll past alloca instructions.
|
||||||
BasicBlock::iterator IP = F.getEntryBlock().begin();
|
BasicBlock::iterator IP = F.getEntryBlock().begin();
|
||||||
while (isa<AllocaInst>(IP)) ++IP;
|
while (isa<AllocaInst>(IP))
|
||||||
|
++IP;
|
||||||
|
|
||||||
// Search for initializers in the initial BB.
|
// Search for initializers in the initial BB.
|
||||||
SmallPtrSet<AllocaInst *, 16> InitedRoots;
|
SmallPtrSet<AllocaInst *, 16> InitedRoots;
|
||||||
@ -154,7 +149,8 @@ bool LowerIntrinsics::InsertRootInitializers(Function &F, AllocaInst **Roots,
|
|||||||
|
|
||||||
for (AllocaInst **I = Roots, **E = Roots + Count; I != E; ++I)
|
for (AllocaInst **I = Roots, **E = Roots + Count; I != E; ++I)
|
||||||
if (!InitedRoots.count(*I)) {
|
if (!InitedRoots.count(*I)) {
|
||||||
StoreInst* SI = new StoreInst(ConstantPointerNull::get(cast<PointerType>(
|
StoreInst *SI = new StoreInst(
|
||||||
|
ConstantPointerNull::get(cast<PointerType>(
|
||||||
cast<PointerType>((*I)->getType())->getElementType())),
|
cast<PointerType>((*I)->getType())->getElementType())),
|
||||||
*I);
|
*I);
|
||||||
SI->insertAfter(*I);
|
SI->insertAfter(*I);
|
||||||
@ -167,16 +163,13 @@ bool LowerIntrinsics::InsertRootInitializers(Function &F, AllocaInst **Roots,
|
|||||||
bool LowerIntrinsics::NeedsDefaultLoweringPass(const GCStrategy &C) {
|
bool LowerIntrinsics::NeedsDefaultLoweringPass(const GCStrategy &C) {
|
||||||
// Default lowering is necessary only if read or write barriers have a default
|
// Default lowering is necessary only if read or write barriers have a default
|
||||||
// action. The default for roots is no action.
|
// action. The default for roots is no action.
|
||||||
return !C.customWriteBarrier()
|
return !C.customWriteBarrier() || !C.customReadBarrier() ||
|
||||||
|| !C.customReadBarrier()
|
C.initializeRoots();
|
||||||
|| C.initializeRoots();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LowerIntrinsics::NeedsCustomLoweringPass(const GCStrategy &C) {
|
bool LowerIntrinsics::NeedsCustomLoweringPass(const GCStrategy &C) {
|
||||||
// Custom lowering is only necessary if enabled for some action.
|
// Custom lowering is only necessary if enabled for some action.
|
||||||
return C.customWriteBarrier()
|
return C.customWriteBarrier() || C.customReadBarrier() || C.customRoots();
|
||||||
|| C.customReadBarrier()
|
|
||||||
|| C.customRoots();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// CouldBecomeSafePoint - Predicate to conservatively determine whether the
|
/// CouldBecomeSafePoint - Predicate to conservatively determine whether the
|
||||||
@ -193,8 +186,8 @@ bool LowerIntrinsics::CouldBecomeSafePoint(Instruction *I) {
|
|||||||
// libcalls upon lowering (e.g., div i64 on a 32-bit platform), so instead
|
// libcalls upon lowering (e.g., div i64 on a 32-bit platform), so instead
|
||||||
// it is necessary to take a conservative approach.
|
// it is necessary to take a conservative approach.
|
||||||
|
|
||||||
if (isa<AllocaInst>(I) || isa<GetElementPtrInst>(I) ||
|
if (isa<AllocaInst>(I) || isa<GetElementPtrInst>(I) || isa<StoreInst>(I) ||
|
||||||
isa<StoreInst>(I) || isa<LoadInst>(I))
|
isa<LoadInst>(I))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// llvm.gcroot is safe because it doesn't do anything at runtime.
|
// llvm.gcroot is safe because it doesn't do anything at runtime.
|
||||||
@ -252,8 +245,8 @@ bool LowerIntrinsics::PerformDefaultLowering(Function &F, GCStrategy &S) {
|
|||||||
case Intrinsic::gcwrite:
|
case Intrinsic::gcwrite:
|
||||||
if (LowerWr) {
|
if (LowerWr) {
|
||||||
// Replace a write barrier with a simple store.
|
// Replace a write barrier with a simple store.
|
||||||
Value *St = new StoreInst(CI->getArgOperand(0),
|
Value *St =
|
||||||
CI->getArgOperand(2), CI);
|
new StoreInst(CI->getArgOperand(0), CI->getArgOperand(2), CI);
|
||||||
CI->replaceAllUsesWith(St);
|
CI->replaceAllUsesWith(St);
|
||||||
CI->eraseFromParent();
|
CI->eraseFromParent();
|
||||||
}
|
}
|
||||||
@ -271,8 +264,8 @@ bool LowerIntrinsics::PerformDefaultLowering(Function &F, GCStrategy &S) {
|
|||||||
if (InitRoots) {
|
if (InitRoots) {
|
||||||
// Initialize the GC root, but do not delete the intrinsic. The
|
// Initialize the GC root, but do not delete the intrinsic. The
|
||||||
// backend needs the intrinsic to flag the stack slot.
|
// backend needs the intrinsic to flag the stack slot.
|
||||||
Roots.push_back(cast<AllocaInst>(
|
Roots.push_back(
|
||||||
CI->getArgOperand(0)->stripPointerCasts()));
|
cast<AllocaInst>(CI->getArgOperand(0)->stripPointerCasts()));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -298,8 +291,7 @@ char &llvm::GCMachineCodeAnalysisID = GCMachineCodeAnalysis::ID;
|
|||||||
INITIALIZE_PASS(GCMachineCodeAnalysis, "gc-analysis",
|
INITIALIZE_PASS(GCMachineCodeAnalysis, "gc-analysis",
|
||||||
"Analyze Machine Code For Garbage Collection", false, false)
|
"Analyze Machine Code For Garbage Collection", false, false)
|
||||||
|
|
||||||
GCMachineCodeAnalysis::GCMachineCodeAnalysis()
|
GCMachineCodeAnalysis::GCMachineCodeAnalysis() : MachineFunctionPass(ID) {}
|
||||||
: MachineFunctionPass(ID) {}
|
|
||||||
|
|
||||||
void GCMachineCodeAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
|
void GCMachineCodeAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
MachineFunctionPass::getAnalysisUsage(AU);
|
MachineFunctionPass::getAnalysisUsage(AU);
|
||||||
@ -334,10 +326,10 @@ void GCMachineCodeAnalysis::VisitCallPoint(MachineBasicBlock::iterator CI) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GCMachineCodeAnalysis::FindSafePoints(MachineFunction &MF) {
|
void GCMachineCodeAnalysis::FindSafePoints(MachineFunction &MF) {
|
||||||
for (MachineFunction::iterator BBI = MF.begin(),
|
for (MachineFunction::iterator BBI = MF.begin(), BBE = MF.end(); BBI != BBE;
|
||||||
BBE = MF.end(); BBI != BBE; ++BBI)
|
++BBI)
|
||||||
for (MachineBasicBlock::iterator MI = BBI->begin(),
|
for (MachineBasicBlock::iterator MI = BBI->begin(), ME = BBI->end();
|
||||||
ME = BBI->end(); MI != ME; ++MI)
|
MI != ME; ++MI)
|
||||||
if (MI->isCall())
|
if (MI->isCall())
|
||||||
VisitCallPoint(MI);
|
VisitCallPoint(MI);
|
||||||
}
|
}
|
||||||
|
@ -16,13 +16,7 @@
|
|||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
GCStrategy::GCStrategy() :
|
GCStrategy::GCStrategy()
|
||||||
UseStatepoints(false),
|
: UseStatepoints(false), NeededSafePoints(0), CustomReadBarriers(false),
|
||||||
NeededSafePoints(0),
|
CustomWriteBarriers(false), CustomRoots(false), CustomSafePoints(false),
|
||||||
CustomReadBarriers(false),
|
InitRoots(true), UsesMetadata(false) {}
|
||||||
CustomWriteBarriers(false),
|
|
||||||
CustomRoots(false),
|
|
||||||
CustomSafePoints(false),
|
|
||||||
InitRoots(true),
|
|
||||||
UsesMetadata(false)
|
|
||||||
{}
|
|
||||||
|
Reference in New Issue
Block a user