mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-21 06:30:16 +00:00
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:
parent
61bd005d1b
commit
999412767a
@ -67,7 +67,6 @@ namespace llvm {
|
|||||||
GCRoot(int N, const Constant *MD) : Num(N), StackOffset(-1), Metadata(MD) {}
|
GCRoot(int N, const Constant *MD) : Num(N), StackOffset(-1), Metadata(MD) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Garbage collection metadata for a single function. Currently, this
|
/// Garbage collection metadata for a single function. Currently, this
|
||||||
/// information only applies to GCStrategies which use GCRoot.
|
/// information only applies to GCStrategies which use GCRoot.
|
||||||
class GCFunctionInfo {
|
class GCFunctionInfo {
|
||||||
@ -155,6 +154,7 @@ namespace llvm {
|
|||||||
/// A list of GCStrategies which are active in this Module. These are
|
/// A list of GCStrategies which are active in this Module. These are
|
||||||
/// not owning pointers.
|
/// not owning pointers.
|
||||||
std::vector<GCStrategy *> StrategyList;
|
std::vector<GCStrategy *> StrategyList;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// List of per function info objects. In theory, Each of these
|
/// List of per function info objects. In theory, Each of these
|
||||||
/// may be associated with a different GC.
|
/// may be associated with a different GC.
|
||||||
@ -163,7 +163,6 @@ namespace llvm {
|
|||||||
FuncInfoVec::iterator funcinfo_begin() { return Functions.begin(); }
|
FuncInfoVec::iterator funcinfo_begin() { return Functions.begin(); }
|
||||||
FuncInfoVec::iterator funcinfo_end() { return Functions.end(); }
|
FuncInfoVec::iterator funcinfo_end() { return Functions.end(); }
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Owning list of all GCFunctionInfos associated with this Module
|
/// Owning list of all GCFunctionInfos associated with this Module
|
||||||
FuncInfoVec Functions;
|
FuncInfoVec Functions;
|
||||||
@ -172,8 +171,8 @@ namespace llvm {
|
|||||||
/// associated with a particular Function.
|
/// associated with a particular Function.
|
||||||
typedef DenseMap<const Function *, GCFunctionInfo *> finfo_map_type;
|
typedef DenseMap<const Function *, GCFunctionInfo *> finfo_map_type;
|
||||||
finfo_map_type FInfoMap;
|
finfo_map_type FInfoMap;
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
typedef std::vector<GCStrategy *>::const_iterator iterator;
|
typedef std::vector<GCStrategy *>::const_iterator iterator;
|
||||||
|
|
||||||
static char ID;
|
static char ID;
|
||||||
@ -195,7 +194,6 @@ namespace llvm {
|
|||||||
/// will soon change.
|
/// will soon change.
|
||||||
GCFunctionInfo &getFunctionInfo(const Function &F);
|
GCFunctionInfo &getFunctionInfo(const Function &F);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -45,24 +45,20 @@ namespace llvm {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
GCMetadataPrinter(const GCMetadataPrinter &) LLVM_DELETED_FUNCTION;
|
GCMetadataPrinter(const GCMetadataPrinter &) LLVM_DELETED_FUNCTION;
|
||||||
GCMetadataPrinter &
|
GCMetadataPrinter &operator=(const GCMetadataPrinter &) LLVM_DELETED_FUNCTION;
|
||||||
operator=(const GCMetadataPrinter &) LLVM_DELETED_FUNCTION;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GCStrategy &getStrategy() { return *S; }
|
GCStrategy &getStrategy() { return *S; }
|
||||||
|
|
||||||
/// Called before the assembly for the module is generated by
|
/// Called before the assembly for the module is generated by
|
||||||
/// the AsmPrinter (but after target specific hooks.)
|
/// the AsmPrinter (but after target specific hooks.)
|
||||||
virtual void beginAssembly(Module &M, GCModuleInfo &Info,
|
virtual void beginAssembly(Module &M, GCModuleInfo &Info, AsmPrinter &AP) {}
|
||||||
AsmPrinter &AP) {}
|
|
||||||
/// Called after the assembly for the module is generated by
|
/// Called after the assembly for the module is generated by
|
||||||
/// the AsmPrinter (but before target specific hooks)
|
/// the AsmPrinter (but before target specific hooks)
|
||||||
virtual void finishAssembly(Module &M, GCModuleInfo &Info,
|
virtual void finishAssembly(Module &M, GCModuleInfo &Info, AsmPrinter &AP) {}
|
||||||
AsmPrinter &AP) {}
|
|
||||||
|
|
||||||
virtual ~GCMetadataPrinter();
|
virtual ~GCMetadataPrinter();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -70,7 +70,6 @@ namespace llvm {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// GCStrategy describes a garbage collector algorithm's code generation
|
/// GCStrategy describes a garbage collector algorithm's code generation
|
||||||
/// requirements, and provides overridable hooks for those needs which cannot
|
/// requirements, and provides overridable hooks for those needs which cannot
|
||||||
/// be abstractly described. GCStrategy objects must be looked up through
|
/// 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
|
/// True if safe points of any kind are required. By default, none are
|
||||||
/// recorded.
|
/// recorded.
|
||||||
bool needsSafePoints() const {
|
bool needsSafePoints() const { return NeededSafePoints != 0; }
|
||||||
return NeededSafePoints != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// True if the given kind of safe point is required. By default, none are
|
/// True if the given kind of safe point is required. By default, none are
|
||||||
/// recorded.
|
/// recorded.
|
||||||
|
@ -36,10 +36,8 @@ namespace {
|
|||||||
|
|
||||||
class ErlangGCPrinter : public GCMetadataPrinter {
|
class ErlangGCPrinter : public GCMetadataPrinter {
|
||||||
public:
|
public:
|
||||||
void finishAssembly(Module &M, GCModuleInfo &Info,
|
void finishAssembly(Module &M, GCModuleInfo &Info, AsmPrinter &AP) override;
|
||||||
AsmPrinter &AP) override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GCMetadataPrinterRegistry::Add<ErlangGCPrinter>
|
static GCMetadataPrinterRegistry::Add<ErlangGCPrinter>
|
||||||
@ -54,9 +52,9 @@ void ErlangGCPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
|
|||||||
AP.TM.getSubtargetImpl()->getDataLayout()->getPointerSize();
|
AP.TM.getSubtargetImpl()->getDataLayout()->getPointerSize();
|
||||||
|
|
||||||
// Put this in a custom .note section.
|
// Put this in a custom .note section.
|
||||||
AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getContext()
|
AP.OutStreamer.SwitchSection(
|
||||||
.getELFSection(".note.gc", ELF::SHT_PROGBITS, 0,
|
AP.getObjFileLowering().getContext().getELFSection(
|
||||||
SectionKind::getDataRel()));
|
".note.gc", ELF::SHT_PROGBITS, 0, SectionKind::getDataRel()));
|
||||||
|
|
||||||
// For each function...
|
// For each function...
|
||||||
for (GCModuleInfo::FuncInfoVec::iterator FI = Info.funcinfo_begin(),
|
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.
|
// Emit stack arity, i.e. the number of stacked arguments.
|
||||||
unsigned RegisteredArgs = IntPtrSize == 4 ? 5 : 6;
|
unsigned RegisteredArgs = IntPtrSize == 4 ? 5 : 6;
|
||||||
unsigned StackArity = MD.getFunction().arg_size() > RegisteredArgs ?
|
unsigned StackArity = MD.getFunction().arg_size() > RegisteredArgs
|
||||||
MD.getFunction().arg_size() - RegisteredArgs : 0;
|
? MD.getFunction().arg_size() - RegisteredArgs
|
||||||
|
: 0;
|
||||||
OS.AddComment("stack arity");
|
OS.AddComment("stack arity");
|
||||||
AP.EmitInt16(StackArity);
|
AP.EmitInt16(StackArity);
|
||||||
|
|
||||||
|
@ -34,12 +34,9 @@ namespace {
|
|||||||
|
|
||||||
class OcamlGCMetadataPrinter : public GCMetadataPrinter {
|
class OcamlGCMetadataPrinter : public GCMetadataPrinter {
|
||||||
public:
|
public:
|
||||||
void beginAssembly(Module &M, GCModuleInfo &Info,
|
void beginAssembly(Module &M, GCModuleInfo &Info, AsmPrinter &AP) override;
|
||||||
AsmPrinter &AP) override;
|
void finishAssembly(Module &M, GCModuleInfo &Info, AsmPrinter &AP) override;
|
||||||
void finishAssembly(Module &M, GCModuleInfo &Info,
|
|
||||||
AsmPrinter &AP) override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GCMetadataPrinterRegistry::Add<OcamlGCMetadataPrinter>
|
static GCMetadataPrinterRegistry::Add<OcamlGCMetadataPrinter>
|
||||||
@ -113,7 +110,8 @@ void OcamlGCMetadataPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
|
|||||||
|
|
||||||
int NumDescriptors = 0;
|
int NumDescriptors = 0;
|
||||||
for (GCModuleInfo::FuncInfoVec::iterator I = Info.funcinfo_begin(),
|
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;
|
GCFunctionInfo &FI = **I;
|
||||||
if (FI.getStrategy().getName() != getStrategy().getName())
|
if (FI.getStrategy().getName() != getStrategy().getName())
|
||||||
// this function is managed by some other GC
|
// 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);
|
AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3);
|
||||||
|
|
||||||
for (GCModuleInfo::FuncInfoVec::iterator I = Info.funcinfo_begin(),
|
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;
|
GCFunctionInfo &FI = **I;
|
||||||
if (FI.getStrategy().getName() != getStrategy().getName())
|
if (FI.getStrategy().getName() != getStrategy().getName())
|
||||||
// this function is managed by some other GC
|
// this function is managed by some other GC
|
||||||
@ -142,8 +141,10 @@ void OcamlGCMetadataPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
|
|||||||
// Very rude!
|
// Very rude!
|
||||||
report_fatal_error("Function '" + FI.getFunction().getName() +
|
report_fatal_error("Function '" + FI.getFunction().getName() +
|
||||||
"' is too large for the ocaml GC! "
|
"' is too large for the ocaml GC! "
|
||||||
"Frame size " + Twine(FrameSize) + ">= 65536.\n"
|
"Frame size " +
|
||||||
"(" + Twine(uintptr_t(&FI)) + ")");
|
Twine(FrameSize) + ">= 65536.\n"
|
||||||
|
"(" +
|
||||||
|
Twine(uintptr_t(&FI)) + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
AP.OutStreamer.AddComment("live roots for " +
|
AP.OutStreamer.AddComment("live roots for " +
|
||||||
@ -156,7 +157,8 @@ void OcamlGCMetadataPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
|
|||||||
// Very rude!
|
// Very rude!
|
||||||
report_fatal_error("Function '" + FI.getFunction().getName() +
|
report_fatal_error("Function '" + FI.getFunction().getName() +
|
||||||
"' is too large for the ocaml GC! "
|
"' 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);
|
AP.OutStreamer.EmitSymbolValue(J->Label, IntPtrSize);
|
||||||
@ -164,7 +166,8 @@ void OcamlGCMetadataPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
|
|||||||
AP.EmitInt16(LiveCount);
|
AP.EmitInt16(LiveCount);
|
||||||
|
|
||||||
for (GCFunctionInfo::live_iterator K = FI.live_begin(J),
|
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) {
|
if (K->StackOffset >= 1 << 16) {
|
||||||
// Very rude!
|
// Very rude!
|
||||||
report_fatal_error(
|
report_fatal_error(
|
||||||
|
@ -31,11 +31,10 @@ namespace {
|
|||||||
public:
|
public:
|
||||||
ErlangGC();
|
ErlangGC();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GCRegistry::Add<ErlangGC>
|
static GCRegistry::Add<ErlangGC> X("erlang",
|
||||||
X("erlang", "erlang-compatible garbage collector");
|
"erlang-compatible garbage collector");
|
||||||
|
|
||||||
void llvm::linkErlangGC() {}
|
void llvm::linkErlangGC() {}
|
||||||
|
|
||||||
|
@ -32,14 +32,12 @@ namespace {
|
|||||||
public:
|
public:
|
||||||
explicit Printer(raw_ostream &OS) : FunctionPass(ID), OS(OS) {}
|
explicit Printer(raw_ostream &OS) : FunctionPass(ID), OS(OS) {}
|
||||||
|
|
||||||
|
|
||||||
const char *getPassName() const override;
|
const char *getPassName() const override;
|
||||||
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
||||||
|
|
||||||
bool runOnFunction(Function &F) override;
|
bool runOnFunction(Function &F) override;
|
||||||
bool doFinalization(Module &M) override;
|
bool doFinalization(Module &M) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
INITIALIZE_PASS(GCModuleInfo, "collector-metadata",
|
INITIALIZE_PASS(GCModuleInfo, "collector-metadata",
|
||||||
@ -56,8 +54,7 @@ GCFunctionInfo::~GCFunctionInfo() {}
|
|||||||
|
|
||||||
char GCModuleInfo::ID = 0;
|
char GCModuleInfo::ID = 0;
|
||||||
|
|
||||||
GCModuleInfo::GCModuleInfo()
|
GCModuleInfo::GCModuleInfo() : ImmutablePass(ID) {
|
||||||
: ImmutablePass(ID) {
|
|
||||||
initializeGCModuleInfoPass(*PassRegistry::getPassRegistry());
|
initializeGCModuleInfoPass(*PassRegistry::getPassRegistry());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +95,6 @@ FunctionPass *llvm::createGCInfoPrinter(raw_ostream &OS) {
|
|||||||
return new Printer(OS);
|
return new Printer(OS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char *Printer::getPassName() const {
|
const char *Printer::getPassName() const {
|
||||||
return "Print Garbage Collector Information";
|
return "Print Garbage Collector Information";
|
||||||
}
|
}
|
||||||
@ -111,33 +107,40 @@ void Printer::getAnalysisUsage(AnalysisUsage &AU) const {
|
|||||||
|
|
||||||
static const char *DescKind(GC::PointKind Kind) {
|
static const char *DescKind(GC::PointKind Kind) {
|
||||||
switch (Kind) {
|
switch (Kind) {
|
||||||
case GC::Loop: return "loop";
|
case GC::Loop:
|
||||||
case GC::Return: return "return";
|
return "loop";
|
||||||
case GC::PreCall: return "pre-call";
|
case GC::Return:
|
||||||
case GC::PostCall: return "post-call";
|
return "return";
|
||||||
|
case GC::PreCall:
|
||||||
|
return "pre-call";
|
||||||
|
case GC::PostCall:
|
||||||
|
return "post-call";
|
||||||
}
|
}
|
||||||
llvm_unreachable("Invalid point kind");
|
llvm_unreachable("Invalid point kind");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Printer::runOnFunction(Function &F) {
|
bool Printer::runOnFunction(Function &F) {
|
||||||
if (F.hasGC()) return false;
|
if (F.hasGC())
|
||||||
|
return false;
|
||||||
|
|
||||||
GCFunctionInfo *FD = &getAnalysis<GCModuleInfo>().getFunctionInfo(F);
|
GCFunctionInfo *FD = &getAnalysis<GCModuleInfo>().getFunctionInfo(F);
|
||||||
|
|
||||||
OS << "GC roots for " << FD->getFunction().getName() << ":\n";
|
OS << "GC roots for " << FD->getFunction().getName() << ":\n";
|
||||||
for (GCFunctionInfo::roots_iterator RI = FD->roots_begin(),
|
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 << "\t" << RI->Num << "\t" << RI->StackOffset << "[sp]\n";
|
||||||
|
|
||||||
OS << "GC safe points for " << FD->getFunction().getName() << ":\n";
|
OS << "GC safe points for " << FD->getFunction().getName() << ":\n";
|
||||||
for (GCFunctionInfo::iterator PI = FD->begin(),
|
for (GCFunctionInfo::iterator PI = FD->begin(), PE = FD->end(); PI != PE;
|
||||||
PE = FD->end(); PI != PE; ++PI) {
|
++PI) {
|
||||||
|
|
||||||
OS << "\t" << PI->Label->getName() << ": "
|
OS << "\t" << PI->Label->getName() << ": " << DescKind(PI->Kind)
|
||||||
<< DescKind(PI->Kind) << ", live = {";
|
<< ", live = {";
|
||||||
|
|
||||||
for (GCFunctionInfo::live_iterator RI = FD->live_begin(PI),
|
for (GCFunctionInfo::live_iterator RI = FD->live_begin(PI),
|
||||||
RE = FD->live_end(PI);;) {
|
RE = FD->live_end(PI);
|
||||||
|
;) {
|
||||||
OS << " " << RI->Num;
|
OS << " " << RI->Num;
|
||||||
if (++RI == RE)
|
if (++RI == RE)
|
||||||
break;
|
break;
|
||||||
|
@ -116,8 +116,6 @@ static bool NeedsCustomLoweringPass(const GCStrategy &C) {
|
|||||||
return C.customWriteBarrier() || C.customReadBarrier() || C.customRoots();
|
return C.customWriteBarrier() || C.customReadBarrier() || C.customRoots();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// doInitialization - If this module uses the GC intrinsics, find them now.
|
/// doInitialization - If this module uses the GC intrinsics, find them now.
|
||||||
bool LowerIntrinsics::doInitialization(Module &M) {
|
bool LowerIntrinsics::doInitialization(Module &M) {
|
||||||
// FIXME: This is rather antisocial in the context of a JIT since it performs
|
// 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;
|
return MadeChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// CouldBecomeSafePoint - Predicate to conservatively determine whether the
|
/// CouldBecomeSafePoint - Predicate to conservatively determine whether the
|
||||||
/// instruction could introduce a safe point.
|
/// instruction could introduce a safe point.
|
||||||
static bool CouldBecomeSafePoint(Instruction *I) {
|
static bool CouldBecomeSafePoint(Instruction *I) {
|
||||||
@ -199,7 +196,6 @@ static bool InsertRootInitializers(Function &F, AllocaInst **Roots,
|
|||||||
return MadeChange;
|
return MadeChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// runOnFunction - Replace gcread/gcwrite intrinsics with loads and stores.
|
/// runOnFunction - Replace gcread/gcwrite intrinsics with loads and stores.
|
||||||
/// Leave gcroot intrinsics; the code generator needs to see those.
|
/// Leave gcroot intrinsics; the code generator needs to see those.
|
||||||
bool LowerIntrinsics::runOnFunction(Function &F) {
|
bool LowerIntrinsics::runOnFunction(Function &F) {
|
||||||
|
@ -26,8 +26,7 @@ namespace {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static GCRegistry::Add<OcamlGC>
|
static GCRegistry::Add<OcamlGC> X("ocaml", "ocaml 3.10-compatible GC");
|
||||||
X("ocaml", "ocaml 3.10-compatible GC");
|
|
||||||
|
|
||||||
void llvm::linkOcamlGC() {}
|
void llvm::linkOcamlGC() {}
|
||||||
|
|
||||||
|
@ -64,14 +64,13 @@ namespace {
|
|||||||
Constant *GetFrameMap(Function &F);
|
Constant *GetFrameMap(Function &F);
|
||||||
Type *GetConcreteStackEntryType(Function &F);
|
Type *GetConcreteStackEntryType(Function &F);
|
||||||
void CollectRoots(Function &F);
|
void CollectRoots(Function &F);
|
||||||
static GetElementPtrInst *CreateGEP(LLVMContext &Context,
|
static GetElementPtrInst *CreateGEP(LLVMContext &Context, IRBuilder<> &B,
|
||||||
IRBuilder<> &B, Value *BasePtr,
|
Value *BasePtr, int Idx1,
|
||||||
int Idx1, const char *Name);
|
const char *Name);
|
||||||
static GetElementPtrInst *CreateGEP(LLVMContext &Context,
|
static GetElementPtrInst *CreateGEP(LLVMContext &Context, IRBuilder<> &B,
|
||||||
IRBuilder<> &B, Value *BasePtr,
|
Value *BasePtr, int Idx1, int Idx2,
|
||||||
int Idx1, int Idx2, const char *Name);
|
const char *Name);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GCRegistry::Add<ShadowStackGC>
|
static GCRegistry::Add<ShadowStackGC>
|
||||||
@ -128,10 +127,9 @@ namespace {
|
|||||||
|
|
||||||
// Find all 'call' instructions.
|
// Find all 'call' instructions.
|
||||||
SmallVector<Instruction *, 16> Calls;
|
SmallVector<Instruction *, 16> Calls;
|
||||||
for (Function::iterator BB = F.begin(),
|
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
|
||||||
E = F.end(); BB != E; ++BB)
|
for (BasicBlock::iterator II = BB->begin(), EE = BB->end(); II != EE;
|
||||||
for (BasicBlock::iterator II = BB->begin(),
|
++II)
|
||||||
EE = BB->end(); II != EE; ++II)
|
|
||||||
if (CallInst *CI = dyn_cast<CallInst>(II))
|
if (CallInst *CI = dyn_cast<CallInst>(II))
|
||||||
if (!CI->getCalledFunction() ||
|
if (!CI->getCalledFunction() ||
|
||||||
!CI->getCalledFunction()->getIntrinsicID())
|
!CI->getCalledFunction()->getIntrinsicID())
|
||||||
@ -143,15 +141,12 @@ namespace {
|
|||||||
// Create a cleanup block.
|
// Create a cleanup block.
|
||||||
LLVMContext &C = F.getContext();
|
LLVMContext &C = F.getContext();
|
||||||
BasicBlock *CleanupBB = BasicBlock::Create(C, CleanupBBName, &F);
|
BasicBlock *CleanupBB = BasicBlock::Create(C, CleanupBBName, &F);
|
||||||
Type *ExnTy = StructType::get(Type::getInt8PtrTy(C),
|
Type *ExnTy =
|
||||||
Type::getInt32Ty(C), nullptr);
|
StructType::get(Type::getInt8PtrTy(C), Type::getInt32Ty(C), nullptr);
|
||||||
Constant *PersFn =
|
Constant *PersFn = F.getParent()->getOrInsertFunction(
|
||||||
F.getParent()->
|
"__gcc_personality_v0", FunctionType::get(Type::getInt32Ty(C), true));
|
||||||
getOrInsertFunction("__gcc_personality_v0",
|
LandingPadInst *LPad =
|
||||||
FunctionType::get(Type::getInt32Ty(C), true));
|
LandingPadInst::Create(ExnTy, PersFn, 1, "cleanup.lpad", CleanupBB);
|
||||||
LandingPadInst *LPad = LandingPadInst::Create(ExnTy, PersFn, 1,
|
|
||||||
"cleanup.lpad",
|
|
||||||
CleanupBB);
|
|
||||||
LPad->setCleanup(true);
|
LPad->setCleanup(true);
|
||||||
ResumeInst *RI = ResumeInst::Create(LPad, CleanupBB);
|
ResumeInst *RI = ResumeInst::Create(LPad, CleanupBB);
|
||||||
|
|
||||||
@ -175,9 +170,9 @@ namespace {
|
|||||||
CallSite CS(CI);
|
CallSite CS(CI);
|
||||||
Args.append(CS.arg_begin(), CS.arg_end());
|
Args.append(CS.arg_begin(), CS.arg_end());
|
||||||
|
|
||||||
InvokeInst *II = InvokeInst::Create(CI->getCalledValue(),
|
InvokeInst *II =
|
||||||
NewBB, CleanupBB,
|
InvokeInst::Create(CI->getCalledValue(), NewBB, CleanupBB, Args,
|
||||||
Args, CI->getName(), CallBB);
|
CI->getName(), CallBB);
|
||||||
II->setCallingConv(CI->getCallingConv());
|
II->setCallingConv(CI->getCallingConv());
|
||||||
II->setAttributes(CI->getAttributes());
|
II->setAttributes(CI->getAttributes());
|
||||||
CI->replaceAllUsesWith(II);
|
CI->replaceAllUsesWith(II);
|
||||||
@ -224,8 +219,7 @@ Constant *ShadowStackGC::GetFrameMap(Function &F) {
|
|||||||
|
|
||||||
Constant *DescriptorElts[] = {
|
Constant *DescriptorElts[] = {
|
||||||
ConstantStruct::get(FrameMapTy, BaseElts),
|
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()};
|
Type *EltTys[] = {DescriptorElts[0]->getType(), DescriptorElts[1]->getType()};
|
||||||
StructType *STy = StructType::create(EltTys, "gc_map." + utostr(NumMeta));
|
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
|
// (which uses a FunctionPassManager (which segfaults (not asserts) if
|
||||||
// provided a ModulePass))).
|
// provided a ModulePass))).
|
||||||
Constant *GV = new GlobalVariable(*F.getParent(), FrameMap->getType(), true,
|
Constant *GV = new GlobalVariable(*F.getParent(), FrameMap->getType(), true,
|
||||||
GlobalVariable::InternalLinkage,
|
GlobalVariable::InternalLinkage, FrameMap,
|
||||||
FrameMap, "__gc_" + F.getName());
|
"__gc_" + F.getName());
|
||||||
|
|
||||||
Constant *GEPIndices[2] = {
|
Constant *GEPIndices[2] = {
|
||||||
ConstantInt::get(Type::getInt32Ty(F.getContext()), 0),
|
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);
|
return ConstantExpr::getGetElementPtr(GV, GEPIndices);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,10 +294,9 @@ bool ShadowStackGC::initializeCustomLowering(Module &M) {
|
|||||||
if (!Head) {
|
if (!Head) {
|
||||||
// If the root chain does not exist, insert a new one with linkonce
|
// If the root chain does not exist, insert a new one with linkonce
|
||||||
// linkage!
|
// linkage!
|
||||||
Head = new GlobalVariable(M, StackEntryPtrTy, false,
|
Head = new GlobalVariable(
|
||||||
GlobalValue::LinkOnceAnyLinkage,
|
M, StackEntryPtrTy, false, GlobalValue::LinkOnceAnyLinkage,
|
||||||
Constant::getNullValue(StackEntryPtrTy),
|
Constant::getNullValue(StackEntryPtrTy), "llvm_gc_root_chain");
|
||||||
"llvm_gc_root_chain");
|
|
||||||
} else if (Head->hasExternalLinkage() && Head->isDeclaration()) {
|
} else if (Head->hasExternalLinkage() && Head->isDeclaration()) {
|
||||||
Head->setInitializer(Constant::getNullValue(StackEntryPtrTy));
|
Head->setInitializer(Constant::getNullValue(StackEntryPtrTy));
|
||||||
Head->setLinkage(GlobalValue::LinkOnceAnyLinkage);
|
Head->setLinkage(GlobalValue::LinkOnceAnyLinkage);
|
||||||
@ -334,7 +326,8 @@ void ShadowStackGC::CollectRoots(Function &F) {
|
|||||||
if (Function *F = CI->getCalledFunction())
|
if (Function *F = CI->getCalledFunction())
|
||||||
if (F->getIntrinsicID() == Intrinsic::gcroot) {
|
if (F->getIntrinsicID() == Intrinsic::gcroot) {
|
||||||
std::pair<CallInst *, AllocaInst *> Pair = std::make_pair(
|
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)))
|
if (IsNullValue(CI->getArgOperand(1)))
|
||||||
Roots.push_back(Pair);
|
Roots.push_back(Pair);
|
||||||
else
|
else
|
||||||
@ -346,9 +339,10 @@ void ShadowStackGC::CollectRoots(Function &F) {
|
|||||||
Roots.insert(Roots.begin(), MetaRoots.begin(), MetaRoots.end());
|
Roots.insert(Roots.begin(), MetaRoots.begin(), MetaRoots.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
GetElementPtrInst *
|
GetElementPtrInst *ShadowStackGC::CreateGEP(LLVMContext &Context,
|
||||||
ShadowStackGC::CreateGEP(LLVMContext &Context, IRBuilder<> &B, Value *BasePtr,
|
IRBuilder<> &B, Value *BasePtr,
|
||||||
int Idx, int Idx2, const char *Name) {
|
int Idx, int Idx2,
|
||||||
|
const char *Name) {
|
||||||
Value *Indices[] = {ConstantInt::get(Type::getInt32Ty(Context), 0),
|
Value *Indices[] = {ConstantInt::get(Type::getInt32Ty(Context), 0),
|
||||||
ConstantInt::get(Type::getInt32Ty(Context), Idx),
|
ConstantInt::get(Type::getInt32Ty(Context), Idx),
|
||||||
ConstantInt::get(Type::getInt32Ty(Context), Idx2)};
|
ConstantInt::get(Type::getInt32Ty(Context), Idx2)};
|
||||||
@ -359,8 +353,8 @@ ShadowStackGC::CreateGEP(LLVMContext &Context, IRBuilder<> &B, Value *BasePtr,
|
|||||||
return dyn_cast<GetElementPtrInst>(Val);
|
return dyn_cast<GetElementPtrInst>(Val);
|
||||||
}
|
}
|
||||||
|
|
||||||
GetElementPtrInst *
|
GetElementPtrInst *ShadowStackGC::CreateGEP(LLVMContext &Context,
|
||||||
ShadowStackGC::CreateGEP(LLVMContext &Context, IRBuilder<> &B, Value *BasePtr,
|
IRBuilder<> &B, Value *BasePtr,
|
||||||
int Idx, const char *Name) {
|
int Idx, const char *Name) {
|
||||||
Value *Indices[] = {ConstantInt::get(Type::getInt32Ty(Context), 0),
|
Value *Indices[] = {ConstantInt::get(Type::getInt32Ty(Context), 0),
|
||||||
ConstantInt::get(Type::getInt32Ty(Context), Idx)};
|
ConstantInt::get(Type::getInt32Ty(Context), Idx)};
|
||||||
@ -391,16 +385,17 @@ bool ShadowStackGC::performCustomLowering(Function &F) {
|
|||||||
BasicBlock::iterator IP = F.getEntryBlock().begin();
|
BasicBlock::iterator IP = F.getEntryBlock().begin();
|
||||||
IRBuilder<> AtEntry(IP->getParent(), IP);
|
IRBuilder<> AtEntry(IP->getParent(), IP);
|
||||||
|
|
||||||
Instruction *StackEntry = AtEntry.CreateAlloca(ConcreteStackEntryTy, nullptr,
|
Instruction *StackEntry =
|
||||||
"gc_frame");
|
AtEntry.CreateAlloca(ConcreteStackEntryTy, nullptr, "gc_frame");
|
||||||
|
|
||||||
while (isa<AllocaInst>(IP)) ++IP;
|
while (isa<AllocaInst>(IP))
|
||||||
|
++IP;
|
||||||
AtEntry.SetInsertPoint(IP->getParent(), IP);
|
AtEntry.SetInsertPoint(IP->getParent(), IP);
|
||||||
|
|
||||||
// Initialize the map pointer and load the current head of the shadow stack.
|
// Initialize the map pointer and load the current head of the shadow stack.
|
||||||
Instruction *CurrentHead = AtEntry.CreateLoad(Head, "gc_currhead");
|
Instruction *CurrentHead = AtEntry.CreateLoad(Head, "gc_currhead");
|
||||||
Instruction *EntryMapPtr = CreateGEP(Context, AtEntry, StackEntry,
|
Instruction *EntryMapPtr =
|
||||||
0,1,"gc_frame.map");
|
CreateGEP(Context, AtEntry, StackEntry, 0, 1, "gc_frame.map");
|
||||||
AtEntry.CreateStore(FrameMap, EntryMapPtr);
|
AtEntry.CreateStore(FrameMap, EntryMapPtr);
|
||||||
|
|
||||||
// After all the allocas...
|
// After all the allocas...
|
||||||
@ -418,14 +413,15 @@ bool ShadowStackGC::performCustomLowering(Function &F) {
|
|||||||
// really necessary (the collector would never see the intermediate state at
|
// 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
|
// runtime), but it's nicer not to push the half-initialized entry onto the
|
||||||
// shadow stack.
|
// shadow stack.
|
||||||
while (isa<StoreInst>(IP)) ++IP;
|
while (isa<StoreInst>(IP))
|
||||||
|
++IP;
|
||||||
AtEntry.SetInsertPoint(IP->getParent(), IP);
|
AtEntry.SetInsertPoint(IP->getParent(), IP);
|
||||||
|
|
||||||
// Push the entry onto the shadow stack.
|
// Push the entry onto the shadow stack.
|
||||||
Instruction *EntryNextPtr = CreateGEP(Context, AtEntry,
|
Instruction *EntryNextPtr =
|
||||||
StackEntry,0,0,"gc_frame.next");
|
CreateGEP(Context, AtEntry, StackEntry, 0, 0, "gc_frame.next");
|
||||||
Instruction *NewHeadVal = CreateGEP(Context, AtEntry,
|
Instruction *NewHeadVal =
|
||||||
StackEntry, 0, "gc_newhead");
|
CreateGEP(Context, AtEntry, StackEntry, 0, "gc_newhead");
|
||||||
AtEntry.CreateStore(CurrentHead, EntryNextPtr);
|
AtEntry.CreateStore(CurrentHead, EntryNextPtr);
|
||||||
AtEntry.CreateStore(NewHeadVal, Head);
|
AtEntry.CreateStore(NewHeadVal, Head);
|
||||||
|
|
||||||
@ -434,8 +430,8 @@ bool ShadowStackGC::performCustomLowering(Function &F) {
|
|||||||
while (IRBuilder<> *AtExit = EE.Next()) {
|
while (IRBuilder<> *AtExit = EE.Next()) {
|
||||||
// Pop the entry from the shadow stack. Don't reuse CurrentHead from
|
// Pop the entry from the shadow stack. Don't reuse CurrentHead from
|
||||||
// AtEntry, since that would make the value live for the entire function.
|
// AtEntry, since that would make the value live for the entire function.
|
||||||
Instruction *EntryNextPtr2 = CreateGEP(Context, *AtExit, StackEntry, 0, 0,
|
Instruction *EntryNextPtr2 =
|
||||||
"gc_frame.next");
|
CreateGEP(Context, *AtExit, StackEntry, 0, 0, "gc_frame.next");
|
||||||
Value *SavedHead = AtExit->CreateLoad(EntryNextPtr2, "gc_savedhead");
|
Value *SavedHead = AtExit->CreateLoad(EntryNextPtr2, "gc_savedhead");
|
||||||
AtExit->CreateStore(SavedHead, Head);
|
AtExit->CreateStore(SavedHead, Head);
|
||||||
}
|
}
|
||||||
|
@ -45,8 +45,8 @@ public:
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static GCRegistry::Add<StatepointGC>
|
static GCRegistry::Add<StatepointGC> X("statepoint-example",
|
||||||
X("statepoint-example", "an example strategy for statepoint");
|
"an example strategy for statepoint");
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
void linkStatepointExampleGC() {}
|
void linkStatepointExampleGC() {}
|
||||||
|
@ -18,5 +18,5 @@ using namespace llvm;
|
|||||||
|
|
||||||
GCStrategy::GCStrategy()
|
GCStrategy::GCStrategy()
|
||||||
: UseStatepoints(false), NeededSafePoints(0), CustomReadBarriers(false),
|
: UseStatepoints(false), NeededSafePoints(0), CustomReadBarriers(false),
|
||||||
CustomWriteBarriers(false), CustomRoots(false),
|
CustomWriteBarriers(false), CustomRoots(false), InitRoots(true),
|
||||||
InitRoots(true), UsesMetadata(false) {}
|
UsesMetadata(false) {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user