|
| 1 | +/* |
| 2 | + * Copyright 2026 WebAssembly Community Group participants |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +// |
| 18 | +// Removes toolchain-specific annotations from the IR. Typically this should be |
| 19 | +// done after toolchain optimizations no longer need the annotations, and before |
| 20 | +// shipping the final wasm (VMs do not need these toolchain annotations). |
| 21 | +// |
| 22 | + |
| 23 | +#include "pass.h" |
| 24 | +#include "wasm-binary.h" |
| 25 | +#include "wasm.h" |
| 26 | + |
| 27 | +namespace wasm { |
| 28 | + |
| 29 | +struct StripToolchainAnnotations |
| 30 | + : public WalkerPass<PostWalker<StripToolchainAnnotations>> { |
| 31 | + bool isFunctionParallel() override { return true; } |
| 32 | + |
| 33 | + bool requiresNonNullableLocalFixups() override { return false; } |
| 34 | + |
| 35 | + std::unique_ptr<Pass> create() override { |
| 36 | + return std::make_unique<StripToolchainAnnotations>(); |
| 37 | + } |
| 38 | + |
| 39 | + void doWalkFunction(Function* func) { |
| 40 | + auto& annotations = func->codeAnnotations; |
| 41 | + auto iter = annotations.begin(); |
| 42 | + while (iter != annotations.end()) { |
| 43 | + // Remove the toolchain-specific annotations. |
| 44 | + auto& annotation = iter->second; |
| 45 | + annotation.removableIfUnused = false; |
| 46 | + |
| 47 | + // If nothing remains, remove the entire annotation. |
| 48 | + if (annotation == CodeAnnotation()) { |
| 49 | + iter = annotations.erase(iter); |
| 50 | + } else { |
| 51 | + ++iter; |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | +}; |
| 56 | + |
| 57 | +Pass* createStripToolchainAnnotationsPass() { |
| 58 | + return new StripToolchainAnnotations(); |
| 59 | +} |
| 60 | + |
| 61 | +} // namespace wasm |
0 commit comments