Skip to content

Commit bc9dfbf

Browse files
authored
Handle some misc TODOs (#8528)
CodeGen_LLVM.cpp: opaque pointers are now standard, and that flag no longer works. Var.h: We convert strings to Vars in many places internally, and some of those Vars originated from implicit Vars, so it's not feasible to require than the version that takes an explicit string isn't allowed to be passed things of the form "_[0-9]*". You can use the explicit constructor to make collisions with other Vars, and yes this includes the implicit vars.
1 parent ac2cd23 commit bc9dfbf

File tree

5 files changed

+26
-36
lines changed

5 files changed

+26
-36
lines changed

src/CodeGen_LLVM.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,6 @@ void CodeGen_LLVM::initialize_llvm() {
234234
for (const std::string &s : arg_vec) {
235235
c_arg_vec.push_back(s.c_str());
236236
}
237-
// TODO: Remove after opaque pointers become the default in LLVM.
238-
// This is here to document how to turn on opaque pointers, for testing, in LLVM 15
239-
// c_arg_vec.push_back("-opaque-pointers");
240237
cl::ParseCommandLineOptions((int)(c_arg_vec.size()), &c_arg_vec[0], "Halide compiler\n");
241238
}
242239

src/Deinterleave.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class Deinterleaver : public IRGraphMutator {
223223
}
224224
}
225225
if (op->value.type().lanes() > 1) {
226-
// There is probably a more efficient way to this.
226+
// There is probably a more efficient way to do this.
227227
return mutate(flatten_nested_ramps(op));
228228
}
229229

