Add ast::InternalDecoration

An tint-internal decoration used to add metadata between a sanitizer transform and a backend.

Will be used for declaring backend-specific intrinsic calls.

Change-Id: Ia05ba7dada0148de2d490605ba4d15c593075356
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46868
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton
2021-04-07 08:09:21 +00:00
committed by Commit Bot service account
parent 86c2cbfb7e
commit b502fdf82b
9 changed files with 138 additions and 11 deletions

View File

@@ -40,7 +40,6 @@ Function::Function(const Source& source,
for (auto* param : params_) {
TINT_ASSERT(param);
}
TINT_ASSERT(body_);
TINT_ASSERT(symbol_.IsValid());
TINT_ASSERT(return_type_);
}

View File

@@ -63,6 +63,18 @@ class Function : public Castable<Function, Node> {
/// @returns the decorations attached to this function
const DecorationList& decorations() const { return decorations_; }
/// @returns the decoration with the type `T` or nullptr if this function does
/// not contain a decoration with the given type
template <typename T>
const T* find_decoration() const {
for (auto* deco : decorations()) {
if (auto* d = deco->As<T>()) {
return d;
}
}
return nullptr;
}
/// @returns the workgroup size {x, y, z} for the function. {1, 1, 1} will be
/// return if no workgroup size was set.
std::tuple<uint32_t, uint32_t, uint32_t> workgroup_size() const;

View File

@@ -0,0 +1,34 @@
// Copyright 2021 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/ast/internal_decoration.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::InternalDecoration);
namespace tint {
namespace ast {
InternalDecoration::InternalDecoration() : Base(Source{}) {}
InternalDecoration::~InternalDecoration() = default;
void InternalDecoration::to_str(const semantic::Info&,
std::ostream& out,
size_t indent) const {
make_indent(out, indent);
out << "tint_internal(" << Name() << ")" << std::endl;
}
} // namespace ast
} // namespace tint

View File

@@ -0,0 +1,53 @@
// Copyright 2021 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_AST_INTERNAL_DECORATION_H_
#define SRC_AST_INTERNAL_DECORATION_H_
#include <string>
#include "src/ast/decoration.h"
namespace tint {
namespace ast {
/// A decoration used to indicate that a function is tint-internal.
/// These decorations are not produced by generators, but instead are usually
/// created by transforms for consumption by a particular backend.
/// Functions annotated with this decoration will have relaxed validation.
class InternalDecoration : public Castable<InternalDecoration, Decoration> {
public:
/// Constructor
InternalDecoration();
/// Destructor
~InternalDecoration() override;
/// @return a short description of the internal decoration which will be
/// displayed in WGSL as `[[internal(<name>)]]` (but is not parsable).
virtual std::string Name() const = 0;
/// Writes a representation of the node to the output stream
/// @param sem the semantic info for the program
/// @param out the stream to write to
/// @param indent number of spaces to indent the node when writing
void to_str(const semantic::Info& sem,
std::ostream& out,
size_t indent) const override;
};
} // namespace ast
} // namespace tint
#endif // SRC_AST_INTERNAL_DECORATION_H_