clang-format all the GC related files (NFC)

Nothing interesting here...




git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226342 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Philip Reames 2015-01-16 23:16:12 +00:00
parent 61bd005d1b
commit 999412767a
14 changed files with 583 additions and 597 deletions

View File

@ -67,7 +67,6 @@ namespace llvm {
GCRoot(int N, const Constant *MD) : Num(N), StackOffset(-1), Metadata(MD) {}
};
/// Garbage collection metadata for a single function. Currently, this
/// information only applies to GCStrategies which use GCRoot.
class GCFunctionInfo {
@ -155,6 +154,7 @@ namespace llvm {
/// A list of GCStrategies which are active in this Module. These are
/// not owning pointers.
std::vector<GCStrategy *> StrategyList;
public:
/// List of per function info objects. In theory, Each of these
/// may be associated with a different GC.
@ -163,7 +163,6 @@ namespace llvm {
FuncInfoVec::iterator funcinfo_begin() { return Functions.begin(); }
FuncInfoVec::iterator funcinfo_end() { return Functions.end(); }
private:
/// Owning list of all GCFunctionInfos associated with this Module
FuncInfoVec Functions;
@ -172,8 +171,8 @@ namespace llvm {
/// associated with a particular Function.
typedef DenseMap<const Function *, GCFunctionInfo *> finfo_map_type;
finfo_map_type FInfoMap;
public:
public:
typedef std::vector<GCStrategy *>::const_iterator iterator;
static char ID;
@ -195,7 +194,6 @@ namespace llvm {
/// will soon change.
GCFunctionInfo &getFunctionInfo(const Function &F);
};
}
#endif

View File

@ -45,24 +45,20 @@ namespace llvm {
private:
GCMetadataPrinter(const GCMetadataPrinter &) LLVM_DELETED_FUNCTION;
GCMetadataPrinter &
operator=(const GCMetadataPrinter &) LLVM_DELETED_FUNCTION;
GCMetadataPrinter &operator=(const GCMetadataPrinter &) LLVM_DELETED_FUNCTION;
public:
GCStrategy &getStrategy() { return *S; }
/// Called before the assembly for the module is generated by
/// the AsmPrinter (but after target specific hooks.)
virtual void beginAssembly(Module &M, GCModuleInfo &Info,
AsmPrinter &AP) {}
virtual void beginAssembly(Module &M, GCModuleInfo &Info, AsmPrinter &AP) {}
/// Called after the assembly for the module is generated by
/// the AsmPrinter (but before target specific hooks)
virtual void finishAssembly(Module &M, GCModuleInfo &Info,
AsmPrinter &AP) {}
virtual void finishAssembly(Module &M, GCModuleInfo &Info, AsmPrinter &AP) {}
virtual ~GCMetadataPrinter();
};
}
#endif

View File

@ -70,7 +70,6 @@ namespace llvm {
};
}
/// GCStrategy describes a garbage collector algorithm's code generation
/// requirements, and provides overridable hooks for those needs which cannot
/// be abstractly described. GCStrategy objects must be looked up through
@ -135,9 +134,7 @@ namespace llvm {
/// True if safe points of any kind are required. By default, none are
/// recorded.
bool needsSafePoints() const {
return NeededSafePoints != 0;
}
bool needsSafePoints() const { return NeededSafePoints != 0; }
/// True if the given kind of safe point is required. By default, none are
/// recorded.

View File

@ -36,10 +36,8 @@ namespace {
class ErlangGCPrinter : public GCMetadataPrinter {
public:
void finishAssembly(Module &M, GCModuleInfo &Info,
AsmPrinter &AP) override;
void finishAssembly(Module &M, GCModuleInfo &Info, AsmPrinter &AP) override;
};
}
static GCMetadataPrinterRegistry::Add<ErlangGCPrinter>
@ -54,9 +52,9 @@ void ErlangGCPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
AP.TM.getSubtargetImpl()->getDataLayout()->getPointerSize();
// Put this in a custom .note section.
AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getContext()
.getELFSection(".note.gc", ELF::SHT_PROGBITS, 0,
SectionKind::getDataRel()));
AP.OutStreamer.SwitchSection(
AP.getObjFileLowering().getContext().getELFSection(
".note.gc", ELF::SHT_PROGBITS, 0, SectionKind::getDataRel()));
// For each function...
for (GCModuleInfo::FuncInfoVec::iterator FI = Info.funcinfo_begin(),
@ -104,8 +102,9 @@ void ErlangGCPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
// Emit stack arity, i.e. the number of stacked arguments.
unsigned RegisteredArgs = IntPtrSize == 4 ? 5 : 6;
unsigned StackArity = MD.getFunction().arg_size() > RegisteredArgs ?
MD.getFunction().arg_size() - RegisteredArgs : 0;
unsigned StackArity = MD.getFunction().arg_size() > RegisteredArgs
? MD.getFunction().arg_size() - RegisteredArgs
: 0;
OS.AddComment("stack arity");
AP.EmitInt16(StackArity);

View File

@ -34,12 +34,9 @@ namespace {
class OcamlGCMetadataPrinter : public GCMetadataPrinter {
public:
void beginAssembly(Module &M, GCModuleInfo &Info,
AsmPrinter &AP) override;
void finishAssembly(Module &M, GCModuleInfo &Info,
AsmPrinter &AP) override;
void beginAssembly(Module &M, GCModuleInfo &Info, AsmPrinter &AP) override;
void finishAssembly(Module &M, GCModuleInfo &Info, AsmPrinter &AP) override;
};
}
static GCMetadataPrinterRegistry::Add<OcamlGCMetadataPrinter>
@ -113,7 +110,8 @@ void OcamlGCMetadataPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
int NumDescriptors = 0;
for (GCModuleInfo::FuncInfoVec::iterator I = Info.funcinfo_begin(),
IE = Info.funcinfo_end(); I != IE; ++I) {
IE = Info.funcinfo_end();
I != IE; ++I) {
GCFunctionInfo &FI = **I;
if (FI.getStrategy().getName() != getStrategy().getName())
// this function is managed by some other GC
@ -131,7 +129,8 @@ void OcamlGCMetadataPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3);
for (GCModuleInfo::FuncInfoVec::iterator I = Info.funcinfo_begin(),
IE = Info.funcinfo_end(); I != IE; ++I) {
IE = Info.funcinfo_end();
I != IE; ++I) {
GCFunctionInfo &FI = **I;
if (FI.getStrategy().getName() != getStrategy().getName())
// this function is managed by some other GC
@ -142,8 +141,10 @@ void OcamlGCMetadataPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
// Very rude!
report_fatal_error("Function '" + FI.getFunction().getName() +
"' is too large for the ocaml GC! "
"Frame size " + Twine(FrameSize) + ">= 65536.\n"
"(" + Twine(uintptr_t(&FI)) + ")");
"Frame size " +
Twine(FrameSize) + ">= 65536.\n"
"(" +
Twine(uintptr_t(&FI)) + ")");
}
AP.OutStreamer.AddComment("live roots for " +
@ -156,7 +157,8 @@ void OcamlGCMetadataPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
// Very rude!
report_fatal_error("Function '" + FI.getFunction().getName() +
"' is too large for the ocaml GC! "
"Live root count "+Twine(LiveCount)+" >= 65536.");
"Live root count " +
Twine(LiveCount) + " >= 65536.");
}
AP.OutStreamer.EmitSymbolValue(J->Label, IntPtrSize);
@ -164,7 +166,8 @@ void OcamlGCMetadataPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
AP.EmitInt16(LiveCount);
for (GCFunctionInfo::live_iterator K = FI.live_begin(J),
KE = FI.live_end(J); K != KE; ++K) {
KE = FI.live_end(J);
K != KE; ++K) {
if (K->StackOffset >= 1 << 16) {
// Very rude!
report_fatal_error(

View File

@ -31,11 +31,10 @@ namespace {
public:
ErlangGC();
};
}
static GCRegistry::Add<ErlangGC>
X("erlang", "erlang-compatible garbage collector");
static GCRegistry::Add<ErlangGC> X("erlang",
"erlang-compatible garbage collector");
void llvm::linkErlangGC() {}

View File

@ -32,14 +32,12 @@ namespace {
public:
explicit Printer(raw_ostream &OS) : FunctionPass(ID), OS(OS) {}
const char *getPassName() const override;
void getAnalysisUsage(AnalysisUsage &AU) const override;
bool runOnFunction(Function &F) override;
bool doFinalization(Module &M) override;
};
}
INITIALIZE_PASS(GCModuleInfo, "collector-metadata",
@ -56,8 +54,7 @@ GCFunctionInfo::~GCFunctionInfo() {}
char GCModuleInfo::ID = 0;
GCModuleInfo::GCModuleInfo()
: ImmutablePass(ID) {
GCModuleInfo::GCModuleInfo() : ImmutablePass(ID) {
initializeGCModuleInfoPass(*PassRegistry::getPassRegistry());
}
@ -98,7 +95,6 @@ FunctionPass *llvm::createGCInfoPrinter(raw_ostream &OS) {
return new Printer(OS);
}
const char *Printer::getPassName() const {
return "Print Garbage Collector Information";
}
@ -111,33 +107,40 @@ void Printer::getAnalysisUsage(AnalysisUsage &AU) const {
static const char *DescKind(GC::PointKind Kind) {
switch (Kind) {
case GC::Loop: return "loop";
case GC::Return: return "return";
case GC::PreCall: return "pre-call";
case GC::PostCall: return "post-call";
case GC::Loop:
return "loop";
case GC::Return:
return "return";
case GC::PreCall:
return "pre-call";
case GC::PostCall:
return "post-call";
}
llvm_unreachable("Invalid point kind");
}
bool Printer::runOnFunction(Function &F) {
if (F.hasGC()) return false;
if (F.hasGC())
return false;
GCFunctionInfo *FD = &getAnalysis<GCModuleInfo>().getFunctionInfo(F);
OS << "GC roots for " << FD->getFunction().getName() << ":\n";
for (GCFunctionInfo::roots_iterator RI = FD->roots_begin(),
RE = FD->roots_end(); RI != RE; ++RI)
RE = FD->roots_end();
RI != RE; ++RI)
OS << "\t" << RI->Num << "\t" << RI->StackOffset << "[sp]\n";
OS << "GC safe points for " << FD->getFunction().getName() << ":\n";
for (GCFunctionInfo::iterator PI = FD->begin(),
PE = FD->end(); PI != PE; ++PI) {
for (GCFunctionInfo::iterator PI = FD->begin(), PE = FD->end(); PI != PE;
++PI) {
OS << "\t" << PI->Label->getName() << ": "
<< DescKind(PI->Kind) << ", live = {";
OS << "\t" << PI->Label->getName() << ": " << DescKind(PI->Kind)
<< ", live = {";
for (GCFunctionInfo::live_iterator RI = FD->live_begin(PI),
RE = FD->live_end(PI);;) {
RE = FD->live_end(PI);
;) {
OS << " " << RI->Num;
if (++RI == RE)
break;

View File

@ -116,8 +116,6 @@ static bool NeedsCustomLoweringPass(const GCStrategy &C) {
return C.customWriteBarrier() || C.customReadBarrier() || C.customRoots();
}
/// doInitialization - If this module uses the GC intrinsics, find them now.
bool LowerIntrinsics::doInitialization(Module &M) {
// FIXME: This is rather antisocial in the context of a JIT since it performs
@ -139,7 +137,6 @@ bool LowerIntrinsics::doInitialization(Module &M) {
return MadeChange;
}
/// CouldBecomeSafePoint - Predicate to conservatively determine whether the
/// instruction could introduce a safe point.
static bool CouldBecomeSafePoint(Instruction *I) {
@ -199,7 +196,6 @@ static bool InsertRootInitializers(Function &F, AllocaInst **Roots,
return MadeChange;
}
/// runOnFunction - Replace gcread/gcwrite intrinsics with loads and stores.
/// Leave gcroot intrinsics; the code generator needs to see those.
bool LowerIntrinsics::runOnFunction(Function &F) {

View File

@ -26,8 +26,7 @@ namespace {
};
}
static GCRegistry::Add<OcamlGC>
X("ocaml", "ocaml 3.10-compatible GC");
static GCRegistry::Add<OcamlGC> X("ocaml", "ocaml 3.10-compatible GC");
void llvm::linkOcamlGC() {}

View File

@ -64,14 +64,13 @@ namespace {
Constant *GetFrameMap(Function &F);
Type *GetConcreteStackEntryType(Function &F);
void CollectRoots(Function &F);
static GetElementPtrInst *CreateGEP(LLVMContext &Context,
IRBuilder<> &B, Value *BasePtr,
int Idx1, const char *Name);
static GetElementPtrInst *CreateGEP(LLVMContext &Context,
IRBuilder<> &B, Value *BasePtr,
int Idx1, int Idx2, const char *Name);
static GetElementPtrInst *CreateGEP(LLVMContext &Context, IRBuilder<> &B,
Value *BasePtr, int Idx1,
const char *Name);
static GetElementPtrInst *CreateGEP(LLVMContext &Context, IRBuilder<> &B,
Value *BasePtr, int Idx1, int Idx2,
const char *Name);
};
}
static GCRegistry::Add<ShadowStackGC>
@ -128,10 +127,9 @@ namespace {
// Find all 'call' instructions.
SmallVector<Instruction *, 16> Calls;
for (Function::iterator BB = F.begin(),
E = F.end(); BB != E; ++BB)
for (BasicBlock::iterator II = BB->begin(),
EE = BB->end(); II != EE; ++II)
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
for (BasicBlock::iterator II = BB->begin(), EE = BB->end(); II != EE;
++II)
if (CallInst *CI = dyn_cast<CallInst>(II))
if (!CI->getCalledFunction() ||
!CI->getCalledFunction()->getIntrinsicID())
@ -143,15 +141,12 @@ namespace {
// Create a cleanup block.
LLVMContext &C = F.getContext();
BasicBlock *CleanupBB = BasicBlock::Create(C, CleanupBBName, &F);
Type *ExnTy = StructType::get(Type::getInt8PtrTy(C),
Type::getInt32Ty(C), nullptr);
Constant *PersFn =
F.getParent()->
getOrInsertFunction("__gcc_personality_v0",
FunctionType::get(Type::getInt32Ty(C), true));
LandingPadInst *LPad = LandingPadInst::Create(ExnTy, PersFn, 1,
"cleanup.lpad",
CleanupBB);
Type *ExnTy =
StructType::get(Type::getInt8PtrTy(C), Type::getInt32Ty(C), nullptr);
Constant *PersFn = F.getParent()->getOrInsertFunction(
"__gcc_personality_v0", FunctionType::get(Type::getInt32Ty(C), true));
LandingPadInst *LPad =
LandingPadInst::Create(ExnTy, PersFn, 1, "cleanup.lpad", CleanupBB);
LPad->setCleanup(true);
ResumeInst *RI = ResumeInst::Create(LPad, CleanupBB);
@ -175,9 +170,9 @@ namespace {
CallSite CS(CI);
Args.append(CS.arg_begin(), CS.arg_end());
InvokeInst *II = InvokeInst::Create(CI->getCalledValue(),
NewBB, CleanupBB,
Args, CI->getName(), CallBB);
InvokeInst *II =
InvokeInst::Create(CI->getCalledValue(), NewBB, CleanupBB, Args,
CI->getName(), CallBB);
II->setCallingConv(CI->getCallingConv());
II->setAttributes(CI->getAttributes());
CI->replaceAllUsesWith(II);
@ -224,8 +219,7 @@ Constant *ShadowStackGC::GetFrameMap(Function &F) {
Constant *DescriptorElts[] = {
ConstantStruct::get(FrameMapTy, BaseElts),
ConstantArray::get(ArrayType::get(VoidPtr, NumMeta), Metadata)
};
ConstantArray::get(ArrayType::get(VoidPtr, NumMeta), Metadata)};
Type *EltTys[] = {DescriptorElts[0]->getType(), DescriptorElts[1]->getType()};
StructType *STy = StructType::create(EltTys, "gc_map." + utostr(NumMeta));
@ -246,13 +240,12 @@ Constant *ShadowStackGC::GetFrameMap(Function &F) {
// (which uses a FunctionPassManager (which segfaults (not asserts) if
// provided a ModulePass))).
Constant *GV = new GlobalVariable(*F.getParent(), FrameMap->getType(), true,
GlobalVariable::InternalLinkage,
FrameMap, "__gc_" + F.getName());
GlobalVariable::InternalLinkage, FrameMap,
"__gc_" + F.getName());
Constant *GEPIndices[2] = {
ConstantInt::get(Type::getInt32Ty(F.getContext()), 0),
ConstantInt::get(Type::getInt32Ty(F.getContext()), 0)
};
ConstantInt::get(Type::getInt32Ty(F.getContext()), 0)};
return ConstantExpr::getGetElementPtr(GV, GEPIndices);
}
@ -301,10 +294,9 @@ bool ShadowStackGC::initializeCustomLowering(Module &M) {
if (!Head) {
// If the root chain does not exist, insert a new one with linkonce
// linkage!
Head = new GlobalVariable(M, StackEntryPtrTy, false,
GlobalValue::LinkOnceAnyLinkage,
Constant::getNullValue(StackEntryPtrTy),
"llvm_gc_root_chain");
Head = new GlobalVariable(
M, StackEntryPtrTy, false, GlobalValue::LinkOnceAnyLinkage,
Constant::getNullValue(StackEntryPtrTy), "llvm_gc_root_chain");
} else if (Head->hasExternalLinkage() && Head->isDeclaration()) {
Head->setInitializer(Constant::getNullValue(StackEntryPtrTy));
Head->setLinkage(GlobalValue::LinkOnceAnyLinkage);
@ -334,7 +326,8 @@ void ShadowStackGC::CollectRoots(Function &F) {
if (Function *F = CI->getCalledFunction())
if (F->getIntrinsicID() == Intrinsic::gcroot) {
std::pair<CallInst *, AllocaInst *> Pair = std::make_pair(
CI, cast<AllocaInst>(CI->getArgOperand(0)->stripPointerCasts()));
CI,
cast<AllocaInst>(CI->getArgOperand(0)->stripPointerCasts()));
if (IsNullValue(CI->getArgOperand(1)))
Roots.push_back(Pair);
else
@ -346,9 +339,10 @@ void ShadowStackGC::CollectRoots(Function &F) {
Roots.insert(Roots.begin(), MetaRoots.begin(), MetaRoots.end());
}
GetElementPtrInst *
ShadowStackGC::CreateGEP(LLVMContext &Context, IRBuilder<> &B, Value *BasePtr,
int Idx, int Idx2, const char *Name) {
GetElementPtrInst *ShadowStackGC::CreateGEP(LLVMContext &Context,
IRBuilder<> &B, Value *BasePtr,
int Idx, int Idx2,
const char *Name) {
Value *Indices[] = {ConstantInt::get(Type::getInt32Ty(Context), 0),
ConstantInt::get(Type::getInt32Ty(Context), Idx),
ConstantInt::get(Type::getInt32Ty(Context), Idx2)};
@ -359,8 +353,8 @@ ShadowStackGC::CreateGEP(LLVMContext &Context, IRBuilder<> &B, Value *BasePtr,
return dyn_cast<GetElementPtrInst>(Val);
}
GetElementPtrInst *
ShadowStackGC::CreateGEP(LLVMContext &Context, IRBuilder<> &B, Value *BasePtr,
GetElementPtrInst *ShadowStackGC::CreateGEP(LLVMContext &Context,
IRBuilder<> &B, Value *BasePtr,
int Idx, const char *Name) {
Value *Indices[] = {ConstantInt::get(Type::getInt32Ty(Context), 0),
ConstantInt::get(Type::getInt32Ty(Context), Idx)};
@ -391,16 +385,17 @@ bool ShadowStackGC::performCustomLowering(Function &F) {
BasicBlock::iterator IP = F.getEntryBlock().begin();
IRBuilder<> AtEntry(IP->getParent(), IP);
Instruction *StackEntry = AtEntry.CreateAlloca(ConcreteStackEntryTy, nullptr,
"gc_frame");
Instruction *StackEntry =
AtEntry.CreateAlloca(ConcreteStackEntryTy, nullptr, "gc_frame");
while (isa<AllocaInst>(IP)) ++IP;
while (isa<AllocaInst>(IP))
++IP;
AtEntry.SetInsertPoint(IP->getParent(), IP);
// Initialize the map pointer and load the current head of the shadow stack.
Instruction *CurrentHead = AtEntry.CreateLoad(Head, "gc_currhead");
Instruction *EntryMapPtr = CreateGEP(Context, AtEntry, StackEntry,
0,1,"gc_frame.map");
Instruction *EntryMapPtr =
CreateGEP(Context, AtEntry, StackEntry, 0, 1, "gc_frame.map");
AtEntry.CreateStore(FrameMap, EntryMapPtr);
// After all the allocas...
@ -418,14 +413,15 @@ bool ShadowStackGC::performCustomLowering(Function &F) {
// really necessary (the collector would never see the intermediate state at
// runtime), but it's nicer not to push the half-initialized entry onto the
// shadow stack.
while (isa<StoreInst>(IP)) ++IP;
while (isa<StoreInst>(IP))
++IP;
AtEntry.SetInsertPoint(IP->getParent(), IP);
// Push the entry onto the shadow stack.
Instruction *EntryNextPtr = CreateGEP(Context, AtEntry,
StackEntry,0,0,"gc_frame.next");
Instruction *NewHeadVal = CreateGEP(Context, AtEntry,
StackEntry, 0, "gc_newhead");
Instruction *EntryNextPtr =
CreateGEP(Context, AtEntry, StackEntry, 0, 0, "gc_frame.next");
Instruction *NewHeadVal =
CreateGEP(Context, AtEntry, StackEntry, 0, "gc_newhead");
AtEntry.CreateStore(CurrentHead, EntryNextPtr);
AtEntry.CreateStore(NewHeadVal, Head);
@ -434,8 +430,8 @@ bool ShadowStackGC::performCustomLowering(Function &F) {
while (IRBuilder<> *AtExit = EE.Next()) {
// Pop the entry from the shadow stack. Don't reuse CurrentHead from
// AtEntry, since that would make the value live for the entire function.
Instruction *EntryNextPtr2 = CreateGEP(Context, *AtExit, StackEntry, 0, 0,
"gc_frame.next");
Instruction *EntryNextPtr2 =
CreateGEP(Context, *AtExit, StackEntry, 0, 0, "gc_frame.next");
Value *SavedHead = AtExit->CreateLoad(EntryNextPtr2, "gc_savedhead");
AtExit->CreateStore(SavedHead, Head);
}

View File

@ -45,8 +45,8 @@ public:
};
}
static GCRegistry::Add<StatepointGC>
X("statepoint-example", "an example strategy for statepoint");
static GCRegistry::Add<StatepointGC> X("statepoint-example",
"an example strategy for statepoint");
namespace llvm {
void linkStatepointExampleGC() {}

View File

@ -18,5 +18,5 @@ using namespace llvm;
GCStrategy::GCStrategy()
: UseStatepoints(false), NeededSafePoints(0), CustomReadBarriers(false),
CustomWriteBarriers(false), CustomRoots(false),
InitRoots(true), UsesMetadata(false) {}
CustomWriteBarriers(false), CustomRoots(false), InitRoots(true),
UsesMetadata(false) {}