Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +2 -0
- deps/exla/cache/xla_extension/include/llvm/Bitcode/BitcodeAnalyzer.h +109 -0
- deps/exla/cache/xla_extension/include/llvm/Bitcode/BitcodeCommon.h +34 -0
- deps/exla/cache/xla_extension/include/llvm/Bitcode/BitcodeConvenience.h +487 -0
- deps/exla/cache/xla_extension/include/llvm/Bitcode/BitcodeReader.h +327 -0
- deps/exla/cache/xla_extension/include/llvm/Bitcode/BitcodeWriter.h +177 -0
- deps/exla/cache/xla_extension/include/llvm/Bitcode/BitcodeWriterPass.h +73 -0
- deps/exla/cache/xla_extension/include/llvm/Bitcode/LLVMBitCodes.h +822 -0
- deps/exla/cache/xla_extension/include/llvm/Support/AdvisoryLock.h +58 -0
- deps/exla/cache/xla_extension/include/llvm/Support/FileSystem/UniqueID.h +79 -0
- deps/exla/cache/xla_extension/include/llvm/Support/MSVCErrorWorkarounds.h +80 -0
- deps/exla/cache/xla_extension/include/llvm/Support/Solaris/sys/regset.h +38 -0
- deps/exla/cache/xla_extension/include/llvm/Support/SystemZ/zOSSupport.h +47 -0
- deps/exla/cache/xla_extension/include/llvm/Support/Windows/WindowsSupport.h +252 -0
- deps/exla/cache/xla_extension/include/llvm/_virtual_includes/X86CommonTableGen/X86GenDAGISel.inc +3 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Bitcode/Reader/MetadataLoader.h +98 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Bitcode/Reader/ValueList.h +94 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Bitcode/Writer/ValueEnumerator.h +305 -0
- deps/exla/cache/xla_extension/include/llvm/lib/MC/MCDisassembler/Disassembler.h +124 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Passes/PassRegistry.def +738 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Remarks/BitstreamRemarkParser.h +86 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Remarks/YAMLRemarkParser.h +117 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Support/BLAKE3/blake3_impl.h +305 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Support/BLAKE3/llvm_blake3_prefix.h +41 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Support/DebugOptions.h +34 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Support/Unix/COM.inc +26 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Support/Unix/DynamicLibrary.inc +136 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Support/Unix/Memory.inc +255 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Support/Unix/Path.inc +1532 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Support/Unix/Process.inc +421 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Support/Unix/Program.inc +588 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Support/Unix/Signals.inc +913 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Support/Unix/Threading.inc +458 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Support/Unix/Unix.h +103 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Support/Unix/Watchdog.inc +33 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Support/regengine.inc +1099 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Support/regex2.h +165 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Support/regex_impl.h +108 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Support/regutils.h +58 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/ImmutableGraph.h +445 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86.h +228 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86AsmPrinter.h +200 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86CallingConv.h +33 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86FrameLowering.h +344 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86GenAsmMatcher.inc +0 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86GenCallingConv.inc +0 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86GenDAGISel.inc +3 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86GenDisassemblerTables.inc +0 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86GenExegesis.inc +547 -0
- deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86GenGlobalISel.inc +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
deps/exla/cache/xla_extension/include/llvm/_virtual_includes/X86CommonTableGen/X86GenDAGISel.inc filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86GenDAGISel.inc filter=lfs diff=lfs merge=lfs -text
|
deps/exla/cache/xla_extension/include/llvm/Bitcode/BitcodeAnalyzer.h
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- llvm/Bitcode/BitcodeAnalyzer.h - Bitcode analyzer --------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This header defines interfaces to analyze LLVM bitcode files/streams.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_BITCODE_BITCODEANALYZER_H
|
| 14 |
+
#define LLVM_BITCODE_BITCODEANALYZER_H
|
| 15 |
+
|
| 16 |
+
#include "llvm/ADT/ArrayRef.h"
|
| 17 |
+
#include "llvm/ADT/StringRef.h"
|
| 18 |
+
#include "llvm/Bitstream/BitstreamReader.h"
|
| 19 |
+
#include "llvm/Support/Compiler.h"
|
| 20 |
+
#include "llvm/Support/Error.h"
|
| 21 |
+
#include <map>
|
| 22 |
+
#include <optional>
|
| 23 |
+
#include <vector>
|
| 24 |
+
|
| 25 |
+
namespace llvm {
|
| 26 |
+
|
| 27 |
+
class raw_ostream;
|
| 28 |
+
|
| 29 |
+
/// CurStreamTypeType - A type for CurStreamType
|
| 30 |
+
enum CurStreamTypeType {
|
| 31 |
+
UnknownBitstream,
|
| 32 |
+
LLVMIRBitstream,
|
| 33 |
+
ClangSerializedASTBitstream,
|
| 34 |
+
ClangSerializedDiagnosticsBitstream,
|
| 35 |
+
LLVMBitstreamRemarks
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
struct BCDumpOptions {
|
| 39 |
+
/// The stream.
|
| 40 |
+
raw_ostream &OS;
|
| 41 |
+
/// Print per-code histogram.
|
| 42 |
+
bool Histogram = false;
|
| 43 |
+
/// Don't emit numeric info in dump if symbolic info is available.
|
| 44 |
+
bool Symbolic = false;
|
| 45 |
+
/// Print binary blobs using hex escapes.
|
| 46 |
+
bool ShowBinaryBlobs = false;
|
| 47 |
+
/// Print BLOCKINFO block details.
|
| 48 |
+
bool DumpBlockinfo = false;
|
| 49 |
+
|
| 50 |
+
BCDumpOptions(raw_ostream &OS) : OS(OS) {}
|
| 51 |
+
};
|
| 52 |
+
|
| 53 |
+
class BitcodeAnalyzer {
|
| 54 |
+
BitstreamCursor Stream;
|
| 55 |
+
BitstreamBlockInfo BlockInfo;
|
| 56 |
+
CurStreamTypeType CurStreamType;
|
| 57 |
+
std::optional<BitstreamCursor> BlockInfoStream;
|
| 58 |
+
unsigned NumTopBlocks = 0;
|
| 59 |
+
|
| 60 |
+
struct PerRecordStats {
|
| 61 |
+
unsigned NumInstances = 0;
|
| 62 |
+
unsigned NumAbbrev = 0;
|
| 63 |
+
uint64_t TotalBits = 0;
|
| 64 |
+
PerRecordStats() = default;
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
struct PerBlockIDStats {
|
| 68 |
+
/// NumInstances - This the number of times this block ID has been seen.
|
| 69 |
+
unsigned NumInstances = 0;
|
| 70 |
+
/// NumBits - The total size in bits of all of these blocks.
|
| 71 |
+
uint64_t NumBits = 0;
|
| 72 |
+
/// NumSubBlocks - The total number of blocks these blocks contain.
|
| 73 |
+
unsigned NumSubBlocks = 0;
|
| 74 |
+
/// NumAbbrevs - The total number of abbreviations.
|
| 75 |
+
unsigned NumAbbrevs = 0;
|
| 76 |
+
/// NumRecords - The total number of records these blocks contain, and the
|
| 77 |
+
/// number that are abbreviated.
|
| 78 |
+
unsigned NumRecords = 0, NumAbbreviatedRecords = 0;
|
| 79 |
+
/// CodeFreq - Keep track of the number of times we see each code.
|
| 80 |
+
std::vector<PerRecordStats> CodeFreq;
|
| 81 |
+
PerBlockIDStats() = default;
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
std::map<unsigned, PerBlockIDStats> BlockIDStats;
|
| 85 |
+
|
| 86 |
+
public:
|
| 87 |
+
LLVM_ABI
|
| 88 |
+
BitcodeAnalyzer(StringRef Buffer,
|
| 89 |
+
std::optional<StringRef> BlockInfoBuffer = std::nullopt);
|
| 90 |
+
/// Analyze the bitcode file.
|
| 91 |
+
LLVM_ABI Error analyze(std::optional<BCDumpOptions> O = std::nullopt,
|
| 92 |
+
std::optional<StringRef> CheckHash = std::nullopt);
|
| 93 |
+
/// Print stats about the bitcode file.
|
| 94 |
+
LLVM_ABI void printStats(BCDumpOptions O,
|
| 95 |
+
std::optional<StringRef> Filename = std::nullopt);
|
| 96 |
+
|
| 97 |
+
private:
|
| 98 |
+
/// Read a block, updating statistics, etc.
|
| 99 |
+
Error parseBlock(unsigned BlockID, unsigned IndentLevel,
|
| 100 |
+
std::optional<BCDumpOptions> O = std::nullopt,
|
| 101 |
+
std::optional<StringRef> CheckHash = std::nullopt);
|
| 102 |
+
|
| 103 |
+
Error decodeMetadataStringsBlob(StringRef Indent, ArrayRef<uint64_t> Record,
|
| 104 |
+
StringRef Blob, raw_ostream &OS);
|
| 105 |
+
};
|
| 106 |
+
|
| 107 |
+
} // end namespace llvm
|
| 108 |
+
|
| 109 |
+
#endif // LLVM_BITCODE_BITCODEANALYZER_H
|
deps/exla/cache/xla_extension/include/llvm/Bitcode/BitcodeCommon.h
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- BitcodeCommon.h - Common code for encode/decode --------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This header defines common code to be used by BitcodeWriter and
|
| 10 |
+
// BitcodeReader.
|
| 11 |
+
//
|
| 12 |
+
//===----------------------------------------------------------------------===//
|
| 13 |
+
|
| 14 |
+
#ifndef LLVM_BITCODE_BITCODECOMMON_H
|
| 15 |
+
#define LLVM_BITCODE_BITCODECOMMON_H
|
| 16 |
+
|
| 17 |
+
#include "llvm/ADT/Bitfields.h"
|
| 18 |
+
|
| 19 |
+
namespace llvm {
|
| 20 |
+
|
| 21 |
+
struct AllocaPackedValues {
|
| 22 |
+
// We increased the number of bits needed to represent alignment to be more
|
| 23 |
+
// than 5, but to preserve backward compatibility we store the upper bits
|
| 24 |
+
// separately.
|
| 25 |
+
using AlignLower = Bitfield::Element<unsigned, 0, 5>;
|
| 26 |
+
using UsedWithInAlloca = Bitfield::Element<bool, AlignLower::NextBit, 1>;
|
| 27 |
+
using ExplicitType = Bitfield::Element<bool, UsedWithInAlloca::NextBit, 1>;
|
| 28 |
+
using SwiftError = Bitfield::Element<bool, ExplicitType::NextBit, 1>;
|
| 29 |
+
using AlignUpper = Bitfield::Element<unsigned, SwiftError::NextBit, 3>;
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
} // namespace llvm
|
| 33 |
+
|
| 34 |
+
#endif // LLVM_BITCODE_BITCODECOMMON_H
|
deps/exla/cache/xla_extension/include/llvm/Bitcode/BitcodeConvenience.h
ADDED
|
@@ -0,0 +1,487 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- llvm/Bitcode/BitcodeConvenience.h - Convenience Wrappers -*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
///
|
| 9 |
+
/// \file Convenience wrappers for the LLVM bitcode format and bitstream APIs.
|
| 10 |
+
///
|
| 11 |
+
/// This allows you to use a sort of DSL to declare and use bitcode
|
| 12 |
+
/// abbreviations and records. Example:
|
| 13 |
+
///
|
| 14 |
+
/// \code
|
| 15 |
+
/// using Metadata = BCRecordLayout<
|
| 16 |
+
/// METADATA_ID, // ID
|
| 17 |
+
/// BCFixed<16>, // Module format major version
|
| 18 |
+
/// BCFixed<16>, // Module format minor version
|
| 19 |
+
/// BCBlob // misc. version information
|
| 20 |
+
/// >;
|
| 21 |
+
/// Metadata metadata(Out);
|
| 22 |
+
/// metadata.emit(ScratchRecord, VERSION_MAJOR, VERSION_MINOR, Data);
|
| 23 |
+
/// \endcode
|
| 24 |
+
///
|
| 25 |
+
/// For details on the bitcode format, see
|
| 26 |
+
/// http://llvm.org/docs/BitCodeFormat.html
|
| 27 |
+
///
|
| 28 |
+
//===----------------------------------------------------------------------===//
|
| 29 |
+
|
| 30 |
+
#ifndef LLVM_BITCODE_BITCODECONVENIENCE_H
|
| 31 |
+
#define LLVM_BITCODE_BITCODECONVENIENCE_H
|
| 32 |
+
|
| 33 |
+
#include "llvm/Bitstream/BitCodes.h"
|
| 34 |
+
#include "llvm/Bitstream/BitstreamWriter.h"
|
| 35 |
+
#include <cstdint>
|
| 36 |
+
#include <optional>
|
| 37 |
+
|
| 38 |
+
namespace llvm {
|
| 39 |
+
namespace detail {
|
| 40 |
+
/// Convenience base for all kinds of bitcode abbreviation fields.
|
| 41 |
+
///
|
| 42 |
+
/// This just defines common properties queried by the metaprogramming.
|
| 43 |
+
template <bool Compound = false> class BCField {
|
| 44 |
+
public:
|
| 45 |
+
static const bool IsCompound = Compound;
|
| 46 |
+
|
| 47 |
+
/// Asserts that the given data is a valid value for this field.
|
| 48 |
+
template <typename T> static void assertValid(const T &data) {}
|
| 49 |
+
|
| 50 |
+
/// Converts a raw numeric representation of this value to its preferred
|
| 51 |
+
/// type.
|
| 52 |
+
template <typename T> static T convert(T rawValue) { return rawValue; }
|
| 53 |
+
};
|
| 54 |
+
} // namespace detail
|
| 55 |
+
|
| 56 |
+
/// Represents a literal operand in a bitcode record.
|
| 57 |
+
///
|
| 58 |
+
/// The value of a literal operand is the same for all instances of the record,
|
| 59 |
+
/// so it is only emitted in the abbreviation definition.
|
| 60 |
+
///
|
| 61 |
+
/// Note that because this uses a compile-time template, you cannot have a
|
| 62 |
+
/// literal operand that is fixed at run-time without dropping down to the
|
| 63 |
+
/// raw LLVM APIs.
|
| 64 |
+
template <uint64_t Value> class BCLiteral : public detail::BCField<> {
|
| 65 |
+
public:
|
| 66 |
+
static void emitOp(llvm::BitCodeAbbrev &abbrev) {
|
| 67 |
+
abbrev.Add(llvm::BitCodeAbbrevOp(Value));
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
template <typename T> static void assertValid(const T &data) {
|
| 71 |
+
assert(data == Value && "data value does not match declared literal value");
|
| 72 |
+
}
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
/// Represents a fixed-width value in a bitcode record.
|
| 76 |
+
///
|
| 77 |
+
/// Note that the LLVM bitcode format only supports unsigned values.
|
| 78 |
+
template <unsigned Width> class BCFixed : public detail::BCField<> {
|
| 79 |
+
public:
|
| 80 |
+
static_assert(Width <= 64, "fixed-width field is too large");
|
| 81 |
+
|
| 82 |
+
static void emitOp(llvm::BitCodeAbbrev &abbrev) {
|
| 83 |
+
abbrev.Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, Width));
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
static void assertValid(const bool &data) {
|
| 87 |
+
assert(llvm::isUInt<Width>(data) &&
|
| 88 |
+
"data value does not fit in the given bit width");
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
template <typename T> static void assertValid(const T &data) {
|
| 92 |
+
assert(data >= 0 && "cannot encode signed integers");
|
| 93 |
+
assert(llvm::isUInt<Width>(data) &&
|
| 94 |
+
"data value does not fit in the given bit width");
|
| 95 |
+
}
|
| 96 |
+
};
|
| 97 |
+
|
| 98 |
+
/// Represents a variable-width value in a bitcode record.
|
| 99 |
+
///
|
| 100 |
+
/// The \p Width parameter should include the continuation bit.
|
| 101 |
+
///
|
| 102 |
+
/// Note that the LLVM bitcode format only supports unsigned values.
|
| 103 |
+
template <unsigned Width> class BCVBR : public detail::BCField<> {
|
| 104 |
+
static_assert(Width >= 2, "width does not have room for continuation bit");
|
| 105 |
+
|
| 106 |
+
public:
|
| 107 |
+
static void emitOp(llvm::BitCodeAbbrev &abbrev) {
|
| 108 |
+
abbrev.Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, Width));
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
template <typename T> static void assertValid(const T &data) {
|
| 112 |
+
assert(data >= 0 && "cannot encode signed integers");
|
| 113 |
+
}
|
| 114 |
+
};
|
| 115 |
+
|
| 116 |
+
/// Represents a character encoded in LLVM's Char6 encoding.
|
| 117 |
+
///
|
| 118 |
+
/// This format is suitable for encoding decimal numbers (without signs or
|
| 119 |
+
/// exponents) and C identifiers (without dollar signs), but not much else.
|
| 120 |
+
///
|
| 121 |
+
/// \sa http://llvm.org/docs/BitCodeFormat.html#char6-encoded-value
|
| 122 |
+
class BCChar6 : public detail::BCField<> {
|
| 123 |
+
public:
|
| 124 |
+
static void emitOp(llvm::BitCodeAbbrev &abbrev) {
|
| 125 |
+
abbrev.Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Char6));
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
template <typename T> static void assertValid(const T &data) {
|
| 129 |
+
assert(llvm::BitCodeAbbrevOp::isChar6(data) && "invalid Char6 data");
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
template <typename T> char convert(T rawValue) {
|
| 133 |
+
return static_cast<char>(rawValue);
|
| 134 |
+
}
|
| 135 |
+
};
|
| 136 |
+
|
| 137 |
+
/// Represents an untyped blob of bytes.
|
| 138 |
+
///
|
| 139 |
+
/// If present, this must be the last field in a record.
|
| 140 |
+
class BCBlob : public detail::BCField<true> {
|
| 141 |
+
public:
|
| 142 |
+
static void emitOp(llvm::BitCodeAbbrev &abbrev) {
|
| 143 |
+
abbrev.Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob));
|
| 144 |
+
}
|
| 145 |
+
};
|
| 146 |
+
|
| 147 |
+
/// Represents an array of some other type.
|
| 148 |
+
///
|
| 149 |
+
/// If present, this must be the last field in a record.
|
| 150 |
+
template <typename ElementTy> class BCArray : public detail::BCField<true> {
|
| 151 |
+
static_assert(!ElementTy::IsCompound, "arrays can only contain scalar types");
|
| 152 |
+
|
| 153 |
+
public:
|
| 154 |
+
static void emitOp(llvm::BitCodeAbbrev &abbrev) {
|
| 155 |
+
abbrev.Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Array));
|
| 156 |
+
ElementTy::emitOp(abbrev);
|
| 157 |
+
}
|
| 158 |
+
};
|
| 159 |
+
|
| 160 |
+
namespace detail {
|
| 161 |
+
/// Attaches the last field to an abbreviation.
|
| 162 |
+
///
|
| 163 |
+
/// This is the base case for \c emitOps.
|
| 164 |
+
///
|
| 165 |
+
/// \sa BCRecordLayout::emitAbbrev
|
| 166 |
+
template <typename FieldTy> static void emitOps(llvm::BitCodeAbbrev &abbrev) {
|
| 167 |
+
FieldTy::emitOp(abbrev);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
/// Attaches fields to an abbreviation.
|
| 171 |
+
///
|
| 172 |
+
/// This is the recursive case for \c emitOps.
|
| 173 |
+
///
|
| 174 |
+
/// \sa BCRecordLayout::emitAbbrev
|
| 175 |
+
template <typename FieldTy, typename Next, typename... Rest>
|
| 176 |
+
static void emitOps(llvm::BitCodeAbbrev &abbrev) {
|
| 177 |
+
static_assert(!FieldTy::IsCompound,
|
| 178 |
+
"arrays and blobs may not appear in the middle of a record");
|
| 179 |
+
FieldTy::emitOp(abbrev);
|
| 180 |
+
emitOps<Next, Rest...>(abbrev);
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
/// Helper class for dealing with a scalar element in the middle of a record.
|
| 184 |
+
///
|
| 185 |
+
/// \sa BCRecordLayout
|
| 186 |
+
template <typename ElementTy, typename... Fields> class BCRecordCoding {
|
| 187 |
+
public:
|
| 188 |
+
template <typename BufferTy, typename ElementDataTy, typename... DataTy>
|
| 189 |
+
static void emit(llvm::BitstreamWriter &Stream, BufferTy &buffer,
|
| 190 |
+
unsigned code, ElementDataTy element, DataTy &&...data) {
|
| 191 |
+
static_assert(!ElementTy::IsCompound,
|
| 192 |
+
"arrays and blobs may not appear in the middle of a record");
|
| 193 |
+
ElementTy::assertValid(element);
|
| 194 |
+
buffer.push_back(element);
|
| 195 |
+
BCRecordCoding<Fields...>::emit(Stream, buffer, code,
|
| 196 |
+
std::forward<DataTy>(data)...);
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
template <typename T, typename ElementDataTy, typename... DataTy>
|
| 200 |
+
static void read(ArrayRef<T> buffer, ElementDataTy &element,
|
| 201 |
+
DataTy &&...data) {
|
| 202 |
+
assert(!buffer.empty() && "too few elements in buffer");
|
| 203 |
+
element = ElementTy::convert(buffer.front());
|
| 204 |
+
BCRecordCoding<Fields...>::read(buffer.slice(1),
|
| 205 |
+
std::forward<DataTy>(data)...);
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
template <typename T, typename... DataTy>
|
| 209 |
+
static void read(ArrayRef<T> buffer, std::nullopt_t, DataTy &&...data) {
|
| 210 |
+
assert(!buffer.empty() && "too few elements in buffer");
|
| 211 |
+
BCRecordCoding<Fields...>::read(buffer.slice(1),
|
| 212 |
+
std::forward<DataTy>(data)...);
|
| 213 |
+
}
|
| 214 |
+
};
|
| 215 |
+
|
| 216 |
+
/// Helper class for dealing with a scalar element at the end of a record.
|
| 217 |
+
///
|
| 218 |
+
/// This has a separate implementation because up until now we've only been
|
| 219 |
+
/// \em building the record (into a data buffer), and now we need to hand it
|
| 220 |
+
/// off to the BitstreamWriter to be emitted.
|
| 221 |
+
///
|
| 222 |
+
/// \sa BCRecordLayout
|
| 223 |
+
template <typename ElementTy> class BCRecordCoding<ElementTy> {
|
| 224 |
+
public:
|
| 225 |
+
template <typename BufferTy, typename DataTy>
|
| 226 |
+
static void emit(llvm::BitstreamWriter &Stream, BufferTy &buffer,
|
| 227 |
+
unsigned code, const DataTy &data) {
|
| 228 |
+
static_assert(!ElementTy::IsCompound,
|
| 229 |
+
"arrays and blobs need special handling");
|
| 230 |
+
ElementTy::assertValid(data);
|
| 231 |
+
buffer.push_back(data);
|
| 232 |
+
Stream.EmitRecordWithAbbrev(code, buffer);
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
template <typename T, typename DataTy>
|
| 236 |
+
static void read(ArrayRef<T> buffer, DataTy &data) {
|
| 237 |
+
assert(buffer.size() == 1 && "record data does not match layout");
|
| 238 |
+
data = ElementTy::convert(buffer.front());
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
template <typename T> static void read(ArrayRef<T> buffer, std::nullopt_t) {
|
| 242 |
+
assert(buffer.size() == 1 && "record data does not match layout");
|
| 243 |
+
(void)buffer;
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
template <typename T> static void read(ArrayRef<T> buffer) = delete;
|
| 247 |
+
};
|
| 248 |
+
|
| 249 |
+
/// Helper class for dealing with an array at the end of a record.
|
| 250 |
+
///
|
| 251 |
+
/// \sa BCRecordLayout::emitRecord
|
| 252 |
+
template <typename ElementTy> class BCRecordCoding<BCArray<ElementTy>> {
|
| 253 |
+
public:
|
| 254 |
+
template <typename BufferTy>
|
| 255 |
+
static void emit(llvm::BitstreamWriter &Stream, BufferTy &buffer,
|
| 256 |
+
unsigned code, StringRef data) {
|
| 257 |
+
// TODO: validate array data.
|
| 258 |
+
Stream.EmitRecordWithArray(code, buffer, data);
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
template <typename BufferTy, typename ArrayTy>
|
| 262 |
+
static void emit(llvm::BitstreamWriter &Stream, BufferTy &buffer,
|
| 263 |
+
unsigned code, const ArrayTy &array) {
|
| 264 |
+
#ifndef NDEBUG
|
| 265 |
+
for (auto &element : array)
|
| 266 |
+
ElementTy::assertValid(element);
|
| 267 |
+
#endif
|
| 268 |
+
buffer.reserve(buffer.size() + std::distance(array.begin(), array.end()));
|
| 269 |
+
llvm::append_range(buffer, array);
|
| 270 |
+
Stream.EmitRecordWithAbbrev(code, buffer);
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
template <typename BufferTy, typename ElementDataTy, typename... DataTy>
|
| 274 |
+
static void emit(llvm::BitstreamWriter &Stream, BufferTy &buffer,
|
| 275 |
+
unsigned code, ElementDataTy element, DataTy... data) {
|
| 276 |
+
std::array<ElementDataTy, 1 + sizeof...(data)> array{{element, data...}};
|
| 277 |
+
emit(Stream, buffer, code, array);
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
template <typename BufferTy>
|
| 281 |
+
static void emit(llvm::BitstreamWriter &Stream, BufferTy &Buffer,
|
| 282 |
+
unsigned code, std::nullopt_t) {
|
| 283 |
+
Stream.EmitRecordWithAbbrev(code, Buffer);
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
template <typename T>
|
| 287 |
+
static void read(ArrayRef<T> Buffer, ArrayRef<T> &rawData) {
|
| 288 |
+
rawData = Buffer;
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
template <typename T, typename ArrayTy>
|
| 292 |
+
static void read(ArrayRef<T> buffer, ArrayTy &array) {
|
| 293 |
+
array.append(llvm::map_iterator(buffer.begin(), T::convert),
|
| 294 |
+
llvm::map_iterator(buffer.end(), T::convert));
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
template <typename T> static void read(ArrayRef<T> buffer, std::nullopt_t) {
|
| 298 |
+
(void)buffer;
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
template <typename T> static void read(ArrayRef<T> buffer) = delete;
|
| 302 |
+
};
|
| 303 |
+
|
| 304 |
+
/// Helper class for dealing with a blob at the end of a record.
|
| 305 |
+
///
|
| 306 |
+
/// \sa BCRecordLayout
|
| 307 |
+
template <> class BCRecordCoding<BCBlob> {
|
| 308 |
+
public:
|
| 309 |
+
template <typename BufferTy>
|
| 310 |
+
static void emit(llvm::BitstreamWriter &Stream, BufferTy &buffer,
|
| 311 |
+
unsigned code, StringRef data) {
|
| 312 |
+
Stream.EmitRecordWithBlob(code, buffer, data);
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
template <typename T> static void read(ArrayRef<T> buffer) { (void)buffer; }
|
| 316 |
+
|
| 317 |
+
/// Blob data is not stored in the buffer if you are using the correct
|
| 318 |
+
/// accessor; this method should not be used.
|
| 319 |
+
template <typename T, typename DataTy>
|
| 320 |
+
static void read(ArrayRef<T> buffer, DataTy &data) = delete;
|
| 321 |
+
};
|
| 322 |
+
|
| 323 |
+
/// A type trait whose \c type field is the last of its template parameters.
|
| 324 |
+
template <typename Head, typename... Tail> struct last_type {
|
| 325 |
+
using type = typename last_type<Tail...>::type;
|
| 326 |
+
};
|
| 327 |
+
|
| 328 |
+
template <typename Head> struct last_type<Head> { using type = Head; };
|
| 329 |
+
|
| 330 |
+
/// A type trait whose \c value field is \c true if the last type is BCBlob.
|
| 331 |
+
template <typename... Types>
|
| 332 |
+
using has_blob = std::is_same<BCBlob, typename last_type<int, Types...>::type>;
|
| 333 |
+
|
| 334 |
+
/// A type trait whose \c value field is \c true if the given type is a
|
| 335 |
+
/// BCArray (of any element kind).
|
| 336 |
+
template <typename T> struct is_array {
|
| 337 |
+
private:
|
| 338 |
+
template <typename E> static bool check(BCArray<E> *);
|
| 339 |
+
static int check(...);
|
| 340 |
+
|
| 341 |
+
public:
|
| 342 |
+
typedef bool value_type;
|
| 343 |
+
static constexpr bool value = !std::is_same<decltype(check((T *)nullptr)),
|
| 344 |
+
decltype(check(false))>::value;
|
| 345 |
+
};
|
| 346 |
+
|
| 347 |
+
/// A type trait whose \c value field is \c true if the last type is a
|
| 348 |
+
/// BCArray (of any element kind).
|
| 349 |
+
template <typename... Types>
|
| 350 |
+
using has_array = is_array<typename last_type<int, Types...>::type>;
|
| 351 |
+
} // namespace detail
|
| 352 |
+
|
| 353 |
+
/// Represents a single bitcode record type.
|
| 354 |
+
///
|
| 355 |
+
/// This class template is meant to be instantiated and then given a name,
|
| 356 |
+
/// so that from then on that name can be used.
|
| 357 |
+
template <typename IDField, typename... Fields> class BCGenericRecordLayout {
|
| 358 |
+
llvm::BitstreamWriter &Stream;
|
| 359 |
+
|
| 360 |
+
public:
|
| 361 |
+
/// The abbreviation code used for this record in the current block.
|
| 362 |
+
///
|
| 363 |
+
/// Note that this is not the same as the semantic record code, which is the
|
| 364 |
+
/// first field of the record.
|
| 365 |
+
const unsigned AbbrevCode;
|
| 366 |
+
|
| 367 |
+
/// Create a layout and register it with the given bitstream writer.
|
| 368 |
+
explicit BCGenericRecordLayout(llvm::BitstreamWriter &Stream)
|
| 369 |
+
: Stream(Stream), AbbrevCode(emitAbbrev(Stream)) {}
|
| 370 |
+
|
| 371 |
+
/// Emit a record to the bitstream writer, using the given buffer for scratch
|
| 372 |
+
/// space.
|
| 373 |
+
///
|
| 374 |
+
/// Note that even fixed arguments must be specified here.
|
| 375 |
+
template <typename BufferTy, typename... Data>
|
| 376 |
+
void emit(BufferTy &buffer, unsigned id, Data &&...data) const {
|
| 377 |
+
emitRecord(Stream, buffer, AbbrevCode, id, std::forward<Data>(data)...);
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
/// Registers this record's layout with the bitstream reader.
|
| 381 |
+
///
|
| 382 |
+
/// eturns The abbreviation code for the newly-registered record type.
|
| 383 |
+
static unsigned emitAbbrev(llvm::BitstreamWriter &Stream) {
|
| 384 |
+
auto Abbrev = std::make_shared<llvm::BitCodeAbbrev>();
|
| 385 |
+
detail::emitOps<IDField, Fields...>(*Abbrev);
|
| 386 |
+
return Stream.EmitAbbrev(std::move(Abbrev));
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
/// Emit a record identified by \p abbrCode to bitstream reader \p Stream,
|
| 390 |
+
/// using \p buffer for scratch space.
|
| 391 |
+
///
|
| 392 |
+
/// Note that even fixed arguments must be specified here. Blobs are passed
|
| 393 |
+
/// as StringRefs, while arrays can be passed inline, as aggregates, or as
|
| 394 |
+
/// pre-encoded StringRef data. Skipped values and empty arrays should use
|
| 395 |
+
/// the special Nothing value.
|
| 396 |
+
template <typename BufferTy, typename... Data>
|
| 397 |
+
static void emitRecord(llvm::BitstreamWriter &Stream, BufferTy &buffer,
|
| 398 |
+
unsigned abbrCode, unsigned recordID, Data &&...data) {
|
| 399 |
+
static_assert(sizeof...(data) <= sizeof...(Fields) ||
|
| 400 |
+
detail::has_array<Fields...>::value,
|
| 401 |
+
"Too many record elements");
|
| 402 |
+
static_assert(sizeof...(data) >= sizeof...(Fields),
|
| 403 |
+
"Too few record elements");
|
| 404 |
+
buffer.clear();
|
| 405 |
+
detail::BCRecordCoding<IDField, Fields...>::emit(
|
| 406 |
+
Stream, buffer, abbrCode, recordID, std::forward<Data>(data)...);
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
/// Extract record data from \p buffer into the given data fields.
|
| 410 |
+
///
|
| 411 |
+
/// Note that even fixed arguments must be specified here. Pass \c Nothing
|
| 412 |
+
/// if you don't care about a particular parameter. Blob data is not included
|
| 413 |
+
/// in the buffer and should be handled separately by the caller.
|
| 414 |
+
template <typename ElementTy, typename... Data>
|
| 415 |
+
static void readRecord(ArrayRef<ElementTy> buffer, Data &&...data) {
|
| 416 |
+
static_assert(sizeof...(data) <= sizeof...(Fields),
|
| 417 |
+
"Too many record elements");
|
| 418 |
+
static_assert(sizeof...(Fields) <=
|
| 419 |
+
sizeof...(data) + detail::has_blob<Fields...>::value,
|
| 420 |
+
"Too few record elements");
|
| 421 |
+
return detail::BCRecordCoding<Fields...>::read(buffer,
|
| 422 |
+
std::forward<Data>(data)...);
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
/// Extract record data from \p buffer into the given data fields.
|
| 426 |
+
///
|
| 427 |
+
/// Note that even fixed arguments must be specified here. Pass \c Nothing
|
| 428 |
+
/// if you don't care about a particular parameter. Blob data is not included
|
| 429 |
+
/// in the buffer and should be handled separately by the caller.
|
| 430 |
+
template <typename BufferTy, typename... Data>
|
| 431 |
+
static void readRecord(BufferTy &buffer, Data &&...data) {
|
| 432 |
+
return readRecord(llvm::ArrayRef(buffer), std::forward<Data>(data)...);
|
| 433 |
+
}
|
| 434 |
+
};
|
| 435 |
+
|
| 436 |
+
/// A record with a fixed record code.
|
| 437 |
+
template <unsigned RecordCode, typename... Fields>
|
| 438 |
+
class BCRecordLayout
|
| 439 |
+
: public BCGenericRecordLayout<BCLiteral<RecordCode>, Fields...> {
|
| 440 |
+
using Base = BCGenericRecordLayout<BCLiteral<RecordCode>, Fields...>;
|
| 441 |
+
|
| 442 |
+
public:
|
| 443 |
+
enum : unsigned {
|
| 444 |
+
/// The record code associated with this layout.
|
| 445 |
+
Code = RecordCode
|
| 446 |
+
};
|
| 447 |
+
|
| 448 |
+
/// Create a layout and register it with the given bitstream writer.
|
| 449 |
+
explicit BCRecordLayout(llvm::BitstreamWriter &Stream) : Base(Stream) {}
|
| 450 |
+
|
| 451 |
+
/// Emit a record to the bitstream writer, using the given buffer for scratch
|
| 452 |
+
/// space.
|
| 453 |
+
///
|
| 454 |
+
/// Note that even fixed arguments must be specified here.
|
| 455 |
+
template <typename BufferTy, typename... Data>
|
| 456 |
+
void emit(BufferTy &buffer, Data &&...data) const {
|
| 457 |
+
Base::emit(buffer, RecordCode, std::forward<Data>(data)...);
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
/// Emit a record identified by \p abbrCode to bitstream reader \p Stream,
|
| 461 |
+
/// using \p buffer for scratch space.
|
| 462 |
+
///
|
| 463 |
+
/// Note that even fixed arguments must be specified here. Currently, arrays
|
| 464 |
+
/// and blobs can only be passed as StringRefs.
|
| 465 |
+
template <typename BufferTy, typename... Data>
|
| 466 |
+
static void emitRecord(llvm::BitstreamWriter &Stream, BufferTy &buffer,
|
| 467 |
+
unsigned abbrCode, Data &&...data) {
|
| 468 |
+
Base::emitRecord(Stream, buffer, abbrCode, RecordCode,
|
| 469 |
+
std::forward<Data>(data)...);
|
| 470 |
+
}
|
| 471 |
+
};
|
| 472 |
+
|
| 473 |
+
/// RAII object to pair entering and exiting a sub-block.
|
| 474 |
+
class BCBlockRAII {
|
| 475 |
+
llvm::BitstreamWriter &Stream;
|
| 476 |
+
|
| 477 |
+
public:
|
| 478 |
+
BCBlockRAII(llvm::BitstreamWriter &Stream, unsigned block, unsigned abbrev)
|
| 479 |
+
: Stream(Stream) {
|
| 480 |
+
Stream.EnterSubblock(block, abbrev);
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
~BCBlockRAII() { Stream.ExitBlock(); }
|
| 484 |
+
};
|
| 485 |
+
} // namespace llvm
|
| 486 |
+
|
| 487 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/Bitcode/BitcodeReader.h
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- llvm/Bitcode/BitcodeReader.h - Bitcode reader ------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This header defines interfaces to read LLVM bitcode files/streams.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_BITCODE_BITCODEREADER_H
|
| 14 |
+
#define LLVM_BITCODE_BITCODEREADER_H
|
| 15 |
+
|
| 16 |
+
#include "llvm/ADT/ArrayRef.h"
|
| 17 |
+
#include "llvm/ADT/StringRef.h"
|
| 18 |
+
#include "llvm/Bitstream/BitCodeEnums.h"
|
| 19 |
+
#include "llvm/IR/GlobalValue.h"
|
| 20 |
+
#include "llvm/Support/Compiler.h"
|
| 21 |
+
#include "llvm/Support/Endian.h"
|
| 22 |
+
#include "llvm/Support/Error.h"
|
| 23 |
+
#include "llvm/Support/ErrorOr.h"
|
| 24 |
+
#include "llvm/Support/MemoryBufferRef.h"
|
| 25 |
+
#include <cstdint>
|
| 26 |
+
#include <memory>
|
| 27 |
+
#include <optional>
|
| 28 |
+
#include <string>
|
| 29 |
+
#include <system_error>
|
| 30 |
+
#include <vector>
|
| 31 |
+
namespace llvm {
|
| 32 |
+
|
| 33 |
+
class LLVMContext;
|
| 34 |
+
class Module;
|
| 35 |
+
class MemoryBuffer;
|
| 36 |
+
class Metadata;
|
| 37 |
+
class ModuleSummaryIndex;
|
| 38 |
+
class Type;
|
| 39 |
+
class Value;
|
| 40 |
+
|
| 41 |
+
// Callback to override the data layout string of an imported bitcode module.
|
| 42 |
+
// The first argument is the target triple, the second argument the data layout
|
| 43 |
+
// string from the input, or a default string. It will be used if the callback
|
| 44 |
+
// returns std::nullopt.
|
| 45 |
+
typedef std::function<std::optional<std::string>(StringRef, StringRef)>
|
| 46 |
+
DataLayoutCallbackFuncTy;
|
| 47 |
+
|
| 48 |
+
typedef std::function<Type *(unsigned)> GetTypeByIDTy;
|
| 49 |
+
|
| 50 |
+
typedef std::function<unsigned(unsigned, unsigned)> GetContainedTypeIDTy;
|
| 51 |
+
|
| 52 |
+
typedef std::function<void(Value *, unsigned, GetTypeByIDTy,
|
| 53 |
+
GetContainedTypeIDTy)>
|
| 54 |
+
ValueTypeCallbackTy;
|
| 55 |
+
|
| 56 |
+
typedef std::function<void(Metadata **, unsigned, GetTypeByIDTy,
|
| 57 |
+
GetContainedTypeIDTy)>
|
| 58 |
+
MDTypeCallbackTy;
|
| 59 |
+
|
| 60 |
+
// These functions are for converting Expected/Error values to
|
| 61 |
+
// ErrorOr/std::error_code for compatibility with legacy clients. FIXME:
|
| 62 |
+
// Remove these functions once no longer needed by the C and libLTO APIs.
|
| 63 |
+
|
| 64 |
+
LLVM_ABI std::error_code errorToErrorCodeAndEmitErrors(LLVMContext &Ctx,
|
| 65 |
+
Error Err);
|
| 66 |
+
|
| 67 |
+
template <typename T>
|
| 68 |
+
ErrorOr<T> expectedToErrorOrAndEmitErrors(LLVMContext &Ctx, Expected<T> Val) {
|
| 69 |
+
if (!Val)
|
| 70 |
+
return errorToErrorCodeAndEmitErrors(Ctx, Val.takeError());
|
| 71 |
+
return std::move(*Val);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
struct ParserCallbacks {
|
| 75 |
+
std::optional<DataLayoutCallbackFuncTy> DataLayout;
|
| 76 |
+
/// The ValueType callback is called for every function definition or
|
| 77 |
+
/// declaration and allows accessing the type information, also behind
|
| 78 |
+
/// pointers. This can be useful, when the opaque pointer upgrade cleans all
|
| 79 |
+
/// type information behind pointers.
|
| 80 |
+
/// The second argument to ValueTypeCallback is the type ID of the
|
| 81 |
+
/// function, the two passed functions can be used to extract type
|
| 82 |
+
/// information.
|
| 83 |
+
std::optional<ValueTypeCallbackTy> ValueType;
|
| 84 |
+
/// The MDType callback is called for every value in metadata.
|
| 85 |
+
std::optional<MDTypeCallbackTy> MDType;
|
| 86 |
+
|
| 87 |
+
ParserCallbacks() = default;
|
| 88 |
+
explicit ParserCallbacks(DataLayoutCallbackFuncTy DataLayout)
|
| 89 |
+
: DataLayout(DataLayout) {}
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
struct BitcodeFileContents;
|
| 93 |
+
|
| 94 |
+
/// Basic information extracted from a bitcode module to be used for LTO.
|
| 95 |
+
struct BitcodeLTOInfo {
|
| 96 |
+
bool IsThinLTO;
|
| 97 |
+
bool HasSummary;
|
| 98 |
+
bool EnableSplitLTOUnit;
|
| 99 |
+
bool UnifiedLTO;
|
| 100 |
+
};
|
| 101 |
+
|
| 102 |
+
/// Represents a module in a bitcode file.
|
| 103 |
+
class BitcodeModule {
|
| 104 |
+
// This covers the identification (if present) and module blocks.
|
| 105 |
+
ArrayRef<uint8_t> Buffer;
|
| 106 |
+
StringRef ModuleIdentifier;
|
| 107 |
+
|
| 108 |
+
// The string table used to interpret this module.
|
| 109 |
+
StringRef Strtab;
|
| 110 |
+
|
| 111 |
+
// The bitstream location of the IDENTIFICATION_BLOCK.
|
| 112 |
+
uint64_t IdentificationBit;
|
| 113 |
+
|
| 114 |
+
// The bitstream location of this module's MODULE_BLOCK.
|
| 115 |
+
uint64_t ModuleBit;
|
| 116 |
+
|
| 117 |
+
BitcodeModule(ArrayRef<uint8_t> Buffer, StringRef ModuleIdentifier,
|
| 118 |
+
uint64_t IdentificationBit, uint64_t ModuleBit)
|
| 119 |
+
: Buffer(Buffer), ModuleIdentifier(ModuleIdentifier),
|
| 120 |
+
IdentificationBit(IdentificationBit), ModuleBit(ModuleBit) {}
|
| 121 |
+
|
| 122 |
+
// Calls the ctor.
|
| 123 |
+
LLVM_ABI_FRIEND friend Expected<BitcodeFileContents>
|
| 124 |
+
getBitcodeFileContents(MemoryBufferRef Buffer);
|
| 125 |
+
|
| 126 |
+
Expected<std::unique_ptr<Module>>
|
| 127 |
+
getModuleImpl(LLVMContext &Context, bool MaterializeAll,
|
| 128 |
+
bool ShouldLazyLoadMetadata, bool IsImporting,
|
| 129 |
+
ParserCallbacks Callbacks = {});
|
| 130 |
+
|
| 131 |
+
public:
|
| 132 |
+
StringRef getBuffer() const {
|
| 133 |
+
return StringRef((const char *)Buffer.begin(), Buffer.size());
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
StringRef getStrtab() const { return Strtab; }
|
| 137 |
+
|
| 138 |
+
StringRef getModuleIdentifier() const { return ModuleIdentifier; }
|
| 139 |
+
|
| 140 |
+
/// Read the bitcode module and prepare for lazy deserialization of function
|
| 141 |
+
/// bodies. If ShouldLazyLoadMetadata is true, lazily load metadata as well.
|
| 142 |
+
/// If IsImporting is true, this module is being parsed for ThinLTO
|
| 143 |
+
/// importing into another module.
|
| 144 |
+
LLVM_ABI Expected<std::unique_ptr<Module>>
|
| 145 |
+
getLazyModule(LLVMContext &Context, bool ShouldLazyLoadMetadata,
|
| 146 |
+
bool IsImporting, ParserCallbacks Callbacks = {});
|
| 147 |
+
|
| 148 |
+
/// Read the entire bitcode module and return it.
|
| 149 |
+
LLVM_ABI Expected<std::unique_ptr<Module>>
|
| 150 |
+
parseModule(LLVMContext &Context, ParserCallbacks Callbacks = {});
|
| 151 |
+
|
| 152 |
+
/// Returns information about the module to be used for LTO: whether to
|
| 153 |
+
/// compile with ThinLTO, and whether it has a summary.
|
| 154 |
+
LLVM_ABI Expected<BitcodeLTOInfo> getLTOInfo();
|
| 155 |
+
|
| 156 |
+
/// Parse the specified bitcode buffer, returning the module summary index.
|
| 157 |
+
LLVM_ABI Expected<std::unique_ptr<ModuleSummaryIndex>> getSummary();
|
| 158 |
+
|
| 159 |
+
/// Parse the specified bitcode buffer and merge its module summary index
|
| 160 |
+
/// into CombinedIndex.
|
| 161 |
+
LLVM_ABI Error
|
| 162 |
+
readSummary(ModuleSummaryIndex &CombinedIndex, StringRef ModulePath,
|
| 163 |
+
std::function<bool(GlobalValue::GUID)> IsPrevailing = nullptr);
|
| 164 |
+
};
|
| 165 |
+
|
| 166 |
+
struct BitcodeFileContents {
|
| 167 |
+
std::vector<BitcodeModule> Mods;
|
| 168 |
+
StringRef Symtab, StrtabForSymtab;
|
| 169 |
+
};
|
| 170 |
+
|
| 171 |
+
/// Returns the contents of a bitcode file. This includes the raw contents of
|
| 172 |
+
/// the symbol table embedded in the bitcode file. Clients which require a
|
| 173 |
+
/// symbol table should prefer to use irsymtab::read instead of this function
|
| 174 |
+
/// because it creates a reader for the irsymtab and handles upgrading bitcode
|
| 175 |
+
/// files without a symbol table or with an old symbol table.
|
| 176 |
+
LLVM_ABI Expected<BitcodeFileContents>
|
| 177 |
+
getBitcodeFileContents(MemoryBufferRef Buffer);
|
| 178 |
+
|
| 179 |
+
/// Returns a list of modules in the specified bitcode buffer.
|
| 180 |
+
LLVM_ABI Expected<std::vector<BitcodeModule>>
|
| 181 |
+
getBitcodeModuleList(MemoryBufferRef Buffer);
|
| 182 |
+
|
| 183 |
+
/// Read the header of the specified bitcode buffer and prepare for lazy
|
| 184 |
+
/// deserialization of function bodies. If ShouldLazyLoadMetadata is true,
|
| 185 |
+
/// lazily load metadata as well. If IsImporting is true, this module is
|
| 186 |
+
/// being parsed for ThinLTO importing into another module.
|
| 187 |
+
LLVM_ABI Expected<std::unique_ptr<Module>>
|
| 188 |
+
getLazyBitcodeModule(MemoryBufferRef Buffer, LLVMContext &Context,
|
| 189 |
+
bool ShouldLazyLoadMetadata = false,
|
| 190 |
+
bool IsImporting = false,
|
| 191 |
+
ParserCallbacks Callbacks = {});
|
| 192 |
+
|
| 193 |
+
/// Like getLazyBitcodeModule, except that the module takes ownership of
|
| 194 |
+
/// the memory buffer if successful. If successful, this moves Buffer. On
|
| 195 |
+
/// error, this *does not* move Buffer. If IsImporting is true, this module is
|
| 196 |
+
/// being parsed for ThinLTO importing into another module.
|
| 197 |
+
LLVM_ABI Expected<std::unique_ptr<Module>> getOwningLazyBitcodeModule(
|
| 198 |
+
std::unique_ptr<MemoryBuffer> &&Buffer, LLVMContext &Context,
|
| 199 |
+
bool ShouldLazyLoadMetadata = false, bool IsImporting = false,
|
| 200 |
+
ParserCallbacks Callbacks = {});
|
| 201 |
+
|
| 202 |
+
/// Read the header of the specified bitcode buffer and extract just the
|
| 203 |
+
/// triple information. If successful, this returns a string. On error, this
|
| 204 |
+
/// returns "".
|
| 205 |
+
LLVM_ABI Expected<std::string> getBitcodeTargetTriple(MemoryBufferRef Buffer);
|
| 206 |
+
|
| 207 |
+
/// Return true if \p Buffer contains a bitcode file with ObjC code (category
|
| 208 |
+
/// or class) in it.
|
| 209 |
+
LLVM_ABI Expected<bool>
|
| 210 |
+
isBitcodeContainingObjCCategory(MemoryBufferRef Buffer);
|
| 211 |
+
|
| 212 |
+
/// Read the header of the specified bitcode buffer and extract just the
|
| 213 |
+
/// producer string information. If successful, this returns a string. On
|
| 214 |
+
/// error, this returns "".
|
| 215 |
+
LLVM_ABI Expected<std::string>
|
| 216 |
+
getBitcodeProducerString(MemoryBufferRef Buffer);
|
| 217 |
+
|
| 218 |
+
/// Read the specified bitcode file, returning the module.
|
| 219 |
+
LLVM_ABI Expected<std::unique_ptr<Module>>
|
| 220 |
+
parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context,
|
| 221 |
+
ParserCallbacks Callbacks = {});
|
| 222 |
+
|
| 223 |
+
/// Returns LTO information for the specified bitcode file.
|
| 224 |
+
LLVM_ABI Expected<BitcodeLTOInfo> getBitcodeLTOInfo(MemoryBufferRef Buffer);
|
| 225 |
+
|
| 226 |
+
/// Parse the specified bitcode buffer, returning the module summary index.
|
| 227 |
+
LLVM_ABI Expected<std::unique_ptr<ModuleSummaryIndex>>
|
| 228 |
+
getModuleSummaryIndex(MemoryBufferRef Buffer);
|
| 229 |
+
|
| 230 |
+
/// Parse the specified bitcode buffer and merge the index into CombinedIndex.
|
| 231 |
+
LLVM_ABI Error readModuleSummaryIndex(MemoryBufferRef Buffer,
|
| 232 |
+
ModuleSummaryIndex &CombinedIndex);
|
| 233 |
+
|
| 234 |
+
/// Parse the module summary index out of an IR file and return the module
|
| 235 |
+
/// summary index object if found, or an empty summary if not. If Path refers
|
| 236 |
+
/// to an empty file and IgnoreEmptyThinLTOIndexFile is true, then
|
| 237 |
+
/// this function will return nullptr.
|
| 238 |
+
LLVM_ABI Expected<std::unique_ptr<ModuleSummaryIndex>>
|
| 239 |
+
getModuleSummaryIndexForFile(StringRef Path,
|
| 240 |
+
bool IgnoreEmptyThinLTOIndexFile = false);
|
| 241 |
+
|
| 242 |
+
/// isBitcodeWrapper - Return true if the given bytes are the magic bytes
|
| 243 |
+
/// for an LLVM IR bitcode wrapper.
|
| 244 |
+
inline bool isBitcodeWrapper(const unsigned char *BufPtr,
|
| 245 |
+
const unsigned char *BufEnd) {
|
| 246 |
+
// See if you can find the hidden message in the magic bytes :-).
|
| 247 |
+
// (Hint: it's a little-endian encoding.)
|
| 248 |
+
return BufPtr != BufEnd &&
|
| 249 |
+
BufPtr[0] == 0xDE &&
|
| 250 |
+
BufPtr[1] == 0xC0 &&
|
| 251 |
+
BufPtr[2] == 0x17 &&
|
| 252 |
+
BufPtr[3] == 0x0B;
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
/// isRawBitcode - Return true if the given bytes are the magic bytes for
|
| 256 |
+
/// raw LLVM IR bitcode (without a wrapper).
|
| 257 |
+
inline bool isRawBitcode(const unsigned char *BufPtr,
|
| 258 |
+
const unsigned char *BufEnd) {
|
| 259 |
+
// These bytes sort of have a hidden message, but it's not in
|
| 260 |
+
// little-endian this time, and it's a little redundant.
|
| 261 |
+
return BufPtr != BufEnd &&
|
| 262 |
+
BufPtr[0] == 'B' &&
|
| 263 |
+
BufPtr[1] == 'C' &&
|
| 264 |
+
BufPtr[2] == 0xc0 &&
|
| 265 |
+
BufPtr[3] == 0xde;
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
/// isBitcode - Return true if the given bytes are the magic bytes for
|
| 269 |
+
/// LLVM IR bitcode, either with or without a wrapper.
|
| 270 |
+
inline bool isBitcode(const unsigned char *BufPtr,
|
| 271 |
+
const unsigned char *BufEnd) {
|
| 272 |
+
return isBitcodeWrapper(BufPtr, BufEnd) ||
|
| 273 |
+
isRawBitcode(BufPtr, BufEnd);
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
/// SkipBitcodeWrapperHeader - Some systems wrap bc files with a special
|
| 277 |
+
/// header for padding or other reasons. The format of this header is:
|
| 278 |
+
///
|
| 279 |
+
/// struct bc_header {
|
| 280 |
+
/// uint32_t Magic; // 0x0B17C0DE
|
| 281 |
+
/// uint32_t Version; // Version, currently always 0.
|
| 282 |
+
/// uint32_t BitcodeOffset; // Offset to traditional bitcode file.
|
| 283 |
+
/// uint32_t BitcodeSize; // Size of traditional bitcode file.
|
| 284 |
+
/// ... potentially other gunk ...
|
| 285 |
+
/// };
|
| 286 |
+
///
|
| 287 |
+
/// This function is called when we find a file with a matching magic number.
|
| 288 |
+
/// In this case, skip down to the subsection of the file that is actually a
|
| 289 |
+
/// BC file.
|
| 290 |
+
/// If 'VerifyBufferSize' is true, check that the buffer is large enough to
|
| 291 |
+
/// contain the whole bitcode file.
|
| 292 |
+
inline bool SkipBitcodeWrapperHeader(const unsigned char *&BufPtr,
|
| 293 |
+
const unsigned char *&BufEnd,
|
| 294 |
+
bool VerifyBufferSize) {
|
| 295 |
+
// Must contain the offset and size field!
|
| 296 |
+
if (unsigned(BufEnd - BufPtr) < BWH_SizeField + 4)
|
| 297 |
+
return true;
|
| 298 |
+
|
| 299 |
+
unsigned Offset = support::endian::read32le(&BufPtr[BWH_OffsetField]);
|
| 300 |
+
unsigned Size = support::endian::read32le(&BufPtr[BWH_SizeField]);
|
| 301 |
+
uint64_t BitcodeOffsetEnd = (uint64_t)Offset + (uint64_t)Size;
|
| 302 |
+
|
| 303 |
+
// Verify that Offset+Size fits in the file.
|
| 304 |
+
if (VerifyBufferSize && BitcodeOffsetEnd > uint64_t(BufEnd-BufPtr))
|
| 305 |
+
return true;
|
| 306 |
+
BufPtr += Offset;
|
| 307 |
+
BufEnd = BufPtr+Size;
|
| 308 |
+
return false;
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
LLVM_ABI APInt readWideAPInt(ArrayRef<uint64_t> Vals, unsigned TypeBits);
|
| 312 |
+
|
| 313 |
+
LLVM_ABI const std::error_category &BitcodeErrorCategory();
|
| 314 |
+
enum class BitcodeError { CorruptedBitcode = 1 };
|
| 315 |
+
inline std::error_code make_error_code(BitcodeError E) {
|
| 316 |
+
return std::error_code(static_cast<int>(E), BitcodeErrorCategory());
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
} // end namespace llvm
|
| 320 |
+
|
| 321 |
+
namespace std {
|
| 322 |
+
|
| 323 |
+
template <> struct is_error_code_enum<llvm::BitcodeError> : std::true_type {};
|
| 324 |
+
|
| 325 |
+
} // end namespace std
|
| 326 |
+
|
| 327 |
+
#endif // LLVM_BITCODE_BITCODEREADER_H
|
deps/exla/cache/xla_extension/include/llvm/Bitcode/BitcodeWriter.h
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- llvm/Bitcode/BitcodeWriter.h - Bitcode writers -----------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This header defines interfaces to write LLVM bitcode files/streams.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_BITCODE_BITCODEWRITER_H
|
| 14 |
+
#define LLVM_BITCODE_BITCODEWRITER_H
|
| 15 |
+
|
| 16 |
+
#include "llvm/ADT/StringRef.h"
|
| 17 |
+
#include "llvm/IR/ModuleSummaryIndex.h"
|
| 18 |
+
#include "llvm/MC/StringTableBuilder.h"
|
| 19 |
+
#include "llvm/Support/Allocator.h"
|
| 20 |
+
#include "llvm/Support/Compiler.h"
|
| 21 |
+
#include "llvm/Support/MemoryBufferRef.h"
|
| 22 |
+
#include <map>
|
| 23 |
+
#include <memory>
|
| 24 |
+
#include <string>
|
| 25 |
+
#include <vector>
|
| 26 |
+
|
| 27 |
+
namespace llvm {
|
| 28 |
+
|
| 29 |
+
class BitstreamWriter;
|
| 30 |
+
class Module;
|
| 31 |
+
class raw_ostream;
|
| 32 |
+
|
| 33 |
+
class BitcodeWriter {
|
| 34 |
+
std::unique_ptr<BitstreamWriter> Stream;
|
| 35 |
+
|
| 36 |
+
StringTableBuilder StrtabBuilder{StringTableBuilder::RAW};
|
| 37 |
+
|
| 38 |
+
// Owns any strings created by the irsymtab writer until we create the
|
| 39 |
+
// string table.
|
| 40 |
+
BumpPtrAllocator Alloc;
|
| 41 |
+
|
| 42 |
+
bool WroteStrtab = false, WroteSymtab = false;
|
| 43 |
+
|
| 44 |
+
void writeBlob(unsigned Block, unsigned Record, StringRef Blob);
|
| 45 |
+
|
| 46 |
+
std::vector<Module *> Mods;
|
| 47 |
+
|
| 48 |
+
public:
|
| 49 |
+
/// Create a BitcodeWriter that writes to Buffer.
|
| 50 |
+
LLVM_ABI BitcodeWriter(SmallVectorImpl<char> &Buffer);
|
| 51 |
+
LLVM_ABI BitcodeWriter(raw_ostream &FS);
|
| 52 |
+
|
| 53 |
+
LLVM_ABI ~BitcodeWriter();
|
| 54 |
+
|
| 55 |
+
/// Attempt to write a symbol table to the bitcode file. This must be called
|
| 56 |
+
/// at most once after all modules have been written.
|
| 57 |
+
///
|
| 58 |
+
/// A reader does not require a symbol table to interpret a bitcode file;
|
| 59 |
+
/// the symbol table is needed only to improve link-time performance. So
|
| 60 |
+
/// this function may decide not to write a symbol table. It may so decide
|
| 61 |
+
/// if, for example, the target is unregistered or the IR is malformed.
|
| 62 |
+
LLVM_ABI void writeSymtab();
|
| 63 |
+
|
| 64 |
+
/// Write the bitcode file's string table. This must be called exactly once
|
| 65 |
+
/// after all modules and the optional symbol table have been written.
|
| 66 |
+
LLVM_ABI void writeStrtab();
|
| 67 |
+
|
| 68 |
+
/// Copy the string table for another module into this bitcode file. This
|
| 69 |
+
/// should be called after copying the module itself into the bitcode file.
|
| 70 |
+
LLVM_ABI void copyStrtab(StringRef Strtab);
|
| 71 |
+
|
| 72 |
+
/// Write the specified module to the buffer specified at construction time.
|
| 73 |
+
///
|
| 74 |
+
/// If \c ShouldPreserveUseListOrder, encode the use-list order for each \a
|
| 75 |
+
/// Value in \c M. These will be reconstructed exactly when \a M is
|
| 76 |
+
/// deserialized.
|
| 77 |
+
///
|
| 78 |
+
/// If \c Index is supplied, the bitcode will contain the summary index
|
| 79 |
+
/// (currently for use in ThinLTO optimization).
|
| 80 |
+
///
|
| 81 |
+
/// \p GenerateHash enables hashing the Module and including the hash in the
|
| 82 |
+
/// bitcode (currently for use in ThinLTO incremental build).
|
| 83 |
+
///
|
| 84 |
+
/// If \p ModHash is non-null, when GenerateHash is true, the resulting
|
| 85 |
+
/// hash is written into ModHash. When GenerateHash is false, that value
|
| 86 |
+
/// is used as the hash instead of computing from the generated bitcode.
|
| 87 |
+
/// Can be used to produce the same module hash for a minimized bitcode
|
| 88 |
+
/// used just for the thin link as in the regular full bitcode that will
|
| 89 |
+
/// be used in the backend.
|
| 90 |
+
LLVM_ABI void writeModule(const Module &M,
|
| 91 |
+
bool ShouldPreserveUseListOrder = false,
|
| 92 |
+
const ModuleSummaryIndex *Index = nullptr,
|
| 93 |
+
bool GenerateHash = false,
|
| 94 |
+
ModuleHash *ModHash = nullptr);
|
| 95 |
+
|
| 96 |
+
/// Write the specified thin link bitcode file (i.e., the minimized bitcode
|
| 97 |
+
/// file) to the buffer specified at construction time. The thin link
|
| 98 |
+
/// bitcode file is used for thin link, and it only contains the necessary
|
| 99 |
+
/// information for thin link.
|
| 100 |
+
///
|
| 101 |
+
/// ModHash is for use in ThinLTO incremental build, generated while the
|
| 102 |
+
/// IR bitcode file writing.
|
| 103 |
+
LLVM_ABI void writeThinLinkBitcode(const Module &M,
|
| 104 |
+
const ModuleSummaryIndex &Index,
|
| 105 |
+
const ModuleHash &ModHash);
|
| 106 |
+
|
| 107 |
+
LLVM_ABI void
|
| 108 |
+
writeIndex(const ModuleSummaryIndex *Index,
|
| 109 |
+
const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex,
|
| 110 |
+
const GVSummaryPtrSet *DecSummaries);
|
| 111 |
+
};
|
| 112 |
+
|
| 113 |
+
/// Write the specified module to the specified raw output stream.
|
| 114 |
+
///
|
| 115 |
+
/// For streams where it matters, the given stream should be in "binary"
|
| 116 |
+
/// mode.
|
| 117 |
+
///
|
| 118 |
+
/// If \c ShouldPreserveUseListOrder, encode the use-list order for each \a
|
| 119 |
+
/// Value in \c M. These will be reconstructed exactly when \a M is
|
| 120 |
+
/// deserialized.
|
| 121 |
+
///
|
| 122 |
+
/// If \c Index is supplied, the bitcode will contain the summary index
|
| 123 |
+
/// (currently for use in ThinLTO optimization).
|
| 124 |
+
///
|
| 125 |
+
/// \p GenerateHash enables hashing the Module and including the hash in the
|
| 126 |
+
/// bitcode (currently for use in ThinLTO incremental build).
|
| 127 |
+
///
|
| 128 |
+
/// If \p ModHash is non-null, when GenerateHash is true, the resulting
|
| 129 |
+
/// hash is written into ModHash. When GenerateHash is false, that value
|
| 130 |
+
/// is used as the hash instead of computing from the generated bitcode.
|
| 131 |
+
/// Can be used to produce the same module hash for a minimized bitcode
|
| 132 |
+
/// used just for the thin link as in the regular full bitcode that will
|
| 133 |
+
/// be used in the backend.
|
| 134 |
+
LLVM_ABI void WriteBitcodeToFile(const Module &M, raw_ostream &Out,
|
| 135 |
+
bool ShouldPreserveUseListOrder = false,
|
| 136 |
+
const ModuleSummaryIndex *Index = nullptr,
|
| 137 |
+
bool GenerateHash = false,
|
| 138 |
+
ModuleHash *ModHash = nullptr);
|
| 139 |
+
|
| 140 |
+
/// Write the specified thin link bitcode file (i.e., the minimized bitcode
|
| 141 |
+
/// file) to the given raw output stream, where it will be written in a new
|
| 142 |
+
/// bitcode block. The thin link bitcode file is used for thin link, and it
|
| 143 |
+
/// only contains the necessary information for thin link.
|
| 144 |
+
///
|
| 145 |
+
/// ModHash is for use in ThinLTO incremental build, generated while the IR
|
| 146 |
+
/// bitcode file writing.
|
| 147 |
+
LLVM_ABI void writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out,
|
| 148 |
+
const ModuleSummaryIndex &Index,
|
| 149 |
+
const ModuleHash &ModHash);
|
| 150 |
+
|
| 151 |
+
/// Write the specified module summary index to the given raw output stream,
|
| 152 |
+
/// where it will be written in a new bitcode block. This is used when
|
| 153 |
+
/// writing the combined index file for ThinLTO. When writing a subset of the
|
| 154 |
+
/// index for a distributed backend, provide the \p ModuleToSummariesForIndex
|
| 155 |
+
/// map. \p DecSummaries specifies the set of summaries for which the
|
| 156 |
+
/// corresponding value should be imported as a declaration (prototype).
|
| 157 |
+
LLVM_ABI void writeIndexToFile(
|
| 158 |
+
const ModuleSummaryIndex &Index, raw_ostream &Out,
|
| 159 |
+
const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex = nullptr,
|
| 160 |
+
const GVSummaryPtrSet *DecSummaries = nullptr);
|
| 161 |
+
|
| 162 |
+
/// If EmbedBitcode is set, save a copy of the llvm IR as data in the
|
| 163 |
+
/// __LLVM,__bitcode section (.llvmbc on non-MacOS).
|
| 164 |
+
/// If available, pass the serialized module via the Buf parameter. If not,
|
| 165 |
+
/// pass an empty (default-initialized) MemoryBufferRef, and the serialization
|
| 166 |
+
/// will be handled by this API. The same behavior happens if the provided Buf
|
| 167 |
+
/// is not bitcode (i.e. if it's invalid data or even textual LLVM assembly).
|
| 168 |
+
/// If EmbedCmdline is set, the command line is also exported in
|
| 169 |
+
/// the corresponding section (__LLVM,_cmdline / .llvmcmd) - even if CmdArgs
|
| 170 |
+
/// were empty.
|
| 171 |
+
LLVM_ABI void embedBitcodeInModule(Module &M, MemoryBufferRef Buf,
|
| 172 |
+
bool EmbedBitcode, bool EmbedCmdline,
|
| 173 |
+
const std::vector<uint8_t> &CmdArgs);
|
| 174 |
+
|
| 175 |
+
} // end namespace llvm
|
| 176 |
+
|
| 177 |
+
#endif // LLVM_BITCODE_BITCODEWRITER_H
|
deps/exla/cache/xla_extension/include/llvm/Bitcode/BitcodeWriterPass.h
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===-- BitcodeWriterPass.h - Bitcode writing pass --------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
/// \file
|
| 9 |
+
///
|
| 10 |
+
/// This file provides a bitcode writing pass.
|
| 11 |
+
///
|
| 12 |
+
//===----------------------------------------------------------------------===//
|
| 13 |
+
|
| 14 |
+
#ifndef LLVM_BITCODE_BITCODEWRITERPASS_H
|
| 15 |
+
#define LLVM_BITCODE_BITCODEWRITERPASS_H
|
| 16 |
+
|
| 17 |
+
#include "llvm/IR/PassManager.h"
|
| 18 |
+
#include "llvm/Support/Compiler.h"
|
| 19 |
+
|
| 20 |
+
namespace llvm {
|
| 21 |
+
class Module;
|
| 22 |
+
class ModulePass;
|
| 23 |
+
class Pass;
|
| 24 |
+
class raw_ostream;
|
| 25 |
+
|
| 26 |
+
/// Create and return a pass that writes the module to the specified
|
| 27 |
+
/// ostream. Note that this pass is designed for use with the legacy pass
|
| 28 |
+
/// manager.
|
| 29 |
+
///
|
| 30 |
+
/// If \c ShouldPreserveUseListOrder, encode use-list order so it can be
|
| 31 |
+
/// reproduced when deserialized.
|
| 32 |
+
LLVM_ABI ModulePass *
|
| 33 |
+
createBitcodeWriterPass(raw_ostream &Str,
|
| 34 |
+
bool ShouldPreserveUseListOrder = false);
|
| 35 |
+
|
| 36 |
+
/// Check whether a pass is a BitcodeWriterPass.
|
| 37 |
+
LLVM_ABI bool isBitcodeWriterPass(Pass *P);
|
| 38 |
+
|
| 39 |
+
/// Pass for writing a module of IR out to a bitcode file.
|
| 40 |
+
///
|
| 41 |
+
/// Note that this is intended for use with the new pass manager. To construct
|
| 42 |
+
/// a pass for the legacy pass manager, use the function above.
|
| 43 |
+
class BitcodeWriterPass : public PassInfoMixin<BitcodeWriterPass> {
|
| 44 |
+
raw_ostream &OS;
|
| 45 |
+
bool ShouldPreserveUseListOrder;
|
| 46 |
+
bool EmitSummaryIndex;
|
| 47 |
+
bool EmitModuleHash;
|
| 48 |
+
|
| 49 |
+
public:
|
| 50 |
+
/// Construct a bitcode writer pass around a particular output stream.
|
| 51 |
+
///
|
| 52 |
+
/// If \c ShouldPreserveUseListOrder, encode use-list order so it can be
|
| 53 |
+
/// reproduced when deserialized.
|
| 54 |
+
///
|
| 55 |
+
/// If \c EmitSummaryIndex, emit the summary index (currently
|
| 56 |
+
/// for use in ThinLTO optimization).
|
| 57 |
+
explicit BitcodeWriterPass(raw_ostream &OS,
|
| 58 |
+
bool ShouldPreserveUseListOrder = false,
|
| 59 |
+
bool EmitSummaryIndex = false,
|
| 60 |
+
bool EmitModuleHash = false)
|
| 61 |
+
: OS(OS), ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
|
| 62 |
+
EmitSummaryIndex(EmitSummaryIndex), EmitModuleHash(EmitModuleHash) {}
|
| 63 |
+
|
| 64 |
+
/// Run the bitcode writer pass, and output the module to the selected
|
| 65 |
+
/// output stream.
|
| 66 |
+
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
|
| 67 |
+
|
| 68 |
+
static bool isRequired() { return true; }
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/Bitcode/LLVMBitCodes.h
ADDED
|
@@ -0,0 +1,822 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- LLVMBitCodes.h - Enum values for the LLVM bitcode format -*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This header defines Bitcode enum values for LLVM IR bitcode files.
|
| 10 |
+
//
|
| 11 |
+
// The enum values defined in this file should be considered permanent. If
|
| 12 |
+
// new features are added, they should have values added at the end of the
|
| 13 |
+
// respective lists.
|
| 14 |
+
//
|
| 15 |
+
//===----------------------------------------------------------------------===//
|
| 16 |
+
|
| 17 |
+
#ifndef LLVM_BITCODE_LLVMBITCODES_H
|
| 18 |
+
#define LLVM_BITCODE_LLVMBITCODES_H
|
| 19 |
+
|
| 20 |
+
// This is the only file included, and it, in turn, is a leaf header.
|
| 21 |
+
// This allows external tools to dump the AST of this file and analyze it for
|
| 22 |
+
// changes without needing to fully or partially build LLVM itself.
|
| 23 |
+
#include "llvm/Bitstream/BitCodeEnums.h"
|
| 24 |
+
|
| 25 |
+
namespace llvm {
|
| 26 |
+
namespace bitc {
|
| 27 |
+
// The only top-level block types are MODULE, IDENTIFICATION, STRTAB and SYMTAB.
|
| 28 |
+
enum BlockIDs {
|
| 29 |
+
// Blocks
|
| 30 |
+
MODULE_BLOCK_ID = FIRST_APPLICATION_BLOCKID,
|
| 31 |
+
|
| 32 |
+
// Module sub-block id's.
|
| 33 |
+
PARAMATTR_BLOCK_ID,
|
| 34 |
+
PARAMATTR_GROUP_BLOCK_ID,
|
| 35 |
+
|
| 36 |
+
CONSTANTS_BLOCK_ID,
|
| 37 |
+
FUNCTION_BLOCK_ID,
|
| 38 |
+
|
| 39 |
+
// Block intended to contains information on the bitcode versioning.
|
| 40 |
+
// Can be used to provide better error messages when we fail to parse a
|
| 41 |
+
// bitcode file.
|
| 42 |
+
IDENTIFICATION_BLOCK_ID,
|
| 43 |
+
|
| 44 |
+
VALUE_SYMTAB_BLOCK_ID,
|
| 45 |
+
METADATA_BLOCK_ID,
|
| 46 |
+
METADATA_ATTACHMENT_ID,
|
| 47 |
+
|
| 48 |
+
TYPE_BLOCK_ID_NEW,
|
| 49 |
+
|
| 50 |
+
USELIST_BLOCK_ID,
|
| 51 |
+
|
| 52 |
+
MODULE_STRTAB_BLOCK_ID,
|
| 53 |
+
GLOBALVAL_SUMMARY_BLOCK_ID,
|
| 54 |
+
|
| 55 |
+
OPERAND_BUNDLE_TAGS_BLOCK_ID,
|
| 56 |
+
|
| 57 |
+
METADATA_KIND_BLOCK_ID,
|
| 58 |
+
|
| 59 |
+
STRTAB_BLOCK_ID,
|
| 60 |
+
|
| 61 |
+
FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID,
|
| 62 |
+
|
| 63 |
+
SYMTAB_BLOCK_ID,
|
| 64 |
+
|
| 65 |
+
SYNC_SCOPE_NAMES_BLOCK_ID,
|
| 66 |
+
};
|
| 67 |
+
|
| 68 |
+
/// Identification block contains a string that describes the producer details,
|
| 69 |
+
/// and an epoch that defines the auto-upgrade capability.
|
| 70 |
+
enum IdentificationCodes {
|
| 71 |
+
IDENTIFICATION_CODE_STRING = 1, // IDENTIFICATION: [strchr x N]
|
| 72 |
+
IDENTIFICATION_CODE_EPOCH = 2, // EPOCH: [epoch#]
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
/// The epoch that defines the auto-upgrade compatibility for the bitcode.
|
| 76 |
+
///
|
| 77 |
+
/// LLVM guarantees in a major release that a minor release can read bitcode
|
| 78 |
+
/// generated by previous minor releases. We translate this by making the reader
|
| 79 |
+
/// accepting only bitcode with the same epoch, except for the X.0 release which
|
| 80 |
+
/// also accepts N-1.
|
| 81 |
+
enum { BITCODE_CURRENT_EPOCH = 0 };
|
| 82 |
+
|
| 83 |
+
/// MODULE blocks have a number of optional fields and subblocks.
|
| 84 |
+
enum ModuleCodes {
|
| 85 |
+
MODULE_CODE_VERSION = 1, // VERSION: [version#]
|
| 86 |
+
MODULE_CODE_TRIPLE = 2, // TRIPLE: [strchr x N]
|
| 87 |
+
MODULE_CODE_DATALAYOUT = 3, // DATALAYOUT: [strchr x N]
|
| 88 |
+
MODULE_CODE_ASM = 4, // ASM: [strchr x N]
|
| 89 |
+
MODULE_CODE_SECTIONNAME = 5, // SECTIONNAME: [strchr x N]
|
| 90 |
+
|
| 91 |
+
// Deprecated, but still needed to read old bitcode files.
|
| 92 |
+
MODULE_CODE_DEPLIB = 6, // DEPLIB: [strchr x N]
|
| 93 |
+
|
| 94 |
+
// GLOBALVAR: [pointer type, isconst, initid,
|
| 95 |
+
// linkage, alignment, section, visibility, threadlocal]
|
| 96 |
+
MODULE_CODE_GLOBALVAR = 7,
|
| 97 |
+
|
| 98 |
+
// FUNCTION: [type, callingconv, isproto, linkage, paramattrs, alignment,
|
| 99 |
+
// section, visibility, gc, unnamed_addr]
|
| 100 |
+
MODULE_CODE_FUNCTION = 8,
|
| 101 |
+
|
| 102 |
+
// ALIAS: [alias type, aliasee val#, linkage, visibility]
|
| 103 |
+
MODULE_CODE_ALIAS_OLD = 9,
|
| 104 |
+
|
| 105 |
+
MODULE_CODE_GCNAME = 11, // GCNAME: [strchr x N]
|
| 106 |
+
MODULE_CODE_COMDAT = 12, // COMDAT: [selection_kind, name]
|
| 107 |
+
|
| 108 |
+
MODULE_CODE_VSTOFFSET = 13, // VSTOFFSET: [offset]
|
| 109 |
+
|
| 110 |
+
// ALIAS: [alias value type, addrspace, aliasee val#, linkage, visibility]
|
| 111 |
+
MODULE_CODE_ALIAS = 14,
|
| 112 |
+
|
| 113 |
+
MODULE_CODE_METADATA_VALUES_UNUSED = 15,
|
| 114 |
+
|
| 115 |
+
// SOURCE_FILENAME: [namechar x N]
|
| 116 |
+
MODULE_CODE_SOURCE_FILENAME = 16,
|
| 117 |
+
|
| 118 |
+
// HASH: [5*i32]
|
| 119 |
+
MODULE_CODE_HASH = 17,
|
| 120 |
+
|
| 121 |
+
// IFUNC: [ifunc value type, addrspace, resolver val#, linkage, visibility]
|
| 122 |
+
MODULE_CODE_IFUNC = 18,
|
| 123 |
+
};
|
| 124 |
+
|
| 125 |
+
/// PARAMATTR blocks have code for defining a parameter attribute set.
|
| 126 |
+
enum AttributeCodes {
|
| 127 |
+
// Deprecated, but still needed to read old bitcode files.
|
| 128 |
+
PARAMATTR_CODE_ENTRY_OLD = 1, // ENTRY: [paramidx0, attr0,
|
| 129 |
+
// paramidx1, attr1...]
|
| 130 |
+
PARAMATTR_CODE_ENTRY = 2, // ENTRY: [attrgrp0, attrgrp1, ...]
|
| 131 |
+
PARAMATTR_GRP_CODE_ENTRY = 3 // ENTRY: [grpid, idx, attr0, attr1, ...]
|
| 132 |
+
};
|
| 133 |
+
|
| 134 |
+
/// TYPE blocks have codes for each type primitive they use.
|
| 135 |
+
enum TypeCodes {
|
| 136 |
+
TYPE_CODE_NUMENTRY = 1, // NUMENTRY: [numentries]
|
| 137 |
+
|
| 138 |
+
// Type Codes
|
| 139 |
+
TYPE_CODE_VOID = 2, // VOID
|
| 140 |
+
TYPE_CODE_FLOAT = 3, // FLOAT
|
| 141 |
+
TYPE_CODE_DOUBLE = 4, // DOUBLE
|
| 142 |
+
TYPE_CODE_LABEL = 5, // LABEL
|
| 143 |
+
TYPE_CODE_OPAQUE = 6, // OPAQUE
|
| 144 |
+
TYPE_CODE_INTEGER = 7, // INTEGER: [width]
|
| 145 |
+
TYPE_CODE_POINTER = 8, // POINTER: [pointee type]
|
| 146 |
+
|
| 147 |
+
TYPE_CODE_FUNCTION_OLD = 9, // FUNCTION: [vararg, attrid, retty,
|
| 148 |
+
// paramty x N]
|
| 149 |
+
|
| 150 |
+
TYPE_CODE_HALF = 10, // HALF
|
| 151 |
+
|
| 152 |
+
TYPE_CODE_ARRAY = 11, // ARRAY: [numelts, eltty]
|
| 153 |
+
TYPE_CODE_VECTOR = 12, // VECTOR: [numelts, eltty]
|
| 154 |
+
|
| 155 |
+
// These are not with the other floating point types because they're
|
| 156 |
+
// a late addition, and putting them in the right place breaks
|
| 157 |
+
// binary compatibility.
|
| 158 |
+
TYPE_CODE_X86_FP80 = 13, // X86 LONG DOUBLE
|
| 159 |
+
TYPE_CODE_FP128 = 14, // LONG DOUBLE (112 bit mantissa)
|
| 160 |
+
TYPE_CODE_PPC_FP128 = 15, // PPC LONG DOUBLE (2 doubles)
|
| 161 |
+
|
| 162 |
+
TYPE_CODE_METADATA = 16, // METADATA
|
| 163 |
+
|
| 164 |
+
TYPE_CODE_X86_MMX = 17, // X86 MMX
|
| 165 |
+
|
| 166 |
+
TYPE_CODE_STRUCT_ANON = 18, // STRUCT_ANON: [ispacked, eltty x N]
|
| 167 |
+
TYPE_CODE_STRUCT_NAME = 19, // STRUCT_NAME: [strchr x N]
|
| 168 |
+
TYPE_CODE_STRUCT_NAMED = 20, // STRUCT_NAMED: [ispacked, eltty x N]
|
| 169 |
+
|
| 170 |
+
TYPE_CODE_FUNCTION = 21, // FUNCTION: [vararg, retty, paramty x N]
|
| 171 |
+
|
| 172 |
+
TYPE_CODE_TOKEN = 22, // TOKEN
|
| 173 |
+
|
| 174 |
+
TYPE_CODE_BFLOAT = 23, // BRAIN FLOATING POINT
|
| 175 |
+
TYPE_CODE_X86_AMX = 24, // X86 AMX
|
| 176 |
+
|
| 177 |
+
TYPE_CODE_OPAQUE_POINTER = 25, // OPAQUE_POINTER: [addrspace]
|
| 178 |
+
|
| 179 |
+
TYPE_CODE_TARGET_TYPE = 26, // TARGET_TYPE
|
| 180 |
+
};
|
| 181 |
+
|
| 182 |
+
enum OperandBundleTagCode {
|
| 183 |
+
OPERAND_BUNDLE_TAG = 1, // TAG: [strchr x N]
|
| 184 |
+
};
|
| 185 |
+
|
| 186 |
+
enum SyncScopeNameCode {
|
| 187 |
+
SYNC_SCOPE_NAME = 1,
|
| 188 |
+
};
|
| 189 |
+
|
| 190 |
+
// Value symbol table codes.
|
| 191 |
+
enum ValueSymtabCodes {
|
| 192 |
+
VST_CODE_ENTRY = 1, // VST_ENTRY: [valueid, namechar x N]
|
| 193 |
+
VST_CODE_BBENTRY = 2, // VST_BBENTRY: [bbid, namechar x N]
|
| 194 |
+
VST_CODE_FNENTRY = 3, // VST_FNENTRY: [valueid, offset, namechar x N]
|
| 195 |
+
// VST_COMBINED_ENTRY: [valueid, refguid]
|
| 196 |
+
VST_CODE_COMBINED_ENTRY = 5
|
| 197 |
+
};
|
| 198 |
+
|
| 199 |
+
// The module path symbol table only has one code (MST_CODE_ENTRY).
|
| 200 |
+
enum ModulePathSymtabCodes {
|
| 201 |
+
MST_CODE_ENTRY = 1, // MST_ENTRY: [modid, namechar x N]
|
| 202 |
+
MST_CODE_HASH = 2, // MST_HASH: [5*i32]
|
| 203 |
+
};
|
| 204 |
+
|
| 205 |
+
// The summary section uses different codes in the per-module
|
| 206 |
+
// and combined index cases.
|
| 207 |
+
enum GlobalValueSummarySymtabCodes {
|
| 208 |
+
// PERMODULE: [valueid, flags, instcount, numrefs, numrefs x valueid,
|
| 209 |
+
// n x (valueid)]
|
| 210 |
+
FS_PERMODULE = 1,
|
| 211 |
+
// PERMODULE_PROFILE: [valueid, flags, instcount, numrefs,
|
| 212 |
+
// numrefs x valueid,
|
| 213 |
+
// n x (valueid, hotness+tailcall)]
|
| 214 |
+
FS_PERMODULE_PROFILE = 2,
|
| 215 |
+
// PERMODULE_GLOBALVAR_INIT_REFS: [valueid, flags, n x valueid]
|
| 216 |
+
FS_PERMODULE_GLOBALVAR_INIT_REFS = 3,
|
| 217 |
+
// COMBINED: [valueid, modid, flags, instcount, numrefs, numrefs x valueid,
|
| 218 |
+
// n x (valueid)]
|
| 219 |
+
FS_COMBINED = 4,
|
| 220 |
+
// COMBINED_PROFILE: [valueid, modid, flags, instcount, numrefs,
|
| 221 |
+
// numrefs x valueid,
|
| 222 |
+
// n x (valueid, hotness+tailcall)]
|
| 223 |
+
FS_COMBINED_PROFILE = 5,
|
| 224 |
+
// COMBINED_GLOBALVAR_INIT_REFS: [valueid, modid, flags, n x valueid]
|
| 225 |
+
FS_COMBINED_GLOBALVAR_INIT_REFS = 6,
|
| 226 |
+
// ALIAS: [valueid, flags, valueid]
|
| 227 |
+
FS_ALIAS = 7,
|
| 228 |
+
// COMBINED_ALIAS: [valueid, modid, flags, valueid]
|
| 229 |
+
FS_COMBINED_ALIAS = 8,
|
| 230 |
+
// COMBINED_ORIGINAL_NAME: [original_name_hash]
|
| 231 |
+
FS_COMBINED_ORIGINAL_NAME = 9,
|
| 232 |
+
// VERSION of the summary, bumped when adding flags for instance.
|
| 233 |
+
FS_VERSION = 10,
|
| 234 |
+
// The list of llvm.type.test type identifiers used by the following function
|
| 235 |
+
// that are used other than by an llvm.assume.
|
| 236 |
+
// [n x typeid]
|
| 237 |
+
FS_TYPE_TESTS = 11,
|
| 238 |
+
// The list of virtual calls made by this function using
|
| 239 |
+
// llvm.assume(llvm.type.test) intrinsics that do not have all constant
|
| 240 |
+
// integer arguments.
|
| 241 |
+
// [n x (typeid, offset)]
|
| 242 |
+
FS_TYPE_TEST_ASSUME_VCALLS = 12,
|
| 243 |
+
// The list of virtual calls made by this function using
|
| 244 |
+
// llvm.type.checked.load intrinsics that do not have all constant integer
|
| 245 |
+
// arguments.
|
| 246 |
+
// [n x (typeid, offset)]
|
| 247 |
+
FS_TYPE_CHECKED_LOAD_VCALLS = 13,
|
| 248 |
+
// Identifies a virtual call made by this function using an
|
| 249 |
+
// llvm.assume(llvm.type.test) intrinsic with all constant integer arguments.
|
| 250 |
+
// [typeid, offset, n x arg]
|
| 251 |
+
FS_TYPE_TEST_ASSUME_CONST_VCALL = 14,
|
| 252 |
+
// Identifies a virtual call made by this function using an
|
| 253 |
+
// llvm.type.checked.load intrinsic with all constant integer arguments.
|
| 254 |
+
// [typeid, offset, n x arg]
|
| 255 |
+
FS_TYPE_CHECKED_LOAD_CONST_VCALL = 15,
|
| 256 |
+
// Assigns a GUID to a value ID. This normally appears only in combined
|
| 257 |
+
// summaries, but it can also appear in per-module summaries for PGO data.
|
| 258 |
+
// [valueid, guid]
|
| 259 |
+
FS_VALUE_GUID = 16,
|
| 260 |
+
// The list of local functions with CFI jump tables. Function names are
|
| 261 |
+
// strings in strtab.
|
| 262 |
+
// [n * name]
|
| 263 |
+
FS_CFI_FUNCTION_DEFS = 17,
|
| 264 |
+
// The list of external functions with CFI jump tables. Function names are
|
| 265 |
+
// strings in strtab.
|
| 266 |
+
// [n * name]
|
| 267 |
+
FS_CFI_FUNCTION_DECLS = 18,
|
| 268 |
+
// Per-module summary that also adds relative block frequency to callee info.
|
| 269 |
+
// PERMODULE_RELBF: [valueid, flags, instcount, numrefs,
|
| 270 |
+
// numrefs x valueid,
|
| 271 |
+
// n x (valueid, relblockfreq+tailcall)]
|
| 272 |
+
FS_PERMODULE_RELBF = 19,
|
| 273 |
+
// Index-wide flags
|
| 274 |
+
FS_FLAGS = 20,
|
| 275 |
+
// Maps type identifier to summary information for that type identifier.
|
| 276 |
+
// Produced by the thin link (only lives in combined index).
|
| 277 |
+
// TYPE_ID: [typeid, kind, bitwidth, align, size, bitmask, inlinebits,
|
| 278 |
+
// n x (typeid, kind, name, numrba,
|
| 279 |
+
// numrba x (numarg, numarg x arg, kind, info, byte, bit))]
|
| 280 |
+
FS_TYPE_ID = 21,
|
| 281 |
+
// For background see overview at https://llvm.org/docs/TypeMetadata.html.
|
| 282 |
+
// The type metadata includes both the type identifier and the offset of
|
| 283 |
+
// the address point of the type (the address held by objects of that type
|
| 284 |
+
// which may not be the beginning of the virtual table). Vtable definitions
|
| 285 |
+
// are decorated with type metadata for the types they are compatible with.
|
| 286 |
+
//
|
| 287 |
+
// Maps type identifier to summary information for that type identifier
|
| 288 |
+
// computed from type metadata: the valueid of each vtable definition
|
| 289 |
+
// decorated with a type metadata for that identifier, and the offset from
|
| 290 |
+
// the corresponding type metadata.
|
| 291 |
+
// Exists in the per-module summary to provide information to thin link
|
| 292 |
+
// for index-based whole program devirtualization.
|
| 293 |
+
// TYPE_ID_METADATA: [typeid, n x (valueid, offset)]
|
| 294 |
+
FS_TYPE_ID_METADATA = 22,
|
| 295 |
+
// Summarizes vtable definition for use in index-based whole program
|
| 296 |
+
// devirtualization during the thin link.
|
| 297 |
+
// PERMODULE_VTABLE_GLOBALVAR_INIT_REFS: [valueid, flags, varflags,
|
| 298 |
+
// numrefs, numrefs x valueid,
|
| 299 |
+
// n x (valueid, offset)]
|
| 300 |
+
FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS = 23,
|
| 301 |
+
// The total number of basic blocks in the module.
|
| 302 |
+
FS_BLOCK_COUNT = 24,
|
| 303 |
+
// Range information for accessed offsets for every argument.
|
| 304 |
+
// [n x (paramno, range, numcalls, numcalls x (callee_guid, paramno, range))]
|
| 305 |
+
FS_PARAM_ACCESS = 25,
|
| 306 |
+
// Summary of per-module memprof callsite metadata.
|
| 307 |
+
// [valueid, n x stackidindex]
|
| 308 |
+
FS_PERMODULE_CALLSITE_INFO = 26,
|
| 309 |
+
// Summary of per-module allocation memprof metadata.
|
| 310 |
+
// [nummib, nummib x (alloc type, context radix tree index),
|
| 311 |
+
// [nummib x (numcontext x total size)]?]
|
| 312 |
+
FS_PERMODULE_ALLOC_INFO = 27,
|
| 313 |
+
// Summary of combined index memprof callsite metadata.
|
| 314 |
+
// [valueid, numstackindices, numver,
|
| 315 |
+
// numstackindices x stackidindex, numver x version]
|
| 316 |
+
FS_COMBINED_CALLSITE_INFO = 28,
|
| 317 |
+
// Summary of combined index allocation memprof metadata.
|
| 318 |
+
// [nummib, numver,
|
| 319 |
+
// nummib x (alloc type, context radix tree index),
|
| 320 |
+
// numver x version]
|
| 321 |
+
FS_COMBINED_ALLOC_INFO = 29,
|
| 322 |
+
// List of all stack ids referenced by index in the callsite and alloc infos.
|
| 323 |
+
// [n x stack id]
|
| 324 |
+
FS_STACK_IDS = 30,
|
| 325 |
+
// List of all full stack id pairs corresponding to the total sizes recorded
|
| 326 |
+
// at the end of the alloc info when reporting of hinted bytes is enabled.
|
| 327 |
+
// We use a fixed-width array, which is more efficient as these ids typically
|
| 328 |
+
// are close to 64 bits in size. The max fixed width value supported is 32
|
| 329 |
+
// bits so each 64-bit context id hash is recorded as a pair (upper 32 bits
|
| 330 |
+
// first). This record must immediately precede the associated alloc info, and
|
| 331 |
+
// the entries must be in the exact same order as the corresponding sizes.
|
| 332 |
+
// [nummib x (numcontext x full stack id)]
|
| 333 |
+
FS_ALLOC_CONTEXT_IDS = 31,
|
| 334 |
+
// Linearized radix tree of allocation contexts. See the description above the
|
| 335 |
+
// CallStackRadixTreeBuilder class in ProfileData/MemProf.h for format.
|
| 336 |
+
// [n x entry]
|
| 337 |
+
FS_CONTEXT_RADIX_TREE_ARRAY = 32,
|
| 338 |
+
// Summary of combined index allocation memprof metadata, without context.
|
| 339 |
+
// [nummib, numver,
|
| 340 |
+
// nummib x alloc type,
|
| 341 |
+
// numver x version]
|
| 342 |
+
FS_COMBINED_ALLOC_INFO_NO_CONTEXT = 33,
|
| 343 |
+
};
|
| 344 |
+
|
| 345 |
+
enum MetadataCodes {
|
| 346 |
+
METADATA_STRING_OLD = 1, // MDSTRING: [values]
|
| 347 |
+
METADATA_VALUE = 2, // VALUE: [type num, value num]
|
| 348 |
+
METADATA_NODE = 3, // NODE: [n x md num]
|
| 349 |
+
METADATA_NAME = 4, // STRING: [values]
|
| 350 |
+
METADATA_DISTINCT_NODE = 5, // DISTINCT_NODE: [n x md num]
|
| 351 |
+
METADATA_KIND = 6, // [n x [id, name]]
|
| 352 |
+
METADATA_LOCATION = 7, // [distinct, line, col, scope, inlined-at?]
|
| 353 |
+
METADATA_OLD_NODE = 8, // OLD_NODE: [n x (type num, value num)]
|
| 354 |
+
METADATA_OLD_FN_NODE = 9, // OLD_FN_NODE: [n x (type num, value num)]
|
| 355 |
+
METADATA_NAMED_NODE = 10, // NAMED_NODE: [n x mdnodes]
|
| 356 |
+
METADATA_ATTACHMENT = 11, // [m x [value, [n x [id, mdnode]]]
|
| 357 |
+
METADATA_GENERIC_DEBUG = 12, // [distinct, tag, vers, header, n x md num]
|
| 358 |
+
METADATA_SUBRANGE = 13, // [distinct, count, lo]
|
| 359 |
+
METADATA_ENUMERATOR = 14, // [isUnsigned|distinct, value, name]
|
| 360 |
+
METADATA_BASIC_TYPE = 15, // [distinct, tag, name, size, align, enc]
|
| 361 |
+
METADATA_FILE = 16, // [distinct, filename, directory, checksumkind, checksum]
|
| 362 |
+
METADATA_DERIVED_TYPE = 17, // [distinct, ...]
|
| 363 |
+
METADATA_COMPOSITE_TYPE = 18, // [distinct, ...]
|
| 364 |
+
METADATA_SUBROUTINE_TYPE = 19, // [distinct, flags, types, cc]
|
| 365 |
+
METADATA_COMPILE_UNIT = 20, // [distinct, ...]
|
| 366 |
+
METADATA_SUBPROGRAM = 21, // [distinct, ...]
|
| 367 |
+
METADATA_LEXICAL_BLOCK = 22, // [distinct, scope, file, line, column]
|
| 368 |
+
METADATA_LEXICAL_BLOCK_FILE = 23, //[distinct, scope, file, discriminator]
|
| 369 |
+
METADATA_NAMESPACE = 24, // [distinct, scope, file, name, line, exportSymbols]
|
| 370 |
+
METADATA_TEMPLATE_TYPE = 25, // [distinct, scope, name, type, ...]
|
| 371 |
+
METADATA_TEMPLATE_VALUE = 26, // [distinct, scope, name, type, value, ...]
|
| 372 |
+
METADATA_GLOBAL_VAR = 27, // [distinct, ...]
|
| 373 |
+
METADATA_LOCAL_VAR = 28, // [distinct, ...]
|
| 374 |
+
METADATA_EXPRESSION = 29, // [distinct, n x element]
|
| 375 |
+
METADATA_OBJC_PROPERTY = 30, // [distinct, name, file, line, ...]
|
| 376 |
+
METADATA_IMPORTED_ENTITY = 31, // [distinct, tag, scope, entity, line, name]
|
| 377 |
+
METADATA_MODULE = 32, // [distinct, scope, name, ...]
|
| 378 |
+
METADATA_MACRO = 33, // [distinct, macinfo, line, name, value]
|
| 379 |
+
METADATA_MACRO_FILE = 34, // [distinct, macinfo, line, file, ...]
|
| 380 |
+
METADATA_STRINGS = 35, // [count, offset] blob([lengths][chars])
|
| 381 |
+
METADATA_GLOBAL_DECL_ATTACHMENT = 36, // [valueid, n x [id, mdnode]]
|
| 382 |
+
METADATA_GLOBAL_VAR_EXPR = 37, // [distinct, var, expr]
|
| 383 |
+
METADATA_INDEX_OFFSET = 38, // [offset]
|
| 384 |
+
METADATA_INDEX = 39, // [bitpos]
|
| 385 |
+
METADATA_LABEL = 40, // [distinct, scope, name, file, line]
|
| 386 |
+
METADATA_STRING_TYPE = 41, // [distinct, name, size, align,...]
|
| 387 |
+
// Codes 42 and 43 are reserved for support for Fortran array specific debug
|
| 388 |
+
// info.
|
| 389 |
+
METADATA_COMMON_BLOCK = 44, // [distinct, scope, name, variable,...]
|
| 390 |
+
METADATA_GENERIC_SUBRANGE = 45, // [distinct, count, lo, up, stride]
|
| 391 |
+
METADATA_ARG_LIST = 46, // [n x [type num, value num]]
|
| 392 |
+
METADATA_ASSIGN_ID = 47, // [distinct, ...]
|
| 393 |
+
METADATA_SUBRANGE_TYPE = 48, // [distinct, ...]
|
| 394 |
+
METADATA_FIXED_POINT_TYPE = 49, // [distinct, ...]
|
| 395 |
+
};
|
| 396 |
+
|
| 397 |
+
// The constants block (CONSTANTS_BLOCK_ID) describes emission for each
|
| 398 |
+
// constant and maintains an implicit current type value.
|
| 399 |
+
enum ConstantsCodes {
|
| 400 |
+
CST_CODE_SETTYPE = 1, // SETTYPE: [typeid]
|
| 401 |
+
CST_CODE_NULL = 2, // NULL
|
| 402 |
+
CST_CODE_UNDEF = 3, // UNDEF
|
| 403 |
+
CST_CODE_INTEGER = 4, // INTEGER: [intval]
|
| 404 |
+
CST_CODE_WIDE_INTEGER = 5, // WIDE_INTEGER: [n x intval]
|
| 405 |
+
CST_CODE_FLOAT = 6, // FLOAT: [fpval]
|
| 406 |
+
CST_CODE_AGGREGATE = 7, // AGGREGATE: [n x value number]
|
| 407 |
+
CST_CODE_STRING = 8, // STRING: [values]
|
| 408 |
+
CST_CODE_CSTRING = 9, // CSTRING: [values]
|
| 409 |
+
CST_CODE_CE_BINOP = 10, // CE_BINOP: [opcode, opval, opval]
|
| 410 |
+
CST_CODE_CE_CAST = 11, // CE_CAST: [opcode, opty, opval]
|
| 411 |
+
CST_CODE_CE_GEP_OLD = 12, // CE_GEP: [n x operands]
|
| 412 |
+
CST_CODE_CE_SELECT = 13, // CE_SELECT: [opval, opval, opval]
|
| 413 |
+
CST_CODE_CE_EXTRACTELT = 14, // CE_EXTRACTELT: [opty, opval, opval]
|
| 414 |
+
CST_CODE_CE_INSERTELT = 15, // CE_INSERTELT: [opval, opval, opval]
|
| 415 |
+
CST_CODE_CE_SHUFFLEVEC = 16, // CE_SHUFFLEVEC: [opval, opval, opval]
|
| 416 |
+
CST_CODE_CE_CMP = 17, // CE_CMP: [opty, opval, opval, pred]
|
| 417 |
+
CST_CODE_INLINEASM_OLD = 18, // INLINEASM: [sideeffect|alignstack,
|
| 418 |
+
// asmstr,conststr]
|
| 419 |
+
CST_CODE_CE_SHUFVEC_EX = 19, // SHUFVEC_EX: [opty, opval, opval, opval]
|
| 420 |
+
CST_CODE_CE_INBOUNDS_GEP = 20, // INBOUNDS_GEP: [n x operands]
|
| 421 |
+
CST_CODE_BLOCKADDRESS = 21, // CST_CODE_BLOCKADDRESS [fnty, fnval, bb#]
|
| 422 |
+
CST_CODE_DATA = 22, // DATA: [n x elements]
|
| 423 |
+
CST_CODE_INLINEASM_OLD2 = 23, // INLINEASM: [sideeffect|alignstack|
|
| 424 |
+
// asmdialect,asmstr,conststr]
|
| 425 |
+
CST_CODE_CE_GEP_WITH_INRANGE_INDEX_OLD = 24, // [opty, flags, n x operands]
|
| 426 |
+
CST_CODE_CE_UNOP = 25, // CE_UNOP: [opcode, opval]
|
| 427 |
+
CST_CODE_POISON = 26, // POISON
|
| 428 |
+
CST_CODE_DSO_LOCAL_EQUIVALENT = 27, // DSO_LOCAL_EQUIVALENT [gvty, gv]
|
| 429 |
+
CST_CODE_INLINEASM_OLD3 = 28, // INLINEASM: [sideeffect|alignstack|
|
| 430 |
+
// asmdialect|unwind,
|
| 431 |
+
// asmstr,conststr]
|
| 432 |
+
CST_CODE_NO_CFI_VALUE = 29, // NO_CFI [ fty, f ]
|
| 433 |
+
CST_CODE_INLINEASM = 30, // INLINEASM: [fnty,
|
| 434 |
+
// sideeffect|alignstack|
|
| 435 |
+
// asmdialect|unwind,
|
| 436 |
+
// asmstr,conststr]
|
| 437 |
+
CST_CODE_CE_GEP_WITH_INRANGE = 31, // [opty, flags, range, n x operands]
|
| 438 |
+
CST_CODE_CE_GEP = 32, // [opty, flags, n x operands]
|
| 439 |
+
CST_CODE_PTRAUTH = 33, // [ptr, key, disc, addrdisc]
|
| 440 |
+
};
|
| 441 |
+
|
| 442 |
+
/// CastOpcodes - These are values used in the bitcode files to encode which
|
| 443 |
+
/// cast a CST_CODE_CE_CAST or a XXX refers to. The values of these enums
|
| 444 |
+
/// have no fixed relation to the LLVM IR enum values. Changing these will
|
| 445 |
+
/// break compatibility with old files.
|
| 446 |
+
enum CastOpcodes {
|
| 447 |
+
CAST_TRUNC = 0,
|
| 448 |
+
CAST_ZEXT = 1,
|
| 449 |
+
CAST_SEXT = 2,
|
| 450 |
+
CAST_FPTOUI = 3,
|
| 451 |
+
CAST_FPTOSI = 4,
|
| 452 |
+
CAST_UITOFP = 5,
|
| 453 |
+
CAST_SITOFP = 6,
|
| 454 |
+
CAST_FPTRUNC = 7,
|
| 455 |
+
CAST_FPEXT = 8,
|
| 456 |
+
CAST_PTRTOINT = 9,
|
| 457 |
+
CAST_INTTOPTR = 10,
|
| 458 |
+
CAST_BITCAST = 11,
|
| 459 |
+
CAST_ADDRSPACECAST = 12
|
| 460 |
+
};
|
| 461 |
+
|
| 462 |
+
/// UnaryOpcodes - These are values used in the bitcode files to encode which
|
| 463 |
+
/// unop a CST_CODE_CE_UNOP or a XXX refers to. The values of these enums
|
| 464 |
+
/// have no fixed relation to the LLVM IR enum values. Changing these will
|
| 465 |
+
/// break compatibility with old files.
|
| 466 |
+
enum UnaryOpcodes {
|
| 467 |
+
UNOP_FNEG = 0
|
| 468 |
+
};
|
| 469 |
+
|
| 470 |
+
/// BinaryOpcodes - These are values used in the bitcode files to encode which
|
| 471 |
+
/// binop a CST_CODE_CE_BINOP or a XXX refers to. The values of these enums
|
| 472 |
+
/// have no fixed relation to the LLVM IR enum values. Changing these will
|
| 473 |
+
/// break compatibility with old files.
|
| 474 |
+
enum BinaryOpcodes {
|
| 475 |
+
BINOP_ADD = 0,
|
| 476 |
+
BINOP_SUB = 1,
|
| 477 |
+
BINOP_MUL = 2,
|
| 478 |
+
BINOP_UDIV = 3,
|
| 479 |
+
BINOP_SDIV = 4, // overloaded for FP
|
| 480 |
+
BINOP_UREM = 5,
|
| 481 |
+
BINOP_SREM = 6, // overloaded for FP
|
| 482 |
+
BINOP_SHL = 7,
|
| 483 |
+
BINOP_LSHR = 8,
|
| 484 |
+
BINOP_ASHR = 9,
|
| 485 |
+
BINOP_AND = 10,
|
| 486 |
+
BINOP_OR = 11,
|
| 487 |
+
BINOP_XOR = 12
|
| 488 |
+
};
|
| 489 |
+
|
| 490 |
+
/// These are values used in the bitcode files to encode AtomicRMW operations.
|
| 491 |
+
/// The values of these enums have no fixed relation to the LLVM IR enum
|
| 492 |
+
/// values. Changing these will break compatibility with old files.
|
| 493 |
+
enum RMWOperations {
|
| 494 |
+
RMW_XCHG = 0,
|
| 495 |
+
RMW_ADD = 1,
|
| 496 |
+
RMW_SUB = 2,
|
| 497 |
+
RMW_AND = 3,
|
| 498 |
+
RMW_NAND = 4,
|
| 499 |
+
RMW_OR = 5,
|
| 500 |
+
RMW_XOR = 6,
|
| 501 |
+
RMW_MAX = 7,
|
| 502 |
+
RMW_MIN = 8,
|
| 503 |
+
RMW_UMAX = 9,
|
| 504 |
+
RMW_UMIN = 10,
|
| 505 |
+
RMW_FADD = 11,
|
| 506 |
+
RMW_FSUB = 12,
|
| 507 |
+
RMW_FMAX = 13,
|
| 508 |
+
RMW_FMIN = 14,
|
| 509 |
+
RMW_UINC_WRAP = 15,
|
| 510 |
+
RMW_UDEC_WRAP = 16,
|
| 511 |
+
RMW_USUB_COND = 17,
|
| 512 |
+
RMW_USUB_SAT = 18,
|
| 513 |
+
RMW_FMAXIMUM = 19,
|
| 514 |
+
RMW_FMINIMUM = 20,
|
| 515 |
+
};
|
| 516 |
+
|
| 517 |
+
/// OverflowingBinaryOperatorOptionalFlags - Flags for serializing
|
| 518 |
+
/// OverflowingBinaryOperator's SubclassOptionalData contents.
|
| 519 |
+
enum OverflowingBinaryOperatorOptionalFlags {
|
| 520 |
+
OBO_NO_UNSIGNED_WRAP = 0,
|
| 521 |
+
OBO_NO_SIGNED_WRAP = 1
|
| 522 |
+
};
|
| 523 |
+
|
| 524 |
+
/// TruncInstOptionalFlags - Flags for serializing
|
| 525 |
+
/// TruncInstOptionalFlags's SubclassOptionalData contents.
|
| 526 |
+
enum TruncInstOptionalFlags {
|
| 527 |
+
TIO_NO_UNSIGNED_WRAP = 0,
|
| 528 |
+
TIO_NO_SIGNED_WRAP = 1
|
| 529 |
+
};
|
| 530 |
+
|
| 531 |
+
/// FastMath Flags
|
| 532 |
+
/// This is a fixed layout derived from the bitcode emitted by LLVM 5.0
|
| 533 |
+
/// intended to decouple the in-memory representation from the serialization.
|
| 534 |
+
enum FastMathMap {
|
| 535 |
+
UnsafeAlgebra = (1 << 0), // Legacy
|
| 536 |
+
NoNaNs = (1 << 1),
|
| 537 |
+
NoInfs = (1 << 2),
|
| 538 |
+
NoSignedZeros = (1 << 3),
|
| 539 |
+
AllowReciprocal = (1 << 4),
|
| 540 |
+
AllowContract = (1 << 5),
|
| 541 |
+
ApproxFunc = (1 << 6),
|
| 542 |
+
AllowReassoc = (1 << 7)
|
| 543 |
+
};
|
| 544 |
+
|
| 545 |
+
/// Flags for serializing PossiblyNonNegInst's SubclassOptionalData contents.
|
| 546 |
+
enum PossiblyNonNegInstOptionalFlags { PNNI_NON_NEG = 0 };
|
| 547 |
+
|
| 548 |
+
/// PossiblyExactOperatorOptionalFlags - Flags for serializing
|
| 549 |
+
/// PossiblyExactOperator's SubclassOptionalData contents.
|
| 550 |
+
enum PossiblyExactOperatorOptionalFlags { PEO_EXACT = 0 };
|
| 551 |
+
|
| 552 |
+
/// PossiblyDisjointInstOptionalFlags - Flags for serializing
|
| 553 |
+
/// PossiblyDisjointInst's SubclassOptionalData contents.
|
| 554 |
+
enum PossiblyDisjointInstOptionalFlags { PDI_DISJOINT = 0 };
|
| 555 |
+
|
| 556 |
+
/// Mark to distinguish metadata from value in an operator bundle.
|
| 557 |
+
enum MetadataOperandBundleValueMarker { OB_METADATA = 0x80000000 };
|
| 558 |
+
|
| 559 |
+
/// GetElementPtrOptionalFlags - Flags for serializing
|
| 560 |
+
/// GEPOperator's SubclassOptionalData contents.
|
| 561 |
+
enum GetElementPtrOptionalFlags {
|
| 562 |
+
GEP_INBOUNDS = 0,
|
| 563 |
+
GEP_NUSW = 1,
|
| 564 |
+
GEP_NUW = 2,
|
| 565 |
+
};
|
| 566 |
+
|
| 567 |
+
/// ICmpOptionalFlags - Flags for serializing
|
| 568 |
+
/// ICmpOptionalFlags's SubclassOptionalData contents.
|
| 569 |
+
enum ICmpOptionalFlags { ICMP_SAME_SIGN = 0 };
|
| 570 |
+
|
| 571 |
+
/// Encoded AtomicOrdering values.
|
| 572 |
+
enum AtomicOrderingCodes {
|
| 573 |
+
ORDERING_NOTATOMIC = 0,
|
| 574 |
+
ORDERING_UNORDERED = 1,
|
| 575 |
+
ORDERING_MONOTONIC = 2,
|
| 576 |
+
ORDERING_ACQUIRE = 3,
|
| 577 |
+
ORDERING_RELEASE = 4,
|
| 578 |
+
ORDERING_ACQREL = 5,
|
| 579 |
+
ORDERING_SEQCST = 6
|
| 580 |
+
};
|
| 581 |
+
|
| 582 |
+
/// Markers and flags for call instruction.
|
| 583 |
+
enum CallMarkersFlags {
|
| 584 |
+
CALL_TAIL = 0,
|
| 585 |
+
CALL_CCONV = 1,
|
| 586 |
+
CALL_MUSTTAIL = 14,
|
| 587 |
+
CALL_EXPLICIT_TYPE = 15,
|
| 588 |
+
CALL_NOTAIL = 16,
|
| 589 |
+
CALL_FMF = 17 // Call has optional fast-math-flags.
|
| 590 |
+
};
|
| 591 |
+
|
| 592 |
+
// The function body block (FUNCTION_BLOCK_ID) describes function bodies. It
|
| 593 |
+
// can contain a constant block (CONSTANTS_BLOCK_ID).
|
| 594 |
+
enum FunctionCodes {
|
| 595 |
+
FUNC_CODE_DECLAREBLOCKS = 1, // DECLAREBLOCKS: [n]
|
| 596 |
+
|
| 597 |
+
FUNC_CODE_INST_BINOP = 2, // BINOP: [opcode, ty, opval, opval]
|
| 598 |
+
FUNC_CODE_INST_CAST = 3, // CAST: [opcode, ty, opty, opval]
|
| 599 |
+
FUNC_CODE_INST_GEP_OLD = 4, // GEP: [n x operands]
|
| 600 |
+
FUNC_CODE_INST_SELECT = 5, // SELECT: [ty, opval, opval, opval]
|
| 601 |
+
FUNC_CODE_INST_EXTRACTELT = 6, // EXTRACTELT: [opty, opval, opval]
|
| 602 |
+
FUNC_CODE_INST_INSERTELT = 7, // INSERTELT: [ty, opval, opval, opval]
|
| 603 |
+
FUNC_CODE_INST_SHUFFLEVEC = 8, // SHUFFLEVEC: [ty, opval, opval, opval]
|
| 604 |
+
FUNC_CODE_INST_CMP = 9, // CMP: [opty, opval, opval, pred]
|
| 605 |
+
|
| 606 |
+
FUNC_CODE_INST_RET = 10, // RET: [opty,opval<both optional>]
|
| 607 |
+
FUNC_CODE_INST_BR = 11, // BR: [bb#, bb#, cond] or [bb#]
|
| 608 |
+
FUNC_CODE_INST_SWITCH = 12, // SWITCH: [opty, op0, op1, ...]
|
| 609 |
+
FUNC_CODE_INST_INVOKE = 13, // INVOKE: [attr, fnty, op0,op1, ...]
|
| 610 |
+
// 14 is unused.
|
| 611 |
+
FUNC_CODE_INST_UNREACHABLE = 15, // UNREACHABLE
|
| 612 |
+
|
| 613 |
+
FUNC_CODE_INST_PHI = 16, // PHI: [ty, val0,bb0, ...]
|
| 614 |
+
// 17 is unused.
|
| 615 |
+
// 18 is unused.
|
| 616 |
+
FUNC_CODE_INST_ALLOCA = 19, // ALLOCA: [instty, opty, op, align]
|
| 617 |
+
FUNC_CODE_INST_LOAD = 20, // LOAD: [opty, op, align, vol]
|
| 618 |
+
// 21 is unused.
|
| 619 |
+
// 22 is unused.
|
| 620 |
+
FUNC_CODE_INST_VAARG = 23, // VAARG: [valistty, valist, instty]
|
| 621 |
+
// This store code encodes the pointer type, rather than the value type
|
| 622 |
+
// this is so information only available in the pointer type (e.g. address
|
| 623 |
+
// spaces) is retained.
|
| 624 |
+
FUNC_CODE_INST_STORE_OLD = 24, // STORE: [ptrty,ptr,val, align, vol]
|
| 625 |
+
// 25 is unused.
|
| 626 |
+
FUNC_CODE_INST_EXTRACTVAL = 26, // EXTRACTVAL: [n x operands]
|
| 627 |
+
FUNC_CODE_INST_INSERTVAL = 27, // INSERTVAL: [n x operands]
|
| 628 |
+
// fcmp/icmp returning Int1TY or vector of Int1Ty. Same as CMP, exists to
|
| 629 |
+
// support legacy vicmp/vfcmp instructions.
|
| 630 |
+
FUNC_CODE_INST_CMP2 = 28, // CMP2: [opty, opval, opval, pred]
|
| 631 |
+
// new select on i1 or [N x i1]
|
| 632 |
+
FUNC_CODE_INST_VSELECT = 29, // VSELECT: [ty,opval,opval,predty,pred]
|
| 633 |
+
FUNC_CODE_INST_INBOUNDS_GEP_OLD = 30, // INBOUNDS_GEP: [n x operands]
|
| 634 |
+
FUNC_CODE_INST_INDIRECTBR = 31, // INDIRECTBR: [opty, op0, op1, ...]
|
| 635 |
+
// 32 is unused.
|
| 636 |
+
FUNC_CODE_DEBUG_LOC_AGAIN = 33, // DEBUG_LOC_AGAIN
|
| 637 |
+
|
| 638 |
+
FUNC_CODE_INST_CALL = 34, // CALL: [attr, cc, fnty, fnid, args...]
|
| 639 |
+
|
| 640 |
+
FUNC_CODE_DEBUG_LOC = 35, // DEBUG_LOC: [Line,Col,ScopeVal, IAVal]
|
| 641 |
+
FUNC_CODE_INST_FENCE = 36, // FENCE: [ordering, synchscope]
|
| 642 |
+
FUNC_CODE_INST_CMPXCHG_OLD = 37, // CMPXCHG: [ptrty, ptr, cmp, val, vol,
|
| 643 |
+
// ordering, synchscope,
|
| 644 |
+
// failure_ordering?, weak?]
|
| 645 |
+
FUNC_CODE_INST_ATOMICRMW_OLD = 38, // ATOMICRMW: [ptrty,ptr,val, operation,
|
| 646 |
+
// align, vol,
|
| 647 |
+
// ordering, synchscope]
|
| 648 |
+
FUNC_CODE_INST_RESUME = 39, // RESUME: [opval]
|
| 649 |
+
FUNC_CODE_INST_LANDINGPAD_OLD =
|
| 650 |
+
40, // LANDINGPAD: [ty,val,val,num,id0,val0...]
|
| 651 |
+
FUNC_CODE_INST_LOADATOMIC = 41, // LOAD: [opty, op, align, vol,
|
| 652 |
+
// ordering, synchscope]
|
| 653 |
+
FUNC_CODE_INST_STOREATOMIC_OLD = 42, // STORE: [ptrty,ptr,val, align, vol
|
| 654 |
+
// ordering, synchscope]
|
| 655 |
+
FUNC_CODE_INST_GEP = 43, // GEP: [inbounds, n x operands]
|
| 656 |
+
FUNC_CODE_INST_STORE = 44, // STORE: [ptrty,ptr,valty,val, align, vol]
|
| 657 |
+
FUNC_CODE_INST_STOREATOMIC = 45, // STORE: [ptrty,ptr,val, align, vol
|
| 658 |
+
FUNC_CODE_INST_CMPXCHG = 46, // CMPXCHG: [ptrty, ptr, cmp, val, vol,
|
| 659 |
+
// success_ordering, synchscope,
|
| 660 |
+
// failure_ordering, weak]
|
| 661 |
+
FUNC_CODE_INST_LANDINGPAD = 47, // LANDINGPAD: [ty,val,num,id0,val0...]
|
| 662 |
+
FUNC_CODE_INST_CLEANUPRET = 48, // CLEANUPRET: [val] or [val,bb#]
|
| 663 |
+
FUNC_CODE_INST_CATCHRET = 49, // CATCHRET: [val,bb#]
|
| 664 |
+
FUNC_CODE_INST_CATCHPAD = 50, // CATCHPAD: [bb#,bb#,num,args...]
|
| 665 |
+
FUNC_CODE_INST_CLEANUPPAD = 51, // CLEANUPPAD: [num,args...]
|
| 666 |
+
FUNC_CODE_INST_CATCHSWITCH =
|
| 667 |
+
52, // CATCHSWITCH: [num,args...] or [num,args...,bb]
|
| 668 |
+
// 53 is unused.
|
| 669 |
+
// 54 is unused.
|
| 670 |
+
FUNC_CODE_OPERAND_BUNDLE = 55, // OPERAND_BUNDLE: [tag#, value...]
|
| 671 |
+
FUNC_CODE_INST_UNOP = 56, // UNOP: [opcode, ty, opval]
|
| 672 |
+
FUNC_CODE_INST_CALLBR = 57, // CALLBR: [attr, cc, norm, transfs,
|
| 673 |
+
// fnty, fnid, args...]
|
| 674 |
+
FUNC_CODE_INST_FREEZE = 58, // FREEZE: [opty, opval]
|
| 675 |
+
FUNC_CODE_INST_ATOMICRMW = 59, // ATOMICRMW: [ptrty, ptr, valty, val,
|
| 676 |
+
// operation, align, vol,
|
| 677 |
+
// ordering, synchscope]
|
| 678 |
+
FUNC_CODE_BLOCKADDR_USERS = 60, // BLOCKADDR_USERS: [value...]
|
| 679 |
+
|
| 680 |
+
FUNC_CODE_DEBUG_RECORD_VALUE =
|
| 681 |
+
61, // [DILocation, DILocalVariable, DIExpression, ValueAsMetadata]
|
| 682 |
+
FUNC_CODE_DEBUG_RECORD_DECLARE =
|
| 683 |
+
62, // [DILocation, DILocalVariable, DIExpression, ValueAsMetadata]
|
| 684 |
+
FUNC_CODE_DEBUG_RECORD_ASSIGN =
|
| 685 |
+
63, // [DILocation, DILocalVariable, DIExpression, ValueAsMetadata,
|
| 686 |
+
// DIAssignID, DIExpression (addr), ValueAsMetadata (addr)]
|
| 687 |
+
FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE =
|
| 688 |
+
64, // [DILocation, DILocalVariable, DIExpression, Value]
|
| 689 |
+
FUNC_CODE_DEBUG_RECORD_LABEL = 65, // [DILocation, DILabel]
|
| 690 |
+
};
|
| 691 |
+
|
| 692 |
+
enum UseListCodes {
|
| 693 |
+
USELIST_CODE_DEFAULT = 1, // DEFAULT: [index..., value-id]
|
| 694 |
+
USELIST_CODE_BB = 2 // BB: [index..., bb-id]
|
| 695 |
+
};
|
| 696 |
+
|
| 697 |
+
enum AttributeKindCodes {
|
| 698 |
+
// = 0 is unused
|
| 699 |
+
ATTR_KIND_ALIGNMENT = 1,
|
| 700 |
+
ATTR_KIND_ALWAYS_INLINE = 2,
|
| 701 |
+
ATTR_KIND_BY_VAL = 3,
|
| 702 |
+
ATTR_KIND_INLINE_HINT = 4,
|
| 703 |
+
ATTR_KIND_IN_REG = 5,
|
| 704 |
+
ATTR_KIND_MIN_SIZE = 6,
|
| 705 |
+
ATTR_KIND_NAKED = 7,
|
| 706 |
+
ATTR_KIND_NEST = 8,
|
| 707 |
+
ATTR_KIND_NO_ALIAS = 9,
|
| 708 |
+
ATTR_KIND_NO_BUILTIN = 10,
|
| 709 |
+
ATTR_KIND_NO_CAPTURE = 11,
|
| 710 |
+
ATTR_KIND_NO_DUPLICATE = 12,
|
| 711 |
+
ATTR_KIND_NO_IMPLICIT_FLOAT = 13,
|
| 712 |
+
ATTR_KIND_NO_INLINE = 14,
|
| 713 |
+
ATTR_KIND_NON_LAZY_BIND = 15,
|
| 714 |
+
ATTR_KIND_NO_RED_ZONE = 16,
|
| 715 |
+
ATTR_KIND_NO_RETURN = 17,
|
| 716 |
+
ATTR_KIND_NO_UNWIND = 18,
|
| 717 |
+
ATTR_KIND_OPTIMIZE_FOR_SIZE = 19,
|
| 718 |
+
ATTR_KIND_READ_NONE = 20,
|
| 719 |
+
ATTR_KIND_READ_ONLY = 21,
|
| 720 |
+
ATTR_KIND_RETURNED = 22,
|
| 721 |
+
ATTR_KIND_RETURNS_TWICE = 23,
|
| 722 |
+
ATTR_KIND_S_EXT = 24,
|
| 723 |
+
ATTR_KIND_STACK_ALIGNMENT = 25,
|
| 724 |
+
ATTR_KIND_STACK_PROTECT = 26,
|
| 725 |
+
ATTR_KIND_STACK_PROTECT_REQ = 27,
|
| 726 |
+
ATTR_KIND_STACK_PROTECT_STRONG = 28,
|
| 727 |
+
ATTR_KIND_STRUCT_RET = 29,
|
| 728 |
+
ATTR_KIND_SANITIZE_ADDRESS = 30,
|
| 729 |
+
ATTR_KIND_SANITIZE_THREAD = 31,
|
| 730 |
+
ATTR_KIND_SANITIZE_MEMORY = 32,
|
| 731 |
+
ATTR_KIND_UW_TABLE = 33,
|
| 732 |
+
ATTR_KIND_Z_EXT = 34,
|
| 733 |
+
ATTR_KIND_BUILTIN = 35,
|
| 734 |
+
ATTR_KIND_COLD = 36,
|
| 735 |
+
ATTR_KIND_OPTIMIZE_NONE = 37,
|
| 736 |
+
ATTR_KIND_IN_ALLOCA = 38,
|
| 737 |
+
ATTR_KIND_NON_NULL = 39,
|
| 738 |
+
ATTR_KIND_JUMP_TABLE = 40,
|
| 739 |
+
ATTR_KIND_DEREFERENCEABLE = 41,
|
| 740 |
+
ATTR_KIND_DEREFERENCEABLE_OR_NULL = 42,
|
| 741 |
+
ATTR_KIND_CONVERGENT = 43,
|
| 742 |
+
ATTR_KIND_SAFESTACK = 44,
|
| 743 |
+
ATTR_KIND_ARGMEMONLY = 45,
|
| 744 |
+
ATTR_KIND_SWIFT_SELF = 46,
|
| 745 |
+
ATTR_KIND_SWIFT_ERROR = 47,
|
| 746 |
+
ATTR_KIND_NO_RECURSE = 48,
|
| 747 |
+
ATTR_KIND_INACCESSIBLEMEM_ONLY = 49,
|
| 748 |
+
ATTR_KIND_INACCESSIBLEMEM_OR_ARGMEMONLY = 50,
|
| 749 |
+
ATTR_KIND_ALLOC_SIZE = 51,
|
| 750 |
+
ATTR_KIND_WRITEONLY = 52,
|
| 751 |
+
ATTR_KIND_SPECULATABLE = 53,
|
| 752 |
+
ATTR_KIND_STRICT_FP = 54,
|
| 753 |
+
ATTR_KIND_SANITIZE_HWADDRESS = 55,
|
| 754 |
+
ATTR_KIND_NOCF_CHECK = 56,
|
| 755 |
+
ATTR_KIND_OPT_FOR_FUZZING = 57,
|
| 756 |
+
ATTR_KIND_SHADOWCALLSTACK = 58,
|
| 757 |
+
ATTR_KIND_SPECULATIVE_LOAD_HARDENING = 59,
|
| 758 |
+
ATTR_KIND_IMMARG = 60,
|
| 759 |
+
ATTR_KIND_WILLRETURN = 61,
|
| 760 |
+
ATTR_KIND_NOFREE = 62,
|
| 761 |
+
ATTR_KIND_NOSYNC = 63,
|
| 762 |
+
ATTR_KIND_SANITIZE_MEMTAG = 64,
|
| 763 |
+
ATTR_KIND_PREALLOCATED = 65,
|
| 764 |
+
ATTR_KIND_NO_MERGE = 66,
|
| 765 |
+
ATTR_KIND_NULL_POINTER_IS_VALID = 67,
|
| 766 |
+
ATTR_KIND_NOUNDEF = 68,
|
| 767 |
+
ATTR_KIND_BYREF = 69,
|
| 768 |
+
ATTR_KIND_MUSTPROGRESS = 70,
|
| 769 |
+
ATTR_KIND_NO_CALLBACK = 71,
|
| 770 |
+
ATTR_KIND_HOT = 72,
|
| 771 |
+
ATTR_KIND_NO_PROFILE = 73,
|
| 772 |
+
ATTR_KIND_VSCALE_RANGE = 74,
|
| 773 |
+
ATTR_KIND_SWIFT_ASYNC = 75,
|
| 774 |
+
ATTR_KIND_NO_SANITIZE_COVERAGE = 76,
|
| 775 |
+
ATTR_KIND_ELEMENTTYPE = 77,
|
| 776 |
+
ATTR_KIND_DISABLE_SANITIZER_INSTRUMENTATION = 78,
|
| 777 |
+
ATTR_KIND_NO_SANITIZE_BOUNDS = 79,
|
| 778 |
+
ATTR_KIND_ALLOC_ALIGN = 80,
|
| 779 |
+
ATTR_KIND_ALLOCATED_POINTER = 81,
|
| 780 |
+
ATTR_KIND_ALLOC_KIND = 82,
|
| 781 |
+
ATTR_KIND_PRESPLIT_COROUTINE = 83,
|
| 782 |
+
ATTR_KIND_FNRETTHUNK_EXTERN = 84,
|
| 783 |
+
ATTR_KIND_SKIP_PROFILE = 85,
|
| 784 |
+
ATTR_KIND_MEMORY = 86,
|
| 785 |
+
ATTR_KIND_NOFPCLASS = 87,
|
| 786 |
+
ATTR_KIND_OPTIMIZE_FOR_DEBUGGING = 88,
|
| 787 |
+
ATTR_KIND_WRITABLE = 89,
|
| 788 |
+
ATTR_KIND_CORO_ONLY_DESTROY_WHEN_COMPLETE = 90,
|
| 789 |
+
ATTR_KIND_DEAD_ON_UNWIND = 91,
|
| 790 |
+
ATTR_KIND_RANGE = 92,
|
| 791 |
+
ATTR_KIND_SANITIZE_NUMERICAL_STABILITY = 93,
|
| 792 |
+
ATTR_KIND_INITIALIZES = 94,
|
| 793 |
+
ATTR_KIND_HYBRID_PATCHABLE = 95,
|
| 794 |
+
ATTR_KIND_SANITIZE_REALTIME = 96,
|
| 795 |
+
ATTR_KIND_SANITIZE_REALTIME_BLOCKING = 97,
|
| 796 |
+
ATTR_KIND_CORO_ELIDE_SAFE = 98,
|
| 797 |
+
ATTR_KIND_NO_EXT = 99,
|
| 798 |
+
ATTR_KIND_NO_DIVERGENCE_SOURCE = 100,
|
| 799 |
+
ATTR_KIND_SANITIZE_TYPE = 101,
|
| 800 |
+
ATTR_KIND_CAPTURES = 102,
|
| 801 |
+
};
|
| 802 |
+
|
| 803 |
+
enum ComdatSelectionKindCodes {
|
| 804 |
+
COMDAT_SELECTION_KIND_ANY = 1,
|
| 805 |
+
COMDAT_SELECTION_KIND_EXACT_MATCH = 2,
|
| 806 |
+
COMDAT_SELECTION_KIND_LARGEST = 3,
|
| 807 |
+
COMDAT_SELECTION_KIND_NO_DUPLICATES = 4,
|
| 808 |
+
COMDAT_SELECTION_KIND_SAME_SIZE = 5,
|
| 809 |
+
};
|
| 810 |
+
|
| 811 |
+
enum StrtabCodes {
|
| 812 |
+
STRTAB_BLOB = 1,
|
| 813 |
+
};
|
| 814 |
+
|
| 815 |
+
enum SymtabCodes {
|
| 816 |
+
SYMTAB_BLOB = 1,
|
| 817 |
+
};
|
| 818 |
+
|
| 819 |
+
} // End bitc namespace
|
| 820 |
+
} // End llvm namespace
|
| 821 |
+
|
| 822 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/Support/AdvisoryLock.h
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===----------------------------------------------------------------------===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
|
| 9 |
+
#ifndef LLVM_SUPPORT_ADVISORYLOCK_H
|
| 10 |
+
#define LLVM_SUPPORT_ADVISORYLOCK_H
|
| 11 |
+
|
| 12 |
+
#include "llvm/Support/Error.h"
|
| 13 |
+
|
| 14 |
+
#include <chrono>
|
| 15 |
+
|
| 16 |
+
namespace llvm {
|
| 17 |
+
/// Describes the result of waiting for the owner to release the lock.
|
| 18 |
+
enum class WaitForUnlockResult {
|
| 19 |
+
/// The lock was released successfully.
|
| 20 |
+
Success,
|
| 21 |
+
/// Owner died while holding the lock.
|
| 22 |
+
OwnerDied,
|
| 23 |
+
/// Reached timeout while waiting for the owner to release the lock.
|
| 24 |
+
Timeout,
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
/// A synchronization primitive with weak mutual exclusion guarantees.
|
| 28 |
+
/// Implementations of this interface may allow multiple threads/processes to
|
| 29 |
+
/// acquire the ownership of the lock simultaneously.
|
| 30 |
+
/// Typically, threads/processes waiting for the lock to be unlocked will
|
| 31 |
+
/// validate that the computation was performed by the expected thread/process
|
| 32 |
+
/// and re-run the computation if not.
|
| 33 |
+
class AdvisoryLock {
|
| 34 |
+
public:
|
| 35 |
+
/// Tries to acquire ownership of the lock without blocking.
|
| 36 |
+
///
|
| 37 |
+
/// \returns true if ownership of the lock was acquired successfully, false if
|
| 38 |
+
/// the lock is already owned by someone else, or \c Error in case of an
|
| 39 |
+
/// unexpected failure.
|
| 40 |
+
virtual Expected<bool> tryLock() = 0;
|
| 41 |
+
|
| 42 |
+
/// For a lock owned by someone else, wait until it is unlocked.
|
| 43 |
+
///
|
| 44 |
+
/// \param MaxSeconds the maximum total wait time in seconds.
|
| 45 |
+
virtual WaitForUnlockResult
|
| 46 |
+
waitForUnlockFor(std::chrono::seconds MaxSeconds) = 0;
|
| 47 |
+
|
| 48 |
+
/// For a lock owned by someone else, unlock it. A permitted side-effect is
|
| 49 |
+
/// that another thread/process may acquire ownership of the lock before the
|
| 50 |
+
/// existing owner unlocks it. This is an unsafe operation.
|
| 51 |
+
virtual std::error_code unsafeMaybeUnlock() = 0;
|
| 52 |
+
|
| 53 |
+
/// Unlocks the lock if its ownership was previously acquired by \c tryLock().
|
| 54 |
+
virtual ~AdvisoryLock() = default;
|
| 55 |
+
};
|
| 56 |
+
} // end namespace llvm
|
| 57 |
+
|
| 58 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/Support/FileSystem/UniqueID.h
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- llvm/Support/FileSystem/UniqueID.h - UniqueID for files --*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file is cut out of llvm/Support/FileSystem.h to allow UniqueID to be
|
| 10 |
+
// reused without bloating the includes.
|
| 11 |
+
//
|
| 12 |
+
//===----------------------------------------------------------------------===//
|
| 13 |
+
|
| 14 |
+
#ifndef LLVM_SUPPORT_FILESYSTEM_UNIQUEID_H
|
| 15 |
+
#define LLVM_SUPPORT_FILESYSTEM_UNIQUEID_H
|
| 16 |
+
|
| 17 |
+
#include "llvm/ADT/DenseMapInfo.h"
|
| 18 |
+
#include "llvm/ADT/Hashing.h"
|
| 19 |
+
#include <cstdint>
|
| 20 |
+
#include <utility>
|
| 21 |
+
|
| 22 |
+
namespace llvm {
|
| 23 |
+
namespace sys {
|
| 24 |
+
namespace fs {
|
| 25 |
+
|
| 26 |
+
class UniqueID {
|
| 27 |
+
uint64_t Device;
|
| 28 |
+
uint64_t File;
|
| 29 |
+
|
| 30 |
+
public:
|
| 31 |
+
UniqueID() = default;
|
| 32 |
+
UniqueID(uint64_t Device, uint64_t File) : Device(Device), File(File) {}
|
| 33 |
+
|
| 34 |
+
bool operator==(const UniqueID &Other) const {
|
| 35 |
+
return Device == Other.Device && File == Other.File;
|
| 36 |
+
}
|
| 37 |
+
bool operator!=(const UniqueID &Other) const { return !(*this == Other); }
|
| 38 |
+
bool operator<(const UniqueID &Other) const {
|
| 39 |
+
/// Don't use std::tie since it bloats the compile time of this header.
|
| 40 |
+
if (Device < Other.Device)
|
| 41 |
+
return true;
|
| 42 |
+
if (Other.Device < Device)
|
| 43 |
+
return false;
|
| 44 |
+
return File < Other.File;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
uint64_t getDevice() const { return Device; }
|
| 48 |
+
uint64_t getFile() const { return File; }
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
} // end namespace fs
|
| 52 |
+
} // end namespace sys
|
| 53 |
+
|
| 54 |
+
// Support UniqueIDs as DenseMap keys.
|
| 55 |
+
template <> struct DenseMapInfo<llvm::sys::fs::UniqueID> {
|
| 56 |
+
static inline llvm::sys::fs::UniqueID getEmptyKey() {
|
| 57 |
+
auto EmptyKey = DenseMapInfo<std::pair<uint64_t, uint64_t>>::getEmptyKey();
|
| 58 |
+
return {EmptyKey.first, EmptyKey.second};
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
static inline llvm::sys::fs::UniqueID getTombstoneKey() {
|
| 62 |
+
auto TombstoneKey =
|
| 63 |
+
DenseMapInfo<std::pair<uint64_t, uint64_t>>::getTombstoneKey();
|
| 64 |
+
return {TombstoneKey.first, TombstoneKey.second};
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
static hash_code getHashValue(const llvm::sys::fs::UniqueID &Tag) {
|
| 68 |
+
return hash_value(std::make_pair(Tag.getDevice(), Tag.getFile()));
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
static bool isEqual(const llvm::sys::fs::UniqueID &LHS,
|
| 72 |
+
const llvm::sys::fs::UniqueID &RHS) {
|
| 73 |
+
return LHS == RHS;
|
| 74 |
+
}
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
} // end namespace llvm
|
| 78 |
+
|
| 79 |
+
#endif // LLVM_SUPPORT_FILESYSTEM_UNIQUEID_H
|
deps/exla/cache/xla_extension/include/llvm/Support/MSVCErrorWorkarounds.h
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===--- MSVCErrorWorkarounds.h - Enable future<Error> in MSVC --*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// MSVC's promise/future implementation requires types to be default
|
| 10 |
+
// constructible, so this header provides analogues of Error an Expected
|
| 11 |
+
// that are default constructed in a safely destructible state.
|
| 12 |
+
//
|
| 13 |
+
// FIXME: Kill off this header and migrate all users to Error/Expected once we
|
| 14 |
+
// move to MSVC versions that support non-default-constructible types.
|
| 15 |
+
//
|
| 16 |
+
//===----------------------------------------------------------------------===//
|
| 17 |
+
|
| 18 |
+
#ifndef LLVM_SUPPORT_MSVCERRORWORKAROUNDS_H
|
| 19 |
+
#define LLVM_SUPPORT_MSVCERRORWORKAROUNDS_H
|
| 20 |
+
|
| 21 |
+
#include "llvm/Support/Error.h"
|
| 22 |
+
|
| 23 |
+
namespace llvm {
|
| 24 |
+
|
| 25 |
+
// A default-constructible llvm::Error that is suitable for use with MSVC's
|
| 26 |
+
// std::future implementation which requires default constructible types.
|
| 27 |
+
class MSVCPError : public Error {
|
| 28 |
+
public:
|
| 29 |
+
MSVCPError() { (void)!!*this; }
|
| 30 |
+
|
| 31 |
+
MSVCPError(MSVCPError &&Other) : Error(std::move(Other)) {}
|
| 32 |
+
|
| 33 |
+
MSVCPError &operator=(MSVCPError Other) {
|
| 34 |
+
Error::operator=(std::move(Other));
|
| 35 |
+
return *this;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
MSVCPError(Error Err) : Error(std::move(Err)) {}
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
// A default-constructible llvm::Expected that is suitable for use with MSVC's
|
| 42 |
+
// std::future implementation, which requires default constructible types.
|
| 43 |
+
template <typename T> class MSVCPExpected : public Expected<T> {
|
| 44 |
+
public:
|
| 45 |
+
MSVCPExpected()
|
| 46 |
+
: Expected<T>(make_error<StringError>("", inconvertibleErrorCode())) {
|
| 47 |
+
consumeError(this->takeError());
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
MSVCPExpected(MSVCPExpected &&Other) : Expected<T>(std::move(Other)) {}
|
| 51 |
+
|
| 52 |
+
MSVCPExpected &operator=(MSVCPExpected &&Other) {
|
| 53 |
+
Expected<T>::operator=(std::move(Other));
|
| 54 |
+
return *this;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
MSVCPExpected(Error Err) : Expected<T>(std::move(Err)) {}
|
| 58 |
+
|
| 59 |
+
template <typename OtherT>
|
| 60 |
+
MSVCPExpected(
|
| 61 |
+
OtherT &&Val,
|
| 62 |
+
std::enable_if_t<std::is_convertible<OtherT, T>::value> * = nullptr)
|
| 63 |
+
: Expected<T>(std::move(Val)) {}
|
| 64 |
+
|
| 65 |
+
template <class OtherT>
|
| 66 |
+
MSVCPExpected(
|
| 67 |
+
Expected<OtherT> &&Other,
|
| 68 |
+
std::enable_if_t<std::is_convertible<OtherT, T>::value> * = nullptr)
|
| 69 |
+
: Expected<T>(std::move(Other)) {}
|
| 70 |
+
|
| 71 |
+
template <class OtherT>
|
| 72 |
+
explicit MSVCPExpected(
|
| 73 |
+
Expected<OtherT> &&Other,
|
| 74 |
+
std::enable_if_t<!std::is_convertible<OtherT, T>::value> * = nullptr)
|
| 75 |
+
: Expected<T>(std::move(Other)) {}
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
} // end namespace llvm
|
| 79 |
+
|
| 80 |
+
#endif // LLVM_SUPPORT_MSVCERRORWORKAROUNDS_H
|
deps/exla/cache/xla_extension/include/llvm/Support/Solaris/sys/regset.h
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*===- llvm/Support/Solaris/sys/regset.h ------------------------*- C++ -*-===*
|
| 2 |
+
*
|
| 3 |
+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
* See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
*
|
| 7 |
+
*===----------------------------------------------------------------------===*
|
| 8 |
+
*
|
| 9 |
+
* This file works around excessive name space pollution from the system header
|
| 10 |
+
* on Solaris hosts.
|
| 11 |
+
*
|
| 12 |
+
*===----------------------------------------------------------------------===*/
|
| 13 |
+
|
| 14 |
+
#ifndef LLVM_SUPPORT_SOLARIS_SYS_REGSET_H
|
| 15 |
+
|
| 16 |
+
#include_next <sys/regset.h>
|
| 17 |
+
|
| 18 |
+
#undef CS
|
| 19 |
+
#undef DS
|
| 20 |
+
#undef ES
|
| 21 |
+
#undef FS
|
| 22 |
+
#undef GS
|
| 23 |
+
#undef SS
|
| 24 |
+
#undef EAX
|
| 25 |
+
#undef ECX
|
| 26 |
+
#undef EDX
|
| 27 |
+
#undef EBX
|
| 28 |
+
#undef ESP
|
| 29 |
+
#undef EBP
|
| 30 |
+
#undef ESI
|
| 31 |
+
#undef EDI
|
| 32 |
+
#undef EIP
|
| 33 |
+
#undef UESP
|
| 34 |
+
#undef EFL
|
| 35 |
+
#undef ERR
|
| 36 |
+
#undef TRAPNO
|
| 37 |
+
|
| 38 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/Support/SystemZ/zOSSupport.h
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- zOSSupport.h - Common z/OS Include File ------------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file defines z/OS implementations for common functions.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_SUPPORT_ZOSSUPPORT_H
|
| 14 |
+
#define LLVM_SUPPORT_ZOSSUPPORT_H
|
| 15 |
+
|
| 16 |
+
#ifdef __MVS__
|
| 17 |
+
#include <sys/resource.h>
|
| 18 |
+
#include <sys/wait.h>
|
| 19 |
+
|
| 20 |
+
// z/OS Unix System Services does not have strsignal() support, so the
|
| 21 |
+
// strsignal() function is implemented here.
|
| 22 |
+
inline char *strsignal(int sig) {
|
| 23 |
+
static char msg[256];
|
| 24 |
+
sprintf(msg, "%d", sig);
|
| 25 |
+
return msg;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
// z/OS Unix System Services does not have wait4() support, so the wait4
|
| 29 |
+
// function is implemented here.
|
| 30 |
+
inline pid_t wait4(pid_t pid, int *wstatus, int options,
|
| 31 |
+
struct rusage *rusage) {
|
| 32 |
+
pid_t Result = waitpid(pid, wstatus, options);
|
| 33 |
+
int GetrusageRC = getrusage(RUSAGE_CHILDREN, rusage);
|
| 34 |
+
assert(!GetrusageRC && "Must have valid measure of the resources!");
|
| 35 |
+
return Result;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
// z/OS Unix System Services does not have strnlen() support, so the strnlen()
|
| 39 |
+
// function is implemented here.
|
| 40 |
+
inline std::size_t strnlen(const char *S, std::size_t MaxLen) {
|
| 41 |
+
const char *PtrToNullChar =
|
| 42 |
+
static_cast<const char *>(std::memchr(S, '\0', MaxLen));
|
| 43 |
+
return PtrToNullChar ? PtrToNullChar - S : MaxLen;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
#endif
|
| 47 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/Support/Windows/WindowsSupport.h
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- WindowsSupport.h - Common Windows Include File -----------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file defines things specific to Windows implementations. In addition to
|
| 10 |
+
// providing some helpers for working with win32 APIs, this header wraps
|
| 11 |
+
// <windows.h> with some portability macros. Always include WindowsSupport.h
|
| 12 |
+
// instead of including <windows.h> directly.
|
| 13 |
+
//
|
| 14 |
+
//===----------------------------------------------------------------------===//
|
| 15 |
+
|
| 16 |
+
//===----------------------------------------------------------------------===//
|
| 17 |
+
//=== WARNING: Implementation here must contain only generic Win32 code that
|
| 18 |
+
//=== is guaranteed to work on *all* Win32 variants.
|
| 19 |
+
//===----------------------------------------------------------------------===//
|
| 20 |
+
|
| 21 |
+
#ifndef LLVM_SUPPORT_WINDOWSSUPPORT_H
|
| 22 |
+
#define LLVM_SUPPORT_WINDOWSSUPPORT_H
|
| 23 |
+
|
| 24 |
+
// mingw-w64 tends to define it as 0x0502 in its headers.
|
| 25 |
+
#undef _WIN32_WINNT
|
| 26 |
+
|
| 27 |
+
// Require at least Windows 7 API.
|
| 28 |
+
#define _WIN32_WINNT 0x0601
|
| 29 |
+
#define WIN32_LEAN_AND_MEAN
|
| 30 |
+
#ifndef NOMINMAX
|
| 31 |
+
#define NOMINMAX
|
| 32 |
+
#endif
|
| 33 |
+
|
| 34 |
+
#include "llvm/ADT/SmallVector.h"
|
| 35 |
+
#include "llvm/ADT/StringExtras.h"
|
| 36 |
+
#include "llvm/ADT/StringRef.h"
|
| 37 |
+
#include "llvm/ADT/Twine.h"
|
| 38 |
+
#include "llvm/Config/llvm-config.h" // Get build system configuration settings
|
| 39 |
+
#include "llvm/Support/Allocator.h"
|
| 40 |
+
#include "llvm/Support/Chrono.h"
|
| 41 |
+
#include "llvm/Support/Compiler.h"
|
| 42 |
+
#include "llvm/Support/ErrorHandling.h"
|
| 43 |
+
#include "llvm/Support/VersionTuple.h"
|
| 44 |
+
#include <cassert>
|
| 45 |
+
#include <string>
|
| 46 |
+
#include <system_error>
|
| 47 |
+
#include <windows.h>
|
| 48 |
+
|
| 49 |
+
// Must be included after windows.h
|
| 50 |
+
#include <wincrypt.h>
|
| 51 |
+
|
| 52 |
+
namespace llvm {
|
| 53 |
+
|
| 54 |
+
/// Determines if the program is running on Windows 8 or newer. This
|
| 55 |
+
/// reimplements one of the helpers in the Windows 8.1 SDK, which are intended
|
| 56 |
+
/// to supercede raw calls to GetVersionEx. Old SDKs, Cygwin, and MinGW don't
|
| 57 |
+
/// yet have VersionHelpers.h, so we have our own helper.
|
| 58 |
+
LLVM_ABI bool RunningWindows8OrGreater();
|
| 59 |
+
|
| 60 |
+
/// Determines if the program is running on Windows 11 or Windows Server 2022.
|
| 61 |
+
LLVM_ABI bool RunningWindows11OrGreater();
|
| 62 |
+
|
| 63 |
+
/// Returns the Windows version as Major.Minor.0.BuildNumber. Uses
|
| 64 |
+
/// RtlGetVersion or GetVersionEx under the hood depending on what is available.
|
| 65 |
+
/// GetVersionEx is deprecated, but this API exposes the build number which can
|
| 66 |
+
/// be useful for working around certain kernel bugs.
|
| 67 |
+
LLVM_ABI llvm::VersionTuple GetWindowsOSVersion();
|
| 68 |
+
|
| 69 |
+
LLVM_ABI bool MakeErrMsg(std::string *ErrMsg, const std::string &prefix);
|
| 70 |
+
|
| 71 |
+
// Include GetLastError() in a fatal error message.
|
| 72 |
+
[[noreturn]] inline void ReportLastErrorFatal(const char *Msg) {
|
| 73 |
+
std::string ErrMsg;
|
| 74 |
+
MakeErrMsg(&ErrMsg, Msg);
|
| 75 |
+
llvm::report_fatal_error(Twine(ErrMsg));
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
template <typename HandleTraits>
|
| 79 |
+
class ScopedHandle {
|
| 80 |
+
typedef typename HandleTraits::handle_type handle_type;
|
| 81 |
+
handle_type Handle;
|
| 82 |
+
|
| 83 |
+
ScopedHandle(const ScopedHandle &other) = delete;
|
| 84 |
+
void operator=(const ScopedHandle &other) = delete;
|
| 85 |
+
public:
|
| 86 |
+
ScopedHandle()
|
| 87 |
+
: Handle(HandleTraits::GetInvalid()) {}
|
| 88 |
+
|
| 89 |
+
explicit ScopedHandle(handle_type h)
|
| 90 |
+
: Handle(h) {}
|
| 91 |
+
|
| 92 |
+
~ScopedHandle() {
|
| 93 |
+
if (HandleTraits::IsValid(Handle))
|
| 94 |
+
HandleTraits::Close(Handle);
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
handle_type take() {
|
| 98 |
+
handle_type t = Handle;
|
| 99 |
+
Handle = HandleTraits::GetInvalid();
|
| 100 |
+
return t;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
ScopedHandle &operator=(handle_type h) {
|
| 104 |
+
if (HandleTraits::IsValid(Handle))
|
| 105 |
+
HandleTraits::Close(Handle);
|
| 106 |
+
Handle = h;
|
| 107 |
+
return *this;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
// True if Handle is valid.
|
| 111 |
+
explicit operator bool() const {
|
| 112 |
+
return HandleTraits::IsValid(Handle) ? true : false;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
operator handle_type() const {
|
| 116 |
+
return Handle;
|
| 117 |
+
}
|
| 118 |
+
};
|
| 119 |
+
|
| 120 |
+
struct CommonHandleTraits {
|
| 121 |
+
typedef HANDLE handle_type;
|
| 122 |
+
|
| 123 |
+
static handle_type GetInvalid() {
|
| 124 |
+
return INVALID_HANDLE_VALUE;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
static void Close(handle_type h) {
|
| 128 |
+
::CloseHandle(h);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
static bool IsValid(handle_type h) {
|
| 132 |
+
return h != GetInvalid();
|
| 133 |
+
}
|
| 134 |
+
};
|
| 135 |
+
|
| 136 |
+
struct JobHandleTraits : CommonHandleTraits {
|
| 137 |
+
static handle_type GetInvalid() {
|
| 138 |
+
return NULL;
|
| 139 |
+
}
|
| 140 |
+
};
|
| 141 |
+
|
| 142 |
+
struct CryptContextTraits : CommonHandleTraits {
|
| 143 |
+
typedef HCRYPTPROV handle_type;
|
| 144 |
+
|
| 145 |
+
static handle_type GetInvalid() {
|
| 146 |
+
return 0;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
static void Close(handle_type h) {
|
| 150 |
+
::CryptReleaseContext(h, 0);
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
static bool IsValid(handle_type h) {
|
| 154 |
+
return h != GetInvalid();
|
| 155 |
+
}
|
| 156 |
+
};
|
| 157 |
+
|
| 158 |
+
struct RegTraits : CommonHandleTraits {
|
| 159 |
+
typedef HKEY handle_type;
|
| 160 |
+
|
| 161 |
+
static handle_type GetInvalid() {
|
| 162 |
+
return NULL;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
static void Close(handle_type h) {
|
| 166 |
+
::RegCloseKey(h);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
static bool IsValid(handle_type h) {
|
| 170 |
+
return h != GetInvalid();
|
| 171 |
+
}
|
| 172 |
+
};
|
| 173 |
+
|
| 174 |
+
struct FindHandleTraits : CommonHandleTraits {
|
| 175 |
+
static void Close(handle_type h) {
|
| 176 |
+
::FindClose(h);
|
| 177 |
+
}
|
| 178 |
+
};
|
| 179 |
+
|
| 180 |
+
struct FileHandleTraits : CommonHandleTraits {};
|
| 181 |
+
|
| 182 |
+
typedef ScopedHandle<CommonHandleTraits> ScopedCommonHandle;
|
| 183 |
+
typedef ScopedHandle<FileHandleTraits> ScopedFileHandle;
|
| 184 |
+
typedef ScopedHandle<CryptContextTraits> ScopedCryptContext;
|
| 185 |
+
typedef ScopedHandle<RegTraits> ScopedRegHandle;
|
| 186 |
+
typedef ScopedHandle<FindHandleTraits> ScopedFindHandle;
|
| 187 |
+
typedef ScopedHandle<JobHandleTraits> ScopedJobHandle;
|
| 188 |
+
|
| 189 |
+
template <class T>
|
| 190 |
+
class SmallVectorImpl;
|
| 191 |
+
|
| 192 |
+
template <class T>
|
| 193 |
+
typename SmallVectorImpl<T>::const_pointer
|
| 194 |
+
c_str(SmallVectorImpl<T> &str) {
|
| 195 |
+
str.push_back(0);
|
| 196 |
+
str.pop_back();
|
| 197 |
+
return str.data();
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
namespace sys {
|
| 201 |
+
|
| 202 |
+
inline std::chrono::nanoseconds toDuration(FILETIME Time) {
|
| 203 |
+
ULARGE_INTEGER TimeInteger;
|
| 204 |
+
TimeInteger.LowPart = Time.dwLowDateTime;
|
| 205 |
+
TimeInteger.HighPart = Time.dwHighDateTime;
|
| 206 |
+
|
| 207 |
+
// FILETIME's are # of 100 nanosecond ticks (1/10th of a microsecond)
|
| 208 |
+
return std::chrono::nanoseconds(100 * TimeInteger.QuadPart);
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
inline TimePoint<> toTimePoint(FILETIME Time) {
|
| 212 |
+
ULARGE_INTEGER TimeInteger;
|
| 213 |
+
TimeInteger.LowPart = Time.dwLowDateTime;
|
| 214 |
+
TimeInteger.HighPart = Time.dwHighDateTime;
|
| 215 |
+
|
| 216 |
+
// Adjust for different epoch
|
| 217 |
+
TimeInteger.QuadPart -= 11644473600ll * 10000000;
|
| 218 |
+
|
| 219 |
+
// FILETIME's are # of 100 nanosecond ticks (1/10th of a microsecond)
|
| 220 |
+
return TimePoint<>(std::chrono::nanoseconds(100 * TimeInteger.QuadPart));
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
inline FILETIME toFILETIME(TimePoint<> TP) {
|
| 224 |
+
ULARGE_INTEGER TimeInteger;
|
| 225 |
+
TimeInteger.QuadPart = TP.time_since_epoch().count() / 100;
|
| 226 |
+
TimeInteger.QuadPart += 11644473600ll * 10000000;
|
| 227 |
+
|
| 228 |
+
FILETIME Time;
|
| 229 |
+
Time.dwLowDateTime = TimeInteger.LowPart;
|
| 230 |
+
Time.dwHighDateTime = TimeInteger.HighPart;
|
| 231 |
+
return Time;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
namespace windows {
|
| 235 |
+
// Returns command line arguments. Unlike arguments given to main(),
|
| 236 |
+
// this function guarantees that the returned arguments are encoded in
|
| 237 |
+
// UTF-8 regardless of the current code page setting.
|
| 238 |
+
LLVM_ABI std::error_code
|
| 239 |
+
GetCommandLineArguments(SmallVectorImpl<const char *> &Args,
|
| 240 |
+
BumpPtrAllocator &Alloc);
|
| 241 |
+
|
| 242 |
+
/// Convert UTF-8 path to a suitable UTF-16 path for use with the Win32 Unicode
|
| 243 |
+
/// File API.
|
| 244 |
+
LLVM_ABI std::error_code widenPath(const Twine &Path8,
|
| 245 |
+
SmallVectorImpl<wchar_t> &Path16,
|
| 246 |
+
size_t MaxPathLen = MAX_PATH);
|
| 247 |
+
|
| 248 |
+
} // end namespace windows
|
| 249 |
+
} // end namespace sys
|
| 250 |
+
} // end namespace llvm.
|
| 251 |
+
|
| 252 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/_virtual_includes/X86CommonTableGen/X86GenDAGISel.inc
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a5639d0e4b14799929c20c1b7fd5659c741902e8a2f4823ae2bf38aa8bf51906
|
| 3 |
+
size 28802632
|
deps/exla/cache/xla_extension/include/llvm/lib/Bitcode/Reader/MetadataLoader.h
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===-- Bitcode/Reader/MetadataLoader.h - Load Metadatas -------*- C++ -*-====//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This class handles loading Metadatas.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_LIB_BITCODE_READER_METADATALOADER_H
|
| 14 |
+
#define LLVM_LIB_BITCODE_READER_METADATALOADER_H
|
| 15 |
+
|
| 16 |
+
#include "llvm/Support/Error.h"
|
| 17 |
+
|
| 18 |
+
#include <functional>
|
| 19 |
+
#include <memory>
|
| 20 |
+
|
| 21 |
+
namespace llvm {
|
| 22 |
+
class BasicBlock;
|
| 23 |
+
class BitcodeReaderValueList;
|
| 24 |
+
class BitstreamCursor;
|
| 25 |
+
class DISubprogram;
|
| 26 |
+
class Function;
|
| 27 |
+
class Instruction;
|
| 28 |
+
class Metadata;
|
| 29 |
+
class Module;
|
| 30 |
+
class Type;
|
| 31 |
+
template <typename T> class ArrayRef;
|
| 32 |
+
|
| 33 |
+
typedef std::function<Type *(unsigned)> GetTypeByIDTy;
|
| 34 |
+
|
| 35 |
+
typedef std::function<unsigned(unsigned, unsigned)> GetContainedTypeIDTy;
|
| 36 |
+
|
| 37 |
+
typedef std::function<void(Metadata **, unsigned, GetTypeByIDTy,
|
| 38 |
+
GetContainedTypeIDTy)>
|
| 39 |
+
MDTypeCallbackTy;
|
| 40 |
+
|
| 41 |
+
struct MetadataLoaderCallbacks {
|
| 42 |
+
GetTypeByIDTy GetTypeByID;
|
| 43 |
+
GetContainedTypeIDTy GetContainedTypeID;
|
| 44 |
+
std::optional<MDTypeCallbackTy> MDType;
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
/// Helper class that handles loading Metadatas and keeping them available.
|
| 48 |
+
class MetadataLoader {
|
| 49 |
+
class MetadataLoaderImpl;
|
| 50 |
+
std::unique_ptr<MetadataLoaderImpl> Pimpl;
|
| 51 |
+
Error parseMetadata(bool ModuleLevel);
|
| 52 |
+
|
| 53 |
+
public:
|
| 54 |
+
~MetadataLoader();
|
| 55 |
+
MetadataLoader(BitstreamCursor &Stream, Module &TheModule,
|
| 56 |
+
BitcodeReaderValueList &ValueList, bool IsImporting,
|
| 57 |
+
MetadataLoaderCallbacks Callbacks);
|
| 58 |
+
MetadataLoader &operator=(MetadataLoader &&);
|
| 59 |
+
MetadataLoader(MetadataLoader &&);
|
| 60 |
+
|
| 61 |
+
// Parse a module metadata block
|
| 62 |
+
Error parseModuleMetadata() { return parseMetadata(true); }
|
| 63 |
+
|
| 64 |
+
// Parse a function metadata block
|
| 65 |
+
Error parseFunctionMetadata() { return parseMetadata(false); }
|
| 66 |
+
|
| 67 |
+
/// Set the mode to strip TBAA metadata on load.
|
| 68 |
+
void setStripTBAA(bool StripTBAA = true);
|
| 69 |
+
|
| 70 |
+
/// Return true if the Loader is stripping TBAA metadata.
|
| 71 |
+
bool isStrippingTBAA();
|
| 72 |
+
|
| 73 |
+
// Return true there are remaining unresolved forward references.
|
| 74 |
+
bool hasFwdRefs() const;
|
| 75 |
+
|
| 76 |
+
/// Return the given metadata, creating a replaceable forward reference if
|
| 77 |
+
/// necessary.
|
| 78 |
+
Metadata *getMetadataFwdRefOrLoad(unsigned Idx);
|
| 79 |
+
|
| 80 |
+
/// Return the DISubprogram metadata for a Function if any, null otherwise.
|
| 81 |
+
DISubprogram *lookupSubprogramForFunction(Function *F);
|
| 82 |
+
|
| 83 |
+
/// Parse a `METADATA_ATTACHMENT` block for a function.
|
| 84 |
+
Error parseMetadataAttachment(Function &F,
|
| 85 |
+
ArrayRef<Instruction *> InstructionList);
|
| 86 |
+
|
| 87 |
+
/// Parse a `METADATA_KIND` block for the current module.
|
| 88 |
+
Error parseMetadataKinds();
|
| 89 |
+
|
| 90 |
+
unsigned size() const;
|
| 91 |
+
void shrinkTo(unsigned N);
|
| 92 |
+
|
| 93 |
+
/// Perform bitcode upgrades on llvm.dbg.* calls.
|
| 94 |
+
void upgradeDebugIntrinsics(Function &F);
|
| 95 |
+
};
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
#endif // LLVM_LIB_BITCODE_READER_METADATALOADER_H
|
deps/exla/cache/xla_extension/include/llvm/lib/Bitcode/Reader/ValueList.h
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===-- Bitcode/Reader/ValueList.h - Number values --------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This class gives values and types Unique ID's.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_LIB_BITCODE_READER_VALUELIST_H
|
| 14 |
+
#define LLVM_LIB_BITCODE_READER_VALUELIST_H
|
| 15 |
+
|
| 16 |
+
#include "llvm/IR/ValueHandle.h"
|
| 17 |
+
#include "llvm/Support/Error.h"
|
| 18 |
+
#include <cassert>
|
| 19 |
+
#include <utility>
|
| 20 |
+
#include <vector>
|
| 21 |
+
|
| 22 |
+
namespace llvm {
|
| 23 |
+
|
| 24 |
+
class Error;
|
| 25 |
+
class Type;
|
| 26 |
+
class Value;
|
| 27 |
+
|
| 28 |
+
class BitcodeReaderValueList {
|
| 29 |
+
/// Maps Value ID to pair of Value* and Type ID.
|
| 30 |
+
std::vector<std::pair<WeakTrackingVH, unsigned>> ValuePtrs;
|
| 31 |
+
|
| 32 |
+
/// Maximum number of valid references. Forward references exceeding the
|
| 33 |
+
/// maximum must be invalid.
|
| 34 |
+
unsigned RefsUpperBound;
|
| 35 |
+
|
| 36 |
+
using MaterializeValueFnTy =
|
| 37 |
+
std::function<Expected<Value *>(unsigned, BasicBlock *)>;
|
| 38 |
+
MaterializeValueFnTy MaterializeValueFn;
|
| 39 |
+
|
| 40 |
+
public:
|
| 41 |
+
BitcodeReaderValueList(size_t RefsUpperBound,
|
| 42 |
+
MaterializeValueFnTy MaterializeValueFn)
|
| 43 |
+
: RefsUpperBound(std::min((size_t)std::numeric_limits<unsigned>::max(),
|
| 44 |
+
RefsUpperBound)),
|
| 45 |
+
MaterializeValueFn(MaterializeValueFn) {}
|
| 46 |
+
|
| 47 |
+
// vector compatibility methods
|
| 48 |
+
unsigned size() const { return ValuePtrs.size(); }
|
| 49 |
+
void resize(unsigned N) {
|
| 50 |
+
ValuePtrs.resize(N);
|
| 51 |
+
}
|
| 52 |
+
void push_back(Value *V, unsigned TypeID) {
|
| 53 |
+
ValuePtrs.emplace_back(V, TypeID);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
void clear() {
|
| 57 |
+
ValuePtrs.clear();
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
Value *operator[](unsigned i) const {
|
| 61 |
+
assert(i < ValuePtrs.size());
|
| 62 |
+
return ValuePtrs[i].first;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
unsigned getTypeID(unsigned ValNo) const {
|
| 66 |
+
assert(ValNo < ValuePtrs.size());
|
| 67 |
+
return ValuePtrs[ValNo].second;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
Value *back() const { return ValuePtrs.back().first; }
|
| 71 |
+
void pop_back() {
|
| 72 |
+
ValuePtrs.pop_back();
|
| 73 |
+
}
|
| 74 |
+
bool empty() const { return ValuePtrs.empty(); }
|
| 75 |
+
|
| 76 |
+
void shrinkTo(unsigned N) {
|
| 77 |
+
assert(N <= size() && "Invalid shrinkTo request!");
|
| 78 |
+
ValuePtrs.resize(N);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
void replaceValueWithoutRAUW(unsigned ValNo, Value *NewV) {
|
| 82 |
+
assert(ValNo < ValuePtrs.size());
|
| 83 |
+
ValuePtrs[ValNo].first = NewV;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
Value *getValueFwdRef(unsigned Idx, Type *Ty, unsigned TyID,
|
| 87 |
+
BasicBlock *ConstExprInsertBB);
|
| 88 |
+
|
| 89 |
+
Error assignValue(unsigned Idx, Value *V, unsigned TypeID);
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
} // end namespace llvm
|
| 93 |
+
|
| 94 |
+
#endif // LLVM_LIB_BITCODE_READER_VALUELIST_H
|
deps/exla/cache/xla_extension/include/llvm/lib/Bitcode/Writer/ValueEnumerator.h
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- Bitcode/Writer/ValueEnumerator.h - Number values ---------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This class gives values and types Unique ID's.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_LIB_BITCODE_WRITER_VALUEENUMERATOR_H
|
| 14 |
+
#define LLVM_LIB_BITCODE_WRITER_VALUEENUMERATOR_H
|
| 15 |
+
|
| 16 |
+
#include "llvm/ADT/ArrayRef.h"
|
| 17 |
+
#include "llvm/ADT/DenseMap.h"
|
| 18 |
+
#include "llvm/ADT/UniqueVector.h"
|
| 19 |
+
#include "llvm/IR/Attributes.h"
|
| 20 |
+
#include "llvm/IR/UseListOrder.h"
|
| 21 |
+
#include <cassert>
|
| 22 |
+
#include <cstdint>
|
| 23 |
+
#include <utility>
|
| 24 |
+
#include <vector>
|
| 25 |
+
|
| 26 |
+
namespace llvm {
|
| 27 |
+
|
| 28 |
+
class BasicBlock;
|
| 29 |
+
class Comdat;
|
| 30 |
+
class DIArgList;
|
| 31 |
+
class Function;
|
| 32 |
+
class Instruction;
|
| 33 |
+
class LocalAsMetadata;
|
| 34 |
+
class MDNode;
|
| 35 |
+
class Metadata;
|
| 36 |
+
class Module;
|
| 37 |
+
class NamedMDNode;
|
| 38 |
+
class raw_ostream;
|
| 39 |
+
class Type;
|
| 40 |
+
class Value;
|
| 41 |
+
class ValueSymbolTable;
|
| 42 |
+
|
| 43 |
+
class ValueEnumerator {
|
| 44 |
+
public:
|
| 45 |
+
using TypeList = std::vector<Type *>;
|
| 46 |
+
|
| 47 |
+
// For each value, we remember its Value* and occurrence frequency.
|
| 48 |
+
using ValueList = std::vector<std::pair<const Value *, unsigned>>;
|
| 49 |
+
|
| 50 |
+
/// Attribute groups as encoded in bitcode are almost AttributeSets, but they
|
| 51 |
+
/// include the AttributeList index, so we have to track that in our map.
|
| 52 |
+
using IndexAndAttrSet = std::pair<unsigned, AttributeSet>;
|
| 53 |
+
|
| 54 |
+
UseListOrderStack UseListOrders;
|
| 55 |
+
|
| 56 |
+
private:
|
| 57 |
+
using TypeMapType = DenseMap<Type *, unsigned>;
|
| 58 |
+
TypeMapType TypeMap;
|
| 59 |
+
TypeList Types;
|
| 60 |
+
|
| 61 |
+
using ValueMapType = DenseMap<const Value *, unsigned>;
|
| 62 |
+
ValueMapType ValueMap;
|
| 63 |
+
ValueList Values;
|
| 64 |
+
|
| 65 |
+
using ComdatSetType = UniqueVector<const Comdat *>;
|
| 66 |
+
ComdatSetType Comdats;
|
| 67 |
+
|
| 68 |
+
std::vector<const Metadata *> MDs;
|
| 69 |
+
std::vector<const Metadata *> FunctionMDs;
|
| 70 |
+
|
| 71 |
+
/// Index of information about a piece of metadata.
|
| 72 |
+
struct MDIndex {
|
| 73 |
+
unsigned F = 0; ///< The ID of the function for this metadata, if any.
|
| 74 |
+
unsigned ID = 0; ///< The implicit ID of this metadata in bitcode.
|
| 75 |
+
|
| 76 |
+
MDIndex() = default;
|
| 77 |
+
explicit MDIndex(unsigned F) : F(F) {}
|
| 78 |
+
|
| 79 |
+
/// Check if this has a function tag, and it's different from NewF.
|
| 80 |
+
bool hasDifferentFunction(unsigned NewF) const { return F && F != NewF; }
|
| 81 |
+
|
| 82 |
+
/// Fetch the MD this references out of the given metadata array.
|
| 83 |
+
const Metadata *get(ArrayRef<const Metadata *> MDs) const {
|
| 84 |
+
assert(ID && "Expected non-zero ID");
|
| 85 |
+
assert(ID <= MDs.size() && "Expected valid ID");
|
| 86 |
+
return MDs[ID - 1];
|
| 87 |
+
}
|
| 88 |
+
};
|
| 89 |
+
|
| 90 |
+
using MetadataMapType = DenseMap<const Metadata *, MDIndex>;
|
| 91 |
+
MetadataMapType MetadataMap;
|
| 92 |
+
|
| 93 |
+
/// Range of metadata IDs, as a half-open range.
|
| 94 |
+
struct MDRange {
|
| 95 |
+
unsigned First = 0;
|
| 96 |
+
unsigned Last = 0;
|
| 97 |
+
|
| 98 |
+
/// Number of strings in the prefix of the metadata range.
|
| 99 |
+
unsigned NumStrings = 0;
|
| 100 |
+
|
| 101 |
+
MDRange() = default;
|
| 102 |
+
explicit MDRange(unsigned First) : First(First) {}
|
| 103 |
+
};
|
| 104 |
+
SmallDenseMap<unsigned, MDRange, 1> FunctionMDInfo;
|
| 105 |
+
|
| 106 |
+
bool ShouldPreserveUseListOrder;
|
| 107 |
+
|
| 108 |
+
using AttributeGroupMapType = DenseMap<IndexAndAttrSet, unsigned>;
|
| 109 |
+
AttributeGroupMapType AttributeGroupMap;
|
| 110 |
+
std::vector<IndexAndAttrSet> AttributeGroups;
|
| 111 |
+
|
| 112 |
+
using AttributeListMapType = DenseMap<AttributeList, unsigned>;
|
| 113 |
+
AttributeListMapType AttributeListMap;
|
| 114 |
+
std::vector<AttributeList> AttributeLists;
|
| 115 |
+
|
| 116 |
+
/// GlobalBasicBlockIDs - This map memoizes the basic block ID's referenced by
|
| 117 |
+
/// the "getGlobalBasicBlockID" method.
|
| 118 |
+
mutable DenseMap<const BasicBlock*, unsigned> GlobalBasicBlockIDs;
|
| 119 |
+
|
| 120 |
+
using InstructionMapType = DenseMap<const Instruction *, unsigned>;
|
| 121 |
+
InstructionMapType InstructionMap;
|
| 122 |
+
unsigned InstructionCount;
|
| 123 |
+
|
| 124 |
+
/// BasicBlocks - This contains all the basic blocks for the currently
|
| 125 |
+
/// incorporated function. Their reverse mapping is stored in ValueMap.
|
| 126 |
+
std::vector<const BasicBlock*> BasicBlocks;
|
| 127 |
+
|
| 128 |
+
/// When a function is incorporated, this is the size of the Values list
|
| 129 |
+
/// before incorporation.
|
| 130 |
+
unsigned NumModuleValues;
|
| 131 |
+
|
| 132 |
+
/// When a function is incorporated, this is the size of the Metadatas list
|
| 133 |
+
/// before incorporation.
|
| 134 |
+
unsigned NumModuleMDs = 0;
|
| 135 |
+
unsigned NumMDStrings = 0;
|
| 136 |
+
|
| 137 |
+
unsigned FirstFuncConstantID;
|
| 138 |
+
unsigned FirstInstID;
|
| 139 |
+
|
| 140 |
+
public:
|
| 141 |
+
ValueEnumerator(const Module &M, bool ShouldPreserveUseListOrder);
|
| 142 |
+
ValueEnumerator(const ValueEnumerator &) = delete;
|
| 143 |
+
ValueEnumerator &operator=(const ValueEnumerator &) = delete;
|
| 144 |
+
|
| 145 |
+
void dump() const;
|
| 146 |
+
void print(raw_ostream &OS, const ValueMapType &Map, const char *Name) const;
|
| 147 |
+
void print(raw_ostream &OS, const MetadataMapType &Map,
|
| 148 |
+
const char *Name) const;
|
| 149 |
+
|
| 150 |
+
unsigned getValueID(const Value *V) const;
|
| 151 |
+
|
| 152 |
+
unsigned getMetadataID(const Metadata *MD) const {
|
| 153 |
+
auto ID = getMetadataOrNullID(MD);
|
| 154 |
+
assert(ID != 0 && "Metadata not in slotcalculator!");
|
| 155 |
+
return ID - 1;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
unsigned getMetadataOrNullID(const Metadata *MD) const {
|
| 159 |
+
return MetadataMap.lookup(MD).ID;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
unsigned numMDs() const { return MDs.size(); }
|
| 163 |
+
|
| 164 |
+
bool shouldPreserveUseListOrder() const { return ShouldPreserveUseListOrder; }
|
| 165 |
+
|
| 166 |
+
unsigned getTypeID(Type *T) const {
|
| 167 |
+
TypeMapType::const_iterator I = TypeMap.find(T);
|
| 168 |
+
assert(I != TypeMap.end() && "Type not in ValueEnumerator!");
|
| 169 |
+
return I->second-1;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
unsigned getInstructionID(const Instruction *I) const;
|
| 173 |
+
void setInstructionID(const Instruction *I);
|
| 174 |
+
|
| 175 |
+
unsigned getAttributeListID(AttributeList PAL) const {
|
| 176 |
+
if (PAL.isEmpty()) return 0; // Null maps to zero.
|
| 177 |
+
AttributeListMapType::const_iterator I = AttributeListMap.find(PAL);
|
| 178 |
+
assert(I != AttributeListMap.end() && "Attribute not in ValueEnumerator!");
|
| 179 |
+
return I->second;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
unsigned getAttributeGroupID(IndexAndAttrSet Group) const {
|
| 183 |
+
if (!Group.second.hasAttributes())
|
| 184 |
+
return 0; // Null maps to zero.
|
| 185 |
+
AttributeGroupMapType::const_iterator I = AttributeGroupMap.find(Group);
|
| 186 |
+
assert(I != AttributeGroupMap.end() && "Attribute not in ValueEnumerator!");
|
| 187 |
+
return I->second;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
/// getFunctionConstantRange - Return the range of values that corresponds to
|
| 191 |
+
/// function-local constants.
|
| 192 |
+
void getFunctionConstantRange(unsigned &Start, unsigned &End) const {
|
| 193 |
+
Start = FirstFuncConstantID;
|
| 194 |
+
End = FirstInstID;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
const ValueList &getValues() const { return Values; }
|
| 198 |
+
|
| 199 |
+
/// Check whether the current block has any metadata to emit.
|
| 200 |
+
bool hasMDs() const { return NumModuleMDs < MDs.size(); }
|
| 201 |
+
|
| 202 |
+
/// Get the MDString metadata for this block.
|
| 203 |
+
ArrayRef<const Metadata *> getMDStrings() const {
|
| 204 |
+
return ArrayRef(MDs).slice(NumModuleMDs, NumMDStrings);
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
/// Get the non-MDString metadata for this block.
|
| 208 |
+
ArrayRef<const Metadata *> getNonMDStrings() const {
|
| 209 |
+
return ArrayRef(MDs).slice(NumModuleMDs).slice(NumMDStrings);
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
const TypeList &getTypes() const { return Types; }
|
| 213 |
+
|
| 214 |
+
const std::vector<const BasicBlock*> &getBasicBlocks() const {
|
| 215 |
+
return BasicBlocks;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
const std::vector<AttributeList> &getAttributeLists() const { return AttributeLists; }
|
| 219 |
+
|
| 220 |
+
const std::vector<IndexAndAttrSet> &getAttributeGroups() const {
|
| 221 |
+
return AttributeGroups;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
const ComdatSetType &getComdats() const { return Comdats; }
|
| 225 |
+
unsigned getComdatID(const Comdat *C) const;
|
| 226 |
+
|
| 227 |
+
/// getGlobalBasicBlockID - This returns the function-specific ID for the
|
| 228 |
+
/// specified basic block. This is relatively expensive information, so it
|
| 229 |
+
/// should only be used by rare constructs such as address-of-label.
|
| 230 |
+
unsigned getGlobalBasicBlockID(const BasicBlock *BB) const;
|
| 231 |
+
|
| 232 |
+
/// incorporateFunction/purgeFunction - If you'd like to deal with a function,
|
| 233 |
+
/// use these two methods to get its data into the ValueEnumerator!
|
| 234 |
+
void incorporateFunction(const Function &F);
|
| 235 |
+
|
| 236 |
+
void purgeFunction();
|
| 237 |
+
uint64_t computeBitsRequiredForTypeIndices() const;
|
| 238 |
+
|
| 239 |
+
private:
|
| 240 |
+
void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
|
| 241 |
+
|
| 242 |
+
/// Reorder the reachable metadata.
|
| 243 |
+
///
|
| 244 |
+
/// This is not just an optimization, but is mandatory for emitting MDString
|
| 245 |
+
/// correctly.
|
| 246 |
+
void organizeMetadata();
|
| 247 |
+
|
| 248 |
+
/// Drop the function tag from the transitive operands of the given node.
|
| 249 |
+
void dropFunctionFromMetadata(MetadataMapType::value_type &FirstMD);
|
| 250 |
+
|
| 251 |
+
/// Incorporate the function metadata.
|
| 252 |
+
///
|
| 253 |
+
/// This should be called before enumerating LocalAsMetadata for the
|
| 254 |
+
/// function.
|
| 255 |
+
void incorporateFunctionMetadata(const Function &F);
|
| 256 |
+
|
| 257 |
+
/// Enumerate a single instance of metadata with the given function tag.
|
| 258 |
+
///
|
| 259 |
+
/// If \c MD has already been enumerated, check that \c F matches its
|
| 260 |
+
/// function tag. If not, call \a dropFunctionFromMetadata().
|
| 261 |
+
///
|
| 262 |
+
/// Otherwise, mark \c MD as visited. Assign it an ID, or just return it if
|
| 263 |
+
/// it's an \a MDNode.
|
| 264 |
+
const MDNode *enumerateMetadataImpl(unsigned F, const Metadata *MD);
|
| 265 |
+
|
| 266 |
+
unsigned getMetadataFunctionID(const Function *F) const;
|
| 267 |
+
|
| 268 |
+
/// Enumerate reachable metadata in (almost) post-order.
|
| 269 |
+
///
|
| 270 |
+
/// Enumerate all the metadata reachable from MD. We want to minimize the
|
| 271 |
+
/// cost of reading bitcode records, and so the primary consideration is that
|
| 272 |
+
/// operands of uniqued nodes are resolved before the nodes are read. This
|
| 273 |
+
/// avoids re-uniquing them on the context and factors away RAUW support.
|
| 274 |
+
///
|
| 275 |
+
/// This algorithm guarantees that subgraphs of uniqued nodes are in
|
| 276 |
+
/// post-order. Distinct subgraphs reachable only from a single uniqued node
|
| 277 |
+
/// will be in post-order.
|
| 278 |
+
///
|
| 279 |
+
/// \note The relative order of a distinct and uniqued node is irrelevant.
|
| 280 |
+
/// \a organizeMetadata() will later partition distinct nodes ahead of
|
| 281 |
+
/// uniqued ones.
|
| 282 |
+
///{
|
| 283 |
+
void EnumerateMetadata(const Function *F, const Metadata *MD);
|
| 284 |
+
void EnumerateMetadata(unsigned F, const Metadata *MD);
|
| 285 |
+
///}
|
| 286 |
+
|
| 287 |
+
void EnumerateFunctionLocalMetadata(const Function &F,
|
| 288 |
+
const LocalAsMetadata *Local);
|
| 289 |
+
void EnumerateFunctionLocalMetadata(unsigned F, const LocalAsMetadata *Local);
|
| 290 |
+
void EnumerateFunctionLocalListMetadata(const Function &F,
|
| 291 |
+
const DIArgList *ArgList);
|
| 292 |
+
void EnumerateFunctionLocalListMetadata(unsigned F, const DIArgList *Arglist);
|
| 293 |
+
void EnumerateNamedMDNode(const NamedMDNode *NMD);
|
| 294 |
+
void EnumerateValue(const Value *V);
|
| 295 |
+
void EnumerateType(Type *T);
|
| 296 |
+
void EnumerateOperandType(const Value *V);
|
| 297 |
+
void EnumerateAttributes(AttributeList PAL);
|
| 298 |
+
|
| 299 |
+
void EnumerateValueSymbolTable(const ValueSymbolTable &ST);
|
| 300 |
+
void EnumerateNamedMetadata(const Module &M);
|
| 301 |
+
};
|
| 302 |
+
|
| 303 |
+
} // end namespace llvm
|
| 304 |
+
|
| 305 |
+
#endif // LLVM_LIB_BITCODE_WRITER_VALUEENUMERATOR_H
|
deps/exla/cache/xla_extension/include/llvm/lib/MC/MCDisassembler/Disassembler.h
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===------------- Disassembler.h - LLVM Disassembler -----------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file defines the interface for the Disassembly library's disassembler
|
| 10 |
+
// context. The disassembler is responsible for producing strings for
|
| 11 |
+
// individual instructions according to a given architecture and disassembly
|
| 12 |
+
// syntax.
|
| 13 |
+
//
|
| 14 |
+
//===----------------------------------------------------------------------===//
|
| 15 |
+
|
| 16 |
+
#ifndef LLVM_LIB_MC_MCDISASSEMBLER_DISASSEMBLER_H
|
| 17 |
+
#define LLVM_LIB_MC_MCDISASSEMBLER_DISASSEMBLER_H
|
| 18 |
+
|
| 19 |
+
#include "llvm-c/DisassemblerTypes.h"
|
| 20 |
+
#include "llvm/ADT/SmallString.h"
|
| 21 |
+
#include "llvm/MC/MCAsmInfo.h"
|
| 22 |
+
#include "llvm/MC/MCContext.h"
|
| 23 |
+
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
|
| 24 |
+
#include "llvm/MC/MCInstPrinter.h"
|
| 25 |
+
#include "llvm/MC/MCInstrInfo.h"
|
| 26 |
+
#include "llvm/MC/MCRegisterInfo.h"
|
| 27 |
+
#include "llvm/MC/MCSubtargetInfo.h"
|
| 28 |
+
#include "llvm/Support/raw_ostream.h"
|
| 29 |
+
#include <string>
|
| 30 |
+
#include <utility>
|
| 31 |
+
|
| 32 |
+
namespace llvm {
|
| 33 |
+
class Target;
|
| 34 |
+
|
| 35 |
+
//
|
| 36 |
+
// This is the disassembler context returned by LLVMCreateDisasm().
|
| 37 |
+
//
|
| 38 |
+
class LLVMDisasmContext {
|
| 39 |
+
private:
|
| 40 |
+
//
|
| 41 |
+
// The passed parameters when the disassembler context is created.
|
| 42 |
+
//
|
| 43 |
+
// The TripleName for this disassembler.
|
| 44 |
+
std::string TripleName;
|
| 45 |
+
// The pointer to the caller's block of symbolic information.
|
| 46 |
+
void *DisInfo;
|
| 47 |
+
// The Triple specific symbolic information type returned by GetOpInfo.
|
| 48 |
+
int TagType;
|
| 49 |
+
// The function to get the symbolic information for operands.
|
| 50 |
+
LLVMOpInfoCallback GetOpInfo;
|
| 51 |
+
// The function to look up a symbol name.
|
| 52 |
+
LLVMSymbolLookupCallback SymbolLookUp;
|
| 53 |
+
//
|
| 54 |
+
// The objects created and saved by LLVMCreateDisasm() then used by
|
| 55 |
+
// LLVMDisasmInstruction().
|
| 56 |
+
//
|
| 57 |
+
// The LLVM target corresponding to the disassembler.
|
| 58 |
+
// FIXME: using std::unique_ptr<const llvm::Target> causes a malloc error
|
| 59 |
+
// when this LLVMDisasmContext is deleted.
|
| 60 |
+
const Target *TheTarget;
|
| 61 |
+
// The assembly information for the target architecture.
|
| 62 |
+
std::unique_ptr<const llvm::MCAsmInfo> MAI;
|
| 63 |
+
// The register information for the target architecture.
|
| 64 |
+
std::unique_ptr<const llvm::MCRegisterInfo> MRI;
|
| 65 |
+
// The subtarget information for the target architecture.
|
| 66 |
+
std::unique_ptr<const llvm::MCSubtargetInfo> MSI;
|
| 67 |
+
// The instruction information for the target architecture.
|
| 68 |
+
std::unique_ptr<const llvm::MCInstrInfo> MII;
|
| 69 |
+
// The assembly context for creating symbols and MCExprs.
|
| 70 |
+
std::unique_ptr<const llvm::MCContext> Ctx;
|
| 71 |
+
// The disassembler for the target architecture.
|
| 72 |
+
std::unique_ptr<const llvm::MCDisassembler> DisAsm;
|
| 73 |
+
// The instruction printer for the target architecture.
|
| 74 |
+
std::unique_ptr<llvm::MCInstPrinter> IP;
|
| 75 |
+
// The options used to set up the disassembler.
|
| 76 |
+
uint64_t Options;
|
| 77 |
+
// The CPU string.
|
| 78 |
+
std::string CPU;
|
| 79 |
+
|
| 80 |
+
public:
|
| 81 |
+
// Comment stream and backing vector.
|
| 82 |
+
SmallString<128> CommentsToEmit;
|
| 83 |
+
raw_svector_ostream CommentStream;
|
| 84 |
+
|
| 85 |
+
LLVMDisasmContext(std::string TripleName, void *DisInfo, int TagType,
|
| 86 |
+
LLVMOpInfoCallback GetOpInfo,
|
| 87 |
+
LLVMSymbolLookupCallback SymbolLookUp,
|
| 88 |
+
const Target *TheTarget,
|
| 89 |
+
std::unique_ptr<const MCAsmInfo> &&MAI,
|
| 90 |
+
std::unique_ptr<const MCRegisterInfo> &&MRI,
|
| 91 |
+
std::unique_ptr<const MCSubtargetInfo> &&MSI,
|
| 92 |
+
std::unique_ptr<const MCInstrInfo> &&MII,
|
| 93 |
+
std::unique_ptr<const llvm::MCContext> &&Ctx,
|
| 94 |
+
std::unique_ptr<const MCDisassembler> &&DisAsm,
|
| 95 |
+
std::unique_ptr<MCInstPrinter> &&IP)
|
| 96 |
+
: TripleName(std::move(TripleName)), DisInfo(DisInfo), TagType(TagType),
|
| 97 |
+
GetOpInfo(GetOpInfo), SymbolLookUp(SymbolLookUp), TheTarget(TheTarget),
|
| 98 |
+
MAI(std::move(MAI)), MRI(std::move(MRI)), MSI(std::move(MSI)),
|
| 99 |
+
MII(std::move(MII)), Ctx(std::move(Ctx)), DisAsm(std::move(DisAsm)),
|
| 100 |
+
IP(std::move(IP)), Options(0), CommentStream(CommentsToEmit) {}
|
| 101 |
+
const std::string &getTripleName() const { return TripleName; }
|
| 102 |
+
void *getDisInfo() const { return DisInfo; }
|
| 103 |
+
int getTagType() const { return TagType; }
|
| 104 |
+
LLVMOpInfoCallback getGetOpInfo() const { return GetOpInfo; }
|
| 105 |
+
LLVMSymbolLookupCallback getSymbolLookupCallback() const {
|
| 106 |
+
return SymbolLookUp;
|
| 107 |
+
}
|
| 108 |
+
const Target *getTarget() const { return TheTarget; }
|
| 109 |
+
const MCDisassembler *getDisAsm() const { return DisAsm.get(); }
|
| 110 |
+
const MCAsmInfo *getAsmInfo() const { return MAI.get(); }
|
| 111 |
+
const MCInstrInfo *getInstrInfo() const { return MII.get(); }
|
| 112 |
+
const MCRegisterInfo *getRegisterInfo() const { return MRI.get(); }
|
| 113 |
+
const MCSubtargetInfo *getSubtargetInfo() const { return MSI.get(); }
|
| 114 |
+
MCInstPrinter *getIP() { return IP.get(); }
|
| 115 |
+
void setIP(MCInstPrinter *NewIP) { IP.reset(NewIP); }
|
| 116 |
+
uint64_t getOptions() const { return Options; }
|
| 117 |
+
void addOptions(uint64_t Options) { this->Options |= Options; }
|
| 118 |
+
StringRef getCPU() const { return CPU; }
|
| 119 |
+
void setCPU(const char *CPU) { this->CPU = CPU; }
|
| 120 |
+
};
|
| 121 |
+
|
| 122 |
+
} // namespace llvm
|
| 123 |
+
|
| 124 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/lib/Passes/PassRegistry.def
ADDED
|
@@ -0,0 +1,738 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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LVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file is used as the registry of passes that are part of the core LLVM
|
| 10 |
+
// libraries. This file describes both transformation passes and analyses
|
| 11 |
+
// Analyses are registered while transformation passes have names registered
|
| 12 |
+
// that can be used when providing a textual pass pipeline.
|
| 13 |
+
//
|
| 14 |
+
//===----------------------------------------------------------------------===//
|
| 15 |
+
|
| 16 |
+
// NOTE: NO INCLUDE GUARD DESIRED!
|
| 17 |
+
|
| 18 |
+
#ifndef MODULE_ANALYSIS
|
| 19 |
+
#define MODULE_ANALYSIS(NAME, CREATE_PASS)
|
| 20 |
+
#endif
|
| 21 |
+
MODULE_ANALYSIS("callgraph", CallGraphAnalysis())
|
| 22 |
+
MODULE_ANALYSIS("collector-metadata", CollectorMetadataAnalysis())
|
| 23 |
+
MODULE_ANALYSIS("ctx-prof-analysis", CtxProfAnalysis())
|
| 24 |
+
MODULE_ANALYSIS("dxil-metadata", DXILMetadataAnalysis())
|
| 25 |
+
MODULE_ANALYSIS("dxil-resources", DXILResourceAnalysis())
|
| 26 |
+
MODULE_ANALYSIS("dxil-resource-type", DXILResourceTypeAnalysis())
|
| 27 |
+
MODULE_ANALYSIS("dxil-resource-bindings", DXILResourceBindingAnalysis())
|
| 28 |
+
MODULE_ANALYSIS("inline-advisor", InlineAdvisorAnalysis())
|
| 29 |
+
MODULE_ANALYSIS("ir2vec-vocab", IR2VecVocabAnalysis())
|
| 30 |
+
MODULE_ANALYSIS("ir-similarity", IRSimilarityAnalysis())
|
| 31 |
+
MODULE_ANALYSIS("last-run-tracking", LastRunTrackingAnalysis())
|
| 32 |
+
MODULE_ANALYSIS("lcg", LazyCallGraphAnalysis())
|
| 33 |
+
MODULE_ANALYSIS("module-summary", ModuleSummaryIndexAnalysis())
|
| 34 |
+
MODULE_ANALYSIS("no-op-module", NoOpModuleAnalysis())
|
| 35 |
+
MODULE_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis(PIC))
|
| 36 |
+
MODULE_ANALYSIS("profile-summary", ProfileSummaryAnalysis())
|
| 37 |
+
MODULE_ANALYSIS("reg-usage", PhysicalRegisterUsageAnalysis())
|
| 38 |
+
MODULE_ANALYSIS("stack-safety", StackSafetyGlobalAnalysis())
|
| 39 |
+
MODULE_ANALYSIS("verify", VerifierAnalysis())
|
| 40 |
+
|
| 41 |
+
#ifndef MODULE_ALIAS_ANALYSIS
|
| 42 |
+
#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
|
| 43 |
+
MODULE_ANALYSIS(NAME, CREATE_PASS)
|
| 44 |
+
#endif
|
| 45 |
+
MODULE_ALIAS_ANALYSIS("globals-aa", GlobalsAA())
|
| 46 |
+
#undef MODULE_ALIAS_ANALYSIS
|
| 47 |
+
#undef MODULE_ANALYSIS
|
| 48 |
+
|
| 49 |
+
#ifndef MODULE_PASS
|
| 50 |
+
#define MODULE_PASS(NAME, CREATE_PASS)
|
| 51 |
+
#endif
|
| 52 |
+
MODULE_PASS("always-inline", AlwaysInlinerPass())
|
| 53 |
+
MODULE_PASS("annotation2metadata", Annotation2MetadataPass())
|
| 54 |
+
MODULE_PASS("assign-guid", AssignGUIDPass())
|
| 55 |
+
MODULE_PASS("attributor", AttributorPass())
|
| 56 |
+
MODULE_PASS("attributor-light", AttributorLightPass())
|
| 57 |
+
MODULE_PASS("called-value-propagation", CalledValuePropagationPass())
|
| 58 |
+
MODULE_PASS("canonicalize-aliases", CanonicalizeAliasesPass())
|
| 59 |
+
MODULE_PASS("check-debugify", NewPMCheckDebugifyPass())
|
| 60 |
+
MODULE_PASS("constmerge", ConstantMergePass())
|
| 61 |
+
MODULE_PASS("coro-cleanup", CoroCleanupPass())
|
| 62 |
+
MODULE_PASS("coro-early", CoroEarlyPass())
|
| 63 |
+
MODULE_PASS("cross-dso-cfi", CrossDSOCFIPass())
|
| 64 |
+
MODULE_PASS("ctx-instr-gen",
|
| 65 |
+
PGOInstrumentationGen(PGOInstrumentationType::CTXPROF))
|
| 66 |
+
MODULE_PASS("ctx-prof-flatten", PGOCtxProfFlatteningPass(/*IsPreThinlink=*/false))
|
| 67 |
+
MODULE_PASS("ctx-prof-flatten-prethinlink",
|
| 68 |
+
PGOCtxProfFlatteningPass(/*IsPreThinlink=*/true))
|
| 69 |
+
MODULE_PASS("noinline-nonprevailing", NoinlineNonPrevailing())
|
| 70 |
+
MODULE_PASS("deadargelim", DeadArgumentEliminationPass())
|
| 71 |
+
MODULE_PASS("debugify", NewPMDebugifyPass())
|
| 72 |
+
MODULE_PASS("dfsan", DataFlowSanitizerPass())
|
| 73 |
+
MODULE_PASS("dot-callgraph", CallGraphDOTPrinterPass())
|
| 74 |
+
MODULE_PASS("dxil-upgrade", DXILUpgradePass())
|
| 75 |
+
MODULE_PASS("elim-avail-extern", EliminateAvailableExternallyPass())
|
| 76 |
+
MODULE_PASS("extract-blocks", BlockExtractorPass({}, false))
|
| 77 |
+
MODULE_PASS("expand-variadics", ExpandVariadicsPass(ExpandVariadicsMode::Disable))
|
| 78 |
+
MODULE_PASS("forceattrs", ForceFunctionAttrsPass())
|
| 79 |
+
MODULE_PASS("function-import", FunctionImportPass())
|
| 80 |
+
MODULE_PASS("global-merge-func", GlobalMergeFuncPass())
|
| 81 |
+
MODULE_PASS("globalopt", GlobalOptPass())
|
| 82 |
+
MODULE_PASS("globalsplit", GlobalSplitPass())
|
| 83 |
+
MODULE_PASS("hipstdpar-interpose-alloc", HipStdParAllocationInterpositionPass())
|
| 84 |
+
MODULE_PASS("hipstdpar-select-accelerator-code",
|
| 85 |
+
HipStdParAcceleratorCodeSelectionPass())
|
| 86 |
+
MODULE_PASS("hotcoldsplit", HotColdSplittingPass())
|
| 87 |
+
MODULE_PASS("inferattrs", InferFunctionAttrsPass())
|
| 88 |
+
MODULE_PASS("inliner-ml-advisor-release",
|
| 89 |
+
ModuleInlinerWrapperPass(getInlineParams(), true, {},
|
| 90 |
+
InliningAdvisorMode::Release, 0))
|
| 91 |
+
MODULE_PASS("inliner-wrapper", ModuleInlinerWrapperPass())
|
| 92 |
+
MODULE_PASS("inliner-wrapper-no-mandatory-first",
|
| 93 |
+
ModuleInlinerWrapperPass(getInlineParams(), false))
|
| 94 |
+
MODULE_PASS("insert-gcov-profiling", GCOVProfilerPass())
|
| 95 |
+
MODULE_PASS("instrprof", InstrProfilingLoweringPass())
|
| 96 |
+
MODULE_PASS("ctx-instr-lower", PGOCtxProfLoweringPass())
|
| 97 |
+
MODULE_PASS("print<ctx-prof-analysis>", CtxProfAnalysisPrinterPass(errs()))
|
| 98 |
+
MODULE_PASS("invalidate<all>", InvalidateAllAnalysesPass())
|
| 99 |
+
MODULE_PASS("iroutliner", IROutlinerPass())
|
| 100 |
+
MODULE_PASS("jmc-instrumenter", JMCInstrumenterPass())
|
| 101 |
+
MODULE_PASS("lower-emutls", LowerEmuTLSPass())
|
| 102 |
+
MODULE_PASS("lower-global-dtors", LowerGlobalDtorsPass())
|
| 103 |
+
MODULE_PASS("lower-ifunc", LowerIFuncPass())
|
| 104 |
+
MODULE_PASS("simplify-type-tests", SimplifyTypeTestsPass())
|
| 105 |
+
MODULE_PASS("lowertypetests", LowerTypeTestsPass())
|
| 106 |
+
MODULE_PASS("fatlto-cleanup", FatLtoCleanup())
|
| 107 |
+
MODULE_PASS("pgo-force-function-attrs", PGOForceFunctionAttrsPass(PGOOpt ? PGOOpt->ColdOptType : PGOOptions::ColdFuncOpt::Default))
|
| 108 |
+
MODULE_PASS("memprof-context-disambiguation", MemProfContextDisambiguation())
|
| 109 |
+
MODULE_PASS("memprof-module", ModuleMemProfilerPass())
|
| 110 |
+
MODULE_PASS("mergefunc", MergeFunctionsPass())
|
| 111 |
+
MODULE_PASS("metarenamer", MetaRenamerPass())
|
| 112 |
+
MODULE_PASS("module-inline", ModuleInlinerPass())
|
| 113 |
+
MODULE_PASS("name-anon-globals", NameAnonGlobalPass())
|
| 114 |
+
MODULE_PASS("no-op-module", NoOpModulePass())
|
| 115 |
+
MODULE_PASS("nsan", NumericalStabilitySanitizerPass())
|
| 116 |
+
MODULE_PASS("objc-arc-apelim", ObjCARCAPElimPass())
|
| 117 |
+
MODULE_PASS("openmp-opt", OpenMPOptPass())
|
| 118 |
+
MODULE_PASS("openmp-opt-postlink",
|
| 119 |
+
OpenMPOptPass(ThinOrFullLTOPhase::FullLTOPostLink))
|
| 120 |
+
MODULE_PASS("partial-inliner", PartialInlinerPass())
|
| 121 |
+
MODULE_PASS("pgo-icall-prom", PGOIndirectCallPromotion())
|
| 122 |
+
MODULE_PASS("pgo-instr-gen", PGOInstrumentationGen())
|
| 123 |
+
MODULE_PASS("pgo-instr-use", PGOInstrumentationUse())
|
| 124 |
+
MODULE_PASS("pre-isel-intrinsic-lowering", PreISelIntrinsicLoweringPass(TM))
|
| 125 |
+
MODULE_PASS("print", PrintModulePass(errs()))
|
| 126 |
+
MODULE_PASS("print-callgraph", CallGraphPrinterPass(errs()))
|
| 127 |
+
MODULE_PASS("print-callgraph-sccs", CallGraphSCCsPrinterPass(errs()))
|
| 128 |
+
MODULE_PASS("print-ir-similarity", IRSimilarityAnalysisPrinterPass(errs()))
|
| 129 |
+
MODULE_PASS("print-lcg", LazyCallGraphPrinterPass(errs()))
|
| 130 |
+
MODULE_PASS("print-lcg-dot", LazyCallGraphDOTPrinterPass(errs()))
|
| 131 |
+
MODULE_PASS("print-must-be-executed-contexts",
|
| 132 |
+
MustBeExecutedContextPrinterPass(errs()))
|
| 133 |
+
MODULE_PASS("print-profile-summary", ProfileSummaryPrinterPass(errs()))
|
| 134 |
+
MODULE_PASS("print-stack-safety", StackSafetyGlobalPrinterPass(errs()))
|
| 135 |
+
MODULE_PASS("print<dxil-metadata>", DXILMetadataAnalysisPrinterPass(errs()))
|
| 136 |
+
MODULE_PASS("print<dxil-resources>", DXILResourcePrinterPass(errs()))
|
| 137 |
+
MODULE_PASS("print<inline-advisor>", InlineAdvisorAnalysisPrinterPass(errs()))
|
| 138 |
+
MODULE_PASS("print<ir2vec>", IR2VecPrinterPass(errs()))
|
| 139 |
+
MODULE_PASS("print<module-debuginfo>", ModuleDebugInfoPrinterPass(errs()))
|
| 140 |
+
MODULE_PASS("print<reg-usage>", PhysicalRegisterUsageInfoPrinterPass(errs()))
|
| 141 |
+
MODULE_PASS("pseudo-probe", SampleProfileProbePass(TM))
|
| 142 |
+
MODULE_PASS("pseudo-probe-update", PseudoProbeUpdatePass())
|
| 143 |
+
MODULE_PASS("recompute-globalsaa", RecomputeGlobalsAAPass())
|
| 144 |
+
MODULE_PASS("rel-lookup-table-converter", RelLookupTableConverterPass())
|
| 145 |
+
MODULE_PASS("rewrite-statepoints-for-gc", RewriteStatepointsForGC())
|
| 146 |
+
MODULE_PASS("rewrite-symbols", RewriteSymbolPass())
|
| 147 |
+
MODULE_PASS("rpo-function-attrs", ReversePostOrderFunctionAttrsPass())
|
| 148 |
+
MODULE_PASS("rtsan", RealtimeSanitizerPass())
|
| 149 |
+
MODULE_PASS("sample-profile", SampleProfileLoaderPass())
|
| 150 |
+
MODULE_PASS("sancov-module", SanitizerCoveragePass())
|
| 151 |
+
MODULE_PASS("sanmd-module", SanitizerBinaryMetadataPass())
|
| 152 |
+
MODULE_PASS("scc-oz-module-inliner",
|
| 153 |
+
buildInlinerPipeline(OptimizationLevel::Oz,
|
| 154 |
+
ThinOrFullLTOPhase::None))
|
| 155 |
+
MODULE_PASS("shadow-stack-gc-lowering", ShadowStackGCLoweringPass())
|
| 156 |
+
MODULE_PASS("strip", StripSymbolsPass())
|
| 157 |
+
MODULE_PASS("strip-dead-debug-info", StripDeadDebugInfoPass())
|
| 158 |
+
MODULE_PASS("strip-dead-prototypes", StripDeadPrototypesPass())
|
| 159 |
+
MODULE_PASS("strip-debug-declare", StripDebugDeclarePass())
|
| 160 |
+
MODULE_PASS("strip-nondebug", StripNonDebugSymbolsPass())
|
| 161 |
+
MODULE_PASS("strip-nonlinetable-debuginfo", StripNonLineTableDebugInfoPass())
|
| 162 |
+
MODULE_PASS("strip-dead-cg-profile", StripDeadCGProfilePass())
|
| 163 |
+
MODULE_PASS("trigger-crash-module", TriggerCrashModulePass())
|
| 164 |
+
MODULE_PASS("trigger-verifier-error", TriggerVerifierErrorPass())
|
| 165 |
+
MODULE_PASS("tsan-module", ModuleThreadSanitizerPass())
|
| 166 |
+
MODULE_PASS("tysan", TypeSanitizerPass())
|
| 167 |
+
MODULE_PASS("verify", VerifierPass())
|
| 168 |
+
MODULE_PASS("view-callgraph", CallGraphViewerPass())
|
| 169 |
+
MODULE_PASS("wholeprogramdevirt", WholeProgramDevirtPass())
|
| 170 |
+
#undef MODULE_PASS
|
| 171 |
+
|
| 172 |
+
#ifndef MODULE_PASS_WITH_PARAMS
|
| 173 |
+
#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS)
|
| 174 |
+
#endif
|
| 175 |
+
MODULE_PASS_WITH_PARAMS(
|
| 176 |
+
"asan", "AddressSanitizerPass",
|
| 177 |
+
[](AddressSanitizerOptions Opts) { return AddressSanitizerPass(Opts); },
|
| 178 |
+
parseASanPassOptions, "kernel")
|
| 179 |
+
MODULE_PASS_WITH_PARAMS(
|
| 180 |
+
"cg-profile", "CGProfilePass",
|
| 181 |
+
[](bool InLTOPostLink) { return CGProfilePass(InLTOPostLink);},
|
| 182 |
+
parseCGProfilePassOptions, "in-lto-post-link")
|
| 183 |
+
MODULE_PASS_WITH_PARAMS(
|
| 184 |
+
"global-merge", "GlobalMergePass",
|
| 185 |
+
[TM = TM](GlobalMergeOptions Opts) { return GlobalMergePass(TM, Opts); },
|
| 186 |
+
parseGlobalMergeOptions,
|
| 187 |
+
"group-by-use;ignore-single-use;max-offset=N;merge-const;"
|
| 188 |
+
"merge-const-aggressive;merge-external;no-group-by-use;"
|
| 189 |
+
"no-ignore-single-use;no-merge-const;no-merge-const-aggressive;"
|
| 190 |
+
"no-merge-external;size-only")
|
| 191 |
+
MODULE_PASS_WITH_PARAMS(
|
| 192 |
+
"embed-bitcode", "EmbedBitcodePass",
|
| 193 |
+
[](EmbedBitcodeOptions Opts) { return EmbedBitcodePass(Opts); },
|
| 194 |
+
parseEmbedBitcodePassOptions, "thinlto;emit-summary")
|
| 195 |
+
MODULE_PASS_WITH_PARAMS(
|
| 196 |
+
"globaldce", "GlobalDCEPass",
|
| 197 |
+
[](bool InLTOPostLink) { return GlobalDCEPass(InLTOPostLink); },
|
| 198 |
+
parseGlobalDCEPassOptions, "in-lto-post-link")
|
| 199 |
+
MODULE_PASS_WITH_PARAMS(
|
| 200 |
+
"hwasan", "HWAddressSanitizerPass",
|
| 201 |
+
[](HWAddressSanitizerOptions Opts) { return HWAddressSanitizerPass(Opts); },
|
| 202 |
+
parseHWASanPassOptions, "kernel;recover")
|
| 203 |
+
MODULE_PASS_WITH_PARAMS(
|
| 204 |
+
"internalize", "InternalizePass",
|
| 205 |
+
[](SmallVector<std::string, 0> PreservedGVs) {
|
| 206 |
+
if (PreservedGVs.empty())
|
| 207 |
+
return InternalizePass();
|
| 208 |
+
auto MustPreserveGV = [=](const GlobalValue &GV) {
|
| 209 |
+
for (auto &PreservedGV : PreservedGVs)
|
| 210 |
+
if (GV.getName() == PreservedGV)
|
| 211 |
+
return true;
|
| 212 |
+
return false;
|
| 213 |
+
};
|
| 214 |
+
return InternalizePass(MustPreserveGV);
|
| 215 |
+
},
|
| 216 |
+
parseInternalizeGVs, "preserve-gv=GV")
|
| 217 |
+
MODULE_PASS_WITH_PARAMS(
|
| 218 |
+
"ipsccp", "IPSCCPPass", [](IPSCCPOptions Opts) { return IPSCCPPass(Opts); },
|
| 219 |
+
parseIPSCCPOptions, "no-func-spec;func-spec")
|
| 220 |
+
MODULE_PASS_WITH_PARAMS(
|
| 221 |
+
"loop-extract", "LoopExtractorPass",
|
| 222 |
+
[](bool Single) {
|
| 223 |
+
if (Single)
|
| 224 |
+
return LoopExtractorPass(1);
|
| 225 |
+
return LoopExtractorPass();
|
| 226 |
+
},
|
| 227 |
+
parseLoopExtractorPassOptions, "single")
|
| 228 |
+
MODULE_PASS_WITH_PARAMS(
|
| 229 |
+
"memprof-use", "MemProfUsePass",
|
| 230 |
+
[](std::string Opts) { return MemProfUsePass(Opts); },
|
| 231 |
+
parseMemProfUsePassOptions, "profile-filename=S")
|
| 232 |
+
MODULE_PASS_WITH_PARAMS(
|
| 233 |
+
"msan", "MemorySanitizerPass",
|
| 234 |
+
[](MemorySanitizerOptions Opts) { return MemorySanitizerPass(Opts); },
|
| 235 |
+
parseMSanPassOptions, "recover;kernel;eager-checks;track-origins=N")
|
| 236 |
+
MODULE_PASS_WITH_PARAMS(
|
| 237 |
+
"print<structural-hash>", "StructuralHashPrinterPass",
|
| 238 |
+
[](StructuralHashOptions Options) {
|
| 239 |
+
return StructuralHashPrinterPass(errs(), Options);
|
| 240 |
+
},
|
| 241 |
+
parseStructuralHashPrinterPassOptions, "detailed;call-target-ignored")
|
| 242 |
+
|
| 243 |
+
#undef MODULE_PASS_WITH_PARAMS
|
| 244 |
+
|
| 245 |
+
#ifndef CGSCC_ANALYSIS
|
| 246 |
+
#define CGSCC_ANALYSIS(NAME, CREATE_PASS)
|
| 247 |
+
#endif
|
| 248 |
+
CGSCC_ANALYSIS("no-op-cgscc", NoOpCGSCCAnalysis())
|
| 249 |
+
CGSCC_ANALYSIS("fam-proxy", FunctionAnalysisManagerCGSCCProxy())
|
| 250 |
+
CGSCC_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis(PIC))
|
| 251 |
+
#undef CGSCC_ANALYSIS
|
| 252 |
+
|
| 253 |
+
#ifndef CGSCC_PASS
|
| 254 |
+
#define CGSCC_PASS(NAME, CREATE_PASS)
|
| 255 |
+
#endif
|
| 256 |
+
CGSCC_PASS("argpromotion", ArgumentPromotionPass())
|
| 257 |
+
CGSCC_PASS("attributor-cgscc", AttributorCGSCCPass())
|
| 258 |
+
CGSCC_PASS("attributor-light-cgscc", AttributorLightCGSCCPass())
|
| 259 |
+
CGSCC_PASS("invalidate<all>", InvalidateAllAnalysesPass())
|
| 260 |
+
CGSCC_PASS("no-op-cgscc", NoOpCGSCCPass())
|
| 261 |
+
CGSCC_PASS("openmp-opt-cgscc", OpenMPOptCGSCCPass())
|
| 262 |
+
CGSCC_PASS("coro-annotation-elide", CoroAnnotationElidePass())
|
| 263 |
+
#undef CGSCC_PASS
|
| 264 |
+
|
| 265 |
+
#ifndef CGSCC_PASS_WITH_PARAMS
|
| 266 |
+
#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS)
|
| 267 |
+
#endif
|
| 268 |
+
CGSCC_PASS_WITH_PARAMS(
|
| 269 |
+
"coro-split", "CoroSplitPass",
|
| 270 |
+
[](bool OptimizeFrame) { return CoroSplitPass(OptimizeFrame); },
|
| 271 |
+
parseCoroSplitPassOptions, "reuse-storage")
|
| 272 |
+
CGSCC_PASS_WITH_PARAMS(
|
| 273 |
+
"function-attrs", "PostOrderFunctionAttrsPass",
|
| 274 |
+
[](bool SkipNonRecursive) {
|
| 275 |
+
return PostOrderFunctionAttrsPass(SkipNonRecursive);
|
| 276 |
+
},
|
| 277 |
+
parsePostOrderFunctionAttrsPassOptions, "skip-non-recursive-function-attrs")
|
| 278 |
+
CGSCC_PASS_WITH_PARAMS(
|
| 279 |
+
"inline", "InlinerPass",
|
| 280 |
+
[](bool OnlyMandatory) { return InlinerPass(OnlyMandatory); },
|
| 281 |
+
parseInlinerPassOptions, "only-mandatory")
|
| 282 |
+
#undef CGSCC_PASS_WITH_PARAMS
|
| 283 |
+
|
| 284 |
+
#ifndef FUNCTION_ANALYSIS
|
| 285 |
+
#define FUNCTION_ANALYSIS(NAME, CREATE_PASS)
|
| 286 |
+
#endif
|
| 287 |
+
FUNCTION_ANALYSIS("aa", AAManager())
|
| 288 |
+
FUNCTION_ANALYSIS("access-info", LoopAccessAnalysis())
|
| 289 |
+
FUNCTION_ANALYSIS("assumptions", AssumptionAnalysis())
|
| 290 |
+
FUNCTION_ANALYSIS("bb-sections-profile-reader", BasicBlockSectionsProfileReaderAnalysis(TM))
|
| 291 |
+
FUNCTION_ANALYSIS("block-freq", BlockFrequencyAnalysis())
|
| 292 |
+
FUNCTION_ANALYSIS("branch-prob", BranchProbabilityAnalysis())
|
| 293 |
+
FUNCTION_ANALYSIS("cycles", CycleAnalysis())
|
| 294 |
+
FUNCTION_ANALYSIS("da", DependenceAnalysis())
|
| 295 |
+
FUNCTION_ANALYSIS("debug-ata", DebugAssignmentTrackingAnalysis())
|
| 296 |
+
FUNCTION_ANALYSIS("demanded-bits", DemandedBitsAnalysis())
|
| 297 |
+
FUNCTION_ANALYSIS("domfrontier", DominanceFrontierAnalysis())
|
| 298 |
+
FUNCTION_ANALYSIS("domtree", DominatorTreeAnalysis())
|
| 299 |
+
FUNCTION_ANALYSIS("ephemerals", EphemeralValuesAnalysis())
|
| 300 |
+
FUNCTION_ANALYSIS("func-properties", FunctionPropertiesAnalysis())
|
| 301 |
+
FUNCTION_ANALYSIS("machine-function-info", MachineFunctionAnalysis(TM))
|
| 302 |
+
FUNCTION_ANALYSIS("gc-function", GCFunctionAnalysis())
|
| 303 |
+
FUNCTION_ANALYSIS("inliner-size-estimator", InlineSizeEstimatorAnalysis())
|
| 304 |
+
FUNCTION_ANALYSIS("last-run-tracking", LastRunTrackingAnalysis())
|
| 305 |
+
FUNCTION_ANALYSIS("lazy-value-info", LazyValueAnalysis())
|
| 306 |
+
FUNCTION_ANALYSIS("loops", LoopAnalysis())
|
| 307 |
+
FUNCTION_ANALYSIS("memdep", MemoryDependenceAnalysis())
|
| 308 |
+
FUNCTION_ANALYSIS("memoryssa", MemorySSAAnalysis())
|
| 309 |
+
FUNCTION_ANALYSIS("no-op-function", NoOpFunctionAnalysis())
|
| 310 |
+
FUNCTION_ANALYSIS("opt-remark-emit", OptimizationRemarkEmitterAnalysis())
|
| 311 |
+
FUNCTION_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis(PIC))
|
| 312 |
+
FUNCTION_ANALYSIS("phi-values", PhiValuesAnalysis())
|
| 313 |
+
FUNCTION_ANALYSIS("postdomtree", PostDominatorTreeAnalysis())
|
| 314 |
+
FUNCTION_ANALYSIS("regions", RegionInfoAnalysis())
|
| 315 |
+
FUNCTION_ANALYSIS("scalar-evolution", ScalarEvolutionAnalysis())
|
| 316 |
+
FUNCTION_ANALYSIS("should-not-run-function-passes",
|
| 317 |
+
ShouldNotRunFunctionPassesAnalysis())
|
| 318 |
+
FUNCTION_ANALYSIS("should-run-extra-vector-passes",
|
| 319 |
+
ShouldRunExtraVectorPasses())
|
| 320 |
+
FUNCTION_ANALYSIS("ssp-layout", SSPLayoutAnalysis())
|
| 321 |
+
FUNCTION_ANALYSIS("stack-safety-local", StackSafetyAnalysis())
|
| 322 |
+
FUNCTION_ANALYSIS("target-ir",
|
| 323 |
+
TM ? TM->getTargetIRAnalysis() : TargetIRAnalysis())
|
| 324 |
+
FUNCTION_ANALYSIS("target-lib-info", TargetLibraryAnalysis())
|
| 325 |
+
FUNCTION_ANALYSIS("uniformity", UniformityInfoAnalysis())
|
| 326 |
+
FUNCTION_ANALYSIS("verify", VerifierAnalysis())
|
| 327 |
+
|
| 328 |
+
#ifndef FUNCTION_ALIAS_ANALYSIS
|
| 329 |
+
#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
|
| 330 |
+
FUNCTION_ANALYSIS(NAME, CREATE_PASS)
|
| 331 |
+
#endif
|
| 332 |
+
FUNCTION_ALIAS_ANALYSIS("basic-aa", BasicAA())
|
| 333 |
+
FUNCTION_ALIAS_ANALYSIS("objc-arc-aa", objcarc::ObjCARCAA())
|
| 334 |
+
FUNCTION_ALIAS_ANALYSIS("scev-aa", SCEVAA())
|
| 335 |
+
FUNCTION_ALIAS_ANALYSIS("scoped-noalias-aa", ScopedNoAliasAA())
|
| 336 |
+
FUNCTION_ALIAS_ANALYSIS("tbaa", TypeBasedAA())
|
| 337 |
+
#undef FUNCTION_ALIAS_ANALYSIS
|
| 338 |
+
#undef FUNCTION_ANALYSIS
|
| 339 |
+
|
| 340 |
+
#ifndef FUNCTION_PASS
|
| 341 |
+
#define FUNCTION_PASS(NAME, CREATE_PASS)
|
| 342 |
+
#endif
|
| 343 |
+
FUNCTION_PASS("aa-eval", AAEvaluator())
|
| 344 |
+
FUNCTION_PASS("adce", ADCEPass())
|
| 345 |
+
FUNCTION_PASS("add-discriminators", AddDiscriminatorsPass())
|
| 346 |
+
FUNCTION_PASS("aggressive-instcombine", AggressiveInstCombinePass())
|
| 347 |
+
FUNCTION_PASS("alignment-from-assumptions", AlignmentFromAssumptionsPass())
|
| 348 |
+
FUNCTION_PASS("annotation-remarks", AnnotationRemarksPass())
|
| 349 |
+
FUNCTION_PASS("assume-builder", AssumeBuilderPass())
|
| 350 |
+
FUNCTION_PASS("assume-simplify", AssumeSimplifyPass())
|
| 351 |
+
FUNCTION_PASS("atomic-expand", AtomicExpandPass(TM))
|
| 352 |
+
FUNCTION_PASS("bdce", BDCEPass())
|
| 353 |
+
FUNCTION_PASS("break-crit-edges", BreakCriticalEdgesPass())
|
| 354 |
+
FUNCTION_PASS("callbr-prepare", CallBrPreparePass())
|
| 355 |
+
FUNCTION_PASS("callsite-splitting", CallSiteSplittingPass())
|
| 356 |
+
FUNCTION_PASS("chr", ControlHeightReductionPass())
|
| 357 |
+
FUNCTION_PASS("codegenprepare", CodeGenPreparePass(TM))
|
| 358 |
+
FUNCTION_PASS("complex-deinterleaving", ComplexDeinterleavingPass(TM))
|
| 359 |
+
FUNCTION_PASS("consthoist", ConstantHoistingPass())
|
| 360 |
+
FUNCTION_PASS("constraint-elimination", ConstraintEliminationPass())
|
| 361 |
+
FUNCTION_PASS("coro-elide", CoroElidePass())
|
| 362 |
+
FUNCTION_PASS("correlated-propagation", CorrelatedValuePropagationPass())
|
| 363 |
+
FUNCTION_PASS("count-visits", CountVisitsPass())
|
| 364 |
+
FUNCTION_PASS("dce", DCEPass())
|
| 365 |
+
FUNCTION_PASS("declare-to-assign", llvm::AssignmentTrackingPass())
|
| 366 |
+
FUNCTION_PASS("dfa-jump-threading", DFAJumpThreadingPass())
|
| 367 |
+
FUNCTION_PASS("div-rem-pairs", DivRemPairsPass())
|
| 368 |
+
FUNCTION_PASS("dot-cfg", CFGPrinterPass())
|
| 369 |
+
FUNCTION_PASS("dot-cfg-only", CFGOnlyPrinterPass())
|
| 370 |
+
FUNCTION_PASS("dot-dom", DomPrinter())
|
| 371 |
+
FUNCTION_PASS("dot-dom-only", DomOnlyPrinter())
|
| 372 |
+
FUNCTION_PASS("dot-post-dom", PostDomPrinter())
|
| 373 |
+
FUNCTION_PASS("dot-post-dom-only", PostDomOnlyPrinter())
|
| 374 |
+
FUNCTION_PASS("dse", DSEPass())
|
| 375 |
+
FUNCTION_PASS("dwarf-eh-prepare", DwarfEHPreparePass(TM))
|
| 376 |
+
FUNCTION_PASS("expand-large-div-rem", ExpandLargeDivRemPass(TM))
|
| 377 |
+
FUNCTION_PASS("expand-fp", ExpandFpPass(TM))
|
| 378 |
+
FUNCTION_PASS("expand-memcmp", ExpandMemCmpPass(TM))
|
| 379 |
+
FUNCTION_PASS("extra-vector-passes",
|
| 380 |
+
ExtraFunctionPassManager<ShouldRunExtraVectorPasses>())
|
| 381 |
+
FUNCTION_PASS("fix-irreducible", FixIrreduciblePass())
|
| 382 |
+
FUNCTION_PASS("flatten-cfg", FlattenCFGPass())
|
| 383 |
+
FUNCTION_PASS("float2int", Float2IntPass())
|
| 384 |
+
FUNCTION_PASS("gc-lowering", GCLoweringPass())
|
| 385 |
+
FUNCTION_PASS("guard-widening", GuardWideningPass())
|
| 386 |
+
FUNCTION_PASS("gvn-hoist", GVNHoistPass())
|
| 387 |
+
FUNCTION_PASS("gvn-sink", GVNSinkPass())
|
| 388 |
+
FUNCTION_PASS("helloworld", HelloWorldPass())
|
| 389 |
+
FUNCTION_PASS("indirectbr-expand", IndirectBrExpandPass(TM))
|
| 390 |
+
FUNCTION_PASS("infer-address-spaces", InferAddressSpacesPass())
|
| 391 |
+
FUNCTION_PASS("infer-alignment", InferAlignmentPass())
|
| 392 |
+
FUNCTION_PASS("inject-tli-mappings", InjectTLIMappings())
|
| 393 |
+
FUNCTION_PASS("instcount", InstCountPass())
|
| 394 |
+
FUNCTION_PASS("instnamer", InstructionNamerPass())
|
| 395 |
+
FUNCTION_PASS("instsimplify", InstSimplifyPass())
|
| 396 |
+
FUNCTION_PASS("interleaved-access", InterleavedAccessPass(TM))
|
| 397 |
+
FUNCTION_PASS("interleaved-load-combine", InterleavedLoadCombinePass(TM))
|
| 398 |
+
FUNCTION_PASS("invalidate<all>", InvalidateAllAnalysesPass())
|
| 399 |
+
FUNCTION_PASS("irce", IRCEPass())
|
| 400 |
+
FUNCTION_PASS("jump-threading", JumpThreadingPass())
|
| 401 |
+
FUNCTION_PASS("jump-table-to-switch", JumpTableToSwitchPass());
|
| 402 |
+
FUNCTION_PASS("kcfi", KCFIPass())
|
| 403 |
+
FUNCTION_PASS("kernel-info", KernelInfoPrinter(TM))
|
| 404 |
+
FUNCTION_PASS("lcssa", LCSSAPass())
|
| 405 |
+
FUNCTION_PASS("libcalls-shrinkwrap", LibCallsShrinkWrapPass())
|
| 406 |
+
FUNCTION_PASS("load-store-vectorizer", LoadStoreVectorizerPass())
|
| 407 |
+
FUNCTION_PASS("loop-data-prefetch", LoopDataPrefetchPass())
|
| 408 |
+
FUNCTION_PASS("loop-distribute", LoopDistributePass())
|
| 409 |
+
FUNCTION_PASS("loop-fusion", LoopFusePass())
|
| 410 |
+
FUNCTION_PASS("loop-load-elim", LoopLoadEliminationPass())
|
| 411 |
+
FUNCTION_PASS("loop-simplify", LoopSimplifyPass())
|
| 412 |
+
FUNCTION_PASS("loop-sink", LoopSinkPass())
|
| 413 |
+
FUNCTION_PASS("loop-versioning", LoopVersioningPass())
|
| 414 |
+
FUNCTION_PASS("lower-atomic", LowerAtomicPass())
|
| 415 |
+
FUNCTION_PASS("lower-constant-intrinsics", LowerConstantIntrinsicsPass())
|
| 416 |
+
FUNCTION_PASS("lower-expect", LowerExpectIntrinsicPass())
|
| 417 |
+
FUNCTION_PASS("lower-guard-intrinsic", LowerGuardIntrinsicPass())
|
| 418 |
+
FUNCTION_PASS("lower-invoke", LowerInvokePass())
|
| 419 |
+
FUNCTION_PASS("lower-switch", LowerSwitchPass())
|
| 420 |
+
FUNCTION_PASS("lower-widenable-condition", LowerWidenableConditionPass())
|
| 421 |
+
FUNCTION_PASS("make-guards-explicit", MakeGuardsExplicitPass())
|
| 422 |
+
FUNCTION_PASS("mem2reg", PromotePass())
|
| 423 |
+
FUNCTION_PASS("memcpyopt", MemCpyOptPass())
|
| 424 |
+
FUNCTION_PASS("memprof", MemProfilerPass())
|
| 425 |
+
FUNCTION_PASS("mergeicmps", MergeICmpsPass())
|
| 426 |
+
FUNCTION_PASS("mergereturn", UnifyFunctionExitNodesPass())
|
| 427 |
+
FUNCTION_PASS("move-auto-init", MoveAutoInitPass())
|
| 428 |
+
FUNCTION_PASS("nary-reassociate", NaryReassociatePass())
|
| 429 |
+
FUNCTION_PASS("newgvn", NewGVNPass())
|
| 430 |
+
FUNCTION_PASS("no-op-function", NoOpFunctionPass())
|
| 431 |
+
FUNCTION_PASS("objc-arc", ObjCARCOptPass())
|
| 432 |
+
FUNCTION_PASS("objc-arc-contract", ObjCARCContractPass())
|
| 433 |
+
FUNCTION_PASS("objc-arc-expand", ObjCARCExpandPass())
|
| 434 |
+
FUNCTION_PASS("pa-eval", PAEvalPass())
|
| 435 |
+
FUNCTION_PASS("partially-inline-libcalls", PartiallyInlineLibCallsPass())
|
| 436 |
+
FUNCTION_PASS("pgo-memop-opt", PGOMemOPSizeOpt())
|
| 437 |
+
FUNCTION_PASS("place-safepoints", PlaceSafepointsPass())
|
| 438 |
+
FUNCTION_PASS("print", PrintFunctionPass(errs()))
|
| 439 |
+
// TODO: rename to print<foo> after NPM switch
|
| 440 |
+
FUNCTION_PASS("print-alias-sets", AliasSetsPrinterPass(errs()))
|
| 441 |
+
FUNCTION_PASS("print-cfg-sccs", CFGSCCPrinterPass(errs()))
|
| 442 |
+
FUNCTION_PASS("print-memderefs", MemDerefPrinterPass(errs()))
|
| 443 |
+
FUNCTION_PASS("print-mustexecute", MustExecutePrinterPass(errs()))
|
| 444 |
+
FUNCTION_PASS("print-predicateinfo", PredicateInfoPrinterPass(errs()))
|
| 445 |
+
FUNCTION_PASS("print<assumptions>", AssumptionPrinterPass(errs()))
|
| 446 |
+
FUNCTION_PASS("print<block-freq>", BlockFrequencyPrinterPass(errs()))
|
| 447 |
+
FUNCTION_PASS("print<branch-prob>", BranchProbabilityPrinterPass(errs()))
|
| 448 |
+
FUNCTION_PASS("print<cost-model>", CostModelPrinterPass(errs()))
|
| 449 |
+
FUNCTION_PASS("print<cycles>", CycleInfoPrinterPass(errs()))
|
| 450 |
+
FUNCTION_PASS("print<da>", DependenceAnalysisPrinterPass(errs()))
|
| 451 |
+
FUNCTION_PASS("print<debug-ata>", DebugAssignmentTrackingPrinterPass(errs()))
|
| 452 |
+
FUNCTION_PASS("print<delinearization>", DelinearizationPrinterPass(errs()))
|
| 453 |
+
FUNCTION_PASS("print<demanded-bits>", DemandedBitsPrinterPass(errs()))
|
| 454 |
+
FUNCTION_PASS("print<domfrontier>", DominanceFrontierPrinterPass(errs()))
|
| 455 |
+
FUNCTION_PASS("print<domtree>", DominatorTreePrinterPass(errs()))
|
| 456 |
+
FUNCTION_PASS("print<func-properties>", FunctionPropertiesPrinterPass(errs()))
|
| 457 |
+
FUNCTION_PASS("print<inline-cost>", InlineCostAnnotationPrinterPass(errs()))
|
| 458 |
+
FUNCTION_PASS("print<inliner-size-estimator>",
|
| 459 |
+
InlineSizeEstimatorAnalysisPrinterPass(errs()))
|
| 460 |
+
FUNCTION_PASS("print<lazy-value-info>", LazyValueInfoPrinterPass(errs()))
|
| 461 |
+
FUNCTION_PASS("print<loops>", LoopPrinterPass(errs()))
|
| 462 |
+
FUNCTION_PASS("print<memoryssa-walker>", MemorySSAWalkerPrinterPass(errs()))
|
| 463 |
+
FUNCTION_PASS("print<phi-values>", PhiValuesPrinterPass(errs()))
|
| 464 |
+
FUNCTION_PASS("print<postdomtree>", PostDominatorTreePrinterPass(errs()))
|
| 465 |
+
FUNCTION_PASS("print<regions>", RegionInfoPrinterPass(errs()))
|
| 466 |
+
FUNCTION_PASS("print<scalar-evolution>", ScalarEvolutionPrinterPass(errs()))
|
| 467 |
+
FUNCTION_PASS("print<stack-safety-local>", StackSafetyPrinterPass(errs()))
|
| 468 |
+
FUNCTION_PASS("print<uniformity>", UniformityInfoPrinterPass(errs()))
|
| 469 |
+
FUNCTION_PASS("reassociate", ReassociatePass())
|
| 470 |
+
FUNCTION_PASS("redundant-dbg-inst-elim", RedundantDbgInstEliminationPass())
|
| 471 |
+
FUNCTION_PASS("reg2mem", RegToMemPass())
|
| 472 |
+
FUNCTION_PASS("safe-stack", SafeStackPass(TM))
|
| 473 |
+
FUNCTION_PASS("sandbox-vectorizer", SandboxVectorizerPass())
|
| 474 |
+
FUNCTION_PASS("scalarize-masked-mem-intrin", ScalarizeMaskedMemIntrinPass())
|
| 475 |
+
FUNCTION_PASS("sccp", SCCPPass())
|
| 476 |
+
FUNCTION_PASS("select-optimize", SelectOptimizePass(TM))
|
| 477 |
+
FUNCTION_PASS("separate-const-offset-from-gep",
|
| 478 |
+
SeparateConstOffsetFromGEPPass())
|
| 479 |
+
FUNCTION_PASS("sink", SinkingPass())
|
| 480 |
+
FUNCTION_PASS("sjlj-eh-prepare", SjLjEHPreparePass(TM))
|
| 481 |
+
FUNCTION_PASS("slp-vectorizer", SLPVectorizerPass())
|
| 482 |
+
FUNCTION_PASS("slsr", StraightLineStrengthReducePass())
|
| 483 |
+
FUNCTION_PASS("stack-protector", StackProtectorPass(TM))
|
| 484 |
+
FUNCTION_PASS("strip-gc-relocates", StripGCRelocates())
|
| 485 |
+
FUNCTION_PASS("tailcallelim", TailCallElimPass())
|
| 486 |
+
FUNCTION_PASS("transform-warning", WarnMissedTransformationsPass())
|
| 487 |
+
FUNCTION_PASS("trigger-crash-function", TriggerCrashFunctionPass())
|
| 488 |
+
FUNCTION_PASS("trigger-verifier-error", TriggerVerifierErrorPass())
|
| 489 |
+
FUNCTION_PASS("tsan", ThreadSanitizerPass())
|
| 490 |
+
FUNCTION_PASS("typepromotion", TypePromotionPass(TM))
|
| 491 |
+
FUNCTION_PASS("unify-loop-exits", UnifyLoopExitsPass())
|
| 492 |
+
FUNCTION_PASS("vector-combine", VectorCombinePass())
|
| 493 |
+
FUNCTION_PASS("verify", VerifierPass())
|
| 494 |
+
FUNCTION_PASS("verify<cycles>", CycleInfoVerifierPass())
|
| 495 |
+
FUNCTION_PASS("verify<domtree>", DominatorTreeVerifierPass())
|
| 496 |
+
FUNCTION_PASS("verify<loops>", LoopVerifierPass())
|
| 497 |
+
FUNCTION_PASS("verify<memoryssa>", MemorySSAVerifierPass())
|
| 498 |
+
FUNCTION_PASS("verify<regions>", RegionInfoVerifierPass())
|
| 499 |
+
FUNCTION_PASS("verify<safepoint-ir>", SafepointIRVerifierPass())
|
| 500 |
+
FUNCTION_PASS("verify<scalar-evolution>", ScalarEvolutionVerifierPass())
|
| 501 |
+
FUNCTION_PASS("view-cfg", CFGViewerPass())
|
| 502 |
+
FUNCTION_PASS("view-cfg-only", CFGOnlyViewerPass())
|
| 503 |
+
FUNCTION_PASS("view-dom", DomViewer())
|
| 504 |
+
FUNCTION_PASS("view-dom-only", DomOnlyViewer())
|
| 505 |
+
FUNCTION_PASS("view-post-dom", PostDomViewer())
|
| 506 |
+
FUNCTION_PASS("view-post-dom-only", PostDomOnlyViewer())
|
| 507 |
+
FUNCTION_PASS("wasm-eh-prepare", WasmEHPreparePass())
|
| 508 |
+
#undef FUNCTION_PASS
|
| 509 |
+
|
| 510 |
+
#ifndef FUNCTION_PASS_WITH_PARAMS
|
| 511 |
+
#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS)
|
| 512 |
+
#endif
|
| 513 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 514 |
+
"cfguard", "CFGuardPass",
|
| 515 |
+
[](CFGuardPass::Mechanism M) { return CFGuardPass(M); },
|
| 516 |
+
parseCFGuardPassOptions, "check;dispatch")
|
| 517 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 518 |
+
"early-cse", "EarlyCSEPass",
|
| 519 |
+
[](bool UseMemorySSA) { return EarlyCSEPass(UseMemorySSA); },
|
| 520 |
+
parseEarlyCSEPassOptions, "memssa")
|
| 521 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 522 |
+
"ee-instrument", "EntryExitInstrumenterPass",
|
| 523 |
+
[](bool PostInlining) { return EntryExitInstrumenterPass(PostInlining); },
|
| 524 |
+
parseEntryExitInstrumenterPassOptions, "post-inline")
|
| 525 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 526 |
+
"function-simplification", "",
|
| 527 |
+
[this](OptimizationLevel OL) {
|
| 528 |
+
return buildFunctionSimplificationPipeline(OL, ThinOrFullLTOPhase::None);
|
| 529 |
+
},
|
| 530 |
+
parseFunctionSimplificationPipelineOptions, "O1;O2;O3;Os;Oz")
|
| 531 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 532 |
+
"gvn", "GVNPass", [](GVNOptions Opts) { return GVNPass(Opts); },
|
| 533 |
+
parseGVNOptions,
|
| 534 |
+
"no-pre;pre;no-load-pre;load-pre;no-split-backedge-load-pre;"
|
| 535 |
+
"split-backedge-load-pre;no-memdep;memdep;no-memoryssa;memoryssa")
|
| 536 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 537 |
+
"hardware-loops", "HardwareLoopsPass",
|
| 538 |
+
[](HardwareLoopOptions Opts) { return HardwareLoopsPass(Opts); },
|
| 539 |
+
parseHardwareLoopOptions,
|
| 540 |
+
"force-hardware-loops;force-hardware-loop-phi;force-nested-hardware-loop;"
|
| 541 |
+
"force-hardware-loop-guard;hardware-loop-decrement=N;"
|
| 542 |
+
"hardware-loop-counter-bitwidth=N")
|
| 543 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 544 |
+
"instcombine", "InstCombinePass",
|
| 545 |
+
[](InstCombineOptions Opts) { return InstCombinePass(Opts); },
|
| 546 |
+
parseInstCombineOptions,
|
| 547 |
+
"no-use-loop-info;use-loop-info;no-verify-fixpoint;verify-fixpoint;"
|
| 548 |
+
"max-iterations=N")
|
| 549 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 550 |
+
"lint", "LintPass",
|
| 551 |
+
[](bool AbortOnError) { return LintPass(AbortOnError); },
|
| 552 |
+
parseLintOptions,
|
| 553 |
+
"abort-on-error")
|
| 554 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 555 |
+
"loop-unroll", "LoopUnrollPass",
|
| 556 |
+
[](LoopUnrollOptions Opts) { return LoopUnrollPass(Opts); },
|
| 557 |
+
parseLoopUnrollOptions,
|
| 558 |
+
"O0;O1;O2;O3;full-unroll-max=N;no-partial;partial;no-peeling;peeling;"
|
| 559 |
+
"no-profile-peeling;profile-peeling;no-runtime;runtime;no-upperbound;"
|
| 560 |
+
"upperbound")
|
| 561 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 562 |
+
"loop-vectorize", "LoopVectorizePass",
|
| 563 |
+
[](LoopVectorizeOptions Opts) { return LoopVectorizePass(Opts); },
|
| 564 |
+
parseLoopVectorizeOptions,
|
| 565 |
+
"no-interleave-forced-only;interleave-forced-only;no-vectorize-forced-only;"
|
| 566 |
+
"vectorize-forced-only")
|
| 567 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 568 |
+
"lower-allow-check", "LowerAllowCheckPass",
|
| 569 |
+
[](LowerAllowCheckPass::Options Opts) { return LowerAllowCheckPass(Opts); },
|
| 570 |
+
parseLowerAllowCheckPassOptions, "")
|
| 571 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 572 |
+
"lower-matrix-intrinsics", "LowerMatrixIntrinsicsPass",
|
| 573 |
+
[](bool Minimal) { return LowerMatrixIntrinsicsPass(Minimal); },
|
| 574 |
+
parseLowerMatrixIntrinsicsPassOptions, "minimal")
|
| 575 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 576 |
+
"normalize", "IRNormalizerPass",
|
| 577 |
+
[](IRNormalizerOptions Options) { return IRNormalizerPass(Options); },
|
| 578 |
+
parseIRNormalizerPassOptions,
|
| 579 |
+
"no-preserve-order;preserve-order;no-rename-all;rename-all;no-fold-all;fold-all;no-reorder-operands;reorder-operands")
|
| 580 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 581 |
+
"mldst-motion", "MergedLoadStoreMotionPass",
|
| 582 |
+
[](MergedLoadStoreMotionOptions Opts) {
|
| 583 |
+
return MergedLoadStoreMotionPass(Opts);
|
| 584 |
+
},
|
| 585 |
+
parseMergedLoadStoreMotionOptions, "no-split-footer-bb;split-footer-bb")
|
| 586 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 587 |
+
"print<access-info>", "LoopAccessInfoPrinterPass",
|
| 588 |
+
[](bool AllowPartial) {
|
| 589 |
+
return LoopAccessInfoPrinterPass(errs(), AllowPartial);
|
| 590 |
+
},
|
| 591 |
+
[](StringRef Params) {
|
| 592 |
+
return PassBuilder::parseSinglePassOption(Params, "allow-partial",
|
| 593 |
+
"LoopAccessInfoPrinterPass");
|
| 594 |
+
},
|
| 595 |
+
"allow-partial")
|
| 596 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 597 |
+
"print<da>", "DependenceAnalysisPrinterPass",
|
| 598 |
+
[](bool NormalizeResults) {
|
| 599 |
+
return DependenceAnalysisPrinterPass(errs(), NormalizeResults);
|
| 600 |
+
},
|
| 601 |
+
parseDependenceAnalysisPrinterOptions, "normalized-results")
|
| 602 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 603 |
+
"print<memoryssa>", "MemorySSAPrinterPass",
|
| 604 |
+
[](bool NoEnsureOptimizedUses) {
|
| 605 |
+
return MemorySSAPrinterPass(errs(), !NoEnsureOptimizedUses);
|
| 606 |
+
},
|
| 607 |
+
parseMemorySSAPrinterPassOptions, "no-ensure-optimized-uses")
|
| 608 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 609 |
+
"print<stack-lifetime>", "StackLifetimePrinterPass",
|
| 610 |
+
[](StackLifetime::LivenessType Type) {
|
| 611 |
+
return StackLifetimePrinterPass(errs(), Type);
|
| 612 |
+
},
|
| 613 |
+
parseStackLifetimeOptions, "may;must")
|
| 614 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 615 |
+
"scalarizer", "ScalarizerPass",
|
| 616 |
+
[](ScalarizerPassOptions Opts) { return ScalarizerPass(Opts); },
|
| 617 |
+
parseScalarizerOptions,
|
| 618 |
+
"load-store;no-load-store;variable-insert-extract;"
|
| 619 |
+
"no-variable-insert-extract;min-bits=N;")
|
| 620 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 621 |
+
"separate-const-offset-from-gep", "SeparateConstOffsetFromGEPPass",
|
| 622 |
+
[](bool LowerGEP) { return SeparateConstOffsetFromGEPPass(LowerGEP); },
|
| 623 |
+
parseSeparateConstOffsetFromGEPPassOptions, "lower-gep")
|
| 624 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 625 |
+
"simplifycfg", "SimplifyCFGPass",
|
| 626 |
+
[](SimplifyCFGOptions Opts) { return SimplifyCFGPass(Opts); },
|
| 627 |
+
parseSimplifyCFGOptions,
|
| 628 |
+
"no-forward-switch-cond;forward-switch-cond;no-switch-range-to-icmp;"
|
| 629 |
+
"switch-range-to-icmp;no-switch-to-lookup;switch-to-lookup;no-keep-loops;"
|
| 630 |
+
"keep-loops;no-hoist-common-insts;hoist-common-insts;no-sink-common-insts;"
|
| 631 |
+
"sink-common-insts;bonus-inst-threshold=N")
|
| 632 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 633 |
+
"speculative-execution", "SpeculativeExecutionPass",
|
| 634 |
+
[](bool OnlyIfDivergentTarget) {
|
| 635 |
+
return SpeculativeExecutionPass(OnlyIfDivergentTarget);
|
| 636 |
+
},
|
| 637 |
+
parseSpeculativeExecutionPassOptions, "only-if-divergent-target")
|
| 638 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 639 |
+
"sroa", "SROAPass",
|
| 640 |
+
[](SROAOptions PreserveCFG) { return SROAPass(PreserveCFG); },
|
| 641 |
+
parseSROAOptions, "preserve-cfg;modify-cfg")
|
| 642 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 643 |
+
"structurizecfg", "StructurizeCFG",
|
| 644 |
+
[](bool SkipUniformRegions) {
|
| 645 |
+
return StructurizeCFGPass(SkipUniformRegions);
|
| 646 |
+
},
|
| 647 |
+
parseStructurizeCFGPassOptions, "skip-uniform-regions")
|
| 648 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 649 |
+
"win-eh-prepare", "WinEHPreparePass",
|
| 650 |
+
[](bool DemoteCatchSwitchPHIOnly) {
|
| 651 |
+
return WinEHPreparePass(DemoteCatchSwitchPHIOnly);
|
| 652 |
+
},
|
| 653 |
+
parseWinEHPrepareOptions, "demote-catchswitch-only")
|
| 654 |
+
FUNCTION_PASS_WITH_PARAMS(
|
| 655 |
+
"bounds-checking", "BoundsCheckingPass",
|
| 656 |
+
[](BoundsCheckingPass::Options Options) {
|
| 657 |
+
return BoundsCheckingPass(Options);
|
| 658 |
+
},
|
| 659 |
+
parseBoundsCheckingOptions, "trap")
|
| 660 |
+
#undef FUNCTION_PASS_WITH_PARAMS
|
| 661 |
+
|
| 662 |
+
#ifndef LOOPNEST_PASS
|
| 663 |
+
#define LOOPNEST_PASS(NAME, CREATE_PASS)
|
| 664 |
+
#endif
|
| 665 |
+
LOOPNEST_PASS("loop-flatten", LoopFlattenPass())
|
| 666 |
+
LOOPNEST_PASS("loop-interchange", LoopInterchangePass())
|
| 667 |
+
LOOPNEST_PASS("loop-unroll-and-jam", LoopUnrollAndJamPass())
|
| 668 |
+
LOOPNEST_PASS("no-op-loopnest", NoOpLoopNestPass())
|
| 669 |
+
#undef LOOPNEST_PASS
|
| 670 |
+
|
| 671 |
+
#ifndef LOOP_ANALYSIS
|
| 672 |
+
#define LOOP_ANALYSIS(NAME, CREATE_PASS)
|
| 673 |
+
#endif
|
| 674 |
+
LOOP_ANALYSIS("ddg", DDGAnalysis())
|
| 675 |
+
LOOP_ANALYSIS("hash-recognize", HashRecognizeAnalysis())
|
| 676 |
+
LOOP_ANALYSIS("iv-users", IVUsersAnalysis())
|
| 677 |
+
LOOP_ANALYSIS("no-op-loop", NoOpLoopAnalysis())
|
| 678 |
+
LOOP_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis(PIC))
|
| 679 |
+
LOOP_ANALYSIS("should-run-extra-simple-loop-unswitch",
|
| 680 |
+
ShouldRunExtraSimpleLoopUnswitch())
|
| 681 |
+
|
| 682 |
+
#undef LOOP_ANALYSIS
|
| 683 |
+
|
| 684 |
+
#ifndef LOOP_PASS
|
| 685 |
+
#define LOOP_PASS(NAME, CREATE_PASS)
|
| 686 |
+
#endif
|
| 687 |
+
LOOP_PASS("canon-freeze", CanonicalizeFreezeInLoopsPass())
|
| 688 |
+
LOOP_PASS("dot-ddg", DDGDotPrinterPass())
|
| 689 |
+
LOOP_PASS("evl-iv-simplify", EVLIndVarSimplifyPass())
|
| 690 |
+
LOOP_PASS("guard-widening", GuardWideningPass())
|
| 691 |
+
LOOP_PASS("extra-simple-loop-unswitch-passes",
|
| 692 |
+
ExtraLoopPassManager<ShouldRunExtraSimpleLoopUnswitch>())
|
| 693 |
+
LOOP_PASS("indvars", IndVarSimplifyPass())
|
| 694 |
+
LOOP_PASS("invalidate<all>", InvalidateAllAnalysesPass())
|
| 695 |
+
LOOP_PASS("loop-bound-split", LoopBoundSplitPass())
|
| 696 |
+
LOOP_PASS("loop-deletion", LoopDeletionPass())
|
| 697 |
+
LOOP_PASS("loop-idiom", LoopIdiomRecognizePass())
|
| 698 |
+
LOOP_PASS("loop-idiom-vectorize", LoopIdiomVectorizePass())
|
| 699 |
+
LOOP_PASS("loop-instsimplify", LoopInstSimplifyPass())
|
| 700 |
+
LOOP_PASS("loop-predication", LoopPredicationPass())
|
| 701 |
+
LOOP_PASS("loop-reduce", LoopStrengthReducePass())
|
| 702 |
+
LOOP_PASS("loop-term-fold", LoopTermFoldPass())
|
| 703 |
+
LOOP_PASS("loop-simplifycfg", LoopSimplifyCFGPass())
|
| 704 |
+
LOOP_PASS("loop-unroll-full", LoopFullUnrollPass())
|
| 705 |
+
LOOP_PASS("loop-versioning-licm", LoopVersioningLICMPass())
|
| 706 |
+
LOOP_PASS("no-op-loop", NoOpLoopPass())
|
| 707 |
+
LOOP_PASS("print", PrintLoopPass(errs()))
|
| 708 |
+
LOOP_PASS("print<ddg>", DDGAnalysisPrinterPass(errs()))
|
| 709 |
+
LOOP_PASS("print<hash-recognize>", HashRecognizePrinterPass(errs()))
|
| 710 |
+
LOOP_PASS("print<iv-users>", IVUsersPrinterPass(errs()))
|
| 711 |
+
LOOP_PASS("print<loop-cache-cost>", LoopCachePrinterPass(errs()))
|
| 712 |
+
LOOP_PASS("print<loopnest>", LoopNestPrinterPass(errs()))
|
| 713 |
+
#undef LOOP_PASS
|
| 714 |
+
|
| 715 |
+
#ifndef LOOP_PASS_WITH_PARAMS
|
| 716 |
+
#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS)
|
| 717 |
+
#endif
|
| 718 |
+
LOOP_PASS_WITH_PARAMS(
|
| 719 |
+
"licm", "LICMPass", [](LICMOptions Params) { return LICMPass(Params); },
|
| 720 |
+
parseLICMOptions, "allowspeculation")
|
| 721 |
+
LOOP_PASS_WITH_PARAMS(
|
| 722 |
+
"lnicm", "LNICMPass", [](LICMOptions Params) { return LNICMPass(Params); },
|
| 723 |
+
parseLICMOptions, "allowspeculation")
|
| 724 |
+
LOOP_PASS_WITH_PARAMS(
|
| 725 |
+
"loop-rotate", "LoopRotatePass",
|
| 726 |
+
[](std::pair<bool, bool> Params) {
|
| 727 |
+
return LoopRotatePass(Params.first, Params.second);
|
| 728 |
+
},
|
| 729 |
+
parseLoopRotateOptions,
|
| 730 |
+
"no-header-duplication;header-duplication;"
|
| 731 |
+
"no-prepare-for-lto;prepare-for-lto")
|
| 732 |
+
LOOP_PASS_WITH_PARAMS(
|
| 733 |
+
"simple-loop-unswitch", "SimpleLoopUnswitchPass",
|
| 734 |
+
[](std::pair<bool, bool> Params) {
|
| 735 |
+
return SimpleLoopUnswitchPass(Params.first, Params.second);
|
| 736 |
+
},
|
| 737 |
+
parseLoopUnswitchOptions, "nontrivial;no-nontrivial;trivial;no-trivial")
|
| 738 |
+
#undef LOOP_PASS_WITH_PARAMS
|
deps/exla/cache/xla_extension/include/llvm/lib/Remarks/BitstreamRemarkParser.h
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===-- BitstreamRemarkParser.h - Parser for Bitstream remarks --*- C++/-*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file provides the impementation of the Bitstream remark parser.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H
|
| 14 |
+
#define LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H
|
| 15 |
+
|
| 16 |
+
#include "llvm/Remarks/BitstreamRemarkContainer.h"
|
| 17 |
+
#include "llvm/Remarks/BitstreamRemarkParser.h"
|
| 18 |
+
#include "llvm/Remarks/RemarkFormat.h"
|
| 19 |
+
#include "llvm/Remarks/RemarkParser.h"
|
| 20 |
+
#include <cstdint>
|
| 21 |
+
#include <memory>
|
| 22 |
+
#include <optional>
|
| 23 |
+
|
| 24 |
+
namespace llvm {
|
| 25 |
+
namespace remarks {
|
| 26 |
+
|
| 27 |
+
struct Remark;
|
| 28 |
+
|
| 29 |
+
/// Parses and holds the state of the latest parsed remark.
|
| 30 |
+
struct BitstreamRemarkParser : public RemarkParser {
|
| 31 |
+
/// The buffer to parse.
|
| 32 |
+
BitstreamParserHelper ParserHelper;
|
| 33 |
+
/// The string table used for parsing strings.
|
| 34 |
+
std::optional<ParsedStringTable> StrTab;
|
| 35 |
+
/// Temporary remark buffer used when the remarks are stored separately.
|
| 36 |
+
std::unique_ptr<MemoryBuffer> TmpRemarkBuffer;
|
| 37 |
+
/// The common metadata used to decide how to parse the buffer.
|
| 38 |
+
/// This is filled when parsing the metadata block.
|
| 39 |
+
uint64_t ContainerVersion = 0;
|
| 40 |
+
uint64_t RemarkVersion = 0;
|
| 41 |
+
BitstreamRemarkContainerType ContainerType =
|
| 42 |
+
BitstreamRemarkContainerType::Standalone;
|
| 43 |
+
/// Wether the parser is ready to parse remarks.
|
| 44 |
+
bool ReadyToParseRemarks = false;
|
| 45 |
+
|
| 46 |
+
/// Create a parser that expects to find a string table embedded in the
|
| 47 |
+
/// stream.
|
| 48 |
+
explicit BitstreamRemarkParser(StringRef Buf)
|
| 49 |
+
: RemarkParser(Format::Bitstream), ParserHelper(Buf) {}
|
| 50 |
+
|
| 51 |
+
/// Create a parser that uses a pre-parsed string table.
|
| 52 |
+
BitstreamRemarkParser(StringRef Buf, ParsedStringTable StrTab)
|
| 53 |
+
: RemarkParser(Format::Bitstream), ParserHelper(Buf),
|
| 54 |
+
StrTab(std::move(StrTab)) {}
|
| 55 |
+
|
| 56 |
+
Expected<std::unique_ptr<Remark>> next() override;
|
| 57 |
+
|
| 58 |
+
static bool classof(const RemarkParser *P) {
|
| 59 |
+
return P->ParserFormat == Format::Bitstream;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
/// Parse and process the metadata of the buffer.
|
| 63 |
+
Error parseMeta();
|
| 64 |
+
|
| 65 |
+
/// Parse a Bitstream remark.
|
| 66 |
+
Expected<std::unique_ptr<Remark>> parseRemark();
|
| 67 |
+
|
| 68 |
+
private:
|
| 69 |
+
/// Helper functions.
|
| 70 |
+
Error processCommonMeta(BitstreamMetaParserHelper &Helper);
|
| 71 |
+
Error processStandaloneMeta(BitstreamMetaParserHelper &Helper);
|
| 72 |
+
Error processSeparateRemarksFileMeta(BitstreamMetaParserHelper &Helper);
|
| 73 |
+
Error processSeparateRemarksMetaMeta(BitstreamMetaParserHelper &Helper);
|
| 74 |
+
Expected<std::unique_ptr<Remark>>
|
| 75 |
+
processRemark(BitstreamRemarkParserHelper &Helper);
|
| 76 |
+
Error processExternalFilePath(std::optional<StringRef> ExternalFilePath);
|
| 77 |
+
};
|
| 78 |
+
|
| 79 |
+
Expected<std::unique_ptr<BitstreamRemarkParser>> createBitstreamParserFromMeta(
|
| 80 |
+
StringRef Buf, std::optional<ParsedStringTable> StrTab = std::nullopt,
|
| 81 |
+
std::optional<StringRef> ExternalFilePrependPath = std::nullopt);
|
| 82 |
+
|
| 83 |
+
} // end namespace remarks
|
| 84 |
+
} // end namespace llvm
|
| 85 |
+
|
| 86 |
+
#endif /* LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H */
|
deps/exla/cache/xla_extension/include/llvm/lib/Remarks/YAMLRemarkParser.h
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===-- YAMLRemarkParser.h - Parser for YAML remarks ------------*- C++/-*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file provides the impementation of the YAML remark parser.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_REMARKS_YAML_REMARK_PARSER_H
|
| 14 |
+
#define LLVM_REMARKS_YAML_REMARK_PARSER_H
|
| 15 |
+
|
| 16 |
+
#include "llvm/Remarks/Remark.h"
|
| 17 |
+
#include "llvm/Remarks/RemarkParser.h"
|
| 18 |
+
#include "llvm/Support/Error.h"
|
| 19 |
+
#include "llvm/Support/MemoryBuffer.h"
|
| 20 |
+
#include "llvm/Support/SourceMgr.h"
|
| 21 |
+
#include "llvm/Support/YAMLParser.h"
|
| 22 |
+
#include "llvm/Support/raw_ostream.h"
|
| 23 |
+
#include <optional>
|
| 24 |
+
#include <string>
|
| 25 |
+
|
| 26 |
+
namespace llvm {
|
| 27 |
+
namespace remarks {
|
| 28 |
+
|
| 29 |
+
class YAMLParseError : public ErrorInfo<YAMLParseError> {
|
| 30 |
+
public:
|
| 31 |
+
static char ID;
|
| 32 |
+
|
| 33 |
+
YAMLParseError(StringRef Message, SourceMgr &SM, yaml::Stream &Stream,
|
| 34 |
+
yaml::Node &Node);
|
| 35 |
+
|
| 36 |
+
YAMLParseError(StringRef Message) : Message(std::string(Message)) {}
|
| 37 |
+
|
| 38 |
+
void log(raw_ostream &OS) const override { OS << Message; }
|
| 39 |
+
std::error_code convertToErrorCode() const override {
|
| 40 |
+
return inconvertibleErrorCode();
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
private:
|
| 44 |
+
std::string Message;
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
/// Regular YAML to Remark parser.
|
| 48 |
+
struct YAMLRemarkParser : public RemarkParser {
|
| 49 |
+
/// The string table used for parsing strings.
|
| 50 |
+
std::optional<ParsedStringTable> StrTab;
|
| 51 |
+
/// Last error message that can come from the YAML parser diagnostics.
|
| 52 |
+
/// We need this for catching errors in the constructor.
|
| 53 |
+
std::string LastErrorMessage;
|
| 54 |
+
/// Source manager for better error messages.
|
| 55 |
+
SourceMgr SM;
|
| 56 |
+
/// Stream for yaml parsing.
|
| 57 |
+
yaml::Stream Stream;
|
| 58 |
+
/// Iterator in the YAML stream.
|
| 59 |
+
yaml::document_iterator YAMLIt;
|
| 60 |
+
/// If we parse remark metadata in separate mode, we need to open a new file
|
| 61 |
+
/// and parse that.
|
| 62 |
+
std::unique_ptr<MemoryBuffer> SeparateBuf;
|
| 63 |
+
|
| 64 |
+
YAMLRemarkParser(StringRef Buf);
|
| 65 |
+
|
| 66 |
+
Expected<std::unique_ptr<Remark>> next() override;
|
| 67 |
+
|
| 68 |
+
static bool classof(const RemarkParser *P) {
|
| 69 |
+
return P->ParserFormat == Format::YAML;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
protected:
|
| 73 |
+
YAMLRemarkParser(StringRef Buf, std::optional<ParsedStringTable> StrTab);
|
| 74 |
+
/// Create a YAMLParseError error from an existing error generated by the YAML
|
| 75 |
+
/// parser.
|
| 76 |
+
/// If there is no error, this returns Success.
|
| 77 |
+
Error error();
|
| 78 |
+
/// Create a YAMLParseError error referencing a specific node.
|
| 79 |
+
Error error(StringRef Message, yaml::Node &Node);
|
| 80 |
+
/// Parse a YAML remark to a remarks::Remark object.
|
| 81 |
+
Expected<std::unique_ptr<Remark>> parseRemark(yaml::Document &Remark);
|
| 82 |
+
/// Parse the type of a remark to an enum type.
|
| 83 |
+
Expected<Type> parseType(yaml::MappingNode &Node);
|
| 84 |
+
/// Parse one key to a string.
|
| 85 |
+
Expected<StringRef> parseKey(yaml::KeyValueNode &Node);
|
| 86 |
+
/// Parse one value to a string.
|
| 87 |
+
virtual Expected<StringRef> parseStr(yaml::KeyValueNode &Node);
|
| 88 |
+
/// Parse one value to an unsigned.
|
| 89 |
+
Expected<unsigned> parseUnsigned(yaml::KeyValueNode &Node);
|
| 90 |
+
/// Parse a debug location.
|
| 91 |
+
Expected<RemarkLocation> parseDebugLoc(yaml::KeyValueNode &Node);
|
| 92 |
+
/// Parse an argument.
|
| 93 |
+
Expected<Argument> parseArg(yaml::Node &Node);
|
| 94 |
+
};
|
| 95 |
+
|
| 96 |
+
/// YAML with a string table to Remark parser.
|
| 97 |
+
struct YAMLStrTabRemarkParser : public YAMLRemarkParser {
|
| 98 |
+
YAMLStrTabRemarkParser(StringRef Buf, ParsedStringTable StrTab)
|
| 99 |
+
: YAMLRemarkParser(Buf, std::move(StrTab)) {}
|
| 100 |
+
|
| 101 |
+
static bool classof(const RemarkParser *P) {
|
| 102 |
+
return P->ParserFormat == Format::YAMLStrTab;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
protected:
|
| 106 |
+
/// Parse one value to a string.
|
| 107 |
+
Expected<StringRef> parseStr(yaml::KeyValueNode &Node) override;
|
| 108 |
+
};
|
| 109 |
+
|
| 110 |
+
Expected<std::unique_ptr<YAMLRemarkParser>> createYAMLParserFromMeta(
|
| 111 |
+
StringRef Buf, std::optional<ParsedStringTable> StrTab = std::nullopt,
|
| 112 |
+
std::optional<StringRef> ExternalFilePrependPath = std::nullopt);
|
| 113 |
+
|
| 114 |
+
} // end namespace remarks
|
| 115 |
+
} // end namespace llvm
|
| 116 |
+
|
| 117 |
+
#endif /* LLVM_REMARKS_YAML_REMARK_PARSER_H */
|
deps/exla/cache/xla_extension/include/llvm/lib/Support/BLAKE3/blake3_impl.h
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef BLAKE3_IMPL_H
|
| 2 |
+
#define BLAKE3_IMPL_H
|
| 3 |
+
|
| 4 |
+
#include <assert.h>
|
| 5 |
+
#include <stdbool.h>
|
| 6 |
+
#include <stddef.h>
|
| 7 |
+
#include <stdint.h>
|
| 8 |
+
#include <string.h>
|
| 9 |
+
|
| 10 |
+
#include "llvm-c/blake3.h"
|
| 11 |
+
// For \p LLVM_LIBRARY_VISIBILITY
|
| 12 |
+
#include "llvm/Support/Compiler.h"
|
| 13 |
+
|
| 14 |
+
#include "llvm_blake3_prefix.h"
|
| 15 |
+
|
| 16 |
+
// internal flags
|
| 17 |
+
enum blake3_flags {
|
| 18 |
+
CHUNK_START = 1 << 0,
|
| 19 |
+
CHUNK_END = 1 << 1,
|
| 20 |
+
PARENT = 1 << 2,
|
| 21 |
+
ROOT = 1 << 3,
|
| 22 |
+
KEYED_HASH = 1 << 4,
|
| 23 |
+
DERIVE_KEY_CONTEXT = 1 << 5,
|
| 24 |
+
DERIVE_KEY_MATERIAL = 1 << 6,
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
// This C implementation tries to support recent versions of GCC, Clang, and
|
| 28 |
+
// MSVC.
|
| 29 |
+
#if defined(_MSC_VER)
|
| 30 |
+
#define INLINE static __forceinline
|
| 31 |
+
#else
|
| 32 |
+
#define INLINE static inline __attribute__((always_inline))
|
| 33 |
+
#endif
|
| 34 |
+
|
| 35 |
+
#if defined(__x86_64__) || defined(_M_X64)
|
| 36 |
+
#define IS_X86
|
| 37 |
+
#define IS_X86_64
|
| 38 |
+
#endif
|
| 39 |
+
|
| 40 |
+
#if defined(__i386__) || defined(_M_IX86)
|
| 41 |
+
#define IS_X86
|
| 42 |
+
#define IS_X86_32
|
| 43 |
+
#endif
|
| 44 |
+
|
| 45 |
+
#if defined(__aarch64__) || defined(_M_ARM64)
|
| 46 |
+
#define IS_AARCH64
|
| 47 |
+
#endif
|
| 48 |
+
|
| 49 |
+
#if defined(IS_X86)
|
| 50 |
+
#if defined(_MSC_VER)
|
| 51 |
+
#include <intrin.h>
|
| 52 |
+
#endif
|
| 53 |
+
#include <immintrin.h>
|
| 54 |
+
#endif
|
| 55 |
+
|
| 56 |
+
#if !defined(BLAKE3_USE_NEON)
|
| 57 |
+
// If BLAKE3_USE_NEON not manually set, autodetect based on
|
| 58 |
+
// AArch64ness and endianness.
|
| 59 |
+
#if defined(IS_AARCH64) && !defined(__ARM_BIG_ENDIAN)
|
| 60 |
+
#define BLAKE3_USE_NEON 1
|
| 61 |
+
#else
|
| 62 |
+
#define BLAKE3_USE_NEON 0
|
| 63 |
+
#endif
|
| 64 |
+
#endif
|
| 65 |
+
|
| 66 |
+
#if defined(IS_X86)
|
| 67 |
+
#define MAX_SIMD_DEGREE 16
|
| 68 |
+
#elif BLAKE3_USE_NEON == 1
|
| 69 |
+
#define MAX_SIMD_DEGREE 4
|
| 70 |
+
#else
|
| 71 |
+
#define MAX_SIMD_DEGREE 1
|
| 72 |
+
#endif
|
| 73 |
+
|
| 74 |
+
// There are some places where we want a static size that's equal to the
|
| 75 |
+
// MAX_SIMD_DEGREE, but also at least 2.
|
| 76 |
+
#define MAX_SIMD_DEGREE_OR_2 (MAX_SIMD_DEGREE > 2 ? MAX_SIMD_DEGREE : 2)
|
| 77 |
+
|
| 78 |
+
static const uint32_t IV[8] = {0x6A09E667UL, 0xBB67AE85UL, 0x3C6EF372UL,
|
| 79 |
+
0xA54FF53AUL, 0x510E527FUL, 0x9B05688CUL,
|
| 80 |
+
0x1F83D9ABUL, 0x5BE0CD19UL};
|
| 81 |
+
|
| 82 |
+
static const uint8_t MSG_SCHEDULE[7][16] = {
|
| 83 |
+
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
|
| 84 |
+
{2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8},
|
| 85 |
+
{3, 4, 10, 12, 13, 2, 7, 14, 6, 5, 9, 0, 11, 15, 8, 1},
|
| 86 |
+
{10, 7, 12, 9, 14, 3, 13, 15, 4, 0, 11, 2, 5, 8, 1, 6},
|
| 87 |
+
{12, 13, 9, 11, 15, 10, 14, 8, 7, 2, 5, 3, 0, 1, 6, 4},
|
| 88 |
+
{9, 14, 11, 5, 8, 12, 15, 1, 13, 3, 0, 10, 2, 6, 4, 7},
|
| 89 |
+
{11, 15, 5, 0, 1, 9, 8, 6, 14, 10, 2, 12, 3, 4, 7, 13},
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
/* Find index of the highest set bit */
|
| 93 |
+
/* x is assumed to be nonzero. */
|
| 94 |
+
static unsigned int highest_one(uint64_t x) {
|
| 95 |
+
#if defined(__GNUC__) || defined(__clang__)
|
| 96 |
+
return 63 ^ __builtin_clzll(x);
|
| 97 |
+
#elif defined(_MSC_VER) && defined(IS_X86_64)
|
| 98 |
+
unsigned long index;
|
| 99 |
+
_BitScanReverse64(&index, x);
|
| 100 |
+
return index;
|
| 101 |
+
#elif defined(_MSC_VER) && defined(IS_X86_32)
|
| 102 |
+
if(x >> 32) {
|
| 103 |
+
unsigned long index;
|
| 104 |
+
_BitScanReverse(&index, (unsigned long)(x >> 32));
|
| 105 |
+
return 32 + index;
|
| 106 |
+
} else {
|
| 107 |
+
unsigned long index;
|
| 108 |
+
_BitScanReverse(&index, (unsigned long)x);
|
| 109 |
+
return index;
|
| 110 |
+
}
|
| 111 |
+
#else
|
| 112 |
+
unsigned int c = 0;
|
| 113 |
+
if(x & 0xffffffff00000000ULL) { x >>= 32; c += 32; }
|
| 114 |
+
if(x & 0x00000000ffff0000ULL) { x >>= 16; c += 16; }
|
| 115 |
+
if(x & 0x000000000000ff00ULL) { x >>= 8; c += 8; }
|
| 116 |
+
if(x & 0x00000000000000f0ULL) { x >>= 4; c += 4; }
|
| 117 |
+
if(x & 0x000000000000000cULL) { x >>= 2; c += 2; }
|
| 118 |
+
if(x & 0x0000000000000002ULL) { c += 1; }
|
| 119 |
+
return c;
|
| 120 |
+
#endif
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
// Count the number of 1 bits.
|
| 124 |
+
INLINE unsigned int popcnt(uint64_t x) {
|
| 125 |
+
#if defined(__GNUC__) || defined(__clang__)
|
| 126 |
+
return __builtin_popcountll(x);
|
| 127 |
+
#else
|
| 128 |
+
unsigned int count = 0;
|
| 129 |
+
while (x != 0) {
|
| 130 |
+
count += 1;
|
| 131 |
+
x &= x - 1;
|
| 132 |
+
}
|
| 133 |
+
return count;
|
| 134 |
+
#endif
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
// Largest power of two less than or equal to x. As a special case, returns 1
|
| 138 |
+
// when x is 0.
|
| 139 |
+
INLINE uint64_t round_down_to_power_of_2(uint64_t x) {
|
| 140 |
+
return 1ULL << highest_one(x | 1);
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
INLINE uint32_t counter_low(uint64_t counter) { return (uint32_t)counter; }
|
| 144 |
+
|
| 145 |
+
INLINE uint32_t counter_high(uint64_t counter) {
|
| 146 |
+
return (uint32_t)(counter >> 32);
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
INLINE uint32_t load32(const void *src) {
|
| 150 |
+
const uint8_t *p = (const uint8_t *)src;
|
| 151 |
+
return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |
|
| 152 |
+
((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24);
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
INLINE void load_key_words(const uint8_t key[BLAKE3_KEY_LEN],
|
| 156 |
+
uint32_t key_words[8]) {
|
| 157 |
+
key_words[0] = load32(&key[0 * 4]);
|
| 158 |
+
key_words[1] = load32(&key[1 * 4]);
|
| 159 |
+
key_words[2] = load32(&key[2 * 4]);
|
| 160 |
+
key_words[3] = load32(&key[3 * 4]);
|
| 161 |
+
key_words[4] = load32(&key[4 * 4]);
|
| 162 |
+
key_words[5] = load32(&key[5 * 4]);
|
| 163 |
+
key_words[6] = load32(&key[6 * 4]);
|
| 164 |
+
key_words[7] = load32(&key[7 * 4]);
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
INLINE void store32(void *dst, uint32_t w) {
|
| 168 |
+
uint8_t *p = (uint8_t *)dst;
|
| 169 |
+
p[0] = (uint8_t)(w >> 0);
|
| 170 |
+
p[1] = (uint8_t)(w >> 8);
|
| 171 |
+
p[2] = (uint8_t)(w >> 16);
|
| 172 |
+
p[3] = (uint8_t)(w >> 24);
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
INLINE void store_cv_words(uint8_t bytes_out[32], uint32_t cv_words[8]) {
|
| 176 |
+
store32(&bytes_out[0 * 4], cv_words[0]);
|
| 177 |
+
store32(&bytes_out[1 * 4], cv_words[1]);
|
| 178 |
+
store32(&bytes_out[2 * 4], cv_words[2]);
|
| 179 |
+
store32(&bytes_out[3 * 4], cv_words[3]);
|
| 180 |
+
store32(&bytes_out[4 * 4], cv_words[4]);
|
| 181 |
+
store32(&bytes_out[5 * 4], cv_words[5]);
|
| 182 |
+
store32(&bytes_out[6 * 4], cv_words[6]);
|
| 183 |
+
store32(&bytes_out[7 * 4], cv_words[7]);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
LLVM_LIBRARY_VISIBILITY
|
| 187 |
+
void blake3_compress_in_place(uint32_t cv[8],
|
| 188 |
+
const uint8_t block[BLAKE3_BLOCK_LEN],
|
| 189 |
+
uint8_t block_len, uint64_t counter,
|
| 190 |
+
uint8_t flags);
|
| 191 |
+
|
| 192 |
+
LLVM_LIBRARY_VISIBILITY
|
| 193 |
+
void blake3_compress_xof(const uint32_t cv[8],
|
| 194 |
+
const uint8_t block[BLAKE3_BLOCK_LEN],
|
| 195 |
+
uint8_t block_len, uint64_t counter, uint8_t flags,
|
| 196 |
+
uint8_t out[64]);
|
| 197 |
+
|
| 198 |
+
LLVM_LIBRARY_VISIBILITY
|
| 199 |
+
void blake3_hash_many(const uint8_t *const *inputs, size_t num_inputs,
|
| 200 |
+
size_t blocks, const uint32_t key[8], uint64_t counter,
|
| 201 |
+
bool increment_counter, uint8_t flags,
|
| 202 |
+
uint8_t flags_start, uint8_t flags_end, uint8_t *out);
|
| 203 |
+
|
| 204 |
+
LLVM_LIBRARY_VISIBILITY
|
| 205 |
+
size_t blake3_simd_degree(void);
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
// Declarations for implementation-specific functions.
|
| 209 |
+
LLVM_LIBRARY_VISIBILITY
|
| 210 |
+
void blake3_compress_in_place_portable(uint32_t cv[8],
|
| 211 |
+
const uint8_t block[BLAKE3_BLOCK_LEN],
|
| 212 |
+
uint8_t block_len, uint64_t counter,
|
| 213 |
+
uint8_t flags);
|
| 214 |
+
|
| 215 |
+
LLVM_LIBRARY_VISIBILITY
|
| 216 |
+
void blake3_compress_xof_portable(const uint32_t cv[8],
|
| 217 |
+
const uint8_t block[BLAKE3_BLOCK_LEN],
|
| 218 |
+
uint8_t block_len, uint64_t counter,
|
| 219 |
+
uint8_t flags, uint8_t out[64]);
|
| 220 |
+
|
| 221 |
+
LLVM_LIBRARY_VISIBILITY
|
| 222 |
+
void blake3_hash_many_portable(const uint8_t *const *inputs, size_t num_inputs,
|
| 223 |
+
size_t blocks, const uint32_t key[8],
|
| 224 |
+
uint64_t counter, bool increment_counter,
|
| 225 |
+
uint8_t flags, uint8_t flags_start,
|
| 226 |
+
uint8_t flags_end, uint8_t *out);
|
| 227 |
+
|
| 228 |
+
#if defined(IS_X86)
|
| 229 |
+
#if !defined(BLAKE3_NO_SSE2)
|
| 230 |
+
LLVM_LIBRARY_VISIBILITY
|
| 231 |
+
void blake3_compress_in_place_sse2(uint32_t cv[8],
|
| 232 |
+
const uint8_t block[BLAKE3_BLOCK_LEN],
|
| 233 |
+
uint8_t block_len, uint64_t counter,
|
| 234 |
+
uint8_t flags);
|
| 235 |
+
LLVM_LIBRARY_VISIBILITY
|
| 236 |
+
void blake3_compress_xof_sse2(const uint32_t cv[8],
|
| 237 |
+
const uint8_t block[BLAKE3_BLOCK_LEN],
|
| 238 |
+
uint8_t block_len, uint64_t counter,
|
| 239 |
+
uint8_t flags, uint8_t out[64]);
|
| 240 |
+
LLVM_LIBRARY_VISIBILITY
|
| 241 |
+
void blake3_hash_many_sse2(const uint8_t *const *inputs, size_t num_inputs,
|
| 242 |
+
size_t blocks, const uint32_t key[8],
|
| 243 |
+
uint64_t counter, bool increment_counter,
|
| 244 |
+
uint8_t flags, uint8_t flags_start,
|
| 245 |
+
uint8_t flags_end, uint8_t *out);
|
| 246 |
+
#endif
|
| 247 |
+
#if !defined(BLAKE3_NO_SSE41)
|
| 248 |
+
LLVM_LIBRARY_VISIBILITY
|
| 249 |
+
void blake3_compress_in_place_sse41(uint32_t cv[8],
|
| 250 |
+
const uint8_t block[BLAKE3_BLOCK_LEN],
|
| 251 |
+
uint8_t block_len, uint64_t counter,
|
| 252 |
+
uint8_t flags);
|
| 253 |
+
LLVM_LIBRARY_VISIBILITY
|
| 254 |
+
void blake3_compress_xof_sse41(const uint32_t cv[8],
|
| 255 |
+
const uint8_t block[BLAKE3_BLOCK_LEN],
|
| 256 |
+
uint8_t block_len, uint64_t counter,
|
| 257 |
+
uint8_t flags, uint8_t out[64]);
|
| 258 |
+
LLVM_LIBRARY_VISIBILITY
|
| 259 |
+
void blake3_hash_many_sse41(const uint8_t *const *inputs, size_t num_inputs,
|
| 260 |
+
size_t blocks, const uint32_t key[8],
|
| 261 |
+
uint64_t counter, bool increment_counter,
|
| 262 |
+
uint8_t flags, uint8_t flags_start,
|
| 263 |
+
uint8_t flags_end, uint8_t *out);
|
| 264 |
+
#endif
|
| 265 |
+
#if !defined(BLAKE3_NO_AVX2)
|
| 266 |
+
LLVM_LIBRARY_VISIBILITY
|
| 267 |
+
void blake3_hash_many_avx2(const uint8_t *const *inputs, size_t num_inputs,
|
| 268 |
+
size_t blocks, const uint32_t key[8],
|
| 269 |
+
uint64_t counter, bool increment_counter,
|
| 270 |
+
uint8_t flags, uint8_t flags_start,
|
| 271 |
+
uint8_t flags_end, uint8_t *out);
|
| 272 |
+
#endif
|
| 273 |
+
#if !defined(BLAKE3_NO_AVX512)
|
| 274 |
+
LLVM_LIBRARY_VISIBILITY
|
| 275 |
+
void blake3_compress_in_place_avx512(uint32_t cv[8],
|
| 276 |
+
const uint8_t block[BLAKE3_BLOCK_LEN],
|
| 277 |
+
uint8_t block_len, uint64_t counter,
|
| 278 |
+
uint8_t flags);
|
| 279 |
+
|
| 280 |
+
LLVM_LIBRARY_VISIBILITY
|
| 281 |
+
void blake3_compress_xof_avx512(const uint32_t cv[8],
|
| 282 |
+
const uint8_t block[BLAKE3_BLOCK_LEN],
|
| 283 |
+
uint8_t block_len, uint64_t counter,
|
| 284 |
+
uint8_t flags, uint8_t out[64]);
|
| 285 |
+
|
| 286 |
+
LLVM_LIBRARY_VISIBILITY
|
| 287 |
+
void blake3_hash_many_avx512(const uint8_t *const *inputs, size_t num_inputs,
|
| 288 |
+
size_t blocks, const uint32_t key[8],
|
| 289 |
+
uint64_t counter, bool increment_counter,
|
| 290 |
+
uint8_t flags, uint8_t flags_start,
|
| 291 |
+
uint8_t flags_end, uint8_t *out);
|
| 292 |
+
#endif
|
| 293 |
+
#endif
|
| 294 |
+
|
| 295 |
+
#if BLAKE3_USE_NEON == 1
|
| 296 |
+
LLVM_LIBRARY_VISIBILITY
|
| 297 |
+
void blake3_hash_many_neon(const uint8_t *const *inputs, size_t num_inputs,
|
| 298 |
+
size_t blocks, const uint32_t key[8],
|
| 299 |
+
uint64_t counter, bool increment_counter,
|
| 300 |
+
uint8_t flags, uint8_t flags_start,
|
| 301 |
+
uint8_t flags_end, uint8_t *out);
|
| 302 |
+
#endif
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
#endif /* BLAKE3_IMPL_H */
|
deps/exla/cache/xla_extension/include/llvm/lib/Support/BLAKE3/llvm_blake3_prefix.h
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef LLVM_BLAKE3_PREFIX_H
|
| 2 |
+
#define LLVM_BLAKE3_PREFIX_H
|
| 3 |
+
|
| 4 |
+
#define BLAKE3_VERSION_STRING LLVM_BLAKE3_VERSION_STRING
|
| 5 |
+
#define BLAKE3_KEY_LEN LLVM_BLAKE3_KEY_LEN
|
| 6 |
+
#define BLAKE3_OUT_LEN LLVM_BLAKE3_OUT_LEN
|
| 7 |
+
#define BLAKE3_BLOCK_LEN LLVM_BLAKE3_BLOCK_LEN
|
| 8 |
+
#define BLAKE3_CHUNK_LEN LLVM_BLAKE3_CHUNK_LEN
|
| 9 |
+
#define BLAKE3_MAX_DEPTH LLVM_BLAKE3_MAX_DEPTH
|
| 10 |
+
#define blake3_hasher llvm_blake3_hasher
|
| 11 |
+
#define blake3_chunk_state llvm_blake3_chunk_state
|
| 12 |
+
#define blake3_compress_in_place llvm_blake3_compress_in_place
|
| 13 |
+
#define blake3_compress_xof llvm_blake3_compress_xof
|
| 14 |
+
#define blake3_hash_many llvm_blake3_hash_many
|
| 15 |
+
#define blake3_simd_degree llvm_blake3_simd_degree
|
| 16 |
+
#define blake3_compress_in_place_portable llvm_blake3_compress_in_place_portable
|
| 17 |
+
#define blake3_compress_xof_portable llvm_blake3_compress_xof_portable
|
| 18 |
+
#define blake3_hash_many_portable llvm_blake3_hash_many_portable
|
| 19 |
+
#define blake3_compress_in_place_sse2 llvm_blake3_compress_in_place_sse2
|
| 20 |
+
#define _blake3_compress_in_place_sse2 _llvm_blake3_compress_in_place_sse2
|
| 21 |
+
#define blake3_compress_xof_sse2 llvm_blake3_compress_xof_sse2
|
| 22 |
+
#define _blake3_compress_xof_sse2 _llvm_blake3_compress_xof_sse2
|
| 23 |
+
#define blake3_hash_many_sse2 llvm_blake3_hash_many_sse2
|
| 24 |
+
#define _blake3_hash_many_sse2 _llvm_blake3_hash_many_sse2
|
| 25 |
+
#define blake3_compress_in_place_sse41 llvm_blake3_compress_in_place_sse41
|
| 26 |
+
#define _blake3_compress_in_place_sse41 _llvm_blake3_compress_in_place_sse41
|
| 27 |
+
#define blake3_compress_xof_sse41 llvm_blake3_compress_xof_sse41
|
| 28 |
+
#define _blake3_compress_xof_sse41 _llvm_blake3_compress_xof_sse41
|
| 29 |
+
#define blake3_hash_many_sse41 llvm_blake3_hash_many_sse41
|
| 30 |
+
#define _blake3_hash_many_sse41 _llvm_blake3_hash_many_sse41
|
| 31 |
+
#define blake3_hash_many_avx2 llvm_blake3_hash_many_avx2
|
| 32 |
+
#define _blake3_hash_many_avx2 _llvm_blake3_hash_many_avx2
|
| 33 |
+
#define blake3_compress_in_place_avx512 llvm_blake3_compress_in_place_avx512
|
| 34 |
+
#define _blake3_compress_in_place_avx512 _llvm_blake3_compress_in_place_avx512
|
| 35 |
+
#define blake3_compress_xof_avx512 llvm_blake3_compress_xof_avx512
|
| 36 |
+
#define _blake3_compress_xof_avx512 _llvm_blake3_compress_xof_avx512
|
| 37 |
+
#define blake3_hash_many_avx512 llvm_blake3_hash_many_avx512
|
| 38 |
+
#define _blake3_hash_many_avx512 _llvm_blake3_hash_many_avx512
|
| 39 |
+
#define blake3_hash_many_neon llvm_blake3_hash_many_neon
|
| 40 |
+
|
| 41 |
+
#endif /* LLVM_BLAKE3_PREFIX_H */
|
deps/exla/cache/xla_extension/include/llvm/lib/Support/DebugOptions.h
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===-- DebugOptions.h - Global Command line opt for libSupport *- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file defines the entry point to initialize the options registered on the
|
| 10 |
+
// command line for libSupport, this is internal to libSupport.
|
| 11 |
+
//
|
| 12 |
+
//===----------------------------------------------------------------------===//
|
| 13 |
+
|
| 14 |
+
#ifndef LLVM_SUPPORT_DEBUGOPTIONS_H
|
| 15 |
+
#define LLVM_SUPPORT_DEBUGOPTIONS_H
|
| 16 |
+
|
| 17 |
+
namespace llvm {
|
| 18 |
+
|
| 19 |
+
// These are invoked internally before parsing command line options.
|
| 20 |
+
// This enables lazy-initialization of all the globals in libSupport, instead
|
| 21 |
+
// of eagerly loading everything on program startup.
|
| 22 |
+
void initDebugCounterOptions();
|
| 23 |
+
void initGraphWriterOptions();
|
| 24 |
+
void initSignalsOptions();
|
| 25 |
+
void initStatisticOptions();
|
| 26 |
+
void initTimerOptions();
|
| 27 |
+
void initTypeSizeOptions();
|
| 28 |
+
void initWithColorOptions();
|
| 29 |
+
void initDebugOptions();
|
| 30 |
+
void initRandomSeedOptions();
|
| 31 |
+
|
| 32 |
+
} // namespace llvm
|
| 33 |
+
|
| 34 |
+
#endif // LLVM_SUPPORT_DEBUGOPTIONS_H
|
deps/exla/cache/xla_extension/include/llvm/lib/Support/Unix/COM.inc
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- llvm/Support/Unix/COM.inc - Unix COM Implementation -----*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file implements the Unix portion of COM support.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
//===----------------------------------------------------------------------===//
|
| 14 |
+
//=== WARNING: Implementation here must contain only generic UNIX code that
|
| 15 |
+
//=== is guaranteed to work on *all* UNIX variants.
|
| 16 |
+
//===----------------------------------------------------------------------===//
|
| 17 |
+
|
| 18 |
+
namespace llvm {
|
| 19 |
+
namespace sys {
|
| 20 |
+
|
| 21 |
+
InitializeCOMRAII::InitializeCOMRAII(COMThreadingMode Threading,
|
| 22 |
+
bool SpeedOverMemory) {}
|
| 23 |
+
|
| 24 |
+
InitializeCOMRAII::~InitializeCOMRAII() = default;
|
| 25 |
+
} // namespace sys
|
| 26 |
+
} // namespace llvm
|
deps/exla/cache/xla_extension/include/llvm/lib/Support/Unix/DynamicLibrary.inc
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- Unix/DynamicLibrary.cpp - Unix DL Implementation ---------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file provides the UNIX specific implementation of DynamicLibrary.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#if defined(HAVE_DLOPEN)
|
| 14 |
+
#include <dlfcn.h>
|
| 15 |
+
|
| 16 |
+
DynamicLibrary::HandleSet::~HandleSet() {
|
| 17 |
+
// Close the libraries in reverse order.
|
| 18 |
+
for (void *Handle : llvm::reverse(Handles))
|
| 19 |
+
::dlclose(Handle);
|
| 20 |
+
if (Process != &Invalid)
|
| 21 |
+
::dlclose(Process);
|
| 22 |
+
|
| 23 |
+
// llvm_shutdown called, Return to default
|
| 24 |
+
DynamicLibrary::SearchOrder = DynamicLibrary::SO_Linker;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
void *DynamicLibrary::HandleSet::DLOpen(const char *File, std::string *Err) {
|
| 28 |
+
void *Handle = ::dlopen(File, RTLD_LAZY | RTLD_GLOBAL);
|
| 29 |
+
if (!Handle) {
|
| 30 |
+
if (Err)
|
| 31 |
+
*Err = ::dlerror();
|
| 32 |
+
return &DynamicLibrary::Invalid;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
#ifdef __CYGWIN__
|
| 36 |
+
// Cygwin searches symbols only in the main
|
| 37 |
+
// with the handle of dlopen(NULL, RTLD_GLOBAL).
|
| 38 |
+
if (!File)
|
| 39 |
+
Handle = RTLD_DEFAULT;
|
| 40 |
+
#endif
|
| 41 |
+
|
| 42 |
+
return Handle;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
void DynamicLibrary::HandleSet::DLClose(void *Handle) { ::dlclose(Handle); }
|
| 46 |
+
|
| 47 |
+
void *DynamicLibrary::HandleSet::DLSym(void *Handle, const char *Symbol) {
|
| 48 |
+
return ::dlsym(Handle, Symbol);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
#else // !HAVE_DLOPEN
|
| 52 |
+
|
| 53 |
+
DynamicLibrary::HandleSet::~HandleSet() {}
|
| 54 |
+
|
| 55 |
+
void *DynamicLibrary::HandleSet::DLOpen(const char *File, std::string *Err) {
|
| 56 |
+
if (Err)
|
| 57 |
+
*Err = "dlopen() not supported on this platform";
|
| 58 |
+
return &Invalid;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
void DynamicLibrary::HandleSet::DLClose(void *Handle) {}
|
| 62 |
+
|
| 63 |
+
void *DynamicLibrary::HandleSet::DLSym(void *Handle, const char *Symbol) {
|
| 64 |
+
return nullptr;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
#endif
|
| 68 |
+
|
| 69 |
+
// Must declare the symbols in the global namespace.
|
| 70 |
+
static void *DoSearch(const char *SymbolName) {
|
| 71 |
+
#define EXPLICIT_SYMBOL(SYM) \
|
| 72 |
+
extern void *SYM; \
|
| 73 |
+
if (!strcmp(SymbolName, #SYM)) \
|
| 74 |
+
return (void *)&SYM
|
| 75 |
+
|
| 76 |
+
// If this is darwin, it has some funky issues, try to solve them here. Some
|
| 77 |
+
// important symbols are marked 'private external' which doesn't allow
|
| 78 |
+
// SearchForAddressOfSymbol to find them. As such, we special case them here,
|
| 79 |
+
// there is only a small handful of them.
|
| 80 |
+
|
| 81 |
+
#ifdef __APPLE__
|
| 82 |
+
{
|
| 83 |
+
// __eprintf is sometimes used for assert() handling on x86.
|
| 84 |
+
//
|
| 85 |
+
// FIXME: Currently disabled when using Clang, as we don't always have our
|
| 86 |
+
// runtime support libraries available.
|
| 87 |
+
#ifndef __clang__
|
| 88 |
+
#ifdef __i386__
|
| 89 |
+
EXPLICIT_SYMBOL(__eprintf);
|
| 90 |
+
#endif
|
| 91 |
+
#endif
|
| 92 |
+
}
|
| 93 |
+
#endif
|
| 94 |
+
|
| 95 |
+
#ifdef __CYGWIN__
|
| 96 |
+
{
|
| 97 |
+
EXPLICIT_SYMBOL(_alloca);
|
| 98 |
+
EXPLICIT_SYMBOL(__main);
|
| 99 |
+
}
|
| 100 |
+
#endif
|
| 101 |
+
|
| 102 |
+
#undef EXPLICIT_SYMBOL
|
| 103 |
+
|
| 104 |
+
// This macro returns the address of a well-known, explicit symbol
|
| 105 |
+
#define EXPLICIT_SYMBOL(SYM) \
|
| 106 |
+
if (!strcmp(SymbolName, #SYM)) \
|
| 107 |
+
return &SYM
|
| 108 |
+
|
| 109 |
+
// Under glibc we have a weird situation. The stderr/out/in symbols are both
|
| 110 |
+
// macros and global variables because of standards requirements. So, we
|
| 111 |
+
// boldly use the EXPLICIT_SYMBOL macro without checking for a #define first.
|
| 112 |
+
#if defined(__GLIBC__)
|
| 113 |
+
{
|
| 114 |
+
EXPLICIT_SYMBOL(stderr);
|
| 115 |
+
EXPLICIT_SYMBOL(stdout);
|
| 116 |
+
EXPLICIT_SYMBOL(stdin);
|
| 117 |
+
}
|
| 118 |
+
#else
|
| 119 |
+
// For everything else, we want to check to make sure the symbol isn't defined
|
| 120 |
+
// as a macro before using EXPLICIT_SYMBOL.
|
| 121 |
+
{
|
| 122 |
+
#ifndef stdin
|
| 123 |
+
EXPLICIT_SYMBOL(stdin);
|
| 124 |
+
#endif
|
| 125 |
+
#ifndef stdout
|
| 126 |
+
EXPLICIT_SYMBOL(stdout);
|
| 127 |
+
#endif
|
| 128 |
+
#ifndef stderr
|
| 129 |
+
EXPLICIT_SYMBOL(stderr);
|
| 130 |
+
#endif
|
| 131 |
+
}
|
| 132 |
+
#endif
|
| 133 |
+
#undef EXPLICIT_SYMBOL
|
| 134 |
+
|
| 135 |
+
return nullptr;
|
| 136 |
+
}
|
deps/exla/cache/xla_extension/include/llvm/lib/Support/Unix/Memory.inc
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- Unix/Memory.cpp - Generic UNIX System Configuration ------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file defines some functions for various memory management utilities.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#include "Unix.h"
|
| 14 |
+
#include "llvm/Config/config.h"
|
| 15 |
+
#include "llvm/Support/Alignment.h"
|
| 16 |
+
#include "llvm/Support/DataTypes.h"
|
| 17 |
+
#include "llvm/Support/ErrorHandling.h"
|
| 18 |
+
#include "llvm/Support/Process.h"
|
| 19 |
+
#include "llvm/Support/Valgrind.h"
|
| 20 |
+
|
| 21 |
+
#ifdef HAVE_SYS_MMAN_H
|
| 22 |
+
#include <sys/mman.h>
|
| 23 |
+
#endif
|
| 24 |
+
|
| 25 |
+
#ifdef __APPLE__
|
| 26 |
+
#include <mach/mach.h>
|
| 27 |
+
#endif
|
| 28 |
+
|
| 29 |
+
#ifdef __Fuchsia__
|
| 30 |
+
#include <zircon/syscalls.h>
|
| 31 |
+
#endif
|
| 32 |
+
|
| 33 |
+
#if defined(__APPLE__)
|
| 34 |
+
extern "C" void sys_icache_invalidate(const void *Addr, size_t len);
|
| 35 |
+
#else
|
| 36 |
+
extern "C" void __clear_cache(void *, void *);
|
| 37 |
+
#endif
|
| 38 |
+
|
| 39 |
+
static int getPosixProtectionFlags(unsigned Flags) {
|
| 40 |
+
switch (Flags & llvm::sys::Memory::MF_RWE_MASK) {
|
| 41 |
+
case llvm::sys::Memory::MF_READ:
|
| 42 |
+
return PROT_READ;
|
| 43 |
+
case llvm::sys::Memory::MF_WRITE:
|
| 44 |
+
return PROT_WRITE;
|
| 45 |
+
case llvm::sys::Memory::MF_READ | llvm::sys::Memory::MF_WRITE:
|
| 46 |
+
return PROT_READ | PROT_WRITE;
|
| 47 |
+
case llvm::sys::Memory::MF_READ | llvm::sys::Memory::MF_EXEC:
|
| 48 |
+
return PROT_READ | PROT_EXEC;
|
| 49 |
+
case llvm::sys::Memory::MF_READ | llvm::sys::Memory::MF_WRITE |
|
| 50 |
+
llvm::sys::Memory::MF_EXEC:
|
| 51 |
+
return PROT_READ | PROT_WRITE | PROT_EXEC;
|
| 52 |
+
case llvm::sys::Memory::MF_EXEC:
|
| 53 |
+
#if defined(__FreeBSD__) || defined(__powerpc__)
|
| 54 |
+
// On PowerPC, having an executable page that has no read permission
|
| 55 |
+
// can have unintended consequences. The function InvalidateInstruction-
|
| 56 |
+
// Cache uses instructions dcbf and icbi, both of which are treated by
|
| 57 |
+
// the processor as loads. If the page has no read permissions,
|
| 58 |
+
// executing these instructions will result in a segmentation fault.
|
| 59 |
+
return PROT_READ | PROT_EXEC;
|
| 60 |
+
#else
|
| 61 |
+
return PROT_EXEC;
|
| 62 |
+
#endif
|
| 63 |
+
default:
|
| 64 |
+
llvm_unreachable("Illegal memory protection flag specified!");
|
| 65 |
+
}
|
| 66 |
+
// Provide a default return value as required by some compilers.
|
| 67 |
+
return PROT_NONE;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
namespace llvm {
|
| 71 |
+
namespace sys {
|
| 72 |
+
|
| 73 |
+
MemoryBlock Memory::allocateMappedMemory(size_t NumBytes,
|
| 74 |
+
const MemoryBlock *const NearBlock,
|
| 75 |
+
unsigned PFlags, std::error_code &EC) {
|
| 76 |
+
EC = std::error_code();
|
| 77 |
+
if (NumBytes == 0)
|
| 78 |
+
return MemoryBlock();
|
| 79 |
+
|
| 80 |
+
// On platforms that have it, we can use MAP_ANON to get a memory-mapped
|
| 81 |
+
// page without file backing, but we need a fallback of opening /dev/zero
|
| 82 |
+
// for strictly POSIX platforms instead.
|
| 83 |
+
int fd;
|
| 84 |
+
#if defined(MAP_ANON)
|
| 85 |
+
fd = -1;
|
| 86 |
+
#else
|
| 87 |
+
fd = open("/dev/zero", O_RDWR);
|
| 88 |
+
if (fd == -1) {
|
| 89 |
+
EC = errnoAsErrorCode();
|
| 90 |
+
return MemoryBlock();
|
| 91 |
+
}
|
| 92 |
+
#endif
|
| 93 |
+
|
| 94 |
+
int MMFlags = MAP_PRIVATE;
|
| 95 |
+
#if defined(MAP_ANON)
|
| 96 |
+
MMFlags |= MAP_ANON;
|
| 97 |
+
#endif
|
| 98 |
+
int Protect = getPosixProtectionFlags(PFlags);
|
| 99 |
+
|
| 100 |
+
#if defined(__NetBSD__) && defined(PROT_MPROTECT)
|
| 101 |
+
Protect |= PROT_MPROTECT(PROT_READ | PROT_WRITE | PROT_EXEC);
|
| 102 |
+
#endif
|
| 103 |
+
|
| 104 |
+
// Use any near hint and the page size to set a page-aligned starting address
|
| 105 |
+
uintptr_t Start = NearBlock ? reinterpret_cast<uintptr_t>(NearBlock->base()) +
|
| 106 |
+
NearBlock->allocatedSize()
|
| 107 |
+
: 0;
|
| 108 |
+
static const size_t PageSize = Process::getPageSizeEstimate();
|
| 109 |
+
const size_t NumPages = (NumBytes + PageSize - 1) / PageSize;
|
| 110 |
+
|
| 111 |
+
if (Start && Start % PageSize)
|
| 112 |
+
Start += PageSize - Start % PageSize;
|
| 113 |
+
|
| 114 |
+
// FIXME: Handle huge page requests (MF_HUGE_HINT).
|
| 115 |
+
void *Addr = ::mmap(reinterpret_cast<void *>(Start), PageSize * NumPages,
|
| 116 |
+
Protect, MMFlags, fd, 0);
|
| 117 |
+
if (Addr == MAP_FAILED) {
|
| 118 |
+
if (NearBlock) { // Try again without a near hint
|
| 119 |
+
#if !defined(MAP_ANON)
|
| 120 |
+
close(fd);
|
| 121 |
+
#endif
|
| 122 |
+
return allocateMappedMemory(NumBytes, nullptr, PFlags, EC);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
EC = errnoAsErrorCode();
|
| 126 |
+
#if !defined(MAP_ANON)
|
| 127 |
+
close(fd);
|
| 128 |
+
#endif
|
| 129 |
+
return MemoryBlock();
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
#if !defined(MAP_ANON)
|
| 133 |
+
close(fd);
|
| 134 |
+
#endif
|
| 135 |
+
|
| 136 |
+
MemoryBlock Result;
|
| 137 |
+
Result.Address = Addr;
|
| 138 |
+
Result.AllocatedSize = PageSize * NumPages;
|
| 139 |
+
Result.Flags = PFlags;
|
| 140 |
+
|
| 141 |
+
// Rely on protectMappedMemory to invalidate instruction cache.
|
| 142 |
+
if (PFlags & MF_EXEC) {
|
| 143 |
+
EC = Memory::protectMappedMemory(Result, PFlags);
|
| 144 |
+
if (EC != std::error_code())
|
| 145 |
+
return MemoryBlock();
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
return Result;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
std::error_code Memory::releaseMappedMemory(MemoryBlock &M) {
|
| 152 |
+
if (M.Address == nullptr || M.AllocatedSize == 0)
|
| 153 |
+
return std::error_code();
|
| 154 |
+
|
| 155 |
+
if (0 != ::munmap(M.Address, M.AllocatedSize))
|
| 156 |
+
return errnoAsErrorCode();
|
| 157 |
+
|
| 158 |
+
M.Address = nullptr;
|
| 159 |
+
M.AllocatedSize = 0;
|
| 160 |
+
|
| 161 |
+
return std::error_code();
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
std::error_code Memory::protectMappedMemory(const MemoryBlock &M,
|
| 165 |
+
unsigned Flags) {
|
| 166 |
+
static const Align PageSize = Align(Process::getPageSizeEstimate());
|
| 167 |
+
if (M.Address == nullptr || M.AllocatedSize == 0)
|
| 168 |
+
return std::error_code();
|
| 169 |
+
|
| 170 |
+
if (!Flags)
|
| 171 |
+
return std::error_code(EINVAL, std::generic_category());
|
| 172 |
+
|
| 173 |
+
int Protect = getPosixProtectionFlags(Flags);
|
| 174 |
+
uintptr_t Start =
|
| 175 |
+
alignAddr((const uint8_t *)M.Address - PageSize.value() + 1, PageSize);
|
| 176 |
+
uintptr_t End =
|
| 177 |
+
alignAddr((const uint8_t *)M.Address + M.AllocatedSize, PageSize);
|
| 178 |
+
|
| 179 |
+
bool InvalidateCache = (Flags & MF_EXEC);
|
| 180 |
+
|
| 181 |
+
#if defined(__arm__) || defined(__aarch64__)
|
| 182 |
+
// Certain ARM implementations treat icache clear instruction as a memory
|
| 183 |
+
// read, and CPU segfaults on trying to clear cache on !PROT_READ page.
|
| 184 |
+
// Therefore we need to temporarily add PROT_READ for the sake of flushing the
|
| 185 |
+
// instruction caches.
|
| 186 |
+
if (InvalidateCache && !(Protect & PROT_READ)) {
|
| 187 |
+
int Result = ::mprotect((void *)Start, End - Start, Protect | PROT_READ);
|
| 188 |
+
if (Result != 0)
|
| 189 |
+
return errnoAsErrorCode();
|
| 190 |
+
|
| 191 |
+
Memory::InvalidateInstructionCache(M.Address, M.AllocatedSize);
|
| 192 |
+
InvalidateCache = false;
|
| 193 |
+
}
|
| 194 |
+
#endif
|
| 195 |
+
|
| 196 |
+
int Result = ::mprotect((void *)Start, End - Start, Protect);
|
| 197 |
+
|
| 198 |
+
if (Result != 0)
|
| 199 |
+
return errnoAsErrorCode();
|
| 200 |
+
|
| 201 |
+
if (InvalidateCache)
|
| 202 |
+
Memory::InvalidateInstructionCache(M.Address, M.AllocatedSize);
|
| 203 |
+
|
| 204 |
+
return std::error_code();
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
/// InvalidateInstructionCache - Before the JIT can run a block of code
|
| 208 |
+
/// that has been emitted it must invalidate the instruction cache on some
|
| 209 |
+
/// platforms.
|
| 210 |
+
void Memory::InvalidateInstructionCache(const void *Addr, size_t Len) {
|
| 211 |
+
|
| 212 |
+
// icache invalidation for PPC and ARM.
|
| 213 |
+
#if defined(__APPLE__)
|
| 214 |
+
|
| 215 |
+
#if (defined(__powerpc__) || defined(__arm__) || defined(__arm64__))
|
| 216 |
+
sys_icache_invalidate(const_cast<void *>(Addr), Len);
|
| 217 |
+
#endif
|
| 218 |
+
|
| 219 |
+
#elif defined(__Fuchsia__)
|
| 220 |
+
|
| 221 |
+
zx_status_t Status = zx_cache_flush(Addr, Len, ZX_CACHE_FLUSH_INSN);
|
| 222 |
+
assert(Status == ZX_OK && "cannot invalidate instruction cache");
|
| 223 |
+
|
| 224 |
+
#else
|
| 225 |
+
|
| 226 |
+
#if defined(__powerpc__) && defined(__GNUC__)
|
| 227 |
+
const size_t LineSize = 32;
|
| 228 |
+
|
| 229 |
+
const intptr_t Mask = ~(LineSize - 1);
|
| 230 |
+
const intptr_t StartLine = ((intptr_t)Addr) & Mask;
|
| 231 |
+
const intptr_t EndLine = ((intptr_t)Addr + Len + LineSize - 1) & Mask;
|
| 232 |
+
|
| 233 |
+
for (intptr_t Line = StartLine; Line < EndLine; Line += LineSize)
|
| 234 |
+
asm volatile("dcbf 0, %0" : : "r"(Line));
|
| 235 |
+
asm volatile("sync");
|
| 236 |
+
|
| 237 |
+
for (intptr_t Line = StartLine; Line < EndLine; Line += LineSize)
|
| 238 |
+
asm volatile("icbi 0, %0" : : "r"(Line));
|
| 239 |
+
asm volatile("isync");
|
| 240 |
+
#elif (defined(__arm__) || defined(__aarch64__) || defined(__loongarch__) || \
|
| 241 |
+
defined(__mips__)) && \
|
| 242 |
+
defined(__GNUC__)
|
| 243 |
+
// FIXME: Can we safely always call this for __GNUC__ everywhere?
|
| 244 |
+
const char *Start = static_cast<const char *>(Addr);
|
| 245 |
+
const char *End = Start + Len;
|
| 246 |
+
__clear_cache(const_cast<char *>(Start), const_cast<char *>(End));
|
| 247 |
+
#endif
|
| 248 |
+
|
| 249 |
+
#endif // end apple
|
| 250 |
+
|
| 251 |
+
ValgrindDiscardTranslations(Addr, Len);
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
} // namespace sys
|
| 255 |
+
} // namespace llvm
|
deps/exla/cache/xla_extension/include/llvm/lib/Support/Unix/Path.inc
ADDED
|
@@ -0,0 +1,1532 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- llvm/Support/Unix/Path.inc - Unix Path Implementation ----*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file implements the Unix specific implementation of the Path API.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
//===----------------------------------------------------------------------===//
|
| 14 |
+
//=== WARNING: Implementation here must contain only generic UNIX code that
|
| 15 |
+
//=== is guaranteed to work on *all* UNIX variants.
|
| 16 |
+
//===----------------------------------------------------------------------===//
|
| 17 |
+
|
| 18 |
+
#include "Unix.h"
|
| 19 |
+
#include <limits.h>
|
| 20 |
+
#include <stdio.h>
|
| 21 |
+
#include <sys/stat.h>
|
| 22 |
+
#include <fcntl.h>
|
| 23 |
+
#ifdef HAVE_UNISTD_H
|
| 24 |
+
#include <unistd.h>
|
| 25 |
+
#endif
|
| 26 |
+
#ifdef HAVE_SYS_MMAN_H
|
| 27 |
+
#include <sys/mman.h>
|
| 28 |
+
#endif
|
| 29 |
+
|
| 30 |
+
#include <dirent.h>
|
| 31 |
+
#include <pwd.h>
|
| 32 |
+
|
| 33 |
+
#ifdef __APPLE__
|
| 34 |
+
#include <copyfile.h>
|
| 35 |
+
#include <mach-o/dyld.h>
|
| 36 |
+
#include <sys/attr.h>
|
| 37 |
+
#if __has_include(<sys/clonefile.h>)
|
| 38 |
+
#include <sys/clonefile.h>
|
| 39 |
+
#endif
|
| 40 |
+
#elif defined(__FreeBSD__)
|
| 41 |
+
#include <osreldate.h>
|
| 42 |
+
#if __FreeBSD_version >= 1300057
|
| 43 |
+
#include <sys/auxv.h>
|
| 44 |
+
#else
|
| 45 |
+
#include <machine/elf.h>
|
| 46 |
+
extern char **environ;
|
| 47 |
+
#endif
|
| 48 |
+
#elif defined(__DragonFly__)
|
| 49 |
+
#include <sys/mount.h>
|
| 50 |
+
#elif defined(__MVS__)
|
| 51 |
+
#include "llvm/Support/AutoConvert.h"
|
| 52 |
+
#include <sys/ps.h>
|
| 53 |
+
#endif
|
| 54 |
+
|
| 55 |
+
// Both stdio.h and cstdio are included via different paths and
|
| 56 |
+
// stdcxx's cstdio doesn't include stdio.h, so it doesn't #undef the macros
|
| 57 |
+
// either.
|
| 58 |
+
#undef ferror
|
| 59 |
+
#undef feof
|
| 60 |
+
|
| 61 |
+
#if !defined(PATH_MAX)
|
| 62 |
+
// For GNU Hurd
|
| 63 |
+
#if defined(__GNU__)
|
| 64 |
+
#define PATH_MAX 4096
|
| 65 |
+
#elif defined(__MVS__)
|
| 66 |
+
#define PATH_MAX _XOPEN_PATH_MAX
|
| 67 |
+
#endif
|
| 68 |
+
#endif
|
| 69 |
+
|
| 70 |
+
#include <sys/types.h>
|
| 71 |
+
#if !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && \
|
| 72 |
+
!defined(__linux__) && !defined(__FreeBSD_kernel__) && !defined(_AIX) && \
|
| 73 |
+
!defined(__managarm__)
|
| 74 |
+
#include <sys/statvfs.h>
|
| 75 |
+
#define STATVFS statvfs
|
| 76 |
+
#define FSTATVFS fstatvfs
|
| 77 |
+
#define STATVFS_F_FRSIZE(vfs) vfs.f_frsize
|
| 78 |
+
#else
|
| 79 |
+
#if defined(__OpenBSD__) || defined(__FreeBSD__)
|
| 80 |
+
#include <sys/mount.h>
|
| 81 |
+
#include <sys/param.h>
|
| 82 |
+
#elif defined(__linux__) || defined(__managarm__)
|
| 83 |
+
#if defined(HAVE_LINUX_MAGIC_H)
|
| 84 |
+
#include <linux/magic.h>
|
| 85 |
+
#else
|
| 86 |
+
#if defined(HAVE_LINUX_NFS_FS_H)
|
| 87 |
+
#include <linux/nfs_fs.h>
|
| 88 |
+
#endif
|
| 89 |
+
#if defined(HAVE_LINUX_SMB_H)
|
| 90 |
+
#include <linux/smb.h>
|
| 91 |
+
#endif
|
| 92 |
+
#endif
|
| 93 |
+
#include <sys/vfs.h>
|
| 94 |
+
#elif defined(_AIX)
|
| 95 |
+
#include <sys/statfs.h>
|
| 96 |
+
|
| 97 |
+
// <sys/vmount.h> depends on `uint` to be a typedef from <sys/types.h> to
|
| 98 |
+
// `uint_t`; however, <sys/types.h> does not always declare `uint`. We provide
|
| 99 |
+
// the typedef prior to including <sys/vmount.h> to work around this issue.
|
| 100 |
+
typedef uint_t uint;
|
| 101 |
+
#include <sys/vmount.h>
|
| 102 |
+
#else
|
| 103 |
+
#include <sys/mount.h>
|
| 104 |
+
#endif
|
| 105 |
+
#define STATVFS statfs
|
| 106 |
+
#define FSTATVFS fstatfs
|
| 107 |
+
#define STATVFS_F_FRSIZE(vfs) static_cast<uint64_t>(vfs.f_bsize)
|
| 108 |
+
#endif
|
| 109 |
+
|
| 110 |
+
#if defined(__NetBSD__) || defined(__DragonFly__) || defined(__GNU__) || \
|
| 111 |
+
defined(__MVS__)
|
| 112 |
+
#define STATVFS_F_FLAG(vfs) (vfs).f_flag
|
| 113 |
+
#else
|
| 114 |
+
#define STATVFS_F_FLAG(vfs) (vfs).f_flags
|
| 115 |
+
#endif
|
| 116 |
+
|
| 117 |
+
using namespace llvm;
|
| 118 |
+
|
| 119 |
+
namespace llvm {
|
| 120 |
+
namespace sys {
|
| 121 |
+
namespace fs {
|
| 122 |
+
|
| 123 |
+
const file_t kInvalidFile = -1;
|
| 124 |
+
|
| 125 |
+
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
|
| 126 |
+
defined(__FreeBSD_kernel__) || defined(__linux__) || \
|
| 127 |
+
defined(__CYGWIN__) || defined(__DragonFly__) || defined(_AIX) || \
|
| 128 |
+
defined(__GNU__) || \
|
| 129 |
+
(defined(__sun__) && defined(__svr4__) || defined(__HAIKU__)) || \
|
| 130 |
+
defined(__managarm__)
|
| 131 |
+
static int test_dir(char ret[PATH_MAX], const char *dir, const char *bin) {
|
| 132 |
+
struct stat sb;
|
| 133 |
+
char fullpath[PATH_MAX];
|
| 134 |
+
|
| 135 |
+
int chars = snprintf(fullpath, PATH_MAX, "%s/%s", dir, bin);
|
| 136 |
+
// We cannot write PATH_MAX characters because the string will be terminated
|
| 137 |
+
// with a null character. Fail if truncation happened.
|
| 138 |
+
if (chars >= PATH_MAX)
|
| 139 |
+
return 1;
|
| 140 |
+
if (!realpath(fullpath, ret))
|
| 141 |
+
return 1;
|
| 142 |
+
if (stat(fullpath, &sb) != 0)
|
| 143 |
+
return 1;
|
| 144 |
+
|
| 145 |
+
return 0;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
static char *getprogpath(char ret[PATH_MAX], const char *bin) {
|
| 149 |
+
if (bin == nullptr)
|
| 150 |
+
return nullptr;
|
| 151 |
+
|
| 152 |
+
/* First approach: absolute path. */
|
| 153 |
+
if (bin[0] == '/') {
|
| 154 |
+
if (test_dir(ret, "/", bin) == 0)
|
| 155 |
+
return ret;
|
| 156 |
+
return nullptr;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
/* Second approach: relative path. */
|
| 160 |
+
if (strchr(bin, '/')) {
|
| 161 |
+
char cwd[PATH_MAX];
|
| 162 |
+
if (!getcwd(cwd, PATH_MAX))
|
| 163 |
+
return nullptr;
|
| 164 |
+
if (test_dir(ret, cwd, bin) == 0)
|
| 165 |
+
return ret;
|
| 166 |
+
return nullptr;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
/* Third approach: $PATH */
|
| 170 |
+
char *pv;
|
| 171 |
+
if ((pv = getenv("PATH")) == nullptr)
|
| 172 |
+
return nullptr;
|
| 173 |
+
char *s = strdup(pv);
|
| 174 |
+
if (!s)
|
| 175 |
+
return nullptr;
|
| 176 |
+
char *state;
|
| 177 |
+
for (char *t = strtok_r(s, ":", &state); t != nullptr;
|
| 178 |
+
t = strtok_r(nullptr, ":", &state)) {
|
| 179 |
+
if (test_dir(ret, t, bin) == 0) {
|
| 180 |
+
free(s);
|
| 181 |
+
return ret;
|
| 182 |
+
}
|
| 183 |
+
}
|
| 184 |
+
free(s);
|
| 185 |
+
return nullptr;
|
| 186 |
+
}
|
| 187 |
+
#endif // __FreeBSD__ || __NetBSD__ || __FreeBSD_kernel__
|
| 188 |
+
|
| 189 |
+
/// GetMainExecutable - Return the path to the main executable, given the
|
| 190 |
+
/// value of argv[0] from program startup.
|
| 191 |
+
std::string getMainExecutable(const char *argv0, void *MainAddr) {
|
| 192 |
+
#if defined(__APPLE__)
|
| 193 |
+
// On OS X the executable path is saved to the stack by dyld. Reading it
|
| 194 |
+
// from there is much faster than calling dladdr, especially for large
|
| 195 |
+
// binaries with symbols.
|
| 196 |
+
char exe_path[PATH_MAX];
|
| 197 |
+
uint32_t size = sizeof(exe_path);
|
| 198 |
+
if (_NSGetExecutablePath(exe_path, &size) == 0) {
|
| 199 |
+
char link_path[PATH_MAX];
|
| 200 |
+
if (realpath(exe_path, link_path))
|
| 201 |
+
return link_path;
|
| 202 |
+
}
|
| 203 |
+
#elif defined(__FreeBSD__)
|
| 204 |
+
// On FreeBSD if the exec path specified in ELF auxiliary vectors is
|
| 205 |
+
// preferred, if available. /proc/curproc/file and the KERN_PROC_PATHNAME
|
| 206 |
+
// sysctl may not return the desired path if there are multiple hardlinks
|
| 207 |
+
// to the file.
|
| 208 |
+
char exe_path[PATH_MAX];
|
| 209 |
+
#if __FreeBSD_version >= 1300057
|
| 210 |
+
if (elf_aux_info(AT_EXECPATH, exe_path, sizeof(exe_path)) == 0) {
|
| 211 |
+
char link_path[PATH_MAX];
|
| 212 |
+
if (realpath(exe_path, link_path))
|
| 213 |
+
return link_path;
|
| 214 |
+
}
|
| 215 |
+
#else
|
| 216 |
+
// elf_aux_info(AT_EXECPATH, ... is not available in all supported versions,
|
| 217 |
+
// fall back to finding the ELF auxiliary vectors after the process's
|
| 218 |
+
// environment.
|
| 219 |
+
char **p = ::environ;
|
| 220 |
+
while (*p++ != 0)
|
| 221 |
+
;
|
| 222 |
+
// Iterate through auxiliary vectors for AT_EXECPATH.
|
| 223 |
+
for (Elf_Auxinfo *aux = (Elf_Auxinfo *)p; aux->a_type != AT_NULL; aux++) {
|
| 224 |
+
if (aux->a_type == AT_EXECPATH) {
|
| 225 |
+
char link_path[PATH_MAX];
|
| 226 |
+
if (realpath((char *)aux->a_un.a_ptr, link_path))
|
| 227 |
+
return link_path;
|
| 228 |
+
}
|
| 229 |
+
}
|
| 230 |
+
#endif
|
| 231 |
+
// Fall back to argv[0] if auxiliary vectors are not available.
|
| 232 |
+
if (getprogpath(exe_path, argv0) != NULL)
|
| 233 |
+
return exe_path;
|
| 234 |
+
#elif defined(_AIX) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) || \
|
| 235 |
+
defined(__NetBSD__)
|
| 236 |
+
const char *curproc = "/proc/curproc/file";
|
| 237 |
+
char exe_path[PATH_MAX];
|
| 238 |
+
if (sys::fs::exists(curproc)) {
|
| 239 |
+
ssize_t len = readlink(curproc, exe_path, sizeof(exe_path));
|
| 240 |
+
if (len > 0) {
|
| 241 |
+
// Null terminate the string for realpath. readlink never null
|
| 242 |
+
// terminates its output.
|
| 243 |
+
len = std::min(len, ssize_t(sizeof(exe_path) - 1));
|
| 244 |
+
exe_path[len] = '\0';
|
| 245 |
+
return exe_path;
|
| 246 |
+
}
|
| 247 |
+
}
|
| 248 |
+
// If we don't have procfs mounted, fall back to argv[0]
|
| 249 |
+
if (getprogpath(exe_path, argv0) != NULL)
|
| 250 |
+
return exe_path;
|
| 251 |
+
#elif defined(__linux__) || defined(__CYGWIN__) || defined(__gnu_hurd__) || \
|
| 252 |
+
defined(__managarm__)
|
| 253 |
+
char exe_path[PATH_MAX];
|
| 254 |
+
const char *aPath = "/proc/self/exe";
|
| 255 |
+
if (sys::fs::exists(aPath)) {
|
| 256 |
+
// /proc is not always mounted under Linux (chroot for example).
|
| 257 |
+
ssize_t len = readlink(aPath, exe_path, sizeof(exe_path));
|
| 258 |
+
if (len < 0)
|
| 259 |
+
return "";
|
| 260 |
+
|
| 261 |
+
// Null terminate the string for realpath. readlink never null
|
| 262 |
+
// terminates its output.
|
| 263 |
+
len = std::min(len, ssize_t(sizeof(exe_path) - 1));
|
| 264 |
+
exe_path[len] = '\0';
|
| 265 |
+
|
| 266 |
+
// On Linux, /proc/self/exe always looks through symlinks. However, on
|
| 267 |
+
// GNU/Hurd, /proc/self/exe is a symlink to the path that was used to start
|
| 268 |
+
// the program, and not the eventual binary file. Therefore, call realpath
|
| 269 |
+
// so this behaves the same on all platforms.
|
| 270 |
+
#if _POSIX_VERSION >= 200112 || defined(__GLIBC__)
|
| 271 |
+
if (char *real_path = realpath(exe_path, nullptr)) {
|
| 272 |
+
std::string ret = std::string(real_path);
|
| 273 |
+
free(real_path);
|
| 274 |
+
return ret;
|
| 275 |
+
}
|
| 276 |
+
#else
|
| 277 |
+
char real_path[PATH_MAX];
|
| 278 |
+
if (realpath(exe_path, real_path))
|
| 279 |
+
return std::string(real_path);
|
| 280 |
+
#endif
|
| 281 |
+
}
|
| 282 |
+
// Fall back to the classical detection.
|
| 283 |
+
if (getprogpath(exe_path, argv0))
|
| 284 |
+
return exe_path;
|
| 285 |
+
#elif defined(__OpenBSD__) || defined(__HAIKU__)
|
| 286 |
+
char exe_path[PATH_MAX];
|
| 287 |
+
// argv[0] only
|
| 288 |
+
if (getprogpath(exe_path, argv0) != NULL)
|
| 289 |
+
return exe_path;
|
| 290 |
+
#elif defined(__sun__) && defined(__svr4__)
|
| 291 |
+
char exe_path[PATH_MAX];
|
| 292 |
+
const char *aPath = "/proc/self/execname";
|
| 293 |
+
if (sys::fs::exists(aPath)) {
|
| 294 |
+
int fd = open(aPath, O_RDONLY);
|
| 295 |
+
if (fd == -1)
|
| 296 |
+
return "";
|
| 297 |
+
if (read(fd, exe_path, sizeof(exe_path)) < 0)
|
| 298 |
+
return "";
|
| 299 |
+
return exe_path;
|
| 300 |
+
}
|
| 301 |
+
// Fall back to the classical detection.
|
| 302 |
+
if (getprogpath(exe_path, argv0) != NULL)
|
| 303 |
+
return exe_path;
|
| 304 |
+
#elif defined(__MVS__)
|
| 305 |
+
int token = 0;
|
| 306 |
+
W_PSPROC buf;
|
| 307 |
+
char exe_path[PS_PATHBLEN];
|
| 308 |
+
pid_t pid = getpid();
|
| 309 |
+
|
| 310 |
+
memset(&buf, 0, sizeof(buf));
|
| 311 |
+
buf.ps_pathptr = exe_path;
|
| 312 |
+
buf.ps_pathlen = sizeof(exe_path);
|
| 313 |
+
|
| 314 |
+
while (true) {
|
| 315 |
+
if ((token = w_getpsent(token, &buf, sizeof(buf))) <= 0)
|
| 316 |
+
break;
|
| 317 |
+
if (buf.ps_pid != pid)
|
| 318 |
+
continue;
|
| 319 |
+
char real_path[PATH_MAX];
|
| 320 |
+
if (realpath(exe_path, real_path))
|
| 321 |
+
return std::string(real_path);
|
| 322 |
+
break; // Found entry, but realpath failed.
|
| 323 |
+
}
|
| 324 |
+
#elif defined(HAVE_DLOPEN)
|
| 325 |
+
// Use dladdr to get executable path if available.
|
| 326 |
+
Dl_info DLInfo;
|
| 327 |
+
int err = dladdr(MainAddr, &DLInfo);
|
| 328 |
+
if (err == 0)
|
| 329 |
+
return "";
|
| 330 |
+
|
| 331 |
+
// If the filename is a symlink, we need to resolve and return the location of
|
| 332 |
+
// the actual executable.
|
| 333 |
+
char link_path[PATH_MAX];
|
| 334 |
+
if (realpath(DLInfo.dli_fname, link_path))
|
| 335 |
+
return link_path;
|
| 336 |
+
#else
|
| 337 |
+
#error GetMainExecutable is not implemented on this host yet.
|
| 338 |
+
#endif
|
| 339 |
+
return "";
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
TimePoint<> basic_file_status::getLastAccessedTime() const {
|
| 343 |
+
return toTimePoint(fs_st_atime, fs_st_atime_nsec);
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
TimePoint<> basic_file_status::getLastModificationTime() const {
|
| 347 |
+
return toTimePoint(fs_st_mtime, fs_st_mtime_nsec);
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
UniqueID file_status::getUniqueID() const {
|
| 351 |
+
return UniqueID(fs_st_dev, fs_st_ino);
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
uint32_t file_status::getLinkCount() const { return fs_st_nlinks; }
|
| 355 |
+
|
| 356 |
+
ErrorOr<space_info> disk_space(const Twine &Path) {
|
| 357 |
+
struct STATVFS Vfs;
|
| 358 |
+
if (::STATVFS(const_cast<char *>(Path.str().c_str()), &Vfs))
|
| 359 |
+
return errnoAsErrorCode();
|
| 360 |
+
auto FrSize = STATVFS_F_FRSIZE(Vfs);
|
| 361 |
+
space_info SpaceInfo;
|
| 362 |
+
SpaceInfo.capacity = static_cast<uint64_t>(Vfs.f_blocks) * FrSize;
|
| 363 |
+
SpaceInfo.free = static_cast<uint64_t>(Vfs.f_bfree) * FrSize;
|
| 364 |
+
SpaceInfo.available = static_cast<uint64_t>(Vfs.f_bavail) * FrSize;
|
| 365 |
+
return SpaceInfo;
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
std::error_code current_path(SmallVectorImpl<char> &result) {
|
| 369 |
+
result.clear();
|
| 370 |
+
|
| 371 |
+
const char *pwd = ::getenv("PWD");
|
| 372 |
+
llvm::sys::fs::file_status PWDStatus, DotStatus;
|
| 373 |
+
if (pwd && llvm::sys::path::is_absolute(pwd) &&
|
| 374 |
+
!llvm::sys::fs::status(pwd, PWDStatus) &&
|
| 375 |
+
!llvm::sys::fs::status(".", DotStatus) &&
|
| 376 |
+
PWDStatus.getUniqueID() == DotStatus.getUniqueID()) {
|
| 377 |
+
result.append(pwd, pwd + strlen(pwd));
|
| 378 |
+
return std::error_code();
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
result.resize_for_overwrite(PATH_MAX);
|
| 382 |
+
|
| 383 |
+
while (true) {
|
| 384 |
+
if (::getcwd(result.data(), result.size()) == nullptr) {
|
| 385 |
+
// See if there was a real error.
|
| 386 |
+
if (errno != ENOMEM) {
|
| 387 |
+
result.clear();
|
| 388 |
+
return errnoAsErrorCode();
|
| 389 |
+
}
|
| 390 |
+
// Otherwise there just wasn't enough space.
|
| 391 |
+
result.resize_for_overwrite(result.capacity() * 2);
|
| 392 |
+
} else {
|
| 393 |
+
break;
|
| 394 |
+
}
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
result.truncate(strlen(result.data()));
|
| 398 |
+
return std::error_code();
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
std::error_code set_current_path(const Twine &path) {
|
| 402 |
+
SmallString<128> path_storage;
|
| 403 |
+
StringRef p = path.toNullTerminatedStringRef(path_storage);
|
| 404 |
+
|
| 405 |
+
if (::chdir(p.begin()) == -1)
|
| 406 |
+
return errnoAsErrorCode();
|
| 407 |
+
|
| 408 |
+
return std::error_code();
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
std::error_code create_directory(const Twine &path, bool IgnoreExisting,
|
| 412 |
+
perms Perms) {
|
| 413 |
+
SmallString<128> path_storage;
|
| 414 |
+
StringRef p = path.toNullTerminatedStringRef(path_storage);
|
| 415 |
+
|
| 416 |
+
if (::mkdir(p.begin(), Perms) == -1) {
|
| 417 |
+
if (errno != EEXIST || !IgnoreExisting)
|
| 418 |
+
return errnoAsErrorCode();
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
return std::error_code();
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
// Note that we are using symbolic link because hard links are not supported by
|
| 425 |
+
// all filesystems (SMB doesn't).
|
| 426 |
+
std::error_code create_link(const Twine &to, const Twine &from) {
|
| 427 |
+
// Get arguments.
|
| 428 |
+
SmallString<128> from_storage;
|
| 429 |
+
SmallString<128> to_storage;
|
| 430 |
+
StringRef f = from.toNullTerminatedStringRef(from_storage);
|
| 431 |
+
StringRef t = to.toNullTerminatedStringRef(to_storage);
|
| 432 |
+
|
| 433 |
+
if (::symlink(t.begin(), f.begin()) == -1)
|
| 434 |
+
return errnoAsErrorCode();
|
| 435 |
+
|
| 436 |
+
return std::error_code();
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
std::error_code create_hard_link(const Twine &to, const Twine &from) {
|
| 440 |
+
// Get arguments.
|
| 441 |
+
SmallString<128> from_storage;
|
| 442 |
+
SmallString<128> to_storage;
|
| 443 |
+
StringRef f = from.toNullTerminatedStringRef(from_storage);
|
| 444 |
+
StringRef t = to.toNullTerminatedStringRef(to_storage);
|
| 445 |
+
|
| 446 |
+
if (::link(t.begin(), f.begin()) == -1)
|
| 447 |
+
return errnoAsErrorCode();
|
| 448 |
+
|
| 449 |
+
return std::error_code();
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
std::error_code remove(const Twine &path, bool IgnoreNonExisting) {
|
| 453 |
+
SmallString<128> path_storage;
|
| 454 |
+
StringRef p = path.toNullTerminatedStringRef(path_storage);
|
| 455 |
+
|
| 456 |
+
struct stat buf;
|
| 457 |
+
if (lstat(p.begin(), &buf) != 0) {
|
| 458 |
+
if (errno != ENOENT || !IgnoreNonExisting)
|
| 459 |
+
return errnoAsErrorCode();
|
| 460 |
+
return std::error_code();
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
// Note: this check catches strange situations. In all cases, LLVM should
|
| 464 |
+
// only be involved in the creation and deletion of regular files. This
|
| 465 |
+
// check ensures that what we're trying to erase is a regular file. It
|
| 466 |
+
// effectively prevents LLVM from erasing things like /dev/null, any block
|
| 467 |
+
// special file, or other things that aren't "regular" files.
|
| 468 |
+
if (!S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode) && !S_ISLNK(buf.st_mode))
|
| 469 |
+
return make_error_code(errc::operation_not_permitted);
|
| 470 |
+
|
| 471 |
+
if (::remove(p.begin()) == -1) {
|
| 472 |
+
if (errno != ENOENT || !IgnoreNonExisting)
|
| 473 |
+
return errnoAsErrorCode();
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
return std::error_code();
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
static bool is_local_impl(struct STATVFS &Vfs) {
|
| 480 |
+
#if defined(__linux__) || defined(__GNU__) || defined(__managarm__)
|
| 481 |
+
#ifndef NFS_SUPER_MAGIC
|
| 482 |
+
#define NFS_SUPER_MAGIC 0x6969
|
| 483 |
+
#endif
|
| 484 |
+
#ifndef SMB_SUPER_MAGIC
|
| 485 |
+
#define SMB_SUPER_MAGIC 0x517B
|
| 486 |
+
#endif
|
| 487 |
+
#ifndef CIFS_MAGIC_NUMBER
|
| 488 |
+
#define CIFS_MAGIC_NUMBER 0xFF534D42
|
| 489 |
+
#endif
|
| 490 |
+
#if defined(__GNU__) && ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 39)))
|
| 491 |
+
switch ((uint32_t)Vfs.__f_type) {
|
| 492 |
+
#else
|
| 493 |
+
switch ((uint32_t)Vfs.f_type) {
|
| 494 |
+
#endif
|
| 495 |
+
case NFS_SUPER_MAGIC:
|
| 496 |
+
case SMB_SUPER_MAGIC:
|
| 497 |
+
case CIFS_MAGIC_NUMBER:
|
| 498 |
+
return false;
|
| 499 |
+
default:
|
| 500 |
+
return true;
|
| 501 |
+
}
|
| 502 |
+
#elif defined(__CYGWIN__)
|
| 503 |
+
// Cygwin doesn't expose this information; would need to use Win32 API.
|
| 504 |
+
return false;
|
| 505 |
+
#elif defined(__Fuchsia__)
|
| 506 |
+
// Fuchsia doesn't yet support remote filesystem mounts.
|
| 507 |
+
return true;
|
| 508 |
+
#elif defined(__EMSCRIPTEN__)
|
| 509 |
+
// Emscripten doesn't currently support remote filesystem mounts.
|
| 510 |
+
return true;
|
| 511 |
+
#elif defined(__HAIKU__)
|
| 512 |
+
// Haiku doesn't expose this information.
|
| 513 |
+
return false;
|
| 514 |
+
#elif defined(__sun)
|
| 515 |
+
// statvfs::f_basetype contains a null-terminated FSType name of the mounted
|
| 516 |
+
// target
|
| 517 |
+
StringRef fstype(Vfs.f_basetype);
|
| 518 |
+
// NFS is the only non-local fstype??
|
| 519 |
+
return fstype != "nfs";
|
| 520 |
+
#elif defined(_AIX)
|
| 521 |
+
// Call mntctl; try more than twice in case of timing issues with a concurrent
|
| 522 |
+
// mount.
|
| 523 |
+
int Ret;
|
| 524 |
+
size_t BufSize = 2048u;
|
| 525 |
+
std::unique_ptr<char[]> Buf;
|
| 526 |
+
int Tries = 3;
|
| 527 |
+
while (Tries--) {
|
| 528 |
+
Buf = std::make_unique<char[]>(BufSize);
|
| 529 |
+
Ret = mntctl(MCTL_QUERY, BufSize, Buf.get());
|
| 530 |
+
if (Ret != 0)
|
| 531 |
+
break;
|
| 532 |
+
BufSize = *reinterpret_cast<unsigned int *>(Buf.get());
|
| 533 |
+
Buf.reset();
|
| 534 |
+
}
|
| 535 |
+
|
| 536 |
+
if (Ret == -1)
|
| 537 |
+
// There was an error; "remote" is the conservative answer.
|
| 538 |
+
return false;
|
| 539 |
+
|
| 540 |
+
// Look for the correct vmount entry.
|
| 541 |
+
char *CurObjPtr = Buf.get();
|
| 542 |
+
while (Ret--) {
|
| 543 |
+
struct vmount *Vp = reinterpret_cast<struct vmount *>(CurObjPtr);
|
| 544 |
+
static_assert(sizeof(Vfs.f_fsid) == sizeof(Vp->vmt_fsid),
|
| 545 |
+
"fsid length mismatch");
|
| 546 |
+
if (memcmp(&Vfs.f_fsid, &Vp->vmt_fsid, sizeof Vfs.f_fsid) == 0)
|
| 547 |
+
return (Vp->vmt_flags & MNT_REMOTE) == 0;
|
| 548 |
+
|
| 549 |
+
CurObjPtr += Vp->vmt_length;
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
// vmount entry not found; "remote" is the conservative answer.
|
| 553 |
+
return false;
|
| 554 |
+
#elif defined(__MVS__)
|
| 555 |
+
// The file system can have an arbitrary structure on z/OS; must go with the
|
| 556 |
+
// conservative answer.
|
| 557 |
+
return false;
|
| 558 |
+
#else
|
| 559 |
+
return !!(STATVFS_F_FLAG(Vfs) & MNT_LOCAL);
|
| 560 |
+
#endif
|
| 561 |
+
}
|
| 562 |
+
|
| 563 |
+
std::error_code is_local(const Twine &Path, bool &Result) {
|
| 564 |
+
struct STATVFS Vfs;
|
| 565 |
+
if (::STATVFS(const_cast<char *>(Path.str().c_str()), &Vfs))
|
| 566 |
+
return errnoAsErrorCode();
|
| 567 |
+
|
| 568 |
+
Result = is_local_impl(Vfs);
|
| 569 |
+
return std::error_code();
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
std::error_code is_local(int FD, bool &Result) {
|
| 573 |
+
struct STATVFS Vfs;
|
| 574 |
+
if (::FSTATVFS(FD, &Vfs))
|
| 575 |
+
return errnoAsErrorCode();
|
| 576 |
+
|
| 577 |
+
Result = is_local_impl(Vfs);
|
| 578 |
+
return std::error_code();
|
| 579 |
+
}
|
| 580 |
+
|
| 581 |
+
std::error_code rename(const Twine &from, const Twine &to) {
|
| 582 |
+
// Get arguments.
|
| 583 |
+
SmallString<128> from_storage;
|
| 584 |
+
SmallString<128> to_storage;
|
| 585 |
+
StringRef f = from.toNullTerminatedStringRef(from_storage);
|
| 586 |
+
StringRef t = to.toNullTerminatedStringRef(to_storage);
|
| 587 |
+
|
| 588 |
+
if (::rename(f.begin(), t.begin()) == -1)
|
| 589 |
+
return errnoAsErrorCode();
|
| 590 |
+
|
| 591 |
+
return std::error_code();
|
| 592 |
+
}
|
| 593 |
+
|
| 594 |
+
std::error_code resize_file(int FD, uint64_t Size) {
|
| 595 |
+
// Use ftruncate as a fallback. It may or may not allocate space. At least on
|
| 596 |
+
// OS X with HFS+ it does.
|
| 597 |
+
if (::ftruncate(FD, Size) == -1)
|
| 598 |
+
return errnoAsErrorCode();
|
| 599 |
+
|
| 600 |
+
return std::error_code();
|
| 601 |
+
}
|
| 602 |
+
|
| 603 |
+
static int convertAccessMode(AccessMode Mode) {
|
| 604 |
+
switch (Mode) {
|
| 605 |
+
case AccessMode::Exist:
|
| 606 |
+
return F_OK;
|
| 607 |
+
case AccessMode::Write:
|
| 608 |
+
return W_OK;
|
| 609 |
+
case AccessMode::Execute:
|
| 610 |
+
return R_OK | X_OK; // scripts also need R_OK.
|
| 611 |
+
}
|
| 612 |
+
llvm_unreachable("invalid enum");
|
| 613 |
+
}
|
| 614 |
+
|
| 615 |
+
std::error_code access(const Twine &Path, AccessMode Mode) {
|
| 616 |
+
SmallString<128> PathStorage;
|
| 617 |
+
StringRef P = Path.toNullTerminatedStringRef(PathStorage);
|
| 618 |
+
|
| 619 |
+
if (::access(P.begin(), convertAccessMode(Mode)) == -1)
|
| 620 |
+
return errnoAsErrorCode();
|
| 621 |
+
|
| 622 |
+
if (Mode == AccessMode::Execute) {
|
| 623 |
+
// Don't say that directories are executable.
|
| 624 |
+
struct stat buf;
|
| 625 |
+
if (0 != stat(P.begin(), &buf))
|
| 626 |
+
return errc::permission_denied;
|
| 627 |
+
if (!S_ISREG(buf.st_mode))
|
| 628 |
+
return errc::permission_denied;
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
return std::error_code();
|
| 632 |
+
}
|
| 633 |
+
|
| 634 |
+
bool can_execute(const Twine &Path) {
|
| 635 |
+
return !access(Path, AccessMode::Execute);
|
| 636 |
+
}
|
| 637 |
+
|
| 638 |
+
bool equivalent(file_status A, file_status B) {
|
| 639 |
+
assert(status_known(A) && status_known(B));
|
| 640 |
+
return A.fs_st_dev == B.fs_st_dev && A.fs_st_ino == B.fs_st_ino;
|
| 641 |
+
}
|
| 642 |
+
|
| 643 |
+
std::error_code equivalent(const Twine &A, const Twine &B, bool &result) {
|
| 644 |
+
file_status fsA, fsB;
|
| 645 |
+
if (std::error_code ec = status(A, fsA))
|
| 646 |
+
return ec;
|
| 647 |
+
if (std::error_code ec = status(B, fsB))
|
| 648 |
+
return ec;
|
| 649 |
+
result = equivalent(fsA, fsB);
|
| 650 |
+
return std::error_code();
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
static void expandTildeExpr(SmallVectorImpl<char> &Path) {
|
| 654 |
+
StringRef PathStr(Path.begin(), Path.size());
|
| 655 |
+
if (PathStr.empty() || !PathStr.starts_with("~"))
|
| 656 |
+
return;
|
| 657 |
+
|
| 658 |
+
PathStr = PathStr.drop_front();
|
| 659 |
+
StringRef Expr =
|
| 660 |
+
PathStr.take_until([](char c) { return path::is_separator(c); });
|
| 661 |
+
StringRef Remainder = PathStr.substr(Expr.size() + 1);
|
| 662 |
+
SmallString<128> Storage;
|
| 663 |
+
if (Expr.empty()) {
|
| 664 |
+
// This is just ~/..., resolve it to the current user's home dir.
|
| 665 |
+
if (!path::home_directory(Storage)) {
|
| 666 |
+
// For some reason we couldn't get the home directory. Just exit.
|
| 667 |
+
return;
|
| 668 |
+
}
|
| 669 |
+
|
| 670 |
+
// Overwrite the first character and insert the rest.
|
| 671 |
+
Path[0] = Storage[0];
|
| 672 |
+
Path.insert(Path.begin() + 1, Storage.begin() + 1, Storage.end());
|
| 673 |
+
return;
|
| 674 |
+
}
|
| 675 |
+
|
| 676 |
+
// This is a string of the form ~username/, look up this user's entry in the
|
| 677 |
+
// password database.
|
| 678 |
+
std::unique_ptr<char[]> Buf;
|
| 679 |
+
long BufSize = sysconf(_SC_GETPW_R_SIZE_MAX);
|
| 680 |
+
if (BufSize <= 0)
|
| 681 |
+
BufSize = 16384;
|
| 682 |
+
Buf = std::make_unique<char[]>(BufSize);
|
| 683 |
+
struct passwd Pwd;
|
| 684 |
+
std::string User = Expr.str();
|
| 685 |
+
struct passwd *Entry = nullptr;
|
| 686 |
+
getpwnam_r(User.c_str(), &Pwd, Buf.get(), BufSize, &Entry);
|
| 687 |
+
|
| 688 |
+
if (!Entry || !Entry->pw_dir) {
|
| 689 |
+
// Unable to look up the entry, just return back the original path.
|
| 690 |
+
return;
|
| 691 |
+
}
|
| 692 |
+
|
| 693 |
+
Storage = Remainder;
|
| 694 |
+
Path.clear();
|
| 695 |
+
Path.append(Entry->pw_dir, Entry->pw_dir + strlen(Entry->pw_dir));
|
| 696 |
+
llvm::sys::path::append(Path, Storage);
|
| 697 |
+
}
|
| 698 |
+
|
| 699 |
+
void expand_tilde(const Twine &path, SmallVectorImpl<char> &dest) {
|
| 700 |
+
dest.clear();
|
| 701 |
+
if (path.isTriviallyEmpty())
|
| 702 |
+
return;
|
| 703 |
+
|
| 704 |
+
path.toVector(dest);
|
| 705 |
+
expandTildeExpr(dest);
|
| 706 |
+
}
|
| 707 |
+
|
| 708 |
+
static file_type typeForMode(mode_t Mode) {
|
| 709 |
+
if (S_ISDIR(Mode))
|
| 710 |
+
return file_type::directory_file;
|
| 711 |
+
else if (S_ISREG(Mode))
|
| 712 |
+
return file_type::regular_file;
|
| 713 |
+
else if (S_ISBLK(Mode))
|
| 714 |
+
return file_type::block_file;
|
| 715 |
+
else if (S_ISCHR(Mode))
|
| 716 |
+
return file_type::character_file;
|
| 717 |
+
else if (S_ISFIFO(Mode))
|
| 718 |
+
return file_type::fifo_file;
|
| 719 |
+
else if (S_ISSOCK(Mode))
|
| 720 |
+
return file_type::socket_file;
|
| 721 |
+
else if (S_ISLNK(Mode))
|
| 722 |
+
return file_type::symlink_file;
|
| 723 |
+
return file_type::type_unknown;
|
| 724 |
+
}
|
| 725 |
+
|
| 726 |
+
static std::error_code fillStatus(int StatRet, const struct stat &Status,
|
| 727 |
+
file_status &Result) {
|
| 728 |
+
if (StatRet != 0) {
|
| 729 |
+
std::error_code EC = errnoAsErrorCode();
|
| 730 |
+
if (EC == errc::no_such_file_or_directory)
|
| 731 |
+
Result = file_status(file_type::file_not_found);
|
| 732 |
+
else
|
| 733 |
+
Result = file_status(file_type::status_error);
|
| 734 |
+
return EC;
|
| 735 |
+
}
|
| 736 |
+
|
| 737 |
+
uint32_t atime_nsec, mtime_nsec;
|
| 738 |
+
#if defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
|
| 739 |
+
atime_nsec = Status.st_atimespec.tv_nsec;
|
| 740 |
+
mtime_nsec = Status.st_mtimespec.tv_nsec;
|
| 741 |
+
#elif defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
|
| 742 |
+
atime_nsec = Status.st_atim.tv_nsec;
|
| 743 |
+
mtime_nsec = Status.st_mtim.tv_nsec;
|
| 744 |
+
#else
|
| 745 |
+
atime_nsec = mtime_nsec = 0;
|
| 746 |
+
#endif
|
| 747 |
+
|
| 748 |
+
perms Perms = static_cast<perms>(Status.st_mode) & all_perms;
|
| 749 |
+
Result = file_status(typeForMode(Status.st_mode), Perms, Status.st_dev,
|
| 750 |
+
Status.st_nlink, Status.st_ino, Status.st_atime,
|
| 751 |
+
atime_nsec, Status.st_mtime, mtime_nsec, Status.st_uid,
|
| 752 |
+
Status.st_gid, Status.st_size);
|
| 753 |
+
|
| 754 |
+
return std::error_code();
|
| 755 |
+
}
|
| 756 |
+
|
| 757 |
+
std::error_code status(const Twine &Path, file_status &Result, bool Follow) {
|
| 758 |
+
SmallString<128> PathStorage;
|
| 759 |
+
StringRef P = Path.toNullTerminatedStringRef(PathStorage);
|
| 760 |
+
|
| 761 |
+
struct stat Status;
|
| 762 |
+
int StatRet = (Follow ? ::stat : ::lstat)(P.begin(), &Status);
|
| 763 |
+
return fillStatus(StatRet, Status, Result);
|
| 764 |
+
}
|
| 765 |
+
|
| 766 |
+
std::error_code status(int FD, file_status &Result) {
|
| 767 |
+
struct stat Status;
|
| 768 |
+
int StatRet = ::fstat(FD, &Status);
|
| 769 |
+
return fillStatus(StatRet, Status, Result);
|
| 770 |
+
}
|
| 771 |
+
|
| 772 |
+
unsigned getUmask() {
|
| 773 |
+
// Chose arbitary new mask and reset the umask to the old mask.
|
| 774 |
+
// umask(2) never fails so ignore the return of the second call.
|
| 775 |
+
unsigned Mask = ::umask(0);
|
| 776 |
+
(void)::umask(Mask);
|
| 777 |
+
return Mask;
|
| 778 |
+
}
|
| 779 |
+
|
| 780 |
+
std::error_code setPermissions(const Twine &Path, perms Permissions) {
|
| 781 |
+
SmallString<128> PathStorage;
|
| 782 |
+
StringRef P = Path.toNullTerminatedStringRef(PathStorage);
|
| 783 |
+
|
| 784 |
+
if (::chmod(P.begin(), Permissions))
|
| 785 |
+
return errnoAsErrorCode();
|
| 786 |
+
return std::error_code();
|
| 787 |
+
}
|
| 788 |
+
|
| 789 |
+
std::error_code setPermissions(int FD, perms Permissions) {
|
| 790 |
+
if (::fchmod(FD, Permissions))
|
| 791 |
+
return errnoAsErrorCode();
|
| 792 |
+
return std::error_code();
|
| 793 |
+
}
|
| 794 |
+
|
| 795 |
+
std::error_code setLastAccessAndModificationTime(int FD, TimePoint<> AccessTime,
|
| 796 |
+
TimePoint<> ModificationTime) {
|
| 797 |
+
#if defined(HAVE_FUTIMENS)
|
| 798 |
+
timespec Times[2];
|
| 799 |
+
Times[0] = sys::toTimeSpec(AccessTime);
|
| 800 |
+
Times[1] = sys::toTimeSpec(ModificationTime);
|
| 801 |
+
if (::futimens(FD, Times))
|
| 802 |
+
return errnoAsErrorCode();
|
| 803 |
+
return std::error_code();
|
| 804 |
+
#elif defined(HAVE_FUTIMES)
|
| 805 |
+
timeval Times[2];
|
| 806 |
+
Times[0] = sys::toTimeVal(
|
| 807 |
+
std::chrono::time_point_cast<std::chrono::microseconds>(AccessTime));
|
| 808 |
+
Times[1] =
|
| 809 |
+
sys::toTimeVal(std::chrono::time_point_cast<std::chrono::microseconds>(
|
| 810 |
+
ModificationTime));
|
| 811 |
+
if (::futimes(FD, Times))
|
| 812 |
+
return errnoAsErrorCode();
|
| 813 |
+
return std::error_code();
|
| 814 |
+
#elif defined(__MVS__)
|
| 815 |
+
attrib_t Attr;
|
| 816 |
+
memset(&Attr, 0, sizeof(Attr));
|
| 817 |
+
Attr.att_atimechg = 1;
|
| 818 |
+
Attr.att_atime = sys::toTimeT(AccessTime);
|
| 819 |
+
Attr.att_mtimechg = 1;
|
| 820 |
+
Attr.att_mtime = sys::toTimeT(ModificationTime);
|
| 821 |
+
if (::__fchattr(FD, &Attr, sizeof(Attr)) != 0)
|
| 822 |
+
return errnoAsErrorCode();
|
| 823 |
+
return std::error_code();
|
| 824 |
+
#else
|
| 825 |
+
#warning Missing futimes() and futimens()
|
| 826 |
+
return make_error_code(errc::function_not_supported);
|
| 827 |
+
#endif
|
| 828 |
+
}
|
| 829 |
+
|
| 830 |
+
std::error_code mapped_file_region::init(int FD, uint64_t Offset,
|
| 831 |
+
mapmode Mode) {
|
| 832 |
+
assert(Size != 0);
|
| 833 |
+
|
| 834 |
+
int flags = (Mode == readwrite) ? MAP_SHARED : MAP_PRIVATE;
|
| 835 |
+
int prot = (Mode == readonly) ? PROT_READ : (PROT_READ | PROT_WRITE);
|
| 836 |
+
#if defined(MAP_NORESERVE)
|
| 837 |
+
flags |= MAP_NORESERVE;
|
| 838 |
+
#endif
|
| 839 |
+
#if defined(__APPLE__)
|
| 840 |
+
//----------------------------------------------------------------------
|
| 841 |
+
// Newer versions of MacOSX have a flag that will allow us to read from
|
| 842 |
+
// binaries whose code signature is invalid without crashing by using
|
| 843 |
+
// the MAP_RESILIENT_CODESIGN flag. Also if a file from removable media
|
| 844 |
+
// is mapped we can avoid crashing and return zeroes to any pages we try
|
| 845 |
+
// to read if the media becomes unavailable by using the
|
| 846 |
+
// MAP_RESILIENT_MEDIA flag. These flags are only usable when mapping
|
| 847 |
+
// with PROT_READ, so take care not to specify them otherwise.
|
| 848 |
+
//----------------------------------------------------------------------
|
| 849 |
+
if (Mode == readonly) {
|
| 850 |
+
#if defined(MAP_RESILIENT_CODESIGN)
|
| 851 |
+
flags |= MAP_RESILIENT_CODESIGN;
|
| 852 |
+
#endif
|
| 853 |
+
#if defined(MAP_RESILIENT_MEDIA)
|
| 854 |
+
flags |= MAP_RESILIENT_MEDIA;
|
| 855 |
+
#endif
|
| 856 |
+
}
|
| 857 |
+
#endif // #if defined (__APPLE__)
|
| 858 |
+
|
| 859 |
+
Mapping = ::mmap(nullptr, Size, prot, flags, FD, Offset);
|
| 860 |
+
if (Mapping == MAP_FAILED)
|
| 861 |
+
return errnoAsErrorCode();
|
| 862 |
+
return std::error_code();
|
| 863 |
+
}
|
| 864 |
+
|
| 865 |
+
mapped_file_region::mapped_file_region(int fd, mapmode mode, size_t length,
|
| 866 |
+
uint64_t offset, std::error_code &ec)
|
| 867 |
+
: Size(length), Mode(mode) {
|
| 868 |
+
(void)Mode;
|
| 869 |
+
ec = init(fd, offset, mode);
|
| 870 |
+
if (ec)
|
| 871 |
+
copyFrom(mapped_file_region());
|
| 872 |
+
}
|
| 873 |
+
|
| 874 |
+
void mapped_file_region::unmapImpl() {
|
| 875 |
+
if (Mapping)
|
| 876 |
+
::munmap(Mapping, Size);
|
| 877 |
+
}
|
| 878 |
+
|
| 879 |
+
void mapped_file_region::dontNeedImpl() {
|
| 880 |
+
assert(Mode == mapped_file_region::readonly);
|
| 881 |
+
if (!Mapping)
|
| 882 |
+
return;
|
| 883 |
+
#if defined(__MVS__) || defined(_AIX)
|
| 884 |
+
// If we don't have madvise, or it isn't beneficial, treat this as a no-op.
|
| 885 |
+
#elif defined(POSIX_MADV_DONTNEED)
|
| 886 |
+
::posix_madvise(Mapping, Size, POSIX_MADV_DONTNEED);
|
| 887 |
+
#else
|
| 888 |
+
::madvise(Mapping, Size, MADV_DONTNEED);
|
| 889 |
+
#endif
|
| 890 |
+
}
|
| 891 |
+
|
| 892 |
+
int mapped_file_region::alignment() { return Process::getPageSizeEstimate(); }
|
| 893 |
+
|
| 894 |
+
std::error_code detail::directory_iterator_construct(detail::DirIterState &it,
|
| 895 |
+
StringRef path,
|
| 896 |
+
bool follow_symlinks) {
|
| 897 |
+
SmallString<128> path_null(path);
|
| 898 |
+
DIR *directory = ::opendir(path_null.c_str());
|
| 899 |
+
if (!directory)
|
| 900 |
+
return errnoAsErrorCode();
|
| 901 |
+
|
| 902 |
+
it.IterationHandle = reinterpret_cast<intptr_t>(directory);
|
| 903 |
+
// Add something for replace_filename to replace.
|
| 904 |
+
path::append(path_null, ".");
|
| 905 |
+
it.CurrentEntry = directory_entry(path_null.str(), follow_symlinks);
|
| 906 |
+
return directory_iterator_increment(it);
|
| 907 |
+
}
|
| 908 |
+
|
| 909 |
+
std::error_code detail::directory_iterator_destruct(detail::DirIterState &it) {
|
| 910 |
+
if (it.IterationHandle)
|
| 911 |
+
::closedir(reinterpret_cast<DIR *>(it.IterationHandle));
|
| 912 |
+
it.IterationHandle = 0;
|
| 913 |
+
it.CurrentEntry = directory_entry();
|
| 914 |
+
return std::error_code();
|
| 915 |
+
}
|
| 916 |
+
|
| 917 |
+
static file_type direntType(dirent *Entry) {
|
| 918 |
+
// Most platforms provide the file type in the dirent: Linux/BSD/Mac.
|
| 919 |
+
// The DTTOIF macro lets us reuse our status -> type conversion.
|
| 920 |
+
// Note that while glibc provides a macro to see if this is supported,
|
| 921 |
+
// _DIRENT_HAVE_D_TYPE, it's not defined on BSD/Mac, so we test for the
|
| 922 |
+
// d_type-to-mode_t conversion macro instead.
|
| 923 |
+
#if defined(DTTOIF)
|
| 924 |
+
return typeForMode(DTTOIF(Entry->d_type));
|
| 925 |
+
#else
|
| 926 |
+
// Other platforms such as Solaris require a stat() to get the type.
|
| 927 |
+
return file_type::type_unknown;
|
| 928 |
+
#endif
|
| 929 |
+
}
|
| 930 |
+
|
| 931 |
+
std::error_code detail::directory_iterator_increment(detail::DirIterState &It) {
|
| 932 |
+
errno = 0;
|
| 933 |
+
dirent *CurDir = ::readdir(reinterpret_cast<DIR *>(It.IterationHandle));
|
| 934 |
+
if (CurDir == nullptr && errno != 0) {
|
| 935 |
+
return errnoAsErrorCode();
|
| 936 |
+
} else if (CurDir != nullptr) {
|
| 937 |
+
StringRef Name(CurDir->d_name);
|
| 938 |
+
if ((Name.size() == 1 && Name[0] == '.') ||
|
| 939 |
+
(Name.size() == 2 && Name[0] == '.' && Name[1] == '.'))
|
| 940 |
+
return directory_iterator_increment(It);
|
| 941 |
+
It.CurrentEntry.replace_filename(Name, direntType(CurDir));
|
| 942 |
+
} else {
|
| 943 |
+
return directory_iterator_destruct(It);
|
| 944 |
+
}
|
| 945 |
+
|
| 946 |
+
return std::error_code();
|
| 947 |
+
}
|
| 948 |
+
|
| 949 |
+
ErrorOr<basic_file_status> directory_entry::status() const {
|
| 950 |
+
file_status s;
|
| 951 |
+
if (auto EC = fs::status(Path, s, FollowSymlinks))
|
| 952 |
+
return EC;
|
| 953 |
+
return s;
|
| 954 |
+
}
|
| 955 |
+
|
| 956 |
+
//
|
| 957 |
+
// FreeBSD optionally provides /proc/self/fd, but it is incompatible with
|
| 958 |
+
// Linux. The thing to use is realpath.
|
| 959 |
+
//
|
| 960 |
+
#if !defined(__FreeBSD__) && !defined(__OpenBSD__)
|
| 961 |
+
#define TRY_PROC_SELF_FD
|
| 962 |
+
#endif
|
| 963 |
+
|
| 964 |
+
#if !defined(F_GETPATH) && defined(TRY_PROC_SELF_FD)
|
| 965 |
+
static bool hasProcSelfFD() {
|
| 966 |
+
// If we have a /proc filesystem mounted, we can quickly establish the
|
| 967 |
+
// real name of the file with readlink
|
| 968 |
+
static const bool Result = (::access("/proc/self/fd", R_OK) == 0);
|
| 969 |
+
return Result;
|
| 970 |
+
}
|
| 971 |
+
#endif
|
| 972 |
+
|
| 973 |
+
static int nativeOpenFlags(CreationDisposition Disp, OpenFlags Flags,
|
| 974 |
+
FileAccess Access) {
|
| 975 |
+
int Result = 0;
|
| 976 |
+
if (Access == FA_Read)
|
| 977 |
+
Result |= O_RDONLY;
|
| 978 |
+
else if (Access == FA_Write)
|
| 979 |
+
Result |= O_WRONLY;
|
| 980 |
+
else if (Access == (FA_Read | FA_Write))
|
| 981 |
+
Result |= O_RDWR;
|
| 982 |
+
|
| 983 |
+
// This is for compatibility with old code that assumed OF_Append implied
|
| 984 |
+
// would open an existing file. See Windows/Path.inc for a longer comment.
|
| 985 |
+
if (Flags & OF_Append)
|
| 986 |
+
Disp = CD_OpenAlways;
|
| 987 |
+
|
| 988 |
+
if (Disp == CD_CreateNew) {
|
| 989 |
+
Result |= O_CREAT; // Create if it doesn't exist.
|
| 990 |
+
Result |= O_EXCL; // Fail if it does.
|
| 991 |
+
} else if (Disp == CD_CreateAlways) {
|
| 992 |
+
Result |= O_CREAT; // Create if it doesn't exist.
|
| 993 |
+
Result |= O_TRUNC; // Truncate if it does.
|
| 994 |
+
} else if (Disp == CD_OpenAlways) {
|
| 995 |
+
Result |= O_CREAT; // Create if it doesn't exist.
|
| 996 |
+
} else if (Disp == CD_OpenExisting) {
|
| 997 |
+
// Nothing special, just don't add O_CREAT and we get these semantics.
|
| 998 |
+
}
|
| 999 |
+
|
| 1000 |
+
// Using append mode with z/OS UTF-8 auto-conversion results in EINVAL when
|
| 1001 |
+
// calling write(). Instead we need to use lseek() to set offset to EOF after
|
| 1002 |
+
// open().
|
| 1003 |
+
#ifndef __MVS__
|
| 1004 |
+
if (Flags & OF_Append)
|
| 1005 |
+
Result |= O_APPEND;
|
| 1006 |
+
#endif
|
| 1007 |
+
|
| 1008 |
+
#ifdef O_CLOEXEC
|
| 1009 |
+
if (!(Flags & OF_ChildInherit))
|
| 1010 |
+
Result |= O_CLOEXEC;
|
| 1011 |
+
#endif
|
| 1012 |
+
|
| 1013 |
+
return Result;
|
| 1014 |
+
}
|
| 1015 |
+
|
| 1016 |
+
std::error_code openFile(const Twine &Name, int &ResultFD,
|
| 1017 |
+
CreationDisposition Disp, FileAccess Access,
|
| 1018 |
+
OpenFlags Flags, unsigned Mode) {
|
| 1019 |
+
int OpenFlags = nativeOpenFlags(Disp, Flags, Access);
|
| 1020 |
+
|
| 1021 |
+
SmallString<128> Storage;
|
| 1022 |
+
StringRef P = Name.toNullTerminatedStringRef(Storage);
|
| 1023 |
+
// Call ::open in a lambda to avoid overload resolution in RetryAfterSignal
|
| 1024 |
+
// when open is overloaded, such as in Bionic.
|
| 1025 |
+
auto Open = [&]() { return ::open(P.begin(), OpenFlags, Mode); };
|
| 1026 |
+
if ((ResultFD = sys::RetryAfterSignal(-1, Open)) < 0)
|
| 1027 |
+
return errnoAsErrorCode();
|
| 1028 |
+
#ifndef O_CLOEXEC
|
| 1029 |
+
if (!(Flags & OF_ChildInherit)) {
|
| 1030 |
+
int r = fcntl(ResultFD, F_SETFD, FD_CLOEXEC);
|
| 1031 |
+
(void)r;
|
| 1032 |
+
assert(r == 0 && "fcntl(F_SETFD, FD_CLOEXEC) failed");
|
| 1033 |
+
}
|
| 1034 |
+
#endif
|
| 1035 |
+
|
| 1036 |
+
#ifdef __MVS__
|
| 1037 |
+
/* Reason about auto-conversion and file tags. Setting the file tag only
|
| 1038 |
+
* applies if file is opened in write mode:
|
| 1039 |
+
*
|
| 1040 |
+
* Text file:
|
| 1041 |
+
* File exists File created
|
| 1042 |
+
* CD_CreateNew n/a conv: on
|
| 1043 |
+
* tag: set 1047
|
| 1044 |
+
* CD_CreateAlways conv: auto conv: on
|
| 1045 |
+
* tag: auto 1047 tag: set 1047
|
| 1046 |
+
* CD_OpenAlways conv: auto conv: on
|
| 1047 |
+
* tag: auto 1047 tag: set 1047
|
| 1048 |
+
* CD_OpenExisting conv: auto n/a
|
| 1049 |
+
* tag: unchanged
|
| 1050 |
+
*
|
| 1051 |
+
* Binary file:
|
| 1052 |
+
* File exists File created
|
| 1053 |
+
* CD_CreateNew n/a conv: off
|
| 1054 |
+
* tag: set binary
|
| 1055 |
+
* CD_CreateAlways conv: off conv: off
|
| 1056 |
+
* tag: auto binary tag: set binary
|
| 1057 |
+
* CD_OpenAlways conv: off conv: off
|
| 1058 |
+
* tag: auto binary tag: set binary
|
| 1059 |
+
* CD_OpenExisting conv: off n/a
|
| 1060 |
+
* tag: unchanged
|
| 1061 |
+
*
|
| 1062 |
+
* Actions:
|
| 1063 |
+
* conv: off -> auto-conversion is turned off
|
| 1064 |
+
* conv: on -> auto-conversion is turned on
|
| 1065 |
+
* conv: auto -> auto-conversion is turned on if the file is untagged
|
| 1066 |
+
* tag: set 1047 -> set the file tag to text encoded in 1047
|
| 1067 |
+
* tag: set binary -> set the file tag to binary
|
| 1068 |
+
* tag: auto 1047 -> set file tag to 1047 if not set
|
| 1069 |
+
* tag: auto binary -> set file tag to binary if not set
|
| 1070 |
+
* tag: unchanged -> do not care about the file tag
|
| 1071 |
+
*
|
| 1072 |
+
* It is not possible to distinguish between the cases "file exists" and
|
| 1073 |
+
* "file created". In the latter case, the file tag is not set and the file
|
| 1074 |
+
* size is zero. The decision table boils down to:
|
| 1075 |
+
*
|
| 1076 |
+
* the file tag is set if
|
| 1077 |
+
* - the file is opened for writing
|
| 1078 |
+
* - the create disposition is not equal to CD_OpenExisting
|
| 1079 |
+
* - the file tag is not set
|
| 1080 |
+
* - the file size is zero
|
| 1081 |
+
*
|
| 1082 |
+
* This only applies if the file is a regular file. E.g. enabling
|
| 1083 |
+
* auto-conversion for reading from /dev/null results in error EINVAL when
|
| 1084 |
+
* calling read().
|
| 1085 |
+
*
|
| 1086 |
+
* Using append mode with z/OS UTF-8 auto-conversion results in EINVAL when
|
| 1087 |
+
* calling write(). Instead we need to use lseek() to set offset to EOF after
|
| 1088 |
+
* open().
|
| 1089 |
+
*/
|
| 1090 |
+
if ((Flags & OF_Append) && lseek(ResultFD, 0, SEEK_END) == -1)
|
| 1091 |
+
return errnoAsErrorCode();
|
| 1092 |
+
struct stat Stat;
|
| 1093 |
+
if (fstat(ResultFD, &Stat) == -1)
|
| 1094 |
+
return errnoAsErrorCode();
|
| 1095 |
+
if (S_ISREG(Stat.st_mode)) {
|
| 1096 |
+
bool DoSetTag = (Access & FA_Write) && (Disp != CD_OpenExisting) &&
|
| 1097 |
+
!Stat.st_tag.ft_txtflag && !Stat.st_tag.ft_ccsid &&
|
| 1098 |
+
Stat.st_size == 0;
|
| 1099 |
+
if (Flags & OF_Text) {
|
| 1100 |
+
if (auto EC = llvm::enablezOSAutoConversion(ResultFD))
|
| 1101 |
+
return EC;
|
| 1102 |
+
if (DoSetTag) {
|
| 1103 |
+
if (auto EC = llvm::setzOSFileTag(ResultFD, CCSID_IBM_1047, true))
|
| 1104 |
+
return EC;
|
| 1105 |
+
}
|
| 1106 |
+
} else {
|
| 1107 |
+
if (auto EC = llvm::disablezOSAutoConversion(ResultFD))
|
| 1108 |
+
return EC;
|
| 1109 |
+
if (DoSetTag) {
|
| 1110 |
+
if (auto EC = llvm::setzOSFileTag(ResultFD, FT_BINARY, false))
|
| 1111 |
+
return EC;
|
| 1112 |
+
}
|
| 1113 |
+
}
|
| 1114 |
+
}
|
| 1115 |
+
#endif
|
| 1116 |
+
|
| 1117 |
+
return std::error_code();
|
| 1118 |
+
}
|
| 1119 |
+
|
| 1120 |
+
Expected<int> openNativeFile(const Twine &Name, CreationDisposition Disp,
|
| 1121 |
+
FileAccess Access, OpenFlags Flags,
|
| 1122 |
+
unsigned Mode) {
|
| 1123 |
+
|
| 1124 |
+
int FD;
|
| 1125 |
+
std::error_code EC = openFile(Name, FD, Disp, Access, Flags, Mode);
|
| 1126 |
+
if (EC)
|
| 1127 |
+
return errorCodeToError(EC);
|
| 1128 |
+
return FD;
|
| 1129 |
+
}
|
| 1130 |
+
|
| 1131 |
+
std::error_code openFileForRead(const Twine &Name, int &ResultFD,
|
| 1132 |
+
OpenFlags Flags,
|
| 1133 |
+
SmallVectorImpl<char> *RealPath) {
|
| 1134 |
+
std::error_code EC =
|
| 1135 |
+
openFile(Name, ResultFD, CD_OpenExisting, FA_Read, Flags, 0666);
|
| 1136 |
+
if (EC)
|
| 1137 |
+
return EC;
|
| 1138 |
+
|
| 1139 |
+
// Attempt to get the real name of the file, if the user asked
|
| 1140 |
+
if (!RealPath)
|
| 1141 |
+
return std::error_code();
|
| 1142 |
+
RealPath->clear();
|
| 1143 |
+
#if defined(F_GETPATH)
|
| 1144 |
+
// When F_GETPATH is availble, it is the quickest way to get
|
| 1145 |
+
// the real path name.
|
| 1146 |
+
char Buffer[PATH_MAX];
|
| 1147 |
+
if (::fcntl(ResultFD, F_GETPATH, Buffer) != -1)
|
| 1148 |
+
RealPath->append(Buffer, Buffer + strlen(Buffer));
|
| 1149 |
+
#else
|
| 1150 |
+
char Buffer[PATH_MAX];
|
| 1151 |
+
#if defined(TRY_PROC_SELF_FD)
|
| 1152 |
+
if (hasProcSelfFD()) {
|
| 1153 |
+
char ProcPath[64];
|
| 1154 |
+
snprintf(ProcPath, sizeof(ProcPath), "/proc/self/fd/%d", ResultFD);
|
| 1155 |
+
ssize_t CharCount = ::readlink(ProcPath, Buffer, sizeof(Buffer));
|
| 1156 |
+
if (CharCount > 0)
|
| 1157 |
+
RealPath->append(Buffer, Buffer + CharCount);
|
| 1158 |
+
} else {
|
| 1159 |
+
#endif
|
| 1160 |
+
SmallString<128> Storage;
|
| 1161 |
+
StringRef P = Name.toNullTerminatedStringRef(Storage);
|
| 1162 |
+
|
| 1163 |
+
// Use ::realpath to get the real path name
|
| 1164 |
+
if (::realpath(P.begin(), Buffer) != nullptr)
|
| 1165 |
+
RealPath->append(Buffer, Buffer + strlen(Buffer));
|
| 1166 |
+
#if defined(TRY_PROC_SELF_FD)
|
| 1167 |
+
}
|
| 1168 |
+
#endif
|
| 1169 |
+
#endif
|
| 1170 |
+
return std::error_code();
|
| 1171 |
+
}
|
| 1172 |
+
|
| 1173 |
+
Expected<file_t> openNativeFileForRead(const Twine &Name, OpenFlags Flags,
|
| 1174 |
+
SmallVectorImpl<char> *RealPath) {
|
| 1175 |
+
file_t ResultFD;
|
| 1176 |
+
std::error_code EC = openFileForRead(Name, ResultFD, Flags, RealPath);
|
| 1177 |
+
if (EC)
|
| 1178 |
+
return errorCodeToError(EC);
|
| 1179 |
+
return ResultFD;
|
| 1180 |
+
}
|
| 1181 |
+
|
| 1182 |
+
file_t getStdinHandle() { return 0; }
|
| 1183 |
+
file_t getStdoutHandle() { return 1; }
|
| 1184 |
+
file_t getStderrHandle() { return 2; }
|
| 1185 |
+
|
| 1186 |
+
Expected<size_t> readNativeFile(file_t FD, MutableArrayRef<char> Buf) {
|
| 1187 |
+
#if defined(__APPLE__)
|
| 1188 |
+
size_t Size = std::min<size_t>(Buf.size(), INT32_MAX);
|
| 1189 |
+
#else
|
| 1190 |
+
size_t Size = Buf.size();
|
| 1191 |
+
#endif
|
| 1192 |
+
ssize_t NumRead = sys::RetryAfterSignal(-1, ::read, FD, Buf.data(), Size);
|
| 1193 |
+
if (ssize_t(NumRead) == -1)
|
| 1194 |
+
return errorCodeToError(errnoAsErrorCode());
|
| 1195 |
+
// The underlying operation on these platforms allow opening directories
|
| 1196 |
+
// for reading in more cases than other platforms.
|
| 1197 |
+
#if defined(__MVS__) || defined(_AIX)
|
| 1198 |
+
struct stat Status;
|
| 1199 |
+
if (fstat(FD, &Status) == -1)
|
| 1200 |
+
return errorCodeToError(errnoAsErrorCode());
|
| 1201 |
+
if (S_ISDIR(Status.st_mode))
|
| 1202 |
+
return errorCodeToError(make_error_code(errc::is_a_directory));
|
| 1203 |
+
#endif
|
| 1204 |
+
return NumRead;
|
| 1205 |
+
}
|
| 1206 |
+
|
| 1207 |
+
Expected<size_t> readNativeFileSlice(file_t FD, MutableArrayRef<char> Buf,
|
| 1208 |
+
uint64_t Offset) {
|
| 1209 |
+
#if defined(__APPLE__)
|
| 1210 |
+
size_t Size = std::min<size_t>(Buf.size(), INT32_MAX);
|
| 1211 |
+
#else
|
| 1212 |
+
size_t Size = Buf.size();
|
| 1213 |
+
#endif
|
| 1214 |
+
#ifdef HAVE_PREAD
|
| 1215 |
+
ssize_t NumRead =
|
| 1216 |
+
sys::RetryAfterSignal(-1, ::pread, FD, Buf.data(), Size, Offset);
|
| 1217 |
+
#else
|
| 1218 |
+
if (lseek(FD, Offset, SEEK_SET) == -1)
|
| 1219 |
+
return errorCodeToError(errnoAsErrorCode());
|
| 1220 |
+
ssize_t NumRead = sys::RetryAfterSignal(-1, ::read, FD, Buf.data(), Size);
|
| 1221 |
+
#endif
|
| 1222 |
+
if (NumRead == -1)
|
| 1223 |
+
return errorCodeToError(errnoAsErrorCode());
|
| 1224 |
+
return NumRead;
|
| 1225 |
+
}
|
| 1226 |
+
|
| 1227 |
+
std::error_code tryLockFile(int FD, std::chrono::milliseconds Timeout) {
|
| 1228 |
+
auto Start = std::chrono::steady_clock::now();
|
| 1229 |
+
auto End = Start + Timeout;
|
| 1230 |
+
do {
|
| 1231 |
+
struct flock Lock;
|
| 1232 |
+
memset(&Lock, 0, sizeof(Lock));
|
| 1233 |
+
Lock.l_type = F_WRLCK;
|
| 1234 |
+
Lock.l_whence = SEEK_SET;
|
| 1235 |
+
Lock.l_start = 0;
|
| 1236 |
+
Lock.l_len = 0;
|
| 1237 |
+
if (::fcntl(FD, F_SETLK, &Lock) != -1)
|
| 1238 |
+
return std::error_code();
|
| 1239 |
+
int Error = errno;
|
| 1240 |
+
if (Error != EACCES && Error != EAGAIN)
|
| 1241 |
+
return std::error_code(Error, std::generic_category());
|
| 1242 |
+
usleep(1000);
|
| 1243 |
+
} while (std::chrono::steady_clock::now() < End);
|
| 1244 |
+
return make_error_code(errc::no_lock_available);
|
| 1245 |
+
}
|
| 1246 |
+
|
| 1247 |
+
std::error_code lockFile(int FD) {
|
| 1248 |
+
struct flock Lock;
|
| 1249 |
+
memset(&Lock, 0, sizeof(Lock));
|
| 1250 |
+
Lock.l_type = F_WRLCK;
|
| 1251 |
+
Lock.l_whence = SEEK_SET;
|
| 1252 |
+
Lock.l_start = 0;
|
| 1253 |
+
Lock.l_len = 0;
|
| 1254 |
+
if (::fcntl(FD, F_SETLKW, &Lock) != -1)
|
| 1255 |
+
return std::error_code();
|
| 1256 |
+
return errnoAsErrorCode();
|
| 1257 |
+
}
|
| 1258 |
+
|
| 1259 |
+
std::error_code unlockFile(int FD) {
|
| 1260 |
+
struct flock Lock;
|
| 1261 |
+
Lock.l_type = F_UNLCK;
|
| 1262 |
+
Lock.l_whence = SEEK_SET;
|
| 1263 |
+
Lock.l_start = 0;
|
| 1264 |
+
Lock.l_len = 0;
|
| 1265 |
+
if (::fcntl(FD, F_SETLK, &Lock) != -1)
|
| 1266 |
+
return std::error_code();
|
| 1267 |
+
return errnoAsErrorCode();
|
| 1268 |
+
}
|
| 1269 |
+
|
| 1270 |
+
std::error_code closeFile(file_t &F) {
|
| 1271 |
+
file_t TmpF = F;
|
| 1272 |
+
F = kInvalidFile;
|
| 1273 |
+
return Process::SafelyCloseFileDescriptor(TmpF);
|
| 1274 |
+
}
|
| 1275 |
+
|
| 1276 |
+
template <typename T>
|
| 1277 |
+
static std::error_code remove_directories_impl(const T &Entry,
|
| 1278 |
+
bool IgnoreErrors) {
|
| 1279 |
+
std::error_code EC;
|
| 1280 |
+
directory_iterator Begin(Entry, EC, false);
|
| 1281 |
+
directory_iterator End;
|
| 1282 |
+
while (Begin != End) {
|
| 1283 |
+
auto &Item = *Begin;
|
| 1284 |
+
ErrorOr<basic_file_status> st = Item.status();
|
| 1285 |
+
if (st) {
|
| 1286 |
+
if (is_directory(*st)) {
|
| 1287 |
+
EC = remove_directories_impl(Item, IgnoreErrors);
|
| 1288 |
+
if (EC && !IgnoreErrors)
|
| 1289 |
+
return EC;
|
| 1290 |
+
}
|
| 1291 |
+
|
| 1292 |
+
EC = fs::remove(Item.path(), true);
|
| 1293 |
+
if (EC && !IgnoreErrors)
|
| 1294 |
+
return EC;
|
| 1295 |
+
} else if (!IgnoreErrors) {
|
| 1296 |
+
return st.getError();
|
| 1297 |
+
}
|
| 1298 |
+
|
| 1299 |
+
Begin.increment(EC);
|
| 1300 |
+
if (EC && !IgnoreErrors)
|
| 1301 |
+
return EC;
|
| 1302 |
+
}
|
| 1303 |
+
return std::error_code();
|
| 1304 |
+
}
|
| 1305 |
+
|
| 1306 |
+
std::error_code remove_directories(const Twine &path, bool IgnoreErrors) {
|
| 1307 |
+
auto EC = remove_directories_impl(path, IgnoreErrors);
|
| 1308 |
+
if (EC && !IgnoreErrors)
|
| 1309 |
+
return EC;
|
| 1310 |
+
EC = fs::remove(path, true);
|
| 1311 |
+
if (EC && !IgnoreErrors)
|
| 1312 |
+
return EC;
|
| 1313 |
+
return std::error_code();
|
| 1314 |
+
}
|
| 1315 |
+
|
| 1316 |
+
std::error_code real_path(const Twine &path, SmallVectorImpl<char> &dest,
|
| 1317 |
+
bool expand_tilde) {
|
| 1318 |
+
dest.clear();
|
| 1319 |
+
if (path.isTriviallyEmpty())
|
| 1320 |
+
return std::error_code();
|
| 1321 |
+
|
| 1322 |
+
if (expand_tilde) {
|
| 1323 |
+
SmallString<128> Storage;
|
| 1324 |
+
path.toVector(Storage);
|
| 1325 |
+
expandTildeExpr(Storage);
|
| 1326 |
+
return real_path(Storage, dest, false);
|
| 1327 |
+
}
|
| 1328 |
+
|
| 1329 |
+
SmallString<128> Storage;
|
| 1330 |
+
StringRef P = path.toNullTerminatedStringRef(Storage);
|
| 1331 |
+
char Buffer[PATH_MAX];
|
| 1332 |
+
if (::realpath(P.begin(), Buffer) == nullptr)
|
| 1333 |
+
return errnoAsErrorCode();
|
| 1334 |
+
dest.append(Buffer, Buffer + strlen(Buffer));
|
| 1335 |
+
return std::error_code();
|
| 1336 |
+
}
|
| 1337 |
+
|
| 1338 |
+
std::error_code changeFileOwnership(int FD, uint32_t Owner, uint32_t Group) {
|
| 1339 |
+
auto FChown = [&]() { return ::fchown(FD, Owner, Group); };
|
| 1340 |
+
// Retry if fchown call fails due to interruption.
|
| 1341 |
+
if ((sys::RetryAfterSignal(-1, FChown)) < 0)
|
| 1342 |
+
return errnoAsErrorCode();
|
| 1343 |
+
return std::error_code();
|
| 1344 |
+
}
|
| 1345 |
+
|
| 1346 |
+
} // end namespace fs
|
| 1347 |
+
|
| 1348 |
+
namespace path {
|
| 1349 |
+
|
| 1350 |
+
bool home_directory(SmallVectorImpl<char> &result) {
|
| 1351 |
+
std::unique_ptr<char[]> Buf;
|
| 1352 |
+
char *RequestedDir = getenv("HOME");
|
| 1353 |
+
if (!RequestedDir) {
|
| 1354 |
+
long BufSize = sysconf(_SC_GETPW_R_SIZE_MAX);
|
| 1355 |
+
if (BufSize <= 0)
|
| 1356 |
+
BufSize = 16384;
|
| 1357 |
+
Buf = std::make_unique<char[]>(BufSize);
|
| 1358 |
+
struct passwd Pwd;
|
| 1359 |
+
struct passwd *pw = nullptr;
|
| 1360 |
+
getpwuid_r(getuid(), &Pwd, Buf.get(), BufSize, &pw);
|
| 1361 |
+
if (pw && pw->pw_dir)
|
| 1362 |
+
RequestedDir = pw->pw_dir;
|
| 1363 |
+
}
|
| 1364 |
+
if (!RequestedDir)
|
| 1365 |
+
return false;
|
| 1366 |
+
|
| 1367 |
+
result.clear();
|
| 1368 |
+
result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
|
| 1369 |
+
return true;
|
| 1370 |
+
}
|
| 1371 |
+
|
| 1372 |
+
static bool getDarwinConfDir(bool TempDir, SmallVectorImpl<char> &Result) {
|
| 1373 |
+
#if defined(_CS_DARWIN_USER_TEMP_DIR) && defined(_CS_DARWIN_USER_CACHE_DIR)
|
| 1374 |
+
// On Darwin, use DARWIN_USER_TEMP_DIR or DARWIN_USER_CACHE_DIR.
|
| 1375 |
+
// macros defined in <unistd.h> on darwin >= 9
|
| 1376 |
+
int ConfName = TempDir ? _CS_DARWIN_USER_TEMP_DIR : _CS_DARWIN_USER_CACHE_DIR;
|
| 1377 |
+
size_t ConfLen = confstr(ConfName, nullptr, 0);
|
| 1378 |
+
if (ConfLen > 0) {
|
| 1379 |
+
do {
|
| 1380 |
+
Result.resize(ConfLen);
|
| 1381 |
+
ConfLen = confstr(ConfName, Result.data(), Result.size());
|
| 1382 |
+
} while (ConfLen > 0 && ConfLen != Result.size());
|
| 1383 |
+
|
| 1384 |
+
if (ConfLen > 0) {
|
| 1385 |
+
assert(Result.back() == 0);
|
| 1386 |
+
Result.pop_back();
|
| 1387 |
+
return true;
|
| 1388 |
+
}
|
| 1389 |
+
|
| 1390 |
+
Result.clear();
|
| 1391 |
+
}
|
| 1392 |
+
#endif
|
| 1393 |
+
return false;
|
| 1394 |
+
}
|
| 1395 |
+
|
| 1396 |
+
bool user_config_directory(SmallVectorImpl<char> &result) {
|
| 1397 |
+
#ifdef __APPLE__
|
| 1398 |
+
// Mac: ~/Library/Preferences/
|
| 1399 |
+
if (home_directory(result)) {
|
| 1400 |
+
append(result, "Library", "Preferences");
|
| 1401 |
+
return true;
|
| 1402 |
+
}
|
| 1403 |
+
#else
|
| 1404 |
+
// XDG_CONFIG_HOME as defined in the XDG Base Directory Specification:
|
| 1405 |
+
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
| 1406 |
+
if (const char *RequestedDir = getenv("XDG_CONFIG_HOME")) {
|
| 1407 |
+
result.clear();
|
| 1408 |
+
result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
|
| 1409 |
+
return true;
|
| 1410 |
+
}
|
| 1411 |
+
#endif
|
| 1412 |
+
// Fallback: ~/.config
|
| 1413 |
+
if (!home_directory(result)) {
|
| 1414 |
+
return false;
|
| 1415 |
+
}
|
| 1416 |
+
append(result, ".config");
|
| 1417 |
+
return true;
|
| 1418 |
+
}
|
| 1419 |
+
|
| 1420 |
+
bool cache_directory(SmallVectorImpl<char> &result) {
|
| 1421 |
+
#ifdef __APPLE__
|
| 1422 |
+
if (getDarwinConfDir(false /*tempDir*/, result)) {
|
| 1423 |
+
return true;
|
| 1424 |
+
}
|
| 1425 |
+
#else
|
| 1426 |
+
// XDG_CACHE_HOME as defined in the XDG Base Directory Specification:
|
| 1427 |
+
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
| 1428 |
+
if (const char *RequestedDir = getenv("XDG_CACHE_HOME")) {
|
| 1429 |
+
result.clear();
|
| 1430 |
+
result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
|
| 1431 |
+
return true;
|
| 1432 |
+
}
|
| 1433 |
+
#endif
|
| 1434 |
+
if (!home_directory(result)) {
|
| 1435 |
+
return false;
|
| 1436 |
+
}
|
| 1437 |
+
append(result, ".cache");
|
| 1438 |
+
return true;
|
| 1439 |
+
}
|
| 1440 |
+
|
| 1441 |
+
static const char *getEnvTempDir() {
|
| 1442 |
+
// Check whether the temporary directory is specified by an environment
|
| 1443 |
+
// variable.
|
| 1444 |
+
const char *EnvironmentVariables[] = {"TMPDIR", "TMP", "TEMP", "TEMPDIR"};
|
| 1445 |
+
for (const char *Env : EnvironmentVariables) {
|
| 1446 |
+
if (const char *Dir = std::getenv(Env))
|
| 1447 |
+
return Dir;
|
| 1448 |
+
}
|
| 1449 |
+
|
| 1450 |
+
return nullptr;
|
| 1451 |
+
}
|
| 1452 |
+
|
| 1453 |
+
static const char *getDefaultTempDir(bool ErasedOnReboot) {
|
| 1454 |
+
#ifdef P_tmpdir
|
| 1455 |
+
if ((bool)P_tmpdir)
|
| 1456 |
+
return P_tmpdir;
|
| 1457 |
+
#endif
|
| 1458 |
+
|
| 1459 |
+
if (ErasedOnReboot)
|
| 1460 |
+
return "/tmp";
|
| 1461 |
+
return "/var/tmp";
|
| 1462 |
+
}
|
| 1463 |
+
|
| 1464 |
+
void system_temp_directory(bool ErasedOnReboot, SmallVectorImpl<char> &Result) {
|
| 1465 |
+
Result.clear();
|
| 1466 |
+
|
| 1467 |
+
if (ErasedOnReboot) {
|
| 1468 |
+
// There is no env variable for the cache directory.
|
| 1469 |
+
if (const char *RequestedDir = getEnvTempDir()) {
|
| 1470 |
+
Result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
|
| 1471 |
+
return;
|
| 1472 |
+
}
|
| 1473 |
+
}
|
| 1474 |
+
|
| 1475 |
+
if (getDarwinConfDir(ErasedOnReboot, Result))
|
| 1476 |
+
return;
|
| 1477 |
+
|
| 1478 |
+
const char *RequestedDir = getDefaultTempDir(ErasedOnReboot);
|
| 1479 |
+
Result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
|
| 1480 |
+
}
|
| 1481 |
+
|
| 1482 |
+
} // end namespace path
|
| 1483 |
+
|
| 1484 |
+
namespace fs {
|
| 1485 |
+
|
| 1486 |
+
#ifdef __APPLE__
|
| 1487 |
+
/// This implementation tries to perform an APFS CoW clone of the file,
|
| 1488 |
+
/// which can be much faster and uses less space.
|
| 1489 |
+
/// Unfortunately fcopyfile(3) does not support COPYFILE_CLONE, so the
|
| 1490 |
+
/// file descriptor variant of this function still uses the default
|
| 1491 |
+
/// implementation.
|
| 1492 |
+
std::error_code copy_file(const Twine &From, const Twine &To) {
|
| 1493 |
+
std::string FromS = From.str();
|
| 1494 |
+
std::string ToS = To.str();
|
| 1495 |
+
#if __has_builtin(__builtin_available)
|
| 1496 |
+
if (__builtin_available(macos 10.12, *)) {
|
| 1497 |
+
// Optimistically try to use clonefile() and handle errors, rather than
|
| 1498 |
+
// calling stat() to see if it'll work.
|
| 1499 |
+
//
|
| 1500 |
+
// Note: It's okay if From is a symlink. In contrast to the behaviour of
|
| 1501 |
+
// copyfile() with COPYFILE_CLONE, clonefile() clones targets (not the
|
| 1502 |
+
// symlink itself) unless the flag CLONE_NOFOLLOW is passed.
|
| 1503 |
+
if (!clonefile(FromS.c_str(), ToS.c_str(), 0))
|
| 1504 |
+
return std::error_code();
|
| 1505 |
+
|
| 1506 |
+
auto Errno = errno;
|
| 1507 |
+
switch (Errno) {
|
| 1508 |
+
case EEXIST: // To already exists.
|
| 1509 |
+
case ENOTSUP: // Device does not support cloning.
|
| 1510 |
+
case EXDEV: // From and To are on different devices.
|
| 1511 |
+
break;
|
| 1512 |
+
default:
|
| 1513 |
+
// Anything else will also break copyfile().
|
| 1514 |
+
return std::error_code(Errno, std::generic_category());
|
| 1515 |
+
}
|
| 1516 |
+
|
| 1517 |
+
// TODO: For EEXIST, profile calling fs::generateUniqueName() and
|
| 1518 |
+
// clonefile() in a retry loop (then rename() on success) before falling
|
| 1519 |
+
// back to copyfile(). Depending on the size of the file this could be
|
| 1520 |
+
// cheaper.
|
| 1521 |
+
}
|
| 1522 |
+
#endif
|
| 1523 |
+
if (!copyfile(FromS.c_str(), ToS.c_str(), /*State=*/NULL, COPYFILE_DATA))
|
| 1524 |
+
return std::error_code();
|
| 1525 |
+
return errnoAsErrorCode();
|
| 1526 |
+
}
|
| 1527 |
+
#endif // __APPLE__
|
| 1528 |
+
|
| 1529 |
+
} // end namespace fs
|
| 1530 |
+
|
| 1531 |
+
} // end namespace sys
|
| 1532 |
+
} // end namespace llvm
|
deps/exla/cache/xla_extension/include/llvm/lib/Support/Unix/Process.inc
ADDED
|
@@ -0,0 +1,421 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- Unix/Process.cpp - Unix Process Implementation --------- -*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file provides the generic Unix implementation of the Process class.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#include "Unix.h"
|
| 14 |
+
#include "llvm/ADT/Hashing.h"
|
| 15 |
+
#include "llvm/ADT/StringRef.h"
|
| 16 |
+
#include "llvm/Config/config.h"
|
| 17 |
+
#include "llvm/Config/llvm-config.h" // for LLVM_ENABLE_THREADS
|
| 18 |
+
#include <mutex>
|
| 19 |
+
#include <optional>
|
| 20 |
+
#include <fcntl.h>
|
| 21 |
+
#include <sys/time.h>
|
| 22 |
+
#include <sys/resource.h>
|
| 23 |
+
#include <sys/stat.h>
|
| 24 |
+
#include <signal.h>
|
| 25 |
+
#if defined(HAVE_MALLINFO) || defined(HAVE_MALLINFO2)
|
| 26 |
+
#include <malloc.h>
|
| 27 |
+
#endif
|
| 28 |
+
#if defined(HAVE_MALLCTL)
|
| 29 |
+
#include <malloc_np.h>
|
| 30 |
+
#endif
|
| 31 |
+
#ifdef HAVE_MALLOC_MALLOC_H
|
| 32 |
+
#include <malloc/malloc.h>
|
| 33 |
+
#endif
|
| 34 |
+
#ifdef HAVE_GETAUXVAL
|
| 35 |
+
#include <sys/auxv.h>
|
| 36 |
+
#endif
|
| 37 |
+
|
| 38 |
+
//===----------------------------------------------------------------------===//
|
| 39 |
+
//=== WARNING: Implementation here must contain only generic UNIX code that
|
| 40 |
+
//=== is guaranteed to work on *all* UNIX variants.
|
| 41 |
+
//===----------------------------------------------------------------------===//
|
| 42 |
+
|
| 43 |
+
using namespace llvm;
|
| 44 |
+
using namespace sys;
|
| 45 |
+
|
| 46 |
+
static std::pair<std::chrono::microseconds, std::chrono::microseconds>
|
| 47 |
+
getRUsageTimes() {
|
| 48 |
+
#if defined(HAVE_GETRUSAGE)
|
| 49 |
+
struct rusage RU;
|
| 50 |
+
::getrusage(RUSAGE_SELF, &RU);
|
| 51 |
+
return {toDuration(RU.ru_utime), toDuration(RU.ru_stime)};
|
| 52 |
+
#else
|
| 53 |
+
#ifndef __MVS__ // Exclude for MVS in case -pedantic is used
|
| 54 |
+
#warning Cannot get usage times on this platform
|
| 55 |
+
#endif
|
| 56 |
+
return {std::chrono::microseconds::zero(), std::chrono::microseconds::zero()};
|
| 57 |
+
#endif
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
Process::Pid Process::getProcessId() {
|
| 61 |
+
static_assert(sizeof(Pid) >= sizeof(pid_t),
|
| 62 |
+
"Process::Pid should be big enough to store pid_t");
|
| 63 |
+
return Pid(::getpid());
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
// On Cygwin, getpagesize() returns 64k(AllocationGranularity) and
|
| 67 |
+
// offset in mmap(3) should be aligned to the AllocationGranularity.
|
| 68 |
+
Expected<unsigned> Process::getPageSize() {
|
| 69 |
+
#if defined(HAVE_GETAUXVAL)
|
| 70 |
+
static const int page_size = ::getauxval(AT_PAGESZ);
|
| 71 |
+
#elif defined(HAVE_GETPAGESIZE)
|
| 72 |
+
static const int page_size = ::getpagesize();
|
| 73 |
+
#elif defined(HAVE_SYSCONF)
|
| 74 |
+
static long page_size = ::sysconf(_SC_PAGE_SIZE);
|
| 75 |
+
#else
|
| 76 |
+
#error Cannot get the page size on this machine
|
| 77 |
+
#endif
|
| 78 |
+
if (page_size == -1)
|
| 79 |
+
return errorCodeToError(errnoAsErrorCode());
|
| 80 |
+
|
| 81 |
+
assert(page_size > 0 && "Page size cannot be 0");
|
| 82 |
+
assert((page_size % 1024) == 0 && "Page size must be aligned by 1024");
|
| 83 |
+
return static_cast<unsigned>(page_size);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
size_t Process::GetMallocUsage() {
|
| 87 |
+
#if defined(HAVE_MALLINFO2)
|
| 88 |
+
struct mallinfo2 mi;
|
| 89 |
+
mi = ::mallinfo2();
|
| 90 |
+
return mi.uordblks;
|
| 91 |
+
#elif defined(HAVE_MALLINFO)
|
| 92 |
+
struct mallinfo mi;
|
| 93 |
+
mi = ::mallinfo();
|
| 94 |
+
return mi.uordblks;
|
| 95 |
+
#elif defined(HAVE_MALLOC_ZONE_STATISTICS) && defined(HAVE_MALLOC_MALLOC_H)
|
| 96 |
+
malloc_statistics_t Stats;
|
| 97 |
+
malloc_zone_statistics(malloc_default_zone(), &Stats);
|
| 98 |
+
return Stats.size_in_use; // darwin
|
| 99 |
+
#elif defined(HAVE_MALLCTL)
|
| 100 |
+
size_t alloc, sz;
|
| 101 |
+
sz = sizeof(size_t);
|
| 102 |
+
if (mallctl("stats.allocated", &alloc, &sz, NULL, 0) == 0)
|
| 103 |
+
return alloc;
|
| 104 |
+
return 0;
|
| 105 |
+
#elif defined(HAVE_SBRK)
|
| 106 |
+
// Note this is only an approximation and more closely resembles
|
| 107 |
+
// the value returned by mallinfo in the arena field.
|
| 108 |
+
static char *StartOfMemory = reinterpret_cast<char *>(::sbrk(0));
|
| 109 |
+
char *EndOfMemory = (char *)sbrk(0);
|
| 110 |
+
if (EndOfMemory != ((char *)-1) && StartOfMemory != ((char *)-1))
|
| 111 |
+
return EndOfMemory - StartOfMemory;
|
| 112 |
+
return 0;
|
| 113 |
+
#else
|
| 114 |
+
#ifndef __MVS__ // Exclude for MVS in case -pedantic is used
|
| 115 |
+
#warning Cannot get malloc info on this platform
|
| 116 |
+
#endif
|
| 117 |
+
return 0;
|
| 118 |
+
#endif
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
void Process::GetTimeUsage(TimePoint<> &elapsed,
|
| 122 |
+
std::chrono::nanoseconds &user_time,
|
| 123 |
+
std::chrono::nanoseconds &sys_time) {
|
| 124 |
+
elapsed = std::chrono::system_clock::now();
|
| 125 |
+
std::tie(user_time, sys_time) = getRUsageTimes();
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
#if defined(HAVE_MACH_MACH_H) && !defined(__GNU__)
|
| 129 |
+
#include <mach/mach.h>
|
| 130 |
+
#endif
|
| 131 |
+
|
| 132 |
+
// Some LLVM programs such as bugpoint produce core files as a normal part of
|
| 133 |
+
// their operation. To prevent the disk from filling up, this function
|
| 134 |
+
// does what's necessary to prevent their generation.
|
| 135 |
+
void Process::PreventCoreFiles() {
|
| 136 |
+
struct rlimit rlim;
|
| 137 |
+
getrlimit(RLIMIT_CORE, &rlim);
|
| 138 |
+
#ifdef __linux__
|
| 139 |
+
// On Linux, if the kernel.core_pattern sysctl starts with a '|' (i.e. it
|
| 140 |
+
// is being piped to a coredump handler such as systemd-coredumpd), the
|
| 141 |
+
// kernel ignores RLIMIT_CORE (since we aren't creating a file in the file
|
| 142 |
+
// system) except for the magic value of 1, which disables coredumps when
|
| 143 |
+
// piping. 1 byte is too small for any kind of valid core dump, so it
|
| 144 |
+
// also disables coredumps if kernel.core_pattern creates files directly.
|
| 145 |
+
// While most piped coredump handlers do respect the crashing processes'
|
| 146 |
+
// RLIMIT_CORE, this is notable not the case for Debian's systemd-coredump
|
| 147 |
+
// due to a local patch that changes sysctl.d/50-coredump.conf to ignore
|
| 148 |
+
// the specified limit and instead use RLIM_INFINITY.
|
| 149 |
+
//
|
| 150 |
+
// The alternative to using RLIMIT_CORE=1 would be to use prctl() with the
|
| 151 |
+
// PR_SET_DUMPABLE flag, however that also prevents ptrace(), so makes it
|
| 152 |
+
// impossible to attach a debugger.
|
| 153 |
+
rlim.rlim_cur = std::min<rlim_t>(1, rlim.rlim_max);
|
| 154 |
+
#else
|
| 155 |
+
rlim.rlim_cur = 0;
|
| 156 |
+
#endif
|
| 157 |
+
setrlimit(RLIMIT_CORE, &rlim);
|
| 158 |
+
|
| 159 |
+
#if defined(HAVE_MACH_MACH_H) && !defined(__GNU__)
|
| 160 |
+
// Disable crash reporting on Mac OS X 10.0-10.4
|
| 161 |
+
|
| 162 |
+
// get information about the original set of exception ports for the task
|
| 163 |
+
mach_msg_type_number_t Count = 0;
|
| 164 |
+
exception_mask_t OriginalMasks[EXC_TYPES_COUNT];
|
| 165 |
+
exception_port_t OriginalPorts[EXC_TYPES_COUNT];
|
| 166 |
+
exception_behavior_t OriginalBehaviors[EXC_TYPES_COUNT];
|
| 167 |
+
thread_state_flavor_t OriginalFlavors[EXC_TYPES_COUNT];
|
| 168 |
+
kern_return_t err = task_get_exception_ports(
|
| 169 |
+
mach_task_self(), EXC_MASK_ALL, OriginalMasks, &Count, OriginalPorts,
|
| 170 |
+
OriginalBehaviors, OriginalFlavors);
|
| 171 |
+
if (err == KERN_SUCCESS) {
|
| 172 |
+
// replace each with MACH_PORT_NULL.
|
| 173 |
+
for (unsigned i = 0; i != Count; ++i)
|
| 174 |
+
task_set_exception_ports(mach_task_self(), OriginalMasks[i],
|
| 175 |
+
MACH_PORT_NULL, OriginalBehaviors[i],
|
| 176 |
+
OriginalFlavors[i]);
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
// Disable crash reporting on Mac OS X 10.5
|
| 180 |
+
signal(SIGABRT, _exit);
|
| 181 |
+
signal(SIGILL, _exit);
|
| 182 |
+
signal(SIGFPE, _exit);
|
| 183 |
+
signal(SIGSEGV, _exit);
|
| 184 |
+
signal(SIGBUS, _exit);
|
| 185 |
+
#endif
|
| 186 |
+
|
| 187 |
+
coreFilesPrevented = true;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
std::optional<std::string> Process::GetEnv(StringRef Name) {
|
| 191 |
+
std::string NameStr = Name.str();
|
| 192 |
+
const char *Val = ::getenv(NameStr.c_str());
|
| 193 |
+
if (!Val)
|
| 194 |
+
return std::nullopt;
|
| 195 |
+
return std::string(Val);
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
namespace {
|
| 199 |
+
class FDCloser {
|
| 200 |
+
public:
|
| 201 |
+
FDCloser(int &FD) : FD(FD), KeepOpen(false) {}
|
| 202 |
+
void keepOpen() { KeepOpen = true; }
|
| 203 |
+
~FDCloser() {
|
| 204 |
+
if (!KeepOpen && FD >= 0)
|
| 205 |
+
::close(FD);
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
private:
|
| 209 |
+
FDCloser(const FDCloser &) = delete;
|
| 210 |
+
void operator=(const FDCloser &) = delete;
|
| 211 |
+
|
| 212 |
+
int &FD;
|
| 213 |
+
bool KeepOpen;
|
| 214 |
+
};
|
| 215 |
+
} // namespace
|
| 216 |
+
|
| 217 |
+
std::error_code Process::FixupStandardFileDescriptors() {
|
| 218 |
+
int NullFD = -1;
|
| 219 |
+
FDCloser FDC(NullFD);
|
| 220 |
+
const int StandardFDs[] = {STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO};
|
| 221 |
+
for (int StandardFD : StandardFDs) {
|
| 222 |
+
struct stat st;
|
| 223 |
+
errno = 0;
|
| 224 |
+
if (RetryAfterSignal(-1, ::fstat, StandardFD, &st) < 0) {
|
| 225 |
+
assert(errno && "expected errno to be set if fstat failed!");
|
| 226 |
+
// fstat should return EBADF if the file descriptor is closed.
|
| 227 |
+
if (errno != EBADF)
|
| 228 |
+
return errnoAsErrorCode();
|
| 229 |
+
}
|
| 230 |
+
// if fstat succeeds, move on to the next FD.
|
| 231 |
+
if (!errno)
|
| 232 |
+
continue;
|
| 233 |
+
assert(errno == EBADF && "expected errno to have EBADF at this point!");
|
| 234 |
+
|
| 235 |
+
if (NullFD < 0) {
|
| 236 |
+
// Call ::open in a lambda to avoid overload resolution in
|
| 237 |
+
// RetryAfterSignal when open is overloaded, such as in Bionic.
|
| 238 |
+
auto Open = [&]() { return ::open("/dev/null", O_RDWR); };
|
| 239 |
+
if ((NullFD = RetryAfterSignal(-1, Open)) < 0)
|
| 240 |
+
return errnoAsErrorCode();
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
if (NullFD == StandardFD)
|
| 244 |
+
FDC.keepOpen();
|
| 245 |
+
else if (dup2(NullFD, StandardFD) < 0)
|
| 246 |
+
return errnoAsErrorCode();
|
| 247 |
+
}
|
| 248 |
+
return std::error_code();
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
std::error_code Process::SafelyCloseFileDescriptor(int FD) {
|
| 252 |
+
// Create a signal set filled with *all* signals.
|
| 253 |
+
sigset_t FullSet, SavedSet;
|
| 254 |
+
if (sigfillset(&FullSet) < 0 || sigfillset(&SavedSet) < 0)
|
| 255 |
+
return errnoAsErrorCode();
|
| 256 |
+
|
| 257 |
+
// Atomically swap our current signal mask with a full mask.
|
| 258 |
+
#if LLVM_ENABLE_THREADS
|
| 259 |
+
if (int EC = pthread_sigmask(SIG_SETMASK, &FullSet, &SavedSet))
|
| 260 |
+
return std::error_code(EC, std::generic_category());
|
| 261 |
+
#else
|
| 262 |
+
if (sigprocmask(SIG_SETMASK, &FullSet, &SavedSet) < 0)
|
| 263 |
+
return errnoAsErrorCode();
|
| 264 |
+
#endif
|
| 265 |
+
// Attempt to close the file descriptor.
|
| 266 |
+
// We need to save the error, if one occurs, because our subsequent call to
|
| 267 |
+
// pthread_sigmask might tamper with errno.
|
| 268 |
+
int ErrnoFromClose = 0;
|
| 269 |
+
if (::close(FD) < 0)
|
| 270 |
+
ErrnoFromClose = errno;
|
| 271 |
+
// Restore the signal mask back to what we saved earlier.
|
| 272 |
+
int EC = 0;
|
| 273 |
+
#if LLVM_ENABLE_THREADS
|
| 274 |
+
EC = pthread_sigmask(SIG_SETMASK, &SavedSet, nullptr);
|
| 275 |
+
#else
|
| 276 |
+
if (sigprocmask(SIG_SETMASK, &SavedSet, nullptr) < 0)
|
| 277 |
+
EC = errno;
|
| 278 |
+
#endif
|
| 279 |
+
// The error code from close takes precedence over the one from
|
| 280 |
+
// pthread_sigmask.
|
| 281 |
+
if (ErrnoFromClose)
|
| 282 |
+
return std::error_code(ErrnoFromClose, std::generic_category());
|
| 283 |
+
return std::error_code(EC, std::generic_category());
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
bool Process::StandardInIsUserInput() {
|
| 287 |
+
return FileDescriptorIsDisplayed(STDIN_FILENO);
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
bool Process::StandardOutIsDisplayed() {
|
| 291 |
+
return FileDescriptorIsDisplayed(STDOUT_FILENO);
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
bool Process::StandardErrIsDisplayed() {
|
| 295 |
+
return FileDescriptorIsDisplayed(STDERR_FILENO);
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
bool Process::FileDescriptorIsDisplayed(int fd) {
|
| 299 |
+
#if HAVE_ISATTY
|
| 300 |
+
return isatty(fd);
|
| 301 |
+
#else
|
| 302 |
+
// If we don't have isatty, just return false.
|
| 303 |
+
return false;
|
| 304 |
+
#endif
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
static unsigned getColumns() {
|
| 308 |
+
// If COLUMNS is defined in the environment, wrap to that many columns.
|
| 309 |
+
if (const char *ColumnsStr = std::getenv("COLUMNS")) {
|
| 310 |
+
int Columns = std::atoi(ColumnsStr);
|
| 311 |
+
if (Columns > 0)
|
| 312 |
+
return Columns;
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
// We used to call ioctl TIOCGWINSZ to determine the width. It is considered
|
| 316 |
+
// unuseful.
|
| 317 |
+
return 0;
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
unsigned Process::StandardOutColumns() {
|
| 321 |
+
if (!StandardOutIsDisplayed())
|
| 322 |
+
return 0;
|
| 323 |
+
|
| 324 |
+
return getColumns();
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
unsigned Process::StandardErrColumns() {
|
| 328 |
+
if (!StandardErrIsDisplayed())
|
| 329 |
+
return 0;
|
| 330 |
+
|
| 331 |
+
return getColumns();
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
static bool terminalHasColors() {
|
| 335 |
+
// Check if the current terminal is one of terminals that are known to support
|
| 336 |
+
// ANSI color escape codes.
|
| 337 |
+
if (const char *TermStr = std::getenv("TERM")) {
|
| 338 |
+
return StringSwitch<bool>(TermStr)
|
| 339 |
+
.Case("ansi", true)
|
| 340 |
+
.Case("cygwin", true)
|
| 341 |
+
.Case("linux", true)
|
| 342 |
+
.StartsWith("screen", true)
|
| 343 |
+
.StartsWith("xterm", true)
|
| 344 |
+
.StartsWith("vt100", true)
|
| 345 |
+
.StartsWith("rxvt", true)
|
| 346 |
+
.EndsWith("color", true)
|
| 347 |
+
.Default(false);
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
return false;
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
bool Process::FileDescriptorHasColors(int fd) {
|
| 354 |
+
// A file descriptor has colors if it is displayed and the terminal has
|
| 355 |
+
// colors.
|
| 356 |
+
return FileDescriptorIsDisplayed(fd) && terminalHasColors();
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
bool Process::StandardOutHasColors() {
|
| 360 |
+
return FileDescriptorHasColors(STDOUT_FILENO);
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
bool Process::StandardErrHasColors() {
|
| 364 |
+
return FileDescriptorHasColors(STDERR_FILENO);
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
void Process::UseANSIEscapeCodes(bool /*enable*/) {
|
| 368 |
+
// No effect.
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
bool Process::ColorNeedsFlush() {
|
| 372 |
+
// No, we use ANSI escape sequences.
|
| 373 |
+
return false;
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
const char *Process::OutputColor(char code, bool bold, bool bg) {
|
| 377 |
+
return colorcodes[bg ? 1 : 0][bold ? 1 : 0][code & 15];
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
const char *Process::OutputBold(bool bg) { return "\033[1m"; }
|
| 381 |
+
|
| 382 |
+
const char *Process::OutputReverse() { return "\033[7m"; }
|
| 383 |
+
|
| 384 |
+
const char *Process::ResetColor() { return "\033[0m"; }
|
| 385 |
+
|
| 386 |
+
#if !HAVE_DECL_ARC4RANDOM
|
| 387 |
+
static unsigned GetRandomNumberSeed() {
|
| 388 |
+
// Attempt to get the initial seed from /dev/urandom, if possible.
|
| 389 |
+
int urandomFD = open("/dev/urandom", O_RDONLY);
|
| 390 |
+
|
| 391 |
+
if (urandomFD != -1) {
|
| 392 |
+
unsigned seed;
|
| 393 |
+
// Don't use a buffered read to avoid reading more data
|
| 394 |
+
// from /dev/urandom than we need.
|
| 395 |
+
int count = read(urandomFD, (void *)&seed, sizeof(seed));
|
| 396 |
+
|
| 397 |
+
close(urandomFD);
|
| 398 |
+
|
| 399 |
+
// Return the seed if the read was successful.
|
| 400 |
+
if (count == sizeof(seed))
|
| 401 |
+
return seed;
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
// Otherwise, swizzle the current time and the process ID to form a reasonable
|
| 405 |
+
// seed.
|
| 406 |
+
const auto Now = std::chrono::high_resolution_clock::now();
|
| 407 |
+
return hash_combine(Now.time_since_epoch().count(), ::getpid());
|
| 408 |
+
}
|
| 409 |
+
#endif
|
| 410 |
+
|
| 411 |
+
unsigned llvm::sys::Process::GetRandomNumber() {
|
| 412 |
+
#if HAVE_DECL_ARC4RANDOM
|
| 413 |
+
return arc4random();
|
| 414 |
+
#else
|
| 415 |
+
static int x = (static_cast<void>(::srand(GetRandomNumberSeed())), 0);
|
| 416 |
+
(void)x;
|
| 417 |
+
return ::rand();
|
| 418 |
+
#endif
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
[[noreturn]] void Process::ExitNoCleanup(int RetCode) { _Exit(RetCode); }
|
deps/exla/cache/xla_extension/include/llvm/lib/Support/Unix/Program.inc
ADDED
|
@@ -0,0 +1,588 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- llvm/Support/Unix/Program.inc ----------------------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file implements the Unix specific portion of the Program class.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
//===----------------------------------------------------------------------===//
|
| 14 |
+
//=== WARNING: Implementation here must contain only generic UNIX
|
| 15 |
+
//=== code that is guaranteed to work on *all* UNIX variants.
|
| 16 |
+
//===----------------------------------------------------------------------===//
|
| 17 |
+
|
| 18 |
+
#include "llvm/Support/Program.h"
|
| 19 |
+
|
| 20 |
+
#include "Unix.h"
|
| 21 |
+
#include "llvm/ADT/StringExtras.h"
|
| 22 |
+
#include "llvm/Config/config.h"
|
| 23 |
+
#include "llvm/Support/AutoConvert.h"
|
| 24 |
+
#include "llvm/Support/Compiler.h"
|
| 25 |
+
#include "llvm/Support/Errc.h"
|
| 26 |
+
#include "llvm/Support/FileSystem.h"
|
| 27 |
+
#include "llvm/Support/Path.h"
|
| 28 |
+
#include "llvm/Support/StringSaver.h"
|
| 29 |
+
#include "llvm/Support/SystemZ/zOSSupport.h"
|
| 30 |
+
#include "llvm/Support/raw_ostream.h"
|
| 31 |
+
#include <sys/stat.h>
|
| 32 |
+
#include <sys/resource.h>
|
| 33 |
+
#include <signal.h>
|
| 34 |
+
#include <fcntl.h>
|
| 35 |
+
#if HAVE_UNISTD_H
|
| 36 |
+
#include <unistd.h>
|
| 37 |
+
#endif
|
| 38 |
+
#ifdef HAVE_POSIX_SPAWN
|
| 39 |
+
#include <spawn.h>
|
| 40 |
+
|
| 41 |
+
#if defined(__APPLE__)
|
| 42 |
+
#include <TargetConditionals.h>
|
| 43 |
+
#endif
|
| 44 |
+
|
| 45 |
+
#if defined(__APPLE__) && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
|
| 46 |
+
#define USE_NSGETENVIRON 1
|
| 47 |
+
#else
|
| 48 |
+
#define USE_NSGETENVIRON 0
|
| 49 |
+
#endif
|
| 50 |
+
|
| 51 |
+
#if !USE_NSGETENVIRON
|
| 52 |
+
extern char **environ;
|
| 53 |
+
#else
|
| 54 |
+
#include <crt_externs.h> // _NSGetEnviron
|
| 55 |
+
#endif
|
| 56 |
+
#endif
|
| 57 |
+
|
| 58 |
+
using namespace llvm;
|
| 59 |
+
using namespace sys;
|
| 60 |
+
|
| 61 |
+
ProcessInfo::ProcessInfo() : Pid(0), ReturnCode(0) {}
|
| 62 |
+
|
| 63 |
+
ErrorOr<std::string> sys::findProgramByName(StringRef Name,
|
| 64 |
+
ArrayRef<StringRef> Paths) {
|
| 65 |
+
assert(!Name.empty() && "Must have a name!");
|
| 66 |
+
// Use the given path verbatim if it contains any slashes; this matches
|
| 67 |
+
// the behavior of sh(1) and friends.
|
| 68 |
+
if (Name.contains('/'))
|
| 69 |
+
return std::string(Name);
|
| 70 |
+
|
| 71 |
+
SmallVector<StringRef, 16> EnvironmentPaths;
|
| 72 |
+
if (Paths.empty())
|
| 73 |
+
if (const char *PathEnv = std::getenv("PATH")) {
|
| 74 |
+
SplitString(PathEnv, EnvironmentPaths, ":");
|
| 75 |
+
Paths = EnvironmentPaths;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
for (auto Path : Paths) {
|
| 79 |
+
if (Path.empty())
|
| 80 |
+
continue;
|
| 81 |
+
|
| 82 |
+
// Check to see if this first directory contains the executable...
|
| 83 |
+
SmallString<128> FilePath(Path);
|
| 84 |
+
sys::path::append(FilePath, Name);
|
| 85 |
+
if (sys::fs::can_execute(FilePath.c_str()))
|
| 86 |
+
return std::string(FilePath); // Found the executable!
|
| 87 |
+
}
|
| 88 |
+
return errc::no_such_file_or_directory;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
static bool RedirectIO(std::optional<StringRef> Path, int FD, std::string *ErrMsg) {
|
| 92 |
+
if (!Path) // Noop
|
| 93 |
+
return false;
|
| 94 |
+
std::string File;
|
| 95 |
+
if (Path->empty())
|
| 96 |
+
// Redirect empty paths to /dev/null
|
| 97 |
+
File = "/dev/null";
|
| 98 |
+
else
|
| 99 |
+
File = std::string(*Path);
|
| 100 |
+
|
| 101 |
+
// Open the file
|
| 102 |
+
int InFD = open(File.c_str(), FD == 0 ? O_RDONLY : O_WRONLY | O_CREAT, 0666);
|
| 103 |
+
if (InFD == -1) {
|
| 104 |
+
MakeErrMsg(ErrMsg, "Cannot open file '" + File + "' for " +
|
| 105 |
+
(FD == 0 ? "input" : "output"));
|
| 106 |
+
return true;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
// Install it as the requested FD
|
| 110 |
+
if (dup2(InFD, FD) == -1) {
|
| 111 |
+
MakeErrMsg(ErrMsg, "Cannot dup2");
|
| 112 |
+
close(InFD);
|
| 113 |
+
return true;
|
| 114 |
+
}
|
| 115 |
+
close(InFD); // Close the original FD
|
| 116 |
+
return false;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
#ifdef HAVE_POSIX_SPAWN
|
| 120 |
+
static bool RedirectIO_PS(const std::string *Path, int FD, std::string *ErrMsg,
|
| 121 |
+
posix_spawn_file_actions_t *FileActions) {
|
| 122 |
+
if (!Path) // Noop
|
| 123 |
+
return false;
|
| 124 |
+
const char *File;
|
| 125 |
+
if (Path->empty())
|
| 126 |
+
// Redirect empty paths to /dev/null
|
| 127 |
+
File = "/dev/null";
|
| 128 |
+
else
|
| 129 |
+
File = Path->c_str();
|
| 130 |
+
|
| 131 |
+
if (int Err = posix_spawn_file_actions_addopen(
|
| 132 |
+
FileActions, FD, File, FD == 0 ? O_RDONLY : O_WRONLY | O_CREAT, 0666))
|
| 133 |
+
return MakeErrMsg(ErrMsg, "Cannot posix_spawn_file_actions_addopen", Err);
|
| 134 |
+
return false;
|
| 135 |
+
}
|
| 136 |
+
#endif
|
| 137 |
+
|
| 138 |
+
static void TimeOutHandler(int Sig) {}
|
| 139 |
+
|
| 140 |
+
static void SetMemoryLimits(unsigned size) {
|
| 141 |
+
struct rlimit r;
|
| 142 |
+
__typeof__(r.rlim_cur) limit = (__typeof__(r.rlim_cur))(size)*1048576;
|
| 143 |
+
|
| 144 |
+
// Heap size
|
| 145 |
+
getrlimit(RLIMIT_DATA, &r);
|
| 146 |
+
r.rlim_cur = limit;
|
| 147 |
+
setrlimit(RLIMIT_DATA, &r);
|
| 148 |
+
#ifdef RLIMIT_RSS
|
| 149 |
+
// Resident set size.
|
| 150 |
+
getrlimit(RLIMIT_RSS, &r);
|
| 151 |
+
r.rlim_cur = limit;
|
| 152 |
+
setrlimit(RLIMIT_RSS, &r);
|
| 153 |
+
#endif
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
static std::vector<const char *>
|
| 157 |
+
toNullTerminatedCStringArray(ArrayRef<StringRef> Strings, StringSaver &Saver) {
|
| 158 |
+
std::vector<const char *> Result;
|
| 159 |
+
for (StringRef S : Strings)
|
| 160 |
+
Result.push_back(Saver.save(S).data());
|
| 161 |
+
Result.push_back(nullptr);
|
| 162 |
+
return Result;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
static bool Execute(ProcessInfo &PI, StringRef Program,
|
| 166 |
+
ArrayRef<StringRef> Args,
|
| 167 |
+
std::optional<ArrayRef<StringRef>> Env,
|
| 168 |
+
ArrayRef<std::optional<StringRef>> Redirects,
|
| 169 |
+
unsigned MemoryLimit, std::string *ErrMsg,
|
| 170 |
+
BitVector *AffinityMask, bool DetachProcess) {
|
| 171 |
+
assert(!AffinityMask && "Starting a process with an affinity mask is "
|
| 172 |
+
"currently not supported on Unix!");
|
| 173 |
+
|
| 174 |
+
BumpPtrAllocator Allocator;
|
| 175 |
+
StringSaver Saver(Allocator);
|
| 176 |
+
std::vector<const char *> ArgVector, EnvVector;
|
| 177 |
+
const char **Argv = nullptr;
|
| 178 |
+
const char **Envp = nullptr;
|
| 179 |
+
ArgVector = toNullTerminatedCStringArray(Args, Saver);
|
| 180 |
+
Argv = ArgVector.data();
|
| 181 |
+
if (Env) {
|
| 182 |
+
EnvVector = toNullTerminatedCStringArray(*Env, Saver);
|
| 183 |
+
Envp = EnvVector.data();
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
// If this OS has posix_spawn and there is no memory limit being implied, use
|
| 187 |
+
// posix_spawn. It is more efficient than fork/exec.
|
| 188 |
+
#ifdef HAVE_POSIX_SPAWN
|
| 189 |
+
// Cannot use posix_spawn if you would like to detach the process
|
| 190 |
+
if (MemoryLimit == 0 && !DetachProcess) {
|
| 191 |
+
posix_spawn_file_actions_t FileActionsStore;
|
| 192 |
+
posix_spawn_file_actions_t *FileActions = nullptr;
|
| 193 |
+
|
| 194 |
+
// If we call posix_spawn_file_actions_addopen we have to make sure the
|
| 195 |
+
// c strings we pass to it stay alive until the call to posix_spawn,
|
| 196 |
+
// so we copy any StringRefs into this variable.
|
| 197 |
+
std::string RedirectsStorage[3];
|
| 198 |
+
|
| 199 |
+
if (!Redirects.empty()) {
|
| 200 |
+
assert(Redirects.size() == 3);
|
| 201 |
+
std::string *RedirectsStr[3] = {nullptr, nullptr, nullptr};
|
| 202 |
+
for (int I = 0; I < 3; ++I) {
|
| 203 |
+
if (Redirects[I]) {
|
| 204 |
+
RedirectsStorage[I] = std::string(*Redirects[I]);
|
| 205 |
+
RedirectsStr[I] = &RedirectsStorage[I];
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
FileActions = &FileActionsStore;
|
| 210 |
+
posix_spawn_file_actions_init(FileActions);
|
| 211 |
+
|
| 212 |
+
// Redirect stdin/stdout.
|
| 213 |
+
if (RedirectIO_PS(RedirectsStr[0], 0, ErrMsg, FileActions) ||
|
| 214 |
+
RedirectIO_PS(RedirectsStr[1], 1, ErrMsg, FileActions))
|
| 215 |
+
return false;
|
| 216 |
+
if (!Redirects[1] || !Redirects[2] || *Redirects[1] != *Redirects[2]) {
|
| 217 |
+
// Just redirect stderr
|
| 218 |
+
if (RedirectIO_PS(RedirectsStr[2], 2, ErrMsg, FileActions))
|
| 219 |
+
return false;
|
| 220 |
+
} else {
|
| 221 |
+
// If stdout and stderr should go to the same place, redirect stderr
|
| 222 |
+
// to the FD already open for stdout.
|
| 223 |
+
if (int Err = posix_spawn_file_actions_adddup2(FileActions, 1, 2))
|
| 224 |
+
return !MakeErrMsg(ErrMsg, "Can't redirect stderr to stdout", Err);
|
| 225 |
+
}
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
if (!Envp)
|
| 229 |
+
#if !USE_NSGETENVIRON
|
| 230 |
+
Envp = const_cast<const char **>(environ);
|
| 231 |
+
#else
|
| 232 |
+
// environ is missing in dylibs.
|
| 233 |
+
Envp = const_cast<const char **>(*_NSGetEnviron());
|
| 234 |
+
#endif
|
| 235 |
+
|
| 236 |
+
constexpr int maxRetries = 8;
|
| 237 |
+
int retries = 0;
|
| 238 |
+
pid_t PID;
|
| 239 |
+
int Err;
|
| 240 |
+
do {
|
| 241 |
+
PID = 0; // Make Valgrind happy.
|
| 242 |
+
Err = posix_spawn(&PID, Program.str().c_str(), FileActions,
|
| 243 |
+
/*attrp*/ nullptr, const_cast<char **>(Argv),
|
| 244 |
+
const_cast<char **>(Envp));
|
| 245 |
+
} while (Err == EINTR && ++retries < maxRetries);
|
| 246 |
+
|
| 247 |
+
if (FileActions)
|
| 248 |
+
posix_spawn_file_actions_destroy(FileActions);
|
| 249 |
+
|
| 250 |
+
if (Err)
|
| 251 |
+
return !MakeErrMsg(ErrMsg, "posix_spawn failed", Err);
|
| 252 |
+
|
| 253 |
+
PI.Pid = PID;
|
| 254 |
+
PI.Process = PID;
|
| 255 |
+
|
| 256 |
+
return true;
|
| 257 |
+
}
|
| 258 |
+
#endif // HAVE_POSIX_SPAWN
|
| 259 |
+
|
| 260 |
+
// Create a child process.
|
| 261 |
+
int child = fork();
|
| 262 |
+
switch (child) {
|
| 263 |
+
// An error occurred: Return to the caller.
|
| 264 |
+
case -1:
|
| 265 |
+
MakeErrMsg(ErrMsg, "Couldn't fork");
|
| 266 |
+
return false;
|
| 267 |
+
|
| 268 |
+
// Child process: Execute the program.
|
| 269 |
+
case 0: {
|
| 270 |
+
// Redirect file descriptors...
|
| 271 |
+
if (!Redirects.empty()) {
|
| 272 |
+
// Redirect stdin
|
| 273 |
+
if (RedirectIO(Redirects[0], 0, ErrMsg)) {
|
| 274 |
+
return false;
|
| 275 |
+
}
|
| 276 |
+
// Redirect stdout
|
| 277 |
+
if (RedirectIO(Redirects[1], 1, ErrMsg)) {
|
| 278 |
+
return false;
|
| 279 |
+
}
|
| 280 |
+
if (Redirects[1] && Redirects[2] && *Redirects[1] == *Redirects[2]) {
|
| 281 |
+
// If stdout and stderr should go to the same place, redirect stderr
|
| 282 |
+
// to the FD already open for stdout.
|
| 283 |
+
if (-1 == dup2(1, 2)) {
|
| 284 |
+
MakeErrMsg(ErrMsg, "Can't redirect stderr to stdout");
|
| 285 |
+
return false;
|
| 286 |
+
}
|
| 287 |
+
} else {
|
| 288 |
+
// Just redirect stderr
|
| 289 |
+
if (RedirectIO(Redirects[2], 2, ErrMsg)) {
|
| 290 |
+
return false;
|
| 291 |
+
}
|
| 292 |
+
}
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
if (DetachProcess) {
|
| 296 |
+
// Detach from controlling terminal
|
| 297 |
+
if (::setsid() == -1) {
|
| 298 |
+
MakeErrMsg(ErrMsg, "Could not detach process, ::setsid failed");
|
| 299 |
+
return false;
|
| 300 |
+
}
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
// Set memory limits
|
| 304 |
+
if (MemoryLimit != 0) {
|
| 305 |
+
SetMemoryLimits(MemoryLimit);
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
// Execute!
|
| 309 |
+
std::string PathStr = std::string(Program);
|
| 310 |
+
if (Envp != nullptr)
|
| 311 |
+
execve(PathStr.c_str(), const_cast<char **>(Argv),
|
| 312 |
+
const_cast<char **>(Envp));
|
| 313 |
+
else
|
| 314 |
+
execv(PathStr.c_str(), const_cast<char **>(Argv));
|
| 315 |
+
// If the execve() failed, we should exit. Follow Unix protocol and
|
| 316 |
+
// return 127 if the executable was not found, and 126 otherwise.
|
| 317 |
+
// Use _exit rather than exit so that atexit functions and static
|
| 318 |
+
// object destructors cloned from the parent process aren't
|
| 319 |
+
// redundantly run, and so that any data buffered in stdio buffers
|
| 320 |
+
// cloned from the parent aren't redundantly written out.
|
| 321 |
+
_exit(errno == ENOENT ? 127 : 126);
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
// Parent process: Break out of the switch to do our processing.
|
| 325 |
+
default:
|
| 326 |
+
break;
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
PI.Pid = child;
|
| 330 |
+
PI.Process = child;
|
| 331 |
+
|
| 332 |
+
return true;
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
namespace llvm {
|
| 336 |
+
namespace sys {
|
| 337 |
+
|
| 338 |
+
#if defined(_AIX)
|
| 339 |
+
static pid_t(wait4)(pid_t pid, int *status, int options, struct rusage *usage);
|
| 340 |
+
#elif !defined(__Fuchsia__)
|
| 341 |
+
using ::wait4;
|
| 342 |
+
#endif
|
| 343 |
+
|
| 344 |
+
} // namespace sys
|
| 345 |
+
} // namespace llvm
|
| 346 |
+
|
| 347 |
+
#ifdef _AIX
|
| 348 |
+
#ifndef _ALL_SOURCE
|
| 349 |
+
extern "C" pid_t(wait4)(pid_t pid, int *status, int options,
|
| 350 |
+
struct rusage *usage);
|
| 351 |
+
#endif
|
| 352 |
+
pid_t(llvm::sys::wait4)(pid_t pid, int *status, int options,
|
| 353 |
+
struct rusage *usage) {
|
| 354 |
+
assert(pid > 0 && "Only expecting to handle actual PID values!");
|
| 355 |
+
assert((options & ~WNOHANG) == 0 && "Expecting WNOHANG at most!");
|
| 356 |
+
assert(usage && "Expecting usage collection!");
|
| 357 |
+
|
| 358 |
+
// AIX wait4 does not work well with WNOHANG.
|
| 359 |
+
if (!(options & WNOHANG))
|
| 360 |
+
return ::wait4(pid, status, options, usage);
|
| 361 |
+
|
| 362 |
+
// For WNOHANG, we use waitid (which supports WNOWAIT) until the child process
|
| 363 |
+
// has terminated.
|
| 364 |
+
siginfo_t WaitIdInfo;
|
| 365 |
+
WaitIdInfo.si_pid = 0;
|
| 366 |
+
int WaitIdRetVal =
|
| 367 |
+
waitid(P_PID, pid, &WaitIdInfo, WNOWAIT | WEXITED | options);
|
| 368 |
+
|
| 369 |
+
if (WaitIdRetVal == -1 || WaitIdInfo.si_pid == 0)
|
| 370 |
+
return WaitIdRetVal;
|
| 371 |
+
|
| 372 |
+
assert(WaitIdInfo.si_pid == pid);
|
| 373 |
+
|
| 374 |
+
// The child has already terminated, so a blocking wait on it is okay in the
|
| 375 |
+
// absence of indiscriminate `wait` calls from the current process (which
|
| 376 |
+
// would cause the call here to fail with ECHILD).
|
| 377 |
+
return ::wait4(pid, status, options & ~WNOHANG, usage);
|
| 378 |
+
}
|
| 379 |
+
#endif
|
| 380 |
+
|
| 381 |
+
ProcessInfo llvm::sys::Wait(const ProcessInfo &PI,
|
| 382 |
+
std::optional<unsigned> SecondsToWait,
|
| 383 |
+
std::string *ErrMsg,
|
| 384 |
+
std::optional<ProcessStatistics> *ProcStat,
|
| 385 |
+
bool Polling) {
|
| 386 |
+
struct sigaction Act, Old;
|
| 387 |
+
assert(PI.Pid && "invalid pid to wait on, process not started?");
|
| 388 |
+
|
| 389 |
+
int WaitPidOptions = 0;
|
| 390 |
+
pid_t ChildPid = PI.Pid;
|
| 391 |
+
bool WaitUntilTerminates = false;
|
| 392 |
+
if (!SecondsToWait) {
|
| 393 |
+
WaitUntilTerminates = true;
|
| 394 |
+
} else {
|
| 395 |
+
if (*SecondsToWait == 0)
|
| 396 |
+
WaitPidOptions = WNOHANG;
|
| 397 |
+
|
| 398 |
+
// Install a timeout handler. The handler itself does nothing, but the
|
| 399 |
+
// simple fact of having a handler at all causes the wait below to return
|
| 400 |
+
// with EINTR, unlike if we used SIG_IGN.
|
| 401 |
+
memset(&Act, 0, sizeof(Act));
|
| 402 |
+
Act.sa_handler = TimeOutHandler;
|
| 403 |
+
sigemptyset(&Act.sa_mask);
|
| 404 |
+
sigaction(SIGALRM, &Act, &Old);
|
| 405 |
+
// FIXME The alarm signal may be delivered to another thread.
|
| 406 |
+
alarm(*SecondsToWait);
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
// Parent process: Wait for the child process to terminate.
|
| 410 |
+
int status = 0;
|
| 411 |
+
ProcessInfo WaitResult;
|
| 412 |
+
#ifndef __Fuchsia__
|
| 413 |
+
rusage Info;
|
| 414 |
+
if (ProcStat)
|
| 415 |
+
ProcStat->reset();
|
| 416 |
+
|
| 417 |
+
do {
|
| 418 |
+
WaitResult.Pid = sys::wait4(ChildPid, &status, WaitPidOptions, &Info);
|
| 419 |
+
} while (WaitUntilTerminates && WaitResult.Pid == -1 && errno == EINTR);
|
| 420 |
+
#endif
|
| 421 |
+
|
| 422 |
+
if (WaitResult.Pid != PI.Pid) {
|
| 423 |
+
if (WaitResult.Pid == 0) {
|
| 424 |
+
// Non-blocking wait.
|
| 425 |
+
return WaitResult;
|
| 426 |
+
} else {
|
| 427 |
+
if (SecondsToWait && errno == EINTR && !Polling) {
|
| 428 |
+
// Kill the child.
|
| 429 |
+
kill(PI.Pid, SIGKILL);
|
| 430 |
+
|
| 431 |
+
// Turn off the alarm and restore the signal handler
|
| 432 |
+
alarm(0);
|
| 433 |
+
sigaction(SIGALRM, &Old, nullptr);
|
| 434 |
+
|
| 435 |
+
// Wait for child to die
|
| 436 |
+
// FIXME This could grab some other child process out from another
|
| 437 |
+
// waiting thread and then leave a zombie anyway.
|
| 438 |
+
if (wait(&status) != ChildPid)
|
| 439 |
+
MakeErrMsg(ErrMsg, "Child timed out but wouldn't die");
|
| 440 |
+
else
|
| 441 |
+
MakeErrMsg(ErrMsg, "Child timed out", 0);
|
| 442 |
+
|
| 443 |
+
WaitResult.ReturnCode = -2; // Timeout detected
|
| 444 |
+
return WaitResult;
|
| 445 |
+
} else if (errno != EINTR) {
|
| 446 |
+
MakeErrMsg(ErrMsg, "Error waiting for child process");
|
| 447 |
+
WaitResult.ReturnCode = -1;
|
| 448 |
+
return WaitResult;
|
| 449 |
+
}
|
| 450 |
+
}
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
// We exited normally without timeout, so turn off the timer.
|
| 454 |
+
if (SecondsToWait && !WaitUntilTerminates) {
|
| 455 |
+
alarm(0);
|
| 456 |
+
sigaction(SIGALRM, &Old, nullptr);
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
#ifndef __Fuchsia__
|
| 460 |
+
if (ProcStat) {
|
| 461 |
+
std::chrono::microseconds UserT = toDuration(Info.ru_utime);
|
| 462 |
+
std::chrono::microseconds KernelT = toDuration(Info.ru_stime);
|
| 463 |
+
uint64_t PeakMemory = 0;
|
| 464 |
+
#if !defined(__HAIKU__) && !defined(__MVS__)
|
| 465 |
+
PeakMemory = static_cast<uint64_t>(Info.ru_maxrss);
|
| 466 |
+
#endif
|
| 467 |
+
*ProcStat = ProcessStatistics{UserT + KernelT, UserT, PeakMemory};
|
| 468 |
+
}
|
| 469 |
+
#endif
|
| 470 |
+
|
| 471 |
+
// Return the proper exit status. Detect error conditions
|
| 472 |
+
// so we can return -1 for them and set ErrMsg informatively.
|
| 473 |
+
int result = 0;
|
| 474 |
+
if (WIFEXITED(status)) {
|
| 475 |
+
result = WEXITSTATUS(status);
|
| 476 |
+
WaitResult.ReturnCode = result;
|
| 477 |
+
|
| 478 |
+
if (result == 127) {
|
| 479 |
+
if (ErrMsg)
|
| 480 |
+
*ErrMsg = llvm::sys::StrError(ENOENT);
|
| 481 |
+
WaitResult.ReturnCode = -1;
|
| 482 |
+
return WaitResult;
|
| 483 |
+
}
|
| 484 |
+
if (result == 126) {
|
| 485 |
+
if (ErrMsg)
|
| 486 |
+
*ErrMsg = "Program could not be executed";
|
| 487 |
+
WaitResult.ReturnCode = -1;
|
| 488 |
+
return WaitResult;
|
| 489 |
+
}
|
| 490 |
+
} else if (WIFSIGNALED(status)) {
|
| 491 |
+
if (ErrMsg) {
|
| 492 |
+
*ErrMsg = strsignal(WTERMSIG(status));
|
| 493 |
+
#ifdef WCOREDUMP
|
| 494 |
+
if (WCOREDUMP(status))
|
| 495 |
+
*ErrMsg += " (core dumped)";
|
| 496 |
+
#endif
|
| 497 |
+
}
|
| 498 |
+
// Return a special value to indicate that the process received an unhandled
|
| 499 |
+
// signal during execution as opposed to failing to execute.
|
| 500 |
+
WaitResult.ReturnCode = -2;
|
| 501 |
+
}
|
| 502 |
+
return WaitResult;
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
std::error_code llvm::sys::ChangeStdinMode(fs::OpenFlags Flags) {
|
| 506 |
+
if (!(Flags & fs::OF_Text))
|
| 507 |
+
return ChangeStdinToBinary();
|
| 508 |
+
return std::error_code();
|
| 509 |
+
}
|
| 510 |
+
|
| 511 |
+
std::error_code llvm::sys::ChangeStdoutMode(fs::OpenFlags Flags) {
|
| 512 |
+
if (!(Flags & fs::OF_Text))
|
| 513 |
+
return ChangeStdoutToBinary();
|
| 514 |
+
return std::error_code();
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
+
std::error_code llvm::sys::ChangeStdinToBinary() {
|
| 518 |
+
#ifdef __MVS__
|
| 519 |
+
return disablezOSAutoConversion(STDIN_FILENO);
|
| 520 |
+
#else
|
| 521 |
+
// Do nothing, as Unix doesn't differentiate between text and binary.
|
| 522 |
+
return std::error_code();
|
| 523 |
+
#endif
|
| 524 |
+
}
|
| 525 |
+
|
| 526 |
+
std::error_code llvm::sys::ChangeStdoutToBinary() {
|
| 527 |
+
// Do nothing, as Unix doesn't differentiate between text and binary.
|
| 528 |
+
return std::error_code();
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
std::error_code
|
| 532 |
+
llvm::sys::writeFileWithEncoding(StringRef FileName, StringRef Contents,
|
| 533 |
+
WindowsEncodingMethod Encoding /*unused*/) {
|
| 534 |
+
std::error_code EC;
|
| 535 |
+
llvm::raw_fd_ostream OS(FileName, EC,
|
| 536 |
+
llvm::sys::fs::OpenFlags::OF_TextWithCRLF);
|
| 537 |
+
|
| 538 |
+
if (EC)
|
| 539 |
+
return EC;
|
| 540 |
+
|
| 541 |
+
OS << Contents;
|
| 542 |
+
|
| 543 |
+
if (OS.has_error())
|
| 544 |
+
return make_error_code(errc::io_error);
|
| 545 |
+
|
| 546 |
+
return EC;
|
| 547 |
+
}
|
| 548 |
+
|
| 549 |
+
bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program,
|
| 550 |
+
ArrayRef<StringRef> Args) {
|
| 551 |
+
static long ArgMax = sysconf(_SC_ARG_MAX);
|
| 552 |
+
// POSIX requires that _POSIX_ARG_MAX is 4096, which is the lowest possible
|
| 553 |
+
// value for ARG_MAX on a POSIX compliant system.
|
| 554 |
+
static long ArgMin = _POSIX_ARG_MAX;
|
| 555 |
+
|
| 556 |
+
// This the same baseline used by xargs.
|
| 557 |
+
long EffectiveArgMax = 128 * 1024;
|
| 558 |
+
|
| 559 |
+
if (EffectiveArgMax > ArgMax)
|
| 560 |
+
EffectiveArgMax = ArgMax;
|
| 561 |
+
else if (EffectiveArgMax < ArgMin)
|
| 562 |
+
EffectiveArgMax = ArgMin;
|
| 563 |
+
|
| 564 |
+
// System says no practical limit.
|
| 565 |
+
if (ArgMax == -1)
|
| 566 |
+
return true;
|
| 567 |
+
|
| 568 |
+
// Conservatively account for space required by environment variables.
|
| 569 |
+
long HalfArgMax = EffectiveArgMax / 2;
|
| 570 |
+
|
| 571 |
+
size_t ArgLength = Program.size() + 1;
|
| 572 |
+
for (StringRef Arg : Args) {
|
| 573 |
+
// Ensure that we do not exceed the MAX_ARG_STRLEN constant on Linux, which
|
| 574 |
+
// does not have a constant unlike what the man pages would have you
|
| 575 |
+
// believe. Since this limit is pretty high, perform the check
|
| 576 |
+
// unconditionally rather than trying to be aggressive and limiting it to
|
| 577 |
+
// Linux only.
|
| 578 |
+
if (Arg.size() >= (32 * 4096))
|
| 579 |
+
return false;
|
| 580 |
+
|
| 581 |
+
ArgLength += Arg.size() + 1;
|
| 582 |
+
if (ArgLength > size_t(HalfArgMax)) {
|
| 583 |
+
return false;
|
| 584 |
+
}
|
| 585 |
+
}
|
| 586 |
+
|
| 587 |
+
return true;
|
| 588 |
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- Signals.cpp - Generic Unix Signals Implementation -----*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file defines some helpful functions for dealing with the possibility of
|
| 10 |
+
// Unix signals occurring while your program is running.
|
| 11 |
+
//
|
| 12 |
+
//===----------------------------------------------------------------------===//
|
| 13 |
+
//
|
| 14 |
+
// This file is extremely careful to only do signal-safe things while in a
|
| 15 |
+
// signal handler. In particular, memory allocation and acquiring a mutex
|
| 16 |
+
// while in a signal handler should never occur. ManagedStatic isn't usable from
|
| 17 |
+
// a signal handler for 2 reasons:
|
| 18 |
+
//
|
| 19 |
+
// 1. Creating a new one allocates.
|
| 20 |
+
// 2. The signal handler could fire while llvm_shutdown is being processed, in
|
| 21 |
+
// which case the ManagedStatic is in an unknown state because it could
|
| 22 |
+
// already have been destroyed, or be in the process of being destroyed.
|
| 23 |
+
//
|
| 24 |
+
// Modifying the behavior of the signal handlers (such as registering new ones)
|
| 25 |
+
// can acquire a mutex, but all this guarantees is that the signal handler
|
| 26 |
+
// behavior is only modified by one thread at a time. A signal handler can still
|
| 27 |
+
// fire while this occurs!
|
| 28 |
+
//
|
| 29 |
+
// Adding work to a signal handler requires lock-freedom (and assume atomics are
|
| 30 |
+
// always lock-free) because the signal handler could fire while new work is
|
| 31 |
+
// being added.
|
| 32 |
+
//
|
| 33 |
+
//===----------------------------------------------------------------------===//
|
| 34 |
+
|
| 35 |
+
#include "Unix.h"
|
| 36 |
+
#include "llvm/ADT/STLExtras.h"
|
| 37 |
+
#include "llvm/Config/config.h"
|
| 38 |
+
#include "llvm/Demangle/Demangle.h"
|
| 39 |
+
#include "llvm/Support/ExitCodes.h"
|
| 40 |
+
#include "llvm/Support/FileSystem.h"
|
| 41 |
+
#include "llvm/Support/FileUtilities.h"
|
| 42 |
+
#include "llvm/Support/Format.h"
|
| 43 |
+
#include "llvm/Support/MemoryBuffer.h"
|
| 44 |
+
#include "llvm/Support/Mutex.h"
|
| 45 |
+
#include "llvm/Support/Program.h"
|
| 46 |
+
#include "llvm/Support/SaveAndRestore.h"
|
| 47 |
+
#include "llvm/Support/raw_ostream.h"
|
| 48 |
+
#include <algorithm>
|
| 49 |
+
#include <string>
|
| 50 |
+
#ifdef HAVE_BACKTRACE
|
| 51 |
+
#include BACKTRACE_HEADER // For backtrace().
|
| 52 |
+
#endif
|
| 53 |
+
#include <signal.h>
|
| 54 |
+
#include <sys/stat.h>
|
| 55 |
+
#include <dlfcn.h>
|
| 56 |
+
#if HAVE_MACH_MACH_H
|
| 57 |
+
#include <mach/mach.h>
|
| 58 |
+
#endif
|
| 59 |
+
#ifdef __APPLE__
|
| 60 |
+
#include <mach-o/dyld.h>
|
| 61 |
+
#endif
|
| 62 |
+
#if __has_include(<link.h>)
|
| 63 |
+
#include <link.h>
|
| 64 |
+
#endif
|
| 65 |
+
#ifdef HAVE__UNWIND_BACKTRACE
|
| 66 |
+
// FIXME: We should be able to use <unwind.h> for any target that has an
|
| 67 |
+
// _Unwind_Backtrace function, but on FreeBSD the configure test passes
|
| 68 |
+
// despite the function not existing, and on Android, <unwind.h> conflicts
|
| 69 |
+
// with <link.h>.
|
| 70 |
+
#ifdef __GLIBC__
|
| 71 |
+
#include <unwind.h>
|
| 72 |
+
#else
|
| 73 |
+
#undef HAVE__UNWIND_BACKTRACE
|
| 74 |
+
#endif
|
| 75 |
+
#endif
|
| 76 |
+
#if ENABLE_BACKTRACES && defined(__MVS__)
|
| 77 |
+
#include "llvm/Support/ConvertEBCDIC.h"
|
| 78 |
+
#include <__le_cwi.h>
|
| 79 |
+
#endif
|
| 80 |
+
|
| 81 |
+
using namespace llvm;
|
| 82 |
+
|
| 83 |
+
static void SignalHandler(int Sig, siginfo_t *Info, void *);
|
| 84 |
+
static void InfoSignalHandler(int Sig); // defined below.
|
| 85 |
+
|
| 86 |
+
using SignalHandlerFunctionType = void (*)();
|
| 87 |
+
/// The function to call if ctrl-c is pressed.
|
| 88 |
+
static std::atomic<SignalHandlerFunctionType> InterruptFunction = nullptr;
|
| 89 |
+
static std::atomic<SignalHandlerFunctionType> InfoSignalFunction = nullptr;
|
| 90 |
+
/// The function to call on SIGPIPE (one-time use only).
|
| 91 |
+
static std::atomic<SignalHandlerFunctionType> OneShotPipeSignalFunction =
|
| 92 |
+
nullptr;
|
| 93 |
+
|
| 94 |
+
namespace {
|
| 95 |
+
/// Signal-safe removal of files.
|
| 96 |
+
/// Inserting and erasing from the list isn't signal-safe, but removal of files
|
| 97 |
+
/// themselves is signal-safe. Memory is freed when the head is freed, deletion
|
| 98 |
+
/// is therefore not signal-safe either.
|
| 99 |
+
class FileToRemoveList {
|
| 100 |
+
std::atomic<char *> Filename = nullptr;
|
| 101 |
+
std::atomic<FileToRemoveList *> Next = nullptr;
|
| 102 |
+
|
| 103 |
+
FileToRemoveList() = default;
|
| 104 |
+
// Not signal-safe.
|
| 105 |
+
FileToRemoveList(const std::string &str) : Filename(strdup(str.c_str())) {}
|
| 106 |
+
|
| 107 |
+
public:
|
| 108 |
+
// Not signal-safe.
|
| 109 |
+
~FileToRemoveList() {
|
| 110 |
+
if (FileToRemoveList *N = Next.exchange(nullptr))
|
| 111 |
+
delete N;
|
| 112 |
+
if (char *F = Filename.exchange(nullptr))
|
| 113 |
+
free(F);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
// Not signal-safe.
|
| 117 |
+
static void insert(std::atomic<FileToRemoveList *> &Head,
|
| 118 |
+
const std::string &Filename) {
|
| 119 |
+
// Insert the new file at the end of the list.
|
| 120 |
+
FileToRemoveList *NewHead = new FileToRemoveList(Filename);
|
| 121 |
+
std::atomic<FileToRemoveList *> *InsertionPoint = &Head;
|
| 122 |
+
FileToRemoveList *OldHead = nullptr;
|
| 123 |
+
while (!InsertionPoint->compare_exchange_strong(OldHead, NewHead)) {
|
| 124 |
+
InsertionPoint = &OldHead->Next;
|
| 125 |
+
OldHead = nullptr;
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
// Not signal-safe.
|
| 130 |
+
static void erase(std::atomic<FileToRemoveList *> &Head,
|
| 131 |
+
const std::string &Filename) {
|
| 132 |
+
// Use a lock to avoid concurrent erase: the comparison would access
|
| 133 |
+
// free'd memory.
|
| 134 |
+
static ManagedStatic<sys::SmartMutex<true>> Lock;
|
| 135 |
+
sys::SmartScopedLock<true> Writer(*Lock);
|
| 136 |
+
|
| 137 |
+
for (FileToRemoveList *Current = Head.load(); Current;
|
| 138 |
+
Current = Current->Next.load()) {
|
| 139 |
+
if (char *OldFilename = Current->Filename.load()) {
|
| 140 |
+
if (OldFilename != Filename)
|
| 141 |
+
continue;
|
| 142 |
+
// Leave an empty filename.
|
| 143 |
+
OldFilename = Current->Filename.exchange(nullptr);
|
| 144 |
+
// The filename might have become null between the time we
|
| 145 |
+
// compared it and we exchanged it.
|
| 146 |
+
if (OldFilename)
|
| 147 |
+
free(OldFilename);
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
static void removeFile(char *path) {
|
| 153 |
+
// Get the status so we can determine if it's a file or directory. If we
|
| 154 |
+
// can't stat the file, ignore it.
|
| 155 |
+
struct stat buf;
|
| 156 |
+
if (stat(path, &buf) != 0)
|
| 157 |
+
return;
|
| 158 |
+
|
| 159 |
+
// If this is not a regular file, ignore it. We want to prevent removal
|
| 160 |
+
// of special files like /dev/null, even if the compiler is being run
|
| 161 |
+
// with the super-user permissions.
|
| 162 |
+
if (!S_ISREG(buf.st_mode))
|
| 163 |
+
return;
|
| 164 |
+
|
| 165 |
+
// Otherwise, remove the file. We ignore any errors here as there is
|
| 166 |
+
// nothing else we can do.
|
| 167 |
+
unlink(path);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
// Signal-safe.
|
| 171 |
+
static void removeAllFiles(std::atomic<FileToRemoveList *> &Head) {
|
| 172 |
+
// If cleanup were to occur while we're removing files we'd have a bad time.
|
| 173 |
+
// Make sure we're OK by preventing cleanup from doing anything while we're
|
| 174 |
+
// removing files. If cleanup races with us and we win we'll have a leak,
|
| 175 |
+
// but we won't crash.
|
| 176 |
+
FileToRemoveList *OldHead = Head.exchange(nullptr);
|
| 177 |
+
|
| 178 |
+
for (FileToRemoveList *currentFile = OldHead; currentFile;
|
| 179 |
+
currentFile = currentFile->Next.load()) {
|
| 180 |
+
// If erasing was occuring while we're trying to remove files we'd look
|
| 181 |
+
// at free'd data. Take away the path and put it back when done.
|
| 182 |
+
if (char *path = currentFile->Filename.exchange(nullptr)) {
|
| 183 |
+
removeFile(path);
|
| 184 |
+
|
| 185 |
+
// We're done removing the file, erasing can safely proceed.
|
| 186 |
+
currentFile->Filename.exchange(path);
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
// We're done removing files, cleanup can safely proceed.
|
| 191 |
+
Head.exchange(OldHead);
|
| 192 |
+
}
|
| 193 |
+
};
|
| 194 |
+
static std::atomic<FileToRemoveList *> FilesToRemove = nullptr;
|
| 195 |
+
|
| 196 |
+
/// Clean up the list in a signal-friendly manner.
|
| 197 |
+
/// Recall that signals can fire during llvm_shutdown. If this occurs we should
|
| 198 |
+
/// either clean something up or nothing at all, but we shouldn't crash!
|
| 199 |
+
struct FilesToRemoveCleanup {
|
| 200 |
+
// Not signal-safe.
|
| 201 |
+
~FilesToRemoveCleanup() {
|
| 202 |
+
FileToRemoveList *Head = FilesToRemove.exchange(nullptr);
|
| 203 |
+
if (Head)
|
| 204 |
+
delete Head;
|
| 205 |
+
}
|
| 206 |
+
};
|
| 207 |
+
} // namespace
|
| 208 |
+
|
| 209 |
+
static StringRef Argv0;
|
| 210 |
+
|
| 211 |
+
/// Signals that represent requested termination. There's no bug or failure, or
|
| 212 |
+
/// if there is, it's not our direct responsibility. For whatever reason, our
|
| 213 |
+
/// continued execution is no longer desirable.
|
| 214 |
+
static const int IntSigs[] = {SIGHUP, SIGINT, SIGTERM, SIGUSR2};
|
| 215 |
+
|
| 216 |
+
/// Signals that represent that we have a bug, and our prompt termination has
|
| 217 |
+
/// been ordered.
|
| 218 |
+
static const int KillSigs[] = {SIGILL,
|
| 219 |
+
SIGTRAP,
|
| 220 |
+
SIGABRT,
|
| 221 |
+
SIGFPE,
|
| 222 |
+
SIGBUS,
|
| 223 |
+
SIGSEGV,
|
| 224 |
+
SIGQUIT
|
| 225 |
+
#ifdef SIGSYS
|
| 226 |
+
,
|
| 227 |
+
SIGSYS
|
| 228 |
+
#endif
|
| 229 |
+
#ifdef SIGXCPU
|
| 230 |
+
,
|
| 231 |
+
SIGXCPU
|
| 232 |
+
#endif
|
| 233 |
+
#ifdef SIGXFSZ
|
| 234 |
+
,
|
| 235 |
+
SIGXFSZ
|
| 236 |
+
#endif
|
| 237 |
+
#ifdef SIGEMT
|
| 238 |
+
,
|
| 239 |
+
SIGEMT
|
| 240 |
+
#endif
|
| 241 |
+
};
|
| 242 |
+
|
| 243 |
+
/// Signals that represent requests for status.
|
| 244 |
+
static const int InfoSigs[] = {SIGUSR1
|
| 245 |
+
#ifdef SIGINFO
|
| 246 |
+
,
|
| 247 |
+
SIGINFO
|
| 248 |
+
#endif
|
| 249 |
+
};
|
| 250 |
+
|
| 251 |
+
static const size_t NumSigs = std::size(IntSigs) + std::size(KillSigs) +
|
| 252 |
+
std::size(InfoSigs) + 1 /* SIGPIPE */;
|
| 253 |
+
|
| 254 |
+
static std::atomic<unsigned> NumRegisteredSignals = 0;
|
| 255 |
+
static struct {
|
| 256 |
+
struct sigaction SA;
|
| 257 |
+
int SigNo;
|
| 258 |
+
} RegisteredSignalInfo[NumSigs];
|
| 259 |
+
|
| 260 |
+
#if defined(HAVE_SIGALTSTACK)
|
| 261 |
+
// Hold onto both the old and new alternate signal stack so that it's not
|
| 262 |
+
// reported as a leak. We don't make any attempt to remove our alt signal
|
| 263 |
+
// stack if we remove our signal handlers; that can't be done reliably if
|
| 264 |
+
// someone else is also trying to do the same thing.
|
| 265 |
+
static stack_t OldAltStack;
|
| 266 |
+
LLVM_ATTRIBUTE_USED static void *NewAltStackPointer;
|
| 267 |
+
|
| 268 |
+
static void CreateSigAltStack() {
|
| 269 |
+
const size_t AltStackSize = MINSIGSTKSZ + 64 * 1024;
|
| 270 |
+
|
| 271 |
+
// If we're executing on the alternate stack, or we already have an alternate
|
| 272 |
+
// signal stack that we're happy with, there's nothing for us to do. Don't
|
| 273 |
+
// reduce the size, some other part of the process might need a larger stack
|
| 274 |
+
// than we do.
|
| 275 |
+
if (sigaltstack(nullptr, &OldAltStack) != 0 ||
|
| 276 |
+
OldAltStack.ss_flags & SS_ONSTACK ||
|
| 277 |
+
(OldAltStack.ss_sp && OldAltStack.ss_size >= AltStackSize))
|
| 278 |
+
return;
|
| 279 |
+
|
| 280 |
+
stack_t AltStack = {};
|
| 281 |
+
AltStack.ss_sp = static_cast<char *>(safe_malloc(AltStackSize));
|
| 282 |
+
NewAltStackPointer = AltStack.ss_sp; // Save to avoid reporting a leak.
|
| 283 |
+
AltStack.ss_size = AltStackSize;
|
| 284 |
+
if (sigaltstack(&AltStack, &OldAltStack) != 0)
|
| 285 |
+
free(AltStack.ss_sp);
|
| 286 |
+
}
|
| 287 |
+
#else
|
| 288 |
+
static void CreateSigAltStack() {}
|
| 289 |
+
#endif
|
| 290 |
+
|
| 291 |
+
static void RegisterHandlers() { // Not signal-safe.
|
| 292 |
+
// The mutex prevents other threads from registering handlers while we're
|
| 293 |
+
// doing it. We also have to protect the handlers and their count because
|
| 294 |
+
// a signal handler could fire while we're registering handlers.
|
| 295 |
+
static ManagedStatic<sys::SmartMutex<true>> SignalHandlerRegistrationMutex;
|
| 296 |
+
sys::SmartScopedLock<true> Guard(*SignalHandlerRegistrationMutex);
|
| 297 |
+
|
| 298 |
+
// If the handlers are already registered, we're done.
|
| 299 |
+
if (NumRegisteredSignals.load() != 0)
|
| 300 |
+
return;
|
| 301 |
+
|
| 302 |
+
// Create an alternate stack for signal handling. This is necessary for us to
|
| 303 |
+
// be able to reliably handle signals due to stack overflow.
|
| 304 |
+
CreateSigAltStack();
|
| 305 |
+
|
| 306 |
+
enum class SignalKind { IsKill, IsInfo };
|
| 307 |
+
auto registerHandler = [&](int Signal, SignalKind Kind) {
|
| 308 |
+
unsigned Index = NumRegisteredSignals.load();
|
| 309 |
+
assert(Index < std::size(RegisteredSignalInfo) &&
|
| 310 |
+
"Out of space for signal handlers!");
|
| 311 |
+
|
| 312 |
+
struct sigaction NewHandler;
|
| 313 |
+
|
| 314 |
+
switch (Kind) {
|
| 315 |
+
case SignalKind::IsKill:
|
| 316 |
+
NewHandler.sa_sigaction = SignalHandler;
|
| 317 |
+
NewHandler.sa_flags = SA_NODEFER | SA_RESETHAND | SA_ONSTACK | SA_SIGINFO;
|
| 318 |
+
break;
|
| 319 |
+
case SignalKind::IsInfo:
|
| 320 |
+
NewHandler.sa_handler = InfoSignalHandler;
|
| 321 |
+
NewHandler.sa_flags = SA_ONSTACK;
|
| 322 |
+
break;
|
| 323 |
+
}
|
| 324 |
+
sigemptyset(&NewHandler.sa_mask);
|
| 325 |
+
|
| 326 |
+
// Install the new handler, save the old one in RegisteredSignalInfo.
|
| 327 |
+
sigaction(Signal, &NewHandler, &RegisteredSignalInfo[Index].SA);
|
| 328 |
+
RegisteredSignalInfo[Index].SigNo = Signal;
|
| 329 |
+
++NumRegisteredSignals;
|
| 330 |
+
};
|
| 331 |
+
|
| 332 |
+
for (auto S : IntSigs)
|
| 333 |
+
registerHandler(S, SignalKind::IsKill);
|
| 334 |
+
for (auto S : KillSigs)
|
| 335 |
+
registerHandler(S, SignalKind::IsKill);
|
| 336 |
+
if (OneShotPipeSignalFunction)
|
| 337 |
+
registerHandler(SIGPIPE, SignalKind::IsKill);
|
| 338 |
+
for (auto S : InfoSigs)
|
| 339 |
+
registerHandler(S, SignalKind::IsInfo);
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
void sys::unregisterHandlers() {
|
| 343 |
+
// Restore all of the signal handlers to how they were before we showed up.
|
| 344 |
+
for (unsigned i = 0, e = NumRegisteredSignals.load(); i != e; ++i) {
|
| 345 |
+
sigaction(RegisteredSignalInfo[i].SigNo, &RegisteredSignalInfo[i].SA,
|
| 346 |
+
nullptr);
|
| 347 |
+
--NumRegisteredSignals;
|
| 348 |
+
}
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
/// Process the FilesToRemove list.
|
| 352 |
+
static void RemoveFilesToRemove() {
|
| 353 |
+
FileToRemoveList::removeAllFiles(FilesToRemove);
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
void sys::CleanupOnSignal(uintptr_t Context) {
|
| 357 |
+
int Sig = (int)Context;
|
| 358 |
+
|
| 359 |
+
if (llvm::is_contained(InfoSigs, Sig)) {
|
| 360 |
+
InfoSignalHandler(Sig);
|
| 361 |
+
return;
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
RemoveFilesToRemove();
|
| 365 |
+
|
| 366 |
+
if (llvm::is_contained(IntSigs, Sig) || Sig == SIGPIPE)
|
| 367 |
+
return;
|
| 368 |
+
|
| 369 |
+
llvm::sys::RunSignalHandlers();
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
// The signal handler that runs.
|
| 373 |
+
static void SignalHandler(int Sig, siginfo_t *Info, void *) {
|
| 374 |
+
// Restore the signal behavior to default, so that the program actually
|
| 375 |
+
// crashes when we return and the signal reissues. This also ensures that if
|
| 376 |
+
// we crash in our signal handler that the program will terminate immediately
|
| 377 |
+
// instead of recursing in the signal handler.
|
| 378 |
+
sys::unregisterHandlers();
|
| 379 |
+
|
| 380 |
+
// Unmask all potentially blocked kill signals.
|
| 381 |
+
sigset_t SigMask;
|
| 382 |
+
sigfillset(&SigMask);
|
| 383 |
+
sigprocmask(SIG_UNBLOCK, &SigMask, nullptr);
|
| 384 |
+
|
| 385 |
+
{
|
| 386 |
+
RemoveFilesToRemove();
|
| 387 |
+
|
| 388 |
+
if (Sig == SIGPIPE)
|
| 389 |
+
if (auto OldOneShotPipeFunction =
|
| 390 |
+
OneShotPipeSignalFunction.exchange(nullptr))
|
| 391 |
+
return OldOneShotPipeFunction();
|
| 392 |
+
|
| 393 |
+
bool IsIntSig = llvm::is_contained(IntSigs, Sig);
|
| 394 |
+
if (IsIntSig)
|
| 395 |
+
if (auto OldInterruptFunction = InterruptFunction.exchange(nullptr))
|
| 396 |
+
return OldInterruptFunction();
|
| 397 |
+
|
| 398 |
+
if (Sig == SIGPIPE || IsIntSig) {
|
| 399 |
+
raise(Sig); // Execute the default handler.
|
| 400 |
+
return;
|
| 401 |
+
}
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
// Otherwise if it is a fault (like SEGV) run any handler.
|
| 405 |
+
llvm::sys::RunSignalHandlers();
|
| 406 |
+
|
| 407 |
+
#ifdef __s390__
|
| 408 |
+
// On S/390, certain signals are delivered with PSW Address pointing to
|
| 409 |
+
// *after* the faulting instruction. Simply returning from the signal
|
| 410 |
+
// handler would continue execution after that point, instead of
|
| 411 |
+
// re-raising the signal. Raise the signal manually in those cases.
|
| 412 |
+
if (Sig == SIGILL || Sig == SIGFPE || Sig == SIGTRAP)
|
| 413 |
+
raise(Sig);
|
| 414 |
+
#endif
|
| 415 |
+
|
| 416 |
+
// Signal sent from another process, do not assume that continuing the
|
| 417 |
+
// execution would re-raise it.
|
| 418 |
+
if (Info->si_pid != getpid())
|
| 419 |
+
raise(Sig);
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
static void InfoSignalHandler(int Sig) {
|
| 423 |
+
SaveAndRestore SaveErrnoDuringASignalHandler(errno);
|
| 424 |
+
if (SignalHandlerFunctionType CurrentInfoFunction = InfoSignalFunction)
|
| 425 |
+
CurrentInfoFunction();
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
void llvm::sys::RunInterruptHandlers() { RemoveFilesToRemove(); }
|
| 429 |
+
|
| 430 |
+
void llvm::sys::SetInterruptFunction(void (*IF)()) {
|
| 431 |
+
InterruptFunction.exchange(IF);
|
| 432 |
+
RegisterHandlers();
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
void llvm::sys::SetInfoSignalFunction(void (*Handler)()) {
|
| 436 |
+
InfoSignalFunction.exchange(Handler);
|
| 437 |
+
RegisterHandlers();
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
void llvm::sys::SetOneShotPipeSignalFunction(void (*Handler)()) {
|
| 441 |
+
OneShotPipeSignalFunction.exchange(Handler);
|
| 442 |
+
RegisterHandlers();
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
void llvm::sys::DefaultOneShotPipeSignalHandler() {
|
| 446 |
+
// Send a special return code that drivers can check for, from sysexits.h.
|
| 447 |
+
exit(EX_IOERR);
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
// The public API
|
| 451 |
+
bool llvm::sys::RemoveFileOnSignal(StringRef Filename, std::string *ErrMsg) {
|
| 452 |
+
// Ensure that cleanup will occur as soon as one file is added.
|
| 453 |
+
static ManagedStatic<FilesToRemoveCleanup> FilesToRemoveCleanup;
|
| 454 |
+
*FilesToRemoveCleanup;
|
| 455 |
+
FileToRemoveList::insert(FilesToRemove, Filename.str());
|
| 456 |
+
RegisterHandlers();
|
| 457 |
+
return false;
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
// The public API
|
| 461 |
+
void llvm::sys::DontRemoveFileOnSignal(StringRef Filename) {
|
| 462 |
+
FileToRemoveList::erase(FilesToRemove, Filename.str());
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
/// Add a function to be called when a signal is delivered to the process. The
|
| 466 |
+
/// handler can have a cookie passed to it to identify what instance of the
|
| 467 |
+
/// handler it is.
|
| 468 |
+
void llvm::sys::AddSignalHandler(sys::SignalHandlerCallback FnPtr,
|
| 469 |
+
void *Cookie) { // Signal-safe.
|
| 470 |
+
insertSignalHandler(FnPtr, Cookie);
|
| 471 |
+
RegisterHandlers();
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
#if ENABLE_BACKTRACES && defined(HAVE_BACKTRACE) && \
|
| 475 |
+
(defined(__linux__) || defined(__FreeBSD__) || \
|
| 476 |
+
defined(__FreeBSD_kernel__) || defined(__NetBSD__) || \
|
| 477 |
+
defined(__OpenBSD__) || defined(__DragonFly__))
|
| 478 |
+
struct DlIteratePhdrData {
|
| 479 |
+
void **StackTrace;
|
| 480 |
+
int depth;
|
| 481 |
+
bool first;
|
| 482 |
+
const char **modules;
|
| 483 |
+
intptr_t *offsets;
|
| 484 |
+
const char *main_exec_name;
|
| 485 |
+
};
|
| 486 |
+
|
| 487 |
+
static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) {
|
| 488 |
+
DlIteratePhdrData *data = (DlIteratePhdrData *)arg;
|
| 489 |
+
const char *name = data->first ? data->main_exec_name : info->dlpi_name;
|
| 490 |
+
data->first = false;
|
| 491 |
+
for (int i = 0; i < info->dlpi_phnum; i++) {
|
| 492 |
+
const auto *phdr = &info->dlpi_phdr[i];
|
| 493 |
+
if (phdr->p_type != PT_LOAD)
|
| 494 |
+
continue;
|
| 495 |
+
intptr_t beg = info->dlpi_addr + phdr->p_vaddr;
|
| 496 |
+
intptr_t end = beg + phdr->p_memsz;
|
| 497 |
+
for (int j = 0; j < data->depth; j++) {
|
| 498 |
+
if (data->modules[j])
|
| 499 |
+
continue;
|
| 500 |
+
intptr_t addr = (intptr_t)data->StackTrace[j];
|
| 501 |
+
if (beg <= addr && addr < end) {
|
| 502 |
+
data->modules[j] = name;
|
| 503 |
+
data->offsets[j] = addr - info->dlpi_addr;
|
| 504 |
+
}
|
| 505 |
+
}
|
| 506 |
+
}
|
| 507 |
+
return 0;
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
/// If this is an ELF platform, we can find all loaded modules and their virtual
|
| 511 |
+
/// addresses with dl_iterate_phdr.
|
| 512 |
+
static bool findModulesAndOffsets(void **StackTrace, int Depth,
|
| 513 |
+
const char **Modules, intptr_t *Offsets,
|
| 514 |
+
const char *MainExecutableName,
|
| 515 |
+
StringSaver &StrPool) {
|
| 516 |
+
DlIteratePhdrData data = {StackTrace, Depth, true,
|
| 517 |
+
Modules, Offsets, MainExecutableName};
|
| 518 |
+
dl_iterate_phdr(dl_iterate_phdr_cb, &data);
|
| 519 |
+
return true;
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
+
class DSOMarkupPrinter {
|
| 523 |
+
llvm::raw_ostream &OS;
|
| 524 |
+
const char *MainExecutableName;
|
| 525 |
+
size_t ModuleCount = 0;
|
| 526 |
+
bool IsFirst = true;
|
| 527 |
+
|
| 528 |
+
public:
|
| 529 |
+
DSOMarkupPrinter(llvm::raw_ostream &OS, const char *MainExecutableName)
|
| 530 |
+
: OS(OS), MainExecutableName(MainExecutableName) {}
|
| 531 |
+
|
| 532 |
+
/// Print llvm-symbolizer markup describing the layout of the given DSO.
|
| 533 |
+
void printDSOMarkup(dl_phdr_info *Info) {
|
| 534 |
+
ArrayRef<uint8_t> BuildID = findBuildID(Info);
|
| 535 |
+
if (BuildID.empty())
|
| 536 |
+
return;
|
| 537 |
+
OS << format("{{{module:%d:%s:elf:", ModuleCount,
|
| 538 |
+
IsFirst ? MainExecutableName : Info->dlpi_name);
|
| 539 |
+
for (uint8_t X : BuildID)
|
| 540 |
+
OS << format("%02x", X);
|
| 541 |
+
OS << "}}}\n";
|
| 542 |
+
|
| 543 |
+
for (int I = 0; I < Info->dlpi_phnum; I++) {
|
| 544 |
+
const auto *Phdr = &Info->dlpi_phdr[I];
|
| 545 |
+
if (Phdr->p_type != PT_LOAD)
|
| 546 |
+
continue;
|
| 547 |
+
uintptr_t StartAddress = Info->dlpi_addr + Phdr->p_vaddr;
|
| 548 |
+
uintptr_t ModuleRelativeAddress = Phdr->p_vaddr;
|
| 549 |
+
std::array<char, 4> ModeStr = modeStrFromFlags(Phdr->p_flags);
|
| 550 |
+
OS << format("{{{mmap:%#016x:%#x:load:%d:%s:%#016x}}}\n", StartAddress,
|
| 551 |
+
Phdr->p_memsz, ModuleCount, &ModeStr[0],
|
| 552 |
+
ModuleRelativeAddress);
|
| 553 |
+
}
|
| 554 |
+
IsFirst = false;
|
| 555 |
+
ModuleCount++;
|
| 556 |
+
}
|
| 557 |
+
|
| 558 |
+
/// Callback for use with dl_iterate_phdr. The last dl_iterate_phdr argument
|
| 559 |
+
/// must be a pointer to an instance of this class.
|
| 560 |
+
static int printDSOMarkup(dl_phdr_info *Info, size_t Size, void *Arg) {
|
| 561 |
+
static_cast<DSOMarkupPrinter *>(Arg)->printDSOMarkup(Info);
|
| 562 |
+
return 0;
|
| 563 |
+
}
|
| 564 |
+
|
| 565 |
+
// Returns the build ID for the given DSO as an array of bytes. Returns an
|
| 566 |
+
// empty array if none could be found.
|
| 567 |
+
ArrayRef<uint8_t> findBuildID(dl_phdr_info *Info) {
|
| 568 |
+
for (int I = 0; I < Info->dlpi_phnum; I++) {
|
| 569 |
+
const auto *Phdr = &Info->dlpi_phdr[I];
|
| 570 |
+
if (Phdr->p_type != PT_NOTE)
|
| 571 |
+
continue;
|
| 572 |
+
|
| 573 |
+
ArrayRef<uint8_t> Notes(
|
| 574 |
+
reinterpret_cast<const uint8_t *>(Info->dlpi_addr + Phdr->p_vaddr),
|
| 575 |
+
Phdr->p_memsz);
|
| 576 |
+
while (Notes.size() > 12) {
|
| 577 |
+
uint32_t NameSize = *reinterpret_cast<const uint32_t *>(Notes.data());
|
| 578 |
+
Notes = Notes.drop_front(4);
|
| 579 |
+
uint32_t DescSize = *reinterpret_cast<const uint32_t *>(Notes.data());
|
| 580 |
+
Notes = Notes.drop_front(4);
|
| 581 |
+
uint32_t Type = *reinterpret_cast<const uint32_t *>(Notes.data());
|
| 582 |
+
Notes = Notes.drop_front(4);
|
| 583 |
+
|
| 584 |
+
ArrayRef<uint8_t> Name = Notes.take_front(NameSize);
|
| 585 |
+
auto CurPos = reinterpret_cast<uintptr_t>(Notes.data());
|
| 586 |
+
uint32_t BytesUntilDesc =
|
| 587 |
+
alignToPowerOf2(CurPos + NameSize, 4) - CurPos;
|
| 588 |
+
if (BytesUntilDesc >= Notes.size())
|
| 589 |
+
break;
|
| 590 |
+
Notes = Notes.drop_front(BytesUntilDesc);
|
| 591 |
+
|
| 592 |
+
ArrayRef<uint8_t> Desc = Notes.take_front(DescSize);
|
| 593 |
+
CurPos = reinterpret_cast<uintptr_t>(Notes.data());
|
| 594 |
+
uint32_t BytesUntilNextNote =
|
| 595 |
+
alignToPowerOf2(CurPos + DescSize, 4) - CurPos;
|
| 596 |
+
if (BytesUntilNextNote > Notes.size())
|
| 597 |
+
break;
|
| 598 |
+
Notes = Notes.drop_front(BytesUntilNextNote);
|
| 599 |
+
|
| 600 |
+
if (Type == 3 /*NT_GNU_BUILD_ID*/ && Name.size() >= 3 &&
|
| 601 |
+
Name[0] == 'G' && Name[1] == 'N' && Name[2] == 'U')
|
| 602 |
+
return Desc;
|
| 603 |
+
}
|
| 604 |
+
}
|
| 605 |
+
return {};
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
// Returns a symbolizer markup string describing the permissions on a DSO
|
| 609 |
+
// with the given p_flags.
|
| 610 |
+
std::array<char, 4> modeStrFromFlags(uint32_t Flags) {
|
| 611 |
+
std::array<char, 4> Mode;
|
| 612 |
+
char *Cur = &Mode[0];
|
| 613 |
+
if (Flags & PF_R)
|
| 614 |
+
*Cur++ = 'r';
|
| 615 |
+
if (Flags & PF_W)
|
| 616 |
+
*Cur++ = 'w';
|
| 617 |
+
if (Flags & PF_X)
|
| 618 |
+
*Cur++ = 'x';
|
| 619 |
+
*Cur = '\0';
|
| 620 |
+
return Mode;
|
| 621 |
+
}
|
| 622 |
+
};
|
| 623 |
+
|
| 624 |
+
static bool printMarkupContext(llvm::raw_ostream &OS,
|
| 625 |
+
const char *MainExecutableName) {
|
| 626 |
+
OS << "{{{reset}}}\n";
|
| 627 |
+
DSOMarkupPrinter MP(OS, MainExecutableName);
|
| 628 |
+
dl_iterate_phdr(DSOMarkupPrinter::printDSOMarkup, &MP);
|
| 629 |
+
return true;
|
| 630 |
+
}
|
| 631 |
+
|
| 632 |
+
#elif ENABLE_BACKTRACES && defined(__APPLE__) && defined(__LP64__)
|
| 633 |
+
static bool findModulesAndOffsets(void **StackTrace, int Depth,
|
| 634 |
+
const char **Modules, intptr_t *Offsets,
|
| 635 |
+
const char *MainExecutableName,
|
| 636 |
+
StringSaver &StrPool) {
|
| 637 |
+
uint32_t NumImgs = _dyld_image_count();
|
| 638 |
+
for (uint32_t ImageIndex = 0; ImageIndex < NumImgs; ImageIndex++) {
|
| 639 |
+
const char *Name = _dyld_get_image_name(ImageIndex);
|
| 640 |
+
intptr_t Slide = _dyld_get_image_vmaddr_slide(ImageIndex);
|
| 641 |
+
auto *Header =
|
| 642 |
+
(const struct mach_header_64 *)_dyld_get_image_header(ImageIndex);
|
| 643 |
+
if (Header == NULL)
|
| 644 |
+
continue;
|
| 645 |
+
auto Cmd = (const struct load_command *)(&Header[1]);
|
| 646 |
+
for (uint32_t CmdNum = 0; CmdNum < Header->ncmds; ++CmdNum) {
|
| 647 |
+
uint32_t BaseCmd = Cmd->cmd & ~LC_REQ_DYLD;
|
| 648 |
+
if (BaseCmd == LC_SEGMENT_64) {
|
| 649 |
+
auto CmdSeg64 = (const struct segment_command_64 *)Cmd;
|
| 650 |
+
for (int j = 0; j < Depth; j++) {
|
| 651 |
+
if (Modules[j])
|
| 652 |
+
continue;
|
| 653 |
+
intptr_t Addr = (intptr_t)StackTrace[j];
|
| 654 |
+
if ((intptr_t)CmdSeg64->vmaddr + Slide <= Addr &&
|
| 655 |
+
Addr < intptr_t(CmdSeg64->vmaddr + CmdSeg64->vmsize + Slide)) {
|
| 656 |
+
Modules[j] = Name;
|
| 657 |
+
Offsets[j] = Addr - Slide;
|
| 658 |
+
}
|
| 659 |
+
}
|
| 660 |
+
}
|
| 661 |
+
Cmd = (const load_command *)(((const char *)Cmd) + (Cmd->cmdsize));
|
| 662 |
+
}
|
| 663 |
+
}
|
| 664 |
+
return true;
|
| 665 |
+
}
|
| 666 |
+
|
| 667 |
+
static bool printMarkupContext(llvm::raw_ostream &OS,
|
| 668 |
+
const char *MainExecutableName) {
|
| 669 |
+
return false;
|
| 670 |
+
}
|
| 671 |
+
#else
|
| 672 |
+
/// Backtraces are not enabled or we don't yet know how to find all loaded DSOs
|
| 673 |
+
/// on this platform.
|
| 674 |
+
static bool findModulesAndOffsets(void **StackTrace, int Depth,
|
| 675 |
+
const char **Modules, intptr_t *Offsets,
|
| 676 |
+
const char *MainExecutableName,
|
| 677 |
+
StringSaver &StrPool) {
|
| 678 |
+
return false;
|
| 679 |
+
}
|
| 680 |
+
|
| 681 |
+
static bool printMarkupContext(llvm::raw_ostream &OS,
|
| 682 |
+
const char *MainExecutableName) {
|
| 683 |
+
return false;
|
| 684 |
+
}
|
| 685 |
+
#endif // ENABLE_BACKTRACES && ... (findModulesAndOffsets variants)
|
| 686 |
+
|
| 687 |
+
#if ENABLE_BACKTRACES && defined(HAVE__UNWIND_BACKTRACE)
|
| 688 |
+
static int unwindBacktrace(void **StackTrace, int MaxEntries) {
|
| 689 |
+
if (MaxEntries < 0)
|
| 690 |
+
return 0;
|
| 691 |
+
|
| 692 |
+
// Skip the first frame ('unwindBacktrace' itself).
|
| 693 |
+
int Entries = -1;
|
| 694 |
+
|
| 695 |
+
auto HandleFrame = [&](_Unwind_Context *Context) -> _Unwind_Reason_Code {
|
| 696 |
+
// Apparently we need to detect reaching the end of the stack ourselves.
|
| 697 |
+
void *IP = (void *)_Unwind_GetIP(Context);
|
| 698 |
+
if (!IP)
|
| 699 |
+
return _URC_END_OF_STACK;
|
| 700 |
+
|
| 701 |
+
assert(Entries < MaxEntries && "recursively called after END_OF_STACK?");
|
| 702 |
+
if (Entries >= 0)
|
| 703 |
+
StackTrace[Entries] = IP;
|
| 704 |
+
|
| 705 |
+
if (++Entries == MaxEntries)
|
| 706 |
+
return _URC_END_OF_STACK;
|
| 707 |
+
return _URC_NO_REASON;
|
| 708 |
+
};
|
| 709 |
+
|
| 710 |
+
_Unwind_Backtrace(
|
| 711 |
+
[](_Unwind_Context *Context, void *Handler) {
|
| 712 |
+
return (*static_cast<decltype(HandleFrame) *>(Handler))(Context);
|
| 713 |
+
},
|
| 714 |
+
static_cast<void *>(&HandleFrame));
|
| 715 |
+
return std::max(Entries, 0);
|
| 716 |
+
}
|
| 717 |
+
#endif
|
| 718 |
+
|
| 719 |
+
#if ENABLE_BACKTRACES && defined(__MVS__)
|
| 720 |
+
static void zosbacktrace(raw_ostream &OS) {
|
| 721 |
+
// A function name in the PPA1 can have length 16k.
|
| 722 |
+
constexpr size_t MAX_ENTRY_NAME = UINT16_MAX;
|
| 723 |
+
// Limit all other strings to 8 byte.
|
| 724 |
+
constexpr size_t MAX_OTHER = 8;
|
| 725 |
+
int32_t dsa_format = -1; // Input/Output
|
| 726 |
+
void *caaptr = _gtca(); // Input
|
| 727 |
+
int32_t member_id; // Output
|
| 728 |
+
char compile_unit_name[MAX_OTHER]; // Output
|
| 729 |
+
void *compile_unit_address; // Output
|
| 730 |
+
void *call_instruction_address = nullptr; // Input/Output
|
| 731 |
+
char entry_name[MAX_ENTRY_NAME]; // Output
|
| 732 |
+
void *entry_address; // Output
|
| 733 |
+
void *callers_instruction_address; // Output
|
| 734 |
+
void *callers_dsaptr; // Output
|
| 735 |
+
int32_t callers_dsa_format; // Output
|
| 736 |
+
char statement_id[MAX_OTHER]; // Output
|
| 737 |
+
void *cibptr; // Output
|
| 738 |
+
int32_t main_program; // Output
|
| 739 |
+
_FEEDBACK fc; // Output
|
| 740 |
+
|
| 741 |
+
// The DSA pointer is the value of the stack pointer r4.
|
| 742 |
+
// __builtin_frame_address() returns a pointer to the stack frame, so the
|
| 743 |
+
// stack bias has to be considered to get the expected DSA value.
|
| 744 |
+
void *dsaptr = static_cast<char *>(__builtin_frame_address(0)) - 2048;
|
| 745 |
+
int count = 0;
|
| 746 |
+
OS << " DSA Adr EP +EP DSA "
|
| 747 |
+
" Entry\n";
|
| 748 |
+
while (1) {
|
| 749 |
+
// After the call, these variables contain the length of the string.
|
| 750 |
+
int32_t compile_unit_name_length = sizeof(compile_unit_name);
|
| 751 |
+
int32_t entry_name_length = sizeof(entry_name);
|
| 752 |
+
int32_t statement_id_length = sizeof(statement_id);
|
| 753 |
+
// See
|
| 754 |
+
// https://www.ibm.com/docs/en/zos/3.1.0?topic=cwicsa6a-celqtbck-also-known-as-celqtbck-64-bit-traceback-service
|
| 755 |
+
// for documentation of the parameters.
|
| 756 |
+
__CELQTBCK(&dsaptr, &dsa_format, &caaptr, &member_id, &compile_unit_name[0],
|
| 757 |
+
&compile_unit_name_length, &compile_unit_address,
|
| 758 |
+
&call_instruction_address, &entry_name[0], &entry_name_length,
|
| 759 |
+
&entry_address, &callers_instruction_address, &callers_dsaptr,
|
| 760 |
+
&callers_dsa_format, &statement_id[0], &statement_id_length,
|
| 761 |
+
&cibptr, &main_program, &fc);
|
| 762 |
+
if (fc.tok_sev) {
|
| 763 |
+
OS << format("error: CELQTBCK returned severity %d message %d\n",
|
| 764 |
+
fc.tok_sev, fc.tok_msgno);
|
| 765 |
+
break;
|
| 766 |
+
}
|
| 767 |
+
|
| 768 |
+
if (count) { // Omit first entry.
|
| 769 |
+
uintptr_t diff = reinterpret_cast<uintptr_t>(call_instruction_address) -
|
| 770 |
+
reinterpret_cast<uintptr_t>(entry_address);
|
| 771 |
+
OS << format(" %3d. 0x%016lX", count, call_instruction_address);
|
| 772 |
+
OS << format(" 0x%016lX +0x%08lX 0x%016lX", entry_address, diff, dsaptr);
|
| 773 |
+
SmallString<256> Str;
|
| 774 |
+
ConverterEBCDIC::convertToUTF8(StringRef(entry_name, entry_name_length),
|
| 775 |
+
Str);
|
| 776 |
+
OS << ' ' << Str << '\n';
|
| 777 |
+
}
|
| 778 |
+
++count;
|
| 779 |
+
if (callers_dsaptr) {
|
| 780 |
+
dsaptr = callers_dsaptr;
|
| 781 |
+
dsa_format = callers_dsa_format;
|
| 782 |
+
call_instruction_address = callers_instruction_address;
|
| 783 |
+
} else
|
| 784 |
+
break;
|
| 785 |
+
}
|
| 786 |
+
}
|
| 787 |
+
#endif
|
| 788 |
+
|
| 789 |
+
// In the case of a program crash or fault, print out a stack trace so that the
|
| 790 |
+
// user has an indication of why and where we died.
|
| 791 |
+
//
|
| 792 |
+
// On glibc systems we have the 'backtrace' function, which works nicely, but
|
| 793 |
+
// doesn't demangle symbols.
|
| 794 |
+
void llvm::sys::PrintStackTrace(raw_ostream &OS, int Depth) {
|
| 795 |
+
#if ENABLE_BACKTRACES
|
| 796 |
+
#ifdef __MVS__
|
| 797 |
+
zosbacktrace(OS);
|
| 798 |
+
#else
|
| 799 |
+
static void *StackTrace[256];
|
| 800 |
+
int depth = 0;
|
| 801 |
+
#if defined(HAVE_BACKTRACE)
|
| 802 |
+
// Use backtrace() to output a backtrace on Linux systems with glibc.
|
| 803 |
+
if (!depth)
|
| 804 |
+
depth = backtrace(StackTrace, static_cast<int>(std::size(StackTrace)));
|
| 805 |
+
#endif
|
| 806 |
+
#if defined(HAVE__UNWIND_BACKTRACE)
|
| 807 |
+
// Try _Unwind_Backtrace() if backtrace() failed.
|
| 808 |
+
if (!depth)
|
| 809 |
+
depth =
|
| 810 |
+
unwindBacktrace(StackTrace, static_cast<int>(std::size(StackTrace)));
|
| 811 |
+
#endif
|
| 812 |
+
if (!depth)
|
| 813 |
+
return;
|
| 814 |
+
// If "Depth" is not provided by the caller, use the return value of
|
| 815 |
+
// backtrace() for printing a symbolized stack trace.
|
| 816 |
+
if (!Depth)
|
| 817 |
+
Depth = depth;
|
| 818 |
+
if (printMarkupStackTrace(Argv0, StackTrace, Depth, OS))
|
| 819 |
+
return;
|
| 820 |
+
if (printSymbolizedStackTrace(Argv0, StackTrace, Depth, OS))
|
| 821 |
+
return;
|
| 822 |
+
OS << "Stack dump without symbol names (ensure you have llvm-symbolizer in "
|
| 823 |
+
"your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point "
|
| 824 |
+
"to it):\n";
|
| 825 |
+
#if HAVE_DLOPEN && !defined(_AIX)
|
| 826 |
+
int width = 0;
|
| 827 |
+
for (int i = 0; i < depth; ++i) {
|
| 828 |
+
Dl_info dlinfo;
|
| 829 |
+
int nwidth;
|
| 830 |
+
if (dladdr(StackTrace[i], &dlinfo) == 0) {
|
| 831 |
+
nwidth = 7; // "(error)"
|
| 832 |
+
} else {
|
| 833 |
+
const char *name = strrchr(dlinfo.dli_fname, '/');
|
| 834 |
+
|
| 835 |
+
if (!name)
|
| 836 |
+
nwidth = strlen(dlinfo.dli_fname);
|
| 837 |
+
else
|
| 838 |
+
nwidth = strlen(name) - 1;
|
| 839 |
+
}
|
| 840 |
+
|
| 841 |
+
if (nwidth > width)
|
| 842 |
+
width = nwidth;
|
| 843 |
+
}
|
| 844 |
+
|
| 845 |
+
for (int i = 0; i < depth; ++i) {
|
| 846 |
+
Dl_info dlinfo;
|
| 847 |
+
|
| 848 |
+
OS << format("%-2d", i);
|
| 849 |
+
|
| 850 |
+
if (dladdr(StackTrace[i], &dlinfo) == 0) {
|
| 851 |
+
OS << format(" %-*s", width, static_cast<const char *>("(error)"));
|
| 852 |
+
dlinfo.dli_sname = nullptr;
|
| 853 |
+
} else {
|
| 854 |
+
const char *name = strrchr(dlinfo.dli_fname, '/');
|
| 855 |
+
if (!name)
|
| 856 |
+
OS << format(" %-*s", width,
|
| 857 |
+
static_cast<const char *>(dlinfo.dli_fname));
|
| 858 |
+
else
|
| 859 |
+
OS << format(" %-*s", width, name + 1);
|
| 860 |
+
}
|
| 861 |
+
|
| 862 |
+
OS << format(" %#0*lx", (int)(sizeof(void *) * 2) + 2,
|
| 863 |
+
(unsigned long)StackTrace[i]);
|
| 864 |
+
|
| 865 |
+
if (dlinfo.dli_sname != nullptr) {
|
| 866 |
+
OS << ' ';
|
| 867 |
+
if (char *d = itaniumDemangle(dlinfo.dli_sname)) {
|
| 868 |
+
OS << d;
|
| 869 |
+
free(d);
|
| 870 |
+
} else {
|
| 871 |
+
OS << dlinfo.dli_sname;
|
| 872 |
+
}
|
| 873 |
+
|
| 874 |
+
OS << format(" + %tu", (static_cast<const char *>(StackTrace[i]) -
|
| 875 |
+
static_cast<const char *>(dlinfo.dli_saddr)));
|
| 876 |
+
}
|
| 877 |
+
OS << '\n';
|
| 878 |
+
}
|
| 879 |
+
#elif defined(HAVE_BACKTRACE)
|
| 880 |
+
backtrace_symbols_fd(StackTrace, Depth, STDERR_FILENO);
|
| 881 |
+
#endif
|
| 882 |
+
#endif
|
| 883 |
+
#endif
|
| 884 |
+
}
|
| 885 |
+
|
| 886 |
+
static void PrintStackTraceSignalHandler(void *) {
|
| 887 |
+
sys::PrintStackTrace(llvm::errs());
|
| 888 |
+
}
|
| 889 |
+
|
| 890 |
+
void llvm::sys::DisableSystemDialogsOnCrash() {}
|
| 891 |
+
|
| 892 |
+
/// When an error signal (such as SIGABRT or SIGSEGV) is delivered to the
|
| 893 |
+
/// process, print a stack trace and then exit.
|
| 894 |
+
void llvm::sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
|
| 895 |
+
bool DisableCrashReporting) {
|
| 896 |
+
::Argv0 = Argv0;
|
| 897 |
+
|
| 898 |
+
AddSignalHandler(PrintStackTraceSignalHandler, nullptr);
|
| 899 |
+
|
| 900 |
+
#if defined(__APPLE__) && ENABLE_CRASH_OVERRIDES
|
| 901 |
+
// Environment variable to disable any kind of crash dialog.
|
| 902 |
+
if (DisableCrashReporting || getenv("LLVM_DISABLE_CRASH_REPORT")) {
|
| 903 |
+
mach_port_t self = mach_task_self();
|
| 904 |
+
|
| 905 |
+
exception_mask_t mask = EXC_MASK_CRASH;
|
| 906 |
+
|
| 907 |
+
kern_return_t ret = task_set_exception_ports(
|
| 908 |
+
self, mask, MACH_PORT_NULL,
|
| 909 |
+
EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, THREAD_STATE_NONE);
|
| 910 |
+
(void)ret;
|
| 911 |
+
}
|
| 912 |
+
#endif
|
| 913 |
+
}
|
deps/exla/cache/xla_extension/include/llvm/lib/Support/Unix/Threading.inc
ADDED
|
@@ -0,0 +1,458 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- Unix/Threading.inc - Unix Threading Implementation ----- -*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file provides the Unix specific implementation of Threading functions.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#include "Unix.h"
|
| 14 |
+
#include "llvm/ADT/ScopeExit.h"
|
| 15 |
+
#include "llvm/ADT/SmallString.h"
|
| 16 |
+
#include "llvm/ADT/SmallVector.h"
|
| 17 |
+
#include "llvm/ADT/StringRef.h"
|
| 18 |
+
#include "llvm/ADT/Twine.h"
|
| 19 |
+
#include "llvm/Support/MemoryBuffer.h"
|
| 20 |
+
#include "llvm/Support/raw_ostream.h"
|
| 21 |
+
|
| 22 |
+
#if defined(__APPLE__)
|
| 23 |
+
#include <mach/mach_init.h>
|
| 24 |
+
#include <mach/mach_port.h>
|
| 25 |
+
#include <pthread/qos.h>
|
| 26 |
+
#include <sys/sysctl.h>
|
| 27 |
+
#include <sys/types.h>
|
| 28 |
+
#endif
|
| 29 |
+
|
| 30 |
+
#include <pthread.h>
|
| 31 |
+
|
| 32 |
+
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
|
| 33 |
+
#include <pthread_np.h> // For pthread_getthreadid_np() / pthread_set_name_np()
|
| 34 |
+
#endif
|
| 35 |
+
|
| 36 |
+
// Must be included after Threading.inc to provide definition for llvm::thread
|
| 37 |
+
// because FreeBSD's condvar.h (included by user.h) misuses the "thread"
|
| 38 |
+
// keyword.
|
| 39 |
+
#ifndef __FreeBSD__
|
| 40 |
+
#include "llvm/Support/thread.h"
|
| 41 |
+
#endif
|
| 42 |
+
|
| 43 |
+
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
| 44 |
+
#include <errno.h>
|
| 45 |
+
#include <sys/cpuset.h>
|
| 46 |
+
#include <sys/sysctl.h>
|
| 47 |
+
#include <sys/user.h>
|
| 48 |
+
#include <unistd.h>
|
| 49 |
+
#endif
|
| 50 |
+
|
| 51 |
+
#if defined(__NetBSD__)
|
| 52 |
+
#include <lwp.h> // For _lwp_self()
|
| 53 |
+
#endif
|
| 54 |
+
|
| 55 |
+
#if defined(__OpenBSD__)
|
| 56 |
+
#include <unistd.h> // For getthrid()
|
| 57 |
+
#endif
|
| 58 |
+
|
| 59 |
+
#if defined(__linux__)
|
| 60 |
+
#include <sched.h> // For sched_getaffinity
|
| 61 |
+
#include <sys/syscall.h> // For syscall codes
|
| 62 |
+
#include <unistd.h> // For syscall()
|
| 63 |
+
#endif
|
| 64 |
+
|
| 65 |
+
#if defined(__HAIKU__)
|
| 66 |
+
#include <OS.h> // For B_OS_NAME_LENGTH
|
| 67 |
+
#endif
|
| 68 |
+
|
| 69 |
+
namespace llvm {
|
| 70 |
+
pthread_t
|
| 71 |
+
llvm_execute_on_thread_impl(void *(*ThreadFunc)(void *), void *Arg,
|
| 72 |
+
std::optional<unsigned> StackSizeInBytes) {
|
| 73 |
+
int errnum;
|
| 74 |
+
|
| 75 |
+
// Construct the attributes object.
|
| 76 |
+
pthread_attr_t Attr;
|
| 77 |
+
if ((errnum = ::pthread_attr_init(&Attr)) != 0) {
|
| 78 |
+
ReportErrnumFatal("pthread_attr_init failed", errnum);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
auto AttrGuard = llvm::make_scope_exit([&] {
|
| 82 |
+
if ((errnum = ::pthread_attr_destroy(&Attr)) != 0) {
|
| 83 |
+
ReportErrnumFatal("pthread_attr_destroy failed", errnum);
|
| 84 |
+
}
|
| 85 |
+
});
|
| 86 |
+
|
| 87 |
+
// Set the requested stack size, if given.
|
| 88 |
+
if (StackSizeInBytes) {
|
| 89 |
+
if ((errnum = ::pthread_attr_setstacksize(&Attr, *StackSizeInBytes)) != 0) {
|
| 90 |
+
ReportErrnumFatal("pthread_attr_setstacksize failed", errnum);
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
// Construct and execute the thread.
|
| 95 |
+
pthread_t Thread;
|
| 96 |
+
if ((errnum = ::pthread_create(&Thread, &Attr, ThreadFunc, Arg)) != 0)
|
| 97 |
+
ReportErrnumFatal("pthread_create failed", errnum);
|
| 98 |
+
|
| 99 |
+
return Thread;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
void llvm_thread_detach_impl(pthread_t Thread) {
|
| 103 |
+
int errnum;
|
| 104 |
+
|
| 105 |
+
if ((errnum = ::pthread_detach(Thread)) != 0) {
|
| 106 |
+
ReportErrnumFatal("pthread_detach failed", errnum);
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
void llvm_thread_join_impl(pthread_t Thread) {
|
| 111 |
+
int errnum;
|
| 112 |
+
|
| 113 |
+
if ((errnum = ::pthread_join(Thread, nullptr)) != 0) {
|
| 114 |
+
ReportErrnumFatal("pthread_join failed", errnum);
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
pthread_t llvm_thread_get_id_impl(pthread_t Thread) { return Thread; }
|
| 119 |
+
|
| 120 |
+
pthread_t llvm_thread_get_current_id_impl() { return ::pthread_self(); }
|
| 121 |
+
|
| 122 |
+
} // namespace llvm
|
| 123 |
+
|
| 124 |
+
uint64_t llvm::get_threadid() {
|
| 125 |
+
#if defined(__APPLE__)
|
| 126 |
+
// Calling "mach_thread_self()" bumps the reference count on the thread
|
| 127 |
+
// port, so we need to deallocate it. mach_task_self() doesn't bump the ref
|
| 128 |
+
// count.
|
| 129 |
+
static thread_local thread_port_t Self = [] {
|
| 130 |
+
thread_port_t InitSelf = mach_thread_self();
|
| 131 |
+
mach_port_deallocate(mach_task_self(), Self);
|
| 132 |
+
return InitSelf;
|
| 133 |
+
}();
|
| 134 |
+
return Self;
|
| 135 |
+
#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
| 136 |
+
return uint64_t(pthread_getthreadid_np());
|
| 137 |
+
#elif defined(__NetBSD__)
|
| 138 |
+
return uint64_t(_lwp_self());
|
| 139 |
+
#elif defined(__OpenBSD__)
|
| 140 |
+
return uint64_t(getthrid());
|
| 141 |
+
#elif defined(__ANDROID__)
|
| 142 |
+
return uint64_t(gettid());
|
| 143 |
+
#elif defined(__linux__)
|
| 144 |
+
return uint64_t(syscall(__NR_gettid));
|
| 145 |
+
#elif defined(_AIX)
|
| 146 |
+
return uint64_t(thread_self());
|
| 147 |
+
#else
|
| 148 |
+
return uint64_t(pthread_self());
|
| 149 |
+
#endif
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
static constexpr uint32_t get_max_thread_name_length_impl() {
|
| 153 |
+
#if defined(PTHREAD_MAX_NAMELEN_NP)
|
| 154 |
+
return PTHREAD_MAX_NAMELEN_NP;
|
| 155 |
+
#elif defined(__HAIKU__)
|
| 156 |
+
return B_OS_NAME_LENGTH;
|
| 157 |
+
#elif defined(__APPLE__)
|
| 158 |
+
return 64;
|
| 159 |
+
#elif defined(__sun__) && defined(__svr4__)
|
| 160 |
+
return 31;
|
| 161 |
+
#elif defined(__linux__) && HAVE_PTHREAD_SETNAME_NP
|
| 162 |
+
return 16;
|
| 163 |
+
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
|
| 164 |
+
defined(__DragonFly__)
|
| 165 |
+
return 16;
|
| 166 |
+
#elif defined(__OpenBSD__)
|
| 167 |
+
return 24;
|
| 168 |
+
#else
|
| 169 |
+
return 0;
|
| 170 |
+
#endif
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
uint32_t llvm::get_max_thread_name_length() {
|
| 174 |
+
return get_max_thread_name_length_impl();
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
void llvm::set_thread_name(const Twine &Name) {
|
| 178 |
+
// Make sure the input is null terminated.
|
| 179 |
+
SmallString<64> Storage;
|
| 180 |
+
StringRef NameStr = Name.toNullTerminatedStringRef(Storage);
|
| 181 |
+
|
| 182 |
+
// Truncate from the beginning, not the end, if the specified name is too
|
| 183 |
+
// long. For one, this ensures that the resulting string is still null
|
| 184 |
+
// terminated, but additionally the end of a long thread name will usually
|
| 185 |
+
// be more unique than the beginning, since a common pattern is for similar
|
| 186 |
+
// threads to share a common prefix.
|
| 187 |
+
// Note that the name length includes the null terminator.
|
| 188 |
+
if (get_max_thread_name_length() > 0)
|
| 189 |
+
NameStr = NameStr.take_back(get_max_thread_name_length() - 1);
|
| 190 |
+
(void)NameStr;
|
| 191 |
+
#if defined(HAVE_PTHREAD_SET_NAME_NP)
|
| 192 |
+
::pthread_set_name_np(::pthread_self(), NameStr.data());
|
| 193 |
+
#elif defined(HAVE_PTHREAD_SETNAME_NP)
|
| 194 |
+
#if defined(__NetBSD__)
|
| 195 |
+
::pthread_setname_np(::pthread_self(), "%s",
|
| 196 |
+
const_cast<char *>(NameStr.data()));
|
| 197 |
+
#elif defined(__APPLE__)
|
| 198 |
+
::pthread_setname_np(NameStr.data());
|
| 199 |
+
#else
|
| 200 |
+
::pthread_setname_np(::pthread_self(), NameStr.data());
|
| 201 |
+
#endif
|
| 202 |
+
#endif
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
void llvm::get_thread_name(SmallVectorImpl<char> &Name) {
|
| 206 |
+
Name.clear();
|
| 207 |
+
|
| 208 |
+
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
| 209 |
+
int pid = ::getpid();
|
| 210 |
+
uint64_t tid = get_threadid();
|
| 211 |
+
|
| 212 |
+
struct kinfo_proc *kp = nullptr, *nkp;
|
| 213 |
+
size_t len = 0;
|
| 214 |
+
int error;
|
| 215 |
+
int ctl[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID | KERN_PROC_INC_THREAD,
|
| 216 |
+
(int)pid};
|
| 217 |
+
|
| 218 |
+
while (1) {
|
| 219 |
+
error = sysctl(ctl, 4, kp, &len, nullptr, 0);
|
| 220 |
+
if (kp == nullptr || (error != 0 && errno == ENOMEM)) {
|
| 221 |
+
// Add extra space in case threads are added before next call.
|
| 222 |
+
len += sizeof(*kp) + len / 10;
|
| 223 |
+
nkp = (struct kinfo_proc *)::realloc(kp, len);
|
| 224 |
+
if (nkp == nullptr) {
|
| 225 |
+
free(kp);
|
| 226 |
+
return;
|
| 227 |
+
}
|
| 228 |
+
kp = nkp;
|
| 229 |
+
continue;
|
| 230 |
+
}
|
| 231 |
+
if (error != 0)
|
| 232 |
+
len = 0;
|
| 233 |
+
break;
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
for (size_t i = 0; i < len / sizeof(*kp); i++) {
|
| 237 |
+
if (kp[i].ki_tid == (lwpid_t)tid) {
|
| 238 |
+
Name.append(kp[i].ki_tdname, kp[i].ki_tdname + strlen(kp[i].ki_tdname));
|
| 239 |
+
break;
|
| 240 |
+
}
|
| 241 |
+
}
|
| 242 |
+
free(kp);
|
| 243 |
+
return;
|
| 244 |
+
#elif defined(__linux__) && HAVE_PTHREAD_GETNAME_NP
|
| 245 |
+
constexpr uint32_t len = get_max_thread_name_length_impl();
|
| 246 |
+
char Buffer[len] = {'\0'}; // FIXME: working around MSan false positive.
|
| 247 |
+
if (0 == ::pthread_getname_np(::pthread_self(), Buffer, len))
|
| 248 |
+
Name.append(Buffer, Buffer + strlen(Buffer));
|
| 249 |
+
#elif defined(HAVE_PTHREAD_GET_NAME_NP) && HAVE_PTHREAD_GET_NAME_NP
|
| 250 |
+
constexpr uint32_t len = get_max_thread_name_length_impl();
|
| 251 |
+
char buf[len];
|
| 252 |
+
::pthread_get_name_np(::pthread_self(), buf, len);
|
| 253 |
+
|
| 254 |
+
Name.append(buf, buf + strlen(buf));
|
| 255 |
+
|
| 256 |
+
#elif defined(HAVE_PTHREAD_GETNAME_NP) && HAVE_PTHREAD_GETNAME_NP
|
| 257 |
+
constexpr uint32_t len = get_max_thread_name_length_impl();
|
| 258 |
+
char buf[len];
|
| 259 |
+
::pthread_getname_np(::pthread_self(), buf, len);
|
| 260 |
+
|
| 261 |
+
Name.append(buf, buf + strlen(buf));
|
| 262 |
+
#endif
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
SetThreadPriorityResult llvm::set_thread_priority(ThreadPriority Priority) {
|
| 266 |
+
#if defined(__linux__) && defined(SCHED_IDLE)
|
| 267 |
+
// Some *really* old glibcs are missing SCHED_IDLE.
|
| 268 |
+
// http://man7.org/linux/man-pages/man3/pthread_setschedparam.3.html
|
| 269 |
+
// http://man7.org/linux/man-pages/man2/sched_setscheduler.2.html
|
| 270 |
+
sched_param priority;
|
| 271 |
+
// For each of the above policies, param->sched_priority must be 0.
|
| 272 |
+
priority.sched_priority = 0;
|
| 273 |
+
// SCHED_IDLE for running very low priority background jobs.
|
| 274 |
+
// SCHED_OTHER the standard round-robin time-sharing policy;
|
| 275 |
+
return !pthread_setschedparam(
|
| 276 |
+
pthread_self(),
|
| 277 |
+
// FIXME: consider SCHED_BATCH for Low
|
| 278 |
+
Priority == ThreadPriority::Default ? SCHED_OTHER : SCHED_IDLE,
|
| 279 |
+
&priority)
|
| 280 |
+
? SetThreadPriorityResult::SUCCESS
|
| 281 |
+
: SetThreadPriorityResult::FAILURE;
|
| 282 |
+
#elif defined(__APPLE__)
|
| 283 |
+
// https://developer.apple.com/documentation/apple-silicon/tuning-your-code-s-performance-for-apple-silicon
|
| 284 |
+
//
|
| 285 |
+
// Background - Applies to work that isn’t visible to the user and may take
|
| 286 |
+
// significant time to complete. Examples include indexing, backing up, or
|
| 287 |
+
// synchronizing data. This class emphasizes energy efficiency.
|
| 288 |
+
//
|
| 289 |
+
// Utility - Applies to work that takes anywhere from a few seconds to a few
|
| 290 |
+
// minutes to complete. Examples include downloading a document or importing
|
| 291 |
+
// data. This class offers a balance between responsiveness, performance, and
|
| 292 |
+
// energy efficiency.
|
| 293 |
+
const auto qosClass = [&]() {
|
| 294 |
+
switch (Priority) {
|
| 295 |
+
case ThreadPriority::Background:
|
| 296 |
+
return QOS_CLASS_BACKGROUND;
|
| 297 |
+
case ThreadPriority::Low:
|
| 298 |
+
return QOS_CLASS_UTILITY;
|
| 299 |
+
case ThreadPriority::Default:
|
| 300 |
+
return QOS_CLASS_DEFAULT;
|
| 301 |
+
}
|
| 302 |
+
}();
|
| 303 |
+
return !pthread_set_qos_class_self_np(qosClass, 0)
|
| 304 |
+
? SetThreadPriorityResult::SUCCESS
|
| 305 |
+
: SetThreadPriorityResult::FAILURE;
|
| 306 |
+
#endif
|
| 307 |
+
return SetThreadPriorityResult::FAILURE;
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
#include <thread>
|
| 311 |
+
|
| 312 |
+
static int computeHostNumHardwareThreads() {
|
| 313 |
+
#if defined(__FreeBSD__)
|
| 314 |
+
cpuset_t mask;
|
| 315 |
+
CPU_ZERO(&mask);
|
| 316 |
+
if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(mask),
|
| 317 |
+
&mask) == 0)
|
| 318 |
+
return CPU_COUNT(&mask);
|
| 319 |
+
#elif defined(__linux__)
|
| 320 |
+
cpu_set_t Set;
|
| 321 |
+
CPU_ZERO(&Set);
|
| 322 |
+
if (sched_getaffinity(0, sizeof(Set), &Set) == 0)
|
| 323 |
+
return CPU_COUNT(&Set);
|
| 324 |
+
#endif
|
| 325 |
+
// Guard against std::thread::hardware_concurrency() returning 0.
|
| 326 |
+
if (unsigned Val = std::thread::hardware_concurrency())
|
| 327 |
+
return Val;
|
| 328 |
+
return 1;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
void llvm::ThreadPoolStrategy::apply_thread_strategy(
|
| 332 |
+
unsigned ThreadPoolNum) const {}
|
| 333 |
+
|
| 334 |
+
llvm::BitVector llvm::get_thread_affinity_mask() {
|
| 335 |
+
// FIXME: Implement
|
| 336 |
+
llvm_unreachable("Not implemented!");
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
unsigned llvm::get_cpus() { return 1; }
|
| 340 |
+
|
| 341 |
+
#if defined(__linux__) && (defined(__i386__) || defined(__x86_64__))
|
| 342 |
+
// On Linux, the number of physical cores can be computed from /proc/cpuinfo,
|
| 343 |
+
// using the number of unique physical/core id pairs. The following
|
| 344 |
+
// implementation reads the /proc/cpuinfo format on an x86_64 system.
|
| 345 |
+
static int computeHostNumPhysicalCores() {
|
| 346 |
+
// Enabled represents the number of physical id/core id pairs with at least
|
| 347 |
+
// one processor id enabled by the CPU affinity mask.
|
| 348 |
+
cpu_set_t Affinity, Enabled;
|
| 349 |
+
if (sched_getaffinity(0, sizeof(Affinity), &Affinity) != 0)
|
| 350 |
+
return -1;
|
| 351 |
+
CPU_ZERO(&Enabled);
|
| 352 |
+
|
| 353 |
+
// Read /proc/cpuinfo as a stream (until EOF reached). It cannot be
|
| 354 |
+
// mmapped because it appears to have 0 size.
|
| 355 |
+
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text =
|
| 356 |
+
llvm::MemoryBuffer::getFileAsStream("/proc/cpuinfo");
|
| 357 |
+
if (std::error_code EC = Text.getError()) {
|
| 358 |
+
llvm::errs() << "Can't read "
|
| 359 |
+
<< "/proc/cpuinfo: " << EC.message() << "\n";
|
| 360 |
+
return -1;
|
| 361 |
+
}
|
| 362 |
+
SmallVector<StringRef, 8> strs;
|
| 363 |
+
(*Text)->getBuffer().split(strs, "\n", /*MaxSplit=*/-1,
|
| 364 |
+
/*KeepEmpty=*/false);
|
| 365 |
+
int CurProcessor = -1;
|
| 366 |
+
int CurPhysicalId = -1;
|
| 367 |
+
int CurSiblings = -1;
|
| 368 |
+
int CurCoreId = -1;
|
| 369 |
+
for (StringRef Line : strs) {
|
| 370 |
+
std::pair<StringRef, StringRef> Data = Line.split(':');
|
| 371 |
+
auto Name = Data.first.trim();
|
| 372 |
+
auto Val = Data.second.trim();
|
| 373 |
+
// These fields are available if the kernel is configured with CONFIG_SMP.
|
| 374 |
+
if (Name == "processor")
|
| 375 |
+
Val.getAsInteger(10, CurProcessor);
|
| 376 |
+
else if (Name == "physical id")
|
| 377 |
+
Val.getAsInteger(10, CurPhysicalId);
|
| 378 |
+
else if (Name == "siblings")
|
| 379 |
+
Val.getAsInteger(10, CurSiblings);
|
| 380 |
+
else if (Name == "core id") {
|
| 381 |
+
Val.getAsInteger(10, CurCoreId);
|
| 382 |
+
// The processor id corresponds to an index into cpu_set_t.
|
| 383 |
+
if (CPU_ISSET(CurProcessor, &Affinity))
|
| 384 |
+
CPU_SET(CurPhysicalId * CurSiblings + CurCoreId, &Enabled);
|
| 385 |
+
}
|
| 386 |
+
}
|
| 387 |
+
return CPU_COUNT(&Enabled);
|
| 388 |
+
}
|
| 389 |
+
#elif (defined(__linux__) && defined(__s390x__)) || defined(_AIX)
|
| 390 |
+
static int computeHostNumPhysicalCores() {
|
| 391 |
+
return sysconf(_SC_NPROCESSORS_ONLN);
|
| 392 |
+
}
|
| 393 |
+
#elif defined(__linux__)
|
| 394 |
+
static int computeHostNumPhysicalCores() {
|
| 395 |
+
cpu_set_t Affinity;
|
| 396 |
+
if (sched_getaffinity(0, sizeof(Affinity), &Affinity) == 0)
|
| 397 |
+
return CPU_COUNT(&Affinity);
|
| 398 |
+
|
| 399 |
+
// The call to sched_getaffinity() may have failed because the Affinity
|
| 400 |
+
// mask is too small for the number of CPU's on the system (i.e. the
|
| 401 |
+
// system has more than 1024 CPUs). Allocate a mask large enough for
|
| 402 |
+
// twice as many CPUs.
|
| 403 |
+
cpu_set_t *DynAffinity;
|
| 404 |
+
DynAffinity = CPU_ALLOC(2048);
|
| 405 |
+
if (sched_getaffinity(0, CPU_ALLOC_SIZE(2048), DynAffinity) == 0) {
|
| 406 |
+
int NumCPUs = CPU_COUNT(DynAffinity);
|
| 407 |
+
CPU_FREE(DynAffinity);
|
| 408 |
+
return NumCPUs;
|
| 409 |
+
}
|
| 410 |
+
return -1;
|
| 411 |
+
}
|
| 412 |
+
#elif defined(__APPLE__)
|
| 413 |
+
// Gets the number of *physical cores* on the machine.
|
| 414 |
+
static int computeHostNumPhysicalCores() {
|
| 415 |
+
uint32_t count;
|
| 416 |
+
size_t len = sizeof(count);
|
| 417 |
+
sysctlbyname("hw.physicalcpu", &count, &len, NULL, 0);
|
| 418 |
+
if (count < 1) {
|
| 419 |
+
int nm[2];
|
| 420 |
+
nm[0] = CTL_HW;
|
| 421 |
+
nm[1] = HW_AVAILCPU;
|
| 422 |
+
sysctl(nm, 2, &count, &len, NULL, 0);
|
| 423 |
+
if (count < 1)
|
| 424 |
+
return -1;
|
| 425 |
+
}
|
| 426 |
+
return count;
|
| 427 |
+
}
|
| 428 |
+
#elif defined(__MVS__)
|
| 429 |
+
static int computeHostNumPhysicalCores() {
|
| 430 |
+
enum {
|
| 431 |
+
// Byte offset of the pointer to the Communications Vector Table (CVT) in
|
| 432 |
+
// the Prefixed Save Area (PSA). The table entry is a 31-bit pointer and
|
| 433 |
+
// will be zero-extended to uintptr_t.
|
| 434 |
+
FLCCVT = 16,
|
| 435 |
+
// Byte offset of the pointer to the Common System Data Area (CSD) in the
|
| 436 |
+
// CVT. The table entry is a 31-bit pointer and will be zero-extended to
|
| 437 |
+
// uintptr_t.
|
| 438 |
+
CVTCSD = 660,
|
| 439 |
+
// Byte offset to the number of live CPs in the LPAR, stored as a signed
|
| 440 |
+
// 32-bit value in the table.
|
| 441 |
+
CSD_NUMBER_ONLINE_STANDARD_CPS = 264,
|
| 442 |
+
};
|
| 443 |
+
char *PSA = 0;
|
| 444 |
+
char *CVT = reinterpret_cast<char *>(
|
| 445 |
+
static_cast<uintptr_t>(reinterpret_cast<unsigned int &>(PSA[FLCCVT])));
|
| 446 |
+
char *CSD = reinterpret_cast<char *>(
|
| 447 |
+
static_cast<uintptr_t>(reinterpret_cast<unsigned int &>(CVT[CVTCSD])));
|
| 448 |
+
return reinterpret_cast<int &>(CSD[CSD_NUMBER_ONLINE_STANDARD_CPS]);
|
| 449 |
+
}
|
| 450 |
+
#else
|
| 451 |
+
// On other systems, return -1 to indicate unknown.
|
| 452 |
+
static int computeHostNumPhysicalCores() { return -1; }
|
| 453 |
+
#endif
|
| 454 |
+
|
| 455 |
+
int llvm::get_physical_cores() {
|
| 456 |
+
static int NumCores = computeHostNumPhysicalCores();
|
| 457 |
+
return NumCores;
|
| 458 |
+
}
|
deps/exla/cache/xla_extension/include/llvm/lib/Support/Unix/Unix.h
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- llvm/Support/Unix/Unix.h - Common Unix Include File -------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file defines things specific to Unix implementations.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_LIB_SUPPORT_UNIX_UNIX_H
|
| 14 |
+
#define LLVM_LIB_SUPPORT_UNIX_UNIX_H
|
| 15 |
+
|
| 16 |
+
//===----------------------------------------------------------------------===//
|
| 17 |
+
//=== WARNING: Implementation here must contain only generic UNIX code that
|
| 18 |
+
//=== is guaranteed to work on all UNIX variants.
|
| 19 |
+
//===----------------------------------------------------------------------===//
|
| 20 |
+
|
| 21 |
+
#include "llvm/Config/config.h"
|
| 22 |
+
#include "llvm/Support/Chrono.h"
|
| 23 |
+
#include "llvm/Support/Errno.h"
|
| 24 |
+
#include "llvm/Support/ErrorHandling.h"
|
| 25 |
+
#include <algorithm>
|
| 26 |
+
#include <assert.h>
|
| 27 |
+
#include <cerrno>
|
| 28 |
+
#include <cstdio>
|
| 29 |
+
#include <cstdlib>
|
| 30 |
+
#include <cstring>
|
| 31 |
+
#include <string>
|
| 32 |
+
#include <sys/types.h>
|
| 33 |
+
#include <sys/wait.h>
|
| 34 |
+
|
| 35 |
+
#ifdef HAVE_UNISTD_H
|
| 36 |
+
#include <unistd.h>
|
| 37 |
+
#endif
|
| 38 |
+
|
| 39 |
+
#include <sys/time.h>
|
| 40 |
+
#include <time.h>
|
| 41 |
+
|
| 42 |
+
#include <dlfcn.h>
|
| 43 |
+
|
| 44 |
+
# include <fcntl.h>
|
| 45 |
+
|
| 46 |
+
/// This function builds an error message into \p ErrMsg using the \p prefix
|
| 47 |
+
/// string and the Unix error number given by \p errnum. If errnum is -1, the
|
| 48 |
+
/// default then the value of errno is used.
|
| 49 |
+
/// Make an error message
|
| 50 |
+
///
|
| 51 |
+
/// If the error number can be converted to a string, it will be
|
| 52 |
+
/// separated from prefix by ": ".
|
| 53 |
+
static inline bool MakeErrMsg(
|
| 54 |
+
std::string* ErrMsg, const std::string& prefix, int errnum = -1) {
|
| 55 |
+
if (!ErrMsg)
|
| 56 |
+
return true;
|
| 57 |
+
if (errnum == -1)
|
| 58 |
+
errnum = errno;
|
| 59 |
+
*ErrMsg = prefix + ": " + llvm::sys::StrError(errnum);
|
| 60 |
+
return true;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
// Include StrError(errnum) in a fatal error message.
|
| 64 |
+
[[noreturn]] static inline void ReportErrnumFatal(const char *Msg, int errnum) {
|
| 65 |
+
std::string ErrMsg;
|
| 66 |
+
MakeErrMsg(&ErrMsg, Msg, errnum);
|
| 67 |
+
llvm::report_fatal_error(llvm::Twine(ErrMsg));
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
namespace llvm {
|
| 71 |
+
namespace sys {
|
| 72 |
+
|
| 73 |
+
/// Convert a struct timeval to a duration. Note that timeval can be used both
|
| 74 |
+
/// as a time point and a duration. Be sure to check what the input represents.
|
| 75 |
+
inline std::chrono::microseconds toDuration(const struct timeval &TV) {
|
| 76 |
+
return std::chrono::seconds(TV.tv_sec) +
|
| 77 |
+
std::chrono::microseconds(TV.tv_usec);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
/// Convert a time point to struct timespec.
|
| 81 |
+
inline struct timespec toTimeSpec(TimePoint<> TP) {
|
| 82 |
+
using namespace std::chrono;
|
| 83 |
+
|
| 84 |
+
struct timespec RetVal;
|
| 85 |
+
RetVal.tv_sec = toTimeT(TP);
|
| 86 |
+
RetVal.tv_nsec = (TP.time_since_epoch() % seconds(1)).count();
|
| 87 |
+
return RetVal;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/// Convert a time point to struct timeval.
|
| 91 |
+
inline struct timeval toTimeVal(TimePoint<std::chrono::microseconds> TP) {
|
| 92 |
+
using namespace std::chrono;
|
| 93 |
+
|
| 94 |
+
struct timeval RetVal;
|
| 95 |
+
RetVal.tv_sec = toTimeT(TP);
|
| 96 |
+
RetVal.tv_usec = (TP.time_since_epoch() % seconds(1)).count();
|
| 97 |
+
return RetVal;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
} // namespace sys
|
| 101 |
+
} // namespace llvm
|
| 102 |
+
|
| 103 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/lib/Support/Unix/Watchdog.inc
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===--- Unix/Watchdog.inc - Unix Watchdog Implementation -------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file provides the generic Unix implementation of the Watchdog class.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#include "llvm/Config/config.h"
|
| 14 |
+
|
| 15 |
+
#ifdef HAVE_UNISTD_H
|
| 16 |
+
#include <unistd.h>
|
| 17 |
+
#endif
|
| 18 |
+
|
| 19 |
+
namespace llvm {
|
| 20 |
+
namespace sys {
|
| 21 |
+
Watchdog::Watchdog(unsigned int seconds) {
|
| 22 |
+
#ifdef HAVE_UNISTD_H
|
| 23 |
+
alarm(seconds);
|
| 24 |
+
#endif
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
Watchdog::~Watchdog() {
|
| 28 |
+
#ifdef HAVE_UNISTD_H
|
| 29 |
+
alarm(0);
|
| 30 |
+
#endif
|
| 31 |
+
}
|
| 32 |
+
} // namespace sys
|
| 33 |
+
} // namespace llvm
|
deps/exla/cache/xla_extension/include/llvm/lib/Support/regengine.inc
ADDED
|
@@ -0,0 +1,1099 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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6 |
+
* The Regents of the University of California. All rights reserved.
|
| 7 |
+
*
|
| 8 |
+
* This code is derived from software contributed to Berkeley by
|
| 9 |
+
* Henry Spencer.
|
| 10 |
+
*
|
| 11 |
+
* Redistribution and use in source and binary forms, with or without
|
| 12 |
+
* modification, are permitted provided that the following conditions
|
| 13 |
+
* are met:
|
| 14 |
+
* 1. Redistributions of source code must retain the above copyright
|
| 15 |
+
* notice, this list of conditions and the following disclaimer.
|
| 16 |
+
* 2. Redistributions in binary form must reproduce the above copyright
|
| 17 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 18 |
+
* documentation and/or other materials provided with the distribution.
|
| 19 |
+
* 3. Neither the name of the University nor the names of its contributors
|
| 20 |
+
* may be used to endorse or promote products derived from this software
|
| 21 |
+
* without specific prior written permission.
|
| 22 |
+
*
|
| 23 |
+
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
| 24 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 25 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 26 |
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
| 27 |
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 28 |
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
| 29 |
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
| 30 |
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 31 |
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
| 32 |
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
| 33 |
+
* SUCH DAMAGE.
|
| 34 |
+
*
|
| 35 |
+
* @(#)engine.c 8.5 (Berkeley) 3/20/94
|
| 36 |
+
*/
|
| 37 |
+
|
| 38 |
+
/*
|
| 39 |
+
* The matching engine and friends. This file is #included by regexec.c
|
| 40 |
+
* after suitable #defines of a variety of macros used herein, so that
|
| 41 |
+
* different state representations can be used without duplicating masses
|
| 42 |
+
* of code.
|
| 43 |
+
*/
|
| 44 |
+
|
| 45 |
+
#ifdef SNAMES
|
| 46 |
+
#define matcher smatcher
|
| 47 |
+
#define fast sfast
|
| 48 |
+
#define slow sslow
|
| 49 |
+
#define dissect sdissect
|
| 50 |
+
#define backref sbackref
|
| 51 |
+
#define step sstep
|
| 52 |
+
#define print sprint
|
| 53 |
+
#define at sat
|
| 54 |
+
#define match smat
|
| 55 |
+
#define nope snope
|
| 56 |
+
#define step_back sstep_back
|
| 57 |
+
#endif
|
| 58 |
+
#ifdef LNAMES
|
| 59 |
+
#define matcher lmatcher
|
| 60 |
+
#define fast lfast
|
| 61 |
+
#define slow lslow
|
| 62 |
+
#define dissect ldissect
|
| 63 |
+
#define backref lbackref
|
| 64 |
+
#define step lstep
|
| 65 |
+
#define print lprint
|
| 66 |
+
#define at lat
|
| 67 |
+
#define match lmat
|
| 68 |
+
#define nope lnope
|
| 69 |
+
#define step_back lstep_back
|
| 70 |
+
#endif
|
| 71 |
+
|
| 72 |
+
/* another structure passed up and down to avoid zillions of parameters */
|
| 73 |
+
struct match {
|
| 74 |
+
struct re_guts *g;
|
| 75 |
+
int eflags;
|
| 76 |
+
llvm_regmatch_t *pmatch; /* [nsub+1] (0 element unused) */
|
| 77 |
+
const char *offp; /* offsets work from here */
|
| 78 |
+
const char *beginp; /* start of string -- virtual NUL precedes */
|
| 79 |
+
const char *endp; /* end of string -- virtual NUL here */
|
| 80 |
+
const char *coldp; /* can be no match starting before here */
|
| 81 |
+
const char **lastpos; /* [nplus+1] */
|
| 82 |
+
STATEVARS;
|
| 83 |
+
states st; /* current states */
|
| 84 |
+
states fresh; /* states for a fresh start */
|
| 85 |
+
states tmp; /* temporary */
|
| 86 |
+
states empty; /* empty set of states */
|
| 87 |
+
};
|
| 88 |
+
|
| 89 |
+
static int matcher(struct re_guts *, const char *, size_t,
|
| 90 |
+
llvm_regmatch_t[], int);
|
| 91 |
+
static const char *dissect(struct match *, const char *, const char *, sopno,
|
| 92 |
+
sopno);
|
| 93 |
+
static const char *backref(struct match *, const char *, const char *, sopno,
|
| 94 |
+
sopno, sopno, int);
|
| 95 |
+
static const char *fast(struct match *, const char *, const char *, sopno, sopno);
|
| 96 |
+
static const char *slow(struct match *, const char *, const char *, sopno, sopno);
|
| 97 |
+
static states step(struct re_guts *, sopno, sopno, states, int, states);
|
| 98 |
+
#define MAX_RECURSION 100
|
| 99 |
+
#define BOL (OUT+1)
|
| 100 |
+
#define EOL (BOL+1)
|
| 101 |
+
#define BOLEOL (BOL+2)
|
| 102 |
+
#define NOTHING (BOL+3)
|
| 103 |
+
#define BOW (BOL+4)
|
| 104 |
+
#define EOW (BOL+5)
|
| 105 |
+
#define CODEMAX (BOL+5) /* highest code used */
|
| 106 |
+
#define NONCHAR(c) ((c) > CHAR_MAX)
|
| 107 |
+
#define NNONCHAR (CODEMAX-CHAR_MAX)
|
| 108 |
+
#ifdef REDEBUG
|
| 109 |
+
static void print(struct match *, const char *, states, int, FILE *);
|
| 110 |
+
#endif
|
| 111 |
+
#ifdef REDEBUG
|
| 112 |
+
static void at(
|
| 113 |
+
struct match *, const char *, const char *, const char *, sopno, sopno);
|
| 114 |
+
#endif
|
| 115 |
+
#ifdef REDEBUG
|
| 116 |
+
static char *pchar(int);
|
| 117 |
+
#endif
|
| 118 |
+
|
| 119 |
+
#ifdef REDEBUG
|
| 120 |
+
#define SP(t, s, c) print(m, t, s, c, stdout)
|
| 121 |
+
#define AT(t, p1, p2, s1, s2) at(m, t, p1, p2, s1, s2)
|
| 122 |
+
#define NOTE(str) { if (m->eflags®_TRACE) (void)printf("=%s\n", (str)); }
|
| 123 |
+
static int nope = 0;
|
| 124 |
+
#else
|
| 125 |
+
#define SP(t, s, c) /* nothing */
|
| 126 |
+
#define AT(t, p1, p2, s1, s2) /* nothing */
|
| 127 |
+
#define NOTE(s) /* nothing */
|
| 128 |
+
#endif
|
| 129 |
+
|
| 130 |
+
/*
|
| 131 |
+
- matcher - the actual matching engine
|
| 132 |
+
*/
|
| 133 |
+
static int /* 0 success, REG_NOMATCH failure */
|
| 134 |
+
matcher(struct re_guts *g, const char *string, size_t nmatch,
|
| 135 |
+
llvm_regmatch_t pmatch[],
|
| 136 |
+
int eflags)
|
| 137 |
+
{
|
| 138 |
+
const char *endp;
|
| 139 |
+
size_t i;
|
| 140 |
+
struct match mv;
|
| 141 |
+
struct match *m = &mv;
|
| 142 |
+
const char *dp;
|
| 143 |
+
const sopno gf = g->firststate+1; /* +1 for OEND */
|
| 144 |
+
const sopno gl = g->laststate;
|
| 145 |
+
const char *start;
|
| 146 |
+
const char *stop;
|
| 147 |
+
|
| 148 |
+
/* simplify the situation where possible */
|
| 149 |
+
if (g->cflags®_NOSUB)
|
| 150 |
+
nmatch = 0;
|
| 151 |
+
if (eflags®_STARTEND) {
|
| 152 |
+
start = string + pmatch[0].rm_so;
|
| 153 |
+
stop = string + pmatch[0].rm_eo;
|
| 154 |
+
} else {
|
| 155 |
+
start = string;
|
| 156 |
+
stop = start + strlen(start);
|
| 157 |
+
}
|
| 158 |
+
if (stop < start)
|
| 159 |
+
return(REG_INVARG);
|
| 160 |
+
|
| 161 |
+
/* prescreening; this does wonders for this rather slow code */
|
| 162 |
+
if (g->must != NULL) {
|
| 163 |
+
for (dp = start; dp < stop; dp++)
|
| 164 |
+
if (*dp == g->must[0] && stop - dp >= g->mlen &&
|
| 165 |
+
memcmp(dp, g->must, (size_t)g->mlen) == 0)
|
| 166 |
+
break;
|
| 167 |
+
if (dp == stop) /* we didn't find g->must */
|
| 168 |
+
return(REG_NOMATCH);
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
/* match struct setup */
|
| 172 |
+
m->g = g;
|
| 173 |
+
m->eflags = eflags;
|
| 174 |
+
m->pmatch = NULL;
|
| 175 |
+
m->lastpos = NULL;
|
| 176 |
+
m->offp = string;
|
| 177 |
+
m->beginp = start;
|
| 178 |
+
m->endp = stop;
|
| 179 |
+
STATESETUP(m, 4);
|
| 180 |
+
SETUP(m->st);
|
| 181 |
+
SETUP(m->fresh);
|
| 182 |
+
SETUP(m->tmp);
|
| 183 |
+
SETUP(m->empty);
|
| 184 |
+
CLEAR(m->empty);
|
| 185 |
+
|
| 186 |
+
/* this loop does only one repetition except for backrefs */
|
| 187 |
+
for (;;) {
|
| 188 |
+
endp = fast(m, start, stop, gf, gl);
|
| 189 |
+
if (endp == NULL) { /* a miss */
|
| 190 |
+
free(m->pmatch);
|
| 191 |
+
free((void*)m->lastpos);
|
| 192 |
+
STATETEARDOWN(m);
|
| 193 |
+
return(REG_NOMATCH);
|
| 194 |
+
}
|
| 195 |
+
if (nmatch == 0 && !g->backrefs)
|
| 196 |
+
break; /* no further info needed */
|
| 197 |
+
|
| 198 |
+
/* where? */
|
| 199 |
+
assert(m->coldp != NULL);
|
| 200 |
+
for (;;) {
|
| 201 |
+
NOTE("finding start");
|
| 202 |
+
endp = slow(m, m->coldp, stop, gf, gl);
|
| 203 |
+
if (endp != NULL)
|
| 204 |
+
break;
|
| 205 |
+
assert(m->coldp < m->endp);
|
| 206 |
+
m->coldp++;
|
| 207 |
+
}
|
| 208 |
+
if (nmatch == 1 && !g->backrefs)
|
| 209 |
+
break; /* no further info needed */
|
| 210 |
+
|
| 211 |
+
/* oh my, they want the subexpressions... */
|
| 212 |
+
if (m->pmatch == NULL)
|
| 213 |
+
m->pmatch = (llvm_regmatch_t *)malloc((m->g->nsub + 1) *
|
| 214 |
+
sizeof(llvm_regmatch_t));
|
| 215 |
+
if (m->pmatch == NULL) {
|
| 216 |
+
STATETEARDOWN(m);
|
| 217 |
+
return(REG_ESPACE);
|
| 218 |
+
}
|
| 219 |
+
for (i = 1; i <= m->g->nsub; i++)
|
| 220 |
+
m->pmatch[i].rm_so = m->pmatch[i].rm_eo = -1;
|
| 221 |
+
if (!g->backrefs && !(m->eflags®_BACKR)) {
|
| 222 |
+
NOTE("dissecting");
|
| 223 |
+
dp = dissect(m, m->coldp, endp, gf, gl);
|
| 224 |
+
} else {
|
| 225 |
+
if (g->nplus > 0 && m->lastpos == NULL)
|
| 226 |
+
m->lastpos = (const char **)malloc((g->nplus+1) *
|
| 227 |
+
sizeof(char *));
|
| 228 |
+
if (g->nplus > 0 && m->lastpos == NULL) {
|
| 229 |
+
free(m->pmatch);
|
| 230 |
+
STATETEARDOWN(m);
|
| 231 |
+
return(REG_ESPACE);
|
| 232 |
+
}
|
| 233 |
+
NOTE("backref dissect");
|
| 234 |
+
dp = backref(m, m->coldp, endp, gf, gl, (sopno)0, 0);
|
| 235 |
+
}
|
| 236 |
+
if (dp != NULL)
|
| 237 |
+
break;
|
| 238 |
+
|
| 239 |
+
/* uh-oh... we couldn't find a subexpression-level match */
|
| 240 |
+
assert(g->backrefs); /* must be back references doing it */
|
| 241 |
+
assert(g->nplus == 0 || m->lastpos != NULL);
|
| 242 |
+
for (;;) {
|
| 243 |
+
if (dp != NULL || endp <= m->coldp)
|
| 244 |
+
break; /* defeat */
|
| 245 |
+
NOTE("backoff");
|
| 246 |
+
endp = slow(m, m->coldp, endp-1, gf, gl);
|
| 247 |
+
if (endp == NULL)
|
| 248 |
+
break; /* defeat */
|
| 249 |
+
/* try it on a shorter possibility */
|
| 250 |
+
#ifndef NDEBUG
|
| 251 |
+
for (i = 1; i <= m->g->nsub; i++) {
|
| 252 |
+
assert(m->pmatch[i].rm_so == -1);
|
| 253 |
+
assert(m->pmatch[i].rm_eo == -1);
|
| 254 |
+
}
|
| 255 |
+
#endif
|
| 256 |
+
NOTE("backoff dissect");
|
| 257 |
+
dp = backref(m, m->coldp, endp, gf, gl, (sopno)0, 0);
|
| 258 |
+
}
|
| 259 |
+
assert(dp == NULL || dp == endp);
|
| 260 |
+
if (dp != NULL) /* found a shorter one */
|
| 261 |
+
break;
|
| 262 |
+
|
| 263 |
+
/* despite initial appearances, there is no match here */
|
| 264 |
+
NOTE("false alarm");
|
| 265 |
+
if (m->coldp == stop)
|
| 266 |
+
break;
|
| 267 |
+
start = m->coldp + 1; /* recycle starting later */
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
/* fill in the details if requested */
|
| 271 |
+
if (nmatch > 0) {
|
| 272 |
+
pmatch[0].rm_so = m->coldp - m->offp;
|
| 273 |
+
pmatch[0].rm_eo = endp - m->offp;
|
| 274 |
+
}
|
| 275 |
+
if (nmatch > 1) {
|
| 276 |
+
assert(m->pmatch != NULL);
|
| 277 |
+
for (i = 1; i < nmatch; i++)
|
| 278 |
+
if (i <= m->g->nsub)
|
| 279 |
+
pmatch[i] = m->pmatch[i];
|
| 280 |
+
else {
|
| 281 |
+
pmatch[i].rm_so = -1;
|
| 282 |
+
pmatch[i].rm_eo = -1;
|
| 283 |
+
}
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
if (m->pmatch != NULL)
|
| 287 |
+
free((char *)m->pmatch);
|
| 288 |
+
if (m->lastpos != NULL)
|
| 289 |
+
free((char *)m->lastpos);
|
| 290 |
+
STATETEARDOWN(m);
|
| 291 |
+
return(0);
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
/* Step back from "stop" to a position where the strip startst..stopst might
|
| 295 |
+
* match. This can always conservatively return "stop - 1", but may return an
|
| 296 |
+
* earlier position if matches at later positions are impossible. */
|
| 297 |
+
static const char *
|
| 298 |
+
step_back(struct re_guts *g, const char *start, const char *stop, sopno startst,
|
| 299 |
+
sopno stopst)
|
| 300 |
+
{
|
| 301 |
+
/* Always step back at least one character. */
|
| 302 |
+
assert(stop > start);
|
| 303 |
+
const char *res = stop - 1;
|
| 304 |
+
|
| 305 |
+
/* Check whether the strip startst..stropst starts with a fixed character,
|
| 306 |
+
* ignoring any closing parentheses. If not, return a conservative result. */
|
| 307 |
+
for (;;) {
|
| 308 |
+
if (startst >= stopst)
|
| 309 |
+
return res;
|
| 310 |
+
if (OP(g->strip[startst]) != ORPAREN)
|
| 311 |
+
break;
|
| 312 |
+
startst++;
|
| 313 |
+
}
|
| 314 |
+
if (OP(g->strip[startst]) != OCHAR)
|
| 315 |
+
return res;
|
| 316 |
+
|
| 317 |
+
/* Find the character that starts the following match. */
|
| 318 |
+
char ch = OPND(g->strip[startst]);
|
| 319 |
+
for (; res != start; --res) {
|
| 320 |
+
if (*res == ch) {
|
| 321 |
+
/* Try to check the next fixed character as well. */
|
| 322 |
+
sopno nextst = startst + 1;
|
| 323 |
+
const char *next = res + 1;
|
| 324 |
+
if (nextst >= stopst || OP(g->strip[nextst]) != OCHAR || next >= stop ||
|
| 325 |
+
*next == (char)OPND(g->strip[nextst]))
|
| 326 |
+
break;
|
| 327 |
+
}
|
| 328 |
+
}
|
| 329 |
+
return res;
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
/*
|
| 333 |
+
- dissect - figure out what matched what, no back references
|
| 334 |
+
*/
|
| 335 |
+
static const char * /* == stop (success) always */
|
| 336 |
+
dissect(struct match *m, const char *start, const char *stop, sopno startst,
|
| 337 |
+
sopno stopst)
|
| 338 |
+
{
|
| 339 |
+
int i;
|
| 340 |
+
sopno ss; /* start sop of current subRE */
|
| 341 |
+
sopno es; /* end sop of current subRE */
|
| 342 |
+
const char *sp; /* start of string matched by it */
|
| 343 |
+
const char *stp; /* string matched by it cannot pass here */
|
| 344 |
+
const char *rest; /* start of rest of string */
|
| 345 |
+
const char *tail; /* string unmatched by rest of RE */
|
| 346 |
+
sopno ssub; /* start sop of subsubRE */
|
| 347 |
+
sopno esub; /* end sop of subsubRE */
|
| 348 |
+
const char *ssp; /* start of string matched by subsubRE */
|
| 349 |
+
const char *sep; /* end of string matched by subsubRE */
|
| 350 |
+
const char *oldssp; /* previous ssp */
|
| 351 |
+
|
| 352 |
+
AT("diss", start, stop, startst, stopst);
|
| 353 |
+
sp = start;
|
| 354 |
+
for (ss = startst; ss < stopst; ss = es) {
|
| 355 |
+
/* identify end of subRE */
|
| 356 |
+
es = ss;
|
| 357 |
+
switch (OP(m->g->strip[es])) {
|
| 358 |
+
case OPLUS_:
|
| 359 |
+
case OQUEST_:
|
| 360 |
+
es += OPND(m->g->strip[es]);
|
| 361 |
+
break;
|
| 362 |
+
case OCH_:
|
| 363 |
+
while (OP(m->g->strip[es]) != O_CH)
|
| 364 |
+
es += OPND(m->g->strip[es]);
|
| 365 |
+
break;
|
| 366 |
+
}
|
| 367 |
+
es++;
|
| 368 |
+
|
| 369 |
+
/* figure out what it matched */
|
| 370 |
+
switch (OP(m->g->strip[ss])) {
|
| 371 |
+
case OEND:
|
| 372 |
+
assert(nope);
|
| 373 |
+
break;
|
| 374 |
+
case OCHAR:
|
| 375 |
+
sp++;
|
| 376 |
+
break;
|
| 377 |
+
case OBOL:
|
| 378 |
+
case OEOL:
|
| 379 |
+
case OBOW:
|
| 380 |
+
case OEOW:
|
| 381 |
+
break;
|
| 382 |
+
case OANY:
|
| 383 |
+
case OANYOF:
|
| 384 |
+
sp++;
|
| 385 |
+
break;
|
| 386 |
+
case OBACK_:
|
| 387 |
+
case O_BACK:
|
| 388 |
+
assert(nope);
|
| 389 |
+
break;
|
| 390 |
+
/* cases where length of match is hard to find */
|
| 391 |
+
case OQUEST_:
|
| 392 |
+
stp = stop;
|
| 393 |
+
for (;;) {
|
| 394 |
+
/* how long could this one be? */
|
| 395 |
+
rest = slow(m, sp, stp, ss, es);
|
| 396 |
+
assert(rest != NULL); /* it did match */
|
| 397 |
+
/* could the rest match the rest? */
|
| 398 |
+
tail = slow(m, rest, stop, es, stopst);
|
| 399 |
+
if (tail == stop)
|
| 400 |
+
break; /* yes! */
|
| 401 |
+
/* no -- try a shorter match for this one */
|
| 402 |
+
stp = step_back(m->g, sp, rest, es, stopst);
|
| 403 |
+
assert(stp >= sp); /* it did work */
|
| 404 |
+
}
|
| 405 |
+
ssub = ss + 1;
|
| 406 |
+
esub = es - 1;
|
| 407 |
+
/* did innards match? */
|
| 408 |
+
if (slow(m, sp, rest, ssub, esub) != NULL) {
|
| 409 |
+
const char *dp = dissect(m, sp, rest, ssub, esub);
|
| 410 |
+
(void)dp; /* avoid warning if assertions off */
|
| 411 |
+
assert(dp == rest);
|
| 412 |
+
} else /* no */
|
| 413 |
+
assert(sp == rest);
|
| 414 |
+
sp = rest;
|
| 415 |
+
break;
|
| 416 |
+
case OPLUS_:
|
| 417 |
+
stp = stop;
|
| 418 |
+
for (;;) {
|
| 419 |
+
/* how long could this one be? */
|
| 420 |
+
rest = slow(m, sp, stp, ss, es);
|
| 421 |
+
assert(rest != NULL); /* it did match */
|
| 422 |
+
/* could the rest match the rest? */
|
| 423 |
+
tail = slow(m, rest, stop, es, stopst);
|
| 424 |
+
if (tail == stop)
|
| 425 |
+
break; /* yes! */
|
| 426 |
+
/* no -- try a shorter match for this one */
|
| 427 |
+
stp = step_back(m->g, sp, rest, es, stopst);
|
| 428 |
+
assert(stp >= sp); /* it did work */
|
| 429 |
+
}
|
| 430 |
+
ssub = ss + 1;
|
| 431 |
+
esub = es - 1;
|
| 432 |
+
ssp = sp;
|
| 433 |
+
oldssp = ssp;
|
| 434 |
+
for (;;) { /* find last match of innards */
|
| 435 |
+
sep = slow(m, ssp, rest, ssub, esub);
|
| 436 |
+
if (sep == NULL || sep == ssp)
|
| 437 |
+
break; /* failed or matched null */
|
| 438 |
+
oldssp = ssp; /* on to next try */
|
| 439 |
+
ssp = sep;
|
| 440 |
+
}
|
| 441 |
+
if (sep == NULL) {
|
| 442 |
+
/* last successful match */
|
| 443 |
+
sep = ssp;
|
| 444 |
+
ssp = oldssp;
|
| 445 |
+
}
|
| 446 |
+
assert(sep == rest); /* must exhaust substring */
|
| 447 |
+
assert(slow(m, ssp, sep, ssub, esub) == rest);
|
| 448 |
+
{
|
| 449 |
+
const char *dp = dissect(m, ssp, sep, ssub, esub);
|
| 450 |
+
(void)dp; /* avoid warning if assertions off */
|
| 451 |
+
assert(dp == sep);
|
| 452 |
+
}
|
| 453 |
+
sp = rest;
|
| 454 |
+
break;
|
| 455 |
+
case OCH_:
|
| 456 |
+
stp = stop;
|
| 457 |
+
for (;;) {
|
| 458 |
+
/* how long could this one be? */
|
| 459 |
+
rest = slow(m, sp, stp, ss, es);
|
| 460 |
+
assert(rest != NULL); /* it did match */
|
| 461 |
+
/* could the rest match the rest? */
|
| 462 |
+
tail = slow(m, rest, stop, es, stopst);
|
| 463 |
+
if (tail == stop)
|
| 464 |
+
break; /* yes! */
|
| 465 |
+
/* no -- try a shorter match for this one */
|
| 466 |
+
stp = rest - 1;
|
| 467 |
+
assert(stp >= sp); /* it did work */
|
| 468 |
+
}
|
| 469 |
+
ssub = ss + 1;
|
| 470 |
+
esub = ss + OPND(m->g->strip[ss]) - 1;
|
| 471 |
+
assert(OP(m->g->strip[esub]) == OOR1);
|
| 472 |
+
for (;;) { /* find first matching branch */
|
| 473 |
+
if (slow(m, sp, rest, ssub, esub) == rest)
|
| 474 |
+
break; /* it matched all of it */
|
| 475 |
+
/* that one missed, try next one */
|
| 476 |
+
assert(OP(m->g->strip[esub]) == OOR1);
|
| 477 |
+
esub++;
|
| 478 |
+
assert(OP(m->g->strip[esub]) == OOR2);
|
| 479 |
+
ssub = esub + 1;
|
| 480 |
+
esub += OPND(m->g->strip[esub]);
|
| 481 |
+
if (OP(m->g->strip[esub]) == OOR2)
|
| 482 |
+
esub--;
|
| 483 |
+
else
|
| 484 |
+
assert(OP(m->g->strip[esub]) == O_CH);
|
| 485 |
+
}
|
| 486 |
+
{
|
| 487 |
+
const char *dp = dissect(m, sp, rest, ssub, esub);
|
| 488 |
+
(void)dp; /* avoid warning if assertions off */
|
| 489 |
+
assert(dp == rest);
|
| 490 |
+
}
|
| 491 |
+
sp = rest;
|
| 492 |
+
break;
|
| 493 |
+
case O_PLUS:
|
| 494 |
+
case O_QUEST:
|
| 495 |
+
case OOR1:
|
| 496 |
+
case OOR2:
|
| 497 |
+
case O_CH:
|
| 498 |
+
assert(nope);
|
| 499 |
+
break;
|
| 500 |
+
case OLPAREN:
|
| 501 |
+
i = OPND(m->g->strip[ss]);
|
| 502 |
+
assert(0 < i && i <= m->g->nsub);
|
| 503 |
+
m->pmatch[i].rm_so = sp - m->offp;
|
| 504 |
+
break;
|
| 505 |
+
case ORPAREN:
|
| 506 |
+
i = OPND(m->g->strip[ss]);
|
| 507 |
+
assert(0 < i && i <= m->g->nsub);
|
| 508 |
+
m->pmatch[i].rm_eo = sp - m->offp;
|
| 509 |
+
break;
|
| 510 |
+
default: /* uh oh */
|
| 511 |
+
assert(nope);
|
| 512 |
+
break;
|
| 513 |
+
}
|
| 514 |
+
}
|
| 515 |
+
|
| 516 |
+
assert(sp == stop);
|
| 517 |
+
return(sp);
|
| 518 |
+
}
|
| 519 |
+
|
| 520 |
+
/*
|
| 521 |
+
- backref - figure out what matched what, figuring in back references
|
| 522 |
+
*/
|
| 523 |
+
static const char * /* == stop (success) or NULL (failure) */
|
| 524 |
+
backref(struct match *m, const char *start, const char *stop, sopno startst,
|
| 525 |
+
sopno stopst, sopno lev, int rec) /* PLUS nesting level */
|
| 526 |
+
{
|
| 527 |
+
int i;
|
| 528 |
+
sopno ss; /* start sop of current subRE */
|
| 529 |
+
const char *sp; /* start of string matched by it */
|
| 530 |
+
sopno ssub; /* start sop of subsubRE */
|
| 531 |
+
sopno esub; /* end sop of subsubRE */
|
| 532 |
+
const char *ssp; /* start of string matched by subsubRE */
|
| 533 |
+
const char *dp;
|
| 534 |
+
size_t len;
|
| 535 |
+
int hard;
|
| 536 |
+
sop s;
|
| 537 |
+
llvm_regoff_t offsave;
|
| 538 |
+
cset *cs;
|
| 539 |
+
|
| 540 |
+
AT("back", start, stop, startst, stopst);
|
| 541 |
+
sp = start;
|
| 542 |
+
|
| 543 |
+
/* get as far as we can with easy stuff */
|
| 544 |
+
hard = 0;
|
| 545 |
+
for (ss = startst; !hard && ss < stopst; ss++)
|
| 546 |
+
switch (OP(s = m->g->strip[ss])) {
|
| 547 |
+
case OCHAR:
|
| 548 |
+
if (sp == stop || *sp++ != (char)OPND(s))
|
| 549 |
+
return(NULL);
|
| 550 |
+
break;
|
| 551 |
+
case OANY:
|
| 552 |
+
if (sp == stop)
|
| 553 |
+
return(NULL);
|
| 554 |
+
sp++;
|
| 555 |
+
break;
|
| 556 |
+
case OANYOF:
|
| 557 |
+
cs = &m->g->sets[OPND(s)];
|
| 558 |
+
if (sp == stop || !CHIN(cs, *sp++))
|
| 559 |
+
return(NULL);
|
| 560 |
+
break;
|
| 561 |
+
case OBOL:
|
| 562 |
+
if ( (sp == m->beginp && !(m->eflags®_NOTBOL)) ||
|
| 563 |
+
(sp < m->endp && *(sp-1) == '\n' &&
|
| 564 |
+
(m->g->cflags®_NEWLINE)) )
|
| 565 |
+
{ /* yes */ }
|
| 566 |
+
else
|
| 567 |
+
return(NULL);
|
| 568 |
+
break;
|
| 569 |
+
case OEOL:
|
| 570 |
+
if ( (sp == m->endp && !(m->eflags®_NOTEOL)) ||
|
| 571 |
+
(sp < m->endp && *sp == '\n' &&
|
| 572 |
+
(m->g->cflags®_NEWLINE)) )
|
| 573 |
+
{ /* yes */ }
|
| 574 |
+
else
|
| 575 |
+
return(NULL);
|
| 576 |
+
break;
|
| 577 |
+
case OBOW:
|
| 578 |
+
if (( (sp == m->beginp && !(m->eflags®_NOTBOL)) ||
|
| 579 |
+
(sp < m->endp && *(sp-1) == '\n' &&
|
| 580 |
+
(m->g->cflags®_NEWLINE)) ||
|
| 581 |
+
(sp > m->beginp &&
|
| 582 |
+
!ISWORD(*(sp-1))) ) &&
|
| 583 |
+
(sp < m->endp && ISWORD(*sp)) )
|
| 584 |
+
{ /* yes */ }
|
| 585 |
+
else
|
| 586 |
+
return(NULL);
|
| 587 |
+
break;
|
| 588 |
+
case OEOW:
|
| 589 |
+
if (( (sp == m->endp && !(m->eflags®_NOTEOL)) ||
|
| 590 |
+
(sp < m->endp && *sp == '\n' &&
|
| 591 |
+
(m->g->cflags®_NEWLINE)) ||
|
| 592 |
+
(sp < m->endp && !ISWORD(*sp)) ) &&
|
| 593 |
+
(sp > m->beginp && ISWORD(*(sp-1))) )
|
| 594 |
+
{ /* yes */ }
|
| 595 |
+
else
|
| 596 |
+
return(NULL);
|
| 597 |
+
break;
|
| 598 |
+
case O_QUEST:
|
| 599 |
+
case O_CH:
|
| 600 |
+
break;
|
| 601 |
+
case OOR1: /* matches null but needs to skip */
|
| 602 |
+
ss++;
|
| 603 |
+
s = m->g->strip[ss];
|
| 604 |
+
do {
|
| 605 |
+
assert(OP(s) == OOR2);
|
| 606 |
+
ss += OPND(s);
|
| 607 |
+
} while (OP(s = m->g->strip[ss]) != O_CH);
|
| 608 |
+
/* note that the ss++ gets us past the O_CH */
|
| 609 |
+
break;
|
| 610 |
+
default: /* have to make a choice */
|
| 611 |
+
hard = 1;
|
| 612 |
+
break;
|
| 613 |
+
}
|
| 614 |
+
if (!hard) { /* that was it! */
|
| 615 |
+
if (sp != stop)
|
| 616 |
+
return(NULL);
|
| 617 |
+
return(sp);
|
| 618 |
+
}
|
| 619 |
+
ss--; /* adjust for the for's final increment */
|
| 620 |
+
|
| 621 |
+
/* the hard stuff */
|
| 622 |
+
AT("hard", sp, stop, ss, stopst);
|
| 623 |
+
s = m->g->strip[ss];
|
| 624 |
+
switch (OP(s)) {
|
| 625 |
+
case OBACK_: /* the vilest depths */
|
| 626 |
+
i = OPND(s);
|
| 627 |
+
assert(0 < i && i <= m->g->nsub);
|
| 628 |
+
if (m->pmatch[i].rm_eo == -1)
|
| 629 |
+
return(NULL);
|
| 630 |
+
assert(m->pmatch[i].rm_so != -1);
|
| 631 |
+
len = m->pmatch[i].rm_eo - m->pmatch[i].rm_so;
|
| 632 |
+
if (len == 0 && rec++ > MAX_RECURSION)
|
| 633 |
+
return(NULL);
|
| 634 |
+
assert(stop - m->beginp >= len);
|
| 635 |
+
if (sp > stop - len)
|
| 636 |
+
return(NULL); /* not enough left to match */
|
| 637 |
+
ssp = m->offp + m->pmatch[i].rm_so;
|
| 638 |
+
if (memcmp(sp, ssp, len) != 0)
|
| 639 |
+
return(NULL);
|
| 640 |
+
while (m->g->strip[ss] != SOP(O_BACK, i))
|
| 641 |
+
ss++;
|
| 642 |
+
return(backref(m, sp+len, stop, ss+1, stopst, lev, rec));
|
| 643 |
+
break;
|
| 644 |
+
case OQUEST_: /* to null or not */
|
| 645 |
+
dp = backref(m, sp, stop, ss+1, stopst, lev, rec);
|
| 646 |
+
if (dp != NULL)
|
| 647 |
+
return(dp); /* not */
|
| 648 |
+
return(backref(m, sp, stop, ss+OPND(s)+1, stopst, lev, rec));
|
| 649 |
+
break;
|
| 650 |
+
case OPLUS_:
|
| 651 |
+
assert(m->lastpos != NULL);
|
| 652 |
+
assert(lev+1 <= m->g->nplus);
|
| 653 |
+
m->lastpos[lev+1] = sp;
|
| 654 |
+
return(backref(m, sp, stop, ss+1, stopst, lev+1, rec));
|
| 655 |
+
break;
|
| 656 |
+
case O_PLUS:
|
| 657 |
+
if (sp == m->lastpos[lev]) /* last pass matched null */
|
| 658 |
+
return(backref(m, sp, stop, ss+1, stopst, lev-1, rec));
|
| 659 |
+
/* try another pass */
|
| 660 |
+
m->lastpos[lev] = sp;
|
| 661 |
+
dp = backref(m, sp, stop, ss-OPND(s)+1, stopst, lev, rec);
|
| 662 |
+
if (dp == NULL)
|
| 663 |
+
return(backref(m, sp, stop, ss+1, stopst, lev-1, rec));
|
| 664 |
+
else
|
| 665 |
+
return(dp);
|
| 666 |
+
break;
|
| 667 |
+
case OCH_: /* find the right one, if any */
|
| 668 |
+
ssub = ss + 1;
|
| 669 |
+
esub = ss + OPND(s) - 1;
|
| 670 |
+
assert(OP(m->g->strip[esub]) == OOR1);
|
| 671 |
+
for (;;) { /* find first matching branch */
|
| 672 |
+
dp = backref(m, sp, stop, ssub, stopst, lev, rec);
|
| 673 |
+
if (dp != NULL)
|
| 674 |
+
return(dp);
|
| 675 |
+
/* that one missed, try next one */
|
| 676 |
+
if (OP(m->g->strip[esub]) == O_CH)
|
| 677 |
+
return(NULL); /* there is none */
|
| 678 |
+
esub++;
|
| 679 |
+
assert(OP(m->g->strip[esub]) == OOR2);
|
| 680 |
+
ssub = esub + 1;
|
| 681 |
+
esub += OPND(m->g->strip[esub]);
|
| 682 |
+
if (OP(m->g->strip[esub]) == OOR2)
|
| 683 |
+
esub--;
|
| 684 |
+
else
|
| 685 |
+
assert(OP(m->g->strip[esub]) == O_CH);
|
| 686 |
+
}
|
| 687 |
+
break;
|
| 688 |
+
case OLPAREN: /* must undo assignment if rest fails */
|
| 689 |
+
i = OPND(s);
|
| 690 |
+
assert(0 < i && i <= m->g->nsub);
|
| 691 |
+
offsave = m->pmatch[i].rm_so;
|
| 692 |
+
m->pmatch[i].rm_so = sp - m->offp;
|
| 693 |
+
dp = backref(m, sp, stop, ss+1, stopst, lev, rec);
|
| 694 |
+
if (dp != NULL)
|
| 695 |
+
return(dp);
|
| 696 |
+
m->pmatch[i].rm_so = offsave;
|
| 697 |
+
return(NULL);
|
| 698 |
+
break;
|
| 699 |
+
case ORPAREN: /* must undo assignment if rest fails */
|
| 700 |
+
i = OPND(s);
|
| 701 |
+
assert(0 < i && i <= m->g->nsub);
|
| 702 |
+
offsave = m->pmatch[i].rm_eo;
|
| 703 |
+
m->pmatch[i].rm_eo = sp - m->offp;
|
| 704 |
+
dp = backref(m, sp, stop, ss+1, stopst, lev, rec);
|
| 705 |
+
if (dp != NULL)
|
| 706 |
+
return(dp);
|
| 707 |
+
m->pmatch[i].rm_eo = offsave;
|
| 708 |
+
return(NULL);
|
| 709 |
+
break;
|
| 710 |
+
default: /* uh oh */
|
| 711 |
+
assert(nope);
|
| 712 |
+
break;
|
| 713 |
+
}
|
| 714 |
+
|
| 715 |
+
/* "can't happen" */
|
| 716 |
+
assert(nope);
|
| 717 |
+
/* NOTREACHED */
|
| 718 |
+
return NULL;
|
| 719 |
+
}
|
| 720 |
+
|
| 721 |
+
/*
|
| 722 |
+
- fast - step through the string at top speed
|
| 723 |
+
*/
|
| 724 |
+
static const char * /* where tentative match ended, or NULL */
|
| 725 |
+
fast(struct match *m, const char *start, const char *stop, sopno startst,
|
| 726 |
+
sopno stopst)
|
| 727 |
+
{
|
| 728 |
+
states st = m->st;
|
| 729 |
+
states fresh = m->fresh;
|
| 730 |
+
states tmp = m->tmp;
|
| 731 |
+
const char *p = start;
|
| 732 |
+
int c = (start == m->beginp) ? OUT : *(start-1);
|
| 733 |
+
int lastc; /* previous c */
|
| 734 |
+
int flagch;
|
| 735 |
+
int i;
|
| 736 |
+
const char *coldp; /* last p after which no match was underway */
|
| 737 |
+
|
| 738 |
+
CLEAR(st);
|
| 739 |
+
SET1(st, startst);
|
| 740 |
+
st = step(m->g, startst, stopst, st, NOTHING, st);
|
| 741 |
+
ASSIGN(fresh, st);
|
| 742 |
+
SP("start", st, *p);
|
| 743 |
+
coldp = NULL;
|
| 744 |
+
for (;;) {
|
| 745 |
+
/* next character */
|
| 746 |
+
lastc = c;
|
| 747 |
+
c = (p == m->endp) ? OUT : *p;
|
| 748 |
+
if (EQ(st, fresh))
|
| 749 |
+
coldp = p;
|
| 750 |
+
|
| 751 |
+
/* is there an EOL and/or BOL between lastc and c? */
|
| 752 |
+
flagch = '\0';
|
| 753 |
+
i = 0;
|
| 754 |
+
if ( (lastc == '\n' && m->g->cflags®_NEWLINE) ||
|
| 755 |
+
(lastc == OUT && !(m->eflags®_NOTBOL)) ) {
|
| 756 |
+
flagch = BOL;
|
| 757 |
+
i = m->g->nbol;
|
| 758 |
+
}
|
| 759 |
+
if ( (c == '\n' && m->g->cflags®_NEWLINE) ||
|
| 760 |
+
(c == OUT && !(m->eflags®_NOTEOL)) ) {
|
| 761 |
+
flagch = (flagch == BOL) ? BOLEOL : EOL;
|
| 762 |
+
i += m->g->neol;
|
| 763 |
+
}
|
| 764 |
+
if (i != 0) {
|
| 765 |
+
for (; i > 0; i--)
|
| 766 |
+
st = step(m->g, startst, stopst, st, flagch, st);
|
| 767 |
+
SP("boleol", st, c);
|
| 768 |
+
}
|
| 769 |
+
|
| 770 |
+
/* how about a word boundary? */
|
| 771 |
+
if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
|
| 772 |
+
(c != OUT && ISWORD(c)) ) {
|
| 773 |
+
flagch = BOW;
|
| 774 |
+
}
|
| 775 |
+
if ( (lastc != OUT && ISWORD(lastc)) &&
|
| 776 |
+
(flagch == EOL || (c != OUT && !ISWORD(c))) ) {
|
| 777 |
+
flagch = EOW;
|
| 778 |
+
}
|
| 779 |
+
if (flagch == BOW || flagch == EOW) {
|
| 780 |
+
st = step(m->g, startst, stopst, st, flagch, st);
|
| 781 |
+
SP("boweow", st, c);
|
| 782 |
+
}
|
| 783 |
+
|
| 784 |
+
/* are we done? */
|
| 785 |
+
if (ISSET(st, stopst) || p == stop)
|
| 786 |
+
break; /* NOTE BREAK OUT */
|
| 787 |
+
|
| 788 |
+
/* no, we must deal with this character */
|
| 789 |
+
ASSIGN(tmp, st);
|
| 790 |
+
ASSIGN(st, fresh);
|
| 791 |
+
assert(c != OUT);
|
| 792 |
+
st = step(m->g, startst, stopst, tmp, c, st);
|
| 793 |
+
SP("aft", st, c);
|
| 794 |
+
assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
|
| 795 |
+
p++;
|
| 796 |
+
}
|
| 797 |
+
|
| 798 |
+
assert(coldp != NULL);
|
| 799 |
+
m->coldp = coldp;
|
| 800 |
+
if (ISSET(st, stopst))
|
| 801 |
+
return(p+1);
|
| 802 |
+
else
|
| 803 |
+
return(NULL);
|
| 804 |
+
}
|
| 805 |
+
|
| 806 |
+
/*
|
| 807 |
+
- slow - step through the string more deliberately
|
| 808 |
+
*/
|
| 809 |
+
static const char * /* where it ended */
|
| 810 |
+
slow(struct match *m, const char *start, const char *stop, sopno startst,
|
| 811 |
+
sopno stopst)
|
| 812 |
+
{
|
| 813 |
+
/* Quickly skip over fixed character matches at the start. */
|
| 814 |
+
const char *p = start;
|
| 815 |
+
for (; startst < stopst; ++startst) {
|
| 816 |
+
int hard = 0;
|
| 817 |
+
sop s = m->g->strip[startst];
|
| 818 |
+
switch (OP(s)) {
|
| 819 |
+
case OLPAREN:
|
| 820 |
+
case ORPAREN:
|
| 821 |
+
/* Not relevant here. */
|
| 822 |
+
break;
|
| 823 |
+
case OCHAR:
|
| 824 |
+
if (p == stop || *p != (char)OPND(s))
|
| 825 |
+
return NULL;
|
| 826 |
+
++p;
|
| 827 |
+
break;
|
| 828 |
+
default:
|
| 829 |
+
hard = 1;
|
| 830 |
+
break;
|
| 831 |
+
}
|
| 832 |
+
if (hard)
|
| 833 |
+
break;
|
| 834 |
+
}
|
| 835 |
+
|
| 836 |
+
states st = m->st;
|
| 837 |
+
states empty = m->empty;
|
| 838 |
+
states tmp = m->tmp;
|
| 839 |
+
int c = (p == m->beginp) ? OUT : *(p-1);
|
| 840 |
+
int lastc; /* previous c */
|
| 841 |
+
int flagch;
|
| 842 |
+
int i;
|
| 843 |
+
const char *matchp; /* last p at which a match ended */
|
| 844 |
+
|
| 845 |
+
AT("slow", start, stop, startst, stopst);
|
| 846 |
+
CLEAR(st);
|
| 847 |
+
SET1(st, startst);
|
| 848 |
+
SP("sstart", st, *p);
|
| 849 |
+
st = step(m->g, startst, stopst, st, NOTHING, st);
|
| 850 |
+
matchp = NULL;
|
| 851 |
+
for (;;) {
|
| 852 |
+
/* next character */
|
| 853 |
+
lastc = c;
|
| 854 |
+
c = (p == m->endp) ? OUT : *p;
|
| 855 |
+
|
| 856 |
+
/* is there an EOL and/or BOL between lastc and c? */
|
| 857 |
+
flagch = '\0';
|
| 858 |
+
i = 0;
|
| 859 |
+
if ( (lastc == '\n' && m->g->cflags®_NEWLINE) ||
|
| 860 |
+
(lastc == OUT && !(m->eflags®_NOTBOL)) ) {
|
| 861 |
+
flagch = BOL;
|
| 862 |
+
i = m->g->nbol;
|
| 863 |
+
}
|
| 864 |
+
if ( (c == '\n' && m->g->cflags®_NEWLINE) ||
|
| 865 |
+
(c == OUT && !(m->eflags®_NOTEOL)) ) {
|
| 866 |
+
flagch = (flagch == BOL) ? BOLEOL : EOL;
|
| 867 |
+
i += m->g->neol;
|
| 868 |
+
}
|
| 869 |
+
if (i != 0) {
|
| 870 |
+
for (; i > 0; i--)
|
| 871 |
+
st = step(m->g, startst, stopst, st, flagch, st);
|
| 872 |
+
SP("sboleol", st, c);
|
| 873 |
+
}
|
| 874 |
+
|
| 875 |
+
/* how about a word boundary? */
|
| 876 |
+
if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
|
| 877 |
+
(c != OUT && ISWORD(c)) ) {
|
| 878 |
+
flagch = BOW;
|
| 879 |
+
}
|
| 880 |
+
if ( (lastc != OUT && ISWORD(lastc)) &&
|
| 881 |
+
(flagch == EOL || (c != OUT && !ISWORD(c))) ) {
|
| 882 |
+
flagch = EOW;
|
| 883 |
+
}
|
| 884 |
+
if (flagch == BOW || flagch == EOW) {
|
| 885 |
+
st = step(m->g, startst, stopst, st, flagch, st);
|
| 886 |
+
SP("sboweow", st, c);
|
| 887 |
+
}
|
| 888 |
+
|
| 889 |
+
/* are we done? */
|
| 890 |
+
if (ISSET(st, stopst))
|
| 891 |
+
matchp = p;
|
| 892 |
+
if (EQ(st, empty) || p == stop)
|
| 893 |
+
break; /* NOTE BREAK OUT */
|
| 894 |
+
|
| 895 |
+
/* no, we must deal with this character */
|
| 896 |
+
ASSIGN(tmp, st);
|
| 897 |
+
ASSIGN(st, empty);
|
| 898 |
+
assert(c != OUT);
|
| 899 |
+
st = step(m->g, startst, stopst, tmp, c, st);
|
| 900 |
+
SP("saft", st, c);
|
| 901 |
+
assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
|
| 902 |
+
p++;
|
| 903 |
+
}
|
| 904 |
+
|
| 905 |
+
return(matchp);
|
| 906 |
+
}
|
| 907 |
+
|
| 908 |
+
|
| 909 |
+
/*
|
| 910 |
+
- step - map set of states reachable before char to set reachable after
|
| 911 |
+
*/
|
| 912 |
+
static states
|
| 913 |
+
step(struct re_guts *g,
|
| 914 |
+
sopno start, /* start state within strip */
|
| 915 |
+
sopno stop, /* state after stop state within strip */
|
| 916 |
+
states bef, /* states reachable before */
|
| 917 |
+
int ch, /* character or NONCHAR code */
|
| 918 |
+
states aft) /* states already known reachable after */
|
| 919 |
+
{
|
| 920 |
+
cset *cs;
|
| 921 |
+
sop s;
|
| 922 |
+
sopno pc;
|
| 923 |
+
onestate here; /* note, macros know this name */
|
| 924 |
+
sopno look;
|
| 925 |
+
int i;
|
| 926 |
+
|
| 927 |
+
for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) {
|
| 928 |
+
s = g->strip[pc];
|
| 929 |
+
switch (OP(s)) {
|
| 930 |
+
case OEND:
|
| 931 |
+
assert(pc == stop-1);
|
| 932 |
+
break;
|
| 933 |
+
case OCHAR:
|
| 934 |
+
/* only characters can match */
|
| 935 |
+
assert(!NONCHAR(ch) || ch != (char)OPND(s));
|
| 936 |
+
if (ch == (char)OPND(s))
|
| 937 |
+
FWD(aft, bef, 1);
|
| 938 |
+
break;
|
| 939 |
+
case OBOL:
|
| 940 |
+
if (ch == BOL || ch == BOLEOL)
|
| 941 |
+
FWD(aft, bef, 1);
|
| 942 |
+
break;
|
| 943 |
+
case OEOL:
|
| 944 |
+
if (ch == EOL || ch == BOLEOL)
|
| 945 |
+
FWD(aft, bef, 1);
|
| 946 |
+
break;
|
| 947 |
+
case OBOW:
|
| 948 |
+
if (ch == BOW)
|
| 949 |
+
FWD(aft, bef, 1);
|
| 950 |
+
break;
|
| 951 |
+
case OEOW:
|
| 952 |
+
if (ch == EOW)
|
| 953 |
+
FWD(aft, bef, 1);
|
| 954 |
+
break;
|
| 955 |
+
case OANY:
|
| 956 |
+
if (!NONCHAR(ch))
|
| 957 |
+
FWD(aft, bef, 1);
|
| 958 |
+
break;
|
| 959 |
+
case OANYOF:
|
| 960 |
+
cs = &g->sets[OPND(s)];
|
| 961 |
+
if (!NONCHAR(ch) && CHIN(cs, ch))
|
| 962 |
+
FWD(aft, bef, 1);
|
| 963 |
+
break;
|
| 964 |
+
case OBACK_: /* ignored here */
|
| 965 |
+
case O_BACK:
|
| 966 |
+
FWD(aft, aft, 1);
|
| 967 |
+
break;
|
| 968 |
+
case OPLUS_: /* forward, this is just an empty */
|
| 969 |
+
FWD(aft, aft, 1);
|
| 970 |
+
break;
|
| 971 |
+
case O_PLUS: /* both forward and back */
|
| 972 |
+
FWD(aft, aft, 1);
|
| 973 |
+
i = ISSETBACK(aft, OPND(s));
|
| 974 |
+
BACK(aft, aft, OPND(s));
|
| 975 |
+
if (!i && ISSETBACK(aft, OPND(s))) {
|
| 976 |
+
/* oho, must reconsider loop body */
|
| 977 |
+
pc -= OPND(s) + 1;
|
| 978 |
+
INIT(here, pc);
|
| 979 |
+
}
|
| 980 |
+
break;
|
| 981 |
+
case OQUEST_: /* two branches, both forward */
|
| 982 |
+
FWD(aft, aft, 1);
|
| 983 |
+
FWD(aft, aft, OPND(s));
|
| 984 |
+
break;
|
| 985 |
+
case O_QUEST: /* just an empty */
|
| 986 |
+
FWD(aft, aft, 1);
|
| 987 |
+
break;
|
| 988 |
+
case OLPAREN: /* not significant here */
|
| 989 |
+
case ORPAREN:
|
| 990 |
+
FWD(aft, aft, 1);
|
| 991 |
+
break;
|
| 992 |
+
case OCH_: /* mark the first two branches */
|
| 993 |
+
FWD(aft, aft, 1);
|
| 994 |
+
assert(OP(g->strip[pc+OPND(s)]) == OOR2);
|
| 995 |
+
FWD(aft, aft, OPND(s));
|
| 996 |
+
break;
|
| 997 |
+
case OOR1: /* done a branch, find the O_CH */
|
| 998 |
+
if (ISSTATEIN(aft, here)) {
|
| 999 |
+
for (look = 1;
|
| 1000 |
+
OP(s = g->strip[pc+look]) != O_CH;
|
| 1001 |
+
look += OPND(s))
|
| 1002 |
+
assert(OP(s) == OOR2);
|
| 1003 |
+
FWD(aft, aft, look);
|
| 1004 |
+
}
|
| 1005 |
+
break;
|
| 1006 |
+
case OOR2: /* propagate OCH_'s marking */
|
| 1007 |
+
FWD(aft, aft, 1);
|
| 1008 |
+
if (OP(g->strip[pc+OPND(s)]) != O_CH) {
|
| 1009 |
+
assert(OP(g->strip[pc+OPND(s)]) == OOR2);
|
| 1010 |
+
FWD(aft, aft, OPND(s));
|
| 1011 |
+
}
|
| 1012 |
+
break;
|
| 1013 |
+
case O_CH: /* just empty */
|
| 1014 |
+
FWD(aft, aft, 1);
|
| 1015 |
+
break;
|
| 1016 |
+
default: /* ooooops... */
|
| 1017 |
+
assert(nope);
|
| 1018 |
+
break;
|
| 1019 |
+
}
|
| 1020 |
+
}
|
| 1021 |
+
|
| 1022 |
+
return(aft);
|
| 1023 |
+
}
|
| 1024 |
+
|
| 1025 |
+
#ifdef REDEBUG
|
| 1026 |
+
/*
|
| 1027 |
+
- print - print a set of states
|
| 1028 |
+
*/
|
| 1029 |
+
static void
|
| 1030 |
+
print(struct match *m, const char *caption, states st, int ch, FILE *d)
|
| 1031 |
+
{
|
| 1032 |
+
struct re_guts *g = m->g;
|
| 1033 |
+
int i;
|
| 1034 |
+
int first = 1;
|
| 1035 |
+
|
| 1036 |
+
if (!(m->eflags®_TRACE))
|
| 1037 |
+
return;
|
| 1038 |
+
|
| 1039 |
+
(void)fprintf(d, "%s", caption);
|
| 1040 |
+
if (ch != '\0')
|
| 1041 |
+
(void)fprintf(d, " %s", pchar(ch));
|
| 1042 |
+
for (i = 0; i < g->nstates; i++)
|
| 1043 |
+
if (ISSET(st, i)) {
|
| 1044 |
+
(void)fprintf(d, "%s%d", (first) ? "\t" : ", ", i);
|
| 1045 |
+
first = 0;
|
| 1046 |
+
}
|
| 1047 |
+
(void)fprintf(d, "\n");
|
| 1048 |
+
}
|
| 1049 |
+
|
| 1050 |
+
/*
|
| 1051 |
+
- at - print current situation
|
| 1052 |
+
*/
|
| 1053 |
+
static void
|
| 1054 |
+
at(struct match *m, const char *title, const char *start, const char *stop,
|
| 1055 |
+
sopno startst, sopno stopst)
|
| 1056 |
+
{
|
| 1057 |
+
if (!(m->eflags®_TRACE))
|
| 1058 |
+
return;
|
| 1059 |
+
|
| 1060 |
+
(void)printf("%s %s-", title, pchar(*start));
|
| 1061 |
+
(void)printf("%s ", pchar(*stop));
|
| 1062 |
+
(void)printf("%ld-%ld\n", (long)startst, (long)stopst);
|
| 1063 |
+
}
|
| 1064 |
+
|
| 1065 |
+
#ifndef PCHARDONE
|
| 1066 |
+
#define PCHARDONE /* never again */
|
| 1067 |
+
/*
|
| 1068 |
+
- pchar - make a character printable
|
| 1069 |
+
*
|
| 1070 |
+
* Is this identical to regchar() over in debug.c? Well, yes. But a
|
| 1071 |
+
* duplicate here avoids having a debugging-capable regexec.o tied to
|
| 1072 |
+
* a matching debug.o, and this is convenient. It all disappears in
|
| 1073 |
+
* the non-debug compilation anyway, so it doesn't matter much.
|
| 1074 |
+
*/
|
| 1075 |
+
static char * /* -> representation */
|
| 1076 |
+
pchar(int ch)
|
| 1077 |
+
{
|
| 1078 |
+
static char pbuf[10];
|
| 1079 |
+
|
| 1080 |
+
if (isprint(ch) || ch == ' ')
|
| 1081 |
+
(void)snprintf(pbuf, sizeof pbuf, "%c", ch);
|
| 1082 |
+
else
|
| 1083 |
+
(void)snprintf(pbuf, sizeof pbuf, "\\%o", ch);
|
| 1084 |
+
return(pbuf);
|
| 1085 |
+
}
|
| 1086 |
+
#endif
|
| 1087 |
+
#endif
|
| 1088 |
+
|
| 1089 |
+
#undef matcher
|
| 1090 |
+
#undef fast
|
| 1091 |
+
#undef slow
|
| 1092 |
+
#undef dissect
|
| 1093 |
+
#undef backref
|
| 1094 |
+
#undef step
|
| 1095 |
+
#undef print
|
| 1096 |
+
#undef at
|
| 1097 |
+
#undef match
|
| 1098 |
+
#undef nope
|
| 1099 |
+
#undef step_back
|
deps/exla/cache/xla_extension/include/llvm/lib/Support/regex2.h
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|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
|
| 3 |
+
*
|
| 4 |
+
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
|
| 5 |
+
* Copyright (c) 1992, 1993, 1994
|
| 6 |
+
* The Regents of the University of California. All rights reserved.
|
| 7 |
+
*
|
| 8 |
+
* This code is derived from software contributed to Berkeley by
|
| 9 |
+
* Henry Spencer.
|
| 10 |
+
*
|
| 11 |
+
* Redistribution and use in source and binary forms, with or without
|
| 12 |
+
* modification, are permitted provided that the following conditions
|
| 13 |
+
* are met:
|
| 14 |
+
* 1. Redistributions of source code must retain the above copyright
|
| 15 |
+
* notice, this list of conditions and the following disclaimer.
|
| 16 |
+
* 2. Redistributions in binary form must reproduce the above copyright
|
| 17 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 18 |
+
* documentation and/or other materials provided with the distribution.
|
| 19 |
+
* 3. Neither the name of the University nor the names of its contributors
|
| 20 |
+
* may be used to endorse or promote products derived from this software
|
| 21 |
+
* without specific prior written permission.
|
| 22 |
+
*
|
| 23 |
+
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
| 24 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 25 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 26 |
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
| 27 |
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 28 |
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
| 29 |
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
| 30 |
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 31 |
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
| 32 |
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
| 33 |
+
* SUCH DAMAGE.
|
| 34 |
+
*
|
| 35 |
+
* @(#)regex2.h 8.4 (Berkeley) 3/20/94
|
| 36 |
+
*/
|
| 37 |
+
|
| 38 |
+
#ifndef LLVM_SUPPORT_REGEX2_H
|
| 39 |
+
#define LLVM_SUPPORT_REGEX2_H
|
| 40 |
+
|
| 41 |
+
#include "regutils.h"
|
| 42 |
+
#include <stddef.h>
|
| 43 |
+
|
| 44 |
+
/*
|
| 45 |
+
* internals of regex_t
|
| 46 |
+
*/
|
| 47 |
+
#define MAGIC1 ((('r'^0200)<<8) | 'e')
|
| 48 |
+
|
| 49 |
+
/*
|
| 50 |
+
* The internal representation is a *strip*, a sequence of
|
| 51 |
+
* operators ending with an endmarker. (Some terminology etc. is a
|
| 52 |
+
* historical relic of earlier versions which used multiple strips.)
|
| 53 |
+
* Certain oddities in the representation are there to permit running
|
| 54 |
+
* the machinery backwards; in particular, any deviation from sequential
|
| 55 |
+
* flow must be marked at both its source and its destination. Some
|
| 56 |
+
* fine points:
|
| 57 |
+
*
|
| 58 |
+
* - OPLUS_ and O_PLUS are *inside* the loop they create.
|
| 59 |
+
* - OQUEST_ and O_QUEST are *outside* the bypass they create.
|
| 60 |
+
* - OCH_ and O_CH are *outside* the multi-way branch they create, while
|
| 61 |
+
* OOR1 and OOR2 are respectively the end and the beginning of one of
|
| 62 |
+
* the branches. Note that there is an implicit OOR2 following OCH_
|
| 63 |
+
* and an implicit OOR1 preceding O_CH.
|
| 64 |
+
*
|
| 65 |
+
* In state representations, an operator's bit is on to signify a state
|
| 66 |
+
* immediately *preceding* "execution" of that operator.
|
| 67 |
+
*/
|
| 68 |
+
typedef unsigned long sop; /* strip operator */
|
| 69 |
+
typedef long sopno;
|
| 70 |
+
#define OPRMASK 0xf8000000LU
|
| 71 |
+
#define OPDMASK 0x07ffffffLU
|
| 72 |
+
#define OPSHIFT ((unsigned)27)
|
| 73 |
+
#define OP(n) ((n)&OPRMASK)
|
| 74 |
+
#define OPND(n) ((n)&OPDMASK)
|
| 75 |
+
#define SOP(op, opnd) ((op)|(opnd))
|
| 76 |
+
/* operators meaning operand */
|
| 77 |
+
/* (back, fwd are offsets) */
|
| 78 |
+
#define OEND (1LU<<OPSHIFT) /* endmarker - */
|
| 79 |
+
#define OCHAR (2LU<<OPSHIFT) /* character unsigned char */
|
| 80 |
+
#define OBOL (3LU<<OPSHIFT) /* left anchor - */
|
| 81 |
+
#define OEOL (4LU<<OPSHIFT) /* right anchor - */
|
| 82 |
+
#define OANY (5LU<<OPSHIFT) /* . - */
|
| 83 |
+
#define OANYOF (6LU<<OPSHIFT) /* [...] set number */
|
| 84 |
+
#define OBACK_ (7LU<<OPSHIFT) /* begin \d paren number */
|
| 85 |
+
#define O_BACK (8LU<<OPSHIFT) /* end \d paren number */
|
| 86 |
+
#define OPLUS_ (9LU<<OPSHIFT) /* + prefix fwd to suffix */
|
| 87 |
+
#define O_PLUS (10LU<<OPSHIFT) /* + suffix back to prefix */
|
| 88 |
+
#define OQUEST_ (11LU<<OPSHIFT) /* ? prefix fwd to suffix */
|
| 89 |
+
#define O_QUEST (12LU<<OPSHIFT) /* ? suffix back to prefix */
|
| 90 |
+
#define OLPAREN (13LU<<OPSHIFT) /* ( fwd to ) */
|
| 91 |
+
#define ORPAREN (14LU<<OPSHIFT) /* ) back to ( */
|
| 92 |
+
#define OCH_ (15LU<<OPSHIFT) /* begin choice fwd to OOR2 */
|
| 93 |
+
#define OOR1 (16LU<<OPSHIFT) /* | pt. 1 back to OOR1 or OCH_ */
|
| 94 |
+
#define OOR2 (17LU<<OPSHIFT) /* | pt. 2 fwd to OOR2 or O_CH */
|
| 95 |
+
#define O_CH (18LU<<OPSHIFT) /* end choice back to OOR1 */
|
| 96 |
+
#define OBOW (19LU<<OPSHIFT) /* begin word - */
|
| 97 |
+
#define OEOW (20LU<<OPSHIFT) /* end word - */
|
| 98 |
+
|
| 99 |
+
/*
|
| 100 |
+
* Structure for [] character-set representation. Character sets are
|
| 101 |
+
* done as bit vectors, grouped 8 to a byte vector for compactness.
|
| 102 |
+
* The individual set therefore has both a pointer to the byte vector
|
| 103 |
+
* and a mask to pick out the relevant bit of each byte. A hash code
|
| 104 |
+
* simplifies testing whether two sets could be identical.
|
| 105 |
+
*
|
| 106 |
+
* This will get trickier for multicharacter collating elements. As
|
| 107 |
+
* preliminary hooks for dealing with such things, we also carry along
|
| 108 |
+
* a string of multi-character elements, and decide the size of the
|
| 109 |
+
* vectors at run time.
|
| 110 |
+
*/
|
| 111 |
+
typedef struct {
|
| 112 |
+
uch *ptr; /* -> uch [csetsize] */
|
| 113 |
+
uch mask; /* bit within array */
|
| 114 |
+
uch hash; /* hash code */
|
| 115 |
+
size_t smultis;
|
| 116 |
+
char *multis; /* -> char[smulti] ab\0cd\0ef\0\0 */
|
| 117 |
+
} cset;
|
| 118 |
+
/* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */
|
| 119 |
+
#define CHadd(cs, c) ((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (c))
|
| 120 |
+
#define CHsub(cs, c) ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (c))
|
| 121 |
+
#define CHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask)
|
| 122 |
+
#define MCadd(p, cs, cp) mcadd(p, cs, cp) /* llvm_regcomp() internal fns */
|
| 123 |
+
#define MCsub(p, cs, cp) mcsub(p, cs, cp)
|
| 124 |
+
#define MCin(p, cs, cp) mcin(p, cs, cp)
|
| 125 |
+
|
| 126 |
+
/* stuff for character categories */
|
| 127 |
+
typedef unsigned char cat_t;
|
| 128 |
+
|
| 129 |
+
/*
|
| 130 |
+
* main compiled-expression structure
|
| 131 |
+
*/
|
| 132 |
+
struct re_guts {
|
| 133 |
+
int magic;
|
| 134 |
+
# define MAGIC2 ((('R'^0200)<<8)|'E')
|
| 135 |
+
sop *strip; /* malloced area for strip */
|
| 136 |
+
int csetsize; /* number of bits in a cset vector */
|
| 137 |
+
int ncsets; /* number of csets in use */
|
| 138 |
+
cset *sets; /* -> cset [ncsets] */
|
| 139 |
+
uch *setbits; /* -> uch[csetsize][ncsets/CHAR_BIT] */
|
| 140 |
+
int cflags; /* copy of llvm_regcomp() cflags argument */
|
| 141 |
+
sopno nstates; /* = number of sops */
|
| 142 |
+
sopno firststate; /* the initial OEND (normally 0) */
|
| 143 |
+
sopno laststate; /* the final OEND */
|
| 144 |
+
int iflags; /* internal flags */
|
| 145 |
+
# define USEBOL 01 /* used ^ */
|
| 146 |
+
# define USEEOL 02 /* used $ */
|
| 147 |
+
# define REGEX_BAD 04 /* something wrong */
|
| 148 |
+
int nbol; /* number of ^ used */
|
| 149 |
+
int neol; /* number of $ used */
|
| 150 |
+
int ncategories; /* how many character categories */
|
| 151 |
+
cat_t *categories; /* ->catspace[-CHAR_MIN] */
|
| 152 |
+
char *must; /* match must contain this string */
|
| 153 |
+
int mlen; /* length of must */
|
| 154 |
+
size_t nsub; /* copy of re_nsub */
|
| 155 |
+
int backrefs; /* does it use back references? */
|
| 156 |
+
sopno nplus; /* how deep does it nest +s? */
|
| 157 |
+
/* catspace must be last */
|
| 158 |
+
cat_t catspace[1]; /* actually [NC] */
|
| 159 |
+
};
|
| 160 |
+
|
| 161 |
+
/* misc utilities */
|
| 162 |
+
#define OUT (CHAR_MAX+1) /* a non-character value */
|
| 163 |
+
#define ISWORD(c) (isalnum(c&0xff) || (c) == '_')
|
| 164 |
+
|
| 165 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/lib/Support/regex_impl.h
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*-
|
| 2 |
+
* This code is derived from OpenBSD's libc/regex, original license follows:
|
| 3 |
+
*
|
| 4 |
+
* Copyright (c) 1992 Henry Spencer.
|
| 5 |
+
* Copyright (c) 1992, 1993
|
| 6 |
+
* The Regents of the University of California. All rights reserved.
|
| 7 |
+
*
|
| 8 |
+
* This code is derived from software contributed to Berkeley by
|
| 9 |
+
* Henry Spencer of the University of Toronto.
|
| 10 |
+
*
|
| 11 |
+
* Redistribution and use in source and binary forms, with or without
|
| 12 |
+
* modification, are permitted provided that the following conditions
|
| 13 |
+
* are met:
|
| 14 |
+
* 1. Redistributions of source code must retain the above copyright
|
| 15 |
+
* notice, this list of conditions and the following disclaimer.
|
| 16 |
+
* 2. Redistributions in binary form must reproduce the above copyright
|
| 17 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 18 |
+
* documentation and/or other materials provided with the distribution.
|
| 19 |
+
* 3. Neither the name of the University nor the names of its contributors
|
| 20 |
+
* may be used to endorse or promote products derived from this software
|
| 21 |
+
* without specific prior written permission.
|
| 22 |
+
*
|
| 23 |
+
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
| 24 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 25 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 26 |
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
| 27 |
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 28 |
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
| 29 |
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
| 30 |
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 31 |
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
| 32 |
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
| 33 |
+
* SUCH DAMAGE.
|
| 34 |
+
*
|
| 35 |
+
* @(#)regex.h 8.1 (Berkeley) 6/2/93
|
| 36 |
+
*/
|
| 37 |
+
|
| 38 |
+
#ifndef LLVM_SUPPORT_REGEX_IMPL_H
|
| 39 |
+
#define LLVM_SUPPORT_REGEX_IMPL_H
|
| 40 |
+
|
| 41 |
+
#include <sys/types.h>
|
| 42 |
+
typedef off_t llvm_regoff_t;
|
| 43 |
+
typedef struct {
|
| 44 |
+
llvm_regoff_t rm_so; /* start of match */
|
| 45 |
+
llvm_regoff_t rm_eo; /* end of match */
|
| 46 |
+
} llvm_regmatch_t;
|
| 47 |
+
|
| 48 |
+
typedef struct llvm_regex {
|
| 49 |
+
int re_magic;
|
| 50 |
+
size_t re_nsub; /* number of parenthesized subexpressions */
|
| 51 |
+
const char *re_endp; /* end pointer for REG_PEND */
|
| 52 |
+
struct re_guts *re_g; /* none of your business :-) */
|
| 53 |
+
} llvm_regex_t;
|
| 54 |
+
|
| 55 |
+
/* llvm_regcomp() flags */
|
| 56 |
+
#define REG_BASIC 0000
|
| 57 |
+
#define REG_EXTENDED 0001
|
| 58 |
+
#define REG_ICASE 0002
|
| 59 |
+
#define REG_NOSUB 0004
|
| 60 |
+
#define REG_NEWLINE 0010
|
| 61 |
+
#define REG_NOSPEC 0020
|
| 62 |
+
#define REG_PEND 0040
|
| 63 |
+
#define REG_DUMP 0200
|
| 64 |
+
|
| 65 |
+
/* llvm_regerror() flags */
|
| 66 |
+
#define REG_NOMATCH 1
|
| 67 |
+
#define REG_BADPAT 2
|
| 68 |
+
#define REG_ECOLLATE 3
|
| 69 |
+
#define REG_ECTYPE 4
|
| 70 |
+
#define REG_EESCAPE 5
|
| 71 |
+
#define REG_ESUBREG 6
|
| 72 |
+
#define REG_EBRACK 7
|
| 73 |
+
#define REG_EPAREN 8
|
| 74 |
+
#define REG_EBRACE 9
|
| 75 |
+
#define REG_BADBR 10
|
| 76 |
+
#define REG_ERANGE 11
|
| 77 |
+
#define REG_ESPACE 12
|
| 78 |
+
#define REG_BADRPT 13
|
| 79 |
+
#define REG_EMPTY 14
|
| 80 |
+
#define REG_ASSERT 15
|
| 81 |
+
#define REG_INVARG 16
|
| 82 |
+
#define REG_ATOI 255 /* convert name to number (!) */
|
| 83 |
+
#define REG_ITOA 0400 /* convert number to name (!) */
|
| 84 |
+
|
| 85 |
+
/* llvm_regexec() flags */
|
| 86 |
+
#define REG_NOTBOL 00001
|
| 87 |
+
#define REG_NOTEOL 00002
|
| 88 |
+
#define REG_STARTEND 00004
|
| 89 |
+
#define REG_TRACE 00400 /* tracing of execution */
|
| 90 |
+
#define REG_LARGE 01000 /* force large representation */
|
| 91 |
+
#define REG_BACKR 02000 /* force use of backref code */
|
| 92 |
+
|
| 93 |
+
#ifdef __cplusplus
|
| 94 |
+
extern "C" {
|
| 95 |
+
#endif
|
| 96 |
+
|
| 97 |
+
int llvm_regcomp(llvm_regex_t *, const char *, int);
|
| 98 |
+
size_t llvm_regerror(int, const llvm_regex_t *, char *, size_t);
|
| 99 |
+
int llvm_regexec(const llvm_regex_t *, const char *, size_t,
|
| 100 |
+
llvm_regmatch_t [], int);
|
| 101 |
+
void llvm_regfree(llvm_regex_t *);
|
| 102 |
+
size_t llvm_strlcpy(char *dst, const char *src, size_t siz);
|
| 103 |
+
|
| 104 |
+
#ifdef __cplusplus
|
| 105 |
+
}
|
| 106 |
+
#endif
|
| 107 |
+
|
| 108 |
+
#endif /* LLVM_SUPPORT_REGEX_IMPL_H */
|
deps/exla/cache/xla_extension/include/llvm/lib/Support/regutils.h
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*-
|
| 2 |
+
* This code is derived from OpenBSD's libc/regex, original license follows:
|
| 3 |
+
*
|
| 4 |
+
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
|
| 5 |
+
* Copyright (c) 1992, 1993, 1994
|
| 6 |
+
* The Regents of the University of California. All rights reserved.
|
| 7 |
+
*
|
| 8 |
+
* This code is derived from software contributed to Berkeley by
|
| 9 |
+
* Henry Spencer.
|
| 10 |
+
*
|
| 11 |
+
* Redistribution and use in source and binary forms, with or without
|
| 12 |
+
* modification, are permitted provided that the following conditions
|
| 13 |
+
* are met:
|
| 14 |
+
* 1. Redistributions of source code must retain the above copyright
|
| 15 |
+
* notice, this list of conditions and the following disclaimer.
|
| 16 |
+
* 2. Redistributions in binary form must reproduce the above copyright
|
| 17 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 18 |
+
* documentation and/or other materials provided with the distribution.
|
| 19 |
+
* 3. Neither the name of the University nor the names of its contributors
|
| 20 |
+
* may be used to endorse or promote products derived from this software
|
| 21 |
+
* without specific prior written permission.
|
| 22 |
+
*
|
| 23 |
+
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
| 24 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 25 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 26 |
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
| 27 |
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 28 |
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
| 29 |
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
| 30 |
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 31 |
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
| 32 |
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
| 33 |
+
* SUCH DAMAGE.
|
| 34 |
+
*
|
| 35 |
+
* @(#)utils.h 8.3 (Berkeley) 3/20/94
|
| 36 |
+
*/
|
| 37 |
+
|
| 38 |
+
#ifndef LLVM_SUPPORT_REGUTILS_H
|
| 39 |
+
#define LLVM_SUPPORT_REGUTILS_H
|
| 40 |
+
|
| 41 |
+
/* utility definitions */
|
| 42 |
+
#define NC (CHAR_MAX - CHAR_MIN + 1)
|
| 43 |
+
typedef unsigned char uch;
|
| 44 |
+
|
| 45 |
+
/* switch off assertions (if not already off) if no REDEBUG */
|
| 46 |
+
#ifndef REDEBUG
|
| 47 |
+
#ifndef NDEBUG
|
| 48 |
+
#define NDEBUG /* no assertions please */
|
| 49 |
+
#endif
|
| 50 |
+
#endif
|
| 51 |
+
#include <assert.h>
|
| 52 |
+
|
| 53 |
+
/* for old systems with bcopy() but no memmove() */
|
| 54 |
+
#ifdef USEBCOPY
|
| 55 |
+
#define memmove(d, s, c) bcopy(s, d, c)
|
| 56 |
+
#endif
|
| 57 |
+
|
| 58 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/ImmutableGraph.h
ADDED
|
@@ -0,0 +1,445 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//==========-- ImmutableGraph.h - A fast DAG implementation ---------=========//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
/// \file
|
| 9 |
+
/// Description: ImmutableGraph is a fast DAG implementation that cannot be
|
| 10 |
+
/// modified, except by creating a new ImmutableGraph. ImmutableGraph is
|
| 11 |
+
/// implemented as two arrays: one containing nodes, and one containing edges.
|
| 12 |
+
/// The advantages to this implementation are two-fold:
|
| 13 |
+
/// 1. Iteration and traversal operations benefit from cache locality.
|
| 14 |
+
/// 2. Operations on sets of nodes/edges are efficient, and representations of
|
| 15 |
+
/// those sets in memory are compact. For instance, a set of edges is
|
| 16 |
+
/// implemented as a bit vector, wherein each bit corresponds to one edge in
|
| 17 |
+
/// the edge array. This implies a lower bound of 64x spatial improvement
|
| 18 |
+
/// over, e.g., an llvm::DenseSet or llvm::SmallSet. It also means that
|
| 19 |
+
/// insert/erase/contains operations complete in negligible constant time:
|
| 20 |
+
/// insert and erase require one load and one store, and contains requires
|
| 21 |
+
/// just one load.
|
| 22 |
+
///
|
| 23 |
+
//===----------------------------------------------------------------------===//
|
| 24 |
+
|
| 25 |
+
#ifndef LLVM_LIB_TARGET_X86_IMMUTABLEGRAPH_H
|
| 26 |
+
#define LLVM_LIB_TARGET_X86_IMMUTABLEGRAPH_H
|
| 27 |
+
|
| 28 |
+
#include "llvm/ADT/BitVector.h"
|
| 29 |
+
#include "llvm/ADT/GraphTraits.h"
|
| 30 |
+
#include "llvm/ADT/STLExtras.h"
|
| 31 |
+
#include <algorithm>
|
| 32 |
+
#include <iterator>
|
| 33 |
+
#include <utility>
|
| 34 |
+
#include <vector>
|
| 35 |
+
|
| 36 |
+
namespace llvm {
|
| 37 |
+
|
| 38 |
+
template <typename NodeValueT, typename EdgeValueT> class ImmutableGraph {
|
| 39 |
+
using Traits = GraphTraits<ImmutableGraph<NodeValueT, EdgeValueT> *>;
|
| 40 |
+
template <typename> friend class ImmutableGraphBuilder;
|
| 41 |
+
|
| 42 |
+
public:
|
| 43 |
+
using node_value_type = NodeValueT;
|
| 44 |
+
using edge_value_type = EdgeValueT;
|
| 45 |
+
using size_type = int;
|
| 46 |
+
class Node;
|
| 47 |
+
class Edge {
|
| 48 |
+
friend class ImmutableGraph;
|
| 49 |
+
template <typename> friend class ImmutableGraphBuilder;
|
| 50 |
+
|
| 51 |
+
const Node *Dest;
|
| 52 |
+
edge_value_type Value;
|
| 53 |
+
|
| 54 |
+
public:
|
| 55 |
+
const Node *getDest() const { return Dest; };
|
| 56 |
+
const edge_value_type &getValue() const { return Value; }
|
| 57 |
+
};
|
| 58 |
+
class Node {
|
| 59 |
+
friend class ImmutableGraph;
|
| 60 |
+
template <typename> friend class ImmutableGraphBuilder;
|
| 61 |
+
|
| 62 |
+
const Edge *Edges;
|
| 63 |
+
node_value_type Value;
|
| 64 |
+
|
| 65 |
+
public:
|
| 66 |
+
const node_value_type &getValue() const { return Value; }
|
| 67 |
+
|
| 68 |
+
const Edge *edges_begin() const { return Edges; }
|
| 69 |
+
// Nodes are allocated sequentially. Edges for a node are stored together.
|
| 70 |
+
// The end of this Node's edges is the beginning of the next node's edges.
|
| 71 |
+
// An extra node was allocated to hold the end pointer for the last real
|
| 72 |
+
// node.
|
| 73 |
+
const Edge *edges_end() const { return (this + 1)->Edges; }
|
| 74 |
+
ArrayRef<Edge> edges() const {
|
| 75 |
+
return ArrayRef(edges_begin(), edges_end());
|
| 76 |
+
}
|
| 77 |
+
};
|
| 78 |
+
|
| 79 |
+
protected:
|
| 80 |
+
ImmutableGraph(std::unique_ptr<Node[]> Nodes, std::unique_ptr<Edge[]> Edges,
|
| 81 |
+
size_type NodesSize, size_type EdgesSize)
|
| 82 |
+
: Nodes(std::move(Nodes)), Edges(std::move(Edges)), NodesSize(NodesSize),
|
| 83 |
+
EdgesSize(EdgesSize) {}
|
| 84 |
+
ImmutableGraph(const ImmutableGraph &) = delete;
|
| 85 |
+
ImmutableGraph(ImmutableGraph &&) = delete;
|
| 86 |
+
ImmutableGraph &operator=(const ImmutableGraph &) = delete;
|
| 87 |
+
ImmutableGraph &operator=(ImmutableGraph &&) = delete;
|
| 88 |
+
|
| 89 |
+
public:
|
| 90 |
+
ArrayRef<Node> nodes() const { return ArrayRef(Nodes.get(), NodesSize); }
|
| 91 |
+
const Node *nodes_begin() const { return nodes().begin(); }
|
| 92 |
+
const Node *nodes_end() const { return nodes().end(); }
|
| 93 |
+
|
| 94 |
+
ArrayRef<Edge> edges() const { return ArrayRef(Edges.get(), EdgesSize); }
|
| 95 |
+
const Edge *edges_begin() const { return edges().begin(); }
|
| 96 |
+
const Edge *edges_end() const { return edges().end(); }
|
| 97 |
+
|
| 98 |
+
size_type nodes_size() const { return NodesSize; }
|
| 99 |
+
size_type edges_size() const { return EdgesSize; }
|
| 100 |
+
|
| 101 |
+
// Node N must belong to this ImmutableGraph.
|
| 102 |
+
size_type getNodeIndex(const Node &N) const {
|
| 103 |
+
return std::distance(nodes_begin(), &N);
|
| 104 |
+
}
|
| 105 |
+
// Edge E must belong to this ImmutableGraph.
|
| 106 |
+
size_type getEdgeIndex(const Edge &E) const {
|
| 107 |
+
return std::distance(edges_begin(), &E);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
// FIXME: Could NodeSet and EdgeSet be templated to share code?
|
| 111 |
+
class NodeSet {
|
| 112 |
+
const ImmutableGraph &G;
|
| 113 |
+
BitVector V;
|
| 114 |
+
|
| 115 |
+
public:
|
| 116 |
+
NodeSet(const ImmutableGraph &G, bool ContainsAll = false)
|
| 117 |
+
: G{G}, V{static_cast<unsigned>(G.nodes_size()), ContainsAll} {}
|
| 118 |
+
bool insert(const Node &N) {
|
| 119 |
+
size_type Idx = G.getNodeIndex(N);
|
| 120 |
+
bool AlreadyExists = V.test(Idx);
|
| 121 |
+
V.set(Idx);
|
| 122 |
+
return !AlreadyExists;
|
| 123 |
+
}
|
| 124 |
+
void erase(const Node &N) {
|
| 125 |
+
size_type Idx = G.getNodeIndex(N);
|
| 126 |
+
V.reset(Idx);
|
| 127 |
+
}
|
| 128 |
+
bool contains(const Node &N) const {
|
| 129 |
+
size_type Idx = G.getNodeIndex(N);
|
| 130 |
+
return V.test(Idx);
|
| 131 |
+
}
|
| 132 |
+
void clear() { V.reset(); }
|
| 133 |
+
size_type empty() const { return V.none(); }
|
| 134 |
+
/// Return the number of elements in the set
|
| 135 |
+
size_type count() const { return V.count(); }
|
| 136 |
+
/// Return the size of the set's domain
|
| 137 |
+
size_type size() const { return V.size(); }
|
| 138 |
+
/// Set union
|
| 139 |
+
NodeSet &operator|=(const NodeSet &RHS) {
|
| 140 |
+
assert(&this->G == &RHS.G);
|
| 141 |
+
V |= RHS.V;
|
| 142 |
+
return *this;
|
| 143 |
+
}
|
| 144 |
+
/// Set intersection
|
| 145 |
+
NodeSet &operator&=(const NodeSet &RHS) {
|
| 146 |
+
assert(&this->G == &RHS.G);
|
| 147 |
+
V &= RHS.V;
|
| 148 |
+
return *this;
|
| 149 |
+
}
|
| 150 |
+
/// Set disjoint union
|
| 151 |
+
NodeSet &operator^=(const NodeSet &RHS) {
|
| 152 |
+
assert(&this->G == &RHS.G);
|
| 153 |
+
V ^= RHS.V;
|
| 154 |
+
return *this;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
using index_iterator = typename BitVector::const_set_bits_iterator;
|
| 158 |
+
index_iterator index_begin() const { return V.set_bits_begin(); }
|
| 159 |
+
index_iterator index_end() const { return V.set_bits_end(); }
|
| 160 |
+
void set(size_type Idx) { V.set(Idx); }
|
| 161 |
+
void reset(size_type Idx) { V.reset(Idx); }
|
| 162 |
+
|
| 163 |
+
class iterator {
|
| 164 |
+
const NodeSet &Set;
|
| 165 |
+
size_type Current;
|
| 166 |
+
|
| 167 |
+
void advance() {
|
| 168 |
+
assert(Current != -1);
|
| 169 |
+
Current = Set.V.find_next(Current);
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
public:
|
| 173 |
+
iterator(const NodeSet &Set, size_type Begin)
|
| 174 |
+
: Set{Set}, Current{Begin} {}
|
| 175 |
+
iterator operator++(int) {
|
| 176 |
+
iterator Tmp = *this;
|
| 177 |
+
advance();
|
| 178 |
+
return Tmp;
|
| 179 |
+
}
|
| 180 |
+
iterator &operator++() {
|
| 181 |
+
advance();
|
| 182 |
+
return *this;
|
| 183 |
+
}
|
| 184 |
+
Node *operator*() const {
|
| 185 |
+
assert(Current != -1);
|
| 186 |
+
return Set.G.nodes_begin() + Current;
|
| 187 |
+
}
|
| 188 |
+
bool operator==(const iterator &other) const {
|
| 189 |
+
assert(&this->Set == &other.Set);
|
| 190 |
+
return this->Current == other.Current;
|
| 191 |
+
}
|
| 192 |
+
bool operator!=(const iterator &other) const { return !(*this == other); }
|
| 193 |
+
};
|
| 194 |
+
|
| 195 |
+
iterator begin() const { return iterator{*this, V.find_first()}; }
|
| 196 |
+
iterator end() const { return iterator{*this, -1}; }
|
| 197 |
+
};
|
| 198 |
+
|
| 199 |
+
class EdgeSet {
|
| 200 |
+
const ImmutableGraph &G;
|
| 201 |
+
BitVector V;
|
| 202 |
+
|
| 203 |
+
public:
|
| 204 |
+
EdgeSet(const ImmutableGraph &G, bool ContainsAll = false)
|
| 205 |
+
: G{G}, V{static_cast<unsigned>(G.edges_size()), ContainsAll} {}
|
| 206 |
+
bool insert(const Edge &E) {
|
| 207 |
+
size_type Idx = G.getEdgeIndex(E);
|
| 208 |
+
bool AlreadyExists = V.test(Idx);
|
| 209 |
+
V.set(Idx);
|
| 210 |
+
return !AlreadyExists;
|
| 211 |
+
}
|
| 212 |
+
void erase(const Edge &E) {
|
| 213 |
+
size_type Idx = G.getEdgeIndex(E);
|
| 214 |
+
V.reset(Idx);
|
| 215 |
+
}
|
| 216 |
+
bool contains(const Edge &E) const {
|
| 217 |
+
size_type Idx = G.getEdgeIndex(E);
|
| 218 |
+
return V.test(Idx);
|
| 219 |
+
}
|
| 220 |
+
void clear() { V.reset(); }
|
| 221 |
+
bool empty() const { return V.none(); }
|
| 222 |
+
/// Return the number of elements in the set
|
| 223 |
+
size_type count() const { return V.count(); }
|
| 224 |
+
/// Return the size of the set's domain
|
| 225 |
+
size_type size() const { return V.size(); }
|
| 226 |
+
/// Set union
|
| 227 |
+
EdgeSet &operator|=(const EdgeSet &RHS) {
|
| 228 |
+
assert(&this->G == &RHS.G);
|
| 229 |
+
V |= RHS.V;
|
| 230 |
+
return *this;
|
| 231 |
+
}
|
| 232 |
+
/// Set intersection
|
| 233 |
+
EdgeSet &operator&=(const EdgeSet &RHS) {
|
| 234 |
+
assert(&this->G == &RHS.G);
|
| 235 |
+
V &= RHS.V;
|
| 236 |
+
return *this;
|
| 237 |
+
}
|
| 238 |
+
/// Set disjoint union
|
| 239 |
+
EdgeSet &operator^=(const EdgeSet &RHS) {
|
| 240 |
+
assert(&this->G == &RHS.G);
|
| 241 |
+
V ^= RHS.V;
|
| 242 |
+
return *this;
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
using index_iterator = typename BitVector::const_set_bits_iterator;
|
| 246 |
+
index_iterator index_begin() const { return V.set_bits_begin(); }
|
| 247 |
+
index_iterator index_end() const { return V.set_bits_end(); }
|
| 248 |
+
void set(size_type Idx) { V.set(Idx); }
|
| 249 |
+
void reset(size_type Idx) { V.reset(Idx); }
|
| 250 |
+
|
| 251 |
+
class iterator {
|
| 252 |
+
const EdgeSet &Set;
|
| 253 |
+
size_type Current;
|
| 254 |
+
|
| 255 |
+
void advance() {
|
| 256 |
+
assert(Current != -1);
|
| 257 |
+
Current = Set.V.find_next(Current);
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
public:
|
| 261 |
+
iterator(const EdgeSet &Set, size_type Begin)
|
| 262 |
+
: Set{Set}, Current{Begin} {}
|
| 263 |
+
iterator operator++(int) {
|
| 264 |
+
iterator Tmp = *this;
|
| 265 |
+
advance();
|
| 266 |
+
return Tmp;
|
| 267 |
+
}
|
| 268 |
+
iterator &operator++() {
|
| 269 |
+
advance();
|
| 270 |
+
return *this;
|
| 271 |
+
}
|
| 272 |
+
Edge *operator*() const {
|
| 273 |
+
assert(Current != -1);
|
| 274 |
+
return Set.G.edges_begin() + Current;
|
| 275 |
+
}
|
| 276 |
+
bool operator==(const iterator &other) const {
|
| 277 |
+
assert(&this->Set == &other.Set);
|
| 278 |
+
return this->Current == other.Current;
|
| 279 |
+
}
|
| 280 |
+
bool operator!=(const iterator &other) const { return !(*this == other); }
|
| 281 |
+
};
|
| 282 |
+
|
| 283 |
+
iterator begin() const { return iterator{*this, V.find_first()}; }
|
| 284 |
+
iterator end() const { return iterator{*this, -1}; }
|
| 285 |
+
};
|
| 286 |
+
|
| 287 |
+
private:
|
| 288 |
+
std::unique_ptr<Node[]> Nodes;
|
| 289 |
+
std::unique_ptr<Edge[]> Edges;
|
| 290 |
+
size_type NodesSize;
|
| 291 |
+
size_type EdgesSize;
|
| 292 |
+
};
|
| 293 |
+
|
| 294 |
+
template <typename GraphT> class ImmutableGraphBuilder {
|
| 295 |
+
using node_value_type = typename GraphT::node_value_type;
|
| 296 |
+
using edge_value_type = typename GraphT::edge_value_type;
|
| 297 |
+
static_assert(
|
| 298 |
+
std::is_base_of<ImmutableGraph<node_value_type, edge_value_type>,
|
| 299 |
+
GraphT>::value,
|
| 300 |
+
"Template argument to ImmutableGraphBuilder must derive from "
|
| 301 |
+
"ImmutableGraph<>");
|
| 302 |
+
using size_type = typename GraphT::size_type;
|
| 303 |
+
using NodeSet = typename GraphT::NodeSet;
|
| 304 |
+
using Node = typename GraphT::Node;
|
| 305 |
+
using EdgeSet = typename GraphT::EdgeSet;
|
| 306 |
+
using Edge = typename GraphT::Edge;
|
| 307 |
+
using BuilderEdge = std::pair<edge_value_type, size_type>;
|
| 308 |
+
using EdgeList = std::vector<BuilderEdge>;
|
| 309 |
+
using BuilderVertex = std::pair<node_value_type, EdgeList>;
|
| 310 |
+
using VertexVec = std::vector<BuilderVertex>;
|
| 311 |
+
|
| 312 |
+
public:
|
| 313 |
+
using BuilderNodeRef = size_type;
|
| 314 |
+
|
| 315 |
+
BuilderNodeRef addVertex(const node_value_type &V) {
|
| 316 |
+
auto I = AdjList.emplace(AdjList.end(), V, EdgeList{});
|
| 317 |
+
return std::distance(AdjList.begin(), I);
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
void addEdge(const edge_value_type &E, BuilderNodeRef From,
|
| 321 |
+
BuilderNodeRef To) {
|
| 322 |
+
AdjList[From].second.emplace_back(E, To);
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
bool empty() const { return AdjList.empty(); }
|
| 326 |
+
|
| 327 |
+
template <typename... ArgT> std::unique_ptr<GraphT> get(ArgT &&... Args) {
|
| 328 |
+
size_type VertexSize = AdjList.size(), EdgeSize = 0;
|
| 329 |
+
for (const auto &V : AdjList) {
|
| 330 |
+
EdgeSize += V.second.size();
|
| 331 |
+
}
|
| 332 |
+
auto VertexArray =
|
| 333 |
+
std::make_unique<Node[]>(VertexSize + 1 /* terminator node */);
|
| 334 |
+
auto EdgeArray = std::make_unique<Edge[]>(EdgeSize);
|
| 335 |
+
size_type VI = 0, EI = 0;
|
| 336 |
+
for (; VI < VertexSize; ++VI) {
|
| 337 |
+
VertexArray[VI].Value = std::move(AdjList[VI].first);
|
| 338 |
+
VertexArray[VI].Edges = &EdgeArray[EI];
|
| 339 |
+
auto NumEdges = static_cast<size_type>(AdjList[VI].second.size());
|
| 340 |
+
for (size_type VEI = 0; VEI < NumEdges; ++VEI, ++EI) {
|
| 341 |
+
auto &E = AdjList[VI].second[VEI];
|
| 342 |
+
EdgeArray[EI].Value = std::move(E.first);
|
| 343 |
+
EdgeArray[EI].Dest = &VertexArray[E.second];
|
| 344 |
+
}
|
| 345 |
+
}
|
| 346 |
+
assert(VI == VertexSize && EI == EdgeSize && "ImmutableGraph malformed");
|
| 347 |
+
VertexArray[VI].Edges = &EdgeArray[EdgeSize]; // terminator node
|
| 348 |
+
return std::make_unique<GraphT>(std::move(VertexArray),
|
| 349 |
+
std::move(EdgeArray), VertexSize, EdgeSize,
|
| 350 |
+
std::forward<ArgT>(Args)...);
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
template <typename... ArgT>
|
| 354 |
+
static std::unique_ptr<GraphT> trim(const GraphT &G, const NodeSet &TrimNodes,
|
| 355 |
+
const EdgeSet &TrimEdges,
|
| 356 |
+
ArgT &&... Args) {
|
| 357 |
+
size_type NewVertexSize = G.nodes_size() - TrimNodes.count();
|
| 358 |
+
size_type NewEdgeSize = G.edges_size() - TrimEdges.count();
|
| 359 |
+
auto NewVertexArray =
|
| 360 |
+
std::make_unique<Node[]>(NewVertexSize + 1 /* terminator node */);
|
| 361 |
+
auto NewEdgeArray = std::make_unique<Edge[]>(NewEdgeSize);
|
| 362 |
+
|
| 363 |
+
// Walk the nodes and determine the new index for each node.
|
| 364 |
+
size_type NewNodeIndex = 0;
|
| 365 |
+
std::vector<size_type> RemappedNodeIndex(G.nodes_size());
|
| 366 |
+
for (const Node &N : G.nodes()) {
|
| 367 |
+
if (TrimNodes.contains(N))
|
| 368 |
+
continue;
|
| 369 |
+
RemappedNodeIndex[G.getNodeIndex(N)] = NewNodeIndex++;
|
| 370 |
+
}
|
| 371 |
+
assert(NewNodeIndex == NewVertexSize &&
|
| 372 |
+
"Should have assigned NewVertexSize indices");
|
| 373 |
+
|
| 374 |
+
size_type VertexI = 0, EdgeI = 0;
|
| 375 |
+
for (const Node &N : G.nodes()) {
|
| 376 |
+
if (TrimNodes.contains(N))
|
| 377 |
+
continue;
|
| 378 |
+
NewVertexArray[VertexI].Value = N.getValue();
|
| 379 |
+
NewVertexArray[VertexI].Edges = &NewEdgeArray[EdgeI];
|
| 380 |
+
for (const Edge &E : N.edges()) {
|
| 381 |
+
if (TrimEdges.contains(E))
|
| 382 |
+
continue;
|
| 383 |
+
NewEdgeArray[EdgeI].Value = E.getValue();
|
| 384 |
+
size_type DestIdx = G.getNodeIndex(*E.getDest());
|
| 385 |
+
size_type NewIdx = RemappedNodeIndex[DestIdx];
|
| 386 |
+
assert(NewIdx < NewVertexSize);
|
| 387 |
+
NewEdgeArray[EdgeI].Dest = &NewVertexArray[NewIdx];
|
| 388 |
+
++EdgeI;
|
| 389 |
+
}
|
| 390 |
+
++VertexI;
|
| 391 |
+
}
|
| 392 |
+
assert(VertexI == NewVertexSize && EdgeI == NewEdgeSize &&
|
| 393 |
+
"Gadget graph malformed");
|
| 394 |
+
NewVertexArray[VertexI].Edges = &NewEdgeArray[NewEdgeSize]; // terminator
|
| 395 |
+
return std::make_unique<GraphT>(std::move(NewVertexArray),
|
| 396 |
+
std::move(NewEdgeArray), NewVertexSize,
|
| 397 |
+
NewEdgeSize, std::forward<ArgT>(Args)...);
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
private:
|
| 401 |
+
VertexVec AdjList;
|
| 402 |
+
};
|
| 403 |
+
|
| 404 |
+
template <typename NodeValueT, typename EdgeValueT>
|
| 405 |
+
struct GraphTraits<ImmutableGraph<NodeValueT, EdgeValueT> *> {
|
| 406 |
+
using GraphT = ImmutableGraph<NodeValueT, EdgeValueT>;
|
| 407 |
+
using NodeRef = typename GraphT::Node const *;
|
| 408 |
+
using EdgeRef = typename GraphT::Edge const &;
|
| 409 |
+
|
| 410 |
+
static NodeRef edge_dest(EdgeRef E) { return E.getDest(); }
|
| 411 |
+
using ChildIteratorType =
|
| 412 |
+
mapped_iterator<typename GraphT::Edge const *, decltype(&edge_dest)>;
|
| 413 |
+
|
| 414 |
+
static NodeRef getEntryNode(GraphT *G) { return G->nodes_begin(); }
|
| 415 |
+
static ChildIteratorType child_begin(NodeRef N) {
|
| 416 |
+
return {N->edges_begin(), &edge_dest};
|
| 417 |
+
}
|
| 418 |
+
static ChildIteratorType child_end(NodeRef N) {
|
| 419 |
+
return {N->edges_end(), &edge_dest};
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
static NodeRef getNode(typename GraphT::Node const &N) { return NodeRef{&N}; }
|
| 423 |
+
using nodes_iterator =
|
| 424 |
+
mapped_iterator<typename GraphT::Node const *, decltype(&getNode)>;
|
| 425 |
+
static nodes_iterator nodes_begin(GraphT *G) {
|
| 426 |
+
return {G->nodes_begin(), &getNode};
|
| 427 |
+
}
|
| 428 |
+
static nodes_iterator nodes_end(GraphT *G) {
|
| 429 |
+
return {G->nodes_end(), &getNode};
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
using ChildEdgeIteratorType = typename GraphT::Edge const *;
|
| 433 |
+
|
| 434 |
+
static ChildEdgeIteratorType child_edge_begin(NodeRef N) {
|
| 435 |
+
return N->edges_begin();
|
| 436 |
+
}
|
| 437 |
+
static ChildEdgeIteratorType child_edge_end(NodeRef N) {
|
| 438 |
+
return N->edges_end();
|
| 439 |
+
}
|
| 440 |
+
static typename GraphT::size_type size(GraphT *G) { return G->nodes_size(); }
|
| 441 |
+
};
|
| 442 |
+
|
| 443 |
+
} // end namespace llvm
|
| 444 |
+
|
| 445 |
+
#endif // LLVM_LIB_TARGET_X86_IMMUTABLEGRAPH_H
|
deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86.h
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===-- X86.h - Top-level interface for X86 representation ------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file contains the entry points for global functions defined in the x86
|
| 10 |
+
// target library, as used by the LLVM JIT.
|
| 11 |
+
//
|
| 12 |
+
//===----------------------------------------------------------------------===//
|
| 13 |
+
|
| 14 |
+
#ifndef LLVM_LIB_TARGET_X86_X86_H
|
| 15 |
+
#define LLVM_LIB_TARGET_X86_X86_H
|
| 16 |
+
|
| 17 |
+
#include "llvm/Support/CodeGen.h"
|
| 18 |
+
|
| 19 |
+
namespace llvm {
|
| 20 |
+
|
| 21 |
+
class FunctionPass;
|
| 22 |
+
class InstructionSelector;
|
| 23 |
+
class PassRegistry;
|
| 24 |
+
class X86RegisterBankInfo;
|
| 25 |
+
class X86Subtarget;
|
| 26 |
+
class X86TargetMachine;
|
| 27 |
+
|
| 28 |
+
/// This pass converts a legalized DAG into a X86-specific DAG, ready for
|
| 29 |
+
/// instruction scheduling.
|
| 30 |
+
FunctionPass *createX86ISelDag(X86TargetMachine &TM, CodeGenOptLevel OptLevel);
|
| 31 |
+
|
| 32 |
+
/// This pass initializes a global base register for PIC on x86-32.
|
| 33 |
+
FunctionPass *createX86GlobalBaseRegPass();
|
| 34 |
+
|
| 35 |
+
/// This pass combines multiple accesses to local-dynamic TLS variables so that
|
| 36 |
+
/// the TLS base address for the module is only fetched once per execution path
|
| 37 |
+
/// through the function.
|
| 38 |
+
FunctionPass *createCleanupLocalDynamicTLSPass();
|
| 39 |
+
|
| 40 |
+
/// This function returns a pass which converts floating-point register
|
| 41 |
+
/// references and pseudo instructions into floating-point stack references and
|
| 42 |
+
/// physical instructions.
|
| 43 |
+
FunctionPass *createX86FloatingPointStackifierPass();
|
| 44 |
+
|
| 45 |
+
/// This pass inserts AVX vzeroupper instructions before each call to avoid
|
| 46 |
+
/// transition penalty between functions encoded with AVX and SSE.
|
| 47 |
+
FunctionPass *createX86IssueVZeroUpperPass();
|
| 48 |
+
|
| 49 |
+
/// This pass inserts ENDBR instructions before indirect jump/call
|
| 50 |
+
/// destinations as part of CET IBT mechanism.
|
| 51 |
+
FunctionPass *createX86IndirectBranchTrackingPass();
|
| 52 |
+
|
| 53 |
+
/// Return a pass that pads short functions with NOOPs.
|
| 54 |
+
/// This will prevent a stall when returning on the Atom.
|
| 55 |
+
FunctionPass *createX86PadShortFunctions();
|
| 56 |
+
|
| 57 |
+
/// Return a pass that selectively replaces certain instructions (like add,
|
| 58 |
+
/// sub, inc, dec, some shifts, and some multiplies) by equivalent LEA
|
| 59 |
+
/// instructions, in order to eliminate execution delays in some processors.
|
| 60 |
+
FunctionPass *createX86FixupLEAs();
|
| 61 |
+
|
| 62 |
+
/// Return a pass that replaces equivalent slower instructions with faster
|
| 63 |
+
/// ones.
|
| 64 |
+
FunctionPass *createX86FixupInstTuning();
|
| 65 |
+
|
| 66 |
+
/// Return a pass that reduces the size of vector constant pool loads.
|
| 67 |
+
FunctionPass *createX86FixupVectorConstants();
|
| 68 |
+
|
| 69 |
+
/// Return a pass that removes redundant LEA instructions and redundant address
|
| 70 |
+
/// recalculations.
|
| 71 |
+
FunctionPass *createX86OptimizeLEAs();
|
| 72 |
+
|
| 73 |
+
/// Return a pass that transforms setcc + movzx pairs into xor + setcc.
|
| 74 |
+
FunctionPass *createX86FixupSetCC();
|
| 75 |
+
|
| 76 |
+
/// Return a pass that transform inline buffer security check into seperate bb
|
| 77 |
+
FunctionPass *createX86WinFixupBufferSecurityCheckPass();
|
| 78 |
+
|
| 79 |
+
/// Return a pass that avoids creating store forward block issues in the hardware.
|
| 80 |
+
FunctionPass *createX86AvoidStoreForwardingBlocks();
|
| 81 |
+
|
| 82 |
+
/// Return a pass that lowers EFLAGS copy pseudo instructions.
|
| 83 |
+
FunctionPass *createX86FlagsCopyLoweringPass();
|
| 84 |
+
|
| 85 |
+
/// Return a pass that expands DynAlloca pseudo-instructions.
|
| 86 |
+
FunctionPass *createX86DynAllocaExpander();
|
| 87 |
+
|
| 88 |
+
/// Return a pass that config the tile registers.
|
| 89 |
+
FunctionPass *createX86TileConfigPass();
|
| 90 |
+
|
| 91 |
+
/// Return a pass that preconfig the tile registers before fast reg allocation.
|
| 92 |
+
FunctionPass *createX86FastPreTileConfigPass();
|
| 93 |
+
|
| 94 |
+
/// Return a pass that config the tile registers after fast reg allocation.
|
| 95 |
+
FunctionPass *createX86FastTileConfigPass();
|
| 96 |
+
|
| 97 |
+
/// Return a pass that insert pseudo tile config instruction.
|
| 98 |
+
FunctionPass *createX86PreTileConfigPass();
|
| 99 |
+
|
| 100 |
+
/// Return a pass that lower the tile copy instruction.
|
| 101 |
+
FunctionPass *createX86LowerTileCopyPass();
|
| 102 |
+
|
| 103 |
+
/// Return a pass that inserts int3 at the end of the function if it ends with a
|
| 104 |
+
/// CALL instruction. The pass does the same for each funclet as well. This
|
| 105 |
+
/// ensures that the open interval of function start and end PCs contains all
|
| 106 |
+
/// return addresses for the benefit of the Windows x64 unwinder.
|
| 107 |
+
FunctionPass *createX86AvoidTrailingCallPass();
|
| 108 |
+
|
| 109 |
+
/// Return a pass that optimizes the code-size of x86 call sequences. This is
|
| 110 |
+
/// done by replacing esp-relative movs with pushes.
|
| 111 |
+
FunctionPass *createX86CallFrameOptimization();
|
| 112 |
+
|
| 113 |
+
/// Return an IR pass that inserts EH registration stack objects and explicit
|
| 114 |
+
/// EH state updates. This pass must run after EH preparation, which does
|
| 115 |
+
/// Windows-specific but architecture-neutral preparation.
|
| 116 |
+
FunctionPass *createX86WinEHStatePass();
|
| 117 |
+
|
| 118 |
+
/// Return a Machine IR pass that expands X86-specific pseudo
|
| 119 |
+
/// instructions into a sequence of actual instructions. This pass
|
| 120 |
+
/// must run after prologue/epilogue insertion and before lowering
|
| 121 |
+
/// the MachineInstr to MC.
|
| 122 |
+
FunctionPass *createX86ExpandPseudoPass();
|
| 123 |
+
|
| 124 |
+
/// This pass converts X86 cmov instructions into branch when profitable.
|
| 125 |
+
FunctionPass *createX86CmovConverterPass();
|
| 126 |
+
|
| 127 |
+
/// Return a Machine IR pass that selectively replaces
|
| 128 |
+
/// certain byte and word instructions by equivalent 32 bit instructions,
|
| 129 |
+
/// in order to eliminate partial register usage, false dependences on
|
| 130 |
+
/// the upper portions of registers, and to save code size.
|
| 131 |
+
FunctionPass *createX86FixupBWInsts();
|
| 132 |
+
|
| 133 |
+
/// Return a Machine IR pass that reassigns instruction chains from one domain
|
| 134 |
+
/// to another, when profitable.
|
| 135 |
+
FunctionPass *createX86DomainReassignmentPass();
|
| 136 |
+
|
| 137 |
+
/// This pass compress instructions from EVEX space to legacy/VEX/EVEX space when
|
| 138 |
+
/// possible in order to reduce code size or facilitate HW decoding.
|
| 139 |
+
FunctionPass *createX86CompressEVEXPass();
|
| 140 |
+
|
| 141 |
+
/// This pass creates the thunks for the retpoline feature.
|
| 142 |
+
FunctionPass *createX86IndirectThunksPass();
|
| 143 |
+
|
| 144 |
+
/// This pass replaces ret instructions with jmp's to __x86_return thunk.
|
| 145 |
+
FunctionPass *createX86ReturnThunksPass();
|
| 146 |
+
|
| 147 |
+
/// This pass ensures instructions featuring a memory operand
|
| 148 |
+
/// have distinctive <LineNumber, Discriminator> (with respect to each other)
|
| 149 |
+
FunctionPass *createX86DiscriminateMemOpsPass();
|
| 150 |
+
|
| 151 |
+
/// This pass applies profiling information to insert cache prefetches.
|
| 152 |
+
FunctionPass *createX86InsertPrefetchPass();
|
| 153 |
+
|
| 154 |
+
/// This pass insert wait instruction after X87 instructions which could raise
|
| 155 |
+
/// fp exceptions when strict-fp enabled.
|
| 156 |
+
FunctionPass *createX86InsertX87waitPass();
|
| 157 |
+
|
| 158 |
+
/// This pass optimizes arithmetic based on knowledge that is only used by
|
| 159 |
+
/// a reduction sequence and is therefore safe to reassociate in interesting
|
| 160 |
+
/// ways.
|
| 161 |
+
FunctionPass *createX86PartialReductionPass();
|
| 162 |
+
|
| 163 |
+
/// // Analyzes and emits pseudos to support Win x64 Unwind V2.
|
| 164 |
+
FunctionPass *createX86WinEHUnwindV2Pass();
|
| 165 |
+
|
| 166 |
+
InstructionSelector *createX86InstructionSelector(const X86TargetMachine &TM,
|
| 167 |
+
const X86Subtarget &,
|
| 168 |
+
const X86RegisterBankInfo &);
|
| 169 |
+
|
| 170 |
+
FunctionPass *createX86LoadValueInjectionLoadHardeningPass();
|
| 171 |
+
FunctionPass *createX86LoadValueInjectionRetHardeningPass();
|
| 172 |
+
FunctionPass *createX86SpeculativeLoadHardeningPass();
|
| 173 |
+
FunctionPass *createX86SpeculativeExecutionSideEffectSuppression();
|
| 174 |
+
FunctionPass *createX86ArgumentStackSlotPass();
|
| 175 |
+
FunctionPass *createX86SuppressAPXForRelocationPass();
|
| 176 |
+
|
| 177 |
+
void initializeCompressEVEXPassPass(PassRegistry &);
|
| 178 |
+
void initializeFPSPass(PassRegistry &);
|
| 179 |
+
void initializeFixupBWInstPassPass(PassRegistry &);
|
| 180 |
+
void initializeFixupLEAPassPass(PassRegistry &);
|
| 181 |
+
void initializeX86ArgumentStackSlotPassPass(PassRegistry &);
|
| 182 |
+
void initializeX86AsmPrinterPass(PassRegistry &);
|
| 183 |
+
void initializeX86FixupInstTuningPassPass(PassRegistry &);
|
| 184 |
+
void initializeX86FixupVectorConstantsPassPass(PassRegistry &);
|
| 185 |
+
void initializeWinEHStatePassPass(PassRegistry &);
|
| 186 |
+
void initializeX86AvoidSFBPassPass(PassRegistry &);
|
| 187 |
+
void initializeX86AvoidTrailingCallPassPass(PassRegistry &);
|
| 188 |
+
void initializeX86CallFrameOptimizationPass(PassRegistry &);
|
| 189 |
+
void initializeX86CmovConverterPassPass(PassRegistry &);
|
| 190 |
+
void initializeX86DAGToDAGISelLegacyPass(PassRegistry &);
|
| 191 |
+
void initializeX86DomainReassignmentPass(PassRegistry &);
|
| 192 |
+
void initializeX86DynAllocaExpanderPass(PassRegistry &);
|
| 193 |
+
void initializeX86ExecutionDomainFixPass(PassRegistry &);
|
| 194 |
+
void initializeX86ExpandPseudoPass(PassRegistry &);
|
| 195 |
+
void initializeX86FastPreTileConfigPass(PassRegistry &);
|
| 196 |
+
void initializeX86FastTileConfigPass(PassRegistry &);
|
| 197 |
+
void initializeX86FixupSetCCPassPass(PassRegistry &);
|
| 198 |
+
void initializeX86WinFixupBufferSecurityCheckPassPass(PassRegistry &);
|
| 199 |
+
void initializeX86FlagsCopyLoweringPassPass(PassRegistry &);
|
| 200 |
+
void initializeX86LoadValueInjectionLoadHardeningPassPass(PassRegistry &);
|
| 201 |
+
void initializeX86LoadValueInjectionRetHardeningPassPass(PassRegistry &);
|
| 202 |
+
void initializeX86LowerAMXIntrinsicsLegacyPassPass(PassRegistry &);
|
| 203 |
+
void initializeX86LowerAMXTypeLegacyPassPass(PassRegistry &);
|
| 204 |
+
void initializeX86LowerTileCopyPass(PassRegistry &);
|
| 205 |
+
void initializeX86OptimizeLEAPassPass(PassRegistry &);
|
| 206 |
+
void initializeX86PartialReductionPass(PassRegistry &);
|
| 207 |
+
void initializeX86PreTileConfigPass(PassRegistry &);
|
| 208 |
+
void initializeX86ReturnThunksPass(PassRegistry &);
|
| 209 |
+
void initializeX86SpeculativeExecutionSideEffectSuppressionPass(PassRegistry &);
|
| 210 |
+
void initializeX86SpeculativeLoadHardeningPassPass(PassRegistry &);
|
| 211 |
+
void initializeX86TileConfigPass(PassRegistry &);
|
| 212 |
+
void initializeX86SuppressAPXForRelocationPassPass(PassRegistry &);
|
| 213 |
+
void initializeX86WinEHUnwindV2Pass(PassRegistry &);
|
| 214 |
+
|
| 215 |
+
namespace X86AS {
|
| 216 |
+
enum : unsigned {
|
| 217 |
+
GS = 256,
|
| 218 |
+
FS = 257,
|
| 219 |
+
SS = 258,
|
| 220 |
+
PTR32_SPTR = 270,
|
| 221 |
+
PTR32_UPTR = 271,
|
| 222 |
+
PTR64 = 272
|
| 223 |
+
};
|
| 224 |
+
} // End X86AS namespace
|
| 225 |
+
|
| 226 |
+
} // End llvm namespace
|
| 227 |
+
|
| 228 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86AsmPrinter.h
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===-- X86AsmPrinter.h - X86 implementation of AsmPrinter ------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
|
| 9 |
+
#ifndef LLVM_LIB_TARGET_X86_X86ASMPRINTER_H
|
| 10 |
+
#define LLVM_LIB_TARGET_X86_X86ASMPRINTER_H
|
| 11 |
+
|
| 12 |
+
#include "llvm/CodeGen/AsmPrinter.h"
|
| 13 |
+
#include "llvm/CodeGen/FaultMaps.h"
|
| 14 |
+
#include "llvm/CodeGen/StackMaps.h"
|
| 15 |
+
|
| 16 |
+
// Implemented in X86MCInstLower.cpp
|
| 17 |
+
namespace {
|
| 18 |
+
class X86MCInstLower;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
namespace llvm {
|
| 22 |
+
class MCCodeEmitter;
|
| 23 |
+
class MCStreamer;
|
| 24 |
+
class X86Subtarget;
|
| 25 |
+
class TargetMachine;
|
| 26 |
+
|
| 27 |
+
class LLVM_LIBRARY_VISIBILITY X86AsmPrinter : public AsmPrinter {
|
| 28 |
+
public:
|
| 29 |
+
static char ID;
|
| 30 |
+
|
| 31 |
+
private:
|
| 32 |
+
const X86Subtarget *Subtarget = nullptr;
|
| 33 |
+
FaultMaps FM;
|
| 34 |
+
std::unique_ptr<MCCodeEmitter> CodeEmitter;
|
| 35 |
+
bool EmitFPOData = false;
|
| 36 |
+
bool ShouldEmitWeakSwiftAsyncExtendedFramePointerFlags = false;
|
| 37 |
+
bool IndCSPrefix = false;
|
| 38 |
+
bool EnableImportCallOptimization = false;
|
| 39 |
+
|
| 40 |
+
enum ImportCallKind : unsigned {
|
| 41 |
+
IMAGE_RETPOLINE_AMD64_IMPORT_BR = 0x02,
|
| 42 |
+
IMAGE_RETPOLINE_AMD64_IMPORT_CALL = 0x03,
|
| 43 |
+
IMAGE_RETPOLINE_AMD64_INDIR_BR = 0x04,
|
| 44 |
+
IMAGE_RETPOLINE_AMD64_INDIR_CALL = 0x05,
|
| 45 |
+
IMAGE_RETPOLINE_AMD64_INDIR_BR_REX = 0x06,
|
| 46 |
+
IMAGE_RETPOLINE_AMD64_CFG_BR = 0x08,
|
| 47 |
+
IMAGE_RETPOLINE_AMD64_CFG_CALL = 0x09,
|
| 48 |
+
IMAGE_RETPOLINE_AMD64_CFG_BR_REX = 0x0A,
|
| 49 |
+
IMAGE_RETPOLINE_AMD64_SWITCHTABLE_FIRST = 0x010,
|
| 50 |
+
IMAGE_RETPOLINE_AMD64_SWITCHTABLE_LAST = 0x01F,
|
| 51 |
+
};
|
| 52 |
+
struct ImportCallInfo {
|
| 53 |
+
MCSymbol *CalleeSymbol;
|
| 54 |
+
ImportCallKind Kind;
|
| 55 |
+
};
|
| 56 |
+
DenseMap<MCSection *, std::vector<ImportCallInfo>>
|
| 57 |
+
SectionToImportedFunctionCalls;
|
| 58 |
+
|
| 59 |
+
// This utility class tracks the length of a stackmap instruction's 'shadow'.
|
| 60 |
+
// It is used by the X86AsmPrinter to ensure that the stackmap shadow
|
| 61 |
+
// invariants (i.e. no other stackmaps, patchpoints, or control flow within
|
| 62 |
+
// the shadow) are met, while outputting a minimal number of NOPs for padding.
|
| 63 |
+
//
|
| 64 |
+
// To minimise the number of NOPs used, the shadow tracker counts the number
|
| 65 |
+
// of instruction bytes output since the last stackmap. Only if there are too
|
| 66 |
+
// few instruction bytes to cover the shadow are NOPs used for padding.
|
| 67 |
+
class StackMapShadowTracker {
|
| 68 |
+
public:
|
| 69 |
+
void startFunction(MachineFunction &MF) {
|
| 70 |
+
this->MF = &MF;
|
| 71 |
+
}
|
| 72 |
+
void count(const MCInst &Inst, const MCSubtargetInfo &STI,
|
| 73 |
+
MCCodeEmitter *CodeEmitter);
|
| 74 |
+
|
| 75 |
+
// Called to signal the start of a shadow of RequiredSize bytes.
|
| 76 |
+
void reset(unsigned RequiredSize) {
|
| 77 |
+
RequiredShadowSize = RequiredSize;
|
| 78 |
+
CurrentShadowSize = 0;
|
| 79 |
+
InShadow = true;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
// Called before every stackmap/patchpoint, and at the end of basic blocks,
|
| 83 |
+
// to emit any necessary padding-NOPs.
|
| 84 |
+
void emitShadowPadding(MCStreamer &OutStreamer, const MCSubtargetInfo &STI);
|
| 85 |
+
private:
|
| 86 |
+
const MachineFunction *MF = nullptr;
|
| 87 |
+
bool InShadow = false;
|
| 88 |
+
|
| 89 |
+
// RequiredShadowSize holds the length of the shadow specified in the most
|
| 90 |
+
// recently encountered STACKMAP instruction.
|
| 91 |
+
// CurrentShadowSize counts the number of bytes encoded since the most
|
| 92 |
+
// recently encountered STACKMAP, stopping when that number is greater than
|
| 93 |
+
// or equal to RequiredShadowSize.
|
| 94 |
+
unsigned RequiredShadowSize = 0, CurrentShadowSize = 0;
|
| 95 |
+
};
|
| 96 |
+
|
| 97 |
+
StackMapShadowTracker SMShadowTracker;
|
| 98 |
+
|
| 99 |
+
// All instructions emitted by the X86AsmPrinter should use this helper
|
| 100 |
+
// method.
|
| 101 |
+
//
|
| 102 |
+
// This helper function invokes the SMShadowTracker on each instruction before
|
| 103 |
+
// outputting it to the OutStream. This allows the shadow tracker to minimise
|
| 104 |
+
// the number of NOPs used for stackmap padding.
|
| 105 |
+
void EmitAndCountInstruction(MCInst &Inst);
|
| 106 |
+
void LowerSTACKMAP(const MachineInstr &MI);
|
| 107 |
+
void LowerPATCHPOINT(const MachineInstr &MI, X86MCInstLower &MCIL);
|
| 108 |
+
void LowerSTATEPOINT(const MachineInstr &MI, X86MCInstLower &MCIL);
|
| 109 |
+
void LowerFAULTING_OP(const MachineInstr &MI, X86MCInstLower &MCIL);
|
| 110 |
+
void LowerPATCHABLE_OP(const MachineInstr &MI, X86MCInstLower &MCIL);
|
| 111 |
+
|
| 112 |
+
void LowerTlsAddr(X86MCInstLower &MCInstLowering, const MachineInstr &MI);
|
| 113 |
+
|
| 114 |
+
// XRay-specific lowering for X86.
|
| 115 |
+
void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI,
|
| 116 |
+
X86MCInstLower &MCIL);
|
| 117 |
+
void LowerPATCHABLE_RET(const MachineInstr &MI, X86MCInstLower &MCIL);
|
| 118 |
+
void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI, X86MCInstLower &MCIL);
|
| 119 |
+
void LowerPATCHABLE_EVENT_CALL(const MachineInstr &MI, X86MCInstLower &MCIL);
|
| 120 |
+
void LowerPATCHABLE_TYPED_EVENT_CALL(const MachineInstr &MI,
|
| 121 |
+
X86MCInstLower &MCIL);
|
| 122 |
+
|
| 123 |
+
void LowerFENTRY_CALL(const MachineInstr &MI, X86MCInstLower &MCIL);
|
| 124 |
+
|
| 125 |
+
// KCFI specific lowering for X86.
|
| 126 |
+
uint32_t MaskKCFIType(uint32_t Value);
|
| 127 |
+
void EmitKCFITypePadding(const MachineFunction &MF, bool HasType = true);
|
| 128 |
+
void LowerKCFI_CHECK(const MachineInstr &MI);
|
| 129 |
+
|
| 130 |
+
// Address sanitizer specific lowering for X86.
|
| 131 |
+
void LowerASAN_CHECK_MEMACCESS(const MachineInstr &MI);
|
| 132 |
+
|
| 133 |
+
// Choose between emitting .seh_ directives and .cv_fpo_ directives.
|
| 134 |
+
void EmitSEHInstruction(const MachineInstr *MI);
|
| 135 |
+
|
| 136 |
+
void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &O) override;
|
| 137 |
+
void PrintOperand(const MachineInstr *MI, unsigned OpNo, raw_ostream &O);
|
| 138 |
+
void PrintModifiedOperand(const MachineInstr *MI, unsigned OpNo,
|
| 139 |
+
raw_ostream &O, StringRef Modifier = {});
|
| 140 |
+
void PrintPCRelImm(const MachineInstr *MI, unsigned OpNo, raw_ostream &O);
|
| 141 |
+
void PrintLeaMemReference(const MachineInstr *MI, unsigned OpNo,
|
| 142 |
+
raw_ostream &O, StringRef Modifier = {});
|
| 143 |
+
void PrintMemReference(const MachineInstr *MI, unsigned OpNo, raw_ostream &O,
|
| 144 |
+
StringRef Modifier = {});
|
| 145 |
+
void PrintIntelMemReference(const MachineInstr *MI, unsigned OpNo,
|
| 146 |
+
raw_ostream &O, StringRef Modifier = {});
|
| 147 |
+
const MCSubtargetInfo *getIFuncMCSubtargetInfo() const override;
|
| 148 |
+
void emitMachOIFuncStubBody(Module &M, const GlobalIFunc &GI,
|
| 149 |
+
MCSymbol *LazyPointer) override;
|
| 150 |
+
void emitMachOIFuncStubHelperBody(Module &M, const GlobalIFunc &GI,
|
| 151 |
+
MCSymbol *LazyPointer) override;
|
| 152 |
+
|
| 153 |
+
void emitCallInstruction(const llvm::MCInst &MCI);
|
| 154 |
+
|
| 155 |
+
// Emits a label to mark the next instruction as being relevant to Import Call
|
| 156 |
+
// Optimization.
|
| 157 |
+
void emitLabelAndRecordForImportCallOptimization(ImportCallKind Kind);
|
| 158 |
+
|
| 159 |
+
public:
|
| 160 |
+
X86AsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer);
|
| 161 |
+
|
| 162 |
+
StringRef getPassName() const override {
|
| 163 |
+
return "X86 Assembly Printer";
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
const X86Subtarget &getSubtarget() const { return *Subtarget; }
|
| 167 |
+
|
| 168 |
+
void emitStartOfAsmFile(Module &M) override;
|
| 169 |
+
|
| 170 |
+
void emitEndOfAsmFile(Module &M) override;
|
| 171 |
+
|
| 172 |
+
void emitInstruction(const MachineInstr *MI) override;
|
| 173 |
+
|
| 174 |
+
void emitBasicBlockEnd(const MachineBasicBlock &MBB) override;
|
| 175 |
+
|
| 176 |
+
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
| 177 |
+
const char *ExtraCode, raw_ostream &O) override;
|
| 178 |
+
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
|
| 179 |
+
const char *ExtraCode, raw_ostream &O) override;
|
| 180 |
+
|
| 181 |
+
bool doInitialization(Module &M) override {
|
| 182 |
+
SMShadowTracker.reset(0);
|
| 183 |
+
SM.reset();
|
| 184 |
+
FM.reset();
|
| 185 |
+
return AsmPrinter::doInitialization(M);
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
bool runOnMachineFunction(MachineFunction &MF) override;
|
| 189 |
+
void emitFunctionBodyStart() override;
|
| 190 |
+
void emitFunctionBodyEnd() override;
|
| 191 |
+
void emitKCFITypeId(const MachineFunction &MF) override;
|
| 192 |
+
|
| 193 |
+
bool shouldEmitWeakSwiftAsyncExtendedFramePointerFlags() const override {
|
| 194 |
+
return ShouldEmitWeakSwiftAsyncExtendedFramePointerFlags;
|
| 195 |
+
}
|
| 196 |
+
};
|
| 197 |
+
|
| 198 |
+
} // end namespace llvm
|
| 199 |
+
|
| 200 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86CallingConv.h
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//=== X86CallingConv.h - X86 Custom Calling Convention Routines -*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file contains the custom routines for the X86 Calling Convention that
|
| 10 |
+
// aren't done by tablegen.
|
| 11 |
+
//
|
| 12 |
+
//===----------------------------------------------------------------------===//
|
| 13 |
+
|
| 14 |
+
#ifndef LLVM_LIB_TARGET_X86_X86CALLINGCONV_H
|
| 15 |
+
#define LLVM_LIB_TARGET_X86_X86CALLINGCONV_H
|
| 16 |
+
|
| 17 |
+
#include "MCTargetDesc/X86MCTargetDesc.h"
|
| 18 |
+
#include "llvm/CodeGen/CallingConvLower.h"
|
| 19 |
+
#include "llvm/IR/CallingConv.h"
|
| 20 |
+
|
| 21 |
+
namespace llvm {
|
| 22 |
+
|
| 23 |
+
bool RetCC_X86(unsigned ValNo, MVT ValVT, MVT LocVT,
|
| 24 |
+
CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags,
|
| 25 |
+
CCState &State);
|
| 26 |
+
|
| 27 |
+
bool CC_X86(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo,
|
| 28 |
+
ISD::ArgFlagsTy ArgFlags, CCState &State);
|
| 29 |
+
|
| 30 |
+
} // End llvm namespace
|
| 31 |
+
|
| 32 |
+
#endif
|
| 33 |
+
|
deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86FrameLowering.h
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===-- X86TargetFrameLowering.h - Define frame lowering for X86 -*- C++ -*-==//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This class implements X86-specific bits of TargetFrameLowering class.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_LIB_TARGET_X86_X86FRAMELOWERING_H
|
| 14 |
+
#define LLVM_LIB_TARGET_X86_X86FRAMELOWERING_H
|
| 15 |
+
|
| 16 |
+
#include "llvm/CodeGen/MachineFunction.h"
|
| 17 |
+
#include "llvm/CodeGen/TargetFrameLowering.h"
|
| 18 |
+
#include "llvm/Support/TypeSize.h"
|
| 19 |
+
|
| 20 |
+
namespace llvm {
|
| 21 |
+
|
| 22 |
+
class MachineInstrBuilder;
|
| 23 |
+
class MCCFIInstruction;
|
| 24 |
+
class X86InstrInfo;
|
| 25 |
+
class X86Subtarget;
|
| 26 |
+
class X86RegisterInfo;
|
| 27 |
+
|
| 28 |
+
class X86FrameLowering : public TargetFrameLowering {
|
| 29 |
+
public:
|
| 30 |
+
X86FrameLowering(const X86Subtarget &STI, MaybeAlign StackAlignOverride);
|
| 31 |
+
|
| 32 |
+
// Cached subtarget predicates.
|
| 33 |
+
|
| 34 |
+
const X86Subtarget &STI;
|
| 35 |
+
const X86InstrInfo &TII;
|
| 36 |
+
const X86RegisterInfo *TRI;
|
| 37 |
+
|
| 38 |
+
unsigned SlotSize;
|
| 39 |
+
|
| 40 |
+
/// Is64Bit implies that x86_64 instructions are available.
|
| 41 |
+
bool Is64Bit;
|
| 42 |
+
|
| 43 |
+
bool IsLP64;
|
| 44 |
+
|
| 45 |
+
/// True if the 64-bit frame or stack pointer should be used. True for most
|
| 46 |
+
/// 64-bit targets with the exception of x32. If this is false, 32-bit
|
| 47 |
+
/// instruction operands should be used to manipulate StackPtr and FramePtr.
|
| 48 |
+
bool Uses64BitFramePtr;
|
| 49 |
+
|
| 50 |
+
Register StackPtr;
|
| 51 |
+
|
| 52 |
+
/// Emit target stack probe code. This is required for all
|
| 53 |
+
/// large stack allocations on Windows. The caller is required to materialize
|
| 54 |
+
/// the number of bytes to probe in RAX/EAX.
|
| 55 |
+
/// \p InstrNum optionally contains a debug-info instruction number for the
|
| 56 |
+
/// new stack pointer.
|
| 57 |
+
void emitStackProbe(MachineFunction &MF, MachineBasicBlock &MBB,
|
| 58 |
+
MachineBasicBlock::iterator MBBI, const DebugLoc &DL,
|
| 59 |
+
bool InProlog,
|
| 60 |
+
std::optional<MachineFunction::DebugInstrOperandPair>
|
| 61 |
+
InstrNum = std::nullopt) const;
|
| 62 |
+
|
| 63 |
+
bool stackProbeFunctionModifiesSP() const override;
|
| 64 |
+
|
| 65 |
+
/// Replace a StackProbe inline-stub with the actual probe code inline.
|
| 66 |
+
void inlineStackProbe(MachineFunction &MF,
|
| 67 |
+
MachineBasicBlock &PrologMBB) const override;
|
| 68 |
+
|
| 69 |
+
void emitCalleeSavedFrameMovesFullCFA(
|
| 70 |
+
MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) const override;
|
| 71 |
+
|
| 72 |
+
void emitCalleeSavedFrameMoves(MachineBasicBlock &MBB,
|
| 73 |
+
MachineBasicBlock::iterator MBBI,
|
| 74 |
+
const DebugLoc &DL, bool IsPrologue) const;
|
| 75 |
+
|
| 76 |
+
/// emitProlog/emitEpilog - These methods insert prolog and epilog code into
|
| 77 |
+
/// the function.
|
| 78 |
+
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
|
| 79 |
+
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
|
| 80 |
+
|
| 81 |
+
void adjustForSegmentedStacks(MachineFunction &MF,
|
| 82 |
+
MachineBasicBlock &PrologueMBB) const override;
|
| 83 |
+
|
| 84 |
+
void adjustForHiPEPrologue(MachineFunction &MF,
|
| 85 |
+
MachineBasicBlock &PrologueMBB) const override;
|
| 86 |
+
|
| 87 |
+
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
|
| 88 |
+
RegScavenger *RS = nullptr) const override;
|
| 89 |
+
|
| 90 |
+
bool
|
| 91 |
+
assignCalleeSavedSpillSlots(MachineFunction &MF,
|
| 92 |
+
const TargetRegisterInfo *TRI,
|
| 93 |
+
std::vector<CalleeSavedInfo> &CSI) const override;
|
| 94 |
+
|
| 95 |
+
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
|
| 96 |
+
MachineBasicBlock::iterator MI,
|
| 97 |
+
ArrayRef<CalleeSavedInfo> CSI,
|
| 98 |
+
const TargetRegisterInfo *TRI) const override;
|
| 99 |
+
|
| 100 |
+
bool
|
| 101 |
+
restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
|
| 102 |
+
MachineBasicBlock::iterator MI,
|
| 103 |
+
MutableArrayRef<CalleeSavedInfo> CSI,
|
| 104 |
+
const TargetRegisterInfo *TRI) const override;
|
| 105 |
+
|
| 106 |
+
void spillFPBP(MachineFunction &MF) const override;
|
| 107 |
+
|
| 108 |
+
bool hasReservedCallFrame(const MachineFunction &MF) const override;
|
| 109 |
+
bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override;
|
| 110 |
+
bool needsFrameIndexResolution(const MachineFunction &MF) const override;
|
| 111 |
+
|
| 112 |
+
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,
|
| 113 |
+
Register &FrameReg) const override;
|
| 114 |
+
|
| 115 |
+
int getWin64EHFrameIndexRef(const MachineFunction &MF, int FI,
|
| 116 |
+
Register &SPReg) const;
|
| 117 |
+
StackOffset getFrameIndexReferenceSP(const MachineFunction &MF, int FI,
|
| 118 |
+
Register &SPReg, int Adjustment) const;
|
| 119 |
+
StackOffset
|
| 120 |
+
getFrameIndexReferencePreferSP(const MachineFunction &MF, int FI,
|
| 121 |
+
Register &FrameReg,
|
| 122 |
+
bool IgnoreSPUpdates) const override;
|
| 123 |
+
|
| 124 |
+
MachineBasicBlock::iterator
|
| 125 |
+
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
| 126 |
+
MachineBasicBlock::iterator MI) const override;
|
| 127 |
+
|
| 128 |
+
unsigned getWinEHParentFrameOffset(const MachineFunction &MF) const override;
|
| 129 |
+
|
| 130 |
+
void processFunctionBeforeFrameFinalized(MachineFunction &MF,
|
| 131 |
+
RegScavenger *RS) const override;
|
| 132 |
+
|
| 133 |
+
void
|
| 134 |
+
processFunctionBeforeFrameIndicesReplaced(MachineFunction &MF,
|
| 135 |
+
RegScavenger *RS) const override;
|
| 136 |
+
|
| 137 |
+
private:
|
| 138 |
+
/// Basic Pseudocode:
|
| 139 |
+
/// if (instruction before/after the passed instruction is ADD/SUB/LEA)
|
| 140 |
+
/// Offset = instruction stack adjustment
|
| 141 |
+
/// ... positive value for ADD/LEA and negative for SUB
|
| 142 |
+
/// FoundStackAdjust(instruction, Offset)
|
| 143 |
+
/// erase(instruction)
|
| 144 |
+
/// return CalcNewOffset(Offset)
|
| 145 |
+
/// else
|
| 146 |
+
/// return CalcNewOffset(0)
|
| 147 |
+
///
|
| 148 |
+
/// It's possible that the selected instruction is not immediately
|
| 149 |
+
/// before/after MBBI for large adjustments that have been split into multiple
|
| 150 |
+
/// instructions.
|
| 151 |
+
///
|
| 152 |
+
/// FoundStackAdjust should have the signature:
|
| 153 |
+
/// void FoundStackAdjust(MachineBasicBlock::iterator PI, int64_t Offset)
|
| 154 |
+
/// CalcNewOffset should have the signature:
|
| 155 |
+
/// int64_t CalcNewOffset(int64_t Offset)
|
| 156 |
+
template <typename FoundT, typename CalcT>
|
| 157 |
+
int64_t mergeSPUpdates(MachineBasicBlock &MBB,
|
| 158 |
+
MachineBasicBlock::iterator &MBBI,
|
| 159 |
+
FoundT FoundStackAdjust, CalcT CalcNewOffset,
|
| 160 |
+
bool doMergeWithPrevious) const;
|
| 161 |
+
|
| 162 |
+
template <typename CalcT>
|
| 163 |
+
int64_t mergeSPUpdates(MachineBasicBlock &MBB,
|
| 164 |
+
MachineBasicBlock::iterator &MBBI, CalcT CalcNewOffset,
|
| 165 |
+
bool doMergeWithPrevious) const {
|
| 166 |
+
auto FoundStackAdjust = [](MachineBasicBlock::iterator MBBI,
|
| 167 |
+
int64_t Offset) {};
|
| 168 |
+
return mergeSPUpdates(MBB, MBBI, FoundStackAdjust, CalcNewOffset,
|
| 169 |
+
doMergeWithPrevious);
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
public:
|
| 173 |
+
/// Equivalent to:
|
| 174 |
+
/// mergeSPUpdates(MBB, MBBI,
|
| 175 |
+
/// [AddOffset](int64_t Offset) {
|
| 176 |
+
/// return AddOffset + Offset;
|
| 177 |
+
/// },
|
| 178 |
+
/// doMergeWithPrevious);
|
| 179 |
+
int64_t mergeSPAdd(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI,
|
| 180 |
+
int64_t AddOffset, bool doMergeWithPrevious) const;
|
| 181 |
+
|
| 182 |
+
/// Emit a series of instructions to increment / decrement the stack
|
| 183 |
+
/// pointer by a constant value.
|
| 184 |
+
void emitSPUpdate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI,
|
| 185 |
+
const DebugLoc &DL, int64_t NumBytes, bool InEpilogue) const;
|
| 186 |
+
|
| 187 |
+
/// Check that LEA can be used on SP in an epilogue sequence for \p MF.
|
| 188 |
+
bool canUseLEAForSPInEpilogue(const MachineFunction &MF) const;
|
| 189 |
+
|
| 190 |
+
/// Check whether or not the given \p MBB can be used as a prologue
|
| 191 |
+
/// for the target.
|
| 192 |
+
/// The prologue will be inserted first in this basic block.
|
| 193 |
+
/// This method is used by the shrink-wrapping pass to decide if
|
| 194 |
+
/// \p MBB will be correctly handled by the target.
|
| 195 |
+
/// As soon as the target enable shrink-wrapping without overriding
|
| 196 |
+
/// this method, we assume that each basic block is a valid
|
| 197 |
+
/// prologue.
|
| 198 |
+
bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
|
| 199 |
+
|
| 200 |
+
/// Check whether or not the given \p MBB can be used as a epilogue
|
| 201 |
+
/// for the target.
|
| 202 |
+
/// The epilogue will be inserted before the first terminator of that block.
|
| 203 |
+
/// This method is used by the shrink-wrapping pass to decide if
|
| 204 |
+
/// \p MBB will be correctly handled by the target.
|
| 205 |
+
bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override;
|
| 206 |
+
|
| 207 |
+
/// Returns true if the target will correctly handle shrink wrapping.
|
| 208 |
+
bool enableShrinkWrapping(const MachineFunction &MF) const override;
|
| 209 |
+
|
| 210 |
+
/// Order the symbols in the local stack.
|
| 211 |
+
/// We want to place the local stack objects in some sort of sensible order.
|
| 212 |
+
/// The heuristic we use is to try and pack them according to static number
|
| 213 |
+
/// of uses and size in order to minimize code size.
|
| 214 |
+
void orderFrameObjects(const MachineFunction &MF,
|
| 215 |
+
SmallVectorImpl<int> &ObjectsToAllocate) const override;
|
| 216 |
+
|
| 217 |
+
/// Wraps up getting a CFI index and building a MachineInstr for it.
|
| 218 |
+
void BuildCFI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
|
| 219 |
+
const DebugLoc &DL, const MCCFIInstruction &CFIInst,
|
| 220 |
+
MachineInstr::MIFlag Flag = MachineInstr::NoFlags) const;
|
| 221 |
+
|
| 222 |
+
/// Sets up EBP and optionally ESI based on the incoming EBP value. Only
|
| 223 |
+
/// needed for 32-bit. Used in funclet prologues and at catchret destinations.
|
| 224 |
+
MachineBasicBlock::iterator
|
| 225 |
+
restoreWin32EHStackPointers(MachineBasicBlock &MBB,
|
| 226 |
+
MachineBasicBlock::iterator MBBI,
|
| 227 |
+
const DebugLoc &DL, bool RestoreSP = false) const;
|
| 228 |
+
|
| 229 |
+
void restoreWinEHStackPointersInParent(MachineFunction &MF) const;
|
| 230 |
+
|
| 231 |
+
int getInitialCFAOffset(const MachineFunction &MF) const override;
|
| 232 |
+
|
| 233 |
+
Register getInitialCFARegister(const MachineFunction &MF) const override;
|
| 234 |
+
|
| 235 |
+
DwarfFrameBase getDwarfFrameBase(const MachineFunction &MF) const override;
|
| 236 |
+
|
| 237 |
+
/// Return true if the function has a redzone (accessible bytes past the
|
| 238 |
+
/// frame of the top of stack function) as part of it's ABI.
|
| 239 |
+
bool has128ByteRedZone(const MachineFunction& MF) const;
|
| 240 |
+
|
| 241 |
+
protected:
|
| 242 |
+
bool hasFPImpl(const MachineFunction &MF) const override;
|
| 243 |
+
|
| 244 |
+
private:
|
| 245 |
+
bool isWin64Prologue(const MachineFunction &MF) const;
|
| 246 |
+
|
| 247 |
+
bool needsDwarfCFI(const MachineFunction &MF) const;
|
| 248 |
+
|
| 249 |
+
uint64_t calculateMaxStackAlign(const MachineFunction &MF) const;
|
| 250 |
+
|
| 251 |
+
/// Emit target stack probe as a call to a helper function
|
| 252 |
+
void emitStackProbeCall(
|
| 253 |
+
MachineFunction &MF, MachineBasicBlock &MBB,
|
| 254 |
+
MachineBasicBlock::iterator MBBI, const DebugLoc &DL, bool InProlog,
|
| 255 |
+
std::optional<MachineFunction::DebugInstrOperandPair> InstrNum) const;
|
| 256 |
+
|
| 257 |
+
/// Emit target stack probe as an inline sequence.
|
| 258 |
+
void emitStackProbeInline(MachineFunction &MF, MachineBasicBlock &MBB,
|
| 259 |
+
MachineBasicBlock::iterator MBBI,
|
| 260 |
+
const DebugLoc &DL, bool InProlog) const;
|
| 261 |
+
void emitStackProbeInlineWindowsCoreCLR64(MachineFunction &MF,
|
| 262 |
+
MachineBasicBlock &MBB,
|
| 263 |
+
MachineBasicBlock::iterator MBBI,
|
| 264 |
+
const DebugLoc &DL,
|
| 265 |
+
bool InProlog) const;
|
| 266 |
+
void emitStackProbeInlineGeneric(MachineFunction &MF, MachineBasicBlock &MBB,
|
| 267 |
+
MachineBasicBlock::iterator MBBI,
|
| 268 |
+
const DebugLoc &DL, bool InProlog) const;
|
| 269 |
+
|
| 270 |
+
void emitStackProbeInlineGenericBlock(MachineFunction &MF,
|
| 271 |
+
MachineBasicBlock &MBB,
|
| 272 |
+
MachineBasicBlock::iterator MBBI,
|
| 273 |
+
const DebugLoc &DL, uint64_t Offset,
|
| 274 |
+
uint64_t Align) const;
|
| 275 |
+
|
| 276 |
+
void emitStackProbeInlineGenericLoop(MachineFunction &MF,
|
| 277 |
+
MachineBasicBlock &MBB,
|
| 278 |
+
MachineBasicBlock::iterator MBBI,
|
| 279 |
+
const DebugLoc &DL, uint64_t Offset,
|
| 280 |
+
uint64_t Align) const;
|
| 281 |
+
|
| 282 |
+
/// Emit target zero call-used regs.
|
| 283 |
+
void emitZeroCallUsedRegs(BitVector RegsToZero,
|
| 284 |
+
MachineBasicBlock &MBB) const override;
|
| 285 |
+
|
| 286 |
+
void adjustFrameForMsvcCxxEh(MachineFunction &MF) const;
|
| 287 |
+
|
| 288 |
+
/// Aligns the stack pointer by ANDing it with -MaxAlign.
|
| 289 |
+
void BuildStackAlignAND(MachineBasicBlock &MBB,
|
| 290 |
+
MachineBasicBlock::iterator MBBI, const DebugLoc &DL,
|
| 291 |
+
Register Reg, uint64_t MaxAlign) const;
|
| 292 |
+
|
| 293 |
+
/// Make small positive stack adjustments using POPs.
|
| 294 |
+
bool adjustStackWithPops(MachineBasicBlock &MBB,
|
| 295 |
+
MachineBasicBlock::iterator MBBI, const DebugLoc &DL,
|
| 296 |
+
int Offset) const;
|
| 297 |
+
|
| 298 |
+
/// Adjusts the stack pointer using LEA, SUB, or ADD.
|
| 299 |
+
MachineInstrBuilder BuildStackAdjustment(MachineBasicBlock &MBB,
|
| 300 |
+
MachineBasicBlock::iterator MBBI,
|
| 301 |
+
const DebugLoc &DL, int64_t Offset,
|
| 302 |
+
bool InEpilogue) const;
|
| 303 |
+
|
| 304 |
+
unsigned getPSPSlotOffsetFromSP(const MachineFunction &MF) const;
|
| 305 |
+
|
| 306 |
+
unsigned getWinEHFuncletFrameSize(const MachineFunction &MF) const;
|
| 307 |
+
|
| 308 |
+
/// Materialize the catchret target MBB in RAX.
|
| 309 |
+
void emitCatchRetReturnValue(MachineBasicBlock &MBB,
|
| 310 |
+
MachineBasicBlock::iterator MBBI,
|
| 311 |
+
MachineInstr *CatchRet) const;
|
| 312 |
+
|
| 313 |
+
/// Issue instructions to allocate stack space and spill frame pointer and/or
|
| 314 |
+
/// base pointer to stack using stack pointer register.
|
| 315 |
+
void spillFPBPUsingSP(MachineFunction &MF,
|
| 316 |
+
const MachineBasicBlock::iterator BeforeMI, Register FP,
|
| 317 |
+
Register BP, int SPAdjust) const;
|
| 318 |
+
|
| 319 |
+
/// Issue instructions to restore frame pointer and/or base pointer from stack
|
| 320 |
+
/// using stack pointer register, and free stack space.
|
| 321 |
+
void restoreFPBPUsingSP(MachineFunction &MF,
|
| 322 |
+
const MachineBasicBlock::iterator AfterMI,
|
| 323 |
+
Register FP, Register BP, int SPAdjust) const;
|
| 324 |
+
|
| 325 |
+
void saveAndRestoreFPBPUsingSP(MachineFunction &MF,
|
| 326 |
+
MachineBasicBlock::iterator BeforeMI,
|
| 327 |
+
MachineBasicBlock::iterator AfterMI,
|
| 328 |
+
bool SpillFP, bool SpillBP) const;
|
| 329 |
+
|
| 330 |
+
void checkInterferedAccess(MachineFunction &MF,
|
| 331 |
+
MachineBasicBlock::reverse_iterator DefMI,
|
| 332 |
+
MachineBasicBlock::reverse_iterator KillMI,
|
| 333 |
+
bool SpillFP, bool SpillBP) const;
|
| 334 |
+
|
| 335 |
+
// If MI uses fp/bp, but target can handle it, and doesn't want to be spilled
|
| 336 |
+
// again, this function should return true, and update MI so we will not check
|
| 337 |
+
// any instructions from related sequence.
|
| 338 |
+
bool skipSpillFPBP(MachineFunction &MF,
|
| 339 |
+
MachineBasicBlock::reverse_iterator &MI) const;
|
| 340 |
+
};
|
| 341 |
+
|
| 342 |
+
} // End llvm namespace
|
| 343 |
+
|
| 344 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86GenAsmMatcher.inc
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86GenCallingConv.inc
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86GenDAGISel.inc
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a5639d0e4b14799929c20c1b7fd5659c741902e8a2f4823ae2bf38aa8bf51906
|
| 3 |
+
size 28802632
|
deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86GenDisassemblerTables.inc
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86GenExegesis.inc
ADDED
|
@@ -0,0 +1,547 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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+
|* *|
|
| 3 |
+
|* Exegesis Tables *|
|
| 4 |
+
|* *|
|
| 5 |
+
|* Automatically generated file, do not edit! *|
|
| 6 |
+
|* *|
|
| 7 |
+
\*===----------------------------------------------------------------------===*/
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
static const char *X86PfmCounterNames[] = {
|
| 11 |
+
"BRANCH-MISSES", // 0
|
| 12 |
+
"DTLB-LOAD-MISSES", // 1
|
| 13 |
+
"DTLB_LOAD_MISSES:MISS_CAUSES_A_WALK", // 2
|
| 14 |
+
"DTLB_STORE_MISSES:MISS_CAUSES_A_WALK", // 3
|
| 15 |
+
"INSTRUCTIONS_RETIRED", // 4
|
| 16 |
+
"ITLB-LOAD-MISSES", // 5
|
| 17 |
+
"ITLB_MISSES:MISS_CAUSES_A_WALK", // 6
|
| 18 |
+
"L1-DCACHE-LOAD-MISSES", // 7
|
| 19 |
+
"L1-DCACHE-STORE-MISSES", // 8
|
| 20 |
+
"L1-ICACHE-LOAD-MISSES", // 9
|
| 21 |
+
"MEM_LOAD_UOPS_RETIRED:L1_MISS", // 10
|
| 22 |
+
"RETIRED_INSTRUCTIONS", // 11
|
| 23 |
+
"cpu_clk_unhalted", // 12
|
| 24 |
+
"cycles_not_in_halt", // 13
|
| 25 |
+
"dispatched_fpu:pipe0", // 14
|
| 26 |
+
"dispatched_fpu:pipe1", // 15
|
| 27 |
+
"dispatched_fpu_ops:ops_pipe0 + dispatched_fpu_ops:ops_dual_pipe0", // 16
|
| 28 |
+
"dispatched_fpu_ops:ops_pipe1 + dispatched_fpu_ops:ops_dual_pipe1", // 17
|
| 29 |
+
"dispatched_fpu_ops:ops_pipe2 + dispatched_fpu_ops:ops_dual_pipe2", // 18
|
| 30 |
+
"dispatched_fpu_ops:ops_pipe3 + dispatched_fpu_ops:ops_dual_pipe3", // 19
|
| 31 |
+
"div_op_count", // 20
|
| 32 |
+
"fpu_pipe_assignment:total0", // 21
|
| 33 |
+
"fpu_pipe_assignment:total1", // 22
|
| 34 |
+
"fpu_pipe_assignment:total2", // 23
|
| 35 |
+
"fpu_pipe_assignment:total3", // 24
|
| 36 |
+
"ls_dispatch:ld_dispatch", // 25
|
| 37 |
+
"ls_dispatch:ld_st_dispatch + ls_dispatch:ld_dispatch + ls_dispatch:store_dispatch", // 26
|
| 38 |
+
"ls_dispatch:store_dispatch", // 27
|
| 39 |
+
"mem_uop_retired:any_ld + mem_uop_retired:any_st", // 28
|
| 40 |
+
"ops_type_dispatched_from_decoder:fp_disp_retire_mode", // 29
|
| 41 |
+
"ops_type_dispatched_from_decoder:int_disp_retire_mode", // 30
|
| 42 |
+
"retired_ops", // 31
|
| 43 |
+
"retired_uops", // 32
|
| 44 |
+
"rs_uops_dispatched_cycles:port_0", // 33
|
| 45 |
+
"rs_uops_dispatched_cycles:port_1", // 34
|
| 46 |
+
"rs_uops_dispatched_cycles:port_2 + rs_uops_dispatched_cycles:port_3", // 35
|
| 47 |
+
"rs_uops_dispatched_cycles:port_4", // 36
|
| 48 |
+
"rs_uops_dispatched_cycles:port_5", // 37
|
| 49 |
+
"unhalted_core_cycles", // 38
|
| 50 |
+
"uops_dispatched:port_0", // 39
|
| 51 |
+
"uops_dispatched:port_1", // 40
|
| 52 |
+
"uops_dispatched:port_2_3", // 41
|
| 53 |
+
"uops_dispatched:port_2_3_10", // 42
|
| 54 |
+
"uops_dispatched:port_4_9", // 43
|
| 55 |
+
"uops_dispatched:port_5", // 44
|
| 56 |
+
"uops_dispatched:port_5_11", // 45
|
| 57 |
+
"uops_dispatched:port_6", // 46
|
| 58 |
+
"uops_dispatched:port_7_8", // 47
|
| 59 |
+
"uops_dispatched_port:port_0", // 48
|
| 60 |
+
"uops_dispatched_port:port_1", // 49
|
| 61 |
+
"uops_dispatched_port:port_2", // 50
|
| 62 |
+
"uops_dispatched_port:port_2 + uops_dispatched_port:port_3", // 51
|
| 63 |
+
"uops_dispatched_port:port_3", // 52
|
| 64 |
+
"uops_dispatched_port:port_4", // 53
|
| 65 |
+
"uops_dispatched_port:port_5", // 54
|
| 66 |
+
"uops_dispatched_port:port_6", // 55
|
| 67 |
+
"uops_dispatched_port:port_7", // 56
|
| 68 |
+
"uops_executed:port0", // 57
|
| 69 |
+
"uops_executed:port1", // 58
|
| 70 |
+
"uops_executed:port2_core + uops_executed:port3_core", // 59
|
| 71 |
+
"uops_executed:port4_core", // 60
|
| 72 |
+
"uops_executed:port5", // 61
|
| 73 |
+
"uops_executed_port:port_0", // 62
|
| 74 |
+
"uops_executed_port:port_1", // 63
|
| 75 |
+
"uops_executed_port:port_2", // 64
|
| 76 |
+
"uops_executed_port:port_3", // 65
|
| 77 |
+
"uops_executed_port:port_4", // 66
|
| 78 |
+
"uops_executed_port:port_5", // 67
|
| 79 |
+
"uops_executed_port:port_6", // 68
|
| 80 |
+
"uops_executed_port:port_7", // 69
|
| 81 |
+
"uops_issued:any", // 70
|
| 82 |
+
"uops_retired", // 71
|
| 83 |
+
"uops_retired:all", // 72
|
| 84 |
+
"uops_retired:any", // 73
|
| 85 |
+
};
|
| 86 |
+
|
| 87 |
+
static const PfmCountersInfo::IssueCounter X86PfmIssueCounters[] = {
|
| 88 |
+
{ X86PfmCounterNames[39], "ADLPPort00"},
|
| 89 |
+
{ X86PfmCounterNames[40], "ADLPPort01"},
|
| 90 |
+
{ X86PfmCounterNames[42], "ADLPPort02_03_10"},
|
| 91 |
+
{ X86PfmCounterNames[43], "ADLPPort04_09"},
|
| 92 |
+
{ X86PfmCounterNames[45], "ADLPPort05_11"},
|
| 93 |
+
{ X86PfmCounterNames[46], "ADLPPort06"},
|
| 94 |
+
{ X86PfmCounterNames[47], "ADLPPort07_08"},
|
| 95 |
+
{ X86PfmCounterNames[16], "PdFPU0"},
|
| 96 |
+
{ X86PfmCounterNames[17], "PdFPU1"},
|
| 97 |
+
{ X86PfmCounterNames[18], "PdFPU2"},
|
| 98 |
+
{ X86PfmCounterNames[19], "PdFPU3"},
|
| 99 |
+
{ X86PfmCounterNames[16], "SrFPU0"},
|
| 100 |
+
{ X86PfmCounterNames[17], "SrFPU1"},
|
| 101 |
+
{ X86PfmCounterNames[18], "SrFPU2"},
|
| 102 |
+
{ X86PfmCounterNames[62], "BWPort0"},
|
| 103 |
+
{ X86PfmCounterNames[63], "BWPort1"},
|
| 104 |
+
{ X86PfmCounterNames[64], "BWPort2"},
|
| 105 |
+
{ X86PfmCounterNames[65], "BWPort3"},
|
| 106 |
+
{ X86PfmCounterNames[66], "BWPort4"},
|
| 107 |
+
{ X86PfmCounterNames[67], "BWPort5"},
|
| 108 |
+
{ X86PfmCounterNames[68], "BWPort6"},
|
| 109 |
+
{ X86PfmCounterNames[69], "BWPort7"},
|
| 110 |
+
{ X86PfmCounterNames[14], "BtFPU0"},
|
| 111 |
+
{ X86PfmCounterNames[15], "BtFPU1"},
|
| 112 |
+
{ X86PfmCounterNames[14], "JFPU0"},
|
| 113 |
+
{ X86PfmCounterNames[15], "JFPU1"},
|
| 114 |
+
{ X86PfmCounterNames[33], "SBPort0"},
|
| 115 |
+
{ X86PfmCounterNames[34], "SBPort1"},
|
| 116 |
+
{ X86PfmCounterNames[35], "SBPort23"},
|
| 117 |
+
{ X86PfmCounterNames[36], "SBPort4"},
|
| 118 |
+
{ X86PfmCounterNames[37], "SBPort5"},
|
| 119 |
+
{ X86PfmCounterNames[62], "HWPort0"},
|
| 120 |
+
{ X86PfmCounterNames[63], "HWPort1"},
|
| 121 |
+
{ X86PfmCounterNames[64], "HWPort2"},
|
| 122 |
+
{ X86PfmCounterNames[65], "HWPort3"},
|
| 123 |
+
{ X86PfmCounterNames[66], "HWPort4"},
|
| 124 |
+
{ X86PfmCounterNames[67], "HWPort5"},
|
| 125 |
+
{ X86PfmCounterNames[68], "HWPort6"},
|
| 126 |
+
{ X86PfmCounterNames[69], "HWPort7"},
|
| 127 |
+
{ X86PfmCounterNames[39], "ICXPort0"},
|
| 128 |
+
{ X86PfmCounterNames[40], "ICXPort1"},
|
| 129 |
+
{ X86PfmCounterNames[41], "ICXPort23"},
|
| 130 |
+
{ X86PfmCounterNames[43], "ICXPort49"},
|
| 131 |
+
{ X86PfmCounterNames[44], "ICXPort5"},
|
| 132 |
+
{ X86PfmCounterNames[46], "ICXPort6"},
|
| 133 |
+
{ X86PfmCounterNames[47], "ICXPort78"},
|
| 134 |
+
{ X86PfmCounterNames[57], "SBPort0"},
|
| 135 |
+
{ X86PfmCounterNames[58], "SBPort1"},
|
| 136 |
+
{ X86PfmCounterNames[59], "SBPort23"},
|
| 137 |
+
{ X86PfmCounterNames[60], "SBPort4"},
|
| 138 |
+
{ X86PfmCounterNames[61], "SBPort5"},
|
| 139 |
+
{ X86PfmCounterNames[28], "SLM_MEC_RSV"},
|
| 140 |
+
{ X86PfmCounterNames[48], "SBPort0"},
|
| 141 |
+
{ X86PfmCounterNames[49], "SBPort1"},
|
| 142 |
+
{ X86PfmCounterNames[51], "SBPort23"},
|
| 143 |
+
{ X86PfmCounterNames[53], "SBPort4"},
|
| 144 |
+
{ X86PfmCounterNames[54], "SBPort5"},
|
| 145 |
+
{ X86PfmCounterNames[39], "SPRPort00"},
|
| 146 |
+
{ X86PfmCounterNames[40], "SPRPort01"},
|
| 147 |
+
{ X86PfmCounterNames[42], "SPRPort02_03_10"},
|
| 148 |
+
{ X86PfmCounterNames[43], "SPRPort04_09"},
|
| 149 |
+
{ X86PfmCounterNames[45], "SPRPort05_11"},
|
| 150 |
+
{ X86PfmCounterNames[46], "SPRPort06"},
|
| 151 |
+
{ X86PfmCounterNames[47], "SPRPort07_08"},
|
| 152 |
+
{ X86PfmCounterNames[48], "SKLPort0"},
|
| 153 |
+
{ X86PfmCounterNames[49], "SKLPort1"},
|
| 154 |
+
{ X86PfmCounterNames[50], "SKLPort2"},
|
| 155 |
+
{ X86PfmCounterNames[52], "SKLPort3"},
|
| 156 |
+
{ X86PfmCounterNames[53], "SKLPort4"},
|
| 157 |
+
{ X86PfmCounterNames[54], "SKLPort5"},
|
| 158 |
+
{ X86PfmCounterNames[55], "SKLPort6"},
|
| 159 |
+
{ X86PfmCounterNames[56], "SKLPort7"},
|
| 160 |
+
{ X86PfmCounterNames[48], "SKXPort0"},
|
| 161 |
+
{ X86PfmCounterNames[49], "SKXPort1"},
|
| 162 |
+
{ X86PfmCounterNames[50], "SKXPort2"},
|
| 163 |
+
{ X86PfmCounterNames[52], "SKXPort3"},
|
| 164 |
+
{ X86PfmCounterNames[53], "SKXPort4"},
|
| 165 |
+
{ X86PfmCounterNames[54], "SKXPort5"},
|
| 166 |
+
{ X86PfmCounterNames[55], "SKXPort6"},
|
| 167 |
+
{ X86PfmCounterNames[56], "SKXPort7"},
|
| 168 |
+
{ X86PfmCounterNames[21], "ZnFPU0"},
|
| 169 |
+
{ X86PfmCounterNames[22], "ZnFPU1"},
|
| 170 |
+
{ X86PfmCounterNames[23], "ZnFPU2"},
|
| 171 |
+
{ X86PfmCounterNames[24], "ZnFPU3"},
|
| 172 |
+
{ X86PfmCounterNames[26], "ZnAGU"},
|
| 173 |
+
{ X86PfmCounterNames[20], "ZnDivider"},
|
| 174 |
+
{ X86PfmCounterNames[26], "Zn2AGU"},
|
| 175 |
+
{ X86PfmCounterNames[20], "Zn2Divider"},
|
| 176 |
+
{ X86PfmCounterNames[30], "Zn3Int"},
|
| 177 |
+
{ X86PfmCounterNames[29], "Zn3FPU"},
|
| 178 |
+
{ X86PfmCounterNames[25], "Zn3Load"},
|
| 179 |
+
{ X86PfmCounterNames[27], "Zn3Store"},
|
| 180 |
+
{ X86PfmCounterNames[20], "Zn3Divider"},
|
| 181 |
+
{ X86PfmCounterNames[30], "Zn4Int"},
|
| 182 |
+
{ X86PfmCounterNames[29], "Zn4FPU"},
|
| 183 |
+
{ X86PfmCounterNames[25], "Zn4Load"},
|
| 184 |
+
{ X86PfmCounterNames[27], "Zn4Store"},
|
| 185 |
+
{ X86PfmCounterNames[20], "Zn4Divider"},
|
| 186 |
+
{ X86PfmCounterNames[26], "Zn4AGU"},
|
| 187 |
+
};
|
| 188 |
+
|
| 189 |
+
static const std::pair<ValidationEvent, const char*> X86AlderLakePfmCountersValidationCounters[] = {
|
| 190 |
+
{ InstructionRetired, X86PfmCounterNames[4]},
|
| 191 |
+
{ L1DCacheLoadMiss, X86PfmCounterNames[10]},
|
| 192 |
+
{ L1ICacheLoadMiss, X86PfmCounterNames[9]},
|
| 193 |
+
{ DataTLBLoadMiss, X86PfmCounterNames[2]},
|
| 194 |
+
{ DataTLBStoreMiss, X86PfmCounterNames[3]},
|
| 195 |
+
{ InstructionTLBLoadMiss, X86PfmCounterNames[6]},
|
| 196 |
+
{ BranchPredictionMiss, X86PfmCounterNames[0]},
|
| 197 |
+
};
|
| 198 |
+
|
| 199 |
+
static const PfmCountersInfo X86AlderLakePfmCounters = {
|
| 200 |
+
X86PfmCounterNames[38], // Cycle counter
|
| 201 |
+
X86PfmCounterNames[70], // Uops counter
|
| 202 |
+
X86PfmIssueCounters + 0, 7, // Issue counters.
|
| 203 |
+
X86AlderLakePfmCountersValidationCounters, 7 // Validation counters.
|
| 204 |
+
};
|
| 205 |
+
|
| 206 |
+
static const PfmCountersInfo X86AtomPfmCounters = {
|
| 207 |
+
X86PfmCounterNames[38], // Cycle counter
|
| 208 |
+
X86PfmCounterNames[73], // Uops counter
|
| 209 |
+
nullptr, 0, // No issue counters
|
| 210 |
+
nullptr, 0 // No validation counters.
|
| 211 |
+
};
|
| 212 |
+
|
| 213 |
+
static const PfmCountersInfo X86BdVer2PfmCounters = {
|
| 214 |
+
X86PfmCounterNames[12], // Cycle counter
|
| 215 |
+
X86PfmCounterNames[32], // Uops counter
|
| 216 |
+
X86PfmIssueCounters + 7, 4, // Issue counters.
|
| 217 |
+
nullptr, 0 // No validation counters.
|
| 218 |
+
};
|
| 219 |
+
|
| 220 |
+
static const PfmCountersInfo X86BdVer3PfmCounters = {
|
| 221 |
+
X86PfmCounterNames[12], // Cycle counter
|
| 222 |
+
X86PfmCounterNames[32], // Uops counter
|
| 223 |
+
X86PfmIssueCounters + 11, 3, // Issue counters.
|
| 224 |
+
nullptr, 0 // No validation counters.
|
| 225 |
+
};
|
| 226 |
+
|
| 227 |
+
static const std::pair<ValidationEvent, const char*> X86BroadwellPfmCountersValidationCounters[] = {
|
| 228 |
+
{ InstructionRetired, X86PfmCounterNames[4]},
|
| 229 |
+
{ L1DCacheLoadMiss, X86PfmCounterNames[10]},
|
| 230 |
+
{ L1ICacheLoadMiss, X86PfmCounterNames[9]},
|
| 231 |
+
{ DataTLBLoadMiss, X86PfmCounterNames[2]},
|
| 232 |
+
{ DataTLBStoreMiss, X86PfmCounterNames[3]},
|
| 233 |
+
{ InstructionTLBLoadMiss, X86PfmCounterNames[6]},
|
| 234 |
+
{ BranchPredictionMiss, X86PfmCounterNames[0]},
|
| 235 |
+
};
|
| 236 |
+
|
| 237 |
+
static const PfmCountersInfo X86BroadwellPfmCounters = {
|
| 238 |
+
X86PfmCounterNames[38], // Cycle counter
|
| 239 |
+
X86PfmCounterNames[70], // Uops counter
|
| 240 |
+
X86PfmIssueCounters + 14, 8, // Issue counters.
|
| 241 |
+
X86BroadwellPfmCountersValidationCounters, 7 // Validation counters.
|
| 242 |
+
};
|
| 243 |
+
|
| 244 |
+
static const PfmCountersInfo X86BtVer1PfmCounters = {
|
| 245 |
+
X86PfmCounterNames[12], // Cycle counter
|
| 246 |
+
X86PfmCounterNames[32], // Uops counter
|
| 247 |
+
X86PfmIssueCounters + 22, 2, // Issue counters.
|
| 248 |
+
nullptr, 0 // No validation counters.
|
| 249 |
+
};
|
| 250 |
+
|
| 251 |
+
static const PfmCountersInfo X86BtVer2PfmCounters = {
|
| 252 |
+
X86PfmCounterNames[12], // Cycle counter
|
| 253 |
+
X86PfmCounterNames[32], // Uops counter
|
| 254 |
+
X86PfmIssueCounters + 24, 2, // Issue counters.
|
| 255 |
+
nullptr, 0 // No validation counters.
|
| 256 |
+
};
|
| 257 |
+
|
| 258 |
+
static const PfmCountersInfo X86Core2PfmCounters = {
|
| 259 |
+
X86PfmCounterNames[38], // Cycle counter
|
| 260 |
+
X86PfmCounterNames[73], // Uops counter
|
| 261 |
+
X86PfmIssueCounters + 26, 5, // Issue counters.
|
| 262 |
+
nullptr, 0 // No validation counters.
|
| 263 |
+
};
|
| 264 |
+
|
| 265 |
+
static const PfmCountersInfo X86CorePfmCounters = {
|
| 266 |
+
X86PfmCounterNames[38], // Cycle counter
|
| 267 |
+
X86PfmCounterNames[73], // Uops counter
|
| 268 |
+
nullptr, 0, // No issue counters
|
| 269 |
+
nullptr, 0 // No validation counters.
|
| 270 |
+
};
|
| 271 |
+
|
| 272 |
+
static const PfmCountersInfo X86DefaultAMDPfmCounters = {
|
| 273 |
+
X86PfmCounterNames[12], // Cycle counter
|
| 274 |
+
X86PfmCounterNames[32], // Uops counter
|
| 275 |
+
nullptr, 0, // No issue counters
|
| 276 |
+
nullptr, 0 // No validation counters.
|
| 277 |
+
};
|
| 278 |
+
|
| 279 |
+
static const PfmCountersInfo X86DefaultPfmCounters = {
|
| 280 |
+
nullptr, // No cycle counter.
|
| 281 |
+
nullptr, // No uops counter.
|
| 282 |
+
nullptr, 0, // No issue counters
|
| 283 |
+
nullptr, 0 // No validation counters.
|
| 284 |
+
};
|
| 285 |
+
|
| 286 |
+
static const std::pair<ValidationEvent, const char*> X86HaswellPfmCountersValidationCounters[] = {
|
| 287 |
+
{ InstructionRetired, X86PfmCounterNames[4]},
|
| 288 |
+
{ L1DCacheLoadMiss, X86PfmCounterNames[10]},
|
| 289 |
+
{ L1ICacheLoadMiss, X86PfmCounterNames[9]},
|
| 290 |
+
{ DataTLBLoadMiss, X86PfmCounterNames[2]},
|
| 291 |
+
{ DataTLBStoreMiss, X86PfmCounterNames[3]},
|
| 292 |
+
{ InstructionTLBLoadMiss, X86PfmCounterNames[6]},
|
| 293 |
+
{ BranchPredictionMiss, X86PfmCounterNames[0]},
|
| 294 |
+
};
|
| 295 |
+
|
| 296 |
+
static const PfmCountersInfo X86HaswellPfmCounters = {
|
| 297 |
+
X86PfmCounterNames[38], // Cycle counter
|
| 298 |
+
X86PfmCounterNames[70], // Uops counter
|
| 299 |
+
X86PfmIssueCounters + 31, 8, // Issue counters.
|
| 300 |
+
X86HaswellPfmCountersValidationCounters, 7 // Validation counters.
|
| 301 |
+
};
|
| 302 |
+
|
| 303 |
+
static const std::pair<ValidationEvent, const char*> X86IceLakePfmCountersValidationCounters[] = {
|
| 304 |
+
{ InstructionRetired, X86PfmCounterNames[4]},
|
| 305 |
+
{ L1DCacheLoadMiss, X86PfmCounterNames[10]},
|
| 306 |
+
{ L1ICacheLoadMiss, X86PfmCounterNames[9]},
|
| 307 |
+
{ DataTLBLoadMiss, X86PfmCounterNames[2]},
|
| 308 |
+
{ DataTLBStoreMiss, X86PfmCounterNames[3]},
|
| 309 |
+
{ InstructionTLBLoadMiss, X86PfmCounterNames[6]},
|
| 310 |
+
{ BranchPredictionMiss, X86PfmCounterNames[0]},
|
| 311 |
+
};
|
| 312 |
+
|
| 313 |
+
static const PfmCountersInfo X86IceLakePfmCounters = {
|
| 314 |
+
X86PfmCounterNames[38], // Cycle counter
|
| 315 |
+
X86PfmCounterNames[70], // Uops counter
|
| 316 |
+
X86PfmIssueCounters + 39, 7, // Issue counters.
|
| 317 |
+
X86IceLakePfmCountersValidationCounters, 7 // Validation counters.
|
| 318 |
+
};
|
| 319 |
+
|
| 320 |
+
static const PfmCountersInfo X86KnightPfmCounters = {
|
| 321 |
+
X86PfmCounterNames[38], // Cycle counter
|
| 322 |
+
X86PfmCounterNames[72], // Uops counter
|
| 323 |
+
nullptr, 0, // No issue counters
|
| 324 |
+
nullptr, 0 // No validation counters.
|
| 325 |
+
};
|
| 326 |
+
|
| 327 |
+
static const PfmCountersInfo X86NehalemPfmCounters = {
|
| 328 |
+
X86PfmCounterNames[38], // Cycle counter
|
| 329 |
+
X86PfmCounterNames[73], // Uops counter
|
| 330 |
+
X86PfmIssueCounters + 46, 5, // Issue counters.
|
| 331 |
+
nullptr, 0 // No validation counters.
|
| 332 |
+
};
|
| 333 |
+
|
| 334 |
+
static const PfmCountersInfo X86PentiumPfmCounters = {
|
| 335 |
+
X86PfmCounterNames[12], // Cycle counter
|
| 336 |
+
X86PfmCounterNames[71], // Uops counter
|
| 337 |
+
nullptr, 0, // No issue counters
|
| 338 |
+
nullptr, 0 // No validation counters.
|
| 339 |
+
};
|
| 340 |
+
|
| 341 |
+
static const PfmCountersInfo X86SLMPfmCounters = {
|
| 342 |
+
X86PfmCounterNames[38], // Cycle counter
|
| 343 |
+
X86PfmCounterNames[73], // Uops counter
|
| 344 |
+
X86PfmIssueCounters + 51, 1, // Issue counters.
|
| 345 |
+
nullptr, 0 // No validation counters.
|
| 346 |
+
};
|
| 347 |
+
|
| 348 |
+
static const std::pair<ValidationEvent, const char*> X86SandyBridgePfmCountersValidationCounters[] = {
|
| 349 |
+
{ InstructionRetired, X86PfmCounterNames[4]},
|
| 350 |
+
{ L1DCacheLoadMiss, X86PfmCounterNames[10]},
|
| 351 |
+
{ L1ICacheLoadMiss, X86PfmCounterNames[9]},
|
| 352 |
+
{ DataTLBLoadMiss, X86PfmCounterNames[2]},
|
| 353 |
+
{ DataTLBStoreMiss, X86PfmCounterNames[3]},
|
| 354 |
+
{ InstructionTLBLoadMiss, X86PfmCounterNames[6]},
|
| 355 |
+
{ BranchPredictionMiss, X86PfmCounterNames[0]},
|
| 356 |
+
};
|
| 357 |
+
|
| 358 |
+
static const PfmCountersInfo X86SandyBridgePfmCounters = {
|
| 359 |
+
X86PfmCounterNames[38], // Cycle counter
|
| 360 |
+
X86PfmCounterNames[70], // Uops counter
|
| 361 |
+
X86PfmIssueCounters + 52, 5, // Issue counters.
|
| 362 |
+
X86SandyBridgePfmCountersValidationCounters, 7 // Validation counters.
|
| 363 |
+
};
|
| 364 |
+
|
| 365 |
+
static const std::pair<ValidationEvent, const char*> X86SapphireRapidsPfmCountersValidationCounters[] = {
|
| 366 |
+
{ InstructionRetired, X86PfmCounterNames[4]},
|
| 367 |
+
{ L1DCacheLoadMiss, X86PfmCounterNames[10]},
|
| 368 |
+
{ L1ICacheLoadMiss, X86PfmCounterNames[9]},
|
| 369 |
+
{ DataTLBLoadMiss, X86PfmCounterNames[2]},
|
| 370 |
+
{ DataTLBStoreMiss, X86PfmCounterNames[3]},
|
| 371 |
+
{ InstructionTLBLoadMiss, X86PfmCounterNames[6]},
|
| 372 |
+
{ BranchPredictionMiss, X86PfmCounterNames[0]},
|
| 373 |
+
};
|
| 374 |
+
|
| 375 |
+
static const PfmCountersInfo X86SapphireRapidsPfmCounters = {
|
| 376 |
+
X86PfmCounterNames[38], // Cycle counter
|
| 377 |
+
X86PfmCounterNames[70], // Uops counter
|
| 378 |
+
X86PfmIssueCounters + 57, 7, // Issue counters.
|
| 379 |
+
X86SapphireRapidsPfmCountersValidationCounters, 7 // Validation counters.
|
| 380 |
+
};
|
| 381 |
+
|
| 382 |
+
static const std::pair<ValidationEvent, const char*> X86SkylakeClientPfmCountersValidationCounters[] = {
|
| 383 |
+
{ InstructionRetired, X86PfmCounterNames[4]},
|
| 384 |
+
{ L1DCacheLoadMiss, X86PfmCounterNames[10]},
|
| 385 |
+
{ L1ICacheLoadMiss, X86PfmCounterNames[9]},
|
| 386 |
+
{ DataTLBLoadMiss, X86PfmCounterNames[2]},
|
| 387 |
+
{ DataTLBStoreMiss, X86PfmCounterNames[3]},
|
| 388 |
+
{ InstructionTLBLoadMiss, X86PfmCounterNames[6]},
|
| 389 |
+
{ BranchPredictionMiss, X86PfmCounterNames[0]},
|
| 390 |
+
};
|
| 391 |
+
|
| 392 |
+
static const PfmCountersInfo X86SkylakeClientPfmCounters = {
|
| 393 |
+
X86PfmCounterNames[38], // Cycle counter
|
| 394 |
+
X86PfmCounterNames[70], // Uops counter
|
| 395 |
+
X86PfmIssueCounters + 64, 8, // Issue counters.
|
| 396 |
+
X86SkylakeClientPfmCountersValidationCounters, 7 // Validation counters.
|
| 397 |
+
};
|
| 398 |
+
|
| 399 |
+
static const std::pair<ValidationEvent, const char*> X86SkylakeServerPfmCountersValidationCounters[] = {
|
| 400 |
+
{ InstructionRetired, X86PfmCounterNames[4]},
|
| 401 |
+
{ L1DCacheLoadMiss, X86PfmCounterNames[10]},
|
| 402 |
+
{ L1ICacheLoadMiss, X86PfmCounterNames[9]},
|
| 403 |
+
{ DataTLBLoadMiss, X86PfmCounterNames[2]},
|
| 404 |
+
{ DataTLBStoreMiss, X86PfmCounterNames[3]},
|
| 405 |
+
{ InstructionTLBLoadMiss, X86PfmCounterNames[6]},
|
| 406 |
+
{ BranchPredictionMiss, X86PfmCounterNames[0]},
|
| 407 |
+
};
|
| 408 |
+
|
| 409 |
+
static const PfmCountersInfo X86SkylakeServerPfmCounters = {
|
| 410 |
+
X86PfmCounterNames[38], // Cycle counter
|
| 411 |
+
X86PfmCounterNames[70], // Uops counter
|
| 412 |
+
X86PfmIssueCounters + 72, 8, // Issue counters.
|
| 413 |
+
X86SkylakeServerPfmCountersValidationCounters, 7 // Validation counters.
|
| 414 |
+
};
|
| 415 |
+
|
| 416 |
+
static const std::pair<ValidationEvent, const char*> X86ZnVer1PfmCountersValidationCounters[] = {
|
| 417 |
+
{ InstructionRetired, X86PfmCounterNames[11]},
|
| 418 |
+
{ L1DCacheLoadMiss, X86PfmCounterNames[7]},
|
| 419 |
+
{ L1DCacheStoreMiss, X86PfmCounterNames[8]},
|
| 420 |
+
{ L1ICacheLoadMiss, X86PfmCounterNames[9]},
|
| 421 |
+
{ DataTLBLoadMiss, X86PfmCounterNames[1]},
|
| 422 |
+
{ InstructionTLBLoadMiss, X86PfmCounterNames[5]},
|
| 423 |
+
{ BranchPredictionMiss, X86PfmCounterNames[0]},
|
| 424 |
+
};
|
| 425 |
+
|
| 426 |
+
static const PfmCountersInfo X86ZnVer1PfmCounters = {
|
| 427 |
+
X86PfmCounterNames[13], // Cycle counter
|
| 428 |
+
X86PfmCounterNames[32], // Uops counter
|
| 429 |
+
X86PfmIssueCounters + 80, 6, // Issue counters.
|
| 430 |
+
X86ZnVer1PfmCountersValidationCounters, 7 // Validation counters.
|
| 431 |
+
};
|
| 432 |
+
|
| 433 |
+
static const std::pair<ValidationEvent, const char*> X86ZnVer2PfmCountersValidationCounters[] = {
|
| 434 |
+
{ InstructionRetired, X86PfmCounterNames[11]},
|
| 435 |
+
{ L1DCacheLoadMiss, X86PfmCounterNames[7]},
|
| 436 |
+
{ L1DCacheStoreMiss, X86PfmCounterNames[8]},
|
| 437 |
+
{ L1ICacheLoadMiss, X86PfmCounterNames[9]},
|
| 438 |
+
{ DataTLBLoadMiss, X86PfmCounterNames[1]},
|
| 439 |
+
{ InstructionTLBLoadMiss, X86PfmCounterNames[5]},
|
| 440 |
+
{ BranchPredictionMiss, X86PfmCounterNames[0]},
|
| 441 |
+
};
|
| 442 |
+
|
| 443 |
+
static const PfmCountersInfo X86ZnVer2PfmCounters = {
|
| 444 |
+
X86PfmCounterNames[13], // Cycle counter
|
| 445 |
+
X86PfmCounterNames[32], // Uops counter
|
| 446 |
+
X86PfmIssueCounters + 86, 2, // Issue counters.
|
| 447 |
+
X86ZnVer2PfmCountersValidationCounters, 7 // Validation counters.
|
| 448 |
+
};
|
| 449 |
+
|
| 450 |
+
static const std::pair<ValidationEvent, const char*> X86ZnVer3PfmCountersValidationCounters[] = {
|
| 451 |
+
{ InstructionRetired, X86PfmCounterNames[11]},
|
| 452 |
+
{ L1DCacheLoadMiss, X86PfmCounterNames[7]},
|
| 453 |
+
{ L1DCacheStoreMiss, X86PfmCounterNames[8]},
|
| 454 |
+
{ L1ICacheLoadMiss, X86PfmCounterNames[9]},
|
| 455 |
+
{ DataTLBLoadMiss, X86PfmCounterNames[1]},
|
| 456 |
+
{ InstructionTLBLoadMiss, X86PfmCounterNames[5]},
|
| 457 |
+
{ BranchPredictionMiss, X86PfmCounterNames[0]},
|
| 458 |
+
};
|
| 459 |
+
|
| 460 |
+
static const PfmCountersInfo X86ZnVer3PfmCounters = {
|
| 461 |
+
X86PfmCounterNames[13], // Cycle counter
|
| 462 |
+
X86PfmCounterNames[31], // Uops counter
|
| 463 |
+
X86PfmIssueCounters + 88, 5, // Issue counters.
|
| 464 |
+
X86ZnVer3PfmCountersValidationCounters, 7 // Validation counters.
|
| 465 |
+
};
|
| 466 |
+
|
| 467 |
+
static const std::pair<ValidationEvent, const char*> X86ZnVer4PfmCountersValidationCounters[] = {
|
| 468 |
+
{ InstructionRetired, X86PfmCounterNames[11]},
|
| 469 |
+
{ L1DCacheLoadMiss, X86PfmCounterNames[7]},
|
| 470 |
+
{ L1DCacheStoreMiss, X86PfmCounterNames[8]},
|
| 471 |
+
{ L1ICacheLoadMiss, X86PfmCounterNames[9]},
|
| 472 |
+
{ DataTLBLoadMiss, X86PfmCounterNames[1]},
|
| 473 |
+
{ InstructionTLBLoadMiss, X86PfmCounterNames[5]},
|
| 474 |
+
{ BranchPredictionMiss, X86PfmCounterNames[0]},
|
| 475 |
+
};
|
| 476 |
+
|
| 477 |
+
static const PfmCountersInfo X86ZnVer4PfmCounters = {
|
| 478 |
+
X86PfmCounterNames[13], // Cycle counter
|
| 479 |
+
X86PfmCounterNames[31], // Uops counter
|
| 480 |
+
X86PfmIssueCounters + 93, 6, // Issue counters.
|
| 481 |
+
X86ZnVer4PfmCountersValidationCounters, 7 // Validation counters.
|
| 482 |
+
};
|
| 483 |
+
|
| 484 |
+
// Sorted (by CpuName) array of pfm counters.
|
| 485 |
+
static const CpuAndPfmCounters X86CpuPfmCounters[] = {
|
| 486 |
+
{ "", &X86DefaultPfmCounters },
|
| 487 |
+
{ "alderlake", &X86AlderLakePfmCounters },
|
| 488 |
+
{ "amdfam10", &X86DefaultAMDPfmCounters },
|
| 489 |
+
{ "athlon", &X86DefaultAMDPfmCounters },
|
| 490 |
+
{ "athlon-4", &X86DefaultAMDPfmCounters },
|
| 491 |
+
{ "athlon-fx", &X86DefaultAMDPfmCounters },
|
| 492 |
+
{ "athlon-mp", &X86DefaultAMDPfmCounters },
|
| 493 |
+
{ "athlon-tbird", &X86DefaultAMDPfmCounters },
|
| 494 |
+
{ "athlon-xp", &X86DefaultAMDPfmCounters },
|
| 495 |
+
{ "athlon64", &X86DefaultAMDPfmCounters },
|
| 496 |
+
{ "athlon64-sse3", &X86DefaultAMDPfmCounters },
|
| 497 |
+
{ "atom", &X86AtomPfmCounters },
|
| 498 |
+
{ "barcelona", &X86DefaultAMDPfmCounters },
|
| 499 |
+
{ "bdver1", &X86BdVer2PfmCounters },
|
| 500 |
+
{ "bdver2", &X86BdVer2PfmCounters },
|
| 501 |
+
{ "bdver3", &X86BdVer3PfmCounters },
|
| 502 |
+
{ "bdver4", &X86BdVer3PfmCounters },
|
| 503 |
+
{ "bonnell", &X86AtomPfmCounters },
|
| 504 |
+
{ "broadwell", &X86BroadwellPfmCounters },
|
| 505 |
+
{ "btver1", &X86BtVer1PfmCounters },
|
| 506 |
+
{ "btver2", &X86BtVer2PfmCounters },
|
| 507 |
+
{ "cannonlake", &X86SkylakeServerPfmCounters },
|
| 508 |
+
{ "cascadelake", &X86SkylakeServerPfmCounters },
|
| 509 |
+
{ "core2", &X86Core2PfmCounters },
|
| 510 |
+
{ "corei7", &X86NehalemPfmCounters },
|
| 511 |
+
{ "goldmont", &X86SLMPfmCounters },
|
| 512 |
+
{ "goldmont-plus", &X86SLMPfmCounters },
|
| 513 |
+
{ "haswell", &X86HaswellPfmCounters },
|
| 514 |
+
{ "icelake-client", &X86IceLakePfmCounters },
|
| 515 |
+
{ "icelake-server", &X86IceLakePfmCounters },
|
| 516 |
+
{ "ivybridge", &X86SandyBridgePfmCounters },
|
| 517 |
+
{ "k8", &X86DefaultAMDPfmCounters },
|
| 518 |
+
{ "k8-sse3", &X86DefaultAMDPfmCounters },
|
| 519 |
+
{ "knl", &X86KnightPfmCounters },
|
| 520 |
+
{ "knm", &X86KnightPfmCounters },
|
| 521 |
+
{ "nehalem", &X86NehalemPfmCounters },
|
| 522 |
+
{ "opteron", &X86DefaultAMDPfmCounters },
|
| 523 |
+
{ "opteron-sse3", &X86DefaultAMDPfmCounters },
|
| 524 |
+
{ "penryn", &X86Core2PfmCounters },
|
| 525 |
+
{ "pentium-m", &X86PentiumPfmCounters },
|
| 526 |
+
{ "pentium2", &X86PentiumPfmCounters },
|
| 527 |
+
{ "pentium3", &X86PentiumPfmCounters },
|
| 528 |
+
{ "pentium3m", &X86PentiumPfmCounters },
|
| 529 |
+
{ "pentiumpro", &X86PentiumPfmCounters },
|
| 530 |
+
{ "prescott", &X86CorePfmCounters },
|
| 531 |
+
{ "rocketlake", &X86IceLakePfmCounters },
|
| 532 |
+
{ "sandybridge", &X86SandyBridgePfmCounters },
|
| 533 |
+
{ "sapphirerapids", &X86SapphireRapidsPfmCounters },
|
| 534 |
+
{ "silvermont", &X86SLMPfmCounters },
|
| 535 |
+
{ "skylake", &X86SkylakeClientPfmCounters },
|
| 536 |
+
{ "skylake-avx512", &X86SkylakeServerPfmCounters },
|
| 537 |
+
{ "tigerlake", &X86IceLakePfmCounters },
|
| 538 |
+
{ "tremont", &X86SLMPfmCounters },
|
| 539 |
+
{ "westmere", &X86NehalemPfmCounters },
|
| 540 |
+
{ "yonah", &X86CorePfmCounters },
|
| 541 |
+
{ "znver1", &X86ZnVer1PfmCounters },
|
| 542 |
+
{ "znver2", &X86ZnVer2PfmCounters },
|
| 543 |
+
{ "znver3", &X86ZnVer3PfmCounters },
|
| 544 |
+
{ "znver4", &X86ZnVer4PfmCounters },
|
| 545 |
+
{ "znver5", &X86ZnVer4PfmCounters },
|
| 546 |
+
};
|
| 547 |
+
|
deps/exla/cache/xla_extension/include/llvm/lib/Target/X86/X86GenGlobalISel.inc
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|