forked from OSchip/llvm-project
Just a small cleanup
No functional change is intended llvm-svn: 273780
This commit is contained in:
parent
e14e7bc4b8
commit
9f506259c8
|
@ -42,11 +42,13 @@
|
|||
#include "llvm/IR/MDBuilder.h"
|
||||
#include "llvm/IR/Metadata.h"
|
||||
#include "llvm/IR/Operator.h"
|
||||
#include "llvm/IR/PatternMatch.h"
|
||||
#include "llvm/IR/ValueHandle.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
using namespace llvm;
|
||||
using namespace llvm::PatternMatch;
|
||||
|
||||
#define DEBUG_TYPE "local"
|
||||
|
||||
|
@ -148,9 +150,7 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions,
|
|||
SmallVector<uint32_t, 8> Weights;
|
||||
for (unsigned MD_i = 1, MD_e = MD->getNumOperands(); MD_i < MD_e;
|
||||
++MD_i) {
|
||||
ConstantInt *CI =
|
||||
mdconst::dyn_extract<ConstantInt>(MD->getOperand(MD_i));
|
||||
assert(CI);
|
||||
auto *CI = mdconst::extract<ConstantInt>(MD->getOperand(MD_i));
|
||||
Weights.push_back(CI->getValue().getZExtValue());
|
||||
}
|
||||
// Merge weight of this case to the default weight.
|
||||
|
@ -1314,8 +1314,8 @@ unsigned llvm::changeToUnreachable(Instruction *I, bool UseLLVMTrap) {
|
|||
BasicBlock *BB = I->getParent();
|
||||
// Loop over all of the successors, removing BB's entry from any PHI
|
||||
// nodes.
|
||||
for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI)
|
||||
(*SI)->removePredecessor(BB);
|
||||
for (BasicBlock *Successor : successors(BB))
|
||||
Successor->removePredecessor(BB);
|
||||
|
||||
// Insert a call to llvm.trap right before this. This turns the undefined
|
||||
// behavior into a hard fail instead of falling through into random code.
|
||||
|
@ -1374,22 +1374,15 @@ static bool markAliveBlocks(Function &F,
|
|||
// Do a quick scan of the basic block, turning any obviously unreachable
|
||||
// instructions into LLVM unreachable insts. The instruction combining pass
|
||||
// canonicalizes unreachable insts into stores to null or undef.
|
||||
for (BasicBlock::iterator BBI = BB->begin(), E = BB->end(); BBI != E;++BBI){
|
||||
for (Instruction &I : *BB) {
|
||||
// Assumptions that are known to be false are equivalent to unreachable.
|
||||
// Also, if the condition is undefined, then we make the choice most
|
||||
// beneficial to the optimizer, and choose that to also be unreachable.
|
||||
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(BBI)) {
|
||||
if (auto *II = dyn_cast<IntrinsicInst>(&I)) {
|
||||
if (II->getIntrinsicID() == Intrinsic::assume) {
|
||||
bool MakeUnreachable = false;
|
||||
if (isa<UndefValue>(II->getArgOperand(0)))
|
||||
MakeUnreachable = true;
|
||||
else if (ConstantInt *Cond =
|
||||
dyn_cast<ConstantInt>(II->getArgOperand(0)))
|
||||
MakeUnreachable = Cond->isZero();
|
||||
|
||||
if (MakeUnreachable) {
|
||||
if (match(II->getArgOperand(0), m_CombineOr(m_Zero(), m_Undef()))) {
|
||||
// Don't insert a call to llvm.trap right before the unreachable.
|
||||
changeToUnreachable(&*BBI, false);
|
||||
changeToUnreachable(II, false);
|
||||
Changed = true;
|
||||
break;
|
||||
}
|
||||
|
@ -1404,8 +1397,8 @@ static bool markAliveBlocks(Function &F,
|
|||
// Note: unlike in llvm.assume, it is not "obviously profitable" for
|
||||
// guards to treat `undef` as `false` since a guard on `undef` can
|
||||
// still be useful for widening.
|
||||
if (auto *CI = dyn_cast<ConstantInt>(II->getArgOperand(0)))
|
||||
if (CI->isZero() && !isa<UnreachableInst>(II->getNextNode())) {
|
||||
if (match(II->getArgOperand(0), m_Zero()))
|
||||
if (!isa<UnreachableInst>(II->getNextNode())) {
|
||||
changeToUnreachable(II->getNextNode(), /*UseLLVMTrap=*/ false);
|
||||
Changed = true;
|
||||
break;
|
||||
|
@ -1413,7 +1406,7 @@ static bool markAliveBlocks(Function &F,
|
|||
}
|
||||
}
|
||||
|
||||
if (CallInst *CI = dyn_cast<CallInst>(BBI)) {
|
||||
if (auto *CI = dyn_cast<CallInst>(&I)) {
|
||||
Value *Callee = CI->getCalledValue();
|
||||
if (isa<ConstantPointerNull>(Callee) || isa<UndefValue>(Callee)) {
|
||||
changeToUnreachable(CI, /*UseLLVMTrap=*/false);
|
||||
|
@ -1424,10 +1417,9 @@ static bool markAliveBlocks(Function &F,
|
|||
// If we found a call to a no-return function, insert an unreachable
|
||||
// instruction after it. Make sure there isn't *already* one there
|
||||
// though.
|
||||
++BBI;
|
||||
if (!isa<UnreachableInst>(BBI)) {
|
||||
if (!isa<UnreachableInst>(CI->getNextNode())) {
|
||||
// Don't insert a call to llvm.trap right before the unreachable.
|
||||
changeToUnreachable(&*BBI, false);
|
||||
changeToUnreachable(CI->getNextNode(), false);
|
||||
Changed = true;
|
||||
}
|
||||
break;
|
||||
|
@ -1437,7 +1429,7 @@ static bool markAliveBlocks(Function &F,
|
|||
// Store to undef and store to null are undefined and used to signal that
|
||||
// they should be changed to unreachable by passes that can't modify the
|
||||
// CFG.
|
||||
if (StoreInst *SI = dyn_cast<StoreInst>(BBI)) {
|
||||
if (auto *SI = dyn_cast<StoreInst>(&I)) {
|
||||
// Don't touch volatile stores.
|
||||
if (SI->isVolatile()) continue;
|
||||
|
||||
|
@ -1511,9 +1503,9 @@ static bool markAliveBlocks(Function &F,
|
|||
}
|
||||
|
||||
Changed |= ConstantFoldTerminator(BB, true);
|
||||
for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI)
|
||||
if (Reachable.insert(*SI).second)
|
||||
Worklist.push_back(*SI);
|
||||
for (BasicBlock *Successor : successors(BB))
|
||||
if (Reachable.insert(Successor).second)
|
||||
Worklist.push_back(Successor);
|
||||
} while (!Worklist.empty());
|
||||
return Changed;
|
||||
}
|
||||
|
@ -1572,10 +1564,9 @@ bool llvm::removeUnreachableBlocks(Function &F, LazyValueInfo *LVI) {
|
|||
if (Reachable.count(&*BB))
|
||||
continue;
|
||||
|
||||
for (succ_iterator SI = succ_begin(&*BB), SE = succ_end(&*BB); SI != SE;
|
||||
++SI)
|
||||
if (Reachable.count(*SI))
|
||||
(*SI)->removePredecessor(&*BB);
|
||||
for (BasicBlock *Successor : successors(&*BB))
|
||||
if (Reachable.count(Successor))
|
||||
Successor->removePredecessor(&*BB);
|
||||
if (LVI)
|
||||
LVI->eraseBlock(&*BB);
|
||||
BB->dropAllReferences();
|
||||
|
|
Loading…
Reference in New Issue