llvm.org GIT mirror llvm / 46510a7
Add const qualifiers to CodeGen's use of LLVM IR constructs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101334 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
64 changed file(s) with 605 addition(s) and 585 deletion(s). Raw diff Collapse all Expand all
8686 /// LLVM IR instruction, and append generated machine instructions to
8787 /// the current block. Return true if selection was successful.
8888 ///
89 bool SelectInstruction(Instruction *I);
89 bool SelectInstruction(const Instruction *I);
9090
9191 /// SelectOperator - Do "fast" instruction selection for the given
9292 /// LLVM IR operator (Instruction or ConstantExpr), and append
9393 /// generated machine instructions to the current block. Return true
9494 /// if selection was successful.
9595 ///
96 bool SelectOperator(User *I, unsigned Opcode);
96 bool SelectOperator(const User *I, unsigned Opcode);
9797
9898 /// getRegForValue - Create a virtual register and arrange for it to
9999 /// be assigned the value for the given LLVM value.
100 unsigned getRegForValue(Value *V);
100 unsigned getRegForValue(const Value *V);
101101
102102 /// lookUpRegForValue - Look up the value to see if its value is already
103103 /// cached in a register. It may be defined by instructions across blocks or
104104 /// defined locally.
105 unsigned lookUpRegForValue(Value *V);
105 unsigned lookUpRegForValue(const Value *V);
106106
107107 /// getRegForGEPIndex - This is a wrapper around getRegForValue that also
108108 /// takes care of truncating or sign-extending the given getelementptr
109109 /// index value.
110 unsigned getRegForGEPIndex(Value *V);
110 unsigned getRegForGEPIndex(const Value *V);
111111
112112 virtual ~FastISel();
113113
127127 /// fit into FastISel's framework. It returns true if it was successful.
128128 ///
129129 virtual bool
130 TargetSelectInstruction(Instruction *I) = 0;
130 TargetSelectInstruction(const Instruction *I) = 0;
131131
132132 /// FastEmit_r - This method is called by target-independent code
133133 /// to request that an instruction with the given type and opcode
169169 virtual unsigned FastEmit_rf(MVT VT,
170170 MVT RetVT,
171171 unsigned Opcode,
172 unsigned Op0, ConstantFP *FPImm);
172 unsigned Op0, const ConstantFP *FPImm);
173173
174174 /// FastEmit_rri - This method is called by target-independent code
175175 /// to request that an instruction with the given type, opcode, and
195195 /// FastEmit_rr instead.
196196 unsigned FastEmit_rf_(MVT VT,
197197 unsigned Opcode,
198 unsigned Op0, ConstantFP *FPImm,
198 unsigned Op0, const ConstantFP *FPImm,
199199 MVT ImmType);
200200
201201 /// FastEmit_i - This method is called by target-independent code
212212 virtual unsigned FastEmit_f(MVT VT,
213213 MVT RetVT,
214214 unsigned Opcode,
215 ConstantFP *FPImm);
215 const ConstantFP *FPImm);
216216
217217 /// FastEmitInst_ - Emit a MachineInstr with no operands and a
218218 /// result register in the given register class.
246246 ///
247247 unsigned FastEmitInst_rf(unsigned MachineInstOpcode,
248248 const TargetRegisterClass *RC,
249 unsigned Op0, ConstantFP *FPImm);
249 unsigned Op0, const ConstantFP *FPImm);
250250
251251 /// FastEmitInst_rri - Emit a MachineInstr with two register operands,
252252 /// an immediate, and a result register in the given register class.
276276 /// the CFG.
277277 void FastEmitBranch(MachineBasicBlock *MBB);
278278
279 unsigned UpdateValueMap(Value* I, unsigned Reg);
279 unsigned UpdateValueMap(const Value* I, unsigned Reg);
280280
281281 unsigned createResultReg(const TargetRegisterClass *RC);
282282
283283 /// TargetMaterializeConstant - Emit a constant in a register using
284284 /// target-specific logic, such as constant pool loads.
285 virtual unsigned TargetMaterializeConstant(Constant* C) {
285 virtual unsigned TargetMaterializeConstant(const Constant* C) {
286286 return 0;
287287 }
288288
289289 /// TargetMaterializeAlloca - Emit an alloca address in a register using
290290 /// target-specific logic.
291 virtual unsigned TargetMaterializeAlloca(AllocaInst* C) {
291 virtual unsigned TargetMaterializeAlloca(const AllocaInst* C) {
292292 return 0;
293293 }
294294
295295 private:
296 bool SelectBinaryOp(User *I, unsigned ISDOpcode);
297
298 bool SelectFNeg(User *I);
299
300 bool SelectGetElementPtr(User *I);
301
302 bool SelectCall(User *I);
303
304 bool SelectBitCast(User *I);
305
306 bool SelectCast(User *I, unsigned Opcode);
296 bool SelectBinaryOp(const User *I, unsigned ISDOpcode);
297
298 bool SelectFNeg(const User *I);
299
300 bool SelectGetElementPtr(const User *I);
301
302 bool SelectCall(const User *I);
303
304 bool SelectBitCast(const User *I);
305
306 bool SelectCast(const User *I, unsigned Opcode);
307307 };
308308
309309 }
6767 struct GCRoot {
6868 int Num; //< Usually a frame index.
6969 int StackOffset; //< Offset from the stack pointer.
70 Constant *Metadata; //< Metadata straight from the call to llvm.gcroot.
70 const Constant *Metadata;//< Metadata straight from the call to llvm.gcroot.
7171
72 GCRoot(int N, Constant *MD) : Num(N), StackOffset(-1), Metadata(MD) {}
72 GCRoot(int N, const Constant *MD) : Num(N), StackOffset(-1), Metadata(MD) {}
7373 };
7474
7575
113113 /// addStackRoot - Registers a root that lives on the stack. Num is the
114114 /// stack object ID for the alloca (if the code generator is
115115 // using MachineFrameInfo).
116 void addStackRoot(int Num, Constant *Metadata) {
116 void addStackRoot(int Num, const Constant *Metadata) {
117117 Roots.push_back(GCRoot(Num, Metadata));
118118 }
119119
7373 public:
7474 /// The constant itself.
7575 union {
76 Constant *ConstVal;
76 const Constant *ConstVal;
7777 MachineConstantPoolValue *MachineCPVal;
7878 } Val;
7979
8181 /// a MachineConstantPoolValue.
8282 unsigned Alignment;
8383
84 MachineConstantPoolEntry(Constant *V, unsigned A)
84 MachineConstantPoolEntry(const Constant *V, unsigned A)
8585 : Alignment(A) {
8686 Val.ConstVal = V;
8787 }
142142 /// getConstantPoolIndex - Create a new entry in the constant pool or return
143143 /// an existing one. User must specify the minimum required alignment for
144144 /// the object.
145 unsigned getConstantPoolIndex(Constant *C, unsigned Alignment);
145 unsigned getConstantPoolIndex(const Constant *C, unsigned Alignment);
146146 unsigned getConstantPoolIndex(MachineConstantPoolValue *V,unsigned Alignment);
147147
148148 /// isEmpty - Return true if this constant pool contains no constants.
103103 return *this;
104104 }
105105
106 const MachineInstrBuilder &addGlobalAddress(GlobalValue *GV,
106 const MachineInstrBuilder &addGlobalAddress(const GlobalValue *GV,
107107 int64_t Offset = 0,
108108 unsigned char TargetFlags = 0) const {
109109 MI->addOperand(MachineOperand::CreateGA(GV, Offset, TargetFlags));
8181 SmallVector BeginLabels; // Labels prior to invoke.
8282 SmallVector EndLabels; // Labels after invoke.
8383 MCSymbol *LandingPadLabel; // Label at beginning of landing pad.
84 Function *Personality; // Personality function.
84 const Function *Personality; // Personality function.
8585 std::vector TypeIds; // List of type ids (filters negative)
8686
8787 explicit LandingPadInfo(MachineBasicBlock *MBB)
100100 MCContext Context;
101101
102102 /// TheModule - This is the LLVM Module being worked on.
103 Module *TheModule;
103 const Module *TheModule;
104104
105105 /// ObjFileMMI - This is the object-file-format-specific implementation of
106106 /// MachineModuleInfoImpl, which lets targets accumulate whatever info they
124124
125125 // TypeInfos - List of C++ TypeInfo used in the current function.
126126 //
127 std::vector<GlobalVariable *> TypeInfos;
127 std::vector<const GlobalVariable *> TypeInfos;
128128
129129 // FilterIds - List of typeids encoding filters used in the current function.
130130 //
137137
138138 // Personalities - Vector of all personality functions ever seen. Used to emit
139139 // common EH frames.
140 std::vector<Function *> Personalities;
140 std::vector<const Function *> Personalities;
141141
142142 /// UsedFunctions - The functions in the @llvm.used list in a more easily
143143 /// searchable format. This does not include the functions in
178178 const MCContext &getContext() const { return Context; }
179179 MCContext &getContext() { return Context; }
180180
181 void setModule(Module *M) { TheModule = M; }
182 Module *getModule() const { return TheModule; }
181 void setModule(const Module *M) { TheModule = M; }
182 const Module *getModule() const { return TheModule; }
183183
184184 /// getInfo - Keep track of various per-function pieces of information for
185185 /// backends that would like to do so.
198198
199199 /// AnalyzeModule - Scan the module for global debug information.
200200 ///
201 void AnalyzeModule(Module &M);
201 void AnalyzeModule(const Module &M);
202202
203203 /// hasDebugInfo - Returns true if valid debug info is present.
204204 ///
251251
252252 /// addPersonality - Provide the personality function for the exception
253253 /// information.
254 void addPersonality(MachineBasicBlock *LandingPad, Function *Personality);
254 void addPersonality(MachineBasicBlock *LandingPad,
255 const Function *Personality);
255256
256257 /// getPersonalityIndex - Get index of the current personality function inside
257258 /// Personalitites array
258259 unsigned getPersonalityIndex() const;
259260
260261 /// getPersonalities - Return array of personality functions ever seen.
261 const std::vector<Function *>& getPersonalities() const {
262 const std::vector<const Function *>& getPersonalities() const {
262263 return Personalities;
263264 }
264265
272273 /// addCatchTypeInfo - Provide the catch typeinfo for a landing pad.
273274 ///
274275 void addCatchTypeInfo(MachineBasicBlock *LandingPad,
275 std::vector<GlobalVariable *> &TyInfo);
276 std::vector<const GlobalVariable *> &TyInfo);
276277
277278 /// addFilterTypeInfo - Provide the filter typeinfo for a landing pad.
278279 ///
279280 void addFilterTypeInfo(MachineBasicBlock *LandingPad,
280 std::vector<GlobalVariable *> &TyInfo);
281 std::vector<const GlobalVariable *> &TyInfo);
281282
282283 /// addCleanup - Add a cleanup action for a landing pad.
283284 ///
285286
286287 /// getTypeIDFor - Return the type id for the specified typeinfo. This is
287288 /// function wide.
288 unsigned getTypeIDFor(GlobalVariable *TI);
289 unsigned getTypeIDFor(const GlobalVariable *TI);
289290
290291 /// getFilterIDFor - Return the id of the filter encoded by TyIds. This is
291292 /// function wide.
322323
323324 /// getTypeInfos - Return a reference to the C++ typeinfo for the current
324325 /// function.
325 const std::vector<GlobalVariable *> &getTypeInfos() const {
326 const std::vector<const GlobalVariable *> &getTypeInfos() const {
326327 return TypeInfos;
327328 }
328329
334335
335336 /// getPersonality - Return a personality function if available. The presence
336337 /// of one is required to emit exception handling info.
337 Function *getPersonality() const;
338 const Function *getPersonality() const;
338339
339340 /// setVariableDbgInfo - Collect information used to emit debugging
340341 /// information of a variable.
116116 union {
117117 int Index; // For MO_*Index - The index itself.
118118 const char *SymbolName; // For MO_ExternalSymbol.
119 GlobalValue *GV; // For MO_GlobalAddress.
120 BlockAddress *BA; // For MO_BlockAddress.
119 const GlobalValue *GV; // For MO_GlobalAddress.
120 const BlockAddress *BA; // For MO_BlockAddress.
121121 } Val;
122122 int64_t Offset; // An offset from the object.
123123 } OffsetedInfo;
314314 return Contents.OffsetedInfo.Val.Index;
315315 }
316316
317 GlobalValue *getGlobal() const {
317 const GlobalValue *getGlobal() const {
318318 assert(isGlobal() && "Wrong MachineOperand accessor");
319319 return Contents.OffsetedInfo.Val.GV;
320320 }
321321
322 BlockAddress *getBlockAddress() const {
322 const BlockAddress *getBlockAddress() const {
323323 assert(isBlockAddress() && "Wrong MachineOperand accessor");
324324 return Contents.OffsetedInfo.Val.BA;
325325 }
456456 Op.setTargetFlags(TargetFlags);
457457 return Op;
458458 }
459 static MachineOperand CreateGA(GlobalValue *GV, int64_t Offset,
459 static MachineOperand CreateGA(const GlobalValue *GV, int64_t Offset,
460460 unsigned char TargetFlags = 0) {
461461 MachineOperand Op(MachineOperand::MO_GlobalAddress);
462462 Op.Contents.OffsetedInfo.Val.GV = GV;
472472 Op.setTargetFlags(TargetFlags);
473473 return Op;
474474 }
475 static MachineOperand CreateBA(BlockAddress *BA,
475 static MachineOperand CreateBA(const BlockAddress *BA,
476476 unsigned char TargetFlags = 0) {
477477 MachineOperand Op(MachineOperand::MO_BlockAddress);
478478 Op.Contents.OffsetedInfo.Val.BA = BA;
349349 SDValue getTargetJumpTable(int JTI, EVT VT, unsigned char TargetFlags = 0) {
350350 return getJumpTable(JTI, VT, true, TargetFlags);
351351 }
352 SDValue getConstantPool(Constant *C, EVT VT,
352 SDValue getConstantPool(const Constant *C, EVT VT,
353353 unsigned Align = 0, int Offs = 0, bool isT=false,
354354 unsigned char TargetFlags = 0);
355 SDValue getTargetConstantPool(Constant *C, EVT VT,
355 SDValue getTargetConstantPool(const Constant *C, EVT VT,
356356 unsigned Align = 0, int Offset = 0,
357357 unsigned char TargetFlags = 0) {
358358 return getConstantPool(C, VT, Align, Offset, true, TargetFlags);
376376 SDValue getValueType(EVT);
377377 SDValue getRegister(unsigned Reg, EVT VT);
378378 SDValue getEHLabel(DebugLoc dl, SDValue Root, MCSymbol *Label);
379 SDValue getBlockAddress(BlockAddress *BA, EVT VT,
379 SDValue getBlockAddress(const BlockAddress *BA, EVT VT,
380380 bool isTarget = false, unsigned char TargetFlags = 0);
381381
382382 SDValue getCopyToReg(SDValue Chain, DebugLoc dl, unsigned Reg, SDValue N) {
766766 ///
767767 SDDbgValue *getDbgValue(MDNode *MDPtr, SDNode *N, unsigned R, uint64_t Off,
768768 DebugLoc DL, unsigned O);
769 SDDbgValue *getDbgValue(MDNode *MDPtr, Value *C, uint64_t Off,
769 SDDbgValue *getDbgValue(MDNode *MDPtr, const Value *C, uint64_t Off,
770770 DebugLoc DL, unsigned O);
771771 SDDbgValue *getDbgValue(MDNode *MDPtr, unsigned FI, uint64_t Off,
772772 DebugLoc DL, unsigned O);
278278 const SDValue *Ops, unsigned NumOps, unsigned EmitNodeInfo);
279279
280280 void PrepareEHLandingPad(MachineBasicBlock *BB);
281 void SelectAllBasicBlocks(Function &Fn);
281 void SelectAllBasicBlocks(const Function &Fn);
282282 void FinishBasicBlock();
283283
284 void SelectBasicBlock(BasicBlock *LLVMBB,
285 BasicBlock::iterator Begin,
286 BasicBlock::iterator End,
284 void SelectBasicBlock(const BasicBlock *LLVMBB,
285 BasicBlock::const_iterator Begin,
286 BasicBlock::const_iterator End,
287287 bool &HadTailCall);
288288 void CodeGenAndEmitDAG();
289 void LowerArguments(BasicBlock *BB);
289 void LowerArguments(const BasicBlock *BB);
290290
291291 void ShrinkDemandedOps();
292292 void ComputeLiveOutVRegInfo();
293293
294 void HandlePHINodesInSuccessorBlocks(BasicBlock *LLVMBB);
295
296 bool HandlePHINodesInSuccessorBlocksFast(BasicBlock *LLVMBB, FastISel *F);
294 void HandlePHINodesInSuccessorBlocks(const BasicBlock *LLVMBB);
295
296 bool HandlePHINodesInSuccessorBlocksFast(const BasicBlock *LLVMBB,
297 FastISel *F);
297298
298299 /// Create the scheduler. If a specific scheduler was specified
299300 /// via the SchedulerRegistry, use it, otherwise select the
11391139 };
11401140
11411141 class GlobalAddressSDNode : public SDNode {
1142 GlobalValue *TheGlobal;
1142 const GlobalValue *TheGlobal;
11431143 int64_t Offset;
11441144 unsigned char TargetFlags;
11451145 friend class SelectionDAG;
11471147 int64_t o, unsigned char TargetFlags);
11481148 public:
11491149
1150 GlobalValue *getGlobal() const { return TheGlobal; }
1150 const GlobalValue *getGlobal() const { return TheGlobal; }
11511151 int64_t getOffset() const { return Offset; }
11521152 unsigned char getTargetFlags() const { return TargetFlags; }
11531153 // Return the address space this GlobalAddress belongs to.
12021202
12031203 class ConstantPoolSDNode : public SDNode {
12041204 union {
1205 Constant *ConstVal;
1205 const Constant *ConstVal;
12061206 MachineConstantPoolValue *MachineCPVal;
12071207 } Val;
12081208 int Offset; // It's a MachineConstantPoolValue if top bit is set.
12091209 unsigned Alignment; // Minimum alignment requirement of CP (not log2 value).
12101210 unsigned char TargetFlags;
12111211 friend class SelectionDAG;
1212 ConstantPoolSDNode(bool isTarget, Constant *c, EVT VT, int o, unsigned Align,
1213 unsigned char TF)
1212 ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1213 unsigned Align, unsigned char TF)
12141214 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
12151215 DebugLoc(),
12161216 getSDVTList(VT)), Offset(o), Alignment(Align), TargetFlags(TF) {
12331233 return (int)Offset < 0;
12341234 }
12351235
1236 Constant *getConstVal() const {
1236 const Constant *getConstVal() const {
12371237 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
12381238 return Val.ConstVal;
12391239 }
13591359 };
13601360
13611361 class BlockAddressSDNode : public SDNode {
1362 BlockAddress *BA;
1362 const BlockAddress *BA;
13631363 unsigned char TargetFlags;
13641364 friend class SelectionDAG;
1365 BlockAddressSDNode(unsigned NodeTy, EVT VT, BlockAddress *ba,
1365 BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
13661366 unsigned char Flags)
13671367 : SDNode(NodeTy, DebugLoc(), getSDVTList(VT)),
13681368 BA(ba), TargetFlags(Flags) {
13691369 }
13701370 public:
1371 BlockAddress *getBlockAddress() const { return BA; }
1371 const BlockAddress *getBlockAddress() const { return BA; }
13721372 unsigned char getTargetFlags() const { return TargetFlags; }
13731373
13741374 static bool classof(const BlockAddressSDNode *) { return true; }
316316 };
317317
318318 virtual bool getTgtMemIntrinsic(IntrinsicInfo &Info,
319 CallInst &I, unsigned Intrinsic) {
319 const CallInst &I, unsigned Intrinsic) {
320320 return false;
321321 }
322322
863863 /// isGAPlusOffset - Returns true (and the GlobalValue and the offset) if the
864864 /// node is a GlobalAddress + offset.
865865 virtual bool
866 isGAPlusOffset(SDNode *N, GlobalValue* &GA, int64_t &Offset) const;
866 isGAPlusOffset(SDNode *N, const GlobalValue* &GA, int64_t &Offset) const;
867867
868868 /// PerformDAGCombine - This method will be invoked for all target nodes and
869869 /// for any target-independent nodes that the target has registered with
424424
425425 if (!MO.isGlobal()) continue;
426426
427 Function *F = dyn_cast(MO.getGlobal());
427 const Function *F = dyn_cast(MO.getGlobal());
428428 if (F == 0) continue;
429429
430430 if (SawFunc) {
578578 /// 3. Type ID table contains references to all the C++ typeinfo for all
579579 /// catches in the function. This tables is reverse indexed base 1.
580580 void DwarfException::EmitExceptionTable() {
581 const std::vector<GlobalVariable *> &TypeInfos = MMI->getTypeInfos();
581 const std::vector<const GlobalVariable *> &TypeInfos = MMI->getTypeInfos();
582582 const std::vector &FilterIds = MMI->getFilterIds();
583583 const std::vector &PadInfos = MMI->getLandingPads();
584584
860860 Asm->OutStreamer.AddComment("-- Catch TypeInfos --");
861861 Asm->OutStreamer.AddBlankLine();
862862 }
863 for (std::vector<GlobalVariable *>::const_reverse_iterator
863 for (std::vector<const GlobalVariable *>::const_reverse_iterator
864864 I = TypeInfos.rbegin(), E = TypeInfos.rend(); I != E; ++I) {
865865 const GlobalVariable *GV = *I;
866866
895895 if (!shouldEmitMovesModule && !shouldEmitTableModule)
896896 return;
897897
898 const std::vector<Function *> Personalities = MMI->getPersonalities();
898 const std::vector<const Function *> Personalities = MMI->getPersonalities();
899899
900900 for (unsigned I = 0, E = Personalities.size(); I < E; ++I)
901901 EmitCIE(Personalities[I], I);
330330 IRBuilder<> Builder(CI->getParent(), CI);
331331 LLVMContext &Context = CI->getContext();
332332
333 Function *Callee = CI->getCalledFunction();
333 const Function *Callee = CI->getCalledFunction();
334334 assert(Callee && "Cannot lower an indirect call!");
335335
336336 switch (Callee->getIntrinsicID()) {
629629
630630 /// CanShareConstantPoolEntry - Test whether the given two constants
631631 /// can be allocated the same constant pool entry.
632 static bool CanShareConstantPoolEntry(Constant *A, Constant *B,
632 static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B,
633633 const TargetData *TD) {
634634 // Handle the trivial case quickly.
635635 if (A == B) return true;
644644
645645 // If a floating-point value and an integer value have the same encoding,
646646 // they can share a constant-pool entry.
647 if (ConstantFP *AFP = dyn_cast(A))
648 if (ConstantInt *BI = dyn_cast(B))
647 if (const ConstantFP *AFP = dyn_cast(A))
648 if (const ConstantInt *BI = dyn_cast(B))
649649 return AFP->getValueAPF().bitcastToAPInt() == BI->getValue();
650 if (ConstantFP *BFP = dyn_cast(B))
651 if (ConstantInt *AI = dyn_cast(A))
650 if (const ConstantFP *BFP = dyn_cast(B))
651 if (const ConstantInt *AI = dyn_cast(A))
652652 return BFP->getValueAPF().bitcastToAPInt() == AI->getValue();
653653
654654 // Two vectors can share an entry if each pair of corresponding
655655 // elements could.
656 if (ConstantVector *AV = dyn_cast(A))
657 if (ConstantVector *BV = dyn_cast(B)) {
656 if (const ConstantVector *AV = dyn_cast(A))
657 if (const ConstantVector *BV = dyn_cast(B)) {
658658 if (AV->getType()->getNumElements() != BV->getType()->getNumElements())
659659 return false;
660660 for (unsigned i = 0, e = AV->getType()->getNumElements(); i != e; ++i)
673673 /// an existing one. User must specify the log2 of the minimum required
674674 /// alignment for the object.
675675 ///
676 unsigned MachineConstantPool::getConstantPoolIndex(Constant *C,
676 unsigned MachineConstantPool::getConstantPoolIndex(const Constant *C,
677677 unsigned Alignment) {
678678 assert(Alignment && "Alignment must be specified!");
679679 if (Alignment > PoolAlignment) PoolAlignment = Alignment;
314314
315315 /// AnalyzeModule - Scan the module for global debug information.
316316 ///
317 void MachineModuleInfo::AnalyzeModule(Module &M) {
317 void MachineModuleInfo::AnalyzeModule(const Module &M) {
318318 // Insert functions in the llvm.used array (but not llvm.compiler.used) into
319319 // UsedFunctions.
320 GlobalVariable *GV = M.getGlobalVariable("llvm.used");
320 const GlobalVariable *GV = M.getGlobalVariable("llvm.used");
321321 if (!GV || !GV->hasInitializer()) return;
322322
323323 // Should be an array of 'i8*'.
324 ConstantArray *InitList = dyn_cast(GV->getInitializer());
324 const ConstantArray *InitList = dyn_cast(GV->getInitializer());
325325 if (InitList == 0) return;
326326
327327 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
328 if (Function *F =
328 if (const Function *F =
329329 dyn_cast(InitList->getOperand(i)->stripPointerCasts()))
330330 UsedFunctions.insert(F);
331331 }
406406 /// addPersonality - Provide the personality function for the exception
407407 /// information.
408408 void MachineModuleInfo::addPersonality(MachineBasicBlock *LandingPad,
409 Function *Personality) {
409 const Function *Personality) {
410410 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
411411 LP.Personality = Personality;
412412
425425 /// addCatchTypeInfo - Provide the catch typeinfo for a landing pad.
426426 ///
427427 void MachineModuleInfo::addCatchTypeInfo(MachineBasicBlock *LandingPad,
428 std::vector<GlobalVariable *> &TyInfo) {
428 std::vectorGlobalVariable *> &TyInfo) {
429429 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
430430 for (unsigned N = TyInfo.size(); N; --N)
431431 LP.TypeIds.push_back(getTypeIDFor(TyInfo[N - 1]));
434434 /// addFilterTypeInfo - Provide the filter typeinfo for a landing pad.
435435 ///
436436 void MachineModuleInfo::addFilterTypeInfo(MachineBasicBlock *LandingPad,
437 std::vector<GlobalVariable *> &TyInfo) {
437 std::vectorGlobalVariable *> &TyInfo) {
438438 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
439439 std::vector IdsInFilter(TyInfo.size());
440440 for (unsigned I = 0, E = TyInfo.size(); I != E; ++I)
491491
492492 /// getTypeIDFor - Return the type id for the specified typeinfo. This is
493493 /// function wide.
494 unsigned MachineModuleInfo::getTypeIDFor(GlobalVariable *TI) {
494 unsigned MachineModuleInfo::getTypeIDFor(const GlobalVariable *TI) {
495495 for (unsigned i = 0, N = TypeInfos.size(); i != N; ++i)
496496 if (TypeInfos[i] == TI) return i + 1;
497497
531531 }
532532
533533 /// getPersonality - Return the personality function for the current function.
534 Function *MachineModuleInfo::getPersonality() const {
534 const Function *MachineModuleInfo::getPersonality() const {
535535 // FIXME: Until PR1414 will be fixed, we're using 1 personality function per
536536 // function
537537 return !LandingPads.empty() ? LandingPads[0].Personality : NULL;
62876287 /// FindBaseOffset - Return true if base is a frame index, which is known not
62886288 // to alias with anything but itself. Provides base object and offset as results.
62896289 static bool FindBaseOffset(SDValue Ptr, SDValue &Base, int64_t &Offset,
6290 GlobalValue *&GV, void *&CV) {
6290 const GlobalValue *&GV, void *&CV) {
62916291 // Assume it is a primitive operation.
62926292 Base = Ptr; Offset = 0; GV = 0; CV = 0;
62936293
63356335 // Gather base node and offset information.
63366336 SDValue Base1, Base2;
63376337 int64_t Offset1, Offset2;
6338 GlobalValue *GV1, *GV2;
6338 const GlobalValue *GV1, *GV2;
63396339 void *CV1, *CV2;
63406340 bool isFrameIndex1 = FindBaseOffset(Ptr1, Base1, Offset1, GV1, CV1);
63416341 bool isFrameIndex2 = FindBaseOffset(Ptr2, Base2, Offset2, GV2, CV2);
5454 #include "FunctionLoweringInfo.h"
5555 using namespace llvm;
5656
57 unsigned FastISel::getRegForValue(Value *V) {
57 unsigned FastISel::getRegForValue(const Value *V) {
5858 EVT RealVT = TLI.getValueType(V->getType(), /*AllowUnknown=*/true);
5959 // Don't handle non-simple values in FastISel.
6060 if (!RealVT.isSimple())
8282 if (Reg != 0)
8383 return Reg;
8484
85 if (ConstantInt *CI = dyn_cast(V)) {
85 if (const ConstantInt *CI = dyn_cast(V)) {
8686 if (CI->getValue().getActiveBits() <= 64)
8787 Reg = FastEmit_i(VT, VT, ISD::Constant, CI->getZExtValue());
8888 } else if (isa(V)) {
9292 // local-CSE'd with actual integer zeros.
9393 Reg =
9494 getRegForValue(Constant::getNullValue(TD.getIntPtrType(V->getContext())));
95 } else if (ConstantFP *CF = dyn_cast(V)) {
95 } else if (const ConstantFP *CF = dyn_cast(V)) {
9696 // Try to emit the constant directly.
9797 Reg = FastEmit_f(VT, VT, ISD::ConstantFP, CF);
9898
115115 Reg = FastEmit_r(IntVT.getSimpleVT(), VT, ISD::SINT_TO_FP, IntegerReg);
116116 }
117117 }
118 } else if (Operator *Op = dyn_cast(V)) {
118 } else if (const Operator *Op = dyn_cast(V)) {
119119 if (!SelectOperator(Op, Op->getOpcode())) return 0;
120120 Reg = LocalValueMap[Op];
121121 } else if (isa(V)) {
135135 return Reg;
136136 }
137137
138 unsigned FastISel::lookUpRegForValue(Value *V) {
138 unsigned FastISel::lookUpRegForValue(const Value *V) {
139139 // Look up the value to see if we already have a register for it. We
140140 // cache values defined by Instructions across blocks, and other values
141141 // only locally. This is because Instructions already have the SSA
151151 /// NOTE: This is only necessary because we might select a block that uses
152152 /// a value before we select the block that defines the value. It might be
153153 /// possible to fix this by selecting blocks in reverse postorder.
154 unsigned FastISel::UpdateValueMap(Value* I, unsigned Reg) {
154 unsigned FastISel::UpdateValueMap(const Value *I, unsigned Reg) {
155155 if (!isa(I)) {
156156 LocalValueMap[I] = Reg;
157157 return Reg;
168168 return AssignedReg;
169169 }
170170
171 unsigned FastISel::getRegForGEPIndex(Value *Idx) {
171 unsigned FastISel::getRegForGEPIndex(const Value *Idx) {
172172 unsigned IdxN = getRegForValue(Idx);
173173 if (IdxN == 0)
174174 // Unhandled operand. Halt "fast" selection and bail.
187187 /// SelectBinaryOp - Select and emit code for a binary operator instruction,
188188 /// which has an opcode which directly corresponds to the given ISD opcode.
189189 ///
190 bool FastISel::SelectBinaryOp(User *I, unsigned ISDOpcode) {
190 bool FastISel::SelectBinaryOp(const User *I, unsigned ISDOpcode) {
191191 EVT VT = EVT::getEVT(I->getType(), /*HandleUnknown=*/true);
192192 if (VT == MVT::Other || !VT.isSimple())
193193 // Unhandled type. Halt "fast" selection and bail.
253253 return true;
254254 }
255255
256 bool FastISel::SelectGetElementPtr(User *I) {
256 bool FastISel::SelectGetElementPtr(const User *I) {
257257 unsigned N = getRegForValue(I->getOperand(0));
258258 if (N == 0)
259259 // Unhandled operand. Halt "fast" selection and bail.
261261
262262 const Type *Ty = I->getOperand(0)->getType();
263263 MVT VT = TLI.getPointerTy();
264 for (GetElementPtrInst::op_iterator OI = I->op_begin()+1, E = I->op_end();
265 OI != E; ++OI) {
266 Value *Idx = *OI;
264 for (GetElementPtrInst::const_op_iterator OI = I->op_begin()+1,
265 E = I->op_end(); OI != E; ++OI) {
266 const Value *Idx = *OI;
267267 if (const StructType *StTy = dyn_cast(Ty)) {
268268 unsigned Field = cast(Idx)->getZExtValue();
269269 if (Field) {
281281 Ty = cast(Ty)->getElementType();
282282
283283 // If this is a constant subscript, handle it quickly.
284 if (ConstantInt *CI = dyn_cast(Idx)) {
284 if (const ConstantInt *CI = dyn_cast(Idx)) {
285285 if (CI->getZExtValue() == 0) continue;
286286 uint64_t Offs =
287287 TD.getTypeAllocSize(Ty)*cast(CI)->getSExtValue();
317317 return true;
318318 }
319319
320 bool FastISel::SelectCall(User *I) {
321 Function *F = cast(I)->getCalledFunction();
320 bool FastISel::SelectCall(const User *I) {
321 const Function *F = cast(I)->getCalledFunction();
322322 if (!F) return false;
323323
324324 // Handle selected intrinsic function calls.
326326 switch (IID) {
327327 default: break;
328328 case Intrinsic::dbg_declare: {
329 DbgDeclareInst *DI = cast(I);
329 const DbgDeclareInst *DI = cast(I);
330330 if (!DIDescriptor::ValidDebugInfo(DI->getVariable(), CodeGenOpt::None) ||
331331 !MF.getMMI().hasDebugInfo())
332332 return true;
333333
334 Value *Address = DI->getAddress();
334 const Value *Address = DI->getAddress();
335335 if (!Address)
336336 return true;
337337 if (isa(Address))
338338 return true;
339 AllocaInst *AI = dyn_cast(Address);
339 const AllocaInst *AI = dyn_cast(Address);
340340 // Don't handle byval struct arguments or VLAs, for example.
341341 if (!AI) break;
342342 DenseMap::iterator SI =
353353 }
354354 case Intrinsic::dbg_value: {
355355 // This form of DBG_VALUE is target-independent.
356 DbgValueInst *DI = cast(I);
356 const DbgValueInst *DI = cast(I);
357357 const TargetInstrDesc &II = TII.get(TargetOpcode::DBG_VALUE);
358 Value *V = DI->getValue();
358 const Value *V = DI->getValue();
359359 if (!V) {
360360 // Currently the optimizer can produce this; insert an undef to
361361 // help debugging. Probably the optimizer should not do this.
362362 BuildMI(MBB, DL, II).addReg(0U).addImm(DI->getOffset()).
363363 addMetadata(DI->getVariable());
364 } else if (ConstantInt *CI = dyn_cast(V)) {
364 } else if (const ConstantInt *CI = dyn_cast(V)) {
365365 BuildMI(MBB, DL, II).addImm(CI->getZExtValue()).addImm(DI->getOffset()).
366366 addMetadata(DI->getVariable());
367 } else if (ConstantFP *CF = dyn_cast(V)) {
367 } else if (const ConstantFP *CF = dyn_cast(V)) {
368368 BuildMI(MBB, DL, II).addFPImm(CF).addImm(DI->getOffset()).
369369 addMetadata(DI->getVariable());
370370 } else if (unsigned Reg = lookUpRegForValue(V)) {
447447 return false;
448448 }
449449
450 bool FastISel::SelectCast(User *I, unsigned Opcode) {
450 bool FastISel::SelectCast(const User *I, unsigned Opcode) {
451451 EVT SrcVT = TLI.getValueType(I->getOperand(0)->getType());
452452 EVT DstVT = TLI.getValueType(I->getType());
453453
499499 return true;
500500 }
501501
502 bool FastISel::SelectBitCast(User *I) {
502 bool FastISel::SelectBitCast(const User *I) {
503503 // If the bitcast doesn't change the type, just use the operand value.
504504 if (I->getType() == I->getOperand(0)->getType()) {
505505 unsigned Reg = getRegForValue(I->getOperand(0));
550550 }
551551
552552 bool
553 FastISel::SelectInstruction(Instruction *I) {
553 FastISel::SelectInstruction(const Instruction *I) {
554554 // First, try doing target-independent selection.
555555 if (SelectOperator(I, I->getOpcode()))
556556 return true;
579579 /// SelectFNeg - Emit an FNeg operation.
580580 ///
581581 bool
582 FastISel::SelectFNeg(User *I) {
582 FastISel::SelectFNeg(const User *I) {
583583 unsigned OpReg = getRegForValue(BinaryOperator::getFNegArgument(I));
584584 if (OpReg == 0) return false;
585585
620620 }
621621
622622 bool
623 FastISel::SelectOperator(User *I, unsigned Opcode) {
623 FastISel::SelectOperator(const User *I, unsigned Opcode) {
624624 switch (Opcode) {
625625 case Instruction::Add:
626626 return SelectBinaryOp(I, ISD::ADD);
666666 return SelectGetElementPtr(I);
667667
668668 case Instruction::Br: {
669 BranchInst *BI = cast(I);
669 const BranchInst *BI = cast(I);
670670
671671 if (BI->isUnconditional()) {
672 BasicBlock *LLVMSucc = BI->getSuccessor(0);
672 const BasicBlock *LLVMSucc = BI->getSuccessor(0);
673673 MachineBasicBlock *MSucc = MBBMap[LLVMSucc];
674674 FastEmitBranch(MSucc);
675675 return true;
781781 }
782782
783783 unsigned FastISel::FastEmit_f(MVT, MVT,
784 unsigned, ConstantFP * /*FPImm*/) {
784 unsigned, const ConstantFP * /*FPImm*/) {
785785 return 0;
786786 }
787787
793793
794794 unsigned FastISel::FastEmit_rf(MVT, MVT,
795795 unsigned, unsigned /*Op0*/,
796 ConstantFP * /*FPImm*/) {
796 const ConstantFP * /*FPImm*/) {
797797 return 0;
798798 }
799799
826826 /// FastEmit_rf. If that fails, it materializes the immediate into a register
827827 /// and try FastEmit_rr instead.
828828 unsigned FastISel::FastEmit_rf_(MVT VT, unsigned Opcode,
829 unsigned Op0, ConstantFP *FPImm,
829 unsigned Op0, const ConstantFP *FPImm,
830830 MVT ImmType) {
831831 // First check if immediate type is legal. If not, we can't use the rf form.
832832 unsigned ResultReg = FastEmit_rf(VT, VT, Opcode, Op0, FPImm);
936936
937937 unsigned FastISel::FastEmitInst_rf(unsigned MachineInstOpcode,
938938 const TargetRegisterClass *RC,
939 unsigned Op0, ConstantFP *FPImm) {
939 unsigned Op0, const ConstantFP *FPImm) {
940940 unsigned ResultReg = createResultReg(RC);
941941 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
942942
315315
316316 // Gather all the type infos for this landing pad and pass them along to
317317 // MachineModuleInfo.
318 std::vector<GlobalVariable *> TyInfo;
318 std::vector<const GlobalVariable *> TyInfo;
319319 unsigned N = I.getNumOperands();
320320
321321 for (unsigned i = N - 1; i > 2; --i) {
530530 AddOperand(&*MIB, Op, (*MIB).getNumOperands(), &II, VRBaseMap,
531531 true /*IsDebug*/);
532532 } else if (SD->getKind() == SDDbgValue::CONST) {
533 Value *V = SD->getConst();
534 if (ConstantInt *CI = dyn_cast(V)) {
533 const Value *V = SD->getConst();
534 if (const ConstantInt *CI = dyn_cast(V)) {
535535 MIB.addImm(CI->getSExtValue());
536 } else if (ConstantFP *CF = dyn_cast(V)) {
536 } else if (const ConstantFP *CF = dyn_cast(V)) {
537537 MIB.addFPImm(CF);
538538 } else {
539539 // Could be an Undef. In any case insert an Undef so we can see what we
4040 SDNode *Node; // valid for expressions
4141 unsigned ResNo; // valid for expressions
4242 } s;
43 Value *Const; // valid for constants
43 const Value *Const; // valid for constants
4444 unsigned FrameIx; // valid for stack objects
4545 } u;
4646 MDNode *mdPtr;
5959 }
6060
6161 // Constructor for constants.
62 SDDbgValue(MDNode *mdP, Value *C, uint64_t off, DebugLoc dl, unsigned O) :
62 SDDbgValue(MDNode *mdP, const Value *C, uint64_t off, DebugLoc dl,
63 unsigned O) :
6364 mdPtr(mdP), Offset(off), DL(dl), Order(O), Invalid(false) {
6465 kind = CONST;
6566 u.Const = C;
8586 unsigned getResNo() { assert (kind==SDNODE); return u.s.ResNo; }
8687
8788 // Returns the Value* for a constant
88 Value *getConst() { assert (kind==CONST); return u.Const; }
89 const Value *getConst() { assert (kind==CONST); return u.Const; }
8990
9091 // Returns the FrameIx for a stack object
9192 unsigned getFrameIx() { assert (kind==FRAMEIX); return u.FrameIx; }
10471047 return SDValue(N, 0);
10481048 }
10491049
1050 SDValue SelectionDAG::getConstantPool(Constant *C, EVT VT,
1050 SDValue SelectionDAG::getConstantPool(const Constant *C, EVT VT,
10511051 unsigned Alignment, int Offset,
10521052 bool isTarget,
10531053 unsigned char TargetFlags) {
13181318 }
13191319
13201320
1321 SDValue SelectionDAG::getBlockAddress(BlockAddress *BA, EVT VT,
1321 SDValue SelectionDAG::getBlockAddress(const BlockAddress *BA, EVT VT,
13221322 bool isTarget,
13231323 unsigned char TargetFlags) {
13241324 unsigned Opc = isTarget ? ISD::TargetBlockAddress : ISD::BlockAddress;
22692269 GlobalAddressSDNode *GA = dyn_cast(Op);
22702270 if (!GA) return false;
22712271 if (GA->getOffset() != 0) return false;
2272 GlobalVariable *GV = dyn_cast(GA->getGlobal());
2272 const GlobalVariable *GV = dyn_cast(GA->getGlobal());
22732273 if (!GV) return false;
22742274 return MF->getMMI().hasDebugInfo();
22752275 }
31943194 if (!G)
31953195 return false;
31963196
3197 GlobalVariable *GV = dyn_cast(G->getGlobal());
3197 const GlobalVariable *GV = dyn_cast(G->getGlobal());
31983198 if (GV && GetConstantStringInfo(GV, Str, SrcDelta, false))
31993199 return true;
32003200
49344934 }
49354935
49364936 SDDbgValue *
4937 SelectionDAG::getDbgValue(MDNode *MDPtr, Value *C, uint64_t Off,
4937 SelectionDAG::getDbgValue(MDNode *MDPtr, const Value *C, uint64_t Off,
49384938 DebugLoc DL, unsigned O) {
49394939 return new (Allocator) SDDbgValue(MDPtr, C, Off, DL, O);
49404940 }
61686168 return true;
61696169 }
61706170
6171 GlobalValue *GV1 = NULL;
6172 GlobalValue *GV2 = NULL;
6171 const GlobalValue *GV1 = NULL;
6172 const GlobalValue *GV2 = NULL;
61736173 int64_t Offset1 = 0;
61746174 int64_t Offset2 = 0;
61756175 bool isGA1 = TLI.isGAPlusOffset(Loc.getNode(), GV1, Offset1);
61846184 /// it cannot be inferred.
61856185 unsigned SelectionDAG::InferPtrAlignment(SDValue Ptr) const {
61866186 // If this is a GlobalAddress + cst, return the alignment.
6187 GlobalValue *GV;
6187 const GlobalValue *GV;
61886188 int64_t GVOffset = 0;
61896189 if (TLI.isGAPlusOffset(Ptr.getNode(), GV, GVOffset)) {
61906190 // If GV has specified alignment, then use it. Otherwise, use the preferred
61916191 // alignment.
61926192 unsigned Align = GV->getAlignment();
61936193 if (!Align) {
6194 if (GlobalVariable *GVar = dyn_cast(GV)) {
6194 if (const GlobalVariable *GVar = dyn_cast(GV)) {
61956195 if (GVar->hasInitializer()) {
61966196 const TargetData *TD = TLI.getTargetData();
61976197 Align = TD->getPreferredAlignment(GVar);
612612 AssignOrderingToNode(Node->getOperand(I).getNode());
613613 }
614614
615 void SelectionDAGBuilder::visit(Instruction &I) {
615 void SelectionDAGBuilder::visit(const Instruction &I) {
616616 visit(I.getOpcode(), I);
617617 }
618618
619 void SelectionDAGBuilder::visit(unsigned Opcode, User &I) {
619 void SelectionDAGBuilder::visit(unsigned Opcode, const User &I) {
620620 // Note: this doesn't use InstVisitor, because it has to work with
621621 // ConstantExpr's in addition to instructions.
622622 switch (Opcode) {
811811 }
812812 }
813813
814 void SelectionDAGBuilder::visitRet(ReturnInst &I) {
814 void SelectionDAGBuilder::visitRet(const ReturnInst &I) {
815815 SDValue Chain = getControlRoot();
816816 SmallVector Outs;
817817 FunctionLoweringInfo &FLI = DAG.getFunctionLoweringInfo();
916916 /// CopyToExportRegsIfNeeded - If the given value has virtual registers
917917 /// created for it, emit nodes to copy the value into the virtual
918918 /// registers.
919 void SelectionDAGBuilder::CopyToExportRegsIfNeeded(Value *V) {
919 void SelectionDAGBuilder::CopyToExportRegsIfNeeded(const Value *V) {
920920 if (!V->use_empty()) {
921921 DenseMap::iterator VMI = FuncInfo.ValueMap.find(V);
922922 if (VMI != FuncInfo.ValueMap.end())
927927 /// ExportFromCurrentBlock - If this condition isn't known to be exported from
928928 /// the current basic block, add it to ValueMap now so that we'll get a
929929 /// CopyTo/FromReg.
930 void SelectionDAGBuilder::ExportFromCurrentBlock(Value *V) {
930 void SelectionDAGBuilder::ExportFromCurrentBlock(const Value *V) {
931931 // No need to export constants.
932932 if (!isa(V) && !isa(V)) return;
933933
938938 CopyValueToVirtualRegister(V, Reg);
939939 }
940940
941 bool SelectionDAGBuilder::isExportableFromCurrentBlock(Value *V,
941 bool SelectionDAGBuilder::isExportableFromCurrentBlock(const Value *V,
942942 const BasicBlock *FromBB) {
943943 // The operands of the setcc have to be in this block. We don't know
944944 // how to export them from some other block.
945 if (Instruction *VI = dyn_cast(V)) {
945 if (const Instruction *VI = dyn_cast(V)) {
946946 // Can export from current BB.
947947 if (VI->getParent() == FromBB)
948948 return true;
976976 /// AND operator tree.
977977 ///
978978 void
979 SelectionDAGBuilder::EmitBranchForMergedCondition(Value *Cond,
979 SelectionDAGBuilder::EmitBranchForMergedCondition(const Value *Cond,
980980 MachineBasicBlock *TBB,
981981 MachineBasicBlock *FBB,
982982 MachineBasicBlock *CurBB) {
984984
985985 // If the leaf of the tree is a comparison, merge the condition into
986986 // the caseblock.
987 if (CmpInst *BOp = dyn_cast(Cond)) {
987 if (const CmpInst *BOp = dyn_cast(Cond)) {
988988 // The operands of the cmp have to be in this block. We don't know
989989 // how to export them from some other block. If this is the first block
990990 // of the sequence, no exporting is needed.
992992 (isExportableFromCurrentBlock(BOp->getOperand(0), BB) &&
993993 isExportableFromCurrentBlock(BOp->getOperand(1), BB))) {
994994 ISD::CondCode Condition;
995 if (ICmpInst *IC = dyn_cast(Cond)) {
995 if (const ICmpInst *IC = dyn_cast(Cond)) {
996996 Condition = getICmpCondCode(IC->getPredicate());
997 } else if (FCmpInst *FC = dyn_cast(Cond)) {
997 } else if (const FCmpInst *FC = dyn_cast(Cond)) {
998998 Condition = getFCmpCondCode(FC->getPredicate());
999999 } else {
10001000 Condition = ISD::SETEQ; // silence warning.
10151015 }
10161016
10171017 /// FindMergedConditions - If Cond is an expression like
1018 void SelectionDAGBuilder::FindMergedConditions(Value *Cond,
1018 void SelectionDAGBuilder::FindMergedConditions(const Value *Cond,
10191019 MachineBasicBlock *TBB,
10201020 MachineBasicBlock *FBB,
10211021 MachineBasicBlock *CurBB,
10221022 unsigned Opc) {
10231023 // If this node is not part of the or/and tree, emit it as a branch.
1024 Instruction *BOp = dyn_cast(Cond);
1024 const Instruction *BOp = dyn_cast(Cond);
10251025 if (!BOp || !(isa(BOp) || isa(BOp)) ||
10261026 (unsigned)BOp->getOpcode() != Opc || !BOp->hasOneUse() ||
10271027 BOp->getParent() != CurBB->getBasicBlock() ||
11011101 return true;
11021102 }
11031103
1104 void SelectionDAGBuilder::visitBr(BranchInst &I) {
1104 void SelectionDAGBuilder::visitBr(const BranchInst &I) {
11051105 // Update machine-CFG edges.
11061106 MachineBasicBlock *Succ0MBB = FuncInfo.MBBMap[I.getSuccessor(0)];
11071107
11261126
11271127 // If this condition is one of the special cases we handle, do special stuff
11281128 // now.
1129 Value *CondVal = I.getCondition();
1129 const Value *CondVal = I.getCondition();
11301130 MachineBasicBlock *Succ1MBB = FuncInfo.MBBMap[I.getSuccessor(1)];
11311131
11321132 // If this is a series of conditions that are or'd or and'd together, emit
11441144 // cmp D, E
11451145 // jle foo
11461146 //
1147 if (BinaryOperator *BOp = dyn_cast(CondVal)) {
1147 if (const BinaryOperator *BOp = dyn_cast(CondVal)) {
11481148 if (BOp->hasOneUse() &&
11491149 (BOp->getOpcode() == Instruction::And ||
11501150 BOp->getOpcode() == Instruction::Or)) {
14161416 DAG.setRoot(BrAnd);
14171417 }
14181418
1419 void SelectionDAGBuilder::visitInvoke(InvokeInst &I) {
1419 void SelectionDAGBuilder::visitInvoke(const InvokeInst &I) {
14201420 // Retrieve successors.
14211421 MachineBasicBlock *Return = FuncInfo.MBBMap[I.getSuccessor(0)];
14221422 MachineBasicBlock *LandingPad = FuncInfo.MBBMap[I.getSuccessor(1)];
14411441 DAG.getBasicBlock(Return)));
14421442 }
14431443
1444 void SelectionDAGBuilder::visitUnwind(UnwindInst &I) {
1444 void SelectionDAGBuilder::visitUnwind(const UnwindInst &I) {
14451445 }
14461446
14471447 /// handleSmallSwitchCaseRange - Emit a series of specific tests (suitable for
14481448 /// small case ranges).
14491449 bool SelectionDAGBuilder::handleSmallSwitchRange(CaseRec& CR,
14501450 CaseRecVector& WorkList,
1451 Value* SV,
1451 const Value* SV,
14521452 MachineBasicBlock* Default) {
14531453 Case& BackCase = *(CR.Range.second-1);
14541454
15021502 FallThrough = Default;
15031503 }
15041504
1505 Value *RHS, *LHS, *MHS;
1505 const Value *RHS, *LHS, *MHS;
15061506 ISD::CondCode CC;
15071507 if (I->High == I->Low) {
15081508 // This is just small small case range :) containing exactly 1 case
15451545 /// handleJTSwitchCase - Emit jumptable for current switch case range
15461546 bool SelectionDAGBuilder::handleJTSwitchCase(CaseRec& CR,
15471547 CaseRecVector& WorkList,
1548 Value* SV,
1548 const Value* SV,
15491549 MachineBasicBlock* Default) {
15501550 Case& FrontCase = *CR.Range.first;
15511551 Case& BackCase = *(CR.Range.second-1);
16401640 /// 2 subtrees.
16411641 bool SelectionDAGBuilder::handleBTSplitSwitchCase(CaseRec& CR,
16421642 CaseRecVector& WorkList,
1643 Value* SV,
1643 const Value* SV,
16441644 MachineBasicBlock* Default) {
16451645 // Get the MachineFunction which holds the current MBB. This is used when
16461646 // inserting any additional MBBs necessary to represent the switch.
17681768 /// of masks and emit bit tests with these masks.
17691769 bool SelectionDAGBuilder::handleBitTestsSwitchCase(CaseRec& CR,
17701770 CaseRecVector& WorkList,
1771 Value* SV,
1771 const Value* SV,
17721772 MachineBasicBlock* Default){
17731773 EVT PTy = TLI.getPointerTy();
17741774 unsigned IntPtrBits = PTy.getSizeInBits();
19381938 return numCmps;
19391939 }
19401940
1941 void SelectionDAGBuilder::visitSwitch(SwitchInst &SI) {
1941 void SelectionDAGBuilder::visitSwitch(const SwitchInst &SI) {
19421942 // Figure out which block is immediately after the current one.
19431943 MachineBasicBlock *NextBlock = 0;
19441944 MachineBasicBlock *Default = FuncInfo.MBBMap[SI.getDefaultDest()];
19701970 // Get the Value to be switched on and default basic blocks, which will be
19711971 // inserted into CaseBlock records, representing basic blocks in the binary
19721972 // search tree.
1973 Value *SV = SI.getOperand(0);
1973 const Value *SV = SI.getOperand(0);
19741974
19751975 // Push the initial CaseRec onto the worklist
19761976 CaseRecVector WorkList;
20012001 }
20022002 }
20032003
2004 void SelectionDAGBuilder::visitIndirectBr(IndirectBrInst &I) {
2004 void SelectionDAGBuilder::visitIndirectBr(const IndirectBrInst &I) {
20052005 // Update machine-CFG edges with unique successors.
20062006 SmallVector succs;
20072007 succs.reserve(I.getNumSuccessors());
20172017 getValue(I.getAddress())));
20182018 }
20192019
2020 void SelectionDAGBuilder::visitFSub(User &I) {
2020 void SelectionDAGBuilder::visitFSub(const User &I) {
20212021 // -0.0 - X --> fneg
20222022 const Type *Ty = I.getType();
20232023 if (Ty->isVectorTy()) {
20472047 visitBinary(I, ISD::FSUB);
20482048 }
20492049
2050 void SelectionDAGBuilder::visitBinary(User &I, unsigned OpCode) {
2050 void SelectionDAGBuilder::visitBinary(const User &I, unsigned OpCode) {
20512051 SDValue Op1 = getValue(I.getOperand(0));
20522052 SDValue Op2 = getValue(I.getOperand(1));
20532053 setValue(&I, DAG.getNode(OpCode, getCurDebugLoc(),
20542054 Op1.getValueType(), Op1, Op2));
20552055 }
20562056
2057 void SelectionDAGBuilder::visitShift(User &I, unsigned Opcode) {
2057 void SelectionDAGBuilder::visitShift(const User &I, unsigned Opcode) {
20582058 SDValue Op1 = getValue(I.getOperand(0));
20592059 SDValue Op2 = getValue(I.getOperand(1));
20602060 if (!I.getType()->isVectorTy() &&
20882088 Op1.getValueType(), Op1, Op2));
20892089 }
20902090
2091 void SelectionDAGBuilder::visitICmp(User &I) {
2091 void SelectionDAGBuilder::visitICmp(const User &I) {
20922092 ICmpInst::Predicate predicate = ICmpInst::BAD_ICMP_PREDICATE;
2093 if (ICmpInst *IC = dyn_cast(&I))
2093 if (const ICmpInst *IC = dyn_cast(&I))
20942094 predicate = IC->getPredicate();
2095 else if (ConstantExpr *IC = dyn_cast(&I))
2095 else if (const ConstantExpr *IC = dyn_cast(&I))
20962096 predicate = ICmpInst::Predicate(IC->getPredicate());
20972097 SDValue Op1 = getValue(I.getOperand(0));
20982098 SDValue Op2 = getValue(I.getOperand(1));
21022102 setValue(&I, DAG.getSetCC(getCurDebugLoc(), DestVT, Op1, Op2, Opcode));
21032103 }
21042104
2105 void SelectionDAGBuilder::visitFCmp(User &I) {
2105 void SelectionDAGBuilder::visitFCmp(const User &I) {
21062106 FCmpInst::Predicate predicate = FCmpInst::BAD_FCMP_PREDICATE;
2107 if (FCmpInst *FC = dyn_cast(&I))
2107 if (const FCmpInst *FC = dyn_cast(&I))
21082108 predicate = FC->getPredicate();
2109 else if (ConstantExpr *FC = dyn_cast(&I))
2109 else if (const ConstantExpr *FC = dyn_cast(&I))
21102110 predicate = FCmpInst::Predicate(FC->getPredicate());
21112111 SDValue Op1 = getValue(I.getOperand(0));
21122112 SDValue Op2 = getValue(I.getOperand(1));
21152115 setValue(&I, DAG.getSetCC(getCurDebugLoc(), DestVT, Op1, Op2, Condition));
21162116 }
21172117
2118 void SelectionDAGBuilder::visitSelect(User &I) {
2118 void SelectionDAGBuilder::visitSelect(const User &I) {
21192119 SmallVector ValueVTs;
21202120 ComputeValueVTs(TLI, I.getType(), ValueVTs);
21212121 unsigned NumValues = ValueVTs.size();
21402140 &Values[0], NumValues));
21412141 }
21422142
2143 void SelectionDAGBuilder::visitTrunc(User &I) {
2143 void SelectionDAGBuilder::visitTrunc(const User &I) {
21442144 // TruncInst cannot be a no-op cast because sizeof(src) > sizeof(dest).
21452145 SDValue N = getValue(I.getOperand(0));
21462146 EVT DestVT = TLI.getValueType(I.getType());
21472147 setValue(&I, DAG.getNode(ISD::TRUNCATE, getCurDebugLoc(), DestVT, N));
21482148 }
21492149
2150 void SelectionDAGBuilder::visitZExt(User &I) {
2150 void SelectionDAGBuilder::visitZExt(const User &I) {
21512151 // ZExt cannot be a no-op cast because sizeof(src) < sizeof(dest).
21522152 // ZExt also can't be a cast to bool for same reason. So, nothing much to do
21532153 SDValue N = getValue(I.getOperand(0));
21552155 setValue(&I, DAG.getNode(ISD::ZERO_EXTEND, getCurDebugLoc(), DestVT, N));
21562156 }
21572157
2158 void SelectionDAGBuilder::visitSExt(User &I) {
2158 void SelectionDAGBuilder::visitSExt(const User &I) {
21592159 // SExt cannot be a no-op cast because sizeof(src) < sizeof(dest).
21602160 // SExt also can't be a cast to bool for same reason. So, nothing much to do
21612161 SDValue N = getValue(I.getOperand(0));
21632163 setValue(&I, DAG.getNode(ISD::SIGN_EXTEND, getCurDebugLoc(), DestVT, N));
21642164 }
21652165
2166 void SelectionDAGBuilder::visitFPTrunc(User &I) {
2166 void SelectionDAGBuilder::visitFPTrunc(const User &I) {
21672167 // FPTrunc is never a no-op cast, no need to check
21682168 SDValue N = getValue(I.getOperand(0));
21692169 EVT DestVT = TLI.getValueType(I.getType());
21712171 DestVT, N, DAG.getIntPtrConstant(0)));
21722172 }
21732173
2174 void SelectionDAGBuilder::visitFPExt(User &I){
2174 void SelectionDAGBuilder::visitFPExt(const User &I){
21752175 // FPTrunc is never a no-op cast, no need to check
21762176 SDValue N = getValue(I.getOperand(0));
21772177 EVT DestVT = TLI.getValueType(I.getType());
21782178 setValue(&I, DAG.getNode(ISD::FP_EXTEND, getCurDebugLoc(), DestVT, N));
21792179 }
21802180
2181 void SelectionDAGBuilder::visitFPToUI(User &I) {
2181 void SelectionDAGBuilder::visitFPToUI(const User &I) {
21822182 // FPToUI is never a no-op cast, no need to check
21832183 SDValue N = getValue(I.getOperand(0));
21842184 EVT DestVT = TLI.getValueType(I.getType());
21852185 setValue(&I, DAG.getNode(ISD::FP_TO_UINT, getCurDebugLoc(), DestVT, N));
21862186 }
21872187
2188 void SelectionDAGBuilder::visitFPToSI(User &I) {
2188 void SelectionDAGBuilder::visitFPToSI(const User &I) {
21892189 // FPToSI is never a no-op cast, no need to check
21902190 SDValue N = getValue(I.getOperand(0));
21912191 EVT DestVT = TLI.getValueType(I.getType());
21922192 setValue(&I, DAG.getNode(ISD::FP_TO_SINT, getCurDebugLoc(), DestVT, N));
21932193 }
21942194
2195 void SelectionDAGBuilder::visitUIToFP(User &I) {
2195 void SelectionDAGBuilder::visitUIToFP(const User &I) {
21962196 // UIToFP is never a no-op cast, no need to check
21972197 SDValue N = getValue(I.getOperand(0));
21982198 EVT DestVT = TLI.getValueType(I.getType());
21992199 setValue(&I, DAG.getNode(ISD::UINT_TO_FP, getCurDebugLoc(), DestVT, N));
22002200 }
22012201
2202 void SelectionDAGBuilder::visitSIToFP(User &I){
2202 void SelectionDAGBuilder::visitSIToFP(const User &I){
22032203 // SIToFP is never a no-op cast, no need to check
22042204 SDValue N = getValue(I.getOperand(0));
22052205 EVT DestVT = TLI.getValueType(I.getType());
22062206 setValue(&I, DAG.getNode(ISD::SINT_TO_FP, getCurDebugLoc(), DestVT, N));
22072207 }
22082208
2209 void SelectionDAGBuilder::visitPtrToInt(User &I) {
2209 void SelectionDAGBuilder::visitPtrToInt(const User &I) {
22102210 // What to do depends on the size of the integer and the size of the pointer.
22112211 // We can either truncate, zero extend, or no-op, accordingly.
22122212 SDValue N = getValue(I.getOperand(0));
22152215 setValue(&I, DAG.getZExtOrTrunc(N, getCurDebugLoc(), DestVT));
22162216 }
22172217
2218 void SelectionDAGBuilder::visitIntToPtr(User &I) {
2218 void SelectionDAGBuilder::visitIntToPtr(const User &I) {
22192219 // What to do depends on the size of the integer and the size of the pointer.
22202220 // We can either truncate, zero extend, or no-op, accordingly.
22212221 SDValue N = getValue(I.getOperand(0));
22242224 setValue(&I, DAG.getZExtOrTrunc(N, getCurDebugLoc(), DestVT));
22252225 }
22262226
2227 void SelectionDAGBuilder::visitBitCast(User &I) {
2227 void SelectionDAGBuilder::visitBitCast(const User &I) {
22282228 SDValue N = getValue(I.getOperand(0));
22292229 EVT DestVT = TLI.getValueType(I.getType());
22302230
22372237 setValue(&I, N); // noop cast.
22382238 }
22392239
2240 void SelectionDAGBuilder::visitInsertElement(User &I) {
2240 void SelectionDAGBuilder::visitInsertElement(const User &I) {
22412241 SDValue InVec = getValue(I.getOperand(0));
22422242 SDValue InVal = getValue(I.getOperand(1));
22432243 SDValue InIdx = DAG.getNode(ISD::ZERO_EXTEND, getCurDebugLoc(),
22482248 InVec, InVal, InIdx));
22492249 }
22502250
2251 void SelectionDAGBuilder::visitExtractElement(User &I) {
2251 void SelectionDAGBuilder::visitExtractElement(const User &I) {
22522252 SDValue InVec = getValue(I.getOperand(0));
22532253 SDValue InIdx = DAG.getNode(ISD::ZERO_EXTEND, getCurDebugLoc(),
22542254 TLI.getPointerTy(),
22672267 return true;
22682268 }
22692269
2270 void SelectionDAGBuilder::visitShuffleVector(User &I) {
2270 void SelectionDAGBuilder::visitShuffleVector(const User &I) {
22712271 SmallVector Mask;
22722272 SDValue Src1 = getValue(I.getOperand(0));
22732273 SDValue Src2 = getValue(I.getOperand(1));
24482448 VT, &Ops[0], Ops.size()));
24492449 }
24502450
2451 void SelectionDAGBuilder::visitInsertValue(InsertValueInst &I) {
2451 void SelectionDAGBuilder::visitInsertValue(const InsertValueInst &I) {
24522452 const Value *Op0 = I.getOperand(0);
24532453 const Value *Op1 = I.getOperand(1);
24542454 const Type *AggTy = I.getType();
24892489 &Values[0], NumAggValues));
24902490 }
24912491
2492 void SelectionDAGBuilder::visitExtractValue(ExtractValueInst &I) {
2492 void SelectionDAGBuilder::visitExtractValue(const ExtractValueInst &I) {
24932493 const Value *Op0 = I.getOperand(0);
24942494 const Type *AggTy = Op0->getType();
24952495 const Type *ValTy = I.getType();
25172517 &Values[0], NumValValues));
25182518 }
25192519
2520 void SelectionDAGBuilder::visitGetElementPtr(User &I) {
2520 void SelectionDAGBuilder::visitGetElementPtr(const User &I) {
25212521 SDValue N = getValue(I.getOperand(0));
25222522 const Type *Ty = I.getOperand(0)->getType();
25232523
2524 for (GetElementPtrInst::op_iterator OI = I.op_begin()+1, E = I.op_end();
2524 for (GetElementPtrInst::const_op_iterator OI = I.op_begin()+1, E = I.op_end();
25252525 OI != E; ++OI) {
2526 Value *Idx = *OI;
2526 const Value *Idx = *OI;
25272527 if (const StructType *StTy = dyn_cast(Ty)) {
25282528 unsigned Field = cast(Idx)->getZExtValue();
25292529 if (Field) {
25432543 Ty = cast(Ty)->getElementType();
25442544
25452545 // If this is a constant subscript, handle it quickly.
2546 if (ConstantInt *CI = dyn_cast(Idx)) {
2546 if (const ConstantInt *CI = dyn_cast(Idx)) {
25472547 if (CI->getZExtValue() == 0) continue;
25482548 uint64_t Offs =
25492549 TD->getTypeAllocSize(Ty)*cast(CI)->getSExtValue();
25942594 setValue(&I, N);
25952595 }
25962596
2597 void SelectionDAGBuilder::visitAlloca(AllocaInst &I) {
2597 void SelectionDAGBuilder::visitAlloca(const AllocaInst &I) {
25982598 // If this is a fixed sized alloca in the entry block of the function,
25992599 // allocate it statically on the stack.
26002600 if (FuncInfo.StaticAllocaMap.count(&I))
26462646 FuncInfo.MF->getFrameInfo()->CreateVariableSizedObject();
26472647 }
26482648
2649 void SelectionDAGBuilder::visitLoad(LoadInst &I) {
2649 void SelectionDAGBuilder::visitLoad(const LoadInst &I) {
26502650 const Value *SV = I.getOperand(0);
26512651 SDValue Ptr = getValue(SV);
26522652
27062706 &Values[0], NumValues));
27072707 }
27082708
2709 void SelectionDAGBuilder::visitStore(StoreInst &I) {
2710 Value *SrcV = I.getOperand(0);
2711 Value *PtrV = I.getOperand(1);
2709 void SelectionDAGBuilder::visitStore(const StoreInst &I) {
2710 const Value *SrcV = I.getOperand(0);
2711 const Value *PtrV = I.getOperand(1);
27122712
27132713 SmallVector ValueVTs;
27142714 SmallVector Offsets;
27452745
27462746 /// visitTargetIntrinsic - Lower a call of a target intrinsic to an INTRINSIC
27472747 /// node.
2748 void SelectionDAGBuilder::visitTargetIntrinsic(CallInst &I,
2748 void SelectionDAGBuilder::visitTargetIntrinsic(const CallInst &I,
27492749 unsigned Intrinsic) {
27502750 bool HasChain = !I.doesNotAccessMemory();
27512751 bool OnlyLoad = HasChain && I.onlyReadsMemory();
28712871 /// visitIntrinsicCall: I is a call instruction
28722872 /// Op is the associated NodeType for I
28732873 const char *
2874 SelectionDAGBuilder::implVisitBinaryAtomic(CallInst& I, ISD::NodeType Op) {
2874 SelectionDAGBuilder::implVisitBinaryAtomic(const CallInst& I,
2875 ISD::NodeType Op) {
28752876 SDValue Root = getRoot();
28762877 SDValue L =
28772878 DAG.getAtomic(Op, getCurDebugLoc(),
28872888
28882889 // implVisitAluOverflow - Lower arithmetic overflow instrinsics.
28892890 const char *
2890 SelectionDAGBuilder::implVisitAluOverflow(CallInst &I, ISD::NodeType Op) {
2891 SelectionDAGBuilder::implVisitAluOverflow(const CallInst &I, ISD::NodeType Op) {
28912892 SDValue Op1 = getValue(I.getOperand(1));
28922893 SDValue Op2 = getValue(I.getOperand(2));
28932894
28992900 /// visitExp - Lower an exp intrinsic. Handles the special sequences for
29002901 /// limited-precision mode.
29012902 void
2902 SelectionDAGBuilder::visitExp(CallInst &I) {
2903 SelectionDAGBuilder::visitExp(const CallInst &I) {
29032904 SDValue result;
29042905 DebugLoc dl = getCurDebugLoc();
29052906
30253026 /// visitLog - Lower a log intrinsic. Handles the special sequences for
30263027 /// limited-precision mode.
30273028 void
3028 SelectionDAGBuilder::visitLog(CallInst &I) {
3029 SelectionDAGBuilder::visitLog(const CallInst &I) {
30293030 SDValue result;
30303031 DebugLoc dl = getCurDebugLoc();
30313032
31353136 /// visitLog2 - Lower a log2 intrinsic. Handles the special sequences for
31363137 /// limited-precision mode.
31373138 void
3138 SelectionDAGBuilder::visitLog2(CallInst &I) {
3139 SelectionDAGBuilder::visitLog2(const CallInst &I) {
31393140 SDValue result;
31403141 DebugLoc dl = getCurDebugLoc();
31413142
32443245 /// visitLog10 - Lower a log10 intrinsic. Handles the special sequences for
32453246 /// limited-precision mode.
32463247 void
3247 SelectionDAGBuilder::visitLog10(CallInst &I) {
3248 SelectionDAGBuilder::visitLog10(const CallInst &I) {
32483249 SDValue result;
32493250 DebugLoc dl = getCurDebugLoc();
32503251
33463347 /// visitExp2 - Lower an exp2 intrinsic. Handles the special sequences for
33473348 /// limited-precision mode.
33483349 void
3349 SelectionDAGBuilder::visitExp2(CallInst &I) {
3350 SelectionDAGBuilder::visitExp2(const CallInst &I) {
33503351 SDValue result;
33513352 DebugLoc dl = getCurDebugLoc();
33523353
34603461 /// visitPow - Lower a pow intrinsic. Handles the special sequences for
34613462 /// limited-precision mode with x == 10.0f.
34623463 void
3463 SelectionDAGBuilder::visitPow(CallInst &I) {
3464 SelectionDAGBuilder::visitPow(const CallInst &I) {
34643465 SDValue result;
3465 Value *Val = I.getOperand(1);
3466 const Value *Val = I.getOperand(1);
34663467 DebugLoc dl = getCurDebugLoc();
34673468 bool IsExp10 = false;
34683469
36493650 /// we want to emit this as a call to a named external function, return the name
36503651 /// otherwise lower it and return null.
36513652 const char *
3652 SelectionDAGBuilder::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
3653 SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
36533654 DebugLoc dl = getCurDebugLoc();
36543655 SDValue Res;
36553656
37413742 if (OptLevel != CodeGenOpt::None)
37423743 // FIXME: Variable debug info is not supported here.
37433744 return 0;
3744 DbgDeclareInst &DI = cast(I);
3745 const DbgDeclareInst &DI = cast(I);
37453746 if (!DIDescriptor::ValidDebugInfo(DI.getVariable(), CodeGenOpt::None))
37463747 return 0;
37473748
37483749 MDNode *Variable = DI.getVariable();
3749 Value *Address = DI.getAddress();
3750 const Value *Address = DI.getAddress();
37503751 if (!Address)
37513752 return 0;
3752 if (BitCastInst *BCI = dyn_cast(Address))
3753 if (const BitCastInst *BCI = dyn_cast(Address))
37533754 Address = BCI->getOperand(0);
3754 AllocaInst *AI = dyn_cast(Address);
3755 const AllocaInst *AI = dyn_cast(Address);
37553756 // Don't handle byval struct arguments or VLAs, for example.
37563757 if (!AI)
37573758 return 0;
37673768 return 0;
37683769 }
37693770 case Intrinsic::dbg_value: {
3770 DbgValueInst &DI = cast(I);
3771 const DbgValueInst &DI = cast(I);
37713772 if (!DIDescriptor::ValidDebugInfo(DI.getVariable(), CodeGenOpt::None))
37723773 return 0;
37733774
37743775 MDNode *Variable = DI.getVariable();
37753776 uint64_t Offset = DI.getOffset();
3776 Value *V = DI.getValue();
3777 const Value *V = DI.getValue();
37773778 if (!V)
37783779 return 0;
37793780
37993800 }
38003801
38013802 // Build a debug info table entry.
3802 if (BitCastInst *BCI = dyn_cast(V))
3803 if (const BitCastInst *BCI = dyn_cast(V))
38033804 V = BCI->getOperand(0);
3804 AllocaInst *AI = dyn_cast(V);
3805 const AllocaInst *AI = dyn_cast(V);
38053806 // Don't handle byval struct arguments or VLAs, for example.
38063807 if (!AI)
38073808 return 0;
39213922 case Intrinsic::convertuu: Code = ISD::CVT_UU; break;
39223923 }
39233924 EVT DestVT = TLI.getValueType(I.getType());
3924 Value *Op1 = I.getOperand(1);
3925 const Value *Op1 = I.getOperand(1);
39253926 Res = DAG.getConvertRndSat(DestVT, getCurDebugLoc(), getValue(Op1),
39263927 DAG.getValueType(DestVT),
39273928 DAG.getValueType(getValue(Op1).getValueType()),
40904091 }
40914092 case Intrinsic::gcroot:
40924093 if (GFI) {
4093 Value *Alloca = I.getOperand(1);
4094 Constant *TypeMap = cast(I.getOperand(2));
4094 const Value *Alloca = I.getOperand(1);
4095 const Constant *TypeMap = cast(I.getOperand(2));
40954096
40964097 FrameIndexSDNode *FI = cast(getValue(Alloca).getNode());
40974098 GFI->addStackRoot(FI->getIndex(), TypeMap);
41954196 ///
41964197 /// This function only tests target-independent requirements.
41974198 static bool
4198 isInTailCallPosition(CallSite CS, Attributes CalleeRetAttr,
4199 isInTailCallPosition(ImmutableCallSite CS, Attributes CalleeRetAttr,
41994200 const TargetLowering &TLI) {
42004201 const Instruction *I = CS.getInstruction();
42014202 const BasicBlock *ExitBB = I->getParent();
42744275 return true;
42754276 }
42764277
4277 void SelectionDAGBuilder::LowerCallTo(CallSite CS, SDValue Callee,
4278 void SelectionDAGBuilder::LowerCallTo(ImmutableCallSite CS, SDValue Callee,
42784279 bool isTailCall,
42794280 MachineBasicBlock *LandingPad) {
42804281 const PointerType *PT = cast(CS.getCalledValue()->getType());
43224323 RetTy = Type::getVoidTy(FTy->getContext());
43234324 }
43244325
4325 for (CallSite::arg_iterator i = CS.arg_begin(), e = CS.arg_end();
4326 for (ImmutableCallSite::arg_iterator i = CS.arg_begin(), e = CS.arg_end();
43264327 i != e; ++i) {
43274328 SDValue ArgNode = getValue(*i);
43284329 Entry.Node = ArgNode; Entry.Ty = (*i)->getType();
44534454
44544455 /// IsOnlyUsedInZeroEqualityComparison - Return true if it only matters that the
44554456 /// value is equal or not-equal to zero.
4456 static bool IsOnlyUsedInZeroEqualityComparison(Value *V) {
4457 for (Value::use_iterator UI = V->use_begin(), E = V->use_end();
4457 static bool IsOnlyUsedInZeroEqualityComparison(const Value *V) {
4458 for (Value::const_use_iterator UI = V->use_begin(), E = V->use_end();
44584459 UI != E; ++UI) {
4459 if (ICmpInst *IC = dyn_cast(*UI))
4460 if (const ICmpInst *IC = dyn_cast(*UI))
44604461 if (IC->isEquality())
4461 if (Constant *C = dyn_cast(IC->getOperand(1)))
4462 if (const Constant *C = dyn_cast(IC->getOperand(1)))
44624463 if (C->isNullValue())
44634464 continue;
44644465 // Unknown instruction.
44674468 return true;
44684469 }
44694470
4470 static SDValue getMemCmpLoad(Value *PtrVal, MVT LoadVT, const Type *LoadTy,
4471 static SDValue getMemCmpLoad(const Value *PtrVal, MVT LoadVT,
4472 const Type *LoadTy,
44714473 SelectionDAGBuilder &Builder) {
44724474
44734475 // Check to see if this load can be trivially constant folded, e.g. if the
44744476 // input is from a string literal.
4475 if (Constant *LoadInput = dyn_cast(PtrVal)) {
4477 if (const Constant *LoadInput = dyn_cast(PtrVal)) {
44764478 // Cast pointer to the type we really want to load.
4477 LoadInput = ConstantExpr::getBitCast(LoadInput,
4479 LoadInput = ConstantExpr::getBitCast(const_cast(LoadInput),
44784480 PointerType::getUnqual(LoadTy));
44794481
4480 if (Constant *LoadCst = ConstantFoldLoadFromConstPtr(LoadInput, Builder.TD))
4482 if (const Constant *LoadCst =
4483 ConstantFoldLoadFromConstPtr(const_cast(LoadInput),
4484 Builder.TD))
44814485 return Builder.getValue(LoadCst);
44824486 }
44834487
45104514 /// visitMemCmpCall - See if we can lower a call to memcmp in an optimized form.
45114515 /// If so, return true and lower it, otherwise return false and it will be
45124516 /// lowered like a normal call.
4513 bool SelectionDAGBuilder::visitMemCmpCall(CallInst &I) {
4517 bool SelectionDAGBuilder::visitMemCmpCall(const CallInst &I) {
45144518 // Verify that the prototype makes sense. int memcmp(void*,void*,size_t)
45154519 if (I.getNumOperands() != 4)
45164520 return false;
45174521
4518 Value *LHS = I.getOperand(1), *RHS = I.getOperand(2);
4522 const Value *LHS = I.getOperand(1), *RHS = I.getOperand(2);
45194523 if (!LHS->getType()->isPointerTy() || !RHS->getType()->isPointerTy() ||
45204524 !I.getOperand(3)->getType()->isIntegerTy() ||
45214525 !I.getType()->isIntegerTy())
45224526 return false;
45234527
4524 ConstantInt *Size = dyn_cast(I.getOperand(3));
4528 const ConstantInt *Size = dyn_cast(I.getOperand(3));
45254529
45264530 // memcmp(S1,S2,2) != 0 -> (*(short*)LHS != *(short*)RHS) != 0
45274531 // memcmp(S1,S2,4) != 0 -> (*(int*)LHS != *(int*)RHS) != 0
45874591 }
45884592
45894593
4590 void SelectionDAGBuilder::visitCall(CallInst &I) {
4594 void SelectionDAGBuilder::visitCall(const CallInst &I) {
45914595 const char *RenameFn = 0;
45924596 if (Function *F = I.getCalledFunction()) {
45934597 if (F->isDeclaration()) {
51595163
51605164 /// visitInlineAsm - Handle a call to an InlineAsm object.
51615165 ///
5162 void SelectionDAGBuilder::visitInlineAsm(CallSite CS) {
5163 InlineAsm *IA = cast(CS.getCalledValue());
5166 void SelectionDAGBuilder::visitInlineAsm(ImmutableCallSite CS) {
5167 const InlineAsm *IA = cast(CS.getCalledValue());
51645168
51655169 /// ConstraintOperands - Information about all of the constraints.
51665170 std::vector ConstraintOperands;
51965200 case InlineAsm::isOutput:
51975201 // Indirect outputs just consume an argument.
51985202 if (OpInfo.isIndirect) {
5199 OpInfo.CallOperandVal = CS.getArgument(ArgNo++);
5203 OpInfo.CallOperandVal = const_cast(CS.getArgument(ArgNo++));
52005204 break;
52015205 }
52025206
52135217 ++ResNo;
52145218 break;
52155219 case InlineAsm::isInput:
5216 OpInfo.CallOperandVal = CS.getArgument(ArgNo++);
5220 OpInfo.CallOperandVal = const_cast(CS.getArgument(ArgNo++));
52175221 break;
52185222 case InlineAsm::isClobber:
52195223 // Nothing to do.
52265230 // Strip bitcasts, if any. This mostly comes up for functions.
52275231 OpInfo.CallOperandVal = OpInfo.CallOperandVal->stripPointerCasts();
52285232
5229 if (BasicBlock *BB = dyn_cast(OpInfo.CallOperandVal)) {
5233 if (const BasicBlock *BB = dyn_cast(OpInfo.CallOperandVal)) {
52305234 OpInfo.CallOperand = DAG.getBasicBlock(FuncInfo.MBBMap[BB]);
52315235 } else {
52325236 OpInfo.CallOperand = getValue(OpInfo.CallOperandVal);
52795283
52805284 // If the operand is a float, integer, or vector constant, spill to a
52815285 // constant pool entry to get its address.
5282 Value *OpVal = OpInfo.CallOperandVal;
5286 const Value *OpVal = OpInfo.CallOperandVal;
52835287 if (isa(OpVal) || isa(OpVal) ||
52845288 isa(OpVal)) {
52855289 OpInfo.CallOperand = DAG.getConstantPool(cast(OpVal),
55715575 return;
55725576 }
55735577
5574 std::vectorValue*> > StoresToEmit;
5578 std::vectorconst Value *> > StoresToEmit;
55755579
55765580 // Process indirect outputs, first output all of the flagged copies out of
55775581 // physregs.
55785582 for (unsigned i = 0, e = IndirectStoresToEmit.size(); i != e; ++i) {
55795583 RegsForValue &OutRegs = IndirectStoresToEmit[i].first;
5580 Value *Ptr = IndirectStoresToEmit[i].second;
5584 const Value *Ptr = IndirectStoresToEmit[i].second;
55815585 SDValue OutVal = OutRegs.getCopyFromRegs(DAG, getCurDebugLoc(),
55825586 Chain, &Flag);
55835587 StoresToEmit.push_back(std::make_pair(OutVal, Ptr));
5584
55855588 }
55865589
55875590 // Emit the non-flagged stores from the physregs.
56025605 DAG.setRoot(Chain);
56035606 }
56045607
5605 void SelectionDAGBuilder::visitVAStart(CallInst &I) {
5608 void SelectionDAGBuilder::visitVAStart(const CallInst &I) {
56065609 DAG.setRoot(DAG.getNode(ISD::VASTART, getCurDebugLoc(),
56075610 MVT::Other, getRoot(),
56085611 getValue(I.getOperand(1)),
56095612 DAG.getSrcValue(I.getOperand(1))));
56105613 }
56115614
5612 void SelectionDAGBuilder::visitVAArg(VAArgInst &I) {
5615 void SelectionDAGBuilder::visitVAArg(const VAArgInst &I) {
56135616 SDValue V = DAG.getVAArg(TLI.getValueType(I.getType()), getCurDebugLoc(),
56145617 getRoot(), getValue(I.getOperand(0)),
56155618 DAG.getSrcValue(I.getOperand(0)));
56175620 DAG.setRoot(V.getValue(1));
56185621 }
56195622
5620 void SelectionDAGBuilder::visitVAEnd(CallInst &I) {
5623 void SelectionDAGBuilder::visitVAEnd(const CallInst &I) {
56215624 DAG.setRoot(DAG.getNode(ISD::VAEND, getCurDebugLoc(),
56225625 MVT::Other, getRoot(),
56235626 getValue(I.getOperand(1)),
56245627 DAG.getSrcValue(I.getOperand(1))));
56255628 }
56265629
5627 void SelectionDAGBuilder::visitVACopy(CallInst &I) {
5630 void SelectionDAGBuilder::visitVACopy(const CallInst &I) {
56285631 DAG.setRoot(DAG.getNode(ISD::VACOPY, getCurDebugLoc(),
56295632 MVT::Other, getRoot(),
56305633 getValue(I.getOperand(1)),
58065809 return SDValue();
58075810 }
58085811
5809 void SelectionDAGBuilder::CopyValueToVirtualRegister(Value *V, unsigned Reg) {
5812 void
5813 SelectionDAGBuilder::CopyValueToVirtualRegister(const Value *V, unsigned Reg) {
58105814 SDValue Op = getValue(V);
58115815 assert((Op.getOpcode() != ISD::CopyFromReg ||
58125816 cast(Op.getOperand(1))->getReg() != Reg) &&
58215825
58225826 #include "llvm/CodeGen/SelectionDAGISel.h"
58235827
5824 void SelectionDAGISel::LowerArguments(BasicBlock *LLVMBB) {
5828 void SelectionDAGISel::LowerArguments(const BasicBlock *LLVMBB) {
58255829 // If this is the entry block, emit arguments.
5826 Function &F = *LLVMBB->getParent();
5830 const Function &F = *LLVMBB->getParent();
58275831 SelectionDAG &DAG = SDB->DAG;
58285832 SDValue OldRoot = DAG.getRoot();
58295833 DebugLoc dl = SDB->getCurDebugLoc();
58555859
58565860 // Set up the incoming argument description vector.
58575861 unsigned Idx = 1;
5858 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end();
5862 for (Function::const_arg_iterator I = F.arg_begin(), E = F.arg_end();
58595863 I != E; ++I, ++Idx) {
58605864 SmallVector ValueVTs;
58615865 ComputeValueVTs(TLI, I->getType(), ValueVTs);
59575961 ++i;
59585962 }
59595963
5960 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E;
5964 for (Function::const_arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E;
59615965 ++I, ++Idx) {
59625966 SmallVector ArgValues;
59635967 SmallVector ValueVTs;
60116015 /// the end.
60126016 ///
60136017 void
6014 SelectionDAGISel::HandlePHINodesInSuccessorBlocks(BasicBlock *LLVMBB) {
6015 TerminatorInst *TI = LLVMBB->getTerminator();
6018 SelectionDAGISel::HandlePHINodesInSuccessorBlocks(const BasicBlock *LLVMBB) {
6019 const TerminatorInst *TI = LLVMBB->getTerminator();
60166020
60176021 SmallPtrSet SuccsHandled;
60186022
60196023 // Check successor nodes' PHI nodes that expect a constant to be available
60206024 // from this block.
60216025 for (unsigned succ = 0, e = TI->getNumSuccessors(); succ != e; ++succ) {
6022 BasicBlock *SuccBB = TI->getSuccessor(succ);
6026 const BasicBlock *SuccBB = TI->getSuccessor(succ);
60236027 if (!isa(SuccBB->begin())) continue;
60246028 MachineBasicBlock *SuccMBB = FuncInfo->MBBMap[SuccBB];
60256029
60286032 if (!SuccsHandled.insert(SuccMBB)) continue;
60296033
60306034 MachineBasicBlock::iterator MBBI = SuccMBB->begin();
6031 PHINode *PN;
60326035
60336036 // At this point we know that there is a 1-1 correspondence between LLVM PHI
60346037 // nodes and Machine PHI nodes, but the incoming operands have not been
60356038 // emitted yet.
6036 for (BasicBlock::iterator I = SuccBB->begin();
6037 (PN = dyn_cast(I)); ++I) {
6039 for (BasicBlock::const_iterator I = SuccBB->begin();
6040 const PHINode *PN = dyn_cast(I); ++I) {
60386041 // Ignore dead phi's.
60396042 if (PN->use_empty()) continue;
60406043
60416044 unsigned Reg;
6042 Value *PHIOp = PN->getIncomingValueForBlock(LLVMBB);
6043
6044 if (Constant *C = dyn_cast(PHIOp)) {
6045 const Value *PHIOp = PN->getIncomingValueForBlock(LLVMBB);
6046
6047 if (const Constant *C = dyn_cast(PHIOp)) {
60456048 unsigned &RegOut = SDB->ConstantsOut[C];
60466049 if (RegOut == 0) {
60476050 RegOut = FuncInfo->CreateRegForValue(C);
60806083 /// creating SelectionDAG nodes.
60816084 ///
60826085 bool
6083 SelectionDAGISel::HandlePHINodesInSuccessorBlocksFast(BasicBlock *LLVMBB,
6086 SelectionDAGISel::HandlePHINodesInSuccessorBlocksFast(const BasicBlock *LLVMBB,
60846087 FastISel *F) {
6085 TerminatorInst *TI = LLVMBB->getTerminator();
6088 const TerminatorInst *TI = LLVMBB->getTerminator();
60866089
60876090 SmallPtrSet SuccsHandled;
60886091 unsigned OrigNumPHINodesToUpdate = SDB->PHINodesToUpdate.size();
60906093 // Check successor nodes' PHI nodes that expect a constant to be available
60916094 // from this block.
60926095 for (unsigned succ = 0, e = TI->getNumSuccessors(); succ != e; ++succ) {
6093 BasicBlock *SuccBB = TI->getSuccessor(succ);
6096 const BasicBlock *SuccBB = TI->getSuccessor(succ);
60946097 if (!isa(SuccBB->begin())) continue;
60956098 MachineBasicBlock *SuccMBB = FuncInfo->MBBMap[SuccBB];
60966099
60996102 if (!SuccsHandled.insert(SuccMBB)) continue;
61006103
61016104 MachineBasicBlock::iterator MBBI = SuccMBB->begin();
6102 PHINode *PN;
61036105
61046106 // At this point we know that there is a 1-1 correspondence between LLVM PHI
61056107 // nodes and Machine PHI nodes, but the incoming operands have not been
61066108 // emitted yet.
6107 for (BasicBlock::iterator I = SuccBB->begin();
6108 (PN = dyn_cast(I)); ++I) {
6109 for (BasicBlock::const_iterator I = SuccBB->begin();
6110 const PHINode *PN = dyn_cast(I); ++I) {
61096111 // Ignore dead phi's.
61106112 if (PN->use_empty()) continue;
61116113
61266128 }
61276129 }
61286130
6129 Value *PHIOp = PN->getIncomingValueForBlock(LLVMBB);
6131 const Value *PHIOp = PN->getIncomingValueForBlock(LLVMBB);
61306132
61316133 unsigned Reg = F->getRegForValue(PHIOp);
61326134 if (Reg == 0) {
141141 /// CaseRec - A struct with ctor used in lowering switches to a binary tree
142142 /// of conditional branches.
143143 struct CaseRec {
144 CaseRec(MachineBasicBlock *bb, Constant *lt, Constant *ge, CaseRange r) :
144 CaseRec(MachineBasicBlock *bb, const Constant *lt, const Constant *ge,
145 CaseRange r) :
145146 CaseBB(bb), LT(lt), GE(ge), Range(r) {}
146147
147148 /// CaseBB - The MBB in which to emit the compare and branch
148149 MachineBasicBlock *CaseBB;
149150 /// LT, GE - If nonzero, we know the current case value must be less-than or
150151 /// greater-than-or-equal-to these Constants.
151 Constant *LT;
152 Constant *GE;
152 const Constant *LT;
153 const Constant *GE;
153154 /// Range - A pair of iterators representing the range of case values to be
154155 /// processed at this point in the binary search tree.
155156 CaseRange Range;
180181 /// SelectionDAGBuilder and SDISel for the code generation of additional basic
181182 /// blocks needed by multi-case switch statements.
182183 struct CaseBlock {
183 CaseBlock(ISD::CondCode cc, Value *cmplhs, Value *cmprhs, Value *cmpmiddle,
184 CaseBlock(ISD::CondCode cc, const Value *cmplhs, const Value *cmprhs,
185 const Value *cmpmiddle,
184186 MachineBasicBlock *truebb, MachineBasicBlock *falsebb,
185187 MachineBasicBlock *me)
186188 : CC(cc), CmpLHS(cmplhs), CmpMHS(cmpmiddle), CmpRHS(cmprhs),
190192 // CmpLHS/CmpRHS/CmpMHS - The LHS/MHS/RHS of the comparison to emit.
191193 // Emit by default LHS op RHS. MHS is used for range comparisons:
192194 // If MHS is not null: (LHS <= MHS) and (MHS <= RHS).
193 Value *CmpLHS, *CmpMHS, *CmpRHS;
195 const Value *CmpLHS, *CmpMHS, *CmpRHS;
194196 // TrueBB/FalseBB - the block to branch to if the setcc is true/false.
195197 MachineBasicBlock *TrueBB, *FalseBB;
196198 // ThisBB - the block into which to emit the code for the setcc and branches
212214 MachineBasicBlock *Default;
213215 };
214216 struct JumpTableHeader {
215 JumpTableHeader(APInt F, APInt L, Value *SV, MachineBasicBlock *H,
217 JumpTableHeader(APInt F, APInt L, const Value *SV, MachineBasicBlock *H,
216218 bool E = false):
217219 First(F), Last(L), SValue(SV), HeaderBB(H), Emitted(E) {}
218220 APInt First;
219221 APInt Last;
220 Value *SValue;
222 const Value *SValue;
221223 MachineBasicBlock *HeaderBB;
222224 bool Emitted;
223225 };
234236 typedef SmallVector BitTestInfo;
235237
236238 struct BitTestBlock {
237 BitTestBlock(APInt F, APInt R, Value* SV,
239 BitTestBlock(APInt F, APInt R, const Value* SV,
238240 unsigned Rg, bool E,
239241 MachineBasicBlock* P, MachineBasicBlock* D,
240242 const BitTestInfo& C):
242244 Parent(P), Default(D), Cases(C) { }
243245 APInt First;
244246 APInt Range;
245 Value *SValue;
247 const Value *SValue;
246248 unsigned Reg;
247249 bool Emitted;
248250 MachineBasicBlock *Parent;
279281
280282 // Emit PHI-node-operand constants only once even if used by multiple
281283 // PHI nodes.
282 DenseMap<Constant*, unsigned> ConstantsOut;
284 DenseMap<const Constant *, unsigned> ConstantsOut;
283285
284286 /// FuncInfo - Information about the function as a whole.
285287 ///
335337
336338 unsigned getSDNodeOrder() const { return SDNodeOrder; }
337339
338 void CopyValueToVirtualRegister(Value *V, unsigned Reg);
340 void CopyValueToVirtualRegister(const Value *V, unsigned Reg);
339341
340342 /// AssignOrderingToNode - Assign an ordering to the node. The order is gotten
341343 /// from how the code appeared in the source. The ordering is used by the
342344 /// scheduler to effectively turn off scheduling.
343345 void AssignOrderingToNode(const SDNode *Node);
344346
345 void visit(Instruction &I);
346
347 void visit(unsigned Opcode, User &I);
347 void visit(const Instruction &I);
348
349 void visit(unsigned Opcode, const User &I);
348350
349351 void setCurrentBasicBlock(MachineBasicBlock *MBB) { CurMBB = MBB; }
350352
360362 std::set &OutputRegs,
361363 std::set &InputRegs);
362364
363 void FindMergedConditions(Value *Cond, MachineBasicBlock *TBB,
365 void FindMergedConditions(const Value *Cond, MachineBasicBlock *TBB,
364366 MachineBasicBlock *FBB, MachineBasicBlock *CurBB,
365367 unsigned Opc);
366 void EmitBranchForMergedCondition(Value *Cond, MachineBasicBlock *TBB,
368 void EmitBranchForMergedCondition(const Value *Cond, MachineBasicBlock *TBB,
367369 MachineBasicBlock *FBB,
368370 MachineBasicBlock *CurBB);
369371 bool ShouldEmitAsBranches(const std::vector &Cases);
370 bool isExportableFromCurrentBlock(Value *V, const BasicBlock *FromBB);
371 void CopyToExportRegsIfNeeded(Value *V);
372 void ExportFromCurrentBlock(Value *V);
373 void LowerCallTo(CallSite CS, SDValue Callee, bool IsTailCall,
372 bool isExportableFromCurrentBlock(const Value *V, const BasicBlock *FromBB);
373 void CopyToExportRegsIfNeeded(const Value *V);
374 void ExportFromCurrentBlock(const Value *V);
375 void LowerCallTo(ImmutableCallSite CS, SDValue Callee, bool IsTailCall,
374376 MachineBasicBlock *LandingPad = NULL);
375377
376378 private:
377379 // Terminator instructions.
378 void visitRet(ReturnInst &I);
379 void visitBr(BranchInst &I);
380 void visitSwitch(SwitchInst &I);
381 void visitIndirectBr(IndirectBrInst &I);
382 void visitUnreachable(UnreachableInst &I) { /* noop */ }
380 void visitRet(const ReturnInst &I);
381 void visitBr(const BranchInst &I);
382 void visitSwitch(const SwitchInst &I);
383 void visitIndirectBr(const IndirectBrInst &I);
384 void visitUnreachable(const UnreachableInst &I) { /* noop */ }
383385
384386 // Helpers for visitSwitch
385387 bool handleSmallSwitchRange(CaseRec& CR,
386388 CaseRecVector& WorkList,
387 Value* SV,
389 const Value* SV,
388390 MachineBasicBlock* Default);
389391 bool handleJTSwitchCase(CaseRec& CR,
390392 CaseRecVector& WorkList,
391 Value* SV,
393 const Value* SV,
392394 MachineBasicBlock* Default);
393395 bool handleBTSplitSwitchCase(CaseRec& CR,
394396 CaseRecVector& WorkList,
395 Value* SV,
397 const Value* SV,
396398 MachineBasicBlock* Default);
397399 bool handleBitTestsSwitchCase(CaseRec& CR,
398400 CaseRecVector& WorkList,
399 Value* SV,
401 const Value* SV,
400402 MachineBasicBlock* Default);
401403 public:
402404 void visitSwitchCase(CaseBlock &CB);
409411
410412 private:
411413 // These all get lowered before this pass.
412 void visitInvoke(InvokeInst &I);
413 void visitUnwind(UnwindInst &I);
414
415 void visitBinary(User &I, unsigned OpCode);
416 void visitShift(User &I, unsigned Opcode);
417 void visitAdd(User &I) { visitBinary(I, ISD::ADD); }
418 void visitFAdd(User &I) { visitBinary(I, ISD::FADD); }
419 void visitSub(User &I) { visitBinary(I, ISD::SUB); }
420 void visitFSub(User &I);
421 void visitMul(User &I) { visitBinary(I, ISD::MUL); }
422 void visitFMul(User &I) { visitBinary(I, ISD::FMUL); }
423 void visitURem(User &I) { visitBinary(I, ISD::UREM); }
424 void visitSRem(User &I) { visitBinary(I, ISD::SREM); }
425 void visitFRem(User &I) { visitBinary(I, ISD::FREM); }
426 void visitUDiv(User &I) { visitBinary(I, ISD::UDIV); }
427 void visitSDiv(User &I) { visitBinary(I, ISD::SDIV); }
428 void visitFDiv(User &I) { visitBinary(I, ISD::FDIV); }
429 void visitAnd (User &I) { visitBinary(I, ISD::AND); }
430 void visitOr (User &I) { visitBinary(I, ISD::OR); }
431 void visitXor (User &I) { visitBinary(I, ISD::XOR); }
432 void visitShl (User &I) { visitShift(I, ISD::SHL); }
433 void visitLShr(User &I) { visitShift(I, ISD::SRL); }
434 void visitAShr(User &I) { visitShift(I, ISD::SRA); }
435 void visitICmp(User &I);
436 void visitFCmp(User &I);
414 void visitInvoke(const InvokeInst &I);
415 void visitUnwind(const UnwindInst &I);
416
417 void visitBinary(const User &I, unsigned OpCode);
418 void visitShift(const User &I, unsigned Opcode);
419 void visitAdd(const User &I) { visitBinary(I, ISD::ADD); }
420 void visitFAdd(const User &I) { visitBinary(I, ISD::FADD); }
421 void visitSub(const User &I) { visitBinary(I, ISD::SUB); }
422 void visitFSub(const User &I);
423 void visitMul(const User &I) { visitBinary(I, ISD::MUL); }
424 void visitFMul(const User &I) { visitBinary(I, ISD::FMUL); }
425 void visitURem(const User &I) { visitBinary(I, ISD::UREM); }
426 void visitSRem(const User &I) { visitBinary(I, ISD::SREM); }
427 void visitFRem(const User &I) { visitBinary(I, ISD::FREM); }
428 void visitUDiv(const User &I) { visitBinary(I, ISD::UDIV); }
429 void visitSDiv(const User &I) { visitBinary(I, ISD::SDIV); }
430 void visitFDiv(const User &I) { visitBinary(I, ISD::FDIV); }
431 void visitAnd (const User &I) { visitBinary(I, ISD::AND); }
432 void visitOr (const User &I) { visitBinary(I, ISD::OR); }
433 void visitXor (const User &I) { visitBinary(I, ISD::XOR); }
434 void visitShl (const User &I) { visitShift(I, ISD::SHL); }
435 void visitLShr(const User &I) { visitShift(I, ISD::SRL); }
436 void visitAShr(const User &I) { visitShift(I, ISD::SRA); }
437 void visitICmp(const User &I);
438 void visitFCmp(const User &I);
437439 // Visit the conversion instructions
438 void visitTrunc(User &I);
439 void visitZExt(User &I);
440 void visitSExt(User &I);
441 void visitFPTrunc(User &I);
442 void visitFPExt(User &I);
443 void visitFPToUI(User &I);
444 void visitFPToSI(User &I);
445 void visitUIToFP(User &I);
446 void visitSIToFP(User &I);
447 void visitPtrToInt(User &I);
448 void visitIntToPtr(User &I);
449 void visitBitCast(User &I);
450
451 void visitExtractElement(User &I);
452 void visitInsertElement(User &I);
453 void visitShuffleVector(User &I);
454
455 void visitExtractValue(ExtractValueInst &I);
456 void visitInsertValue(InsertValueInst &I);
457
458 void visitGetElementPtr(User &I);
459 void visitSelect(User &I);
460
461 void visitAlloca(AllocaInst &I);
462 void visitLoad(LoadInst &I);
463 void visitStore(StoreInst &I);
464 void visitPHI(PHINode &I) { } // PHI nodes are handled specially.
465 void visitCall(CallInst &I);
466 bool visitMemCmpCall(CallInst &I);
440 void visitTrunc(const User &I);
441 void visitZExt(const User &I);
442 void visitSExt(const User &I);
443 void visitFPTrunc(const User &I);
444 void visitFPExt(const User &I);
445 void visitFPToUI(const User &I);
446 void visitFPToSI(const User &I);
447 void visitUIToFP(const User &I);
448 void visitSIToFP(const User &I);
449 void visitPtrToInt(const User &I);
450 void visitIntToPtr(const User &I);
451 void visitBitCast(const User &I);
452
453 void visitExtractElement(const User &I);
454 void visitInsertElement(const User &I);
455 void visitShuffleVector(const User &I);
456
457 void visitExtractValue(const ExtractValueInst &I);
458 void visitInsertValue(const InsertValueInst &I);
459
460 void visitGetElementPtr(const User &I);
461 void visitSelect(const User &I);
462
463 void visitAlloca(const AllocaInst &I);
464 void visitLoad(const LoadInst &I);
465 void visitStore(const StoreInst &I);
466 void visitPHI(const PHINode &I) { } // PHI nodes are handled specially.
467 void visitCall(const CallInst &I);
468 bool visitMemCmpCall(const CallInst &I);
467469
468 void visitInlineAsm(CallSite CS);
469 const char *visitIntrinsicCall(CallInst &I, unsigned Intrinsic);
470 void visitTargetIntrinsic(CallInst &I, unsigned Intrinsic);
471
472 void visitPow(CallInst &I);
473 void visitExp2(CallInst &I);
474 void visitExp(CallInst &I);
475 void visitLog(CallInst &I);
476 void visitLog2(CallInst &I);
477 void visitLog10(CallInst &I);
478
479 void visitVAStart(CallInst &I);
480 void visitVAArg(VAArgInst &I);
481 void visitVAEnd(CallInst &I);
482 void visitVACopy(CallInst &I);
483
484 void visitUserOp1(Instruction &I) {
470 void visitInlineAsm(ImmutableCallSite CS);
471 const char *visitIntrinsicCall(const CallInst &I, unsigned Intrinsic);
472 void visitTargetIntrinsic(const CallInst &I, unsigned Intrinsic);
473
474 void visitPow(const CallInst &I);
475 void visitExp2(const CallInst &I);
476 void visitExp(const CallInst &I);
477 void visitLog(const CallInst &I);
478 void visitLog2(const CallInst &I);
479 void visitLog10(const CallInst &I);
480
481 void visitVAStart(const CallInst &I);
482 void visitVAArg(const VAArgInst &I);
483 void visitVAEnd(const CallInst &I);
484 void visitVACopy(const CallInst &I);
485
486 void visitUserOp1(const Instruction &I) {
485487 llvm_unreachable("UserOp1 should not exist at instruction selection time!");
486488 }
487 void visitUserOp2(Instruction &I) {
489 void visitUserOp2(const Instruction &I) {
488490 llvm_unreachable("UserOp2 should not exist at instruction selection time!");
489491 }
490492
491 const char *implVisitBinaryAtomic(CallInst& I, ISD::NodeType Op);
492 const char *implVisitAluOverflow(CallInst &I, ISD::NodeType Op);
493 const char *implVisitBinaryAtomic(const CallInst& I, ISD::NodeType Op);
494 const char *implVisitAluOverflow(const CallInst &I, ISD::NodeType Op);
493495 };
494496
495497 } // end namespace llvm
225225
226226 /// SetDebugLoc - Update MF's and SDB's DebugLocs if debug information is
227227 /// attached with this instruction.
228 static void SetDebugLoc(Instruction *I, SelectionDAGBuilder *SDB,
228 static void SetDebugLoc(const Instruction *I, SelectionDAGBuilder *SDB,
229229 FastISel *FastIS, MachineFunction *MF) {
230230 DebugLoc DL = I->getDebugLoc();
231231 if (DL.isUnknown()) return;
248248 FastIS->setCurDebugLoc(DebugLoc());
249249 }
250250
251 void SelectionDAGISel::SelectBasicBlock(BasicBlock *LLVMBB,
252 BasicBlock::iterator Begin,
253 BasicBlock::iterator End,
251 void SelectionDAGISel::SelectBasicBlock(const BasicBlock *LLVMBB,
252 BasicBlock::const_iterator Begin,
253 BasicBlock::const_iterator End,
254254 bool &HadTailCall) {
255255 SDB->setCurrentBasicBlock(BB);
256256
257257 // Lower all of the non-terminator instructions. If a call is emitted
258258 // as a tail call, cease emitting nodes for this block.
259 for (BasicBlock::iterator I = Begin; I != End && !SDB->HasTailCall; ++I) {
259 for (BasicBlock::const_iterator I = Begin;
260 I != End && !SDB->HasTailCall; ++I) {
260261 SetDebugLoc(I, SDB, 0, MF);
261262
262263 // Visit the instruction. Terminators are handled below.
269270 if (!SDB->HasTailCall) {
270271 // Ensure that all instructions which are used outside of their defining
271272 // blocks are available as virtual registers. Invoke is handled elsewhere.
272 for (BasicBlock::iterator I = Begin; I != End; ++I)
273 for (BasicBlock::const_iterator I = Begin; I != End; ++I)
273274 if (!isa(I) && !isa(I))
274275 SDB->CopyToExportRegsIfNeeded(I);
275276
743744 }
744745 }
745746
746 void SelectionDAGISel::SelectAllBasicBlocks(Function &Fn) {
747 void SelectionDAGISel::SelectAllBasicBlocks(const Function &Fn) {
747748 // Initialize the Fast-ISel state, if needed.
748749 FastISel *FastIS = 0;
749750 if (EnableFastISel)
755756 );
756757
757758 // Iterate over all basic blocks in the function.
758 for (Function::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) {
759 BasicBlock *LLVMBB = &*I;
759 for (Function::const_iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) {
760 const BasicBlock *LLVMBB = &*I;
760761 BB = FuncInfo->MBBMap[LLVMBB];
761762
762 BasicBlock::iterator const Begin = LLVMBB->begin();
763 BasicBlock::iterator const End = LLVMBB->end();
764 BasicBlock::iterator BI = Begin;
763 BasicBlock::const_iterator const Begin = LLVMBB->begin();
764 BasicBlock::const_iterator const End = LLVMBB->end();
765 BasicBlock::const_iterator BI = Begin;
765766
766767 // Lower any arguments needed in this block if this is the entry block.
767768 bool SuppressFastISel = false;
772773 // fast-isel in the entry block.
773774 if (FastIS) {
774775 unsigned j = 1;
775 for (Function::arg_iterator I = Fn.arg_begin(), E = Fn.arg_end();
776 for (Function::const_arg_iterator I = Fn.arg_begin(), E = Fn.arg_end();
776777 I != E; ++I, ++j)
777778 if (Fn.paramHasAttr(j, Attribute::ByVal)) {
778779 if (EnableFastISelVerbose || EnableFastISelAbort)
22442244
22452245 /// isGAPlusOffset - Returns true (and the GlobalValue and the offset) if the
22462246 /// node is a GlobalAddress + offset.
2247 bool TargetLowering::isGAPlusOffset(SDNode *N, GlobalValue* &GA,
2247 bool TargetLowering::isGAPlusOffset(SDNode *N, const GlobalValue* &GA,
22482248 int64_t &Offset) const {
22492249 if (isa(N)) {
22502250 GlobalAddressSDNode *GASD = cast(N);
5151
5252 unsigned char* Result = 0;
5353
54 const std::vector<Function *> Personalities = MMI->getPersonalities();
54 const std::vector<const Function *> Personalities = MMI->getPersonalities();
5555 EHFramePtr = EmitCommonEHFrame(Personalities[MMI->getPersonalityIndex()]);
5656
5757 Result = EmitEHFrame(Personalities[MMI->getPersonalityIndex()], EHFramePtr,
200200 // Map all labels and get rid of any dead landing pads.
201201 MMI->TidyLandingPads();
202202
203 const std::vector<GlobalVariable *> &TypeInfos = MMI->getTypeInfos();
203 const std::vector<const GlobalVariable *> &TypeInfos = MMI->getTypeInfos();
204204 const std::vector &FilterIds = MMI->getFilterIds();
205205 const std::vector &PadInfos = MMI->getLandingPads();
206206 if (PadInfos.empty()) return 0;
449449
450450 // Emit the type ids.
451451 for (unsigned M = TypeInfos.size(); M; --M) {
452 GlobalVariable *GV = TypeInfos[M - 1];
452 const GlobalVariable *GV = TypeInfos[M - 1];
453453
454454 if (GV) {
455455 if (TD->getPointerSize() == sizeof(int32_t))
608608
609609 FinalSize += GetExceptionTableSizeInBytes(&F);
610610
611 const std::vector<Function *> Personalities = MMI->getPersonalities();
611 const std::vector<const Function *> Personalities = MMI->getPersonalities();
612612 FinalSize +=
613613 GetCommonEHFrameSizeInBytes(Personalities[MMI->getPersonalityIndex()]);
614614
781781 // Map all labels and get rid of any dead landing pads.
782782 MMI->TidyLandingPads();
783783
784 const std::vector<GlobalVariable *> &TypeInfos = MMI->getTypeInfos();
784 const std::vector<const GlobalVariable *> &TypeInfos = MMI->getTypeInfos();
785785 const std::vector &FilterIds = MMI->getFilterIds();
786786 const std::vector &PadInfos = MMI->getLandingPads();
787787 if (PadInfos.empty()) return 0;
994994 for (unsigned CurOp = 0; CurOp < NumOps; CurOp++) {
995995 const MachineOperand &MO = MI.getOperand(CurOp);
996996 if (MO.isGlobal()) {
997 GlobalValue* V = MO.getGlobal();
997 const GlobalValue* V = MO.getGlobal();
998998 const GlobalVariable *GV = dyn_cast(V);
999999 if (!GV)
10001000 continue;
10011001 // If seen in previous function, it will have an entry here.
1002 if (TheJIT->getPointerToGlobalIfAvailable(GV))
1002 if (TheJIT->getPointerToGlobalIfAvailable(
1003 const_cast(GV)))
10031004 continue;
10041005 // If seen earlier in this function, it will have an entry here.
10051006 // FIXME: it should be possible to combine these tables, by
10491049 unsigned PredReg) const {
10501050 MachineFunction &MF = *MBB.getParent();
10511051 MachineConstantPool *ConstantPool = MF.getConstantPool();
1052 Constant *C =
1052 const Constant *C =
10531053 ConstantInt::get(Type::getInt32Ty(MF.getFunction()->getContext()), Val);
10541054 unsigned Idx = ConstantPool->getConstantPoolIndex(C, 4);
10551055
149149
150150 /// Routines that handle operands which add machine relocations which are
151151 /// fixed up by the relocation stage.
152 void emitGlobalAddress(GlobalValue *GV, unsigned Reloc,
152 void emitGlobalAddress(const GlobalValue *GV, unsigned Reloc,
153153 bool MayNeedFarStub, bool Indirect,
154154 intptr_t ACPV = 0);
155155 void emitExternalSymbolAddress(const char *ES, unsigned Reloc);
248248
249249 /// emitGlobalAddress - Emit the specified address to the code stream.
250250 ///
251 void ARMCodeEmitter::emitGlobalAddress(GlobalValue *GV, unsigned Reloc,
251 void ARMCodeEmitter::emitGlobalAddress(const GlobalValue *GV, unsigned Reloc,
252252 bool MayNeedFarStub, bool Indirect,
253253 intptr_t ACPV) {
254254 MachineRelocation MR = Indirect
255255 ? MachineRelocation::getIndirectSymbol(MCE.getCurrentPCOffset(), Reloc,
256 GV, ACPV, MayNeedFarStub)
256 const_cast(GV),
257 ACPV, MayNeedFarStub)
257258 : MachineRelocation::getGV(MCE.getCurrentPCOffset(), Reloc,
258 GV, ACPV, MayNeedFarStub);
259 const_cast(GV), ACPV,
260 MayNeedFarStub);
259261 MCE.addRelocation(MR);
260262 }
261263
390392 << (void*)MCE.getCurrentPCValue() << " " << *ACPV << '\n');
391393
392394 assert(ACPV->isGlobalValue() && "unsupported constant pool value");
393 GlobalValue *GV = ACPV->getGV();
395 const GlobalValue *GV = ACPV->getGV();
394396 if (GV) {
395397 Reloc::Model RelocM = TM.getRelocationModel();
396398 emitGlobalAddress(GV, ARM::reloc_arm_machine_cp_entry,
402404 }
403405 emitWordLE(0);
404406 } else {
405 Constant *CV = MCPE.Val.ConstVal;
407 const Constant *CV = MCPE.Val.ConstVal;
406408
407409 DEBUG({
408410 errs() << " ** Constant pool #" << CPI << " @ "
414416 errs() << '\n';
415417 });
416418
417 if (GlobalValue *GV = dyn_cast(CV)) {
419 if (const GlobalValue *GV = dyn_cast(CV)) {
418420 emitGlobalAddress(GV, ARM::reloc_arm_absolute, isa(GV), false);
419421 emitWordLE(0);
420422 } else if (const ConstantInt *CI = dyn_cast(CV)) {
2020 #include
2121 using namespace llvm;
2222
23 ARMConstantPoolValue::ARMConstantPoolValue(Constant *cval, unsigned id,
23 ARMConstantPoolValue::ARMConstantPoolValue(const Constant *cval, unsigned id,
2424 ARMCP::ARMCPKind K,
2525 unsigned char PCAdj,
2626 const char *Modif,
3838 CVal(NULL), S(strdup(s)), LabelId(id), Kind(ARMCP::CPExtSymbol),
3939 PCAdjust(PCAdj), Modifier(Modif), AddCurrentAddress(AddCA) {}
4040
41 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, const char *Modif)
41 ARMConstantPoolValue::ARMConstantPoolValue(const GlobalValue *gv,
42 const char *Modif)
4243 : MachineConstantPoolValue((const Type*)Type::getInt32Ty(gv->getContext())),
4344 CVal(gv), S(NULL), LabelId(0), Kind(ARMCP::CPValue), PCAdjust(0),
4445 Modifier(Modif) {}
4546
46 GlobalValue *ARMConstantPoolValue::getGV() const {
47 const GlobalValue *ARMConstantPoolValue::getGV() const {
4748 return dyn_cast_or_null(CVal);
4849 }
4950
50 BlockAddress *ARMConstantPoolValue::getBlockAddress() const {
51 const BlockAddress *ARMConstantPoolValue::getBlockAddress() const {
5152 return dyn_cast_or_null(CVal);
5253 }
5354
3535 /// represent PC-relative displacement between the address of the load
3636 /// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
3737 class ARMConstantPoolValue : public MachineConstantPoolValue {
38 Constant *CVal; // Constant being loaded.
38 const Constant *CVal; // Constant being loaded.
3939 const char *S; // ExtSymbol being loaded.
4040 unsigned LabelId; // Label id of the load.
4141 ARMCP::ARMCPKind Kind; // Kind of constant.
4545 bool AddCurrentAddress;
4646
4747 public:
48 ARMConstantPoolValue(Constant *cval, unsigned id,
48 ARMConstantPoolValue(const Constant *cval, unsigned id,
4949 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
5050 unsigned char PCAdj = 0, const char *Modifier = NULL,
5151 bool AddCurrentAddress = false);
5252 ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
5353 unsigned char PCAdj = 0, const char *Modifier = NULL,
5454 bool AddCurrentAddress = false);
55 ARMConstantPoolValue(GlobalValue *GV, const char *Modifier);
55 ARMConstantPoolValue(const GlobalValue *GV, const char *Modifier);
5656 ARMConstantPoolValue();
5757 ~ARMConstantPoolValue();
5858
59 GlobalValue *getGV() const;
59 const GlobalValue *getGV() const;
6060 const char *getSymbol() const { return S; }
61 BlockAddress *getBlockAddress() const;
61 const BlockAddress *getBlockAddress() const;
6262 const char *getModifier() const { return Modifier; }
6363 bool hasModifier() const { return Modifier != NULL; }
6464 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
9090 LO16 = LO16.addImm(Lo16);
9191 HI16 = HI16.addImm(Hi16);
9292 } else {
93 GlobalValue *GV = MO.getGlobal();
93 const GlobalValue *GV = MO.getGlobal();
9494 unsigned TF = MO.getTargetFlags();
9595 LO16 = LO16.addGlobalAddress(GV, MO.getOffset(), TF | ARMII::MO_LO16);
9696 HI16 = HI16.addGlobalAddress(GV, MO.getOffset(), TF | ARMII::MO_HI16);
10691069 false, false, 0);
10701070 }
10711071 } else if (GlobalAddressSDNode *G = dyn_cast(Callee)) {
1072 GlobalValue *GV = G->getGlobal();
1072 const GlobalValue *GV = G->getGlobal();
10731073 isDirect = true;
10741074 bool isExt = GV->isDeclaration() || GV->isWeakForLinker();
10751075 bool isStub = (isExt && Subtarget->isTargetDarwin()) &&
12811281 unsigned ARMPCLabelIndex = 0;
12821282 DebugLoc DL = Op.getDebugLoc();
12831283 EVT PtrVT = getPointerTy();
1284 BlockAddress *BA = cast(Op)->getBlockAddress();
1284 const BlockAddress *BA = cast(Op)->getBlockAddress();
12851285 Reloc::Model RelocM = getTargetMachine().getRelocationModel();
12861286 SDValue CPAddr;
12871287 if (RelocM == Reloc::Static) {
13471347 SDValue
13481348 ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA,
13491349 SelectionDAG &DAG) {
1350 GlobalValue *GV = GA->getGlobal();
1350 const GlobalValue *GV = GA->getGlobal();
13511351 DebugLoc dl = GA->getDebugLoc();
13521352 SDValue Offset;
13531353 SDValue Chain = DAG.getEntryNode();
14101410 SelectionDAG &DAG) {
14111411 EVT PtrVT = getPointerTy();
14121412 DebugLoc dl = Op.getDebugLoc();
1413 GlobalValue *GV = cast(Op)->getGlobal();
1413 const GlobalValue *GV = cast(Op)->getGlobal();
14141414 Reloc::Model RelocM = getTargetMachine().getRelocationModel();
14151415 if (RelocM == Reloc::PIC_) {
14161416 bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility();
14531453 unsigned ARMPCLabelIndex = 0;
14541454 EVT PtrVT = getPointerTy();
14551455 DebugLoc dl = Op.getDebugLoc();
1456 GlobalValue *GV = cast(Op)->getGlobal();
1456 const GlobalValue *GV = cast(Op)->getGlobal();
14571457 Reloc::Model RelocM = getTargetMachine().getRelocationModel();
14581458 SDValue CPAddr;
14591459 if (RelocM == Reloc::Static)
18491849 if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) {
18501850 SDValue WrapperOp = Op.getOperand(1).getOperand(0);
18511851 if (ConstantPoolSDNode *CP = dyn_cast(WrapperOp))
1852 if (ConstantFP *CFP = dyn_cast(CP->getConstVal()))
1852 if (const ConstantFP *CFP = dyn_cast(CP->getConstVal()))
18531853 return CFP->getValueAPF().isPosZero();
18541854 }
18551855 }
115115
116116 /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
117117 bool
118 ARMSubtarget::GVIsIndirectSymbol(GlobalValue *GV, Reloc::Model RelocM) const {
118 ARMSubtarget::GVIsIndirectSymbol(const GlobalValue *GV,
119 Reloc::Model RelocM) const {
119120 if (RelocM == Reloc::Static)
120121 return false;
121122
159159
160160 /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect
161161 /// symbol.
162 bool GVIsIndirectSymbol(GlobalValue *GV, Reloc::Model RelocM) const;
162 bool GVIsIndirectSymbol(const GlobalValue *GV, Reloc::Model RelocM) const;
163163 };
164164 } // End llvm namespace
165165
238238 } else if (ACPV->isBlockAddress()) {
239239 O << *GetBlockAddressSymbol(ACPV->getBlockAddress());
240240 } else if (ACPV->isGlobalValue()) {
241 GlobalValue *GV = ACPV->getGV();
241 const GlobalValue *GV = ACPV->getGV();
242242 bool isIndirect = Subtarget->isTargetDarwin() &&
243243 Subtarget->GVIsIndirectSymbol(GV, TM.getRelocationModel());
244244 if (!isIndirect)
351351 return;
352352 case MachineOperand::MO_GlobalAddress: {
353353 bool isCallOp = Modifier && !strcmp(Modifier, "call");
354 GlobalValue *GV = MO.getGlobal();
354 const GlobalValue *GV = MO.getGlobal();
355355
356356 if ((Modifier && strcmp(Modifier, "lo16") == 0) ||
357357 (TF & ARMII::MO_LO16))
5555 unsigned PredReg) const {
5656 MachineFunction &MF = *MBB.getParent();
5757 MachineConstantPool *ConstantPool = MF.getConstantPool();
58 Constant *C = ConstantInt::get(
58 const Constant *C = ConstantInt::get(
5959 Type::getInt32Ty(MBB.getParent()->getFunction()->getContext()), Val);
6060 unsigned Idx = ConstantPool->getConstantPoolIndex(C, 4);
6161
5151 unsigned PredReg) const {
5252 MachineFunction &MF = *MBB.getParent();
5353 MachineConstantPool *ConstantPool = MF.getConstantPool();
54 Constant *C = ConstantInt::get(
54 const Constant *C = ConstantInt::get(
5555 Type::getInt32Ty(MBB.getParent()->getFunction()->getContext()), Val);
5656 unsigned Idx = ConstantPool->getConstantPoolIndex(C, 4);
5757
191191 llvm_unreachable("unknown relocatable instruction");
192192 }
193193 if (MO.isGlobal())
194 MCE.addRelocation(MachineRelocation::getGV(MCE.getCurrentPCOffset(),
195 Reloc, MO.getGlobal(), Offset,
196 isa(MO.getGlobal()),
197 useGOT));
194 MCE.addRelocation(MachineRelocation::getGV(
195 MCE.getCurrentPCOffset(),
196 Reloc,
197 const_cast(MO.getGlobal()),
198 Offset,
199 isa(MO.getGlobal()),
200 useGOT));
198201 else if (MO.isSymbol())
199202 MCE.addRelocation(MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
200203 Reloc, MO.getSymbolName(),
623623 }
624624 case ISD::ConstantPool: {
625625 ConstantPoolSDNode *CP = cast(Op);
626 Constant *C = CP->getConstVal();
626 const Constant *C = CP->getConstVal();
627627 SDValue CPI = DAG.getTargetConstantPool(C, MVT::i64, CP->getAlignment());
628628 // FIXME there isn't really any debug info here
629629
636636 llvm_unreachable("TLS not implemented for Alpha.");
637637 case ISD::GlobalAddress: {
638638 GlobalAddressSDNode *GSDN = cast(Op);
639 GlobalValue *GV = GSDN->getGlobal();
639 const GlobalValue *GV = GSDN->getGlobal();
640640 SDValue GA = DAG.getTargetGlobalAddress(GV, MVT::i64, GSDN->getOffset());
641641 // FIXME there isn't really any debug info here
642642
140140 SDValue BlackfinTargetLowering::LowerGlobalAddress(SDValue Op,
141141 SelectionDAG &DAG) {
142142 DebugLoc DL = Op.getDebugLoc();
143 GlobalValue *GV = cast(Op)->getGlobal();
143 const GlobalValue *GV = cast(Op)->getGlobal();
144144
145145 Op = DAG.getTargetGlobalAddress(GV, MVT::i32);
146146 return DAG.getNode(BFISD::Wrapper, DL, MVT::i32, Op);
306306 // External or weakly linked global variables need non-lazily-resolved
307307 // stubs
308308 if (TM.getRelocationModel() != Reloc::Static) {
309 GlobalValue *GV = MO.getGlobal();
309 const GlobalValue *GV = MO.getGlobal();
310310 if (((GV->isDeclaration() || GV->hasWeakLinkage() ||
311311 GV->hasLinkOnceLinkage() || GV->hasCommonLinkage()))) {
312312 O << *GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
305305 CV.push_back(const_cast(V->getConstantIntValue()));
306306 }
307307
308 Constant *CP = ConstantVector::get(CV);
308 const Constant *CP = ConstantVector::get(CV);
309309 SDValue CPIdx = CurDAG->getConstantPool(CP, SPUtli.getPointerTy());
310310 unsigned Alignment = cast(CPIdx)->getAlignment();
311311 SDValue CGPoolOffset =
453453
454454 case ISD::TargetGlobalAddress: {
455455 GlobalAddressSDNode *GSDN = cast(Op0);
456 GlobalValue *GV = GSDN->getGlobal();
456 const GlobalValue *GV = GSDN->getGlobal();
457457 if (GV->getAlignment() == 16) {
458458 Base = Op0;
459459 Index = Zero;
892892 LowerConstantPool(SDValue Op, SelectionDAG &DAG, const SPUSubtarget *ST) {
893893 EVT PtrVT = Op.getValueType();
894894 ConstantPoolSDNode *CP = cast(Op);
895 Constant *C = CP->getConstVal();
895 const Constant *C = CP->getConstVal();
896896 SDValue CPI = DAG.getTargetConstantPool(C, PtrVT, CP->getAlignment());
897897 SDValue Zero = DAG.getConstant(0, PtrVT);
898898 const TargetMachine &TM = DAG.getTarget();
950950 LowerGlobalAddress(SDValue Op, SelectionDAG &DAG, const SPUSubtarget *ST) {
951951 EVT PtrVT = Op.getValueType();
952952 GlobalAddressSDNode *GSDN = cast(Op);
953 GlobalValue *GV = GSDN->getGlobal();
953 const GlobalValue *GV = GSDN->getGlobal();
954954 SDValue GA = DAG.getTargetGlobalAddress(GV, PtrVT, GSDN->getOffset());
955955 const TargetMachine &TM = DAG.getTarget();
956956 SDValue Zero = DAG.getConstant(0, PtrVT);
12411241 // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol
12421242 // node so that legalize doesn't hack it.
12431243 if (GlobalAddressSDNode *G = dyn_cast(Callee)) {
1244 GlobalValue *GV = G->getGlobal();
1244 const GlobalValue *GV = G->getGlobal();
12451245 EVT CalleeVT = Callee.getValueType();
12461246 SDValue Zero = DAG.getConstant(0, PtrVT);
12471247 SDValue GA = DAG.getTargetGlobalAddress(GV, CalleeVT);
411411 LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) {
412412 // FIXME there isn't actually debug info here
413413 DebugLoc dl = Op.getDebugLoc();
414 GlobalValue *GV = cast(Op)->getGlobal();
414 const GlobalValue *GV = cast(Op)->getGlobal();
415415 SDValue GA = DAG.getTargetGlobalAddress(GV, MVT::i32);
416416
417417 return DAG.getNode(MBlazeISD::Wrap, dl, MVT::i32, GA);
445445 SDValue ResNode;
446446 EVT PtrVT = Op.getValueType();
447447 ConstantPoolSDNode *N = cast(Op);
448 Constant *C = N->getConstVal();
448 const Constant *C = N->getConstVal();
449449 SDValue Zero = DAG.getConstant(0, PtrVT);
450450 DebugLoc dl = Op.getDebugLoc();
451451
4444 } Base;
4545
4646 int16_t Disp;
47 GlobalValue *GV;
48 Constant *CP;
49 BlockAddress *BlockAddr;
47 const GlobalValue *GV;
48 const Constant *CP;
49 const BlockAddress *BlockAddr;
5050 const char *ES;
5151 int JT;
5252 unsigned Align; // CP alignment.
483483 SDValue MipsTargetLowering::LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) {
484484 // FIXME there isn't actually debug info here
485485 DebugLoc dl = Op.getDebugLoc();
486 GlobalValue *GV = cast(Op)->getGlobal();
486 const GlobalValue *GV = cast(Op)->getGlobal();
487487
488488 if (getTargetMachine().getRelocationModel() != Reloc::PIC_) {
489489 SDVTList VTs = DAG.getVTList(MVT::i32);
563563 {
564564 SDValue ResNode;
565565 ConstantPoolSDNode *N = cast(Op);
566 Constant *C = N->getConstVal();
566 const Constant *C = N->getConstVal();
567567 // FIXME there isn't actually debug info here
568568 DebugLoc dl = Op.getDebugLoc();
569569
14081408 if (IsDirectCall) {
14091409 // Considering the GlobalAddressNode case here.
14101410 if (GlobalAddressSDNode *G = dyn_cast(Callee)) {
1411 GlobalValue *GV = G->getGlobal();
1411 const GlobalValue *GV = G->getGlobal();
14121412 Callee = DAG.getTargetGlobalAddress(GV, MVT::i8);
14131413 Name = G->getGlobal()->getName();
14141414 } else {// Considering the ExternalSymbol case here
171171 VarName = I->getName().str();
172172 if (PAN::isLocalToFunc(FnName, VarName)) {
173173 // Auto variable for current function found. Clone it.
174 GlobalVariable *GV = I;
174 const GlobalVariable *GV = I;
175175
176176 const Type *InitTy = GV->getInitializer()->getType();
177177 GlobalVariable *ClonedGV =
133133 const MCSection *
134134 PIC16TargetObjectFile::allocateUDATA(const GlobalVariable *GV) const {
135135 assert(GV->hasInitializer() && "This global doesn't need space");
136 Constant *C = GV->getInitializer();
136 const Constant *C = GV->getInitializer();
137137 assert(C->isNullValue() && "Unitialized globals has non-zero initializer");
138138
139139 // Find how much space this global needs.
168168 const MCSection *
169169 PIC16TargetObjectFile::allocateIDATA(const GlobalVariable *GV) const{
170170 assert(GV->hasInitializer() && "This global doesn't need space");
171 Constant *C = GV->getInitializer();
171 const Constant *C = GV->getInitializer();
172172 assert(!C->isNullValue() && "initialized globals has zero initializer");
173173 assert(GV->getType()->getAddressSpace() == PIC16ISD::RAM_SPACE &&
174174 "can allocate initialized RAM data only");
199199 const MachineOperand &MO = MI->getOperand(OpNo);
200200 if (TM.getRelocationModel() != Reloc::Static) {
201201 if (MO.getType() == MachineOperand::MO_GlobalAddress) {
202 GlobalValue *GV = MO.getGlobal();
202 const GlobalValue *GV = MO.getGlobal();
203203 if (GV->isDeclaration() || GV->isWeakForLinker()) {
204204 // Dynamically-resolved functions need a stub for the function.
205205 MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$stub");
404404 }
405405 case MachineOperand::MO_GlobalAddress: {
406406 // Computing the address of a global symbol, not calling it.
407 GlobalValue *GV = MO.getGlobal();
407 const GlobalValue *GV = MO.getGlobal();
408408 MCSymbol *SymToPrint;
409409
410410 // External or weakly linked global variables need non-lazily-resolved stubs
793793 if (MAI->doesSupportExceptionHandling() && MMI) {
794794 // Add the (possibly multiple) personalities to the set of global values.
795795 // Only referenced functions get into the Personalities list.
796 const std::vector &Personalities = MMI->getPersonalities();
797 for (std::vector::const_iterator I = Personalities.begin(),
796 const std::vector &Personalities = MMI->getPersonalities();
797 for (std::vector::const_iterator I = Personalities.begin(),
798798 E = Personalities.end(); I != E; ++I) {
799799 if (*I) {
800800 MCSymbol *NLPSym = GetSymbolWithGlobalValueBase(*I, "$non_lazy_ptr");
201201 MachineRelocation R;
202202 if (MO.isGlobal()) {
203203 R = MachineRelocation::getGV(MCE.getCurrentPCOffset(), Reloc,
204 MO.getGlobal(), 0,
204 const_cast(MO.getGlobal()), 0,
205205 isa(MO.getGlobal()));
206206 } else if (MO.isSymbol()) {
207207 R = MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
475475 else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) {
476476 // Maybe this has already been legalized into the constant pool?
477477 if (ConstantPoolSDNode *CP = dyn_cast(Op.getOperand(1)))
478 if (ConstantFP *CFP = dyn_cast(CP->getConstVal()))
478 if (const ConstantFP *CFP = dyn_cast(CP->getConstVal()))
479479 return CFP->getValueAPF().isZero();
480480 }
481481 return false;
10971097 SelectionDAG &DAG) {
10981098 EVT PtrVT = Op.getValueType();
10991099 ConstantPoolSDNode *CP = cast(Op);
1100 Constant *C = CP->getConstVal();
1100 const Constant *C = CP->getConstVal();
11011101 SDValue CPI = DAG.getTargetConstantPool(C, PtrVT, CP->getAlignment());
11021102 SDValue Zero = DAG.getConstant(0, PtrVT);
11031103 // FIXME there isn't really any debug info here
11711171 EVT PtrVT = Op.getValueType();
11721172 DebugLoc DL = Op.getDebugLoc();
11731173
1174 BlockAddress *BA = cast(Op)->getBlockAddress();
1174 const BlockAddress *BA = cast(Op)->getBlockAddress();
11751175 SDValue TgtBA = DAG.getBlockAddress(BA, PtrVT, /*isTarget=*/true);
11761176 SDValue Zero = DAG.getConstant(0, PtrVT);
11771177 SDValue Hi = DAG.getNode(PPCISD::Hi, DL, PtrVT, TgtBA, Zero);
12011201 SelectionDAG &DAG) {
12021202 EVT PtrVT = Op.getValueType();
12031203 GlobalAddressSDNode *GSDN = cast(Op);
1204 GlobalValue *GV = GSDN->getGlobal();
1204 const GlobalValue *GV = GSDN->getGlobal();
12051205 SDValue GA = DAG.getTargetGlobalAddress(GV, PtrVT, GSDN->getOffset());
12061206 SDValue Zero = DAG.getConstant(0, PtrVT);
12071207 // FIXME there isn't really any debug info here
752752
753753 SDValue SparcTargetLowering::LowerGlobalAddress(SDValue Op,
754754 SelectionDAG &DAG) {
755 GlobalValue *GV = cast(Op)->getGlobal();
755 const GlobalValue *GV = cast(Op)->getGlobal();
756756 // FIXME there isn't really any debug info here
757757 DebugLoc dl = Op.getDebugLoc();
758758 SDValue GA = DAG.getTargetGlobalAddress(GV, MVT::i32);
776776 ConstantPoolSDNode *N = cast(Op);
777777 // FIXME there isn't really any debug info here
778778 DebugLoc dl = Op.getDebugLoc();
779 Constant *C = N->getConstVal();
779 const Constant *C = N->getConstVal();
780780 SDValue CP = DAG.getTargetConstantPool(C, MVT::i32, N->getAlignment());
781781 SDValue Hi = DAG.getNode(SPISD::Hi, dl, MVT::i32, CP);
782782 SDValue Lo = DAG.getNode(SPISD::Lo, dl, MVT::i32, CP);
715715 SDValue SystemZTargetLowering::LowerGlobalAddress(SDValue Op,
716716 SelectionDAG &DAG) {
717717 DebugLoc dl = Op.getDebugLoc();
718 GlobalValue *GV = cast(Op)->getGlobal();
718 const GlobalValue *GV = cast(Op)->getGlobal();
719719 int64_t Offset = cast(Op)->getOffset();
720720
721721 bool IsPic = getTargetMachine().getRelocationModel() == Reloc::PIC_;
4343
4444 unsigned IndexReg;
4545 int32_t Disp;
46 GlobalValue *GV;
46 const GlobalValue *GV;
4747
4848 SystemZAddressMode() : BaseType(RegBase), IndexReg(0), Disp(0) {
4949 Base.Reg = 0;
7878
7979 private:
8080 void emitPCRelativeBlockAddress(MachineBasicBlock *MBB);
81 void emitGlobalAddress(GlobalValue *GV, unsigned Reloc,
81 void emitGlobalAddress(const GlobalValue *GV, unsigned Reloc,
8282 intptr_t Disp = 0, intptr_t PCAdj = 0,
8383 bool Indirect = false);
8484 void emitExternalSymbolAddress(const char *ES, unsigned Reloc);
162162 /// this is part of a "take the address of a global" instruction.
163163 ///
164164 template
165 void Emitter::emitGlobalAddress(GlobalValue *GV, unsigned Reloc,
165 void Emitter::emitGlobalAddress(const GlobalValue *GV,
166 unsigned Reloc,
166167 intptr_t Disp /* = 0 */,
167168 intptr_t PCAdj /* = 0 */,
168169 bool Indirect /* = false */) {
173174 RelocCST = PCAdj;
174175 MachineRelocation MR = Indirect
175176 ? MachineRelocation::getIndirectSymbol(MCE.getCurrentPCOffset(), Reloc,
176 GV, RelocCST, false)
177 const_cast(GV),
178 RelocCST, false)
177179 : MachineRelocation::getGV(MCE.getCurrentPCOffset(), Reloc,
178 GV, RelocCST, false);
180 const_cast(GV), RelocCST, false);
179181 MCE.addRelocation(MR);
180182 // The relocated value will be added to the displacement
181183 if (Reloc == X86::reloc_absolute_dword)
7171 X86ScalarSSEf32 = Subtarget->hasSSE1();
7272 }
7373
74 virtual bool TargetSelectInstruction(Instruction *I);
74 virtual bool TargetSelectInstruction(const Instruction *I);
7575
7676 #include "X86GenFastISel.inc"
7777
7878 private:
79 bool X86FastEmitCompare(Value *LHS, Value *RHS, EVT VT);
79 bool X86FastEmitCompare(const Value *LHS, const Value *RHS, EVT VT);
8080
8181 bool X86FastEmitLoad(EVT VT, const X86AddressMode &AM, unsigned &RR);
8282
83 bool X86FastEmitStore(EVT VT, Value *Val,
83 bool X86FastEmitStore(EVT VT, const Value *Val,
8484 const X86AddressMode &AM);
8585 bool X86FastEmitStore(EVT VT, unsigned Val,
8686 const X86AddressMode &AM);
8888 bool X86FastEmitExtend(ISD::NodeType Opc, EVT DstVT, unsigned Src, EVT SrcVT,
8989 unsigned &ResultReg);
9090
91 bool X86SelectAddress(Value *V, X86AddressMode &AM);
92 bool X86SelectCallAddress(Value *V, X86AddressMode &AM);
93
94 bool X86SelectLoad(Instruction *I);
95
96 bool X86SelectStore(Instruction *I);
97
98 bool X86SelectCmp(Instruction *I);
99
100 bool X86SelectZExt(Instruction *I);
101
102 bool X86SelectBranch(Instruction *I);
103
104 bool X86SelectShift(Instruction *I);
105
106 bool X86SelectSelect(Instruction *I);
107
108 bool X86SelectTrunc(Instruction *I);
91 bool X86SelectAddress(const Value *V, X86AddressMode &AM);
92 bool X86SelectCallAddress(const Value *V, X86AddressMode &AM);
93
94 bool X86SelectLoad(const Instruction *I);
95
96 bool X86SelectStore(const Instruction *I);
97
98 bool X86SelectCmp(const Instruction *I);
99
100 bool X86SelectZExt(const Instruction *I);
101
102 bool X86SelectBranch(const Instruction *I);
103
104 bool X86SelectShift(const Instruction *I);
105
106 bool X86SelectSelect(const Instruction *I);
107
108 bool X86SelectTrunc(const Instruction *I);
109109
110 bool X86SelectFPExt(Instruction *I);
111 bool X86SelectFPTrunc(Instruction *I);
112
113 bool X86SelectExtractValue(Instruction *I);
114
115 bool X86VisitIntrinsicCall(IntrinsicInst &I);
116 bool X86SelectCall(Instruction *I);
110 bool X86SelectFPExt(const Instruction *I);
111 bool X86SelectFPTrunc(const Instruction *I);
112
113 bool X86SelectExtractValue(const Instruction *I);
114
115 bool X86VisitIntrinsicCall(const IntrinsicInst &I);
116 bool X86SelectCall(const Instruction *I);
117117
118118 CCAssignFn *CCAssignFnForCall(CallingConv::ID CC, bool isTailCall = false);
119119