1 /* 2 * Copyright 2012, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "bcc/Renderscript/RSScript.h" 18 19 #include "bcc/Assert.h" 20 #include "bcc/Source.h" 21 #include "bcc/Support/Log.h" 22 #include "bcc/Support/CompilerConfig.h" 23 24 using namespace bcc; 25 26 bool RSScript::LinkRuntime(RSScript &pScript, const char *core_lib) { 27 bccAssert(core_lib != nullptr); 28 29 // Using the same context with the source in pScript. 30 BCCContext &context = pScript.getSource().getContext(); 31 32 Source *libclcore_source = Source::CreateFromFile(context, core_lib); 33 if (libclcore_source == nullptr) { 34 ALOGE("Failed to load Renderscript library '%s' to link!", core_lib); 35 return false; 36 } 37 38 if (pScript.mLinkRuntimeCallback != nullptr) { 39 pScript.mLinkRuntimeCallback(&pScript, 40 &pScript.getSource().getModule(), &libclcore_source->getModule()); 41 } 42 43 if (!pScript.getSource().merge(*libclcore_source)) { 44 ALOGE("Failed to link Renderscript library '%s'!", core_lib); 45 delete libclcore_source; 46 return false; 47 } 48 49 return true; 50 } 51 52 RSScript::RSScript(Source &pSource) 53 : Script(pSource), mCompilerVersion(0), 54 mOptimizationLevel(kOptLvl3), mLinkRuntimeCallback(nullptr), 55 mEmbedInfo(false), mEmbedGlobalInfo(false), 56 mEmbedGlobalInfoSkipConstant(false) { } 57 58 RSScript::RSScript(Source &pSource, const CompilerConfig * pCompilerConfig): RSScript(pSource) 59 { 60 switch (pCompilerConfig->getOptimizationLevel()) { 61 case llvm::CodeGenOpt::None: mOptimizationLevel = kOptLvl0; break; 62 case llvm::CodeGenOpt::Less: mOptimizationLevel = kOptLvl1; break; 63 case llvm::CodeGenOpt::Default: mOptimizationLevel = kOptLvl2; break; 64 case llvm::CodeGenOpt::Aggressive: //Intentional fallthrough 65 default: { 66 mOptimizationLevel = kOptLvl3; 67 break; 68 } 69 } 70 } 71 72 bool RSScript::doReset() { 73 mCompilerVersion = 0; 74 mOptimizationLevel = kOptLvl3; 75 return true; 76 } 77