本文整理汇总了C#中Microsoft.Boogie.Implementation.ComputePredecessorsForBlocks方法的典型用法代码示例。如果您正苦于以下问题:C# Implementation.ComputePredecessorsForBlocks方法的具体用法?C# Implementation.ComputePredecessorsForBlocks怎么用?C# Implementation.ComputePredecessorsForBlocks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Boogie.Implementation
的用法示例。
在下文中一共展示了Implementation.ComputePredecessorsForBlocks方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ComputeYieldingLoopHeaders
private Graph<Block> ComputeYieldingLoopHeaders(Implementation impl, out HashSet<Block> yieldingHeaders)
{
Graph<Block> graph;
impl.PruneUnreachableBlocks();
impl.ComputePredecessorsForBlocks();
graph = Program.GraphFromImpl(impl);
graph.ComputeLoops();
if (!graph.Reducible)
{
throw new Exception("Irreducible flow graphs are unsupported.");
}
yieldingHeaders = new HashSet<Block>();
IEnumerable<Block> sortedHeaders = graph.SortHeadersByDominance();
foreach (Block header in sortedHeaders)
{
if (yieldingHeaders.Any(x => graph.DominatorMap.DominatedBy(x, header)))
{
yieldingHeaders.Add(header);
}
else if (IsYieldingHeader(graph, header))
{
yieldingHeaders.Add(header);
}
else
{
continue;
}
}
return graph;
}
示例2: ProcessLoops
public Graph<Block> ProcessLoops(Implementation impl) {
while (true) {
impl.PruneUnreachableBlocks();
impl.ComputePredecessorsForBlocks();
Graph<Block/*!*/>/*!*/ g = GraphFromImpl(impl);
g.ComputeLoops();
if (g.Reducible) {
return g;
}
throw new IrreducibleLoopException();
#if USED_CODE
System.Diagnostics.Debug.Assert(g.SplitCandidates.Count > 0);
Block splitCandidate = null;
foreach (Block b in g.SplitCandidates) {
if (b.Predecessors.Length > 1) {
splitCandidate = b;
break;
}
}
System.Diagnostics.Debug.Assert(splitCandidate != null);
int count = 0;
foreach (Block b in splitCandidate.Predecessors) {
GotoCmd gotoCmd = (GotoCmd)b.TransferCmd;
gotoCmd.labelNames.Remove(splitCandidate.Label);
gotoCmd.labelTargets.Remove(splitCandidate);
CodeCopier codeCopier = new CodeCopier(new Hashtable(), new Hashtable());
List<Cmd> newCmdSeq = codeCopier.CopyCmdSeq(splitCandidate.Cmds);
TransferCmd newTransferCmd;
GotoCmd splitGotoCmd = splitCandidate.TransferCmd as GotoCmd;
if (splitGotoCmd == null) {
newTransferCmd = new ReturnCmd(splitCandidate.tok);
}
else {
List<String> newLabelNames = new List<String>();
newLabelNames.AddRange(splitGotoCmd.labelNames);
List<Block> newLabelTargets = new List<Block>();
newLabelTargets.AddRange(splitGotoCmd.labelTargets);
newTransferCmd = new GotoCmd(splitCandidate.tok, newLabelNames, newLabelTargets);
}
Block copy = new Block(splitCandidate.tok, splitCandidate.Label + count++, newCmdSeq, newTransferCmd);
impl.Blocks.Add(copy);
gotoCmd.AddTarget(copy);
}
#endif
}
}
示例3: VisitImplementation
public override Implementation VisitImplementation(Implementation node)
{
node.PruneUnreachableBlocks();
node.ComputePredecessorsForBlocks();
GraphUtil.Graph<Block> graph = Program.GraphFromImpl(node);
graph.ComputeLoops();
HashSet<Variable> start = new HashSet<Variable>(globalVarToDomainName.Keys);
for (int i = 0; i < node.InParams.Count; i++)
{
Variable v = node.Proc.InParams[i];
string domainName = FindDomainName(v);
if (domainName != null)
{
var kind = FindLinearKind(v);
inParamToLinearQualifier[node.InParams[i]] = new LinearQualifier(domainName, kind);
if (kind == LinearKind.LINEAR || kind == LinearKind.LINEAR_IN)
{
start.Add(node.InParams[i]);
}
}
}
for (int i = 0; i < node.OutParams.Count; i++)
{
string domainName = FindDomainName(node.Proc.OutParams[i]);
if (domainName != null)
{
outParamToDomainName[node.OutParams[i]] = domainName;
}
}
var oldErrorCount = this.errorCount;
var impl = base.VisitImplementation(node);
if (oldErrorCount < this.errorCount)
return impl;
Stack<Block> dfsStack = new Stack<Block>();
HashSet<Block> dfsStackAsSet = new HashSet<Block>();
availableLinearVars[node.Blocks[0]] = start;
dfsStack.Push(node.Blocks[0]);
dfsStackAsSet.Add(node.Blocks[0]);
while (dfsStack.Count > 0)
{
Block b = dfsStack.Pop();
dfsStackAsSet.Remove(b);
HashSet<Variable> end = PropagateAvailableLinearVarsAcrossBlock(b);
if (b.TransferCmd is ReturnCmd)
{
foreach (GlobalVariable g in globalVarToDomainName.Keys.Except(end))
{
Error(b.TransferCmd, string.Format("Global variable {0} must be available at a return", g.Name));
}
foreach (Variable v in node.InParams)
{
if (FindDomainName(v) == null || FindLinearKind(v) == LinearKind.LINEAR_IN || end.Contains(v)) continue;
Error(b.TransferCmd, string.Format("Input variable {0} must be available at a return", v.Name));
}
foreach (Variable v in node.OutParams)
{
if (FindDomainName(v) == null || end.Contains(v)) continue;
Error(b.TransferCmd, string.Format("Output variable {0} must be available at a return", v.Name));
}
continue;
}
GotoCmd gotoCmd = b.TransferCmd as GotoCmd;
foreach (Block target in gotoCmd.labelTargets)
{
if (!availableLinearVars.ContainsKey(target))
{
availableLinearVars[target] = new HashSet<Variable>(end);
dfsStack.Push(target);
dfsStackAsSet.Add(target);
}
else
{
var savedAvailableVars = new HashSet<Variable>(availableLinearVars[target]);
availableLinearVars[target].IntersectWith(end);
if (savedAvailableVars.IsProperSupersetOf(availableLinearVars[target]) && !dfsStackAsSet.Contains(target))
{
dfsStack.Push(target);
dfsStackAsSet.Add(target);
}
}
}
}
if (graph.Reducible)
{
foreach (Block header in graph.Headers)
{
foreach (GlobalVariable g in globalVarToDomainName.Keys.Except(availableLinearVars[header]))
{
Error(header, string.Format("Global variable {0} must be available at a loop head", g.Name));
}
}
}
return impl;
}
示例4: TransformImpl
private void TransformImpl(Implementation impl)
{
if (!QKeyValue.FindBoolAttribute(impl.Proc.Attributes, "yields")) return;
// Find the yielding loop headers
impl.PruneUnreachableBlocks();
impl.ComputePredecessorsForBlocks();
GraphUtil.Graph<Block> graph = Program.GraphFromImpl(impl);
graph.ComputeLoops();
if (!graph.Reducible)
{
throw new Exception("Irreducible flow graphs are unsupported.");
}
HashSet<Block> yieldingHeaders = new HashSet<Block>();
IEnumerable<Block> sortedHeaders = graph.SortHeadersByDominance();
foreach (Block header in sortedHeaders)
{
if (yieldingHeaders.Any(x => graph.DominatorMap.DominatedBy(x, header)))
{
yieldingHeaders.Add(header);
}
else if (IsYieldingHeader(graph, header))
{
yieldingHeaders.Add(header);
}
else
{
continue;
}
}
Program program = linearTypeChecker.program;
Dictionary<Variable, Expr> map = new Dictionary<Variable, Expr>();
foreach (Variable local in impl.LocVars)
{
var copy = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, local.Name, local.TypedIdent.Type));
map[local] = new IdentifierExpr(Token.NoToken, copy);
}
Dictionary<Variable, Variable> ogOldGlobalMap = new Dictionary<Variable, Variable>();
foreach (IdentifierExpr ie in globalMods)
{
Variable g = ie.Decl;
LocalVariable l = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, string.Format("og_global_old_{0}", g.Name), g.TypedIdent.Type));
ogOldGlobalMap[g] = l;
impl.LocVars.Add(l);
}
Dictionary<string, Variable> domainNameToInputVar = new Dictionary<string, Variable>();
Dictionary<string, Variable> domainNameToLocalVar = new Dictionary<string, Variable>();
{
int i = impl.InParams.Count - linearTypeChecker.linearDomains.Count;
foreach (string domainName in linearTypeChecker.linearDomains.Keys)
{
Variable inParam = impl.InParams[i];
domainNameToInputVar[domainName] = inParam;
Variable l = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, inParam.Name + "_local", inParam.TypedIdent.Type));
domainNameToLocalVar[domainName] = l;
impl.LocVars.Add(l);
i++;
}
}
// Collect the yield predicates and desugar yields
List<List<Cmd>> yields = new List<List<Cmd>>();
List<Cmd> cmds = new List<Cmd>();
foreach (Block b in impl.Blocks)
{
YieldCmd yieldCmd = null;
List<Cmd> newCmds = new List<Cmd>();
for (int i = 0; i < b.Cmds.Count; i++)
{
Cmd cmd = b.Cmds[i];
if (cmd is YieldCmd)
{
yieldCmd = (YieldCmd)cmd;
continue;
}
if (yieldCmd != null)
{
PredicateCmd pcmd = cmd as PredicateCmd;
if (pcmd == null)
{
DesugarYield(yieldCmd, cmds, newCmds, ogOldGlobalMap, domainNameToInputVar, domainNameToLocalVar);
if (cmds.Count > 0)
{
yields.Add(cmds);
cmds = new List<Cmd>();
}
yieldCmd = null;
}
else
{
cmds.Add(pcmd);
}
}
if (cmd is CallCmd)
{
CallCmd callCmd = cmd as CallCmd;
if (callCmd.IsAsync || QKeyValue.FindBoolAttribute(callCmd.Proc.Attributes, "yields"))
{
//.........这里部分代码省略.........