mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2026-01-31 01:35:20 +01:00
A random set of attributes are implemented by llc/opt forcing the string attributes on the IR functions before processing anything. This would not happen for MIR functions, which have not yet been created at this point. Use a callback in the MIR parser, purely to avoid dealing with the ugliness that the command line flags are in a .inc file, and would require allowing access to these flags from multiple places (either from the MIR parser directly, or a new utility pass to implement these flags). It would probably be better to cleanup the flag handling into a separate library. This is in preparation for treating more command line flags with a corresponding function attribute in a more uniform way. The fast math flags in particular have a messy system where the command line flag sets the behavior from a function attribute if present, and otherwise the command line flag. This means if any other pass tries to inspect the function attributes directly, it will be inconsistent with the intended behavior. This is also inconsistent with the current behavior of -mcpu and -mattr, which overwrites any pre-existing function attributes. I would like to move this to consistenly have the command line flags not overwrite any pre-existing attributes, and to always ensure the command line flags are consistent with the function attributes.
85 lines
3.0 KiB
C++
85 lines
3.0 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;
|
|
|
|
/// 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();
|
|
|
|
/// 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
|