Change inline asms to be uniqued like constants, not embedded in a Module.

llvm-svn: 25610
This commit is contained in:
Chris Lattner 2006-01-25 18:57:27 +00:00
parent d07c86465d
commit 8bbcda2fda
5 changed files with 19 additions and 108 deletions

View File

@ -8,7 +8,8 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// //
// This class represents the inline asm strings, which are Value*'s that are // This class represents the inline asm strings, which are Value*'s that are
// used as the callee operand of call instructions. // used as the callee operand of call instructions. InlineAsm's are uniqued
// like constants, and created via InlineAsm::get(...).
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -23,35 +24,24 @@ struct AssemblyAnnotationWriter;
class PointerType; class PointerType;
class FunctionType; class FunctionType;
class Module; class Module;
template<typename SC> struct ilist_traits;
template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
typename SubClass> class SymbolTableListTraits;
class InlineAsm : public Value { class InlineAsm : public Value {
friend class SymbolTableListTraits<InlineAsm, Module, Module,
ilist_traits<InlineAsm> >;
InlineAsm(const InlineAsm &); // do not implement InlineAsm(const InlineAsm &); // do not implement
void operator=(const InlineAsm&); // do not implement void operator=(const InlineAsm&); // do not implement
void setParent(Module *Parent);
InlineAsm *Prev, *Next;
void setNext(InlineAsm *N) { Next = N; }
void setPrev(InlineAsm *N) { Prev = N; }
InlineAsm *getNext() { return Next; }
const InlineAsm *getNext() const { return Next; }
InlineAsm *getPrev() { return Prev; }
const InlineAsm *getPrev() const { return Prev; }
Module *Parent;
std::string AsmString, Constraints; std::string AsmString, Constraints;
bool AsmHasSideEffects; bool HasSideEffects;
public:
InlineAsm(const FunctionType *Ty, const std::string &AsmString,
const std::string &Constraints, bool hasSideEffects,
const std::string &Name = "", Module *ParentModule = 0);
bool getHasSideEffects() const { return AsmHasSideEffects; } InlineAsm(const FunctionType *Ty, const std::string &AsmString,
void setSideEffects(bool X) { AsmHasSideEffects = X; } const std::string &Constraints, bool hasSideEffects);
public:
/// InlineAsm::get - Return the the specified uniqued inline asm string.
///
static InlineAsm *get(const FunctionType *Ty, const std::string &AsmString,
const std::string &Constraints, bool hasSideEffects);
bool hasSideEffects() const { return HasSideEffects; }
/// getType - InlineAsm's are always pointers. /// getType - InlineAsm's are always pointers.
/// ///
@ -63,17 +53,6 @@ public:
/// ///
const FunctionType *getFunctionType() const; const FunctionType *getFunctionType() const;
/// getParent - Get the module that this global value is contained inside
/// of...
Module *getParent() { return Parent; }
const Module *getParent() const { return Parent; }
/// removeFromParent/eraseFromParent - Unlink and unlink/delete this object
/// from the module it is embedded into.
void removeFromParent();
void eraseFromParent();
virtual void print(std::ostream &O) const { print(O, 0); } virtual void print(std::ostream &O) const { print(O, 0); }
void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const; void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const;

View File

@ -21,7 +21,6 @@
#include "llvm/Function.h" #include "llvm/Function.h"
#include "llvm/GlobalVariable.h" #include "llvm/GlobalVariable.h"
#include "llvm/InlineAsm.h"
#include "llvm/ADT/SetVector.h" #include "llvm/ADT/SetVector.h"
#include "llvm/Support/DataTypes.h" #include "llvm/Support/DataTypes.h"
@ -46,19 +45,11 @@ template<> struct ilist_traits<GlobalVariable>
static void destroySentinel(GlobalVariable *GV) { delete GV; } static void destroySentinel(GlobalVariable *GV) { delete GV; }
static iplist<GlobalVariable> &getList(Module *M); static iplist<GlobalVariable> &getList(Module *M);
}; };
template<> struct ilist_traits<InlineAsm>
: public SymbolTableListTraits<InlineAsm, Module, Module> {
// createSentinel is used to create a node that marks the end of the list.
static InlineAsm *createSentinel();
static void destroySentinel(InlineAsm *GV) { delete GV; }
static iplist<InlineAsm> &getList(Module *M);
};
class Module { class Module {
public: public:
typedef iplist<GlobalVariable> GlobalListType; typedef iplist<GlobalVariable> GlobalListType;
typedef iplist<Function> FunctionListType; typedef iplist<Function> FunctionListType;
typedef iplist<InlineAsm> InlineAsmListType;
typedef SetVector<std::string> LibraryListType; typedef SetVector<std::string> LibraryListType;
// Global Variable iterators. // Global Variable iterators.
@ -69,10 +60,6 @@ public:
typedef FunctionListType::iterator iterator; typedef FunctionListType::iterator iterator;
typedef FunctionListType::const_iterator const_iterator; typedef FunctionListType::const_iterator const_iterator;
// Inline Asm iterators.
typedef InlineAsmListType::iterator inlineasm_iterator;
typedef InlineAsmListType::const_iterator const_inlineasm_iterator;
// Library list iterators. // Library list iterators.
typedef LibraryListType::const_iterator lib_iterator; typedef LibraryListType::const_iterator lib_iterator;
@ -82,7 +69,6 @@ public:
private: private:
GlobalListType GlobalList; // The Global Variables in the module GlobalListType GlobalList; // The Global Variables in the module
FunctionListType FunctionList; // The Functions in the module FunctionListType FunctionList; // The Functions in the module
InlineAsmListType InlineAsmList; // The inline asm objects in the module.
LibraryListType LibraryList; // The Libraries needed by the module LibraryListType LibraryList; // The Libraries needed by the module
std::string GlobalScopeAsm; // Inline Asm at global scope. std::string GlobalScopeAsm; // Inline Asm at global scope.
SymbolTable *SymTab; // Symbol Table for the module SymbolTable *SymTab; // Symbol Table for the module
@ -193,8 +179,6 @@ public:
GlobalListType &getGlobalList() { return GlobalList; } GlobalListType &getGlobalList() { return GlobalList; }
const FunctionListType &getFunctionList() const { return FunctionList; } const FunctionListType &getFunctionList() const { return FunctionList; }
FunctionListType &getFunctionList() { return FunctionList; } FunctionListType &getFunctionList() { return FunctionList; }
const InlineAsmListType &getInlineAsmList() const { return InlineAsmList; }
InlineAsmListType &getInlineAsmList() { return InlineAsmList; }
/// getSymbolTable() - Get access to the symbol table for the module, where /// getSymbolTable() - Get access to the symbol table for the module, where
/// global variables and functions are identified. /// global variables and functions are identified.
@ -222,21 +206,6 @@ public:
size_t size() const { return FunctionList.size(); } size_t size() const { return FunctionList.size(); }
bool empty() const { return FunctionList.empty(); } bool empty() const { return FunctionList.empty(); }
// Inline Asm list interface
inlineasm_iterator inlineasm_begin() {
return InlineAsmList.begin();
}
const_inlineasm_iterator inlineasm_begin() const {
return InlineAsmList.begin();
}
inlineasm_iterator inlineasm_end() {
return InlineAsmList.end();
}
const_inlineasm_iterator inlineasm_end() const {
return InlineAsmList.end();
}
bool inlineasm_empty() const { return InlineAsmList.empty(); }
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
// List of dependent library access functions // List of dependent library access functions

View File

@ -21,6 +21,7 @@
#include "llvm/CallingConv.h" #include "llvm/CallingConv.h"
#include "llvm/Constants.h" #include "llvm/Constants.h"
#include "llvm/DerivedTypes.h" #include "llvm/DerivedTypes.h"
#include "llvm/InlineAsm.h"
#include "llvm/Instruction.h" #include "llvm/Instruction.h"
#include "llvm/Instructions.h" #include "llvm/Instructions.h"
#include "llvm/Module.h" #include "llvm/Module.h"
@ -1270,9 +1271,6 @@ void Function::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
} }
void InlineAsm::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const { void InlineAsm::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
SlotMachine SlotTable(getParent());
AssemblyWriter W(o, SlotTable, getParent(), AAW);
assert(0 && "Inline asm printing unimplemented!"); assert(0 && "Inline asm printing unimplemented!");
//W.write(this); //W.write(this);
} }

