llvm.org GIT mirror llvm / 2928c83
Pass StringRef by value. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86251 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 10 years ago
51 changed file(s) with 196 addition(s) and 200 deletion(s). Raw diff Collapse all Expand all
9595 /// specified bucket will be non-null. Otherwise, it will be null. In either
9696 /// case, the FullHashValue field of the bucket will be set to the hash value
9797 /// of the string.
98 unsigned LookupBucketFor(const StringRef &Key);
98 unsigned LookupBucketFor(StringRef Key);
9999
100100 /// FindKey - Look up the bucket that contains the specified key. If it exists
101101 /// in the map, return the bucket number of the key. Otherwise return -1.
102102 /// This does not modify the map.
103 int FindKey(const StringRef &Key) const;
103 int FindKey(StringRef Key) const;
104104
105105 /// RemoveKey - Remove the specified StringMapEntry from the table, but do not
106106 /// delete it. This aborts if the value isn't in the table.
108108
109109 /// RemoveKey - Remove the StringMapEntry for the specified key from the
110110 /// table, returning it. If the key is not in the table, this returns null.
111 StringMapEntryBase *RemoveKey(const StringRef &Key);
111 StringMapEntryBase *RemoveKey(StringRef Key);
112112 private:
113113 void init(unsigned Size);
114114 public:
281281 return const_iterator(TheTable+NumBuckets, true);
282282 }
283283
284 iterator find(const StringRef &Key) {
284 iterator find(StringRef Key) {
285285 int Bucket = FindKey(Key);
286286 if (Bucket == -1) return end();
287287 return iterator(TheTable+Bucket);
288288 }
289289
290 const_iterator find(const StringRef &Key) const {
290 const_iterator find(StringRef Key) const {
291291 int Bucket = FindKey(Key);
292292 if (Bucket == -1) return end();
293293 return const_iterator(TheTable+Bucket);
295295
296296 /// lookup - Return the entry for the specified key, or a default
297297 /// constructed value if no such entry exists.
298 ValueTy lookup(const StringRef &Key) const {
298 ValueTy lookup(StringRef Key) const {
299299 const_iterator it = find(Key);
300300 if (it != end())
301301 return it->second;
302302 return ValueTy();
303303 }
304304
305 ValueTy& operator[](const StringRef &Key) {
305 ValueTy& operator[](StringRef Key) {
306306 return GetOrCreateValue(Key).getValue();
307307 }
308308
309 size_type count(const StringRef &Key) const {
309 size_type count(StringRef Key) const {
310310 return find(Key) == end() ? 0 : 1;
311311 }
312312
349349 /// exists, return it. Otherwise, default construct a value, insert it, and
350350 /// return.
351351 template
352 StringMapEntry &GetOrCreateValue(const StringRef &Key,
352 StringMapEntry &GetOrCreateValue(StringRef Key,
353353 InitTy Val) {
354354 unsigned BucketNo = LookupBucketFor(Key);
355355 ItemBucket &Bucket = TheTable[BucketNo];
372372 return *NewItem;
373373 }
374374
375 StringMapEntry &GetOrCreateValue(const StringRef &Key) {
375 StringMapEntry &GetOrCreateValue(StringRef Key) {
376376 return GetOrCreateValue(Key, ValueTy());
377377 }
378378
400400 V.Destroy(Allocator);
401401 }
402402
403 bool erase(const StringRef &Key) {
403 bool erase(StringRef Key) {
404404 iterator I = find(Key);
405405 if (I == end()) return false;
406406 erase(I);
9191
9292 /// equals - Check for string equality, this is more efficient than
9393 /// compare() when the relative ordering of inequal strings isn't needed.
94 bool equals(const StringRef &RHS) const {
94 bool equals(StringRef RHS) const {
9595 return (Length == RHS.Length &&
9696 memcmp(Data, RHS.Data, RHS.Length) == 0);
9797 }
9898
9999 /// compare - Compare two strings; the result is -1, 0, or 1 if this string
100100 /// is lexicographically less than, equal to, or greater than the \arg RHS.
101 int compare(const StringRef &RHS) const {
101 int compare(StringRef RHS) const {
102102 // Check the prefix for a mismatch.
103103 if (int Res = memcmp(Data, RHS.Data, std::min(Length, RHS.Length)))
104104 return Res < 0 ? -1 : 1;
134134 /// @{
135135
136136 /// startswith - Check if this string starts with the given \arg Prefix.
137 bool startswith(const StringRef &Prefix) const {
137 bool startswith(StringRef Prefix) const {
138138 return substr(0, Prefix.Length).equals(Prefix);
139139 }
140140
141141 /// endswith - Check if this string ends with the given \arg Suffix.
142 bool endswith(const StringRef &Suffix) const {
142 bool endswith(StringRef Suffix) const {
143143 return slice(size() - Suffix.Length, size()).equals(Suffix);
144144 }
145145
162162 ///
163163 /// \return - The index of the first occurence of \arg Str, or npos if not
164164 /// found.
165 size_t find(const StringRef &Str) const;
165 size_t find(StringRef Str) const;
166166
167167 /// rfind - Search for the last character \arg C in the string.
168168 ///
183183 ///
184184 /// \return - The index of the last occurence of \arg Str, or npos if not
185185 /// found.
186 size_t rfind(const StringRef &Str) const;
186 size_t rfind(StringRef Str) const;
187187
188188 /// find_first_of - Find the first instance of the specified character or
189189 /// return npos if not in string. Same as find.
212212
213213 /// count - Return the number of non-overlapped occurrences of \arg Str in
214214 /// the string.
215 size_t count(const StringRef &Str) const;
215 size_t count(StringRef Str) const;
216216
217217 /// getAsInteger - Parse the current string as an integer of the specified
218218 /// radix. If Radix is specified as zero, this does radix autosensing using
303303 /// @name StringRef Comparison Operators
304304 /// @{
305305
306 inline bool operator==(const StringRef &LHS, const StringRef &RHS) {
306 inline bool operator==(StringRef LHS, StringRef RHS) {
307307 return LHS.equals(RHS);
308308 }
309309
310 inline bool operator!=(const StringRef &LHS, const StringRef &RHS) {
310 inline bool operator!=(StringRef LHS, StringRef RHS) {
311311 return !(LHS == RHS);
312312 }
313313
314 inline bool operator<(const StringRef &LHS, const StringRef &RHS) {
314 inline bool operator<(StringRef LHS, StringRef RHS) {
315315 return LHS.compare(RHS) == -1;
316316 }
317317
318 inline bool operator<=(const StringRef &LHS, const StringRef &RHS) {
318 inline bool operator<=(StringRef LHS, StringRef RHS) {
319319 return LHS.compare(RHS) != 1;
320320 }
321321
322 inline bool operator>(const StringRef &LHS, const StringRef &RHS) {
322 inline bool operator>(StringRef LHS, StringRef RHS) {
323323 return LHS.compare(RHS) == 1;
324324 }
325325
326 inline bool operator>=(const StringRef &LHS, const StringRef &RHS) {
326 inline bool operator>=(StringRef LHS, StringRef RHS) {
327327 return LHS.compare(RHS) != -1;
328328 }
329329
217217
218218 /// setArchName - Set the architecture (first) component of the
219219 /// triple by name.
220 void setArchName(const StringRef &Str);
220 void setArchName(StringRef Str);
221221
222222 /// setVendorName - Set the vendor (second) component of the triple
223223 /// by name.
224 void setVendorName(const StringRef &Str);
224 void setVendorName(StringRef Str);
225225
226226 /// setOSName - Set the operating system (third) component of the
227227 /// triple by name.
228 void setOSName(const StringRef &Str);
228 void setOSName(StringRef Str);
229229
230230 /// setEnvironmentName - Set the optional environment (fourth)
231231 /// component of the triple by name.
232 void setEnvironmentName(const StringRef &Str);
232 void setEnvironmentName(StringRef Str);
233233
234234 /// setOSAndEnvironmentName - Set the operating system and optional
235235 /// environment components with a single string.
236 void setOSAndEnvironmentName(const StringRef &Str);
236 void setOSAndEnvironmentName(StringRef Str);
237237
238238 /// @}
239239 /// @name Static helpers for IDs.
264264
265265 /// getArchTypeForLLVMName - The canonical type for the given LLVM
266266 /// architecture name (e.g., "x86").
267 static ArchType getArchTypeForLLVMName(const StringRef &Str);
267 static ArchType getArchTypeForLLVMName(StringRef Str);
268268
269269 /// getArchTypeForDarwinArchName - Get the architecture type for a "Darwin"
270270 /// architecture name, for example as accepted by "gcc -arch" (see also
271271 /// arch(3)).
272 static ArchType getArchTypeForDarwinArchName(const StringRef &Str);
272 static ArchType getArchTypeForDarwinArchName(StringRef Str);
273273
274274 /// @}
275275 };
293293 /// known to exist at the end of the the record.
294294 template
295295 void EmitRecordWithAbbrevImpl(unsigned Abbrev, SmallVectorImpl &Vals,
296 const StringRef &Blob) {
296 StringRef Blob) {
297297 const char *BlobData = Blob.data();
298298 unsigned BlobLen = (unsigned) Blob.size();
299299 unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
421421 /// of the record.
422422 template
423423 void EmitRecordWithBlob(unsigned Abbrev, SmallVectorImpl &Vals,
424 const StringRef &Blob) {
424 StringRef Blob) {
425425 EmitRecordWithAbbrevImpl(Abbrev, Vals, Blob);
426426 }
427427 template
434434 /// that end with an array.
435435 template
436436 void EmitRecordWithArray(unsigned Abbrev, SmallVectorImpl &Vals,
437 const StringRef &Array) {
437 StringRef Array) {
438438 EmitRecordWithAbbrevImpl(Abbrev, Vals, Array);
439439 }
440440 template
8585
8686 /// Return a ConstantInt constructed from the string strStart with the given
8787 /// radix.
88 static ConstantInt *get(const IntegerType *Ty, const StringRef &Str,
88 static ConstantInt *get(const IntegerType *Ty, StringRef Str,
8989 uint8_t radix);
9090
9191 /// If Ty is a vector type, return a Constant with a splat of the given
254254 /// only be used for simple constant values like 2.0/1.0 etc, that are
255255 /// known-valid both as host double and as the target format.
256256 static Constant *get(const Type* Ty, double V);
257 static Constant *get(const Type* Ty, const StringRef &Str);
257 static Constant *get(const Type* Ty, StringRef Str);
258258 static ConstantFP *get(LLVMContext &Context, const APFloat &V);
259259 static ConstantFP *getNegativeZero(const Type* Ty);
260260 static ConstantFP *getInfinity(const Type *Ty, bool Negative = false);
352352 /// of the array by one (you've been warned). However, in some situations
353353 /// this is not desired so if AddNull==false then the string is copied without
354354 /// null termination.
355 static Constant *get(LLVMContext &Context, const StringRef &Initializer,
355 static Constant *get(LLVMContext &Context, StringRef Initializer,
356356 bool AddNull = true);
357357
358358 /// Transparently provide more efficient getOperand methods.
8989
9090 bool hasSection() const { return !Section.empty(); }
9191 const std::string &getSection() const { return Section; }
92 void setSection(const StringRef &S) { Section = S; }
92 void setSection(StringRef S) { Section = S; }
9393
9494 /// If the usage is empty (except transitively dead constants), then this
9595 /// global value can can be safely deleted since the destructor will
3232 bool HasSideEffects;
3333 bool IsAlignStack;
3434
35 InlineAsm(const FunctionType *Ty, const StringRef &AsmString,
36 const StringRef &Constraints, bool hasSideEffects,
35 InlineAsm(const FunctionType *Ty, StringRef AsmString,
36 StringRef Constraints, bool hasSideEffects,
3737 bool isAlignStack = false);
3838 virtual ~InlineAsm();
3939 public:
4040
4141 /// InlineAsm::get - Return the the specified uniqued inline asm string.
4242 ///
43 static InlineAsm *get(const FunctionType *Ty, const StringRef &AsmString,
44 const StringRef &Constraints, bool hasSideEffects,
43 static InlineAsm *get(const FunctionType *Ty, StringRef AsmString,
44 StringRef Constraints, bool hasSideEffects,
4545 bool isAlignStack = false);
4646
4747 bool hasSideEffects() const { return HasSideEffects; }
6464 /// the specified constraint string is legal for the type. This returns true
6565 /// if legal, false if not.
6666 ///
67 static bool Verify(const FunctionType *Ty, const StringRef &Constraints);
67 static bool Verify(const FunctionType *Ty, StringRef Constraints);
6868
6969 // Constraint String Parsing
7070 enum ConstraintPrefix {
109109 /// Parse - Analyze the specified string (e.g. "=*&{eax}") and fill in the
110110 /// fields in this structure. If the constraint string is not understood,
111111 /// return true, otherwise return false.
112 bool Parse(const StringRef &Str,
112 bool Parse(StringRef Str,
113113 std::vector &ConstraintsSoFar);
114114 };
115115
117117 /// constraints and their prefixes. If this returns an empty vector, and if
118118 /// the constraint string itself isn't empty, there was an error parsing.
119119 static std::vector
120 ParseConstraints(const StringRef &ConstraintString);
120 ParseConstraints(StringRef ConstraintString);
121121
122122 /// ParseConstraints - Parse the constraints of this inlineasm object,
123123 /// returning them the same way that ParseConstraints(str) does.
6464 /// Construct the Linker with an empty module which will be given the
6565 /// name \p progname. \p progname will also be used for error messages.
6666 /// @brief Construct with empty module
67 Linker(const StringRef &progname, ///< name of tool running linker
68 const StringRef &modulename, ///< name of linker's end-result module
67 Linker(StringRef progname, ///< name of tool running linker
68 StringRef modulename, ///< name of linker's end-result module
6969 LLVMContext &C, ///< Context for global info
7070 unsigned Flags = 0 ///< ControlFlags (one or more |'d together)
7171 );
7373 /// Construct the Linker with a previously defined module, \p aModule. Use
7474 /// \p progname for the name of the program in error messages.
7575 /// @brief Construct with existing module
76 Linker(const StringRef& progname, Module* aModule, unsigned Flags = 0);
76 Linker(StringRef progname, Module* aModule, unsigned Flags = 0);
7777
7878 /// Destruct the Linker.
7979 /// @brief Destructor
213213 /// @returns true if an error occurs, false otherwise
214214 /// @brief Link one library into the module
215215 bool LinkInLibrary (
216 const StringRef &Library, ///< The library to link in
217 bool& is_native ///< Indicates if lib a native library
216 StringRef Library, ///< The library to link in
217 bool& is_native ///< Indicates if lib a native library
218218 );
219219
220220 /// This function links one bitcode archive, \p Filename, into the module.
266266 /// will be empty (i.e. sys::Path::isEmpty() will return true).
267267 /// @returns A sys::Path to the found library
268268 /// @brief Find a library from its short name.
269 sys::Path FindLib(const StringRef &Filename);
269 sys::Path FindLib(StringRef Filename);
270270
271271 /// @}
272272 /// @name Implementation
276276 /// Module it contains (wrapped in an auto_ptr), or 0 if an error occurs.
277277 std::auto_ptr LoadObject(const sys::Path& FN);
278278
279 bool warning(const StringRef &message);
280 bool error(const StringRef &message);
281 void verbose(const StringRef &message);
279 bool warning(StringRef message);
280 bool error(StringRef message);
281 void verbose(StringRef message);
282282
283283 /// @}
284284 /// @name Data
5555
5656 public:
5757 AsmToken() {}
58 AsmToken(TokenKind _Kind, const StringRef &_Str, int64_t _IntVal = 0)
58 AsmToken(TokenKind _Kind, StringRef _Str, int64_t _IntVal = 0)
5959 : Kind(_Kind), Str(_Str), IntVal(_IntVal) {}
6060
6161 TokenKind getKind() const { return Kind; }
4848 /// CreateSymbol - Create a new symbol with the specified @param Name.
4949 ///
5050 /// @param Name - The symbol name, which must be unique across all symbols.
51 MCSymbol *CreateSymbol(const StringRef &Name);
51 MCSymbol *CreateSymbol(StringRef Name);
5252
5353 /// GetOrCreateSymbol - Lookup the symbol inside with the specified
5454 /// @param Name. If it exists, return it. If not, create a forward
5757 /// @param Name - The symbol name, which must be unique across all symbols.
5858 /// @param IsTemporary - Whether this symbol is an assembler temporary,
5959 /// which should not survive into the symbol table for the translation unit.
60 MCSymbol *GetOrCreateSymbol(const StringRef &Name);
60 MCSymbol *GetOrCreateSymbol(StringRef Name);
6161 MCSymbol *GetOrCreateSymbol(const Twine &Name);
6262
6363 /// CreateTemporarySymbol - Create a new temporary symbol with the specified
6666 /// @param Name - The symbol name, for debugging purposes only, temporary
6767 /// symbols do not surive assembly. If non-empty the name must be unique
6868 /// across all symbols.
69 MCSymbol *CreateTemporarySymbol(const StringRef &Name = "");
69 MCSymbol *CreateTemporarySymbol(StringRef Name = "");
7070
7171 /// LookupSymbol - Get the symbol for @param Name, or null.
72 MCSymbol *LookupSymbol(const StringRef &Name) const;
72 MCSymbol *LookupSymbol(StringRef Name) const;
7373
7474 /// @}
7575
119119 /// @{
120120
121121 static const MCSymbolRefExpr *Create(const MCSymbol *Symbol, MCContext &Ctx);
122 static const MCSymbolRefExpr *Create(const StringRef &Name, MCContext &Ctx);
122 static const MCSymbolRefExpr *Create(StringRef Name, MCContext &Ctx);
123123
124124 /// @}
125125 /// @name Accessors
5050 /// of a syntactic one.
5151 bool IsDirective;
5252
53 MCSectionCOFF(const StringRef &name, bool isDirective, SectionKind K)
53 MCSectionCOFF(StringRef name, bool isDirective, SectionKind K)
5454 : MCSection(K), Name(name), IsDirective(isDirective) {
5555 }
5656 public:
5757
58 static MCSectionCOFF *Create(const StringRef &Name, bool IsDirective,
59 SectionKind K, MCContext &Ctx);
58 static MCSectionCOFF *Create(StringRef Name, bool IsDirective,
59 SectionKind K, MCContext &Ctx);
6060
6161 const std::string &getName() const { return Name; }
6262 bool isDirective() const { return IsDirective; }
3434 bool IsExplicit;
3535
3636 protected:
37 MCSectionELF(const StringRef &Section, unsigned type, unsigned flags,
37 MCSectionELF(StringRef Section, unsigned type, unsigned flags,
3838 SectionKind K, bool isExplicit)
3939 : MCSection(K), SectionName(Section.str()), Type(type), Flags(flags),
4040 IsExplicit(isExplicit) {}
4141 public:
4242
43 static MCSectionELF *Create(const StringRef &Section, unsigned Type,
43 static MCSectionELF *Create(StringRef Section, unsigned Type,
4444 unsigned Flags, SectionKind K, bool isExplicit,
4545 MCContext &Ctx);
4646
3232 /// size of stubs, for example.
3333 unsigned Reserved2;
3434
35 MCSectionMachO(const StringRef &Segment, const StringRef &Section,
35 MCSectionMachO(StringRef Segment, StringRef Section,
3636 unsigned TAA, unsigned reserved2, SectionKind K)
3737 : MCSection(K), TypeAndAttributes(TAA), Reserved2(reserved2) {
3838 assert(Segment.size() <= 16 && Section.size() <= 16 &&
5151 }
5252 public:
5353
54 static MCSectionMachO *Create(const StringRef &Segment,
55 const StringRef &Section,
54 static MCSectionMachO *Create(StringRef Segment,
55 StringRef Section,
5656 unsigned TypeAndAttributes,
5757 unsigned Reserved2,
5858 SectionKind K, MCContext &Ctx);
154154 ///
155155 /// This is used to implement assembler directives such as .byte, .ascii,
156156 /// etc.
157 virtual void EmitBytes(const StringRef &Data) = 0;
157 virtual void EmitBytes(StringRef Data) = 0;
158158
159159 /// EmitValue - Emit the expression @param Value into the output as a native
160160 /// integer of the given @param Size bytes.
5555
5656 private: // MCContext creates and uniques these.
5757 friend class MCContext;
58 MCSymbol(const StringRef &_Name, bool _IsTemporary)
58 MCSymbol(StringRef _Name, bool _IsTemporary)
5959 : Name(_Name), Section(0), Value(0), IsTemporary(_IsTemporary) {}
6060
6161 MCSymbol(const MCSymbol&); // DO NOT IMPLEMENT
153153 public:
154154 /// The Module constructor. Note that there is no default constructor. You
155155 /// must provide a name for the module upon construction.
156 explicit Module(const StringRef &ModuleID, LLVMContext& C);
156 explicit Module(StringRef ModuleID, LLVMContext& C);
157157 /// The module destructor. This will dropAllReferences.
158158 ~Module();
159159
195195 public:
196196
197197 /// Set the module identifier.
198 void setModuleIdentifier(const StringRef &ID) { ModuleID = ID; }
198 void setModuleIdentifier(StringRef ID) { ModuleID = ID; }
199199
200200 /// Set the data layout
201 void setDataLayout(const StringRef &DL) { DataLayout = DL; }
201 void setDataLayout(StringRef DL) { DataLayout = DL; }
202202
203203 /// Set the target triple.
204 void setTargetTriple(const StringRef &T) { TargetTriple = T; }
204 void setTargetTriple(StringRef T) { TargetTriple = T; }
205205
206206 /// Set the module-scope inline assembly blocks.
207 void setModuleInlineAsm(const StringRef &Asm) { GlobalScopeAsm = Asm; }
207 void setModuleInlineAsm(StringRef Asm) { GlobalScopeAsm = Asm; }
208208
209209 /// Append to the module-scope inline assembly blocks, automatically
210210 /// appending a newline to the end.
211 void appendModuleInlineAsm(const StringRef &Asm) {
211 void appendModuleInlineAsm(StringRef Asm) {
212212 GlobalScopeAsm += Asm;
213213 GlobalScopeAsm += '\n';
214214 }
220220 /// getNamedValue - Return the first global value in the module with
221221 /// the specified name, of arbitrary type. This method returns null
222222 /// if a global with the specified name is not found.
223 GlobalValue *getNamedValue(const StringRef &Name) const;
223 GlobalValue *getNamedValue(StringRef Name) const;
224224
225225 /// @}
226226 /// @name Function Accessors
235235 /// the existing function.
236236 /// 4. Finally, the function exists but has the wrong prototype: return the
237237 /// function with a constantexpr cast to the right prototype.
238 Constant *getOrInsertFunction(const StringRef &Name, const FunctionType *T,
238 Constant *getOrInsertFunction(StringRef Name, const FunctionType *T,
239239 AttrListPtr AttributeList);
240240
241 Constant *getOrInsertFunction(const StringRef &Name, const FunctionType *T);
241 Constant *getOrInsertFunction(StringRef Name, const FunctionType *T);
242242
243243 /// getOrInsertFunction - Look up the specified function in the module symbol
244244 /// table. If it does not exist, add a prototype for the function and return
247247 /// named function has a different type. This version of the method takes a
248248 /// null terminated list of function arguments, which makes it easier for
249249 /// clients to use.
250 Constant *getOrInsertFunction(const StringRef &Name,
250 Constant *getOrInsertFunction(StringRef Name,
251251 AttrListPtr AttributeList,
252252 const Type *RetTy, ...) END_WITH_NULL;
253253
254254 /// getOrInsertFunction - Same as above, but without the attributes.
255 Constant *getOrInsertFunction(const StringRef &Name, const Type *RetTy, ...)
255 Constant *getOrInsertFunction(StringRef Name, const Type *RetTy, ...)
256256 END_WITH_NULL;
257257
258 Constant *getOrInsertTargetIntrinsic(const StringRef &Name,
258 Constant *getOrInsertTargetIntrinsic(StringRef Name,
259259 const FunctionType *Ty,
260260 AttrListPtr AttributeList);
261261
262262 /// getFunction - Look up the specified function in the module symbol table.
263263 /// If it does not exist, return null.
264 Function *getFunction(const StringRef &Name) const;
264 Function *getFunction(StringRef Name) const;
265265
266266 /// @}
267267 /// @name Global Variable Accessors
271271 /// symbol table. If it does not exist, return null. If AllowInternal is set
272272 /// to true, this function will return types that have InternalLinkage. By
273273 /// default, these types are not returned.
274 GlobalVariable *getGlobalVariable(const StringRef &Name,
274 GlobalVariable *getGlobalVariable(StringRef Name,
275275 bool AllowInternal = false) const;
276276
277277 /// getNamedGlobal - Return the first global variable in the module with the
278278 /// specified name, of arbitrary type. This method returns null if a global
279279 /// with the specified name is not found.
280 GlobalVariable *getNamedGlobal(const StringRef &Name) const {
280 GlobalVariable *getNamedGlobal(StringRef Name) const {
281281 return getGlobalVariable(Name, true);
282282 }
283283
288288 /// with a constantexpr cast to the right type.
289289 /// 3. Finally, if the existing global is the correct delclaration, return
290290 /// the existing global.
291 Constant *getOrInsertGlobal(const StringRef &Name, const Type *Ty);
291 Constant *getOrInsertGlobal(StringRef Name, const Type *Ty);
292292
293293 /// @}
294294 /// @name Global Alias Accessors
297297 /// getNamedAlias - Return the first global alias in the module with the
298298 /// specified name, of arbitrary type. This method returns null if a global
299299 /// with the specified name is not found.
300 GlobalAlias *getNamedAlias(const StringRef &Name) const;
300 GlobalAlias *getNamedAlias(StringRef Name) const;
301301
302302 /// @}
303303 /// @name Named Metadata Accessors
306306 /// getNamedMetadata - Return the first NamedMDNode in the module with the
307307 /// specified name. This method returns null if a NamedMDNode with the
308308 /// specified name is not found.
309 NamedMDNode *getNamedMetadata(const StringRef &Name) const;
309 NamedMDNode *getNamedMetadata(StringRef Name) const;
310310
311311 /// getOrInsertNamedMetadata - Return the first named MDNode in the module
312312 /// with the specified name. This method returns a new NamedMDNode if a
313313 /// NamedMDNode with the specified name is not found.
314 NamedMDNode *getOrInsertNamedMetadata(const StringRef &Name);
314 NamedMDNode *getOrInsertNamedMetadata(StringRef Name);
315315
316316 /// @}
317317 /// @name Type Accessors
320320 /// addTypeName - Insert an entry in the symbol table mapping Str to Type. If
321321 /// there is already an entry for this name, true is returned and the symbol
322322 /// table is not modified.
323 bool addTypeName(const StringRef &Name, const Type *Ty);
323 bool addTypeName(StringRef Name, const Type *Ty);
324324
325325 /// getTypeName - If there is at least one entry in the symbol table for the
326326 /// specified type, return it.
328328
329329 /// getTypeByName - Return the type with the specified name in this module, or
330330 /// null if there is none by that name.
331 const Type *getTypeByName(const StringRef &Name) const;
331 const Type *getTypeByName(StringRef Name) const;
332332
333333 /// @}
334334 /// @name Direct access to the globals list, functions list, and symbol table
414414 /// @brief Returns the number of items in the list of libraries.
415415 inline size_t lib_size() const { return LibraryList.size(); }
416416 /// @brief Add a library to the list of dependent libraries
417 void addLibrary(const StringRef &Lib);
417 void addLibrary(StringRef Lib);
418418 /// @brief Remove a library from the list of dependent libraries
419 void removeLibrary(const StringRef &Lib);
419 void removeLibrary(StringRef Lib);
420420 /// @brief Get all the libraries
421421 inline const LibraryListType& getLibraries() const { return LibraryList; }
422422
166166
167167 // lookupPassInfo - Return the pass info object for the pass with the given
168168 // argument string, or null if it is not known.
169 static const PassInfo *lookupPassInfo(const StringRef &Arg);
169 static const PassInfo *lookupPassInfo(StringRef Arg);
170170
171171 /// getAnalysisIfAvailable() - Subclasses use this function to
172172 /// get analysis information that might be around, for example to update it.
2121 #include
2222 #include "llvm/Pass.h"
2323 #include "llvm/ADT/SmallVector.h"
24 #include "llvm/ADT/StringRef.h"
2425
2526 namespace llvm {
2627
9495 // This can be useful when a pass is trivially preserved, but may not be
9596 // linked in. Be careful about spelling!
9697 //
97 AnalysisUsage &addPreserved(const StringRef &Arg) {
98 AnalysisUsage &addPreserved(StringRef Arg) {
9899 const PassInfo *PI = Pass::lookupPassInfo(Arg);
99100 // If the pass exists, preserve it. Otherwise silently do nothing.
100101 if (PI) Preserved.push_back(PI);
283283 void removeNotPreservedAnalysis(Pass *P);
284284
285285 /// Remove dead passes used by P.
286 void removeDeadPasses(Pass *P, const StringRef &Msg,
286 void removeDeadPasses(Pass *P, StringRef Msg,
287287 enum PassDebuggingString);
288288
289289 /// Remove P.
290 void freePass(Pass *P, const StringRef &Msg,
290 void freePass(Pass *P, StringRef Msg,
291291 enum PassDebuggingString);
292292
293293 /// Add pass P into the PassVector. Update
343343 void dumpLastUses(Pass *P, unsigned Offset) const;
344344 void dumpPassArguments() const;
345345 void dumpPassInfo(Pass *P, enum PassDebuggingString S1,
346 enum PassDebuggingString S2, const StringRef &Msg);
346 enum PassDebuggingString S2, StringRef Msg);
347347 void dumpRequiredSet(const Pass *P) const;
348348 void dumpPreservedSet(const Pass *P) const;
349349
387387 bool isPassDebuggingExecutionsOrMore() const;
388388
389389 private:
390 void dumpAnalysisUsage(const StringRef &Msg, const Pass *P,
391 const AnalysisUsage::VectorType &Set) const;
390 void dumpAnalysisUsage(StringRef Msg, const Pass *P,
391 const AnalysisUsage::VectorType &Set) const;
392392
393393 // Set of available Analysis. This information is used while scheduling
394394 // pass. If a pass requires an analysis which is not not available then
168168 return *this;
169169 }
170170
171 raw_ostream &operator<<(const StringRef &Str) {
171 raw_ostream &operator<<(StringRef Str) {
172172 // Inline fast path, particularly for strings with a known length.
173173 size_t Size = Str.size();
174174
1414 #ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
1515 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
1616
17 #include "llvm/ADT/StringRef.h"
1718 #include "llvm/MC/SectionKind.h"
1819
1920 namespace llvm {
2526 class MCSectionMachO;
2627 class MCContext;
2728 class GlobalValue;
28 class StringRef;
2929 class TargetMachine;
3030
3131 class TargetLoweringObjectFile {
287287
288288 /// getMachOSection - Return the MCSection for the specified mach-o section.
289289 /// This requires the operands to be valid.
290 const MCSectionMachO *getMachOSection(const StringRef &Segment,
291 const StringRef &Section,
290 const MCSectionMachO *getMachOSection(StringRef Segment,
291 StringRef Section,
292292 unsigned TypeAndAttributes,
293293 SectionKind K) const {
294294 return getMachOSection(Segment, Section, TypeAndAttributes, 0, K);
295295 }
296 const MCSectionMachO *getMachOSection(const StringRef &Segment,
297 const StringRef &Section,
296 const MCSectionMachO *getMachOSection(StringRef Segment,
297 StringRef Section,
298298 unsigned TypeAndAttributes,
299299 unsigned Reserved2,
300300 SectionKind K) const;
5050 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
5151
5252 typedef const MCAsmInfo *(*AsmInfoCtorFnTy)(const Target &T,
53 const StringRef &TT);
53 StringRef TT);
5454 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
5555 const std::string &TT,
5656 const std::string &Features);
162162 /// feature set; it should always be provided. Generally this should be
163163 /// either the target triple from the module, or the target triple of the
164164 /// host if that does not exist.
165 const MCAsmInfo *createAsmInfo(const StringRef &Triple) const {
165 const MCAsmInfo *createAsmInfo(StringRef Triple) const {
166166 if (!AsmInfoCtorFn)
167167 return 0;
168168 return AsmInfoCtorFn(*this, Triple);
460460 TargetRegistry::RegisterAsmInfo(T, &Allocator);
461461 }
462462 private:
463 static const MCAsmInfo *Allocator(const Target &T, const StringRef &TT) {
463 static const MCAsmInfo *Allocator(const Target &T, StringRef TT) {
464464 return new MCAsmInfoImpl(T, TT);
465465 }
466466
5757 /// incrementing an integer and appending it to the name, if necessary
5858 /// @returns the unique name
5959 /// @brief Get a unique name for a type
60 std::string getUniqueName(const StringRef &BaseName) const;
60 std::string getUniqueName(StringRef BaseName) const;
6161
6262 /// This method finds the type with the given \p name in the type map
6363 /// and returns it.
6464 /// @returns null if the name is not found, otherwise the Type
6565 /// associated with the \p name.
6666 /// @brief Lookup a type by name.
67 Type *lookup(const StringRef &name) const;
67 Type *lookup(StringRef name) const;
6868
6969 /// Lookup the type associated with name.
7070 /// @returns end() if the name is not found, or an iterator at the entry for
7171 /// Type.
72 iterator find(const StringRef &Name) {
72 iterator find(StringRef Name) {
7373 return tmap.find(Name);
7474 }
7575
7676 /// Lookup the type associated with name.
7777 /// @returns end() if the name is not found, or an iterator at the entry for
7878 /// Type.
79 const_iterator find(const StringRef &Name) const {
79 const_iterator find(StringRef Name) const {
8080 return tmap.find(Name);
8181 }
8282
118118 /// a many-to-one mapping between names and types. This method allows a type
119119 /// with an existing entry in the symbol table to get a new name.
120120 /// @brief Insert a type under a new name.
121 void insert(const StringRef &Name, const Type *Typ);
121 void insert(StringRef Name, const Type *Typ);
122122
123123 /// Remove a type at the specified position in the symbol table.
124124 /// @returns the removed Type.
6868 /// the symbol table.
6969 /// @returns the value associated with the \p Name
7070 /// @brief Lookup a named Value.
71 Value *lookup(const StringRef &Name) const { return vmap.lookup(Name); }
71 Value *lookup(StringRef Name) const { return vmap.lookup(Name); }
7272
7373 /// @returns true iff the symbol table is empty
7474 /// @brief Determine if the symbol table is empty
111111 /// createValueName - This method attempts to create a value name and insert
112112 /// it into the symbol table with the specified name. If it conflicts, it
113113 /// auto-renames the name and returns that instead.
114 ValueName *createValueName(const StringRef &Name, Value *V);
114 ValueName *createValueName(StringRef Name, Value *V);
115115
116116 /// This method removes a value from the symbol table. It leaves the
117117 /// ValueName attached to the value, but it is no longer inserted in the
6969
7070 /// LinkInLibrary - links one library into the HeadModule.
7171 ///
72 bool Linker::LinkInLibrary(const StringRef &Lib, bool& is_native) {
72 bool Linker::LinkInLibrary(StringRef Lib, bool& is_native) {
7373 is_native = false;
7474 // Determine where this library lives.
7575 sys::Path Pathname = FindLib(Lib);
1919 #include "llvm/Config/config.h"
2020 using namespace llvm;
2121
22 Linker::Linker(const StringRef &progname, const StringRef &modname,
23 LLVMContext& C, unsigned flags):
22 Linker::Linker(StringRef progname, StringRef modname,
23 LLVMContext& C, unsigned flags):
2424 Context(C),
2525 Composite(new Module(modname, C)),
2626 LibPaths(),
2828 Error(),
2929 ProgramName(progname) { }
3030
31 Linker::Linker(const StringRef &progname, Module* aModule, unsigned flags) :
31 Linker::Linker(StringRef progname, Module* aModule, unsigned flags) :
3232 Context(aModule->getContext()),
3333 Composite(aModule),
3434 LibPaths(),
4141 }
4242
4343 bool
44 Linker::error(const StringRef &message) {
44 Linker::error(StringRef message) {
4545 Error = message;
4646 if (!(Flags&QuietErrors))
4747 errs() << ProgramName << ": error: " << message << "\n";
4949 }
5050
5151 bool
52 Linker::warning(const StringRef &message) {
52 Linker::warning(StringRef message) {
5353 Error = message;
5454 if (!(Flags&QuietWarnings))
5555 errs() << ProgramName << ": warning: " << message << "\n";
5757 }
5858
5959 void
60 Linker::verbose(const StringRef &message) {
60 Linker::verbose(StringRef message) {
6161 if (Flags&Verbose)
6262 errs() << " " << message << "\n";
6363 }
113113
114114 // IsLibrary - Determine if "Name" is a library in "Directory". Return
115115 // a non-empty sys::Path if its found, an empty one otherwise.
116 static inline sys::Path IsLibrary(const StringRef &Name,
116 static inline sys::Path IsLibrary(StringRef Name,
117117 const sys::Path &Directory) {
118118
119119 sys::Path FullPath(Directory);
152152 /// Path if no matching file can be found.
153153 ///
154154 sys::Path
155 Linker::FindLib(const StringRef &Filename) {
155 Linker::FindLib(StringRef Filename) {
156156 // Determine if the pathname can be found as it stands.
157157 sys::Path FilePath(Filename);
158158 if (FilePath.canRead() &&
5757 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
5858 unsigned Size = 0, unsigned ByteAlignment = 0);
5959
60 virtual void EmitBytes(const StringRef &Data);
60 virtual void EmitBytes(StringRef Data);
6161
6262 virtual void EmitValue(const MCExpr *Value, unsigned Size);
6363
185185 OS << '\n';
186186 }
187187
188 void MCAsmStreamer::EmitBytes(const StringRef &Data) {
188 void MCAsmStreamer::EmitBytes(StringRef Data) {
189189 assert(CurSection && "Cannot emit contents before setting section!");
190190 for (unsigned i = 0, e = Data.size(); i != e; ++i)
191191 OS << ".byte " << (unsigned) (unsigned char) Data[i] << '\n';
179179 OS << StringRef(Zeros, N % 16);
180180 }
181181
182 void WriteString(const StringRef &Str, unsigned ZeroFillSize = 0) {
182 void WriteString(StringRef Str, unsigned ZeroFillSize = 0) {
183183 OS << Str;
184184 if (ZeroFillSize)
185185 WriteZeros(ZeroFillSize - Str.size());
2222 // we don't need to free them here.
2323 }
2424
25 MCSymbol *MCContext::CreateSymbol(const StringRef &Name) {
25 MCSymbol *MCContext::CreateSymbol(StringRef Name) {
2626 assert(Name[0] != '\0' && "Normal symbols cannot be unnamed!");
2727
2828 // Create and bind the symbol, and ensure that names are unique.
3131 return Entry = new (*this) MCSymbol(Name, false);
3232 }
3333
34 MCSymbol *MCContext::GetOrCreateSymbol(const StringRef &Name) {
34 MCSymbol *MCContext::GetOrCreateSymbol(StringRef Name) {
3535 MCSymbol *&Entry = Symbols[Name];
3636 if (Entry) return Entry;
3737
4545 }
4646
4747
48 MCSymbol *MCContext::CreateTemporarySymbol(const StringRef &Name) {
48 MCSymbol *MCContext::CreateTemporarySymbol(StringRef Name) {
4949 // If unnamed, just create a symbol.
5050 if (Name.empty())
5151 new (*this) MCSymbol("", true);
5656 return Entry = new (*this) MCSymbol(Name, true);
5757 }
5858
59 MCSymbol *MCContext::LookupSymbol(const StringRef &Name) const {
59 MCSymbol *MCContext::LookupSymbol(StringRef Name) const {
6060 return Symbols.lookup(Name);
6161 }
132132 return new (Ctx) MCSymbolRefExpr(Sym);
133133 }
134134
135 const MCSymbolRefExpr *MCSymbolRefExpr::Create(const StringRef &Name,
136 MCContext &Ctx) {
135 const MCSymbolRefExpr *MCSymbolRefExpr::Create(StringRef Name, MCContext &Ctx) {
137136 return Create(Ctx.GetOrCreateSymbol(Name), Ctx);
138137 }
139138
133133 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
134134 unsigned Size = 0, unsigned ByteAlignment = 0);
135135
136 virtual void EmitBytes(const StringRef &Data);
136 virtual void EmitBytes(StringRef Data);
137137
138138 virtual void EmitValue(const MCExpr *Value, unsigned Size);
139139
314314 SectData.setAlignment(ByteAlignment);
315315 }
316316
317 void MCMachOStreamer::EmitBytes(const StringRef &Data) {
317 void MCMachOStreamer::EmitBytes(StringRef Data) {
318318 MCDataFragment *DF = dyn_cast_or_null(getCurrentFragment());
319319 if (!DF)
320320 DF = new MCDataFragment(CurSectionData);
4444 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
4545 unsigned Size = 0, unsigned ByteAlignment = 0) {}
4646
47 virtual void EmitBytes(const StringRef &Data) {}
47 virtual void EmitBytes(StringRef Data) {}
4848
4949 virtual void EmitValue(const MCExpr *Value, unsigned Size) {}
5050
2424 //===----------------------------------------------------------------------===//
2525
2626 MCSectionCOFF *MCSectionCOFF::
27 Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
27 Create(StringRef Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
2828 return new (Ctx) MCSectionCOFF(Name, IsDirective, K);
2929 }
3030
1414 using namespace llvm;
1515
1616 MCSectionELF *MCSectionELF::
17 Create(const StringRef &Section, unsigned Type, unsigned Flags,
17 Create(StringRef Section, unsigned Type, unsigned Flags,
1818 SectionKind K, bool isExplicit, MCContext &Ctx) {
1919 return new (Ctx) MCSectionELF(Section, Type, Flags, K, isExplicit);
2020 }
6565
6666
6767 MCSectionMachO *MCSectionMachO::
68 Create(const StringRef &Segment, const StringRef &Section,
68 Create(StringRef Segment, StringRef Section,
6969 unsigned TypeAndAttributes, unsigned Reserved2,
7070 SectionKind K, MCContext &Ctx) {
7171 // S_SYMBOL_STUBS must be set for Reserved2 to be non-zero.
3434
3535 /// NameNeedsEscaping - Return true if the identifier \arg Str needs quotes
3636 /// for this assembler.
37 static bool NameNeedsEscaping(const StringRef &Str, const MCAsmInfo &MAI) {
37 static bool NameNeedsEscaping(StringRef Str, const MCAsmInfo &MAI) {
3838 assert(!Str.empty() && "Cannot create an empty MCSymbol");
3939
4040 // If the first character is a number and the target does not allow this, we
5151 /// specified bucket will be non-null. Otherwise, it will be null. In either
5252 /// case, the FullHashValue field of the bucket will be set to the hash value
5353 /// of the string.
54 unsigned StringMapImpl::LookupBucketFor(const StringRef &Name) {
54 unsigned StringMapImpl::LookupBucketFor(StringRef Name) {
5555 unsigned HTSize = NumBuckets;
5656 if (HTSize == 0) { // Hash table unallocated so far?
5757 init(16);
109109 /// FindKey - Look up the bucket that contains the specified key. If it exists
110110 /// in the map, return the bucket number of the key. Otherwise return -1.
111111 /// This does not modify the map.
112 int StringMapImpl::FindKey(const StringRef &Key) const {
112 int StringMapImpl::FindKey(StringRef Key) const {
113113 unsigned HTSize = NumBuckets;
114114 if (HTSize == 0) return -1; // Really empty table?
115115 unsigned FullHashValue = HashString(Key);
160160
161161 /// RemoveKey - Remove the StringMapEntry for the specified key from the
162162 /// table, returning it. If the key is not in the table, this returns null.
163 StringMapEntryBase *StringMapImpl::RemoveKey(const StringRef &Key) {
163 StringMapEntryBase *StringMapImpl::RemoveKey(StringRef Key) {
164164 int Bucket = FindKey(Key);
165165 if (Bucket == -1) return 0;
166166
2323 ///
2424 /// \return - The index of the first occurence of \arg Str, or npos if not
2525 /// found.
26 size_t StringRef::find(const StringRef &Str) const {
26 size_t StringRef::find(StringRef Str) const {
2727 size_t N = Str.size();
2828 if (N > Length)
2929 return npos;
3737 ///
3838 /// \return - The index of the last occurence of \arg Str, or npos if not
3939 /// found.
40 size_t StringRef::rfind(const StringRef &Str) const {
40 size_t StringRef::rfind(StringRef Str) const {
4141 size_t N = Str.size();
4242 if (N > Length)
4343 return npos;
7474
7575 /// count - Return the number of non-overlapped occurrences of \arg Str in
7676 /// the string.
77 size_t StringRef::count(const StringRef &Str) const {
77 size_t StringRef::count(StringRef Str) const {
7878 size_t Count = 0;
7979 size_t N = Str.size();
8080 if (N > Length)
101101 return "";
102102 }
103103
104 Triple::ArchType Triple::getArchTypeForLLVMName(const StringRef &Name) {
104 Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
105105 if (Name == "alpha")
106106 return alpha;
107107 if (Name == "arm")
140140 return UnknownArch;
141141 }
142142
143 Triple::ArchType Triple::getArchTypeForDarwinArchName(const StringRef &Str) {
143 Triple::ArchType Triple::getArchTypeForDarwinArchName(StringRef Str) {
144144 // See arch(3) and llvm-gcc's driver-driver.c. We don't implement support for
145145 // archs which Darwin doesn't use.
146146
392392 setOSName(getOSTypeName(Kind));
393393 }
394394
395 void Triple::setArchName(const StringRef &Str) {
395 void Triple::setArchName(StringRef Str) {
396396 // Work around a miscompilation bug for Twines in gcc 4.0.3.
397397 SmallString<64> Triple;
398398 Triple += Str;
403403 setTriple(Triple.str());
404404 }
405405
406 void Triple::setVendorName(const StringRef &Str) {
406 void Triple::setVendorName(StringRef Str) {
407407 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
408408 }
409409
410 void Triple::setOSName(const StringRef &Str) {
410 void Triple::setOSName(StringRef Str) {
411411 if (hasEnvironment())
412412 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
413413 "-" + getEnvironmentName());
415415 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
416416 }
417417
418 void Triple::setEnvironmentName(const StringRef &Str) {
419 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
418 void Triple::setEnvironmentName(StringRef Str) {
419 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
420420 "-" + Str);
421421 }
422422
423 void Triple::setOSAndEnvironmentName(const StringRef &Str) {
423 void Triple::setOSAndEnvironmentName(StringRef Str) {
424424 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
425425 }
2020 #include "llvm/Target/TargetRegistry.h"
2121 using namespace llvm;
2222
23 static const MCAsmInfo *createMCAsmInfo(const Target &T,
24 const StringRef &TT) {
23 static const MCAsmInfo *createMCAsmInfo(const Target &T, StringRef TT) {
2524 Triple TheTriple(TT);
2625 switch (TheTriple.getOS()) {
2726 case Triple::Darwin:
1919 #include "llvm/Support/FormattedStream.h"
2020 using namespace llvm;
2121
22 static const MCAsmInfo *createMCAsmInfo(const Target &T,
23 const StringRef &TT) {
22 static const MCAsmInfo *createMCAsmInfo(const Target &T, StringRef TT) {
2423 Triple TheTriple(TT);
2524 bool isPPC64 = TheTriple.getArch() == Triple::ppc64;
2625 if (TheTriple.getOS() == Triple::Darwin)
670670
671671
672672 const MCSectionMachO *TargetLoweringObjectFileMachO::
673 getMachOSection(const StringRef &Segment, const StringRef &Section,
673 getMachOSection(StringRef Segment, StringRef Section,
674674 unsigned TypeAndAttributes,
675675 unsigned Reserved2, SectionKind Kind) const {
676676 // We unique sections by their segment/section pair. The returned section
2121 #include "llvm/Target/TargetRegistry.h"
2222 using namespace llvm;
2323
24 static const MCAsmInfo *createMCAsmInfo(const Target &T,
25 const StringRef &TT) {
24 static const MCAsmInfo *createMCAsmInfo(const Target &T, StringRef TT) {
2625 Triple TheTriple(TT);
2726 switch (TheTriple.getOS()) {
2827 case Triple::Darwin:
317317 return C;
318318 }
319319
320 ConstantInt* ConstantInt::get(const IntegerType* Ty, const StringRef& Str,
320 ConstantInt* ConstantInt::get(const IntegerType* Ty, StringRef Str,
321321 uint8_t radix) {
322322 return get(Ty->getContext(), APInt(Ty->getBitWidth(), Str, radix));
323323 }
361361 }
362362
363363
364 Constant* ConstantFP::get(const Type* Ty, const StringRef& Str) {
364 Constant* ConstantFP::get(const Type* Ty, StringRef Str) {
365365 LLVMContext &Context = Ty->getContext();
366366
367367 APFloat FV(*TypeToFloatSemantics(Ty->getScalarType()), Str);
507507 /// Otherwise, the length parameter specifies how much of the string to use
508508 /// and it won't be null terminated.
509509 ///
510 Constant* ConstantArray::get(LLVMContext &Context, const StringRef &Str,
510 Constant* ConstantArray::get(LLVMContext &Context, StringRef Str,
511511 bool AddNull) {
512512 std::vector ElementVals;
513513 for (unsigned i = 0; i < Str.size(); ++i)
2525 // NOTE: when memoizing the function type, we have to be careful to handle the
2626 // case when the type gets refined.
2727
28 InlineAsm *InlineAsm::get(const FunctionType *Ty, const StringRef &AsmString,
29 const StringRef &Constraints, bool hasSideEffects,
28 InlineAsm *InlineAsm::get(const FunctionType *Ty, StringRef AsmString,
29 StringRef Constraints, bool hasSideEffects,
3030 bool isAlignStack) {
3131 // FIXME: memoize!
3232 return new InlineAsm(Ty, AsmString, Constraints, hasSideEffects,
3333 isAlignStack);
3434 }
3535
36 InlineAsm::InlineAsm(const FunctionType *Ty, const StringRef &asmString,
37 const StringRef &constraints, bool hasSideEffects,
36 InlineAsm::InlineAsm(const FunctionType *Ty, StringRef asmString,
37 StringRef constraints, bool hasSideEffects,
3838 bool isAlignStack)
3939 : Value(PointerType::getUnqual(Ty),
4040 Value::InlineAsmVal),
5353 /// Parse - Analyze the specified string (e.g. "==&{eax}") and fill in the
5454 /// fields in this structure. If the constraint string is not understood,
5555 /// return true, otherwise return false.
56 bool InlineAsm::ConstraintInfo::Parse(const StringRef &Str,
56 bool InlineAsm::ConstraintInfo::Parse(StringRef Str,
5757 std::vector &ConstraintsSoFar) {
5858 StringRef::iterator I = Str.begin(), E = Str.end();
5959
148148 }
149149
150150 std::vector
151 InlineAsm::ParseConstraints(const StringRef &Constraints) {
151 InlineAsm::ParseConstraints(StringRef Constraints) {
152152 std::vector Result;
153153
154154 // Scan the constraints string.
182182
183183 /// Verify - Verify that the specified constraint string is reasonable for the
184184 /// specified function type, and otherwise validate the constraint string.
185 bool InlineAsm::Verify(const FunctionType *Ty, const StringRef &ConstStr) {
185 bool InlineAsm::Verify(const FunctionType *Ty, StringRef ConstStr) {
186186 if (Ty->isVarArg()) return false;
187187
188188 std::vector Constraints = ParseConstraints(ConstStr);
5454 // Primitive Module methods.
5555 //
5656
57 Module::Module(const StringRef &MID, LLVMContext& C)
57 Module::Module(StringRef MID, LLVMContext& C)
5858 : Context(C), ModuleID(MID), DataLayout("") {
5959 ValSymTab = new ValueSymbolTable();
6060 TypeSymTab = new TypeSymbolTable();
113113 /// getNamedValue - Return the first global value in the module with
114114 /// the specified name, of arbitrary type. This method returns null
115115 /// if a global with the specified name is not found.
116 GlobalValue *Module::getNamedValue(const StringRef &Name) const {
116 GlobalValue *Module::getNamedValue(StringRef Name) const {
117117 return cast_or_null(getValueSymbolTable().lookup(Name));
118118 }
119119
126126 // it. This is nice because it allows most passes to get away with not handling
127127 // the symbol table directly for this common task.
128128 //
129 Constant *Module::getOrInsertFunction(const StringRef &Name,
129 Constant *Module::getOrInsertFunction(StringRef Name,
130130 const FunctionType *Ty,
131131 AttrListPtr AttributeList) {
132132 // See if we have a definition for the specified function already.
159159 return F;
160160 }
161161
162 Constant *Module::getOrInsertTargetIntrinsic(const StringRef &Name,
162 Constant *Module::getOrInsertTargetIntrinsic(StringRef Name,
163163 const FunctionType *Ty,
164164 AttrListPtr AttributeList) {
165165 // See if we have a definition for the specified function already.
176176 return F;
177177 }
178178
179 Constant *Module::getOrInsertFunction(const StringRef &Name,
179 Constant *Module::getOrInsertFunction(StringRef Name,
180180 const FunctionType *Ty) {
181181 AttrListPtr AttributeList = AttrListPtr::get((AttributeWithIndex *)0, 0);
182182 return getOrInsertFunction(Name, Ty, AttributeList);
187187 // This version of the method takes a null terminated list of function
188188 // arguments, which makes it easier for clients to use.
189189 //
190 Constant *Module::getOrInsertFunction(const StringRef &Name,
190 Constant *Module::getOrInsertFunction(StringRef Name,
191191 AttrListPtr AttributeList,
192192 const Type *RetTy, ...) {
193193 va_list Args;
206206 AttributeList);
207207 }
208208
209 Constant *Module::getOrInsertFunction(const StringRef &Name,
209 Constant *Module::getOrInsertFunction(StringRef Name,
210210 const Type *RetTy, ...) {
211211 va_list Args;
212212 va_start(Args, RetTy);
227227 // getFunction - Look up the specified function in the module symbol table.
228228 // If it does not exist, return null.
229229 //
230 Function *Module::getFunction(const StringRef &Name) const {
230 Function *Module::getFunction(StringRef Name) const {
231231 return dyn_cast_or_null(getNamedValue(Name));
232232 }
233233
242242 /// If AllowLocal is set to true, this function will return types that
243243 /// have an local. By default, these types are not returned.
244244 ///
245 GlobalVariable *Module::getGlobalVariable(const StringRef &Name,
245 GlobalVariable *Module::getGlobalVariable(StringRef Name,
246246 bool AllowLocal) const {
247247 if (GlobalVariable *Result =
248248 dyn_cast_or_null(getNamedValue(Name)))
257257 /// with a constantexpr cast to the right type.
258258 /// 3. Finally, if the existing global is the correct delclaration, return the
259259 /// existing global.
260 Constant *Module::getOrInsertGlobal(const StringRef &Name, const Type *Ty) {
260 Constant *Module::getOrInsertGlobal(StringRef Name, const Type *Ty) {
261261 // See if we have a definition for the specified global already.
262262 GlobalVariable *GV = dyn_cast_or_null(getNamedValue(Name));
263263 if (GV == 0) {
284284 // getNamedAlias - Look up the specified global in the module symbol table.
285285 // If it does not exist, return null.
286286 //
287 GlobalAlias *Module::getNamedAlias(const StringRef &Name) const {
287 GlobalAlias *Module::getNamedAlias(StringRef Name) const {
288288 return dyn_cast_or_null(getNamedValue(Name));
289289 }
290290
291291 /// getNamedMetadata - Return the first NamedMDNode in the module with the
292292 /// specified name. This method returns null if a NamedMDNode with the
293293 //// specified name is not found.
294 NamedMDNode *Module::getNamedMetadata(const StringRef &Name) const {
294 NamedMDNode *Module::getNamedMetadata(StringRef Name) const {
295295 return dyn_cast_or_null(getValueSymbolTable().lookup(Name));
296296 }
297297
298298 /// getOrInsertNamedMetadata - Return the first named MDNode in the module
299299 /// with the specified name. This method returns a new NamedMDNode if a
300300 /// NamedMDNode with the specified name is not found.
301 NamedMDNode *Module::getOrInsertNamedMetadata(const StringRef &Name) {
301 NamedMDNode *Module::getOrInsertNamedMetadata(StringRef Name) {
302302 NamedMDNode *NMD =
303303 dyn_cast_or_null(getValueSymbolTable().lookup(Name));
304304 if (!NMD)
315315 // there is already an entry for this name, true is returned and the symbol
316316 // table is not modified.
317317 //
318 bool Module::addTypeName(const StringRef &Name, const Type *Ty) {
318 bool Module::addTypeName(StringRef Name, const Type *Ty) {
319319 TypeSymbolTable &ST = getTypeSymbolTable();
320320
321321 if (ST.lookup(Name)) return true; // Already in symtab...
329329
330330 /// getTypeByName - Return the type with the specified name in this module, or
331331 /// null if there is none by that name.
332 const Type *Module::getTypeByName(const StringRef &Name) const {
332 const Type *Module::getTypeByName(StringRef Name) const {
333333 const TypeSymbolTable &ST = getTypeSymbolTable();
334334 return cast_or_null(ST.lookup(Name));
335335 }
375375 I->dropAllReferences();
376376 }
377377
378 void Module::addLibrary(const StringRef& Lib) {
378 void Module::addLibrary(StringRef Lib) {
379379 for (Module::lib_iterator I = lib_begin(), E = lib_end(); I != E; ++I)
380380 if (*I == Lib)
381381 return;
382382 LibraryList.push_back(Lib);
383383 }
384384
385 void Module::removeLibrary(const StringRef& Lib) {
385 void Module::removeLibrary(StringRef Lib) {
386386 LibraryListType::iterator I = LibraryList.begin();
387387 LibraryListType::iterator E = LibraryList.end();
388388 for (;I != E; ++I)
148148 return I != PassInfoMap.end() ? I->second : 0;
149149 }
150150
151 const PassInfo *GetPassInfo(const StringRef &Arg) const {
151 const PassInfo *GetPassInfo(StringRef Arg) const {
152152 StringMapType::const_iterator I = PassInfoStringMap.find(Arg);
153153 return I != PassInfoStringMap.end() ? I->second : 0;
154154 }
237237 return getPassRegistrar()->GetPassInfo(TI);
238238 }
239239
240 const PassInfo *Pass::lookupPassInfo(const StringRef &Arg) {
240 const PassInfo *Pass::lookupPassInfo(StringRef Arg) {
241241 return getPassRegistrar()->GetPassInfo(Arg);
242242 }
243243
745745 }
746746
747747 /// Remove analysis passes that are not used any longer
748 void PMDataManager::removeDeadPasses(Pass *P, const StringRef &Msg,
748 void PMDataManager::removeDeadPasses(Pass *P, StringRef Msg,
749749 enum PassDebuggingString DBG_STR) {
750750
751751 SmallVector DeadPasses;
767767 freePass(*I, Msg, DBG_STR);
768768 }
769769
770 void PMDataManager::freePass(Pass *P, const StringRef &Msg,
770 void PMDataManager::freePass(Pass *P, StringRef Msg,
771771 enum PassDebuggingString DBG_STR) {
772772 dumpPassInfo(P, FREEING_MSG, DBG_STR, Msg);
773773
971971
972972 void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1,
973973 enum PassDebuggingString S2,
974 const StringRef &Msg) {
974 StringRef Msg) {
975975 if (PassDebugging < Executions)
976976 return;
977977 errs() << (void*)this << std::string(getDepth()*2+1, ' ');
10271027 dumpAnalysisUsage("Preserved", P, analysisUsage.getPreservedSet());
10281028 }
10291029
1030 void PMDataManager::dumpAnalysisUsage(const StringRef &Msg, const Pass *P,
1030 void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P,
10311031 const AnalysisUsage::VectorType &Set) const {
10321032 assert(PassDebugging >= Details);
10331033 if (Set.empty())
3030 }
3131 }
3232
33 std::string TypeSymbolTable::getUniqueName(const StringRef &BaseName) const {
33 std::string TypeSymbolTable::getUniqueName(StringRef BaseName) const {
3434 std::string TryName = BaseName;
3535
3636 const_iterator End = tmap.end();
4242 }
4343
4444 // lookup a type by name - returns null on failure
45 Type* TypeSymbolTable::lookup(const StringRef &Name) const {
45 Type* TypeSymbolTable::lookup(StringRef Name) const {
4646 const_iterator TI = tmap.find(Name);
4747 Type* result = 0;
4848 if (TI != tmap.end())
4949 result = const_cast(TI->second);
5050 return result;
5151 }
52
5352
5453 // remove - Remove a type from the symbol table...
5554 Type* TypeSymbolTable::remove(iterator Entry) {
7978
8079
8180 // insert - Insert a type into the symbol table with the specified name...
82 void TypeSymbolTable::insert(const StringRef &Name, const Type* T) {
81 void TypeSymbolTable::insert(StringRef Name, const Type* T) {
8382 assert(T && "Can't insert null type into symbol table!");
8483
8584 if (tmap.insert(std::make_pair(Name, T)).second) {
7676 /// createValueName - This method attempts to create a value name and insert
7777 /// it into the symbol table with the specified name. If it conflicts, it
7878 /// auto-renames the name and returns that instead.
79 ValueName *ValueSymbolTable::createValueName(const StringRef &Name, Value *V) {
79 ValueName *ValueSymbolTable::createValueName(StringRef Name, Value *V) {
8080 // In the common case, the name is not already in the symbol table.
8181 ValueName &Entry = vmap.GetOrCreateValue(Name);
8282 if (Entry.getValue() == 0) {