Skip to content

Commit

Permalink
Remove using llvh::dbgs() from Hermes headers
Browse files Browse the repository at this point in the history
Summary:
This change removes the using llvh::dbgs declaration from hermes headers, and then
deals with fallout from the change.

Reviewed By: kodafb

Differential Revision: D38229825

fbshipit-source-id: 7bbf666a3c3e4491e30feacb63138f75654e7af8
  • Loading branch information
jpporto authored and facebook-github-bot committed Aug 2, 2022
1 parent 2264f74 commit a96ad7d
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 82 deletions.
30 changes: 15 additions & 15 deletions include/hermes/Optimizer/PassManager/PassManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

#define DEBUG_TYPE "passmanager"

using llvh::dbgs;

namespace hermes {

/// The pass manager is responsible for running the transformation passes on the
Expand Down Expand Up @@ -78,12 +76,12 @@ class PassManager {
return;

if (!lastPass) {
dbgs() << "*** INITIAL STATE\n\n";
llvh::dbgs() << "*** INITIAL STATE\n\n";
} else {
dbgs() << "\n*** AFTER " << lastPass->getName() << "\n\n";
llvh::dbgs() << "\n*** AFTER " << lastPass->getName() << "\n\n";
}

F->dump(dbgs());
F->dump(llvh::dbgs());
lastPass = newPass;
};

Expand All @@ -93,10 +91,10 @@ class PassManager {

auto *FP = llvh::dyn_cast<FunctionPass>(P);
assert(FP && "Invalid pass kind");
LLVM_DEBUG(dbgs() << "Running the pass " << FP->getName() << "\n");
LLVM_DEBUG(llvh::dbgs() << "Running the pass " << FP->getName() << "\n");
LLVM_DEBUG(
dbgs() << "Optimizing the function " << F->getInternalNameStr()
<< "\n");
llvh::dbgs() << "Optimizing the function " << F->getInternalNameStr()
<< "\n");
FP->runOnFunction(F);
}
dumpLastPass(nullptr);
Expand All @@ -116,12 +114,12 @@ class PassManager {
return;

if (!lastPass) {
dbgs() << "*** INITIAL STATE\n\n";
llvh::dbgs() << "*** INITIAL STATE\n\n";
} else {
dbgs() << "\n*** AFTER " << lastPass->getName() << "\n\n";
llvh::dbgs() << "\n*** AFTER " << lastPass->getName() << "\n\n";
}

M->dump(dbgs());
M->dump(llvh::dbgs());
lastPass = newPass;
};

Expand All @@ -137,15 +135,16 @@ class PassManager {
/// Handle function passes:
if (auto *FP = llvh::dyn_cast<FunctionPass>(P)) {
LLVM_DEBUG(
dbgs() << "Running the function pass " << FP->getName() << "\n");
llvh::dbgs() << "Running the function pass " << FP->getName()
<< "\n");

for (auto &I : *M) {
Function *F = &I;
if (F->isLazy())
continue;
LLVM_DEBUG(
dbgs() << "Optimizing the function " << F->getInternalNameStr()
<< "\n");
llvh::dbgs() << "Optimizing the function "
<< F->getInternalNameStr() << "\n");
FP->runOnFunction(F);
}

