LLVM  17.0.0git
COFF.cpp
Go to the documentation of this file.
1 //===- llvm/BinaryFormat/COFF.cpp - The COFF format -----------------------===//
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 
10 #include "llvm/ADT/SmallVector.h"
11 #include "llvm/ADT/Twine.h"
12 
13 // Maximum offsets for different string table entry encodings.
14 enum : unsigned { Max7DecimalOffset = 9999999U };
15 enum : uint64_t { MaxBase64Offset = 0xFFFFFFFFFULL }; // 64^6, including 0
16 
17 // Encode a string table entry offset in base 64, padded to 6 chars, and
18 // prefixed with a double slash: '//AAAAAA', '//AAAAAB', ...
19 // Buffer must be at least 8 bytes large. No terminating null appended.
20 static void encodeBase64StringEntry(char *Buffer, uint64_t Value) {
22  "Illegal section name encoding for value");
23 
24  static const char Alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
25  "abcdefghijklmnopqrstuvwxyz"
26  "0123456789+/";
27 
28  Buffer[0] = '/';
29  Buffer[1] = '/';
30 
31  char *Ptr = Buffer + 7;
32  for (unsigned i = 0; i < 6; ++i) {
33  unsigned Rem = Value % 64;
34  Value /= 64;
35  *(Ptr--) = Alphabet[Rem];
36  }
37 }
38 
40  if (Offset <= Max7DecimalOffset) {
41  // Offsets of 7 digits or less are encoded in ASCII.
43  Twine('/').concat(Twine(Offset)).toVector(Buffer);
44  assert(Buffer.size() <= COFF::NameSize && Buffer.size() >= 2);
45  std::memcpy(Out, Buffer.data(), Buffer.size());
46  return true;
47  }
48 
49  if (Offset <= MaxBase64Offset) {
50  // Starting with 10,000,000, offsets are encoded as base64.
52  return true;
53  }
54 
55  // The offset is too large to be encoded.
56  return false;
57 }
i
i
Definition: README.txt:29
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1199
COFF.h
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:80
Twine.h
encodeBase64StringEntry
static void encodeBase64StringEntry(char *Buffer, uint64_t Value)
Definition: COFF.cpp:20
Max7DecimalOffset
@ Max7DecimalOffset
Definition: COFF.cpp:14
uint64_t
llvm::Twine::toVector
void toVector(SmallVectorImpl< char > &Out) const
Append the concatenated string into the given SmallString or SmallVector.
Definition: Twine.cpp:32
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
memcpy
<%struct.s * > cast struct s *S to sbyte *< sbyte * > sbyte uint cast struct s *agg result to sbyte *< sbyte * > sbyte uint cast struct s *memtmp to sbyte *< sbyte * > sbyte uint ret void llc ends up issuing two memcpy or custom lower memcpy(of small size) to be ldmia/stmia. I think option 2 is better but the current register allocator cannot allocate a chunk of registers at a time. A feasible temporary solution is to use specific physical registers at the lowering time for small(<
llvm::COFF::NameSize
@ NameSize
Definition: COFF.h:57
Ptr
@ Ptr
Definition: TargetLibraryInfo.cpp:62
llvm::COFF::encodeSectionName
bool encodeSectionName(char *Out, uint64_t Offset)
Encode section name based on string table offset.
Definition: COFF.cpp:39
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
MaxBase64Offset
@ MaxBase64Offset
Definition: COFF.cpp:15
SmallVector.h
llvm::Twine::concat
Twine concat(const Twine &Suffix) const
Definition: Twine.h:506