Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace IR::getBitType with IR::Type_Bits::get. #4669

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backends/p4tools/common/compiler/convert_hs_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const IR::Node *HSIndexToMember::postorder(IR::ArrayIndex *curArrayIndex) {
const IR::ArrayIndex *HSIndexToMember::produceStackIndex(const IR::Type *type,
const IR::Expression *expression,
size_t arrayIndex) {
return new IR::ArrayIndex(type, expression, IR::Constant::get(IR::getBitType(32), arrayIndex));
return new IR::ArrayIndex(type, expression,
IR::Constant::get(IR::Type_Bits::get(32), arrayIndex));
}

} // namespace P4Tools
2 changes: 1 addition & 1 deletion backends/p4tools/common/lib/taint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class TaintPropagator : public Transform {
auto slLeftInt = slice->e1->checkedTo<IR::Constant>()->asInt();
auto slRightInt = slice->e2->checkedTo<IR::Constant>()->asInt();
auto width = 1 + slLeftInt - slRightInt;
const auto *sliceTb = IR::getBitType(width);
const auto *sliceTb = IR::Type_Bits::get(width);
if (Taint::hasTaint(slice)) {
return ToolsVariables::getTaintExpression(sliceTb);
}
Expand Down
2 changes: 1 addition & 1 deletion backends/p4tools/common/lib/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ big_int Utils::getRandBigInt(big_int max) {
const IR::Constant *Utils::getRandConstantForWidth(int bitWidth) {
auto maxVal = IR::getMaxBvVal(bitWidth);
auto randInt = Utils::getRandBigInt(maxVal);
const auto *constType = IR::getBitType(bitWidth);
const auto *constType = IR::Type_Bits::get(bitWidth);
return IR::Constant::get(constType, randInt);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ void ExprStepper::evalExternMethodCall(const IR::MethodCallExpression *call,
BUG_CHECK(!fieldType->is<IR::Type_StructLike>(),
"Unexpected emit field %1% of type %2%", fieldExpr, fieldType);
if (const auto *varbits = fieldType->to<IR::Extracted_Varbits>()) {
fieldType = IR::getBitType(varbits->assignedSize);
fieldType = IR::Type_Bits::get(varbits->assignedSize);
}
auto fieldWidth = fieldType->width_bits();
// If the width is zero, do not bother with emitting.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const IR::StateVariable &TableStepper::getTableActionVar(const IR::P4Table *tabl
size_t max = 255;
BUG_CHECK(numActions < max, "Number of actions in the table (%1%) exceeds the maximum of %2%.",
numActions, max);
return getTableStateVariable(IR::getBitType(8), table, "*action");
return getTableStateVariable(IR::Type_Bits::get(8), table, "*action");
}

const IR::StateVariable &TableStepper::getTableResultVar(const IR::P4Table *table) {
Expand Down
32 changes: 16 additions & 16 deletions backends/p4tools/modules/testgen/lib/execution_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ ExecutionState::ExecutionState(const IR::P4Program *program)
: AbstractExecutionState(program),
body({program}),
stack(*(new std::stack<std::reference_wrapper<const StackFrame>>())) {
env.set(&PacketVars::INPUT_PACKET_LABEL, IR::Constant::get(IR::getBitType(0), 0));
env.set(&PacketVars::PACKET_BUFFER_LABEL, IR::Constant::get(IR::getBitType(0), 0));
env.set(&PacketVars::INPUT_PACKET_LABEL, IR::Constant::get(IR::Type_Bits::get(0), 0));
env.set(&PacketVars::PACKET_BUFFER_LABEL, IR::Constant::get(IR::Type_Bits::get(0), 0));
// We also add the taint property and set it to false.
setProperty("inUndefinedState", false);
// Drop is initialized to false, too.
Expand Down Expand Up @@ -385,14 +385,14 @@ int ExecutionState::getInputPacketSize() const {

void ExecutionState::appendToInputPacket(const IR::Expression *expr) {
const auto *inputPkt = getInputPacket();
const auto *width = IR::getBitType(expr->type->width_bits() + inputPkt->type->width_bits());
const auto *width = IR::Type_Bits::get(expr->type->width_bits() + inputPkt->type->width_bits());
const auto *concat = new IR::Concat(width, inputPkt, expr);
env.set(&PacketVars::INPUT_PACKET_LABEL, concat);
}

void ExecutionState::prependToInputPacket(const IR::Expression *expr) {
const auto *inputPkt = getInputPacket();
const auto *width = IR::getBitType(expr->type->width_bits() + inputPkt->type->width_bits());
const auto *width = IR::Type_Bits::get(expr->type->width_bits() + inputPkt->type->width_bits());
const auto *concat = new IR::Concat(width, expr, inputPkt);
env.set(&PacketVars::INPUT_PACKET_LABEL, concat);
}
Expand All @@ -415,18 +415,18 @@ const IR::Expression *ExecutionState::peekPacketBuffer(int amount) {
auto bufferSize = buffer->type->width_bits();

auto diff = amount - bufferSize;
const auto *amountType = IR::getBitType(amount);
const auto *amountType = IR::Type_Bits::get(amount);
// We are running off the available buffer, we need to generate new packet content.
if (diff > 0) {
// We need to enlarge the input packet by the amount we are exceeding the buffer.
// TODO: How should we perform accounting here?
const IR::Expression *newVar = createPacketVariable(IR::getBitType(diff));
const IR::Expression *newVar = createPacketVariable(IR::Type_Bits::get(diff));
appendToInputPacket(newVar);
// If the buffer was not empty, append the data we have consumed to the newly generated
// content and reset the buffer.
if (bufferSize > 0) {
auto *slice = new IR::Slice(buffer, bufferSize - 1, 0);
slice->type = IR::getBitType(amount);
slice->type = IR::Type_Bits::get(amount);
newVar = new IR::Concat(amountType, slice, newVar);
resetPacketBuffer();
}
Expand Down Expand Up @@ -457,18 +457,18 @@ const IR::Expression *ExecutionState::slicePacketBuffer(int amount) {

// Compute the difference between what we have in the buffer and what we want to slice.
auto diff = amount - bufferSize;
const auto *amountType = IR::getBitType(amount);
const auto *amountType = IR::Type_Bits::get(amount);
// We are running off the available buffer, we need to generate new packet content.
if (diff > 0) {
// We need to enlarge the input packet by the amount we are exceeding the buffer.
// TODO: How should we perform accounting here?
const IR::Expression *newVar = createPacketVariable(IR::getBitType(diff));
const IR::Expression *newVar = createPacketVariable(IR::Type_Bits::get(diff));
appendToInputPacket(newVar);
// If the buffer was not empty, append the data we have consumed to the newly generated
// content and reset the buffer.
if (bufferSize > 0) {
auto *slice = new IR::Slice(buffer, bufferSize - 1, 0);
slice->type = IR::getBitType(amount);
slice->type = IR::Type_Bits::get(amount);
newVar = new IR::Concat(amountType, slice, newVar);
resetPacketBuffer();
}
Expand All @@ -482,7 +482,7 @@ const IR::Expression *ExecutionState::slicePacketBuffer(int amount) {
// If the buffer is larger, update the buffer with its remainder.
if (diff < 0) {
auto *remainder = new IR::Slice(buffer, bufferSize - amount - 1, 0);
remainder->type = IR::getBitType(bufferSize - amount);
remainder->type = IR::Type_Bits::get(bufferSize - amount);
env.set(&PacketVars::PACKET_BUFFER_LABEL, remainder);
}
// The amount we slice is equal to what is in the buffer. Just set the buffer to zero.
Expand All @@ -494,33 +494,33 @@ const IR::Expression *ExecutionState::slicePacketBuffer(int amount) {

void ExecutionState::appendToPacketBuffer(const IR::Expression *expr) {
const auto *buffer = getPacketBuffer();
const auto *width = IR::getBitType(expr->type->width_bits() + buffer->type->width_bits());
const auto *width = IR::Type_Bits::get(expr->type->width_bits() + buffer->type->width_bits());
const auto *concat = new IR::Concat(width, buffer, expr);
env.set(&PacketVars::PACKET_BUFFER_LABEL, concat);
}

void ExecutionState::prependToPacketBuffer(const IR::Expression *expr) {
const auto *buffer = getPacketBuffer();
const auto *width = IR::getBitType(expr->type->width_bits() + buffer->type->width_bits());
const auto *width = IR::Type_Bits::get(expr->type->width_bits() + buffer->type->width_bits());
const auto *concat = new IR::Concat(width, expr, buffer);
env.set(&PacketVars::PACKET_BUFFER_LABEL, concat);
}

void ExecutionState::resetPacketBuffer() {
env.set(&PacketVars::PACKET_BUFFER_LABEL, IR::Constant::get(IR::getBitType(0), 0));
env.set(&PacketVars::PACKET_BUFFER_LABEL, IR::Constant::get(IR::Type_Bits::get(0), 0));
}

const IR::Expression *ExecutionState::getEmitBuffer() const {
return env.get(&PacketVars::EMIT_BUFFER_LABEL);
}

void ExecutionState::resetEmitBuffer() {
env.set(&PacketVars::EMIT_BUFFER_LABEL, IR::Constant::get(IR::getBitType(0), 0));
env.set(&PacketVars::EMIT_BUFFER_LABEL, IR::Constant::get(IR::Type_Bits::get(0), 0));
}

void ExecutionState::appendToEmitBuffer(const IR::Expression *expr) {
const auto *buffer = getEmitBuffer();
const auto *width = IR::getBitType(expr->type->width_bits() + buffer->type->width_bits());
const auto *width = IR::Type_Bits::get(expr->type->width_bits() + buffer->type->width_bits());
const auto *concat = new IR::Concat(width, buffer, expr);
env.set(&PacketVars::EMIT_BUFFER_LABEL, concat);
}
Expand Down
2 changes: 1 addition & 1 deletion backends/p4tools/modules/testgen/lib/final_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void FinalState::calculatePayload(const ExecutionState &executionState, Model &e
const auto *inputPacketExpr = executionState.getInputPacket();
int payloadSize = calculatedPacketSize - inputPacketExpr->type->width_bits();
if (payloadSize > 0) {
const auto *payloadType = IR::getBitType(payloadSize);
const auto *payloadType = IR::Type_Bits::get(payloadSize);
const IR::Expression *payloadExpr = evaluatedModel.get(&PacketVars::PAYLOAD_SYMBOL, false);
if (payloadExpr == nullptr) {
payloadExpr = Utils::getRandConstantForType(payloadType);
Expand Down
8 changes: 4 additions & 4 deletions backends/p4tools/modules/testgen/lib/test_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ TestBackEnd::TestInfo TestBackEnd::produceTestInfo(
const auto *payloadExpr = finalModel->get(&PacketVars::PAYLOAD_SYMBOL, false);
if (payloadExpr != nullptr) {
inputPacketExpr =
new IR::Concat(IR::getBitType(calculatedPacketSize), inputPacketExpr, payloadExpr);
outputPacketExpr = new IR::Concat(
IR::getBitType(outputPacketExpr->type->width_bits() + payloadExpr->type->width_bits()),
outputPacketExpr, payloadExpr);
new IR::Concat(IR::Type_Bits::get(calculatedPacketSize), inputPacketExpr, payloadExpr);
outputPacketExpr = new IR::Concat(IR::Type_Bits::get(outputPacketExpr->type->width_bits() +
payloadExpr->type->width_bits()),
outputPacketExpr, payloadExpr);
}
const auto *inputPacket = finalModel->evaluate(inputPacketExpr, true);
const auto *outputPacket = finalModel->evaluate(outputPacketExpr, true);
Expand Down
4 changes: 2 additions & 2 deletions backends/p4tools/modules/testgen/targets/bmv2/cmd_stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ void Bmv2V1ModelCmdStepper::initializeTargetEnvironment(ExecutionState &nextStat
blockIdx++;
}

const auto *nineBitType = IR::getBitType(9);
const auto *oneBitType = IR::getBitType(1);
const auto *nineBitType = IR::Type_Bits::get(9);
const auto *oneBitType = IR::Type_Bits::get(1);
nextState.set(programInfo.getTargetInputPortVar(),
ToolsVariables::getSymbolicVariable(nineBitType, "bmv2_ingress_port"));
// BMv2 implicitly sets the output port to 0.
Expand Down
6 changes: 3 additions & 3 deletions backends/p4tools/modules/testgen/targets/bmv2/concolic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ big_int Bmv2Concolic::computeChecksum(const std::vector<const IR::Expression *>
for (size_t idx = 1; idx < exprList.size(); idx++) {
const auto *expr = exprList.at(idx);
const auto *newWidth =
IR::getBitType(concatExpr->type->width_bits() + expr->type->width_bits());
IR::Type_Bits::get(concatExpr->type->width_bits() + expr->type->width_bits());
concatExpr = new IR::Concat(newWidth, concatExpr, expr);
}

Expand All @@ -71,8 +71,8 @@ big_int Bmv2Concolic::computeChecksum(const std::vector<const IR::Expression *>
if (remainder != 0) {
auto fillWidth = CHUNK_SIZE - remainder;
concatWidth += fillWidth;
const auto *remainderExpr = IR::Constant::get(IR::getBitType(fillWidth), 0);
concatExpr = new IR::Concat(IR::getBitType(concatWidth), concatExpr, remainderExpr);
const auto *remainderExpr = IR::Constant::get(IR::Type_Bits::get(fillWidth), 0);
concatExpr = new IR::Concat(IR::Type_Bits::get(concatWidth), concatExpr, remainderExpr);
}
auto dataInt =
IR::getBigIntFromLiteral(finalModel.evaluate(concatExpr, true, resolvedExpressions));
Expand Down
12 changes: 6 additions & 6 deletions backends/p4tools/modules/testgen/targets/bmv2/expr_stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void Bmv2V1ModelExprStepper::processClone(const ExecutionState &state,
std::vector<Continuation::Command> cmds;

// We need to set the instance type once we recirculate.
const auto *instanceBitType = IR::getBitType(32);
const auto *instanceBitType = IR::Type_Bits::get(32);
const auto *instanceTypeVar = new IR::Member(
instanceBitType, new IR::PathExpression("*standard_metadata"), "instance_type");

Expand Down Expand Up @@ -270,7 +270,7 @@ void Bmv2V1ModelExprStepper::processRecirculate(const ExecutionState &state,
}

// Update the metadata variable to the correct instance type as provided by recirculation.
const auto *bitType = IR::getBitType(32);
const auto *bitType = IR::Type_Bits::get(32);
const auto *instanceTypeVar =
new IR::Member(bitType, new IR::PathExpression("*standard_metadata"), "instance_type");
recState.set(instanceTypeVar, IR::Constant::get(bitType, instanceType));
Expand Down Expand Up @@ -342,7 +342,7 @@ void Bmv2V1ModelExprStepper::evalExternMethodCall(const IR::MethodCallExpression
IR::ID & /*methodName*/, const IR::Vector<IR::Argument> *args,
const ExecutionState &state, SmallStepEvaluator::Result &result) {
auto &nextState = state.clone();
const auto *nineBitType = IR::getBitType(BMv2Constants::PORT_BIT_WIDTH);
const auto *nineBitType = IR::Type_Bits::get(BMv2Constants::PORT_BIT_WIDTH);
const auto *metadataLabel = args->at(0)->expression->checkedTo<IR::InOutReference>();
// Use an assignment to set egress_spec to true.
// This variable will be processed in the deparser.
Expand Down Expand Up @@ -931,7 +931,7 @@ void Bmv2V1ModelExprStepper::evalExternMethodCall(const IR::MethodCallExpression
} else {
meterValue = new Bmv2V1ModelMeterValue(inputValue, true);
}
meterValue->writeToIndex(IR::Constant::get(IR::getBitType(1), 0), inputValue);
meterValue->writeToIndex(IR::Constant::get(IR::Type_Bits::get(1), 0), inputValue);
nextState.addTestObject("meter_values", externInstance->controlPlaneName(),
meterValue);

Expand Down Expand Up @@ -1342,7 +1342,7 @@ void Bmv2V1ModelExprStepper::evalExternMethodCall(const IR::MethodCallExpression
const auto *checksumValue = args->at(2)->expression;
const auto *checksumValueType = checksumValue->type;
const auto *algo = args->at(3)->expression;
const auto *oneBitType = IR::getBitType(1);
const auto *oneBitType = IR::Type_Bits::get(1);

// In some cases the condition is false already. No need to do complex processing then.
if (const auto *boolVal = verifyCond->to<IR::BoolLiteral>()) {
Expand Down Expand Up @@ -1589,7 +1589,7 @@ void Bmv2V1ModelExprStepper::evalExternMethodCall(const IR::MethodCallExpression
const auto *checksumValue = args->at(2)->expression;
const auto *checksumValueType = checksumValue->type;
const auto *algo = args->at(3)->expression;
const auto *oneBitType = IR::getBitType(1);
const auto *oneBitType = IR::Type_Bits::get(1);
// If the condition is tainted or the input data is tainted, the checksum error
// will not be reliable.
if (argsAreTainted) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ const RefersToParser::RefersToBuiltinMap RefersToParser::REFERS_TO_BUILTIN_MAP =
{
{
"multicast_group_id",
IR::SymbolicVariable(IR::getBitType(16), "refers_to_multicast_group_id"),
IR::SymbolicVariable(IR::Type_Bits::get(16), "refers_to_multicast_group_id"),
},
{
"replica.port",
IR::SymbolicVariable(IR::getBitType(9), "refers_to_replica.port"),
IR::SymbolicVariable(IR::Type_Bits::get(9), "refers_to_replica.port"),
},
{
"replica.instance",
IR::SymbolicVariable(IR::getBitType(16), "refers_to_replica.instance"),
IR::SymbolicVariable(IR::Type_Bits::get(16), "refers_to_replica.instance"),
},
},
}};
Expand Down
10 changes: 5 additions & 5 deletions backends/p4tools/modules/testgen/targets/bmv2/program_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ std::vector<Continuation::Command> Bmv2V1ModelProgramInfo::processDeclaration(
// processing. For example, the egress port.
if ((archMember->blockName == "Ingress")) {
auto *egressPortVar =
new IR::Member(IR::getBitType(BMv2Constants::PORT_BIT_WIDTH),
new IR::Member(IR::Type_Bits::get(BMv2Constants::PORT_BIT_WIDTH),
new IR::PathExpression("*standard_metadata"), "egress_port");
auto *portStmt = new IR::AssignmentStatement(egressPortVar, getTargetOutputPortVar());
cmds.emplace_back(portStmt);
Expand All @@ -161,8 +161,8 @@ std::vector<Continuation::Command> Bmv2V1ModelProgramInfo::processDeclaration(
// TODO: We have not implemented multi cast yet.
// Drop the packet if the multicast group is set.
const IR::Expression *mcastGroupVar = new IR::Member(
IR::getBitType(16), new IR::PathExpression("*standard_metadata"), "mcast_grp");
mcastGroupVar = new IR::Neq(mcastGroupVar, IR::Constant::get(IR::getBitType(16), 0));
IR::Type_Bits::get(16), new IR::PathExpression("*standard_metadata"), "mcast_grp");
mcastGroupVar = new IR::Neq(mcastGroupVar, IR::Constant::get(IR::Type_Bits::get(16), 0));
auto *mcastStmt = new IR::IfStatement(mcastGroupVar, dropStmt, nullptr);
cmds.emplace_back(mcastStmt);
}
Expand All @@ -183,13 +183,13 @@ std::vector<Continuation::Command> Bmv2V1ModelProgramInfo::processDeclaration(
}

const IR::StateVariable &Bmv2V1ModelProgramInfo::getTargetInputPortVar() const {
return *new IR::StateVariable(new IR::Member(IR::getBitType(BMv2Constants::PORT_BIT_WIDTH),
return *new IR::StateVariable(new IR::Member(IR::Type_Bits::get(BMv2Constants::PORT_BIT_WIDTH),
new IR::PathExpression("*standard_metadata"),
"ingress_port"));
}

const IR::StateVariable &Bmv2V1ModelProgramInfo::getTargetOutputPortVar() const {
return *new IR::StateVariable(new IR::Member(IR::getBitType(BMv2Constants::PORT_BIT_WIDTH),
return *new IR::StateVariable(new IR::Member(IR::Type_Bits::get(BMv2Constants::PORT_BIT_WIDTH),
new IR::PathExpression("*standard_metadata"),
"egress_spec"));
}
Expand Down
Loading
Loading