Expand All @@ -156,7 +155,8 @@ class PassManager {
/// Handle module passes:
if (auto *MP = llvh::dyn_cast<ModulePass>(P)) {
LLVM_DEBUG(
dbgs() << "Running the module pass " << MP->getName() << "\n");
llvh::dbgs() << "Running the module pass " << MP->getName()
<< "\n");
MP->runOnModule(M);
// Move to the next pass.
continue;
Expand Down
1 change: 1 addition & 0 deletions lib/BCGen/HBC/ISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using namespace hermes;
using namespace hbc;

using llvh::dbgs;
using llvh::Optional;

#define INCLUDE_HBC_INSTRS
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/ESTreeIRGen-except.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace hermes {
namespace irgen {

void ESTreeIRGen::genTryStatement(ESTree::TryStatementNode *tryStmt) {
LLVM_DEBUG(dbgs() << "IRGen 'try' statement\n");
LLVM_DEBUG(llvh::dbgs() << "IRGen 'try' statement\n");

// try-catch-finally statements must have been transformed by the validator
// into two nested try statements with only "catch" or "finally" each.
Expand Down
72 changes: 41 additions & 31 deletions lib/IRGen/ESTreeIRGen-expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ namespace irgen {

Value *ESTreeIRGen::genExpression(ESTree::Node *expr, Identifier nameHint) {
LLVM_DEBUG(
dbgs() << "IRGen expression of type " << expr->getNodeName() << "\n");
llvh::dbgs() << "IRGen expression of type " << expr->getNodeName()
<< "\n");
IRBuilder::ScopedLocationChange slc(Builder, expr->getDebugLoc());

// Handle identifiers.
Expand All @@ -31,16 +32,17 @@ Value *ESTreeIRGen::genExpression(ESTree::Node *expr, Identifier nameHint) {
// Handle String Literals.
// http://www.ecma-international.org/ecma-262/6.0/#sec-literals-string-literals
if (auto *Lit = llvh::dyn_cast<ESTree::StringLiteralNode>(expr)) {
LLVM_DEBUG(dbgs() << "Loading String Literal \"" << Lit->_value << "\"\n");
LLVM_DEBUG(
llvh::dbgs() << "Loading String Literal \"" << Lit->_value << "\"\n");
return Builder.getLiteralString(Lit->_value->str());
}

// Handle Regexp Literals.
// http://www.ecma-international.org/ecma-262/6.0/#sec-literals-regular-expression-literals
if (auto *Lit = llvh::dyn_cast<ESTree::RegExpLiteralNode>(expr)) {
LLVM_DEBUG(
dbgs() << "Loading regexp Literal \"" << Lit->_pattern->str() << " / "
<< Lit->_flags->str() << "\"\n");
llvh::dbgs() << "Loading regexp Literal \"" << Lit->_pattern->str()
<< " / " << Lit->_flags->str() << "\"\n");

return Builder.createRegExpInst(
Identifier::getFromPointer(Lit->_pattern),
Expand All @@ -50,22 +52,25 @@ Value *ESTreeIRGen::genExpression(ESTree::Node *expr, Identifier nameHint) {
// Handle Boolean Literals.
// http://www.ecma-international.org/ecma-262/6.0/#sec-boolean-literals
if (auto *Lit = llvh::dyn_cast<ESTree::BooleanLiteralNode>(expr)) {
LLVM_DEBUG(dbgs() << "Loading String Literal \"" << Lit->_value << "\"\n");
LLVM_DEBUG(
llvh::dbgs() << "Loading String Literal \"" << Lit->_value << "\"\n");
return Builder.getLiteralBool(Lit->_value);
}

// Handle Number Literals.
// http://www.ecma-international.org/ecma-262/6.0/#sec-literals-numeric-literals
if (auto *Lit = llvh::dyn_cast<ESTree::NumericLiteralNode>(expr)) {
LLVM_DEBUG(dbgs() << "Loading Numeric Literal \"" << Lit->_value << "\"\n");
LLVM_DEBUG(
llvh::dbgs() << "Loading Numeric Literal \"" << Lit->_value << "\"\n");
return Builder.getLiteralNumber(Lit->_value);
}

// Handle BigInt Literals.
// https://262.ecma-international.org/#sec-ecmascript-language-types-bigint-type
if (auto *Lit = llvh::dyn_cast<ESTree::BigIntLiteralNode>(expr)) {
LLVM_DEBUG(
dbgs() << "Loading BitInt Literal \"" << Lit->_bigint->str() << "\"\n");
llvh::dbgs() << "Loading BitInt Literal \"" << Lit->_bigint->str()
<< "\"\n");
return Builder.getLiteralBigInt(Lit->_bigint);
}

Expand Down Expand Up @@ -242,7 +247,7 @@ void ESTreeIRGen::genExpressionBranch(
}

Value *ESTreeIRGen::genArrayFromElements(ESTree::NodeList &list) {
LLVM_DEBUG(dbgs() << "Initializing a new array\n");
LLVM_DEBUG(llvh::dbgs() << "Initializing a new array\n");
AllocArrayInst::ArrayValueList elements;

// Precalculate the minimum number of elements in case we need to call
Expand Down Expand Up @@ -366,7 +371,7 @@ Value *ESTreeIRGen::genArrayExpr(ESTree::ArrayExpressionNode *Expr) {
}

Value *ESTreeIRGen::genCallExpr(ESTree::CallExpressionNode *call) {
LLVM_DEBUG(dbgs() << "IRGen 'call' statement/expression.\n");
LLVM_DEBUG(llvh::dbgs() << "IRGen 'call' statement/expression.\n");

// Check for a direct call to eval().
if (auto *identNode = llvh::dyn_cast<ESTree::IdentifierNode>(call->_callee)) {
Expand Down Expand Up @@ -658,20 +663,23 @@ static llvh::StringRef propertyKeyAsString(
// Handle String Literals.
// http://www.ecma-international.org/ecma-262/6.0/#sec-literals-string-literals
if (auto *Lit = llvh::dyn_cast<ESTree::StringLiteralNode>(Key)) {
LLVM_DEBUG(dbgs() << "Loading String Literal \"" << Lit->_value << "\"\n");
LLVM_DEBUG(
llvh::dbgs() << "Loading String Literal \"" << Lit->_value << "\"\n");
return Lit->_value->str();
}

// Handle identifiers as if they are String Literals.
if (auto *Iden = llvh::dyn_cast<ESTree::IdentifierNode>(Key)) {
LLVM_DEBUG(dbgs() << "Loading String Literal \"" << Iden->_name << "\"\n");
LLVM_DEBUG(
llvh::dbgs() << "Loading String Literal \"" << Iden->_name << "\"\n");
return Iden->_name->str();
}

// Handle Number Literals.
// http://www.ecma-international.org/ecma-262/6.0/#sec-literals-numeric-literals
if (auto *Lit = llvh::dyn_cast<ESTree::NumericLiteralNode>(Key)) {
LLVM_DEBUG(dbgs() << "Loading Numeric Literal \"" << Lit->_value << "\"\n");
LLVM_DEBUG(
llvh::dbgs() << "Loading Numeric Literal \"" << Lit->_value << "\"\n");
storage.resize(NUMBER_TO_STRING_BUF_SIZE);
auto len = numberToString(Lit->_value, storage.data(), storage.size());
return llvh::StringRef(storage.begin(), len);
Expand All @@ -682,7 +690,7 @@ static llvh::StringRef propertyKeyAsString(
}

Value *ESTreeIRGen::genObjectExpr(ESTree::ObjectExpressionNode *Expr) {
LLVM_DEBUG(dbgs() << "Initializing a new object\n");
LLVM_DEBUG(llvh::dbgs() << "Initializing a new object\n");

/// Store information about a property. Is it an accessor (getter/setter) or
/// a value, and the actual value.
Expand Down Expand Up @@ -1388,15 +1396,15 @@ Value *ESTreeIRGen::genUnaryExpression(ESTree::UnaryExpressionNode *U) {
if (kind == UnaryOperatorInst::OpKind::DeleteKind) {
if (auto *memberExpr =
llvh::dyn_cast<ESTree::MemberExpressionNode>(U->_argument)) {
LLVM_DEBUG(dbgs() << "IRGen delete member expression.\n");
LLVM_DEBUG(llvh::dbgs() << "IRGen delete member expression.\n");

return genMemberExpression(memberExpr, MemberExpressionOperation::Delete)
.result;
}

if (auto *memberExpr = llvh::dyn_cast<ESTree::OptionalMemberExpressionNode>(
U->_argument)) {
LLVM_DEBUG(dbgs() << "IRGen delete optional member expression.\n");
LLVM_DEBUG(llvh::dbgs() << "IRGen delete optional member expression.\n");

return genOptionalMemberExpression(
memberExpr, nullptr, MemberExpressionOperation::Delete)
Expand Down Expand Up @@ -1454,7 +1462,7 @@ Value *ESTreeIRGen::genUnaryExpression(ESTree::UnaryExpressionNode *U) {
}

Value *ESTreeIRGen::genUpdateExpr(ESTree::UpdateExpressionNode *updateExpr) {
LLVM_DEBUG(dbgs() << "IRGen update expression.\n");
LLVM_DEBUG(llvh::dbgs() << "IRGen update expression.\n");
bool isPrefix = updateExpr->_prefix;

UnaryOperatorInst::OpKind opKind;
Expand Down Expand Up @@ -1496,7 +1504,7 @@ static Identifier extractNameHint(const LReference &lref) {
}

Value *ESTreeIRGen::genAssignmentExpr(ESTree::AssignmentExpressionNode *AE) {
LLVM_DEBUG(dbgs() << "IRGen assignment operator.\n");
LLVM_DEBUG(llvh::dbgs() << "IRGen assignment operator.\n");

auto opStr = AE->_operator->str();

Expand Down Expand Up @@ -1643,7 +1651,8 @@ Value *ESTreeIRGen::genConditionalExpr(ESTree::ConditionalExpressionNode *C) {
Value *ESTreeIRGen::genIdentifierExpression(
ESTree::IdentifierNode *Iden,
bool afterTypeOf) {
LLVM_DEBUG(dbgs() << "Looking for identifier \"" << Iden->_name << "\"\n");
LLVM_DEBUG(
llvh::dbgs() << "Looking for identifier \"" << Iden->_name << "\"\n");

// 'arguments' is an array-like object holding all function arguments.
// If one of the parameters is called "arguments" then it shadows the
Expand All @@ -1670,14 +1679,14 @@ Value *ESTreeIRGen::genIdentifierExpression(
}

LLVM_DEBUG(
dbgs() << "Found variable " << StrName << " in function \""
<< (llvh::isa<GlobalObjectProperty>(Var)
? llvh::StringRef("global")
: cast<Variable>(Var)
->getParent()
->getFunction()
->getInternalNameStr())
<< "\"\n");
llvh::dbgs() << "Found variable " << StrName << " in function \""
<< (llvh::isa<GlobalObjectProperty>(Var)
? llvh::StringRef("global")
: cast<Variable>(Var)
->getParent()
->getFunction()
->getInternalNameStr())
<< "\"\n");

// Typeof <variable> does not throw.
return emitLoad(Builder, Var, afterTypeOf);
Expand Down Expand Up @@ -1710,7 +1719,7 @@ Value *ESTreeIRGen::genMetaProperty(ESTree::MetaPropertyNode *MP) {
}

Value *ESTreeIRGen::genNewExpr(ESTree::NewExpressionNode *N) {
LLVM_DEBUG(dbgs() << "IRGen 'new' statement/expression.\n");
LLVM_DEBUG(llvh::dbgs() << "IRGen 'new' statement/expression.\n");

Value *callee = genExpression(N->_callee);

Expand Down Expand Up @@ -1742,7 +1751,7 @@ Value *ESTreeIRGen::genNewExpr(ESTree::NewExpressionNode *N) {
Value *ESTreeIRGen::genLogicalExpression(
ESTree::LogicalExpressionNode *logical) {
auto opStr = logical->_operator->str();
LLVM_DEBUG(dbgs() << "IRGen of short circuiting: " << opStr << ".\n");
LLVM_DEBUG(llvh::dbgs() << "IRGen of short circuiting: " << opStr << ".\n");

enum class Kind {
And, // &&
Expand Down Expand Up @@ -1823,7 +1832,8 @@ void ESTreeIRGen::genLogicalExpressionBranch(
BasicBlock *onFalse,
BasicBlock *onNullish) {
auto opStr = logical->_operator->str();
LLVM_DEBUG(dbgs() << "IRGen of short circuiting: " << opStr << " branch.\n");
LLVM_DEBUG(
llvh::dbgs() << "IRGen of short circuiting: " << opStr << " branch.\n");

auto parentFunc = Builder.getInsertionBlock()->getParent();
auto *block = Builder.createBasicBlock(parentFunc);
Expand All @@ -1842,7 +1852,7 @@ void ESTreeIRGen::genLogicalExpressionBranch(
}

Value *ESTreeIRGen::genTemplateLiteralExpr(ESTree::TemplateLiteralNode *Expr) {
LLVM_DEBUG(dbgs() << "IRGen 'TemplateLiteral' expression.\n");
LLVM_DEBUG(llvh::dbgs() << "IRGen 'TemplateLiteral' expression.\n");

assert(
Expr->_quasis.size() == Expr->_expressions.size() + 1 &&
Expand Down Expand Up @@ -1885,7 +1895,7 @@ Value *ESTreeIRGen::genTemplateLiteralExpr(ESTree::TemplateLiteralNode *Expr) {

Value *ESTreeIRGen::genTaggedTemplateExpr(
ESTree::TaggedTemplateExpressionNode *Expr) {
LLVM_DEBUG(dbgs() << "IRGen 'TaggedTemplateExpression' expression.\n");
LLVM_DEBUG(llvh::dbgs() << "IRGen 'TaggedTemplateExpression' expression.\n");
// Step 1: get the template object.
auto *templateLit = cast<ESTree::TemplateLiteralNode>(Expr->_quasi);

Expand Down
24 changes: 12 additions & 12 deletions lib/IRGen/ESTreeIRGen-func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void ESTreeIRGen::genFunctionDeclaration(

// Find the name of the function.
Identifier functionName = getNameFieldFromID(func->_id);
LLVM_DEBUG(dbgs() << "IRGen function \"" << functionName << "\".\n");
LLVM_DEBUG(llvh::dbgs() << "IRGen function \"" << functionName << "\".\n");

auto *funcStorage = nameTable_.lookup(functionName);
assert(
Expand All @@ -90,9 +90,9 @@ Value *ESTreeIRGen::genFunctionExpression(
}

LLVM_DEBUG(
dbgs() << "Creating anonymous closure. "
<< Builder.getInsertionBlock()->getParent()->getInternalName()
<< ".\n");
llvh::dbgs()
<< "Creating anonymous closure. "
<< Builder.getInsertionBlock()->getParent()->getInternalName() << ".\n");

NameTableScopeTy newScope(nameTable_);
Variable *tempClosureVar = nullptr;
Expand Down Expand Up @@ -133,9 +133,9 @@ Value *ESTreeIRGen::genArrowFunctionExpression(
ESTree::ArrowFunctionExpressionNode *AF,
Identifier nameHint) {
LLVM_DEBUG(
dbgs() << "Creating arrow function. "
<< Builder.getInsertionBlock()->getParent()->getInternalName()
<< ".\n");
llvh::dbgs()
<< "Creating arrow function. "
<< Builder.getInsertionBlock()->getParent()->getInternalName() << ".\n");

if (AF->_async) {
Builder.getModule()->getContext().getSourceErrorManager().error(
Expand Down Expand Up @@ -481,9 +481,9 @@ void ESTreeIRGen::emitFunctionPrologue(
auto *newFunc = curFunction()->function;
auto *semInfo = curFunction()->getSemInfo();
LLVM_DEBUG(
dbgs() << "Hoisting "
<< (semInfo->varDecls.size() + semInfo->closures.size())
<< " variable decls.\n");
llvh::dbgs() << "Hoisting "
<< (semInfo->varDecls.size() + semInfo->closures.size())
<< " variable decls.\n");

Builder.setLocation(newFunc->getSourceRange().Start);

Expand Down Expand Up @@ -547,12 +547,12 @@ void ESTreeIRGen::emitFunctionPrologue(
void ESTreeIRGen::emitParameters(ESTree::FunctionLikeNode *funcNode) {
auto *newFunc = curFunction()->function;

LLVM_DEBUG(dbgs() << "IRGen function parameters.\n");
LLVM_DEBUG(llvh::dbgs() << "IRGen function parameters.\n");

// Create a variable for every parameter.
for (auto paramDecl : funcNode->getSemInfo()->paramNames) {
Identifier paramName = getNameFieldFromID(paramDecl.identifier);
LLVM_DEBUG(dbgs() << "Adding parameter: " << paramName << "\n");
LLVM_DEBUG(llvh::dbgs() << "Adding parameter: " << paramName << "\n");
auto *paramStorage = Builder.createVariable(
newFunc->getFunctionScope(), Variable::DeclKind::Var, paramName);
// Register the storage for the parameter.
Expand Down
Loading

0 comments on commit a96ad7d

Please sign in to comment.