View File

@ -18,33 +18,15 @@
using namespace llvm; using namespace llvm;
InlineAsm::InlineAsm(const FunctionType *Ty, const std::string &asmString, InlineAsm::InlineAsm(const FunctionType *Ty, const std::string &asmString,
const std::string &constraints, bool hasSideEffects, const std::string &constraints, bool hasSideEffects)
const std::string &name, Module *ParentModule) : Value(PointerType::get(Ty), Value::InlineAsmVal), AsmString(asmString),
: Value(PointerType::get(Ty), Value::InlineAsmVal, name), Constraints(constraints), HasSideEffects(hasSideEffects) {
Parent(0), AsmString(asmString), Constraints(constraints),
AsmHasSideEffects(hasSideEffects) {
LeakDetector::addGarbageObject(this); LeakDetector::addGarbageObject(this);
if (ParentModule) // FIXME: do various checks on the constraint string and type.
ParentModule->getInlineAsmList().push_back(this);
} }
const FunctionType *InlineAsm::getFunctionType() const { const FunctionType *InlineAsm::getFunctionType() const {
return cast<FunctionType>(getType()->getElementType()); return cast<FunctionType>(getType()->getElementType());
} }
void InlineAsm::setParent(Module *parent) {
if (getParent())
LeakDetector::addGarbageObject(this);
Parent = parent;
if (getParent())
LeakDetector::removeGarbageObject(this);
}
void InlineAsm::removeFromParent() {
getParent()->getInlineAsmList().remove(this);
}
void InlineAsm::eraseFromParent() {
getParent()->getInlineAsmList().erase(this);
}

