forked from OSchip/llvm-project
[PlaceSafepoints] Cleanup InsertSafepointPoll function
While working on another change, I noticed that the naming in this function was mildly deceptive. While fixing that, I took the oppurtunity to modernize some of the code. NFC intended. llvm-svn: 238252
This commit is contained in:
parent
316b571007
commit
38840245e4
|
@ -116,6 +116,7 @@ public:
|
||||||
///
|
///
|
||||||
/// Note: this is undefined behavior if the block does not have a parent.
|
/// Note: this is undefined behavior if the block does not have a parent.
|
||||||
const Module *getModule() const;
|
const Module *getModule() const;
|
||||||
|
Module *getModule();
|
||||||
|
|
||||||
/// \brief Returns the terminator instruction if the block is well formed or
|
/// \brief Returns the terminator instruction if the block is well formed or
|
||||||
/// null if the block is not well formed.
|
/// null if the block is not well formed.
|
||||||
|
|
|
@ -78,6 +78,7 @@ public:
|
||||||
/// Note: this is undefined behavior if the instruction does not have a
|
/// Note: this is undefined behavior if the instruction does not have a
|
||||||
/// parent, or the parent basic block does not have a parent function.
|
/// parent, or the parent basic block does not have a parent function.
|
||||||
const Module *getModule() const;
|
const Module *getModule() const;
|
||||||
|
Module *getModule();
|
||||||
|
|
||||||
/// removeFromParent - This method unlinks 'this' from the containing basic
|
/// removeFromParent - This method unlinks 'this' from the containing basic
|
||||||
/// block, but does not delete it.
|
/// block, but does not delete it.
|
||||||
|
|
|
@ -117,6 +117,10 @@ const Module *BasicBlock::getModule() const {
|
||||||
return getParent()->getParent();
|
return getParent()->getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Module *BasicBlock::getModule() {
|
||||||
|
return getParent()->getParent();
|
||||||
|
}
|
||||||
|
|
||||||
TerminatorInst *BasicBlock::getTerminator() {
|
TerminatorInst *BasicBlock::getTerminator() {
|
||||||
if (InstList.empty()) return nullptr;
|
if (InstList.empty()) return nullptr;
|
||||||
return dyn_cast<TerminatorInst>(&InstList.back());
|
return dyn_cast<TerminatorInst>(&InstList.back());
|
||||||
|
|
|
@ -58,6 +58,11 @@ const Module *Instruction::getModule() const {
|
||||||
return getParent()->getModule();
|
return getParent()->getModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Module *Instruction::getModule() {
|
||||||
|
return getParent()->getModule();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Instruction::removeFromParent() {
|
void Instruction::removeFromParent() {
|
||||||
getParent()->getInstList().remove(this);
|
getParent()->getInstList().remove(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,7 +187,7 @@ struct PlaceSafepoints : public FunctionPass {
|
||||||
// not handle the parsability of state at the runtime call, that's the
|
// not handle the parsability of state at the runtime call, that's the
|
||||||
// callers job.
|
// callers job.
|
||||||
static void
|
static void
|
||||||
InsertSafepointPoll(Instruction *after,
|
InsertSafepointPoll(Instruction *InsertBefore,
|
||||||
std::vector<CallSite> &ParsePointsNeeded /*rval*/);
|
std::vector<CallSite> &ParsePointsNeeded /*rval*/);
|
||||||
|
|
||||||
static bool isGCLeafFunction(const CallSite &CS);
|
static bool isGCLeafFunction(const CallSite &CS);
|
||||||
|
@ -801,42 +801,39 @@ static bool isGCLeafFunction(const CallSite &CS) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
InsertSafepointPoll(Instruction *term,
|
InsertSafepointPoll(Instruction *InsertBefore,
|
||||||
std::vector<CallSite> &ParsePointsNeeded /*rval*/) {
|
std::vector<CallSite> &ParsePointsNeeded /*rval*/) {
|
||||||
Module *M = term->getParent()->getParent()->getParent();
|
BasicBlock *OrigBB = InsertBefore->getParent();
|
||||||
assert(M);
|
Module *M = InsertBefore->getModule();
|
||||||
|
assert(M && "must be part of a module");
|
||||||
|
|
||||||
// Inline the safepoint poll implementation - this will get all the branch,
|
// Inline the safepoint poll implementation - this will get all the branch,
|
||||||
// control flow, etc.. Most importantly, it will introduce the actual slow
|
// control flow, etc.. Most importantly, it will introduce the actual slow
|
||||||
// path call - where we need to insert a safepoint (parsepoint).
|
// path call - where we need to insert a safepoint (parsepoint).
|
||||||
FunctionType *ftype =
|
|
||||||
FunctionType::get(Type::getVoidTy(M->getContext()), false);
|
auto *F = M->getFunction(GCSafepointPollName);
|
||||||
assert(ftype && "null?");
|
assert(F->getType()->getElementType() ==
|
||||||
// Note: This cast can fail if there's a function of the same name with a
|
FunctionType::get(Type::getVoidTy(M->getContext()), false) &&
|
||||||
// different type inserted previously
|
"gc.safepoint_poll declared with wrong type");
|
||||||
Function *F =
|
|
||||||
dyn_cast<Function>(M->getOrInsertFunction("gc.safepoint_poll", ftype));
|
|
||||||
assert(F && "void @gc.safepoint_poll() must be defined");
|
|
||||||
assert(!F->empty() && "gc.safepoint_poll must be a non-empty function");
|
assert(!F->empty() && "gc.safepoint_poll must be a non-empty function");
|
||||||
CallInst *poll = CallInst::Create(F, "", term);
|
CallInst *PollCall = CallInst::Create(F, "", InsertBefore);
|
||||||
|
|
||||||
// Record some information about the call site we're replacing
|
// Record some information about the call site we're replacing
|
||||||
BasicBlock *OrigBB = term->getParent();
|
BasicBlock::iterator before(PollCall), after(PollCall);
|
||||||
BasicBlock::iterator before(poll), after(poll);
|
|
||||||
bool isBegin(false);
|
bool isBegin(false);
|
||||||
if (before == term->getParent()->begin()) {
|
if (before == OrigBB->begin()) {
|
||||||
isBegin = true;
|
isBegin = true;
|
||||||
} else {
|
} else {
|
||||||
before--;
|
before--;
|
||||||
}
|
}
|
||||||
after++;
|
after++;
|
||||||
assert(after != poll->getParent()->end() && "must have successor");
|
assert(after != OrigBB->end() && "must have successor");
|
||||||
|
|
||||||
// do the actual inlining
|
// do the actual inlining
|
||||||
InlineFunctionInfo IFI;
|
InlineFunctionInfo IFI;
|
||||||
bool inlineStatus = InlineFunction(poll, IFI);
|
bool InlineStatus = InlineFunction(PollCall, IFI);
|
||||||
assert(inlineStatus && "inline must succeed");
|
assert(InlineStatus && "inline must succeed");
|
||||||
(void)inlineStatus; // suppress warning in release-asserts
|
(void)InlineStatus; // suppress warning in release-asserts
|
||||||
|
|
||||||
// Check post conditions
|
// Check post conditions
|
||||||
assert(IFI.StaticAllocas.empty() && "can't have allocs");
|
assert(IFI.StaticAllocas.empty() && "can't have allocs");
|
||||||
|
|
Loading…
Reference in New Issue