Skip to content

Commit 8ef2267

Browse files
jrtc27veselypeta
authored andcommitted
[NFCI][CodeGen][MC][Mips][RISCV] Follow emitValue for EmitCheriCapability
Rename the underlying function to emitCheriCapability, and have the symbol-only version be non-virtual and called emitSymbolCheriCapability like emitSymbolValue. Drop the addend overloads and let the callers create the adds. Not many callers exist, no equivalent exists for integers, and two of the three uses will be changed in a future commit anyway.
2 parents b5890af + 0817f2d commit 8ef2267

File tree

11 files changed

+42
-48
lines changed

11 files changed

+42
-48
lines changed

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -836,14 +836,12 @@ class MCStreamer {
836836
// MCAsmInfo only knowns about the triple which is not enough
837837

838838
// Emit the expression \p Value into the output as a CHERI capability
839-
virtual void EmitCheriCapability(const MCExpr *Value, unsigned CapSize,
839+
virtual void emitCheriCapability(const MCExpr *Value, unsigned CapSize,
840840
SMLoc Loc = SMLoc());
841-
void EmitCheriCapability(const MCSymbol *Value, const MCExpr *Addend,
842-
unsigned CapSize, SMLoc Loc = SMLoc());
843-
void EmitCheriCapability(const MCSymbol *Value, int64_t Addend,
844-
unsigned CapSize, SMLoc Loc = SMLoc());
845-
void EmitCheriCapability(const MCSymbol *Value, unsigned CapSize,
846-
SMLoc Loc = SMLoc());
841+
842+
/// Special case of emitCheriCapability that avoids the client having to pass
843+
/// in a MCExpr for MCSymbols.
844+
void emitSymbolCheriCapability(const MCSymbol *Sym, unsigned CapSize);
847845

848846
// Emit \p Value as an untagged capability-size value
849847
virtual void emitCheriIntcap(int64_t Value, unsigned CapSize,

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,7 +2312,8 @@ bool AsmPrinter::doFinalization(Module &M) {
23122312
for (const auto &Stub : Stubs) {
23132313
OutStreamer->emitLabel(Stub.first);
23142314
if (DL.isFatPointer(AS))
2315-
OutStreamer->EmitCheriCapability(Stub.second.getPointer(), Size);
2315+
OutStreamer->emitSymbolCheriCapability(Stub.second.getPointer(),
2316+
Size);
23162317
else
23172318
OutStreamer->emitSymbolValue(Stub.second.getPointer(), Size);
23182319
}
@@ -3654,20 +3655,26 @@ static void emitGlobalConstantCHERICap(const DataLayout &DL, const Constant *CV,
36543655
return;
36553656
}
36563657
GlobalValue *GV;
3657-
APInt Addend;
3658-
if (IsConstantOffsetFromGlobal(const_cast<Constant *>(CV), GV, Addend, DL,
3658+
APInt Offset;
3659+
MCContext &Ctx = AP.OutContext;
3660+
if (IsConstantOffsetFromGlobal(const_cast<Constant *>(CV), GV, Offset, DL,
36593661
true)) {
3660-
AP.OutStreamer->EmitCheriCapability(AP.getSymbol(GV), Addend.getSExtValue(),
3661-
CapWidth);
3662+
const MCExpr *CapExpr = MCSymbolRefExpr::create(AP.getSymbol(GV), Ctx);
3663+
int64_t Addend = Offset.getSExtValue();
3664+
if (Addend != 0)
3665+
CapExpr = MCBinaryExpr::createAdd(
3666+
CapExpr, MCConstantExpr::create(Addend, Ctx), Ctx);
3667+
AP.OutStreamer->emitCheriCapability(CapExpr, CapWidth);
36623668
return;
36633669
} else if (const MCSymbolRefExpr *SRE = dyn_cast<MCSymbolRefExpr>(Expr)) {
36643670
if (auto BA = dyn_cast<BlockAddress>(CV)) {
36653671
// For block addresses we emit `.chericap FN+(.LtmpN - FN)`
36663672
// NB: Must use a non-preemptible symbol
36673673
auto FnStart = AP.getSymbolPreferLocal(*BA->getFunction(), true);
3668-
const MCExpr *DiffToStart = MCBinaryExpr::createSub(
3669-
SRE, MCSymbolRefExpr::create(FnStart, AP.OutContext), AP.OutContext);
3670-
AP.OutStreamer->EmitCheriCapability(FnStart, DiffToStart, CapWidth);
3674+
const MCExpr *Start = MCSymbolRefExpr::create(FnStart, Ctx);
3675+
const MCExpr *DiffToStart = MCBinaryExpr::createSub(SRE, Start, Ctx);
3676+
const MCExpr *CapExpr = MCBinaryExpr::createAdd(Start, DiffToStart, Ctx);
3677+
AP.OutStreamer->emitCheriCapability(CapExpr, CapWidth);
36713678
return;
36723679
}
36733680
// Emit capability for label whose address is stored in a global variable
@@ -3676,7 +3683,7 @@ static void emitGlobalConstantCHERICap(const DataLayout &DL, const Constant *CV,
36763683
report_fatal_error(
36773684
"Cannot emit a global .chericap referring to a temporary since this "
36783685
"will result in the wrong value at runtime!");
3679-
AP.OutStreamer->EmitCheriCapability(&SRE->getSymbol(), CapWidth);
3686+
AP.OutStreamer->emitSymbolCheriCapability(&SRE->getSymbol(), CapWidth);
36803687
return;
36813688
}
36823689
}

llvm/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,23 @@ void AsmPrinter::emitCallSiteValue(uint64_t Value, unsigned Encoding) const {
203203

204204
void AsmPrinter::emitCallSiteCheriCapability(const MCSymbol *Hi,
205205
const MCSymbol *Lo) const {
206+
assert(CurrentFnBeginLocal && "Missing local function entry alias for EH!");
207+
206208
const TargetLoweringObjectFile &TLOF = getObjFileLowering();
209+
207210
// Get the Hi-Lo expression. We use (and need) Lo since the offset needs to
208211
// be a constant expression, whereas CurrentFnSym is preemptible.
209212
const MCExpr *DiffToStart = MCBinaryExpr::createSub(
210213
MCSymbolRefExpr::create(Hi, OutContext),
211214
MCSymbolRefExpr::create(Lo, OutContext),
212215
OutContext);
213216
// Note: we cannot use Lo here since that is an assembler-local symbol and
214-
// this would result in EmitCheriCapability() creating a relocation against
217+
// this would result in emitCheriCapability() creating a relocation against
215218
// section plus offset rather than function + offset. We need the right
216219
// bounds and permissions info and need to use a non-preemptible alias.
217-
assert(CurrentFnBeginLocal && "Missing local function entry alias for EH!");
218-
OutStreamer->EmitCheriCapability(CurrentFnBeginLocal, DiffToStart,
219-
TLOF.getCheriCapabilitySize(TM));
220+
const MCExpr *Expr = MCSymbolRefExpr::create(CurrentFnBeginLocal, OutContext);
221+
Expr = MCBinaryExpr::createAdd(Expr, DiffToStart, OutContext);
222+
OutStreamer->emitCheriCapability(Expr, TLOF.getCheriCapabilitySize(TM));
220223
}
221224

222225
//===----------------------------------------------------------------------===//

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ void TargetLoweringObjectFileELF::emitPersonalityValue(
434434
Streamer.emitLabel(Label);
435435

436436
if (DL.isFatPointer(AS)) {
437-
Streamer.EmitCheriCapability(Sym, Size);
437+
Streamer.emitSymbolCheriCapability(Sym, Size);
438438
} else {
439439
Streamer.emitSymbolValue(Sym, Size);
440440
}

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ class MCAsmStreamer final : public MCStreamer {
390390
void emitBundleLock(bool AlignToEnd) override;
391391
void emitBundleUnlock() override;
392392

393-
void EmitCheriCapability(const MCExpr *Value, unsigned CapSize,
393+
void emitCheriCapability(const MCExpr *Value, unsigned CapSize,
394394
SMLoc Loc = SMLoc()) override;
395395
void emitCheriIntcap(const MCExpr *Expr, unsigned CapSize,
396396
SMLoc Loc = SMLoc()) override;
@@ -2483,7 +2483,7 @@ void MCAsmStreamer::emitBundleUnlock() {
24832483
EmitEOL();
24842484
}
24852485

2486-
void MCAsmStreamer::EmitCheriCapability(const MCExpr *Value, unsigned CapSize,
2486+
void MCAsmStreamer::emitCheriCapability(const MCExpr *Value, unsigned CapSize,
24872487
SMLoc Loc) {
24882488
OS << "\t.chericap\t";
24892489
if (MCTargetStreamer *TS = getTargetStreamer()) {

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5890,7 +5890,7 @@ bool AsmParser::parseDirectiveCheriCap(SMLoc DirectiveLoc) {
58905890
if (Expr->evaluateAsAbsolute(Value, getStreamer().getAssemblerPtr()))
58915891
getStreamer().emitCheriIntcap(Value, CapSize, ExprLoc);
58925892
else
5893-
getStreamer().EmitCheriCapability(Expr, CapSize, ExprLoc);
5893+
getStreamer().emitCheriCapability(Expr, CapSize, ExprLoc);
58945894

58955895
if (parseToken(AsmToken::EndOfStatement, "expected end of statement"))
58965896
return true;

llvm/lib/MC/MCStreamer.cpp

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -220,29 +220,15 @@ void MCStreamer::emitGPRel32Value(const MCExpr *Value) {
220220
report_fatal_error("unsupported directive in streamer");
221221
}
222222

223-
void MCStreamer::EmitCheriCapability(const MCExpr *Value, unsigned CapSize,
223+
void MCStreamer::emitCheriCapability(const MCExpr *Value, unsigned CapSize,
224224
SMLoc Loc) {
225-
report_fatal_error("EmitCheriCapability is not implemented for this target!");
225+
report_fatal_error("emitCheriCapability is not implemented for this target!");
226226
}
227227

228-
void MCStreamer::EmitCheriCapability(const MCSymbol *Value,
229-
const MCExpr *Addend, unsigned CapSize,
230-
SMLoc Loc) {
231-
const MCExpr *Expr = MCSymbolRefExpr::create(Value, Context);
232-
if (Addend)
233-
Expr = MCBinaryExpr::createAdd(Expr, Addend, Context);
234-
EmitCheriCapability(Expr, CapSize, Loc);
235-
}
236-
237-
void MCStreamer::EmitCheriCapability(const MCSymbol *Value, int64_t Addend,
238-
unsigned CapSize, SMLoc Loc) {
239-
EmitCheriCapability(Value, MCConstantExpr::create(Addend, Context), CapSize,
240-
Loc);
241-
}
242-
243-
void MCStreamer::EmitCheriCapability(const MCSymbol *Value, unsigned CapSize,
244-
SMLoc Loc) {
245-
EmitCheriCapability(Value, nullptr, CapSize, Loc);
228+
void MCStreamer::emitSymbolCheriCapability(const MCSymbol *Sym,
229+
unsigned CapSize) {
230+
const MCExpr *Expr = MCSymbolRefExpr::create(Sym, getContext());
231+
emitCheriCapability(Expr, CapSize);
246232
}
247233

248234
void MCStreamer::emitCheriIntcap(int64_t Value, unsigned CapSize, SMLoc Loc) {

llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void MipsELFStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
105105
Labels.clear();
106106
}
107107

108-
void MipsELFStreamer::EmitCheriCapability(const MCExpr *Value, unsigned CapSize,
108+
void MipsELFStreamer::emitCheriCapability(const MCExpr *Value, unsigned CapSize,
109109
SMLoc Loc) {
110110
visitUsedExpr(*Value);
111111

llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class MipsELFStreamer : public MCELFStreamer {
7575
void createPendingLabelRelocs();
7676

7777
protected:
78-
void EmitCheriCapability(const MCExpr *Value, unsigned CapSize,
78+
void emitCheriCapability(const MCExpr *Value, unsigned CapSize,
7979
SMLoc Loc) override;
8080
};
8181

llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ void RISCVELFStreamer::emitCheriIntcap(const MCExpr *Expr, unsigned CapSize,
208208
emitCheriIntcapGeneric(Expr, CapSize, Loc);
209209
}
210210

211-
void RISCVELFStreamer::EmitCheriCapability(const MCExpr *Value,
211+
void RISCVELFStreamer::emitCheriCapability(const MCExpr *Value,
212212
unsigned CapSize, SMLoc Loc) {
213213
visitUsedExpr(*Value);
214214

0 commit comments

Comments
 (0)