View File

@ -44,30 +44,17 @@ GlobalVariable *ilist_traits<GlobalVariable>::createSentinel() {
return Ret; return Ret;
} }
InlineAsm *ilist_traits<InlineAsm>::createSentinel() {
InlineAsm *Ret = new InlineAsm(FunctionType::get(Type::VoidTy,
std::vector<const Type*>(), false), "", "",
false);
// This should not be garbage monitored.
LeakDetector::removeGarbageObject(Ret);
return Ret;
}
iplist<Function> &ilist_traits<Function>::getList(Module *M) { iplist<Function> &ilist_traits<Function>::getList(Module *M) {
return M->getFunctionList(); return M->getFunctionList();
} }
iplist<GlobalVariable> &ilist_traits<GlobalVariable>::getList(Module *M) { iplist<GlobalVariable> &ilist_traits<GlobalVariable>::getList(Module *M) {
return M->getGlobalList(); return M->getGlobalList();
} }
iplist<InlineAsm> &ilist_traits<InlineAsm>::getList(Module *M) {
return M->getInlineAsmList();
}
// Explicit instantiations of SymbolTableListTraits since some of the methods // Explicit instantiations of SymbolTableListTraits since some of the methods
// are not in the public header file. // are not in the public header file.
template class SymbolTableListTraits<GlobalVariable, Module, Module>; template class SymbolTableListTraits<GlobalVariable, Module, Module>;
template class SymbolTableListTraits<Function, Module, Module>; template class SymbolTableListTraits<Function, Module, Module>;
template class SymbolTableListTraits<InlineAsm, Module, Module>;
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Primitive Module methods. // Primitive Module methods.
@ -79,8 +66,6 @@ Module::Module(const std::string &MID)
FunctionList.setParent(this); FunctionList.setParent(this);
GlobalList.setItemParent(this); GlobalList.setItemParent(this);
GlobalList.setParent(this); GlobalList.setParent(this);
InlineAsmList.setItemParent(this);
InlineAsmList.setParent(this);
SymTab = new SymbolTable(); SymTab = new SymbolTable();
} }
@ -90,8 +75,6 @@ Module::~Module() {
GlobalList.setParent(0); GlobalList.setParent(0);
FunctionList.clear(); FunctionList.clear();
FunctionList.setParent(0); FunctionList.setParent(0);
InlineAsmList.clear();
InlineAsmList.setParent(0);
LibraryList.clear(); LibraryList.clear();
delete SymTab; delete SymTab;
} }