Skip to content

Commit

Permalink
[Xtensa] Add emit constant pool option.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreisfr committed Sep 8, 2022
1 parent 2f89cd7 commit 151975d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -4446,6 +4446,7 @@ def mfix_esp32_psram_cache_strategy_EQ : Joined<["-"], "mfix-esp32-psram-cache-s
HelpText<" Psram cache fix strategies : memw, nops">,
Values<"memw, nops">;
def mlongcalls : Flag<["-"], "mlongcalls">, Group<m_xtensa_Features_Group>;
def text_section_literals : Flag<["-"], "text-section-literals">, Group<m_xtensa_Features_Group>;

// These are legacy user-facing driver-level option spellings. They are always
// aliases for options that are spelled using the more common Unix / GNU flag
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2378,6 +2378,11 @@ void Clang::AddXtensaTargetArgs(const ArgList &Args,
}
}
}

if (Args.getLastArg(options::OPT_text_section_literals) != nullptr) {
CmdArgs.push_back("-mllvm");
CmdArgs.push_back("-text-section-literals");
}
}

void Clang::DumpCompilationDatabase(Compilation &C, StringRef Filename,
Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/Target/Xtensa/XtensaAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//===----------------------------------------------------------------------===//

#include "XtensaAsmPrinter.h"
#include "XtensaSubtarget.h"
#include "MCTargetDesc/XtensaInstPrinter.h"
#include "XtensaConstantPoolValue.h"
#include "XtensaMCInstLower.h"
Expand Down Expand Up @@ -68,6 +69,8 @@ void XtensaAsmPrinter::emitConstantPool() {
const Function &F = MF->getFunction();
const MachineConstantPool *MCP = MF->getConstantPool();
const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
const XtensaSubtarget *Subtarget = &MF->getSubtarget<XtensaSubtarget>();

if (CP.empty())
return;

Expand Down Expand Up @@ -97,6 +100,8 @@ void XtensaAsmPrinter::emitConstantPool() {
SectionName += ".literal";
}

if (Subtarget->useTextSectionLiterals())
SectionName = CSectionName;
MCSectionELF *S =
OutContext.getELFSection(SectionName, ELF::SHT_PROGBITS,
ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
Expand Down Expand Up @@ -213,6 +218,8 @@ void XtensaAsmPrinter::emitMachineConstantPoolValue(

const MCExpr *Expr = MCSymbolRefExpr::create(MCSym, VK, OutContext);
uint64_t Size = getDataLayout().getTypeAllocSize(ACPV->getType());
OutStreamer->emitCodeAlignment(
4, OutStreamer->getContext().getSubtargetInfo());
OutStreamer->emitLabel(LblSym);
OutStreamer->emitValue(Expr, Size);
}
Expand Down
13 changes: 13 additions & 0 deletions llvm/lib/Target/Xtensa/XtensaSubtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@

using namespace llvm;

enum PSRAMFixChoice {
ESP32_PSRAM_FIX_MEMW,
ESP32_PSRAM_FIX_NOPS
};

static cl::opt<bool> TextSectionLiterals("text-section-literals",
cl::init(false), cl::Hidden);

bool XtensaSubtarget::useTextSectionLiterals() const
{
return TextSectionLiterals;
}

XtensaSubtarget &
XtensaSubtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS) {
StringRef CPUName = CPU;
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/Xtensa/XtensaSubtarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ class XtensaSubtarget : public XtensaGenSubtargetInfo {

bool hasESP32S3Ops() const { return HasESP32S3Ops; }

bool useTextSectionLiterals() const;

// Automatically generated by tblgen.
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
};
Expand Down

0 comments on commit 151975d

Please sign in to comment.