"Fossies" - the Fresh Open Source Software Archive

Member "pocl-1.8/lib/llvmopencl/AllocasToEntry.cc" (12 Oct 2021, 2397 Bytes) of package /linux/misc/pocl-1.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AllocasToEntry.cc" see the Fossies "Dox" file reference documentation.

    1 // AllocasToEntry, an LLVM pass to move allocas to the function entry node.
    2 // 
    3 // Copyright (c) 2013 Pekka Jääskeläinen / TUT
    4 // 
    5 // Permission is hereby granted, free of charge, to any person obtaining a copy
    6 // of this software and associated documentation files (the "Software"), to deal
    7 // in the Software without restriction, including without limitation the rights
    8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    9 // copies of the Software, and to permit persons to whom the Software is
   10 // furnished to do so, subject to the following conditions:
   11 // 
   12 // The above copyright notice and this permission notice shall be included in
   13 // all copies or substantial portions of the Software.
   14 // 
   15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   21 // THE SOFTWARE.
   22 
   23 #include <sstream>
   24 #include <iostream>
   25 
   26 #include "config.h"
   27 
   28 #include "CompilerWarnings.h"
   29 IGNORE_COMPILER_WARNING("-Wunused-parameter")
   30 
   31 #include <llvm/IR/Constants.h>
   32 #include <llvm/IR/Instructions.h>
   33 
   34 #include "AllocasToEntry.h"
   35 
   36 namespace pocl {
   37 
   38 using namespace llvm;
   39 
   40 namespace {
   41   static
   42   RegisterPass<pocl::AllocasToEntry> X("allocastoentry", 
   43                                        "Move allocas to the function entry node.");
   44 }
   45 
   46 char AllocasToEntry::ID = 0;
   47 
   48 
   49 AllocasToEntry::AllocasToEntry() : FunctionPass(ID)
   50 {
   51 }
   52 
   53 bool
   54 AllocasToEntry::runOnFunction(Function &F)
   55 {
   56   // This solves problem with dynamic stack objects that are 
   57   // not supported by some targets (TCE).
   58   Function::iterator I = F.begin();
   59   Instruction *firstInsertionPt = &*(I++)->getFirstInsertionPt();
   60     
   61   bool changed = false;
   62   for (Function::iterator E = F.end(); I != E; ++I) {
   63     for (BasicBlock::iterator BI = I->begin(), BE = I->end(); BI != BE;) {
   64       AllocaInst *allocaInst = dyn_cast<AllocaInst>(BI++);
   65       if (allocaInst && isa<ConstantInt>(allocaInst->getArraySize())) {
   66         allocaInst->moveBefore(firstInsertionPt);
   67         changed = true;
   68       }
   69     }
   70   }
   71   return changed;
   72 }
   73 
   74 }