llvm.org GIT mirror llvm / 523b30c
* Fix order of #includes to follow style guide * It's no longer a BasicBlock pass: update comment on run() method * Fix placement of braces to be consistent * Delete extraneous whitespace git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9361 91177308-0d34-0410-b5e6-96231b3b80d8 Misha Brukman 17 years ago
1 changed file(s) with 27 addition(s) and 39 deletion(s). Raw diff Collapse all Expand all
1515 //===----------------------------------------------------------------------===//
1616
1717 #include "SparcInternals.h"
18 #include "llvm/Target/TargetMachine.h"
19 #include "llvm/Target/TargetInstrInfo.h"
20 #include "llvm/Transforms/Scalar.h"
21 #include "llvm/Support/InstVisitor.h"
22 #include "llvm/Module.h"
2318 #include "llvm/Constants.h"
2419 #include "llvm/iMemory.h"
2520 #include "llvm/iPHINode.h"
2621 #include "llvm/iOther.h"
2722 #include "llvm/DerivedTypes.h"
23 #include "llvm/Module.h"
2824 #include "llvm/Pass.h"
25 #include "llvm/Support/InstVisitor.h"
26 #include "llvm/Target/TargetInstrInfo.h"
27 #include "llvm/Target/TargetMachine.h"
28 #include "llvm/Transforms/Scalar.h"
2929 #include
3030
3131 namespace {
5252 PreSelection(const TargetMachine &T)
5353 : instrInfo(T.getInstrInfo()), TheModule(0) {}
5454
55 // runOnBasicBlock - apply this pass to each BB
55 // run - apply this pass to the entire Module
5656 bool run(Module &M) {
5757 TheModule = &M;
5858
9999
100100
101101 // getGlobalAddr(): Put address of a global into a v. register.
102 static GetElementPtrInst* getGlobalAddr(Value* ptr, Instruction& insertBefore)
103 {
102 static GetElementPtrInst* getGlobalAddr(Value* ptr, Instruction& insertBefore) {
104103 if (isa(ptr))
105104 ptr = cast(ptr)->getValue();
106105
113112
114113
115114 // Wrapper on Constant::classof to use in find_if :-(
116 inline static bool nonConstant(const Use& U)
117 {
115 inline static bool nonConstant(const Use& U) {
118116 return ! isa(U);
119117 }
120118
179177 if (CV == NULL)
180178 return;
181179
182 if (ConstantExpr* CE = dyn_cast(CV))
183 { // load-time constant: factor it out so we optimize as best we can
184 Instruction* computeConst = DecomposeConstantExpr(CE, insertBefore);
185 I.setOperand(opNum, computeConst); // replace expr operand with result
186 }
187 else if (instrInfo.ConstantTypeMustBeLoaded(CV))
188 { // load address of constant into a register, then load the constant
189 GetElementPtrInst* gep = getGlobalAddr(getGlobalForConstant(CV),
190 insertBefore);
191 LoadInst* ldI = new LoadInst(gep, "loadConst", &insertBefore);
192 I.setOperand(opNum, ldI); // replace operand with copy in v.reg.
193 }
194 else if (instrInfo.ConstantMayNotFitInImmedField(CV, &I))
195 { // put the constant into a virtual register using a cast
196 CastInst* castI = new CastInst(CV, CV->getType(), "copyConst",
197 &insertBefore);
198 I.setOperand(opNum, castI); // replace operand with copy in v.reg.
199 }
180 if (ConstantExpr* CE = dyn_cast(CV)) {
181 // load-time constant: factor it out so we optimize as best we can
182 Instruction* computeConst = DecomposeConstantExpr(CE, insertBefore);
183 I.setOperand(opNum, computeConst); // replace expr operand with result
184 } else if (instrInfo.ConstantTypeMustBeLoaded(CV)) {
185 // load address of constant into a register, then load the constant
186 GetElementPtrInst* gep = getGlobalAddr(getGlobalForConstant(CV),
187 insertBefore);
188 LoadInst* ldI = new LoadInst(gep, "loadConst", &insertBefore);
189 I.setOperand(opNum, ldI); // replace operand with copy in v.reg.
190 } else if (instrInfo.ConstantMayNotFitInImmedField(CV, &I)) {
191 // put the constant into a virtual register using a cast
192 CastInst* castI = new CastInst(CV, CV->getType(), "copyConst",
193 &insertBefore);
194 I.setOperand(opNum, castI); // replace operand with copy in v.reg.
195 }
200196 }
201197
202198 // visitOperands() transforms individual operands of all instructions:
231227
232228 // Common work for *all* instructions. This needs to be called explicitly
233229 // by other visit functions.
234 inline void
235 PreSelection::visitInstruction(Instruction &I)
236 {
230 inline void PreSelection::visitInstruction(Instruction &I) {
237231 visitOperands(I); // Perform operand transformations
238232 }
239233
240234
241235 // GetElementPtr instructions: check if pointer is a global
242 void
243 PreSelection::visitGetElementPtrInst(GetElementPtrInst &I)
244 {
236 void PreSelection::visitGetElementPtrInst(GetElementPtrInst &I) {
245237 Instruction* curI = &I;
246238
247239 // Decompose multidimensional array references
260252 visitInstruction(*curI);
261253 }
262254
263
264 void
265 PreSelection::visitCallInst(CallInst &I)
266 {
255 void PreSelection::visitCallInst(CallInst &I) {
267256 // Tell visitOperands to ignore the function name if this is a direct call.
268257 visitOperands(I, (/*firstOp=*/ I.getCalledFunction()? 1 : 0));
269258 }
276265 Pass* createPreSelectionPass(TargetMachine &T) {
277266 return new PreSelection(T);
278267 }
279