本文整理汇总了C++中Procedure::values方法的典型用法代码示例。如果您正苦于以下问题:C++ Procedure::values方法的具体用法?C++ Procedure::values怎么用?C++ Procedure::values使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Procedure
的用法示例。
在下文中一共展示了Procedure::values方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
UseCounts::UseCounts(Procedure& procedure)
: m_counts(procedure.values().size())
{
Vector<Value*, 64> children;
for (Value* value : procedure.values()) {
children.shrink(0);
for (Value* child : value->children()) {
m_counts[child].numUses++;
children.append(child);
}
std::sort(children.begin(), children.end());
Value* last = nullptr;
for (Value* child : children) {
if (child == last)
continue;
m_counts[child].numUsingInstructions++;
last = child;
}
}
}
示例2: demoteValues
void demoteValues(Procedure& proc, const IndexSet<Value>& values)
{
HashMap<Value*, StackSlotValue*> map;
HashMap<Value*, StackSlotValue*> phiMap;
// Create stack slots.
InsertionSet insertionSet(proc);
for (Value* value : values.values(proc.values())) {
StackSlotValue* stack = insertionSet.insert<StackSlotValue>(
0, value->origin(), sizeofType(value->type()), StackSlotKind::Anonymous);
map.add(value, stack);
if (value->opcode() == Phi) {
StackSlotValue* phiStack = insertionSet.insert<StackSlotValue>(
0, value->origin(), sizeofType(value->type()), StackSlotKind::Anonymous);
phiMap.add(value, phiStack);
}
}
insertionSet.execute(proc[0]);
if (verbose) {
dataLog("Demoting values as follows:\n");
dataLog(" map = ");
CommaPrinter comma;
for (auto& entry : map)
dataLog(comma, *entry.key, "=>", *entry.value);
dataLog("\n");
dataLog(" phiMap = ");
comma = CommaPrinter();
for (auto& entry : phiMap)
dataLog(comma, *entry.key, "=>", *entry.value);
dataLog("\n");
}
// Change accesses to the values to accesses to the stack slots.
for (BasicBlock* block : proc) {
for (unsigned valueIndex = 0; valueIndex < block->size(); ++valueIndex) {
Value* value = block->at(valueIndex);
if (value->opcode() == Phi) {
if (StackSlotValue* stack = phiMap.get(value)) {
value->replaceWithIdentity(
insertionSet.insert<MemoryValue>(
valueIndex, Load, value->type(), value->origin(), stack));
}
} else {
for (Value*& child : value->children()) {
if (StackSlotValue* stack = map.get(child)) {
child = insertionSet.insert<MemoryValue>(
valueIndex, Load, child->type(), value->origin(), stack);
}
}
if (UpsilonValue* upsilon = value->as<UpsilonValue>()) {
if (StackSlotValue* stack = phiMap.get(upsilon->phi())) {
insertionSet.insert<MemoryValue>(
valueIndex, Store, upsilon->origin(), upsilon->child(0), stack);
value->replaceWithNop();
}
}
}
if (StackSlotValue* stack = map.get(value)) {
insertionSet.insert<MemoryValue>(
valueIndex + 1, Store, value->origin(), value, stack);
}
}
insertionSet.execute(block);
}
}
示例3: fixSSA
bool fixSSA(Procedure& proc)
{
PhaseScope phaseScope(proc, "fixSSA");
// Collect the stack "variables". If there aren't any, then we don't have anything to do.
// That's a fairly common case.
HashMap<StackSlotValue*, Type> stackVariable;
for (Value* value : proc.values()) {
if (StackSlotValue* stack = value->as<StackSlotValue>()) {
if (stack->kind() == StackSlotKind::Anonymous)
stackVariable.add(stack, Void);
}
}
if (stackVariable.isEmpty())
return false;
// Make sure that we know how to optimize all of these. We only know how to handle Load and
// Store on anonymous variables.
for (Value* value : proc.values()) {
auto reject = [&] (Value* value) {
if (StackSlotValue* stack = value->as<StackSlotValue>())
stackVariable.remove(stack);
};
auto handleAccess = [&] (Value* access, Type type) {
StackSlotValue* stack = access->lastChild()->as<StackSlotValue>();
if (!stack)
return;
if (value->as<MemoryValue>()->offset()) {
stackVariable.remove(stack);
return;
}
auto result = stackVariable.find(stack);
if (result == stackVariable.end())
return;
if (result->value == Void) {
result->value = type;
return;
}
if (result->value == type)
return;
stackVariable.remove(result);
};
switch (value->opcode()) {
case Load:
// We're OK with loads from stack variables at an offset of zero.
handleAccess(value, value->type());
break;
case Store:
// We're OK with stores to stack variables, but not storing stack variables.
reject(value->child(0));
handleAccess(value, value->child(0)->type());
break;
default:
for (Value* child : value->children())
reject(child);
break;
}
}
Vector<StackSlotValue*> deadValues;
for (auto& entry : stackVariable) {
if (entry.value == Void)
deadValues.append(entry.key);
}
for (StackSlotValue* deadValue : deadValues) {
deadValue->replaceWithNop();
stackVariable.remove(deadValue);
}
if (stackVariable.isEmpty())
return false;
// We know that we have variables to optimize, so do that now.
breakCriticalEdges(proc);
SSACalculator ssa(proc);
// Create a SSACalculator::Variable for every stack variable.
Vector<StackSlotValue*> variableToStack;
HashMap<StackSlotValue*, SSACalculator::Variable*> stackToVariable;
for (auto& entry : stackVariable) {
StackSlotValue* stack = entry.key;
SSACalculator::Variable* variable = ssa.newVariable();
RELEASE_ASSERT(variable->index() == variableToStack.size());
variableToStack.append(stack);
stackToVariable.add(stack, variable);
}
// Create Defs for all of the stores to the stack variable.
for (BasicBlock* block : proc) {
for (Value* value : *block) {
if (value->opcode() != Store)
continue;
//.........这里部分代码省略.........