llvm.org GIT mirror llvm / f976c85
Remove trailing whitespace git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21422 91177308-0d34-0410-b5e6-96231b3b80d8 Misha Brukman 15 years ago
45 changed file(s) with 453 addition(s) and 453 deletion(s). Raw diff Collapse all Expand all
0 //===-- TargetLowering.cpp - Implement the TargetLowering class -----------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This implements the TargetLowering class.
7575 // Everything defaults to one.
7676 for (unsigned i = 0; i != MVT::LAST_VALUETYPE; ++i)
7777 NumElementsForVT[i] = 1;
78
78
7979 // Find the largest integer register class.
8080 unsigned LargestIntReg = MVT::i128;
8181 for (; RegClassForVT[LargestIntReg] == 0; --LargestIntReg)
100100 TransformToType, ValueTypeActions);
101101 else
102102 TransformToType[(MVT::ValueType)IntReg] = (MVT::ValueType)IntReg;
103
103
104104 // If the target does not have native support for F32, promote it to F64.
105105 if (!hasNativeSupportFor(MVT::f32))
106106 SetValueTypeAction(MVT::f32, Promote, *this,
0 //===-- Intercept.cpp - System function interception routines -------------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // If a function call occurs to an external function, the JIT is designed to use
4949 #if defined(__linux__)
5050 #if defined(HAVE_SYS_STAT_H)
5151 #include
52 #endif
52 #endif
5353 void *FunctionPointers[] = {
5454 (void *) stat,
5555 (void *) fstat,
8383 }
8484
8585 //===----------------------------------------------------------------------===//
86 //
86 //
8787 /// getPointerToNamedFunction - This method returns the address of the specified
88 /// function by using the dynamic loader interface. As such it is only useful
88 /// function by using the dynamic loader interface. As such it is only useful
8989 /// for resolving library symbols, not code generated symbols.
9090 ///
9191 void *JIT::getPointerToNamedFunction(const std::string &Name) {
0 //===-- JIT.cpp - LLVM Just in Time Compiler ------------------------------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This tool implements a just-in-time compiler for LLVM, allowing direct
3434
3535 // Initialize MCE
3636 MCE = createEmitter(*this);
37
37
3838 // Add target data
3939 PM.add(new TargetData(TM.getTargetData()));
4040
7676 if (RetTy == Type::IntTy || RetTy == Type::UIntTy || RetTy == Type::VoidTy) {
7777 switch (ArgValues.size()) {
7878 case 3:
79 if ((FTy->getParamType(0) == Type::IntTy ||
79 if ((FTy->getParamType(0) == Type::IntTy ||
8080 FTy->getParamType(0) == Type::UIntTy) &&
8181 isa(FTy->getParamType(1)) &&
8282 isa(FTy->getParamType(2))) {
9191 }
9292 break;
9393 case 2:
94 if ((FTy->getParamType(0) == Type::IntTy ||
94 if ((FTy->getParamType(0) == Type::IntTy ||
9595 FTy->getParamType(0) == Type::UIntTy) &&
9696 isa(FTy->getParamType(1))) {
9797 int (*PF)(int, char **) = (int(*)(int, char **))FPtr;
104104 break;
105105 case 1:
106106 if (FTy->getNumParams() == 1 &&
107 (FTy->getParamType(0) == Type::IntTy ||
107 (FTy->getParamType(0) == Type::IntTy ||
108108 FTy->getParamType(0) == Type::UIntTy)) {
109109 GenericValue rv;
110110 int (*PF)(int) = (int(*)(int))FPtr;
238238 return Addr; // Check if function already code gen'd
239239
240240 // Make sure we read in the function if it exists in this Module
241 if (F->hasNotBeenReadFromBytecode())
241 if (F->hasNotBeenReadFromBytecode())
242242 try {
243243 MP->materializeFunction(F);
244244 } catch ( std::string& errmsg ) {
0 //===-- JIT.h - Class definition for the JIT --------------------*- C++ -*-===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file defines the top-level JIT data structure.
2929 class JIT : public ExecutionEngine {
3030 TargetMachine &TM; // The current target we are compiling to
3131 TargetJITInfo &TJI; // The JITInfo for the target we are compiling to
32
32
3333 FunctionPassManager PM; // Passes to compile a function
3434 MachineCodeEmitter *MCE; // MCE object
3535
6666
6767 // CompilationCallback - Invoked the first time that a call site is found,
6868 // which causes lazy compilation of the target function.
69 //
69 //
7070 static void CompilationCallback();
7171
7272 /// getPointerToFunction - This returns the address of the specified function,
0 //===-- JITEmitter.cpp - Write machine code to executable memory ----------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file defines a MachineCodeEmitter object that is used by the JIT to
5353 public:
5454 JITMemoryManager();
5555 ~JITMemoryManager();
56
56
5757 inline unsigned char *allocateStub(unsigned StubSize);
5858 inline unsigned char *allocateConstant(unsigned ConstantSize,
5959 unsigned Alignment);
189189 void *Actual = (void*)LazyResolverFn;
190190 if (F->isExternal() && F->hasExternalLinkage())
191191 Actual = TheJIT->getPointerToFunction(F);
192
192
193193 // Otherwise, codegen a new stub. For now, the stub will call the lazy
194194 // resolver function.
195195 Stub = TheJIT->getJITInfo().emitFunctionStub(Actual, MCE);
229229 /// it if necessary, then returns the resultant function pointer.
230230 void *JITResolver::JITCompilerFn(void *Stub) {
231231 JITResolver &JR = getJITResolver();
232
232
233233 // The address given to us for the stub may not be exactly right, it might be
234234 // a little bit after the stub. As such, use upper_bound to find it.
235235 std::map::iterator I =
372372 void *ResultPtr;
373373 if (MR.isString()) {
374374 ResultPtr = TheJIT->getPointerToNamedFunction(MR.getString());
375
375
376376 // If the target REALLY wants a stub for this function, emit it now.
377377 if (!MR.doesntNeedFunctionStub())
378378 ResultPtr = getJITResolver(this).getExternalFunctionStub(ResultPtr);
0 //===-- TargetSelect.cpp - Target Chooser Code ----------------------------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This just asks the TargetMachineRegistry for the appropriate JIT to use, and
0 //===- lib/Linker/LinkArchives.cpp - Link LLVM objects and libraries ------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file contains routines to handle linking together LLVM bytecode files,
2525 /// GetAllDefinedSymbols - Modifies its parameter DefinedSymbols to contain the
2626 /// name of each externally-visible symbol defined in M.
2727 ///
28 static void
28 static void
2929 GetAllDefinedSymbols(Module *M, std::set &DefinedSymbols) {
3030 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
3131 if (I->hasName() && !I->isExternal() && !I->hasInternalLinkage())
5959 Function *Main = M->getMainFunction();
6060 if (Main == 0 || Main->isExternal())
6161 UndefinedSymbols.insert("main");
62
62
6363 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
6464 if (I->hasName()) {
6565 if (I->isExternal())
7575 else if (!I->hasInternalLinkage())
7676 DefinedSymbols.insert(I->getName());
7777 }
78
78
7979 // Prune out any defined symbols from the undefined symbols set...
8080 for (std::set::iterator I = UndefinedSymbols.begin();
8181 I != UndefinedSymbols.end(); )
9494 /// Return Value:
9595 /// TRUE - An error occurred.
9696 /// FALSE - No errors.
97 bool
97 bool
9898 Linker::LinkInArchive(const sys::Path &Filename) {
9999
100100 // Make sure this is an archive file we're dealing with
109109 // no reason to link in any archive files.
110110 std::set UndefinedSymbols;
111111 GetAllUndefinedSymbols(Composite, UndefinedSymbols);
112
112
113113 if (UndefinedSymbols.empty()) {
114 verbose("No symbols undefined, skipping library '" +
114 verbose("No symbols undefined, skipping library '" +
115115 Filename.toString() + "'");
116116 return false; // No need to link anything in!
117117 }
123123 Archive* arch = AutoArch.get();
124124
125125 if (!arch)
126 return error("Cannot read archive '" + Filename.toString() +
126 return error("Cannot read archive '" + Filename.toString() +
127127 "': " + ErrMsg);
128128
129129 // Save a set of symbols that are not defined by the archive. Since we're
132132 std::set NotDefinedByArchive;
133133
134134 // While we are linking in object files, loop.
135 while (true) {
135 while (true) {
136136
137137 // Find the modules we need to link into the target module
138138 std::set Modules;
139139 arch->findModulesDefiningSymbols(UndefinedSymbols, Modules);
140140
141 // If we didn't find any more modules to link this time, we are done
141 // If we didn't find any more modules to link this time, we are done
142142 // searching this archive.
143143 if (Modules.empty())
144144 break;
161161
162162 // Link it in
163163 if (LinkInModule(aModule))
164 return error("Cannot link in module '" +
164 return error("Cannot link in module '" +
165165 aModule->getModuleIdentifier() + "': " + Error);
166166 }
167167
170170 GetAllUndefinedSymbols(Composite, UndefinedSymbols);
171171
172172 // At this point we have two sets of undefined symbols: UndefinedSymbols
173 // which holds the undefined symbols from all the modules, and
173 // which holds the undefined symbols from all the modules, and
174174 // NotDefinedByArchive which holds symbols we know the archive doesn't
175175 // define. There's no point searching for symbols that we won't find in the
176176 // archive so we subtract these sets.
177177 set_subtract(UndefinedSymbols, NotDefinedByArchive);
178
178
179179 // If there's no symbols left, no point in continuing to search the
180180 // archive.
181181 if (UndefinedSymbols.empty())
182182 break;
183183 }
184
184
185185 return false;
186186 }
0 //===- lib/Linker/LinkItems.cpp - Link LLVM objects and libraries ---------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
4 // This file was developed by Reid Spencer and is distributed under the
4 // This file was developed by Reid Spencer and is distributed under the
55 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file contains routines to handle linking together LLVM bytecode files,
2020 bool
2121 Linker::LinkInItems(const ItemList& Items) {
2222 // For each linkage item ...
23 for (ItemList::const_iterator I = Items.begin(), E = Items.end();
23 for (ItemList::const_iterator I = Items.begin(), E = Items.end();
2424 I != E; ++I) {
2525 if (I->second) {
2626 // Link in the library suggested.
3737 // that module should also be aggregated with duplicates eliminated. This is
3838 // now the time to process the dependent libraries to resolve any remaining
3939 // symbols.
40 for (Module::lib_iterator I = Composite->lib_begin(),
40 for (Module::lib_iterator I = Composite->lib_begin(),
4141 E = Composite->lib_end(); I != E; ++I)
4242 if(LinkInLibrary(*I))
4343 return true;
9494 // now the time to process the dependent libraries to resolve any remaining
9595 // symbols.
9696 const Module::LibraryListType& DepLibs = Composite->getLibraries();
97 for (Module::LibraryListType::const_iterator I = DepLibs.begin(),
98 E = DepLibs.end(); I != E; ++I)
99 if (LinkInLibrary(*I))
97 for (Module::LibraryListType::const_iterator I = DepLibs.begin(),
98 E = DepLibs.end(); I != E; ++I)
99 if (LinkInLibrary(*I))
100100 return true;
101101
102102 return false;
129129 verbose("Linking bytecode file '" + File.toString() + "'");
130130
131131 std::auto_ptr M(LoadObject(File));
132 if (M.get() == 0)
132 if (M.get() == 0)
133133 return error("Cannot load file '" + File.toString() + "'" + Error);
134134 if (LinkInModule(M.get()))
135135 return error("Cannot link file '" + File.toString() + "'" + Error);
0 //===- lib/Linker/LinkModules.cpp - Module Linker Implementation ----------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file implements the LLVM module linker.
9797 const Type *SrcTyT = SrcTy.get();
9898 const Type *DestTyT = DestTy.get();
9999 if (DestTyT == SrcTyT) return false; // If already equal, noop
100
100
101101 // If we found our opaque type, resolve it now!
102102 if (isa(DestTyT) || isa(SrcTyT))
103103 return ResolveTypes(DestTyT, SrcTyT, DestST, Name);
104
104
105105 // Two types cannot be resolved together if they are of different primitive
106106 // type. For example, we cannot resolve an int to a float.
107107 if (DestTyT->getTypeID() != SrcTyT->getTypeID()) return true;
122122 return false;
123123 }
124124 case Type::StructTyID: {
125 if (getST(DestTy)->getNumContainedTypes() !=
125 if (getST(DestTy)->getNumContainedTypes() !=
126126 getST(SrcTy)->getNumContainedTypes()) return 1;
127127 for (unsigned i = 0, e = getST(DestTy)->getNumContainedTypes(); i != e; ++i)
128128 if (RecursiveResolveTypesI(getST(DestTy)->getContainedType(i),
158158 return Result;
159159 }
160160 default: assert(0 && "Unexpected type!"); return true;
161 }
161 }
162162 }
163163
164164 static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
228228 if (!RecursiveResolveTypes(T2, T1, DestST, Name)) {
229229 // We are making progress!
230230 DelayedTypesToResolve.erase(DelayedTypesToResolve.begin()+i);
231
231
232232 // Go back to the main loop, perhaps we can resolve directly by name
233233 // now...
234234 break;
406406 } else {
407407 assert(Dest->hasExternalLinkage() && Src->hasExternalLinkage() &&
408408 "Unexpected linkage type!");
409 return Error(Err, "Linking globals named '" + Src->getName() +
409 return Error(Err, "Linking globals named '" + Src->getName() +
410410 "': symbol multiply defined!");
411411 }
412412 return false;
422422 // We will need a module level symbol table if the src module has a module
423423 // level symbol table...
424424 SymbolTable *ST = (SymbolTable*)&Dest->getSymbolTable();
425
425
426426 // Loop over all of the globals in the src module, mapping them over as we go
427427 for (Module::global_iterator I = Src->global_begin(), E = Src->global_end(); I != E; ++I) {
428428 GlobalVariable *SGV = I;
540540 Constant *SInit =
541541 cast(RemapOperand(SGV->getInitializer(), ValueMap));
542542
543 GlobalVariable *DGV = cast(ValueMap[SGV]);
543 GlobalVariable *DGV = cast(ValueMap[SGV]);
544544 if (DGV->hasInitializer()) {
545545 if (SGV->hasExternalLinkage()) {
546546 if (DGV->getInitializer() != SInit)
547 return Error(Err, "Global Variable Collision on '" +
547 return Error(Err, "Global Variable Collision on '" +
548548 ToStr(SGV->getType(), Src) +"':%"+SGV->getName()+
549549 " - Global variables have different initializers");
550550 } else if (DGV->hasLinkOnceLinkage() || DGV->hasWeakLinkage()) {
576576 std::map &GlobalsByName,
577577 std::string *Err) {
578578 SymbolTable *ST = (SymbolTable*)&Dest->getSymbolTable();
579
579
580580 // Loop over all of the functions in the src module, mapping them over as we
581581 // go
582582 for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
636636 "' have different linkage specifiers!");
637637 } else if (SF->hasExternalLinkage()) {
638638 // The function is defined in both modules!!
639 return Error(Err, "Function '" +
640 ToStr(SF->getFunctionType(), Src) + "':\"" +
639 return Error(Err, "Function '" +
640 ToStr(SF->getFunctionType(), Src) + "':\"" +
641641 SF->getName() + "\" - Function is already defined!");
642642 } else {
643643 assert(0 && "Unknown linkage configuration found!");
717717 std::multimap &AppendingVars,
718718 std::string *ErrorMsg) {
719719 if (AppendingVars.empty()) return false; // Nothing to do.
720
720
721721 // Loop over the multimap of appending vars, processing any variables with the
722722 // same name, forming a new appending global variable with both of the
723723 // initializers merged together, then rewrite references to the old variables
734734 GlobalVariable *G1 = First->second, *G2 = Second->second;
735735 const ArrayType *T1 = cast(G1->getType()->getElementType());
736736 const ArrayType *T2 = cast(G2->getType()->getElementType());
737
737
738738 // Check to see that they two arrays agree on type...
739739 if (T1->getElementType() != T2->getElementType())
740740 return Error(ErrorMsg,
802802 // error occurs, true is returned and ErrorMsg (if not null) is set to indicate
803803 // the problem. Upon failure, the Dest module could be in a modified state, and
804804 // shouldn't be relied on to be consistent.
805 bool
805 bool
806806 Linker::LinkModules(Module *Dest, Module *Src, std::string *ErrorMsg) {
807807 assert(Dest != 0 && "Invalid Destination module");
808808 assert(Src != 0 && "Invalid Source Module");
823823 if (!Src->getTargetTriple().empty() &&
824824 Dest->getTargetTriple() != Src->getTargetTriple())
825825 std::cerr << "WARNING: Linking two modules of different target triples!\n";
826
826
827827 // Update the destination module's dependent libraries list with the libraries
828828 // from the source module. There's no opportunity for duplicates here as the
829829 // Module ensures that duplicate insertions are discarded.
0 //===- lib/Linker/Linker.cpp - Basic Linker functionality ----------------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
4 // This file was developed by Reid Spencer and is distributed under the
4 // This file was developed by Reid Spencer and is distributed under the
55 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file contains basic Linker functionality that all usages will need.
4141 delete Composite;
4242 }
4343
44 bool
44 bool
4545 Linker::error(const std::string& message) {
4646 Error = message;
4747 if (!(Flags&QuietErrors)) {
9898 }
9999
100100 // LoadObject - Read in and parse the bytecode file named by FN and return the
101 // module it contains (wrapped in an auto_ptr), or auto_ptr() and set
101 // module it contains (wrapped in an auto_ptr), or auto_ptr() and set
102102 // Error if an error occurs.
103 std::auto_ptr
103 std::auto_ptr
104104 Linker::LoadObject(const sys::Path &FN) {
105105 std::string ParseErrorMessage;
106106 Module *Result = ParseBytecodeFile(FN.toString(), &ParseErrorMessage);
107 if (Result)
107 if (Result)
108108 return std::auto_ptr(Result);
109109 Error = "Bytecode file '" + FN.toString() + "' could not be loaded";
110 if (ParseErrorMessage.size())
110 if (ParseErrorMessage.size())
111111 Error += ": " + ParseErrorMessage;
112112 return std::auto_ptr();
113113 }
114114
115 // IsLibrary - Determine if "Name" is a library in "Directory". Return
115 // IsLibrary - Determine if "Name" is a library in "Directory". Return
116116 // a non-empty sys::Path if its found, an empty one otherwise.
117 static inline sys::Path IsLibrary(const std::string& Name,
117 static inline sys::Path IsLibrary(const std::string& Name,
118118 const sys::Path& Directory) {
119119
120120 assert(Directory.isDirectory() && "Need to specify a directory");
144144 /// FindLib - Try to convert Filename into the name of a file that we can open,
145145 /// if it does not already name a file we can open, by first trying to open
146146 /// Filename, then libFilename.[suffix] for each of a set of several common
147 /// library suffixes, in each of the directories in LibPaths. Returns an empty
147 /// library suffixes, in each of the directories in LibPaths. Returns an empty
148148 /// Path if no matching file can be found.
149149 ///
150 sys::Path
151 Linker::FindLib(const std::string &Filename)
150 sys::Path
151 Linker::FindLib(const std::string &Filename)
152152 {
153153 // Determine if the pathname can be found as it stands.
154154 sys::Path FilePath(Filename);
155 if (FilePath.readable() &&
155 if (FilePath.readable() &&
156156 (FilePath.isArchive() || FilePath.isDynamicLibrary()))
157157 return FilePath;
158158
0 //===-- Annotation.cpp - Implement the Annotation Classes -----------------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file implements the AnnotationManager class.
6666 void *Data) {
6767 AnnotationID Result(getID(Name));
6868 registerAnnotationFactory(Result, Fact, Data);
69 return Result;
69 return Result;
7070 }
7171
7272 // getName - This function is especially slow, but that's okay because it should
8181 }
8282
8383 // registerAnnotationFactory - This method is used to register a callback
84 // function used to create an annotation on demand if it is needed by the
84 // function used to create an annotation on demand if it is needed by the
8585 // Annotable::findOrCreateAnnotation method.
8686 //
8787 void AnnotationManager::registerAnnotationFactory(AnnotationID ID, AnnFactory F,
9595 // createAnnotation - Create an annotation of the specified ID for the
9696 // specified object, using a register annotation creation function.
9797 //
98 Annotation *AnnotationManager::createAnnotation(AnnotationID ID,
98 Annotation *AnnotationManager::createAnnotation(AnnotationID ID,
9999 const Annotable *Obj) {
100100 FactMapType::iterator I = getFactMap().find(ID.ID);
101101 if (I == getFactMap().end()) return 0;
0 //===-- CommandLine.cpp - Command line parser implementation --------------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This class implements a command line argument processor that is useful when
6767
6868 static void AddArgument(const char *ArgName, Option *Opt) {
6969 if (getOption(ArgName)) {
70 std::cerr << ProgramName << ": CommandLine Error: Argument '"
70 std::cerr << ProgramName << ": CommandLine Error: Argument '"
7171 << ArgName << "' defined more than once!\n";
7272 } else {
7373 // Add argument to the argument map!
7777
7878 // RemoveArgument - It's possible that the argument is no longer in the map if
7979 // options have already been processed and the map has been deleted!
80 //
80 //
8181 static void RemoveArgument(const char *ArgName, Option *Opt) {
8282 if(getOpts().empty()) return;
8383
106106 break;
107107 case ValueDisallowed:
108108 if (*Value != 0)
109 return Handler->error(" does not allow a value! '" +
109 return Handler->error(" does not allow a value! '" +
110110 std::string(Value) + "' specified.");
111111 break;
112 case ValueOptional:
112 case ValueOptional:
113113 break;
114 default:
115 std::cerr << ProgramName
116 << ": Bad ValueMask flag! CommandLine usage error:"
117 << Handler->getValueExpectedFlag() << "\n";
114 default:
115 std::cerr << ProgramName
116 << ": Bad ValueMask flag! CommandLine usage error:"
117 << Handler->getValueExpectedFlag() << "\n";
118118 abort();
119119 break;
120120 }
123123 return Handler->addOccurrence(i, ArgName, Value);
124124 }
125125
126 static bool ProvidePositionalOption(Option *Handler, const std::string &Arg,
126 static bool ProvidePositionalOption(Option *Handler, const std::string &Arg,
127127 int i) {
128128 int Dummy = i;
129129 return ProvideOption(Handler, Handler->ArgStr, Arg.c_str(), 0, 0, Dummy);
146146 //
147147 static Option *getOptionPred(std::string Name, unsigned &Length,
148148 bool (*Pred)(const Option*)) {
149
149
150150 Option *Op = getOption(Name);
151151 if (Op && Pred(Op)) {
152152 Length = Name.length();
235235 // Check args.
236236 assert(progName && "Program name not specified");
237237 assert(envVar && "Environment variable name missing");
238
238
239239 // Get the environment variable they want us to parse options out of.
240240 const char *envValue = getenv (envVar);
241241 if (!envValue)
264264 /// that as well.
265265 static Option *LookupOption(const char *&Arg, const char *&Value) {
266266 while (*Arg == '-') ++Arg; // Eat leading dashes
267
267
268268 const char *ArgEnd = Arg;
269269 while (*ArgEnd && *ArgEnd != '=')
270270 ++ArgEnd; // Scan till end of argument name...
272272 Value = ArgEnd;
273273 if (*Value) // If we have an equals sign...
274274 ++Value; // Advance to value...
275
275
276276 if (*Arg == 0) return 0;
277277
278278 // Look up the option.
365365 // All of the positional arguments have been fulfulled, give the rest to
366366 // the consume after option... if it's specified...
367367 //
368 if (PositionalVals.size() >= NumPositionalRequired &&
368 if (PositionalVals.size() >= NumPositionalRequired &&
369369 ConsumeAfterOpt != 0) {
370370 for (++i; i < argc; ++i)
371371 PositionalVals.push_back(std::make_pair(argv[i],i));
401401 if (RealName.size() > 1) {
402402 unsigned Length = 0;
403403 Option *PGOpt = getOptionPred(RealName, Length, isPrefixedOrGrouping);
404
404
405405 // If the option is a prefixed option, then the value is simply the
406406 // rest of the name... so fall through to later processing, by
407407 // setting up the argument name flags and value fields.
414414 } else if (PGOpt) {
415415 // This must be a grouped option... handle them now.
416416 assert(isGrouping(PGOpt) && "Broken getOptionPred!");
417
417
418418 do {
419419 // Move current arg name out of RealName into RealArgName...
420420 std::string RealArgName(RealName.begin(),
421421 RealName.begin() + Length);
422422 RealName.erase(RealName.begin(), RealName.begin() + Length);
423
423
424424 // Because ValueRequired is an invalid flag for grouped arguments,
425425 // we don't need to pass argc/argv in...
426426 //
429429 int Dummy;
430430 ErrorParsing |= ProvideOption(PGOpt, RealArgName.c_str(),
431431 "", 0, 0, Dummy);
432
432
433433 // Get the next grouping option...
434434 PGOpt = getOptionPred(RealName, Length, isGrouping);
435435 } while (PGOpt && Length != RealName.size());
436
436
437437 Handler = PGOpt; // Ate all of the options.
438438 }
439439 }
472472 // active one...
473473 if (Handler->getFormattingFlag() == cl::Positional)
474474 ActivePositionalArg = Handler;
475 else
475 else
476476 ErrorParsing |= ProvideOption(Handler, ArgName, Value, argc, argv, i);
477477 }
478478
479479 // Check and handle positional arguments now...
480480 if (NumPositionalRequired > PositionalVals.size()) {
481 std::cerr << ProgramName
481 std::cerr << ProgramName
482482 << ": Not enough positional command line arguments specified!\n"
483483 << "Must specify at least " << NumPositionalRequired
484484 << " positional arguments: See: " << argv[0] << " --help\n";
490490 unsigned ValNo = 0, NumVals = PositionalVals.size();
491491 for (unsigned i = 0, e = PositionalOpts.size(); i != e; ++i) {
492492 if (RequiresValue(PositionalOpts[i])) {
493 ProvidePositionalOption(PositionalOpts[i], PositionalVals[ValNo].first,
493 ProvidePositionalOption(PositionalOpts[i], PositionalVals[ValNo].first,
494494 PositionalVals[ValNo].second);
495495 ValNo++;
496496 --NumPositionalRequired; // We fulfilled our duty...
541541 PositionalVals[ValNo].second);
542542 ValNo++;
543543 }
544
544
545545 // Handle over all of the rest of the arguments to the
546546 // cl::ConsumeAfter command line option...
547547 for (; ValNo != PositionalVals.size(); ++ValNo)
551551 }
552552
553553 // Loop over args and make sure all required args are specified!
554 for (std::map::iterator I = Opts.begin(),
554 for (std::map::iterator I = Opts.begin(),
555555 E = Opts.end(); I != E; ++I) {
556556 switch (I->second->getNumOccurrencesFlag()) {
557557 case Required:
687687 return Len + 6;
688688 }
689689
690 // printOptionInfo - Print out information about this option. The
690 // printOptionInfo - Print out information about this option. The
691691 // to-be-maintained width is specified.
692692 //
693693 void basic_parser_impl::printOptionInfo(const Option &O,
708708 //
709709 bool parser::parse(Option &O, const char *ArgName,
710710 const std::string &Arg, bool &Value) {
711 if (Arg == "" || Arg == "true" || Arg == "TRUE" || Arg == "True" ||
711 if (Arg == "" || Arg == "true" || Arg == "TRUE" || Arg == "True" ||
712712 Arg == "1") {
713713 Value = true;
714714 } else if (Arg == "false" || Arg == "FALSE" || Arg == "False" || Arg == "0") {
726726 const std::string &Arg, int &Value) {
727727 char *End;
728728 Value = (int)strtol(Arg.c_str(), &End, 0);
729 if (*End != 0)
729 if (*End != 0)
730730 return O.error(": '" + Arg + "' value invalid for integer argument!");
731731 return false;
732732 }
752752 const char *ArgStart = Arg.c_str();
753753 char *End;
754754 Value = strtod(ArgStart, &End);
755 if (*End != 0)
755 if (*End != 0)
756756 return O.error(": '" +Arg+ "' value invalid for floating point argument!");
757757 return false;
758758 }
807807 }
808808 }
809809
810 // printOptionInfo - Print out information about this option. The
810 // printOptionInfo - Print out information about this option. The
811811 // to-be-maintained width is specified.
812812 //
813813 void generic_parser_base::printOptionInfo(const Option &O,
824824 }
825825 } else {
826826 if (O.HelpStr[0])
827 std::cerr << " " << O.HelpStr << "\n";
827 std::cerr << " " << O.HelpStr << "\n";
828828 for (unsigned i = 0, e = getNumOptions(); i != e; ++i) {
829829 unsigned L = std::strlen(getOption(i));
830830 std::cerr << " -" << getOption(i) << std::string(GlobalWidth-L-8, ' ')
866866 copy(getOpts().begin(), getOpts().end(), std::back_inserter(Options));
867867
868868 // Eliminate Hidden or ReallyHidden arguments, depending on ShowHidden
869 Options.erase(std::remove_if(Options.begin(), Options.end(),
869 Options.erase(std::remove_if(Options.begin(), Options.end(),
870870 std::ptr_fun(ShowHidden ? isReallyHidden : isHidden)),
871871 Options.end());
872872
927927 public:
928928 void operator=(bool OptionWasSpecified) {
929929 if (OptionWasSpecified) {
930 std::cerr << "Low Level Virtual Machine (" << PACKAGE_NAME << ") "
930 std::cerr << "Low Level Virtual Machine (" << PACKAGE_NAME << ") "
931931 << PACKAGE_VERSION << " (see http://llvm.cs.uiuc.edu/)\n";
932932 getOpts().clear(); // Don't bother making option dtors remove from map.
933933 exit(1);
942942 HelpPrinter NormalPrinter(false);
943943 HelpPrinter HiddenPrinter(true);
944944
945 cl::opt >
945 cl::opt >
946946 HOp("help", cl::desc("display available options (--help-hidden for more)"),
947947 cl::location(NormalPrinter), cl::ValueDisallowed);
948948
953953 // Define the --version option that prints out the LLVM version for the tool
954954 VersionPrinter VersionPrinterInstance;
955955 cl::opt >
956 VersOp("version", cl::desc("display the version"),
956 VersOp("version", cl::desc("display the version"),
957957 cl::location(VersionPrinterInstance), cl::ValueDisallowed);
958958
959959
961961
962962 // Utility function for printing the help message.
963963 void cl::PrintHelpMessage() {
964 // This looks weird, but it actually prints the help message. The
964 // This looks weird, but it actually prints the help message. The
965965 // NormalPrinter variable is a HelpPrinter and the help gets printed when
966966 // its operator= is invoked. That's because the "normal" usages of the
967 // help printer is to be assigned true/false depending on whether the
967 // help printer is to be assigned true/false depending on whether the
968968 // --help option was given or not. Since we're circumventing that we have
969969 // to make it look like --help was given, so we assign true.
970970 NormalPrinter = true;
0 //===- lib/Support/Compressor.cpp -------------------------------*- C++ -*-===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
4 // This file was developed by Reid Spencer and is distributed under the
4 // This file was developed by Reid Spencer and is distributed under the
55 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file implements the llvm::Compressor class, an abstraction for memory
2525 COMP_TYPE_BZIP2 = '2',
2626 };
2727
28 static int getdata(char*& buffer, size_t &size,
28 static int getdata(char*& buffer, size_t &size,
2929 llvm::Compressor::OutputDataCallback* cb, void* context) {
3030 buffer = 0;
3131 size = 0;
3535 return result;
3636 }
3737
38 static int getdata_uns(char*& buffer, unsigned &size,
38 static int getdata_uns(char*& buffer, unsigned &size,
3939 llvm::Compressor::OutputDataCallback* cb, void* context) {
4040 size_t SizeOut;
4141 int Res = getdata(buffer, SizeOut, cb, context);
4444 }
4545
4646 //===----------------------------------------------------------------------===//
47 //=== NULLCOMP - a compression like set of routines that just copies data
47 //=== NULLCOMP - a compression like set of routines that just copies data
4848 //=== without doing any compression. This is provided so that if the
4949 //=== configured environment doesn't have a compression library the
5050 //=== program can still work, albeit using more data/memory.
120120
121121 /// This structure is only used when a bytecode file is compressed.
122122 /// As bytecode is being decompressed, the memory buffer might need
123 /// to be reallocated. The buffer allocation is handled in a callback
123 /// to be reallocated. The buffer allocation is handled in a callback
124124 /// and this structure is needed to retain information across calls
125125 /// to the callback.
126126 /// @brief An internal buffer object used for handling decompression
127127 struct BufferContext {
128128 char* buff;
129129 size_t size;
130 BufferContext(size_t compressedSize) {
130 BufferContext(size_t compressedSize) {
131131 // Null to indicate malloc of a new block
132 buff = 0;
132 buff = 0;
133133
134134 // Compute the initial length of the uncompression buffer. Note that this
135135 // is twice the length of the compressed buffer and will be doubled again
136 // in the callback for an initial allocation of 4x compressedSize. This
137 // calculation is based on the typical compression ratio of bzip2 on LLVM
138 // bytecode files which typically ranges in the 50%-75% range. Since we
139 // typically get at least 50%, doubling is insufficient. By using a 4x
136 // in the callback for an initial allocation of 4x compressedSize. This
137 // calculation is based on the typical compression ratio of bzip2 on LLVM
138 // bytecode files which typically ranges in the 50%-75% range. Since we
139 // typically get at least 50%, doubling is insufficient. By using a 4x
140140 // multiplier on the first allocation, we minimize the impact of having to
141141 // copy the buffer on reallocation.
142 size = compressedSize*2;
142 size = compressedSize*2;
143143 }
144144
145145 /// trimTo - Reduce the size of the buffer down to the specified amount. This
153153
154154 /// This function handles allocation of the buffer used for decompression of
155155 /// compressed bytecode files. It is called by Compressor::decompress which is
156 /// called by BytecodeReader::ParseBytecode.
156 /// called by BytecodeReader::ParseBytecode.
157157 static size_t callback(char*&buff, size_t &sz, void* ctxt){
158158 // Case the context variable to our BufferContext
159159 BufferContext* bc = reinterpret_cast(ctxt);
167167 // Figure out what to return to the Compressor. If this is the first call,
168168 // then bc->buff will be null. In this case we want to return the entire
169169 // buffer because there was no previous allocation. Otherwise, when the
170 // buffer is reallocated, we save the new base pointer in the
171 // BufferContext.buff field but return the address of only the extension,
172 // mid-way through the buffer (since its size was doubled). Furthermore,
170 // buffer is reallocated, we save the new base pointer in the
171 // BufferContext.buff field but return the address of only the extension,
172 // mid-way through the buffer (since its size was doubled). Furthermore,
173173 // the sz result must be 1/2 the total size of the buffer.
174174 if (bc->buff == 0 ) {
175175 buff = bc->buff = new_buff;
188188 }
189189 };
190190
191 } // end anonymous namespace
191 } // end anonymous namespace
192192
193193
194194 namespace {
195195
196196 // This structure retains the context when compressing the bytecode file. The
197197 // WriteCompressedData function below uses it to keep track of the previously
198 // filled chunk of memory (which it writes) and how many bytes have been
198 // filled chunk of memory (which it writes) and how many bytes have been
199199 // written.
200200 struct WriterContext {
201201 // Initialize the context
202 WriterContext(std::ostream*OS, size_t CS)
202 WriterContext(std::ostream*OS, size_t CS)
203203 : chunk(0), sz(0), written(0), compSize(CS), Out(OS) {}
204204
205205 // Make sure we clean up memory
218218 sz = 0;
219219 }
220220
221 // This function is a callback used by the Compressor::compress function to
221 // This function is a callback used by the Compressor::compress function to
222222 // allocate memory for the compression buffer. This function fulfills that
223223 // responsibility but also writes the previous (now filled) buffer out to the
224 // stream.
224 // stream.
225225 static size_t callback(char*& buffer, size_t &size, void* context) {
226226 // Cast the context to the structure it must point to.
227227 WriterContext* ctxt = reinterpret_cast(context);
258258 } // end anonymous namespace
259259
260260 // Compress in one of three ways
261 size_t Compressor::compress(const char* in, size_t size,
261 size_t Compressor::compress(const char* in, size_t size,
262262 OutputDataCallback* cb, void* context) {
263263 assert(in && "Can't compress null buffer");
264264 assert(size && "Can't compress empty buffer");
354354 return result;
355355 }
356356
357 size_t
357 size_t
358358 Compressor::compressToStream(const char*in, size_t size, std::ostream& out) {
359359 // Set up the context and writer
360360 WriterContext ctxt(&out, size / 2);
459459 return result;
460460 }
461461
462 size_t
462 size_t
463463 Compressor::decompressToNewBuffer(const char* in, size_t size, char*&out) {
464464 BufferContext bc(size);
465465 size_t result = decompress(in,size,BufferContext::callback,(void*)&bc);
467467 return result;
468468 }
469469
470 size_t
470 size_t
471471 Compressor::decompressToStream(const char*in, size_t size, std::ostream& out){
472472 // Set up the context and writer
473473 WriterContext ctxt(&out,size / 2);
0 //===-- Debug.cpp - An easy way to add debug output to your code ----------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file implements a handle way of adding debugging information to your
0 //===- Support/FileUtilities.cpp - File System Utilities ------------------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file implements a family of utility functions which are useful for doing
2323 static bool isNumberChar(char C) {
2424 switch (C) {
2525 case '0': case '1': case '2': case '3': case '4':
26 case '5': case '6': case '7': case '8': case '9':
26 case '5': case '6': case '7': case '8': case '9':
2727 case '.': case '+': case '-':
2828 case 'e':
2929 case 'E': return true;
4646 double AbsTolerance, double RelTolerance,
4747 std::string *ErrorMsg) {
4848 char *F1NumEnd, *F2NumEnd;
49 double V1 = 0.0, V2 = 0.0;
49 double V1 = 0.0, V2 = 0.0;
5050
5151 // If one of the positions is at a space and the other isn't, chomp up 'til
5252 // the end of the space.
141141 return 1;
142142
143143 // Now its safe to mmap the files into memory becasue both files
144 // have a non-zero size.
144 // have a non-zero size.
145145 sys::MappedFile F1(FileA);
146146 sys::MappedFile F2(FileB);
147147 F1.map();
170170 // If the files need padding, do so now.
171171 PadFileIfNeeded(File1Start, File1End, F1P);
172172 PadFileIfNeeded(File2Start, File2End, F2P);
173
173
174174 bool CompareFailed = false;
175175 while (1) {
176176 // Scan for the end of file or next difference.
0 //===-- IsInf.cpp - Platform-independent wrapper around C99 isinf() -------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88
99 #include "llvm/Config/config.h"
2525 #define isinf(X) (!_finite(X))
2626 #elif defined(_AIX) && defined(__GNUC__)
2727 // GCC's fixincludes seems to be removing the isinf() declaration from the
28 // system header /usr/include/math.h
28 // system header /usr/include/math.h
2929 # include
3030 static int isinf(double x) { return !finite(x) && x==x; }
3131 #else
0 //===-- IsNAN.cpp ---------------------------------------------------------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
9 // Platform-independent wrapper around C99 isnan().
9 // Platform-independent wrapper around C99 isnan().
1010 //
1111 //===----------------------------------------------------------------------===//
1212
0 //===-- PluginLoader.cpp - Implement -load command line option ------------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file implements the -load command line option handler.
0 //===-- SlowOperationInformer.cpp - Keep the user informed ----------------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
8 //
8 //
99 // This file implements the SlowOperationInformer class for the LLVM debugger.
1010 //
1111 //===----------------------------------------------------------------------===//
0 //===-- Statistic.cpp - Easy way to expose stats information --------------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file implements the 'Statistic' class, which is designed to be an easy
7777 // Figure out how long the biggest Value and Name fields are...
7878 unsigned MaxNameLen = 0, MaxValLen = 0;
7979 for (unsigned i = 0, e = AccumStats->size(); i != e; ++i) {
80 MaxValLen = std::max(MaxValLen,
80 MaxValLen = std::max(MaxValLen,
8181 (unsigned)(*AccumStats)[i].Value.length());
82 MaxNameLen = std::max(MaxNameLen,
82 MaxNameLen = std::max(MaxNameLen,
8383 (unsigned)std::strlen((*AccumStats)[i].Name));
8484 }
8585
0 //===-- StringExtras.cpp - Implement the StringExtras header --------------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file implements the StringExtras.h header
3434
3535 // Create the return token.
3636 std::string Result = std::string(Source.begin()+Start, Source.begin()+End);
37
37
3838 // Erase the token that we read in.
3939 Source.erase(Source.begin(), Source.begin()+End);
40
40
4141 return Result;
4242 }
0 //===- SystemUtils.cpp - Utilities for low-level system tasks -------------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file contains functions used to do a variety of low-level, often
4141 #undef FindExecutable // needed on windows :(
4242 sys::Path llvm::FindExecutable(const std::string &ExeName,
4343 const std::string &ProgramPath) {
44 // First check the directory that the calling program is in. We can do this
44 // First check the directory that the calling program is in. We can do this
4545 // if ProgramPath contains at least one / character, indicating that it is a
4646 // relative path to bugpoint itself.
4747 sys::Path Result ( ProgramPath );
4848 Result.elideFile();
4949 if (!Result.isEmpty()) {
5050 Result.appendFile(ExeName);
51 if (Result.executable())
51 if (Result.executable())
5252 return Result;
5353 }
5454
0 //===-- Timer.cpp - Interval Timing Support -------------------------------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // Interval Timing implementation.
237237 if (Total.getProcessTime())
238238 printVal(getProcessTime(), Total.getProcessTime(), OS);
239239 printVal(Elapsed, Total.Elapsed, OS);
240
240
241241 OS << " ";
242242
243243 if (Total.MemUsed) {
293293 { // Scope to contain Total timer... don't allow total timer to drop us to
294294 // zero timers...
295295 Timer Total("TOTAL");
296
296
297297 for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i)
298298 Total.sum(TimersToPrint[i]);
299
299
300300 // Print out timing header...
301301 *OutStream << "===" << std::string(73, '-') << "===\n"
302302 << std::string(Padding, ' ') << Name << "\n"
328328 if (Total.getPeakMem())
329329 *OutStream << " -PeakMem-";
330330 *OutStream << " --- Name ---\n";
331
331
332332 // Loop through all of the timing data, printing it out...
333333 for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i)
334334 TimersToPrint[i].print(Total, *OutStream);
335
335
336336 Total.print(Total, *OutStream);
337337 *OutStream << std::endl; // Flush output
338338 }
0 //===-- ToolRunner.cpp ----------------------------------------------------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file implements the interfaces described in the ToolRunner.h file.
3535 redirects[0] = &StdInFile;
3636 redirects[1] = &StdOutFile;
3737 redirects[2] = &StdErrFile;
38
39 return
38
39 return
4040 sys::Program::ExecuteAndWait(ProgramPath, Args, 0, redirects, NumSeconds);
4141 }
4242
8181 ToolArgs.clear ();
8282 if (Args) { ToolArgs = *Args; }
8383 }
84
84
8585 virtual int ExecuteProgram(const std::string &Bytecode,
8686 const std::vector &Args,
8787 const std::string &InputFile,
8888 const std::string &OutputFile,
89 const std::vector &SharedLibs =
89 const std::vector &SharedLibs =
9090 std::vector(),
9191 unsigned Timeout = 0);
9292 };
123123 std::cerr << "\n";
124124 );
125125 return RunProgramWithTimeout(sys::Path(LLIPath), &LLIArgs[0],
126 sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
126 sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
127127 Timeout);
128128 }
129129
167167 std::cerr << " " << LLCArgs[i];
168168 std::cerr << "\n";
169169 );
170 if (RunProgramWithTimeout(sys::Path(LLCPath), &LLCArgs[0],
170 if (RunProgramWithTimeout(sys::Path(LLCPath), &LLCArgs[0],
171171 sys::Path(), sys::Path(), sys::Path()))
172172 ProcessFailure(sys::Path(LLCPath), &LLCArgs[0]);
173173 }
227227 ToolArgs.clear ();
228228 if (Args) { ToolArgs = *Args; }
229229 }
230
230
231231 virtual int ExecuteProgram(const std::string &Bytecode,
232232 const std::vector &Args,
233233 const std::string &InputFile,
234234 const std::string &OutputFile,
235 const std::vector &SharedLibs =
235 const std::vector &SharedLibs =
236236 std::vector(), unsigned Timeout =0);
237237 };
238238 }
270270 );
271271 DEBUG(std::cerr << "\nSending output to " << OutputFile << "\n");
272272 return RunProgramWithTimeout(sys::Path(LLIPath), &JITArgs[0],
273 sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
273 sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
274274 Timeout);
275275 }
276276
312312 std::cerr << " " << LLCArgs[i];
313313 std::cerr << "\n";
314314 );
315 if (RunProgramWithTimeout(LLCPath, &LLCArgs[0], sys::Path(), sys::Path(),
315 if (RunProgramWithTimeout(LLCPath, &LLCArgs[0], sys::Path(), sys::Path(),
316316 sys::Path()))
317317 ProcessFailure(LLCPath, &LLCArgs[0]);
318318 }
334334
335335 FileRemover CFileRemove(OutputCFile);
336336
337 return gcc->ExecuteProgram(OutputCFile.toString(), Args, GCC::CFile,
337 return gcc->ExecuteProgram(OutputCFile.toString(), Args, GCC::CFile,
338338 InputFile, OutputFile, SharedLibs, Timeout);
339339 }
340340
345345 const std::vector *Args) {
346346 sys::Path LLCPath = FindExecutable("llc", ProgramPath);
347347 if (LLCPath.isEmpty()) {
348 Message =
348 Message =
349349 "Cannot find `llc' in executable directory or PATH!\n";
350350 return 0;
351351 }
376376 // Specify the shared libraries to link in...
377377 for (unsigned i = 0, e = SharedLibs.size(); i != e; ++i)
378378 GCCArgs.push_back(SharedLibs[i].c_str());
379
379
380380 // Specify -x explicitly in case the extension is wonky
381381 GCCArgs.push_back("-x");
382382 if (fileType == CFile) {
422422
423423 FileRemover OutputBinaryRemover(OutputBinary);
424424 return RunProgramWithTimeout(OutputBinary, &ProgramArgs[0],
425 sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
425 sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
426426 Timeout);
427427 }
428428
457457 "-O2", // Optimize the program a bit...
458458 0
459459 };
460
460
461461 std::cout << "" << std::flush;
462 if (RunProgramWithTimeout(GCCPath, GCCArgs, sys::Path(), sys::Path(),
462 if (RunProgramWithTimeout(GCCPath, GCCArgs, sys::Path(), sys::Path(),
463463 sys::Path())) {
464464 ProcessFailure(GCCPath, GCCArgs);
465465 return 1;
1616 1. Redistributions of source code must retain the above copyright
1717 notice, this list of conditions and the following disclaimer.
1818
19 2. The origin of this software must not be misrepresented; you must
20 not claim that you wrote the original software. If you use this
21 software in a product, an acknowledgment in the product
19 2. The origin of this software must not be misrepresented; you must
20 not claim that you wrote the original software. If you use this
21 software in a product, an acknowledgment in the product
2222 documentation would be appreciated but is not required.
2323
2424 3. Altered source versions must be plainly marked as such, and must
2525 not be misrepresented as being the original software.
2626
27 4. The name of the author may not be used to endorse or promote
28 products derived from this software without specific prior written
27 4. The name of the author may not be used to endorse or promote
28 products derived from this software without specific prior written
2929 permission.
3030
3131 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
8484 #define BZ_OUTBUFF_FULL (-8)
8585 #define BZ_CONFIG_ERROR (-9)
8686
87 typedef
87 typedef
8888 struct {
8989 char *next_in;
9090 unsigned int avail_in;
101101 void *(*bzalloc)(void *,int,int);
102102 void (*bzfree)(void *,void *);
103103 void *opaque;
104 }
104 }
105105 bz_stream;
106106
107107
134134
135135 /*-- Core (low-level) library functions --*/
136136
137 BZ_EXTERN int BZ_API(BZ2_bzCompressInit) (
138 bz_stream* strm,
139 int blockSize100k,
140 int verbosity,
141 int workFactor
142 );
143
144 BZ_EXTERN int BZ_API(BZ2_bzCompress) (
145 bz_stream* strm,
146 int action
147 );
148
149 BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) (
150 bz_stream* strm
151 );
152
153 BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) (
154 bz_stream *strm,
155 int verbosity,
137 BZ_EXTERN int BZ_API(BZ2_bzCompressInit) (
138 bz_stream* strm,
139 int blockSize100k,
140 int verbosity,
141 int workFactor
142 );
143
144 BZ_EXTERN int BZ_API(BZ2_bzCompress) (
145 bz_stream* strm,
146 int action
147 );
148
149 BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) (
150 bz_stream* strm
151 );
152
153 BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) (
154 bz_stream *strm,
155 int verbosity,
156156 int small
157157 );
158158
159 BZ_EXTERN int BZ_API(BZ2_bzDecompress) (
160 bz_stream* strm
161 );
162
163 BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) (
164 bz_stream *strm
159 BZ_EXTERN int BZ_API(BZ2_bzDecompress) (
160 bz_stream* strm
161 );
162
163 BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) (
164 bz_stream *strm
165165 );
166166
167167
173173
174174 typedef void BZFILE;
175175
176 BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) (
177 int* bzerror,
178 FILE* f,
179 int verbosity,
176 BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) (
177 int* bzerror,
178 FILE* f,
179 int verbosity,
180180 int small,
181 void* unused,
182 int nUnused
183 );
184
185 BZ_EXTERN void BZ_API(BZ2_bzReadClose) (
186 int* bzerror,
187 BZFILE* b
188 );
189
190 BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) (
191 int* bzerror,
192 BZFILE* b,
193 void** unused,
194 int* nUnused
195 );
196
197 BZ_EXTERN int BZ_API(BZ2_bzRead) (
198 int* bzerror,
199 BZFILE* b,
200 void* buf,
201 int len
202 );
203
204 BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) (
205 int* bzerror,
206 FILE* f,
207 int blockSize100k,
208 int verbosity,
209 int workFactor
210 );
211
212 BZ_EXTERN void BZ_API(BZ2_bzWrite) (
213 int* bzerror,
214 BZFILE* b,
215 void* buf,
216 int len
217 );
218
219 BZ_EXTERN void BZ_API(BZ2_bzWriteClose) (
220 int* bzerror,
221 BZFILE* b,
222 int abandon,
223 unsigned int* nbytes_in,
224 unsigned int* nbytes_out
225 );
226
227 BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) (
228 int* bzerror,
229 BZFILE* b,
230 int abandon,
231 unsigned int* nbytes_in_lo32,
232 unsigned int* nbytes_in_hi32,
233 unsigned int* nbytes_out_lo32,
181 void* unused,
182 int nUnused
183 );
184
185 BZ_EXTERN void BZ_API(BZ2_bzReadClose) (
186 int* bzerror,
187 BZFILE* b
188 );
189
190 BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) (
191 int* bzerror,
192 BZFILE* b,
193 void** unused,
194 int* nUnused
195 );
196
197 BZ_EXTERN int BZ_API(BZ2_bzRead) (
198 int* bzerror,
199 BZFILE* b,
200 void* buf,
201 int len
202 );
203
204 BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) (
205 int* bzerror,
206 FILE* f,
207 int blockSize100k,
208 int verbosity,
209 int workFactor
210 );
211
212 BZ_EXTERN void BZ_API(BZ2_bzWrite) (
213 int* bzerror,
214 BZFILE* b,
215 void* buf,
216 int len
217 );
218
219 BZ_EXTERN void BZ_API(BZ2_bzWriteClose) (
220 int* bzerror,
221 BZFILE* b,
222 int abandon,
223 unsigned int* nbytes_in,
224 unsigned int* nbytes_out
225 );
226
227 BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) (
228 int* bzerror,
229 BZFILE* b,
230 int abandon,
231 unsigned int* nbytes_in_lo32,
232 unsigned int* nbytes_in_hi32,
233 unsigned int* nbytes_out_lo32,
234234 unsigned int* nbytes_out_hi32
235235 );
236236 #endif
238238
239239 /*-- Utility functions --*/
240240
241 BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) (
242 char* dest,
241 BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) (
242 char* dest,
243243 unsigned int* destLen,
244 char* source,
244 char* source,
245245 unsigned int sourceLen,
246 int blockSize100k,
247 int verbosity,
248 int workFactor
249 );
250
251 BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) (
252 char* dest,
246 int blockSize100k,
247 int verbosity,
248 int workFactor
249 );
250
251 BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) (
252 char* dest,
253253 unsigned int* destLen,
254 char* source,
254 char* source,
255255 unsigned int sourceLen,
256 int small,
257 int verbosity
256 int small,
257 int verbosity
258258 );
259259
260260
282282 int fd,
283283 const char *mode
284284 );
285
285
286286 BZ_EXTERN int BZ_API(BZ2_bzread) (
287 BZFILE* b,
288 void* buf,
289 int len
287 BZFILE* b,
288 void* buf,
289 int len
290290 );
291291
292292 BZ_EXTERN int BZ_API(BZ2_bzwrite) (
293 BZFILE* b,
294 void* buf,
295 int len
293 BZFILE* b,
294 void* buf,
295 int len
296296 );
297297
298298 BZ_EXTERN int BZ_API(BZ2_bzflush) (
304304 );
305305
306306 BZ_EXTERN const char * BZ_API(BZ2_bzerror) (
307 BZFILE *b,
307 BZFILE *b,
308308 int *errnum
309309 );
310310 #endif
1616 1. Redistributions of source code must retain the above copyright
1717 notice, this list of conditions and the following disclaimer.
1818
19 2. The origin of this software must not be misrepresented; you must
20 not claim that you wrote the original software. If you use this
21 software in a product, an acknowledgment in the product
19 2. The origin of this software must not be misrepresented; you must
20 not claim that you wrote the original software. If you use this
21 software in a product, an acknowledgment in the product
2222 documentation would be appreciated but is not required.
2323
2424 3. Altered source versions must be plainly marked as such, and must
2525 not be misrepresented as being the original software.
2626
27 4. The name of the author may not be used to endorse or promote
28 products derived from this software without specific prior written
27 4. The name of the author may not be used to endorse or promote
28 products derived from this software without specific prior written
2929 permission.
3030
3131 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
9090
9191 #ifndef __GNUC__
9292 #define __inline__ /* */
93 #endif
93 #endif
9494
9595 #ifndef BZ_NO_STDIO
9696 extern void BZ2_bz__AssertH__fail ( int errcode );
142142 #define BZ_HDR_Z 0x5a /* 'Z' */
143143 #define BZ_HDR_h 0x68 /* 'h' */
144144 #define BZ_HDR_0 0x30 /* '0' */
145
145
146146 /*-- Constants for the back end. --*/
147147
148148 #define BZ_MAX_ALPHA_SIZE 258
302302
303303 /*-- externs for compression. --*/
304304
305 extern void
305 extern void
306306 BZ2_blockSort ( EState* );
307307
308 extern void
308 extern void
309309 BZ2_compressBlock ( EState*, Bool );
310310
311 extern void
311 extern void
312312 BZ2_bsInitWrite ( EState* );
313313
314 extern void
314 extern void
315315 BZ2_hbAssignCodes ( Int32*, UChar*, Int32, Int32, Int32 );
316316
317 extern void
317 extern void
318318 BZ2_hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 );
319319
320320
458458 Int32 save_N;
459459 Int32 save_curr;
460460 Int32 save_zt;
461 Int32 save_zn;
461 Int32 save_zn;
462462 Int32 save_zvec;
463463 Int32 save_zj;
464464 Int32 save_gSel;
508508
509509 /*-- externs for decompression. --*/
510510
511 extern Int32
511 extern Int32
512512 BZ2_indexIntoF ( Int32, Int32* );
513513
514 extern Int32
514 extern Int32
515515 BZ2_decompress ( DState* );
516516
517 extern void
517 extern void
518518 BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*,
519519 Int32, Int32, Int32 );
520520
0 //===-- DynamicLibrary.cpp - Runtime link/load libraries --------*- C++ -*-===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
4 // This file was developed by Reid Spencer and is distributed under the
4 // This file was developed by Reid Spencer and is distributed under the
55 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This header file implements the operating system DynamicLibrary concept.
3232
3333 //===----------------------------------------------------------------------===//
3434 //=== WARNING: Implementation here must contain only TRULY operating system
35 //=== independent code.
35 //=== independent code.
3636 //===----------------------------------------------------------------------===//
3737
3838 static bool did_initialize_ltdl = false;
5454
5555 if (a_handle == 0)
5656 throw std::string("Can't open program as dynamic library");
57
57
5858 handle = a_handle;
5959 OpenedHandles.push_back(a_handle);
6060 }
0 //===- MappedFile.cpp - MappedFile Support ----------------------*- C++ -*-===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
4 // This file was developed by Reid Spencer and is distributed under the
4 // This file was developed by Reid Spencer and is distributed under the
55 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file implements the mapped file concept.
1818
1919 //===----------------------------------------------------------------------===//
2020 //=== WARNING: Implementation here must contain only TRULY operating system
21 //=== independent code.
21 //=== independent code.
2222 //===----------------------------------------------------------------------===//
2323
2424 }
0 //===- Memory.cpp - Memory Handling Support ---------------------*- C++ -*-===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
4 // This file was developed by Reid Spencer and is distributed under the
4 // This file was developed by Reid Spencer and is distributed under the
55 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file defines some helpful functions for allocating memory and dealing
1919
2020 //===----------------------------------------------------------------------===//
2121 //=== WARNING: Implementation here must contain only TRULY operating system
22 //=== independent code.
22 //=== independent code.
2323 //===----------------------------------------------------------------------===//
2424
2525 }
0 //===-- Path.cpp - Implement OS Path Concept --------------------*- C++ -*-===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
4 // This file was developed by Reid Spencer and is distributed under the
4 // This file was developed by Reid Spencer and is distributed under the
55 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This header file implements the operating system Path concept.
1919
2020 //===----------------------------------------------------------------------===//
2121 //=== WARNING: Implementation here must contain only TRULY operating system
22 //=== independent code.
22 //=== independent code.
2323 //===----------------------------------------------------------------------===//
2424
2525 Path
3232 return GetLLVMDefaultConfigDir();
3333 }
3434
35 LLVMFileType
35 LLVMFileType
3636 sys::IdentifyFileType(const char*magic, unsigned length) {
3737 assert(magic && "Invalid magic number string");
3838 assert(length >=4 && "Invalid magic number length");
6868
6969 bool
7070 Path::isDynamicLibrary() const {
71 if (readable())
71 if (readable())
7272 return hasMagicNumber("\177ELF");
7373 return false;
7474 }
0 //===-- Process.cpp - Implement OS Process Concept --------------*- C++ -*-===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
4 // This file was developed by Reid Spencer and is distributed under the
4 // This file was developed by Reid Spencer and is distributed under the
55 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This header file implements the operating system Process concept.
1818
1919 //===----------------------------------------------------------------------===//
2020 //=== WARNING: Implementation here must contain only TRULY operating system
21 //=== independent code.
21 //=== independent code.
2222 //===----------------------------------------------------------------------===//
2323
2424 }
0 //===-- Program.cpp - Implement OS Program Concept --------------*- C++ -*-===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
4 // This file was developed by Reid Spencer and is distributed under the
4 // This file was developed by Reid Spencer and is distributed under the
55 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This header file implements the operating system Program concept.
1818
1919 //===----------------------------------------------------------------------===//
2020 //=== WARNING: Implementation here must contain only TRULY operating system
21 //=== independent code.
21 //=== independent code.
2222 //===----------------------------------------------------------------------===//
2323
2424 }
0 //===- Signals.cpp - Signal Handling support --------------------*- C++ -*-===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file defines some helpful functions for dealing with the possibility of
1919
2020 //===----------------------------------------------------------------------===//
2121 //=== WARNING: Implementation here must contain only TRULY operating system
22 //=== independent code.
22 //=== independent code.
2323 //===----------------------------------------------------------------------===//
2424
2525 }
0 //===-- TimeValue.cpp - Implement OS TimeValue Concept ----------*- C++ -*-===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
4 // This file was developed by Reid Spencer and is distributed under the
4 // This file was developed by Reid Spencer and is distributed under the
55 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file implements the operating system TimeValue concept.
0 //===- Unix/SUS/Process.cpp - Linux Process Implementation ---- -*- C++ -*-===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
4 // This file was developed by Reid Spencer and is distributed under the
4 // This file was developed by Reid Spencer and is distributed under the
55 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file provides the Linux specific implementation of the Process class.
1313 #include
1414
1515 //===----------------------------------------------------------------------===//
16 //=== WARNING: Implementation here must contain only code specific to the
16 //=== WARNING: Implementation here must contain only code specific to the
1717 //=== SUS (Single Unix Specification).
1818 //===----------------------------------------------------------------------===//
1919
2020 namespace llvm {
2121 using namespace sys;
2222
23 unsigned
23 unsigned
2424 Process::GetPageSize() {
2525 static const long page_size = sysconf(_SC_PAGE_SIZE);
2626 return static_cast(page_size);
0 //===- llvm/System/Unix/Unix.h - Common Unix Include File -------*- C++ -*-===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
4 // This file was developed by Reid Spencer and is distributed under the
4 // This file was developed by Reid Spencer and is distributed under the
55 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file defines things specific to Unix implementations.
3636
3737 #ifdef HAVE_SYS_PARAM_H
3838 #include
39 #endif
39 #endif
4040
4141 #ifdef HAVE_ASSERT_H
4242 #include
0 //===- Win32/Win32.h - Common Win32 Include File ----------------*- C++ -*-===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
4 // This file was developed by Reid Spencer and is distributed under the
4 // This file was developed by Reid Spencer and is distributed under the
55 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file defines things specific to Unix implementations.
0 //===- MRegisterInfo.cpp - Target Register Information Implementation -----===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file implements the MRegisterInfo interface.
3737 Allocatable[*I] = true;
3838 }
3939 return Allocatable;
40 }
40 }
4141
4242 } // End llvm namespace
0 //===-- TargetData.cpp - Data size & alignment routines --------------------==//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file defines target properties related to datatype size/offset/alignment
4242 StructSize = 0;
4343
4444 // Loop over each of the elements, placing them in memory...
45 for (StructType::element_iterator TI = ST->element_begin(),
45 for (StructType::element_iterator TI = ST->element_begin(),
4646 TE = ST->element_end(); TI != TE; ++TI) {
4747 const Type *Ty = *TI;
4848 unsigned char A;
9494 TargetData::TargetData(const std::string &TargetName,
9595 bool isLittleEndian, unsigned char PtrSize,
9696 unsigned char PtrAl, unsigned char DoubleAl,
97 unsigned char FloatAl, unsigned char LongAl,
97 unsigned char FloatAl, unsigned char LongAl,
9898 unsigned char IntAl, unsigned char ShortAl,
9999 unsigned char ByteAl, unsigned char BoolAl) {
100100
204204 Size = Layout->StructSize; Alignment = Layout->StructAlignment;
205205 return;
206206 }
207
207
208208 default:
209209 assert(0 && "Bad type for getTypeInfo!!!");
210210 return;
0 //===-- TargetFrameInfo.cpp - Implement machine frame interface -*- C++ -*-===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // Implements the layout of a stack frame on the target machine.
2121 //===--------------------------------------------------------------------===//
2222
2323 // This method adjusts a stack offset to meet alignment rules of target.
24 int
24 int
2525 TargetFrameInfo::adjustAlignment(int unalignedOffset, bool growUp,
2626 unsigned align) const {
2727 abort();
3232 // function. The frame contents are obtained from the MachineFunction object
3333 // for the given function. The rest must be implemented by the
3434 // machine-specific subclass.
35 //
35 //
3636 int
3737 TargetFrameInfo::getIncomingArgOffset(MachineFunction& mcInfo, unsigned argNum)
3838 const {
5454 return 0;
5555 }
5656
57 int
57 int
5858 TargetFrameInfo::getRegSpillAreaOffset(MachineFunction& mcInfo, bool& growUp)
5959 const {
6060 abort();
6767 return 0;
6868 }
6969
70 int
70 int
7171 TargetFrameInfo::getDynamicAreaOffset(MachineFunction& mcInfo, bool& growUp)
7272 const {
7373 abort();
0 //===-- TargetInstrInfo.cpp - Target Instruction Information --------------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file implements the TargetInstrInfo class.
1919 namespace llvm {
2020 // External object describing the machine instructions Initialized only when
2121 // the TargetMachine class is created and reset when that class is destroyed.
22 //
22 //
2323 // FIXME: UGLY SPARCV9 HACK!
2424 const TargetInstrDescriptor* TargetInstrDescriptors = 0;
2525 }
4848 // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
4949 // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
5050 // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
51
51
5252 // Now check if the constant fits
5353 if (intValue <= (int64_t) maxImmedValue &&
5454 intValue >= -((int64_t) maxImmedValue+1))
5555 return true;
5656 }
57
57
5858 return false;
5959 }
6060
0 //===-- TargetMachine.cpp - General Target Information ---------------------==//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file describes the general parts of a Target machine.
3131 cl::desc("Print generated machine code"),
3232 cl::location(PrintMachineCode), cl::init(false));
3333
34 cl::opt
34 cl::opt
3535 DisableFPElim("disable-fp-elim",
3636 cl::desc("Disable frame pointer elimination optimization"),
3737 cl::location(NoFramePointerElim),
0 //===-- TargetMachineRegistry.cpp - Target Auto Registration Impl ---------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file exposes the RegisterTarget class, which TargetMachine
6161 return 0;
6262 } else if (UsableTargets.size() == 1)
6363 return UsableTargets.back().second;
64
64
6565 // Otherwise, take the best target, but make sure we don't have to equally
6666 // good best targets.
6767 std::sort(UsableTargets.begin(), UsableTargets.end());
9090 return 0;
9191 } else if (UsableTargets.size() == 1)
9292 return UsableTargets.back().second;
93
93
9494 // Otherwise, take the best target. If there is a tie, just pick one.
9595 unsigned MaxQual = UsableTargets.front().first;
9696 const Entry *MaxQualTarget = UsableTargets.front().second;
100100 MaxQual = UsableTargets[i].first;
101101 MaxQualTarget = UsableTargets[i].second;
102102 }
103
103
104104 return MaxQualTarget;
105105 }
106
106
0 //===-- SchedInfo.cpp - Generic code to support target schedulers ----------==//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file implements the generic part of a Scheduler description for a
2020
2121 resourceId_t llvm::CPUResource::nextId = 0;
2222 static std::vector *CPUResourceMap = 0;
23
23
2424 CPUResource::CPUResource(const std::string& resourceName, int maxUsers)
2525 : rname(resourceName), rid(nextId++), maxNumUsers(maxUsers) {
2626 if(!CPUResourceMap)
4444 RUConflict(const std::vector& fromRVec,
4545 const std::vector& toRVec)
4646 {
47
48 unsigned fN = fromRVec.size(), tN = toRVec.size();
47
48 unsigned fN = fromRVec.size(), tN = toRVec.size();
4949 unsigned fi = 0, ti = 0;
5050
5151 while (fi < fN && ti < tN) {
6161
6262
6363 static CycleCount_t
64 ComputeMinGap(const InstrRUsage &fromRU,
64 ComputeMinGap(const InstrRUsage &fromRU,
6565 const InstrRUsage &toRU)
6666 {
6767 CycleCount_t minGap = 0;
68
68
6969 if (fromRU.numBubbles > 0)
7070 minGap = fromRU.numBubbles;
71
71
7272 if (minGap < fromRU.numCycles) {
7373 // only need to check from cycle `minGap' onwards
7474 for (CycleCount_t gap=minGap; gap <= fromRU.numCycles-1; gap++) {
8484 }
8585 }
8686 }
87
87
8888 return minGap;
8989 }
9090
113113 {
114114 assert(MAX_NUM_SLOTS >= (int)getMaxNumIssueTotal()
115115 && "Insufficient slots for static data! Increase MAX_NUM_SLOTS");
116
116
117117 // First, compute common resource usage info for each class because
118118 // most instructions will probably behave the same as their class.
119119 // Cannot allocate a vector of InstrRUsage so new each one.
120 //
120 //
121121 std::vector instrRUForClasses;
122122 instrRUForClasses.resize(numSchedClasses);
123123 for (InstrSchedClass sc = 0; sc < numSchedClasses; sc++) {
125125 instrRUForClasses[sc].setMaxSlots(getMaxNumIssueTotal());
126126 instrRUForClasses[sc].setTo(classRUsages[sc]);
127127 }
128
128
129129 computeInstrResources(instrRUForClasses);
130130 computeIssueGaps(instrRUForClasses);
131131 }
137137 {
138138 int numOpCodes = mii->getNumOpcodes();
139139 instrRUsages.resize(numOpCodes);
140
140
141141 // First get the resource usage information from the class resource usages.
142142 for (MachineOpCode op = 0; op < numOpCodes; ++op) {
143143 InstrSchedClass sc = getSchedClass(op);
144144 assert(sc < numSchedClasses);
145145 instrRUsages[op] = instrRUForClasses[sc];
146146 }
147
147
148148 // Now, modify the resource usages as specified in the deltas.
149149 for (unsigned i = 0; i < numUsageDeltas; ++i) {
150150 MachineOpCode op = usageDeltas[i].opCode;
151151 assert(op < numOpCodes);
152152 instrRUsages[op].addUsageDelta(usageDeltas[i]);
153153 }
154
154
155155 // Then modify the issue restrictions as specified in the deltas.
156156 for (unsigned i = 0; i < numIssueDeltas; ++i) {
157157 MachineOpCode op = issueDeltas[i].opCode;
172172 // First, compute issue gaps between pairs of classes based on common
173173 // resources usages for each class, because most instruction pairs will
174174 // usually behave the same as their class.
175 //
175 //
176176 int* classPairGaps =
177177 static_cast(alloca(sizeof(int) * numSchedClasses * numSchedClasses));
178178 for (InstrSchedClass fromSC=0; fromSC < numSchedClasses; fromSC++)
179179 for (InstrSchedClass toSC=0; toSC < numSchedClasses; toSC++) {
180180 int classPairGap = ComputeMinGap(instrRUForClasses[fromSC],
181181 instrRUForClasses[toSC]);
182 classPairGaps[fromSC*numSchedClasses + toSC] = classPairGap;
182 classPairGaps[fromSC*numSchedClasses + toSC] = classPairGap;
183183 }
184184
185185 // Now, for each pair of instructions, use the class pair gap if both
190190
191191 for (MachineOpCode fromOp=0; fromOp < numOpCodes; fromOp++)
192192 for (MachineOpCode toOp=0; toOp < numOpCodes; toOp++) {
193 int instrPairGap =
193 int instrPairGap =
194194 (instrRUsages[fromOp].sameAsClass && instrRUsages[toOp].sameAsClass)
195195 ? classPairGaps[getSchedClass(fromOp)*numSchedClasses + getSchedClass(toOp)]
196196 : ComputeMinGap(instrRUsages[fromOp], instrRUsages[toOp]);
207207 void InstrRUsage::setTo(const InstrClassRUsage& classRU) {
208208 sameAsClass = true;
209209 isSingleIssue = classRU.isSingleIssue;
210 breaksGroup = classRU.breaksGroup;
210 breaksGroup = classRU.breaksGroup;
211211 numBubbles = classRU.numBubbles;
212
212
213213 for (unsigned i=0; i < classRU.numSlots; i++) {
214214 unsigned slot = classRU.feasibleSlots[i];
215215 assert(slot < feasibleSlots.size() && "Invalid slot specified!");
216216 this->feasibleSlots[slot] = true;
217217 }
218
218
219219 numCycles = classRU.totCycles;
220220 resourcesByCycle.resize(this->numCycles);
221
221
222222 for (unsigned i=0; i < classRU.numRUEntries; i++)
223223 for (unsigned c=classRU.V[i].startCycle, NC = c + classRU.V[i].numCycles;
224224 c < NC; c++)
225225 this->resourcesByCycle[c].push_back(classRU.V[i].resourceId);
226
226
227227 // Sort each resource usage vector by resourceId_t to speed up conflict
228228 // checking
229229 for (unsigned i=0; i < this->resourcesByCycle.size(); i++)
233233 // Add the extra resource usage requirements specified in the delta.
234234 // Note that a negative value of `numCycles' means one entry for that
235235 // resource should be deleted for each cycle.
236 //
236 //
237237 void InstrRUsage::addUsageDelta(const InstrRUsageDelta &delta) {
238238 int NC = delta.numCycles;
239239 sameAsClass = false;
240
240
241241 // resize the resources vector if more cycles are specified
242242 unsigned maxCycles = this->numCycles;
243243 maxCycles = std::max(maxCycles, delta.startCycle + abs(NC) - 1);
245245 this->resourcesByCycle.resize(maxCycles);
246246 this->numCycles = maxCycles;
247247 }
248
248
249249 if (NC >= 0)
250250 for (unsigned c=delta.startCycle, last=c+NC-1; c <= last; c++)
251251 this->resourcesByCycle[c].push_back(delta.resourceId);
0 //===-- ToolRunner.cpp ----------------------------------------------------===//
1 //
1 //
22 // The LLVM Compiler Infrastructure
33 //
44 // This file was developed by the LLVM research group and is distributed under
55 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
6 //
77 //===----------------------------------------------------------------------===//
88 //
99 // This file implements the interfaces described in the ToolRunner.h file.
3535 redirects[0] = &StdInFile;
3636 redirects[1] = &StdOutFile;
3737 redirects[2] = &StdErrFile;
38
39 return
38
39 return
4040 sys::Program::ExecuteAndWait(ProgramPath, Args, 0, redirects, NumSeconds);
4141 }
4242
8181 ToolArgs.clear ();
8282 if (Args) { ToolArgs = *Args; }
8383 }
84
84
8585 virtual int ExecuteProgram(const std::string &Bytecode,
8686 const std::vector &Args,
8787 const std::string &InputFile,
8888 const std::string &OutputFile,
89 const std::vector &SharedLibs =
89 const std::vector &SharedLibs =
9090 std::vector(),
9191 unsigned Timeout = 0);
9292 };
123123 std::cerr << "\n";
124124 );
125125 return RunProgramWithTimeout(sys::Path(LLIPath), &LLIArgs[0],
126 sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
126 sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
127127 Timeout);
128128 }
129129
167167 std::cerr << " " << LLCArgs[i];
168168 std::cerr << "\n";
169169 );
170 if (RunProgramWithTimeout(sys::Path(LLCPath), &LLCArgs[0],
170 if (RunProgramWithTimeout(sys::Path(LLCPath), &LLCArgs[0],
171171 sys::Path(), sys::Path(), sys::Path()))
172172 ProcessFailure(sys::Path(LLCPath), &LLCArgs[0]);
173173 }
227227 ToolArgs.clear ();
228228 if (Args) { ToolArgs = *Args; }
229229 }
230
230
231231 virtual int ExecuteProgram(const std::string &Bytecode,
232232 const std::vector &Args,
233233 const std::string &InputFile,
234234 const std::string &OutputFile,
235 const std::vector &SharedLibs =
235 const std::vector &SharedLibs =
236236 std::vector(), unsigned Timeout =0);
237237 };
238238 }
270270 );
271271 DEBUG(std::cerr << "\nSending output to " << OutputFile << "\n");
272272 return RunProgramWithTimeout(sys::Path(LLIPath), &JITArgs[0],
273 sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
273 sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
274274 Timeout);
275275 }
276276
312312 std::cerr << " " << LLCArgs[i];
313313 std::cerr << "\n";
314314 );
315 if (RunProgramWithTimeout(LLCPath, &LLCArgs[0], sys::Path(), sys::Path(),
315 if (RunProgramWithTimeout(LLCPath, &LLCArgs[0], sys::Path(), sys::Path(),
316316 sys::Path()))
317317 ProcessFailure(LLCPath, &LLCArgs[0]);
318318 }
334334
335335 FileRemover CFileRemove(OutputCFile);
336336
337 return gcc->ExecuteProgram(OutputCFile.toString(), Args, GCC::CFile,
337 return gcc->ExecuteProgram(OutputCFile.toString(), Args, GCC::CFile,
338338 InputFile, OutputFile, SharedLibs, Timeout);
339339 }
340340
345345 const std::vector *Args) {
346346 sys::Path LLCPath = FindExecutable("llc", ProgramPath);
347347 if (LLCPath.isEmpty()) {
348 Message =
348 Message =
349349 "Cannot find `llc' in executable directory or PATH!\n";
350350 return 0;
351351 }
376376 // Specify the shared libraries to link in...
377377 for (unsigned i = 0, e = SharedLibs.size(); i != e; ++i)
378378 GCCArgs.push_back(SharedLibs[i].c_str());
379
379
380380 // Specify -x explicitly in case the extension is wonky
381381 GCCArgs.push_back("-x");
382382 if (fileType == CFile) {
422422
423423 FileRemover OutputBinaryRemover(OutputBinary);
424424 return RunProgramWithTimeout(OutputBinary, &ProgramArgs[0],
425 sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
425 sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
426426 Timeout);
427427 }
428428
457457 "-O2", // Optimize the program a bit...
458458 0
459459 };
460
460
461461 std::cout << "" << std::flush;
462 if (RunProgramWithTimeout(GCCPath, GCCArgs, sys::Path(), sys::Path(),
462 if (RunProgramWithTimeout(GCCPath, GCCArgs, sys::Path(), sys::Path(),
463463 sys::Path())) {
464464 ProcessFailure(GCCPath, GCCArgs);
465465 return 1;