Allow ability to name unnamed global addresses in Subzero.
This is a workaround for issue that Subzero currently assumes all
global addresses have a name, but finalized pexe files leave most
global addresses unnamed.
It does this by allowing two optional command-line flag name prefixes
that are used to generate names for unnamed global addresses.
BUG= None
R=stichnot@chromium.org
Review URL: https://codereview.chromium.org/567703003
diff --git a/src/IceTranslator.cpp b/src/IceTranslator.cpp
index 59403d2..05332b4 100644
--- a/src/IceTranslator.cpp
+++ b/src/IceTranslator.cpp
@@ -16,7 +16,9 @@
#include "IceCfg.h"
#include "IceClFlags.h"
+#include "IceDefs.h"
#include "IceTargetLowering.h"
+#include "llvm/IR/Module.h"
#include <iostream>
@@ -24,14 +26,58 @@
Translator::~Translator() {}
-void Translator::translateFcn(Ice::Cfg *Fcn) {
+namespace {
+void setValueName(llvm::Value *V, const char *Kind, const IceString &Prefix,
+ uint32_t &NameIndex, Ostream &errs) {
+ if (V->hasName()) {
+ const std::string &Name(V->getName());
+ if (Name.find(Prefix) == 0) {
+ errs << "Warning: Default " << Kind << " prefix '" << Prefix
+ << "' conflicts with name '" << Name << "'.\n";
+ }
+ return;
+ }
+ if (NameIndex == 0) {
+ V->setName(Prefix);
+ ++NameIndex;
+ return;
+ }
+ std::string Buffer;
+ llvm::raw_string_ostream StrBuf(Buffer);
+ StrBuf << Prefix << NameIndex;
+ V->setName(StrBuf.str());
+ ++NameIndex;
+}
+} // end of anonymous namespace
+
+void Translator::nameUnnamedGlobalAddresses(llvm::Module *Mod) {
+ const IceString &GlobalPrefix = Flags.DefaultGlobalPrefix;
+ Ostream &errs = Ctx->getStrDump();
+ if (!GlobalPrefix.empty()) {
+ uint32_t NameIndex = 0;
+ for (llvm::Module::global_iterator I = Mod->global_begin(),
+ E = Mod->global_end();
+ I != E; ++I) {
+ setValueName(I, "global", GlobalPrefix, NameIndex, errs);
+ }
+ }
+ const IceString &FunctionPrefix = Flags.DefaultFunctionPrefix;
+ if (FunctionPrefix.empty())
+ return;
+ uint32_t NameIndex = 0;
+ for (llvm::Module::iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) {
+ setValueName(I, "function", FunctionPrefix, NameIndex, errs);
+ }
+}
+
+void Translator::translateFcn(Cfg *Fcn) {
Func.reset(Fcn);
if (Ctx->getFlags().DisableInternal)
Func->setInternal(false);
if (Ctx->getFlags().DisableTranslation) {
Func->dump();
} else {
- Ice::Timer TTranslate;
+ Timer TTranslate;
Func->translate();
if (Ctx->getFlags().SubzeroTimingEnabled) {
std::cerr << "[Subzero timing] Translate function "
@@ -43,7 +89,7 @@
ErrorStatus = true;
}
- Ice::Timer TEmit;
+ Timer TEmit;
Func->emit();
if (Ctx->getFlags().SubzeroTimingEnabled) {
std::cerr << "[Subzero timing] Emit function " << Func->getFunctionName()