mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 20:23:11 +01:00
f5d3346387
For IR generated by a compiler, this is really simple: you just take the datalayout from the beginning of the file, and apply it to all the IR later in the file. For optimization testcases that don't care about the datalayout, this is also really simple: we just use the default datalayout. The complexity here comes from the fact that some LLVM tools allow overriding the datalayout: some tools have an explicit flag for this, some tools will infer a datalayout based on the code generation target. Supporting this properly required plumbing through a bunch of new machinery: we want to allow overriding the datalayout after the datalayout is parsed from the file, but before we use any information from it. Therefore, IR/bitcode parsing now has a callback to allow tools to compute the datalayout at the appropriate time. Not sure if I covered all the LLVM tools that want to use the callback. (clang? lli? Misc IR manipulation tools like llvm-link?). But this is at least enough for all the LLVM regression tests, and IR without a datalayout is not something frontends should generate. This change had some sort of weird effects for certain CodeGen regression tests: if the datalayout is overridden with a datalayout with a different program or stack address space, we now parse IR based on the overridden datalayout, instead of the one written in the file (or the default one, if none is specified). This broke a few AVR tests, and one AMDGPU test. Outside the CodeGen tests I mentioned, the test changes are all just fixing CHECK lines and moving around datalayout lines in weird places. Differential Revision: https://reviews.llvm.org/D78403
89 lines
3.2 KiB
C++
89 lines
3.2 KiB
C++
//===- MIRParser.h - MIR serialization format parser ------------*- C++ -*-===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This MIR serialization library is currently a work in progress. It can't
|
|
// serialize machine functions at this time.
|
|
//
|
|
// This file declares the functions that parse the MIR serialization format
|
|
// files.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_CODEGEN_MIRPARSER_MIRPARSER_H
|
|
#define LLVM_CODEGEN_MIRPARSER_MIRPARSER_H
|
|
|
|
#include "llvm/IR/Module.h"
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
#include <memory>
|
|
|
|
namespace llvm {
|
|
|
|
class Function;
|
|
class MIRParserImpl;
|
|
class MachineModuleInfo;
|
|
class SMDiagnostic;
|
|
class StringRef;
|
|
|
|
typedef llvm::function_ref<Optional<std::string>(StringRef)>
|
|
DataLayoutCallbackTy;
|
|
|
|
/// This class initializes machine functions by applying the state loaded from
|
|
/// a MIR file.
|
|
class MIRParser {
|
|
std::unique_ptr<MIRParserImpl> Impl;
|
|
|
|
public:
|
|
MIRParser(std::unique_ptr<MIRParserImpl> Impl);
|
|
MIRParser(const MIRParser &) = delete;
|
|
~MIRParser();
|
|
|
|
/// Parses the optional LLVM IR module in the MIR file.
|
|
///
|
|
/// A new, empty module is created if the LLVM IR isn't present.
|
|
/// \returns nullptr if a parsing error occurred.
|
|
std::unique_ptr<Module> parseIRModule(
|
|
DataLayoutCallbackTy DataLayoutCallback = [](StringRef) { return None; });
|
|
|
|
/// Parses MachineFunctions in the MIR file and add them to the given
|
|
/// MachineModuleInfo \p MMI.
|
|
///
|
|
/// \returns true if an error occurred.
|
|
bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI);
|
|
};
|
|
|
|
/// This function is the main interface to the MIR serialization format parser.
|
|
///
|
|
/// It reads in a MIR file and returns a MIR parser that can parse the embedded
|
|
/// LLVM IR module and initialize the machine functions by parsing the machine
|
|
/// function's state.
|
|
///
|
|
/// \param Filename - The name of the file to parse.
|
|
/// \param Error - Error result info.
|
|
/// \param Context - Context which will be used for the parsed LLVM IR module.
|
|
/// \param ProcessIRFunction - function to run on every IR function or stub
|
|
/// loaded from the MIR file.
|
|
std::unique_ptr<MIRParser> createMIRParserFromFile(
|
|
StringRef Filename, SMDiagnostic &Error, LLVMContext &Context,
|
|
std::function<void(Function &)> ProcessIRFunction = nullptr);
|
|
|
|
/// This function is another interface to the MIR serialization format parser.
|
|
///
|
|
/// It returns a MIR parser that works with the given memory buffer and that can
|
|
/// parse the embedded LLVM IR module and initialize the machine functions by
|
|
/// parsing the machine function's state.
|
|
///
|
|
/// \param Contents - The MemoryBuffer containing the machine level IR.
|
|
/// \param Context - Context which will be used for the parsed LLVM IR module.
|
|
std::unique_ptr<MIRParser>
|
|
createMIRParser(std::unique_ptr<MemoryBuffer> Contents, LLVMContext &Context,
|
|
std::function<void(Function &)> ProcessIRFunction = nullptr);
|
|
|
|
} // end namespace llvm
|
|
|
|
#endif // LLVM_CODEGEN_MIRPARSER_MIRPARSER_H
|