-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGARelAttr.cpp
More file actions
67 lines (58 loc) · 1.85 KB
/
Copy pathGARelAttr.cpp
File metadata and controls
67 lines (58 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <llvm/ADT/ArrayRef.h>
#include <llvm/ADT/TypeSwitch.h>
#include <mlir/IR/Builders.h>
#include <mlir/IR/BuiltinAttributes.h>
#include <mlir/IR/DialectImplementation.h>
#include <mlir/IR/OpImplementation.h>
#include "garel/GARelAttr.h"
#include "garel/GARelDialect.h"
#include "garel/GARelEnumAttr.cpp.inc"
#include "garel/GARelTypes.h"
#define GET_ATTRDEF_CLASSES
#include "garel/GARelAttr.cpp.inc"
namespace garel {
mlir::Type AggregatorAttr::getResultType(mlir::Type inputRel) {
switch (getFunc()) {
case AggregateFunc::SUM:
case AggregateFunc::MIN:
case AggregateFunc::MAX:
case AggregateFunc::LOR:
case AggregateFunc::ARGMIN:
// NOTE: argmin(arg, val) also uses first input column as output type.
return llvm::cast<RelationType>(inputRel).getColumns()[getInputs()[0]];
case AggregateFunc::COUNT:
return mlir::IntegerType::get(inputRel.getContext(), 64);
}
}
static std::size_t expectedNumInputs(AggregateFunc f) {
switch (f) {
case AggregateFunc::SUM:
case AggregateFunc::MIN:
case AggregateFunc::MAX:
case AggregateFunc::LOR:
return 1;
case AggregateFunc::ARGMIN:
return 2;
case AggregateFunc::COUNT:
return 0;
}
}
mlir::LogicalResult
AggregatorAttr::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
AggregateFunc func, llvm::ArrayRef<ColumnIdx> inputs) {
if (inputs.size() != expectedNumInputs(func)) {
return emitError() << stringifyAggregateFunc(func) << " expects exactly "
<< expectedNumInputs(func) << " inputs, got "
<< inputs.size();
}
return mlir::success();
}
// Need to define this here to avoid depending on GARelAttr in
// GARelDialect and creating a cycle.
void GARelDialect::registerAttributes() {
addAttributes<
#define GET_ATTRDEF_LIST
#include "garel/GARelAttr.cpp.inc"
>();
}
} // namespace garel