Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Xtensa] Add emit constant pool option. #1

Open
wants to merge 2 commits into
base: xtensa_release_14.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 9 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 @@ -150,6 +155,8 @@ void XtensaAsmPrinter::emitConstantPool() {

OutStreamer->emitRawText(StringRef(str));
} else {
OutStreamer->emitCodeAlignment(
4, OutStreamer->getContext().getSubtargetInfo());
OutStreamer->emitLabel(LblSym);
emitGlobalConstant(getDataLayout(), CPE.Val.ConstVal);
}
Expand Down Expand Up @@ -213,6 +220,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