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

Unified Diff: tools/pnacl-llc/pnacl-llc.cpp

Issue 940243003: PNaCl localmod mods in LLVM to 223109 (local files only) (Closed)
Patch Set: xx Created 5 years, 10 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
« no previous file with comments | « tools/pnacl-llc/ThreadedStreamingCache.cpp ('k') | tools/pnacl-thaw/CMakeLists.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/pnacl-llc/pnacl-llc.cpp
diff --git a/tools/pnacl-llc/pnacl-llc.cpp b/tools/pnacl-llc/pnacl-llc.cpp
index 27c7a07ac690dd820d42c9486d1380f0f346d7c9..f18938aa742f4cacc41f427f52071895a4cf2688 100644
--- a/tools/pnacl-llc/pnacl-llc.cpp
+++ b/tools/pnacl-llc/pnacl-llc.cpp
@@ -16,7 +16,6 @@
#include "llvm/Bitcode/NaCl/NaClReaderWriter.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/CodeGen/CommandFlags.h"
-#include "llvm/CodeGen/LinkAllAsmWriterComponents.h"
#include "llvm/CodeGen/LinkAllCodegenComponents.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/LLVMContext.h"
@@ -34,16 +33,16 @@
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/Mutex.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
-#include "llvm/Support/StreamableMemoryObject.h"
+#include "llvm/Support/StreamingMemoryObject.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Target/TargetLibraryInfo.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetSubtargetInfo.h"
#include "llvm/Transforms/NaCl.h"
#include "ThreadedFunctionQueue.h"
@@ -226,14 +225,13 @@ static tool_output_file *GetOutputStream(const char *TargetName,
}
// Open the file.
- std::string error;
+ std::error_code EC;
sys::fs::OpenFlags OpenFlags = sys::fs::F_None;
if (!Binary)
OpenFlags |= sys::fs::F_Text;
- tool_output_file *FDOut =
- new tool_output_file(Filename.c_str(), error, OpenFlags);
- if (!error.empty()) {
- errs() << error << '\n';
+ tool_output_file *FDOut = new tool_output_file(Filename, EC, OpenFlags);
+ if (EC) {
+ errs() << EC.message() << '\n';
delete FDOut;
return nullptr;
}
@@ -319,9 +317,10 @@ static void CheckABIVerifyErrors(PNaClABIErrorReporter &Reporter,
Reporter.reset();
}
-static Module* getModule(StringRef ProgramName, LLVMContext &Context,
- StreamingMemoryObject *StreamingObject) {
- Module *M = nullptr;
+static std::unique_ptr<Module> getModule(
+ StringRef ProgramName, LLVMContext &Context,
+ StreamingMemoryObject *StreamingObject) {
+ std::unique_ptr<Module> M;
SMDiagnostic Err;
std::string VerboseBuffer;
raw_string_ostream VerboseStrm(VerboseBuffer);
@@ -329,15 +328,15 @@ static Module* getModule(StringRef ProgramName, LLVMContext &Context,
std::string StrError;
switch (InputFileFormat) {
case PNaClFormat:
- M = getNaClStreamedBitcodeModule(
+ M.reset(getNaClStreamedBitcodeModule(
InputFilename,
new ThreadedStreamingCache(StreamingObject), Context, &VerboseStrm,
- &StrError);
+ &StrError));
break;
case LLVMFormat:
- M = getStreamedBitcodeModule(
+ M.reset(getStreamedBitcodeModule(
InputFilename,
- new ThreadedStreamingCache(StreamingObject), Context, &StrError);
+ new ThreadedStreamingCache(StreamingObject), Context, &StrError));
break;
case AutodetectFileFormat:
report_fatal_error("Command can't autodetect file format!");
@@ -364,7 +363,7 @@ static Module* getModule(StringRef ProgramName, LLVMContext &Context,
return nullptr;
#endif
}
- return M;
+ return std::move(M);
}
static cl::opt<bool>
@@ -372,7 +371,7 @@ ExternalizeAll("externalize",
cl::desc("Externalize all symbols"),
cl::init(false));
-static int runCompilePasses(Module *mod,
+static int runCompilePasses(Module *ModuleRef,
jvoung (off chromium) 2015/02/24 18:38:48 Went ahead and capitalized the variable name for c
unsigned ModuleIndex,
ThreadedFunctionQueue *FuncQueue,
const Triple &TheTriple,
@@ -385,14 +384,14 @@ static int runCompilePasses(Module *mod,
// Add function and global names, and give them external linkage.
// This relies on LLVM's consistent auto-generation of names, we could
// maybe do our own in case something changes there.
- for (Module::iterator I = mod->begin(), E = mod->end(); I != E; ++I) {
- if (!I->hasName())
- I->setName("Function");
- if (I->hasInternalLinkage())
- I->setLinkage(GlobalValue::ExternalLinkage);
+ for (Function &F : *ModuleRef) {
+ if (!F.hasName())
+ F.setName("Function");
+ if (F.hasInternalLinkage())
+ F.setLinkage(GlobalValue::ExternalLinkage);
}
- for (Module::global_iterator GI = mod->global_begin(),
- GE = mod->global_end();
+ for (Module::global_iterator GI = ModuleRef->global_begin(),
+ GE = ModuleRef->global_end();
GI != GE; ++GI) {
if (!GI->hasName())
GI->setName("Global");
@@ -402,8 +401,8 @@ static int runCompilePasses(Module *mod,
if (ModuleIndex > 0) {
// Remove the initializers for all global variables, turning them into
// declarations.
- for (Module::global_iterator GI = mod->global_begin(),
- GE = mod->global_end();
+ for (Module::global_iterator GI = ModuleRef->global_begin(),
+ GE = ModuleRef->global_end();
GI != GE; ++GI) {
assert(GI->hasInitializer() && "Global variable missing initializer");
Constant *Init = GI->getInitializer();
@@ -417,12 +416,12 @@ static int runCompilePasses(Module *mod,
// Make all non-weak symbols hidden for better code. We cannot do
// this for weak symbols. The linker complains when some weak
// symbols are not resolved.
- for (Module::iterator I = mod->begin(), E = mod->end(); I != E; ++I) {
- if (!I->isWeakForLinker() && !I->hasLocalLinkage())
- I->setVisibility(GlobalValue::HiddenVisibility);
+ for (Function &F : *ModuleRef) {
+ if (!F.isWeakForLinker() && !F.hasLocalLinkage())
+ F.setVisibility(GlobalValue::HiddenVisibility);
}
- for (Module::global_iterator GI = mod->global_begin(),
- GE = mod->global_end();
+ for (Module::global_iterator GI = ModuleRef->global_begin(),
+ GE = ModuleRef->global_end();
GI != GE; ++GI) {
if (!GI->isWeakForLinker() && !GI->hasLocalLinkage())
GI->setVisibility(GlobalValue::HiddenVisibility);
@@ -431,14 +430,14 @@ static int runCompilePasses(Module *mod,
// Build up all of the passes that we want to do to the module.
std::unique_ptr<PassManagerBase> PM;
if (LazyBitcode)
- PM.reset(new FunctionPassManager(mod));
+ PM.reset(new FunctionPassManager(ModuleRef));
else
PM.reset(new PassManager());
// Add the target data from the target machine, if it exists, or the module.
- if (const DataLayout *DL = Target.getDataLayout())
- mod->setDataLayout(DL);
- PM->add(new DataLayoutPass(mod));
+ if (const DataLayout *DL = Target.getSubtargetImpl()->getDataLayout())
+ ModuleRef->setDataLayout(DL);
+ PM->add(new DataLayoutPass());
// For conformance with llc, we let the user disable LLVM IR verification with
// -disable-verify. Unlike llc, when LLVM IR verification is enabled we only
@@ -482,11 +481,11 @@ static int runCompilePasses(Module *mod,
unsigned FuncIndex = 0;
switch (SplitModuleSched) {
case SplitModuleStatic:
- for (Module::iterator I = mod->begin(), E = mod->end(); I != E; ++I) {
+ for (Function &F : *ModuleRef) {
if (FuncQueue->GrabFunctionStatic(FuncIndex, ModuleIndex)) {
- FPM->run(*I);
- CheckABIVerifyErrors(ABIErrorReporter, "Function " + I->getName());
- I->Dematerialize();
+ FPM->run(F);
+ CheckABIVerifyErrors(ABIErrorReporter, "Function " + F.getName());
+ F.Dematerialize();
}
++FuncIndex;
}
@@ -494,7 +493,7 @@ static int runCompilePasses(Module *mod,
case SplitModuleDynamic:
unsigned ChunkSize = 0;
unsigned NumFunctions = FuncQueue->Size();
- Module::iterator I = mod->begin();
+ Module::iterator I = ModuleRef->begin();
while (FuncIndex < NumFunctions) {
ChunkSize = FuncQueue->RecommendedChunkSize();
unsigned NextIndex;
@@ -527,7 +526,7 @@ static int runCompilePasses(Module *mod,
}
FPM->doFinalization();
} else
- static_cast<PassManager *>(PM.get())->run(*mod);
+ static_cast<PassManager *>(PM.get())->run(*ModuleRef);
return 0;
}
@@ -538,7 +537,7 @@ static int compileSplitModule(const TargetOptions &Options,
const std::string &FeaturesStr,
CodeGenOpt::Level OLvl,
const StringRef &ProgramName,
- Module *GlobalModule,
+ Module *GlobalModuleRef,
StreamingMemoryObject *StreamingObject,
unsigned ModuleIndex,
ThreadedFunctionQueue *FuncQueue) {
@@ -557,27 +556,29 @@ static int compileSplitModule(const TargetOptions &Options,
// The OwningPtrs are only used if we are not the primary module.
std::unique_ptr<LLVMContext> C;
std::unique_ptr<Module> M;
- Module *mod(nullptr);
+ Module *ModuleRef = nullptr;
if (ModuleIndex == 0) {
- mod = GlobalModule;
+ ModuleRef = GlobalModuleRef;
} else {
C.reset(new LLVMContext());
- mod = getModule(ProgramName, *C, StreamingObject);
- if (!mod)
+ M = getModule(ProgramName, *C, StreamingObject);
+ if (!M)
return 1;
- M.reset(mod);
+ // M owns the temporary module, but use a reference through ModuleRef
+ // to also work in the case we are using GlobalModuleRef.
+ ModuleRef = M.get();
// Add declarations for external functions required by PNaCl. The
// ResolvePNaClIntrinsics function pass running during streaming
// depends on these declarations being in the module.
std::unique_ptr<ModulePass> AddPNaClExternalDeclsPass(
createAddPNaClExternalDeclsPass());
- AddPNaClExternalDeclsPass->runOnModule(*M);
+ AddPNaClExternalDeclsPass->runOnModule(*ModuleRef);
AddPNaClExternalDeclsPass.reset();
}
- mod->setTargetTriple(Triple::normalize(UserDefinedTriple));
+ ModuleRef->setTargetTriple(Triple::normalize(UserDefinedTriple));
{
#if !defined(PNACL_BROWSER_TRANSLATOR)
@@ -592,11 +593,11 @@ static int compileSplitModule(const TargetOptions &Options,
if (!Out) return 1;
formatted_raw_ostream FOS(Out->os());
#else
- raw_fd_ostream ROS(getObjectFileFD(ModuleIndex), true, sys::fs::F_None);
+ raw_fd_ostream ROS(getObjectFileFD(ModuleIndex), /* ShouldClose */ true);
ROS.SetBufferSize(1 << 20);
formatted_raw_ostream FOS(ROS);
#endif
- int ret = runCompilePasses(mod, ModuleIndex, FuncQueue,
+ int ret = runCompilePasses(ModuleRef, ModuleIndex, FuncQueue,
TheTriple, Target, ProgramName,
FOS);
if (ret)
@@ -619,7 +620,7 @@ struct ThreadData {
std::string FeaturesStr;
CodeGenOpt::Level OLvl;
std::string ProgramName;
- Module *GlobalModule;
+ Module *GlobalModuleRef;
StreamingMemoryObject *StreamingObject;
unsigned ModuleIndex;
ThreadedFunctionQueue *FuncQueue;
@@ -634,7 +635,7 @@ static void *runCompileThread(void *arg) {
Data->FeaturesStr,
Data->OLvl,
Data->ProgramName,
- Data->GlobalModule,
+ Data->GlobalModuleRef,
Data->StreamingObject,
Data->ModuleIndex,
Data->FuncQueue);
@@ -649,7 +650,7 @@ static int compileModule(StringRef ProgramName) {
// plumbing change to fix it, we work around it by using a new context here
// and leaving PseudoSourceValue as the only user of the global context.
std::unique_ptr<LLVMContext> MainContext(new LLVMContext());
- std::unique_ptr<Module> mod;
+ std::unique_ptr<Module> MainMod;
Triple TheTriple;
PNaClABIErrorReporter ABIErrorReporter;
std::unique_ptr<StreamingMemoryObject> StreamingObject;
@@ -672,15 +673,15 @@ static int compileModule(StringRef ProgramName) {
StreamingObject.reset(new StreamingMemoryObjectImpl(FileStreamer));
}
#endif
- mod.reset(getModule(ProgramName, *MainContext.get(), StreamingObject.get()));
+ MainMod = getModule(ProgramName, *MainContext.get(), StreamingObject.get());
- if (!mod) return 1;
+ if (!MainMod) return 1;
if (PNaClABIVerify) {
// Verify the module (but not the functions yet)
std::unique_ptr<ModulePass> VerifyPass(
createPNaClABIVerifyModulePass(&ABIErrorReporter, LazyBitcode));
- VerifyPass->runOnModule(*mod);
+ VerifyPass->runOnModule(*MainMod);
CheckABIVerifyErrors(ABIErrorReporter, "Module");
VerifyPass.reset();
}
@@ -690,14 +691,14 @@ static int compileModule(StringRef ProgramName) {
// depends on these declarations being in the module.
std::unique_ptr<ModulePass> AddPNaClExternalDeclsPass(
createAddPNaClExternalDeclsPass());
- AddPNaClExternalDeclsPass->runOnModule(*mod);
+ AddPNaClExternalDeclsPass->runOnModule(*MainMod);
AddPNaClExternalDeclsPass.reset();
if (UserDefinedTriple.empty()) {
report_fatal_error("-mtriple must be set to a target triple for pnacl-llc");
} else {
- mod->setTargetTriple(Triple::normalize(UserDefinedTriple));
- TheTriple = Triple(mod->getTargetTriple());
+ MainMod->setTargetTriple(Triple::normalize(UserDefinedTriple));
+ TheTriple = Triple(MainMod->getTargetTriple());
}
// Get the target specific parser.
@@ -738,13 +739,13 @@ static int compileModule(StringRef ProgramName) {
SmallVector<pthread_t, 4> Pthreads(SplitModuleCount);
SmallVector<ThreadData, 4> ThreadDatas(SplitModuleCount);
- ThreadedFunctionQueue FuncQueue(mod.get(), SplitModuleCount);
+ ThreadedFunctionQueue FuncQueue(MainMod.get(), SplitModuleCount);
if (SplitModuleCount == 1) {
// No need for dynamic scheduling with one thread.
SplitModuleSched = SplitModuleStatic;
return compileSplitModule(Options, TheTriple, TheTarget, FeaturesStr,
- OLvl, ProgramName, mod.get(), nullptr, 0,
+ OLvl, ProgramName, MainMod.get(), nullptr, 0,
&FuncQueue);
}
@@ -755,7 +756,7 @@ static int compileModule(StringRef ProgramName) {
ThreadDatas[ModuleIndex].FeaturesStr = FeaturesStr;
ThreadDatas[ModuleIndex].OLvl = OLvl;
ThreadDatas[ModuleIndex].ProgramName = ProgramName.str();
- ThreadDatas[ModuleIndex].GlobalModule = mod.get();
+ ThreadDatas[ModuleIndex].GlobalModuleRef = MainMod.get();
ThreadDatas[ModuleIndex].StreamingObject = StreamingObject.get();
ThreadDatas[ModuleIndex].ModuleIndex = ModuleIndex;
ThreadDatas[ModuleIndex].FuncQueue = &FuncQueue;
« no previous file with comments | « tools/pnacl-llc/ThreadedStreamingCache.cpp ('k') | tools/pnacl-thaw/CMakeLists.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698