Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: src/IceTranslator.cpp

Issue 567703003: Allow ability to name unnamed global addresses in Subzero. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Add tests Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/IceTranslator.cpp
diff --git a/src/IceTranslator.cpp b/src/IceTranslator.cpp
index 59403d284e12e9a9e3da62a0ab63236d1df15ed2..247eb9b302e03305dabe23b0ab3d6f624c4e1143 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,6 +26,41 @@ using namespace Ice;
Translator::~Translator() {}
+namespace {
+static void setValueName(llvm::Value *V, const std::string &Prefix,
+ uint32_t &NameIndex) {
+ if (V->hasName()) {
+ const std::string &Name(V->getName());
+ if (Name.find(Prefix) == 0) {
+ std::string Buffer;
+ llvm::raw_string_ostream StrBuf(Buffer);
+ llvm::outs() << "Warning: Default global prefix '" << Prefix
Jim Stichnoth 2014/09/11 22:08:19 Can you use Translator::getGlobalContext()->getStr
Karl 2014/09/12 16:29:06 Done.
+ << "' conflicts with name '" << Name << "'.";
+ }
+ return;
+ }
+ std::string Buffer;
+ llvm::raw_string_ostream StrBuf(Buffer);
+ StrBuf << Prefix << NameIndex;
+ V->setName(StrBuf.str());
+ ++NameIndex;
+}
+}
+
+void Translator::nameUnnamedGlobalAddresses(llvm::Module *Mod) {
+ const std::string &Prefix = getFlags().DefaultGlobalPrefix;
+ if (Prefix.empty()) return;
+ uint32_t NameIndex = 0;
+ for (llvm::Module::global_iterator
+ I = Mod->global_begin(), E = Mod->global_end();
+ I != E; ++I) {
+ setValueName(I, Prefix, NameIndex);
+ }
+ for (llvm::Module::iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) {
+ setValueName(I, Prefix, NameIndex);
+ }
+}
+
void Translator::translateFcn(Ice::Cfg *Fcn) {
Func.reset(Fcn);
if (Ctx->getFlags().DisableInternal)

Powered by Google App Engine
This is Rietveld 408576698