Skip to content
Snippets Groups Projects
Commit e0315833 authored by Alessandro Di Federico's avatar Alessandro Di Federico
Browse files

Set CSVs linkage to internal

This simple commit should improve performance of the generated program
sensibly. Basically all the global variables will have internal linkage
from now on (unless the `--external` parameter is specified on the
command line). This way, the compiler will be able to avoid load/store
instructions when leaving code in the current translation unit.
parent e01f0cc2
No related branches found
No related tags found
No related merge requests found
......@@ -73,7 +73,8 @@ CodeGenerator::CodeGenerator(BinaryFile &Binary,
std::string BBSummary,
bool EnableOSRA,
bool DetectFunctionBoundaries,
bool EnableLinking) :
bool EnableLinking,
bool ExternalCSVs) :
TargetArchitecture(Target),
Context(getGlobalContext()),
TheModule((new Module("top", Context))),
......@@ -82,7 +83,8 @@ CodeGenerator::CodeGenerator(BinaryFile &Binary,
Binary(Binary),
EnableOSRA(EnableOSRA),
DetectFunctionBoundaries(DetectFunctionBoundaries),
EnableLinking(EnableLinking)
EnableLinking(EnableLinking),
ExternalCSVs(ExternalCSVs)
{
OriginalInstrMDKind = Context.getMDKindID("oi");
PTCInstrMDKind = Context.getMDKindID("pi");
......@@ -910,6 +912,9 @@ void CodeGenerator::translate(uint64_t VirtualAddress) {
JumpTargets.noReturn().cleanup();
Translator.finalizeNewPCMarkers(CoveragePath);
Variables.finalize(ExternalCSVs);
Debug->generateDebugInfo();
}
......
......@@ -73,7 +73,8 @@ public:
std::string BBSummary,
bool EnableOSRA,
bool DetectFunctionBoundaries,
bool EnableLinking);
bool EnableLinking,
bool ExternalCSVs);
~CodeGenerator();
......@@ -121,6 +122,7 @@ private:
std::string FunctionListPath;
bool DetectFunctionBoundaries;
bool EnableLinking;
bool ExternalCSVs;
};
#endif // _CODEGENERATOR_H
......@@ -70,6 +70,11 @@ are described:
appear as calls to extern functions. This option makes
the resulting module non-functioncal but it's useful for
analysis-only purposes.
:``-E``, ``--external``: Set the linkage of global variables representing the
CPU state (aka CSVs) to `external` instead of
`internal`. This degrades performances of the produced
binary sensibly but makes debugging the generated code
easier.
:``-S``, ``--use-sections``: If they are available, ELF sections are employed to
identify executable code. This options is useful to
evaluate `revamb` ignoring the code identification
......
......@@ -52,6 +52,7 @@ struct ProgramParameters {
bool UseSections;
bool DetectFunctionsBoundaries;
bool NoLink;
bool External;
};
using LibraryDestructor = GenericFunctor<decltype(&dlclose), &dlclose>;
......@@ -181,6 +182,8 @@ static int parseArgs(int Argc, const char *Argv[],
"disable OSRA."),
OPT_BOOLEAN('L', "no-link", &Parameters->NoLink,
"do not link the output to QEMU helpers."),
OPT_BOOLEAN('E', "external", &Parameters->External,
"set CSVs linkage to external, useful for debugging purposes."),
OPT_BOOLEAN('S', "use-sections", &Parameters->UseSections,
"use section informations, if available."),
OPT_STRING('b', "bb-summary",
......@@ -287,7 +290,8 @@ int main(int argc, const char *argv[]) {
std::string(Parameters.BBSummaryPath),
!Parameters.NoOSRA,
Parameters.DetectFunctionsBoundaries,
!Parameters.NoLink);
!Parameters.NoLink,
Parameters.External);
Generator.translate(Parameters.EntryPointAddress);
......
......@@ -167,6 +167,18 @@ public:
return storeToCPUStateOffset(Builder, StoreSize, ActualOffset, ToStore);
}
/// \brief Perform finalization steps on variables
///
/// \param ExternalCSVs true if CSVs linkage should not be turned into static.
void finalize(bool ExternalCSVs) {
if (!ExternalCSVs) {
for (auto P : CPUStateGlobals)
P.second->setLinkage(llvm::GlobalValue::InternalLinkage);
for (auto P : OtherGlobals)
P.second->setLinkage(llvm::GlobalValue::InternalLinkage);
}
}
private:
llvm::Value *loadFromCPUStateOffset(llvm::IRBuilder<> &Builder,
unsigned LoadSize,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment