aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Transforms/NaCl.h3
-rw-r--r--lib/Analysis/LLVMBuild.txt2
-rw-r--r--lib/Analysis/Makefile2
-rw-r--r--lib/Analysis/NaCl/CMakeLists.txt6
-rw-r--r--lib/Analysis/NaCl/LLVMBuild.txt23
-rw-r--r--lib/Analysis/NaCl/Makefile14
-rw-r--r--lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp66
-rw-r--r--lib/Analysis/NaCl/PNaClABIVerifyModule.cpp86
-rw-r--r--lib/Transforms/NaCl/LLVMBuild.txt4
9 files changed, 202 insertions, 4 deletions
diff --git a/include/llvm/Transforms/NaCl.h b/include/llvm/Transforms/NaCl.h
index 79c9b9fe79..ecdfa9043f 100644
--- a/include/llvm/Transforms/NaCl.h
+++ b/include/llvm/Transforms/NaCl.h
@@ -12,11 +12,14 @@
namespace llvm {
+class FunctionPass;
class ModulePass;
ModulePass *createExpandCtorsPass();
ModulePass *createExpandTlsPass();
ModulePass *createExpandTlsConstantExprPass();
+FunctionPass *createPNaClABIVerifyFunctionsPass();
+ModulePass *createPNaClABIVerifyModulePass();
}
diff --git a/lib/Analysis/LLVMBuild.txt b/lib/Analysis/LLVMBuild.txt
index a8a8079d1e..de734ec3f7 100644
--- a/lib/Analysis/LLVMBuild.txt
+++ b/lib/Analysis/LLVMBuild.txt
@@ -16,7 +16,7 @@
;===------------------------------------------------------------------------===;
[common]
-subdirectories = IPA
+subdirectories = IPA NaCl
[component_0]
type = Library
diff --git a/lib/Analysis/Makefile b/lib/Analysis/Makefile
index 4af6d350a6..426ed1699d 100644
--- a/lib/Analysis/Makefile
+++ b/lib/Analysis/Makefile
@@ -9,7 +9,7 @@
LEVEL = ../..
LIBRARYNAME = LLVMAnalysis
-DIRS = IPA
+DIRS = IPA NaCl
BUILD_ARCHIVE = 1
include $(LEVEL)/Makefile.common
diff --git a/lib/Analysis/NaCl/CMakeLists.txt b/lib/Analysis/NaCl/CMakeLists.txt
new file mode 100644
index 0000000000..8a5eceb3e4
--- /dev/null
+++ b/lib/Analysis/NaCl/CMakeLists.txt
@@ -0,0 +1,6 @@
+add_llvm_library(LLVMAnalysisNaCl
+ PNaClABIVerifyFunctions.cpp
+ PNaClABIVerifyModule.cpp
+ )
+
+add_dependencies(LLVMAnalysisNaCl intrinsics_gen)
diff --git a/lib/Analysis/NaCl/LLVMBuild.txt b/lib/Analysis/NaCl/LLVMBuild.txt
new file mode 100644
index 0000000000..997803bb5d
--- /dev/null
+++ b/lib/Analysis/NaCl/LLVMBuild.txt
@@ -0,0 +1,23 @@
+;===- ./lib/Analysis/NaCl/LLVMBuild.txt ----------------------*- Conf -*--===;
+;
+; The LLVM Compiler Infrastructure
+;
+; This file is distributed under the University of Illinois Open Source
+; License. See LICENSE.TXT for details.
+;
+;===------------------------------------------------------------------------===;
+;
+; This is an LLVMBuild description file for the components in this subdirectory.
+;
+; For more information on the LLVMBuild system, please see:
+;
+; http://llvm.org/docs/LLVMBuild.html
+;
+;===------------------------------------------------------------------------===;
+
+[component_0]
+type = Library
+name = NaClAnalysis
+parent = Analysis
+library_name = NaClAnalysis
+required_libraries = Core
diff --git a/lib/Analysis/NaCl/Makefile b/lib/Analysis/NaCl/Makefile
new file mode 100644
index 0000000000..6a2f0ed8d9
--- /dev/null
+++ b/lib/Analysis/NaCl/Makefile
@@ -0,0 +1,14 @@
+##===- lib/Analysis/NaCl/Makefile-------------------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../../..
+LIBRARYNAME = LLVMAnalysisNaCl
+BUILD_ARCHIVE = 1
+
+include $(LEVEL)/Makefile.common \ No newline at end of file
diff --git a/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp b/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp
new file mode 100644
index 0000000000..a2e5f1b2a5
--- /dev/null
+++ b/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp
@@ -0,0 +1,66 @@
+//===- PNaClABIVerifyFunctions.cpp - Verify PNaCl ABI rules --------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Verify function-level PNaCl ABI requirements.
+//
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/Twine.h"
+#include "llvm/Function.h"
+#include "llvm/Instruction.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Transforms/NaCl.h"
+using namespace llvm;
+
+namespace {
+
+// Checks that examine anything in the function body should be in
+// FunctionPasses to make them streaming-friendly
+struct PNaClABIVerifyFunctions : public FunctionPass {
+ static char ID;
+ PNaClABIVerifyFunctions() : FunctionPass(ID) {}
+ bool runOnFunction(Function &F);
+};
+} // and anonymous namespace
+
+bool PNaClABIVerifyFunctions::runOnFunction(Function &F) {
+ for (Function::const_iterator FI = F.begin(), FE = F.end();
+ FI != FE; ++FI) {
+ for (BasicBlock::const_iterator BBI = FI->begin(), BBE = FI->end();
+ BBI != BBE; ++BBI) {
+ switch (BBI->getOpcode()) {
+ // Terminator instructions
+ case Instruction::Ret:
+ case Instruction::Br:
+ case Instruction::Switch:
+ case Instruction::Resume:
+ case Instruction::Unreachable:
+ // indirectbr is not allowed for now.
+ // invoke and call are handled separately.
+ break;
+ default:
+ errs() << Twine("Function ") + FI->getName() +
+ " has Disallowed instruction: " +
+ BBI->getOpcodeName() + "\n";
+ }
+ }
+ }
+ return false;
+}
+
+char PNaClABIVerifyFunctions::ID = 0;
+
+static RegisterPass<PNaClABIVerifyFunctions> X("pnaclabi-functions",
+ "Verify functions for PNaCl", false, false);
+
+FunctionPass *llvm::createPNaClABIVerifyFunctionsPass() {
+ return new PNaClABIVerifyFunctions();
+}
diff --git a/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp
new file mode 100644
index 0000000000..f39b83881e
--- /dev/null
+++ b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp
@@ -0,0 +1,86 @@
+//===- PNaClABIVerifyModule.cpp - Verify PNaCl ABI rules --------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Verify module-level PNaCl ABI requirements (specifically those that do not
+// require looking at the function bodies)
+//
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/Twine.h"
+#include "llvm/Module.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Transforms/NaCl.h"
+using namespace llvm;
+
+namespace {
+
+// This pass should not touch function bodies, to stay streaming-friendly
+struct PNaClABIVerifyModule : public ModulePass {
+ static char ID;
+ PNaClABIVerifyModule() : ModulePass(ID) {}
+ bool runOnModule(Module &M);
+};
+
+static const char* LinkageName(GlobalValue::LinkageTypes LT) {
+ // This logic is taken from PrintLinkage in lib/VMCore/AsmWriter.cpp
+ switch (LT) {
+ case GlobalValue::ExternalLinkage: return "external";
+ case GlobalValue::PrivateLinkage: return "private ";
+ case GlobalValue::LinkerPrivateLinkage: return "linker_private ";
+ case GlobalValue::LinkerPrivateWeakLinkage: return "linker_private_weak ";
+ case GlobalValue::InternalLinkage: return "internal ";
+ case GlobalValue::LinkOnceAnyLinkage: return "linkonce ";
+ case GlobalValue::LinkOnceODRLinkage: return "linkonce_odr ";
+ case GlobalValue::LinkOnceODRAutoHideLinkage:
+ return "linkonce_odr_auto_hide ";
+ case GlobalValue::WeakAnyLinkage: return "weak ";
+ case GlobalValue::WeakODRLinkage: return "weak_odr ";
+ case GlobalValue::CommonLinkage: return "common ";
+ case GlobalValue::AppendingLinkage: return "appending ";
+ case GlobalValue::DLLImportLinkage: return "dllimport ";
+ case GlobalValue::DLLExportLinkage: return "dllexport ";
+ case GlobalValue::ExternalWeakLinkage: return "extern_weak ";
+ case GlobalValue::AvailableExternallyLinkage:
+ return "available_externally ";
+ default:
+ return "unknown";
+ }
+}
+
+} // end anonymous namespace
+
+bool PNaClABIVerifyModule::runOnModule(Module &M) {
+ // Check GV linkage types
+ for (Module::const_global_iterator MI = M.global_begin(), ME = M.global_end();
+ MI != ME; ++MI) {
+ switch(MI->getLinkage()) {
+ case GlobalValue::ExternalLinkage:
+ case GlobalValue::AvailableExternallyLinkage:
+ case GlobalValue::InternalLinkage:
+ case GlobalValue::PrivateLinkage:
+ break;
+ default:
+ errs() << (Twine("Variable ") + MI->getName() +
+ " has Disallowed linkage type: " +
+ LinkageName(MI->getLinkage()) + "\n");
+ }
+ }
+ return false;
+}
+
+char PNaClABIVerifyModule::ID = 0;
+
+static RegisterPass<PNaClABIVerifyModule> X("pnaclabi-module",
+ "Verify module for PNaCl", false, false);
+
+ModulePass *llvm::createPNaClABIVerifyModulePass() {
+ return new PNaClABIVerifyModule();
+}
diff --git a/lib/Transforms/NaCl/LLVMBuild.txt b/lib/Transforms/NaCl/LLVMBuild.txt
index 2f1522b3e5..14c85c9c04 100644
--- a/lib/Transforms/NaCl/LLVMBuild.txt
+++ b/lib/Transforms/NaCl/LLVMBuild.txt
@@ -17,7 +17,7 @@
[component_0]
type = Library
-name = NaCl
+name = NaClTransforms
parent = Transforms
-library_name = NaCl
+library_name = NaClTransforms
required_libraries = Core