[llvm] r238252 - [PlaceSafepoints] Cleanup InsertSafepointPoll function
Philip Reames
listmail at philipreames.com
Tue May 26 14:03:23 PDT 2015
Author: reames
Date: Tue May 26 16:03:23 2015
New Revision: 238252
URL: http://llvm.org/viewvc/llvm-project?rev=238252&view=rev
Log:
[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.
Modified:
llvm/trunk/include/llvm/IR/BasicBlock.h
llvm/trunk/include/llvm/IR/Instruction.h
llvm/trunk/lib/IR/BasicBlock.cpp
llvm/trunk/lib/IR/Instruction.cpp
llvm/trunk/lib/Transforms/Scalar/PlaceSafepoints.cpp
Modified: llvm/trunk/include/llvm/IR/BasicBlock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/BasicBlock.h?rev=238252&r1=238251&r2=238252&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/BasicBlock.h (original)
+++ llvm/trunk/include/llvm/IR/BasicBlock.h Tue May 26 16:03:23 2015
@@ -116,6 +116,7 @@ public:
///
/// Note: this is undefined behavior if the block does not have a parent.
const Module *getModule() const;
+ Module *getModule();
/// \brief Returns the terminator instruction if the block is well formed or
/// null if the block is not well formed.
Modified: llvm/trunk/include/llvm/IR/Instruction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Instruction.h?rev=238252&r1=238251&r2=238252&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Instruction.h (original)
+++ llvm/trunk/include/llvm/IR/Instruction.h Tue May 26 16:03:23 2015
@@ -78,6 +78,7 @@ public:
/// Note: this is undefined behavior if the instruction does not have a
/// parent, or the parent basic block does not have a parent function.
const Module *getModule() const;
+ Module *getModule();
/// removeFromParent - This method unlinks 'this' from the containing basic
/// block, but does not delete it.
Modified: llvm/trunk/lib/IR/BasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/BasicBlock.cpp?rev=238252&r1=238251&r2=238252&view=diff
==============================================================================
--- llvm/trunk/lib/IR/BasicBlock.cpp (original)
+++ llvm/trunk/lib/IR/BasicBlock.cpp Tue May 26 16:03:23 2015
@@ -117,6 +117,10 @@ const Module *BasicBlock::getModule() co
return getParent()->getParent();
}
+Module *BasicBlock::getModule() {
+ return getParent()->getParent();
+}
+
TerminatorInst *BasicBlock::getTerminator() {
if (InstList.empty()) return nullptr;
return dyn_cast<TerminatorInst>(&InstList.back());
Modified: llvm/trunk/lib/IR/Instruction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Instruction.cpp?rev=238252&r1=238251&r2=238252&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Instruction.cpp (original)
+++ llvm/trunk/lib/IR/Instruction.cpp Tue May 26 16:03:23 2015
@@ -58,6 +58,11 @@ const Module *Instruction::getModule() c
return getParent()->getModule();
}
+Module *Instruction::getModule() {
+ return getParent()->getModule();
+}
+
+
void Instruction::removeFromParent() {
getParent()->getInstList().remove(this);
}
Modified: llvm/trunk/lib/Transforms/Scalar/PlaceSafepoints.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/PlaceSafepoints.cpp?rev=238252&r1=238251&r2=238252&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/PlaceSafepoints.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/PlaceSafepoints.cpp Tue May 26 16:03:23 2015
@@ -187,7 +187,7 @@ struct PlaceSafepoints : public Function
// not handle the parsability of state at the runtime call, that's the
// callers job.
static void
-InsertSafepointPoll(Instruction *after,
+InsertSafepointPoll(Instruction *InsertBefore,
std::vector<CallSite> &ParsePointsNeeded /*rval*/);
static bool isGCLeafFunction(const CallSite &CS);
@@ -801,42 +801,39 @@ static bool isGCLeafFunction(const CallS
}
static void
-InsertSafepointPoll(Instruction *term,
+InsertSafepointPoll(Instruction *InsertBefore,
std::vector<CallSite> &ParsePointsNeeded /*rval*/) {
- Module *M = term->getParent()->getParent()->getParent();
- assert(M);
+ BasicBlock *OrigBB = InsertBefore->getParent();
+ Module *M = InsertBefore->getModule();
+ assert(M && "must be part of a module");
// Inline the safepoint poll implementation - this will get all the branch,
// control flow, etc.. Most importantly, it will introduce the actual slow
// path call - where we need to insert a safepoint (parsepoint).
- FunctionType *ftype =
- FunctionType::get(Type::getVoidTy(M->getContext()), false);
- assert(ftype && "null?");
- // Note: This cast can fail if there's a function of the same name with a
- // different type inserted previously
- Function *F =
- dyn_cast<Function>(M->getOrInsertFunction("gc.safepoint_poll", ftype));
- assert(F && "void @gc.safepoint_poll() must be defined");
+
+ auto *F = M->getFunction(GCSafepointPollName);
+ assert(F->getType()->getElementType() ==
+ FunctionType::get(Type::getVoidTy(M->getContext()), false) &&
+ "gc.safepoint_poll declared with wrong type");
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
- BasicBlock *OrigBB = term->getParent();
- BasicBlock::iterator before(poll), after(poll);
+ BasicBlock::iterator before(PollCall), after(PollCall);
bool isBegin(false);
- if (before == term->getParent()->begin()) {
+ if (before == OrigBB->begin()) {
isBegin = true;
} else {
before--;
}
after++;
- assert(after != poll->getParent()->end() && "must have successor");
+ assert(after != OrigBB->end() && "must have successor");
// do the actual inlining
InlineFunctionInfo IFI;
- bool inlineStatus = InlineFunction(poll, IFI);
- assert(inlineStatus && "inline must succeed");
- (void)inlineStatus; // suppress warning in release-asserts
+ bool InlineStatus = InlineFunction(PollCall, IFI);
+ assert(InlineStatus && "inline must succeed");
+ (void)InlineStatus; // suppress warning in release-asserts
// Check post conditions
assert(IFI.StaticAllocas.empty() && "can't have allocs");
More information about the llvm-commits
mailing list