summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhigang Gong <zhigang.gong@intel.com>2015-03-19 17:25:26 +0800
committerZhigang Gong <zhigang.gong@intel.com>2015-04-13 16:11:08 +0800
commit54ebb557a940b041e52d6527b2d0c4ffeb62be28 (patch)
tree719551ac6c2da1ed28991fe81d248a44696e63e3
parent4c530f94ee4e016e32997bb60f7f74589301b412 (diff)
strip unsupported attributes and calling conventions.
Signed-off-by: Zhigang Gong <zhigang.gong@intel.com> Reviewed-by: "Yang, Rong R" <rong.r.yang@intel.com>
-rw-r--r--backend/src/CMakeLists.txt1
-rw-r--r--backend/src/llvm/StripAttributes.cpp119
-rw-r--r--backend/src/llvm/llvm_gen_backend.cpp7
-rw-r--r--backend/src/llvm/llvm_gen_backend.hpp4
-rw-r--r--backend/src/llvm/llvm_scalarize.cpp1
-rw-r--r--backend/src/llvm/llvm_to_gen.cpp6
6 files changed, 134 insertions, 4 deletions
diff --git a/backend/src/CMakeLists.txt b/backend/src/CMakeLists.txt
index 5335893d..ddf295df 100644
--- a/backend/src/CMakeLists.txt
+++ b/backend/src/CMakeLists.txt
@@ -87,6 +87,7 @@ set (GBE_SRC
llvm/ExpandUtils.cpp
llvm/PromoteIntegers.cpp
llvm/ExpandLargeIntegers.cpp
+ llvm/StripAttributes.cpp
llvm/llvm_to_gen.cpp
llvm/llvm_loadstore_optimization.cpp
llvm/llvm_gen_backend.hpp
diff --git a/backend/src/llvm/StripAttributes.cpp b/backend/src/llvm/StripAttributes.cpp
new file mode 100644
index 00000000..05cac174
--- /dev/null
+++ b/backend/src/llvm/StripAttributes.cpp
@@ -0,0 +1,119 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+// Imported from pNaCl project
+// Copyright (c) 2003-2014 University of Illinois at Urbana-Champaign.
+// All rights reserved.
+//
+// Developed by:
+//
+// LLVM Team
+//
+// University of Illinois at Urbana-Champaign
+//
+// http://llvm.org
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy of
+// this software and associated documentation files (the "Software"), to deal with
+// the Software without restriction, including without limitation the rights to
+// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+// of the Software, and to permit persons to whom the Software is furnished to do
+// so, subject to the following conditions:
+//
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimers.
+//
+// * Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimers in the
+// documentation and/or other materials provided with the distribution.
+//
+// * Neither the names of the LLVM Team, University of Illinois at
+// Urbana-Champaign, nor the names of its contributors may be used to
+// endorse or promote products derived from this Software without specific
+// prior written permission.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
+// SOFTWARE.
+
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass strips out attributes that are not supported by Beignet.
+// Currently, this strips out:
+//
+// * Calling conventions from functions and function calls.
+//
+
+#include "llvm/IR/Function.h"
+#include "llvm/Pass.h"
+
+#if LLVM_VERSION_MINOR >= 5
+#include "llvm/IR/CallSite.h"
+#else
+#include "llvm/Support/CallSite.h"
+#endif
+
+#include "llvm_gen_backend.hpp"
+
+using namespace llvm;
+
+namespace {
+ class StripAttributes : public FunctionPass {
+ public:
+ static char ID; // Pass identification, replacement for typeid
+ StripAttributes() : FunctionPass(ID) {
+ }
+
+ virtual bool runOnFunction(Function &Func);
+ };
+}
+
+char StripAttributes::ID = 0;
+
+bool StripAttributes::runOnFunction(Function &Func) {
+ if (!gbe::isKernelFunction(Func))
+ Func.addFnAttr(Attribute::AlwaysInline);
+ Func.setCallingConv(CallingConv::C);
+ Func.setLinkage(GlobalValue::ExternalLinkage);
+
+ for (Function::iterator BB = Func.begin(), E = Func.end();
+ BB != E; ++BB) {
+ for (BasicBlock::iterator Inst = BB->begin(), E = BB->end();
+ Inst != E; ++Inst) {
+ CallSite Call(Inst);
+ if (Call)
+ Call.setCallingConv(CallingConv::C);
+ }
+ }
+
+ return true;
+}
+
+FunctionPass *llvm::createStripAttributesPass() {
+ return new StripAttributes();
+}
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
index bf03a130..30f5cb33 100644
--- a/backend/src/llvm/llvm_gen_backend.cpp
+++ b/backend/src/llvm/llvm_gen_backend.cpp
@@ -2796,8 +2796,13 @@ namespace gbe
break;
case GEN_OCL_PRINTF:
break;
+ case GEN_OCL_NOT_FOUND:
default:
- GBE_ASSERTM(false, "Function call are not supported yet");
+ std::cerr << "Caller instruction: " << std::endl;
+ I.dump();
+ std::cerr << "Callee function: " << std::endl;
+ Callee->dump();
+ GBE_ASSERT(0);
};
}
diff --git a/backend/src/llvm/llvm_gen_backend.hpp b/backend/src/llvm/llvm_gen_backend.hpp
index b21e8047..1f165574 100644
--- a/backend/src/llvm/llvm_gen_backend.hpp
+++ b/backend/src/llvm/llvm_gen_backend.hpp
@@ -50,6 +50,7 @@ namespace llvm {
FunctionPass *createExpandConstantExprPass();
FunctionPass *createExpandLargeIntegersPass();
FunctionPass *createPromoteIntegersPass();
+ FunctionPass *createStripAttributesPass();
// Copy debug information from Original to New, and return New.
template <typename T> T *CopyDebug(T *New, llvm::Instruction *Original) {
New->setDebugLoc(Original->getDebugLoc());
@@ -66,6 +67,7 @@ namespace gbe
enum OCLInstrinsic {
#define DECL_LLVM_GEN_FUNCTION(ID, NAME) GEN_OCL_##ID,
#include "llvm_gen_ocl_function.hxx"
+ GEN_OCL_NOT_FOUND,
#undef DECL_LLVM_GEN_FUNCTION
};
@@ -97,7 +99,7 @@ namespace gbe
if (it == map.end()) {
std::cerr << "Unresolved symbol: " << symbol << std::endl;
std::cerr << "Aborting..." << std::endl;
- exit(-1);
+ return GEN_OCL_NOT_FOUND;
}
return it->second;
}
diff --git a/backend/src/llvm/llvm_scalarize.cpp b/backend/src/llvm/llvm_scalarize.cpp
index 15309de7..e1afa04b 100644
--- a/backend/src/llvm/llvm_scalarize.cpp
+++ b/backend/src/llvm/llvm_scalarize.cpp
@@ -667,6 +667,7 @@ namespace gbe {
CallSite::arg_iterator CI = CS.arg_begin() + 1;
switch (genIntrinsicID) {
+ case GEN_OCL_NOT_FOUND:
default: break;
case GEN_OCL_READ_IMAGE_I:
case GEN_OCL_READ_IMAGE_UI:
diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp
index b1dc6862..4ea722af 100644
--- a/backend/src/llvm/llvm_to_gen.cpp
+++ b/backend/src/llvm/llvm_to_gen.cpp
@@ -134,8 +134,9 @@ namespace gbe
MPM.add(createInstructionCombiningPass());// Clean up after IPCP & DAE
MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE
MPM.add(createPruneEHPass()); // Remove dead EH info
+ MPM.add(createStripAttributesPass()); // Strip unsupported attributes and calling conventions.
MPM.add(createBarrierNodupPass(false)); // remove noduplicate fnAttr before inlining.
- MPM.add(createFunctionInliningPass(200000));
+ MPM.add(createFunctionInliningPass(20000));
MPM.add(createBarrierNodupPass(true)); // restore noduplicate fnAttr after inlining.
MPM.add(createFunctionAttrsPass()); // Set readonly/readnone attrs
@@ -276,7 +277,8 @@ namespace gbe
#endif
// Print the code before further optimizations
passes.add(createIntrinsicLoweringPass());
- passes.add(createFunctionInliningPass(200000));
+ passes.add(createStripAttributesPass()); // Strip unsupported attributes and calling conventions.
+ passes.add(createFunctionInliningPass(20000));
passes.add(createScalarReplAggregatesPass(64, true, -1, -1, 64));
passes.add(createLoadStoreOptimizationPass());
passes.add(createConstantPropagationPass());