[llvm-commits] [hlvm] r38197 - /hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp

Reid Spencer reid at x10sys.com
Sat Jul 7 17:01:04 PDT 2007


Author: reid
Date: Sat Jul  7 19:01:04 2007
New Revision: 38197

URL: http://llvm.org/viewvc/llvm-project?rev=38197&view=rev
Log:
Process the collected programs at the end of a bundle, not at the end of
and AST parse. There might be multiple bundles and the previous implementation
would cause the programs to be inserted into the last llvm Module processed,
not the Module containing the programs.

Modified:
    hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp

Modified: hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp?rev=38197&r1=38196&r2=38197&view=diff

==============================================================================
--- hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp (original)
+++ hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp Sat Jul  7 19:01:04 2007
@@ -150,6 +150,8 @@
   template <class NodeClass>
   inline void gen(NodeClass *nc);
 
+  void genProgramLinkage();
+
   virtual void handleInitialize();
   virtual void handle(Node* n,Pass::TraversalKinds mode);
   virtual void handleTerminate();
@@ -905,6 +907,72 @@
   gvars.clear();
 }
 
+void 
+LLVMGeneratorPass::genProgramLinkage()
+{
+  // Short circuit if there's nothing to do
+  if (progs.empty())
+    return;
+
+  // Define the type of the array elements (a structure with a pointer to
+  // a string and a pointer to the function).
+  std::vector<const llvm::Type*> Fields;
+  Fields.push_back(llvm::PointerType::get(llvm::Type::SByteTy));
+  Fields.push_back(llvm::PointerType::get(get_hlvm_program_signature()));
+  llvm::StructType* entry_elem_type = llvm::StructType::get(Fields);
+
+  // Define the type of the array for the entry points
+  llvm::ArrayType* entry_points_type = 
+    llvm::ArrayType::get(entry_elem_type,progs.size());
+
+  // Create a vector to hold the entry elements as they are created.
+  std::vector<llvm::Constant*> entry_points_items;
+
+  for (std::vector<llvm::Function*>::iterator I = progs.begin(), 
+       E = progs.end(); I != E; ++I )
+  {
+    const std::string& funcName = (*I)->getName();
+    // Get a constant for the name of the entry point (char array)
+    llvm::Constant* name_val = llvm::ConstantArray::get(funcName,true);
+
+    // Create a constant global variable to hold the name of the program.
+    llvm::GlobalVariable* name = new llvm::GlobalVariable(
+      /*Type=*/name_val->getType(),
+      /*isConst=*/true,
+      /*Linkage=*/llvm::GlobalValue::InternalLinkage, 
+      /*Initializer=*/name_val, 
+      /*name=*/"", 
+      /*InsertInto=*/lmod
+    );
+
+    llvm::Constant* index = llvm::ConstantExpr::getPtrPtrFromArrayPtr(name);
+
+    // Get a constant structure for the entry containing the name and pointer
+    // to the function.
+    std::vector<llvm::Constant*> items;
+    items.push_back(index);
+    items.push_back(*I);
+    llvm::Constant* entry = llvm::ConstantStruct::get(entry_elem_type,items);
+
+    // Save the entry into the list of entry point items
+    entry_points_items.push_back(entry);
+  }
+
+  // Create a constant array to initialize the entry_points
+  llvm::Constant* entry_points_initializer = llvm::ConstantArray::get(
+    entry_points_type,entry_points_items);
+
+  // Now get the GlobalVariable
+  llvm::GlobalVariable* entry_points = new llvm::GlobalVariable(
+    /*Type=*/entry_points_type,
+    /*isConstant=*/true,
+    /*Linkage=*/llvm::GlobalValue::AppendingLinkage,
+    /*Initializer=*/entry_points_initializer,
+    /*Name=*/"hlvm_programs",
+    /*Parent=*/lmod
+  );
+}
+
 void
 LLVMGeneratorPass::handleInitialize()
 {
@@ -963,6 +1031,8 @@
 
     // ignore end of block, program, function and bundle
     case BundleID:
+      genProgramLinkage();
+      lmod = 0;
       break;
     case ProgramID:
     case FunctionID:
@@ -983,70 +1053,9 @@
 void
 LLVMGeneratorPass::handleTerminate()
 {
-  // Short circuit if there's nothing to do
-  if (progs.empty())
-    return;
-
-  // Define the type of the array elements (a structure with a pointer to
-  // a string and a pointer to the function).
-  std::vector<const llvm::Type*> Fields;
-  Fields.push_back(llvm::PointerType::get(llvm::Type::SByteTy));
-  Fields.push_back(llvm::PointerType::get(get_hlvm_program_signature()));
-  llvm::StructType* entry_elem_type = llvm::StructType::get(Fields);
-
-  // Define the type of the array for the entry points
-  llvm::ArrayType* entry_points_type = 
-    llvm::ArrayType::get(entry_elem_type,progs.size());
-
-  // Create a vector to hold the entry elements as they are created.
-  std::vector<llvm::Constant*> entry_points_items;
-
-  for (std::vector<llvm::Function*>::iterator I = progs.begin(), 
-       E = progs.end(); I != E; ++I )
-  {
-    const std::string& funcName = (*I)->getName();
-    // Get a constant for the name of the entry point (char array)
-    llvm::Constant* name_val = llvm::ConstantArray::get(funcName,true);
-
-    // Create a constant global variable to hold the name of the program.
-    llvm::GlobalVariable* name = new llvm::GlobalVariable(
-      /*Type=*/name_val->getType(),
-      /*isConst=*/true,
-      /*Linkage=*/llvm::GlobalValue::InternalLinkage, 
-      /*Initializer=*/name_val, 
-      /*name=*/"", 
-      /*InsertInto=*/lmod
-    );
-
-    llvm::Constant* index = llvm::ConstantExpr::getPtrPtrFromArrayPtr(name);
-
-    // Get a constant structure for the entry containing the name and pointer
-    // to the function.
-    std::vector<llvm::Constant*> items;
-    items.push_back(index);
-    items.push_back(*I);
-    llvm::Constant* entry = llvm::ConstantStruct::get(entry_elem_type,items);
-
-    // Save the entry into the list of entry point items
-    entry_points_items.push_back(entry);
-  }
-
-  // Create a constant array to initialize the entry_points
-  llvm::Constant* entry_points_initializer = llvm::ConstantArray::get(
-    entry_points_type,entry_points_items);
-
-  // Now get the GlobalVariable
-  llvm::GlobalVariable* entry_points = new llvm::GlobalVariable(
-    /*Type=*/entry_points_type,
-    /*isConstant=*/true,
-    /*Linkage=*/llvm::GlobalValue::AppendingLinkage,
-    /*Initializer=*/entry_points_initializer,
-    /*Name=*/"hlvm_programs",
-    /*Parent=*/lmod
-  );
+  // Nothing to do.
 }
 
-
 llvm::Module*
 LLVMGeneratorPass::linkModules()
 {





More information about the llvm-commits mailing list