llvm.org GIT mirror llvm / ae541aa
Add more const qualifiers for LLVM IR pointers in CodeGen. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101342 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
9 changed file(s) with 30 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
6969 };
7070
7171 class MachineFunction {
72 Function *Fn;
72 const Function *Fn;
7373 const TargetMachine &Target;
7474 MCContext &Ctx;
7575 MachineModuleInfo &MMI;
123123 MachineFunction(const MachineFunction &); // DO NOT IMPLEMENT
124124 void operator=(const MachineFunction&); // DO NOT IMPLEMENT
125125 public:
126 MachineFunction(Function *Fn, const TargetMachine &TM, unsigned FunctionNum,
127 MachineModuleInfo &MMI);
126 MachineFunction(const Function *Fn, const TargetMachine &TM,
127 unsigned FunctionNum, MachineModuleInfo &MMI);
128128 ~MachineFunction();
129129
130130 MachineModuleInfo &getMMI() const { return MMI; }
132132
133133 /// getFunction - Return the LLVM function that this machine code represents
134134 ///
135 Function *getFunction() const { return Fn; }
135 const Function *getFunction() const { return Fn; }
136136
137137 /// getFunctionNumber - Return a unique ID for the current function.
138138 ///
207207 }
208208
209209 // getTextSection - Get the text section for the specified function
210 ELFSection &ELFWriter::getTextSection(Function *F) {
210 ELFSection &ELFWriter::getTextSection(const Function *F) {
211211 const MCSectionELF *Text =
212212 (const MCSectionELF *)TLOF.SectionForGlobal(F, Mang, TM);
213213 return getSection(Text->getSectionName(), Text->getType(), Text->getFlags());
190190 ELFSection &getDtorSection();
191191 ELFSection &getJumpTableSection();
192192 ELFSection &getConstantPoolSection(MachineConstantPoolEntry &CPE);
193 ELFSection &getTextSection(Function *F);
193 ELFSection &getTextSection(const Function *F);
194194 ELFSection &getRelocSection(ELFSection &S);
195195
196196 // Helpers for obtaining ELF specific info.
5050 MBB->getParent()->DeleteMachineBasicBlock(MBB);
5151 }
5252
53 MachineFunction::MachineFunction(Function *F, const TargetMachine &TM,
53 MachineFunction::MachineFunction(const Function *F, const TargetMachine &TM,
5454 unsigned FunctionNum, MachineModuleInfo &mmi)
5555 : Fn(F), Target(TM), Ctx(mmi.getContext()), MMI(mmi) {
5656 if (TM.getRegisterInfo())
122122 /// isUsedOutsideOfDefiningBlock - Return true if this instruction is used by
123123 /// PHI nodes or outside of the basic block that defines it, or used by a
124124 /// switch or atomic instruction, which may expand to multiple basic blocks.
125 static bool isUsedOutsideOfDefiningBlock(Instruction *I) {
125 static bool isUsedOutsideOfDefiningBlock(const Instruction *I) {
126126 if (isa(I)) return true;
127 BasicBlock *BB = I->getParent();
128 for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); UI != E; ++UI)
127 const BasicBlock *BB = I->getParent();
128 for (Value::const_use_iterator UI = I->use_begin(), E = I->use_end();
129 UI != E; ++UI)
129130 if (cast(*UI)->getParent() != BB || isa(*UI))
130131 return true;
131132 return false;
134135 /// isOnlyUsedInEntryBlock - If the specified argument is only used in the
135136 /// entry block, return true. This includes arguments used by switches, since
136137 /// the switch may expand into multiple basic blocks.
137 static bool isOnlyUsedInEntryBlock(Argument *A, bool EnableFastISel) {
138 static bool isOnlyUsedInEntryBlock(const Argument *A, bool EnableFastISel) {
138139 // With FastISel active, we may be splitting blocks, so force creation
139140 // of virtual registers for all non-dead arguments.
140141 // Don't force virtual registers for byval arguments though, because
142143 if (EnableFastISel && !A->hasByValAttr())
143144 return A->use_empty();
144145
145 BasicBlock *Entry = A->getParent()->begin();
146 for (Value::use_iterator UI = A->use_begin(), E = A->use_end(); UI != E; ++UI)
146 const BasicBlock *Entry = A->getParent()->begin();
147 for (Value::const_use_iterator UI = A->use_begin(), E = A->use_end();
148 UI != E; ++UI)
147149 if (cast(*UI)->getParent() != Entry || isa(*UI))
148150 return false; // Use not in entry block.
149151 return true;
153155 : TLI(tli) {
154156 }
155157
156 void FunctionLoweringInfo::set(Function &fn, MachineFunction &mf,
158 void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
157159 bool EnableFastISel) {
158160 Fn = &fn;
159161 MF = &mf;
161163
162164 // Create a vreg for each argument register that is not dead and is used
163165 // outside of the entry block for the function.
164 for (Function::arg_iterator AI = Fn->arg_begin(), E = Fn->arg_end();
166 for (Function::const_arg_iterator AI = Fn->arg_begin(), E = Fn->arg_end();
165167 AI != E; ++AI)
166168 if (!isOnlyUsedInEntryBlock(AI, EnableFastISel))
167169 InitializeRegForValue(AI);
169171 // Initialize the mapping of values to registers. This is only set up for
170172 // instruction values that are used outside of the block that defines
171173 // them.
172 Function::iterator BB = Fn->begin(), EB = Fn->end();
173 for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
174 if (AllocaInst *AI = dyn_cast(I))
175 if (ConstantInt *CUI = dyn_cast(AI->getArraySize())) {
174 Function::const_iterator BB = Fn->begin(), EB = Fn->end();
175 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I)
176 if (const AllocaInst *AI = dyn_cast(I))
177 if (const ConstantInt *CUI = dyn_cast(AI->getArraySize())) {
176178 const Type *Ty = AI->getAllocatedType();
177179 uint64_t TySize = TLI.getTargetData()->getTypeAllocSize(Ty);
178180 unsigned Align =
186188 }
187189
188190 for (; BB != EB; ++BB)
189 for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
191 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I)
190192 if (!I->use_empty() && isUsedOutsideOfDefiningBlock(I))
191193 if (!isa(I) ||
192194 !StaticAllocaMap.count(cast(I)))
208210
209211 // Create Machine PHI nodes for LLVM PHI nodes, lowering them as
210212 // appropriate.
211 PHINode *PN;
213 const PHINode *PN;
212214 DebugLoc DL;
213 for (BasicBlock::iterator
215 for (BasicBlock::const_iterator
214216 I = BB->begin(), E = BB->end(); I != E; ++I) {
215217
216218 PN = dyn_cast(I);
234236
235237 // Mark landing pad blocks.
236238 for (BB = Fn->begin(); BB != EB; ++BB)
237 if (InvokeInst *Invoke = dyn_cast(BB->getTerminator()))
239 if (const InvokeInst *Invoke = dyn_cast(BB->getTerminator()))
238240 MBBMap[Invoke->getSuccessor(1)]->setIsLandingPad();
239241 }
240242
4747 class FunctionLoweringInfo {
4848 public:
4949 TargetLowering &TLI;
50 Function *Fn;
50 const Function *Fn;
5151 MachineFunction *MF;
5252 MachineRegisterInfo *RegInfo;
5353
9292 /// set - Initialize this FunctionLoweringInfo with the given Function
9393 /// and its associated MachineFunction.
9494 ///
95 void set(Function &Fn, MachineFunction &MF, bool EnableFastISel);
95 void set(const Function &Fn, MachineFunction &MF, bool EnableFastISel);
9696
9797 /// clear - Clear out all the function-specific state. This returns this
9898 /// FunctionLoweringInfo to an empty state, ready to be used for a
36093609 if (Val == 0)
36103610 return DAG.getConstantFP(1.0, LHS.getValueType());
36113611
3612 Function *F = DAG.getMachineFunction().getFunction();
3612 const Function *F = DAG.getMachineFunction().getFunction();
36133613 if (!F->hasFnAttr(Attribute::OptimizeForSize) ||
36143614 // If optimizing for size, don't insert too many multiplies. This
36153615 // inserts up to 5 multiplies.
194194 assert((!EnableFastISelAbort || EnableFastISel) &&
195195 "-fast-isel-abort requires -fast-isel");
196196
197 Function &Fn = *mf.getFunction();
197 const Function &Fn = *mf.getFunction();
198198 const TargetInstrInfo &TII = *TM.getInstrInfo();
199199 const TargetRegisterInfo &TRI = *TM.getRegisterInfo();
200200
13571357 return false;
13581358
13591359 unsigned Align = (*Op0->memoperands_begin())->getAlignment();
1360 Function *Func = MF->getFunction();
1360 const Function *Func = MF->getFunction();
13611361 unsigned ReqAlign = STI->hasV6Ops()
13621362 ? TD->getPrefTypeAlignment(Type::getInt64Ty(Func->getContext()))
13631363 : 8; // Pre-v6 need 8-byte align