Clean up assume intrinsic pattern matching, no need to check that the argument is a value.

Also make it const safe and remove superfluous casting. NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220616 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2014-10-25 18:09:01 +00:00
parent 5c50ab84b3
commit 05b492db56
3 changed files with 11 additions and 15 deletions

View File

@ -32,7 +32,6 @@
#include "llvm/IR/CallSite.h" #include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h" #include "llvm/IR/Constants.h"
#include "llvm/IR/Instructions.h" #include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Operator.h" #include "llvm/IR/Operator.h"
namespace llvm { namespace llvm {
@ -1158,8 +1157,10 @@ struct IntrinsicID_match {
template<typename OpTy> template<typename OpTy>
bool match(OpTy *V) { bool match(OpTy *V) {
IntrinsicInst *II = dyn_cast<IntrinsicInst>(V); if (const CallInst *CI = dyn_cast<CallInst>(V))
return II && II->getIntrinsicID() == ID; if (const Function *F = CI->getCalledFunction())
return F->getIntrinsicID() == ID;
return false;
} }
}; };

View File

@ -46,10 +46,8 @@ void AssumptionTracker::CallCallbackVH::deleted() {
AssumptionTracker::FunctionCallsMap::iterator AssumptionTracker::FunctionCallsMap::iterator
AssumptionTracker::scanFunction(Function *F) { AssumptionTracker::scanFunction(Function *F) {
auto IP = auto IP = CachedAssumeCalls.insert(std::make_pair(
CachedAssumeCalls.insert(std::make_pair(FunctionCallbackVH(F, this), FunctionCallbackVH(F, this), llvm::make_unique<CallHandleSet>()));
std::unique_ptr<CallHandleSet>(
new CallHandleSet())));
assert(IP.second && "Scanning function already in the map?"); assert(IP.second && "Scanning function already in the map?");
FunctionCallsMap::iterator I = IP.first; FunctionCallsMap::iterator I = IP.first;
@ -58,7 +56,7 @@ AssumptionTracker::scanFunction(Function *F) {
// to our cache. // to our cache.
for (BasicBlock &B : *F) for (BasicBlock &B : *F)
for (Instruction &II : B) for (Instruction &II : B)
if (match(cast<Value>(&II), m_Intrinsic<Intrinsic::assume>(m_Value()))) if (match(&II, m_Intrinsic<Intrinsic::assume>()))
I->second->insert(CallCallbackVH(&II, this)); I->second->insert(CallCallbackVH(&II, this));
return I; return I;
@ -69,10 +67,8 @@ void AssumptionTracker::verifyAnalysis() const {
for (const auto &I : CachedAssumeCalls) { for (const auto &I : CachedAssumeCalls) {
for (const BasicBlock &B : cast<Function>(*I.first)) for (const BasicBlock &B : cast<Function>(*I.first))
for (const Instruction &II : B) { for (const Instruction &II : B) {
Instruction *C = const_cast<Instruction*>(&II); if (match(&II, m_Intrinsic<Intrinsic::assume>())) {
if (match(C, m_Intrinsic<Intrinsic::assume>(m_Value()))) { assert(I.second->find_as(&II) != I.second->end() &&
assert(I.second->count(CallCallbackVH(C,
const_cast<AssumptionTracker*>(this))) &&
"Assumption in scanned function not in cache"); "Assumption in scanned function not in cache");
} }
} }
@ -81,8 +77,7 @@ void AssumptionTracker::verifyAnalysis() const {
} }
void AssumptionTracker::registerAssumption(CallInst *CI) { void AssumptionTracker::registerAssumption(CallInst *CI) {
assert(match(cast<Value>(CI), assert(match(CI, m_Intrinsic<Intrinsic::assume>()) &&
m_Intrinsic<Intrinsic::assume>(m_Value())) &&
"Registered call does not call @llvm.assume"); "Registered call does not call @llvm.assume");
assert(CI->getParent() && assert(CI->getParent() &&
"Cannot register @llvm.assume call not in a basic block"); "Cannot register @llvm.assume call not in a basic block");

View File

@ -86,7 +86,7 @@ public:
Worklist.Add(I); Worklist.Add(I);
using namespace llvm::PatternMatch; using namespace llvm::PatternMatch;
if ((match(I, m_Intrinsic<Intrinsic::assume>(m_Value())))) if (match(I, m_Intrinsic<Intrinsic::assume>()))
AT->registerAssumption(cast<CallInst>(I)); AT->registerAssumption(cast<CallInst>(I));
} }
}; };