com.ibm.wala.escape.LocalLiveRangeAnalysis Maven / Gradle / Ivy
/*
* Copyright (c) 2002 - 2006 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*/
package com.ibm.wala.escape;
import com.ibm.wala.ssa.DefUse;
import com.ibm.wala.ssa.IR;
import com.ibm.wala.ssa.ISSABasicBlock;
import com.ibm.wala.ssa.SSACFG;
import com.ibm.wala.ssa.SSACFG.BasicBlock;
import com.ibm.wala.ssa.SSAInstruction;
import com.ibm.wala.ssa.SSAReturnInstruction;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.collections.Iterator2Collection;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.graph.traverse.DFS;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.function.Predicate;
/** Intraprocedural SSA-based live range analysis. This is horribly inefficient. */
public class LocalLiveRangeAnalysis {
/**
* Is the variable with value number v live immediately after a particular instruction index?
*
* Algorithm: returns true if there is a path from pc to some use of v that does not traverse
* the def of v
*
* @param instructionIndex index of an instruction in the IR
* @throws IllegalArgumentException if du is null
*/
public static boolean isLive(int v, int instructionIndex, IR ir, DefUse du) {
if (du == null) {
throw new IllegalArgumentException("du is null");
}
if (du.isUnused(v)) {
return false;
}
if (instructionIndex < 0) {
Assertions.UNREACHABLE();
}
ISSABasicBlock queryBlock = findBlock(ir, instructionIndex);
SSAInstruction def = du.getDef(v);
final SSACFG.BasicBlock defBlock = def == null ? null : findBlock(ir, def);
final Collection uses = findBlocks(ir, du.getUses(v));
// a filter which accepts everything but the block which defs v
Predicate