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

Side by Side Diff: lib/Target/NVPTX/NVVMReflect.cpp

Issue 183273009: Prep for merging 3.4: Undo changes from 3.3 branch (Closed) Base URL: http://git.chromium.org/native_client/pnacl-llvm.git@master
Patch Set: Retry Created 6 years, 9 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 unified diff | Download patch
OLDNEW
1 //===- NVVMReflect.cpp - NVVM Emulate conditional compilation -------------===// 1 //===- NVVMReflect.cpp - NVVM Emulate conditional compilation -------------===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This pass replaces occurences of __nvvm_reflect("string") with an 10 // This pass replaces occurences of __nvvm_reflect("string") with an
11 // integer based on -nvvm-reflect-list string=<int> option given to this pass. 11 // integer based on -nvvm-reflect-list string=<int> option given to this pass.
12 // If an undefined string value is seen in a call to __nvvm_reflect("string"), 12 // If an undefined string value is seen in a call to __nvvm_reflect("string"),
13 // a default value of 0 will be used. 13 // a default value of 0 will be used.
14 // 14 //
15 //===----------------------------------------------------------------------===// 15 //===----------------------------------------------------------------------===//
16 16
17 #include "NVPTX.h"
18 #include "llvm/ADT/DenseMap.h" 17 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/SmallVector.h" 18 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/StringMap.h" 19 #include "llvm/ADT/StringMap.h"
21 #include "llvm/Pass.h" 20 #include "llvm/Pass.h"
22 #include "llvm/IR/Function.h" 21 #include "llvm/IR/Function.h"
23 #include "llvm/IR/Module.h" 22 #include "llvm/IR/Module.h"
24 #include "llvm/IR/Type.h" 23 #include "llvm/IR/Type.h"
25 #include "llvm/IR/DerivedTypes.h" 24 #include "llvm/IR/DerivedTypes.h"
26 #include "llvm/IR/Instructions.h" 25 #include "llvm/IR/Instructions.h"
27 #include "llvm/IR/Constants.h" 26 #include "llvm/IR/Constants.h"
28 #include "llvm/Support/CommandLine.h" 27 #include "llvm/Support/CommandLine.h"
29 #include "llvm/Support/Debug.h" 28 #include "llvm/Support/Debug.h"
30 #include "llvm/Support/raw_os_ostream.h" 29 #include "llvm/Support/raw_os_ostream.h"
31 #include "llvm/Transforms/Scalar.h" 30 #include "llvm/Transforms/Scalar.h"
32 #include <map> 31 #include <map>
33 #include <sstream> 32 #include <sstream>
34 #include <string> 33 #include <string>
35 #include <vector> 34 #include <vector>
36 35
37 #define NVVM_REFLECT_FUNCTION "__nvvm_reflect" 36 #define NVVM_REFLECT_FUNCTION "__nvvm_reflect"
38 37
39 using namespace llvm; 38 using namespace llvm;
40 39
41 namespace llvm { void initializeNVVMReflectPass(PassRegistry &); } 40 namespace llvm { void initializeNVVMReflectPass(PassRegistry &); }
42 41
43 namespace { 42 namespace {
44 class NVVMReflect : public ModulePass { 43 class LLVM_LIBRARY_VISIBILITY NVVMReflect : public ModulePass {
45 private: 44 private:
46 StringMap<int> VarMap; 45 StringMap<int> VarMap;
47 typedef DenseMap<std::string, int>::iterator VarMapIter; 46 typedef DenseMap<std::string, int>::iterator VarMapIter;
48 Function *ReflectFunction; 47 Function *ReflectFunction;
49 48
50 public: 49 public:
51 static char ID; 50 static char ID;
52 NVVMReflect() : ModulePass(ID), ReflectFunction(0) { 51 NVVMReflect() : ModulePass(ID) {
53 initializeNVVMReflectPass(*PassRegistry::getPassRegistry());
54 VarMap.clear(); 52 VarMap.clear();
55 } 53 ReflectFunction = 0;
56
57 NVVMReflect(const StringMap<int> &Mapping)
58 : ModulePass(ID), ReflectFunction(0) {
59 initializeNVVMReflectPass(*PassRegistry::getPassRegistry());
60 for (StringMap<int>::const_iterator I = Mapping.begin(), E = Mapping.end();
61 I != E; ++I) {
62 VarMap[(*I).getKey()] = (*I).getValue();
63 }
64 } 54 }
65 55
66 void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); } 56 void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); }
67 virtual bool runOnModule(Module &); 57 virtual bool runOnModule(Module &);
68 58
69 void setVarMap(); 59 void setVarMap();
70 }; 60 };
71 } 61 }
72 62
73 ModulePass *llvm::createNVVMReflectPass() {
74 return new NVVMReflect();
75 }
76
77 ModulePass *llvm::createNVVMReflectPass(const StringMap<int>& Mapping) {
78 return new NVVMReflect(Mapping);
79 }
80
81 static cl::opt<bool> 63 static cl::opt<bool>
82 NVVMReflectEnabled("nvvm-reflect-enable", cl::init(true), 64 NVVMReflectEnabled("nvvm-reflect-enable", cl::init(true),
83 cl::desc("NVVM reflection, enabled by default")); 65 cl::desc("NVVM reflection, enabled by default"));
84 66
85 char NVVMReflect::ID = 0; 67 char NVVMReflect::ID = 0;
86 INITIALIZE_PASS(NVVMReflect, "nvvm-reflect", 68 INITIALIZE_PASS(NVVMReflect, "nvvm-reflect",
87 "Replace occurences of __nvvm_reflect() calls with 0/1", false, 69 "Replace occurences of __nvvm_reflect() calls with 0/1", false,
88 false) 70 false)
89 71
90 static cl::list<std::string> 72 static cl::list<std::string>
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 ConstantInt::get(Reflect->getType(), ReflectVal)); 168 ConstantInt::get(Reflect->getType(), ReflectVal));
187 ToRemove.push_back(Reflect); 169 ToRemove.push_back(Reflect);
188 } 170 }
189 if (ToRemove.size() == 0) 171 if (ToRemove.size() == 0)
190 return false; 172 return false;
191 173
192 for (unsigned i = 0, e = ToRemove.size(); i != e; ++i) 174 for (unsigned i = 0, e = ToRemove.size(); i != e; ++i)
193 ToRemove[i]->eraseFromParent(); 175 ToRemove[i]->eraseFromParent();
194 return true; 176 return true;
195 } 177 }
OLDNEW
« no previous file with comments | « lib/Target/NVPTX/NVPTXTargetMachine.cpp ('k') | lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698