Skip to content

Commit 4e76fa6

Browse files
rebase
Created using spr 1.3.6
2 parents 6af11fe + 5acb658 commit 4e76fa6

File tree

4 files changed

+31
-45
lines changed

4 files changed

+31
-45
lines changed

llvm/include/llvm/MC/MCSymbol.h

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ class raw_ostream;
4242
class MCSymbol {
4343
protected:
4444
// A symbol can be regular, equated to an expression, or a common symbol.
45-
enum Contents : uint8_t {
46-
SymContentsUnset,
47-
SymContentsVariable,
48-
SymContentsCommon,
49-
SymContentsTargetCommon, // Index stores the section index
45+
enum Kind : uint8_t {
46+
Regular,
47+
Equated,
48+
Common,
5049
};
5150

5251
// Special sentinel value for the absolute pseudo fragment.
@@ -65,9 +64,9 @@ class MCSymbol {
6564
/// relative to, if any.
6665
mutable MCFragment *Fragment = nullptr;
6766

68-
/// This is actually a Contents enumerator, but is unsigned to avoid sign
69-
/// extension and achieve better bitpacking with MSVC.
70-
unsigned SymbolContents : 2;
67+
/// The symbol kind. Use an unsigned bitfield to achieve better bitpacking
68+
/// with MSVC.
69+
unsigned kind : 2;
7170

7271
/// True if this symbol is named. A named symbol will have a pointer to the
7372
/// name allocated in the bytes immediately prior to the MCSymbol.
@@ -145,10 +144,10 @@ class MCSymbol {
145144
};
146145

147146
MCSymbol(const MCSymbolTableEntry *Name, bool isTemporary)
148-
: SymbolContents(SymContentsUnset), IsTemporary(isTemporary),
149-
IsRedefinable(false), IsRegistered(false), IsExternal(false),
150-
IsPrivateExtern(false), IsWeakExternal(false), IsUsedInReloc(false),
151-
IsResolving(0), CommonAlignLog2(0), Flags(0) {
147+
: kind(Kind::Regular), IsTemporary(isTemporary), IsRedefinable(false),
148+
IsRegistered(false), IsExternal(false), IsPrivateExtern(false),
149+
IsWeakExternal(false), IsUsedInReloc(false), IsResolving(0),
150+
CommonAlignLog2(0), Flags(0) {
152151
Offset = 0;
153152
HasName = !!Name;
154153
if (Name)
@@ -212,9 +211,9 @@ class MCSymbol {
212211
/// Prepare this symbol to be redefined.
213212
void redefineIfPossible() {
214213
if (IsRedefinable) {
215-
if (SymbolContents == SymContentsVariable) {
214+
if (kind == Kind::Equated) {
216215
Value = nullptr;
217-
SymbolContents = SymContentsUnset;
216+
kind = Kind::Regular;
218217
}
219218
setUndefined();
220219
IsRedefinable = false;
@@ -268,9 +267,7 @@ class MCSymbol {
268267
/// @{
269268

270269
/// isVariable - Check if this is a variable symbol.
271-
bool isVariable() const {
272-
return SymbolContents == SymContentsVariable;
273-
}
270+
bool isVariable() const { return kind == Equated; }
274271

275272
/// Get the expression of the variable symbol.
276273
const MCExpr *getVariableValue() const {
@@ -293,12 +290,12 @@ class MCSymbol {
293290
}
294291

295292
uint64_t getOffset() const {
296-
assert(SymbolContents == SymContentsUnset &&
293+
assert(kind == Kind::Regular &&
297294
"Cannot get offset for a common/variable symbol");
298295
return Offset;
299296
}
300297
void setOffset(uint64_t Value) {
301-
assert(SymbolContents == SymContentsUnset &&
298+
assert(kind == Kind::Regular &&
302299
"Cannot set offset for a common/variable symbol");
303300
Offset = Value;
304301
}
@@ -314,10 +311,10 @@ class MCSymbol {
314311
/// \param Size - The size of the symbol.
315312
/// \param Alignment - The alignment of the symbol.
316313
/// \param Target - Is the symbol a target-specific common-like symbol.
317-
void setCommon(uint64_t Size, Align Alignment, bool Target = false) {
314+
void setCommon(uint64_t Size, Align Alignment) {
318315
assert(getOffset() == 0);
319316
CommonSize = Size;
320-
SymbolContents = Target ? SymContentsTargetCommon : SymContentsCommon;
317+
kind = Kind::Common;
321318

322319
unsigned Log2Align = encode(Alignment);
323320
assert(Log2Align < (1U << NumCommonAlignmentBits) &&
@@ -335,29 +332,19 @@ class MCSymbol {
335332
///
336333
/// \param Size - The size of the symbol.
337334
/// \param Alignment - The alignment of the symbol.
338-
/// \param Target - Is the symbol a target-specific common-like symbol.
339335
/// \return True if symbol was already declared as a different type
340-
bool declareCommon(uint64_t Size, Align Alignment, bool Target = false) {
336+
bool declareCommon(uint64_t Size, Align Alignment) {
341337
assert(isCommon() || getOffset() == 0);
342338
if(isCommon()) {
343-
if (CommonSize != Size || getCommonAlignment() != Alignment ||
344-
isTargetCommon() != Target)
339+
if (CommonSize != Size || getCommonAlignment() != Alignment)
345340
return true;
346341
} else
347-
setCommon(Size, Alignment, Target);
342+
setCommon(Size, Alignment);
348343
return false;
349344
}
350345

351346
/// Is this a 'common' symbol.
352-
bool isCommon() const {
353-
return SymbolContents == SymContentsCommon ||
354-
SymbolContents == SymContentsTargetCommon;
355-
}
356-
357-
/// Is this a target-specific common-like symbol.
358-
bool isTargetCommon() const {
359-
return SymbolContents == SymContentsTargetCommon;
360-
}
347+
bool isCommon() const { return kind == Kind::Common; }
361348

362349
MCFragment *getFragment() const {
363350
if (Fragment || !isVariable() || isWeakExternal())

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,12 +541,12 @@ void ELFWriter::computeSymbolTable(const RevGroupMapTy &RevGroupMap) {
541541
if (Symbol.isAbsolute()) {
542542
MSD.SectionIndex = ELF::SHN_ABS;
543543
} else if (Symbol.isCommon()) {
544-
if (Symbol.isTargetCommon()) {
545-
MSD.SectionIndex = Symbol.getIndex();
546-
} else {
544+
auto Shndx = Symbol.getIndex();
545+
if (!Shndx) {
547546
assert(!Local);
548-
MSD.SectionIndex = ELF::SHN_COMMON;
547+
Shndx = ELF::SHN_COMMON;
549548
}
549+
MSD.SectionIndex = Shndx;
550550
} else if (Symbol.isUndefined()) {
551551
if (Symbol.isSignature() && !Symbol.isUsedInReloc()) {
552552
MSD.SectionIndex = RevGroupMap.lookup(&Symbol);

llvm/lib/MC/MCSymbol.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ void *MCSymbol::operator new(size_t s, const MCSymbolTableEntry *Name,
4848
}
4949

5050
void MCSymbol::setVariableValue(const MCExpr *Value) {
51-
assert(Value && "Invalid variable value!");
52-
assert((SymbolContents == SymContentsUnset ||
53-
SymbolContents == SymContentsVariable) &&
54-
"Cannot give common/offset symbol a variable value");
51+
assert(Value && "Invalid equated expression");
52+
assert((kind == Kind::Regular || kind == Kind::Equated) &&
53+
"Cannot equate a common symbol");
5554
this->Value = Value;
56-
SymbolContents = SymContentsVariable;
55+
kind = Kind::Equated;
5756
setUndefined();
5857
}
5958

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ void AMDGPUTargetELFStreamer::emitAMDGPULDS(MCSymbol *Symbol, unsigned Size,
886886
if (!SymbolELF->isBindingSet())
887887
SymbolELF->setBinding(ELF::STB_GLOBAL);
888888

889-
if (SymbolELF->declareCommon(Size, Alignment, true)) {
889+
if (SymbolELF->declareCommon(Size, Alignment)) {
890890
report_fatal_error("Symbol: " + Symbol->getName() +
891891
" redeclared as different type");
892892
}

0 commit comments

Comments
 (0)