Implement operands for the lower and upper bounds of the for statement.
This revamps implementation of the loop bounds in the ForStmt, using general representation that supports operands. The frequent case of constant bounds is supported
via special access methods.
This also includes:
- Operand iterators for the Statement class.
- OpPointer::is() method to query the class of the Operation.
- Support for the bound shorthand notation parsing and printing.
- Validity checks for the bound operands used as dim ids and symbols
I didn't mean this CL to be so large. It just happened this way, as one thing led to another.
PiperOrigin-RevId: 210204858
diff --git a/lib/IR/Verifier.cpp b/lib/IR/Verifier.cpp
index b74e113..deda932 100644
--- a/lib/IR/Verifier.cpp
+++ b/lib/IR/Verifier.cpp
@@ -372,6 +372,7 @@
// TODO: check that operation is not a return statement unless it's
// the last one in the function.
+ // TODO: check that loop bounds are properly formed.
if (verifyReturn())
return true;
@@ -409,23 +410,20 @@
liveValues.insert(forStmt, true);
for (auto &stmt : block) {
- // TODO: For and If will eventually have operands, we need to check them.
- // When this happens, Statement should have a general getOperands() method
- // we can use here first.
- if (auto *opStmt = dyn_cast<OperationStmt>(&stmt)) {
- // Verify that each of the operands are live.
- unsigned operandNo = 0;
- for (auto *opValue : opStmt->getOperands()) {
- if (!liveValues.count(opValue)) {
- opStmt->emitError("operand #" + Twine(operandNo) +
- " does not dominate this use");
- if (auto *useStmt = opValue->getDefiningStmt())
- useStmt->emitNote("operand defined here");
- return true;
- }
- ++operandNo;
+ // Verify that each of the operands are live.
+ unsigned operandNo = 0;
+ for (auto *opValue : stmt.getOperands()) {
+ if (!liveValues.count(opValue)) {
+ stmt.emitError("operand #" + Twine(operandNo) +
+ " does not dominate this use");
+ if (auto *useStmt = opValue->getDefiningStmt())
+ useStmt->emitNote("operand defined here");
+ return true;
}
+ ++operandNo;
+ }
+ if (auto *opStmt = dyn_cast<OperationStmt>(&stmt)) {
// Operations define values, add them to the hash table.
for (auto *result : opStmt->getResults())
liveValues.insert(result, true);