Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit 3bbf8d8

Browse files
committed
Sema: respect CompilerOptions
Semantic analyzer may output warnings. Take an instance of CompilerOptions when constructing a Sema and pass use it to decide how to treat warnings.
1 parent d4a569e commit 3bbf8d8

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

tc/core/tc2halide.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,8 @@ HalideComponents translate(
915915
const tc::CompilerOptions& compilerOptions = tc::CompilerOptions()) {
916916
LOG_IF(INFO, tc::FLAGS_debug_halide) << treeRef;
917917
return translateDef(
918-
lang::Def(lang::Sema().checkFunction(treeRef)), compilerOptions);
918+
lang::Def(lang::Sema(compilerOptions).checkFunction(treeRef)),
919+
compilerOptions);
919920
}
920921

921922
// NOTE: there is no guarantee here that the tc string has only one def. It

tc/lang/sema.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "tc/lang/error_report.h"
2222
#include "tc/lang/tree.h"
2323
#include "tc/lang/tree_views.h"
24+
#include "tc/utils/compiler_options.h"
2425

2526
namespace lang {
2627

@@ -170,6 +171,10 @@ static inline TreeRef match_types(TreeRef a, TreeRef b) {
170171
/// variable objects.
171172
/// - checks that input variables are readonly.
172173
struct Sema {
174+
explicit Sema(
175+
const tc::CompilerOptions& compilerOptions = tc::CompilerOptions())
176+
: compilerOptions(compilerOptions) {}
177+
173178
TreeRef typeOfExpr(TreeRef ref) {
174179
if (expr_to_type.count(ref) == 0) {
175180
throw ErrorReport(ref)
@@ -556,7 +561,7 @@ struct Sema {
556561
<< " is not pre-initialized before calling the TC function,"
557562
<< " consider using the !-suffixed reduction operator " << tk
558563
<< "! instead of " << tk;
559-
warn(err);
564+
warn(err, compilerOptions);
560565
}
561566

562567
auto type = TensorType::create(
@@ -709,5 +714,8 @@ struct Sema {
709714

710715
std::unordered_set<std::string> inputParameters;
711716
std::unordered_set<std::string> nonTemporaries;
717+
718+
// TC compilation flow options.
719+
tc::CompilerOptions compilerOptions;
712720
};
713721
} // namespace lang

0 commit comments

Comments
 (0)