mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 03:02:36 +01:00
538b137e0b
This to protect against non-sensical instruction sequences being assembled, which would either cause asserts/crashes further down, or a Wasm module being output that doesn't validate. Unlike a validator, this type checker is able to give type-errors as part of the parsing process, which makes the assembler much friendlier to be used by humans writing manual input. Because the MC system is single pass (instructions aren't even stored in MC format, they are directly output) the type checker has to be single pass as well, which means that from now on .globaltype and .functype decls must come before their use. An extra pass is added to Codegen to collect information for this purpose, since AsmPrinter is normally single pass / streaming as well, and would otherwise generate this information on the fly. A `-no-type-check` flag was added to llvm-mc (and any other tools that take asm input) that surpresses type errors, as a quick escape hatch for tests that were not intended to be type correct. This is a first version of the type checker that ignores control flow, i.e. it checks that types are correct along the linear path, but not the branch path. This will still catch most errors. Branch checking could be added in the future. Differential Revision: https://reviews.llvm.org/D104945
87 lines
2.8 KiB
C++
87 lines
2.8 KiB
C++
//===-- WebAssemblyMCLowerPrePass.cpp - Prepare for MC lower --------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// \file
|
|
/// Some information in MC lowering / asm printing gets generated as
|
|
/// instructions get emitted, but may be necessary at the start, such as for
|
|
/// .globaltype declarations. This pass collects this information.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
|
|
#include "Utils/WebAssemblyUtilities.h"
|
|
#include "WebAssembly.h"
|
|
#include "WebAssemblyMachineFunctionInfo.h"
|
|
#include "WebAssemblySubtarget.h"
|
|
#include "llvm/ADT/SCCIterator.h"
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
#include "llvm/CodeGen/MachineLoopInfo.h"
|
|
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
|
#include "llvm/CodeGen/Passes.h"
|
|
#include "llvm/Support/Debug.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
using namespace llvm;
|
|
|
|
#define DEBUG_TYPE "wasm-mclower-prepass"
|
|
|
|
namespace {
|
|
class WebAssemblyMCLowerPrePass final : public MachineFunctionPass {
|
|
StringRef getPassName() const override {
|
|
return "WebAssembly MC Lower Pre Pass";
|
|
}
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
AU.setPreservesCFG();
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
}
|
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
|
|
|
public:
|
|
static char ID; // Pass identification, replacement for typeid
|
|
WebAssemblyMCLowerPrePass() : MachineFunctionPass(ID) {}
|
|
};
|
|
} // end anonymous namespace
|
|
|
|
char WebAssemblyMCLowerPrePass::ID = 0;
|
|
INITIALIZE_PASS(
|
|
WebAssemblyMCLowerPrePass, DEBUG_TYPE,
|
|
"Collects information ahead of time for MC lowering",
|
|
false, false)
|
|
|
|
FunctionPass *llvm::createWebAssemblyMCLowerPrePass() {
|
|
return new WebAssemblyMCLowerPrePass();
|
|
}
|
|
|
|
bool WebAssemblyMCLowerPrePass::runOnMachineFunction(MachineFunction &MF) {
|
|
LLVM_DEBUG(dbgs() << "********** MC Lower Pre Pass **********\n"
|
|
"********** Function: "
|
|
<< MF.getName() << '\n');
|
|
|
|
MachineModuleInfo &MMI = MF.getMMI();
|
|
MachineModuleInfoWasm &MMIW = MMI.getObjFileInfo<MachineModuleInfoWasm>();
|
|
|
|
for (MachineBasicBlock &MBB : MF) {
|
|
for (auto &MI : MBB) {
|
|
// FIXME: what should all be filtered out beyond these?
|
|
if (MI.isDebugInstr() || MI.isInlineAsm())
|
|
continue;
|
|
for (MachineOperand &MO : MI.uses()) {
|
|
if (MO.isSymbol()) {
|
|
MMIW.MachineSymbolsUsed.insert(MO.getSymbolName());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|