2008-05-12 09:12:24 +08:00
|
|
|
//===- SparsePropagation.cpp - Sparse Conditional Property Propagation ----===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements an abstract sparse conditional propagation algorithm,
|
|
|
|
// modeled after SCCP, but with a customizable lattice function.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Analysis/SparsePropagation.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
2008-05-12 09:12:24 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-26 17:48:23 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-05-12 09:12:24 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:48:03 +08:00
|
|
|
#define DEBUG_TYPE "sparseprop"
|
|
|
|
|
2008-05-12 09:12:24 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// AbstractLatticeFunction Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
AbstractLatticeFunction::~AbstractLatticeFunction() {}
|
|
|
|
|
|
|
|
/// PrintValue - Render the specified lattice value to the specified stream.
|
2009-08-23 12:37:46 +08:00
|
|
|
void AbstractLatticeFunction::PrintValue(LatticeVal V, raw_ostream &OS) {
|
2008-05-12 09:12:24 +08:00
|
|
|
if (V == UndefVal)
|
|
|
|
OS << "undefined";
|
|
|
|
else if (V == OverdefinedVal)
|
|
|
|
OS << "overdefined";
|
|
|
|
else if (V == UntrackedVal)
|
|
|
|
OS << "untracked";
|
|
|
|
else
|
|
|
|
OS << "unknown lattice value";
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// SparseSolver Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// getOrInitValueState - Return the LatticeVal object that corresponds to the
|
|
|
|
/// value, initializing the value's state if it hasn't been entered into the
|
|
|
|
/// map yet. This function is necessary because not all values should start
|
|
|
|
/// out in the underdefined state... Arguments should be overdefined, and
|
|
|
|
/// constants should be marked as constants.
|
|
|
|
///
|
|
|
|
SparseSolver::LatticeVal SparseSolver::getOrInitValueState(Value *V) {
|
|
|
|
DenseMap<Value*, LatticeVal>::iterator I = ValueState.find(V);
|
|
|
|
if (I != ValueState.end()) return I->second; // Common case, in the map
|
|
|
|
|
|
|
|
LatticeVal LV;
|
|
|
|
if (LatticeFunc->IsUntrackedValue(V))
|
|
|
|
return LatticeFunc->getUntrackedVal();
|
|
|
|
else if (Constant *C = dyn_cast<Constant>(V))
|
|
|
|
LV = LatticeFunc->ComputeConstant(C);
|
2008-08-10 01:23:35 +08:00
|
|
|
else if (Argument *A = dyn_cast<Argument>(V))
|
|
|
|
LV = LatticeFunc->ComputeArgument(A);
|
2008-05-12 09:12:24 +08:00
|
|
|
else if (!isa<Instruction>(V))
|
2008-08-10 01:23:35 +08:00
|
|
|
// All other non-instructions are overdefined.
|
2008-05-12 09:12:24 +08:00
|
|
|
LV = LatticeFunc->getOverdefinedVal();
|
|
|
|
else
|
|
|
|
// All instructions are underdefined by default.
|
|
|
|
LV = LatticeFunc->getUndefVal();
|
|
|
|
|
|
|
|
// If this value is untracked, don't add it to the map.
|
|
|
|
if (LV == LatticeFunc->getUntrackedVal())
|
|
|
|
return LV;
|
|
|
|
return ValueState[V] = LV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// UpdateState - When the state for some instruction is potentially updated,
|
|
|
|
/// this function notices and adds I to the worklist if needed.
|
|
|
|
void SparseSolver::UpdateState(Instruction &Inst, LatticeVal V) {
|
|
|
|
DenseMap<Value*, LatticeVal>::iterator I = ValueState.find(&Inst);
|
|
|
|
if (I != ValueState.end() && I->second == V)
|
|
|
|
return; // No change.
|
|
|
|
|
|
|
|
// An update. Visit uses of I.
|
|
|
|
ValueState[&Inst] = V;
|
|
|
|
InstWorkList.push_back(&Inst);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// MarkBlockExecutable - This method can be used by clients to mark all of
|
|
|
|
/// the blocks that are known to be intrinsically live in the processed unit.
|
|
|
|
void SparseSolver::MarkBlockExecutable(BasicBlock *BB) {
|
2009-12-24 06:28:01 +08:00
|
|
|
DEBUG(dbgs() << "Marking Block Executable: " << BB->getName() << "\n");
|
2008-05-12 09:12:24 +08:00
|
|
|
BBExecutable.insert(BB); // Basic block is executable!
|
|
|
|
BBWorkList.push_back(BB); // Add the block to the work list!
|
|
|
|
}
|
|
|
|
|
|
|
|
/// markEdgeExecutable - Mark a basic block as executable, adding it to the BB
|
|
|
|
/// work list if it is not already executable...
|
|
|
|
void SparseSolver::markEdgeExecutable(BasicBlock *Source, BasicBlock *Dest) {
|
|
|
|
if (!KnownFeasibleEdges.insert(Edge(Source, Dest)).second)
|
|
|
|
return; // This edge is already known to be executable!
|
|
|
|
|
2009-12-24 06:28:01 +08:00
|
|
|
DEBUG(dbgs() << "Marking Edge Executable: " << Source->getName()
|
2009-07-26 17:48:23 +08:00
|
|
|
<< " -> " << Dest->getName() << "\n");
|
2008-05-28 04:47:30 +08:00
|
|
|
|
2008-05-12 09:12:24 +08:00
|
|
|
if (BBExecutable.count(Dest)) {
|
|
|
|
// The destination is already executable, but we just made an edge
|
|
|
|
// feasible that wasn't before. Revisit the PHI nodes in the block
|
|
|
|
// because they have potentially new operands.
|
|
|
|
for (BasicBlock::iterator I = Dest->begin(); isa<PHINode>(I); ++I)
|
|
|
|
visitPHINode(*cast<PHINode>(I));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
MarkBlockExecutable(Dest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// getFeasibleSuccessors - Return a vector of booleans to indicate which
|
|
|
|
/// successors are reachable from a given terminator instruction.
|
|
|
|
void SparseSolver::getFeasibleSuccessors(TerminatorInst &TI,
|
2008-05-20 11:39:39 +08:00
|
|
|
SmallVectorImpl<bool> &Succs,
|
|
|
|
bool AggressiveUndef) {
|
2008-05-12 09:12:24 +08:00
|
|
|
Succs.resize(TI.getNumSuccessors());
|
|
|
|
if (TI.getNumSuccessors() == 0) return;
|
|
|
|
|
|
|
|
if (BranchInst *BI = dyn_cast<BranchInst>(&TI)) {
|
|
|
|
if (BI->isUnconditional()) {
|
|
|
|
Succs[0] = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-20 11:39:39 +08:00
|
|
|
LatticeVal BCValue;
|
|
|
|
if (AggressiveUndef)
|
|
|
|
BCValue = getOrInitValueState(BI->getCondition());
|
|
|
|
else
|
|
|
|
BCValue = getLatticeState(BI->getCondition());
|
|
|
|
|
2008-05-12 09:12:24 +08:00
|
|
|
if (BCValue == LatticeFunc->getOverdefinedVal() ||
|
|
|
|
BCValue == LatticeFunc->getUntrackedVal()) {
|
|
|
|
// Overdefined condition variables can branch either way.
|
|
|
|
Succs[0] = Succs[1] = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If undefined, neither is feasible yet.
|
|
|
|
if (BCValue == LatticeFunc->getUndefVal())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Constant *C = LatticeFunc->GetConstant(BCValue, BI->getCondition(), *this);
|
2014-04-15 12:59:12 +08:00
|
|
|
if (!C || !isa<ConstantInt>(C)) {
|
2008-05-12 09:12:24 +08:00
|
|
|
// Non-constant values can go either way.
|
|
|
|
Succs[0] = Succs[1] = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Constant condition variables mean the branch can only go a single way
|
2009-12-19 07:42:08 +08:00
|
|
|
Succs[C->isNullValue()] = true;
|
2008-05-12 09:12:24 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isa<InvokeInst>(TI)) {
|
|
|
|
// Invoke instructions successors are always executable.
|
|
|
|
// TODO: Could ask the lattice function if the value can throw.
|
|
|
|
Succs[0] = Succs[1] = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-28 08:19:10 +08:00
|
|
|
if (isa<IndirectBrInst>(TI)) {
|
2009-10-28 05:27:42 +08:00
|
|
|
Succs.assign(Succs.size(), true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-12 09:12:24 +08:00
|
|
|
SwitchInst &SI = cast<SwitchInst>(TI);
|
2008-05-20 11:39:39 +08:00
|
|
|
LatticeVal SCValue;
|
|
|
|
if (AggressiveUndef)
|
|
|
|
SCValue = getOrInitValueState(SI.getCondition());
|
|
|
|
else
|
|
|
|
SCValue = getLatticeState(SI.getCondition());
|
|
|
|
|
2008-05-12 09:12:24 +08:00
|
|
|
if (SCValue == LatticeFunc->getOverdefinedVal() ||
|
|
|
|
SCValue == LatticeFunc->getUntrackedVal()) {
|
|
|
|
// All destinations are executable!
|
|
|
|
Succs.assign(TI.getNumSuccessors(), true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If undefined, neither is feasible yet.
|
|
|
|
if (SCValue == LatticeFunc->getUndefVal())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Constant *C = LatticeFunc->GetConstant(SCValue, SI.getCondition(), *this);
|
2014-04-15 12:59:12 +08:00
|
|
|
if (!C || !isa<ConstantInt>(C)) {
|
2008-05-12 09:12:24 +08:00
|
|
|
// All destinations are executable!
|
|
|
|
Succs.assign(TI.getNumSuccessors(), true);
|
|
|
|
return;
|
|
|
|
}
|
2012-03-08 15:06:20 +08:00
|
|
|
SwitchInst::CaseIt Case = SI.findCaseValue(cast<ConstantInt>(C));
|
|
|
|
Succs[Case.getSuccessorIndex()] = true;
|
2008-05-12 09:12:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// isEdgeFeasible - Return true if the control flow edge from the 'From'
|
|
|
|
/// basic block to the 'To' basic block is currently feasible...
|
2008-05-20 11:39:39 +08:00
|
|
|
bool SparseSolver::isEdgeFeasible(BasicBlock *From, BasicBlock *To,
|
|
|
|
bool AggressiveUndef) {
|
2008-05-12 09:12:24 +08:00
|
|
|
SmallVector<bool, 16> SuccFeasible;
|
|
|
|
TerminatorInst *TI = From->getTerminator();
|
2008-05-20 11:39:39 +08:00
|
|
|
getFeasibleSuccessors(*TI, SuccFeasible, AggressiveUndef);
|
2008-05-12 09:12:24 +08:00
|
|
|
|
|
|
|
for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
|
|
|
|
if (TI->getSuccessor(i) == To && SuccFeasible[i])
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SparseSolver::visitTerminatorInst(TerminatorInst &TI) {
|
|
|
|
SmallVector<bool, 16> SuccFeasible;
|
2008-05-20 11:39:39 +08:00
|
|
|
getFeasibleSuccessors(TI, SuccFeasible, true);
|
2008-05-12 09:12:24 +08:00
|
|
|
|
|
|
|
BasicBlock *BB = TI.getParent();
|
|
|
|
|
|
|
|
// Mark all feasible successors executable...
|
|
|
|
for (unsigned i = 0, e = SuccFeasible.size(); i != e; ++i)
|
|
|
|
if (SuccFeasible[i])
|
|
|
|
markEdgeExecutable(BB, TI.getSuccessor(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SparseSolver::visitPHINode(PHINode &PN) {
|
2009-09-20 03:00:06 +08:00
|
|
|
// The lattice function may store more information on a PHINode than could be
|
|
|
|
// computed from its incoming values. For example, SSI form stores its sigma
|
|
|
|
// functions as PHINodes with a single incoming value.
|
2009-09-20 02:33:36 +08:00
|
|
|
if (LatticeFunc->IsSpecialCasedPHI(&PN)) {
|
|
|
|
LatticeVal IV = LatticeFunc->ComputeInstructionState(PN, *this);
|
|
|
|
if (IV != LatticeFunc->getUntrackedVal())
|
|
|
|
UpdateState(PN, IV);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-12 09:12:24 +08:00
|
|
|
LatticeVal PNIV = getOrInitValueState(&PN);
|
|
|
|
LatticeVal Overdefined = LatticeFunc->getOverdefinedVal();
|
|
|
|
|
|
|
|
// If this value is already overdefined (common) just return.
|
|
|
|
if (PNIV == Overdefined || PNIV == LatticeFunc->getUntrackedVal())
|
|
|
|
return; // Quick exit
|
|
|
|
|
|
|
|
// Super-extra-high-degree PHI nodes are unlikely to ever be interesting,
|
|
|
|
// and slow us down a lot. Just mark them overdefined.
|
|
|
|
if (PN.getNumIncomingValues() > 64) {
|
|
|
|
UpdateState(PN, Overdefined);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look at all of the executable operands of the PHI node. If any of them
|
|
|
|
// are overdefined, the PHI becomes overdefined as well. Otherwise, ask the
|
|
|
|
// transfer function to give us the merge of the incoming values.
|
|
|
|
for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) {
|
|
|
|
// If the edge is not yet known to be feasible, it doesn't impact the PHI.
|
2008-05-20 11:39:39 +08:00
|
|
|
if (!isEdgeFeasible(PN.getIncomingBlock(i), PN.getParent(), true))
|
2008-05-12 09:12:24 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Merge in this value.
|
|
|
|
LatticeVal OpVal = getOrInitValueState(PN.getIncomingValue(i));
|
|
|
|
if (OpVal != PNIV)
|
|
|
|
PNIV = LatticeFunc->MergeValues(PNIV, OpVal);
|
|
|
|
|
|
|
|
if (PNIV == Overdefined)
|
|
|
|
break; // Rest of input values don't matter.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the PHI with the compute value, which is the merge of the inputs.
|
|
|
|
UpdateState(PN, PNIV);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SparseSolver::visitInst(Instruction &I) {
|
|
|
|
// PHIs are handled by the propagation logic, they are never passed into the
|
|
|
|
// transfer functions.
|
|
|
|
if (PHINode *PN = dyn_cast<PHINode>(&I))
|
|
|
|
return visitPHINode(*PN);
|
|
|
|
|
|
|
|
// Otherwise, ask the transfer function what the result is. If this is
|
|
|
|
// something that we care about, remember it.
|
|
|
|
LatticeVal IV = LatticeFunc->ComputeInstructionState(I, *this);
|
|
|
|
if (IV != LatticeFunc->getUntrackedVal())
|
|
|
|
UpdateState(I, IV);
|
|
|
|
|
|
|
|
if (TerminatorInst *TI = dyn_cast<TerminatorInst>(&I))
|
|
|
|
visitTerminatorInst(*TI);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SparseSolver::Solve(Function &F) {
|
2008-05-28 04:55:29 +08:00
|
|
|
MarkBlockExecutable(&F.getEntryBlock());
|
2008-05-12 09:12:24 +08:00
|
|
|
|
|
|
|
// Process the work lists until they are empty!
|
|
|
|
while (!BBWorkList.empty() || !InstWorkList.empty()) {
|
|
|
|
// Process the instruction work list.
|
|
|
|
while (!InstWorkList.empty()) {
|
|
|
|
Instruction *I = InstWorkList.back();
|
|
|
|
InstWorkList.pop_back();
|
|
|
|
|
2009-12-24 06:28:01 +08:00
|
|
|
DEBUG(dbgs() << "\nPopped off I-WL: " << *I << "\n");
|
2008-05-12 09:12:24 +08:00
|
|
|
|
|
|
|
// "I" got into the work list because it made a transition. See if any
|
|
|
|
// users are both live and in need of updating.
|
2014-03-09 11:16:01 +08:00
|
|
|
for (User *U : I->users()) {
|
|
|
|
Instruction *UI = cast<Instruction>(U);
|
|
|
|
if (BBExecutable.count(UI->getParent())) // Inst is executable?
|
|
|
|
visitInst(*UI);
|
2008-05-12 09:12:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process the basic block work list.
|
|
|
|
while (!BBWorkList.empty()) {
|
|
|
|
BasicBlock *BB = BBWorkList.back();
|
|
|
|
BBWorkList.pop_back();
|
|
|
|
|
2009-12-24 06:28:01 +08:00
|
|
|
DEBUG(dbgs() << "\nPopped off BBWL: " << *BB);
|
2008-05-12 09:12:24 +08:00
|
|
|
|
|
|
|
// Notify all instructions in this basic block that they are newly
|
|
|
|
// executable.
|
2016-06-27 01:27:42 +08:00
|
|
|
for (Instruction &I : *BB)
|
|
|
|
visitInst(I);
|
2008-05-12 09:12:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-23 12:37:46 +08:00
|
|
|
void SparseSolver::Print(Function &F, raw_ostream &OS) const {
|
2011-11-16 00:27:03 +08:00
|
|
|
OS << "\nFUNCTION: " << F.getName() << "\n";
|
Analysis: Remove implicit ilist iterator conversions
Remove implicit ilist iterator conversions from LLVMAnalysis.
I came across something really scary in `llvm::isKnownNotFullPoison()`
which relied on `Instruction::getNextNode()` being completely broken
(not surprising, but scary nevertheless). This function is documented
(and coded to) return `nullptr` when it gets to the sentinel, but with
an `ilist_half_node` as a sentinel, the sentinel check looks into some
other memory and we don't recognize we've hit the end.
Rooting out these scary cases is the reason I'm removing the implicit
conversions before doing anything else with `ilist`; I'm not at all
surprised that clients rely on badness.
I found another scary case -- this time, not relying on badness, just
bad (but I guess getting lucky so far) -- in
`ObjectSizeOffsetEvaluator::compute_()`. Here, we save out the
insertion point, do some things, and then restore it. Previously, we
let the iterator auto-convert to `Instruction*`, and then set it back
using the `Instruction*` version:
Instruction *PrevInsertPoint = Builder.GetInsertPoint();
/* Logic that may change insert point */
if (PrevInsertPoint)
Builder.SetInsertPoint(PrevInsertPoint);
The check for `PrevInsertPoint` doesn't protect correctly against bad
accesses. If the insertion point has been set to the end of a basic
block (i.e., `SetInsertPoint(SomeBB)`), then `GetInsertPoint()` returns
an iterator pointing at the list sentinel. The version of
`SetInsertPoint()` that's getting called will then call
`PrevInsertPoint->getParent()`, which explodes horribly. The only
reason this hasn't blown up is that it's fairly unlikely the builder is
adding to the end of the block; usually, we're adding instructions
somewhere before the terminator.
llvm-svn: 249925
2015-10-10 08:53:03 +08:00
|
|
|
for (auto &BB : F) {
|
|
|
|
if (!BBExecutable.count(&BB))
|
2008-05-12 09:12:24 +08:00
|
|
|
OS << "INFEASIBLE: ";
|
|
|
|
OS << "\t";
|
Analysis: Remove implicit ilist iterator conversions
Remove implicit ilist iterator conversions from LLVMAnalysis.
I came across something really scary in `llvm::isKnownNotFullPoison()`
which relied on `Instruction::getNextNode()` being completely broken
(not surprising, but scary nevertheless). This function is documented
(and coded to) return `nullptr` when it gets to the sentinel, but with
an `ilist_half_node` as a sentinel, the sentinel check looks into some
other memory and we don't recognize we've hit the end.
Rooting out these scary cases is the reason I'm removing the implicit
conversions before doing anything else with `ilist`; I'm not at all
surprised that clients rely on badness.
I found another scary case -- this time, not relying on badness, just
bad (but I guess getting lucky so far) -- in
`ObjectSizeOffsetEvaluator::compute_()`. Here, we save out the
insertion point, do some things, and then restore it. Previously, we
let the iterator auto-convert to `Instruction*`, and then set it back
using the `Instruction*` version:
Instruction *PrevInsertPoint = Builder.GetInsertPoint();
/* Logic that may change insert point */
if (PrevInsertPoint)
Builder.SetInsertPoint(PrevInsertPoint);
The check for `PrevInsertPoint` doesn't protect correctly against bad
accesses. If the insertion point has been set to the end of a basic
block (i.e., `SetInsertPoint(SomeBB)`), then `GetInsertPoint()` returns
an iterator pointing at the list sentinel. The version of
`SetInsertPoint()` that's getting called will then call
`PrevInsertPoint->getParent()`, which explodes horribly. The only
reason this hasn't blown up is that it's fairly unlikely the builder is
adding to the end of the block; usually, we're adding instructions
somewhere before the terminator.
llvm-svn: 249925
2015-10-10 08:53:03 +08:00
|
|
|
if (BB.hasName())
|
|
|
|
OS << BB.getName() << ":\n";
|
2008-05-12 09:12:24 +08:00
|
|
|
else
|
|
|
|
OS << "; anon bb\n";
|
Analysis: Remove implicit ilist iterator conversions
Remove implicit ilist iterator conversions from LLVMAnalysis.
I came across something really scary in `llvm::isKnownNotFullPoison()`
which relied on `Instruction::getNextNode()` being completely broken
(not surprising, but scary nevertheless). This function is documented
(and coded to) return `nullptr` when it gets to the sentinel, but with
an `ilist_half_node` as a sentinel, the sentinel check looks into some
other memory and we don't recognize we've hit the end.
Rooting out these scary cases is the reason I'm removing the implicit
conversions before doing anything else with `ilist`; I'm not at all
surprised that clients rely on badness.
I found another scary case -- this time, not relying on badness, just
bad (but I guess getting lucky so far) -- in
`ObjectSizeOffsetEvaluator::compute_()`. Here, we save out the
insertion point, do some things, and then restore it. Previously, we
let the iterator auto-convert to `Instruction*`, and then set it back
using the `Instruction*` version:
Instruction *PrevInsertPoint = Builder.GetInsertPoint();
/* Logic that may change insert point */
if (PrevInsertPoint)
Builder.SetInsertPoint(PrevInsertPoint);
The check for `PrevInsertPoint` doesn't protect correctly against bad
accesses. If the insertion point has been set to the end of a basic
block (i.e., `SetInsertPoint(SomeBB)`), then `GetInsertPoint()` returns
an iterator pointing at the list sentinel. The version of
`SetInsertPoint()` that's getting called will then call
`PrevInsertPoint->getParent()`, which explodes horribly. The only
reason this hasn't blown up is that it's fairly unlikely the builder is
adding to the end of the block; usually, we're adding instructions
somewhere before the terminator.
llvm-svn: 249925
2015-10-10 08:53:03 +08:00
|
|
|
for (auto &I : BB) {
|
|
|
|
LatticeFunc->PrintValue(getLatticeState(&I), OS);
|
|
|
|
OS << I << "\n";
|
2008-05-12 09:12:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|