@@ -236,7 +236,14 @@ class Deinterleaver : public IRGraphMutator {
236236
} else {
237237
Type t = op->type.with_lanes(new_lanes);
238238
ModulusRemainder align = op->alignment;
239-
// TODO: Figure out the alignment of every nth lane
239+
// The alignment of a Load refers to the alignment of the first
240+
// lane, so we can preserve the existing alignment metadata if the
241+
// deinterleave is asking for any subset of lanes that includes the
242+
// first. Otherwise we just drop it. We could check if the index is
243+
// a ramp with constant stride or some other special case, but if
244+
// that's the case, the simplifier is very good at figuring out the
245+
// alignment, and it has access to context (e.g. the alignment of
246+
// enclosing lets) that we do not have here.
240247
if (starting_lane != 0) {
241248
align = ModulusRemainder();
242249
}

src/IRMatch.h

+2-7
Original file line numberDiff line numberDiff line change
@@ -1320,11 +1320,6 @@ constexpr bool and_reduce(bool first, Args... rest) {
13201320
return first && and_reduce(rest...);
13211321
}
13221322

1323-
// TODO: this can be replaced with std::min() once we require C++14 or later
1324-
constexpr int const_min(int a, int b) {
1325-
return a < b ? a : b;
1326-
}
1327-
13281323
template<Call::IntrinsicOp intrin>
13291324
struct OptionalIntrinType {
13301325
bool check(const Type &) const {
@@ -1413,7 +1408,7 @@ struct Intrin {
14131408
return saturating_cast(optional_type_hint.type, std::move(arg0));
14141409
}
14151410

1416-
Expr arg1 = std::get<const_min(1, sizeof...(Args) - 1)>(args).make(state, type_hint);
1411+
Expr arg1 = std::get<std::min<size_t>(1, sizeof...(Args) - 1)>(args).make(state, type_hint);
14171412
if (intrin == Call::absd) {
14181413
return absd(std::move(arg0), std::move(arg1));
14191414
} else if (intrin == Call::widen_right_add) {
@@ -1448,7 +1443,7 @@ struct Intrin {
14481443
return rounding_shift_right(std::move(arg0), std::move(arg1));
14491444
}
14501445

1451-
Expr arg2 = std::get<const_min(2, sizeof...(Args) - 1)>(args).make(state, type_hint);
1446+
Expr arg2 = std::get<std::min<size_t>(2, sizeof...(Args) - 1)>(args).make(state, type_hint);
14521447
if (intrin == Call::mul_shift_right) {
14531448
return mul_shift_right(std::move(arg0), std::move(arg1), std::move(arg2));
14541449
} else if (intrin == Call::rounding_mul_shift_right) {

src/IROperator.cpp

+12-20
Original file line numberDiff line numberDiff line change
@@ -1048,49 +1048,41 @@ Expr strided_ramp_base(const Expr &e, int stride) {
10481048

10491049
namespace {
10501050

1051-
struct RemoveLikelies : public IRMutator {
1051+
// Replace a specified list of intrinsics with their first arg.
1052+
class RemoveIntrinsics : public IRMutator {
10521053
using IRMutator::visit;
1054+
const std::initializer_list<Call::IntrinsicOp> &ops;
1055+
10531056
Expr visit(const Call *op) override {
1054-
if (op->is_intrinsic(Call::likely) ||
1055-
op->is_intrinsic(Call::likely_if_innermost)) {
1057+
if (op->is_intrinsic(ops)) {
10561058
return mutate(op->args[0]);
10571059
} else {
10581060
return IRMutator::visit(op);
10591061
}
10601062
}
1061-
};
10621063

1063-
// TODO: There could just be one IRMutator that can remove
1064-
// calls from a list. If we need more of these, it might be worth
1065-
// doing that refactor.
1066-
struct RemovePromises : public IRMutator {
1067-
using IRMutator::visit;
1068-
Expr visit(const Call *op) override {
1069-
if (op->is_intrinsic(Call::promise_clamped) ||
1070-
op->is_intrinsic(Call::unsafe_promise_clamped)) {
1071-
return mutate(op->args[0]);
1072-
} else {
1073-
return IRMutator::visit(op);
1074-
}
1064+
public:
1065+
RemoveIntrinsics(const std::initializer_list<Call::IntrinsicOp> &ops)
1066+
: ops(ops) {
10751067
}
10761068
};
10771069

10781070
} // namespace
10791071

10801072
Expr remove_likelies(const Expr &e) {
1081-
return RemoveLikelies().mutate(e);
1073+
return RemoveIntrinsics({Call::likely, Call::likely_if_innermost}).mutate(e);
10821074
}
10831075

10841076
Stmt remove_likelies(const Stmt &s) {
1085-
return RemoveLikelies().mutate(s);
1077+
return RemoveIntrinsics({Call::likely, Call::likely_if_innermost}).mutate(s);
10861078
}
10871079

10881080
Expr remove_promises(const Expr &e) {
1089-
return RemovePromises().mutate(e);
1081+
return RemoveIntrinsics({Call::promise_clamped, Call::unsafe_promise_clamped}).mutate(e);
10901082
}
10911083

10921084
Stmt remove_promises(const Stmt &s) {
1093-
return RemovePromises().mutate(s);
1085+
return RemoveIntrinsics({Call::promise_clamped, Call::unsafe_promise_clamped}).mutate(s);
10941086
}
10951087

10961088
Expr unwrap_tags(const Expr &e) {

src/Var.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ class Var {
2525
Expr e;
2626

2727
public:
28-
/** Construct a Var with the given name */
28+
/** Construct a Var with the given name. Unlike Funcs, this will be treated
29+
* as the same Var as another other Var with the same name, including
30+
* implicit Vars. */
2931
Var(const std::string &n);
3032

3133
/** Construct a Var with an automatically-generated unique name. */
@@ -120,9 +122,6 @@ class Var {
120122
static Var implicit(int n);
121123

122124
/** Return whether a variable name is of the form for an implicit argument.
123-
* TODO: This is almost guaranteed to incorrectly fire on user
124-
* declared variables at some point. We should likely prevent
125-
* user Var declarations from making names of this form.
126125
*/
127126
//{
128127
static bool is_implicit(const std::string &name);

0 commit comments

Comments
 (0)